Skip to content

Give field keys knobs: choose with the arrows, turn with up and down, and map them through each instrument's knob file (instrument-knobs.md chunk 1) - #209

Merged
ninjudd merged 8 commits into
mainfrom
knobs/turn
Oct 11, 2026

Conversation

@ninjudd

@ninjudd ninjudd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

field keys could change one thing about an instrument's sound while you played: the modulation wheel, in six fixed steps on keys 3 to 8. Everything else was fixed when the program loaded, so hearing juno with a darker filter meant editing juno.scd and saving. This change makes field keys a MIDI controller with knobs, as the first rollout chunk of the instrument-knobs plan (#202) describes. You choose a knob with the left and right arrows and turn it with up and down, faster the longer you hold. Every turn leaves field keys as a plain control change on Field Keys, so any instrument can answer it and a take you record keeps it.

An instrument describes its knobs in a knob file beside its program, juno.knobs.yaml beside juno.scd: each knob's name, controller, range, curve, step, units, and default. --knobs reads a knob file for an instrument field keys does not play, such as a hardware synth or an instrument in Logic. One zod schema, src/schema/knobs.ts, checks every knob file on every path that hands one to an instrument: field keys at start and on each save, and a take's render in its validate, which is also how field check reports it. A knob line between the instrument's line and the status line shows every knob at a fixed width, with the chosen knob in reverse video and a window that scrolls on a narrow terminal.

musical, Field's take on Logic Pro's Musical Typing, replaces musical-typing as the default keymap. It keeps every note and the octave, velocity, and sustain keys, puts the knobs on the arrows, and moves the bend to , and .. It leaves the number row free for chunk 2, which types a knob's value there. docs/keys.md gives Logic's number row as controls to copy into a keymap of your own.

On the SuperCollider side, the voicer hands every controller from 2 to 119 except sustain to the voices as cc<n>, from 0 to 1, as it already handed over the wheel as mod, and it knows nothing about knobs. A voice maps its controls itself. juno and bass read their ranges from the copy of their knob file that Field checked, which FIELD_KNOBS names, so each range is written once, the recommendation #202 merged with. A knob file can leave any knob out, and a voice then keeps that setting's fixed value. Their render branches keep their bytes.

Implementation settled a few things the plan left open, and §9 of the plan records them. The largest is that the copy a voice reads spells out every field with the defaults filled in, so a knob file can lean on the schema's defaults.

Typing a value and the glide come in chunk 2, and a take that starts where your knobs are comes in chunk 3. Both will stack on this pull request.

Testing

I ran these on macOS with SuperCollider 3.14.1, from the root of a checkout of this branch unless a step says otherwise. Build first:

pnpm install
pnpm build
pnpm build:native

pnpm build:native builds field-audiod and FieldOut into the checkout. Build them here: a daemon built before #196 fails the daemon tests with session version mismatch, which says nothing about this change.

  1. pnpm typecheck prints nothing and exits 0.

  2. pnpm vitest run reports 90 test files, 1171 tests passed and 1 skipped. A failure in src/schema/knobs.test.ts, src/keys/knobs.test.ts, src/keys/session.test.ts, or src/commands/keys.test.ts points at this change.

  3. pnpm vitest run src/keys/voicer.test.ts src/generators/voice-render.test.ts src/keys/routing-voice.test.ts runs through real sclang and passes 16 tests. routing-voice boots scsynth on your output device for a few seconds. If the voicer's cc<n> test fails, CC 74 does not reach the voices; if the render's knob-file test fails, a take's controllers do not reach the voice through its knob file. If the render of bloom's juno or bass from a knob file with cutoff alone fails with Message 'at' not understood, a knob file without one of their four knobs stops their voice from loading.

  4. From examples/bloom, node ../../dist/cli.js keys --keymap musical-typing exits 1 with no built-in keymap named "musical-typing" (built-ins: fourths, musical, tracker). node ../../dist/cli.js keys --print draws musical with K-1, K+1, R+1, and R-1 on the arrows.

  5. From examples/bloom, compare main's juno render with this branch's (criterion 19). Run the same with bass in place of juno:

    git show origin/main:examples/bloom/shared/instruments/juno.scd > shared/instruments/juno-main.scd
    node ../../dist/cli.js sc render shared/instruments/juno-main.scd --seed 1 --duration 4 --output /tmp/juno-main.wav
    node ../../dist/cli.js sc render shared/instruments/juno.scd --seed 1 --duration 4 --output /tmp/juno-branch.wav
    cmp /tmp/juno-main.wav /tmp/juno-branch.wav
    rm shared/instruments/juno-main.scd

    cmp prints nothing. Any output means the change touched a render branch.

  6. From examples/bloom, break juno's knob file under a track that records for juno (criterion 22), then put both files back:

    printf '  - record:\n      instrument: juno\n' >> songs/creek/tracks/keys.yaml
    sed -i '' 's/min: 50, max: 15000/min: 0, max: 15000/' shared/instruments/juno.knobs.yaml
    node ../../dist/cli.js check
    git checkout songs/creek/tracks/keys.yaml shared/instruments/juno.knobs.yaml

    field check exits 1 and names shared/instruments/juno.knobs.yaml: knobs.0.min: cutoff: an exp curve needs min and max of one sign and neither 0, not 0 and 15000. field build creek fails with the same line. Silence from field check means the render's validate no longer checks the knob file.

