I found the problem: meta-event codes (in my case 0x51
) are proceeded by a chunk size just like normal events. The reason I thought otherwise is because, for the set tempo meta-event, the tempo data size is always 3. Therefore 51 03 05 7B 71
is actually the set tempo event code (51
), the size of the tempo data (03
) then the actual tempo (05 7B 71
), and then the 00
is just another variable-length value telling me that the next event is at time 0.
I hope this helps someone. I also found a better piece of documentation for the MIDI format which made this clearer: http://www.omega-art.com/midi/mfiles.html