From 14a5fcf410da7d9db4af2cb0635da40ed2bdd2e2 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 6 Mar 2014 16:02:09 +0000 Subject: [PATCH] Attempt at better recovery from malformed sysex messages in a midi stream. --- .../native/juce_MidiDataConcatenator.h | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_MidiDataConcatenator.h b/modules/juce_audio_devices/native/juce_MidiDataConcatenator.h index 435e30c4b2..4dc70b9bb7 100644 --- a/modules/juce_audio_devices/native/juce_MidiDataConcatenator.h +++ b/modules/juce_audio_devices/native/juce_MidiDataConcatenator.h @@ -123,6 +123,14 @@ private: { if (pendingBytes > 0 && *d >= 0x80) { + if (*d == 0xf7) + { + *dest++ = *d++; + ++pendingBytes; + --numBytes; + break; + } + if (*d >= 0xfa || *d == 0xf8) { callback.handleIncomingMidiMessage (input, MidiMessage (*d, time)); @@ -131,11 +139,15 @@ private: } else { - if (*d == 0xf7) + pendingBytes = 0; + int used = 0; + const MidiMessage m (d, numBytes, used, 0, time); + + if (used > 0) { - *dest++ = *d++; - pendingBytes++; - --numBytes; + callback.handleIncomingMidiMessage (input, m); + numBytes -= used; + d += used; } break; @@ -144,7 +156,7 @@ private: else { *dest++ = *d++; - pendingBytes++; + ++pendingBytes; --numBytes; } }