From 85f01f6723f67fd982922142dbcb5ef60b5f42c5 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Sat, 26 Sep 2026 12:46:11 +0200 Subject: [PATCH] Grid and BPM can now be fully manual --- CLAUDE.md | 3 +- frontend/src/components/GridControls.tsx | 55 ++++++++++++++++++------ frontend/src/components/PrepStrip.tsx | 49 ++++++++++++++------- 3 files changed, 77 insertions(+), 30 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9546f7a..9d69ffe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -431,7 +431,8 @@ Two independent apps that talk over HTTP: - **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it, in three rows. **Header**: cover, title/artist · album · genre, a Read-only badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` — - click to type an exact BPM), SNAP, Analyze, Auto hotcues. **Waveforms**: + click to type an exact BPM; with no grid, a typed or tapped BPM CREATES one at the playhead, and + Set grid on a track with no BPM opens the readout to ask rather than failing), 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`, which frames the main view's visible range around the diff --git a/frontend/src/components/GridControls.tsx b/frontend/src/components/GridControls.tsx index 482160b..52c6467 100644 --- a/frontend/src/components/GridControls.tsx +++ b/frontend/src/components/GridControls.tsx @@ -25,27 +25,51 @@ function markerTime(t: number): string { return `${m}:${s < 10 ? '0' : ''}${s.toFixed(3)}` } -/** The header readout's BPM cell. Click to type an exact tempo. */ +/** The header readout's BPM cell. Click to type an exact tempo — with no grid, + * typing one creates it (the caller decides where its first marker goes). */ export function BpmReadout({ bpm, editable, onSetBpm, + onClose, + openRequest = 0, }: { /** Tempo of the marker governing the playhead; null without a grid. */ bpm: number | null editable: boolean onSetBpm: (bpm: number) => void + /** The editor closed, committed or not. */ + onClose?: () => void + /** Bump to open the editor from elsewhere (Set grid on a track with no BPM). */ + openRequest?: number }) { const [editing, setEditing] = useState(false) + const editingRef = useRef(false) const [val, setVal] = useState('') - const commit = () => { + const open = () => { + setVal(bpm != null ? bpm.toFixed(3) : '') + editingRef.current = true + setEditing(true) + } + // Only a CHANGE opens it, so remounting with a non-zero count does not. + const seenRequestRef = useRef(openRequest) + useEffect(() => { + if (openRequest === seenRequestRef.current) return + seenRequestRef.current = openRequest + open() + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [openRequest]) + const close = (commit: boolean) => { + if (!editingRef.current) return // Enter commits; a blur as it unmounts must not again + editingRef.current = false const n = parseFloat(val) - if (isFinite(n) && n > 0) onSetBpm(Math.round(n * 1000) / 1000) + if (commit && isFinite(n) && n > 0) onSetBpm(Math.round(n * 1000) / 1000) setEditing(false) + onClose?.() } const label = ( - BPM{editable && bpm != null ? ' ✎' : ''} + BPM{editable ? ' ✎' : ''} ) if (editing) { @@ -55,26 +79,29 @@ export function BpmReadout({ setVal(e.target.value)} - onBlur={commit} + onBlur={() => close(true)} onKeyDown={(e) => { - if (e.key === 'Enter') commit() - if (e.key === 'Escape') setEditing(false) + if (e.key === 'Enter') close(true) + if (e.key === 'Escape') close(false) e.stopPropagation() // Space/arrows must not drive the deck while typing }} - className="w-[5.5rem] rounded-md bg-ink-800 px-1 font-mono text-[17px] font-semibold text-accent outline-none ring-1 ring-accent" + className="w-[5.5rem] rounded-md bg-ink-800 px-1 font-mono text-[17px] font-semibold text-accent outline-none ring-1 ring-accent placeholder:text-faint" /> ) } return (