Switched to more generic wording

This commit is contained in:
patben8 committed 2026-09-17 22:24:56 +02:00
1 parent c9e85bbdb5
commit 6e24f5ef1d
29 files changed
+796 -319

No files matched your search

+24 -7
View File
@@ -1,6 +1,8 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import type { ColumnSizingState, SortingState, VisibilityState } from '@tanstack/react-table'
import { CapabilitiesContext } from './lib/capabilities'
import { writeHint } from './lib/platformCopy'
import { api, type Track } from './api'
import {
DEFAULT_COLUMN_ORDER,
@@ -113,6 +115,22 @@ export default function App() {
}
}, [columnVisibility, columnOrder, columnSizing])
const collection = useQuery({ queryKey: ['collection'], queryFn: api.collection })
const loaded = collection.data?.loaded ?? false
// What the loaded library can persist. Never stale within a session, and the
// app does not render until it resolves — so no first frame can offer an edit
// the adapter would reject.
const capabilities = useQuery({
queryKey: ['capabilities'],
queryFn: api.capabilities,
enabled: loaded,
staleTime: Infinity,
})
const save = capabilities.data?.save
// From the adapter, not a path split: a Serato library is a directory.
const libraryName = collection.data?.library?.display_name ?? null
const writeHintText = save ? writeHint(save) : 'save to write it to disk'
const notify = useCallback((kind: ToastMsg['kind'], text: string) => {
setToast({ id: Date.now(), kind, text })
}, [])
@@ -128,16 +146,13 @@ export default function App() {
qc.invalidateQueries({ queryKey: ['playlist'] })
qc.invalidateQueries({ queryKey: ['state'] })
qc.invalidateQueries({ queryKey: ['facets'] })
qc.invalidateQueries({ queryKey: ['stats'] })
notify('success', `Updated ${String(field)} — Save to write to Traktor`)
notify('success', `Updated ${String(field)} — ${writeHintText}`)
})
.catch((e) => onError((e as Error).message))
},
[qc, notify, onError],
[qc, notify, onError, writeHintText],
)
const collection = useQuery({ queryKey: ['collection'], queryFn: api.collection })
const loaded = collection.data?.loaded ?? false
// NOTE: all hooks must run on every render (Rules of Hooks). Data queries are
// gated with `enabled: loaded` so they don't fire before a collection is open;
@@ -206,7 +221,7 @@ export default function App() {
qc.invalidateQueries() // refetch everything for the newly-opened collection
}
if (collection.isLoading) {
if (collection.isLoading || (loaded && !capabilities.data)) {
return (
<div className="flex h-screen w-screen items-center justify-center bg-ink-950 text-muted">
Loading…
@@ -241,6 +256,7 @@ export default function App() {
)
return (
<CapabilitiesContext.Provider value={capabilities.data!}>
<div className="flex h-screen w-screen flex-col overflow-hidden bg-ink-950">
<Toast toast={toast} onClose={() => setToast(null)} />
{menu && (
@@ -387,11 +403,12 @@ export default function App() {
total={tracks.length}
sourceName={isAll ? 'All Tracks' : source.name}
loading={loading}
collectionName={collection.data?.path?.split('/').pop() ?? null}
collectionName={capabilities.data ? libraryName : null}
onChangeCollection={() => setForcePicker(true)}
/>
</main>
</div>
</div>
</CapabilitiesContext.Provider>
)
}
+129 -61
View File
@@ -12,20 +12,27 @@ export interface Track {
mix: string | null
comment: string | null
bpm: number | null
/** The platform's own display string, shown verbatim: "10m", "8A", "Am". */
key: string | null
/** Camelot wheel position 1-12 + mode, parsed by the ADAPTER — notation is
* platform knowledge, not display formatting. Null when unparseable. */
key_wheel: number | null
key_mode: 'major' | 'minor' | null
rating: number
playcount: number | null
length: number | null
bitrate: number | null
/** ISO-8601 "YYYY-MM-DD", normalised by the adapter. */
import_date: string | null
last_played: string | null
release_date: string | null
filepath: string | null
cue_count: number
hotcue_count: number
has_grid: boolean
grid_markers: number // >1 = a flexible (multi-tempo) beatgrid
is_stem: boolean
/** 0 = no beatgrid, 1 = constant tempo, >1 = a flexible (multi-tempo) grid. */
grid_marker_count: number
grid_locked: boolean
media_kind: MediaKind
}
export interface TrackPage {
@@ -48,29 +55,21 @@ export interface Facets {
total_tracks: number
}
export interface Stats {
total_tracks: number
total_playlists: number
rated: number
unrated: number
missing_key: number
missing_genre: number
missing_bpm: number
no_cues: number
rating_breakdown: Record<string, number>
bpm_histogram: { bucket: string; count: number }[]
top_genres: GenreCount[]
}
export type PlaylistType = 'FOLDER' | 'PLAYLIST' | 'SMARTLIST'
export interface PlaylistNode {
/** Opaque, adapter-minted. The UI never constructs, parses or prefixes it. */
id: string
name: string
type: PlaylistType
uuid: string | null
/** For choosing an icon only — every behavioural question is answered by the
* flags below, so the UI never infers what a node can do from its kind. */
kind: PlaylistKind
count: number
children: PlaylistNode[]
selectable: boolean
can_add_tracks: boolean
can_reorder: boolean
can_rename: boolean
can_delete: boolean
can_contain_children: boolean
}
export type SortField =
@@ -99,19 +98,31 @@ export interface TrackQuery {
offset?: number
}
export type Platform = string
export type CueRole = 'hotcue' | 'memory'
export type CueType = 'cue' | 'fade_in' | 'fade_out' | 'load' | 'loop'
export type MediaKind = 'audio' | 'stem' | 'video'
export type PlaylistKind = 'folder' | 'playlist' | 'smart'
export type TrackField =
| 'title' | 'artist' | 'album' | 'genre' | 'label' | 'remixer'
| 'producer' | 'mix' | 'release_date' | 'comment' | 'rating'
export interface CuePoint {
name: string | null
type: number // 0 cue, 1 fade-in, 2 fade-out, 3 load, 4 grid, 5 loop
type: CueType
/** Memory cues have no bank slot. Only Rekordbox has them, so they are
* preserved and shown but not editable anywhere yet. */
role: CueRole
start: number // seconds
length: number // seconds (>0 for loops)
hotcue: number // -1 if not a hotcue
color: string | null // "#RRGGBB"
/**
* Index of the grid marker this cue is the companion of, if any. Traktor
* pairs most grid markers with a white cue that occupies a real hotcue slot;
* it belongs to the beatgrid, so it is shown read-only and the backend
* refuses hotcue edits on it.
*/
slot: number | null // bank slot; null for a cue not in a bank
color: string | null // "#RRGGBB" as the platform stored it
/** False when the adapter refuses commands on this cue. Gate on THIS, never
* on a platform-specific reason like grid_marker. */
editable: boolean
readonly_reason: 'beatgrid_companion' | 'platform_managed' | null
/** Index of the grid marker this cue mirrors, where the platform pairs them.
* A display hint only; null on platforms that do not. */
grid_marker: number | null
}
@@ -131,18 +142,74 @@ export interface TrackCues {
* render and edit wrongly.
*/
grid_markers: GridMarker[]
locked: boolean
grid_locked: boolean
cues: CuePoint[]
}
export interface CueCapabilities {
hotcue_slots: number
slot_labels: 'number' | 'letter'
memory_cues: boolean
max_memory_cues: number | null
types: CueType[]
color: 'none' | 'free' | 'palette'
palette: string[]
named: boolean
loops: 'none' | 'cue_type' | 'separate_bank'
loop_slots: number | null
}
export interface SaveCapabilities {
/** Structured facts, never finished sentences — the UI composes the wording
* (see lib/platformCopy.ts) so it stays specific without being hard-coded. */
app_name: string
library_label: string
overwrite_risk: 'none' | 'on_exit' | 'while_running'
history: boolean
}
export interface Capabilities {
platform: Platform
version: string | null
cues: CueCapabilities
grid: { editable: boolean; flexible: boolean; lockable: boolean }
tracks: {
rating_max: number
editable_fields: TrackField[]
media_kinds: MediaKind[]
artwork: boolean
artwork_note: string | null
}
playlists: { folders: boolean; smart: 'none' | 'read_only'; reorder: boolean }
save: SaveCapabilities
}
export interface LibraryInfo {
platform: Platform
name: string // the DJ app's name, e.g. "Traktor"
library_label: string // e.g. "collection.nml"
path: string
display_name: string
version: string | null
}
export interface PlatformOption {
platform: Platform
name: string
library_label: string
selects: 'file' | 'directory'
installed: boolean
}
export interface EditState {
dirty: boolean
nml_path: string
library: LibraryInfo
}
export interface CollectionStatus {
loaded: boolean
path: string | null
library: LibraryInfo | null
tracks: number | null
playlists: number | null
}
@@ -259,28 +326,29 @@ function qs(params: Record<string, unknown>): string {
export const api = {
// ---- collection selection ----
collection: () => getJSON<CollectionStatus>('/api/collection'),
collection: () => getJSON<CollectionStatus>('/api/library'),
openCollection: (path: string) =>
send<CollectionStatus>('POST', '/api/collection/open', { path }),
collectionOptions: () => getJSON<CollectionOptions>('/api/collection/options'),
send<CollectionStatus>('POST', '/api/library/open', { path }),
collectionOptions: () => getJSON<CollectionOptions>('/api/library/options'),
listDir: (path?: string) =>
getJSON<FsListing>(`/api/fs/list${path ? `?path=${encodeURIComponent(path)}` : ''}`),
// ---- path remapping (per-collection OS-path prefix translation) ----
getPathMapping: () => getJSON<PathMapping>('/api/collection/path-mapping'),
getPathMapping: () => getJSON<PathMapping>('/api/library/path-mapping'),
suggestPrefix: () =>
getJSON<PrefixSuggestions>('/api/collection/path-mapping/suggest'),
getJSON<PrefixSuggestions>('/api/library/path-mapping/suggest'),
putPathMapping: (m: PathMapping) =>
send<PathMapping>('PUT', '/api/collection/path-mapping', m),
send<PathMapping>('PUT', '/api/library/path-mapping', m),
previewRemap: (from: string, to: string) =>
getJSON<RemapPreview>(
`/api/collection/path-mapping/preview?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
`/api/library/path-mapping/preview?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
),
// Write-back: permanently rewrite matching LOCATIONs in the .nml (committed to history).
remapPaths: (from: string, to: string) =>
send<RemapResult>('POST', '/api/collection/remap-paths', { from, to }),
send<RemapResult>('POST', '/api/library/remap-paths', { from, to }),
stats: () => getJSON<Stats>('/api/stats'),
capabilities: () => getJSON<Capabilities>('/api/capabilities'),
platforms: () => getJSON<PlatformOption[]>('/api/platforms'),
facets: () => getJSON<Facets>('/api/facets'),
playlists: () => getJSON<PlaylistNode[]>('/api/playlists'),
tracks: (query: TrackQuery) =>
@@ -292,18 +360,18 @@ export const api = {
state: () => getJSON<EditState>('/api/state'),
createPlaylist: (name: string, parentId?: string) =>
send<PlaylistNode>('POST', '/api/playlists', { name, parent_id: parentId ?? null }),
renamePlaylist: (uuid: string, name: string) =>
send<{ status: string }>('PATCH', `/api/playlists/${uuid}`, { name }),
deletePlaylist: (uuid: string) =>
send<{ status: string }>('DELETE', `/api/playlists/${uuid}`),
setEntries: (uuid: string, trackIds: string[]) =>
send<{ status: string; count: number }>('PUT', `/api/playlists/${uuid}/entries`, {
renamePlaylist: (nodeId: string, name: string) =>
send<{ status: string }>('PATCH', `/api/playlists/${encodeURIComponent(nodeId)}`, { name }),
deletePlaylist: (nodeId: string) =>
send<{ status: string }>('DELETE', `/api/playlists/${encodeURIComponent(nodeId)}`),
setEntries: (nodeId: string, trackIds: string[]) =>
send<{ status: string; count: number }>('PUT', `/api/playlists/${encodeURIComponent(nodeId)}/entries`, {
track_ids: trackIds,
}),
addEntries: (uuid: string, trackIds: string[]) =>
addEntries: (nodeId: string, trackIds: string[]) =>
send<{ status: string; added: number; count: number }>(
'POST',
`/api/playlists/${uuid}/add`,
`/api/playlists/${encodeURIComponent(nodeId)}/add`,
{ track_ids: trackIds },
),
getPrefs: () => getJSON<Record<string, unknown>>('/api/prefs'),
@@ -325,15 +393,15 @@ export const api = {
`${API_BASE}/api/tracks/audio?track_id=${encodeURIComponent(trackId)}`,
trackCues: (trackId: string) =>
getJSON<TrackCues>(`/api/tracks/cues?track_id=${encodeURIComponent(trackId)}`),
createHotcue: (
createCue: (
trackId: string,
slot: number,
start: number,
type: number,
type: CueType,
length = 0,
name?: string,
) =>
send<TrackCues>('POST', '/api/tracks/hotcue', {
send<TrackCues>('POST', '/api/tracks/cue', {
track_id: trackId,
slot,
start,
@@ -342,20 +410,20 @@ export const api = {
name,
}),
// Backend analyses the audio and places structural hotcues into empty slots.
autoHotcues: (trackId: string, maxCues?: number) =>
send<TrackCues>('POST', '/api/tracks/auto-hotcues', {
autoCues: (trackId: string, maxCues?: number) =>
send<TrackCues>('POST', '/api/tracks/cue/auto', {
track_id: trackId,
max_cues: maxCues,
}),
// Backend detects tempo + first beat: sets BPM, hotcue 1, and grid anchor.
autoGrid: (trackId: string) =>
send<TrackCues>('POST', '/api/tracks/auto-grid', { track_id: trackId }),
setHotcueType: (trackId: string, slot: number, type: number) =>
send<TrackCues>('PATCH', '/api/tracks/hotcue', { track_id: trackId, slot, type }),
deleteHotcue: (trackId: string, slot: number) =>
send<TrackCues>('POST', '/api/tracks/grid/auto', { track_id: trackId }),
setCueType: (trackId: string, slot: number, type: CueType) =>
send<TrackCues>('PATCH', '/api/tracks/cue', { track_id: trackId, slot, type }),
deleteCue: (trackId: string, slot: number) =>
send<TrackCues>(
'DELETE',
`/api/tracks/hotcue?track_id=${encodeURIComponent(trackId)}&slot=${slot}`,
`/api/tracks/cue?track_id=${encodeURIComponent(trackId)}&slot=${slot}`,
),
/** Retempo and/or move one marker. `index` is its position in grid_markers;
* a move is clamped between its neighbours rather than reordering them. */
@@ -378,8 +446,8 @@ export const api = {
send<TrackCues>('PUT', '/api/tracks/grid', { track_id: trackId, markers }),
deleteGrid: (trackId: string) =>
send<TrackCues>('DELETE', `/api/tracks/grid?track_id=${encodeURIComponent(trackId)}`),
setLock: (trackId: string, locked: boolean) =>
send<TrackCues>('PATCH', '/api/tracks/lock', { track_id: trackId, locked }),
setGridLock: (trackId: string, locked: boolean) =>
send<TrackCues>('PATCH', '/api/tracks/grid/lock', { track_id: trackId, locked }),
uploadArt: async (trackId: string, file: File) => {
const fd = new FormData()
fd.append('track_id', trackId)
+13 -6
View File
@@ -52,6 +52,13 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
const [manual, setManual] = useState('')
const options = useQuery({ queryKey: ['collectionOptions'], queryFn: api.collectionOptions })
// The picker runs BEFORE a library is open, so capabilities do not exist yet —
// /api/platforms is the pre-load equivalent.
const { data: platforms } = useQuery({ queryKey: ['platforms'], queryFn: api.platforms })
// One platform today, so name it; with more, stay general rather than listing.
const only = platforms?.length === 1 ? platforms[0] : null
const appName = only?.name ?? 'DJ'
const fileLabel = only?.library_label ?? 'library file'
const listing = useQuery({
queryKey: ['fs', dir ?? '~'],
queryFn: () => api.listDir(dir),
@@ -76,12 +83,12 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
<div className="flex items-center gap-3 border-b border-line px-5 py-4">
<div className="flex-1">
<div className="text-[15px] font-semibold tracking-tight">
Select your Traktor collection
Select your {appName} library
</div>
<div className="text-xs text-muted">
{mode === 'choose'
? 'Open automatically, resume your last one, or browse.'
: 'Choose a collection.nml file to open.'}
: `Choose a ${fileLabel} to open.`}
</div>
</div>
{mode === 'browse' && (
@@ -112,8 +119,8 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
auto
? `${auto.label} · modified ${formatWhen(auto.modified)}`
: options.isLoading
? 'Searching for a Traktor collection…'
: 'No Traktor collection found in the default location'
? `Searching for a ${appName} library…`
: `No ${appName} library found in the default location`
}
disabled={!auto}
busy={open.isPending}
@@ -136,7 +143,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
<OptionCard
icon="📂"
title="Find collection manually"
subtitle="Browse for a collection.nml file"
subtitle={`Browse for a ${fileLabel}`}
busy={open.isPending}
onClick={() => setMode('browse')}
/>
@@ -218,7 +225,7 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
onKeyDown={(e) => {
if (e.key === 'Enter' && manual.trim()) open.mutate(manual.trim())
}}
placeholder="…or paste a full path to collection.nml"
placeholder={`…or paste a full path to ${fileLabel}`}
className="min-w-0 flex-1 rounded-md border border-line bg-ink-850 px-3 py-2 font-mono text-xs text-text outline-none placeholder:text-faint focus:border-accent"
/>
<button
+12 -12
View File
@@ -2,6 +2,9 @@ import { useRef, useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type Track } from '../api'
import { formatBpm, formatDuration } from '../lib/format'
import { useCaps } from '../lib/capabilities'
import { RatingStars } from './RatingStars'
import { saveLabel, writeHint } from '../lib/platformCopy'
interface Props {
track: Track
@@ -25,6 +28,7 @@ const TEXT_FIELDS: { key: keyof Track; label: string; textarea?: boolean }[] = [
]
export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
const caps = useCaps()
const qc = useQueryClient()
const { data: facets } = useQuery({ queryKey: ['facets'], queryFn: api.facets })
@@ -61,7 +65,9 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
qc.invalidateQueries({ queryKey: ['state'] })
qc.invalidateQueries({ queryKey: ['facets'] })
qc.invalidateQueries({ queryKey: ['stats'] })
onApplied(`Updated “${form.title || track.title || 'track'}” — Save to write to Traktor`)
onApplied(
`Updated “${form.title || track.title || 'track'}” — ${writeHint(caps.save)}`,
)
onClose()
},
onError: (e: Error) => onError(e.message),
@@ -170,15 +176,7 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
Rating
</span>
<div className="flex items-center gap-1 text-xl">
{[1, 2, 3, 4, 5].map((i) => (
<button
key={i}
onClick={() => setRating(i === rating ? 0 : i)}
className={i <= rating ? 'text-gold' : 'text-ink-600 hover:text-faint'}
>
★
</button>
))}
<RatingStars value={rating} max={caps.tracks.rating_max} onChange={setRating} />
{rating > 0 && (
<button
onClick={() => setRating(0)}
@@ -204,8 +202,10 @@ export function EditTagsDialog({ track, onClose, onApplied, onError }: Props) {
</div>
<p className="text-[11px] leading-snug text-faint">
BPM, key and path aren’t editable here. Changes apply in-app; click
<span className="text-muted"> Save to Traktor</span> to write them to disk.
New album art is written into the file; Traktor may need a manual
<span className="text-muted"> {saveLabel(caps.save)}</span> to write them to disk.
New album art is written into the file.{' '}
{caps.tracks.artwork_note}
{'' /* platform-specific footnote, supplied by the adapter */}
“Import Cover Art” to refresh its own cached thumbnail.
</p>
</div>
+5 -3
View File
@@ -1,6 +1,8 @@
import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type HistoryEntry } from '../api'
import { useCaps } from '../lib/capabilities'
import { restoreWarning } from '../lib/platformCopy'
import type { ToastMsg } from './Toast'
interface Props {
@@ -37,9 +39,10 @@ function summaryChips(summary: string): string[] {
* a purely-local git repo (see backend history.py); this lists them newest-first
* and lets the user restore any past version (written back as a new forward save)
* or wipe the entire history. Restore overwrites the collection on disk, so the
* user must close Traktor first (it rewrites the .nml on exit).
* user is warned first, in the loaded platform's own terms.
*/
export function HistoryPanel({ onClose, onNotify, onError }: Props) {
const caps = useCaps()
const qc = useQueryClient()
const history = useQuery({ queryKey: ['history'], queryFn: api.history })
const [confirmingId, setConfirmingId] = useState<string | null>(null)
@@ -87,8 +90,7 @@ export function HistoryPanel({ onClose, onNotify, onError }: Props) {
<div className="border-b border-line px-5 py-4">
<div className="text-[15px] font-semibold tracking-tight">Version History</div>
<div className="text-xs text-muted">
Every save is a restorable version of this collection. Close Traktor before
restoring — it overwrites the collection on exit.
Every save is a restorable version of this library. {restoreWarning(caps.save)}
</div>
</div>
+37 -14
View File
@@ -1,14 +1,21 @@
import type { CuePoint } from '../api'
import { contrastText, cueColor, GRID_MARKER_COLOR } from '../lib/cues'
import { contrastText, cueColor, cueGlyph } from '../lib/cues'
interface Props {
cues: CuePoint[]
/** Bank size, from capabilities — not every platform has eight. */
slotCount: number
/** How a slot is labelled ("1".."8" or "A".."H"). */
slotLabel: (slot: number) => string
selectedSlot: number | null
onSlotPress: (slot: number) => void
onSlotRelease: (slot: number) => void
}
const SLOTS = [0, 1, 2, 3, 4, 5, 6, 7] // Traktor hotcue slots → labelled 1–8
const READONLY_LABELS: Record<string, string> = {
beatgrid_companion: 'Beatgrid marker — managed by the grid controls',
platform_managed: 'Managed by the DJ app — not editable here',
}
/**
* The 8 hotcue slots, colour-coded by cue type when assigned (gray when empty).
@@ -24,14 +31,24 @@ const SLOTS = [0, 1, 2, 3, 4, 5, 6, 7] // Traktor hotcue slots → labelled 1–
* the backend refuses hotcue edits on them, and showing that up front is better
* than surfacing the refusal as an error.
*/
export function HotcueBar({ cues, selectedSlot, onSlotPress, onSlotRelease }: Props) {
export function HotcueBar({
cues,
slotCount,
slotLabel,
selectedSlot,
onSlotPress,
onSlotRelease,
}: Props) {
return (
<div className="flex flex-1 items-stretch gap-px">
{SLOTS.map((slot) => {
const cue = cues.find((c) => c.hotcue === slot) ?? null
const isMarker = cue?.grid_marker != null
const selected = selectedSlot === slot && !isMarker
const color = cue ? (isMarker ? GRID_MARKER_COLOR : cueColor(cue)) : null
{Array.from({ length: slotCount }, (_, i) => i).map((slot) => {
const cue = cues.find((c) => c.role === 'hotcue' && c.slot === slot) ?? null
// Gate on `editable`, never on why: a platform-owned cue is a read-only
// case, not a Traktor-companion case.
const locked = cue != null && !cue.editable
const selected = selectedSlot === slot && !locked
const color = cue ? cueColor(cue) : null
const glyph = cue ? cueGlyph(cue) : ''
return (
<button
key={slot}
@@ -45,13 +62,14 @@ export function HotcueBar({ cues, selectedSlot, onSlotPress, onSlotRelease }: Pr
onPointerUp={() => onSlotRelease(slot)}
onPointerCancel={() => onSlotRelease(slot)}
title={
isMarker
? `Beatgrid marker ${(cue!.grid_marker ?? 0) + 1} — managed by the grid controls`
locked
? (cue!.readonly_reason && READONLY_LABELS[cue!.readonly_reason]) ??
'Not editable here'
: cue
? cue.name && cue.name !== 'n.n.'
? `${slot + 1}: ${cue.name}`
: `Hotcue ${slot + 1}`
: `Hotcue ${slot + 1} — click to set at playhead`
? `${slotLabel(slot)}: ${cue.name}`
: `Hotcue ${slotLabel(slot)}`
: `Hotcue ${slotLabel(slot)} — click to set at playhead`
}
style={color ? { backgroundColor: color, color: contrastText(color) } : undefined}
className={
@@ -60,7 +78,12 @@ export function HotcueBar({ cues, selectedSlot, onSlotPress, onSlotRelease }: Pr
(selected ? ' ring-2 ring-inset ring-white/80' : '')
}
>
{isMarker ? '⊞' : slot + 1}
{locked ? '🔒' : slotLabel(slot)}
{glyph && (
<span className="absolute right-0.5 top-0 text-[9px] leading-none opacity-80">
{glyph}
</span>
)}
</button>
)
})}
+61 -32
View File
@@ -1,7 +1,9 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type GridMarker, type Track, type TrackCues } from '../api'
import { api, type CueType, type GridMarker, type Track, type TrackCues } from '../api'
import { buildBeatGrid, GRID_EPS } from '../lib/beatgrid'
import { slotLabeller, useCaps } from '../lib/capabilities'
import { CUE_TYPE_LABELS } from '../lib/cues'
import { analyzeWaveform, type WaveColumn } from '../lib/waveform'
import { ScratchEngine } from '../lib/scratchEngine'
import { PlaybackEngine } from '../lib/playbackEngine'
@@ -29,13 +31,22 @@ function fmt(secs: number): string {
return `${m}:${s.toString().padStart(2, '0')}`
}
const CUE_TYPES: { value: number; label: string }[] = [
{ value: 0, label: 'Cue' },
{ value: 1, label: 'Fade-In' },
{ value: 2, label: 'Fade-Out' },
{ value: 3, label: 'Load' },
]
const LOOP_TYPE = 5
/**
* Digit key -> bank slot: 1..9 map to slots 0..8 and 0 maps to slot 10.
*
* Ten digits is the physical ceiling, so a bank larger than that simply has no
* shortcut for its tail. Returns null when the key is not a digit or the slot is
* beyond this platform's bank — an 8-slot bank behaves exactly as before.
*/
const DIGIT_RE = /^(?:Digit|Numpad)([0-9])$/
function slotForDigit(code: string, slotCount: number): number | null {
const m = code.match(DIGIT_RE)
if (!m) return null
const slot = m[1] === '0' ? 9 : Number(m[1]) - 1
return slot < slotCount ? slot : null
}
const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
/**
@@ -549,8 +560,17 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [grid])
// ---- capability-derived -----------------------------------------------
const caps = useCaps()
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
// dropdown only ever offers the point types.
const pointCueTypes = caps.cues.types.filter((t) => t !== 'loop')
// ---- hotcues ----------------------------------------------------------
const hotcueAt = (slot: number) => cueData?.cues.find((c) => c.hotcue === slot) ?? null
const hotcueAt = (slot: number) =>
cueData?.cues.find((c) => c.role === 'hotcue' && c.slot === slot) ?? null
const applyCueEdit = (fresh: TrackCues) => {
setCueData(fresh)
@@ -597,10 +617,10 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
// Setting a hotcue while a loop is active stores it as a loop hotcue.
if (loopActive && loopRegion) {
const len = loopRegion.end - loopRegion.start
applyCueEdit(await api.createHotcue(track.id, slot, loopRegion.start, LOOP_TYPE, len))
applyCueEdit(await api.createCue(track.id, slot, loopRegion.start, 'loop', len))
} else {
const t = snapTime(playbackRef.current?.getPosition() ?? current)
applyCueEdit(await api.createHotcue(track.id, slot, t, 0))
applyCueEdit(await api.createCue(track.id, slot, t, 'cue'))
}
setSelectedSlot(slot)
} catch (e) {
@@ -613,7 +633,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
if (!eng || !eng.ready) return
getCtx()
// A loop hotcue jumps to its start AND re-engages a loop of its length.
if (cue.type === LOOP_TYPE && cue.length > 0) {
if (cue.type === 'loop' && cue.length > 0) {
seek(cue.start)
engagLoop(cue.start, cue.start + cue.length, beatsForLoop(cue.start, cue.length))
} else {
@@ -633,15 +653,15 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
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')
c?.cues.filter((x) => x.role === 'hotcue' && x.slot != null).length ?? 0
if (hotcueCount(cueData) >= slotCount) {
onError?.(`No free hotcue slots (${slotCount} of ${slotCount} used) — delete some first`)
return
}
setAutoBusy(true)
try {
const before = hotcueCount(cueData)
const fresh = await api.autoHotcues(track.id)
const fresh = await api.autoCues(track.id)
applyCueEdit(fresh)
const placed = Math.max(0, hotcueCount(fresh) - before)
if (placed === 0) {
@@ -656,10 +676,10 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
}
}
const changeSelectedType = async (type: number) => {
const changeSelectedType = async (type: CueType) => {
if (!track || selectedSlot == null) return
try {
applyCueEdit(await api.setHotcueType(track.id, selectedSlot, type))
applyCueEdit(await api.setCueType(track.id, selectedSlot, type))
} catch (e) {
onError?.((e as Error).message)
}
@@ -668,7 +688,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
const deleteSelected = async () => {
if (!track || selectedSlot == null) return
try {
applyCueEdit(await api.deleteHotcue(track.id, selectedSlot))
applyCueEdit(await api.deleteCue(track.id, selectedSlot))
setSelectedSlot(null)
} catch (e) {
onError?.((e as Error).message)
@@ -680,7 +700,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
if (!track || !existing) return // nothing to remove in an empty slot
if (existing.grid_marker != null) return // beatgrid-owned: delete the marker instead
try {
applyCueEdit(await api.deleteHotcue(track.id, slot))
applyCueEdit(await api.deleteCue(track.id, slot))
if (selectedSlot === slot) setSelectedSlot(null)
} catch (e) {
onError?.((e as Error).message)
@@ -757,7 +777,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
const toggleLock = async () => {
if (!track) return
try {
applyCueEdit(await api.setLock(track.id, !cueData?.locked))
applyCueEdit(await api.setGridLock(track.id, !cueData?.grid_locked))
} catch (e) {
onError?.((e as Error).message)
}
@@ -799,6 +819,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
beatJump,
prevMarker,
nextMarker,
slotCount,
})
shortcutsRef.current = {
toggle,
@@ -810,6 +831,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
beatJump,
prevMarker,
nextMarker,
slotCount,
}
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
@@ -840,10 +862,9 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
else shortcutsRef.current.beatJump(1)
return
}
const digit = e.code.match(/^(?:Digit|Numpad)([1-8])$/)
if (digit) {
const slot = slotForDigit(e.code, shortcutsRef.current.slotCount)
if (slot != null) {
e.preventDefault()
const slot = Number(digit[1]) - 1
if (e.shiftKey) void shortcutsRef.current.deleteHotcueSlot(slot)
else void shortcutsRef.current.onSlotPress(slot)
}
@@ -851,8 +872,8 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
// keyup ends a held hotcue's momentary preview (release).
const onKeyRelease = (e: KeyboardEvent) => {
if (e.code === 'KeyC') shortcutsRef.current.onCueRelease()
const digit = e.code.match(/^(?:Digit|Numpad)([1-8])$/)
if (digit) shortcutsRef.current.onSlotRelease(Number(digit[1]) - 1)
const slot = slotForDigit(e.code, shortcutsRef.current.slotCount)
if (slot != null) shortcutsRef.current.onSlotRelease(slot)
}
window.addEventListener('keydown', onKey)
window.addEventListener('keyup', onKeyRelease)
@@ -893,7 +914,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
markerStart={activeMarker?.start ?? null}
atMarker={atMarker}
beforeFirst={beforeFirstMarker}
locked={cueData?.locked ?? false}
locked={cueData?.grid_locked ?? false}
canReset={originalGridRef.current != null}
onSetBpm={setBpm}
onNudgeBpm={nudgeBpm}
@@ -1034,24 +1055,32 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify }: Props)
</span>
<HotcueBar
cues={cueData?.cues ?? []}
slotCount={slotCount}
slotLabel={slotLabel}
selectedSlot={selectedSlot}
onSlotPress={onSlotPress}
onSlotRelease={onSlotRelease}
/>
<div className="flex w-28 items-center justify-center bg-ink-900 px-1">
{selectedCue && selectedCue.type === LOOP_TYPE ? (
{selectedCue && selectedCue.type === 'loop' ? (
<span className="text-sm font-semibold text-mint">Loop</span>
) : pointCueTypes.length < 2 ? (
// One point type means there is nothing to choose between —
// show it rather than a dropdown that cannot change anything.
<span className="text-sm font-semibold text-text">
{selectedCue ? CUE_TYPE_LABELS[selectedCue.type] : '—'}
</span>
) : (
<select
value={selectedCue ? selectedCue.type : ''}
disabled={!selectedCue}
onChange={(e) => changeSelectedType(Number(e.target.value))}
onChange={(e) => changeSelectedType(e.target.value as CueType)}
className="w-full bg-transparent text-center text-sm font-semibold text-text outline-none disabled:opacity-40"
>
{!selectedCue && <option value="">—</option>}
{CUE_TYPES.map((t) => (
<option key={t.value} value={t.value}>
{t.label}
{pointCueTypes.map((t) => (
<option key={t} value={t}>
{CUE_TYPE_LABELS[t]}
</option>
))}
</select>
+13 -10
View File
@@ -2,22 +2,25 @@ import { useState } from 'react'
interface Props {
value: number
/** When provided, the stars become clickable to set the rating (0–5). */
/** Scale length, from capabilities.tracks.rating_max. */
max?: number
/** When provided, the stars become clickable to set the rating. */
onChange?: (value: number) => void
}
// Compact 5-star rating. Read-only by default (shows a dash when unrated). When
// `onChange` is given it's interactive: always shows five stars — hollow (☆) up
// to the rating, solid gold (★) below it — with hover preview. Clicking a star
// sets that rating; clicking the current top star again clears it to 0.
export function RatingStars({ value, onChange }: Props) {
// Compact star rating. Read-only by default (shows a dash when unrated). When
// `onChange` is given it's interactive: hollow (☆) above the rating, solid gold
// (★) up to it, with hover preview. Clicking a star sets that rating; clicking
// the current top star again clears it to 0.
export function RatingStars({ value, max = 5, onChange }: Props) {
const [hover, setHover] = useState(0)
const stars = Array.from({ length: max }, (_, i) => i + 1)
if (!onChange) {
if (!value) return <span className="text-faint">—</span>
return (
<span className="whitespace-nowrap tracking-tight" title={`${value} / 5`}>
{[1, 2, 3, 4, 5].map((i) => (
<span className="whitespace-nowrap tracking-tight" title={`${value} / ${max}`}>
{stars.map((i) => (
<span key={i} className={i <= value ? 'text-gold' : 'text-ink-600'}>
{i <= value ? '★' : '☆'}
</span>
@@ -28,8 +31,8 @@ export function RatingStars({ value, onChange }: Props) {
const shown = hover || value
return (
<span className="whitespace-nowrap tracking-tight" title={`${value} / 5`}>
{[1, 2, 3, 4, 5].map((i) => (
<span className="whitespace-nowrap tracking-tight" title={`${value} / ${max}`}>
{stars.map((i) => (
<button
key={i}
onClick={(e) => {
+7 -3
View File
@@ -1,6 +1,8 @@
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'
interface Props {
onError: (msg: string) => void
@@ -26,13 +28,15 @@ export function SaveBar({ onError }: Props) {
onError: (e: Error) => onError(e.message),
})
const caps = useCaps()
const warning = overwriteWarning(caps.save)
const dirty = state?.dirty ?? false
return (
<div className="border-t border-line bg-ink-900 px-3 py-3">
{dirty && (
{dirty && warning && (
<div className="mb-2 rounded-md bg-gold/10 px-2 py-1.5 text-[11px] leading-snug text-gold">
⚠ Close Traktor before saving — it overwrites the collection on exit.
⚠ {warning}
</div>
)}
<button
@@ -49,7 +53,7 @@ export function SaveBar({ onError }: Props) {
) : dirty ? (
<>
<span className="h-1.5 w-1.5 rounded-full bg-ink-950/60" />
Save to Traktor
{saveLabel(caps.save)}
</>
) : (
'No unsaved changes'
+1 -1
View File
@@ -12,7 +12,7 @@ interface Props {
function flattenPlaylists(nodes: PlaylistNode[]): PlaylistNode[] {
return nodes.flatMap((n) => [
...(n.type === 'PLAYLIST' ? [n] : []),
...(n.can_add_tracks ? [n] : []),
...flattenPlaylists(n.children),
])
}
+12 -10
View File
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type PlaylistNode } from '../api'
import { api, type PlaylistKind, type PlaylistNode } from '../api'
import { SaveBar } from './SaveBar'
export type Source = { kind: 'all' } | { kind: 'playlist'; id: string; name: string }
@@ -12,10 +12,12 @@ interface Props {
onOpenHistory: () => void
}
const icons: Record<string, string> = {
FOLDER: '▸',
PLAYLIST: '♫',
SMARTLIST: '✦',
// Kind picks the icon; every behavioural question is answered by the node's own
// flags, so nothing here infers what a node can do from what it is called.
const icons: Record<PlaylistKind, string> = {
folder: '▸',
playlist: '♫',
smart: '✦',
}
function NodeRow({
@@ -35,9 +37,9 @@ function NodeRow({
const [open, setOpen] = useState(true)
const [renaming, setRenaming] = useState(false)
const [draft, setDraft] = useState(node.name)
const isFolder = node.type === 'FOLDER'
const isFolder = node.kind === 'folder'
const selected = source.kind === 'playlist' && source.id === node.id
const selectable = node.type === 'PLAYLIST'
const selectable = node.selectable
const invalidate = () => {
qc.invalidateQueries({ queryKey: ['playlists'] })
@@ -82,10 +84,10 @@ function NodeRow({
>
<span
className={`w-3 shrink-0 text-center text-[11px] ${
isFolder ? 'text-faint' : node.type === 'SMARTLIST' ? 'text-pink' : 'text-accent'
isFolder ? 'text-faint' : node.kind === 'smart' ? 'text-pink' : 'text-accent'
} ${isFolder && open ? 'rotate-90' : ''} transition-transform`}
>
{icons[node.type]}
{icons[node.kind]}
</span>
{renaming ? (
<input
@@ -113,7 +115,7 @@ function NodeRow({
)}
</button>
{node.type === 'PLAYLIST' && !renaming && (
{node.can_rename && !renaming && (
<>
<button
title="Rename"
+3 -1
View File
@@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import type { VisibilityState } from '@tanstack/react-table'
import { api } from '../api'
import { useCaps } from '../lib/capabilities'
import { ColumnsMenu } from './ColumnsMenu'
import { SettingsMenu } from './SettingsMenu'
@@ -44,6 +45,7 @@ export function Toolbar({
onResetColumns,
onOpenPathMapping,
}: Props) {
const caps = useCaps()
const { data: facets } = useQuery({ queryKey: ['facets'], queryFn: api.facets })
const set = (patch: Partial<Filters>) => onChange({ ...filters, ...patch })
const active =
@@ -117,7 +119,7 @@ export function Toolbar({
className={selectCls}
>
<option value={0}>Any rating</option>
{[1, 2, 3, 4, 5].map((r) => (
{Array.from({ length: caps.tracks.rating_max }, (_, i) => i + 1).map((r) => (
<option key={r} value={r}>
{'★'.repeat(r)}+
</option>
+32
View File
@@ -0,0 +1,32 @@
import { createContext, useContext } from 'react'
import type { Capabilities } from '../api'
/**
* What the loaded library can persist.
*
* Components read this instead of branching on the platform, so a control is
* never offered for an edit that would silently vanish on save. There is no
* default value on purpose: the app does not render until capabilities have
* resolved, which removes any chance of a permissive first frame offering an
* edit the adapter would reject.
*
* Containers call `useCaps()`; presentational leaves take plain values as props
* so they stay trivially testable.
*/
export const CapabilitiesContext = createContext<Capabilities | null>(null)
export function useCaps(): Capabilities {
const caps = useContext(CapabilitiesContext)
if (!caps) {
throw new Error('useCaps() used outside <CapabilitiesContext.Provider>')
}
return caps
}
/** Label for a bank slot: "1".."8" or "A".."H", per the platform's convention. */
export function slotLabeller(caps: Capabilities): (slot: number) => string {
return caps.cues.slot_labels === 'letter'
? (slot) => String.fromCharCode(65 + slot)
: (slot) => String(slot + 1)
}
+62 -22
View File
@@ -1,21 +1,56 @@
import type { CuePoint } from '../api'
import type { CuePoint, CueType } from '../api'
import { BEATS_PER_BAR, type BeatGrid } from './beatgrid'
// Marker colour by Traktor cue type. Type is authoritative here (the NML's
// stored per-cue colour is intentionally ignored) so each type reads consistently.
// There is deliberately no entry for type 4 (grid): grid markers are not cues —
// they arrive as TrackCues.grid_markers and are drawn by drawBeatgrid.
const TYPE_COLORS: Record<number, string> = {
0: '#3b82f6', // cue — blue
1: '#ff8c2f', // fade-in — orange
2: '#ff8c2f', // fade-out — orange
3: '#ffd60a', // load — yellow
5: '#22c55e', // loop — green
// Fallback colour by cue type, used when the platform stored none.
const TYPE_COLORS: Record<CueType, string> = {
cue: '#3b82f6', // blue
fade_in: '#ff8c2f', // orange
fade_out: '#ff8c2f', // orange
load: '#ffd60a', // yellow
loop: '#22c55e', // green
}
const OTHER_COLOR = '#8b93a3' // gray
const MEMORY_COLOR = '#8b93a3' // gray
export const CUE_TYPE_LABELS: Record<CueType, string> = {
cue: 'Cue',
fade_in: 'Fade-In',
fade_out: 'Fade-Out',
load: 'Load',
loop: 'Loop',
}
// A second, always-present channel for type. Colour used to be type-derived and
// therefore always carried it; now that a user's stored colour wins, the glyph
// is what keeps a fade-in distinguishable from a plain cue.
const TYPE_GLYPHS: Record<CueType, string> = {
cue: '',
fade_in: '▶',
fade_out: '◀',
load: '⏏',
loop: '⟳',
}
/**
* Colour for a cue marker or button.
*
* Stored colour wins where the platform has one: on Rekordbox and Serato it is
* the attribute the user actually set, and overriding it with a type palette
* would discard their own organisation. Traktor rarely stores one, so in a
* Traktor library the type palette still drives virtually every cue and the
* existing look is preserved.
*/
export function cueColor(cue: CuePoint): string {
return TYPE_COLORS[cue.type] ?? OTHER_COLOR
if (cue.color) return cue.color
if (cue.role === 'memory') return MEMORY_COLOR
return TYPE_COLORS[cue.type] ?? MEMORY_COLOR
}
export function cueTypeColor(type: CueType): string {
return TYPE_COLORS[type] ?? MEMORY_COLOR
}
export function cueGlyph(cue: CuePoint): string {
return TYPE_GLYPHS[cue.type] ?? ''
}
function withAlpha(hex: string, a: number): string {
@@ -46,6 +81,8 @@ export function drawCues(
dpr: number,
timeToX: (t: number) => number,
labels: boolean,
/** How a bank slot is labelled — "1".."8" or "A".."H", per the platform. */
slotLabel: (slot: number) => string = (slot) => String(slot + 1),
): void {
const lineW = Math.max(2, Math.round(2 * dpr))
const outline = Math.max(1, Math.round(dpr))
@@ -53,10 +90,9 @@ export function drawCues(
const flagH = Math.round(14 * dpr)
const half = Math.floor(lineW / 2)
for (const cue of cues) {
// Grid markers and their companion cues belong to the beatgrid and are
// drawn by drawBeatgrid; painting them here too would stack a grey line and
// a numbered flag on top of every marker.
if (cue.type === 4 || cue.grid_marker != null) continue
// A grid marker's companion cue is drawn by drawBeatgrid; painting it here
// too would stack a flag on top of every marker line.
if (cue.grid_marker != null) continue
const color = cueColor(cue)
const x = Math.round(timeToX(cue.start))
@@ -78,16 +114,20 @@ export function drawCues(
ctx.fillRect(x - half, 0, lineW, h)
if (labels) {
// A flag tab at the top for every cue (outlined), with the hotcue number.
// A flag tab at the top for every cue (outlined). A banked cue carries its
// slot label; one without a slot (a memory cue) gets a half-height tab, so
// it still reads as a real object rather than an anonymous line.
const banked = cue.slot != null
const tabH = banked ? flagH : Math.round(flagH / 2)
ctx.fillStyle = 'rgba(0,0,0,0.7)'
ctx.fillRect(x - half - outline, 0, flagW + outline * 2, flagH + outline * 2)
ctx.fillRect(x - half - outline, 0, flagW + outline * 2, tabH + outline * 2)
ctx.fillStyle = color
ctx.fillRect(x - half, 0, flagW, flagH)
if (cue.hotcue >= 0) {
ctx.fillRect(x - half, 0, flagW, tabH)
if (banked) {
ctx.fillStyle = contrastText(color)
ctx.font = `bold ${Math.round(10 * dpr)}px system-ui, sans-serif`
ctx.textBaseline = 'top'
ctx.fillText(String(cue.hotcue + 1), x - half + Math.round(2 * dpr), Math.round(2 * dpr))
ctx.fillText(slotLabel(cue.slot!), x - half + Math.round(2 * dpr), Math.round(2 * dpr))
}
}
}
+10 -10
View File
@@ -12,14 +12,14 @@ export function formatBpm(bpm: number | null): string {
return bpm.toFixed(1)
}
// Traktor stores keys like "10m" / "8d" (Open Key notation) or classic "8A".
// Give each of the 12 pitch classes a stable hue so harmonic groups read at a
// glance — adjacent/compatible keys land near each other on the color wheel.
export function keyColor(key: string | null): string | undefined {
if (!key) return undefined
const m = key.match(/(\d+)/)
if (!m) return undefined
const n = parseInt(m[1], 10) % 12
const hue = (n / 12) * 360
return `hsl(${hue} 65% 62%)`
/**
* Hue by wheel position, so harmonically adjacent keys sit adjacent in colour.
*
* Takes the parsed Camelot position rather than the key string: "10m" vs "Am"
* vs "8A" is platform notation, and parsing it is the adapter's job. Doing it
* here used to mean every non-Traktor key lost its colour.
*/
export function keyColor(wheel: number | null): string | undefined {
if (wheel == null) return undefined
return `hsl(${((wheel % 12) / 12) * 360} 65% 62%)`
}
+41
View File
@@ -0,0 +1,41 @@
/**
* Wording that names the loaded platform.
*
* The adapter supplies structured facts, never finished sentences, and these
* compose them. That keeps the copy (and any future translation) in the UI while
* 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'
export function saveLabel(save: SaveCapabilities): string {
return `Save to ${save.app_name}`
}
/** Shown while there are unsaved changes. Null when the platform has no hazard. */
export function overwriteWarning(save: SaveCapabilities): string | null {
switch (save.overwrite_risk) {
case 'none':
return null
case 'on_exit':
return `Close ${save.app_name} before saving — it overwrites ${save.library_label} on exit.`
case 'while_running':
return `${save.app_name} is open — it may overwrite or re-sync ${save.library_label} while running. Close it before saving.`
}
}
export function restoreWarning(save: SaveCapabilities): string | null {
switch (save.overwrite_risk) {
case 'none':
return null
case 'on_exit':
return `Close ${save.app_name} before restoring — it overwrites ${save.library_label} on exit.`
case 'while_running':
return `${save.app_name} is open — close it before restoring, or it may overwrite ${save.library_label}.`
}
}
/** Trailing hint after an in-memory edit. */
export function writeHint(save: SaveCapabilities): string {
return `Save to ${save.app_name} to write it to disk`
}
+8 -5
View File
@@ -122,12 +122,12 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
)
},
}),
col.accessor('is_stem', {
col.accessor('media_kind', {
id: 'type',
header: 'Type',
size: 64,
cell: (c) =>
c.getValue() ? (
c.getValue() === 'stem' ? (
// Stem file → stacked lines ("burger"), the usual stem glyph.
<span title="Stem file" className="text-accent">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-label="Stem">
@@ -168,7 +168,10 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
return (
<span
className="rounded px-1.5 py-0.5 text-xs font-semibold"
style={{ color: keyColor(k), background: 'color-mix(in srgb, currentColor 14%, transparent)' }}
style={{
color: keyColor(c.row.original.key_wheel),
background: 'color-mix(in srgb, currentColor 14%, transparent)',
}}
>
{k}
</span>
@@ -211,12 +214,12 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
size: 72,
cell: (c) => {
const n = c.getValue()
const markers = c.row.original.grid_markers
const markers = c.row.original.grid_marker_count
// Gold marks a flexible (multi-tempo) grid, mint an ordinary constant one.
return (
<span className="flex items-center gap-1 tabular-nums">
<span className={n > 0 ? 'text-text' : 'text-faint'}>{n}</span>
{c.row.original.has_grid && (
{markers > 0 && (
<span
className={markers > 1 ? 'text-[10px] text-gold' : 'text-[10px] text-mint'}
title={markers > 1 ? `Flexible beatgrid (${markers} markers)` : 'Beatgrid analyzed'}