Skip to content

Commit 70ff978

Browse files
author
Francois Best
committed
2 parents 1813094 + 6351751 commit 70ff978

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
@@ -545,29 +545,11 @@ bool MidiInterface<SerialPort>::parse()
545545
// Else: well, we received another status byte,
546546
// so the running status does not apply here.
547547
// It will be updated upon completion of this message.
548-
549-
if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1))
550-
{
551-
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
552-
mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
553-
mMessage.data1 = mPendingMessage[1];
554-
555-
// Save data2 only if applicable
556-
if (mPendingMessageExpectedLenght == 3)
557-
mMessage.data2 = mPendingMessage[2];
558-
else
559-
mMessage.data2 = 0;
560-
561-
mPendingMessageIndex = 0;
562-
mPendingMessageExpectedLenght = 0;
563-
mMessage.valid = true;
564-
return true;
565-
}
566548
}
567549

568550
switch (getTypeFromStatusByte(mPendingMessage[0]))
569551
{
570-
// 1 byte messages
552+
// 1 byte messages
571553
case Start:
572554
case Continue:
573555
case Stop:
@@ -627,17 +609,38 @@ bool MidiInterface<SerialPort>::parse()
627609
break;
628610
}
629611

630-
// Then update the index of the pending message.
631-
mPendingMessageIndex++;
612+
if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1))
613+
{
614+
// Reception complete
615+
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
616+
mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
617+
mMessage.data1 = mPendingMessage[1];
632618

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

642645
}
643646
else

0 commit comments

Comments
 (0)