Fixed bugs on SysEx reception.

This commit is contained in:
Francois Best 2012-10-08 22:12:42 +02:00
parent b7e23f6d0e
commit 5a55f715da
2 changed files with 17 additions and 15 deletions

View File

@ -189,7 +189,7 @@ struct Message
\n Array length is stocked on 16 bits, \n Array length is stocked on 16 bits,
in data1 (LSB) and data2 (MSB) 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. /*! This boolean indicates if the message is valid or not.
There is no channel consideration here, There is no channel consideration here,

View File

@ -560,7 +560,6 @@ bool MidiInterface<SerialPort>::parse(Channel inChannel)
break; break;
} }
switch (getTypeFromStatusByte(mPendingMessage[0])) switch (getTypeFromStatusByte(mPendingMessage[0]))
{ {
// 1 byte messages // 1 byte messages
@ -612,6 +611,7 @@ bool MidiInterface<SerialPort>::parse(Channel inChannel)
// between 3 and MIDI_SYSEX_ARRAY_SIZE bytes // between 3 and MIDI_SYSEX_ARRAY_SIZE bytes
mPendingMessageExpectedLenght = MIDI_SYSEX_ARRAY_SIZE; mPendingMessageExpectedLenght = MIDI_SYSEX_ARRAY_SIZE;
mRunningStatus_RX = InvalidType; mRunningStatus_RX = InvalidType;
mMessage.sysexArray[0] = SystemExclusive;
break; break;
case InvalidType: case InvalidType:
@ -669,17 +669,16 @@ bool MidiInterface<SerialPort>::parse(Channel inChannel)
// End of Exclusive // End of Exclusive
case 0xF7: case 0xF7:
if (getTypeFromStatusByte(mPendingMessage[0]) == SystemExclusive) if (mMessage.sysexArray[0] == SystemExclusive)
{ {
// Store System Exclusive array in midimsg structure // Store the last byte (EOX)
for (byte i=0;i<MIDI_SYSEX_ARRAY_SIZE;i++) mMessage.sysexArray[mPendingMessageIndex++] = 0xF7;
mMessage.sysex_array[i] = mPendingMessage[i];
mMessage.type = SystemExclusive; mMessage.type = SystemExclusive;
// Get length // Get length
mMessage.data1 = (mPendingMessageIndex+1) & 0xFF; mMessage.data1 = mPendingMessageIndex & 0xFF;
mMessage.data2 = (mPendingMessageIndex+1) >> 8; mMessage.data2 = mPendingMessageIndex >> 8;
mMessage.channel = 0; mMessage.channel = 0;
mMessage.valid = true; mMessage.valid = true;
@ -700,6 +699,9 @@ bool MidiInterface<SerialPort>::parse(Channel inChannel)
} }
// Add extracted data byte to pending message // Add extracted data byte to pending message
if (mPendingMessage[0] == SystemExclusive)
mMessage.sysexArray[mPendingMessageIndex] = extracted;
else
mPendingMessage[mPendingMessageIndex] = extracted; mPendingMessage[mPendingMessageIndex] = extracted;
// Now we are going to check if we have reached the end of the message // Now we are going to check if we have reached the end of the message
@ -708,7 +710,7 @@ bool MidiInterface<SerialPort>::parse(Channel inChannel)
// "FML" case: fall down here with an overflown SysEx.. // "FML" case: fall down here with an overflown SysEx..
// This means we received the last possible data byte that can fit // This means we received the last possible data byte that can fit
// the buffer. If this happens, try increasing MIDI_SYSEX_ARRAY_SIZE. // the buffer. If this happens, try increasing MIDI_SYSEX_ARRAY_SIZE.
if (getTypeFromStatusByte(mPendingMessage[0]) == SystemExclusive) if (mPendingMessage[0] == SystemExclusive)
{ {
resetInput(); resetInput();
return false; return false;
@ -858,7 +860,7 @@ DataByte MidiInterface<SerialPort>::getData2() const
template<class SerialPort> template<class SerialPort>
const byte* MidiInterface<SerialPort>::getSysExArray() const const byte* MidiInterface<SerialPort>::getSysExArray() const
{ {
return mMessage.sysex_array; return mMessage.sysexArray;
} }
/*! \brief Get the lenght of the System Exclusive array. /*! \brief Get the lenght of the System Exclusive array.
@ -1005,7 +1007,7 @@ void MidiInterface<SerialPort>::launchCallback()
case AfterTouchChannel: if (mAfterTouchChannelCallback != 0) mAfterTouchChannelCallback(mMessage.channel,mMessage.data1); break; case AfterTouchChannel: if (mAfterTouchChannelCallback != 0) mAfterTouchChannelCallback(mMessage.channel,mMessage.data1); break;
case ProgramChange: if (mProgramChangeCallback != 0) mProgramChangeCallback(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 // Occasional messages
case TimeCodeQuarterFrame: if (mTimeCodeQuarterFrameCallback != 0) mTimeCodeQuarterFrameCallback(mMessage.data1); break; case TimeCodeQuarterFrame: if (mTimeCodeQuarterFrameCallback != 0) mTimeCodeQuarterFrameCallback(mMessage.data1); break;
@ -1164,7 +1166,7 @@ void MidiInterface<SerialPort>::thruFilter(Channel inChannel)
case SystemExclusive: case SystemExclusive:
// Send SysEx (0xF0 and 0xF7 are included in the buffer) // Send SysEx (0xF0 and 0xF7 are included in the buffer)
sendSysEx(mMessage.data1,mMessage.sysex_array,true); sendSysEx(mMessage.data1,mMessage.sysexArray,true);
return; return;
break; break;