I also ran field keys --knobs with a one-knob file in a pseudo-terminal, with the real helper, sending the kitty protocol's bytes for ArrowRight, ArrowUp held for a second, and one ArrowDown. The knob line went from mod 0 cutoff 2.00 kHz to cutoff 4.27 kHz with cutoff in reverse video, at one width throughout, and the status line had no mod field.

What I could not run is everything that needs a kitty terminal and ears: criteria 1 to 3, 9, 11, 13, 15 to 17, and 12 and 18 up to their typed values. Start with node ../../dist/cli.js keys juno from examples/bloom in Ghostty or iTerm2. The knob line should read mod 0 cutoff 2.00 kHz res 0.300 attack 800 ms release 1.50 s, and holding ArrowUp on cutoff under a chord should open the filter, faster the longer you hold. A filter that does not move while the line does means the voice is not reading cc74. I also did not see a turn's MIDI through CoreMIDI: your field keys creek/track:main was running, so --midi-monitor "Field Keys" attached to its source and saw none of the test's messages. src/keys/session.test.ts pins what a turn sends and when.

📽️ Projector summary of 3204492: https://field.amnes.ac/reviews/209

… and map them through each instrument's knob file (instrument-knobs.md chunk 1)

field keys reads an instrument's knob file beside its program, and any
--knobs file, checks it with one schema, and shows every knob on a line
between the instrument's line and the status line. musical replaces
musical-typing as the default keymap: the arrows choose and turn, and
the bend moves to Comma and Period. A turn is a control change on Field
Keys, faster the longer the key is held, so any instrument answers it
and a take keeps it.

The voicer hands every controller from 2 to 119 but sustain to the
voices as cc<n>, and juno and bass map four knobs through the checked
copy of their knob files that FIELD_KNOBS names, live and in a take's
render. The render checks the knob file and hashes it as an input, so
field check and the build name a file that fails.

Co-Authored-By: Claude <[email protected]>

@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.7 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 29m 17s over 2 heads

This pull request makes field keys a MIDI controller with knobs, as chunk 1 of the instrument-knobs plan describes. A knob file names each knob's controller and range, one zod schema checks it on every path that hands it to an instrument, the arrows choose and turn knobs on a new knob line, and every turn leaves as a control change on Field Keys. The voicer hands controllers 2 to 119, except sustain, to the voices as cc<n>, and juno and bass map four knobs each through the checked copy that FIELD_KNOBS names, live and in a take's render. musical replaces musical-typing as the default keymap, and typing a value, the glide, and a take's starting positions are left to chunks 2 and 3.

1 finding thread: 0 resolved, 1 open

Covered 35 of 35 changed files. None is generated.

Disclosures

  • Reviewed by reading, without running the head's code. Both commits carry a Co-Authored-By: Claude <[email protected]> trailer, which makes GitHub list the login claude among their authors, and that login has read access to this repository, not write. A commit that names an author without write access withholds trust, so this review ran no test, build, or typecheck from the head, although project review setup recorded the head as trusted. The finding was verified by reading, and by a SuperCollider probe written for this review, with no server and no MIDI, which shows that indexing nil with ["min"] throws Message 'at' not understood. project check passes. Its two warnings, about AGENTS.md's Projector section and the site workflow, are on main too.
  • CI passes on this head. linux and windows both run pnpm typecheck, pnpm build, field check on examples/bloom, and pnpm test, where the tests that need real sclang skip, as they do on main. windows failed on the previous head, b4be562, and this head's only change makes the --knobs path test build its expected paths with join and resolve.
  • Criteria that need a kitty terminal and sound were not run here either. The Testing section lists them as owed.

Merging with main. main has not changed examples/bloom/shared/instruments/juno.scd since #188, so this branch's hunks in it apply to main without a conflict. They change the header comment (lines 7 to 10 at the head), the comment above ju06a (26 to 34), and the voice-mode branch (59 to 78), and they leave pad and the render branch alone.

Plan conformance

  • Scope. Everything §6 gives chunk 1 is here: knob files and --knobs, the knob line, choosing and turning, musical with the bend on , and ., the voicer's cc<n>, the checked copies, the render's check and cache input, field check, juno and bass, the docs, and the note at keyboard-instrument.md §3. Criteria 4 to 8, 14, and 23 belong to chunk 2, and 20 and 21 to chunk 3.
  • The checked copy. The voices read the copy that FIELD_KNOBS names, the option §3.2 recommends while recording that Justin has not ruled on it. This pull request does not record a ruling, so that call is still open.
  • Checked against the head. A held turn moves 1 step at the press, none before 300 ms, then 1, 2, and 4 steps a 40 ms tick, so it crosses 0 to 127 in about 2.32 s and sends at most 25 control changes a second. Release, focus-out, panic, and quit stop it. The knob line's widths give mod 0 cutoff 2.00 kHz res 0.300 attack 800 ms release 1.50 s. The schema rejects an exp range that touches 0, and its range ends are inclusive. A rejected save keeps the voice's copy and reloads nothing, a program saved while its knob file fails loads the last good copy, and a render checks the knob file in validate, writes its own copy, hashes the file as an input, and refuses to cache when it changes during the render. tracker and fourths are unchanged, and nothing in the docs presents chunk 2 or chunk 3 behavior as current.

Suggestions

  • examples/bloom/shared/instruments/juno.knobs.yaml:1, bass.knobs.yaml:1, juno.scd:62, bass.scd:64: cite docs/keys.md's "Knob files" and "Make an instrument playable" sections, because the doc has no "Knobs" heading.
  • src/schema/knobs.ts:34: reject a step that does not divide max - min, because the top controller value then rounds past max. With min: 0, max: 1, step: 0.4, the line and ControlSpec both reach 1.2.
  • src/keys/knobs.ts:154: give a lin knob with a fractional step at least the step's decimal places, so step: 2.5 on 0 to 100 prints 2.5 rather than 3, and amend §2.5's width rule to match.
  • src/keys/knobs.ts:67: KnobsError, parseKnobs, loadKnobs, and watchKnobs repeat KeymapError, parseKeymap, loadKeymap, and watchKeymap in src/keys/keymap.ts almost line for line. One helper that loads and watches a schema-checked YAML file could serve both.
  • src/keys/knobs.ts:12, src/schema/knobs.ts:73: nothing outside its module reads CC_MAX or KnobFile, so drop the exports.
  • src/commands/keys.ts:547: slice the chosen cell to the width left after ‹ and ›. On a terminal narrower than about 25 columns the markers push the knob line past the edge, it wraps, and redrawAbove's cursor-up count no longer matches the screen.
  • src/keys/print.ts:57: write "move the choice 1 knob to the right" rather than "choose the knob 1 to the right", which reads as a knob's number, and update the stored copy in src/keys/print.test.ts.
  • docs/keys.md:111: "a knob has 128 positions" contradicts the step row below it. Say that a knob with a step moves to the next value that rounds differently.
  • docs/keys.md:212: the source name drops a plain .yaml too, as knobFileName does, so ju-06a.yaml gives ju-06a.
  • docs/build-graph.md:275: reflow the paragraph, which leaves reading them. A as a short line.
  • docs/projects/instrument-knobs/readme.md:501: §2.9 and §3 say setsMod() becomes a read of the controller map, but it still asks the keymap whether a key can move the wheel. Record in §9.1 that it stays a keymap query.

…ts knob out

The knob schema accepts any set of knobs, and criterion 11 deletes
attack and release from juno.knobs.yaml. The knob helper in juno.scd
and bass.scd indexed the knob it looked up without checking that it
found one, so a file without one of the four knobs failed voice mode
with "Message 'at' not understood": the voice did not reload, field keys
could not start it, and a take's render through it failed the build.

The helper now takes the setting's fixed value as its second argument
and returns it when the checked copy has no knob of that name. A real
sclang test renders a take through bloom's juno and bass from a knob
file with cutoff alone, and docs/keys.md shows the new helper.
When the chosen knob alone was wider than the terminal, the knob line
cut it to the full width and then added the ‹ and › markers, so the
line ran up to four columns past the edge and wrapped, and redrawAbove's
cursor-up count no longer matched the screen. The knob line now cuts
each knob to the room the markers leave.
A lin knob printed the decimal places its range's far end needs, so a
step of 2.5 on 0 to 100 printed 2.5 as 3 and two neighboring values
the same. The knob line now prints at least the step's places, and
docs/keys.md and the plan's width rule in §2.5 say so.
"choose the knob 1 to the right" read as choosing knob number 1. A
knob key now prints as "move the choice 1 knob to the right".
Nothing outside the schema reads the parsed knob file's type; callers
take Knob[] from parseKnobs. CC_MAX stays exported, because the
session's glide reads it in instrument-knobs.md chunk 2.
- juno's and bass's knob files and programs cite docs/keys.md's "Knob
  files" and "Make an instrument playable" sections, because the doc
  has no "Knobs" heading.
- docs/keys.md says that a turn on a knob with a step moves to the
  next value that rounds differently, as its step row does, and that a
  knob file named without .knobs.yaml drops .yaml, as knobFileName
  does.
- docs/build-graph.md's voice-mode paragraph is reflowed.
- The plan's §9.1 records that setsMod() stays a keymap query.

@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.8 · model claude-opus-5-5 · effort xhigh · CLEAN · took 2m 38s

This pull request makes field keys a MIDI controller with knobs, as chunk 1 of the instrument-knobs plan describes. A knob file names each knob's controller and range, one zod schema checks it on every path that hands it to an instrument, the arrows choose and turn knobs on a new knob line, and every turn leaves as a control change on Field Keys. The voicer hands controllers 2 to 119, except sustain, to the voices as cc<n>, and juno and bass map four knobs each through the checked copy that FIELD_KNOBS names, live and in a take's render. Since the last review, the voices keep a setting's fixed value for a knob their file leaves out, the knob line fits a narrow terminal, a lin knob with a fractional step prints its places, and the docs and plan take the earlier suggestions.

1 finding thread: 1 resolved, 0 open

Covered 35 of 35 changed files. None is generated.

Disclosures

  • The head is trusted, by Justin's ruling. Every commit's git author and committer is ninjudd. Two commits also carry a Co-Authored-By: Claude <[email protected]> trailer, which GitHub attributes to the login claude, with read access only. The previous review treated that trailer as withholding trust and ran nothing. Justin has since ruled that the trailer on his own commits does not make a head untrusted, so this review ran the head's code.
  • Not run: the tests that boot scsynth on an audio device or publish or arm MIDI (src/keys/routing-voice.test.ts, src/keys/helper-native.test.ts, the MIDI cases in src/commands/record-midi-daemon.test.ts) and the full suite, because a live field keys session was using the machine's MIDI and audio. The criteria that need a kitty terminal and sound were not run either.

Suggestions

  • src/schema/knobs.ts:34: reject a step that does not divide max - min, because the top controller value then rounds past max. With min: 0, max: 1, step: 0.4, the line and ControlSpec both reach 1.2.
  • src/keys/knobs.ts:67: KnobsError, parseKnobs, loadKnobs, and watchKnobs repeat KeymapError, parseKeymap, loadKeymap, and watchKeymap in src/keys/keymap.ts almost line for line. One helper that loads and watches a schema-checked YAML file could serve both.
  • src/keys/knobs.ts:12: nothing outside the module reads CC_MAX, so drop the export.
  • src/keys/knobs.ts:188: decimalPlaces repeats the bend's decimalPlaces in src/commands/keys.ts:489 under the same name with a different method. One shared helper would keep the knob line and the status line counting places the same way.

What was checked

  • The earlier finding is fixed. juno.scd and bass.scd now give knob the setting's fixed value and return it when the copy has no knob of that name. Loading each voice through sc/voice-load.scd under FIELD_MODE=voice, without a server, gives a SynthDef from a copy with only cutoff and res, whose controls are cc74 and cc71, and from a copy with knobs: [], which has none. A copy with all four knobs still adds cc73 and cc72, and an unset FIELD_KNOBS still fails with the instrument's own message. The new real-sclang render case renders both instruments from a knob file with cutoff alone.
  • Tests run on this head, all passing:
    • pnpm install --frozen-lockfile and pnpm typecheck.
    • src/schema/knobs.test.ts, src/keys/knobs.test.ts, src/keys/keymap.test.ts, src/schema/keymap.test.ts, src/keys/print.test.ts, src/keys/session.test.ts, src/commands/keys.test.ts, src/keys/voice-host.test.ts (against its stub sclang), and src/model/project.test.ts: 220 tests.
    • src/keys/voicer.test.ts and src/generators/voice-render.test.ts through real sclang and an offline field-audiod --render: 15 tests.
    • project check: the plans are valid.
  • CI passes on this head. linux and windows run pnpm typecheck, pnpm build, field check on examples/bloom, and pnpm test.
  • The new knob line fit. KnobLine takes the markers' width off before it cuts the chosen knob's cell. A window of several knobs already fits by span, so the cut only shortens a single knob wider than the terminal. The new test holds every choice at every width from 8 to 40.
  • Suggestions taken. The knob files and the voices cite "Knob files" and "Make an instrument playable". A lin knob with a fractional step prints at least the step's places, and the plan amends §2.5 to match. --print says "move the choice 1 knob". docs/keys.md covers a stepped knob's steps and the plain .yaml source name, docs/build-graph.md is reflowed, and §9.1 records why setsMod() stays a keymap query. The unused KnobFile type is gone.
  • Plan conformance, unchanged from the last review: everything §6 gives chunk 1 is here, criteria 4 to 8, 14, and 23 belong to chunk 2, and 20 and 21 to chunk 3. The voices read the checked copy that §3.2 recommends, which the plan still records as Justin's call. This pull request records no ruling on it.
  • Merging with main. main has not changed examples/bloom/shared/instruments/juno.scd since #188, so this branch's hunks in it apply without a conflict. They change the header comment, the comment above ju06a, and the voice-mode branch, and they leave pad and the render branch alone.

