10 if (status >= 0xF1 && status <= 0xF6)
12 switch (status & 0xF0) {
111 if (
length < 2 || (data[0] & 0x80) == 0) {
112 for (
size_t i = 0; i <
length; i++)
119 bool expect_timestamp =
true;
120 for (
size_t i = 1; i <
length; i++) {
121 const uint8_t
byte = data[i];
122 if ((
byte & 0x80) == 0) {
129 expect_timestamp =
true;
132 if (expect_timestamp) {
133 expect_timestamp =
false;
136 expect_timestamp =
true;
148 if (
byte == STATUS_SYSEX_END) {
160 if (
byte == STATUS_SYSEX_START) {
179 const size_t skip_start = payload[0] == STATUS_SYSEX_START ? 1 : 0;
180 const size_t skip_end = payload[
length - 1] == STATUS_SYSEX_END ? 1 : 0;
181 const size_t body =
length - skip_start - skip_end;
183 const size_t framed = body + 3;
184 if (framed > out_size)
187 for (
size_t i = 0; i < body; i++) {
188 if (payload[skip_start + i] & 0x80)
191 out[0] = STATUS_SYSEX_START;
192 std::memcpy(
out + 1, payload + skip_start, body);
193 out[body + 1] = PACKET_TIMESTAMP;
194 out[body + 2] = STATUS_SYSEX_END;
void take_data_(const uint8_t *byte, MidiMessageHandler handler, void *ctx)
uint8_t current_message_[3]
void feed(const uint8_t *data, size_t length, MidiMessageHandler handler, void *ctx)
Feed one BLE notification payload.
void emit_current_(MidiMessageHandler handler, void *ctx)
static uint8_t expected_data_bytes(uint8_t status)
Number of data bytes that follow a status byte other than SysEx.
uint8_t current_expected_
void emit_(MessageType type, const uint8_t *data, uint16_t length, MidiMessageHandler handler, void *ctx)
void sysex_push_(uint8_t byte)
const uint16_t sysex_capacity_
uint8_t *const sysex_buffer_
void reset()
Drop all parser state.
void end_sysex_(bool complete, MidiMessageHandler handler, void *ctx)
std::vector< uint8_t > & out
size_t frame_sysex(const uint8_t *payload, size_t length, uint8_t *out, size_t out_size)
Frame a SysEx payload for one BLE-MIDI packet: 0xF0 and 0xF7 are added when the payload lacks them,...
void(*)(void *ctx, const MidiMessage &message) MidiMessageHandler
Called once per decoded message with the context passed to feed().