Amended sketch (attached version 1.1).
When testing on a different device I was getting strange sequences that I initially assumed were an electrical problem. However they persisted. It turns out that (rather unclearly from the specs) you can have multiple "command" messages followed by parameters. For example, Channel 1 Note on is 0x90 followed by the note and the pressure, eg.
0x90 0x45 0x32
However it appears (to save space) you can have multiple notes, like this:
0x90 0x45 0x32 0x46 0x32 0x47 0x32
The amended code checks if an incoming byte has the high-bit set, and if not, uses the last byte with the high-bit set as a "repeat last command" idea.
MIDI_decoder.ino (13.6 KB)