mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 18:22:53 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9851c3c056 | ||
|
|
17b68c40bb | ||
|
|
cb76277016 | ||
|
|
24b9dfe49f | ||
|
|
513808a6d2 | ||
|
|
85f01f6723 | ||
|
|
2e04bcb9f6 |
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,
|
||||
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
|
||||
@@ -851,7 +852,8 @@ that number and nothing else — everything derives from it:
|
||||
`test_rekordbox_fidelity.py`, end to end through the API, and in Rekordbox 7
|
||||
itself. Research is captured in `.claude/handoffs/rekordbox-adapter.md` §8,
|
||||
incl. the verified result that Rekordbox accepts Konduktor-written rows when
|
||||
USNs are maintained. Remaining gap: **cover art**. **No version history on Rekordbox** — accepted scope decision,
|
||||
USNs are maintained. Remaining gap: **writing cover art** (reading works: the file's embedded art,
|
||||
else Rekordbox's own `ImagePath` copy under `share/`). **No version history on Rekordbox** — accepted scope decision,
|
||||
see handoff §11.
|
||||
- ✅ **Import a OneLibrary stick into Traktor** — done end to end. A plugged-in
|
||||
drive appears under **Devices** in the sidebar, browses in the ordinary table
|
||||
|
||||
@@ -407,7 +407,7 @@ class RekordboxAdapter:
|
||||
self._refuse("Editing cover art")
|
||||
|
||||
def cover_art(self, track_id: str) -> tuple[bytes, str] | None:
|
||||
return None
|
||||
return self._store.cover_art(track_id)
|
||||
|
||||
def set_grid_lock(self, track_id: str, locked: bool) -> TrackCues:
|
||||
# Rekordbox has no per-track grid lock; capabilities.grid.lockable says so.
|
||||
|
||||
@@ -292,6 +292,31 @@ class RekordboxStore:
|
||||
return None
|
||||
return self._mapping.apply(Path(str(folder)))
|
||||
|
||||
def cover_art(self, track_id: str) -> tuple[bytes, str] | None:
|
||||
"""The art embedded in the audio file, else Rekordbox's own copy.
|
||||
|
||||
The file comes first because it is what Traktor reads too, so one track
|
||||
shows the same art on both platforms. Rekordbox's copy (`ImagePath`,
|
||||
rooted at `share/` like `AnalysisDataPath`) covers files it cannot be
|
||||
read from — a WAV, or a drive that is not mounted.
|
||||
"""
|
||||
from ...core import audio_tags
|
||||
|
||||
path = self.audio_path(track_id)
|
||||
if path is not None and path.is_file():
|
||||
art = audio_tags.read_cover(path)
|
||||
if art:
|
||||
return art
|
||||
rel = getattr(self.content(track_id), "ImagePath", None)
|
||||
if not rel:
|
||||
return None
|
||||
image = self.path.parent / "share" / str(rel).lstrip("/\\")
|
||||
try:
|
||||
data = image.read_bytes()
|
||||
except OSError:
|
||||
return None
|
||||
return data, "image/png" if image.suffix.lower() == ".png" else "image/jpeg"
|
||||
|
||||
def all_audio_paths(self) -> list[str]:
|
||||
return [
|
||||
str(c.FolderPath) for c in self.iter_content() if getattr(c, "FolderPath", None)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.1.2",
|
||||
"version": "0.2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -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 = (
|
||||
<span className="text-[10px] tracking-[0.08em] text-faint">
|
||||
BPM{editable && bpm != null ? ' ✎' : ''}
|
||||
BPM{editable ? ' ✎' : ''}
|
||||
</span>
|
||||
)
|
||||
if (editing) {
|
||||
@@ -55,26 +79,29 @@ export function BpmReadout({
|
||||
<input
|
||||
autoFocus
|
||||
value={val}
|
||||
placeholder={bpm == null ? 'BPM?' : undefined}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<button
|
||||
onClick={() => {
|
||||
if (!editable || bpm == null) return
|
||||
setVal(bpm.toFixed(3))
|
||||
setEditing(true)
|
||||
}}
|
||||
title={editable && bpm != null ? 'Click to type an exact BPM' : undefined}
|
||||
onClick={() => editable && open()}
|
||||
title={
|
||||
!editable
|
||||
? undefined
|
||||
: bpm != null
|
||||
? '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"
|
||||
>
|
||||
{label}
|
||||
@@ -184,6 +211,7 @@ export function GridEditStrip({
|
||||
onPrevMarker,
|
||||
onNextMarker,
|
||||
onNudgeMarker,
|
||||
onNudgeMarkerBeats,
|
||||
onAddMarker,
|
||||
onDeleteMarker,
|
||||
onDeleteGrid,
|
||||
@@ -198,6 +226,7 @@ export function GridEditStrip({
|
||||
onPrevMarker: () => void
|
||||
onNextMarker: () => void
|
||||
onNudgeMarker: (deltaMs: number) => void
|
||||
onNudgeMarkerBeats: (beats: number) => void
|
||||
onAddMarker: () => void
|
||||
onDeleteMarker: () => void
|
||||
onDeleteGrid: () => void
|
||||
@@ -246,6 +275,8 @@ export function GridEditStrip({
|
||||
<div className="glass-group flex h-10 shrink-0 items-center overflow-hidden rounded-xl">
|
||||
{/* Phase nudges move the GOVERNING marker — not gated on atMarker,
|
||||
since the drift is heard at the playhead, not at the marker. */}
|
||||
<button className={nudge} onClick={() => onNudgeMarkerBeats(-1)} disabled={!hasGrid} title="Move the marker −1 beat">-1b</button>
|
||||
<span aria-hidden className="h-[18px] w-px bg-line" />
|
||||
<button className={nudge} onClick={() => onNudgeMarker(-10)} disabled={!hasGrid} title="Move the marker −10 ms">−10</button>
|
||||
<button className={nudge} onClick={() => onNudgeMarker(-1)} disabled={!hasGrid} title="Move the marker −1 ms">−1</button>
|
||||
<button
|
||||
@@ -258,6 +289,8 @@ export function GridEditStrip({
|
||||
</button>
|
||||
<button className={nudge} onClick={() => onNudgeMarker(1)} disabled={!hasGrid} title="Move the marker +1 ms">+1</button>
|
||||
<button className={nudge} onClick={() => onNudgeMarker(10)} disabled={!hasGrid} title="Move the marker +10 ms">+10</button>
|
||||
<span aria-hidden className="h-[18px] w-px bg-line" />
|
||||
<button className={nudge} onClick={() => onNudgeMarkerBeats(1)} disabled={!hasGrid} title="Move the marker +1 beat">+1b</button>
|
||||
</div>
|
||||
|
||||
{/* Only a marker you are standing on can be deleted, so one scrolled
|
||||
|
||||
@@ -405,6 +405,7 @@ export function PrepStrip({
|
||||
setCueHeld(true)
|
||||
getCtx()
|
||||
if (eng.playing) {
|
||||
leaveLoopFor(cuePoint)
|
||||
eng.pause()
|
||||
eng.seek(cuePoint)
|
||||
setPlaying(false)
|
||||
@@ -417,6 +418,7 @@ export function PrepStrip({
|
||||
eng.seek(t)
|
||||
setCurrent(t)
|
||||
} else {
|
||||
leaveLoopFor(cuePoint)
|
||||
beginPreview('cue', cuePoint)
|
||||
}
|
||||
}
|
||||
@@ -474,6 +476,16 @@ export function PrepStrip({
|
||||
setCurrent(t)
|
||||
}
|
||||
|
||||
// A cue jump that lands outside the engaged loop leaves it, Traktor-style.
|
||||
// Without this the loop stays in force and Web Audio, started past a loop's
|
||||
// end, wraps straight back into it. A jump inside the loop keeps it.
|
||||
const leaveLoopFor = (t: number) => {
|
||||
if (!loopActive || !loopRegion) return
|
||||
if (t >= loopRegion.start && t < loopRegion.end) return
|
||||
playbackRef.current?.setLoopEnabled(false)
|
||||
setLoopActive(false)
|
||||
}
|
||||
|
||||
// User-driven seek from the waveforms: navigating away drops the active loop
|
||||
// (otherwise it would just pull playback back into the loop region).
|
||||
const seekManual = (t: number) => {
|
||||
@@ -770,13 +782,14 @@ export function PrepStrip({
|
||||
const eng = playbackRef.current
|
||||
if (!eng || !eng.ready) return
|
||||
getCtx()
|
||||
// A loop hotcue jumps to its start AND re-engages a loop of its length.
|
||||
// A loop hotcue jumps to its start AND engages a loop of its length — the
|
||||
// new loop FIRST, so the seek is not wrapped back into the old one.
|
||||
if (cue.type === 'loop' && cue.length > 0) {
|
||||
seek(cue.start)
|
||||
engagLoop(cue.start, cue.start + cue.length, beatsForLoop(cue.start, cue.length))
|
||||
} else {
|
||||
seek(cue.start)
|
||||
leaveLoopFor(cue.start)
|
||||
}
|
||||
seek(cue.start)
|
||||
// Paused at press → momentary preview: play while held.
|
||||
if (!eng.playing) beginPreview(`hc:${slot}`, cue.start)
|
||||
}
|
||||
@@ -881,44 +894,62 @@ export function PrepStrip({
|
||||
// in this panel — a section can be octave-wrong on its own.
|
||||
const halveBpm = () => activeMarker && setBpm(activeMarker.bpm / 2)
|
||||
const doubleBpm = () => activeMarker && setBpm(activeMarker.bpm * 2)
|
||||
// A beat is the governing marker's own beat: moving a marker by whole beats
|
||||
// shifts which beat is the downbeat without changing the phase.
|
||||
const nudgeGridBeats = (beats: number) => {
|
||||
if (activeMarker) nudgeGrid((beats * 60000) / activeMarker.bpm)
|
||||
}
|
||||
const nudgeGrid = (deltaMs: number) => {
|
||||
if (!activeMarker) return
|
||||
editMarker(activeMarkerIndex, { start: Math.max(0, activeMarker.start + deltaMs / 1000) })
|
||||
}
|
||||
// Tap tempo retempos the governing marker, or — with no grid — creates one
|
||||
// at the tempo tapped, anchored where the run began (the first tap is a beat
|
||||
// when tapping along; the Grid-mode nudges fix the phase). While that create
|
||||
// is in flight, later taps wait for it rather than creating a second grid.
|
||||
// With no grid, a tempo from TAP or the typed readout CREATES one, with its
|
||||
// first marker at an anchor captured when the gesture began: the first tap
|
||||
// (a beat, when tapping along), or where the playhead stood when Set 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 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 = () => {
|
||||
tapAnchorRef.current = playheadNow()
|
||||
}
|
||||
const tapBpm = async (bpm: number) => {
|
||||
const commitBpm = async (bpm: number, anchor: number) => {
|
||||
if (!track) return
|
||||
// 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.
|
||||
if (tapCreateRef.current) {
|
||||
if (await tapCreateRef.current) editMarker(0, { bpm })
|
||||
// activeMarkerIndex — but a grid created here has exactly one marker.
|
||||
if (gridCreateRef.current) {
|
||||
if (await gridCreateRef.current) editMarker(0, { bpm })
|
||||
return
|
||||
}
|
||||
if (markerCount > 0) return setBpm(bpm)
|
||||
if (refuseGridEdit()) return
|
||||
const create = api
|
||||
.addGridMarker(track.id, tapAnchorRef.current, bpm)
|
||||
.addGridMarker(track.id, anchor, bpm)
|
||||
.then((cues) => (applyCueEdit(cues), true))
|
||||
.catch((e) => (onError?.((e as Error).message), false))
|
||||
.finally(() => (tapCreateRef.current = null))
|
||||
tapCreateRef.current = create
|
||||
.finally(() => (gridCreateRef.current = null))
|
||||
gridCreateRef.current = create
|
||||
await create
|
||||
}
|
||||
// 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.
|
||||
// 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 () => {
|
||||
if (!track) return
|
||||
if (refuseGridEdit()) return
|
||||
if (markerCount === 0 && !track.bpm) {
|
||||
gridAnchorRef.current = playheadNow()
|
||||
setBpmEntryRequest((n) => n + 1)
|
||||
return
|
||||
}
|
||||
try {
|
||||
applyCueEdit(await api.addGridMarker(track.id, playheadNow()))
|
||||
applyCueEdit(
|
||||
await api.addGridMarker(track.id, playheadNow(), markerCount === 0 ? (track.bpm ?? undefined) : undefined),
|
||||
)
|
||||
} catch (e) {
|
||||
onError?.((e as Error).message)
|
||||
}
|
||||
@@ -1182,7 +1213,13 @@ export function PrepStrip({
|
||||
</span>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
<button
|
||||
@@ -1344,6 +1381,7 @@ export function PrepStrip({
|
||||
onPrevMarker={prevMarker}
|
||||
onNextMarker={nextMarker}
|
||||
onNudgeMarker={nudgeGrid}
|
||||
onNudgeMarkerBeats={nudgeGridBeats}
|
||||
onAddMarker={addMarkerHere}
|
||||
onDeleteMarker={deleteMarkerHere}
|
||||
onDeleteGrid={deleteGrid}
|
||||
@@ -1374,7 +1412,7 @@ export function PrepStrip({
|
||||
flexible={markerCount > 1}
|
||||
markerIndex={activeMarkerIndex}
|
||||
onTapStart={tapStart}
|
||||
onTapBpm={tapBpm}
|
||||
onTapBpm={(bpm) => commitBpm(bpm, tapAnchorRef.current)}
|
||||
onNudgeBpm={nudgeBpm}
|
||||
onHalve={halveBpm}
|
||||
onDouble={doubleBpm}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useRef, useState, type MutableRefObject } from 'react'
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type MutableRefObject } from 'react'
|
||||
import {
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
@@ -300,11 +300,26 @@ export function TrackTable({
|
||||
const parentRef = useRef<HTMLDivElement>(null)
|
||||
const bodyRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// The rows start BELOW the sticky header, inside the same scroller, so the
|
||||
// virtualizer is told where they start (scrollMargin) and how much of the
|
||||
// top the header covers (scrollPaddingStart). Without both, scrollToIndex
|
||||
// lands a row too far down on ↓ — just out of view — and under the header on ↑.
|
||||
const [bodyOffset, setBodyOffset] = useState({ top: 0, header: 0 })
|
||||
useLayoutEffect(() => {
|
||||
const body = bodyRef.current
|
||||
const scroller = parentRef.current
|
||||
if (!body || !scroller) return
|
||||
const top = body.getBoundingClientRect().top - scroller.getBoundingClientRect().top + scroller.scrollTop
|
||||
const header = (body.previousElementSibling as HTMLElement | null)?.offsetHeight ?? 0
|
||||
setBodyOffset((o) => (o.top === top && o.header === header ? o : { top, header }))
|
||||
}, [])
|
||||
const virtualizer = useVirtualizer({
|
||||
count: rows.length,
|
||||
getScrollElement: () => parentRef.current,
|
||||
estimateSize: () => ROW_HEIGHT,
|
||||
overscan: 12,
|
||||
scrollMargin: bodyOffset.top,
|
||||
scrollPaddingStart: bodyOffset.header,
|
||||
})
|
||||
const virtualRows = virtualizer.getVirtualItems()
|
||||
|
||||
@@ -552,7 +567,7 @@ export function TrackTable({
|
||||
className={`group absolute left-0 flex items-center border-b border-ink-850 text-sm ${
|
||||
isSelected ? 'bg-accent-soft/50' : drag ? '' : 'hover:bg-ink-850'
|
||||
} ${isMoving ? 'opacity-40' : ''}`}
|
||||
style={{ top: 0, transform: `translateY(${vr.start}px)`, height: vr.size, width: '100%' }}
|
||||
style={{ top: 0, transform: `translateY(${vr.start - bodyOffset.top}px)`, height: vr.size, width: '100%' }}
|
||||
onMouseDown={(e) => {
|
||||
// Shift/Cmd-click would otherwise also select page text.
|
||||
if (selection && (e.shiftKey || e.metaKey || e.ctrlKey)) e.preventDefault()
|
||||
|
||||
Reference in new issue
Block a user