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.
Seven payload bits per byte; the high bit set means another byte follows. A parser that loses sync here misreads everything after it. acidcat's running-status bookkeeping is exactly where a one-byte desync once corrupted note counts.
Consecutive channel events with the same status may drop the repeated status byte; the parser must remember the last one. Every mainstream DAW exports this way.
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.