mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Grid and BPM can now be fully manual
This commit is contained in:
1 parent
2e04bcb9f6
commit
85f01f6723
3 files changed
+77
-30
No files matched your search
@@ -431,7 +431,8 @@ Two independent apps that talk over HTTP:
|
|||||||
- **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it,
|
- **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
|
in three rows. **Header**: cover, title/artist · album · genre, a Read-only
|
||||||
badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` —
|
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
|
`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`, which frames the main view's visible range around the
|
`OverviewWaveform`, which frames the main view's visible range around the
|
||||||
|
|||||||
@@ -25,27 +25,51 @@ function markerTime(t: number): string {
|
|||||||
return `${m}:${s < 10 ? '0' : ''}${s.toFixed(3)}`
|
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({
|
export function BpmReadout({
|
||||||
bpm,
|
bpm,
|
||||||
editable,
|
editable,
|
||||||
onSetBpm,
|
onSetBpm,
|
||||||
|
onClose,
|
||||||
|
openRequest = 0,
|
||||||
}: {
|
}: {
|
||||||
/** Tempo of the marker governing the playhead; null without a grid. */
|
/** Tempo of the marker governing the playhead; null without a grid. */
|
||||||
bpm: number | null
|
bpm: number | null
|
||||||
editable: boolean
|
editable: boolean
|
||||||
onSetBpm: (bpm: number) => void
|
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 [editing, setEditing] = useState(false)
|
||||||
|
const editingRef = useRef(false)
|
||||||
const [val, setVal] = useState('')
|
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)
|
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)
|
setEditing(false)
|
||||||
|
onClose?.()
|
||||||
}
|
}
|
||||||
const label = (
|
const label = (
|
||||||
<span className="text-[10px] tracking-[0.08em] text-faint">
|
<span className="text-[10px] tracking-[0.08em] text-faint">
|
||||||
BPM{editable && bpm != null ? ' ✎' : ''}
|
BPM{editable ? ' ✎' : ''}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
if (editing) {
|
if (editing) {
|
||||||
@@ -55,26 +79,29 @@ export function BpmReadout({
|
|||||||
<input
|
<input
|
||||||
autoFocus
|
autoFocus
|
||||||
value={val}
|
value={val}
|
||||||
|
placeholder={bpm == null ? 'BPM?' : undefined}
|
||||||
onChange={(e) => setVal(e.target.value)}
|
onChange={(e) => setVal(e.target.value)}
|
||||||
onBlur={commit}
|
onBlur={() => close(true)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === 'Enter') commit()
|
if (e.key === 'Enter') close(true)
|
||||||
if (e.key === 'Escape') setEditing(false)
|
if (e.key === 'Escape') close(false)
|
||||||
e.stopPropagation() // Space/arrows must not drive the deck while typing
|
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"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => editable && open()}
|
||||||
if (!editable || bpm == null) return
|
title={
|
||||||
setVal(bpm.toFixed(3))
|
!editable
|
||||||
setEditing(true)
|
? undefined
|
||||||
}}
|
: bpm != null
|
||||||
title={editable && bpm != null ? 'Click to type an exact BPM' : undefined}
|
? 'Click to type an exact BPM'
|
||||||
|
: 'Click to type a BPM — starts the beatgrid at the playhead'
|
||||||
|
}
|
||||||
className="flex flex-col justify-center gap-px rounded-r-xl px-4 text-left hover:bg-ink-850"
|
className="flex flex-col justify-center gap-px rounded-r-xl px-4 text-left hover:bg-ink-850"
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
|
|||||||
@@ -885,40 +885,53 @@ export function PrepStrip({
|
|||||||
if (!activeMarker) return
|
if (!activeMarker) return
|
||||||
editMarker(activeMarkerIndex, { start: Math.max(0, activeMarker.start + deltaMs / 1000) })
|
editMarker(activeMarkerIndex, { start: Math.max(0, activeMarker.start + deltaMs / 1000) })
|
||||||
}
|
}
|
||||||
// Tap tempo retempos the governing marker, or — with no grid — creates one
|
// With no grid, a tempo from TAP or the typed readout CREATES one, with its
|
||||||
// at the tempo tapped, anchored where the run began (the first tap is a beat
|
// first marker at an anchor captured when the gesture began: the first tap
|
||||||
// when tapping along; the Grid-mode nudges fix the phase). While that create
|
// (a beat, when tapping along), or where the playhead stood when Set grid
|
||||||
// is in flight, later taps wait for it rather than creating a second grid.
|
// asked for a BPM. The Grid-mode nudges fix the phase. While that create is
|
||||||
|
// in flight, later tempos wait for it rather than creating a second grid.
|
||||||
const tapAnchorRef = useRef(0)
|
const tapAnchorRef = useRef(0)
|
||||||
const tapCreateRef = useRef<Promise<boolean> | null>(null)
|
const gridAnchorRef = useRef<number | null>(null) // Set grid's, while the readout asks
|
||||||
|
const gridCreateRef = useRef<Promise<boolean> | null>(null)
|
||||||
|
const [bpmEntryRequest, setBpmEntryRequest] = useState(0) // bump → readout opens for typing
|
||||||
const tapStart = () => {
|
const tapStart = () => {
|
||||||
tapAnchorRef.current = playheadNow()
|
tapAnchorRef.current = playheadNow()
|
||||||
}
|
}
|
||||||
const tapBpm = async (bpm: number) => {
|
const commitBpm = async (bpm: number, anchor: number) => {
|
||||||
if (!track) return
|
if (!track) return
|
||||||
// This closure predates the grid it is waiting for, so it cannot use
|
// This closure predates the grid it is waiting for, so it cannot use
|
||||||
// activeMarkerIndex — but a grid created by a tap has exactly one marker.
|
// activeMarkerIndex — but a grid created here has exactly one marker.
|
||||||
if (tapCreateRef.current) {
|
if (gridCreateRef.current) {
|
||||||
if (await tapCreateRef.current) editMarker(0, { bpm })
|
if (await gridCreateRef.current) editMarker(0, { bpm })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (markerCount > 0) return setBpm(bpm)
|
if (markerCount > 0) return setBpm(bpm)
|
||||||
if (refuseGridEdit()) return
|
if (refuseGridEdit()) return
|
||||||
const create = api
|
const create = api
|
||||||
.addGridMarker(track.id, tapAnchorRef.current, bpm)
|
.addGridMarker(track.id, anchor, bpm)
|
||||||
.then((cues) => (applyCueEdit(cues), true))
|
.then((cues) => (applyCueEdit(cues), true))
|
||||||
.catch((e) => (onError?.((e as Error).message), false))
|
.catch((e) => (onError?.((e as Error).message), false))
|
||||||
.finally(() => (tapCreateRef.current = null))
|
.finally(() => (gridCreateRef.current = null))
|
||||||
tapCreateRef.current = create
|
gridCreateRef.current = create
|
||||||
await create
|
await create
|
||||||
}
|
}
|
||||||
// Adds a marker at the playhead — and creates the grid when there is none.
|
// Adds a marker at the playhead — and creates the grid when there is none.
|
||||||
// Uses the raw playhead, not snapTime: a marker defines where beats are.
|
// Uses the raw playhead, not snapTime: a marker defines where beats are.
|
||||||
|
// A first marker needs a tempo: the track's own BPM when it has one (passed
|
||||||
|
// explicitly — Rekordbox does not fall back to it), else the readout opens
|
||||||
|
// to ask, and the marker lands where the playhead is NOW once it is typed.
|
||||||
const addMarkerHere = async () => {
|
const addMarkerHere = async () => {
|
||||||
if (!track) return
|
if (!track) return
|
||||||
if (refuseGridEdit()) return
|
if (refuseGridEdit()) return
|
||||||
|
if (markerCount === 0 && !track.bpm) {
|
||||||
|
gridAnchorRef.current = playheadNow()
|
||||||
|
setBpmEntryRequest((n) => n + 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
applyCueEdit(await api.addGridMarker(track.id, playheadNow()))
|
applyCueEdit(
|
||||||
|
await api.addGridMarker(track.id, playheadNow(), markerCount === 0 ? (track.bpm ?? undefined) : undefined),
|
||||||
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onError?.((e as Error).message)
|
onError?.((e as Error).message)
|
||||||
}
|
}
|
||||||
@@ -1182,7 +1195,13 @@ export function PrepStrip({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span aria-hidden className="my-2 w-px bg-line" />
|
<span aria-hidden className="my-2 w-px bg-line" />
|
||||||
<BpmReadout bpm={activeMarker?.bpm ?? null} editable={canEditGrid} onSetBpm={setBpm} />
|
<BpmReadout
|
||||||
|
bpm={activeMarker?.bpm ?? null}
|
||||||
|
editable={canEditGrid}
|
||||||
|
onSetBpm={(bpm) => commitBpm(bpm, gridAnchorRef.current ?? playheadNow())}
|
||||||
|
onClose={() => (gridAnchorRef.current = null)}
|
||||||
|
openRequest={bpmEntryRequest}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -1374,7 +1393,7 @@ export function PrepStrip({
|
|||||||
flexible={markerCount > 1}
|
flexible={markerCount > 1}
|
||||||
markerIndex={activeMarkerIndex}
|
markerIndex={activeMarkerIndex}
|
||||||
onTapStart={tapStart}
|
onTapStart={tapStart}
|
||||||
onTapBpm={tapBpm}
|
onTapBpm={(bpm) => commitBpm(bpm, tapAnchorRef.current)}
|
||||||
onNudgeBpm={nudgeBpm}
|
onNudgeBpm={nudgeBpm}
|
||||||
onHalve={halveBpm}
|
onHalve={halveBpm}
|
||||||
onDouble={doubleBpm}
|
onDouble={doubleBpm}
|
||||||
|
|||||||
Reference in new issue
Block a user