Skip to content

Commit 6351751

Browse files
author
Francois Best
committed
Fixed 1byte running status bug (GitHub issue #12)
1 parent e3dd227 commit 6351751

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/MIDI.hpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,11 @@ bool MidiInterface<SerialPort>::parse()
547547
// Else: well, we received another status byte,
548548
// so the running status does not apply here.
549549
// It will be updated upon completion of this message.
550-
551-
if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1))
552-
{
553-
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
554-
mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
555-
mMessage.data1 = mPendingMessage[1];
556-
557-
// Save data2 only if applicable
558-
if (mPendingMessageExpectedLenght == 3)
559-
mMessage.data2 = mPendingMessage[2];
560-
else
561-
mMessage.data2 = 0;
562-
563-
mPendingMessageIndex = 0;
564-
mPendingMessageExpectedLenght = 0;
565-
mMessage.valid = true;
566-
return true;
567-
}
568550
}
569551

570552
switch (getTypeFromStatusByte(mPendingMessage[0]))
571553
{
572-
// 1 byte messages
554+
// 1 byte messages
573555
case Start:
574556
case Continue:
575557
case Stop:
@@ -629,17 +611,38 @@ bool MidiInterface<SerialPort>::parse()
629611
break;
630612
}
631613

632-
// Then update the index of the pending message.
633-
mPendingMessageIndex++;
614+
if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1))
615+
{
616+
// Reception complete
617+
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
618+
mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
619+
mMessage.data1 = mPendingMessage[1];
634620

635-
#if USE_1BYTE_PARSING
621+
// Save data2 only if applicable
622+
if (mPendingMessageExpectedLenght == 3)
623+
mMessage.data2 = mPendingMessage[2];
624+
else
625+
mMessage.data2 = 0;
626+
627+
mPendingMessageIndex = 0;
628+
mPendingMessageExpectedLenght = 0;
629+
mMessage.valid = true;
630+
return true;
631+
}
632+
else
633+
{
634+
// Waiting for more data
635+
mPendingMessageIndex++;
636+
}
637+
638+
#if USE_1BYTE_PARSING
636639
// Message is not complete.
637640
return false;
638-
#else
641+
#else
639642
// Call the parser recursively
640643
// to parse the rest of the message.
641644
return parse();
642-
#endif
645+
#endif
643646

644647
}
645648
else

0 commit comments

Comments
 (0)