MIDI Programming

MIDI Timing
MIDI events have a Delta Time value, which determines when the event should be played relative to the track's last event. It is measured in ticks.

The header defines the tempo of quarter notes in the time division field, measured in ticks per quarter note.

Tempo is 120 BPM per default, and can be changed using a 'Set Tempo' meta event, setting the tempo in terms of microseconds per quarter-note.

Delta time   : ticks Time division : ticks/quarternote Tempo        : μs/quarternote x BPM = x quarternotes/m = 1/x m/quarternote = 60,000,000/x μs/quarternote

Example: if a MIDI event has a delta time = 46 ticks, and the tempo = 120 BPM = 500,000 μs/quarternote and time division = 192 ticks/quarternote, then the actual time to wait before playing the event is: 46 ticks ---                  = 23/96 quarternotes 192 ticks/quarternote which is: 23/96 quarternotes * 500,000 μs/quarternote ~ 119792 μs ~ 120 ms