Skip to content

Plan the keyboard instrument: field keys with keymaps, a SuperCollider voice host, and recorded keys - #175

Merged
ninjudd merged 10 commits into
mainfrom
keys/plan
Oct 10, 2026
Merged

ninjudd merged 10 commits into
mainfrom
keys/plan

Conversation

@ninjudd

@ninjudd ninjudd commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Field can hear an instrument only by rendering it. A SuperCollider program in shared/instruments/ runs offline from a spec and writes one WAV, and nothing in Field takes notes: no code opens a MIDI input, hosted plugins get an empty MidiBuffer, and no command reads the keyboard as anything but commands. So there is no way to find out how a sound responds under your fingers, which is how a player judges an instrument. This plan, docs/projects/keyboard-instrument/readme.md, closes that gap in four chunks.

The first chunk adds field keys, which turns the computer keyboard into a virtual MIDI source named Field Keys that Logic or any other application can play from. Terminals normally report only key presses, so it reads releases through the kitty keyboard protocol, which Ghostty and iTerm2 3.5 and later implement. It refuses a terminal without the protocol, because every way of guessing releases makes sustained sounds unplayable. It finds the physical key behind each press, so Dvorak, AZERTY, and other keyboard layouts play the same notes without switching back to QWERTY. The position comes from the terminal's base layout key when the terminal sends one, and otherwise from the keyboard layout that the helper reads from macOS.

What each key plays comes from a keymap: a YAML file, checked by a zod schema, that binds positions (named by their KeyboardEvent.code values) to notes, chords, and controls. The built-ins use the same format as a keymap you write. A bare --keymap name picks a built-in and anything else is a path, FIELD_KEYMAP sets your default, a keymap given by path reloads when you save it, and --print draws any keymap as a keyboard diagram. A grid rule writes an isomorphic keymap in one line. Logic's Musical Typing, which Ableton Live shares, is the default, including pitch bend and modulation. The native work lives in a new short-lived field-audiod --keys mode rather than an npm binding, which keeps the control plane free of native dependencies and keeps JUCE inside the daemon.

The second chunk adds field keys <instrument>. It starts an sclang voice host that boots its own scsynth on the output device and plays the instrument's voice from every MIDI source, so a USB controller plays it too. An instrument opts in by answering FIELD_MODE=voice with a SynthDef that takes freq, amp, and gate, beside its unchanged render mode. That is the "same .scd does both" shape that project-layout.md §4.6 chose. The sound goes straight to the device and skips the mix, until live-supercollider puts scsynth in the graph. Sharing the device means sharing its rate: scsynth keeps computing at the rate it booted at, so when a field play started afterwards moves the device to another rate, the voice host restarts scsynth at the new one.

The third chunk ships two more built-in keymaps: tracker, the two-octave layout trackers use, and fourths, an isomorphic grid. Chunk 1's schema tests already carry both as fixtures, so the format is known to express them. The fourth chunk records the keys. The daemon stamps each event on the transport's sample clock, the take lands the way an audio take does, and the build renders it offline through the same voice. The take's file format, the entry that plays it, and who builds the NRT score are recorded as open questions for Justin to settle when that chunk starts, so the plan is ready for chunks 1 to 3.

project check warns that the Projector section of AGENTS.md is version 1 while the CLI ships version 2. This PR deliberately leaves that alone. Running project init adds a rule to stack large work with gh stack and carry fixes up by rebasing, which is a policy change that deserves its own review.

Testing

This PR changes only docs/projects/keyboard-instrument/readme.md, so there is nothing to build and no test exercises it. I ran these from the repository root of a checkout at the head of keys/plan:

project check
git diff --check origin/main...HEAD
project list | grep keyboard-instrument

project check prints Project plans are valid. and exits 0, after the one instructions-outdated warning about AGENTS.md described above. Any other warning or error, or a nonzero exit, means the plan's frontmatter or layout is wrong. git diff --check prints nothing, and any output names trailing whitespace or a conflict marker. project list shows keyboard-instrument ready Plan: Keyboard instrument in the now: group. The commands leave no state behind.

I did not run pnpm typecheck or vitest, because the diff contains no TypeScript. I checked the plan's arithmetic by hand: Musical Typing binds 18 notes, tracker 32, and fourths 27, and the fourths grid puts 48 on KeyZ, 53 on KeyA, 58 on KeyQ, and 63 on Digit1, as criterion 29 and the schema test expect.

📽️ Projector summary of ba65e62: https://field.amnes.ac/reviews/175

… and recorded keys

Field can only hear an instrument by rendering it, so nothing lets you
play one by hand. This plan adds `field keys`, which publishes the
computer keyboard as a virtual MIDI source through a small
field-audiod mode, reading key releases through the kitty keyboard
protocol. Given an instrument, it starts an sclang voice host that
plays the instrument's voice SynthDef from every MIDI source, so a USB
controller plays it too. Recording the keys against the transport
comes last, with its take format and entry shape left as named open
questions.
A layout keyed by characters scatters the notes on Dvorak, AZERTY, and
every other non-QWERTY layout, and the only fix would be switching back
to QWERTY to play. field keys now resolves each key to its physical
position: from the terminal's kitty base layout key when it sends one,
and otherwise from a layout map the helper reads from macOS's Text
Input Sources API and refreshes when the input source changes. The
helper's mode becomes --keys, since it now does both jobs.

The layout adds Musical Typing's pitch bend and modulation keys, records
the tracker and isomorphic layouts as the alternatives it beat, and
keeps the table as data so a second layout is a follow-up.
A keymap, Field's map from each physical key to the note, chord, or
control it plays, is now a YAML file checked by a zod schema, and the
built-in keymaps use the same format as one you write. A bare
--keymap name picks a built-in, anything else is a path, and
FIELD_KEYMAP sets your default. A keymap given by path reloads when
you save it, and --print draws any keymap as a keyboard diagram.
Positions are named by their KeyboardEvent.code values. A grid rule
writes isomorphic keymaps in one line.

Musical Typing stays the default. The tracker and fourths keymaps
become built-ins in a new chunk 3, so recording moves to chunk 4. The
plan now says "keymap" for Field's map and "keyboard layout" for the
OS's, so the two never share a word.
@ninjudd ninjudd changed the title Plan the keyboard instrument: field keys, a SuperCollider voice host, and recorded keys Plan the keyboard instrument: field keys with keymaps, a SuperCollider voice host, and recorded keys Oct 10, 2026

@minjudd minjudd left a comment

Copy link
Copy Markdown

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 18m 55s

This pull request adds the keyboard-instrument plan at status: ready, priority: now. The plan designs field keys, which reads key presses and releases through the kitty keyboard protocol, finds each key's physical position, and sends what a YAML keymap binds there from a virtual MIDI source that a new field-audiod --keys mode publishes. A voice host in sclang then plays an instrument's new voice mode from every MIDI source, two more built-in keymaps follow, and a recording chunk comes last with its format questions left open. The change touches no code, and ready claims chunks 1 to 3.

4 finding threads: 0 resolved, 4 open

Covered 1 of 1 changed files; no generated files.

The head is trusted, but it changes only a plan, so the checks run were project check (valid, with the one instructions-outdated warning the pull request body explains) and git diff --check (clean). pnpm typecheck and vitest did not run, because the diff holds no code.

Readiness: the plan is ready. §7 questions 1 to 3 belong to chunk 4, and §6 item 4 defers them explicitly to that chunk's start. Questions 4 to 8 each name what they wait for. None of them blocks the claim for chunks 1 to 3.

Checked against the code and plans at this head, and found accurate:

  • The code the plan builds on. programPath(), runScProgram, and the FIELD_SCLANG, PATH, app-bundle lookup in src/generators/supercollider.ts, daemonBinary(), the picker's raw-mode drawing, the empty juce::MidiBuffer in hosting.cpp, the daemon's --scan and --render modes, the three runtime dependencies, and field sc render's flags.
  • The cited sections. sc-render.md §2, recording.md §3 and §4, and nested-tracks.md §18 decision 4 say what the plan says they do. The project-layout.md citation is the exception, in its own thread.
  • The keymap arithmetic. Criteria 2, 8, 12 to 15, 19, 28, and 29, the fourths grid values, and the 18, 32, and 27 note ranges of the three built-ins.

Suggestions

  • docs/projects/keyboard-instrument/readme.md:297: the "Modifiers do not bind" rule should say that a release always ends the notes its press started, whatever modifiers it carries, and that the Caps Lock and Num Lock bits, which flag 8 reports on every key, are ignored. Add both cases to session.test.ts.
  • docs/projects/keyboard-instrument/readme.md:595: criterion 14's keymap sounds note 60 from both KeyA and KeyF, so releasing one while the other is held sends a note-off for a note the other key still holds. Say whether the session counts the keys holding a note before it sends the note-off, and cover the overlap in session.test.ts.
  • docs/projects/keyboard-instrument/readme.md:189: on macOS a Node watch on a file stays with the original file, so an editor that saves by renaming a temporary file over the keymap ends the watch after the first save. Watch the keymap's directory, and have keymap.test.ts save that way once.
  • docs/projects/keyboard-instrument/readme.md:567: §3 says keymap names reuse programPath()'s bare-name rule, but §2.4 makes a name ending in .yaml a path, which programPath() treats as bare. Say that the keymap rule adds the suffix test.

Three places cited project-layout.md §1 decision 6, which is "One
ledger per scope". The text they rely on is §4.6: shared/ lands on
three shelves (make, is, change), and the same .scd renders from a
spec or plays from notes depending on how it is invoked.
field play moves the output device to the rate of what it plays
(playback.md §3.5), so starting it after field keys switches the rate
under a running scsynth. scsynth's CoreAudio driver listens for no
rate change and keeps computing at its boot rate, so every voice
would play about a semitone and a half sharp between 44.1 and 48 kHz.

The voice host now compares the boot rate with the rate scsynth
measures from the device's clock in each status reply, and reboots
scsynth at the device's new rate when they differ by more than 1%.
Criterion 25 runs both orders and names the sharp note as the failure.
§3 records why the host follows the device rather than booting at the
project's sample_rate.
docs/projects/README.md asks for a settled decision to carry the
(DECIDED) marker, and AGENTS.md tells agents not to reopen one that
does. §3 records each choice with the alternatives it beat but carried
no marker, so the agents building chunks 1 to 3 had no signal that it
is settled. The heading now reads (DECIDED, 2026-10-10), as the remote
plan's did in the pull request that proposed it (#168).

The sclang bullet said the voice host's code builds chunk 4's NRT
score, which §7 question 3 leaves open, so it now says the code can.
Criterion 10 was the only check that the helper reports a new keyboard
layout mid-session, but in Ghostty it passed without that report:
Ghostty sends a base layout key for KeyA and KeyZ on AZERTY, so
position.ts never consulted the helper. The criterion now also
switches to U.S. International – PC without restarting and expects
the status line to name Quote as a dead key, which only the helper's
second report can produce, in any terminal.
Two gaps let a note-off go missing or arrive early. Under the kitty
protocol a key event carries every active modifier, so a release with
Ctrl held carries the ctrl bit, and the rule that a key held with Ctrl
does nothing would leave the note stuck. Flag 8 also sets the Caps
Lock and Num Lock bits on every key, which the rule did not mention.
And two keys can hold the same note, through a chord or a transpose,
so releasing one sent a note-off for a note the other still held.

A release now always ends what its press started, the lock bits are
ignored, and the session counts the keys holding each note: the first
press sends the note-on, and the last release sends the note-off.
session.test.ts covers all three.
Many editors save by writing a temporary file and renaming it over
the original, and Node's fs.watch on a file keeps watching the
original file on macOS and Linux. A watch on the keymap itself would
end after the first such save. field keys now watches the directory
that holds the keymap and reacts to changes to the keymap's name, and
keymap.test.ts saves that way twice in a row.
§3 said keymap names reuse programPath()'s bare-name rule, but §2.4
makes a name ending in .yaml a path, and programPath() treats a name
as a path only when it contains a /. The paragraph now says the keymap
rule adds that one test.

@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 4m 49s

This pull request adds the keyboard-instrument plan at status: ready, priority: now. It covers four chunks. field keys turns the computer keyboard into a virtual MIDI source driven by YAML keymaps. field keys <instrument> plays a SuperCollider voice through an sclang voice host. Two more built-in keymaps follow, and recording comes last. The plan claims readiness for chunks 1 to 3 only, and leaves the recording design to questions settled when chunk 4 starts.

4 finding threads: 4 resolved, 0 open

Covered 1 of 1 changed files.

The plan is ready, so every open question has to be answered or explicitly deferred. All eight in §7 are deferred with a named trigger. Questions 1 to 3 are settled when chunk 4 starts, question 4 belongs to live-supercollider, questions 5 and 6 wait until chunk 2 has been played, question 7 waits until a keymap needs layers, and question 8 waits for a Linux player with a non-QWERTY layout. None of them blocks chunks 1 to 3.

What was checked at ba65e62:

  • The 4 earlier findings, which are all fixed at this head. §1 and §3 now cite project-layout.md §4.6, which is the decision that puts one .scd on the instruments shelf for both rendering and playing. §2.6 restarts scsynth when the device's rate moves, and criterion 25 runs both start orders. §3's heading carries (DECIDED, 2026-10-10). Criterion 10 ends with a layout switch that only the helper's second report can detect.
  • The plan's claims about existing code, against the head:
    • programPath() treats a source as a path only when it contains /, and otherwise joins it to shared/instruments.
    • The sclang lookup order is FIELD_SCLANG, then PATH, then the app bundle.
    • daemonBinary() is the entry point helper.ts would use.
    • field-audiod already has the --scan and --render modes.
    • hosting.cpp hands plugins an empty juce::MidiBuffer.
    • maybeMatchDeviceRate runs on load and on session swap.
    • The control plane has three runtime dependencies, none of them native.
    • package.json has no files list, so keymaps/ and sc/ resolve from the package root the way python/ does.
    • field sc render takes --seed, --duration, and --output, and field play takes --device.
  • The cited sections: sc-render.md §2, playback.md §3.5, recording.md §3 and §4, and nested-tracks.md §18 decision 4.
  • The keymap arithmetic. The fourths grid puts 48, 53, 58, and 63 on KeyZ, KeyA, KeyQ, and Digit1. Its offsets run 0 to 26, which makes 27 notes. Criterion 29's triads are 48, 52, 55 and then 49, 53, 56. The bend and CC values in criteria 12 and 13 are right, and so is criterion 2's note-off. The KeyK example of two keys holding note 60 checks out.
  • The new note-pairing rule in §2.1 is consistent with the voice host's one-voice-per-note rule in §2.6 and with the session tests in §4. The directory watch in §2.4 matches Node's documented fs.watch behavior for a file replaced by rename.
  • Criterion 25 runs at bloom's sample_rate: 48000, and creek sets no rate of its own.
  • project check passes at the head. Its one warning is the AGENTS.md version notice that the pull request body explains. git diff --check prints nothing.

@ninjudd
ninjudd marked this pull request as ready for review October 10, 2026 22:16
@ninjudd
ninjudd merged commit 813dad2 into main Oct 10, 2026
1 check passed
@ninjudd
ninjudd deleted the keys/plan branch October 10, 2026 22:28
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.

2 participants