Parse function reworked to better deal with SysEx #368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A reworking of the parse function to deal with SysEx start & stop bytes as per the Midi guidelines:
http://midi.teragonaudio.com/tech/midispec/sysex.htm#
In summary....
Non realtime Status bytes received will now abort any current SysEx message..... and SysEx stop bytes will now be ignored unless there has previously been a SysEx start byte received for the current pending message.... Also reworked how SysEx bytes are dealt with in general (Start and Stop bytes are no longer treated as the same).
This was the root cause of the Midi input becoming locked in a SysEx loop, with no route to recovery when an erroneous SysEx start or stop byte was received potentially caused by plugging in a TRS Midi connector (which can cause random garbage data), or the unlikely event of connecting Midi cables in-between a SysEx transmission.
Also SysEx messages which are larger than the SysEx buffer (which will result in them being split into chunks) will no longer be considered valid Midi messages, and will have to be dealt with via callbacks only. This is to avoid malformed and incomplete SysEx messages (at the end of a split), which would be automatically transmitted if Thru mode was On. Also reintroduced the WarningSplitSysEx error which will notify when a SysEx message has overrun its buffer, and will be cleared when a fresh SysEx message has begun.
I have tested this as much as I can with my Midi setup (Teensy 4) and all looks good, but I have not run the unit tests because I (embarrassingly) am unsure how to set them up. I've been a bit generous with the comments so hopefully the code is easy to follow.
Thanks to everyone who has previously contributed to this. For the most part this library has been pretty solid for me, and I'm happy to potentially contribute..... I'm not a professional when it comes to coding, and this is my first ever PR, (I'll be quietly chuffed if it gets taken in), but it's a fairly big change, so it's probably a good idea for others to give this one a proper check over first.