Repository navigation
Mode-agnostic loop on the composed timeline + reconcile/strip fixes - #29
Merged
Merged
Conversation
Phase 1 of mode-agnostic loop. The editor walker today has two paths: an arrangement-segment walker that ignores `playback.loop`, and a legacy direct-mode loop block that's unreachable when segments exist. The loop-toggle in long-form mode is a no-op + toast. These pure helpers are the projection layer that lets a single walker treat the loop as in/out markers on the composed timeline (OP-1 tape style): - nextLoopWrapMasterT(loop, segments) — projects an arr-time loop into master-time wrap geometry: where the wrap fires, where the idle <audio> parks, and the segment indices on both sides so the swap block doesn't re-derive (handles duplicate chunks). - clampLoopToBounds(loop, segments, trim) — mode-aware clamp; arr-mode clamps to [0, totalArrDuration], direct-mode keeps trim-clamp. Additive: no existing call sites changed. 14 new tests, 912 total green.
Phase 2 of mode-agnostic loop. The segment walker now reads `playback.loop` and projects it through `nextLoopWrapMasterT` per tick to figure out where the wrap fires in master-time. The wrap takes priority over hop-arming when it lands inside the current segment, so loops that end mid-chunk no longer get over-ridden by the next-chunk hop. Three branches in the walker now: - inside loop, wrap-segment is current segment → arm wrap when distance ≤ LEAD_TIME_S (mirrors the legacy direct-mode arming), - outside loop region (user scrubbed past end or before start) → arm immediate wrap with zero crossfade distance — same intent as the legacy "scrub-back-restart" path, - otherwise → existing hop arming or end-pause scheduling. Last-segment + loop-end-at-out wraps instead of pausing. Additive: legacy direct-mode loop block (lines ~644-692) is still in place; it runs only when `arrangementSegments` is empty. Phase 3 will collapse the two paths. 5 new tests, 917 total green.
Phase 3 of mode-agnostic loop. Direct-mode now flows through the same
walker as arrangement-mode by synthesizing a single segment covering
the full master audio when `arrangementSegments` is empty. Arr-time
helpers are identity in that case (segments.length === 0 → passthrough),
so a master-time loop in direct-mode is structurally identical to an
arr-time loop in arrangement-mode — same code path, same arming logic.
- 50-line legacy loop block (`shouldArmCrossfade` + `loopWrapTime`
call site) deleted; their imports removed from the file.
- `t >= dur` early auto-pause deleted; the walker's last-segment
end-pause-timer covers it (fires ~LEAD_TIME_S before t = dur).
- Walker entry guard now produces synthetic `[{in:0, out:dur}]` for
direct-mode and bails when neither real segments nor a finite
duration are available.
All 22 useAudioMaster tests + 917 total still green — including the
direct-mode loop tests which now exercise the unified path.
Phase 4 of mode-agnostic loop. The toggle, drag, hit-test, and band visual all live on the composed timeline now — direct-mode and arrangement-mode share one code path because in direct-mode arr-time == master-time (segments empty → arr-helpers passthrough). - TransportBar: remove the `isArrMode → toast + return` short-circuit in `toggleLoop`. Anchor new loops on the composed timeline; clamp to `[0, totalArrDuration]` in arr-mode and to trim in direct-mode. - TransportBar: I/O setpoint in the "loop" branch projects the master-time playhead through `masterToArr` before updating the loop region. - Timeline: loop band drawing moved out of the `!isArrMode` branch. `arrTToX` is identity in direct-mode so the same call works in both flows. - Timeline: loop hit-test + drag operate in arr-time; clamp picks the matching bound (totalArrDuration vs trim). - Store: `setLoop`, `shiftLoop`, and `setTrim`'s loop re-clamp use `clampLoopToBounds` so trim changes stop fighting the loop in arr-mode (where trim has no semantic). All 917 tests still green; UI changes verified to compile clean.
Two regressions from the mode-agnostic refactor showed up the moment the user actually moved a loop: 1. The new walker checked `insideLoop` and immediate-wrapped whenever the playhead sat outside the loop region — so an `Alt+arrow` shiftLoop, which sets `pendingWrapAt` to the OLD loop.end and expects the active element to keep playing through, was silently yanked back the next tick. Re-introduce a pendingWrapAt branch that defers arming until master-time crosses the deferred wrap point; only then crossfade to the new loop.start. Hop-arming stays free to walk segments to reach pendingWrapAt. 2. `shiftLoop`'s `insideNew` check compared a master-time playhead against arr-time loop bounds — broken in arr-mode. Project `currentTime` through `masterToArr` first. 3. New `moveLoop(loop)` action: same OP-1 deferred-wrap semantics for absolute placements (Timeline drag), with `setLoop` kept as the "full replacement" entry point. Multiple drags before the first wrap fires preserve the earliest old-end as the trigger so the wrap can't keep getting pushed forward indefinitely. Strengthened the existing pendingWrapAt walker test: now asserts NO ramp is scheduled while playhead is below the deferred wrap point — the previous version only checked a ramp eventually fires, which my broken walker happened to satisfy by arming immediately. 917 tests all green.
Race the user just hit: the editor was opened (and persisted pills) before the sync algorithm finished — pill saved with arrStartS=0, sync later resolved to -2896ms, so the auto-baseline shifted to arrStartS=2.896 but the stored pill stayed at 0. On the next reload, `reconcilePills` only refreshed the `original*` fields and kept the stale arr-position, leaving the cam pill (drawn from pill bounds) and the cuts strip (drawn from `clipRangeS`) on different x-coordinates: thumbnails span the full timeline, the program-strip blue stripe only starts at master 2.9. Detect the "never user-edited" case by comparing the stored pill against its own stored originals within `DIRTY_EPS_S`. If they match, the pill was auto-derived all along — drop it and use the freshly generated values so sync changes flow through. User-edited pills (stored arr/source ≠ originals) keep their edits as before. 918 tests green.
Hardening the previous fix. The unedited-heuristic only worked on clean stored pills (arr matches stored originals); a previous reconcile cycle that already refreshed `originalArrStartS` to the post-sync fresh value left the pill in a "polluted" state where stored.arr=0 but stored.original=2.896 — the heuristic flagged that as user-edited even though no user touched it, and a second hard-reload didn't help. Direct-mode pills (no arrangement) are mathematically determined by clip + sync — there's no per-(cam × item) layout for the user to rearrange. So in direct-mode, just always use freshly generated pills and ignore stored. Pill move/trim in direct-mode persists via clip- level fields anyway, not via the pill, so this isn't a regression for real user edits. Arrangement-mode keeps the heuristic — there the per-pill placement DOES carry user intent (chunk reordering, per-item trim) that has to survive across reloads. 919 tests green.
Drop the value-comparison heuristic. The previous version regenerated pills only when stored arr/source matched stored originals, which broke down once any earlier reconcile cycle had refreshed the originals — pills then looked "edited" forever even when no user had touched them. Splitting direct- vs arr-mode wasn't right either: the editor should behave the same regardless of which workflow opened it. New rule, applied uniformly: a stored pill's arr/source override the fresh auto-baseline ONLY when `userEdited === true`. The flag is set by every store action that's a real user gesture (drag pill body, drag pill edges, nudge arr/source) and cleared by RESET. Auto-derived pills (everything else, including `setClipSyncOverride`'s side-effect pill shifts) carry no flag and get regenerated on every reconcile, so sync resolution / trim changes / clip mutations flow through to where the cuts strip and compositor expect them. Pre-flag stored pills are unflagged → treated as auto. That drops any user pill edits made before this commit, but those edits were already unreliable (the stale-after-reload bug the user just hit). Pill + PillRecord types gain `userEdited?: boolean`. Backward-compat: old persisted pills round-trip without it, get regenerated on first load, then re-persisted with the flag where applicable. 920 tests green.
The actual cut-bar bug. The ProgramStrip samples in `stripDuration` units — master-time in direct-mode, arr-time when an arrangement is loaded. But `camLookupsForStrip` was always feeding `clipRangeS(c)` (master-time), so in arr-mode `buildProgram` compared arr-time samples against master-time cam ranges. The blue stripe ended up starting at the cam's master-time start (= 2.896s for a -2896ms synced cam) regardless of where the cam actually lives on the composed timeline — mismatching both the cam-lane pill (drawn from pill arr-bounds) and the compositor (which uses `activeCamAtArr` on pills). In arr-mode, pills already hold the right ranges: one per chunk×clip intersection, in arr-time. Use them as the strip lookup directly. Multiple entries with the same cam id are fine — first range that contains the sample wins, which is what we want for non-contiguous coverage. Direct-mode is unchanged — `clipRangeS` IS the strip's sampling domain there. 920 tests green.
2 tasks done
johannboehme
added a commit
that referenced
this pull request
May 5, 2026
Phase 4 of #29 switched the loop-band drag from `setLoop` to `moveLoop` (OP-1 deferred wrap) but left the now-unused `setLoop` selector in place. CI's `tsc --noEmit` flags it under TS6133 (declared but never read) and fails the lint job. PR was merged anyway, so this lands the follow-up fix on a fresh branch. `pnpm lint` clean, 920 tests green.
3 tasks done
johannboehme
added a commit
that referenced
this pull request
May 6, 2026
Introduced in PR #29 alongside `cam-track-move` (the MATCH snap-mode body-drag), but the candidate-snap step never landed: the handler just applied the raw arr-delta to all of the cam's pills, which is free movement in any snap mode. Pre-refactor (b382cbc) `clip-move` had the proper snap-to-nearest-candidate path; PR #29 dropped it when it swapped clip-move out for cam-track-move. Plus a second, deeper bug: pills are authoritative for source-time post pill-refactor, so changing `clip.syncOffsetMs` (what the candidate switch does) had no visible effect — pills kept playing the old candidate's frames at the same arr-positions. Fix: - store.setSelectedCandidateIdx mirrors the offsetMs delta into every pill of the cam (live + originals), the same way setClipSyncOverride mirrors syncOverrideMs nudges. Now a candidate switch actually slides the cam-content visually. - Timeline cam-track-move handler in MATCH mode (non-shift): compute the drag-target master-startS from the cam's frozen origMasterStartS + arr-delta, find the nearest candidate-implied startS via buildClipMatchPositions / candidateIdxNearestStart, fire setSelectedCandidateIdx if it changed. No threshold — every candidate is a valid lock-target. Free-drag pills only when MATCH is off or shift is held. - New `origMasterStartS` field on the cam-track-move drag state freezes the cam-anchor at drag-start so candidate positions stay stable across mid-drag switches (otherwise middle candidates become unreachable as the math cascades). Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Loop is now a single-path feature on the composed timeline (OP-1 tape style) — works the same whether the editor was opened from a single-take upload or from the long-form Arrange handoff. Drops the toast-disable in arrangement-mode and the legacy direct-only loop block in the audio walker.
Three follow-up bug fixes after the user testing:
pendingWrapAtagain soAlt+arrowshiftLoop and the new tape-drag don't yank the playhead.userEditedflag — sync resolution / clip mutations flow through to the pill instead of getting frozen by stored arr-time values.Phases
arrangement-loop.ts— pure helpers projecting an arr-time loop into master-time wrap geometry (handles duplicate chunks).clampLoopToBounds.Test plan
pnpm test— 920 passingAlt+arrowshiftLoop defers wrap to old loop.end (no playhead jump)Known follow-up
The editor still carries 61
isArrMode/arrangementSegments.length > 0branches across timeline drawing, store actions, and helpers. The right architecture is a single uniform model (segments + pills always populated, single-take = synthetic 1-segment + 1 pill per cam) — tracked separately, not in this PR.🤖 Generated with Claude Code