From 0d596066b44bc67729c221e1535b66bef217b3fe Mon Sep 17 00:00:00 2001 From: lathoub Date: Mon, 10 Feb 2020 15:04:45 +0100 Subject: [PATCH] added support for receiving SysEx command segments Very long SysEx mesaages are cut in to multiple command segments Where a normal SysEx starts with F0 and ends with F7, the first segment will start with F0 and end with F0, the middle section (optional) start with F7 and ends with F7 - the last segments starts with F7 and ends with F0 --- src/MIDI.hpp | 16 ++++++++++------ src/midi_Defs.h | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 76a4fb8..fe4afa2 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -795,12 +795,13 @@ bool MidiInterface::parse() mPendingMessageExpectedLenght = 3; break; - case SystemExclusive: + case SystemExclusiveStart: + case SystemExclusiveEnd: // The message can be any lenght // between 3 and MidiMessage::sSysExMaxSize bytes mPendingMessageExpectedLenght = MidiMessage::sSysExMaxSize; mRunningStatus_RX = InvalidType; - mMessage.sysexArray[0] = SystemExclusive; + mMessage.sysexArray[0] = pendingType; break; case InvalidType: @@ -873,11 +874,13 @@ bool MidiInterface::parse() return true; // End of Exclusive - case 0xf7: - if (mMessage.sysexArray[0] == SystemExclusive) + case SystemExclusiveStart: + case SystemExclusiveEnd: + if ((mMessage.sysexArray[0] == SystemExclusiveStart) + || (mMessage.sysexArray[0] == SystemExclusiveEnd)) { // Store the last byte (EOX) - mMessage.sysexArray[mPendingMessageIndex++] = 0xf7; + mMessage.sysexArray[mPendingMessageIndex++] = extracted; mMessage.type = SystemExclusive; // Get length @@ -902,7 +905,8 @@ bool MidiInterface::parse() } // Add extracted data byte to pending message - if (mPendingMessage[0] == SystemExclusive) + if ((mPendingMessage[0] == SystemExclusiveStart) + || (mPendingMessage[0] == SystemExclusiveEnd)) mMessage.sysexArray[mPendingMessageIndex] = extracted; else mPendingMessage[mPendingMessageIndex] = extracted; diff --git a/src/midi_Defs.h b/src/midi_Defs.h index 786da70..5f43098 100644 --- a/src/midi_Defs.h +++ b/src/midi_Defs.h @@ -73,10 +73,12 @@ enum MidiType: uint8_t AfterTouchChannel = 0xD0, ///< Channel (monophonic) AfterTouch PitchBend = 0xE0, ///< Pitch Bend SystemExclusive = 0xF0, ///< System Exclusive + SystemExclusiveStart = SystemExclusive, ///< System Exclusive Start TimeCodeQuarterFrame = 0xF1, ///< System Common - MIDI Time Code Quarter Frame SongPosition = 0xF2, ///< System Common - Song Position Pointer SongSelect = 0xF3, ///< System Common - Song Select TuneRequest = 0xF6, ///< System Common - Tune Request + SystemExclusiveEnd = 0xF7, ///< System Exclusive End Clock = 0xF8, ///< System Real Time - Timing Clock Start = 0xFA, ///< System Real Time - Start Continue = 0xFB, ///< System Real Time - Continue