MIDI Format: The Complete Technical Guide
MIDI (Musical Instrument Digital Interface) is not an audio format — it contains no audio data. Instead, it is a protocol and file format that stores musical performance information as discrete events: which note was played, when, for how long, how hard, on which instrument channel, and with which controller changes (pitch bend, modulation, expression). A MIDI file is essentially a recipe for a performance that a synthesizer, sampler, or software instrument reads and plays back. Standardized in 1983 by the MIDI Manufacturers Association (MMA), MIDI transformed the music industry and remains foundational to music production 40 years later.
Historical Context
Before MIDI, synthesizers from different manufacturers could not communicate. Each had proprietary connections; connecting a Minimoog keyboard to a Roland synthesizer was impossible without custom wiring. MIDI was developed collaboratively by Sequential Circuits, Roland, Korg, Yamaha, and others as an open standard — revolutionary for the era. The first public MIDI demonstration was at NAMM 1983, connecting a Sequential Circuits Prophet-600 to a Roland JP-6. Dave Smith (Sequential Circuits) is widely credited as MIDI's primary inventor. MIDI's design for 31,250 baud serial transmission over 5-pin DIN connectors was chosen for cost: standard UART chips were cheap in 1983. The same protocol still ships hardware in 2024, though USB-MIDI and MIDI over IP (RTP-MIDI/AppleMIDI) are now standard.
MIDI 1.0 Physical Layer
Traditional MIDI uses:
- 5-pin DIN connectors: MIDI IN (receive), MIDI OUT (transmit), MIDI THRU (pass-through copy of IN)
- 31,250 baud serial, 8N1: 8 data bits, no parity, 1 stop bit. Each byte takes 320 µs to transmit.
- Optoisolator on MIDI IN: Isolates ground loops between instruments
- Maximum cable length: 15 meters (specified), though 50+ meters often works in practice
MIDI 2.0 (2020) upgrades to 32-bit messages and bidirectional protocol negotiation while maintaining backward compatibility.
MIDI File Format (SMF — Standard MIDI File)
MIDI files are Standard MIDI Files (SMF). They have two parts:
Header Chunk
4D 54 68 64 = "MThd" (magic)
00 00 00 06 = Chunk length: always 6 bytes
00 01 = Format: 0, 1, or 2
00 XX = Number of tracks
E7 28 = Division (timing resolution)
Format types:
- Format 0: Single track containing all channels. All events in one track. Simplest format; compatible with all hardware.
- Format 1: Multiple synchronous tracks. First track = tempo map; additional tracks = individual instruments. Most common for multi-track sequencer files.
- Format 2: Multiple independent patterns (less common; used for song libraries).
Division (timing):
- Ticks Per Quarter Note (PPQN): e.g., 480 TPQN means 480 ticks per beat. Tempo (in the Set Tempo event) determines actual time per tick.
- SMPTE timecode: Division encodes SMPTE frame rate + subframes per frame for video sync.
Track Chunk
Each track chunk: 4D 54 72 6B ("MTrk") + 4-byte length + MIDI events.
Events are preceded by a variable-length delta time (1–4 bytes, MSB-first with continuation bit):
- 0x00 = 0 ticks (simultaneous with previous event)
- 0x60 = 96 ticks
- 0x81 0x00 = 128 ticks (2-byte encoding)
MIDI Event Types
Channel Voice Messages
The core of MIDI performance data. Channel number is in the low nibble of the status byte.
| Status Nibble | Event | Data Bytes | Description |
|---|---|---|---|
| 0x8n | Note Off | note (0–127), velocity (0–127) | Release note on channel n |
| 0x9n | Note On | note, velocity | Press note. Velocity=0 = Note Off |
| 0xAn | Aftertouch | note, pressure | Per-note pressure (rare) |
| 0xBn | Control Change (CC) | controller (0–127), value (0–127) | Modulation, volume, pan, etc. |
| 0xCn | Program Change | program (0–127) | Select instrument/patch |
| 0xDn | Channel Pressure | pressure (0–127) | Overall channel aftertouch |
| 0xEn | Pitch Bend | LSB (0–127), MSB (0–127) | Pitch deviation ±2 semitones (default) |
Note numbers: Middle C = note 60 (MIDI C4 convention). Range 0–127 = C-1 to G9.
Velocity: 0–127 represents note attack strength. Velocity 0 on Note On is equivalent to Note Off (running status optimization).
Important Control Change Numbers
| CC# | Controller | Purpose |
|---|---|---|
| 1 | Modulation Wheel | Vibrato depth, LFO |
| 7 | Channel Volume | Overall channel level |
| 10 | Pan | Stereo position (0=left, 64=center, 127=right) |
| 11 | Expression | Relative volume (CC7 × CC11 / 127) |
| 64 | Sustain Pedal | Hold notes (0–63=off, 64–127=on) |
| 91 | Reverb Send | Effect return level |
| 93 | Chorus Send | Effect return level |
| 120 | All Sound Off | Immediately silence all notes |
| 121 | Reset All Controllers | Restore CC defaults |
| 123 | All Notes Off | Release all held notes |
General MIDI (GM)
General MIDI standardizes Program Change assignments so that a GM-compatible synthesizer always responds to the same instrument on the same program number. Channel 10 is reserved for drums (note number = drum sound). Piano = 0, Electric Bass = 33, Violin = 40, Trumpet = 56, Acoustic Guitar = 25. 128 instruments + 47 drum sounds.
GM Level 2 (GM2) extends to 256 instruments, 16 drum kits, and additional controllers.
Meta Events
Meta events are SMF-specific (not transmitted over MIDI hardware). They carry non-performance data:
| FF type | Name | Data |
|---|---|---|
| FF 01 | Text Event | Arbitrary text |
| FF 02 | Copyright Notice | Copyright string |
| FF 03 | Track Name | Track/sequence name |
| FF 05 | Lyric | Lyric text for karaoke |
| FF 06 | Marker | Section marker (intro, chorus) |
| FF 20 | MIDI Channel Prefix | Route following SysEx to channel |
| FF 2F 00 | End of Track | Required at end of every track |
| FF 51 03 | Set Tempo | 3 bytes: microseconds per quarter note (e.g., 500000 = 120 BPM) |
| FF 54 | SMPTE Offset | Start offset for SMPTE sync |
| FF 58 | Time Signature | Numerator, denominator (power of 2), clocks per metronome, 32nds per quarter |
| FF 59 | Key Signature | Key (0=C, 1=G..., -1=F...), mode (0=major, 1=minor) |
| FF 7F | Sequencer Specific | Application-specific data |
System Exclusive (SysEx)
SysEx messages (0xF0 ... 0xF7) allow device-specific communication — sending patch data, tuning tables, custom parameters. SysEx IDs are registered with the MMA to avoid conflicts. Universal SysEx messages (0x7E and 0x7F IDs) provide standardized functions like Sample Dump, MIDI Show Control, and MIDI Machine Control.
MIDI Timing and Tempo
Tempo is stored in microseconds per quarter note (µs/quarter):
- 120 BPM = 500,000 µs/quarter
- 60 BPM = 1,000,000 µs/quarter
- 240 BPM = 250,000 µs/quarter
A Set Tempo event (FF 51 03 tt tt tt) can change tempo mid-file. With 480 PPQN and 500,000 µs/quarter, each tick = 500,000/480 ≈ 1,041.7 µs ≈ 1.04 ms.
MIDI timing has inherent imprecision due to the serial transmission delay (~320 µs per byte) and the sequencer's scheduling resolution. For video sync, SMPTE timecode (FF 54 meta event) is used.
MIDI File Tools and Conversion
# Play MIDI with TiMidity++ software synthesizer
timidity input.mid
# Play with FluidSynth and a SoundFont
fluidsynth -a alsa /usr/share/sounds/sf2/FluidR3_GM.sf2 input.mid
# Convert MIDI to audio with FluidSynth
fluidsynth -F output.wav /path/to/soundfont.sf2 input.mid
ffmpeg -i output.wav -c:a libmp3lame -q:a 2 output.mp3
# Convert MIDI to audio with TiMidity++
timidity input.mid -Ow -o output.wav
# Analyze MIDI file structure
python3 -c "import mido; mid = mido.MidiFile('input.mid'); print(mid)"
# Python: read all note events
python3 << 'EOF'
import mido
mid = mido.MidiFile('input.mid')
for track in mid.tracks:
for msg in track:
if msg.type in ['note_on', 'note_off']:
print(msg)
EOF
# Merge multiple MIDI files
python3 -c "
import mido
mid1 = mido.MidiFile('track1.mid')
mid2 = mido.MidiFile('track2.mid')
merged = mido.MidiFile(type=1)
for track in mid1.tracks + mid2.tracks[1:]:
merged.tracks.append(track)
merged.save('merged.mid')
"
MIDI in Modern Production
MIDI remains the universal language between:
- DAWs: Ableton Live, Logic Pro, Pro Tools, FL Studio, Cubase, Reaper — all use MIDI internally
- Hardware synthesizers: Roland, Korg, Moog, Sequential — all have MIDI IN/OUT
- Software instruments: VST/AU/AAX plugins (Kontakt, Serum, Massive, Omnisphere) respond to MIDI
- Controllers: Piano keyboards, pads (Maschine, Push), wind controllers, drum kits
- Stage equipment: Lighting consoles (DMX via MIDI Show Control), mixers, effects units
MIDI 2.0 (released 2020) extends message resolution from 7-bit to 32-bit values (4.3 billion levels of expression vs. 128), adds per-note controllers, bidirectional property exchange, and profile configuration — while maintaining backward compatibility with MIDI 1.0.
Related conversions
Frequent conversions across the catalogue: