Skip to content

Record the keys: MIDI takes rendered through their instrument (keyboard-instrument.md chunk 4) - #182

Merged
ninjudd merged 17 commits into
keys/chunk-3from
keys/chunk-4
Oct 11, 2026
Merged

ninjudd merged 17 commits into
keys/chunk-3from
keys/chunk-4

Conversation

@ninjudd

@ninjudd ninjudd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

field keys lets you play an instrument, but until now nothing you played could be kept: the moment you found a part, it was gone. This last chunk of the keyboard-instrument plan, stacked on #181, records it. Give a track's record entry an instrument, run field record against the song as you would for a vocal, and the take lands as the notes you played. The build then renders those notes through the instrument, where you played them in the song.

The design is the one the plan's §12 settled, building on the audio recording already in Field rather than beside it. A MIDI take is a transaction like an audio take, lands in the same takes.yaml with chosen, is placed by the same arithmetic, and is picked with the same field choose. It differs only where it must. The daemon arms for MIDI instead of an input: it opens every MIDI source and stamps each message on the audio callback's clock, so the take lines up with the song as an audio take does. The take lands as a small text file of notes, audio/<track>/<take>.notes.yaml, pinned in the song's ledger, and its row carries sources where an audio row carries device and input. Its latency is the output latency alone, because you play in time with what you hear. The build mints a voice-render node for the chosen take, which runs Field's own sc/voice-render.scd. That script plays the instrument's voice from the notes with sc/voicer.scd, the same voicing field keys plays live, so sustain and pitch bend sound as they did while you played. The notes file, the instrument, and both scripts key the cache, so editing the instrument re-renders every take recorded for it.

The kinds stay apart. A take of the other kind than its entry records will not land, and field check treats a mismatch or an instrument with no program as an error. field record refuses --input, --device, and --loop on a MIDI entry before it touches the daemon. The canonical spelling is instrument: on its own line under record:, which is what field fmt writes.

The daemon's half came from a parallel branch as three commits, c9ce60f, 6341242, and 9025aad: arming for MIDI, the take.midi.ndjson transaction with recovery, and the protocol with its daemon tests and docs. docs/keys.md gains "Record what you play"; tracks.md, project-model.md, build-graph.md, architecture.md, and audio-engine.md describe the entry, the take, the render node, and the capture. The plan records the chunk as built in §13, with criteria 30 to 36. The criteria that need ears are still owed, so the plan stays in-progress.

Testing

From the repository root of this branch, with the native helper built (pnpm build:native) and SuperCollider installed:

pnpm typecheck
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test
project check

You should see the typecheck pass, 929 passed | 1 skipped, and Project plans are valid. The skip is the no-MIDI-source refusal, which runs only where there is no MIDI service. The tests that cover this chunk:

  • src/commands/land.test.ts (the MIDI cases): a take landed on a track placed at bar 5 sits at sample 48000 with latency 128, the output's alone, and the notes file, row, and ledger pin are exact.
  • src/generators/voice-render.test.ts: the render's cache inputs, and a real-sclang render that is the same bytes from a cold cache.
  • src/commands/record-midi-daemon.test.ts: field record end to end through the null output with a source the helper publishes.

A failure in the last one that reads cannot create a virtual MIDI source after retries means CoreMIDI is refusing sources outright, not the brief refusal plan §13.2 describes. If the Mac sleeps during the suite, every test running at that moment times out together; run it under caffeinate -s -i, as I did.

To try it by hand without sound, in a scratch project (field init, field song create creek, copy examples/bloom/shared/instruments/still-water-pad.scd into shared/instruments/, then create a played track whose record entry has instrument: still-water-pad):

  1. Publish a source with native/audiod/build/field-audiod_artefacts/Release/field-audiod --keys "Field Keys Verify", or run field keys still-water-pad, which plays aloud.
  2. In another terminal, from the scratch project, run FIELD_AUDIOD_NULL=1 field record creek/track:played --at 1.2.1. Send a few notes (in field keys, type them), then press Ctrl-C.
  3. Run field record --list, then field build creek.

I ran exactly this with a script sending two notes. Expect armed MIDI from Field Keys Verify, then recording take-… from 1.2.1 (0:00.5), then take creek/played ← take-… at bar 1.2, chosen (audio/played/take-….notes.yaml, 2.3 s, 4 events). The notes file holds one row per note, timed to within 5 ms of when they were sent. field build creek builds //songs/creek/gen:played and the track over it. A take with no .notes.yaml, or gen:played missing from the build, means the MIDI path did not run. The run leaves the scratch project with the take, its ledger row, and .field/out/ renders; nothing outside it changes. Criteria 30, 31, 35, and 36 still need a real output device and ears: record with field keys still-water-pad playing, then field play creek.

📽️ Projector summary of 98ca869: https://field.amnes.ac/reviews/182

sc/voicer.scd holds the rules between MIDI and voices: one voice per sounding note, the sustain pedal, All Notes Off, and pitch bend on every sounding voice. The live host now drives it with callbacks that start and gate Synths, and sc/voice-render.scd drives it with callbacks that write a Score, then renders the score in NRT under the sc-render contract. A take therefore renders with exactly the voicing it was heard with while it was played. Two renders of the same events through still-water-pad are byte-identical.
§12 answers §7 questions 1 to 3 with the recommendations §7 made, recorded as decisions with the alternatives they beat: a MIDI take lands as a text list of notes, a record entry with an instrument records MIDI, and Field's renderer builds the score with the shared voicer. It also designs MIDI capture in the daemon, its protocol, the flow, and the files.
A record entry may now name an instrument, which makes it record MIDI (keyboard-instrument.md §12.2). Its takes rows carry sources in place of an audio take's device and input. src/schema/notes.ts holds the notes file (§12.1): its schema, pairing the daemon's captured messages into notes, the one writer of its bytes (a row per note, so a take diffs line by line), and the time-ordered event list the offline renderer reads.
…ument

The voice-render generator renders a notes file through an instrument in NRT with sc/voice-render.scd (keyboard-instrument.md §12.3), for the take's length plus a 4-second release tail, at the rate the graph gives it. Its key holds the notes file through its ledger hash, and the instrument program and both harness scripts by content hash, so editing any of them re-renders. runScProgram takes extra environment for it, and supercollider.ts now holds the instrument rule (instrumentProgram) and the path to Field's sc/ scripts (scScript), which the voice host shares. The graph does not mint the node yet.
…on the callback's clock, and write take.midi.ndjson transactions (keyboard-instrument.md §12.4)
…beside the audio one, and a daemon test against a published source
land.ts splits landing into what every take shares (the checks, the record node, the ledger, the placement on the track, the musical position, and the takes.yaml write) and what each kind adds. landMidiTake pairs the captured messages into a notes file, writes it with its one writer, pins it in the ledger with no WAV facts, and writes a row with the MIDI sources and the output latency alone (keyboard-instrument.md §12.1, §12.2). A take of one kind refuses to land on an entry of the other. landAnyTake picks by the manifest.

field record arms for MIDI when the target's record entry names an instrument, refuses --input, --device, and --loop there, and shows the events caught instead of a level meter. Every landing path (the take event, stop, the recordings fallback, --recover, --land) lands either kind.
…strument

The graph mints a voice-render gen node for a record entry with an instrument whose chosen take is a MIDI row, at the track's rate, and withTakes places that render where the take was played (keyboard-instrument.md §12.3). field check refuses an instrument with no program, and a take of the other kind than its entry records. field record's landed line counts a MIDI take's events, and its help marks --input, --device, and --loop as audio-only.

Tests: landing a MIDI take by hand (placement, the notes file, the row, the ledger pin, the kind checks); the voice-render node's inputs and cache, plus a real-sclang render that is identical every time; and field record end to end through the daemon with a published source. The daemon test's publish retries a refused source on macOS, which CoreMIDI does for a moment after the file's earlier tests kill their helpers and daemons.
…'s dropped count

field fmt writes instrument: on its own line under record:, as for a supercollider: entry, so the tests and the landing error use that form. For a MIDI take, dropped counts messages lost before they reached the take, so field record says that, and what a lost note-on or note-off does to the notes.
keys.md gains Record what you play; tracks.md and project-model.md describe a record entry with an instrument, the notes file, and the MIDI takes row; build-graph.md describes the voice-render node and no longer says voice mode never enters the build; architecture.md notes MIDI capture in the daemon and the take's render. The plan's §12.2 example takes the block form, and §13 records chunk 4: criteria 30 to 36, what implementation settled, what was verified, and what is still owed by ear.
A MIDI transaction writes lines, not frames, so its frames_on_disk is always 0; the list now counts its events, and adds its samples and seconds once it is complete. The plan's §13.3 adds the second take and field choose to the by-hand run.
@ninjudd
ninjudd added this pull request to stack #180 October 11, 2026 01:01
@ninjudd ninjudd changed the title keys/chunk 4 Record the keys: MIDI takes rendered through their instrument (keyboard-instrument.md chunk 4) Oct 11, 2026

@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.3 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 48m 12s

This pull request finishes the keyboard-instrument plan by recording what you play. A record: entry that names an instrument: arms field-audiod for MIDI, which stamps each message on the audio callback's clock into take.midi.ndjson. field record lands that as a pinned <take>.notes.yaml with a sources row, and the build renders the chosen take through sc/voice-render.scd and sc/voicer.scd, the voicing it now shares with the live voice host. The plan settles §7 questions 1 to 3 in §12 and records the chunk as built in §13. The by-ear criteria 30, 31, 35, and 36 are still owed, so the plan stays in-progress.

8 finding threads: 0 resolved, 8 open

Covered 37 of 37 changed files; none are generated.

Disclosures

  • What ran. These commands ran in a scratch worktree at this head:

    • pnpm install --frozen-lockfile, then pnpm typecheck, which passes.
    • A native build of field-audiod from a copy of the JUCE sources, with no warnings from Field's own sources.
    • vitest on src/schema/notes.test.ts, src/commands/land.test.ts, and src/generators/voice-render.test.ts: 26 pass, including the render through real sclang.
    • The daemon tests src/commands/record-midi-daemon.test.ts, record-daemon.test.ts, and punch-daemon.test.ts against that build: 21 pass and 1 skips. The skip is the no-source refusal, which runs only on Linux without ALSA.
    • The existing tests around the changed code, in src/graph, src/model, src/schema, src/generators, src/keys/voice-host.test.ts, and src/commands/choose.test.ts: 410 pass.
    • project check: the plans are valid.

    The full pnpm test suite did not run.

  • Reproductions. Four throwaway tests back the threads below. They ran in the scratch worktree and are deleted. They covered a zero-length note rendered through sclang, voicer.clear run in sclang, a daemon killed 200 ms after a note, and the voice render's output per score bundle.

  • What did not run. Nothing played through a real output device, and field keys, field record, and field play were not run by hand. So no one listened to the by-ear criteria or to criterion 25's rate restart. The restart finding comes from running the voicer in sclang. The punch-out finding comes from reading the daemon, not from a run. The daemon tests armed for MIDI, which opens every MIDI source on this machine for reading.

  • Dependencies. None added or changed.

Readiness gate

The plan is in-progress, and this change edits it, so it owns every question it settles. §12.1 to §12.3 answer §7 questions 1 to 3 as decisions, each with the alternative it beat. Question 1's answer leaves out the MIDI export that its recommendation included, which is a thread. §13.4 explicitly defers editing a notes file by hand. Questions 4 to 8 predate this change, and it leaves them unchanged. Questions 4, 5, 6, and 8 are deferred, and question 7 (layers) waits on Justin's call. These are noted here rather than threaded.

