Can't read the midi file? [extended specification?]

I am trying to read a midi file in C ++, and I am stuck in an error that appears to be an event that is not defined in the standard midi specification (retrieved from many sites, including this: http://www.sonicspot.com/ guide / midifiles.html )

I opened midi in the HEX editor and indicated an error. This happens before the very first note on event. The file was generated using Sibelius 6 software, and I was wondering if I publish a section of the file, here someone will help me get around this.

This is the start of the third track:

4D 54 72 6B (MTrk magic number) 00 00 1F F5 (track size in bytes - 8181) 00 FF 03 04 (4 bytes follows) (track sequence name) 00 FF 04 0B (11 bytes follows) (instrument name) 00 C0 34 (program change event) 00 B0 79 00 (controller event) 00 5B <- (what the heck is that?!) 

It cannot be deltas, since the first value is 00 (there is no MSB set to 1), this is also an unrecognized event. After 10 bytes I recognize the event "note on" This goes:

00 5B 30 00 40 00 00 07 64 00 0A 10 00 90 3E 47 <- note on

I have no idea what these 12 bytes before "note on" represent and therefore cannot read the file. I know that the very first note is quite long, maybe the reason. I also noticed that I could not find an event to represent the pauses. Maybe this is the code for the bar + length? Should I read them like tics?

Thanks, any help would be appreciated.

+4
source share
1 answer

One difficulty MIDI files Launch Status . If the message sequence is of the same type and channel (for example, all controllers or all notes), then MIDI can store several bytes, omitting the status byte. If this did not use the current status, then the bytes you see are as follows:

 00 B0 79 00 - controller 121: controller reset 00 B0 5B 00 - controller 91: reverb 00 B0 40 00 - controller 64: sustain 00 B0 07 64 - controller 7: volume 00 B0 0A 10 - controller 10: pan 00 90 3E 47 - note message 

Since all controller messages are contiguous and intended for the same channel, the status byte may be omitted. As soon as the message type changes, the status byte must be added again.

If you are trying to understand MIDI files, I would recommend using a separate tool, such as Python-MIDI or GNMidi, as a means of verifying performance when there is a MIDI event that you cannot understand about. They can show it as text so you can imitate what it does.

EDIT: Another issue to keep in mind is that any MIDI messages that accept a length or duration parameter (for example, the time in the PPQN between events in a MIDI file or the length of messages for boobs or meta events) use a variable length therefore do not assume that all length fields are always fixed length.

Disclaimer: I wrote a MIDI export code in Sibelius 6 ...

+6
source

Source: https://habr.com/ru/post/1440143/


All Articles