8000 Editor: collapse direct-mode / arrangement-mode split by johannboehme · Pull Request #32 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

Editor: collapse direct-mode / arrangement-mode split - #32

Merged
johannboehme merged 10 commits into
mainfrom
claude/vigilant-lederberg-8847e2
May 6, 2026
Merged

johannboehme merged 10 commits into
mainfrom
claude/vigilant-lederberg-8847e2

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

The editor used to carry two parallel data flows: a direct-mode path for single-take uploads (arrangementSegments empty) and an arrangement-mode path for long-form jobs (arrangementSegments populated). 59 mode-split branches threaded through Editor.tsx, Timeline.tsx, TransportBar.tsx, store.ts, useAudioMaster.ts, build-descriptor.ts, and the timing selectors.

This PR collapses both flows into a single mode-agnostic path by synthesising a single [{in:0, out:duration}] arrangement segment for direct-mode jobs at load time. Every arr-time helper in arrangement-time.ts is already Identity for that single-segment input, so all the consumers can drop their if (isArrMode) ... else ... branches and call the helpers unconditionally.

After: 59 → 1 remaining occurrence of isArrMode / arrangementSegments.length > 0 in editor code (the legitimate loadJob defensive default).

What changed

  • Phase A — job-synth.ts: synthesises arrangementSegments + arrangement + chunks for every job. Pill IDs stay stable on existing direct-mode jobs (synthetic arrangement[0].id = "__default__" matches the legacy sentinel).
  • B.1 — arrangement-pills.ts: drop generateDefaultPills; generatePills is single-bodied.
  • B.2 — useAudioMaster.ts: drop walker effectiveSegs fallback; loadJob defaults to a synthetic single-segment so the walker can rely on segs.length > 0.
  • B.3+B.4 — Master-trim universal: clampLoopToBounds projects trim through masterToArr; buildEditSpec slices arrangementSegments at the master-trim window via sliceByArrSegments. Long-form export now respects master-trim too (it was silently ignored before).
  • B.5 — TransportBar.tsx: all 12 isArrMode branches gone. Skip-to-in/out anchor on trim.in / trim.out universally; arrow-keys universally use stepByActiveSnap (per-chunk-grid rationale removed).
  • B.6 — Timeline.tsx: ~30 branches collapsed. Trim-dim, trim-handles, audio-start-marker render universally via mastersToArrAll; splice marks render only when segments.length > 1; cuts/fx strip projections always run; loop-drag clamps to master-trim's arr-projection.
  • B.7+B.8 — Editor.tsx + build-descriptor.ts: useArrMode gone; activeCamAtArr is the only resolver. buildPreviewLayers (master-time-only) and computeCamRanges deleted from build-descriptor. Drift-fix in pill-source-time mapping: linear interpolation between pill.sourceInS and pill.sourceOutS across the arr-span (was naive sourceIn + delta, ignored driftRatio).
  • B.9 — selectors/timing.ts: drop the arrangementSegments[0].audioStartMs branch from effectiveBeatPhaseS / effectiveAudioStartS / effectiveBarPhaseS. Selectors return pure master-time. Consumers project via masterToArr at the call site. The editor now uses one master bar grid for every job — anchored on meta.bpm.phase + audioStartNudgeS regardless of arrangement order. Per-chunk grid (each chunk's audioStartMs seeding its own phase) is gone — that lives only in Triage now.

Test plan

  • pnpm test --run: 935 passing (920 baseline + 12 new for synthesizeJobLoadShape, master-trim slicing, drift fix; +3 from the WebGPU-probe upstream)
  • pnpm tsc --noEmit: clean (excluding pre-existing wasm/sync-core package-not-built warnings)
  • Acceptance grep isArrMode|arrangementSegments\.length > 0 in editor + Editor.tsx → 1 (the legitimate loadJob defensive default)
  • Manual browser test against http://localhost:5174 with the existing 2-cam job:
    • Timeline-click seek (via UI) ✅
    • Snap-mode 1 ↔ 1/4 toggle ✅
    • Loop set/clear (via store action — UI button reflects pressed state) ✅
    • Cut placement → ProgramStrip renders the alternating CAM 1 / CAM 2 strip correctly ✅
    • Pill move + reset ✅
    • FX add ✅
    • buildEditSpec with narrow trim slices to [trim.in, trim.out] ✅
    • Trim-dim renders universally (full waveform when trim wide, dimmed when narrow) ✅
    • BeatRuler bar-phase identical in master/arr for single-take ✅
    • activeCamId resolves correctly through cuts ✅
  • Browser MCP environment didn't load <audio> metadata, so audio playback + compositor preview frames couldn't be visually verified live; covered instead by the vitest pipeline (useAudioMaster + descriptor + walker tests)

Risks

  • buildEditSpec slicing in long-form is a new behavior (export was previously ignoring trim entirely). If any user had a long-form job where they'd set trim "for navigation only" and still expected the full arrangement to render, that contract changes. Addressed explicitly with the user — they confirmed master-trim must be universal.
  • Master bar-grid replacing per-chunk grid is also a behavior change for long-form jobs. Confirmed with the user.

🤖 Generated with Claude Code

johannboehme and others added 10 commits May 6, 2026 12:53
Single-take and long-form jobs now feed the editor through the same
data path. Direct-mode jobs synthesize arrangementSegments=[{in:0,
out:duration}] plus a single arrangement-item + chunk; long-form jobs
pass through their persisted arrangement.

Pill IDs are stable: the synthetic item id is __default__ (= the legacy
DEFAULT_ITEM_ID sentinel), so persisted user edits on existing
direct-mode jobs survive the unification.

isArrMode branches still exist; this commit only makes them dispatch
identically for both modes via the synthetic single-segment shape.
Phase B will strip the branches file by file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Drop generateDefaultPills + the early-out branch in generatePills. The
function now has one body that walks any arrangement+chunks input —
single-take jobs feed it the synthetic single-item arrangement from
synthesizeJobLoadShape, long-form jobs feed it their persisted one,
and pill IDs (`${camId}::${itemId}`) come out the same shape either
way thanks to the __default__ sentinel.

reconcilePills tests previously called with [] / [] for direct-mode
input; updated to pass the synthetic shape that production now uses.
The race-/pollution-protection assertions still cover the same bugs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
useAudioMaster walker: drop the [{in:0, out:dur}] fallback. The store's
loadJob now defaults arrangementSegments to the synthetic single-segment
when callers omit it, so the walker can rely on segs.length > 0.

clampLoopToBounds: project master-trim through `masterToArr` and
intersect with [0, totalArrDuration]. Loop now respects master-trim
in long-form too — previously trim was ignored once an arrangement
was present.

buildEditSpec: slice arrangementSegments at master-trim via
sliceByArrSegments. Single-take with trim {1, 5} keeps emitting
[{in:1, out:5}]; long-form with trim cuts each chunk at the trim
window (was: trim ignored entirely).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The lockfile was generated by `pnpm install` in this worktree and
slipped into the previous refactor commit unintentionally. Repo had
never tracked it before; this restores that state. The local file
stays in the working tree (gitignored as install side-effect).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
shiftLoop and moveLoop projected the playhead through masterToArr only
when arrangementSegments was non-empty. The store now invariantly
carries at least one segment, so always project — single-take's
whole-master segment makes it Identity.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The lockfile is generated locally by pnpm install; it was never
tracked historically and keeps slipping into refactor commits via
`git add -A`. Mirroring the uv.lock entry so git stays clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
12 isArrMode branches collapsed:
- seekStartS / seekEndS land on master-time trim.in / trim.out (was:
  master-time min/max segment bounds in arr-mode, ignoring trim)
- step() always round-trips through arr-time so chunk seams are honoured
- IN/OUT loop case + toggleLoop project playhead via masterToArr
  unconditionally (Identity for single-take)
- Arrow-key handler always uses stepByActiveSnap; per-chunk-grid
  rationale is gone (master bar grid runs continuously across the song,
  not per-chunk)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
~30 isArrMode branches removed. Highlights:

- Range / time-conversion: liveTimelineRange is invariant `[0, arrTotal]`;
  masterToView / viewToMaster always project through arrangementSegments
  (Identity for single-take). Candidate-marker range extension dropped.
- Trim-dim, trim-handles, audio-start marker render universally — master
  trim is projected through `mastersToArrAll` so single-take keeps its
  one tick / one dimmed band, long-form gets one per chunk-occurrence.
- Splice marks render only when `arrangementSegments.length > 1` (no-op
  for single-take's single segment).
- Loop drag clamps to the master-trim's arr-projection — same trim-
  universal contract clampLoopToBounds enforces in the store.
- camLookupsForStrip is always pills-derived (pills now exist for every
  job); ProgramStrip onRemoveCut / onCutDrag / paintPreview always
  round-trip through master ↔ view, Identity in single-take.
- findPillAt no longer early-exits in direct-mode.
- Drop unused setLoop dependency that fell out of B.5.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Editor.tsx: drop the `arrangementSegments.length > 0` guards on the
trim-default + segment-0 seek paths. Both run for every job — the
trim default now derives from the master span across all segments
(single-take's whole-master segment yields [0, duration]); seek to
segments[0].in lands at 0 in single-take.

build-descriptor: collapse `useArrMode` into one path. activeCamAtArr
+ pill-based source-time mapping is the only resolver now;
buildPreviewLayers (master-time-only) and computeCamRanges drop out
along with the cuts.ts:activeCamAt import.

Pill-based source-time mapping was missing drift handling — fix it
to linearly interpolate between pill.sourceInS and pill.sourceOutS
across pill.arrStartS/arrEndS, which bakes driftRatio into the pill's
source-span (already done by generateArrangementPills via
camSourceTimeS). Pre-refactor direct-mode tests catch this through
the syncOffset/drift placement test.

Tests: build-descriptor + preview-runtime + preview-export-convergence
synthesize pills + arrangementSegments from clips (mirroring what
synthesizeJobLoadShape does in production), so test setups stay focused
on cam/cut/rotation behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
selectors/timing.ts: drop the segment[0].audioStartMs branch from
effectiveBeatPhaseS / effectiveAudioStartS / effectiveBarPhaseS. They
return pure master-time. The arrangementSegments parameter is gone —
the editor uses one master bar grid for every job, anchored on
`meta.bpm.phase + audioStartNudgeS` regardless of arrangement order.
Per-chunk grid was the previous behavior (each chunk's audioStartMs
seeded its own phase) and produced inconsistent bar lines across
chunk reorders; the song now renders into a coherent master grid.

Consumer projection at the call site:
- store.ts (stepByActiveSnap, snapMasterTime, startQuantizeHold): both
  the input `t` and the bar phase are master-time, snap directly.
- Timeline.snapped() and the loop-drag snap path: convert master phase
  to arr-time via masterToArr so the bar grid the user sees on the
  arr-time canvas matches what snap rounds to.
- BeatRuler: same projection; ticks drawn on the arr-time canvas.
- BeatRuler.onClick: arr-time → master via arrToMaster before seek,
  fixing a pre-existing seek-domain mismatch in long-form.
- TransportBar.effectiveStart: pure master-time (no segments needed).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@johannboehme
johannboehme merged commit af672af into main May 6, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/vigilant-lederberg-8847e2 branch May 6, 2026 15:43
johannboehme added a commit that referenced this pull request May 6, 2026
Pill body-drag (`pill-move`) only had edge-to-edge magnetic snap to
neighbour pills — no grid snap, even with snap mode "1" / "1/4" /
etc. Pre-refactor the symptom was hidden because pills only existed
in arr-mode; after #32 made pills universal, single-take drag
exposes the gap.

Pill-trim-in / pill-trim-out called `snapped(arrAtPointer, e)` but
`arrAtPointer` is arr-time and `snapped()` interprets master-time.
Identity in single-take's whole-master segment, double-projected
(broken) in long-form.

Fix: introduce `snappedArr(arrT, e)` — same snap pipeline but the
input domain is arr-time. Apply to pill-move (new grid snap on top
of the existing edge-to-edge magnet) and pill-trim-{in,out} (replace
the master-domain `snapped()` with the arr-domain helper).

Verified locally: pill-move with snap "1" lands on bar boundaries;
snap OFF passes through unchanged; existing 935 tests still pass.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
johannboehme added a commit that referenced this pull request May 6, 2026
Trim is master-time, but the audio canvas runs in arr-time. With a
chunk repeated N times in a long-form arrangement, the trim master-
time has N arr-time occurrences. After #32, the trim-dim band and
handles only rendered at min(in)..max(out) — one big region spanning
the whole song with handles only at the earliest/latest occurrence.
That's wrong: the un-trimmed parts of repeated chunks didn't get
dimmed, and only one of the N pairs of handles was draggable.

Fix:
- Dim path uses sliceByArrSegments(trim.in, trim.out, segments) to
  get the playable arr-time slices directly. Everything outside any
  slice is dimmed. Trim entirely outside all segments → whole canvas
  dimmed. Per-occurrence dim bands fall out for free.
- Handles render at every mastersToArrAll(trim.in/out) occurrence.
  All clipped to canvas extent; off-screen positions don't render.
- classifyAudioHit walks all occurrences of trim.in / trim.out and
  reports trim-in / trim-out on hit at any of them. Drag handler
  unchanged — it sets master-trim, so dragging any occurrence moves
  every visual handle in lockstep.

Single-take and long-form-without-duplicates: identical to before
(one occurrence each). Long-form-with-duplicates: now visually
truthful + interactable at every chunk repeat.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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