Suggestions

  • native/audiod/src/player.cpp:1566: the stop waits for one more block to begin, but callbackEpoch advances before that block drains MIDI, so a detach can land in between. Count the epoch after the MIDI drain, or wait for two epochs, so the comment's guarantee holds.
  • native/audiod/src/player.cpp:1300: arming opens the MIDI sources that exist at that moment, so a source started or restarted mid-take, such as a restarted field keys, records nothing. Say "at arm" in docs/keys.md and docs/audio-engine.md, or open new sources as they appear.
  • src/generators/supercollider.ts:131: execFile keeps Node's 1 MiB maxBuffer. A voice render prints about 20 bytes of nextOSCPacket per score bundle, so a take past about 52,000 bundles fails with a message that says sclang timed out. Raise maxBuffer, or quiet scsynth in sc/voice-render.scd.
  • src/schema/record.ts:80: the union of two strict schemas reports a broken audio row as Invalid input at takes.0 instead of naming the field. Pick the branch by the presence of sources before parsing.
  • src/commands/record.ts:144: --console-preset and an explicit --monitoring are dropped without a word on a MIDI take. Refuse them with --input, --device, and --loop.
  • src/commands/land.ts:296 and src/commands/land.ts:338: the two landing paths repeat the write, the hash, the size, and the row's shared fields. Move them into a helper on Landing.
  • sc/voicer.scd:7: the header lists three callbacks, but the function also takes an optional fourth, onVoice.
  • src/commands/record.ts:140: "whose takes stay audio-only under a loop" reads as if MIDI takes were audio. Say that loop takes record audio only.
  • src/audiod/protocol.ts:166: events is a count, so it has no rate.
  • src/commands/record-midi-daemon.test.ts:338: the note-off goes out after the take has ended, so the until case never exercises the filter it names. Send messages across until and assert that every recorded at is below it.
  • src/generators/voice-render.test.ts:129: the render's placement is checked only by a file-exists assertion in a case that skips on CI. In the stub-runner block, assert that the track plans gen:keys with a non-zero start and latency.
  • src/commands/record-midi-daemon.test.ts:39: every run sends channel 16 note 7, so two runs on one machine read each other's notes. Derive the note from process.pid.
  • src/commands/record-midi-daemon.test.ts:506: / [2-9]\d* events / never matches 10 to 19 or 100 to 199 events. Parse the number and compare it.
  • docs/projects/keyboard-instrument/readme.md:1014: §12 says it answers questions 1 to 3 "with the recommendations §7 made", but §7 made no recommendation for question 2.
  • docs/projects/keyboard-instrument/readme.md:461: §2.7 step 4 still has the voice host build the score, where §12.3 has sc/voice-render.scd do it.

Comment thread sc/voice-host.scd Resolved
Comment thread src/schema/notes.ts Resolved
Comment thread native/audiod/src/player.cpp Resolved
Comment thread native/audiod/src/capture.cpp Resolved
Comment thread src/model/project.ts Resolved
Comment thread sc/voice-render.scd Resolved
Comment thread .github/workflows/ci.yml Resolved
Review of #182 (P1): Event inherits a real clear from Set, and a real method runs before an Event's own entry of that name, so the host's restart emptied the voicer instead of forgetting its voices, and field keys was silent after a rate change. src/keys/voicer.test.ts plays through real sclang across forgetVoices.
…the supercollider path rule, and hide the render variables from the voice

Review of #182. renderEvents ranks a note's off with the ons when the note ends where it starts, so the voice it starts is released; voice-render's version is 2 so cached renders are redone. field check resolves the instrument through the voice-render generator's validate, as a supercollider: source resolves, which refuses a path outside the project and a directory. sc/voice-render.scd unsets the render variables before it loads the instrument, so voice mode is the same in a render as live.
Review of #182. until and the start are bed samples, and the take's clock counts the device's, so the span between them converts by the two rates; a 24 kHz bed on the 48 kHz null device now ends a half-second until after 24000 frames, not 12000. MidiCapture::drain flushes what it wrote every 20 ms tick, so a daemon that dies loses at most a partial last line, as recover promises; the recovery test now sees the note-on in the file within 500 ms. Both assertions fail against the previous daemon.
Review of #182. The CI comment counted one always-skipped sclang case; there are now four, in build.test.ts, voice-render.test.ts, and voicer.test.ts. The plan's §12.1 says field export writing a Standard MIDI File is deferred, not dropped, and how a take reaches Logic until then; §7 question 1 and §13.4 say so too, criterion 34 quotes the new check message, and §13.2 records what the review settled.
… buffer, shared landing helpers, and sturdier tests

