mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented Librosa Laplacian audio processing algorythm
# Conflicts: # frontend/src/components/PrepStrip.tsx
This commit is contained in:
1 parent
5ff79eb118
commit
986a2cee54
9 files changed
+439
-7
No files matched your search
@@ -16,6 +16,8 @@ interface Props {
|
||||
/** Bumped by the library's per-row play button to load + auto-play. */
|
||||
playRequest?: number
|
||||
onError?: (msg: string) => void
|
||||
/** Neutral/success feedback (e.g. Auto Hotcues result). */
|
||||
onNotify?: (kind: 'success' | 'error', msg: string) => void
|
||||
}
|
||||
|
||||
function fmt(secs: number): string {
|
||||
@@ -41,7 +43,7 @@ const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
|
||||
* Web Audio PlaybackEngine (seamless loops); the same decoded buffer feeds the
|
||||
* scratch engine and both waveform views.
|
||||
*/
|
||||
export function PrepStrip({ track, playRequest = 0, onError }: Props) {
|
||||
export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const [playing, setPlaying] = useState(false)
|
||||
const [previewing, setPreviewing] = useState(false) // momentary hold-to-play active
|
||||
@@ -72,6 +74,7 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
|
||||
const engagedRef = useRef(false) // scratch engine is dragging or coasting
|
||||
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)
|
||||
// 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.
|
||||
@@ -553,6 +556,36 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
|
||||
// Hotcue slot released (mouse/touch up, or key up). Ends its momentary preview.
|
||||
const onSlotRelease = (slot: number) => endPreview(`hc:${slot}`)
|
||||
|
||||
// Auto Hotcues: the backend analyses the track's audio (librosa structural
|
||||
// segmentation), snaps boundaries to the beatgrid, and fills empty slots only.
|
||||
// Requires a beatgrid (button disabled otherwise).
|
||||
const canAutoCue = !!(cueData?.bpm && cueData.bpm > 0 && cueData.grid_anchor != null)
|
||||
const runAutoHotcues = async () => {
|
||||
if (!track || !canAutoCue || autoBusy) return
|
||||
const hotcueCount = (c: TrackCues | null) =>
|
||||
c?.cues.filter((x) => x.hotcue >= 0).length ?? 0
|
||||
if (hotcueCount(cueData) >= 8) {
|
||||
onError?.('No free hotcue slots — delete some first')
|
||||
return
|
||||
}
|
||||
setAutoBusy(true)
|
||||
try {
|
||||
const before = hotcueCount(cueData)
|
||||
const fresh = await api.autoHotcues(track.id)
|
||||
applyCueEdit(fresh)
|
||||
const placed = Math.max(0, hotcueCount(fresh) - before)
|
||||
if (placed === 0) {
|
||||
onNotify?.('error', 'No clear structure found — no hotcues placed')
|
||||
} else {
|
||||
onNotify?.('success', `Placed ${placed} auto hotcue${placed === 1 ? '' : 's'}`)
|
||||
}
|
||||
} catch (e) {
|
||||
onError?.((e as Error).message)
|
||||
} finally {
|
||||
setAutoBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const changeSelectedType = async (type: number) => {
|
||||
if (!track || selectedSlot == null) return
|
||||
try {
|
||||
@@ -863,6 +896,18 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={runAutoHotcues}
|
||||
disabled={!canAutoCue || autoBusy}
|
||||
title={
|
||||
canAutoCue
|
||||
? 'Auto-place hotcues at detected phrase boundaries (empty slots only)'
|
||||
: 'Set a beatgrid first'
|
||||
}
|
||||
className="flex w-16 items-center justify-center gap-1 bg-ink-900 text-[11px] font-semibold uppercase tracking-wider text-muted transition-colors hover:bg-ink-800 hover:text-accent disabled:opacity-30 disabled:hover:bg-ink-900 disabled:hover:text-muted"
|
||||
>
|
||||
{autoBusy ? '…' : '✨ Auto'}
|
||||
</button>
|
||||
<button
|
||||
onClick={deleteSelected}
|
||||
disabled={!selectedCue}
|
||||
|
||||
Reference in new issue
Block a user