Repository navigation
Add field keys: the computer keyboard as a MIDI source, with keymaps (keyboard-instrument.md chunk 1) - #178
Conversation
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 14m 22s
This pull request adds field keys, chunk 1 of the keyboard-instrument plan. It reads key presses and releases through the kitty keyboard protocol, finds each key's physical position from the terminal's base layout key or from the keyboard layout that a new field-audiod --keys mode reports, and plays a YAML keymap as the virtual MIDI source Field Keys. It adds the keymap schema, loader, reload on save, and --print diagram, the default musical-typing keymap, a --midi-monitor mode, and docs/keys.md, and it records chunk 1 as built in plan §9. It leaves the voice host, the tracker and fourths built-ins, recording, Linux keyboard layouts, and the hand-run criteria 1 to 20 for later.
3 finding threads: 0 resolved, 3 open
Covered 31 of 31 changed files; none are generated.
The plan moves from ready to in-progress. That is not a move out of draft, so it takes on no open question. All eight questions in §7 are deferred: 1 to 3 to chunk 4, and 4 to 8 until chunk 2 has been played with or someone needs them. None of them blocks chunk 1.
Disclosures:
- Hand-run criteria. Plan §4 criteria 1 to 20 need a person at Ghostty, iTerm2, and Apple's Terminal. This review did not run them, and plan §9.3 records them as owed.
- Native binary. The shared checkout's
field-audiodpredates--keys, so the round trip ran against afield-audiodbuilt from this head in a scratch worktree.
Suggestions
src/schema/keymap.ts:103: positions in a named row never entergridPositions, sorows: [home, [KeyA]]androws: [home, home]both load, andKeyAsilently plays the later row's offset. Add each named row's positions togridPositionsso the "appears twice" rule covers them.src/keys/session.ts:128: atogglecontroller that is on gets no 0 fromquitorpanic, andsetKeymapforgets that it is on. A toggled sustain therefore leaves the receiver at 127 afterfield keysexits. Send 0 for each toggled-on controller at quit, at panic, and on reload.src/keys/helper-native.test.ts:21:BINDABLE_POSITIONScopiesTEXT_POSITIONSfromsrc/schema/keymap.ts. Import it instead, so that a position added to the schema fails the round trip untilkeyboard-layout.cppreports it.src/keys/session.ts:36:signed()repeats the one insrc/keys/print.ts:38, andstatusTextinsrc/commands/keys.ts:139writes it out a third time. Export one and use it in all three places.
What ran at this head:
pnpm typecheck. Clean.vitest run src/keys src/schema/keymap.test.ts. 76 TypeScript tests pass: schema 13, keymap 10, print 3, terminal 13, position 11, session 20, helper 6, the counts plan §9.2 records.- The native round trip.
src/keys/helper-native.test.tspasses all 8 cases on macOS against the head's ownfield-audiod. On CI's Linux job, which passed, each case skips by name because the runner has no ALSA sequencer. field keys --print. Draws the Musical Typing diagram the pull request body describes, and exits 0.project check. The plans are valid.- Reproductions. What
probeKittyProtocolreturns when key events arrive during the probe,isQuiton Ctrl-C under a Cyrillic layout, duplicate grid positions, and 300 helper starts that print an error line and exit at once. None of those starts lost the error message to the exit event.
… the probe drops Review of #178: under the Russian input source, Ctrl plus the key at the US c position arrives as CSI 1089::99;5u, which isQuit did not take for Ctrl-C, so only Esc quit. isQuit now also takes a Ctrl press whose base layout key is c when the typed key is outside ASCII; a layout that types ASCII there, such as Dvorak's j, keeps its own Ctrl-C. The probe's comment promised to return key events that it drops; it now says that only a sequence cut off at the end comes back, and a test pins that.
Review of #178: installing Field links only field onto PATH, so the guide's field-audiod --midi-monitor printed command not found. docs/keys.md and plan criterion 1 now give the binary's path in the checkout, as the pull request's Testing section does, and mention $FIELD_AUDIOD.
Review of #178: positions in a named row never entered the duplicate check, so rows: [home, home] and [home, [KeyA]] loaded, and KeyA silently played the later row's offset.
Review of #178: a toggle controller left on got no 0 from quit or panic, and a reload forgot it was on, so a toggled sustain held the receiver's notes after field keys exited. The session now remembers each toggled-on controller's channel and number and sends it 0 then; setKeymap returns those messages for field keys to send. signed() is now exported once from print.ts and used by the session and the status line.
Review of #178: the round trip copied the bindable positions, so a position added to the schema would not have failed it until keyboard-layout.cpp reported it. It now uses TEXT_POSITIONS.
…d diagram A keymap (keyboard-instrument.md §2.4) binds positions, named by their KeyboardEvent.code values, to notes, chords, and controls. The zod schema enforces the plan's rules: known positions only, a position is a note or a control, Escape is reserved, and every note stays in MIDI's range. A grid writes an isomorphic keymap in one line, and the schema tests carry the tracker and fourths keymaps as fixtures so the format is known to express them before chunk 3 ships them. A bare --keymap name resolves only to a built-in in keymaps/, and anything with a slash or a .yaml ending is a path, with ~/ expanded and FIELD_KEYMAP as the default. A keymap given by path reloads on save through a watch on its directory, so an editor's rename-on-save keeps working, and only a change of text reloads.
The terminal decoder reads the kitty keyboard protocol's press, repeat, and release events with their modifiers and base layout keys, the arrows, focus reports, and the answers to the protocol probe, and carries a sequence cut off at the end of one stdin chunk into the next (keyboard-instrument.md §2.2). Escape and Ctrl-C always quit. A key's position comes from the terminal's base layout key when it sends one, and otherwise from the helper's report of the keyboard layout, read backwards; with no report a character reads as its US position (§2.3).
KeysSession maps a position's press and release to MIDI under the keymap (keyboard-instrument.md §2.1, §2.4). It counts the keys holding each note, so a note two keys share gets one note-on and one note-off, and a release always ends the notes its own press started, on their channel, whatever transpose, modifier, or reload came between. Ctrl, Alt, and Cmd block a press; Shift and the lock bits change nothing. Controls cover transpose within MIDI's range, velocity, pitch bend while held, controllers in set, hold, and toggle modes, and panic. Focus-out releases everything, and quitting adds All Notes Off. KeysHelper spawns field-audiod --keys and speaks its NDJSON (§2.5): keyboard layout reports, ready, MIDI lines, and errors. Closing its input removes the virtual source, and an exit the session did not ask for is reported with the helper's own error.
field keys probes the terminal for the kitty keyboard protocol and refuses one without it, naming the terminals that have it. It turns the protocol on with focus reports, starts field-audiod --keys, and plays each key event through its position and the session out to the virtual source, with one status line and a keymap given by path reloading on save. Raw mode and the protocol flags come back on every way out, including a signal and a crash. --print draws the keymap and needs no terminal at all. docs/keys.md is the reference for playing and for writing a keymap; README.md, docs/README.md, AGENTS.md, and architecture.md point to it, and architecture.md records the two new short-lived modes of field-audiod.
…nd keyboard layout report behind field keys (keyboard-instrument.md chunk 1, native half)
`--keys <name>` is a short-lived subprocess mode, apart from the daemon's
socket and transport. On macOS it first reports the active keyboard
layout, read with UCKeyTranslate for every bindable position, and
reports it again whenever the selected input source changes. It then
publishes a virtual MIDI source, prints ready, sends each
{"midi":[...]} line from stdin as one message, and closes the source at
end of input. A malformed line gets an error line and exit 1.
`--midi-monitor <name>` opens the named source, waiting up to five
seconds for it, and prints each message as an NDJSON line until end of
input, SIGTERM, or SIGINT.
src/keys/helper-native.test.ts runs both against the real binary. It
probes for a MIDI service by running `--keys`, and skips by name only on
a Linux machine without the ALSA sequencer.
A release used to resolve its position afresh. Switching the input source while a key was held, or a release reported without the base layout key its press carried, resolved it somewhere else, and the note sounded until focus-out or quit. An end-to-end run through CoreMIDI under a ColemakC layout showed it: the note-off came only with All Notes Off. PressedKeys remembers each pressed key's position by the key the terminal reported, and a release takes that position; focus-out forgets them all.
The plan moves to in-progress with this chunk. §2.4 and §2.8 take what implementation settled: panic is a bare word, a keymap plays at least one note, reload follows a change of text, the grid expands in the schema file, and the shell is src/commands/keys.ts. §9 records chunk 1 as built: the release-follows-press fix an end-to-end CoreMIDI run under ColemakC found, what was verified and how, and what still needs a person at a real keyboard. docs/keys.md says to run field keys again if CoreMIDI refuses the first source.
… the probe drops Review of #178: under the Russian input source, Ctrl plus the key at the US c position arrives as CSI 1089::99;5u, which isQuit did not take for Ctrl-C, so only Esc quit. isQuit now also takes a Ctrl press whose base layout key is c when the typed key is outside ASCII; a layout that types ASCII there, such as Dvorak's j, keeps its own Ctrl-C. The probe's comment promised to return key events that it drops; it now says that only a sequence cut off at the end comes back, and a test pins that.
Review of #178: installing Field links only field onto PATH, so the guide's field-audiod --midi-monitor printed command not found. docs/keys.md and plan criterion 1 now give the binary's path in the checkout, as the pull request's Testing section does, and mention $FIELD_AUDIOD.
Review of #178: positions in a named row never entered the duplicate check, so rows: [home, home] and [home, [KeyA]] loaded, and KeyA silently played the later row's offset.
Review of #178: a toggle controller left on got no 0 from quit or panic, and a reload forgot it was on, so a toggled sustain held the receiver's notes after field keys exited. The session now remembers each toggled-on controller's channel and number and sends it 0 then; setKeymap returns those messages for field keys to send. signed() is now exported once from print.ts and used by the session and the status line.
Review of #178: the round trip copied the bindable positions, so a position added to the schema would not have failed it until keyboard-layout.cpp reported it. It now uses TEXT_POSITIONS.
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CLEAN · took 2m 49s over 2 heads
This pull request adds field keys, chunk 1 of the keyboard-instrument plan. It reads key presses and releases through the kitty keyboard protocol, finds each key's physical position from the terminal's base layout key or from the keyboard layout that a new field-audiod --keys mode reports, and plays a YAML keymap as the virtual MIDI source Field Keys. This head answers the first review's three findings and four suggestions, and rebases the branch onto main, which gained #159. It leaves the voice host, the tracker and fourths built-ins, recording, Linux keyboard layouts, and the hand-run criteria 1 to 20 for later.
3 finding threads: 3 resolved, 0 open
Covered 31 of 31 changed files; none are generated. The rebase changed nothing in the pull request's own patch: the diff from the new merge base is byte-identical to the one at aa8bf6d. #159 touches only field init, which nothing here uses.
Each earlier finding is fixed at this head:
- Ctrl-C under a layout with no
c.isQuitnow also quits on a Ctrl press whose base layout key iscwhen the typed key is outside ASCII.terminal.test.tscovers the Russian case and Dvorak'sj, which keeps its own Ctrl-C. - The probe comment. It now says that complete key events during the probe are dropped and that only a cut-off sequence comes back as
rest. A new test pins that behavior. - The monitor command in
docs/keys.md. The guide gives the binary's path in the checkout and says whyfield-audiodis not on yourPATH. Plan criterion 1 gives the path too.
The four suggestions also landed. Named grid rows count toward the "appears twice" rule, toggled controllers return to 0 at quit, panic, and reload, the native test imports TEXT_POSITIONS, and signed() has one definition.
Disclosures:
- Hand-run criteria. Plan §4 criteria 1 to 20 need a person at Ghostty, iTerm2, and Apple's Terminal. This review did not run them, and plan §9.3 records them as owed.
- Native binary. The round trip ran against a
field-audiodbuilt in a scratch worktree from the first reviewed head. This head leavesnative/unchanged. - CI. The Linux job for this head was still running when this review was published. It passed at the first reviewed head.
Suggestions
docs/keys.md:154: saving now turns a toggled controller back to 0. So with this page's own example keymap, a save while the space bar's sustain is on lets go of the notes the pedal was holding. The paragraph says notes already sounding "finish as they started". Say here, and besidetogglein the Actions table, that quit, panic, and a reload turn a toggled controller off.
What ran at this head:
pnpm typecheck. Clean.vitest run src/keys src/schema/keymap.test.ts src/commands/init.test.ts. 90 tests pass, including the 8 native round-trip cases on macOS and the new tests for the Russian Ctrl-C, the dropped probe events, named-row duplicates, and toggles turned off at quit, panic, and reload.project check. The plans are valid.- The rebase. The pull request's patch from its new merge base matches the one from its old merge base line for line.
Review of #178: since a reload turns a toggled controller back to 0, saving the guide's own example keymap with the space bar's sustain on lets go of the notes the pedal held, which the reload paragraph did not say.
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 1m 02s
This pull request adds field keys, chunk 1 of the keyboard-instrument plan. It reads key presses and releases through the kitty keyboard protocol, finds each key's physical position from the terminal's base layout key or from the keyboard layout that a new field-audiod --keys mode reports, and plays a YAML keymap as the virtual MIDI source Field Keys. This head adds one docs commit to the head the last review passed. It follows that review's suggestion: docs/keys.md now says that quit, panic, and a reload turn a toggled controller back to 0. It leaves the voice host, the tracker and fourths built-ins, recording, Linux keyboard layouts, and the hand-run criteria 1 to 20 for later.
4 finding threads: 3 resolved, 1 open
Covered 31 of 31 changed files; none are generated. Since d20bab9 only docs/keys.md changed. Nothing under src/ or native/ moved, so the three earlier findings stay fixed as the last review verified.
The new text is accurate. KeysSession sends 0 for each controller a toggle key left on in quit, in panic, and in setKeymap, which play calls on each successful reload. A save that fails validation reloads nothing, so it leaves a toggle alone, which matches "on the reload".
Disclosures:
- Hand-run criteria. Plan §4 criteria 1 to 20 need a person at Ghostty, iTerm2, and Apple's Terminal. This review did not run them, and plan §9.3 records them as owed.
- Native binary. The round trip ran against a
field-audiodbuilt in a scratch worktree from the first reviewed head. This head leavesnative/unchanged.
What ran at this head:
pnpm typecheck. Clean.vitest run src/keys src/schema/keymap.test.ts. 89 tests pass, including the 8 native round-trip cases on macOS.project check. The plans are valid.- Line widths. Every prose line in the
docs/*.mdfiles at the merge base is 80 characters or less.
Review of #178: adding the toggle sentence joined the next sentence onto its line, leaving a 122-character line in a paragraph wrapped at 72.
ninjudd
left a comment
There was a problem hiding this comment.
📽️ Projector review · 0.7.3 · model claude-opus-5-5 · effort xhigh · CLEAN · took 0m 25s
This pull request adds field keys, chunk 1 of the keyboard-instrument plan. It reads key presses and releases through the kitty keyboard protocol, finds each key's physical position from the terminal's base layout key or from the keyboard layout that a new field-audiod --keys mode reports, and plays a YAML keymap as the virtual MIDI source Field Keys. This head adds one commit to the last reviewed head: it rewraps the paragraph in docs/keys.md that the last review found with a 122-character line. It leaves the voice host, the tracker and fourths built-ins, recording, Linux keyboard layouts, and the hand-run criteria 1 to 20 for later.
4 finding threads: 4 resolved, 0 open
Covered 31 of 31 changed files; none are generated. Since cd3a125 only docs/keys.md changed.
The wrap finding is fixed. Every line of the paragraph is now 72 characters or less, and its words are identical to cd3a125, so only the line breaks moved. The three earlier findings stay fixed, because nothing under src/ or native/ changed.
Disclosures:
- No new test run. Only documentation changed, so this review did not rerun
pnpm typecheckor the tests. Atcd3a125, which has the same code, typecheck was clean and 89 focused tests passed, including the 8 native round-trip cases on macOS. - Hand-run criteria. Plan §4 criteria 1 to 20 need a person at Ghostty, iTerm2, and Apple's Terminal. This review did not run them, and plan §9.3 records them as owed.
What this review checked:
- The rewrap. Line widths in the paragraph, and a word-for-word comparison with
cd3a125. - The code. Nothing under
src/ornative/changed sincecd3a125. - The earlier findings. All four finding threads are resolved, and each fix is still in place at this head.
…(keyboard-instrument.md chunk 2) (#179) The first chunk of the keyboard-instrument plan made the computer keyboard a MIDI source, but Field still had no way to play its own instruments from notes: a SuperCollider instrument could only render offline from a spec. This chunk, stacked on #178, adds `field keys <instrument>`, which plays an instrument from the `shared/instruments/` shelf live, from the keyboard and from every other MIDI source, so you can audition how a sound responds under your fingers. The instrument plays through a voice host: `sclang` running Field's `sc/voice-host.scd`. The host boots its own `scsynth` on the output device at the device's current rate, loads the instrument's voice, and plays one voice per note, with the sustain pedal, All Notes Off, and pitch bend. An instrument opts in with a voice mode beside its unchanged render mode: under `FIELD_MODE=voice` its value is a SynthDef with `freq`, `amp`, `gate`, and `out`. `still-water-pad` in `examples/bloom` now answers it, and its render branch still renders the same bytes for seed 90210. The voice's sound goes straight to the device beside `field play`'s, until live-supercollider puts `scsynth` in the session graph. Running the host on real hardware found that the plan was wrong about one thing. On macOS `scsynth` opens the default input device even with no input channels, and opening it waits on the microphone permission, so a host started from a process that cannot ask never becomes ready, and one started from a terminal would show a microphone prompt for a keyboard instrument. The host now names one device for both directions, and `field-audiod --keys` reports the system output's name for when `--device` is absent. Plan §10.1 records the evidence, and §2.6 is corrected. The rest keeps the host from outliving `field keys` or hiding its failures. The host watches its own boot, because SuperCollider 3.14's `waitForBoot` never reports a server that exits while it boots, and it fails naming the device when that happens or after 20 seconds. It checks the device name before boot, refusing one `scsynth` would not find (which would open the microphone) and one with characters that would reach the shell that starts `scsynth`. It ignores notes until its server answers. `field keys` chooses the `scsynth` port so it can send `/quit` itself, the host reports each server's process so a booting server can be stopped by process too, `Esc` closes a host that is still booting, the host quits once `field keys` is gone, and a device whose rate moves under the host restarts its server rather than leaving every note sharp or flat. An instrument without a voice mode, such as `creek-kit`, stops `field keys` with `creek-kit.scd does not answer FIELD_MODE=voice` and the output that explains why. `sclang` is now found in one place, `sclangCommand()`, for renders and the host alike. ## Testing Run these from the repository root of this branch, with SuperCollider installed and the daemon built (`pnpm build:native`), since this layer changes `field-audiod`. ```sh pnpm install --frozen-lockfile pnpm build:native pnpm typecheck pnpm test ``` `pnpm test` passes, including `src/keys/voice-host.test.ts`, which runs the host's protocol against a stub `sclang` and needs no SuperCollider, and the native round trip, which now also checks the ready line's `output` field on macOS. When I ran them on this head, the suite passed 903 tests with none skipped, and typecheck was clean. Then check that the pad's render did not move. From `examples/bloom`, with `field` on your `PATH`: ```sh cd examples/bloom git show main:examples/bloom/shared/instruments/still-water-pad.scd > /tmp/pad-main.scd field sc render /tmp/pad-main.scd --seed 90210 --duration 10 --output /tmp/pad-main.wav field sc render shared/instruments/still-water-pad.scd --seed 90210 --duration 10 --output /tmp/pad-branch.wav cmp /tmp/pad-main.wav /tmp/pad-branch.wav ``` `cmp` prints nothing. I ran the same render on this file before and after the edit, and the two files were identical. Any difference means the voice-mode edit changed the render branch. The commands leave the four files in `/tmp`. Then play it, in Ghostty or iTerm2, from `examples/bloom`: ```sh field keys still-water-pad ``` The status line shows `still-water-pad starting`, then `still-water-pad live at 48000 Hz on <your output>` within a few seconds. Play a chord: you hear the pad. Hold `Tab` and release the keys: the notes ring until you release `Tab`. Hold `2` over a sounding note: it bends up two semitones and returns on release. `Esc` stops everything, and `pgrep scsynth` finds nothing left. A microphone prompt, a host that never goes live, or an `scsynth` left running means the change is wrong. `field keys creek-kit` exits 1 naming `FIELD_MODE=voice`. What I could not run: every check that makes sound. I ran the host on this Mac with a silent voice and heard a note start and end a voice through CoreMIDI, started `still-water-pad`'s voice live without playing it, saw `creek-kit` rejected, and killed the parent to see `sclang` and `scsynth` exit within three seconds. Plan §10.3 lists what was verified and §10.4 what is owed: criteria 21 to 26 by ear, including the rate restart, which needs a device whose rate moves. <!-- projector-summary v=1 sha=b35267b94290ad445351aa5283c1df3ab426b9b4 --> 📽️ **Projector summary** of b35267b: https://field.amnes.ac/reviews/179
…#181) Musical Typing is the keymap most musicians know from a computer keyboard, but it reaches only 18 notes before you transpose. This chunk of the keyboard-instrument plan, stacked on #179, ships the two alternatives the plan chose as built-ins: `tracker`, the layout trackers have used from FastTracker 2 to Renoise, with two piano octaves on the bottom and top rows (32 notes), and `fourths`, an isomorphic grid with a semitone per key and a perfect fourth per row (27 notes), where a chord shape plays the same in every key. Both are plain keymap files in the format #178 introduced, and both were already that chunk's schema fixtures, so the format was known to express them; the tests now read the shipped files instead. Each puts transpose and velocity on the arrows and sustain on `Space`, because their notes take the rows Musical Typing keeps for controls. `docs/keys.md` describes them, and the plan records the chunk as built in §11. ## Testing Run these from the repository root of this branch. `field keys` needs the daemon (`pnpm build:native`); `--print` does not. ```sh pnpm install --frozen-lockfile pnpm typecheck pnpm test pnpm field keys --keymap tracker --print pnpm field keys --keymap fourths --print ``` `pnpm test` passes; when I ran it on this head, 904 tests passed with none skipped. The `tracker` diagram puts C3 under `Z` and C4 under both `,` and `Q`; the `fourths` diagram puts C3 under `Z`, F3 under `A`, A#3 under `Q`, and D#4 under `1`. A diagram with notes elsewhere means a keymap file is wrong. Then play them in Ghostty or iTerm2 with `pnpm field keys --keymap tracker` and, in a second terminal, `native/audiod/build/field-audiod_artefacts/Release/field-audiod --midi-monitor "Field Keys"`. Pressing `Z`, `Q`, and `I` prints note-ons 48, 60, and 72, and `→` shows `transpose +12` on the status line. With `--keymap fourths`, pressing `Z B D` together and then `X N F` together prints 48, 52, 55 and then 49, 53, 56. I ran both in a pseudo-terminal through the real helper and CoreMIDI, typing as this Mac's ColemakC keyboard layout does, and the monitor heard exactly those notes, each with one note-off. Real keys in a real terminal are still owed, as plan §9.3 says. The commands leave no state behind. <!-- projector-summary v=1 sha=07e720867e718bd72878ed35abb4738f676718c8 --> 📽️ **Projector summary** of 07e7208: https://field.amnes.ac/reviews/181
…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
Field could hear an instrument only by rendering it: nothing took notes, and nothing read the keyboard as anything but commands. This is the first chunk of the keyboard-instrument plan (
docs/projects/keyboard-instrument/readme.md).field keysturns the computer keyboard into a virtual MIDI source namedField Keys, which Logic or any other MIDI application can play from. The later layers of this stack play a SuperCollider instrument from it, add two more built-in keymaps, and record what you play.Terminals normally report only key presses, and a note needs its release, so
field keysreads releases through the kitty keyboard protocol. Ghostty, iTerm2 3.5 and later, kitty, and WezTerm speak it.field keysprobes for it and refuses a terminal without it, naming the ones that have it. It also turns on focus reports, so a terminal that loses focus releases every held note instead of leaving one stuck.Keys are read by physical position, never by character, so Dvorak, AZERTY, and Colemak play the same notes without switching back to QWERTY. A position comes from the terminal's base layout key when the terminal sends one, and otherwise from the keyboard layout the native helper reads from macOS, which follows an input-source switch while you play. A release takes the position its press resolved to, which an end-to-end run under a ColemakC layout showed is needed: a release resolved afresh could land on another position and leave the note sounding.
What each key plays comes from a keymap: a YAML file, checked by a zod schema, that binds positions (named by their
KeyboardEvent.codevalues) to notes, chords, and controls. The built-inmusical-typingkeymap follows Logic Pro's Musical Typing, with pitch bend and modulation, and it uses the same format as a keymap you write. A bare--keymapname picks a built-in and anything else is a path;FIELD_KEYMAPsets your default; a keymap given by path reloads when you save it; and--printdraws any keymap as a keyboard. The tests carry the tracker and fourths keymaps as fixtures, so the format is known to express them before chunk 3 ships them.The native work is two short-lived modes of
field-audiod, not an npm binding, so the control plane stays free of native dependencies and JUCE stays inside the daemon.--keysowns the virtual source and reports the keyboard layout;--midi-monitorprints what a named MIDI source sends, which the round-trip test and a person checking a controller both use.docs/keys.mdis the reference for playing and for writing a keymap, and the plan moves toin-progresswith §9 recording this chunk as built.Testing
Run these from the repository root of this branch. Build the daemon first with
pnpm build:native; without it the native round trip skips andfield keysrefuses to start.pnpm install --frozen-lockfile pnpm build:native pnpm typecheck pnpm test pnpm field keys --printpnpm testpasses, includingsrc/keys/helper-native.test.ts, the native MIDI round trip, which runs 8 cases on macOS and skips by name only on a Linux machine without/dev/snd/seq. A failure there that saysexited before stdout line 1means the binary predates--keys.pnpm field keys --printdraws the Musical Typing keyboard: C4 underA, black keys on the row above,T-12andT+12onZandX. When I ran them on this head, the suite passed 890 tests with none skipped, and typecheck was clean.Then play it, in Ghostty or iTerm2:
In a second terminal, from the same directory:
native/audiod/build/field-audiod_artefacts/Release/field-audiod --midi-monitor "Field Keys"Press and release
Ain the first terminal: the monitor prints{"midi":[144,60,100]}then{"midi":[128,60,0]}. HoldA, pressX, releaseA: the note-off is for 60, not 72. Switch to another window while holding a key: its note-off arrives when focus leaves.Escsends All Notes Off ([176,123,0]), the shell echoes normally afterwards, and the monitor can no longer findField Keys. A note-on with no note-off, or a terminal left in raw mode, means the change is wrong. In Apple's Terminal,field keysexits 1 naming the supported terminals.What I could not run: I drove
field keysin a pseudo-terminal by typing the protocol's bytes, under a stub helper reporting Dvorak and under the real helper on this Mac's ColemakC layout, heard through CoreMIDI. That proves the decoding, the positions, the session, and the helper, but not how Ghostty, iTerm2, and Apple's Terminal behave with real keys; plan §4 criteria 1 to 20 and §9.3 list what to try by hand, including switching input sources mid-session. Nothing has run on Linux. The commands leave no state behind.📽️ Projector summary of ee005c1: https://field.amnes.ac/reviews/178