Skip to content

Carry the voice host's audio into the daemon through FieldOut and a shared-memory ring (live-supercollider.md chunk 2) - #198

Merged
ninjudd merged 3 commits into
live/input-windowfrom
live/ring
Oct 11, 2026
Merged

ninjudd merged 3 commits into
live/input-windowfrom
live/ring

Conversation

@ninjudd

@ninjudd ninjudd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Chunk 1 (#196) taught the live session to carry an input up through every chain above its track, but nothing in the daemon could feed one: only --render-live, from a file. This is chunk 2 of the live-supercollider plan: the path that carries the voice host's audio into the daemon, so chunk 3 can point field keys at it and the "dry" note goes away.

The voice host runs its own scsynth, so the audio has to cross processes. Per the plan's decision, it crosses through a POSIX shared-memory ring: FieldOut, a small scsynth UGen, writes its two inputs into the ring, and the daemon reads it once per block. The daemon owns the ring. The new input op makes one under a name and answers its number, which is what FieldOut.ar(ring, left, right) takes, kept below 2^24 because every UGen input is a float. A session's input window of that name then reads it. input_close frees the name, while a session still reading the ring keeps it. status lists each open input's counters, and hello lists live-input.

FieldOut is GPL-3.0-or-later, with its own LICENSE in native/sc-fieldout, because it builds against SuperCollider's plugin interface, which is GPL. Justin chose to keep it in this repository on 2026-10-11, and the plan records that as §11. The rest of Field stays MIT. The daemon and the plugin share only native/ring/field_ring.h, an MIT header holding the layout and the writer's code, and nothing links across that line. The plugin's headers are vendored from SuperCollider Version-3.14.1, about 180 KB, so the build needs no network and pins the plugin API. pnpm build:native now builds the plugin after the daemon; it is skipped on Windows, which has no POSIX shared memory, and the daemon there answers input with that reason.

The daemon's reader, RingInput, is a small jitter buffer. It waits until it holds a block plus 256 frames, the block being the largest any call has asked for, so a block the session splits at a loop wrap reads against the same margin as a whole one; past a song's content the engine now renders a block whole rather than a frame at a time. It then plays one block per call. When the writer runs fast enough to hold twice that, it drops the oldest frames. When the writer stops, it plays what it has, counts an underrun, and waits to fill again. When nothing read for longer than the ring holds, so that the writer dropped frames, it skips what it held and starts at the present. Every ring is retired before the daemon's fast exit after hosting a plugin, which skips destructors. Both processes play on the same device, so drift should be rare, and the counters in status show it when it isn't. Whether 256 frames is the right margin is criterion 4's question, which needs the real device and waits for chunk 3.

Building it turned up one constraint for chunk 3, recorded in the plan and the plugin's README. At shutdown scsynth unloads its plugins before it frees the synths still running, so a FieldOut left running crashes scsynth on its way out; the voice host must free it first. src/keys/synthdef.ts writes SynthDefs and OSC directly, without sclang, because sclang has no FieldOut class and installing one would mean editing every user's class library. The tests use it now, and chunk 3's voice host will use it for its routing synth.

field upgrade status counts native/ring and native/sc-fieldout as daemon sources, beside native/audiod, because field-audiod includes the ring header and install.sh audiod builds FieldOut in the same build:native. Without them, a change to either reported audiod-current, and docs/install.md says so.

Testing

From the repository root of this branch, after pnpm install and pnpm build:native (the daemon changed, and it builds the plugin into native/sc-fieldout/build/plugins/):

pnpm typecheck
native/audiod/build/field-audiod_artefacts/Release/field-audiod --ring-selftest
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm exec vitest run src/audiod/live-ring.test.ts src/audiod/live-input.test.ts
pnpm exec vitest run src/install.test.ts
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test
project check

The typecheck passes. --ring-selftest prints {"ok":true}. The two focused files pass 9 of 9. install.test.ts passes 36 of 36, including the case that backdates every native/audiod source, then commits a ring header and a FieldOut source and expects audiod-stale to name each; with the old check it reports audiod-current. The full suite passes 1089 with 1 skipped (the no-MIDI-source case, which runs only without a MIDI service). project check passes with its standing site-workflow warning.

--ring-selftest runs RingInput against the writer in field_ring.h, the code FieldOut runs, interleaved the way two callbacks are, in four scenarios:

  • Steady: after priming, every frame plays once, in order.
  • A stopped writer: one underrun, then playback resumes from the frame after the last one played, with nothing lost or repeated.
  • A fast writer: frames are skipped to hold the level, and the reader never runs dry.
  • No reader: the ring fills to its 8,192 frames and the rest counts as dropped.

live-ring.test.ts covers the daemon:

  • The ops: input, the refusal of a duplicate or empty name, input_close, and status.
  • A session: one whose input names no open input is refused, and one that names an open input loads and plays.
  • FieldOut itself: where scsynth and the built plugin are installed, scsynth's non-realtime mode runs a sine through FieldOut into a ring the daemon made. The ring holds 8,192 frames with 39,808 dropped. A playing session then reads all 8,192, skipping the stale excess down to its level. That case is skipped where scsynth is missing, as on CI.

Any of these would mean the change is wrong: a failing self-test, a FieldOut: ring line in scsynth's output, a written count other than the capacity after the render, or a session that loads with an input nothing feeds. Nothing here plays through a real device. The tests leave nothing behind outside their temporary directories, and each ring is unlinked when its input closes or the daemon exits.

📽️ Projector summary of d1e80ab: https://field.amnes.ac/reviews/198

@ninjudd
ninjudd added this pull request to stack #199 October 11, 2026 16:22
ninjudd added a commit that referenced this pull request Oct 11, 2026
Every project plan opened with a `# Plan: …` heading. The prefix says
nothing the reader doesn't already know: each one lives under
`docs/projects/`, and the `project` command already labels it as a
project. Because Projector takes a project's title from its first
heading, the prefix also filled every row of `project list` and the
project site with the same word, which made the titles harder to scan.

This change removes the prefix from all 51 plans that had it.
`daw-features` never had one. Three headings started with an ordinary
lowercase word once the prefix was gone, so they now start with a
capital: "The UI, first version", "The TUI" and "Hosted plugins — AU and
VST3 as inserts". Headings that start with a name the docs keep
lowercase stay as they were: `bloom`, `prettier`, `src/engine` and the
backticked `field` commands.

Projector's own templates never add the prefix. It was a habit in this
repository, and new plans picked it up by copying the existing ones.
Once this merges, `main` has no plan left to copy it from.

This change covers only plans that already exist on `main`. Two open PRs
add new plans that still carry the prefix, because their authors copied
it from `main`: #185 adds `install` (`# Plan: Install and upgrade`) and
#202 adds `instrument-knobs` (`# Plan: Instrument knobs`). Each needs
the same one-line fix on its own branch. The other open PRs that edit
plans (#196, #197, #198, #201) change plan bodies but not headings, so
they merge cleanly on top of this.

## Testing

From the repository root, with nothing to build first:

```sh
grep -rn "Plan: " docs/projects
project list
project check
```

`grep` should print nothing. `project list` should show titles such as
`Arming` and `The UI, first version`. A title that still begins with
`Plan:` means a heading was missed. `project check` should print
`Project plans are valid.` It also prints a `site-workflow-outdated`
warning, which `main` already shows and which this change does not
touch. None of the commands change any files.

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 47m 24s over 2 heads

This head carries the voice host's audio into field-audiod. FieldOut, a new GPL-3.0-or-later scsynth UGen, writes stereo frames into a POSIX shared-memory ring that the daemon makes with the new input op. A live session's input window reads that ring once per block through RingInput, a jitter buffer that holds a block plus 256 frames. The change also vendors SuperCollider 3.14.1's plugin headers, adds src/keys/synthdef.ts to write SynthDefs and OSC without sclang, and records the license choice as plan §11. It leaves field keys unwired until chunk 3, and defers criteria 4 and 5, the added latency and an hour without a dropout, to the real device there.

3 finding threads: 0 resolved, 3 open

Covered 20 of 57 changed files; 37 vendored files skipped: the 36 SuperCollider headers under native/sc-fieldout/vendor/ and the GPL text in native/sc-fieldout/LICENSE, whose provenance is checked below.

The head moved from 63dffac to 2e68438 during this review, when the base branch was rebased. This pull request's own commit is unchanged (git range-diff shows the two as equal), and every check below ran again at 2e68438.

The full test suite did not run here, because it arms MIDI sources and starts voice hosts while a live field keys session was running on this machine; Linux CI ran it. Only isolated runs happened: null-output daemons in temporary projects, and the FieldOut test's scsynth in non-realtime mode, which opens no device. macOS has no command that lists POSIX shared-memory objects, so I probed every ring name the tests and reproducers opened, by shm_open, after they finished. None remained, apart from the one the hosting reproducer left behind, which I then removed.

Suggestions

  • native/audiod/src/ring_input.cpp:104: after a gap in reading longer than the ring, about 170 ms at 48 kHz, the writer has dropped the newest frames. A stopped transport, or a far locate that holds the session lock, makes such a gap. This skip then keeps a block plus 256 frames written when the ring filled and jumps to the present, which is the click criterion 5 rules out. Discarding everything held when dropped grew since the last read would start at the present. docs/audio-engine.md's "reads it every block" also holds only while the transport plays.
  • native/audiod/src/player.cpp:699: the ring's sampleRate, and the sample_rate the input op answers, are the device rate before any session loads. A session load that switches the device leaves both stale, so FieldOut on a correctly booted server warns falsely. In converted delivery the session reads the ring at its own rate, so a 44.1 kHz session on a 48 kHz device would play a 48 kHz voice about 8 % flat. Chunk 3 could take the rate from the session answer and refuse or convert a mismatch.
  • native/sc-fieldout/FieldOut.cpp:36: FieldOut neither sums nor checks its inputs. Two FieldOuts on one ring append their blocks one after the other, and a scalar or control-rate left or right makes next read a block from a one-sample wire. The README could say one FieldOut per ring with audio-rate inputs, or the constructor could check INRATE.
  • src/keys/synthdef.ts:57: pstring writes its length with writeInt8, which throws a RangeError for the 128 to 255 bytes that SuperCollider's unsigned length byte allows. writeUInt8 matches the 255 guard above it.
  • src/keys/synthdef.ts:122: this second exported oscMessage covers src/keys/voice-host.ts:35's, which is its no-argument case, so voice-host.ts can import this one.
  • native/sc-fieldout/FieldOut.cpp:12: the copyright line names "the Field authors", while the root LICENSE names Amnesiac, LLC. Naming the same holder keeps the GPL notice unambiguous.

Checked

  • Builds and tests at 2e68438: pnpm typecheck and project check pass, and field-audiod (JUCE 8.0.4) and FieldOut.scx build. field-audiod --ring-selftest prints {"ok":true}. live-ring.test.ts and live-input.test.ts pass 9 of 9, the FieldOut case included, which runs scsynth 3.14.1's non-realtime mode into a daemon ring. That case is the end-to-end check of synthDefFile, because no test round-trips a SynthDef through sclang. On CI, linux passes. Windows builds the daemon, configures FieldOut as skipped, and skips the ring tests, then fails twelve tests in voice-host.test.ts and record-midi-daemon.test.ts, the same twelve that fail at the base branch's head.
  • The ring: the writer's acquire load of read pairs with the reader's release store, and the reader's acquire load of written pairs with the writer's release store. The reader masks with its own capacity, so a garbled counter cannot index outside the data. Only the installed session reads a ring: a swap retires the old session under liveLock, and the warmup render reads no input, so read never runs on two threads.
  • Real-time safety: RingInput::read and FieldOut_next take no lock, allocate nothing, and make no system call. FieldOut's constructor and destructor call shm_open, mmap, and munmap on scsynth's audio thread once per synth, a cost the constructor's comment accepts.
  • Exposure: each ring is created with O_EXCL and mode 0600 under a random number below 2^24. No other user can open it, and the daemon never adopts an object someone else made. The input and input_close ops sit behind the same socket as every other op.
  • Latency against the plan: the reader holds a block plus 256 frames, 16 ms at a 512-frame block and 48 kHz, and corrects drift only past twice that. Criterion 4 allows one daemon block plus one device buffer, and the plan's progress entry defers that measurement to chunk 3.
  • Licensing: native/sc-fieldout/LICENSE is byte-identical to SuperCollider 3.14.1's COPYING, the standard GPLv3 text. The current gnu.org copy differs from it only in its links, which now use https. package.json still says MIT, which is right for the CLI it describes.
  • Vendored headers: all 36 files under native/sc-fieldout/vendor/supercollider/include/ are byte-identical to SuperCollider's Version-3.14.1 tag, the version of the scsynth the FieldOut test ran.
  • Plan gate: live-supercollider stays in-progress. This head adds §11 as a DECIDED record, an amendment to §2.2 that matches the built input op, and a progress entry. It opens no question: the progress entry defers the 256-frame margin and criteria 4 and 5 to chunk 3, and §7's three questions were already taken or decided.

Comment thread native/audiod/src/ring_input.cpp Resolved
Comment thread native/audiod/src/ring_input.cpp Resolved
Comment thread docs/architecture.md Resolved

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CLEAN · took 16m 23s

This head answers the three findings from the review of 2e68438. RingInput::read now measures its margin against the largest block any call has asked for, and renderBlock no longer steps one frame at a time past a song's content. The daemon retires every ring before its fast exit, and the README and docs/architecture.md name FieldOut's GPL-3.0-or-later terms and the ring. It also takes most of the suggestions: the reader starts at the present after a gap longer than the ring, FieldOut refuses inputs that are not audio rate, pstring writes an unsigned length, voice-host.ts uses synthdef.ts's oscMessage, and FieldOut's copyright names Amnesiac, LLC. The stale ring rate stays with chunk 3, as the plan's progress entry now says.

3 finding threads: 3 resolved, 0 open

Covered 23 of 60 changed files; 37 vendored files skipped: the 36 SuperCollider headers under native/sc-fieldout/vendor/ and the GPL text in native/sc-fieldout/LICENSE, unchanged since the last review checked them against SuperCollider 3.14.1.

A live field keys session was running on this machine, so this review ran nothing that arms MIDI, starts a voice host, or starts scsynth. That skips the full suite, the FieldOut case in live-ring.test.ts, and the voice-host process tests; Linux CI ran all three. macOS has no command that lists POSIX shared-memory objects, so I recorded every ring name the tests and reproducers opened and probed each by shm_open after they finished: none remained.

Suggestions

  • native/sc-fieldout/README.md:16: the edited paragraph's new line runs to 83 characters where the file wraps near 70. AGENTS.md asks a Markdown edit to match the wrapping around it.

Checked

  • The split-block margin: the reproducer from the last review, a steady 48 kHz writer into a null-output daemon, now gives no underruns after warm-up in each case. That covers playing past the content, which gave 311 underruns in five seconds at 2e68438, two runs of a 0.5 s loop whose wraps walk across the block, and a session with content to play. The new split and gap scenarios in --ring-selftest pass.
  • Rings at exit: the hosting reproducer, a daemon that opened an input, loaded a session with the fixture VST3, and quit, now leaves no ring, as the same run without the plugin does. closeInputs runs on the main thread after the connections drain. A session still playing keeps its rings mapped through their shared_ptr, so clearing rings there never unmaps what the audio thread reads.
  • Whole blocks past the content: the limiter and the filters process sample by sample, so a whole block renders the same samples as the one-frame steps it replaces. live-session.test.ts, live-input.test.ts, and plugin-hosting.test.ts, whose live renders must equal the offline ones byte for byte, pass at this head.
  • Builds and tests at fe1a020: pnpm typecheck and project check pass, and field-audiod (JUCE 8.0.4) and FieldOut.scx build. field-audiod --ring-selftest prints {"ok":true}. live-ring.test.ts, live-input.test.ts, live-session.test.ts, plugin-hosting.test.ts, render-daemon.test.ts, and the voice-host.test.ts cases that start no process pass, 70 tests with 9 skipped. The 9 are the cases named above.
  • CI at fe1a020: linux passes. Windows fails the same twelve tests in voice-host.test.ts and record-midi-daemon.test.ts that fail at the base branch's head, test for test; this head does not include main's Windows fixes yet.
  • The reader's new state: block and droppedSeen belong to the audio thread alone. A dropped count newer than the written the reader loaded only moves the skip to the next call.
  • FieldOut: the constructor checks for three inputs with audio-rate left and right before it opens the ring, and the README now says one FieldOut per ring.
  • Licensing: the README's License section and the Licensing paragraph in docs/architecture.md name FieldOut, its GPL-3.0-or-later terms, and the vendored headers. The IPC section names the ring.
  • Plan gate: live-supercollider stays in-progress. The progress entry records the review's fixes and defers the ring's rate to chunk 3, so this head opens no question.
  • Earlier findings: all three threads were resolved with the author's replies, and each fix holds at fe1a020 as above.

…hared-memory ring (live-supercollider.md chunk 2)

FieldOut, an scsynth UGen in native/sc-fieldout, writes its two inputs into a POSIX shared-memory ring the daemon makes. It is GPL-3.0-or-later with its own LICENSE, because it builds against SuperCollider 3.14.1's plugin headers, vendored beside it; the rest of Field stays MIT and shares only native/ring/field_ring.h, the layout and the writer, with it.

The daemon's input op makes a ring under a name and answers its number; a session's input window of that name reads it through RingInput, a jitter buffer that holds a block plus 256 frames, drops the oldest frames when the writer runs fast, and waits to fill again when it runs dry. input_close frees the name, status lists each input's counters, and hello lists live-input. --ring-selftest runs the reader against FieldOut's writer, and live-ring.test.ts runs FieldOut itself in scsynth's non-realtime mode into a ring a playing session reads. src/keys/synthdef.ts writes the SynthDef and OSC that test needs, which chunk 3's voice host will use too.
…t exit, and name FieldOut's license

RingInput sized its margin from each call, and a session splits a block at every loop wrap and, past a song's content, into single frames, so the reader skipped and ran dry. The margin now rests on the largest block asked for, and past the content a block renders whole. After a gap longer than the ring, the reader starts at the present instead of playing what the writer kept, counting the rest as skipped.

A daemon that hosted a plugin exits through _Exit, which skipped ~RingInput; it now retires every ring first. FieldOut refuses inputs that are not audio rate and names Amnesiac, LLC as its copyright holder; the README's License section, architecture.md's licensing paragraph, and its IPC section now describe FieldOut, its GPL terms, and the ring. synthdef.ts writes a name's length unsigned, and voice-host.ts uses its oscMessage.

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CLEAN · took 19m 45s

This head rebases the live stack onto main through d94b734. This pull request's two commits carry over unchanged (git range-diff shows both as equal), so its own diff against live/input-window is the one the review of fe1a020 found clean. The new base brings install.sh and field upgrade, main's Windows test fixes, the dropped "Plan: " heading prefix, and #196 rebased onto them; none of it changes a file under native/. This review reads the same diff against that base: the four files both sides change, and where the new installer meets FieldOut's build.

3 finding threads: 3 resolved, 0 open

Covered 23 of 60 changed files; 37 vendored files skipped: the 36 SuperCollider headers under native/sc-fieldout/vendor/ and the GPL text in native/sc-fieldout/LICENSE, unchanged since the first review checked them against SuperCollider 3.14.1.

A live field keys session was running on this machine, so this review ran nothing that arms MIDI, starts a voice host, or starts scsynth. That skips the full suite, the FieldOut case in live-ring.test.ts, and the voice-host process tests, which CI runs. The tests ran against the field-audiod built for fe1a020, because git diff fe1a020 {short_sha} -- native/ is empty. macOS has no command that lists POSIX shared-memory objects, so I recorded every ring name the tests opened and probed each by shm_open after they finished: none remained.

Suggestions

  • install.sh:364: audiod-stale compares the daemon against tracked files under native/audiod only, but field-audiod now also compiles native/ring/field_ring.h, and install.sh audiod now builds FieldOut through build:native too. After a change to the ring header alone, field upgrade status would still report audiod-current. Adding native/ring to that check, and naming FieldOut in docs/install.md's audiod row, would keep both accurate.
  • native/sc-fieldout/README.md:16: this line runs to 83 characters where the file wraps near 70. AGENTS.md asks a Markdown edit to match the wrapping around it.

Checked

  • Files both sides change: README.md's FieldOut paragraph sits in the License section, which main's rewrite of "Try it" leaves alone. docs/architecture.md's base change is the build-stamp paragraph, apart from the Licensing and IPC paragraphs this pull request edits. src/audiod/client.ts takes main's BUILD_DAEMON error text beside openInput and closeInput. The plan loses only its "Plan: " prefix.
  • The installer: install.sh audiod runs pnpm run build:native, which builds FieldOut after the daemon, configured as skipped on Windows. install.test.ts passes at this head.
  • voice-host.ts against main's test changes: voice-host.ts re-exports synthdef.ts's oscMessage, and main's voice-host.test.ts still imports it from there. Typecheck passes, and the test's cases that start no process pass.
  • Builds and tests at d2a0e58: pnpm typecheck and project check pass, and field-audiod --ring-selftest prints {"ok":true}. live-ring.test.ts, live-input.test.ts, live-session.test.ts, plugin-hosting.test.ts, render-daemon.test.ts, install.test.ts, and the voice-host.test.ts cases that start no process pass, 105 tests with 9 skipped. The 9 are the cases named above.
  • CI at d2a0e58: linux passes 1,065 tests with 24 skipped, and windows, whose base now includes main's Windows fixes, passes 975 with 114 skipped and no failures.
  • Earlier findings: the three threads stay resolved. The code that fixed them is byte-identical at this head, so the split-block margin, the ring cleanup at exit, and the license statements hold as the review of fe1a020 verified.
  • Plan gate: live-supercollider stays in-progress, and this head changes only its heading, so it opens no question.

… status

field-audiod now compiles native/ring/field_ring.h, and install.sh audiod builds the FieldOut plugin through build:native, but audiod-stale compared the binary against native/audiod alone, so a change to the ring header or to FieldOut still reported audiod-current. The check now reads all three directories, install.md's audiod rows say so and name FieldOut, and FieldOut's README paragraph rewraps to the file's width.

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CLEAN · incremental from d2a0e58 · took 1m 19s

Incremental review of the change since the full review of d2a0e58: +35 −11 lines in 4 files.

This push takes both suggestions from the last review. install.sh now marks audiod-stale for a tracked change under native/ring or native/sc-fieldout as well as native/audiod, docs/install.md says so and names FieldOut in the audiod row, and FieldOut's README rewraps the long line. I ran install.test.ts at d1e80ab: 36 of 36 pass, including the new case where a commit to the ring header alone, and then to FieldOut.cpp alone, turns audiod-current into audiod-stale. Typecheck passes.

@ninjudd
ninjudd merged commit cb55fa8 into main Oct 11, 2026
2 checks passed
@ninjudd
ninjudd deleted the live/ring branch October 11, 2026 19:09
ninjudd added a commit that referenced this pull request Oct 11, 2026
…ough FieldOut (live-supercollider.md chunk 3) (#201)

When you play a track with `field keys`, you should hear it the way the
song plays it, through the track's effects and the effects of every
track above it up to `main`'s limiter. Until now the voice played
straight to the device, and the line said "dry". This is chunk 3 of the
live-supercollider plan, the one you hear. It wires `field keys` to the
input path of #196 and the ring of #198, and makes the daemon play
inputs while the song is stopped.

When you name tracks, `field keys` asks the daemon for an input per
armed track, loads the song's live session with those inputs, and starts
the voice host with one ring per instrument. Each track gets a voice of
its own, even when two tracks share an instrument, because each voice
goes to its own ring. In the voice host, each routed instrument's voices
play into a private bus, and a route synth at the tail, `In` into
`FieldOut`, carries that bus into the ring. sclang has no `FieldOut`
class, and adding one would mean editing every user's class library, so
Field writes the route's SynthDef itself with `src/keys/synthdef.ts` and
the host loads it by file. An instrument named without a track still
plays straight to the device. When you quit, the inputs close and the
song loads again without them.

When routing isn't possible, the voice still plays straight to the
device, and the instrument's line keeps the dry note with the reason:
`FieldOut` not built, Windows, a daemon that predates live inputs,
tracks in two songs, `--device` naming a device other than the daemon's,
or a device the daemon has to convert the song's rate for. So a missing
build degrades to what the line already said, never to silence. The
voice host boots on the daemon's device, so the two share a clock, and
`FieldOut` reaches `scsynth` through `SC_PLUGIN_PATH`, beside its own
plugins.

A routed voice survives the rest of Field: `field play`, its `--watch`,
`field ui`, and `field record` compile in the open `keys:` inputs for
their song when they load it, and `field keys`' own loads keep the loop,
region, and solo another terminal set. An input closes on its own when
the connection that opened it drops, so a `field keys` that fails or is
killed leaves nothing open. Once the voice is live, `field keys` checks
that `FieldOut` is writing its ring, and otherwise marks the line dry. A
gain ramp on the routed voice glides on the overlay's own clock, so it
finishes while the transport is stopped.

With the transport stopped, the daemon now plays what the inputs reach,
as the plan's §7 question 2 settled. It runs a second instance of
`main`'s chain, so you play over silence while the song's own chain and
position stay where they were; pressing play hands the input to the
song's path. Each input now reports a `peak`, and `field-audiod
--ring-feed <ring> <file.wav>` writes a file into a ring at real-time
pace as `FieldOut` would, so an input can be checked without
SuperCollider.

Chunk 2 found that `scsynth` crashes quitting with a `FieldOut` still
running. Every way the voice host stops now frees its nodes first:
`field keys` quitting, the host's own restart for a new sample rate, and
the host noticing its parent has gone.

## Testing

From the repository root of this branch, after `pnpm install` and `pnpm
build:native`, which builds the daemon and `FieldOut`:

```sh
pnpm typecheck
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm exec vitest run src/keys/routing-voice.test.ts src/keys/routing.test.ts src/audiod/live-ring.test.ts src/keys/voice-host.test.ts src/commands/keys.test.ts
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test
project check
```

The typecheck passes. The five focused files pass, and the full suite
passes 1103 with 1 skipped (the no-MIDI-source case, which runs only
without a MIDI service). `project check` passes with its standing
site-workflow warning.

- **`routing-voice.test.ts`**, through real programs: a track is routed
into the daemon in null-output mode, the real voice host starts on
sclang and `scsynth` with `FieldOut`, and a note from a published MIDI
source reaches the track's input. The daemon reports a peak above 0.01
while the transport is stopped. It needs SuperCollider, the built
plugin, and an output device for `scsynth`, so it runs on a workstation
and skips on CI.
- **`routing.test.ts`:** `routeArmed` opens `keys:creek/bass` with a
ring, loads `creek` with it, and on close leaves no inputs and the song
loaded. It also says why when it can't route: tracks in two songs, or
`FieldOut` not built.
- **`live-ring.test.ts`:** a ring fed by `--ring-feed` while the
transport is stopped is read through the idle path at the sine's 0.25
peak. Where `scsynth` is installed, the route SynthDef carries a private
bus into the ring in non-realtime mode.
- **`voice-host.test.ts`:** the host receives `FIELD_RINGS`,
`FIELD_FIELDOUT`, and a route file that starts `SCgf`, routes nothing
when no instrument has a ring, and sends `/g_freeAll` before `/quit`.
- **`keys.test.ts`:** the instrument line drops the dry note when
routed, and gives the reason when not.

By hand, in `examples/bloom` with `creek`'s `bass` track given `record:
{instrument: bass}` and placed in `main`: `field keys creek/track:bass`
should show no dry note, and the bass should play through `main`'s
limiter. `field keys creek/track:main` should do the same. I couldn't
play it myself, because `field keys` needs a kitty-protocol terminal, so
criterion 3, hearing it, is yours. Any of these would mean the change is
wrong: a dry note with no reason, silence instead of the dry fallback,
or a crash report from `scsynth` after quitting. Criteria 4 and 5 (the
added latency, and an hour without a dropout) need the real device and
are owed by hand. A session swap under a playing input rebuilds the
overlay cold, a gap of the path's latency; §10 records that as accepted
for now.

<!-- projector-summary v=1 sha=b13d283245689e90b7215f1ec7eaa9aad88dcfa3
-->
📽️ **Projector summary** of b13d283: https://field.amnes.ac/reviews/201
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