8000 fix(editor): preview goes black after adding video/image to running editor by johannboehme · Pull Request #2 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(editor): preview goes black after adding video/image to run 8000 ning editor - #2

Merged
johannboehme merged 1 commit into
mainfrom
claude/cool-kepler-b06f1c
May 1, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/cool-kepler-b06f1c

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

  • Fixes the black-preview bug when the user adds a second video/image via the "+ Media" flow.
  • Root cause was two-fold: updateClip rebuilt clips from ClipInit and dropped the displayW/displayH reported by <video> metadata, so any job-update event blanked the bbox for every existing clip and resolveOutputDims() returned null. Separately, PreviewRuntime captured the cams URL map at construction so a newly-added clip's URL never reached the pool / bitmap loader.
  • Now updateClip preserves the dims in its merge, PreviewRuntime exposes a setCams() setter, and Compositor pushes prop changes through (with a camsRef to bridge the init() race).

Test plan

  • 4 new unit tests (red→green): 2 for updateClip preserving displayW/displayH (video + image), 2 for setCams plumbing video URLs and image bitmap fetches
  • Full unit suite green (593/593)
  • Manual: open editor with one cam, click "+ Media" to add a second video → preview must keep showing the first cam, not go black
  • Manual: same flow but with an image; cut to the new clip → image renders instead of black

🤖 Generated with Claude Code

…ditor

Two bugs combined to blank the live preview as soon as a user added a
second clip via the "+ Media" flow.

1. updateClip rebuilt clips from ClipInit and dropped displayW/displayH.
   Editor.tsx fires updateClip on every existing cam during a job-update
   event, so adding a new clip wiped dims off ALL existing clips.
   resolveOutputDims then returned null and the descriptor went layer-less.

2. PreviewRuntime captured the cams URL map at construction time and
   never re-read the prop. A newly-added clip's URL never reached the
   pool, so its <video> couldn't mount and its bitmap couldn't load —
   cutting to it rendered nothing.

Fix: preserve displayW/displayH in updateClip's merge, add setCams() to
PreviewRuntime, and push cams-prop changes from Compositor on each render
(with a ref to bridge the init() race).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit b63b225 into main May 1, 2026
1 check passed
johannboehme added a commit that referenced this pull request May 3, 2026
Robust matching for noisy same-source recordings (clean direct take vs
mic-recording with room verb / codec artefacts). The previous pipeline
walked 1.1 s off the true offset on a 15-min beat-making session — even
though chroma had picked the right answer, multi-seed PHAT overrode it
because every seed produced uniformly mediocre PNR (~10) and a
marginally-stronger alternate won the tie. New pipeline drops the
error to ~5 ms (sub-perceptible) on the same case while staying
identical on clean tracks.

Stages, coarse → fine:

  envelope (tier 0, NEW)
    RMS-envelope cross-correlation at 10 Hz. Cheap, robust against
    mic EQ / room verb / codec artefacts. Produces a coarse offset
    that seeds the salient-anchor search corridor.

  chroma + onset (tier 1, unchanged)
    Existing pitch-class + spectral-flux fusion. Now works inside the
    envelope-anchored search space.

  PHAT refinement (tier 2, fixed)
    Multi-seed alternate may now only override the chroma primary
    when its PNR is ≥ 1.5× higher. The legitimate case this guards
    (real-music bench house-loop: alt PNR ≈ 2e8 vs primary ≈ 50,
    ratio 4 M:1) clears trivially. The failure mode it kills:
    mic-noisy long-form material where every seed lands near PNR 10
    and a 1.08× ratio walked the lag onto a self-similar bar shift.

  salient-anchor consensus (tier 3, NEW — replaces uniform chunking)
    Picks K spectrally-unique 8-s windows in the cleaner of the two
    tracks (ref_is_cleaner via peak-to-RMS heuristic), runs sample-
    level GCC-PHAT for each in a ±2 s corridor around the envelope
    seed, bucket-votes the offsets. Salient anchors sit on events
    that don't repeat elsewhere — by construction they can't fall on
    a bar-shifted impostor. Falls back to uniform chunked when no
    salient anchors are found.

  drift correction (tier 4, unchanged)

  DTW fallback (unchanged)
    Kept for non-linear time-warping in long-tail setups (wireless
    audio, asynchronous SRC, tape wow & flutter).

Per-stage progress:
  WASM exposes syncAudioPcmWithProgress(ref, query, sr, callback).
  Worker forwards each stage transition to the UI thread; jobs.ts
  maps it onto the 40-55 % per-cam progress band so the bar moves
  continuously through the ~5 s match instead of freezing at 40 %.
  Existing syncAudioPcm() entrypoint preserved for backwards-compat.

Verification (16-min beat-making session, noisy mic vs clean master):
  before:    -3991 ms  (1091 ms off truth)
  fix #1:    -2978 ms  (78 ms off, PHAT margin alone)
  fix #1+#2: -2947 ms  (47 ms off, uniform consensus)
  final:     -2895 ms  (4.4 ms off, salient anchors + envelope seed)

  Pipeline runtime: 1.6 s native = ~590× realtime on 16 min.
  All 40 unit tests pass; real-music bench identity / ±100ms /
  ±500ms / ±2000ms scenarios remain green on user-beatmaking
  fixtures.

New supporting files:
  src/envelope.rs        — tier 0
  src/salience.rs        — novelty curve + anchor selection
  src/consensus.rs       — extended with salient_phat_consensus
  examples/diagnose_match.rs  — signal-level probe for sync failures
  examples/time_pipeline.rs   — bare timing harness

Co-authored-by: Claude Opus 4.7 (1M context) <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