From 5a55f715da949c65ecd423c6eaf03008061775f4 Mon Sep 17 00:00:00 2001 From: Francois Best Date: Mon, 8 Oct 2012 22:12:42 +0200 Subject: [PATCH] Fixed bugs on SysEx reception. --- src/midi_Defs.h | 2 +- src/midi_Inline.hpp | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/midi_Defs.h b/src/midi_Defs.h index fc9d740..ed782ed 100644 --- a/src/midi_Defs.h +++ b/src/midi_Defs.h @@ -189,7 +189,7 @@ struct Message \n Array length is stocked on 16 bits, in data1 (LSB) and data2 (MSB) */ - DataByte sysex_array[MIDI_SYSEX_ARRAY_SIZE]; + DataByte sysexArray[MIDI_SYSEX_ARRAY_SIZE]; /*! This boolean indicates if the message is valid or not. There is no channel consideration here, diff --git a/src/midi_Inline.hpp b/src/midi_Inline.hpp index 97575c1..de8bfe0 100644 --- a/src/midi_Inline.hpp +++ b/src/midi_Inline.hpp @@ -301,14 +301,14 @@ void MidiInterface::sendSysEx(unsigned int inLength, { mSerial.write(0xF0); - for (unsigned int i=0;i::parse(Channel inChannel) break; } - switch (getTypeFromStatusByte(mPendingMessage[0])) { // 1 byte messages @@ -612,6 +611,7 @@ bool MidiInterface::parse(Channel inChannel) // between 3 and MIDI_SYSEX_ARRAY_SIZE bytes mPendingMessageExpectedLenght = MIDI_SYSEX_ARRAY_SIZE; mRunningStatus_RX = InvalidType; + mMessage.sysexArray[0] = SystemExclusive; break; case InvalidType: @@ -669,17 +669,16 @@ bool MidiInterface::parse(Channel inChannel) // End of Exclusive case 0xF7: - if (getTypeFromStatusByte(mPendingMessage[0]) == SystemExclusive) + if (mMessage.sysexArray[0] == SystemExclusive) { - // Store System Exclusive array in midimsg structure - for (byte i=0;i> 8; + mMessage.data1 = mPendingMessageIndex & 0xFF; + mMessage.data2 = mPendingMessageIndex >> 8; mMessage.channel = 0; mMessage.valid = true; @@ -700,7 +699,10 @@ bool MidiInterface::parse(Channel inChannel) } // Add extracted data byte to pending message - mPendingMessage[mPendingMessageIndex] = extracted; + if (mPendingMessage[0] == SystemExclusive) + mMessage.sysexArray[mPendingMessageIndex] = extracted; + else + mPendingMessage[mPendingMessageIndex] = extracted; // Now we are going to check if we have reached the end of the message if (mPendingMessageIndex >= (mPendingMessageExpectedLenght-1)) @@ -708,7 +710,7 @@ bool MidiInterface::parse(Channel inChannel) // "FML" case: fall down here with an overflown SysEx.. // This means we received the last possible data byte that can fit // the buffer. If this happens, try increasing MIDI_SYSEX_ARRAY_SIZE. - if (getTypeFromStatusByte(mPendingMessage[0]) == SystemExclusive) + if (mPendingMessage[0] == SystemExclusive) { resetInput(); return false; @@ -858,7 +860,7 @@ DataByte MidiInterface::getData2() const template const byte* MidiInterface::getSysExArray() const { - return mMessage.sysex_array; + return mMessage.sysexArray; } /*! \brief Get the lenght of the System Exclusive array. @@ -1005,7 +1007,7 @@ void MidiInterface::launchCallback() case AfterTouchChannel: if (mAfterTouchChannelCallback != 0) mAfterTouchChannelCallback(mMessage.channel,mMessage.data1); break; case ProgramChange: if (mProgramChangeCallback != 0) mProgramChangeCallback(mMessage.channel,mMessage.data1); break; - case SystemExclusive: if (mSystemExclusiveCallback != 0) mSystemExclusiveCallback(mMessage.sysex_array,mMessage.data1); break; + case SystemExclusive: if (mSystemExclusiveCallback != 0) mSystemExclusiveCallback(mMessage.sysexArray,mMessage.data1); break; // Occasional messages case TimeCodeQuarterFrame: if (mTimeCodeQuarterFrameCallback != 0) mTimeCodeQuarterFrameCallback(mMessage.data1); break; @@ -1164,7 +1166,7 @@ void MidiInterface::thruFilter(Channel inChannel) case SystemExclusive: // Send SysEx (0xF0 and 0xF7 are included in the buffer) - sendSysEx(mMessage.data1,mMessage.sysex_array,true); + sendSysEx(mMessage.data1,mMessage.sysexArray,true); return; break;