Skip to content

MIDI: parse the hardware port as a byte stream - #29

Open
diegoMalagrida wants to merge 1 commit into
torvalds:mainfrom
diegoMalagrida:fix/din-midi-stream-parser
Open

MIDI: parse the hardware port as a byte stream#29
diegoMalagrida wants to merge 1 commit into
torvalds:mainfrom
diegoMalagrida:fix/din-midi-stream-parser

Conversation

@diegoMalagrida

@diegoMalagrida diegoMalagrida commented Jul 29, 2026

Copy link
Copy Markdown

The screenless pedal can be programmed over either USB or TRS Type-A MIDI, and the current scene protocol carries schema, state, and routing commands over SysEx. uart_midi_read() currently treats F0-F7 as zero-length status bytes, so a SysEx request arriving at the physical MIDI input is discarded before handle_midi_packet() sees it.

The same reader drops every System Real-Time and System Common message. MIDI Clock arriving at the TRS jack therefore never reaches USB, and a two-byte channel message can retain the final byte of an earlier three-byte packet.

This replaces that ad-hoc reader with a byte-stream parser. It preserves channel running status, emits real-time without disturbing a partially received channel or SysEx message, handles System Common and System Reset, packs SysEx into CIN 4..7, and zero-pads unused packet bytes.

The host-side validation covers channel running status for two- and three-byte messages, real-time interleaved with channel and SysEx messages, System Reset, System Common, and all three SysEx ending forms. This revision is based on the reorganized tree and updates the validation include to Firmware/midi/midi.h.

Validated with:

  • make -BC Validation test-midi-cin && ./Validation/test-midi-cin (all MIDI checks pass)
  • GCC 13.3 with -Wall -Wextra -Wpedantic -Wconversion and AddressSanitizer/UBSan
  • 10,000,000 randomized malformed-stream bytes under AddressSanitizer/UBSan

@diegoMalagrida
diegoMalagrida force-pushed the fix/din-midi-stream-parser branch 2 times, most recently from f7d3245 to 694a401 Compare July 29, 2026 08:44
@torvalds
torvalds force-pushed the main branch 2 times, most recently from 0d04135 to 52eac9e Compare August 11, 2026 00:07
The screenless pedal is meant to be programmed over either USB or its
TRS Type-A MIDI ports, and the scene protocol now carries its schema,
state and routing commands over SysEx.  The transmit side learned all
the USB-MIDI CIN lengths in commit db24ff6 ("Get the USB-MIDI code
index numbers right in both directions"), but uart_midi_read() still
treats F0-F7 as zero-length status bytes.  A SysEx request arriving at
the TRS input disappears before handle_midi_packet() sees it.

The same reader recognizes only channel voice messages.  It drops
every real-time byte, so MIDI Clock arriving at the TRS jack never
reaches USB, and System Common messages disappear too.  A two-byte
channel message also leaves the final packet byte holding data from an
earlier three-byte event.

Replace that ad-hoc reader with a byte-stream parser.  Keep channel
running status, emit real-time without disturbing a partly read message,
handle System Common, and pack SysEx into the CIN 4..7 forms USB-MIDI
needs.  System Reset is the real-time exception and clears the parser
state.  Zero-pad every packet byte that the MIDI message does not use.

Keep the parser next to the CIN helpers so the hardware MIDI path has
host-side coverage.  Feed it channel running status, real-time
interleaved with both channel and SysEx messages, System Common, System
Reset, and all three SysEx ending forms.

Fixes: 95881ae ("Re-organize MIDI code a bit, add UART option")
Assisted-by: Codex:gpt-5
Signed-off-by: diegoMalagrida <diegomalagrida@gmail.com>
@diegoMalagrida
diegoMalagrida force-pushed the fix/din-midi-stream-parser branch from 694a401 to bf6b02b Compare August 12, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant