Repository navigation
Reload an instrument's voice when its program is saved, and give voices the modulation wheel (keyboard-instrument.md §14) - #188
Conversation
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 11m 54s
This change answers the keyboard-instrument plan's open questions 5 and 6, in a new §14. Saving an instrument's program while field keys plays now loads it again. Field watches the file with watchText, the directory watch that watchKeymap now shares, and sends /field/reload to the port it gives sclang with -u. The host reloads with the new sc/voice-load.scd, the loader its first load and the take render also use, and a load that fails keeps the last good voice and says why. The modulation wheel (CC 1) becomes mod, an optional voice control that the voicer passes to each new voice and sets on every sounding one, live and in a take's render; juno turns it into vibrato and bass into an opening filter. §14.5 leaves criteria 37 to 41 by ear, and a save lost in a session's first seconds, for later.
2 finding threads: 0 resolved, 2 open
Covered 17 of 17 changed files; none is generated.
The head is trusted: its branch is in this repository, and its one commit is the operator's. So its code ran here, with three limits:
- No live host. No live
sclangorscsynthran and no audio or MIDI device opened, so the reload path in a real host rests on reading, on the stubbed host test, and on an offline render. Criteria 37 to 41 were not played. - The daemon came from the main checkout. A fresh worktree has no native build, so the focused run pointed
FIELD_AUDIODat the main checkout'sfield-audiod. This change touches no native code. - Windows CI was pending when this review published. The Linux job passed.
The plan keyboard-instrument is in-progress. This change answers §7 questions 5 and 6 in §14 and adds no question, and §14.5 lists checks still owed rather than open questions, so the readiness gate holds. Questions 4, 7, and 8 were open before this change and are not its to answer.
Suggestions
docs/projects/keyboard-instrument/readme.md:410: §2.6 still says "The host ignores CC 1", and its contract table lists nomod. Point both at §14, as questions 5 and 6 now are, so the design section does not read as current.docs/build-graph.md:264: "controls, and optionallymod, that frees itself aftergategoes to 0" now reads as ifmodfrees itself. Give the optional control a sentence of its own when you reflow the paragraph.src/keys/voice-host.ts:154:reloadErrorscollects everyERROR:line between reloads, but only the first is read. Keep only the first.
What was checked
- Typecheck.
pnpm typecheckpasses. - Focused tests.
vitest run src/keys src/generators/voice-render.test.tspasses 99 of 99, with realsclangfor the voicer and the take render, including the newmodcases. - The shared watch.
watchTextis the oldwatchKeymapbody unchanged, directory watch and text comparison included. The keymap reload tests, which re-save every 500 ms, passed five runs of five. - Event names. The voicer's Event entries are unchanged:
noteOn,noteOff,cc,bend, andforgetVoices. The newsetandmodare a closure argument and a local variable, which resolve lexically and never through a method of Event's class chain. - Sounding voices through a reload. An offline render replaced a SynthDef under a running node: the node kept its old graph, and a node started afterwards used the new one. The voicer's held and sustained notes are untouched by a reload.
- A reload during a rate restart. A reload while
bootingupdatesvoiceDef, which the boot adds once the server answers.NetAddr.syncgives each call its own condition, so a reload's sync cannot hold up the boot's. modstays optional. The render tests through a voice with nomodcontrol pass, sincescsynthignores a control a SynthDef lacks.- Render branches.
junoandbassin render mode, seed 1, 4 seconds, stereo and mono, render the same bytes at the merge base and at this head, with real sound. - The take render's cache key. The harness files are content-hashed inputs, and
sc/voice-load.scdjoins them, so a harness change re-renders without a version bump. - Plans.
project checkpasses.
…es the modulation wheel as mod keyboard-instrument.md §7 questions 5 and 6, answered in §14. field keys watches the instrument's program with watchText, the directory watch watchKeymap now uses too, and on a change sends /field/reload to sclang's own port, which Field chooses with -u. The host loads the program again with sc/voice-load.scd, the loader its first load and the take render share: a voice that loads plays the next note, and one that does not keeps the last good voice and says why on the instrument's line, with sclang's ERROR line for a program that does not compile. CC 1 over 127 is mod, an optional voice control the voicer passes to each new voice and sets on every sounding one, live and in renders; setFreq became set(voice, control, value). juno gets vibrato and bass an opening filter; their render branches pass no mod and render the same bytes as before.
…nt the plan's contract at mod From the review of #188. A take records only what arrives once it has started, so a wheel left up before then plays live but not in the render; docs/keys.md says to set it again after the take starts, and plan §14.5 says why carrying it waits for a lasting arm. The two edited paragraphs are reflowed, mod has a sentence of its own in build-graph.md, plan §2.6 and its contract table point at §14, and VoiceHost keeps only the first ERROR line since a reload.
286fe04 to
8c282db
Compare
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CLEAN · took 2m 29s
This change answers the keyboard-instrument plan's open questions 5 and 6, in a new §14. Saving an instrument's program while field keys plays now loads it again: Field watches the file with watchText, the directory watch that watchKeymap now shares, and sends /field/reload to the port it gives sclang with -u. The host reloads with the new sc/voice-load.scd, which its first load and the take render also use, and a load that fails keeps the last good voice and says why. The modulation wheel (CC 1) becomes mod, an optional voice control that the voicer passes to each new voice and sets on every sounding one, live and in a take's render. This head rebases the change onto main and answers the first review: docs/keys.md and §14.5 now say a take starts with the wheel at 0, the two paragraphs are reflowed, and the review's three suggestions are taken.
2 finding threads: 2 resolved, 0 open
Covered 17 of 17 changed files; none is generated.
The head is trusted: its branch is in this repository, and both its commits are the operator's. No live sclang or scsynth ran and no audio or MIDI device opened, so criteria 37 to 41 are still unplayed. The focused run pointed FIELD_AUDIOD at the main checkout's field-audiod, because a fresh worktree has no native build. Both CI jobs were pending when this review published.
The plan keyboard-instrument is in-progress. This change answers §7 questions 5 and 6 in §14 and adds no question. The new §14.5 item defers carrying the wheel into a take explicitly, so the readiness gate holds. Questions 4, 7, and 8 were open before this change.
Suggestions
docs/projects/keyboard-instrument/readme.md:1349: §14.5 cites "arming.md chunk 3", which only #189, stacked above this pull request, adds. If this merges first, the citation names a planmaindoes not have until #189 lands. That plan also leaves open whether a lasting arm lives in the daemon or in.field/(its §7 question 1), and only the daemon answer keeps MIDI sources open between takes. Name the condition, "once the daemon keeps MIDI sources open between takes", and cite the plan when it exists.
What was checked
- Both earlier findings, at this head.
docs/keys.md"Record what you play" now says a take starts with the wheel at 0 and to set it again after the take starts, and §14.5 records why carrying the wheel waits. That is one of the two fixes the finding named. The reflowed paragraphs indocs/keys.mdanddocs/build-graph.mdnow run 59 to 72 columns, like the lines around them. - The rebase.
git range-diffshows the rebased commit identical to286fe04. Since that head, the only code change issrc/keys/voice-host.ts, which keeps the firstERROR:line since a reload, the one it read before. - Typecheck.
pnpm typecheckpasses. - Focused tests.
vitest run src/keys src/generators/voice-render.test.tspasses 99 of 99, with realsclangfor the voicer and the take render's NRT renders. - Unchanged since the first review. The SC harness and both instruments are byte-identical to
286fe04. So these results from that review still hold:junoandbassrender the same bytes in render mode as at the merge base, a reload leaves sounding notes on their old graph, the voicer adds no Event entry, andmodstays optional. - Plans.
project checkpasses.
…n unison (arming.md chunk 1) (#189) `field keys` could play only an instrument named by its program, and `field record` records one track per pass, because the daemon holds one arm. Justin asked for three things on 2026-10-11. The first is to play a MIDI track, a track whose record entry names an instrument, even with no takes yet. The second is to play a track above it with effects. The third is to choose the tracks to "arm" and hear every armed track in unison, and to record audio, MIDI, or both. This pull request, stacked on #188, plans all of it and builds the first chunk. `docs/projects/arming/readme.md` is the plan. You arm tracks by naming them, since both commands already take targets. `field keys` plays every armed MIDI track's instrument in unison. `field record` will arm each named track in the daemon, an audio track on its own input and a MIDI track on the MIDI sources, start them on one latch, and land each as its own take (chunk 2). A lasting arm, through `field arm` and the UI's arm buttons, comes third, after Justin decides where it lives. Justin made the two calls that matter: you choose what is armed, and armed tracks play in unison. Section 3 records the rest as decisions with the alternatives they beat, for review. They include refusing a bus over several MIDI tracks rather than arming them all, one voice host for unison rather than one per instrument, and audio inputs in the order you name the tracks. Hearing a track's effects is the hard part. The voice plays in its own `scsynth`, a track's inserts run in `field-audiod`, and a survey of the daemon found two obstacles: nothing carries audio between Field's processes, and a live session renders every track except the output track in full when it loads. `docs/projects/live-supercollider/readme.md` was a stub and is now a draft plan. It adds an `input` window kind and live tracks that run in the audio callback. The voice reaches the input through a shared-memory ring written by a small `scsynth` plugin. The plan weighs that against embedding `libscsynth` and against a loopback device, and leaves Justin two questions: the transport, and whether live tracks run with the transport stopped. Until it lands, `field keys` plays an armed track dry and says so. The chunk built here is `field keys` on tracks. A target with `track:` in it is a track. It plays the instrument its record entry names, or the one MIDI track under it down its `track:` inputs; a track with several under it lists them and stops, so you name the ones you mean. Anything else is an instrument as before, so the two mix. `src/keys/targets.ts` resolves targets and now holds `resolveInstrument` and the shelf listing, moved from `src/commands/keys.ts` so that nothing imports the command back. The voice host takes the programs as a JSON list in `FIELD_INSTRUMENTS`. It renames each SynthDef for its place in the list, so two programs that name their voices alike both play, and starts a voice from each program on every key. The voicer needed no change, because a list of synths is a voice. The instrument's line names each armed track and its program, as `keys (juno) + bass (bass) live at …`, and ends `· dry: the effects on keys-bus are not heard yet` when a named track has inserts above its MIDI track. ## Testing From the repository root of this branch, after `pnpm install`, with SuperCollider installed and the native tools built (`pnpm build:native`): ```sh pnpm typecheck pnpm exec vitest run src/keys FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test project check ``` The typecheck passes, the keys tests pass, the full suite passes 992 with 1 skipped (the no-MIDI-source case, which runs only without a MIDI service), and the plans are valid. `project check` also warns that `.github/workflows/projector-site.yml` is an earlier shape; that is on `main` already and is not this change. `src/keys/targets.test.ts` is the test for the new rule. It covers a MIDI track with no takes, a bus with an EQ (armed, and named as unheard), a bus over two MIDI tracks (listed, exit), a track with none under it, and several mixed and repeated targets (each armed once). To try it by hand, in `examples/bloom` add a track `mjuno` whose record entry has `instrument: juno`, a track `mbass` with `instrument: bass`, and a bus `mbus` with an EQ insert whose only input is `track: mjuno`. Then: - `field keys creek/track:mjuno creek/track:mbass` should show `mjuno (juno) + mbass (bass) live at …`, and every key should sound both instruments. - `field keys creek/track:mbus` should show `mjuno (juno) live at … · dry: the effects on mbus are not heard yet`. - A bus over both tracks should exit, listing them. A key that sounds only one instrument, or a line naming the wrong program, would mean the change is wrong. Delete the three tracks afterwards. I could not listen. In place of that I ran the real voice host with two silent programs that both name their SynthDef `\quiet`, and played one note from a source `field-audiod --keys` published. The host went live, and reported the note's voice starting and ending with no error; it reports a start only after the start callback has run and an end only after the release has. Criterion 4, two instruments sounding one key, is still owed by ear. <!-- projector-summary v=1 sha=b3b9b77ede0685b8a568e680a398a5877c8f11d6 --> 📽️ **Projector summary** of b3b9b77: https://field.amnes.ac/reviews/189
…ne (#195) `field keys` sends pitch bend from keys `1` and `2` in the default keymap, and the modulation wheel from `3` to `8`. Since #188 the bloom instruments answer both: the bend moves every sounding voice up to two semitones, and the wheel adds vibrato on `juno` and opens the filter on `bass`. But the status line said nothing about either, so you couldn't see whether a bend key had registered, or where the wheel sat after a few presses. Justin asked for both on screen while playing on 2026-10-11. The bend matters for a second reason: a laptop keyboard can drop a key pressed while three others are held, and the line is how you tell a key that never arrived from a bend that didn't sound. The session now remembers what it last sent. The bend runs from -1 to 1 and returns to 0 when its key is released or the terminal loses focus. The wheel is the last value sent on controller 1, including a hold-mode key's return to 0 and the resets at panic, reload, and quit. The status line shows both after the velocity, so the notes still come last: ```console Field Keys · musical-typing · transpose 0 · velocity 100 · bend -1 · mod 76 · C4 E4 F4 ``` The bend always carries its sign, `+0` at rest, and prints with as many decimal places as the finest bend in the keymap needs, up to four, so bending a held chord does not shift the notes along the line. A keymap with a `0.25` bend reads `+0.00` at rest, `+0.25`, and `-1.00`, while `musical-typing` keeps `+0` and `-1`. Each field appears only when the keymap has keys that set it, or when its value is away from rest. `musical-typing` gains both; `tracker` and `fourths`, which can set neither, show nothing new. The values are what `field keys` sent. A USB controller's bender and wheel go straight to the receiver and do not change them, and `docs/keys.md` says so beside the updated examples. ## Testing From the repository root of this branch, after `pnpm install`: ```sh pnpm typecheck pnpm exec vitest run src/keys src/commands/keys.test.ts FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test project check ``` The typecheck passes, and the keys tests pass 100 with 8 skipped. Those 8 need a native build, which my worktree did not have. The full suite, run against a daemon built from `main`'s native code, passes 1029 with 3 skipped. These cases pin the change: - `session.test.ts`: `bend` is -1 while `1` is held, 0 after the release, 1 while `2` is held, and 0 after a focus-out. `mod` starts at 0, is 76 after `6` and still 76 after its release, since set mode sends nothing on release, and is 0 after `3`. A hold-mode key on controller 1 sets 90 while held and 0 on release. - `keys.test.ts`: the line reads `velocity 100 · bend +0 · mod 0 · –` at the start. Holding `1` over C4 gives `bend -1 · mod 0 · C4` at the same length as the line at rest, and the release brings back the line at rest. `mod 76` shows after `6`, and the `tracker` keymap's line has neither field. A keymap with bends of -1 and 0.25 reads `bend +0.00` at rest, `bend +0.25`, and `bend -1.00`, and one with a `0.333333` bend reads `bend +0.3333`. By hand, after `pnpm build`: in `examples/bloom`, run `field keys juno`. Holding `1` shows `bend -1` before the notes, and letting go shows `bend +0`. Pressing `5` shows `mod 51`. With a keymap of your own at `~/keymaps/mine.yaml` that binds `Digit2: { bend: 0.25 }`, run as `field keys juno --keymap ~/keymaps/mine.yaml`, the line reads `bend +0.00` at rest and `bend +0.25` while `2` is held, at the same length. A field that does not change when you press its key, a line whose notes move as you bend, or a field after the notes would mean the change is wrong. I couldn't watch the line myself: `field keys` needs a terminal that speaks the kitty keyboard protocol, and this session has none. Nothing is left behind. <!-- projector-summary v=1 sha=a5ae0a46cf17061760a77d75259564c8c41ffbf3 --> 📽️ **Projector summary** of a5ae0a4: https://field.amnes.ac/reviews/195
Designing an instrument like
junomeant quittingfield keys, editing the program, and starting again, which takes several seconds each time whilescsynthboots. The modulation wheel did nothing: the voice contract had no control for it, so the voice host ignored CC 1, and themusical-typingkeys3to8that set it went nowhere. The keyboard-instrument plan deferred both, as §7 questions 5 and 6, "until chunk 2 has been played with". This answers both, in a new §14.Saving the instrument's program while
field keysplays now loads it again. Field watches the program withwatchText, a directory watch that waswatchKeymap's and now serves both, so a save that renames a temporary file over the program still counts. On a change, Field sends/field/reloadtosclang's own port, which it chooses and passes with-u, as it already choosesscsynth's. The host accepts that message only from127.0.0.1and loads the program again withsc/voice-load.scd. That loader is new, and the host's first load and the take render now use it too, so all three load a program the same way. A voice that loads plays the next note, and notes already sounding finish as they started. One that does not, such as a save with a syntax error, leaves the last good voice playing. The instrument's line then leads with why,juno kept its last voice: juno.scd does not compile: syntax error, …, attachingsclang's ownERROR:line, because you cannot seesclang's output otherwise.The modulation wheel is now
mod, CC 1 over 127, an optional control of the voice contract. The voicer passes it to each new voice and sets it on every sounding voice when it moves, both live and in a take's render, so a take recorded with the wheel renders with it. ItssetFreqcallback becameset.(voice, control, value), which carries both. A voice may leavemodout, becausescsynthignores a control a SynthDef lacks.junoturns the wheel into vibrato, up to half a semitone at 5.5 Hz, as the lever on a Juno's bender does;bassopens its filter, up to four times its cutoff;padhas nomod. The render branches ofjunoandbasspass nomod, so their graphs and their renders are unchanged.docs/keys.mdaddsmodto the contract and describes reloading;docs/build-graph.mdnames the new harness file, which is also a cache input of every take render. The plan's §14 records the design, four decisions with the alternatives they beat, criteria 37 to 41, and what was verified.Testing
From the repository root of this branch, after
pnpm install, with SuperCollider installed and the native tools built withpnpm build:native(main's native code has moved, so an older build failssrc/audio/eq-response.test.ts):The typecheck passes, the focused run passes, and the full suite passes 987 with 1 skipped (the no-MIDI-source case, which runs only without a MIDI service). These are the cases that pin the change:
src/keys/voicer.test.ts, through realsclang:modstarts at 0, CC 1 at 127 sets 1.0 on a sounding voice and starts a new one with it, and CC 1 at 0 sets both back.src/keys/voice-host.test.ts, against a stubsclang: the host starts with-u <port> -D <script>,reloadreaches that port, and both answers become statuses, the failure withsclang's error line.src/generators/voice-render.test.ts, through realsclang: a voice whose level ismodrenders a take with no CC 1 as silence and one with CC 1 at 127 as sound.To see reload by hand without playing, run
field keys junofromexamples/bloom, wait forjuno live at …, then changevar level = 0.12;inshared/instruments/juno.scdand save. The line should end· reloaded. Delete that semicolon and save: the line should readjuno kept its last voice: juno.scd does not compile: …. Put it back, and· reloadedreturns. I ran exactly this in a pseudo-terminal with the real host and saw those three lines. A line that never changes on save, or a host that exits on the bad save, would mean reload is broken. Restore the file afterwards; nothing else is left behind.By ear, which I could not do: criteria 37 to 41 in plan §14.3, the held note through a reload, vibrato on
junoand the filter onbassfrom keys8and3, and a recorded take with the wheel moving.📽️ Projector summary of 8c282db: https://field.amnes.ac/reviews/188