mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Extended Rekordbox support
This commit is contained in:
1 parent
010f67cd2d
commit
43e712afbd
17 files changed
+837
-100
No files matched your search
@@ -147,6 +147,9 @@ export interface TrackCues {
|
||||
}
|
||||
|
||||
export interface CueCapabilities {
|
||||
/** Whether cues can be created or changed. Symmetric with grid.editable: a
|
||||
* platform can be writable overall while its cue store is not implemented. */
|
||||
editable: boolean
|
||||
hotcue_slots: number
|
||||
slot_labels: 'number' | 'letter'
|
||||
memory_cues: boolean
|
||||
|
||||
@@ -563,13 +563,31 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
|
||||
// ---- capability-derived -----------------------------------------------
|
||||
const caps = useCaps()
|
||||
// A read-only library refuses every edit. Guarding at the point of INTENT
|
||||
// means the user gets the reason instead of a 422 from the adapter's backstop,
|
||||
// and the deck stays fully usable for listening — which is most of its value
|
||||
// on a library you cannot write.
|
||||
const refuseIfReadOnly = () => {
|
||||
if (caps.writable) return false
|
||||
onError?.(readOnlyNotice(caps) ?? 'This library is read-only.')
|
||||
// Edits are guarded at the point of INTENT, so the user gets the reason
|
||||
// instead of a 422 from the adapter's backstop, and the deck stays fully
|
||||
// usable for listening — which is most of its value on a library you cannot
|
||||
// write.
|
||||
//
|
||||
// TWO gates, not one. `writable` is the library; `cues.editable` and
|
||||
// `grid.editable` are the features. A platform can be writable overall while
|
||||
// its cue or grid store is not implemented yet, so gating only on `writable`
|
||||
// would re-expose these controls the moment that flips — which is exactly how
|
||||
// this would regress unnoticed when Rekordbox writes land.
|
||||
const canEditCues = caps.writable && caps.cues.editable
|
||||
const canEditGrid = caps.writable && caps.grid.editable
|
||||
const refuseCueEdit = () => {
|
||||
if (canEditCues) return false
|
||||
onError?.(
|
||||
readOnlyNotice(caps) ?? `Cues cannot be edited on ${caps.save.app_name} libraries yet.`,
|
||||
)
|
||||
return true
|
||||
}
|
||||
const refuseGridEdit = () => {
|
||||
if (canEditGrid) return false
|
||||
onError?.(
|
||||
readOnlyNotice(caps) ??
|
||||
`The beatgrid cannot be edited on ${caps.save.app_name} libraries yet.`,
|
||||
)
|
||||
return true
|
||||
}
|
||||
const slotCount = caps.cues.hotcue_slots
|
||||
@@ -623,7 +641,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
return
|
||||
}
|
||||
if (!cue) {
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseCueEdit()) return
|
||||
try {
|
||||
// Setting a hotcue while a loop is active stores it as a loop hotcue.
|
||||
if (loopActive && loopRegion) {
|
||||
@@ -663,7 +681,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
const canAutoCue = grid != null
|
||||
const runAutoHotcues = async () => {
|
||||
if (!track || !canAutoCue || autoBusy) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseCueEdit()) return
|
||||
const hotcueCount = (c: TrackCues | null) =>
|
||||
c?.cues.filter((x) => x.role === 'hotcue' && x.slot != null).length ?? 0
|
||||
if (hotcueCount(cueData) >= slotCount) {
|
||||
@@ -690,7 +708,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
|
||||
const changeSelectedType = async (type: CueType) => {
|
||||
if (!track || selectedSlot == null) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseCueEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.setCueType(track.id, selectedSlot, type))
|
||||
} catch (e) {
|
||||
@@ -700,7 +718,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
|
||||
const deleteSelected = async () => {
|
||||
if (!track || selectedSlot == null) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseCueEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.deleteCue(track.id, selectedSlot))
|
||||
setSelectedSlot(null)
|
||||
@@ -713,7 +731,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
const existing = hotcueAt(slot)
|
||||
if (!track || !existing) return // nothing to remove in an empty slot
|
||||
if (existing.grid_marker != null) return // beatgrid-owned: delete the marker instead
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseCueEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.deleteCue(track.id, slot))
|
||||
if (selectedSlot === slot) setSelectedSlot(null)
|
||||
@@ -738,7 +756,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
|
||||
const editMarker = async (index: number, patch: { bpm?: number; start?: number }) => {
|
||||
if (!track || index < 0) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.setGridMarker(track.id, index, patch))
|
||||
} catch (e) {
|
||||
@@ -760,7 +778,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
// Uses the raw playhead, not snapTime: a marker defines where beats are.
|
||||
const addMarkerHere = async () => {
|
||||
if (!track) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.addGridMarker(track.id, playheadNow()))
|
||||
} catch (e) {
|
||||
@@ -769,7 +787,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
}
|
||||
const deleteMarkerHere = async () => {
|
||||
if (!track || activeMarkerIndex < 0) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.deleteGridMarker(track.id, activeMarkerIndex))
|
||||
} catch (e) {
|
||||
@@ -786,7 +804,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
const resetGrid = async () => {
|
||||
const o = originalGridRef.current
|
||||
if (!track || !o) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.replaceGridMarkers(track.id, o))
|
||||
} catch (e) {
|
||||
@@ -795,7 +813,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
}
|
||||
const toggleLock = async () => {
|
||||
if (!track) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.setGridLock(track.id, !cueData?.grid_locked))
|
||||
} catch (e) {
|
||||
@@ -804,7 +822,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
}
|
||||
const deleteGrid = async () => {
|
||||
if (!track) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
try {
|
||||
applyCueEdit(await api.deleteGrid(track.id))
|
||||
} catch (e) {
|
||||
@@ -814,7 +832,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
|
||||
// Analyze: backend detects BPM + first beat, sets the grid anchor and hotcue 1.
|
||||
const runAnalyzeGrid = async () => {
|
||||
if (!track || gridBusy) return
|
||||
if (refuseIfReadOnly()) return
|
||||
if (refuseGridEdit()) return
|
||||
setGridBusy(true)
|
||||
try {
|
||||
applyCueEdit(await api.autoGrid(track.id))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState, type MutableRefObject } from 'react'
|
||||
import { useEffect, useMemo, useRef, useState, type MutableRefObject } from 'react'
|
||||
import {
|
||||
flexRender,
|
||||
getCoreRowModel,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
type VisibilityState,
|
||||
} from '@tanstack/react-table'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
import { useCaps } from '../lib/capabilities'
|
||||
import {
|
||||
DndContext,
|
||||
PointerSensor,
|
||||
@@ -31,6 +32,15 @@ import { CSS } from '@dnd-kit/utilities'
|
||||
import type { Track } from '../api'
|
||||
import { TRACK_COLUMNS } from '../lib/trackColumns'
|
||||
|
||||
/** Fields this platform can persist, for the table's per-cell edit gating.
|
||||
* Platforms differ in WHICH fields they accept, so the all-or-nothing
|
||||
* `onEditField` handler is not enough on its own. */
|
||||
function useEditableFields(): ReadonlySet<string> {
|
||||
const caps = useCaps()
|
||||
return useMemo(() => new Set(caps.tracks.editable_fields), [caps.tracks.editable_fields])
|
||||
}
|
||||
|
||||
|
||||
const ROW_HEIGHT = 44
|
||||
// Stable reference. A controlled `state.sorting` that's a fresh `[]` each render
|
||||
// (with no `onSortingChange`) makes TanStack Table re-sync its internal state
|
||||
@@ -259,11 +269,12 @@ export function TrackTable({
|
||||
onEditField,
|
||||
activeTrackId,
|
||||
}: Props) {
|
||||
const editableFields = useEditableFields()
|
||||
const table = useReactTable({
|
||||
data: tracks,
|
||||
columns: TRACK_COLUMNS,
|
||||
state: { sorting, columnVisibility, columnOrder, columnSizing },
|
||||
meta: { onEditField },
|
||||
meta: { onEditField, editableFields },
|
||||
onSortingChange: (updater) =>
|
||||
onSortingChange(typeof updater === 'function' ? updater(sorting) : updater),
|
||||
onColumnSizingChange: (updater) =>
|
||||
@@ -457,11 +468,12 @@ export function PlaylistTable({
|
||||
const [items, setItems] = useState<Track[]>(tracks)
|
||||
useEffect(() => setItems(tracks), [tracks])
|
||||
|
||||
const editableFields = useEditableFields()
|
||||
const table = useReactTable({
|
||||
data: items,
|
||||
columns: TRACK_COLUMNS,
|
||||
state: { sorting: NO_SORTING, columnVisibility, columnOrder, columnSizing },
|
||||
meta: { onEditField },
|
||||
meta: { onEditField, editableFields },
|
||||
enableSorting: false, // playlist order is manual
|
||||
onColumnSizingChange: (updater) =>
|
||||
onColumnSizingChange(typeof updater === 'function' ? updater(columnSizing) : updater),
|
||||
|
||||
@@ -22,6 +22,12 @@ declare module '@tanstack/react-table' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
interface TableMeta<TData extends RowData> {
|
||||
onEditField?: (track: Track, field: keyof Track, value: string | number) => void
|
||||
/** Fields the loaded platform can actually persist
|
||||
* (`capabilities.tracks.editable_fields`). A field outside this set renders
|
||||
* read-only: the platform-level `onEditField` gate is all-or-nothing, and
|
||||
* platforms genuinely differ in WHICH fields they accept. Undefined means
|
||||
* "not gated" — every field with a handler stays editable. */
|
||||
editableFields?: ReadonlySet<string>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +40,14 @@ function InlineEdit({
|
||||
display,
|
||||
onCommit,
|
||||
className = 'w-full min-w-0 truncate text-muted',
|
||||
readOnly = false,
|
||||
}: {
|
||||
value: string | null
|
||||
display?: ReactNode
|
||||
onCommit: (v: string) => void
|
||||
className?: string
|
||||
/** Render the value without offering an editor. */
|
||||
readOnly?: boolean
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [val, setVal] = useState('')
|
||||
@@ -70,6 +79,13 @@ function InlineEdit({
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (readOnly) {
|
||||
return (
|
||||
<div className={className}>
|
||||
{display ?? (value?.trim() ? value : <span className="text-faint">—</span>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div
|
||||
onDoubleClick={(e) => {
|
||||
@@ -85,12 +101,20 @@ function InlineEdit({
|
||||
)
|
||||
}
|
||||
|
||||
/** Whether this table may edit `field`, per the platform's capabilities. */
|
||||
function canEdit(c: CellContext<Track, unknown>, field: string): boolean {
|
||||
const meta = c.table.options.meta
|
||||
if (!meta?.onEditField) return false
|
||||
return meta.editableFields ? meta.editableFields.has(field) : true
|
||||
}
|
||||
|
||||
// Cell renderer factory for a plain editable text field.
|
||||
function editable(field: keyof Track, className?: string) {
|
||||
return (c: CellContext<Track, unknown>) => (
|
||||
<InlineEdit
|
||||
value={c.getValue() as string | null}
|
||||
className={className}
|
||||
readOnly={!canEdit(c, field)}
|
||||
onCommit={(v) => c.table.options.meta?.onEditField?.(c.row.original, field, v)}
|
||||
/>
|
||||
)
|
||||
@@ -111,11 +135,13 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
value={title}
|
||||
display={title || <span className="text-faint">Untitled</span>}
|
||||
className="w-full min-w-0 truncate font-medium text-text"
|
||||
readOnly={!canEdit(c, 'title')}
|
||||
onCommit={(v) => edit?.(r, 'title', v)}
|
||||
/>
|
||||
<InlineEdit
|
||||
value={r.artist}
|
||||
className="w-full min-w-0 truncate text-xs text-muted"
|
||||
readOnly={!canEdit(c, 'artist')}
|
||||
onCommit={(v) => edit?.(r, 'artist', v)}
|
||||
/>
|
||||
</div>
|
||||
@@ -185,7 +211,13 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
cell: (c) => (
|
||||
<RatingStars
|
||||
value={c.getValue() as number}
|
||||
onChange={(v) => c.table.options.meta?.onEditField?.(c.row.original, 'rating', v)}
|
||||
// RatingStars is read-only without an onChange, which is exactly the
|
||||
// behaviour wanted when the platform cannot persist a rating.
|
||||
onChange={
|
||||
canEdit(c, 'rating')
|
||||
? (v) => c.table.options.meta?.onEditField?.(c.row.original, 'rating', v)
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
),
|
||||
}),
|
||||
@@ -257,6 +289,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
|
||||
<InlineEdit
|
||||
value={c.getValue() as string | null}
|
||||
display={<span className="tabular-nums text-muted">{formatDate(c.getValue() as string | null)}</span>}
|
||||
readOnly={!canEdit(c, 'release_date')}
|
||||
onCommit={(v) => c.table.options.meta?.onEditField?.(c.row.original, 'release_date', v)}
|
||||
/>
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user