The Standard MIDI File format was adopted in 1988 as an extension to the MIDI specification primarily to allow the exchange of sequence data created with different programs.
There are three types of MIDI files:
Format 0: the MIDI data is represented in a single track, though perhaps using several MIDI channels.
Format 1: the MIDI data is represented by multiple tracks, all synchronized to a common time representation (the first track should provide a tempo map).
Format 2: the MIDI data is represented with multiple independent tracks, perhaps a collection of Format 0 sequences.
In addition to note data, MIDI files can contain Meta-Events, which include specifications for tempo, time signature, key signature, sequence and track names, lyrics, cue points, score markers, timing resolution, copyright notices, and sequencer-specific information.
All events in a MIDI file are time stamped with delta time values of variable length (up to 28-bits represented in 4 bytes of data). These values represent clock ticks, the exact duration of which are controlled via other MIDI file parameters or Meta-Events.
As is common with several binary file formats, such as .wav audio files, the data in a MIDI file is sectioned into “chunks.” MIDI files contain one “Header chunk” and at least one “Track chunk.”