Made UI improvements

This commit is contained in:
Ben committed 2026-07-04 22:43:00 +02:00
1 parent 2f9b1d59ae
commit d848efaf50
15 files changed
+563 -118

No files matched your search

+9 -1
View File
@@ -45,6 +45,12 @@ export default function App() {
const [menu, setMenu] = useState<{ track: Track; x: number; y: number } | null>(null)
const [editing, setEditing] = useState<Track | null>(null)
const [prepTrack, setPrepTrack] = useState<Track | null>(null)
const [playRequest, setPlayRequest] = useState(0) // bump → deck loads & auto-plays
const playTrack = useCallback((t: Track) => {
setPrepTrack(t)
setPlayRequest((n) => n + 1)
}, [])
const notify = useCallback((kind: ToastMsg['kind'], text: string) => {
setToast({ id: Date.now(), kind, text })
@@ -144,7 +150,7 @@ export default function App() {
)}
{/* Prep strip spans the top of the window; the library sits below it. */}
<PrepStrip track={prepTrack} onError={onError} />
<PrepStrip track={prepTrack} playRequest={playRequest} onError={onError} />
<div className="flex min-h-0 flex-1 overflow-hidden">
<Sidebar source={source} onSelect={selectSource} onError={onError} />
@@ -183,6 +189,8 @@ export default function App() {
allSelected: selected.size > 0 && selected.size === filtered.length,
}}
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
onPlay={playTrack}
activeTrackId={prepTrack?.id ?? null}
/>
)
) : (
+14
View File
@@ -125,6 +125,19 @@ export interface CollectionStatus {
playlists: number | null
}
export interface CollectionCandidate {
path: string
label: string
version: string | null
modified: number | null // epoch seconds
exists: boolean
}
export interface CollectionOptions {
auto: CollectionCandidate | null // best auto-detected (latest Traktor version)
recent: CollectionCandidate | null // last opened (may no longer exist)
}
export interface FsEntry {
name: string
path: string
@@ -183,6 +196,7 @@ export const api = {
collection: () => getJSON<CollectionStatus>('/api/collection'),
openCollection: (path: string) =>
send<CollectionStatus>('POST', '/api/collection/open', { path }),
collectionOptions: () => getJSON<CollectionOptions>('/api/collection/options'),
listDir: (path?: string) =>
getJSON<FsListing>(`/api/fs/list${path ? `?path=${encodeURIComponent(path)}` : ''}`),
+185 -82
View File
@@ -7,13 +7,55 @@ interface Props {
onCancel?: () => void // shown only when switching from an already-loaded collection
}
function formatWhen(sec: number | null): string {
if (!sec) return 'unknown'
return new Date(sec * 1000).toLocaleString(undefined, {
dateStyle: 'medium',
timeStyle: 'short',
})
}
function OptionCard({
icon,
title,
subtitle,
disabled,
busy,
onClick,
}: {
icon: string
title: string
subtitle: string
disabled?: boolean
busy?: boolean
onClick: () => void
}) {
return (
<button
disabled={disabled || busy}
onClick={onClick}
className="flex w-full items-center gap-3 rounded-lg border border-line bg-ink-850 px-4 py-3 text-left transition-colors hover:border-accent hover:bg-ink-800 disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-line disabled:hover:bg-ink-850"
>
<span className="text-xl">{icon}</span>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-text">{title}</div>
<div className="truncate text-xs text-faint">{subtitle}</div>
</div>
<span className="text-faint">›</span>
</button>
)
}
export function CollectionPicker({ onOpened, onCancel }: Props) {
const [mode, setMode] = useState<'choose' | 'browse'>('choose')
const [dir, setDir] = useState<string | undefined>(undefined) // undefined => home
const [manual, setManual] = useState('')
const options = useQuery({ queryKey: ['collectionOptions'], queryFn: api.collectionOptions })
const listing = useQuery({
queryKey: ['fs', dir ?? '~'],
queryFn: () => api.listDir(dir),
enabled: mode === 'browse',
})
const open = useMutation({
@@ -22,23 +64,34 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
})
const data = listing.data
const opt = options.data
const auto = opt?.auto ?? null
const recent = opt?.recent ?? null
const recentAvailable = !!recent && recent.exists
return (
<div className="flex h-screen w-screen items-center justify-center bg-ink-950 p-6">
<div className="flex h-[600px] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl">
{/* Header */}
<div className="flex items-center gap-3 border-b border-line px-5 py-4">
<div className="flex h-8 w-8 items-center justify-center rounded-md bg-accent text-sm font-bold text-ink-950">
K
</div>
<div className="flex-1">
<div className="text-[15px] font-semibold tracking-tight">
Select your Traktor collection
</div>
<div className="text-xs text-muted">
Choose a <span className="text-text">collection.nml</span> file to open.
{mode === 'choose'
? 'Open automatically, resume your last one, or browse.'
: 'Choose a collection.nml file to open.'}
</div>
</div>
{mode === 'browse' && (
<button
onClick={() => setMode('choose')}
className="rounded-md px-2.5 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
‹ Back
</button>
)}
{onCancel && (
<button
onClick={onCancel}
@@ -49,86 +102,136 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
)}
</div>
{/* Path bar */}
<div className="flex items-center gap-2 border-b border-line bg-ink-850 px-4 py-2">
<button
title="Home"
onClick={() => setDir(data?.home)}
className="rounded px-2 py-1 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
⌂
</button>
<button
title="Up one level"
disabled={!data?.parent}
onClick={() => data?.parent && setDir(data.parent)}
className="rounded px-2 py-1 text-sm text-muted hover:bg-ink-800 hover:text-text disabled:cursor-not-allowed disabled:opacity-40"
>
↑
</button>
<span className="truncate font-mono text-xs text-faint" dir="rtl">
{data?.path ?? 'Loading…'}
</span>
</div>
{/* Listing */}
<div className="min-h-0 flex-1 overflow-y-auto p-2">
{listing.isLoading && <div className="p-4 text-sm text-faint">Loading…</div>}
{data && data.dirs.length === 0 && data.files.length === 0 && (
<div className="p-4 text-sm text-faint">No folders or .nml files here.</div>
)}
{data?.dirs.map((d) => (
<button
key={d.path}
onClick={() => setDir(d.path)}
className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm text-muted hover:bg-ink-800 hover:text-text"
>
<span className="text-faint">📁</span>
<span className="truncate">{d.name}</span>
</button>
))}
{data?.files.map((f) => (
<button
key={f.path}
onClick={() => open.mutate(f.path)}
disabled={open.isPending}
className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm text-text hover:bg-accent-soft"
>
<span className="text-accent">♫</span>
<span className="truncate">{f.name}</span>
<span className="ml-auto text-[10px] uppercase tracking-wider text-faint">
open
</span>
</button>
))}
</div>
{/* Manual path + errors */}
<div className="border-t border-line px-4 py-3">
{open.isError && (
<div className="mb-2 rounded-md border border-pink/40 bg-ink-850 px-3 py-2 text-xs text-pink">
{(open.error as Error).message}
</div>
)}
<div className="flex items-center gap-2">
<input
value={manual}
onChange={(e) => setManual(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && manual.trim()) open.mutate(manual.trim())
}}
placeholder="…or paste a full path to collection.nml"
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"
{mode === 'choose' ? (
/* ---- Chooser ---- */
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto p-5">
<OptionCard
icon="✨"
title="Automatic"
subtitle={
auto
? `${auto.label} · modified ${formatWhen(auto.modified)}`
: options.isLoading
? 'Searching for a Traktor collection…'
: 'No Traktor collection found in the default location'
}
disabled={!auto}
busy={open.isPending}
onClick={() => auto && open.mutate(auto.path)}
/>
<button
disabled={!manual.trim() || open.isPending}
onClick={() => open.mutate(manual.trim())}
className="rounded-md bg-accent px-4 py-2 text-sm font-medium text-ink-950 hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-40"
>
{open.isPending ? 'Opening…' : 'Open'}
</button>
<OptionCard
icon="🕘"
title="Open last collection"
subtitle={
recent
? recent.exists
? recent.path
: `${recent.path} · no longer exists`
: 'No previously opened collection'
}
disabled={!recentAvailable}
busy={open.isPending}
onClick={() => recent && open.mutate(recent.path)}
/>
<OptionCard
icon="📂"
title="Find collection manually"
subtitle="Browse for a collection.nml file"
busy={open.isPending}
onClick={() => setMode('browse')}
/>
{open.isError && (
<div className="rounded-md border border-pink/40 bg-ink-850 px-3 py-2 text-xs text-pink">
{(open.error as Error).message}
</div>
)}
</div>
</div>
) : (
/* ---- Manual browser ---- */
<>
{/* Path bar */}
<div className="flex items-center gap-2 border-b border-line bg-ink-850 px-4 py-2">
<button
title="Home"
onClick={() => setDir(data?.home)}
className="rounded px-2 py-1 text-sm text-muted hover:bg-ink-800 hover:text-text"
>
⌂
</button>
<button
title="Up one level"
disabled={!data?.parent}
onClick={() => data?.parent && setDir(data.parent)}
className="rounded px-2 py-1 text-sm text-muted hover:bg-ink-800 hover:text-text disabled:cursor-not-allowed disabled:opacity-40"
>
↑
</button>
<span className="truncate font-mono text-xs text-faint" dir="rtl">
{data?.path ?? 'Loading…'}
</span>
</div>
{/* Listing */}
<div className="min-h-0 flex-1 overflow-y-auto p-2">
{listing.isLoading && <div className="p-4 text-sm text-faint">Loading…</div>}
{data && data.dirs.length === 0 && data.files.length === 0 && (
<div className="p-4 text-sm text-faint">No folders or .nml files here.</div>
)}
{data?.dirs.map((d) => (
<button
key={d.path}
onClick={() => setDir(d.path)}
className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm text-muted hover:bg-ink-800 hover:text-text"
>
<span className="text-faint">📁</span>
<span className="truncate">{d.name}</span>
</button>
))}
{data?.files.map((f) => (
<button
key={f.path}
onClick={() => open.mutate(f.path)}
disabled={open.isPending}
className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm text-text hover:bg-accent-soft"
>
<span className="text-accent">♫</span>
<span className="truncate">{f.name}</span>
<span className="ml-auto text-[10px] uppercase tracking-wider text-faint">
open
</span>
</button>
))}
</div>
{/* Manual path + errors */}
<div className="border-t border-line px-4 py-3">
{open.isError && (
<div className="mb-2 rounded-md border border-pink/40 bg-ink-850 px-3 py-2 text-xs text-pink">
{(open.error as Error).message}
</div>
)}
<div className="flex items-center gap-2">
<input
value={manual}
onChange={(e) => setManual(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && manual.trim()) open.mutate(manual.trim())
}}
placeholder="…or paste a full path to collection.nml"
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
disabled={!manual.trim() || open.isPending}
onClick={() => open.mutate(manual.trim())}
className="rounded-md bg-accent px-4 py-2 text-sm font-medium text-ink-950 hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-40"
>
{open.isPending ? 'Opening…' : 'Open'}
</button>
</div>
</div>
</>
)}
</div>
</div>
)
+32 -5
View File
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react'
import type { CuePoint } from '../api'
import { drawBeatgrid, drawCues, drawLoop } from '../lib/cues'
import { drawBeatgrid, drawCuePoint, drawCues, drawLoop } from '../lib/cues'
import { paintWave, type WaveColumn } from '../lib/waveform'
interface Props {
@@ -8,6 +8,7 @@ interface Props {
currentTime: number
duration: number
cues: CuePoint[]
cuePoint: number | null
bpm: number | null
gridAnchor: number | null
loop: { start: number; end: number } | null
@@ -34,6 +35,7 @@ export function MainWaveform({
currentTime,
duration,
cues,
cuePoint,
bpm,
gridAnchor,
loop,
@@ -83,12 +85,37 @@ export function MainWaveform({
if (cues.length) {
drawCues(ctx, cues, w, h, dpr, timeToX, true)
}
if (cuePoint != null && cuePoint >= startSec && cuePoint <= endSec) {
drawCuePoint(ctx, Math.round(timeToX(cuePoint)), h, dpr)
}
}
// Fixed centre playhead.
const pw = Math.max(2, Math.round(2 * dpr))
ctx.fillStyle = '#e6e9ef'
ctx.fillRect(Math.floor(w / 2) - Math.floor(pw / 2), 0, pw, h)
// Fixed centre playhead — red core with a translucent black outline so it
// separates from the waveform, plus inward-pointing triangle caps top and
// bottom that anchor the eye in the quiet margins.
const core = Math.max(2, Math.round(2 * dpr))
const edge = Math.max(1, Math.round(dpr))
const cx = Math.floor(w / 2)
const px = cx - Math.floor(core / 2)
ctx.fillStyle = 'rgba(0,0,0,0.5)'
ctx.fillRect(px - edge, 0, core + edge * 2, h)
ctx.fillStyle = '#ff3b30'
ctx.fillRect(px, 0, core, h)
const cap = Math.round(6 * dpr)
ctx.fillStyle = '#ff3b30'
ctx.beginPath()
ctx.moveTo(cx - cap, 0)
ctx.lineTo(cx + cap, 0)
ctx.lineTo(cx, cap)
ctx.closePath()
ctx.fill()
ctx.beginPath()
ctx.moveTo(cx - cap, h)
ctx.lineTo(cx + cap, h)
ctx.lineTo(cx, h - cap)
ctx.closePath()
ctx.fill()
}
const drawRef = useRef(draw)
+23 -6
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useRef } from 'react'
import type { CuePoint } from '../api'
import { drawCues, drawLoop } from '../lib/cues'
import { drawCuePoint, drawCues, drawLoop } from '../lib/cues'
import { paintWave, type WaveColumn } from '../lib/waveform'
interface Props {
@@ -8,6 +8,7 @@ interface Props {
currentTime: number
duration: number
cues: CuePoint[]
cuePoint: number | null
loop: { start: number; end: number } | null
onSeek: (t: number) => void
}
@@ -17,13 +18,22 @@ interface Props {
* offscreen canvas) with a moving playhead + dimmed played region. Click to
* seek anywhere in the track.
*/
export function OverviewWaveform({ cols, currentTime, duration, cues, loop, onSeek }: Props) {
export function OverviewWaveform({
cols,
currentTime,
duration,
cues,
cuePoint,
loop,
onSeek,
}: Props) {
const wrapRef = useRef<HTMLDivElement>(null)
const canvasRef = useRef<HTMLCanvasElement>(null)
const cacheRef = useRef<HTMLCanvasElement | null>(null)
const timeRef = useRef(0)
const durRef = useRef(0)
const cuesRef = useRef<CuePoint[]>(cues)
const cuePointRef = useRef<number | null>(cuePoint)
const loopRef = useRef(loop)
const renderCache = useCallback(() => {
@@ -60,9 +70,15 @@ export function OverviewWaveform({ cols, currentTime, duration, cues, loop, onSe
if (lp) drawLoop(ctx, (lp.start / dur) * w, (lp.end / dur) * w, h, dpr)
// Cue markers (no beatgrid/labels in the overview).
drawCues(ctx, cuesRef.current, w, h, dpr, (t) => (t / dur) * w, false)
const cp = cuePointRef.current
if (cp != null) drawCuePoint(ctx, Math.round((cp / dur) * w), h, dpr)
const pw = Math.max(2, Math.round(2 * dpr))
ctx.fillStyle = '#e6e9ef'
ctx.fillRect(px - Math.floor(pw / 2), 0, pw, h)
const px0 = px - Math.floor(pw / 2)
const po = Math.max(1, Math.round(dpr))
ctx.fillStyle = 'rgba(0,0,0,0.6)'
ctx.fillRect(px0 - po, 0, pw + po * 2, h)
ctx.fillStyle = '#ff3b30'
ctx.fillRect(px0, 0, pw, h)
}
}, [])
@@ -97,12 +113,13 @@ export function OverviewWaveform({ cols, currentTime, duration, cues, loop, onSe
draw()
}, [currentTime, duration, draw])
// Redraw when the cue set or loop changes.
// Redraw when the cue set, cue point, or loop changes.
useEffect(() => {
cuesRef.current = cues
cuePointRef.current = cuePoint
loopRef.current = loop
draw()
}, [cues, loop, draw])
}, [cues, cuePoint, loop, draw])
const seek = (e: React.MouseEvent<HTMLDivElement>) => {
if (!duration) return
+79 -5
View File
@@ -13,6 +13,8 @@ import { OverviewWaveform } from './OverviewWaveform'
interface Props {
/** The track currently loaded into the prep deck, if any. */
track: Track | null
/** Bumped by the library's per-row play button to load + auto-play. */
playRequest?: number
onError?: (msg: string) => void
}
@@ -39,7 +41,7 @@ const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
* Web Audio PlaybackEngine (seamless loops); the same decoded buffer feeds the
* scratch engine and both waveform views.
*/
export function PrepStrip({ track, onError }: Props) {
export function PrepStrip({ track, playRequest = 0, onError }: Props) {
const qc = useQueryClient()
const [playing, setPlaying] = useState(false)
const [current, setCurrent] = useState(0)
@@ -50,6 +52,7 @@ export function PrepStrip({ track, onError }: Props) {
const [cueData, setCueData] = useState<TrackCues | null>(null)
const [snap, setSnap] = useState(true)
const [selectedSlot, setSelectedSlot] = useState<number | null>(null)
const [cuePoint, setCuePoint] = useState(0) // floating "CUE" point (frontend-only)
// Loop state (transient — persisted only when saved as a hotcue later).
const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null)
@@ -65,6 +68,8 @@ export function PrepStrip({ track, onError }: Props) {
const wasPlayingRef = useRef(false)
const scratchRafRef = useRef(0)
const engagedRef = useRef(false) // scratch engine is dragging or coasting
const pendingPlayRef = useRef(false) // a play was requested; start once ready
const loadedIdRef = useRef<string | null>(null) // trackId whose buffer is loaded
const trackId = track?.id ?? null
@@ -100,6 +105,7 @@ export function PrepStrip({ track, onError }: Props) {
setLoopRegion(null)
setLoopActive(false)
setActiveBeats(null)
setCuePoint(0)
loopInRef.current = null
}, [trackId])
@@ -133,6 +139,13 @@ export function PrepStrip({ track, onError }: Props) {
playbackRef.current.load(ctx, res.buffer)
setDuration(res.buffer.duration)
setReady(true)
loadedIdRef.current = trackId
// A play was requested (library row button) → start now that it's ready.
if (pendingPlayRef.current) {
pendingPlayRef.current = false
playbackRef.current.play()
setPlaying(true)
}
})
.catch(() => {
if (!cancelled) setWaveStatus('error')
@@ -180,6 +193,43 @@ export function PrepStrip({ track, onError }: Props) {
setCurrent(eng.getPosition())
}
// CUE (Traktor/CDJ-style): while playing, jump back to the cue point and
// pause; while paused and away from the cue, drop the cue at the playhead;
// while paused and already at the cue, play from it.
const handleCue = () => {
const eng = playbackRef.current
if (!eng || !eng.ready) return
getCtx()
if (eng.playing) {
eng.pause()
eng.seek(cuePoint)
setPlaying(false)
setCurrent(cuePoint)
} else if (Math.abs(current - cuePoint) > 0.03) {
setCuePoint(current)
} else {
eng.play()
setPlaying(true)
}
}
// A library row's play button bumps `playRequest`: load (if needed) + play.
// If the requested track is already loaded and ready, start immediately;
// otherwise flag it and the analysis effect starts playback once ready.
useEffect(() => {
if (playRequest === 0) return
pendingPlayRef.current = true
const eng = playbackRef.current
if (loadedIdRef.current === trackId && eng?.ready) {
pendingPlayRef.current = false
getCtx()
eng.play()
setPlaying(true)
setCurrent(eng.getPosition())
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [playRequest])
// Follow the Web Audio clock while playing (high-res → smooth playhead).
useEffect(() => {
if (!playing) return
@@ -494,16 +544,38 @@ export function PrepStrip({ track, onError }: Props) {
/>
)}
<div className="mt-auto flex items-center gap-3">
<div className="mt-auto flex items-center gap-2">
<button
onClick={handleCue}
disabled={!ready}
className="flex h-11 items-center justify-center rounded-xl border border-line bg-ink-850 px-4 text-sm font-bold tracking-wide text-gold transition-colors hover:border-gold disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-line"
title="Cue — set the cue point (paused) or jump back to it (playing)"
>
CUE
</button>
<button
onClick={toggle}
disabled={!ready}
className="flex h-9 w-9 items-center justify-center rounded-full border border-line bg-ink-850 text-text hover:border-accent disabled:opacity-40 disabled:hover:border-line"
className={
'flex h-11 w-11 items-center justify-center rounded-xl transition-all active:scale-95 disabled:cursor-not-allowed disabled:opacity-40 ' +
(playing
? 'bg-mint text-ink-950 shadow-lg shadow-mint/20 hover:brightness-110'
: 'border border-line bg-ink-850 text-text hover:border-accent disabled:hover:border-line')
}
title={playing ? 'Pause' : 'Play'}
>
{playing ? '❚❚' : '▶'}
{playing ? (
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</svg>
) : (
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<path d="M8 5.14v13.72a1 1 0 0 0 1.54.84l10.29-6.86a1 1 0 0 0 0-1.68L9.54 4.3A1 1 0 0 0 8 5.14z" />
</svg>
)}
</button>
<div className="tabular-nums text-xs text-faint">
<div className="tabular-nums text-lg font-medium text-muted">
{fmt(current)} / {fmt(duration)}
</div>
</div>
@@ -528,6 +600,7 @@ export function PrepStrip({ track, onError }: Props) {
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
bpm={cueData?.bpm ?? null}
gridAnchor={cueData?.grid_anchor ?? null}
loop={activeLoop}
@@ -549,6 +622,7 @@ export function PrepStrip({ track, onError }: Props) {
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
loop={activeLoop}
onSeek={seekManual}
/>
+1 -8
View File
@@ -184,14 +184,7 @@ export function Sidebar({ source, onSelect, onError }: Props) {
return (
<aside className="flex h-full w-64 shrink-0 flex-col border-r border-line bg-ink-900">
<div className="flex items-center gap-2 px-4 py-4">
<div className="flex h-7 w-7 items-center justify-center rounded-md bg-accent text-sm font-bold text-ink-950">
K
</div>
<div className="text-[15px] font-semibold tracking-tight">konduktor</div>
</div>
<div className="px-2">
<div className="px-2 pt-3">
<button
onClick={() => onSelect({ kind: 'all' })}
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors ${
+34 -2
View File
@@ -109,9 +109,19 @@ interface Props {
onSortingChange: (s: SortingState) => void
selection?: Selection
onRowContextMenu?: (track: Track, x: number, y: number) => void
onPlay?: (track: Track) => void
activeTrackId?: string | null
}
export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowContextMenu }: Props) {
export function TrackTable({
tracks,
sorting,
onSortingChange,
selection,
onRowContextMenu,
onPlay,
activeTrackId,
}: Props) {
const table = useReactTable({
data: tracks,
columns,
@@ -157,6 +167,7 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
) : (
<span className="w-10 shrink-0" />
)}
{onPlay && <span className="w-9 shrink-0" />}
{table.getHeaderGroups()[0].headers.map((header) => {
const sorted = header.column.getIsSorted()
return (
@@ -180,10 +191,11 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
{virtualRows.map((vr) => {
const row = rows[vr.index]
const isSelected = selection?.selected.has(row.original.id) ?? false
const isActive = activeTrackId === row.original.id
return (
<div
key={row.id}
className={`absolute left-0 flex items-center border-b border-ink-850 text-sm ${
className={`group absolute left-0 flex items-center border-b border-ink-850 text-sm ${
isSelected ? 'bg-accent-soft/50' : 'hover:bg-ink-850'
}`}
style={{
@@ -212,6 +224,26 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
{vr.index + 1}
</span>
)}
{onPlay && (
<span className="flex w-9 shrink-0 items-center justify-center">
<button
onClick={(e) => {
e.stopPropagation()
onPlay(row.original)
}}
className={`flex h-6 w-6 items-center justify-center rounded-full transition-colors hover:bg-accent hover:text-ink-950 ${
isActive
? 'text-accent opacity-100'
: 'text-faint opacity-0 group-hover:opacity-100'
}`}
title="Play in deck"
>
<svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<path d="M8 5.14v13.72a1 1 0 0 0 1.54.84l10.29-6.86a1 1 0 0 0 0-1.68L9.54 4.3A1 1 0 0 0 8 5.14z" />
</svg>
</button>
</span>
)}
{row.getVisibleCells().map((cell) => (
<div
key={cell.id}
+27
View File
@@ -86,6 +86,33 @@ export function drawCues(
}
}
/**
* Draw the floating "CUE" point: a gold vertical line with a dark outline and a
* solid downward triangle tab at the top, distinct from numbered hotcue flags,
* the white beatgrid, and the red playhead.
*/
export function drawCuePoint(
ctx: CanvasRenderingContext2D,
x: number,
h: number,
dpr: number,
): void {
const lw = Math.max(2, Math.round(2 * dpr))
const half = Math.floor(lw / 2)
const outline = Math.max(1, Math.round(dpr))
const tab = Math.round(8 * dpr)
ctx.fillStyle = 'rgba(0,0,0,0.6)'
ctx.fillRect(x - half - outline, 0, lw + outline * 2, h)
ctx.fillStyle = '#ffb020'
ctx.fillRect(x - half, 0, lw, h)
ctx.beginPath()
ctx.moveTo(x - tab, 0)
ctx.lineTo(x + tab, 0)
ctx.lineTo(x, tab)
ctx.closePath()
ctx.fill()
}
/** Draw the active loop region: a translucent green band with bright edges. */
export function drawLoop(
ctx: CanvasRenderingContext2D,
+24 -9
View File
@@ -3,12 +3,15 @@
// The audio is downmixed to mono and split into three frequency bands with
// native BiquadFilters (via OfflineAudioContext — fast, off the main thread).
// Per output column we keep each band's RMS energy plus the amplitude peak.
// Colour = balance of the three bands (bass→red, mids→green, highs→blue);
// height = amplitude. This mirrors how Traktor's Spectrum waveform reads.
// Each band is mapped to a target colour on Traktor's warm→cool ramp
// (bass→orange, mids→violet, highs→cyan) and the three are blended by energy;
// height = amplitude. Traktor's palette has NO green — mapping bands straight
// to R/G/B (the naive approach) produces yellows/greens it never shows, so we
// blend named palette colours instead. Tune the three constants below.
export interface WaveColumn {
peak: number // 0..1 amplitude (column height)
r: number // 0..1 colour channels (already contrast-boosted)
r: number // 0..1 final blended colour (already contrast-boosted)
g: number
b: number
}
@@ -20,6 +23,11 @@ const MID_HZ = 1200
const MID_Q = 0.6
const HIGH_HZ = 5000
// Target colour per band on Traktor's ramp (0..1 RGB). Blended by band energy.
const LOW_COL = [1.0, 0.30, 0.15] // bass → orange-red
const MID_COL = [0.65, 0.18, 0.95] // mids → violet / magenta
const HIGH_COL = [0.15, 0.65, 1.0] // highs → cyan-blue
/**
* Paint a slice of the analysed columns across a canvas: source columns in the
* fractional range [startFrac, endFrac) (of the whole track) are mapped across
@@ -167,12 +175,19 @@ export async function analyzeWaveform(url: string, buckets?: number): Promise<Wa
// tied to loudness — amplitude is shown by height, like Traktor). Gamma
// sharpens the separation between bands.
const mx = Math.max(l, m, h, 1e-9)
cols[b] = {
peak: peak[b] / maxPeak,
r: Math.pow(l / mx, 1.3),
g: Math.pow(m / mx, 1.3),
b: Math.pow(h / mx, 1.3),
}
const wl = Math.pow(l / mx, 1.3)
const wm = Math.pow(m / mx, 1.3)
const wh = Math.pow(h / mx, 1.3)
// Blend the three band palette colours by weight, then normalise to the
// brightest channel so the colour stays vivid (height carries loudness).
let cr = wl * LOW_COL[0] + wm * MID_COL[0] + wh * HIGH_COL[0]
let cg = wl * LOW_COL[1] + wm * MID_COL[1] + wh * HIGH_COL[1]
let cb = wl * LOW_COL[2] + wm * MID_COL[2] + wh * HIGH_COL[2]
const cmax = Math.max(cr, cg, cb, 1e-9)
cr /= cmax
cg /= cmax
cb /= cmax
cols[b] = { peak: peak[b] / maxPeak, r: cr, g: cg, b: cb }
}
return { cols, buffer: audio }
}