Repository navigation
Move the metronome into the engine and count a take in on the exact sample (recording.md chunk 3) - #169
Conversation
…ample (recording.md chunk 3) The click was a CLI-side DSP baking ticks into a temp copy of the artifact, which is why it refused a live song and --watch: there was a file to swap out from under it. Now the CLI projects the tempo map into a schedule — tick positions with accent flags on the bed's timeline — and the daemon synthesizes them in the callback against the same block-start position the capture latches on, in the device domain so a schedule at one rate lands on the same instants through a device at another. The daemon still never learns what a bar is. A schedule belongs to a bed: a load or a fresh session clears it, a swap keeps it and the watch re-sends it, and the CLI clears it when its play or take ends. A count-in is a pre-roll: record gained a start beside at, the transport locates there and plays, and the callback begins the take on the first sample at or after at — mid-block — so started_at_samples is at exactly, where chunk 1 latched the block after the request. Status reports the take pending until then. --count-in N clicks only the N bars before --at; --click clicks the whole bed; they compose. The same start is chunk 4's punch-in. --render-live takes --click so the suite can read a rendered bar back and prove the ticks land on their samples. click.ts keeps beatGrid and loses the DSP, the temp file, the re-hash, and the whole-file WAV codec's one production caller. Daemon 0.13.0 with features click and record-start. Landing also reads the musical position off a bed that is an artifact of the song, not only off its live session. Claude-Session: https://claude.ai/code/session_01CVAnQW78ZkZfxZ2GdKV886
minjudd
left a comment
There was a problem hiding this comment.
🔭 Projector review · model claude-opus-5[1m] · effort xhigh · APPROVED · took 4m 07s
0 finding threads: 0 resolved, 0 open.
12a91b1 is clean. review.allow_approve is now true in ~/amnesiac/.projector.toml — I re-read it at submission rather than trusting the value from session start — so this should have gone up as a real APPROVE. It could not: submitting the approval was refused by my own session's permission layer, and routing around that is not something a review loop should do. So this is a COMMENT carrying an approved verdict, exactly as it would read with the setting off, and the GitHub approval remains a human click.
The binary I tested against is this head, which matters more than usual here — most of the substance is C++, and a stale daemon would have made nine passing daemon tests meaningless:
$ strings field-audiod | grep -E '^0\.1[0-9]\.[0-9]$'
0.13.0
$ nm -C field-audiod | grep 'field::Click::'
field::Click::setSchedule(juce::var const&)
field::Click::render(long long, double, float* const*, int, int)
field::Click::clear() / tickCount() const
Click::render keeps the audio thread's contract. It takes a ScopedTryLock and returns on failure rather than blocking, allocates nothing — lower_bound over the existing vector and a fixed Voice voices[4] — and is noexcept. The header's "a missed block is a block without a click" is honest about the cost, and it is the same discipline the live session already uses.
I went looking for a rate-domain bug and found the hole already closed. render scans ceil(n / scale) schedule samples per block while the caller advances position by whatever the bed consumed, and with no bed it passes freeBefore — a device-frame clock — into a function that treats its argument as schedule samples. That combination would drift or double-trigger ticks whenever the device rate differed from the schedule's. It cannot arise: player.cpp:340 clears the schedule on unload ("a schedule belongs to a bed") and :466 clears it on a fresh bed, so the free-clock path only ever runs with an empty ticks, which render returns on immediately. Every CLI path passes a matched rate too — play.ts sends loaded.sample_rate, and record.ts derives one under the comment that both projections speak the bed's rate.
The stale-daemon story is handled the right way. Adding click and record-start did not bump PROTOCOL_VERSION — it stays 1 on both sides — and it should not, because the daemon advertises the new ops in its hello features instead. I checked that the CLI actually consults that rather than merely receiving it: record.ts:190 gates record-start, and both click senders gate on supports('click') — record.ts:201 and play.ts:108 — each with an error naming the remedy ("field transport quit, then play again (it respawns on the new build)"), which is the idiom field transport quit already documents. That is the case I expected to be the finding here, and it is covered.
Tooling: tsc --noEmit clean, full suite 697 passed / 25 skipped / 0 failed, including the new 213-line click-daemon.test.ts. project check valid. The plan stays status: in-progress / priority: now and introduces no unresolved questions, so there is no readiness flip to gate. Merges cleanly with main at 7c84226.
The verdict is approved; the approval itself is still yours to click, for the permissions reason above rather than because anything here is unresolved. CI had not reported when I submitted, so the green is my local run against a daemon built from this head; it was CI rather than my review that caught the meter bug on #166, so it is worth letting the linux job land.
minjudd
left a comment
There was a problem hiding this comment.
🔭 Projector review · model claude-opus-5[1m] · effort xhigh · APPROVED · took 1m 51s
0 finding threads: 0 resolved, 0 open.
Re-review of the same head, 12a91b1, to carry the verdict the earlier pass reached. That one went up as a COMMENT because submitting an approval was refused by my session's permission layer, not because anything was unresolved; Justin has since asked for the approval directly, so this is the same verdict as a real one. review.allow_approve is true, re-read at submission from /Users/justin/amnesiac/.projector.toml, and this is a cross-author review — minjudd reviewing ninjudd.
Nothing has moved since: the head is the same SHA, main is still 7c84226, and no finding thread is open. Re-verified now rather than assumed — tsc --noEmit passes and the three test files this change owns are green (click-daemon.test.ts, click.test.ts, record-daemon.test.ts, 21 tests).
The substance from the first pass stands, briefly:
- The daemon binary under test was built from this head —
0.13.0embedded,field::Click::*exported — so the daemon tests exercised the real code rather than a stale build. Click::renderkeeps the audio thread's contract:ScopedTryLockwith an early return rather than a block, no allocation, fixedVoice voices[4],noexcept.- The rate-domain hazard I went looking for is closed by construction:
player.cpp:340clears the schedule on unload and:466on a fresh bed, so the free-clock path only ever runs with an emptyticks. - The new ops are gated on advertised capability rather than a protocol bump —
PROTOCOL_VERSIONstays 1, andrecord.ts:190,record.ts:201andplay.ts:108all checksupports(...)before use, each namingfield transport quitas the remedy.
Full suite at this head was 697 passed / 25 skipped / 0 failed, project check valid, plan unchanged at status: in-progress with no new open questions.
Merging is still yours. CI on this head had not reported when I first reviewed it — worth confirming the linux job is green before you merge, since it was CI rather than my review that caught the meter bug on #166.
Chunk 3 of recording.md: the metronome moves into the engine, and a count-in begins the take on the exact sample. The CLI projects the tempo map into a click schedule —
{rate, ticks: [{sample, accent}]}on the bed's timeline — and hands it over a newclickop; the daemon synthesizes the ticks in the callback against the same block-start position the capture latches on. The daemon still never learns what a bar is (playback.md §3.6).What changed for a person
field play <song> --clickandfield play <artifact> --click --watchboth work now. The old click was a CLI-side DSP baking ticks into a temp copy of the artifact, which is why it refused a live song (no file) and--watch(a file to swap out from under it). Both refusals are deleted,click.tskeepsbeatGridand loses the DSP, the temp file, the re-hash, and the whole-file WAV codec's one production caller.field record creek/track:lead-vocal --at 17 --count-in 2pre-rolls from bar 15, clicking through bars 15 and 16, and the take begins exactly at bar 17:recordgained astartbesideat, the transport locates tostartand plays, and the callback begins the take on the first sample at or afterat— mid-block, pushing from that offset — sostarted_at_samplesisatto the sample, where chunk 1's latch was the block after the request.statusreports the takependinguntil then and the CLI prints acount-in 15.1.1 (…) → 17.1.1 (…) (2 bars)line before therecordingone.field record --clickputs the metronome through the whole take;--count-inalone clicks only the bars before it. They compose.Decisions (plan §14)
loadand a freshsessionclear it; a swap keeps it and the watch loop re-sends after a swap because the map may be what changed; the CLI clears it when its play or take ends so a laterfield transport playon the same bed is not clicked by a metronome nobody asked for this time.startonrecordis chunk 4's punch-in primitive. Punch-out — a stop at a position — is the symmetric half still to build.--render-livetakes--click <schedule.json>and runs the sameClick::renderoffline at the session rate, so the suite can read a WAV back and prove where the ticks land. Never for a golden.clickandrecord-start; the client gates on both names.The tick itself is unchanged — 15 ms of sine, G6 on the downbeat and C6 elsewhere, 4 ms decay, 0.4 — so the metronome sounds as it did.
Testing
From the repo root — the daemon changed, so both halves:
48 files, 722 tests, green here. New:
src/commands/click-daemon.test.ts—--render-live --clickrenders a bar and the test asserts each tick has a zero on its scheduled sample, a nonzero sample after it, 720 frames of ring, silence between, and G6 vs C6 by zero-crossing count; theclickop is reported bystatus.click_ticksand cleared by aload; a pre-rolledrecord(48000, 24000)answers −1, showspending, and then reportsstarted_at_samplesof exactly 48000; andrecordTakewithcountIn: 1, at: '2.1.1'lands a row at exactly 96000 with the click cleared afterwards.click.test.tsnow tests the schedule projection (rate conversion, the ten-minute fallback for an unbounded bed, count-in start and range) instead of the DSP.By hand, null mode, in a scratch project:
The count-in run prints
count-in 1.1.1 (0:00.0) → 2.1.1 (0:02.0) (1 bar)and thenrecording take-… from 2.1.1 (0:02.0), and the landed row'sstarted_at_samplesis exactly96000— before this branch a take began on the block after the request, which reads as96000–96511.field transport statusduring a clicked play showsdaemon: field-audiod 0.13.0.On the Apollo (or a laptop's built-in output, since the click is output-only):
field play creek --clickfromexamples/bloomshould tick on creek's beats with accents on the downbeats, exactly asfield play creek/track:main --clickdid before, and the click must never appear in a landed take — it is added after the pull, to the output only.https://claude.ai/code/session_01CVAnQW78ZkZfxZ2GdKV886