OK, I have a few monutes, I’ll try to show off a bit..
0000: 4D 54 68 64 00 00 00 06 00 01 00 03 02 D0 4D 54 MThd…MT
0010: 72 6B 00 00 00 0B 00 FF 51 03 07 A1 20 00 FF 2F rk…Q… ../
0020: 00 4D 54 72 6B 00 00 00 33 00 B0 07 7F 00 C0 18 .MTrk…3…
0030: 00 B0 65 00 00 B0 64 00 00 B0 06 18 00 B1 07 7F ..e…d…
0040: 00 C1 18 00 B1 65 00 00 B1 64 00 00 B1 06 18 00 …e…d…
0050: 90 30 68 96 40 80 30 00 00 FF 2F 00 4D 54 72 6B .0h.@.0…/.MTrk
0060: 00 00 00 2A 00 B2 07 7F 00 C2 21 00 B2 65 00 00 …*…!..e..
0070: B2 64 00 00 B2 06 18 00 B3 07 7F 00 C3 21 00 B3 .d…!..
0080: 65 00 00 B3 64 00 00 B3 06 18 00 FF 2F 00 e…d…/.
OK. I have a few minutes, and the format should be fresh in my mind. Let’s see how much I remember.
MIDI files are divided into chunks. the two “official” chunk types are MThd at the head of the file and MTrk at the beginning of each track.
Your file starts with “MThd 00 00 00 06”, this is the header chunk, and always has a length of six, as shown. Following that are six bytes, representing three SHORT numbers. “00 01” is format 1 (multitrack), “00 03” is track count, three tracks should follow. “02 D0” is the divisor, indicating 720 “ticks” per quarter note.
Next is the first track. Like all tracks, it begins with the MTrk chunk header, followed by a LONG length. In this case, this first track has a length of “0B” (11) Following this will be a variable-length time delay, then a MIDI event, then time delay, then event et-cetera until the track is finished. In this case, delay 0, then Meta-Event
“FF 51 03 07 A1 20”, which is NOT a MIDI event, it just instructs the sequencer to set the tempo to “07 A1 20” microseconds per quarter-note. In this case, 07a120 is 500000, so we get a tempo of 120 BPM. Then we get another delay of zero, and “FF 2F 00” which marks the end of track.
On to the next track.. MTrk header, track length will be
33(51). Delay zero, then event “B0 07 7F” which is control change, channel 1 Volume to MAX. then delay 0, then “C0 18” which will send a program change, channel 1, to the 24th patch. delay zero again, then “B0 65 00” which will send Control Change, channel one, Portamento OFF. Then delay of zero again, and “B0 64 00” Control change, channel 1, Hold pedal OFF. then delay zero again, and “B0 06 18” setting channel 1 data entry slider(coarse) to 24.(why??)
The next groups, without any delays will send all the same to channel two. “00 B1 07 7F 00 C1 18 00 B1 65 00 00 B1 64 00 00 B1 06 18 00” Then we get on to “90 30 68” which sends NOTE ON, channel 1, the 48th note, velocity 104. Then we have “96 40” which is a delay of 2880 “midi ticks” (remember, all delay values may be variable-length) That should be one whole-note long unless I screwed up the math.(720 from the file header = 1 quarter-note, so 2880 is a whole note) Then comes an “80 30 00” which will turn the previous note on channel 1 OFF. then a delay of zero, and the “FF 2F 00” end of track marker.
On to the third track. (Ugh, getting tired!)
standard track header, track length will be 42 bytes. delay zero, “B2 07 7F” channel 3 volume max. “C2 21” channel 3 program change 33, “B2 65 00” channel 3 Portamento OFF, “B2 64 00” Channel 3 hold pedal OFF, “B2 06 18” Channel 3 Data slider (coarse) at 24. Then “B3 07 7F 00 C3 21 00 B3 65 00 00 B3 64 00 00 B3 06 18 00” does much the same for channel 4. Finally, FF 2F 00 ends the track.
There is a lot in this that is not needed to play a single note. It’s doing basic setup for channels 1-4. This is nice, but a lot more than you need.
Also, you can see that the length of a note is not encoded in the note-on message, but in the time that passes between the note-on and the note off.
Have Fun,.
LyleHaze
Interesting..
I wonder how many Format 1 MIDI files have multiple channels of data in a single track? I wonder how many players assume that all events in a single track are the same channel? I have at least one sequencer here that makes this mistake. Among other things, it puts the drums into the wrong channel for playback.
I learned something today! No wonder I’m so tired. 