@ninjudd
ninjudd marked this pull request as ready for review October 11, 2026 21:22
@ninjudd
ninjudd merged commit 2cfe975 into main Oct 11, 2026
7 checks passed
@ninjudd
ninjudd deleted the knobs/turn branch October 11, 2026 21:33
ninjudd added a commit that referenced this pull request Oct 11, 2026
…eld keys on Ctrl-C alone (instrument-knobs.md chunk 2) (#210)

Turning a knob from one end of its range to the other takes about 2.3
seconds of holding an arrow, and landing on a particular value means
watching the line and letting go in time. This second chunk of the
instrument-knobs plan (#202) lets you type the value instead. In
`musical` the number row types the chosen knob's value, in the units its
knob file names, so `800` on `cutoff` means 800 Hz and `0.8` on `attack`
means 800 ms. `Enter` completes it, and the knob glides to the
controller value nearest the number, since a controller carries only 128
values: `800` lands on `810 Hz`.

The glide is a run of control changes, one every 40 ms at most, at a
speed the keymap's new `glide` field sets: the seconds a value takes to
cross a knob's whole range. `musical` sets one second, and a keymap that
never mentions `glide` sets a typed value at once. Because the glide is
MIDI, a take keeps it and any instrument answers it, which a longer lag
inside the instrument could not do.

`.` was the bend up's key in chunk 1, so `Period` types the decimal
point only while a value is open, as #202 recommended and Justin merged.
With no value open it still bends, which is why a value cannot start
with `.`. `Backspace` edits a value, and a knob key completes it first,
the way moving off a cell completes it in a spreadsheet. Notes keep
playing while you type, so you can type over a held chord.

`Esc` now cancels a value instead of quitting, and with no value open it
puts `Ctrl-C quits` on the status line. `Ctrl-C` alone quits, and no
keymap can bind `Esc` or a `Ctrl` chord, so no keymap can trap you
still. This amends keyboard-instrument.md §2.4, which now carries a
dated note pointing at the plan. `Enter`, `Backspace`, and `Escape` are
positions the session handles before the keymap, from the kitty
protocol's `CSI 13 u`, `CSI 127 u`, and `CSI 27 u`.

This stacks on #209. §10 of the plan records what implementation
settled.

## Testing

I ran these on macOS, from the root of a checkout of this branch unless
a step says otherwise, after building as #209's Testing section does
(`pnpm install`, `pnpm build`, `pnpm build:native`).

1. `pnpm typecheck` prints nothing and exits 0.
2. `pnpm vitest run` reports 90 test files, 1191 tests passed and 1
skipped. A failure in `src/keys/session.test.ts`'s "typing a knob's
value" tests, `src/commands/keys.test.ts`'s "typing on the knob line",
or `src/keys/terminal.test.ts`'s quitting tests points at this change.
3. From `examples/bloom`, `node ../../dist/cli.js keys --print` draws
`musical` with `1` to `0` and `-` on the number row and lists each as
`type <c> into the chosen knob's value`.

I also drove `field keys --knobs` in a pseudo-terminal, sending the
kitty protocol's bytes, against a stand-in for `field-audiod --keys`
that logs every message it is sent and publishes no MIDI source. The
knob file had `juno`'s `cutoff` and `attack`. What it showed:

- `800` read `cutoff 800_ Hz`, and `Enter` glided CC 74 from 82 down to
62, five values a tick, to `810 Hz` (criterion 4).
- `12`, `Backspace`, `5` read `15_ Hz`. The first `Esc` closed it and
left `810 Hz`, the second put `Ctrl-C quits` on the status line, and
`Ctrl-C` quit with All Notes Off (criterion 6).
- `300` and `ArrowRight` glided to `301 Hz` and moved the choice
(criterion 7).
- `0`, `.`, `8` read `0.8_ s` and landed `attack` on `782 ms`, and `.`
with the value closed sent a bend up and its release (criterion 23).
- At most 5 control changes went out in any second.

The stand-in is a 15-line Node script that prints
`{"ready":true,"name":"Field Keys"}` and appends each line it reads to a
log; point `FIELD_AUDIOD` at it to repeat the run without a MIDI source.

What I could not run is anything by ear or in a real kitty terminal:
criteria 4 to 8, 12, 14, 18, and 23 by hand. From `examples/bloom` in
Ghostty or iTerm2, run `node ../../dist/cli.js keys juno`, hold a chord,
choose `cutoff`, type `800`, and press `Enter`. The filter should close
over about half a second while the line runs down to `810 Hz`. A line
that jumps straight there means `glide` did not load from `musical`, and
a chord that stops when you type means the number row is still playing
notes.

<!-- projector-summary v=1 sha=cd79e60cbb9caef6c52bf077bbfebd65fb3579da
-->
📽️ **Projector summary** of cd79e60: https://field.amnes.ac/reviews/210

---------

Co-authored-by: Claude <[email protected]>
ninjudd added a commit that referenced this pull request Oct 11, 2026
…ent, and the daemon chases it to the take's first sample (instrument-knobs.md chunk 3) (#212)

A MIDI take records only the messages that arrive once it has started.
So a knob you turned before pressing record, such as `juno`'s cutoff
dialed down for a darker pad, played live but rendered at its default in
the take until you happened to turn it again. The same gap hit the
modulation wheel, and keyboard-instrument.md §14.5 left it open. This
third chunk of the instrument-knobs plan (#202) closes it in the daemon,
with MIDI alone, so it works for any source.

There are three parts:

- **`field keys` publishes what it has sent.** Run inside a project, it
keeps every controller from 0 to 119 it has sent, by channel, in
`.field/keys.json`, written to a temporary file and renamed over the
last on each control change, and removed when it quits. A `field keys`
removes the file only if it wrote it, so two in one project do not
delete each other's. One that cannot write the file keeps playing and
names the error on the status line, and a take then starts without its
knobs.
- **`field record` passes them in `arm`.** When it arms a MIDI take, in
the one-track form or with `tracks`, and the `field keys` that wrote the
file is still running, it adds `controllers` to `arm`. It does so only
for a daemon that lists the new `midi-chase` feature, so an older daemon
never sees the field.
- **The daemon chases controllers.** From the arm, it keeps the latest
value of each controller from 0 to 119 on each channel: the ones `arm`
passed, then every control change that arrives, a count-in included,
whether before the take, during it, or past its `until`. Before this
change it dropped those that arrived before the start. At the take's
first sample it writes one line per channel and controller at `at: 0`,
ahead of every other line, in the order the values last arrived, in each
MIDI take of the pass. Controllers 120 to 127 are channel mode messages
and are never chased. A hardware knob moved after the arm counts too. A
change the take records enters the table only after those lines, so a
second take on one arm, which arming.md chunk 3's lasting arm will make,
starts each controller where the first take left it.

On the audio thread, the chase is a fixed table of 16 channels by 120
controllers, updated in constant time per message wherever the callback
used to discard arrivals before the start. `arm` hands its seeds to the
callback under a spin lock that the callback only ever tries, so it
never blocks, and each arm starts the table over. The lines go in just
before the take's first stamped message. So an arrival in the start
block that falls before the start sample is chased before the lines are
written, and the lines still lead the file. `arm` refuses `controllers`
out of range, as it refuses a bad input channel. A block whose pull ran
before `record`'s request, which #204 lets wait for the next block to
start the take, chases what it drains too, because that arrived before
the start.

#209 and #210, chunks 1 and 2, are on `main`, and this branch is rebased
onto it, #213's host monitoring included. `armSet` takes the chase's
seeds and then #213's connection `owner`, and the `tracks` form of `arm`
passes both. With this, every chunk of the plan is built, and what
remains is the criteria to check by hand. §11 of the plan records what
implementation settled.

## Testing

I ran these on macOS, from the root of a checkout of this branch, after
`pnpm install`, `pnpm build`, and `pnpm build:native`. `pnpm
build:native` matters here, since this change is in the daemon. Against
a daemon built before it, the `midi-chase` tests fail on
`client.supports('midi-chase')`.

1. `pnpm typecheck` prints nothing and exits 0.
2. `pnpm vitest run` reports 91 test files, 1216 tests passed and 1
skipped.
3. `pnpm vitest run src/commands/record-midi-daemon.test.ts
src/commands/record-plan.test.ts` passes 16 tests and skips 1, which
runs only where there is no MIDI service. The daemon tests publish a
CoreMIDI source of their own, `Field Keys Capture <pid> …`, for a few
seconds, and arm a daemon of their own in null-output mode; they touch
no running daemon. The chase test seeds `cc 110 = 10` and `cc 111 = 20`
on channel 16 at the arm. Before the start, it sends `cc 112 = 30` on
channel 15, `cc 110 = 40` on 16, and CC 120; after the start, `cc 111 =
50`. The take's lines at `at: 0` must be `cc 111 = 20`, `cc 112 = 30`,
`cc 110 = 40`, in that order, with no CC 120, and `cc 111 = 50` must
land later at its own time. Lines in another order mean the chase no
longer orders by last arrival. A `cc 110 = 10` line means a seed was not
replaced. The `field record` test publishes `.field/keys.json` as its
own process and checks that the landed notes file has `{ at: 0, cc: 113,
value: 23, channel: 16 }`. The latch test sets
`FIELD_AUDIOD_LATCH_STALL_MS=8` and sends a controller just before each
of ten `record`s on one arm. "the controller sent before take N:
expected [] to have a length of 1" means a block whose pull ran before
`record`'s request dropped what it drained instead of chasing it. The
carry test records twice on one arm, with `cc 114 = 20` before the first
take and `cc 114 = 50` during it, and the second take's line at `at: 0`
must be `cc 114 = 50`. `cc 114 = 20` there means a change the take
recorded never reached the chase.

What I could not run is criteria 20 and 21 by hand, which need a kitty
terminal and ears. From `examples/bloom`, give `creek` a track `keys`
with `instrument: juno`. In one terminal, run `node ../../dist/cli.js
keys juno` and turn `cutoff` down. In another, run `node
../../dist/cli.js record creek/track:keys --at 17`, play without
touching a knob, stop, build, and play. The take should render dark from
its first note, and its notes file's first `controls` row should be `{
at: 0, cc: 74, value: … }`. Both terminals need this branch's `dist` and
daemon: a daemon left running from another build answers without
`midi-chase`, so run `field transport quit` first. With `--count-in 1`,
turning `res` during the count-in should start the take with that `res`.

<!-- projector-summary v=1 sha=68d929f49bdbec524a494779a2cfc85fb8ff5fb9
-->
📽️ **Projector summary** of 68d929f: https://field.amnes.ac/reviews/212

This branch was previously deployed

1 inactive deployment
github-pages — 32044927 Deployed Oct 11, 2026 by ninjudd via publish #152
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