SysEx Continuation:

SysEx (System Exclusive) messages in MIDI can be continued across multiple
packets, often with the use of a continuation byte (0xF7). This is necessary
when the SysEx data exceeds the maximum length of a single MIDI message or
when there's a need to interleave other MIDI messages within a SysEx stream.
Here's a breakdown of how SysEx continuation works:

1. The Problem:

Standard MIDI messages have a limited length, and SysEx messages can be quite
long, especially when dealing with patch data or bulk dumps.  Sometimes, a
device might need to interrupt a large SysEx transfer with other MIDI
messages (like note ons or control changes).  2. The Solution: SysEx
Continuation (F7)

A SysEx message starts with the status byte 0xF0 (Start).  It's followed by
the manufacturer's ID, device ID, and the actual data.  The message ends with
0xF7 (End/Escape).  To send a long SysEx message, it's split into smaller
chunks.  Each chunk, except the last one, ends with 0xF7, indicating that
there is more data to follow.  The receiving device recognizes these 0xF7
bytes as continuation markers and knows to expect the next chunk. 

3. Interleaved Messages

When a device needs to send other MIDI messages (like note or control
changes) while a SysEx transfer is in progress, it can do so by sending the
regular MIDI messages, then resuming the SysEx stream with the 0xF7
continuation byte.  The receiver must be able to distinguish between the
continuation byte and the end-of-SysEx byte, as both are 0xF7. 

4. Escaped Events (F7 as Escape)

The 0xF7 byte can also be used as an "escape" character to embed other MIDI
messages (like realtime or common messages) within a SysEx stream.  In this
case, the 0xF7 byte is followed by a standard MIDI status byte (e.g., 0xF1,
0xF2), indicating an escaped message.  This allows for embedding commands for
other devices, or control messages for the same device, into a SysEx stream.
In essence, the 0xF7 byte acts as a signal for either continuing a SysEx
message or embedding other MIDI data within it, providing flexibility in how
SysEx messages are structured and transmitted. 

