MIDI
MIDI (Musical Instrument Digital Interface) is a standard serial protocol and file format to represent musical performance as timed messages (notes, control changes, program changes) used in music production, synthesis and multimedia synchronization.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
MIDI is used by engineers to transmit and record musical performance data, control synthesizers and DAWs, and synchronize multimedia systems (audio, video, lighting). Knowing MIDI lets you integrate music hardware and software, compute timing for playback, and implement MIDI parsers and generators in multimedia applications.
Key ideas
Start from first principles and simple definitions:
MIDI (Musical Instrument Digital Interface): a standardized digital protocol and data representation that sends musical performance events (notes, controller changes, program changes) as bytes over a serial link or stored inside files. It encodes "what" was played, not raw audio.
Byte-oriented serial transport: Standard MIDI uses asynchronous serial communication at a baud rate of 31250 bit/s with 8 data bits, no parity, 1 stop bit (commonly written 8‑N‑1). Each transmitted unit is a byte (8 bits) framed by start and stop bits on the wire.
Status byte and data byte: A status byte has its most-significant bit (MSB) = 1 (values 0x80–0xFF). Data bytes have MSB = 0 (values 0x00–0x7F). This single-bit convention is the basis for parsing.
Channels: MIDI defines 16 channels (numbered 1–16 for humans, encoded 0–15 in the low nibble of the status byte). Channel messages (voice messages) use status bytes whose high nibble identifies the type (e.g., Note On, Note Off) and low nibble the channel.
Voice (Channel) messages: Common messages include Note On (
0x9n), Note Off (0x8n), Polyphonic Key Pressure (0xAn), Control Change (0xBn), Program Change (0xCn— single data byte), Channel Pressure (0xDn), Pitch Bend (0xEn— 14-bit value across two data bytes). Note On with velocity 0 must be treated as Note Off. Control Change controller numbers 120–127 are Channel Mode messages (e.g., All Notes Off). For Pitch Bend, the two data bytes are sent LSB then MSB; center (no bend) is 8192 (0x2000), encoded as data bytes0x00 0x40.System messages: Messages that are not channel-specific (System Real Time, System Common, System Exclusive or SysEx). SysEx (
0xF0...0xF7) carries manufacturer-specific variable-length data and is delimited by0xF7. System Real-Time messages (0xF8–0xFF) may appear at any time, even between data bytes, and do not affect running status; MIDI Clock (0xF8) is 24 pulses per quarter note.MIDI file vs MIDI wire protocol: A MIDI file (Standard MIDI File, SMF) stores timed events in tracks using delta-times encoded as Variable-Length Quantities (VLQ) and may include Meta-events (tempo, time signature) which appear only in files (not on the wire). The file also has a header with format type and ticks-per-quarter-note (PPQ). VLQ encodes values in 7‑bit groups with the MSB used as a continuation flag (1 = more bytes follow, 0 = last), big‑endian order. Meta‑events are introduced by
0xFFin files; on the wire0xFFis System Reset (not a meta‑event). The time division in the header can be PPQ or, alternatively, an SMPTE‑based division (negative value) indicating frames per second and ticks per frame.Delta-times and PPQ: A MIDI file expresses event timing as ticks; the file header contains PPQ (pulses per quarter note) a.k.a. ticks per quarter note. To convert these ticks to real time you need tempo.
Tempo: Tempo in MIDI files is usually given by a Meta-event that encodes microseconds per quarter note (a 3-byte integer). Often we express tempo in BPM (beats per minute). Conversion formulas connect BPM, microseconds per quarter note, and ticks. If no tempo meta-event is present, the default is 500000 μs per quarter note (120 BPM).
Running status: To save bandwidth, consecutive messages of the same status byte can omit the status byte; the receiver must reuse the previous status. This is legal on the MIDI wire and may also be used in SMF tracks for MIDI channel messages, but never for SysEx or meta events. System Real-Time bytes (
0xF8–0xFF) do not affect or cancel running status.Parsing and framing diagrams (draw these in an exam):
- Draw a serial frame: label Start bit (0), 8 data bits (LSB first), Stop bit (1). Annotate bit duration = 1/31250 s for standard MIDI.
- Draw a byte diagram: show 8 bits, mark MSB and LSB, label status byte (MSB=1) and data byte (MSB=0).
- Draw a Note On message layout: draw three boxes labeled Status byte = 0x9n, Data1 = note number (0–127), Data2 = velocity (0–127). Note channel mapping: channel 1 → n=0.
Assumptions often used in derivations: standard MIDI baud 31250 bit/s, asynchronous UART framing 8‑N‑1, channels 1–16 map to n=0–15, PPQ > 0 and tempo positive.
Formulas
μs_per_quarter = 60000000 / BPM — microseconds per quarter note; μs, BPM in beats per minute. Applies when tempo is given in BPM.
seconds_per_tick = (60 / BPM) / PPQ — seconds per tick when PPQ (ticks per quarter note) and BPM are known. seconds_per_tick in seconds. Equivalently, using a tempo meta-event: seconds_per_tick = (μs_per_quarter / 1e6) / PPQ.
time_for_ticks_seconds = ticks * seconds_per_tick — real time for a given number of ticks.
bit_time = 1 / baud — seconds per bit on the MIDI serial line. For standard MIDI baud = 31250 (verify), so bit_time ≈ 32 μs. For 8‑N‑1 framing, byte_time_8N1 = 10 / baud (1 start + 8 data + 1 stop); at 31250 bps this is ≈ 320 μs per byte.
Explain symbols: BPM = beats per minute (min⁻¹), PPQ = pulses (ticks) per quarter note (dimensionless), ticks = integer tick count, baud = bits per second (s⁻¹), μs = microseconds (1e-6 s).
Worked examples
Example 1 — Convert ticks to milliseconds (typical exam calculation) Given: tempo = 120 BPM, PPQ = 480, event delta = 240 ticks. Find event length in milliseconds. Steps:
seconds_per_tick = (60 / BPM) / PPQ(formula). Substitute:seconds_per_tick = (60 / 120) / 480.- Compute:
(60/120) = 0.5seconds per quarter note; divide by 480 →seconds_per_tick = 0.5 / 480 = 0.0010416666667 s. - Multiply by ticks:
time = 240 * 0.0010416666667 s = 0.25 s = 250 ms. Answer: 250 ms.
Example 2 — MIDI wire bytes for a Note On Task: Create the MIDI bytes to send Middle C (note number 60) on human channel 1 with velocity 100. Steps:
- Channel 1 maps to n = 0 in the status nibble. Note On status =
0x9n→0x90. - Data1 = note number = 60 decimal =
0x3C. - Data2 = velocity = 100 decimal =
0x64. - The three bytes on the wire are:
0x90 0x3C 0x64. UARTs transmit each byte with its least-significant bit first inside the serial frame; this bit order is fixed by the protocol. Final answer: 0x90 0x3C 0x64 (three bytes).
Example 3 — Running status savings
Sequence to send: Note On ch1 note 60 vel 90; Note On ch1 note 64 vel 80; Note On ch1 note 67 vel 100.
Full messages: 0x90 0x3C 0x5A ; 0x90 0x40 0x50 ; 0x90 0x43 0x64 — total 9 bytes.
With running status, send first status once, then only data pairs: 0x90 0x3C 0x5A 0x40 0x50 0x43 0x64 — total 7 bytes, saved 2 bytes. Answer shows how running status reduces bandwidth when many same-type messages follow.
Common mistakes
- Mixing MIDI file delta-times and MIDI wire timing: SMF stores delta-times in ticks (PPQ) and uses meta-events for tempo; the wire uses real-time bytes and running status — they are different contexts.
- Using the wrong tempo formula sign/unit (mixing µs per quarter and BPM incorrectly). Use
μs_per_quarter = 60000000/BPMorseconds_per_tick = (60/BPM)/PPQ. - Writing bit order incorrectly: bytes are transmitted LSB-first on the MIDI serial line; many novices assume MSB-first.
For your exam
Kinds of questions you will get:
- Definitions: define MIDI, status/data byte, SysEx, PPQ, running status, VLQ.
- Short notes: describe MIDI file structure, explain running status, compare MIDI wire vs SMF.
- Derivations: show conversion from BPM to seconds per tick and compute timings for events (numerical example with units required).
- Numericals: compute real-time durations given BPM and PPQ; compute bytes for a given note message; calculate baud bit time.
- Programs/algorithms: trace a small sequence showing running status removal or reconstructing absolute times from delta-times.
- Diagrams: draw serial frame, byte format, or Note On message layout.
What a full-marks answer includes:
- Clear definitions with the bold term named and explained.
- For numeric problems: state formula, substitute numeric values with units, show intermediate arithmetic, give final answer with units (SI).
- For protocol questions: show byte values in hex and decimal, explain MSB conventions, and mention assumptions (baud, 8‑N‑1 framing) if required.
Quick check
- What bit value (MSB) distinguishes a MIDI status byte from a data byte?
- How many human-visible MIDI channels exist and how are they encoded in the status byte?
- If tempo is 100 BPM and PPQ = 240, what is the time (ms) of 120 ticks?
Answers: 1) MSB = 1 for status, 0 for data. 2) 16 channels (numbered 1–16 for humans), encoded as n = 0–15 in the low nibble of the status byte. 3) seconds_per_tick = (60/100)/240 = 0.6/240 = 0.0025 s, time = 120 * 0.0025 s = 0.3 s = 300 ms.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?