Posted on

MIDI Time Math…Again

Time, MIDI, Music and Math

Originally published: 2007-05-28 04:57:55
Original post URL:

I am getting tired of deriving formulas for converting various MIDI data to real time. At the moment I’m wanting to make a standard MIDI file (SMF) to CSound .sco conversion utility. (Yes, I know there already is one) The most significant part of the task is to come up with some code that takes the time signature, tempo, and timing data and converts it to clock time (in seconds)

So here we go, with an attempt of memorializing this once and for all!

MIDI Division is the number of delta-times per quarter note. I’m calling the units of division [ticks/quarter-note]

MIDI Tempo is specified in [microsecond/quarter-note]

A MIDI quarter-note is 24 MIDI-clocks. (clocks are not ticks. Clocks are not delta-times)

Some quantities comprising a MIDI time signature (we don’t need this for the problem at hand but, while I’m documenting this stuff, I’ll include it): numerator (beats-per-bar), denominator – as a negative power of two, number of MIDI-clocks per metronome click [MIDI-clocks/beat] and number of 32nd notes per MIDI quarter (this last number I’m assuming is always constant equal to eight.

So, to convert a quantity of MIDI delta-times to seconds:

(numDeltaTimes[ticks] / division [ticks/quarter-note]) * tempo[microseconds/quarternote]*(1[second]/10^6[microseconds])

or with out all my ‘unit’ notation:

numTicks * tempo / (division * 10^6)

where numTicks, tempo and division are the raw quantities from the events and header of the MIDI file.