A Standard MIDI File is one MThd header chunk followed by one or more MTrk track chunks. MThd is 14 bytes; each MTrk is a stream of events, every event prefixed by a variable-length delta time. The clever field is division: its top bit flips the meaning of the other fifteen. Hover to light bytes or bits, click a + for its table. Color marks kind (see the key).
One header, then the tracks. Events use compact encodings (VLQ deltas, running status) that a parser must track byte by byte.
Format, track count, and timing division. The length is always 6 (extra header bytes are legal and skipped). See the byte map below.
The only length in the file, and it is a byte count, not an event count.
Seven payload bits per byte; the high bit set means another byte follows. A VLQ is capped at 4 bytes (28 payload bits), so the largest delta is 0x0FFFFFFF. A parser that loses sync here misreads everything after it. running-status bookkeeping is exactly where a one-byte desync turns into wrong note counts rather than an error.
Seven bits of payload per byte. The eighth says whether another byte follows.
Consecutive channel events with the same status may drop the repeated status byte; the parser must remember the last one. Most exporters use it.
High nibble is the message type, low nibble the channel (0-15). Types 8n-Bn and En carry two data bytes, Cn and Dn one. Note On with velocity 0 means Note Off.
In a file, F0 and F7 are followed by a VLQ byte length, then the payload; F7 carries escapes and continuations. Both cancel running status, same as meta events.
14 bytes. Example: format 1, 3 tracks, 480 ticks per quarter note.
The 16-bit timing field, expanded. Top bit chooses the scheme; here it is 0, so the rest is ticks per quarter note.
MIDI 2.0 does not extend the .mid file — that format is frozen at 1.0. It replaces the wire and the file with the Universal MIDI Packet: 1 to 4 big-endian 32-bit words whose top nibble, the Message Type, alone fixes the packet size. That makes a UMP stream self-delimiting — no length prefixes — so the same bytes parse whether they arrive from a file or a pipe. A MIDI Clip File (.midi2) is just an 8-byte SMF2CLIP magic then one of those streams. Hover to light bytes, click a + for its table.
Scope note, honestly: real .midi2 files are still rare (the spec is 2023, few producers). The format's home today is the live stream layer shipping in Windows MIDI Services, ALSA UMP and CoreMIDI — and because UMP is self-delimiting, the same grammar decodes off a file or a captured stream.
The top 4 bits of word 1. The MT alone fixes the packet size, so a reader stays synchronized even through message types it does not understand.
Example: group 1, channel 1, note 60 (middle C), velocity 0x8000, no attribute. Two 32-bit words, big-endian (Message Type 0x4).
No chunks. An 8-byte magic, then a big-endian UMP stream: a Configuration Header (mandatory DCTPQ, optional tempo / time signature / metadata) and the Clip Sequence, bracketed by Start and End of Clip. A Delta Clockstamp precedes essentially every message.