tags:

views:

320

answers:

1

A fairly simple question for which I have a guess, but I can't find a definitive answer anywhere.

The background: I have a multi-track midi file with TEMPO controls in the first track. I need to translate the ABSOLUTE_TICK count in other tracks to "Seconds" (fractional seconds offset from the beginning of the midi file).

I have the formula to relate ABSOLUTE_TICK to Seconds based on the PulsePerQuarterNote (PPQN) for the file to the tempo (MS per quarter note).

The question is: do TEMPO changes in the first track (track 0) apply to all the other tracks?

If so, then while I'm parsing other tracks (e.g. track 4, which has NOTE_ON and NOTE_OFF messages I am interested in) I will need to keep a finger pointing to the TEMPO changes in track 0 in parallel. Is that right?

Thanks,

Mark

+2  A: 

In short, yes. The first track contains the timing info which will be applied for the entire arrangement, so you apply these messages for each of the tracks with the same absolute time. Since all events use an offset in ticks, you need to first extract the tempo change messages, convert them to absolute time, and then as you are reading in the other tracks you will apply these messages based on that timeline.

From the MIDI fanatic's technical brainwashing center:

In a format 0 file, the tempo changes are scattered throughout the one MTrk. In format 1, the very first MTrk should consist of only the tempo (and time signature) events so that it could be read by some device capable of generating a "tempo map". It is best not to place MIDI events in this MTrk. In format 2, each MTrk should begin with at least one initial tempo (and time signature) event.

That said, some sequencers do break this rule and put actual MIDI events in the first track alongside timing info, since the standard isn't so specific in this regard. Your program should deal with both cases, since it is likely to encounter MIDI files in the wild which are formatted in this way.

Nik Reiman
Thanks Nik...and the reference you gave is by far the most useful MIDI reference I've found.
Mark Laff
Yep, I love that webpage myself. It's a treasure trove for all things MIDI, and also has a nice dose of geek humor to keep things from getting too dry. In case you didn't figure it out already, the main portal page is actually at http://home.roadrunner.com/~jgglatt/
Nik Reiman