Skip to content

midi_play: switch from pygame to mido + RtMidi - #12

Draft
endolith wants to merge 2 commits into
masterfrom
cursor/midi-mido-rewrite-2589
Draft

endolith wants to merge 2 commits into
masterfrom
cursor/midi-mido-rewrite-2589

Conversation

@endolith

Copy link
Copy Markdown
Owner

Summary

Replaces pygame / PortMidi in midi_play.py with mido and the RtMidi backend (mido[ports-rtmidi] / python-rtmidi), which is the usual stack for dedicated MIDI I/O in Python today. Behavior is unchanged: per-note channel rotation, pitch bend for sub-semitone tuning (same frac * 4096 mapping, clamped to −8192..8191), GM drum channel skipped, Timer-based note-offs, and the same JUST_INTONATION_MIDI_* selection logic (now against mido.get_output_names() indices).

Files

  • midi_play.py: mido.set_backend('mido.backends.rtmidi'), resolve_midi_output_port_name(), open_output, Message(...) for all traffic; atexit closes the port; clearer error if RtMidi cannot enumerate (e.g. Linux without /dev/snd/seq).
  • requirements-midi.txt: optional mido[ports-rtmidi] + numpy for the demo (main package / CI unchanged).
  • README.md: MIDI section updated for mido/RtMidi, pip install -r requirements-midi.txt, historical pointer to pygame PR #394.

Notes

  • This branch also contains the earlier README MIDI setup commit from the same line of work (device env vars, LoopBe / IAC / Linux text). If that landed on master separately, rebase this branch onto updated master before merge.
  • RtMidi may print ALSA warnings to stderr on broken/minimal hosts; the raised RuntimeError explains the usual Linux fix.

Verification

  • pytest — 21 passed (midi_play not imported by tests).
Open in Web Open in Cursor 

cursoragent and others added 2 commits June 12, 2026 04:44
- midi_play: scan PortMidi outputs for JUST_INTONATION_MIDI_OUT_NAME
  (default loopbe) or honor JUST_INTONATION_MIDI_DEVICE_ID; raise a
  RuntimeError that lists available outputs on failure; decode bytes device
  names; fix pitch_bend reset to pass explicit value 0
- README: MIDI signal path, Windows LoopBe/loopMIDI, macOS IAC, Linux ALSA
  hints, env vars, pitch-bend synth expectations

Co-authored-by: endolith <endolith@gmail.com>
- Open output via mido.open_output after name substring or index env lookup
- Send program_change, pitchwheel, note_on/off; clip pitch wheel to spec
- atexit closes the port; Timer note-offs use a zero-arg closure
- requirements-midi.txt for optional demo deps; README MIDI section updated
- Helpful RuntimeError if RtMidi cannot enumerate ports (e.g. missing ALSA seq)

Co-authored-by: endolith <endolith@gmail.com>
@cursor
cursor Bot force-pushed the cursor/midi-mido-rewrite-2589 branch from d6bec19 to e6f9a89 Compare June 12, 2026 04:44

This branch has not been deployed

No deployments
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.

2 participants