mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added Rekordbox capabilities handling
This commit is contained in:
1 parent
4592e13228
commit
010f67cd2d
14 files changed
+297
-43
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in new issue
Block a user