sysex.h
SysexAssembler: one complete message out of however many pieces arrive.
#include <sonore/sysex.h>- 1type
- Guides: MIDI and MPE
On this page
Design notes
Why reassembly is needed at all
A System Exclusive message has no length field. It starts with 0xF0 and runs until 0xF7, and everything in between is data bytes with the top bit clear. How it reaches a program depends entirely on the transport:
- A serial MIDI stream delivers it a byte at a time, and REALTIME bytes may appear in the middle of it. A clock byte between two data bytes is legal MIDI, and a reassembler that treats it as data corrupts the message.
- Windows multimedia hands over a buffer at a time and will split a long message across several, flagged with MHDR_DONE only at the end.
- CoreMIDI and ALSA deliver packets that may contain a fragment, several whole messages, or a fragment of one and the start of another.
So every backend has the same job and, left to itself, would grow its own copy of it. This project has now found the same rule diverging across wrappers three times -- the LV2 turtle validator, the MIDI status filter, the denormal guard -- so the rule is written once here.
What it refuses to do
It never emits a partial message. A SysEx cut short is not a shorter message, it is a different one: the manufacturer id still parses, the message type still parses, and the payload is simply wrong. Silence is recoverable; a plausible wrong answer is not.
Types 1
Feed it bytes; it hands back complete messages.
Fixed capacity and no allocation, because the serial backends run this on their own reader thread and the packet backends run it on a callback that must not block.