From the suggestions on the first review of #182. A MIDI stop waits two callback epochs before it detaches, because the epoch advances before a block drains MIDI, so one epoch let the detach skip the drain. runScProgram allows sclang 64 MiB of output, since scsynth prints a line per NRT bundle and a long take outgrew Node's 1 MiB. Both landing paths place their file and share the row's fields through helpers on Landing. The MIDI daemon test sends a note chosen by its pid and parses the event count, and a stub-runner case checks a MIDI take's render is placed at its start less the output latency. The docs say a take hears the sources that exist when it arms; comments, plan §2.7 step 4, and §12's opening are corrected.

@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.3 · model claude-opus-5-5 · effort xhigh · CLEAN · took 54m 40s over 2 heads

This pull request finishes the keyboard-instrument plan by recording what you play. A record: entry that names an instrument: arms field-audiod for MIDI, which stamps each message on the audio callback's clock into take.midi.ndjson. field record lands that as a pinned <take>.notes.yaml, and the build renders the chosen take through sc/voice-render.scd with sc/voicer.scd, the voicing it shares with the live voice host. Since the review of 8a11f14, five commits fix all eight findings from that review and take twelve of its fifteen suggestions. The by-ear criteria are still owed, so the plan stays in-progress.

8 finding threads: 8 resolved, 0 open

Covered 38 of 38 changed files; none are generated.

Disclosures

  • What ran. These commands ran in a scratch worktree at this head:

    • pnpm install --frozen-lockfile, then pnpm typecheck, which passes.
    • A native build of field-audiod from a copy of the JUCE sources, with no warnings from Field's own sources.
    • The tests this pull request adds or changes, against that build: src/schema/notes.test.ts, src/keys/voicer.test.ts, src/commands/land.test.ts, src/generators/voice-render.test.ts, and the three daemon test files.: 51 pass and 1 skips. The skip is the no-source refusal, which runs only on Linux without ALSA.
    • The existing tests around the changed code, in src/graph, src/model, src/schema, src/generators, src/keys/voice-host.test.ts, and src/commands/choose.test.ts.: 413 pass.
    • project check: the plans are valid.

    The full pnpm test suite did not run.

  • Reproductions. The first review's three throwaway reproductions ran again at this head and were deleted afterwards:

    • The voicer. It still starts a voice after forgetVoices, and none of its entry names is a real method on Event.
    • A zero-length note. It renders on, then off, and leaves the tail silent.
    • A crash. A note-on is on disk 200 ms after it was sent, before the daemon is killed.
  • What did not run. Nothing played through a real output device, and field keys, field record, and field play were not run by hand. So the by-ear criteria and criterion 25's rate restart were not heard. The daemon tests armed for MIDI, which opens every MIDI source on this machine for reading.

  • Dependencies. None added or changed.

Readiness gate

The plan is in-progress. §12.1 to §12.3 answer §7 questions 1 to 3. §12.1 now defers the take's MIDI export, field export writing a Standard MIDI File, and names what triggers it. §13.4 lists it beside editing a notes file by hand. Questions 4 to 8 predate this change, and it leaves them unchanged.

Suggestions

These three suggestions from the first review still apply.

  • src/schema/record.ts:80: the union of two strict schemas reports a broken audio row as Invalid input at takes.0 instead of naming the field. Pick the branch by the presence of sources before parsing.
  • src/commands/record.ts:144: --console-preset and an explicit --monitoring are dropped without a word on a MIDI take. Refuse them with --input, --device, and --loop.
  • src/commands/record-midi-daemon.test.ts: in "ends at until", the note-off goes out after the take has ended, so the case never sends a message the until filter has to drop.

