Linux & testing
Two ways to reach a MIDI port
Section titled “Two ways to reach a MIDI port”Linux exposes the same hardware twice:
- Raw MIDI (
/dev/snd/midiC*): a byte pipe. The TUI opens it read-only to receive input. - ALSA sequencer (
aconnect,amidi -p, DAWs): a client/port graph with timestamps and routing.
Both can read the jack. Mixing them is the usual cause of Device or resource busy: the raw device is exclusive per direction, so an O_RDONLY reader blocks
another reader until it closes. A writer can coexist with a reader; two readers
cannot.
Check who owns the port:
fuser -v /dev/snd/midiC5D0cat /proc/asound/card5/midi0fuser -k /dev/snd/midiC* clears a stale process. Do not run it while a DAW is
using the pedal.
amidi is the reference tool for this device:
amidi -l # list portsamidi -p hw:5,0,0 -d # dump incoming MIDIamidi -p hw:5,0,0 -S f000320d... -d -t 2 # send and receive in one invocationTwo traps:
- Send and receive in the same invocation. With
-Salone the port closes when the send finishes, and the reply is lost.-d/-rin the same command keeps the input open;--timeoutis an inactivity timeout in seconds (fractions work). - Device numbers change on replug.
hw:5,0,0is not stable; use auto-detection or re-list.
The TUI writes with a short-lived amidi -S subprocess, because raw ALSA writes
can block the UI; reads use the raw fd.
USB MIDI framing
Section titled “USB MIDI framing”USB-MIDI sends 4-byte event packets (a cable/CIN header plus three bytes).
SysEx is split into 3-byte chunks with CIN 0x4 and a final 0x5–0x7; ALSA
reassembles them, so a reader sees a byte stream and must wait for F7 rather
than assume one read is one message. A 23 KB configuration read is thousands of
packets; drain continuously.
Permissions
Section titled “Permissions”The active desktop user is normally in the audio group. Verify:
id -nGls -l /dev/snd/midiC*If the node is not group-readable, add a udev rule for the USB ID or fix group membership; do not run the TUI as root.
Testing without hardware
Section titled “Testing without hardware”The repository’s device tests skip when no pedal is present, and the unit tests run anywhere:
go test ./... # device tests skip when no device is foundgo test -p 1 ./... # serialise packages if a pedal is attachedWith a pedal attached, package tests can compete for the same raw port.
Running with -p 1 avoids that.
For a synthetic port:
sudo modprobe snd-virmidiamidi -l # a Virtual Raw MIDI port appearsamidi -p virtual -d # read itsnd-virmidi bridges raw MIDI and the sequencer; it is enough to test framing
and reassembly without a Chocolate. snd-seq-dummy provides a “Midi Through”
port that loops a client’s output back to itself.
Bluetooth MIDI
Section titled “Bluetooth MIDI”BLE-MIDI works through BlueZ’s experimental MIDI support or WirePlumber, and is fine for notes and CC during a show. Vendor configuration over BLE is a different GATT tunnel, and the official app is the practical way to do it. For this TUI, use USB.