Added waveform range indicator

This commit is contained in:
patben8 committed 2026-09-25 16:22:12 +02:00
1 parent 46d3978580
commit 805d360907
3 files changed
+54 -3

No files matched your search

+2 -1
View File
@@ -393,7 +393,8 @@ Two independent apps that talk over HTTP:
click to type an exact BPM), SNAP, Analyze, Auto hotcues. **Waveforms**: click to type an exact BPM), SNAP, Analyze, Auto hotcues. **Waveforms**:
`MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, owned `MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, owned
by `PrepStrip` so it survives track switches and persists) over 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` `HotcueBar` OR — in **Grid mode** — `GridEditStrip`, then `TempoControls`
(±0.01 / ±0.25, ÷2 ×2, tap, lock) and the Grid toggle. Every grid control acts (±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 on the marker **governing the playhead**, since a beatgrid is a marker list
+51 -2
View File
@@ -10,6 +10,9 @@ interface Props {
cues: CuePoint[] cues: CuePoint[]
cuePoint: number | null cuePoint: number | null
loop: { start: number; end: 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 onSeek: (t: number) => void
} }
@@ -25,6 +28,7 @@ export function OverviewWaveform({
cues, cues,
cuePoint, cuePoint,
loop, loop,
secPerView,
onSeek, onSeek,
}: Props) { }: Props) {
const wrapRef = useRef<HTMLDivElement>(null) const wrapRef = useRef<HTMLDivElement>(null)
@@ -33,6 +37,7 @@ export function OverviewWaveform({
const timeRef = useRef(0) const timeRef = useRef(0)
const durRef = useRef(0) const durRef = useRef(0)
const cuesRef = useRef<CuePoint[]>(cues) const cuesRef = useRef<CuePoint[]>(cues)
const viewRef = useRef(secPerView)
const cuePointRef = useRef<number | null>(cuePoint) const cuePointRef = useRef<number | null>(cuePoint)
const loopRef = useRef(loop) const loopRef = useRef(loop)
@@ -72,6 +77,7 @@ export function OverviewWaveform({
drawCues(ctx, cuesRef.current, w, h, dpr, (t) => (t / dur) * w, false) drawCues(ctx, cuesRef.current, w, h, dpr, (t) => (t / dur) * w, false)
const cp = cuePointRef.current const cp = cuePointRef.current
if (cp != null) drawCuePoint(ctx, Math.round((cp / dur) * w), h, dpr) 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) drawPlayhead(ctx, px, h, dpr, false)
} }
}, []) }, [])
@@ -107,13 +113,14 @@ export function OverviewWaveform({
draw() draw()
}, [currentTime, duration, 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(() => { useEffect(() => {
cuesRef.current = cues cuesRef.current = cues
cuePointRef.current = cuePoint cuePointRef.current = cuePoint
loopRef.current = loop loopRef.current = loop
viewRef.current = secPerView
draw() draw()
}, [cues, cuePoint, loop, draw]) }, [cues, cuePoint, loop, secPerView, draw])
const seek = (e: React.MouseEvent<HTMLDivElement>) => { const seek = (e: React.MouseEvent<HTMLDivElement>) => {
if (!duration) return if (!duration) return
@@ -128,3 +135,45 @@ export function OverviewWaveform({
</div> </div>
) )
} }
/**
* 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()
}
+1
View File
@@ -1208,6 +1208,7 @@ export function PrepStrip({
cues={cueData?.cues ?? []} cues={cueData?.cues ?? []}
cuePoint={cuePoint} cuePoint={cuePoint}
loop={activeLoop} loop={activeLoop}
secPerView={secPerView}
onSeek={seekManual} onSeek={seekManual}
/> />
)} )}