Added Rekordbox capabilities handling

This commit is contained in:
patben8 committed 2026-09-18 09:36:05 +02:00
1 parent 4592e13228
commit 010f67cd2d
14 files changed
+297 -43

No files matched your search

+12 -4
View File
@@ -136,7 +136,11 @@ export default function App() {
}, [])
const onError = useCallback((msg: string) => notify('error', msg), [notify])
// Inline single-field edit from a double-clicked table cell.
// Inline single-field edit from a double-clicked table cell. Only offered when
// the library can take an edit: passing `undefined` makes those cells inert
// rather than firing a request the adapter will refuse. Defaults to false, so
// no edit is ever offered before capabilities have resolved.
const canEdit = capabilities.data?.writable ?? false
const editField = useCallback(
(track: Track, field: keyof Track, value: string | number) => {
api
@@ -265,7 +269,11 @@ export default function App() {
y={menu.y}
items={[
{ label: 'Load to Deck', onClick: () => setPrepTrack(menu.track) },
{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) },
// Offering "Edit Tags…" on a read-only library would open a dialog
// whose every save is refused, so it is not offered at all.
...(canEdit
? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }]
: []),
]}
onClose={() => setMenu(null)}
/>
@@ -348,7 +356,7 @@ export default function App() {
}}
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
onPlay={playTrack}
onEditField={editField}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
columnVisibility={columnVisibility}
columnOrder={columnOrder}
@@ -374,7 +382,7 @@ export default function App() {
tracks={filtered}
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
onPlay={playTrack}
onEditField={editField}
onEditField={canEdit ? editField : undefined}
activeTrackId={prepTrack?.id ?? null}
columnVisibility={columnVisibility}
columnOrder={columnOrder}
+12
View File
@@ -168,9 +168,21 @@ export interface SaveCapabilities {
history: boolean
}
/** Why a library cannot be edited. A fact — lib/platformCopy.ts words it. */
export type ReadonlyCause = 'platform_incomplete' | 'cloud_synced'
export interface Capabilities {
platform: Platform
version: string | null
/** Whether ANY edit can be persisted.
*
* Deliberately not the same as every per-feature flag being false: "the
* platform has no such feature" and "this library cannot be written at all"
* look identical to a UI that only sees the per-feature flags, and silently
* inert controls read as a bug. Gate edit affordances on this AND on the
* per-feature flag. */
writable: boolean
readonly_cause: ReadonlyCause | null
cues: CueCapabilities
grid: { editable: boolean; flexible: boolean; lockable: boolean }
tracks: {
+33
View File
@@ -4,6 +4,7 @@ import { api, type CueType, type GridMarker, type Track, type TrackCues } from '
import { buildBeatGrid, GRID_EPS } from '../lib/beatgrid'
import { slotLabeller, useCaps } from '../lib/capabilities'
import { CUE_TYPE_LABELS } from '../lib/cues'
import { readOnlyShort, readOnlyNotice } from '../lib/platformCopy'
import { analyzeWaveform, type WaveColumn } from '../lib/waveform'
import { ScratchEngine } from '../lib/scratchEngine'
import { PlaybackEngine } from '../lib/playbackEngine'
@@ -562,6 +563,15 @@ 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.')
return true
}
const slotCount = caps.cues.hotcue_slots
const slotLabel = slotLabeller(caps)
// Loops are a cue TYPE on some platforms and a separate bank on others; the
@@ -613,6 +623,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
return
}
if (!cue) {
if (refuseIfReadOnly()) return
try {
// Setting a hotcue while a loop is active stores it as a loop hotcue.
if (loopActive && loopRegion) {
@@ -652,6 +663,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
const hotcueCount = (c: TrackCues | null) =>
c?.cues.filter((x) => x.role === 'hotcue' && x.slot != null).length ?? 0
if (hotcueCount(cueData) >= slotCount) {
@@ -678,6 +690,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
const changeSelectedType = async (type: CueType) => {
if (!track || selectedSlot == null) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.setCueType(track.id, selectedSlot, type))
} catch (e) {
@@ -687,6 +700,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
const deleteSelected = async () => {
if (!track || selectedSlot == null) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.deleteCue(track.id, selectedSlot))
setSelectedSlot(null)
@@ -699,6 +713,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
try {
applyCueEdit(await api.deleteCue(track.id, slot))
if (selectedSlot === slot) setSelectedSlot(null)
@@ -723,6 +738,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
try {
applyCueEdit(await api.setGridMarker(track.id, index, patch))
} catch (e) {
@@ -744,6 +760,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
try {
applyCueEdit(await api.addGridMarker(track.id, playheadNow()))
} catch (e) {
@@ -752,6 +769,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
}
const deleteMarkerHere = async () => {
if (!track || activeMarkerIndex < 0) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.deleteGridMarker(track.id, activeMarkerIndex))
} catch (e) {
@@ -768,6 +786,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
const resetGrid = async () => {
const o = originalGridRef.current
if (!track || !o) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.replaceGridMarkers(track.id, o))
} catch (e) {
@@ -776,6 +795,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
}
const toggleLock = async () => {
if (!track) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.setGridLock(track.id, !cueData?.grid_locked))
} catch (e) {
@@ -784,6 +804,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
}
const deleteGrid = async () => {
if (!track) return
if (refuseIfReadOnly()) return
try {
applyCueEdit(await api.deleteGrid(track.id))
} catch (e) {
@@ -793,6 +814,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
setGridBusy(true)
try {
applyCueEdit(await api.autoGrid(track.id))
@@ -900,6 +922,17 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
<div className="truncate text-xs text-muted" title={track.artist ?? ''}>
{track.artist ?? 'Unknown artist'}
</div>
{/* The deck stays usable for listening on a read-only library, so
say which it is rather than leaving the edit controls looking
live. The controls themselves report the reason when pressed. */}
{readOnlyShort(caps) && (
<div
className="mt-1 inline-block rounded bg-ink-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-faint"
title={readOnlyNotice(caps) ?? ''}
>
{readOnlyShort(caps)}
</div>
)}
</>
) : (
<div className="text-xs uppercase tracking-wider text-faint">No track loaded</div>
+15 -1
View File
@@ -2,7 +2,7 @@ import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api } from '../api'
import { useCaps } from '../lib/capabilities'
import { overwriteWarning, saveLabel } from '../lib/platformCopy'
import { overwriteWarning, readOnlyNotice, saveLabel } from '../lib/platformCopy'
interface Props {
onError: (msg: string) => void
@@ -31,6 +31,20 @@ export function SaveBar({ onError }: Props) {
const caps = useCaps()
const warning = overwriteWarning(caps.save)
const dirty = state?.dirty ?? false
const readOnly = readOnlyNotice(caps)
// A read-only library has no save to offer, and saying so plainly is the whole
// point: a greyed-out button with no explanation reads as a bug.
if (readOnly) {
return (
<div className="border-t border-line bg-ink-900 px-3 py-3">
<div className="rounded-md bg-ink-800 px-2 py-2 text-[11px] leading-snug text-faint">
<span className="font-medium text-ink-200">Read-only</span>
<div className="mt-1">{readOnly}</div>
</div>
</div>
)
}
return (
<div className="border-t border-line bg-ink-900 px-3 py-3">
+50 -35
View File
@@ -1,6 +1,7 @@
import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type PlaylistKind, type PlaylistNode } from '../api'
import { useCaps } from '../lib/capabilities'
import { SaveBar } from './SaveBar'
export type Source = { kind: 'all' } | { kind: 'playlist'; id: string; name: string }
@@ -115,31 +116,40 @@ function NodeRow({
)}
</button>
{node.can_rename && !renaming && (
<>
<button
title="Rename"
onClick={() => {
setDraft(node.name)
setRenaming(true)
}}
className="hidden shrink-0 rounded px-1 text-xs text-faint hover:text-text group-hover:block"
>
✎
</button>
<button
title="Delete playlist"
onClick={() => {
if (confirm(`Delete playlist "${node.name}"?`)) del.mutate()
}}
className="hidden shrink-0 rounded px-1 text-xs text-faint hover:text-pink group-hover:block"
>
×
</button>
<span className="shrink-0 rounded bg-ink-800 px-1.5 py-0.5 text-[10px] tabular-nums text-faint group-hover:hidden">
{node.count}
</span>
</>
{/* Each action gates on ITS OWN flag: a platform may allow renaming but
not deleting. The count shows either way — it is information, not an
action, and hiding it on a read-only library loses real data. */}
{!renaming && node.can_rename && (
<button
title="Rename"
onClick={() => {
setDraft(node.name)
setRenaming(true)
}}
className="hidden shrink-0 rounded px-1 text-xs text-faint hover:text-text group-hover:block"
>
✎
</button>
)}
{!renaming && node.can_delete && (
<button
title="Delete playlist"
onClick={() => {
if (confirm(`Delete playlist "${node.name}"?`)) del.mutate()
}}
className="hidden shrink-0 rounded px-1 text-xs text-faint hover:text-pink group-hover:block"
>
×
</button>
)}
{!renaming && !isFolder && (
<span
className={`shrink-0 rounded bg-ink-800 px-1.5 py-0.5 text-[10px] tabular-nums text-faint ${
node.can_rename || node.can_delete ? 'group-hover:hidden' : ''
}`}
>
{node.count}
</span>
)}
</div>
{isFolder && open && node.children.length > 0 && (
@@ -162,6 +172,9 @@ function NodeRow({
export function Sidebar({ source, onSelect, onError, onOpenHistory }: Props) {
const qc = useQueryClient()
// There is no per-node flag for "you may create a NEW playlist" — the node
// flags describe existing nodes — so this is the library-level gate.
const canCreate = useCaps().writable
const [creating, setCreating] = useState(false)
const [newName, setNewName] = useState('')
const { data: playlists, isLoading } = useQuery({
@@ -205,16 +218,18 @@ export function Sidebar({ source, onSelect, onError, onOpenHistory }: Props) {
<span className="text-[10px] font-semibold uppercase tracking-wider text-faint">
Playlists
</span>
<button
title="New playlist"
onClick={() => {
setCreating(true)
setNewName('')
}}
className="rounded px-1 text-sm text-faint hover:text-text"
>
+
</button>
{canCreate && (
<button
title="New playlist"
onClick={() => {
setCreating(true)
setNewName('')
}}
className="rounded px-1 text-sm text-faint hover:text-text"
>
+
</button>
)}
</div>
<div className="mt-1 flex-1 overflow-y-auto px-2 pb-4">
+6
View File
@@ -30,3 +30,9 @@ export function slotLabeller(caps: Capabilities): (slot: number) => string {
? (slot) => String.fromCharCode(65 + slot)
: (slot) => String(slot + 1)
}
/** Whether the loaded library accepts edits at all. Gate every edit affordance
* on this in addition to the relevant per-feature capability. */
export function useWritable(): boolean {
return useCaps().writable
}
+26 -1
View File
@@ -6,7 +6,7 @@
* staying genuinely specific — the pre-save warning is a real, per-platform
* hazard and must not be watered down into something vague.
*/
import type { SaveCapabilities } from '../api'
import type { Capabilities, SaveCapabilities } from '../api'
export function saveLabel(save: SaveCapabilities): string {
return `Save to ${save.app_name}`
@@ -39,3 +39,28 @@ export function restoreWarning(save: SaveCapabilities): string | null {
export function writeHint(save: SaveCapabilities): string {
return `Save to ${save.app_name} to write it to disk`
}
/**
* Why this library is read-only, or null when it is editable.
*
* The two causes need genuinely different wording: a missing feature is a gap
* the user should expect Konduktor to close, whereas a cloud-synced library is
* a deliberate, permanent refusal that protects their other machines — and a
* user told only "read-only" would reasonably file the second as a bug.
*/
export function readOnlyNotice(caps: Capabilities): string | null {
if (caps.writable) return null
switch (caps.readonly_cause) {
case 'cloud_synced':
return `This ${caps.save.app_name} library is synced with ${caps.save.app_name} Cloud, so Konduktor will not write to it — an edit it did not make could break syncing on your other devices.`
case 'platform_incomplete':
default:
return `Konduktor can read ${caps.save.app_name} libraries but cannot save changes to them yet.`
}
}
/** Compact form for a badge or a disabled control's tooltip. */
export function readOnlyShort(caps: Capabilities): string | null {
if (caps.writable) return null
return caps.readonly_cause === 'cloud_synced' ? 'Read-only · cloud-synced' : 'Read-only'
}