Repository navigation
Description
Here's a CoreMIDI one that has two unfortunate effects at once. The MIDI spec allows the single-byte system real-time messages — F8 (clock), FA (start), FC (stop), and friends — to appear literally anywhere in the stream, including right in the middle of a SysEx. A receiver is supposed to act on that real-time byte immediately and then carry on with the SysEx as if the byte hadn't been there. On CoreMIDI in minimidio today, a real-time byte that lands mid-SysEx gets pulled into the SysEx instead.
What's happening
The CoreMIDI read loop handles real-time bytes correctly when they're at the top level — there's a nice if (s >= 0xF8) block for that (around minimidio.h:731–:743). But once it sees an F0 and starts scanning a SysEx, the scan just runs forward until it hits F7, without checking for real-time bytes along the way:
if (s == 0xF0) {
size_t start = j;
while (j < pkt->length && pkt->data[j] != 0xF7) j++; /* :748 */
if (j < pkt->length) j++;
msg.type = MM_SYSEX; msg.sysex = &pkt->data[start];
msg.sysex_size = j - start; /* :751 */
dev->callback(dev, &msg, dev->userdata); continue;
}So if an F8 clock byte shows up between the F0 and the F7, two things go wrong:
- The clock is lost — it never gets delivered as a real-time message, so anything trying to stay in sync with incoming MIDI clock misses a tick.
- The SysEx is corrupted — that
F8is now sitting inside the payload bytes handed to the consumer, so the SysEx they receive isn't the one that was sent.
The second part is the trickier one — it's not just "a byte got dropped," it's "the data got poisoned."
How to see it
On CoreMIDI, send a SysEx with an F8 injected partway through, e.g. F0 7E 00 … F8 … F7. Then check two things:
- Did an
MM_CLOCKget delivered? (for us: no.) - Does the
MM_SYSEXpayload contain a stray0xF8? (for us: yes.)
Neither of those is what you'd want.
A possible fix
Inside the SysEx scan, you could watch for bytes >= 0xF8: when you hit one, deliver it immediately as its own real-time message and skip it from the SysEx accumulation, then keep scanning for the F7. That gives you both the clock tick and a clean SysEx. This matters most for anyone slaving to MIDI clock while also receiving SysEx, but the corruption angle affects any SysEx that happens to share the stream with real-time traffic.
Nice bonus: this is exactly the inbound-framing behavior the raw-bytes API is going to propose separately ... we're going to need anyway, so if you go that route, fixing this and implementing raw SysEx framing on CoreMIDI are essentially the same change :-)
Activity
maxcomperatore commentedon Sep 13, 2026
This is a classic MIDI 1.0 streaming bug that is very frequently overlooked.
According to the MIDI 1.0 Detailed Specification, System Real-Time messages (
0xF8Timing Clock,0xFAStart,0xFBContinue,0xFCStop,0xFEActive Sensing) are single-byte messages that may be inserted at any point in the data stream, including between the0xF0status byte and0xF7EOX of a System Exclusive message.To correctly parse the stream without corrupting the SysEx payload or losing clock sync:
0xF0toward0xF7, every byte must be inspected forbyte >= 0xF8.>= 0xF8) is encountered, emit the real-time event immediately via the callback, but omit that byte from the SysEx buffer slice.Handling interleaved real-time clock bytes during large patch transfers was one of the key requirements we had to solve when developing bipluk.com.