How a MIDI file is built
A Standard MIDI File is a list of chunks. Each starts with a four-letter id and its length. The first, MThd, is the header: the file format, the number of tracks and how many ticks make a quarter note. Then come the tracks, each an MTrk chunk.
A track is a list of events. Every event has two parts:
- Delta time: how many ticks after the previous event it happens.
- The event: a channel message like Note on (
9n) or Control change (Bn), a meta event (FF) with things like tempo, track names and lyrics, or a SysEx message (F0) for one maker's devices.
Every track ends with an End of track meta event, FF 2F 00. The demo file shows all of this in a few hundred bytes.
Questions
Is my file uploaded anywhere?
No. The file is read by your browser and never leaves your computer.
What is a delta time?
Every event in a MIDI file starts with the time since the previous event, in ticks. It is stored as a variable-length number: each byte carries 7 bits, and the top bit says whether another byte follows. Small gaps take one byte, long ones up to four.
What is running status?
If an event has the same status byte as the one before it (for example, another Note on on the same channel), the status byte can be left out. It saves space, which is why many files write note offs as Note on with velocity 0. The inspector marks events that use it with "rs".
What is the difference between format 0, 1 and 2?
Format 0 puts everything in one track. Format 1 has several tracks that play together, usually one per instrument, with tempo and time signature in the first. Format 2, which is rare, holds independent patterns.
What does a tick mean?
The header says how many ticks make a quarter note (often 480 or 960). Tempo events then say how long a quarter note lasts, which turns ticks into seconds.
My file won't play correctly. Can this help?
Yes. The inspector lists problems it finds: wrong chunk lengths, missing End of track, damaged events, notes that never stop, running status in the wrong place and more, with the byte position of each.