Introduction
A Standard MIDI File stores music as performance instructions, not sound: which note to play, when, how hard and on which instrument. A synthesiser or sound bank turns the instructions into audio, so the same file sounds different on different devices. The format is defined by the MIDI Association and is used to move songs between sequencers, notation programs and keyboards.
Files use the extension .mid and sometimes .midi.
Structure
A MIDI file is a series of chunks, each a four-letter type and a 32-bit big-endian
length. The header chunk MThd comes first. Its six bytes give the file
format (0 for a single track, 1 for several tracks played together, 2 for independent
patterns), the number of tracks and the timing division, usually ticks per quarter
note.
Each track chunk MTrk is a list of events. Every event starts with a
delta time, the ticks since the previous event, written as a variable-length number
of 7 bits per byte. The event is then a MIDI message (note on, note off, control
change, program change and so on), a system exclusive message, or a meta event
starting FF such as tempo, time signature, track name or end of track.
0MThd format, track count, division14 bytes14MTrk track chunk, one per trackrepeated+0MTrk chunk type and length8 bytes+8Events delta time, then a MIDI, SysEx or meta eventrepeated
Links
Software
- MuseScore (Windows, macOS, Linux)
- REAPER (Windows, macOS, Linux)
- Logic Pro (macOS)
- GarageBand (macOS, iOS)
- FL Studio (Windows, macOS)
- Ableton Live (Windows, macOS)
- Cubase (Windows, macOS)
Developers
- Mido, Python library that reads and writes MIDI files
- midifile, C++ library for Standard MIDI Files
- FluidSynth, C synthesiser library that plays MIDI files with SoundFonts
Reference
- MIDI specifications, the MIDI Association, including Standard MIDI Files