8000 midi: let a track listen to one MIDI source by mparrett · Pull Request #51 · nooga/slab · GitHub
[go: up one dir, main page]

Skip to content

midi: let a track listen to one MIDI source - #51

Open
mparrett wants to merge 2 commits into
nooga:masterfrom
mparrett:midi-source-routing
Open

mparrett wants to merge 2 commits into
nooga:masterfrom
mparrett:midi-source-routing

Conversation

@mparrett
Copy link
Copy Markdown
Contributor

Stacked on #50. This branch contains #50's commit; review the top commit only (midi: a track can listen to one MIDI source).

A track can now listen to one MIDI source. Right-click its R → MIDI in → When selected (the default, today's behaviour) or a connected device by name.

  • A source's notes, on any channel, play every track set to it, selected or not. Sources no track claims fall through to the selected track, so existing projects play as before.
  • With MIDI REC on, each claimed source records into its own track: the note clip under the playhead, or a new take clip. The pass is still one undo step, and the selection doesn't move.
  • Saved per track by device name, as "midi_in": "…" (docs/19). A source not connected is kept, listed as not connected, and plays again when it's plugged in. MIDI-learn and the knob map are unchanged.

This replaces #48, which routed by MIDI 1.0 channel number (1–16). Routing by source doesn't tie tracks to channel numbers, doesn't fight MPE (which spends a channel per note), and is the same for hardware and software. A program that sends several parts publishes a source per part: undertone's -midi-live -midi-split publishes undertone drone, undertone lead, undertone drums and so on, one track each.

Live state is per source and channel, so the sustain pedal (CC64) and all-notes-off (CC120/123) act on their own channel, per the MIDI spec. Before, a pedal on channel 1 also held channel-10 notes. When devices come or go, each source's state follows it to its new index by name, and only a departed source's notes let go. poll now drains the ring before rescanning, so a queued message keeps the source index it was sent under. That overlaps #49, which releases everything when any source goes. With both in, this per-source release would take the place of #49's, keeping its unique-ID check for a source replaced under the same name.

Up to 16 sources are kept apart; more still play, sharing the last one's state.

Testing. zig build test passes, with new tests for per-source and per-channel state, a rescan that moves sources and one that removes one, routing two sources to two tracks, a pitch held from a source and the computer keyboard at once, a track moved under held notes, and the project round-trip of midi_in.

🤖 Generated with Claude Code

mparrett and others added 2 commits November 25, 2026 07:35
The engine held the editor's keys for one track at a time (aud_held,
aud_track), so a key for a second track released the first, and a key held
while tracks were moved, deleted, grouped, duplicated or inserted above it
released at its old index and stuck. Each track now keeps its own keys
(Track.keys_held), and every edit that renumbers tracks remaps them through
tracksRenumbered, along with the engine's queued key events.

Stopped with keys on several tracks, audition renders the whole graph, and
the never-quiet ring limit counts from the last release, so a key held past
RING_MAX_S keeps its tail.

No input plays two tracks at once yet; this is the engine side any such
routing needs, whatever the protocol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Right-click a track's R, then MIDI in, and pick a connected device by
name: its notes, on any channel, play the track whether or not it is
selected, and REC records them into the track's own clip in the same
pass. Sources no track listens to play the selected track, so the
default, When selected, changes nothing.

The setting is saved by device name (docs/19 midi_in). A source not
connected is kept, listed as not connected, and plays when it returns.

Live state is per source and channel, so the sustain pedal and
all-notes-off act on their own channel. A rescan moves each source's
state to its new index by name, and only a departed source's notes let
go. poll drains the ring before rescanning, so queued messages keep the
index they were sent under.

This routes by source rather than by MIDI 1.0 channel number; a program
that publishes a source per part (undertone -midi-split) plays several
tracks at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

0