Skip to content

Record several armed tracks in one pass: audio, MIDI, or both (arming.md chunk 2) - #191

Merged
ninjudd merged 3 commits into
keys/armingfrom
keys/record-tracks
Oct 11, 2026
Merged

ninjudd merged 3 commits into
keys/armingfrom
keys/record-tracks

Conversation

@ninjudd

@ninjudd ninjudd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

field record recorded one track per pass, because field-audiod held one arm. Singing and playing together, or two MIDI parts, took two performances. Justin asked on 2026-10-11 to record audio, MIDI, or both. This is chunk 2 of the arming plan (#189, which this is stacked on): name several tracks, and one pass records every one of them, each take starting on the same sample and landing on its own track.

field record now takes any number of tracks. planArm resolves each to its record entry before anything opens, where its instrument decides MIDI or audio, and gives each audio track its --input in the order named: --input 1,2, or 1, 2, and on by default. It refuses, with a message saying why:

  • a track named twice;
  • tracks in two songs;
  • --input, --device, or --loop when every track records MIDI;
  • --loop over more than one track.

One track arms exactly as before. Several arm through the daemon's arm with tracks, and every take that comes back lands, whether it arrives as an event, from the stop, or through the recordings fallback. If one take of several never arrives, field record exits with an error naming the track and the field record --recover <id> that finalizes it, as a single track's lost take always has. field transport status in another terminal lists every armed track, a MIDI one by the sources it hears.

The daemon was the real work. Rather than rewrite the capture path, which carries the latch, count-in, punch-out mid-block, and the loop hand-off, the first armed track is the primary, and every one of those rules runs on it unchanged. The other tracks are companions, in fixed slots the audio callback reads only through atomics, so the message thread can change a slot while it is not live and nothing on the audio thread allocates. Companions start on the primary's latch, an audio companion pushes the same span of its own input, and they end with the pass. An audio track is the primary whenever one is armed, so --until still cuts audio on its exact sample. A MIDI take ends a block after until, so that messages drained late are still stamped. That stamping is now one step: a MIDI primary's companions mirror it, and an audio primary's MIDI companions run it themselves, a block after the audio ends. The pass finalizes when every take has ended. arm and the MIDI arm are one-entry forms of armSet, with their answers unchanged. armSet opens the MIDI sources, unstarted, before it touches the audio device, so a set refused for its MIDI or its audio leaves the device, and the arm before it, as they were. stop returns every manifest as takes beside take. status.record lists armed when more than one track is armed, and the MIDI sources whenever one of them records MIDI, so a one-track status is unchanged. recordings and recover know every take in flight. The null input presents each armed channel in order, which is how the tests tell input 1 from input 2.

Docs follow the behavior. docs/audio-engine.md gains "Several armed tracks". docs/cli.md describes recording several tracks and gains the field keys row it never had. docs/keys.md shows singing and playing in one pass. Plan §10 records the chunk. It also records something found along the way: an audio punch-out against a file bed ends 3 samples short of until, with one track as with several, because a file bed's reported position runs a few samples ahead. That is older than this change, and #194 tracks it.

Testing

From the repository root of this branch, after pnpm install, with the native tools rebuilt from this branch (pnpm build:native; the daemon changed):

pnpm typecheck
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm exec vitest run src/commands/record-tracks-daemon.test.ts src/commands/record-plan.test.ts
FIELD_AUDIOD=$PWD/native/audiod/build/field-audiod_artefacts/Release/field-audiod pnpm test

The typecheck passes. The two focused files pass 8 of 8, and the full suite passes 1004 with 1 skipped (the no-MIDI-source case, which runs only without a MIDI service). record-tracks-daemon.test.ts runs the daemon in null mode:

  • Two audio tracks on inputs 1 and 2: one take holds the sawtooth, the other the constant, with the same start and length. An input or a track armed twice is refused, and so is a loop over two. A set the daemon refuses leaves the arm before it as it was.
  • An audio track and a MIDI track: both start together, and the MIDI take holds the note.
  • A punch-out at 24000 over a live session: the audio take is exactly 24000 frames, the MIDI take ends a block later at 24000, and both land.
  • Two MIDI tracks: both hold the same notes.
  • field record with an audio and a MIDI track: it lands both on their own tracks, field transport status names both while they record, and field check is clean.

The MIDI cases skip on Windows, which has no virtual MIDI ports, as record-midi-daemon.test.ts does.

The existing daemon tests (record-daemon, punch-daemon, record-midi-daemon, click-daemon, play-daemon) all pass against the reworked daemon, which is the evidence that one track records exactly as before. A take holding the wrong input, two takes with different starts, or any of those older tests failing would mean the change is wrong.

Nothing here played through a real interface. Plan criteria 6 to 8, two microphones on two inputs and a controller beside a vocal, are owed by hand. The tests leave nothing behind outside their temporary directories.

📽️ Projector summary of 30c7303: https://field.amnes.ac/reviews/191

….md chunk 2)

field record takes any number of tracks. planArm resolves each to its record entry and kind, gives each audio track its --input in order, 1, 2, and on by default, and refuses a track named twice, tracks in two songs, audio flags on MIDI-only sets, and --loop over more than one track. One track arms as before; several arm through the daemon's arm with tracks, and every take lands on its own track.

In field-audiod, arm and armMidi are one-entry forms of armSet. The first armed track is the primary, on which every existing capture rule runs unchanged; the rest are companions in fixed slots the callback reads through atomics. They start on the primary's latch, an audio companion pushes the same span of its own input, and they end with the pass. An audio track is the primary whenever one is armed, so --until still cuts audio exactly; the MIDI clock's stamping is one step that a MIDI primary's companions mirror and an audio primary's MIDI companions run, ending a block after the audio. stop returns every manifest as takes beside take, status lists armed when more than one track is, and the null input presents each armed channel. Loop takes stay one track.

docs/audio-engine.md, docs/cli.md (which also gains its missing field keys row), and docs/keys.md describe it; plan §10 records the chunk and a pre-existing 3-sample punch-out shortfall against a file bed.
@ninjudd
ninjudd added this pull request to stack #190 October 11, 2026 05:46

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 25m 00s

This change lets field record arm and record several tracks in one pass, any mix of audio and MIDI, as chunk 2 of the arming plan. The CLI resolves every target before anything opens and gives the audio tracks their inputs in the order named. The daemon keeps every existing capture rule on one primary track and adds up to 15 companions in fixed slots that the audio callback reads only through atomics; they start on the primary's latch and end with its pass, and stop, status, recordings, and recover learn about every take. It knowingly leaves loop takes to one track, MIDI routing to unison, the lasting arm to chunk 3, and plan criteria 6 to 8 to a hand test on a real interface.

2 finding threads: 0 resolved, 2 open

Covered 17 of 17 changed files; none are generated.

  • No real device. I opened no audio or MIDI device. The daemon tests run in null-output mode, with field-audiod --keys publishing a virtual MIDI source. The arm finding rests on reading, because null mode never opens a device.
  • Windows CI. The Windows job fails 19 tests against the base branch's 12. Five are this change's new test file, which a thread covers. The other two are a 5-second timeout in live-session.test.ts and the inventory cache case in plugin-hosting.test.ts, a known flake; neither runs code this change touches.

The arming plan is in-progress. This change adds §10 and no open question. Of §7's questions, the first belongs to chunk 3 and the other two are explicitly deferred. §10 records criteria 6 to 8 as owed by hand and the file-bed punch-out as outside this chunk, so the readiness gate holds.

Suggestions

  • src/commands/record.ts:481: after the recordings fallback, name each transaction in started.takes that never landed, with field record --recover <id>. A take whose finalize throws is left out of stop's takes and sends no event, so beside a take that lands it goes unreported and field record exits 0, where one track with the same failure throws "its manifest never arrived".
  • src/commands/transport.ts:129: field transport status prints only the primary's track and input. Read status.record.armed so a second terminal sees every armed track.
  • docs/projects/arming/readme.md:94: the shapes table gives each armed entry "input or sources", but the daemon puts no sources on a MIDI entry; they stay on status.record itself. Make the two agree.
  • docs/projects/arming/readme.md:256: the file-bed punch-out that ends 3 samples short is recorded only as "not this chunk's". Give it a home that tracks it, such as an issue or the recording plan.

