Midi list header & midi list - JoueBien/rtp-midi-transport GitHub Wiki
A short breakdown of how Midi is encoded with in an RTP message (After the header). For further reading see RFC 6295 3.2
Midi List Header & Midi List
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|B|J|Z|P|LEN... | MIDI list ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| B | and | LEN |
B denotes how large entire header is.
When B is set 0 the header size is 8 bits long. In this mode LEN is 4 bits long & the MIDI List can be up to 15 bytes long.
When B is set 1 the header size is 16 bits long. In this mode LEN is 12 bits long & the MIDI List can be up to 4095 bytes long.
LEN denotes how long the Midi List is in bytes. LEN can be either 4 bits or 12 bits long depending on the state of B.
| J |
J denotes if a journal should be included.
When J is set to 1 there must be a Journal after each Midi command in the MIDI List.
When J is set to 0 the it means that there should be no Journal in the MIDI List section.
| Z |
Z denotes if the midi list includes 4 byte timestamps before each Midi command in the MIDI List.
If Z is 1 then timestamps proceed each Midi command.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Delta Time 0 (1-4 octets long, or 0 octets if Z = 0) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command 0 (1 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Delta Time 1 (1-4 octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command 1 (1 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Delta Time N (1-4 octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command N (0 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
If Z is 0 then there are no timestamps in the MIDI List section.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command 0 (1 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command 1 (1 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MIDI Command N (0 or more octets long) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| P |
TLDR use 0. You'll only need to consider using 1 if you are re-encoding Midi data that was originally transported over 5 Pin DIN or 1/4 inch jacks.
The short long version:
P denotes if the source used to generate the Midi List used the first status byte for all subsequent Midi commands. When P is set to 1 it denotes this original encoding. When set to 0 every Midi command in the source data included a status byte.
The P bit describes the MIDI source data stream, not the MIDI RTP list encoding; regardless of the state of the P bit, the MIDI list MUST include the status octet.
For further reading see the oping paragraphs of section 3.2
Midi List - Repeat Commands
A command status can be repeated without being specified. When a data value is in a place a status value should be the previous status should be used. A command status always starts with a 1 bit where as a data value always starts with a 0 bit. This difference allows us to detect the difference between a status byte and data value byte
90 3C 64 | 3E 64 | 40 46
| | | | | | |
| Data Data Data
Status
When this mode is encoded into RTP MIDI the status byte is added before each data set.
90 3C 64 | 90 3E 64 | 90 40 46
| | | | | | | | |
| Data | Data | Data
Status Status Status