MIDI files are made up of packets. Each packet has a type and a 32-bit length. The file type on the Macintosh for a file in this format is "Midi".
Programs ignore packets of unknown type. This permits the introduction of new types with out changing existing software. Typically, there are two types of packets: a Header packet and a Track Packet. A Header packet provides information about the MIDI file. Track Packets contain MIDI data. This data describes up to 16 channels. Track Packets are used to describe tracks, outputs, patterns, sequences, and songs.
A MIDI file always starts with a Header packet, and is followed by one or more Track Packets. The following MBNF may be extended with the introduction of new packet types:
1. <midi file> ::= <midi header> <packet data>
2. <midi header> ::= MThd <length of header data> <header data>
3. <header data> ::= <format> <ntrks> <division>
4. <packet data> ::= <Track Packet>
5. <Track Packet> ::= MTrk <length of track data> <track data> <midi data>
6. <track data> :: = <delta-time> <event>
7. <delta-time> := <variable length number>
8. <event> = <chan msg> | <sysex msg> | <meta-event>
9. <meta-event> ::= 255 <type> <length> <bytes>
10. <type> ::= 0..127
11. <length> ::= <variable length number>
12. <chan msg> ::= <chan 1byte msg> | <chan 2byte msg>
13. <chan 1byte msg> ::= <chan stat1 byte> <data singlet> <running singlets>
14. <chan 2byte msg> ::= <chan stat2 byte> <data pair> <running pairs>
15. <chan stat1 byte> ::= 192..223
16. <chan stat2 byte> ::= 128..191 | 224..239
17. <data pair> ::= <data singlet> <data singlet>
18. <data singlet> ::= <realtime byte> <data singlet> | <data byte>
19. <running pairs> ::= <empty> | <data pair> <running pairs>
20. <running singlets> ::= <empty> | <data singlet> <running singlets>
21. <data byte> ::= 0..127
22. <realtime byte> ::= 248 | 250 | 251 | 252 | 254 | 255
23. <sys msg> ::= <sys common msg> | <sysex msg> | <sys realtime msg>
24. <sys realtime msg> ::= <realtime byte>
25. <sysex msg> ::= 240 <data singlet> <running singlets> 247
26. <sys common msg> ::= <Song Position msg> | <Song Select msg> | 246
27. <Tune Request> ::= 246
28. <Song Position msg> ::= 242 <data pair>
29. <Song Select msg> ::= 243 <data singlet>
Delta-time specifies the time before the following event. Delta-time is in fractions of a beat, or of a second as specified in the Header packet.
Meta-event specifies non-MIDI information useful to this format or to sequencers. As with SysEx events, running status is not allowed. New meta-events may be added.
[ Index | Main Paragraph | Next Paragraph ]