From 805d3609077faf9906885ba7675826f267ca1fc0 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Fri, 25 Sep 2026 16:22:12 +0200 Subject: [PATCH] Added waveform range indicator --- CLAUDE.md | 3 +- frontend/src/components/OverviewWaveform.tsx | 53 +++++++++++++++++++- frontend/src/components/PrepStrip.tsx | 1 + 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f817129..8a7c700 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -393,7 +393,8 @@ Two independent apps that talk over HTTP: click to type an exact BPM), SNAP, Analyze, Auto hotcues. **Waveforms**: `MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, owned by `PrepStrip` so it survives track switches and persists) over - `OverviewWaveform`. **Controls**: play, CUE, `LoopControls`, then EITHER + `OverviewWaveform`, which frames the main view's visible range around the + playhead (it takes `secPerView` for exactly that). **Controls**: play, CUE, `LoopControls`, then EITHER `HotcueBar` OR — in **Grid mode** — `GridEditStrip`, then `TempoControls` (±0.01 / ±0.25, ÷2 ×2, tap, lock) and the Grid toggle. Every grid control acts on the marker **governing the playhead**, since a beatgrid is a marker list diff --git a/frontend/src/components/OverviewWaveform.tsx b/frontend/src/components/OverviewWaveform.tsx index dc89109..c8fa06a 100644 --- a/frontend/src/components/OverviewWaveform.tsx +++ b/frontend/src/components/OverviewWaveform.tsx @@ -10,6 +10,9 @@ interface Props { cues: CuePoint[] cuePoint: number | null loop: { start: number; end: number } | null + /** Seconds the MAIN waveform shows — drawn here as a window around the + * playhead, so the overview says which part of the track is on screen. */ + secPerView: number onSeek: (t: number) => void } @@ -25,6 +28,7 @@ export function OverviewWaveform({ cues, cuePoint, loop, + secPerView, onSeek, }: Props) { const wrapRef = useRef(null) @@ -33,6 +37,7 @@ export function OverviewWaveform({ const timeRef = useRef(0) const durRef = useRef(0) const cuesRef = useRef(cues) + const viewRef = useRef(secPerView) const cuePointRef = useRef(cuePoint) const loopRef = useRef(loop) @@ -72,6 +77,7 @@ export function OverviewWaveform({ drawCues(ctx, cuesRef.current, w, h, dpr, (t) => (t / dur) * w, false) const cp = cuePointRef.current if (cp != null) drawCuePoint(ctx, Math.round((cp / dur) * w), h, dpr) + drawViewWindow(ctx, timeRef.current, viewRef.current, dur, w, h, dpr) drawPlayhead(ctx, px, h, dpr, false) } }, []) @@ -107,13 +113,14 @@ export function OverviewWaveform({ draw() }, [currentTime, duration, draw]) - // Redraw when the cue set, cue point, or loop changes. + // Redraw when the cue set, cue point, loop or main-view zoom changes. useEffect(() => { cuesRef.current = cues cuePointRef.current = cuePoint loopRef.current = loop + viewRef.current = secPerView draw() - }, [cues, cuePoint, loop, draw]) + }, [cues, cuePoint, loop, secPerView, draw]) const seek = (e: React.MouseEvent) => { if (!duration) return @@ -128,3 +135,45 @@ export function OverviewWaveform({ ) } + +/** + * The main waveform's visible range: a frosted, outlined window centred on the + * playhead, `secPerView` wide. Clipped to the track at either end, as the main + * view is (it shows blank past the edges), and never narrower than a few + * pixels, so it stays findable when zoomed right in on a long track. + */ +function drawViewWindow( + ctx: CanvasRenderingContext2D, + t: number, + secPerView: number, + dur: number, + w: number, + h: number, + dpr: number, +): void { + if (!(secPerView > 0)) return + const minW = 6 * dpr + let x0 = ((t - secPerView / 2) / dur) * w + let x1 = ((t + secPerView / 2) / dur) * w + if (x1 - x0 < minW) { + const c = (x0 + x1) / 2 + x0 = c - minW / 2 + x1 = c + minW / 2 + } + x0 = Math.max(0, x0) + x1 = Math.min(w, x1) + if (x1 <= x0) return + const inset = dpr + const r = Math.min(4 * dpr, (x1 - x0) / 2) + ctx.save() + ctx.beginPath() + ctx.roundRect(x0 + inset / 2, inset, x1 - x0 - inset, h - inset * 2, r) + ctx.fillStyle = 'rgba(255,255,255,0.10)' + ctx.fill() + ctx.shadowColor = 'rgba(255,255,255,0.35)' + ctx.shadowBlur = 8 * dpr + ctx.lineWidth = Math.max(1, dpr) + ctx.strokeStyle = 'rgba(255,255,255,0.75)' + ctx.stroke() + ctx.restore() +} diff --git a/frontend/src/components/PrepStrip.tsx b/frontend/src/components/PrepStrip.tsx index cdbca87..450fda5 100644 --- a/frontend/src/components/PrepStrip.tsx +++ b/frontend/src/components/PrepStrip.tsx @@ -1208,6 +1208,7 @@ export function PrepStrip({ cues={cueData?.cues ?? []} cuePoint={cuePoint} loop={activeLoop} + secPerView={secPerView} onSeek={seekManual} /> )}