What holds

  • The callback. recordAudioBlock, recordMidiCompanions, and stampMidiBlock allocate nothing, take no lock, and do no I/O; the added work is a bounded loop over at most 15 slots.
  • Detach and finalize. stopRecording keeps the wait for two epochs before the MIDI detach and after it, and covers the companions in both. After a punch-out, serviceCapture finalizes a companion only after the callback has cleared its pointer and set captureDone, in either order of the audio cut and the MIDI end.
  • The MIDI clock. Companions of an audio primary stamp against midiUntilFrames, which converts until to the device's samples as #182 settled. One midiArrivalsLost exchange per block feeds every take's dropped, and a block with no MIDI take running still drains the queue.
  • Crash safety. Each companion is its own transaction with its own journal, so recordings lists it as active and recover refuses it while it records.
  • Protocol. Every reader of stop, record, arm, and status.record in src/ reads the new fields as optional, so a one-track daemon and a one-track CLI behave as before.

I ran pnpm install --frozen-lockfile, pnpm typecheck, and project check, which all pass; record-plan.test.ts and cliParsers.test.ts, 16 of 16; a Release field-audiod built from this head, with no warnings from native/audiod/src; and against it record-tracks-daemon, record-daemon, record-midi-daemon, punch-daemon, click-daemon, and play-daemon, 42 passed and 1 skipped, the no-source case this machine's MIDI service rules out.

Comment thread native/audiod/src/player.cpp Resolved
armSet opened the duplex input before looking for MIDI sources, so a set refused for its MIDI left the microphone open with nothing armed, or a previous audio arm's channels changed under it. MIDI sources now open first, unstarted, so a MIDI refusal returns before the device changes and an audio failure drops only those inputs; the companions stop being read only once a failed close can no longer leave the arm before them.

field transport status lists every armed track, a MIDI one by the sources it hears, and status.record names those sources for an audio primary's MIDI companions too. When one take of several never arrives, field record exits naming the track and its --recover command. The new daemon test skips its MIDI cases on Windows and cleans up with removeTempProject, and the plan points the file-bed punch-out at #194.

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

📽️ Projector review · 0.7.4 · model claude-opus-5-5 · effort xhigh · CHANGES REQUESTED · took 28m 30s

This change lets field record arm and record several tracks in one pass, any mix of audio and MIDI, as chunk 2 of the arming plan. The CLI resolves every target before anything opens. The daemon keeps every capture rule on one primary track and adds up to 15 companions that the audio callback reads only through atomics. This head answers the first review: armSet opens its MIDI sources before the audio device, the new daemon test skips its MIDI cases on Windows and cleans up with removeTempProject, and the four suggestions are taken. It knowingly leaves loop takes to one track, MIDI routing to unison, the lasting arm to chunk 3, and plan criteria 6 to 8 to a hand test on a real interface.

3 finding threads: 2 resolved, 1 open

Covered 18 of 18 changed files; none are generated. I read the whole diff on the first head and, on this head, the new commit in full along with src/commands/transport.ts, which joins the change here.

  • No real device. I opened no audio or MIDI device, so the arm fix is verified by reading armSet and by the daemon test of a refused set, which checks the daemon's state but cannot see the device in null mode.

The earlier findings, checked at this head:

  • The refused arm (player.cpp). Fixed. Both MIDI refusals, "no MIDI sources" and "cannot open any MIDI source", now return before openAudioInputs changes the device. After a successful audio open nothing else can fail, because closeAudioInput runs only for a set with no audio. liveCompanions is cleared only after that close, so a refused close keeps the arm before it whole.
  • The Windows test failures. Fixed. publish skips on win32, afterEach uses removeTempProject, and the Windows job for this head, run 38117906465, passes this file's audio case and skips its four MIDI cases. That job fails the same 12 tests as the base branch's run and no others.

The arming plan is in-progress. This head answers nothing new and opens no question; §10 now points the file-bed punch-out at #194, which is open. The readiness gate holds.

What holds

  • The arm. A set's MIDI inputs open unstarted and drop with no side effect when the audio open fails, and a refused set leaves armedInputs, captureChannel, and the companion slots as they were.
  • The new status line. field transport status falls back to the one-track fields when status.record.armed is absent, so an older daemon reads as before, and a lone MIDI arm now prints its sources rather than undefined input undefined.
  • The missing-take error. field record names a track only after the recordings fallback has landed every complete take, so a take it names is incomplete on disk and --recover is the command that finalizes it.

I ran pnpm install --frozen-lockfile, pnpm typecheck, and project check, which all pass; record-plan.test.ts and cliParsers.test.ts, 16 of 16; a Release field-audiod built from this head, with no warnings from native/audiod/src; and against it the record-tracks, record, record-midi, punch, click, and play daemon tests and src/audiod, 62 passed and 1 skipped, the no-source case this machine's MIDI service rules out. CI on Linux passes, and Windows fails only the base's 12.

Comment thread docs/projects/arming/readme.md Resolved

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

This change lets field record arm and record several tracks in one pass, any mix of audio and MIDI, as chunk 2 of the arming plan. The CLI resolves every target before anything opens. The daemon keeps every capture rule on one primary track and adds up to 15 companions that the audio callback reads only through atomics. This head rewraps the arming plan's punch-out note, which the review of 6e2c0ec found too wide. It knowingly leaves loop takes to one track, MIDI routing to unison, the lasting arm to chunk 3, and plan criteria 6 to 8 to a hand test on a real interface.

3 finding threads: 3 resolved, 0 open

Covered 18 of 18 changed files; none are generated. The full diff was read at 9217fe4 and 6e2c0ec. Since 6e2c0ec, this head changes two lines of docs/projects/arming/readme.md and nothing else.

  • Not rerun. I did not rebuild field-audiod or rerun the daemon tests, because no file under native/ or src/ differs from 6e2c0ec. At 6e2c0ec, a daemon built from the head passed the daemon tests (62 passed, 1 skipped), Linux CI passed, and Windows CI failed only the base branch's 12 tests. CI for this head was still running when this review posted.
  • No real device. No audio or MIDI device was opened at any head.

The earlier findings, checked at this head:

  • The refused arm (player.cpp). Fixed at 6e2c0ec, and unchanged here. Both MIDI refusals return before openAudioInputs changes the device, and nothing can fail after a successful audio open.
  • The Windows test failures. Fixed at 6e2c0ec, and unchanged here. The MIDI cases skip on Windows and afterEach uses removeTempProject.
  • The plan's line wrapping. Fixed. Lines 261 and 262 are 69 and 67 characters, inside the paragraph's own width of 67 to 73, and the words match 6e2c0ec's exactly. No prose line in the plan runs past 80 characters.

The arming plan is in-progress, and this head adds no question; §10 points the file-bed punch-out at #194, which is open. The readiness gate holds.

What was checked

  • The callback. recordAudioBlock, recordMidiCompanions, and stampMidiBlock allocate nothing, take no lock, and do no I/O. The added work is a bounded loop over at most 15 slots.
  • The arm. armSet opens MIDI sources unstarted before the audio device, so a refused set leaves the device, armedInputs, captureChannel, and the companion slots as they were.
  • Detach and finalize. stopRecording waits two epochs before and after the detach, MIDI companions included. After a punch-out, serviceCapture finalizes a companion only once the callback has cleared its pointer, in either order of the audio cut and the MIDI end.
  • The MIDI clock. Companions of an audio primary stamp against midiUntilFrames, in the device's samples. One midiArrivalsLost exchange per block feeds every take's dropped.
  • Crash safety. Each companion is its own transaction with its own journal, which recordings lists as active and recover refuses while it records.
  • Protocol and CLI. Every reader of stop, record, arm, and status.record treats the new fields as optional. field record names any take that never landed with its --recover command, and field transport status lists every armed track.
  • Checks at this head. project check passes.

@ninjudd
ninjudd marked this pull request as ready for review October 11, 2026 06:55
@ninjudd
ninjudd merged commit d53b282 into main Oct 11, 2026
1 of 2 checks passed
@ninjudd
ninjudd deleted the keys/record-tracks branch October 11, 2026 15:08
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