8000 fix(transport): L shortcut clamps loop region into trim by johannboehme · Pull Request #20 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(transport): L shortcut clamps loop region into trim - #20

Merged
johannboehme merged 2 commits into
mainfrom
claude/fix-l-shortcut-toggle-loop
May 2, 2026
Merged

johannboehme merged 2 commits into
mainfrom
claude/fix-l-shortcut-toggle-loop

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

toggleLoop proposed {currentTime, currentTime+2} blindly. setLoop then clamps that against the trim region via clampLoopRegion — and when the playhead sits outside trim (typical right after opening the editor: currentTime = 0, trim.in = the audio start, e.g. 6.4 s), the proposal lies entirely outside trim, the clamp returns null, and L appears to do nothing.

Verified live: with trim = {6.43, 10.43} and the playhead at 0, pressing L produced a setLoop({0, 2}) that clamped to null. After the fix the proposal becomes {6.43, 8.43} and the loop activates as expected.

Same handler is used for the LOOP button click and the L shortcut, so clicking from the same out-of-trim playhead position was equally broken — it just wasn't caught because typical use clicks LOOP after the playhead is already inside trim.

Anchor strategy

const start = Math.max(trim.in, Math.min(trim.out - 1 / fps, t));
const end   = Math.min(trim.out, start + 2);
  • Playhead before trim → snap start to trim.in
  • Playhead past trim end → snap start to trim.out − 1 frame (loop is at least one frame long)
  • Default 2-second region, but never escaping trim

Test plan

  • All 669 unit tests pass
  • Manually verified: with playhead at t=0 (outside trim), L now activates the loop (button turns orange) and a second L deactivates it
  • Verify L still works correctly with playhead INSIDE trim region (typical case) — should set 2-sec loop from playhead

🤖 Generated with Claude Code

johannboehme and others added 2 commits May 2, 2026 21:15
…udio>/<TransportBar>

EditorShell rendered the desktop and mobile layouts side-by-side and
relied on `hidden lg:grid` / `lg:hidden` to swap them. Both branches
received the SAME `videoArea`/`transport`/`timeline` ReactNodes, so
React mounted each twice — including <MasterAudio> (= a second WebAudio
ping-pong wired into ctx.destination) and <TransportBar> (= a second
window keydown listener). Two effects:

  - Loop "phasing" across the whole region: two parallel ping-pong
    setups decoded the same source with independent decoder latencies
    and summed into the same destination, producing constant comb-
    filtering through every loop iteration. Verified via React fiber
    walk: 2× MasterAudio + 4 <audio> elements before, 1× and 2 after.

  - Arrow-key snap navigation stepped 2× the snap distance: each
    keypress fired both TransportBars' onKey, dispatching
    stepByActiveSnap twice. Verified live: 0.43s → 2.43 → 4.43 → 6.43
    after the fix (was 0.43 → 4.43 → 8.43 → 12.43 before).

Fix: gate each layout branch on `useIsLargeViewport()` so only the
matching one mounts. Also tighten stepByActiveSnap's eps fallback from
`step * 0.01` (= 20ms at 1-bar / 120bpm, wide enough to falsely fire
when the playhead lands within 1% of a snap) to `step * 1e-9` (FP
tolerance only — the fallback exists solely to absorb Math.round's
round-half-toward-+∞ asymmetry on negative half-tick probes).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`toggleLoop` blindly proposed `{currentTime, currentTime+2}` which
`setLoop` then clamps against the trim region (`clampLoopRegion` in
OffsetScheduler). When the playhead sits before/after the trimmed audio
— typical right after opening the editor, where currentTime defaults to
0 but `trim.in` is the audio start (e.g. 6.4 s) — the proposal is
entirely outside trim, the clamp returns null, and L appears to do
nothing.

Verified live: with trim={6.43, 10.43} and playhead at 0, pressing L
produced a `setLoop({0, 2})` that clamped to null. After this fix the
proposal becomes `{6.43, 8.43}` and the loop activates.

Anchor strategy:
  start = clamp(currentTime, trim.in, trim.out − 1 frame)
  end   = min(trim.out, start + 2)

Same handler is used for the LOOP button click and the L shortcut, so
clicking from the same out-of-trim playhead position was equally broken
— the click bug just hadn't been caught because typical use clicks the
LOOP button after the playhead is already inside trim.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit f10b82a into main May 2, 2026
1 check failed
@johannboehme
johannboehme deleted the claude/fix-l-shortcut-toggle-loop branch May 2, 2026 20:33
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

0