Repository navigation
Play a SuperCollider instrument from field keys through a voice host (keyboard-instrument.md chunk 2) - #179
Conversation
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 24m 12s over 2 heads
This pull request adds field keys <instrument>, chunk 2 of keyboard-instrument.md. sclang runs sc/voice-host.scd, which boots its own scsynth on the output device at the device's current rate, loads the SynthDef the instrument returns under FIELD_MODE=voice, and plays it from every MIDI source, restarting the server when the device's rate moves. Around it, sclangCommand() becomes the one sclang lookup, field-audiod --keys reports the system output's name so the host can name one device for both directions, and still-water-pad gains a voice mode with its render branch unchanged. The change knowingly leaves criteria 21 to 26 to be checked by ear, and sends the voice straight to the device until live-supercollider puts scsynth in the session graph.
4 finding threads: 0 resolved, 4 open
Covered 15 of 15 changed files; no generated files.
The head moved from df8416a to 1e9e8d6 during this review, by a rebase onto the updated keys/chunk-1. The pull request's own change is the same at both heads, and every check below ran at 1e9e8d6:
- Typecheck.
pnpm typecheckis clean. - Focused tests.
src/keys/voice-host.test.ts,src/keys/helper.test.ts, andsrc/keys/helper-native.test.tspass, 25 tests, with the native round trip againstfield-audiodbuilt at this head on macOS. All ninesrc/keysand keymap schema suites pass, 100 tests, and the stub-onlyrunScProgram edgesblock ofsrc/graph/build.test.tspasses, 4 tests. - The ready line's
outputfield. A throwaway test throughKeysHelperreadMacBook Pro Speakers. It ran atdf8416a, andkeys.cppandhelper.tsare identical at this head.
Some of this review rests on reading rather than running:
- SuperCollider was not run. Starting the host plays audio on the machine that runs it, so I started neither
sclangnorscsynth. The four threads rest on SuperCollider's own code instead: the 3.14.1 class library (Server,ServerStatusWatcher,ServerOptions,String.quote) and the server and language sources on its default branch (scsynth_main.cpp,SC_World.cpp,SC_CoreAudio.cpp,sc_popen.cpp,SC_TerminalClient.cpp). - Criteria 21 to 26 are still owed by ear, as the pull request says. Criterion 21's Apollo has inputs, unlike the speakers §10.1 tested. For one named device,
scsynthstarts a single IOProc with every stream on, inputs included, unlessServerOptions.inputStreamsEnabledturns them off. I could not confirm whether macOS then asks for the microphone, so watch for that prompt in criterion 21. - CI builds only on Linux, where
defaultOutputDevice()compiles to its empty branch. The macOS build above is the only build of its CoreAudio branch besides the author's.
The plan stays in-progress. Its §7 open questions predate this change, and each is deferred to chunk 4 or until chunk 2 has been played with.
Suggestions
src/keys/helper-native.test.ts:131: on macOS, requireoutput, or skip by name when the Mac has no output device. The check runs only when the field is present, so a helper that stops sending it still passes.docs/keys.md:85: say that inside a project a path resolves from the project root, as asupercollider:entry'ssource:does. A path typed relative to a subdirectory fails withno instrument program at ….
sclangCommand() resolves FIELD_SCLANG, then PATH, then the SuperCollider.app bundle, and returns a path a long-running spawn can use. runScProgram now calls it instead of retrying the bundle after an ENOENT, so a render and the voice host can never find different sclangs (keyboard-instrument.md §2.8). The messages for a missing override and a missing sclang are unchanged.
field keys <instrument> starts sc/voice-host.scd under sclang after the helper publishes Field Keys. The host boots its own scsynth on the output device at the device's rate, loads the voice the instrument returns under FIELD_MODE=voice, and plays it from every MIDI source: one voice per note, sustain, All Notes Off, and pitch bend on the sounding voices (keyboard-instrument.md §2.6). It restarts scsynth when the device's measured rate leaves the rate it booted at, and quits once field keys is gone; field keys also sends /quit to the scsynth port it chose. The status line shows the instrument starting, live, or restarting. scsynth on macOS opens the default input device even with no input channels, and blocks on the microphone permission, which a run of the host found. The host therefore names the output device for both directions, and field-audiod --keys reports the system output's name on its ready line for when --device is absent. still-water-pad answers voice mode with a gated version of its voice. Its render branch keeps its code, and renders the same bytes as before for seed 90210.
docs/keys.md covers field keys <instrument>, the voice host, and how to give an instrument a voice mode; build-graph.md states voice mode beside the render contract, and architecture.md's live SuperCollider mode describes the voice host. The plan corrects §2.6's no-inputs bullet, notes the ready line's output field in §2.5, and records chunk 2 as built in §10, including the microphone finding in §10.1.
…check its device Review of #179 found four ways the voice host could hang or misbehave, all fixed here: - waitForBoot's onFailure never runs in SuperCollider 3.14.1, so a server that exited while it booted left field keys at starting forever. The host now watches its own boot and fails, naming the device, when the server's process exits before it answers or after 20 seconds. - field keys waited for the host to be ready before it could quit, so a host that never became ready left the terminal raw. VoiceHost.start now resolves once sclang runs, ready says when the host goes live, and Esc closes a host that is still booting. - A server still booting has not bound its port, so the /quit that close sent was lost and the new scsynth kept the device. The host reports each server's process, and both field keys and the host stop it by process as well as by /quit. - scsynth falls back to the default input and output for a device name it does not find, which opened the microphone, and SuperCollider passes the name to a shell between bare double quotes. The host now refuses a name ServerOptions.outDevices does not list, and one with a quote, backtick, dollar sign, or backslash. Plan §10.2 records each.
Review of #179: the check ran only when the field was present, so a helper that stopped sending it would still pass.
Review of #179: a path typed relative to a subdirectory failed with no instrument program at, and the guide did not say why.
A run of the host showed notes from another MIDI source reaching it during its first boot. They had no server to sound on, but the host tracked voices that never existed. The flag that ignored notes during a restart now covers the first boot as well, renamed booting.
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CLEAN · took 8m 07s over 2 heads
This pull request adds field keys <instrument>, chunk 2 of keyboard-instrument.md. sclang runs sc/voice-host.scd, which boots its own scsynth on the output device at the device's current rate, loads the SynthDef the instrument returns under FIELD_MODE=voice, and plays it from every MIDI source, restarting the server when the device's rate moves. Around it, sclangCommand() becomes the one sclang lookup, field-audiod --keys reports the system output's name so the host can name one device for both directions, and still-water-pad gains a voice mode with its render branch unchanged. The change knowingly leaves criteria 21 to 26 to be checked by ear, and sends the voice straight to the device until live-supercollider puts scsynth in the session graph.
4 finding threads: 4 resolved, 0 open
Covered 15 of 15 changed files; no generated files.
Since the review of 1e9e8d6, four commits answer that review, and the branch was rebased twice onto keys/chunk-1, the second time from f8b0f8a while this review ran. Both rebases left every commit of this pull request unchanged, and brought in only #178's own changes. Each finding is fixed at b35267b:
- A server that fails to boot. The host no longer relies on
waitForBoot. It boots, then watches: it fails, naming the device, when the server'spidreturns to nil beforeserverRunningturns true, or after 20 seconds. - Quitting before the host is ready.
VoiceHost.startresolves oncesclangis spawned, a separatereadypromise says when the host goes live, and quitting callsclose()without waiting for it. - Quitting during a restart. The host reports each server's process on a
server_pidline.close(), the host's failure path, and its parent check all stop that process, so a server that has not bound its port yet still stops. - The device name. Before any server starts,
deviceProblemrefuses a name thatServerOptions.outDevicesdoes not list, and one that contains", a backtick,$, or\.
Checked at b35267b:
- Typecheck.
pnpm typecheckis clean. - The voice host tests.
src/keys/voice-host.test.tspasses, 13 tests, including the two new cases that close a host still booting and stop a stub server that ignores/quit. No stub server outlived the run. - Every keys suite. All nine
src/keysand keymap schema suites pass, 102 tests. That includes the native round trip againstfield-audiodbuilt at this head on macOS, which now requiresoutputon the ready line. - Renders. The stub-only
runScProgram edgesblock ofsrc/graph/build.test.tspasses, 4 tests. - The SuperCollider side, by reading. I read the new boot watcher and device check against SuperCollider 3.14.1's
Server.boot,prOnServerProcessExit,Server.quit, andServerOptions.outDevices.
Some of this review rests on reading rather than running:
- SuperCollider was not run. Starting the host plays audio on the machine that runs it, so I started neither
sclangnorscsynth. - Criteria 21 to 26 are still owed by ear, as the pull request says. Criterion 21's Apollo has inputs, unlike the speakers §10.1 tested. For one named device,
scsynthstarts a single IOProc with every stream on, inputs included, unlessServerOptions.inputStreamsEnabledturns them off, so watch for a microphone prompt there. - CI builds only on Linux, where
defaultOutputDevice()compiles to its empty branch.
The plan stays in-progress. Its §7 open questions predate this change, and each is deferred to chunk 4 or until chunk 2 has been played with.
Suggestions
sc/voice-host.scd:86: on a rate restart,bootruns fromserver.quit'sonComplete, which fires on/done /quit.scsynthsends that before it stops the audio driver, unloads its plugins, and exits, andServer.pidholds the old process untilprOnServerProcessExitclears it. If that takes longer than the watcher's first 0.1-second tick,launchedcaptures the old process, and the restart then either fails as "exited while it booted" or reports the old process asserver_pid. Record thepidthatbootstarts with and accept only a different one, as SuperCollider's ownprWaitForPidReleasewaits for the old one to clear. I could not measure the exit time without runningscsynth.docs/projects/keyboard-instrument/readme.md:978: §10.3 saysvoice-host.test.tshas 11 passing tests. It has 13 at this head, including the two close cases.
…#181) Musical Typing is the keymap most musicians know from a computer keyboard, but it reaches only 18 notes before you transpose. This chunk of the keyboard-instrument plan, stacked on #179, ships the two alternatives the plan chose as built-ins: `tracker`, the layout trackers have used from FastTracker 2 to Renoise, with two piano octaves on the bottom and top rows (32 notes), and `fourths`, an isomorphic grid with a semitone per key and a perfect fourth per row (27 notes), where a chord shape plays the same in every key. Both are plain keymap files in the format #178 introduced, and both were already that chunk's schema fixtures, so the format was known to express them; the tests now read the shipped files instead. Each puts transpose and velocity on the arrows and sustain on `Space`, because their notes take the rows Musical Typing keeps for controls. `docs/keys.md` describes them, and the plan records the chunk as built in §11. ## Testing Run these from the repository root of this branch. `field keys` needs the daemon (`pnpm build:native`); `--print` does not. ```sh pnpm install --frozen-lockfile pnpm typecheck pnpm test pnpm field keys --keymap tracker --print pnpm field keys --keymap fourths --print ``` `pnpm test` passes; when I ran it on this head, 904 tests passed with none skipped. The `tracker` diagram puts C3 under `Z` and C4 under both `,` and `Q`; the `fourths` diagram puts C3 under `Z`, F3 under `A`, A#3 under `Q`, and D#4 under `1`. A diagram with notes elsewhere means a keymap file is wrong. Then play them in Ghostty or iTerm2 with `pnpm field keys --keymap tracker` and, in a second terminal, `native/audiod/build/field-audiod_artefacts/Release/field-audiod --midi-monitor "Field Keys"`. Pressing `Z`, `Q`, and `I` prints note-ons 48, 60, and 72, and `→` shows `transpose +12` on the status line. With `--keymap fourths`, pressing `Z B D` together and then `X N F` together prints 48, 52, 55 and then 49, 53, 56. I ran both in a pseudo-terminal through the real helper and CoreMIDI, typing as this Mac's ColemakC keyboard layout does, and the monitor heard exactly those notes, each with one note-off. Real keys in a real terminal are still owed, as plan §9.3 says. The commands leave no state behind. <!-- projector-summary v=1 sha=07e720867e718bd72878ed35abb4738f676718c8 --> 📽️ **Projector summary** of 07e7208: https://field.amnes.ac/reviews/181
§7.2 said PATH and FIELD_SCLANG already work on Windows and only the /Applications fallback needed a Windows spelling. That held at 4f90a87, where execFile searched PATH itself. Since #179, sclangCommand does its own search for renders and the field keys voice host. That search tries only "sclang", never "sclang.exe", and it also handles a FIELD_SCLANG with no forward slash, such as a native Windows path, so that path is reported missing. The bullet now names all three gaps, cites the function rather than a pinned line, and says what porting it takes.
The comment on the two sclang-stub tests said a real sclang.exe goes through the same spawn untouched. Since #179, runScProgram finds sclang through sclangCommand first, which looks for "sclang" without ".exe" and treats a native FIELD_SCLANG path as a name to search for, so on Windows a real sclang never reaches the spawn. The comment now says so and points at windows-portability.md §7.2, which records the gap.
Since the keyboard instrument's voice host (#179), field finds `sclang` itself in `sclangCommand`, and both SuperCollider renders and `field keys` go through it. On Windows that lookup could not find a real `sclang` at all, even with SuperCollider installed: its `PATH` search tried only `sclang`, never `sclang.exe`; a native `FIELD_SCLANG` such as `C:\Program Files\SuperCollider-3.13.0\sclang.exe` contains no `/`, so it was searched for as a bare name and reported missing; and the fallback probed only the macOS app bundle. The Windows stack recorded this as an open item in windows-portability.md §7.2. This makes the lookup platform-aware without changing it on macOS or Linux: - On Windows the `PATH` search tries `.com` and `.exe`, and never the bare name, because an extensionless file cannot run there. The rest of `PATHEXT` is left out on purpose: both callers spawn without a shell, and Node refuses a `.bat` or `.cmd` that way (`spawn EINVAL`, since the CVE-2024-27980 releases). A `FIELD_SCLANG` that names a batch file is refused with that reason. - A `FIELD_SCLANG` with a backslash, a slash, or a drive is read as a path; a bare name is still searched for on `PATH`, so a wrapper like `sclang-wrapper.exe` keeps working. - The fallback takes the newest `SuperCollider-<version>` folder under Program Files, sorting versions numerically so 3.13.0 beats 3.9.3. - `PATH` and `ProgramFiles` are read without regard to case. Windows usually spells the first one `Path`, and the voice host can pass a copied environment, which loses the case-insensitive lookup that only `process.env` has. The platform is a parameter of `sclangCommand`, defaulting to `process.platform`, so `src/generators/supercollider.test.ts` exercises each Windows rule against real files on any machine; the two tests whose fixtures only a POSIX host can hold skip on Windows. `build.test.ts` now probes for a real `sclang` with the same lookup, so its integration test runs on Windows when SuperCollider is installed. `docs/cli.md` and `docs/keys.md` describe the whole lookup order, and the plan records the item as ported. #185 also edits `docs/cli.md`, in different lines (its `FIELD_OFFLINE` row and the Platform notes), so whichever merges second should merge cleanly. ## Testing From the root of a checkout of `windows/sclang-lookup`, with the daemon built by `pnpm build:native` (the full suite's daemon tests need it): ```sh pnpm install --frozen-lockfile pnpm typecheck pnpm exec vitest run src/generators/supercollider.test.ts pnpm test project check ``` You should see a clean typecheck, `Tests 11 passed (11)` for the lookup tests, the full suite passing (995 passed and 1 skipped on macOS here), and `Project plans are valid.` The lookup tests are what would show the change wrong: a failure in any test whose name mentions Windows means `sclang.exe`, a native `FIELD_SCLANG`, or the Program Files fallback is not found. Against `main`'s lookup, every Windows test fails. Nothing here can be exercised by hand on macOS. The `windows` CI job runs the same tests natively on Windows. A by-hand check on a Windows machine with SuperCollider installed is `field keys` or `field build` on a project with a `supercollider:` entry, which should find `sclang.exe` with no `FIELD_SCLANG` set. The commands leave the checkout unchanged. <!-- projector-summary v=1 sha=d1169c1d93a915b25bd10f61bb2ebd1d67ef76d7 --> 📽️ **Projector summary** of d1169c1: https://field.amnes.ac/reviews/186
The first chunk of the keyboard-instrument plan made the computer keyboard a MIDI source, but Field still had no way to play its own instruments from notes: a SuperCollider instrument could only render offline from a spec. This chunk, stacked on #178, adds
field keys <instrument>, which plays an instrument from theshared/instruments/shelf live, from the keyboard and from every other MIDI source, so you can audition how a sound responds under your fingers.The instrument plays through a voice host:
sclangrunning Field'ssc/voice-host.scd. The host boots its ownscsynthon the output device at the device's current rate, loads the instrument's voice, and plays one voice per note, with the sustain pedal, All Notes Off, and pitch bend. An instrument opts in with a voice mode beside its unchanged render mode: underFIELD_MODE=voiceits value is a SynthDef withfreq,amp,gate, andout.still-water-padinexamples/bloomnow answers it, and its render branch still renders the same bytes for seed 90210. The voice's sound goes straight to the device besidefield play's, until live-supercollider putsscsynthin the session graph.Running the host on real hardware found that the plan was wrong about one thing. On macOS
scsynthopens the default input device even with no input channels, and opening it waits on the microphone permission, so a host started from a process that cannot ask never becomes ready, and one started from a terminal would show a microphone prompt for a keyboard instrument. The host now names one device for both directions, andfield-audiod --keysreports the system output's name for when--deviceis absent. Plan §10.1 records the evidence, and §2.6 is corrected.The rest keeps the host from outliving
field keysor hiding its failures. The host watches its own boot, because SuperCollider 3.14'swaitForBootnever reports a server that exits while it boots, and it fails naming the device when that happens or after 20 seconds. It checks the device name before boot, refusing onescsynthwould not find (which would open the microphone) and one with characters that would reach the shell that startsscsynth. It ignores notes until its server answers.field keyschooses thescsynthport so it can send/quititself, the host reports each server's process so a booting server can be stopped by process too,Esccloses a host that is still booting, the host quits oncefield keysis gone, and a device whose rate moves under the host restarts its server rather than leaving every note sharp or flat. An instrument without a voice mode, such ascreek-kit, stopsfield keyswithcreek-kit.scd does not answer FIELD_MODE=voiceand the output that explains why.sclangis now found in one place,sclangCommand(), for renders and the host alike.Testing
Run these from the repository root of this branch, with SuperCollider installed and the daemon built (
pnpm build:native), since this layer changesfield-audiod.pnpm install --frozen-lockfile pnpm build:native pnpm typecheck pnpm testpnpm testpasses, includingsrc/keys/voice-host.test.ts, which runs the host's protocol against a stubsclangand needs no SuperCollider, and the native round trip, which now also checks the ready line'soutputfield on macOS. When I ran them on this head, the suite passed 903 tests with none skipped, and typecheck was clean.Then check that the pad's render did not move. From
examples/bloom, withfieldon yourPATH:cmpprints nothing. I ran the same render on this file before and after the edit, and the two files were identical. Any difference means the voice-mode edit changed the render branch. The commands leave the four files in/tmp.Then play it, in Ghostty or iTerm2, from
examples/bloom:The status line shows
still-water-pad starting, thenstill-water-pad live at 48000 Hz on <your output>within a few seconds. Play a chord: you hear the pad. HoldTaband release the keys: the notes ring until you releaseTab. Hold2over a sounding note: it bends up two semitones and returns on release.Escstops everything, andpgrep scsynthfinds nothing left. A microphone prompt, a host that never goes live, or anscsynthleft running means the change is wrong.field keys creek-kitexits 1 namingFIELD_MODE=voice.What I could not run: every check that makes sound. I ran the host on this Mac with a silent voice and heard a note start and end a voice through CoreMIDI, started
still-water-pad's voice live without playing it, sawcreek-kitrejected, and killed the parent to seesclangandscsynthexit within three seconds. Plan §10.3 lists what was verified and §10.4 what is owed: criteria 21 to 26 by ear, including the rate restart, which needs a device whose rate moves.📽️ Projector summary of b35267b: https://field.amnes.ac/reviews/179