Tux Guitar

Help

  Forums : Help
Subject Trying to determine measure# a sequence is playing



Author Message
Tails
Post: Nov 16th 2008 at 3:47 PM

I'm playing a midi file as a Java Sequence.
Now, I'd like to be able to determine what measure the sequence is currently playing.

I guess I need to know how long (in milliseconds) a TGMeasure is, or at how many milliseconds in the file it starts.

So I would like to know what exactly the methods getStart() and getLength() in TGMeasureHeader return.

Do they return the length and positions of quarternotes? Of milliseconds in the file? Of ticks? Tick lengths?


Back to Top
 
Julian
Post: Nov 16th 2008 at 4:28 PM

I'm not sure what are you doing.
But a java "Sequence" uses MIDI format, and it don't have measures, beats, etc... it only have MidiEvents.

Now, if you are doing something with tuxguitar classes,
i can tell you that tuxguitar uses: "org.herac.tuxguitar.gui.util.MidiTickUtil"
to get TG vs MIDI positions. (these positions may seems the same, but they are different after things like repeats )

but this class uses TGSongManager from tuxguitar instance.. so you'll need use it, or modify the class.

Once you have the measure start doing:
long start = MidiTickUtil.getStart( midiTick )

You can get the measure doing:
songManager.getMeasureManager().getMeasureAt(TGTrack track, long start)

Ofcourse, songManager instance must be same as used on MidiTickUtil.

> So I would like to know what exactly the methods getStart() and getLength() in TGMeasureHeader return.

It's a time position (but not a millisecond time, a real time in milliseconds may allways depend on the "tempo" value ).
As default, tuxguitar uses "960" as a "Quarter" duration.
This constant is setted at TGDuration.QUARTER_TIME

The length is calculated by the time signature.
if a measure have a 2/4 time signature, this means that it will have 2 quarter beats.
so the length will be numerator (2) * denominator value ( QUARTER_TIME ) = 1920.

As default, first measure starts at QUARTER_TIME.
so this 2/4 measure, will start at 960, and will finish at 2880 ( start + length ).
then, if there is a new measure, it will start at 2880 (when previous finished ), and will end at start + length..


Back to Top
 
Tails
Post: Nov 16th 2008 at 10:52 PM

Thanks!
It works now. I'm able to determine the current measure in a sequence by the following: (provided is the TGSong song)

public static int getCurrentBar()
{
long pos = sequencer.getTickPosition();

int i;
for (i = 0; i < song.countMeasureHeaders(); i++)
{
TGMeasureHeader bar = song.getMeasureHeader(i);
long length = bar.getLength();
long start = bar.getStart();
if (pos >= start && pos < start + length)
{
break;
}
}

return i;
}


Back to Top
 
Julian
Post: Nov 16th 2008 at 11:17 PM

It may don't work if any TGMeasureHeader have repeats..
Just think, that for midi, the measure repeats don't exists.
so the sequence have duplicated events.

See for example.
1 measure start at 4000, and finish at 8000, but it have a repeat.
on MIDI, the sequence will add it from 4000 To 8000, and will add it again from 8000 To 12000.
This means, that next measure, on MIDI Sequence will start at 12000 while for TGSong structure it will be at 8000.

This is the objetive of MidiTickUtil. it call to another class (don't remember the name) what check repeats, alternative endings, etc...


Back to Top
 
Tails
Post: Nov 17th 2008 at 9:57 AM

MidiRepeatController(TGSong)

I modified MidiTickUtil a bit so I could provide my given TGSong. This way, I do not have to get the SongManager from the TuxGuitar GUI (which I do not have).

It works fine :)

I'm beginning to understand your code ;)


Back to Top
 
cheap watch
Post: Apr 27th 2012 at 4:59 AM

In our replica watches shop- Cartier watches – the world ‘s top swiss watches , connected art and creative and perfect workmanship into one . In our watches shop you could see our replica cartier watches in all selections from Replica Cartier Watches Santos , Replica Cartier Watches Tank Louis , Replica Cartier Watches Pasha , Replica Cartier Watches Roaster , To Replica Cartier Watches Ronde , Replica Cartier Watches Ballon Bleu . Our Cartier watches are all classical compared to other watches shop . All Our replica Cartier watches or other swiss watches are made by top 1:1 original swiss watches from appearance to internal movement core . All swiss watches for sales in our watches shop are high quality watches in perfect working condition. Nowadays All Our Cartier watches shop and All Cartier Swiss watches are on sales . With interest to see swiss watches for sales or replica watches , Cartier watches . Please visit our watches shop –In our www.shopbuynet.com


Back to Top