MIDI Files: Musical Instrument Digital Interface Explained
MIDI (Musical Instrument Digital Interface) is one of the music industry's most enduring technical standards. Finalized in 1983 by a consortium of synthesizer manufacturers (Roland, Sequential Circuits, Yamaha, Korg, Oberheim), MIDI defines both a communication protocol between hardware devices and a file format for storing musical performance data. Unlike audio formats (MP3, WAV, FLAC) that store recorded sound, MIDI stores instructions — which notes to play, how loud, on which instrument, with what timing. The same MIDI file sounds completely different when played back on a Roland synthesizer vs. a Yamaha grand piano plugin vs. a General MIDI soundfont.
What MIDI Is (and Is Not)
MIDI stores performance data, not audio. A MIDI file for Beethoven's Moonlight Sonata might be 15 KB. An equivalent WAV recording at CD quality is 40+ MB. The MIDI file says "play note C4 at velocity 80 for 1.2 seconds on channel 1" — it says nothing about what C4 actually sounds like. The playback device or software synthesizer supplies the sound.
This has profound implications:
- Editability: Every note, velocity, timing, and instrument assignment is individually editable
- Transposability: Transpose the entire piece by any interval without quality loss
- Tempo flexibility: Change the tempo without affecting pitch (unlike speeding up audio)
- Arrangement: Mute, solo, rearrange any instrument independently
- Tiny file size: Complex compositions fit in a few kilobytes
What MIDI cannot do:
- Capture subtle tonal variations that live performances have (breath, vibrato, bowing pressure)
- Store audio effects like reverb or distortion
- Guarantee identical playback across different synthesizers
- Represent audio (drums recorded as audio vs. programmed MIDI sound completely different)
MIDI File Structure (SMF — Standard MIDI File)
MIDI files use the .mid or .midi extension and conform to the Standard MIDI File (SMF) format. An SMF file consists of chunks:
Header chunk: 14 bytes
4D 54 68 64 → "MThd" (Magic)
00 00 00 06 → Chunk length (always 6)
00 01 → Format (0=single track, 1=multi-track sync, 2=multi-track independent)
00 04 → Number of tracks
01 E0 → Division (ticks per quarter note = 480 here)
Track chunks (one per track, Format 1):
4D 54 72 6B → "MTrk"
XX XX XX XX → Track data length
[delta_time, MIDI_event...]
Each event in a track is prefixed by a delta time — the number of ticks since the previous event. This variable-length encoding is efficient for musical data where events are often close together.
MIDI Event Types
Channel Voice Messages (musical performance):
8nNote Off — stop playing note (channel n, note, velocity)9nNote On — start playing note (channel n, note, velocity)AnAftertouch — pressure after key pressBnControl Change — CC messages (volume, pan, modulation, sustain pedal, etc.)CnProgram Change — switch instrument (General MIDI instrument number)DnChannel Pressure — overall channel pressureEnPitch Bend — pitch wheel ±8,192 semitones up or down
System Exclusive (SysEx) F0...F7:
Manufacturer-specific messages for synthesizer parameter control (patch data, tuning, etc.).
Meta Events FF:
FF 51— Set Tempo (microseconds per quarter note)FF 58— Time SignatureFF 59— Key SignatureFF 03— Track NameFF 01— Text CommentFF 2F— End of Track
MIDI Channels and General MIDI
MIDI has 16 channels. Each channel can be assigned a different instrument via Program Change messages. Channel 10 is universally reserved for drums in General MIDI (GM) — percussion instruments are mapped to specific note numbers on channel 10.
General MIDI (GM) defines a standard set of 128 instruments (patches) that all GM-compliant synthesizers must support, using the same numbering:
- 0 = Acoustic Grand Piano
- 24 = Acoustic Guitar (nylon)
- 40 = Violin
- 56 = Trumpet
- 72 = Piccolo
- 80 = Lead 1 (square wave)
GM ensures that a MIDI file composed on one GM synthesizer sounds approximately correct on another — though timbre still varies significantly between manufacturers.
General MIDI 2 (GM2), Roland GS, and Yamaha XG extend GM with additional patches, variations, and effects parameters.
Converting MIDI Files
MIDI to MP3 / WAV (Synthesizing Audio)
This is the most common conversion request. It requires a software synthesizer to render the MIDI performance to audio using a soundfont or sample library.
Using FluidSynth (free, open source):
# Download a General MIDI soundfont first (e.g., FluidR3_GM.sf2)
fluidsynth -ni -F output.wav -r 44100 /path/to/FluidR3_GM.sf2 input.mid
# Then convert WAV to MP3
ffmpeg -i output.wav -c:a libmp3lame -q:a 2 output.mp3
Using TiMidity++ (free, open source):
timidity -Ow -o output.wav input.mid
Using MuseScore (GUI): File → Export → MP3 / WAV. MuseScore uses its own high-quality soundfont.
Quality tip: The output quality depends almost entirely on the soundfont. The free FluidR3_GM.sf2 (141 MB) sounds much better than the built-in Windows MIDI synth. Professional soundfonts (Vienna Symphonic Library, BBCSO, Spitfire) produce orchestral-quality output.
MIDI to Sheet Music / MusicXML
MIDI contains enough information (notes, durations, dynamics) to produce sheet music, though the result requires manual cleanup:
MuseScore: File → Open (MIDI file) → automatic quantization → Edit → Export → MusicXML / PDF
Sibelius / Finale / Dorico: All support MIDI import with quantization settings to clean up timing.
midi2abc: Converts MIDI to ABC notation (a text-based sheet music format):
midi2abc input.mid -o output.abc
MIDI to JSON / Text for Analysis
from mido import MidiFile
import json
mid = MidiFile('input.mid')
events = []
for track in mid.tracks:
for msg in track:
events.append({
'type': msg.type,
'time': msg.time,
'channel': getattr(msg, 'channel', None),
'note': getattr(msg, 'note', None),
'velocity': getattr(msg, 'velocity', None),
})
with open('output.json', 'w') as f:
json.dump(events, f, indent=2)
MIDI in Music Production
Digital Audio Workstations (DAWs): Every professional DAW — Ableton Live, Logic Pro, Pro Tools, Cubase, FL Studio, Reaper — uses MIDI as its core performance language. Programmers record MIDI from keyboards, quantize timing, edit individual notes in a piano roll editor, then route each MIDI track to a software synthesizer or virtual instrument plugin.
Live performance: MIDI keyboards, drum pads, wind controllers, and guitar synthesizers send MIDI data to synthesizers, computers, or effects processors in real time.
Notation software: MuseScore, Sibelius, Finale, and Dorico use MIDI as input and output for playback and import/export.
Game audio: MIDI was used extensively in early game music (Nintendo's NES had hardware comparable to a MIDI synthesizer). Modern games use pre-rendered audio, but MIDI still powers some adaptive music systems.
MIDI vs. Audio Files
| Feature | MIDI | Audio (WAV/MP3) |
|---|---|---|
| File size | Tiny (KB) | Large (MB) |
| Editable notes | ✅ | ❌ |
| Sounds like original | Depends on synth | ✅ Exact |
| Transposable | ✅ No quality loss | Requires pitch shifting |
| Tempo changeable | ✅ | Requires time stretching |
| Cross-platform sound | Varies by synth | Consistent |
| Captures live audio | ❌ | ✅ |
MIDI is a composition and performance format. Audio is a playback format. Professional music production uses both: MIDI for arrangement and editing, audio for final mixdown.
Related conversions
Frequent conversions across the catalogue: