-
Notifications
You must be signed in to change notification settings - Fork 270
Description
Hello,
Been having an issue that when hot swapping out TRS Midi input cables it would occasionally cause the MIDI library to freeze or become unresponsive.
It seems that hot swapping TRS cables can occasionally cause garbled or incorrect Midi data to be produced when plugging in or unplugging the cable (I'm sure DIN cables can do this to, on rare occasion, but it seems more common on TRS cables due to how they physically connect).
I've done some basic tests, but the problem seems to be that hot swapping out a TRS connector on a Midi input, can on occasion, create a "phantom" SysEx Start, or a SysEx Stop byte (also seems to be more common when there is already MIDI data being transmitted when plugging in the TRS connector). This will then seem to lock up the MIDI library causing it not to respond to regular Midi channel messages (as it thinks it's in the middle of receiving a SysEx message).
When a SysEx Start byte is received in error, there doesn't seem to be any recovery mechanism in place for when another Channel Status Byte is subsequently received, which seems to cause this issue.
I added this code snippet between lines 1035 & 1036 of MIDI.hpp (which happens when the "extracted byte" is a channel Status byte), and it does seem to help:
// If a Channel Status byte is received after a SysEx Start byte
if ((mPendingMessage[0] == SystemExclusiveStart)
|| (mPendingMessage[0] == SystemExclusiveEnd))
{
// Something has gone wrong... Lets reset
resetInput();
return false;
}
I'm a bit of a n00b at all this, so what I've done may not be suitable, or completely off, but it does seem to help (although I've not actually tested this with SysEx messages). Anyway thanks for everyone's work on this.