What was checked

  • The voicer survives a restart. Its reset is forgetVoices, and restart in sc/voice-host.scd calls it. Run in sclang, none of the voicer's entry names is a method on Event, and a note plays after the reset. src/keys/voicer.test.ts covers this through real sclang.
  • A zero-length note releases. renderEvents ranks a zero-length note's off with the ons, so the off sorts right after its own on. A same-instant retrigger still ends the first voice before the second starts. voiceRenderGenerator.version is 2, so cached renders are redone.
  • until counts in the device's samples. recordMidiBlock scales the span from take.timelineRate(), the live session's rate or the file's, to the device's rate. The daemon test's 24 kHz bed on the 48 kHz null device ends at 24000 frames.
  • A crash keeps what was written. MidiCapture::drain flushes after each write, which makes the claims in capture.h, plan §12.4, and docs/audio-engine.md true.
  • The instrument resolves by the supercollider: path rule. field check calls the render's validate with resolveAssetFile, and validate adds the normalized-form check the supercollider: rule makes. land.test.ts covers a missing program, a path that escapes the project, and a directory.
  • Voice mode looks the same in a render. sc/voice-render.scd unsets the five render variables before it loads the instrument. A real-sclang case renders through an instrument that throws if any of them is set.
  • The CI comment counts the sclang skips correctly. The comment names the one case in build.test.ts, the two in voice-render.test.ts, and the one in voicer.test.ts. sclangCommand() throws when nothing is found, so the voicer case skips on the runner.
  • The plan defers the MIDI export. field export creek/gen:keys, which the plan names as the way to Logic until then, resolves through the same song-relative labels field play takes.
  • The suggestions this head took. These hold at this head:
    • The stop. It now waits two callback epochs, and the callback runs one block at a time, so the block that drains the last messages finishes before the detach.
    • The sclang output buffer. runScProgram allows 64 MiB of output.
    • The landing helpers. placeFile and sharedRow write the same paths and row fields as before.
    • Tests and docs. The daemon test derives its note from the pid and parses the event count. The new placement case checks the render at its start less the output latency. The docs say a take hears only the sources present when it arms.

