MP3 to MIDI: Three Meta Events That Carry a Number, Not a Note

A Standard MIDI File defines fifteen meta events. Seven carry text and eight carry numbers, and three of those eight are nothing but addresses: which sequence, which channel, which manufacturer. None of the three states a pitch, a velocity or a time, and none is required. A converter can leave all three out and the file plays the same notes.

Short answer

  • Three addresses, no instructions. Sequence Number names a sequence, Channel Prefix names a channel, Sequencer Specific names a vendor.
  • Two fixed lengths, one variable. FF 00 02 always carries two bytes, FF 20 01 exactly one, FF 7F a counted blob.
  • The prefix expires. A Channel Prefix stops applying at the next message that carries a channel of its own, so it has to be re-sent.
  • All three are droppable. End of Track is the only meta event the specification calls not optional.

The frame all three share

Every meta event opens with FF, a type byte below 128, a length stored as a variable-length quantity, then data. A reader that does not recognise a type must ignore the event but must never ignore its length: it steps over exactly as many bytes as the length states. That rule lets a reader skip a type it does not know.

FF 00 02: two bytes that are never named

Sequence Number carries exactly two bytes: 65,536 values. The syntax line gives the length and the label and nothing else. Tempo is written tttttt and key signature sf mi; this one names neither byte, so their order is not stated on that line either. Position is constrained instead: the beginning of a track, before any nonzero delta-time, before any transmittable event, and at time zero. In a format 2 file, one or more sequentially independent single-track patterns, it identifies each pattern, and a Cue message can refer to one by that number. Omit it and the sequences' positions become the default identifiers.

FF 20 01: one byte for everything without a channel

Channel Prefix carries one byte, 0 to 15: the sixteen values a channel message's low nibble can hold. Its scope is unusual: it covers all events that follow, including System exclusive and meta-events, until the next normal MIDI event or the next Channel Prefix. That makes it the only way in the format to attach a channel to data that has no channel field. A sysex has none, a text event has none; a prefix ahead of them supplies one. Because the scope ends at the next channel message, it cannot be declared once per track; it must be re-sent after every run of notes.

FF 7F: a count and a manufacturer

Sequencer Specific is the only meta event whose payload is neither text nor a fixed-width number. Its first byte is a manufacturer ID, or its first three bytes when the first is 00, and the rest is whatever that manufacturer defined. The specification asks anyone who defines one to publish it, and suggests private formats stay close to the standard features. The event is a namespace rather than a value: the same bytes mean different things under different IDs.

What a converted file loses

Nothing in the format requires any of the three. The section that defines them says every program need not support every meta-event; End of Track is the exception, and carries no data. A transcriber writing one sequence and one track per instrument has no use for them. What disappears is not sound. It is the ability to say which of several patterns a file holds, which channel a stray sysex belongs to, and whose convention a private block follows. A MIDI file is a timeline of note events, and these three sit outside that timeline: they describe the container, not the performance.

Related