Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Parsing SysEx events

This thread is locked; no one can reply to it. rss feed Print
Parsing SysEx events
raynebc
Member #11,908
May 2010

I'm trying to determine if my MIDI parsing engine needs to have its Sysex behavior changed. Several MIDI spec websites, including my favorite (http://www.sonicspot.com/guide/midifiles.html) and the Java documentation on Sysex (http://download.oracle.com/javase/1.4.2/docs/api/javax/sound/midi/SysexMessage.html), indicate that Sysex messages include a length for the message before the first data byte.

However, other websites, including whitepapers on the MIDI website (http://www.midi.org/techspecs/ca22.pdf) and various manufacturer documents (http://www.clavia.se/downloads/manuals/nord%20stage/Nord%20Stage%20Sysex%20Guide.pdf) indicate that Sysex messages do not include a length, and the message only ends when a 0xF7 (EOX, or End of Sysex) byte is reached.

My implementation assumes that the byte following the initial 0xF0 or 0xF7 status is the message's length stored as a variable length value. After checking Allegro's source, it appears Allegro's MIDI parser assumes the same. I haven't run into any MIDIs that ended up being misread by my parser due to this, but can anybody confirm for sure which Sysex definition is correct? Thank you in advance for any help you can provide.

Kitty Cat
Member #2,815
October 2002
avatar

MIDI files are different from the MIDI protocol. MIDI was designed as a communication protocol between devices, so that information can be passed quickly for real-time performance. MIDI files use a similar bytestream, but there are differences.

For MIDI, a sysex message ends with 0xF7. If it does not, then a following message (starting with 0xF7 instead of 0xF0) will come later to continue it. This is to split long messages up to get passed over time, instead of flooding with larger messages all at once. You'll get more messages like that until one ends with 0xF7.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

raynebc
Member #11,908
May 2010

Thank you for your reply. I'm referring to parsing MIDI files instead of handling a MIDI protocol stream. If MIDI files do not use a defined length before the start of the Sysex message data, then I believe Allegro's implementation may be incorrect, as it is the same as my implementation. Can you provide any further clarification on this matter?

Kitty Cat
Member #2,815
October 2002
avatar

MIDI files do provide the length of a sysex message. Or more precisely, a sysex message chunk. If a sysex message does not end with a 0xF7 byte, then a continuation will be provided later using 0xF7 instead of 0xF0 (which also specifies a length), and you'll get more continuations until one of them ends with a 0xF7 byte. These aren't separate messages, but a single message broken up into multiple chunks. Your first link mentions this under "Divided SysEx Events".

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

raynebc
Member #11,908
May 2010

Thank you very much! It looks like I can leave my parser's implementation as-is for now, as it just skips past Sysex events, effectively ignoring them.

Go to: