Skip to content

Looping end to end: song length, loop fold, bloom play --loop - #23

Merged
ninjudd merged 12 commits into
mainfrom
feat/song-length
Aug 6, 2026
Merged

ninjudd merged 12 commits into
mainfrom
feat/song-length

Conversation

@ninjudd

@ninjudd ninjudd commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

One coherent chunk (consolidated from #22 + #23 after Justin rightly pointed out they're one testable thing): everything needed to hear a song loop.

The three layers

  • Song render (song.yaml): length: (ticks) makes the mix render exactly that long — authored extent, not emergent from whichever stem rings longest. Plain length hard-cuts after the master chain and pads short content: a bounce that ends. Adding loop: true instead folds the overhang back onto the start — bar 12's reverb tail rings into bar 1, wrapping as many times as it needs — so the render is one seamless pass of the infinite loop, and playing it on repeat is indistinguishable from the song playing forever. A looping song's length IS its loop length (no second field to disagree with); loop without length is a diagnostic.
  • Player : bloom play --loop replays the resolved queue until ctrl-c. --from re-applies each pass. Each pass reloads the artifact — a short gap, noted in-code; daemon-native looping is the follow-up that removes it. The afplay fallback declines the flag like --from/--device.
  • (Clip-level looping already merged in Clip looping: the window fills, on the grid, cut or rung out #21 — the three compose.)

Verified

  • Creek measured sample-exact at 12 bars before any of this (28.92575 s = 20 s + the 16-beat ramp integral 8.9257 s) — but only by luck of the longest stem. With length: 46080 + loop: true declared it renders 1,388,436 samples by construction.
  • Fold arithmetic pinned by test (3-sample loop, 8 samples of content, double wrap, exact dyadic values); truncate/pad exactness; --loop tested against the real daemon (three passes, interrupt, exact pass count).
  • 197/197, typecheck clean.

Also carries the TTS roadmap lines in next.md per discussion: say as a hermetic build rule; voice generation as a local-first ACE-style workflow (2026 open models within ~80 ELO of ElevenLabs; zero-shot cloning makes a voice a committed 3-second reference asset), ElevenLabs demoted to optional keyed backend.


Addendum (5dd635b): daemon-native loop. Justin couldn't judge the seam because the CLI-requeue reload gap swamped it — so the gap is gone. --loop with a single target (and no --from — the daemon wraps to sample 0, not the locate point, so region auditions keep the requeue path, per review) now loops inside bloom-audiod: load carries a loop flag, the JUCE reader wraps at end-of-file sample-exactly, streamFinished never fires, and the blocking play holds until ctrl-c. Multi-target --loop keeps the CLI-requeue fallback (documented gap). Daemon bumps to 0.3.0; the CLI version-guards native loop and instructs bloom transport quit against an older daemon — and transport quit is now a real command (restart-to-pick-up-a-new-build was folklore until the guard needed to name it). Tested against the real daemon: one load, position events still streaming past 3× the file's length, stop ends it; the multi-item requeue path keeps its own test. 198/198.

ninjudd added 3 commits August 5, 2026 19:17
length: (ticks) in song.yaml, projected through the tempo map where the
mix spec is synthesized. Tails truncate after the master chain, short
content pads — a song's extent is authored, not emergent from whichever
stem rings longest, which is what makes a whole song loopable on its
own bar line. Absent, nothing changes (and no action key moves).

Creek measured sample-exact at 12 bars before this (28.9257 s, the
closed-form ramp integral) — but only because the keys clip happened to
be the longest stem, one reverb tail away from drifting.
…e loop

Justin: truncating reverb is the wrong tool for a song that loops. With
loop: true beside length in song.yaml, everything past the loop point
folds back onto the start (bar 12's tail rings into bar 1, wrapping as
many times as it needs), so playing the file on repeat is
indistinguishable from the song playing forever. Plain length keeps the
hard cut — a bounce that ends. A looping song's length IS its loop
length, so there is no second field to disagree with; loop without
length is a diagnostic.
--loop replays the resolved queue until ctrl-c — the audition companion
to clip loops. CLI-side by design: each pass reloads the artifact, a
short gap; gapless is the daemon's to offer if the gap ever matters.
--from re-applies each pass so looping a region audition repeats the
region. The afplay fallback declines the flag like --from/--device.

Also records the TTS direction in next.md per discussion: say as a
hermetic build rule (sc-render's shape), and voice generation as a
local-first ACE-style workflow — 2026 open models sit within ~80 ELO
of ElevenLabs and zero-shot cloning makes a voice a committed 3-second
reference asset, so no API key on the main path.
@ninjudd ninjudd changed the title Songs declare their length: the mix renders exactly that long Looping end to end: song length, loop fold, bloom play --loop Aug 6, 2026

@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.

Reviewed at head 41f55dc (in place — the checkout was already on it), all three commits. Typecheck clean, 197/197 tests (including the three-pass --loop test against the real daemon), CI green. No findings. Consolidating #22+#23 into one PR was right — the three layers only mean anything together, and the tests prove them together.

Verified by execution:

  • The flagship number, independently measured: field's creek mix artifact is exactly 1,388,436 frames (46080 ticks through the ramp = 28.92575 s × 48 k). Extent by construction, not by luck of the longest stem — and bloom check/full build stay green on field with length + loop declared.
  • End-to-end fold through the real CLI in a scratch project: a 24000-sample stem under length: 480 (= 12000 samples) with loop: true renders exactly 12000 frames. The fold arithmetic itself is pinned by the dyadic unit test (double wrap, exact values) — the right test to exist forever, same spirit as #21's hand-tiling equivalence.
  • loop: true without length → loop needs a declared length — the loop point is the length, exit 1. The one-field design (a looping song's length IS its loop length) eliminates the disagreement bug class outright.

Verified by reading, no issues found:

  • Action-key hygiene: length_samples/loop are omit-when-empty, so length-less songs keep their exact old mix keys — the established pattern, correctly applied; songs that declare a length re-render once, which is the point.
  • The fold applies after the master chain, so even chain-grown tails respect the bar line; declared-longer-than-content pads (with loop, a loop that includes its silence — correct); loop: false + length truncates, sensibly.
  • The --loop do/while composes correctly with the #13 interrupt discipline: every inner break re-checks at the while, ctrl-c lands on whichever side it lands, and — important now that passes are unbounded — the #13 listener-leak fix is what makes an all-night loop not accumulate handlers. --from re-applying per pass makes region auditioning loop the region, which is the behavior a musician wants.
  • The afplay fallback declines --loop with the updated message, consistent with --from/--device.
  • The TTS roadmap lines put say and voice generation on opposite sides of the determinism boundary explicitly — that's the ACE §2 lesson generalizing, and committing a 3-second reference asset as "the voice" is better provenance than any vendor voice ID.

One small placement nudge, not a finding: the pass-gap ("daemon-native looping is the follow-up that removes it") lives only in a code comment and the PR body. The repo's own convention (#17's §5) is that follow-ups live somewhere findable — a line in next.md or a §follow-ups entry, so it doesn't rely on someone re-reading play.ts to remember. Ready for Justin's merge.

ninjudd added 8 commits August 5, 2026 19:31
…seam

bloom play --loop with a single target now loops inside bloom-audiod —
load carries a loop flag, the JUCE reader wraps at end-of-file
sample-exactly, and the stream never finishes, so the blocking play
holds until ctrl-c. No reload between passes: the gap that was
swamping every seam audition is gone. Multi-target --loop keeps the
CLI-requeue fallback. Daemon 0.3.0; the CLI version-guards and tells
an older daemon's user to bloom transport quit — which now exists as
a command, since restarting the daemon to pick up a new build was
folklore until it was needed.
CI's startup latency ate a heartbeat and the 900 ms window saw exactly
2 positions. Now the test interrupts after the 4th position event —
~1 s of streaming a 0.25 s file, unreachable without the loop — so
slower runners wait instead of fail.
…rsion

Justin, mid-audition: 'how do I know if I'm running on the latest
daemon?' — there was no way short of a node one-liner. status now shows
the daemon version on its own line and a (looping) marker on the state
line (statusResponseSchema learns the 0.3 field; absent on older
daemons).
The click renders CLI-side into a temp copy of the artifact — the
daemon stays artifacts-only — with every beat projected through the
tempo map individually, so ramps click at the ramped tempo, odd meters
accent their own downbeats, and the click loops seamlessly with
--loop. G6 on the downbeat, C6 elsewhere, 15 ms blips. The diagnostic
Justin actually wanted: is the phrase off the grid, or is the grid off
the phrase?
transport status on a --click play showed raw samples: the temp copy
at .bloom/tmp/click-*.wav had no songs/ segment for songDirOfPath.
Copies now land under .bloom/tmp/<pkg>/click-<name>.wav.
Heartbeat-paced positions land on arbitrary ticks — noise while
listening. The readout now shows 1.1 1.2 1.3 1.4 2.1, gated on beat
boundaries, 1-indexed to match --from and YAML positions everywhere
(Justin sketched 0-indexed; consistency won — flagged for his veto).
Targets without a tempo map get whole seconds. transport status keeps
the full bar.beat.tick + clock detail.
Gating on beat changes still printed whenever a 250 ms heartbeat
happened to cross a boundary — up to a quarter-second late, unevenly.
Heartbeat positions are now anchors (sample ↔ wall clock) and each
beat's print is scheduled by timer at the beat itself, drift-corrected
on every fresh anchor. A stalled anchor (pause) suspends the timers.
The daemon stays musically ignorant — musical time still never crosses
the socket.

@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.

Scoped follow-up over 41f55dc..2c28234 (in place) — which turned out to be six commits, not just 5dd635b: the native loop, its deflake, the status additions, and a whole --click metronome. All reviewed. Typecheck clean, 202/202 (native-loop and requeue-loop tests both ran against the real 0.3.0 binary — I checked the built artifact reports 0.3.0 before trusting them), CI green. One P3, verified by execution, on a semantic seam the native loop introduced.

  1. P3 — --from + --loop no longer repeats the region, and the comment still says it does. Inline on play.ts. Confirmed against the real daemon (null output): after the reader wraps, position returns through 0, not to the locate point — and since --from demands a single target, the single-target native path is the only path --from can take, so the region-repeat behavior this PR's own body advertised no longer exists anywhere.

Verified by execution:

  • Native wrap probe (raw client, null daemon): load(loop) → locate(12000) → play on a 24000-sample file streams positions 19683 → 3875 → 12067 → 20259 → 4451 … — gapless wrap, and status.sample stays loop-relative (so musical positions display correctly forever, no monotonic drift). looping: true reported throughout.
  • The suite's two loop tests split exactly along the design seam: single-target native (one onItem, positions outliving the file, event-driven interrupt — the deflake shape is right) vs multi-target requeue (three labels across passes).
  • Suite-level: click's beat grid pinned through a decelerating ramp (widening gaps) and 7/8 accents; the overlay test asserts silence between clicks and an untouched artifact.

Verified by reading, no issues found:

  • The native side is small and correct: setLooping on the reader source (JUCE's gapless path), streamFinished() guarded so a looping stream never finishes — which is precisely what makes the blocking waitForStop contract work — and looping in status. Protocol stays additive: loop omitted-unless-set on load (old daemons ignore it safely), looping optional in the zod schema, version 0.3.0 with the guard producing an actionable message (bloom transport quit, then play again).
  • The version guard sends loop: true only after checking ≥0.3, and the multi-target path still requeues CLI-side — the two compose in the do/while via !nativeLoop without a second code path.
  • --click is the right architecture: rendered CLI-side into .bloom/tmp/<pkg>/, daemon stays artifacts-only, and placing the copy under the label's package path is what keeps musical time working on clicked files (songDirOfPath) — that's a subtle detail done deliberately, per the in-code comment. Clicks summed into a native-loop file loop with it by construction. One micro-observation, not a finding: the click sums with no headroom guard, so a −1 dBFS-limited mix plus a coincident 0.4-gain click can exceed full scale (float WAV carries it; the DAC clips it) — harmless for auditioning, worth a ducking multiplier only if it ever audibly bites.
  • transport quit closes the #16 promise ("the last time you should ever need pkill") with a description that says exactly when to use it, and transport status answering both loop questions plus the daemon version kills the am-I-on-the-new-build folklore.

Ready for Justin's merge once the --from+--loop semantics are dispositioned — comment fix at minimum, region-loop or a warning if the old behavior was the intended contract.

Comment thread src/commands/play.ts 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.

Addendum: two more commits (ec1d530, cfcdda8 — the beat-phase-locked readout) landed while the previous review was being written, so this covers them and re-verifies the head. Typecheck clean, 202/202 re-run at cfcdda8 (the native-loop test's adaptation is sound: with a 1.25 s / 2.5-beat file, a 4th beat change is only reachable if the reader actually wraps, whether or not positions wrap with it). No new findings, and the P3 from the previous review carries forward unchanged — the --from+--loop region comment (play.ts:100) is untouched by these commits and still describes behavior that no longer exists.

On the scheduler, verified by reading plus the daemon tests:

  • The architecture holds the line that matters: heartbeat positions are anchors (sample ↔ wall clock), beats print from timers at the moment they sound, every fresh anchor drift-corrects by rescheduling, and musical time still never crosses the socket.
  • The pause handling is neat — a stalled anchor (same sample twice) freezes the readout and clears the pending timer, so a paused transport doesn't tick; movement resumes it.
  • Native-loop wrap composes: a wrapped anchor is just a backward-jumping sample, the current beat re-emits (deduped against the last line), and the readout follows the loop. One consequence of the dedup worth knowing rather than fixing: a loop of exactly one beat shows a static readout — which is arguably correct, since the musical position genuinely never changes.
  • cancel() in finally reaps the pending timer on stop/interrupt; a timer that fires in the gap between the stop event and finally can print at most one phantom beat line — cosmetic, bounded, not worth machinery.
  • Micro-nit, body-only: the no-tempo fallback prints 0:${seconds} with unbounded seconds (0:75 after a minute and a quarter). It's near-dead code — a valid project's songs all carry tempo maps, so ctx is essentially always present — but if it ever fires, minutes-and-seconds would read better.

Still ready for Justin's merge once the --from+--loop semantics thread is dispositioned.

The daemon's native wrap returns to sample 0, not the locate point, so
routing --from through native loop silently replaced repeat-the-region
with play-the-region-then-loop-the-file — for every --from, since
--from forces the single-target shape. Native loop now requires no
--from; the requeue path re-locates each pass. Regression test drives
two region passes and asserts no position ever falls before the locate
point.

@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.

Final scoped pass at head 95158e3 (in place). Typecheck clean, 203/203, CI green. No findings — the P3 is fixed exactly as suggested and the thread resolution is accurate.

Verified: nativeLoop now requires options.from === undefined, so region auditions take the requeue path where the locate re-applies every pass; the play.ts comment now states the real contract including why (wrap returns to sample 0); and the PR body's stale sentence is gone (checked — squash hygiene preserved). The regression test is the probe made permanent, and it asserts the strongest available invariant: across two full region passes through the real daemon, no position event ever falls before the locate point — that's the property that was silently lost, stated as a floor on the entire position stream rather than a spot check. Both contracts now hold and are separately tested: bare --loop gapless-native (positions outliving the file), --from --loop region-repeating (reload gap as the region's price, honestly documented until daemon-side loop regions exist).

The beat-readout synchronization (ec1d530 + cfcdda8) was covered in the addendum review — no findings there stand.

#23 is done: three layers of looping (clip fold from #21's lineage, song-length fold, transport), each with the test that pins its defining property. Ready for Justin's merge.

@ninjudd
ninjudd merged commit ed1a399 into main Aug 6, 2026
1 check passed
ninjudd added a commit that referenced this pull request Aug 6, 2026
Scalars stay ticks; arrays are musical, resolved through the song's
meter map at load — the numbers musicians think in, in the files they
author.

- **Notation** ([musical-time.md](docs/projects/all/musical-time.md)
records the decisions): positions are ordinal and 1-indexed — `at: [9,
2]` is bar 9 beat 2, there is no bar 0; spans are cardinal and
zero-legal — `duration: [4]` is four bars, `every: [0, 2]` is two beats
— advanced from the field's anchor through the meter map, stepping bars
and beats at whatever meter is in force, so a span crossing a meter
change means what a musician means by it. Dotted strings were rejected:
`1.3` is a YAML float, and a forgotten quote silently means a different
number. `--from` keeps its dotted form — a shell arg is not YAML.
- **Fields (v1):** clip `position`/`duration`, `loop.every`, arrangement
section `at`, song `length`. Musical arrays require `anchor: musical`;
on absolute clips they are an error, not a conversion. Deferred:
tempo/meter event `at` (self-referential enough not to rush) and take
`position` (recorder-written, dual-representation).
- **Division of labor:** the schema validates shape only (1–3 integers,
ordinal vs cardinal minimums); the model layer resolves against the
song's `MeterMap` and diagnoses ranges (`beat 5 out of range for 4/4 at
bar 2`), misanchoring, zero-resolving spans, and arrays with no valid
meter map. Resolution rewrites arrays to tick scalars at the load
boundary, so the graph never sees an array and either spelling produces
the same action key — verified on field by converting creek to `length:
[12]` / `duration: [12]` / `every: [4]`: every target was a cache hit.
- **Emission:** `KeyOrder` gains a per-key `flow` flag — time arrays
stay single-line (`length: [12]`), the one recorded exception to block
style; `flowCollectionPadding: false` keeps them unpadded. `fmt`
preserves the author's notation: scalar stays scalar, array stays array.
- **Housekeeping:** clip-looping.md status → complete (#21, extended by
#23); now.md swaps that line for this project; project-model.md and
build-graph.md document the notation.

Tests: meter-map ordinal/cardinal resolution through meter changes and
7/8; flow emission and comment preservation; load-time resolution,
array-vs-tick load equality, and each diagnostic. 216 pass.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes the project load/validation boundary for timeline fields
across songs, clips, and arrangements; incorrect resolution would affect
mix length and placement, though tests and cache-equivalence with tick
spellings reduce regression risk.
> 
> **Overview**
> Project YAML time fields can now be written as **musical arrays**
(`[bar, beat?, tick?]`) as well as tick scalars. **Scalars still mean
ticks**; **arrays are musical** and are resolved through the song's
meter map at load—downstream code and the build graph only see tick
numbers, so `length: [12]` and an equivalent tick value yield the same
build/cache behavior.
> 
> **Resolution and validation** happen in `loadProject`/`validate`:
ordinal positions (e.g. `at: [9, 2]`), cardinal spans (e.g. `duration:
[4]`, `every: [0, 2]`), song `length` from bar 1, and clip spans
anchored at clip position. The schema checks array shape only; beat/tick
range, zero spans, missing meter map, and **musical arrays on `anchor:
absolute` clips** are diagnosed explicitly.
> 
> **`MeterMap`** adds `positionTicks` and `spanTicks` (meter changes
included); **`parse`** delegates to `positionTicks`.
> 
> **Canonical YAML** adds a per-key `flow` flag so time arrays stay
single-line (`length: [12]`); `fmt` preserves scalar vs array choice.
> 
> Docs add **musical-time.md** and cross-links; **clip-looping** is
marked complete in planning docs.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
240ea48. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@ninjudd
ninjudd deleted the feat/song-length branch September 28, 2026 04:11
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