8000 fix(editor): unmount inactive layout — kill duplicate <MasterAudio>/<TransportBar> by johannboehme · Pull Request #18 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(editor): unmount inactive layout — kill duplicate <MasterAudio>/<TransportBar> - #18

Merged
johannboehme merged 1 commit into
mainfrom
claude/adoring-babbage-b93436
May 2, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/adoring-babbage-b93436

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

EditorShell mounted both desktop and mobile layouts simultaneously and used CSS (hidden lg:grid / lg:hidden) to swap them. Both branches received the same videoArea / transport / timeline ReactNodes — React mounted each twice. Two visible bugs from one root cause:

  • Loop "phasing" across the whole region: 2× <MasterAudio> = two parallel WebAudio ping-pong setups, each decoding the same source with independent decoder latencies, both summed into ctx.destination → constant comb-filtering through every loop iteration.
  • Arrow-key snap navigation stepped 2× the snap: 2× <TransportBar> = two window.addEventListener("keydown", ...) listeners → each press fired stepByActiveSnap twice.

Verified live in browser via React fiber walk: 2× MasterAudio + 4 <audio> elements before, 1× and 2 after. Snap jump 0.43→2.43→4.43→6.43 after fix (was 0.43→4.43→8.43→12.43).

Changes

  • EditorShell.tsx: new useIsLargeViewport() hook; conditionally render only the matching layout branch instead of CSS-toggling both.
  • store.ts:1044: tighten stepByActiveSnap's eps fallback from step * 0.01 (= 20 ms at 1-bar/120bpm — wide enough to falsely fire when the playhead lands within 1% of a snap, e.g. via audio-mirror seek precision) 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).
  • store.test.ts: 2 new regression tests for stepByActiveSnap near-snap edge cases.

Test plan

  • All 669 unit tests pass (bun test)
  • Set a 2-bar loop, play 30+ iterations, listen for phasing/comb artifacts — should be gone
  • Snap mode "1", arrow-keys → exactly 1 bar per press (try also 1/2, 1/4, 1/8, 1/16)
  • Resize the browser across the lg breakpoint (1024px) during playback — audio context will re-init briefly (acceptable; was previously a duplicate-mount); layout swaps cleanly
  • Mobile/tablet viewport renders only the mobile branch (no hidden desktop branch)

🤖 Generated with Claude Code

…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>
@johannboehme
johannboehme merged commit 1789d50 into main May 2, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/adoring-babbage-b93436 branch May 2, 2026 19:38
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