Implemented cross-platform track color support

This commit is contained in:
patben8 committed 2026-10-17 19:50:56 +02:00
1 parent 0605dbabe6
commit 06361a851f
38 files changed
+547 -34

No files matched your search

+34
View File
@@ -226,6 +226,21 @@ export default function App() {
[qc, notify, onError, writeHintText],
)
// The context menu's Colour ▸ — swatches are this library's own (by hex in
// the menu, sent as the neutral colour name), applied to the whole selection.
const trackColors = capabilities.data?.tracks.colors ?? []
const setTrackColor = (ids: string[], hex: string | null) => {
const swatch = trackColors.find((s) => s.hex === hex) ?? null
api
.setTrackColor(ids, swatch?.color ?? null)
.then(() => {
invalidateTrackLists(qc)
const what = swatch ? `Colour set to ${swatch.label}` : 'Colour cleared'
notify('success', `${what}${ids.length > 1 ? ` on ${ids.length} tracks` : ''} — ${writeHintText}`)
})
.catch((e) => onError((e as Error).message))
}
// 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;
@@ -1214,6 +1229,25 @@ export default function App() {
...(canEdit && !viewingDevice && menu.ids.length === 1
? [{ label: 'Edit Tags…', onClick: gated(() => setEditing(menu.track)) }]
: []),
...(canEdit && !viewingDevice && trackColors.length
? [
{
label: 'Colour',
submenu: [
{
swatches: trackColors.map((s) => s.hex),
labels: trackColors.map((s) => s.label),
noneLabel: 'No Color',
// A multi-selection may hold several colours, so none
// is marked ('' matches no swatch and is not "none").
selected: menu.ids.length === 1 ? menu.track.color_hex : '',
onPick: (hex: string | null) =>
menuLoose.length ? void askToAdd(menuLoose) : setTrackColor(menu.ids, hex),
},
],
},
]
: []),
...(canAnalyze
? [
{
+20
View File
@@ -39,6 +39,10 @@ export interface Track {
grid_marker_count: number
grid_locked: boolean
media_kind: MediaKind
/** The track's colour tag — the platform-neutral identity — and the
* library's own display colour for it; both null when uncoloured. */
color: TrackColor | null
color_hex: string | null
}
/** One occupied hotcue slot, as the library table previews it. */
@@ -117,6 +121,15 @@ 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'
/** A track colour tag; each library maps its own palette onto these by name. */
export type TrackColor = 'pink' | 'red' | 'orange' | 'yellow' | 'green' | 'aqua' | 'blue' | 'purple'
/** One track colour a library offers, in its own menu order. */
export interface ColorSwatch {
color: TrackColor
hex: string
/** The platform's own name for it ("Violet" in Traktor). */
label: string
}
export type PlaylistKind = 'folder' | 'playlist' | 'smart'
export type TrackField =
| 'title' | 'artist' | 'album' | 'genre' | 'label' | 'remixer'
@@ -279,6 +292,8 @@ export interface Capabilities {
audio_destination: 'host' | 'library'
/** Added files can be left where they are rather than copied. */
reference: boolean
/** The track colours this library can store; empty = no track colour. */
colors: ColorSwatch[]
}
playlists: {
folders: boolean
@@ -1072,6 +1087,11 @@ export const api = {
editTrack: (trackId: string, fields: Record<string, string | number | null>) =>
send<{ status: string }>('PATCH', '/api/tracks', { track_id: trackId, fields }),
setTrackColor: (trackIds: string[], color: TrackColor | null) =>
send<{ status: string; tracks: Track[] }>('PATCH', '/api/tracks/color', {
track_ids: trackIds,
color,
}),
artUrl: (trackId: string) =>
`${API_BASE}/api/tracks/art?track_id=${encodeURIComponent(trackId)}`,
audioUrl: (trackId: string) =>
+8 -4
View File
@@ -19,6 +19,10 @@ export type MenuItem =
selected: string | null
onPick: (color: string | null) => void
disabled?: boolean
/** Names for the swatches (tooltips), else the hex is shown. */
labels?: string[]
/** The uncoloured choice's wording; "Default" when omitted. */
noneLabel?: string
}
| { separator: true }
@@ -259,13 +263,13 @@ function SwatchGrid({
return (
<div className="px-3 pb-2 pt-1" onMouseEnter={onEnter}>
<div className="grid w-max grid-cols-8 gap-1.5">
{item.swatches.map((color) => (
{item.swatches.map((color, i) => (
<button
key={color}
role="menuitemradio"
aria-checked={selected === color.toUpperCase()}
aria-label={color}
title={color}
aria-label={item.labels?.[i] ?? color}
title={item.labels?.[i] ?? color}
disabled={item.disabled}
onClick={() => pick(color)}
className={`h-4 w-4 rounded-full transition-transform disabled:cursor-default disabled:opacity-40 ${ring(
@@ -289,7 +293,7 @@ function SwatchGrid({
selected === null ? 'outline outline-2 outline-offset-1 outline-white' : ''
}`}
/>
Default
{item.noneLabel ?? 'Default'}
</button>
</div>
)
+10 -5
View File
@@ -169,10 +169,14 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
id: 'type',
header: 'Type',
size: 64,
cell: (c) =>
c.getValue() === 'stem' ? (
// The icon takes the track's colour tag, when it has one; otherwise both
// glyphs are neutral, so colour in this column only ever means the tag.
cell: (c) => {
const color = c.row.original.color_hex
const tint = color ? undefined : 'text-faint'
return c.getValue() === 'stem' ? (
// Stem file → stacked lines ("burger"), the usual stem glyph.
<span title="Stem file" className="text-accent">
<span title="Stem file" className={tint} style={color ? { color } : undefined}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-label="Stem">
<rect x="3" y="6" width="18" height="2.4" rx="1.2" />
<rect x="3" y="10.8" width="18" height="2.4" rx="1.2" />
@@ -181,12 +185,13 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
</span>
) : (
// Normal audio track → music note.
<span title="Audio track" className="text-faint">
<span title="Audio track" className={tint} style={color ? { color } : undefined}>
<svg width="15" height="15" viewBox="0 0 24 24" fill="currentColor" aria-label="Audio">
<path d="M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6z" />
</svg>
</span>
),
)
},
}),
col.accessor('album', { id: 'album', header: 'Album', size: 180, cell: editable('album') }),
col.accessor('genre', { id: 'genre', header: 'Genre', size: 140, cell: editable('genre') }),