mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented basic track analysis
This commit is contained in:
1 parent
986a2cee54
commit
c7169c8bbe
6 files changed
+83
-1
No files matched your search
@@ -271,6 +271,9 @@ export const api = {
|
||||
track_id: trackId,
|
||||
max_cues: maxCues,
|
||||
}),
|
||||
// Backend detects tempo + first beat: sets BPM, hotcue 1, and grid anchor.
|
||||
autoGrid: (trackId: string) =>
|
||||
send<TrackCues>('POST', '/api/tracks/auto-grid', { track_id: trackId }),
|
||||
setHotcueType: (trackId: string, slot: number, type: number) =>
|
||||
send<TrackCues>('PATCH', '/api/tracks/hotcue', { track_id: trackId, slot, type }),
|
||||
deleteHotcue: (trackId: string, slot: number) =>
|
||||
|
||||
@@ -13,6 +13,9 @@ interface Props {
|
||||
onReset: () => void
|
||||
onToggleLock: () => void
|
||||
onDeleteGrid: () => void
|
||||
/** Detect BPM + first beat and build the grid (sets hotcue 1 + anchor). */
|
||||
onAnalyze: () => void
|
||||
analyzing: boolean
|
||||
}
|
||||
|
||||
const BTN =
|
||||
@@ -39,6 +42,8 @@ export function GridControls({
|
||||
onReset,
|
||||
onToggleLock,
|
||||
onDeleteGrid,
|
||||
onAnalyze,
|
||||
analyzing,
|
||||
}: Props) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [val, setVal] = useState('')
|
||||
@@ -194,6 +199,18 @@ export function GridControls({
|
||||
🗑 Grid
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* analyze: detect BPM + first beat, set hotcue 1 + grid anchor */}
|
||||
<div className="flex gap-1">
|
||||
<button
|
||||
className={BTN}
|
||||
onClick={onAnalyze}
|
||||
disabled={analyzing}
|
||||
title="Detect BPM and first beat, then set the grid + hotcue 1 (fix octave with ÷2 / ×2)"
|
||||
>
|
||||
{analyzing ? '…' : 'Analyze'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -75,6 +75,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
const pendingPlayRef = useRef(false) // a play was requested; start once ready
|
||||
const loadedIdRef = useRef<string | null>(null) // trackId whose buffer is loaded
|
||||
const [autoBusy, setAutoBusy] = useState(false)
|
||||
const [gridBusy, setGridBusy] = useState(false)
|
||||
// Active momentary "cue preview": a hotcue OR the CUE button held while paused
|
||||
// plays from its point and stops on release, unless `latched` (play pressed
|
||||
// during the hold). `id` identifies the holder so its release matches.
|
||||
@@ -717,13 +718,26 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
onError?.((e as Error).message)
|
||||
}
|
||||
}
|
||||
// Analyze: backend detects BPM + first beat, sets the grid anchor and hotcue 1.
|
||||
const runAnalyzeGrid = async () => {
|
||||
if (!track || gridBusy) return
|
||||
setGridBusy(true)
|
||||
try {
|
||||
applyCueEdit(await api.autoGrid(track.id))
|
||||
onNotify?.('success', 'Analyzed — set BPM, grid, and hotcue 1')
|
||||
} catch (e) {
|
||||
onError?.((e as Error).message)
|
||||
} finally {
|
||||
setGridBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const selectedCue = selectedSlot != null ? hotcueAt(selectedSlot) : null
|
||||
const showWaves = track && cols && waveStatus === 'ready'
|
||||
const activeLoop = loopActive && loopRegion ? loopRegion : null
|
||||
|
||||
return (
|
||||
<div className="flex h-[21rem] shrink-0 items-stretch gap-px border-b border-line bg-ink-950">
|
||||
<div className="flex h-[23rem] shrink-0 items-stretch gap-px border-b border-line bg-ink-950">
|
||||
{/* Controls */}
|
||||
<div className="flex w-72 shrink-0 flex-col gap-3 bg-ink-900 px-4 py-3">
|
||||
<div className="min-w-0">
|
||||
@@ -755,6 +769,8 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
onReset={resetGrid}
|
||||
onToggleLock={toggleLock}
|
||||
onDeleteGrid={deleteGrid}
|
||||
onAnalyze={runAnalyzeGrid}
|
||||
analyzing={gridBusy}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user