Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Midi TEMPO message apply to other tracks?

Tags:

midi

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

like image 843
Mark Laff Avatar asked Jul 03 '09 17:07

Mark Laff


1 Answers

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.

like image 123
Nik Reiman Avatar answered Oct 22 '22 11:10

Nik Reiman