mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Made UI improvements
This commit is contained in:
1 parent
2f9b1d59ae
commit
d848efaf50
15 files changed
+563
-118
No files matched your search
@@ -35,3 +35,6 @@ Thumbs.db
|
|||||||
*.log
|
*.log
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
|
|
||||||
|
# Local user preferences (not shared)
|
||||||
|
backend/userprefs.json
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
"""Locate Traktor collections in their default install locations.
|
||||||
|
|
||||||
|
Traktor stores each version's data under a versioned folder:
|
||||||
|
~/Documents/Native Instruments/Traktor <version>/collection.nml
|
||||||
|
This is the same relative path on macOS and Windows (both under the user's
|
||||||
|
Documents folder), so a single glob covers both.
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
_VERSION_RE = re.compile(r"(\d+(?:\.\d+)*)")
|
||||||
|
|
||||||
|
|
||||||
|
def _traktor_root() -> Path:
|
||||||
|
return Path.home() / "Documents" / "Native Instruments"
|
||||||
|
|
||||||
|
|
||||||
|
def _version_key(version: str | None) -> tuple[int, ...]:
|
||||||
|
"""Sortable tuple for a dotted version string; missing/odd → lowest."""
|
||||||
|
if not version:
|
||||||
|
return (0,)
|
||||||
|
try:
|
||||||
|
return tuple(int(p) for p in version.split("."))
|
||||||
|
except ValueError:
|
||||||
|
return (0,)
|
||||||
|
|
||||||
|
|
||||||
|
def describe(path: Path) -> dict:
|
||||||
|
"""Build a candidate record for a collection.nml path. The label/version
|
||||||
|
come from the parent folder name (e.g. 'Traktor 4.5.0')."""
|
||||||
|
parent = path.parent.name
|
||||||
|
m = _VERSION_RE.search(parent)
|
||||||
|
exists = path.is_file()
|
||||||
|
return {
|
||||||
|
"path": str(path),
|
||||||
|
"label": parent or path.name,
|
||||||
|
"version": m.group(1) if m else None,
|
||||||
|
"modified": (path.stat().st_mtime if exists else None),
|
||||||
|
"exists": exists,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def detect_collections() -> list[dict]:
|
||||||
|
"""All Traktor collection.nml files found in default locations, newest
|
||||||
|
Traktor version first (then most-recently-modified)."""
|
||||||
|
root = _traktor_root()
|
||||||
|
found: list[dict] = []
|
||||||
|
if not root.is_dir():
|
||||||
|
return found
|
||||||
|
for d in sorted(root.iterdir()):
|
||||||
|
if not d.is_dir() or not d.name.lower().startswith("traktor"):
|
||||||
|
continue
|
||||||
|
nml = d / "collection.nml"
|
||||||
|
if nml.is_file():
|
||||||
|
found.append(describe(nml))
|
||||||
|
found.sort(
|
||||||
|
key=lambda c: (_version_key(c["version"]), c["modified"] or 0.0),
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
|
return found
|
||||||
@@ -13,9 +13,13 @@ from fastapi import FastAPI, File, Form, HTTPException, Query, Response, UploadF
|
|||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
|
||||||
|
from . import prefs
|
||||||
from .collection_service import CollectionService
|
from .collection_service import CollectionService
|
||||||
|
from .discovery import describe, detect_collections
|
||||||
from .playlist_store import PlaylistError, PlaylistStore
|
from .playlist_store import PlaylistError, PlaylistStore
|
||||||
from .schemas import (
|
from .schemas import (
|
||||||
|
CollectionCandidate,
|
||||||
|
CollectionOptions,
|
||||||
CollectionStatus,
|
CollectionStatus,
|
||||||
CreatePlaylist,
|
CreatePlaylist,
|
||||||
CuePoint,
|
CuePoint,
|
||||||
@@ -121,9 +125,23 @@ def open_collection(body: OpenCollection) -> CollectionStatus:
|
|||||||
raise HTTPException(400, f"Not a valid Traktor collection: {ex}")
|
raise HTTPException(400, f"Not a valid Traktor collection: {ex}")
|
||||||
except Exception as ex: # noqa: BLE001
|
except Exception as ex: # noqa: BLE001
|
||||||
raise HTTPException(400, f"Could not parse as a Traktor collection: {ex}")
|
raise HTTPException(400, f"Could not parse as a Traktor collection: {ex}")
|
||||||
|
prefs.set_last_collection(str(path))
|
||||||
return collection_status()
|
return collection_status()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/collection/options", response_model=CollectionOptions)
|
||||||
|
def collection_options() -> CollectionOptions:
|
||||||
|
"""Startup shortcuts for the picker: the best auto-detected Traktor
|
||||||
|
collection and the last one opened (may no longer exist → exists=False)."""
|
||||||
|
detected = detect_collections()
|
||||||
|
auto = CollectionCandidate(**detected[0]) if detected else None
|
||||||
|
recent = None
|
||||||
|
last = prefs.get_last_collection()
|
||||||
|
if last:
|
||||||
|
recent = CollectionCandidate(**describe(Path(last)))
|
||||||
|
return CollectionOptions(auto=auto, recent=recent)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/fs/list", response_model=FsListing)
|
@app.get("/api/fs/list", response_model=FsListing)
|
||||||
def fs_list(path: str | None = None) -> FsListing:
|
def fs_list(path: str | None = None) -> FsListing:
|
||||||
"""List directories and .nml files for the in-app file browser."""
|
"""List directories and .nml files for the in-app file browser."""
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
"""Tiny persisted user-preferences store.
|
||||||
|
|
||||||
|
Kept as a self-contained JSON file that travels with the app (resolved relative
|
||||||
|
to this package, not a per-OS config dir) so it works the same on every platform
|
||||||
|
and when the app is moved. Best-effort: any I/O error degrades to "no prefs".
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# backend/userprefs.json — one level up from the package (konduktor/).
|
||||||
|
_PREFS_PATH = Path(__file__).resolve().parent.parent / "userprefs.json"
|
||||||
|
|
||||||
|
|
||||||
|
def load_prefs() -> dict:
|
||||||
|
try:
|
||||||
|
data = json.loads(_PREFS_PATH.read_text())
|
||||||
|
return data if isinstance(data, dict) else {}
|
||||||
|
except (OSError, ValueError):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def save_prefs(prefs: dict) -> None:
|
||||||
|
try:
|
||||||
|
_PREFS_PATH.write_text(json.dumps(prefs, indent=2))
|
||||||
|
except OSError:
|
||||||
|
pass # non-fatal — prefs are a convenience, not a requirement
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_collection() -> str | None:
|
||||||
|
val = load_prefs().get("last_collection")
|
||||||
|
return val if isinstance(val, str) else None
|
||||||
|
|
||||||
|
|
||||||
|
def set_last_collection(path: str) -> None:
|
||||||
|
prefs = load_prefs()
|
||||||
|
prefs["last_collection"] = path
|
||||||
|
save_prefs(prefs)
|
||||||
@@ -178,6 +178,19 @@ class OpenCollection(BaseModel):
|
|||||||
path: str
|
path: str
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionCandidate(BaseModel):
|
||||||
|
path: str
|
||||||
|
label: str # folder name, e.g. "Traktor 4.5.0"
|
||||||
|
version: str | None = None # "4.5.0"
|
||||||
|
modified: float | None = None # collection.nml mtime, epoch seconds
|
||||||
|
exists: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionOptions(BaseModel):
|
||||||
|
auto: CollectionCandidate | None = None # best auto-detected (latest version)
|
||||||
|
recent: CollectionCandidate | None = None # last opened (from userprefs)
|
||||||
|
|
||||||
|
|
||||||
class FsEntry(BaseModel):
|
class FsEntry(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
path: str
|
path: str
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ export default function App() {
|
|||||||
const [menu, setMenu] = useState<{ track: Track; x: number; y: number } | null>(null)
|
const [menu, setMenu] = useState<{ track: Track; x: number; y: number } | null>(null)
|
||||||
const [editing, setEditing] = useState<Track | null>(null)
|
const [editing, setEditing] = useState<Track | null>(null)
|
||||||
const [prepTrack, setPrepTrack] = 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) => {
|
const notify = useCallback((kind: ToastMsg['kind'], text: string) => {
|
||||||
setToast({ id: Date.now(), kind, text })
|
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. */}
|
{/* 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">
|
<div className="flex min-h-0 flex-1 overflow-hidden">
|
||||||
<Sidebar source={source} onSelect={selectSource} onError={onError} />
|
<Sidebar source={source} onSelect={selectSource} onError={onError} />
|
||||||
@@ -183,6 +189,8 @@ export default function App() {
|
|||||||
allSelected: selected.size > 0 && selected.size === filtered.length,
|
allSelected: selected.size > 0 && selected.size === filtered.length,
|
||||||
}}
|
}}
|
||||||
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
onRowContextMenu={(track, x, y) => setMenu({ track, x, y })}
|
||||||
|
onPlay={playTrack}
|
||||||
|
activeTrackId={prepTrack?.id ?? null}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -125,6 +125,19 @@ export interface CollectionStatus {
|
|||||||
playlists: number | null
|
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 {
|
export interface FsEntry {
|
||||||
name: string
|
name: string
|
||||||
path: string
|
path: string
|
||||||
@@ -183,6 +196,7 @@ export const api = {
|
|||||||
collection: () => getJSON<CollectionStatus>('/api/collection'),
|
collection: () => getJSON<CollectionStatus>('/api/collection'),
|
||||||
openCollection: (path: string) =>
|
openCollection: (path: string) =>
|
||||||
send<CollectionStatus>('POST', '/api/collection/open', { path }),
|
send<CollectionStatus>('POST', '/api/collection/open', { path }),
|
||||||
|
collectionOptions: () => getJSON<CollectionOptions>('/api/collection/options'),
|
||||||
listDir: (path?: string) =>
|
listDir: (path?: string) =>
|
||||||
getJSON<FsListing>(`/api/fs/list${path ? `?path=${encodeURIComponent(path)}` : ''}`),
|
getJSON<FsListing>(`/api/fs/list${path ? `?path=${encodeURIComponent(path)}` : ''}`),
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,55 @@ interface Props {
|
|||||||
onCancel?: () => void // shown only when switching from an already-loaded collection
|
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) {
|
export function CollectionPicker({ onOpened, onCancel }: Props) {
|
||||||
|
const [mode, setMode] = useState<'choose' | 'browse'>('choose')
|
||||||
const [dir, setDir] = useState<string | undefined>(undefined) // undefined => home
|
const [dir, setDir] = useState<string | undefined>(undefined) // undefined => home
|
||||||
const [manual, setManual] = useState('')
|
const [manual, setManual] = useState('')
|
||||||
|
|
||||||
|
const options = useQuery({ queryKey: ['collectionOptions'], queryFn: api.collectionOptions })
|
||||||
const listing = useQuery({
|
const listing = useQuery({
|
||||||
queryKey: ['fs', dir ?? '~'],
|
queryKey: ['fs', dir ?? '~'],
|
||||||
queryFn: () => api.listDir(dir),
|
queryFn: () => api.listDir(dir),
|
||||||
|
enabled: mode === 'browse',
|
||||||
})
|
})
|
||||||
|
|
||||||
const open = useMutation({
|
const open = useMutation({
|
||||||
@@ -22,23 +64,34 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const data = listing.data
|
const data = listing.data
|
||||||
|
const opt = options.data
|
||||||
|
const auto = opt?.auto ?? null
|
||||||
|
const recent = opt?.recent ?? null
|
||||||
|
const recentAvailable = !!recent && recent.exists
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-screen items-center justify-center bg-ink-950 p-6">
|
<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">
|
<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 */}
|
{/* Header */}
|
||||||
<div className="flex items-center gap-3 border-b border-line px-5 py-4">
|
<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="flex-1">
|
||||||
<div className="text-[15px] font-semibold tracking-tight">
|
<div className="text-[15px] font-semibold tracking-tight">
|
||||||
Select your Traktor collection
|
Select your Traktor collection
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xs text-muted">
|
<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>
|
||||||
</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 && (
|
{onCancel && (
|
||||||
<button
|
<button
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
@@ -49,86 +102,136 @@ export function CollectionPicker({ onOpened, onCancel }: Props) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Path bar */}
|
{mode === 'choose' ? (
|
||||||
<div className="flex items-center gap-2 border-b border-line bg-ink-850 px-4 py-2">
|
/* ---- Chooser ---- */
|
||||||
<button
|
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto p-5">
|
||||||
title="Home"
|
<OptionCard
|
||||||
onClick={() => setDir(data?.home)}
|
icon="✨"
|
||||||
className="rounded px-2 py-1 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
title="Automatic"
|
||||||
>
|
subtitle={
|
||||||
⌂
|
auto
|
||||||
</button>
|
? `${auto.label} · modified ${formatWhen(auto.modified)}`
|
||||||
<button
|
: options.isLoading
|
||||||
title="Up one level"
|
? 'Searching for a Traktor collection…'
|
||||||
disabled={!data?.parent}
|
: 'No Traktor collection found in the default location'
|
||||||
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"
|
disabled={!auto}
|
||||||
>
|
busy={open.isPending}
|
||||||
↑
|
onClick={() => auto && open.mutate(auto.path)}
|
||||||
</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
|
<OptionCard
|
||||||
disabled={!manual.trim() || open.isPending}
|
icon="🕘"
|
||||||
onClick={() => open.mutate(manual.trim())}
|
title="Open last collection"
|
||||||
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"
|
subtitle={
|
||||||
>
|
recent
|
||||||
{open.isPending ? 'Opening…' : 'Open'}
|
? recent.exists
|
||||||
</button>
|
? 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>
|
||||||
</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>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import type { CuePoint } from '../api'
|
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'
|
import { paintWave, type WaveColumn } from '../lib/waveform'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -8,6 +8,7 @@ interface Props {
|
|||||||
currentTime: number
|
currentTime: number
|
||||||
duration: number
|
duration: number
|
||||||
cues: CuePoint[]
|
cues: CuePoint[]
|
||||||
|
cuePoint: number | null
|
||||||
bpm: number | null
|
bpm: number | null
|
||||||
gridAnchor: number | null
|
gridAnchor: number | null
|
||||||
loop: { start: number; end: number } | null
|
loop: { start: number; end: number } | null
|
||||||
@@ -34,6 +35,7 @@ export function MainWaveform({
|
|||||||
currentTime,
|
currentTime,
|
||||||
duration,
|
duration,
|
||||||
cues,
|
cues,
|
||||||
|
cuePoint,
|
||||||
bpm,
|
bpm,
|
||||||
gridAnchor,
|
gridAnchor,
|
||||||
loop,
|
loop,
|
||||||
@@ -83,12 +85,37 @@ export function MainWaveform({
|
|||||||
if (cues.length) {
|
if (cues.length) {
|
||||||
drawCues(ctx, cues, w, h, dpr, timeToX, true)
|
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.
|
// Fixed centre playhead — red core with a translucent black outline so it
|
||||||
const pw = Math.max(2, Math.round(2 * dpr))
|
// separates from the waveform, plus inward-pointing triangle caps top and
|
||||||
ctx.fillStyle = '#e6e9ef'
|
// bottom that anchor the eye in the quiet margins.
|
||||||
ctx.fillRect(Math.floor(w / 2) - Math.floor(pw / 2), 0, pw, h)
|
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)
|
const drawRef = useRef(draw)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef } from 'react'
|
||||||
import type { CuePoint } from '../api'
|
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'
|
import { paintWave, type WaveColumn } from '../lib/waveform'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -8,6 +8,7 @@ interface Props {
|
|||||||
currentTime: number
|
currentTime: number
|
||||||
duration: number
|
duration: number
|
||||||
cues: CuePoint[]
|
cues: CuePoint[]
|
||||||
|
cuePoint: number | null
|
||||||
loop: { start: number; end: number } | null
|
loop: { start: number; end: number } | null
|
||||||
onSeek: (t: number) => void
|
onSeek: (t: number) => void
|
||||||
}
|
}
|
||||||
@@ -17,13 +18,22 @@ interface Props {
|
|||||||
* offscreen canvas) with a moving playhead + dimmed played region. Click to
|
* offscreen canvas) with a moving playhead + dimmed played region. Click to
|
||||||
* seek anywhere in the track.
|
* 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 wrapRef = useRef<HTMLDivElement>(null)
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null)
|
const canvasRef = useRef<HTMLCanvasElement>(null)
|
||||||
const cacheRef = useRef<HTMLCanvasElement | null>(null)
|
const cacheRef = useRef<HTMLCanvasElement | null>(null)
|
||||||
const timeRef = useRef(0)
|
const timeRef = useRef(0)
|
||||||
const durRef = useRef(0)
|
const durRef = useRef(0)
|
||||||
const cuesRef = useRef<CuePoint[]>(cues)
|
const cuesRef = useRef<CuePoint[]>(cues)
|
||||||
|
const cuePointRef = useRef<number | null>(cuePoint)
|
||||||
const loopRef = useRef(loop)
|
const loopRef = useRef(loop)
|
||||||
|
|
||||||
const renderCache = useCallback(() => {
|
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)
|
if (lp) drawLoop(ctx, (lp.start / dur) * w, (lp.end / dur) * w, h, dpr)
|
||||||
// Cue markers (no beatgrid/labels in the overview).
|
// Cue markers (no beatgrid/labels in the overview).
|
||||||
drawCues(ctx, cuesRef.current, w, h, dpr, (t) => (t / dur) * w, false)
|
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))
|
const pw = Math.max(2, Math.round(2 * dpr))
|
||||||
ctx.fillStyle = '#e6e9ef'
|
const px0 = px - Math.floor(pw / 2)
|
||||||
ctx.fillRect(px - Math.floor(pw / 2), 0, pw, h)
|
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()
|
draw()
|
||||||
}, [currentTime, duration, draw])
|
}, [currentTime, duration, draw])
|
||||||
|
|
||||||
// Redraw when the cue set or loop changes.
|
// Redraw when the cue set, cue point, or loop changes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
cuesRef.current = cues
|
cuesRef.current = cues
|
||||||
|
cuePointRef.current = cuePoint
|
||||||
loopRef.current = loop
|
loopRef.current = loop
|
||||||
draw()
|
draw()
|
||||||
}, [cues, loop, draw])
|
}, [cues, cuePoint, loop, draw])
|
||||||
|
|
||||||
const seek = (e: React.MouseEvent<HTMLDivElement>) => {
|
const seek = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
if (!duration) return
|
if (!duration) return
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { OverviewWaveform } from './OverviewWaveform'
|
|||||||
interface Props {
|
interface Props {
|
||||||
/** The track currently loaded into the prep deck, if any. */
|
/** The track currently loaded into the prep deck, if any. */
|
||||||
track: Track | null
|
track: Track | null
|
||||||
|
/** Bumped by the library's per-row play button to load + auto-play. */
|
||||||
|
playRequest?: number
|
||||||
onError?: (msg: string) => void
|
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
|
* Web Audio PlaybackEngine (seamless loops); the same decoded buffer feeds the
|
||||||
* scratch engine and both waveform views.
|
* scratch engine and both waveform views.
|
||||||
*/
|
*/
|
||||||
export function PrepStrip({ track, onError }: Props) {
|
export function PrepStrip({ track, playRequest = 0, onError }: Props) {
|
||||||
const qc = useQueryClient()
|
const qc = useQueryClient()
|
||||||
const [playing, setPlaying] = useState(false)
|
const [playing, setPlaying] = useState(false)
|
||||||
const [current, setCurrent] = useState(0)
|
const [current, setCurrent] = useState(0)
|
||||||
@@ -50,6 +52,7 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
const [cueData, setCueData] = useState<TrackCues | null>(null)
|
const [cueData, setCueData] = useState<TrackCues | null>(null)
|
||||||
const [snap, setSnap] = useState(true)
|
const [snap, setSnap] = useState(true)
|
||||||
const [selectedSlot, setSelectedSlot] = useState<number | null>(null)
|
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).
|
// Loop state (transient — persisted only when saved as a hotcue later).
|
||||||
const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null)
|
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 wasPlayingRef = useRef(false)
|
||||||
const scratchRafRef = useRef(0)
|
const scratchRafRef = useRef(0)
|
||||||
const engagedRef = useRef(false) // scratch engine is dragging or coasting
|
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
|
const trackId = track?.id ?? null
|
||||||
|
|
||||||
@@ -100,6 +105,7 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
setLoopRegion(null)
|
setLoopRegion(null)
|
||||||
setLoopActive(false)
|
setLoopActive(false)
|
||||||
setActiveBeats(null)
|
setActiveBeats(null)
|
||||||
|
setCuePoint(0)
|
||||||
loopInRef.current = null
|
loopInRef.current = null
|
||||||
}, [trackId])
|
}, [trackId])
|
||||||
|
|
||||||
@@ -133,6 +139,13 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
playbackRef.current.load(ctx, res.buffer)
|
playbackRef.current.load(ctx, res.buffer)
|
||||||
setDuration(res.buffer.duration)
|
setDuration(res.buffer.duration)
|
||||||
setReady(true)
|
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(() => {
|
.catch(() => {
|
||||||
if (!cancelled) setWaveStatus('error')
|
if (!cancelled) setWaveStatus('error')
|
||||||
@@ -180,6 +193,43 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
setCurrent(eng.getPosition())
|
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).
|
// Follow the Web Audio clock while playing (high-res → smooth playhead).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!playing) return
|
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
|
<button
|
||||||
onClick={toggle}
|
onClick={toggle}
|
||||||
disabled={!ready}
|
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'}
|
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>
|
</button>
|
||||||
<div className="tabular-nums text-xs text-faint">
|
<div className="tabular-nums text-lg font-medium text-muted">
|
||||||
{fmt(current)} / {fmt(duration)}
|
{fmt(current)} / {fmt(duration)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -528,6 +600,7 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
currentTime={current}
|
currentTime={current}
|
||||||
duration={duration}
|
duration={duration}
|
||||||
cues={cueData?.cues ?? []}
|
cues={cueData?.cues ?? []}
|
||||||
|
cuePoint={cuePoint}
|
||||||
bpm={cueData?.bpm ?? null}
|
bpm={cueData?.bpm ?? null}
|
||||||
gridAnchor={cueData?.grid_anchor ?? null}
|
gridAnchor={cueData?.grid_anchor ?? null}
|
||||||
loop={activeLoop}
|
loop={activeLoop}
|
||||||
@@ -549,6 +622,7 @@ export function PrepStrip({ track, onError }: Props) {
|
|||||||
currentTime={current}
|
currentTime={current}
|
||||||
duration={duration}
|
duration={duration}
|
||||||
cues={cueData?.cues ?? []}
|
cues={cueData?.cues ?? []}
|
||||||
|
cuePoint={cuePoint}
|
||||||
loop={activeLoop}
|
loop={activeLoop}
|
||||||
onSeek={seekManual}
|
onSeek={seekManual}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -184,14 +184,7 @@ export function Sidebar({ source, onSelect, onError }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="flex h-full w-64 shrink-0 flex-col border-r border-line bg-ink-900">
|
<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="px-2 pt-3">
|
||||||
<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">
|
|
||||||
<button
|
<button
|
||||||
onClick={() => onSelect({ kind: 'all' })}
|
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 ${
|
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors ${
|
||||||
|
|||||||
@@ -109,9 +109,19 @@ interface Props {
|
|||||||
onSortingChange: (s: SortingState) => void
|
onSortingChange: (s: SortingState) => void
|
||||||
selection?: Selection
|
selection?: Selection
|
||||||
onRowContextMenu?: (track: Track, x: number, y: number) => void
|
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({
|
const table = useReactTable({
|
||||||
data: tracks,
|
data: tracks,
|
||||||
columns,
|
columns,
|
||||||
@@ -157,6 +167,7 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
|
|||||||
) : (
|
) : (
|
||||||
<span className="w-10 shrink-0" />
|
<span className="w-10 shrink-0" />
|
||||||
)}
|
)}
|
||||||
|
{onPlay && <span className="w-9 shrink-0" />}
|
||||||
{table.getHeaderGroups()[0].headers.map((header) => {
|
{table.getHeaderGroups()[0].headers.map((header) => {
|
||||||
const sorted = header.column.getIsSorted()
|
const sorted = header.column.getIsSorted()
|
||||||
return (
|
return (
|
||||||
@@ -180,10 +191,11 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
|
|||||||
{virtualRows.map((vr) => {
|
{virtualRows.map((vr) => {
|
||||||
const row = rows[vr.index]
|
const row = rows[vr.index]
|
||||||
const isSelected = selection?.selected.has(row.original.id) ?? false
|
const isSelected = selection?.selected.has(row.original.id) ?? false
|
||||||
|
const isActive = activeTrackId === row.original.id
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={row.id}
|
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'
|
isSelected ? 'bg-accent-soft/50' : 'hover:bg-ink-850'
|
||||||
}`}
|
}`}
|
||||||
style={{
|
style={{
|
||||||
@@ -212,6 +224,26 @@ export function TrackTable({ tracks, sorting, onSortingChange, selection, onRowC
|
|||||||
{vr.index + 1}
|
{vr.index + 1}
|
||||||
</span>
|
</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) => (
|
{row.getVisibleCells().map((cell) => (
|
||||||
<div
|
<div
|
||||||
key={cell.id}
|
key={cell.id}
|
||||||
|
|||||||
@@ -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. */
|
/** Draw the active loop region: a translucent green band with bright edges. */
|
||||||
export function drawLoop(
|
export function drawLoop(
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
|
|||||||
@@ -3,12 +3,15 @@
|
|||||||
// The audio is downmixed to mono and split into three frequency bands with
|
// The audio is downmixed to mono and split into three frequency bands with
|
||||||
// native BiquadFilters (via OfflineAudioContext — fast, off the main thread).
|
// native BiquadFilters (via OfflineAudioContext — fast, off the main thread).
|
||||||
// Per output column we keep each band's RMS energy plus the amplitude peak.
|
// 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);
|
// Each band is mapped to a target colour on Traktor's warm→cool ramp
|
||||||
// height = amplitude. This mirrors how Traktor's Spectrum waveform reads.
|
// (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 {
|
export interface WaveColumn {
|
||||||
peak: number // 0..1 amplitude (column height)
|
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
|
g: number
|
||||||
b: number
|
b: number
|
||||||
}
|
}
|
||||||
@@ -20,6 +23,11 @@ const MID_HZ = 1200
|
|||||||
const MID_Q = 0.6
|
const MID_Q = 0.6
|
||||||
const HIGH_HZ = 5000
|
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
|
* 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
|
* 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
|
// tied to loudness — amplitude is shown by height, like Traktor). Gamma
|
||||||
// sharpens the separation between bands.
|
// sharpens the separation between bands.
|
||||||
const mx = Math.max(l, m, h, 1e-9)
|
const mx = Math.max(l, m, h, 1e-9)
|
||||||
cols[b] = {
|
const wl = Math.pow(l / mx, 1.3)
|
||||||
peak: peak[b] / maxPeak,
|
const wm = Math.pow(m / mx, 1.3)
|
||||||
r: Math.pow(l / mx, 1.3),
|
const wh = Math.pow(h / mx, 1.3)
|
||||||
g: Math.pow(m / mx, 1.3),
|
// Blend the three band palette colours by weight, then normalise to the
|
||||||
b: Math.pow(h / mx, 1.3),
|
// 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 }
|
return { cols, buffer: audio }
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user