@ninjudd
ninjudd marked this pull request as ready for review October 11, 2026 03:03
@ninjudd
ninjudd merged commit f80efb6 into main Oct 11, 2026
1 check passed
@ninjudd
ninjudd deleted the keys/chunk-4 branch October 11, 2026 03:19
ninjudd added a commit that referenced this pull request Oct 11, 2026
…ame the pad, and keep the notes last (#183)

Trying the keyboard instrument after #178 to #182 merged turned up five
things, and this pull request collects the fixes from that testing.

First, `field keys bass` in `examples/bloom` printed only that
`shared/instruments/bass.scd` did not exist, which leaves you guessing
at what the names are. A name that is not on the shelf now lists what is
there, split into the instruments that play from notes and those that
only render. The split reads each program's text for `FIELD_MODE`: a
program that never reads it cannot answer voice mode, so its text is
enough to tell, without starting `sclang` once per program. Directories
and files that are not `.scd` are left out. Outside a project, a bare
name still fails as before, because there is no shelf to list.

Second, `still-water-pad` was the only instrument you could play.
`examples/bloom` now has two more, `juno` and `bass`, both the JU-06A
from [okamnesiac/offset](https://github.com/okamnesiac/offset)
(`patches/ju06a.scd`), a model of the Roland Juno's chain: DCO (saw,
pulse, sub, noise), high-pass, resonant low-pass, VCA, and a BBD-style
chorus under one ADSR. `juno` is set to offset's classic Juno pad from
`sessions/juno.scd`, and `bass` to the bass that patch's factory makes,
which is the bass synth we built there. Each answers `FIELD_MODE=voice`
with a SynthDef under the voice contract, at true pitch, and otherwise
renders a short demo under the sc-render contract, so it also works as a
`supercollider:` source: `juno` a held C minor ninth, `bass` offset's
line. Each program carries its own copy of the graph, because a
program's bytes are the cache key for what it renders, and a shared file
loaded at run time would not re-key the renders that used it.

Third, `still-water-pad` is now `pad`, so `field keys pad` reads like
`field keys juno` and `field keys bass`. Its SynthDefs are `padKey` and
`padVoice`, and with seed 90210 and 10 s it renders the same bytes
`still-water-pad.scd` did on main. The `pad-sc` track, both READMEs, the
docs, and the plan follow; the plan's verification rows keep the old
name, because the runs used it.

Fourth, playing moved the status line around: the notes sat in the
middle, so everything after them shifted with every key. The notes are
last now, and a narrow terminal shortens the text before them, never the
notes. The `Playing … Esc or Ctrl-C quits.` line is gone, and an
instrument's state, such as `juno live at 48000 Hz on MacBook Pro
Speakers`, has the first line to itself, redrawn in place only when it
changes.

Fifth, the keymap reload test failed now and then under load. A watch
just started can lose a directory event outright, not only see it late,
so the test saves again every 500 ms until each reload arrives; a save
of text already loaded reloads nothing, so a repeat never adds one.
Sixteen concurrent runs of the file pass.

`docs/keys.md` shows the new listing and names the three playable
instruments.

## Testing

From the repository root of this branch, after `pnpm install`, with
SuperCollider installed:

```sh
pnpm typecheck
pnpm exec vitest run src/keys/voice-host.test.ts src/keys/keymap.test.ts
cd examples/bloom
../../node_modules/.bin/tsx ../../src/cli.ts keys organ
../../node_modules/.bin/tsx ../../src/cli.ts sc render shared/instruments/juno.scd --seed 1 --duration 4 --output /tmp/juno.wav
../../node_modules/.bin/tsx ../../src/cli.ts sc render shared/instruments/bass.scd --seed 1 --duration 4 --output /tmp/bass.wav
```

The typecheck passes, and the two test files pass 25 of 25. A program
named like `pad.v2.scd` lists under that whole name, which `field keys`
resolves. The `keys organ` command exits 1 and prints:

```
field keys organ: no instrument program at …/examples/bloom/shared/instruments/organ.scd
In shared/instruments/:
  plays from notes: bass, juno, pad
  renders only:     creek-kit, seven-eight-loop (no FIELD_MODE=voice branch; Field's docs/keys.md says how to add one)
```

`juno` or `bass` under "renders only", or no list at all, would mean the
change is wrong. Each render writes a 4-second stereo WAV; I measured
the chord at a -5.5 dBFS peak and the line at -9.4 dBFS, and a second
render with the same seed was byte-identical, in stereo and mono. A
clipped or silent file would mean the program is wrong. The renders are
left in `/tmp`.

To play them, from `examples/bloom` in Ghostty or iTerm2, run `field
keys juno` or `field keys bass`, with `field` built from this branch. I
could not listen here. In voice mode I rendered a recorded take of two
notes through each, through `field build` of a record entry with that
instrument: both sounded from the first note, peaked near -10.5 dBFS,
and fell silent one release time after the last note-off (1.5 s for
`juno`, 0.15 s for `bass`), so every voice frees itself.

The status line is covered by `src/commands/keys.test.ts`. I also ran
`field keys` and `field keys juno` in a pseudo-terminal that answers the
keyboard protocol: the first drew only the status line, ending `· C4 E4`
while two keys were held; the second drew `juno starting` above it, then
rewrote that line in place to `juno live at 48000 Hz on MacBook Pro
Speakers`. In a real terminal, the start of the status line should stay
still while you play; anything after the notes, or a second status line,
would mean the drawing is wrong.

I also ran the full suite with `FIELD_AUDIOD` pointed at a native build:
932 passed, 1 skipped (the no-MIDI-source case, which runs only without
a MIDI service).

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