Updated readme

This commit is contained in:
Ben committed 2026-07-04 23:45:32 +02:00
1 parent c98b621f05
commit a4797d9b99
2 files changed
+166 -82

No files matched your search

+97 -23
View File
@@ -8,8 +8,9 @@ Guidance for working in this repo. Read before making changes.
Instruments Traktor** (Pro 4 / NML v20), built on the `traktor-nml-utils`
library. The user is a DJ; the goal is a polished, multiplatform web app for
browsing the collection, editing playlists, and preparing tracks (metadata,
cover art; later audio/cue prep) — a lightweight alternative to heavy Traktor,
later possibly wrapped in Tauri and given a mobile version.
cover art, and audio prep: playback, waveform, beatgrid, cues/hotcues, loops) —
a lightweight alternative to heavy Traktor, later possibly wrapped in Tauri and
given a mobile version.
## Architecture
@@ -23,30 +24,54 @@ Two independent apps that talk over HTTP:
(filter/sort/facets/stats) lives here. `replace_track()` refreshes one
projection after an edit (bridges the read model and the edit store).
- `playlist_store.py` (`PlaylistStore`) — the **edit** model: owns the parsed
dataclass NML and applies all edits (playlists AND track metadata AND cover
art), then renders + saves. See "Write path" below.
dataclass NML and applies all edits (playlists, track metadata, cover art,
AND track-prep edits: hotcues/cues, beatgrid/BPM, lock), then renders +
saves. See "Write path" below.
- `file_tags.py` — reads/writes embedded audio-file tags & cover art (mutagen)
and resolves Traktor `LOCATION`s to OS paths. Best-effort.
- `discovery.py` — finds Traktor collections in their default install location
(`~/Documents/Native Instruments/Traktor <version>/collection.nml`) for the
picker's "Automatic" option; sorts newest Traktor version first.
- `prefs.py` — tiny persisted user-prefs store in `userprefs.json` (resolved
relative to the package so it travels with the app; gitignored). Holds the
last-opened collection path and the library column layout. Best-effort I/O.
- `schemas.py` — Pydantic response/request models.
- `main.py` — FastAPI routes (all under `/api`). Holds an `AppState` with the
currently-loaded collection; it starts **unloaded** and the collection is
chosen at runtime via `POST /api/collection/open` (data routes 409 until
then). `GET /api/fs/list` powers the in-app file browser. Setting
`KONDUKTOR_NML` auto-loads on startup (dev/tests).
then). `GET /api/fs/list` powers the in-app file browser;
`GET /api/collection/options` feeds the picker's auto-detect + last-opened
shortcuts; `GET`/`PATCH /api/prefs` persist UI prefs. Setting `KONDUKTOR_NML`
auto-loads on startup (dev/tests).
- **`frontend/`** — React + TypeScript + Vite. A dark, virtualized track
explorer. Entry: [frontend/src/App.tsx](frontend/src/App.tsx).
- `api.ts` — typed client + all API types (keep in sync with backend
`schemas.py`).
- `components/` — `CollectionPicker` (startup file-browser gate), `Sidebar`
(playlist tree + create/rename/delete), `SaveBar`, `Toolbar`
(search/filters), `TrackTable` (TanStack Table + Virtual grid),
`PlaylistEditor` (dnd-kit reorder), `SelectionBar` (bulk add-to-playlist),
`ContextMenu` + `EditTagsDialog` (right-click → metadata + album-art edit),
`StatusBar`, `RatingStars`, `Toast`.
- `components/` — `CollectionPicker` (startup chooser: Automatic / Open last /
Find manually — the last reveals a file browser), `Sidebar` (playlist tree +
create/rename/delete), `SaveBar`, `Toolbar` (search/filters + `ColumnsMenu`),
`TrackTable` (TanStack Table + Virtual grid; per-row play button, configurable
columns, inline double-click editing), `PlaylistEditor` (dnd-kit reorder),
`SelectionBar` (bulk add-to-playlist), `ContextMenu` + `EditTagsDialog`
(right-click → multi-field metadata + album-art edit), `StatusBar`,
`RatingStars` (read-only, or click-to-set when given `onChange`), `Toast`.
- **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it —
transport (play/pause, CUE), two waveforms (`MainWaveform` scrolling+zoomable,
`OverviewWaveform` whole-track), `LoopControls`, `HotcueBar`, `GridControls`.
Prep libs live in `src/lib/`: `playbackEngine.ts` (Web Audio, seamless loops),
`scratchEngine.ts` (drag-to-scratch), `waveform.ts` (frequency-colored
analysis + paint), `cues.ts` (draw cues/loop/beatgrid/cue-point). See "Prep
engine" below.
- `lib/trackColumns.tsx` — single source of truth for the library table's
columns (defs, default widths/visibility/order, the Columns-menu list, the
inline `InlineEdit` cell, and the `TableMeta.onEditField` augmentation).
- Data flow: the whole library is fetched once (`/api/tracks?limit=20000`);
filtering and sorting happen **client-side** for instant interaction. Edits
apply in-memory (server holds them) and the sidebar **Save to Traktor**
button flushes to disk. Styling is Tailwind v4 with tokens in `src/index.css`.
Library column layout (visibility/order/width) persists to `userprefs.json`
via `GET`/`PATCH /api/prefs` (debounced; hydrated on launch, merged against
defaults so newly-added columns still appear).
## Commands
@@ -67,10 +92,11 @@ npm run build # tsc -b && vite build — run this to typecheck
**Tests:** `cd backend && ./run_tests.sh` (runs against a temp copy of the real
collection). **ALWAYS run this before changing anything in the save /
serialization path.** It enforces:
- `test_save_fidelity.py` — a no-op save is byte-identical; a playlist edit
changes only that playlist's block; and a **track-metadata edit changes only
that `<ENTRY>`** (Invariant C). The guard that catches serialization
regressions like the lxml reformatting bug.
- `test_save_fidelity.py` — a no-op save is byte-identical (A); a playlist edit
changes only that playlist's block (B); a **track-metadata edit changes only
that `<ENTRY>`** (C); a **hotcue create is localized + round-trips** with
START stored in ms (D); a **beatgrid/BPM edit is localized + round-trips** (E).
The guard that catches serialization regressions like the lxml reformatting bug.
- `test_phase3.py` — full create/add/reorder/rename/delete/save cycle stays
Traktor-valid, backup-first, COLLECTION byte-identical, original untouched.
@@ -112,8 +138,8 @@ frontend at `http://localhost:5173`.
- Backend: type hints, Pydantic models for all responses, keep query logic in
`collection_service.py` (routes stay thin).
- Frontend: functional components, TanStack Query for fetching, Tailwind
utility classes with the `ink-*`/`accent`/`gold` tokens from `index.css`.
Keep `api.ts` types aligned with `schemas.py`.
utility classes with the `ink-*`/`accent`/`gold`/`mint`/`pink` tokens from
`index.css`. Keep `api.ts` types aligned with `schemas.py`.
- Python 3.14 note: pin dependencies loosely enough to get prebuilt wheels
(older `pydantic-core` pins force a from-source Rust build that fails).
@@ -123,11 +149,18 @@ frontend at `http://localhost:5173`.
- ✅ Phase 2 — track explorer UI
- ✅ Phase 3 — playlist editing/creation + safe (backup-first, surgical) saves
- ✅ Runtime collection picker (in-app file browser)
- ✅ Track metadata editing (right-click → Edit Tags) + embedded file-tag & cover-art writing
- ⬜ Track prep — audio playback / cue-point & loop editing (Tier 2; needs audio engine)
- ✅ Track metadata editing (right-click → Edit Tags dialog, plus inline
double-click cell editing + click-to-set rating stars) with embedded file-tag
& cover-art writing
- ✅ Configurable library columns (show/hide, drag-reorder, resize) + auto-detect
collection picker (Automatic / last-opened / manual), persisted to `userprefs.json`
- ✅ Track prep — audio playback, frequency-colored scrolling waveform, scratch,
beatgrid display + editing, cue/hotcue create/jump/delete, loops; keyboard
shortcuts (Space = play/pause, 1–8 = hotcues, Shift+1–8 = delete). See "Prep engine".
- ⬜ Track prep Tier 2 — cue-point fine editing / audio export polish
- ⬜ Bulk metadata editing; ⬜ Phase 4 — polish + optional Tauri desktop packaging
## Write path (playlists + track metadata)
## Write path (playlists + track metadata + prep)
`PlaylistStore` edits the **traktor-nml-utils dataclass model** in memory and,
on `save()`, renders the WHOLE model and writes it (backup-first, into a
@@ -145,7 +178,18 @@ diff — no COLLECTION splicing needed.
- **Track metadata**: `set_track_metadata(track_id, fields)` edits only the SAFE
set — title, artist, album, genre, label, remixer, producer, mix,
release_date, comment, rating (0–5 stars → `RANKING = stars*51`). Path, BPM and
key are intentionally NOT editable (path = identity; BPM/key are audio/grid).
key are intentionally NOT editable via metadata (path = identity; BPM/key are
audio/grid — BPM is edited through the grid path below). This is the set the
Edit Tags dialog AND the inline table editing (double-click cell, click rating
stars) both write.
- **Track prep** (also `PlaylistStore`, same render/save pipeline):
`set_hotcue(track_id, slot, start_sec, type, length_sec)` creates/replaces a
`CUE_V2` (types 0 cue, 1 fade-in, 2 fade-out, 3 load, 5 loop; START/LEN stored
in **ms**; a loop hotcue carries LEN); `set_hotcue_type` changes just the type;
`delete_hotcue` removes a slot. `set_grid(track_id, bpm?, anchor_sec?)` edits
the TEMPO + the grid marker (`CUE_V2` type 4 with a `<GRID BPM>` child);
`delete_grid` drops it; `set_lock(track_id, locked)` toggles the `LOCK` attr.
Invariants D/E prove hotcue + grid edits are localized and round-trip.
- **Embedded file tags + cover art**: on save, for each edited track,
`_sync_file_tags()` writes the changed fields (and staged cover art) into the
audio file via `file_tags` (mutagen; ID3/MP4/FLAC/AIFF, WAV skipped) —
@@ -160,6 +204,36 @@ diff — no COLLECTION splicing needed.
- `POST /api/save` always writes (backup-first); no write gate. Endpoints:
`POST/PATCH/DELETE /api/playlists[...]`, `PUT .../entries` (replace),
`POST .../add` (append); `PATCH /api/tracks` (metadata); `GET/PUT /api/tracks/art`
(cover art); `POST /api/save`.
(cover art); `GET /api/tracks/audio` (Range-aware stream for playback/analysis);
`GET /api/tracks/cues`, `POST/PATCH/DELETE /api/tracks/hotcue`,
`PATCH/DELETE /api/tracks/grid`, `PATCH /api/tracks/lock` (prep); `POST /api/save`.
- Tests: `backend/run_tests.sh` → `test_save_fidelity.py` + `test_phase3.py`
(both run against a temp copy). Run before touching the save/serialization path.
## Prep engine (frontend)
The prep strip plays every track through the **Web Audio API** (a plain
`<audio>` element can't do reverse/arbitrary-rate scratch or seamless loops).
- `playbackEngine.ts` — an `AudioBufferSourceNode` with a `startOffset`/
`startedAt` position model; `getPosition()` reads the AudioContext clock
(high-res → smooth playhead). Seamless loops via native `loopStart`/`loopEnd`;
`setLoop()` re-anchors position so enabling/disabling a loop doesn't desync.
- `scratchEngine.ts` — a persistent (idle-silent) `ScriptProcessorNode` that,
while dragging the main waveform, plays PCM at a position gliding toward the
cursor, then coasts with inertia on release.
- **CRITICAL gotcha**: playing an `AudioBuffer` "acquires the content" in
Firefox and **detaches** any `getChannelData()` views held elsewhere. The
scratch engine therefore **copies** the PCM in `load()` (never holds the
playback buffer's views). Playback and scratch also run on **separate
`AudioContext`s** — sharing one goes silent after a source has played.
- `waveform.ts` — decodes once (buffer reused by both engines, no re-decode),
splits into 3 bands via `OfflineAudioContext` biquads, and colors each column
by blending three palette targets (bass→orange, mids→violet, highs→cyan — no
green, matching Traktor's Spectrum). Height = amplitude.
- `cues.ts` — canvas drawers for cue markers (type-colored), the active loop
band, the beatgrid (white beats/brighter downbeats), and the floating CUE
point (gold). The main waveform's playhead is red; both waveforms share these.
- Prep edits go straight to the prep endpoints above; after each edit the
endpoint refreshes the read model (`service.replace_track()`) so cue/grid
counts update live, and the frontend invalidates the relevant queries.
+69 -59
View File
@@ -1,29 +1,53 @@
# Konduktor
A library-management and track-preparation tool for **Native Instruments
Traktor** (Pro 4 / NML v20), built on top of
[`traktor-nml-utils`](https://github.com/MrPatben8/traktor-nml-utils).
**A fast, modern home for your Traktor collection.**
- **backend/** — FastAPI service that parses `collection.nml` and serves it as a
query API (tracks, stats, facets, playlists). Read-only in the current phase.
- **frontend/** — React + TypeScript (Vite) track explorer: a polished, dark,
virtualized grid with search, filtering, sorting, and playlist browsing.
Konduktor is a lightweight desktop-style app for DJs who run **Native
Instruments Traktor** (Pro 4 / NML v20). It opens your existing
`collection.nml`, gives you a beautiful dark library to explore, and lets you
build playlists and prep tracks — without launching the whole heavyweight
Traktor app just to tidy up your tags or drop a few cue points.
## Quick start
Your collection stays exactly where it is. Konduktor reads and writes the same
file Traktor uses, so everything you do shows up next time you open Traktor.
After the one-time setup below, start everything with a single command:
---
```bash
./dev.sh
```
## Why you'll like it
Then open **http://localhost:5173**. Press `Ctrl-C` to stop both servers.
- **Instant, searchable library.** Your whole collection loads into a snappy,
virtualized grid. Search, filter by genre / key / BPM / rating, and sort by
any column — all instant, no waiting.
- **Make it yours.** Show only the columns you care about, drag them into the
order you like, and resize them to fit. Your layout is remembered.
- **Edit tags without the ceremony.** Double-click any field to fix a title or
genre on the spot, click the stars to rate a track, or right-click for a full
tag + cover-art editor. Great for quick one-off fixes.
- **Playlists, the easy way.** Create, rename, and delete playlists, then
drag-and-drop to reorder or add tracks.
- **A real prep deck.** Load any track into the deck at the top and:
- play it with a **frequency-colored waveform** (Traktor-style Spectrum look),
scrolling under a fixed playhead with zoom in/out
- scratch it by dragging the waveform
- see and adjust the **beatgrid** and BPM
- set, jump to, and delete **hotcues** (with a color-coded 8-slot bar)
- build **loops** in fixed beat sizes, tied into the hotcue system
- use keyboard shortcuts: **Space** to play/pause, **1–8** to fire hotcues,
**Shift+1–8** to clear them
- **Your data is safe.** Every save makes a timestamped backup first, and only
ever touches the parts you changed — the rest of the file stays byte-for-byte
identical.
## One-time setup
---
You only need to do this once (installs backend and frontend dependencies).
## Getting started
**Backend** (Python 3.11+):
Konduktor runs as two small local servers (a Python backend and a web
frontend). One-time setup, then a single command to launch.
### 1. Install (once)
**Backend** — needs Python 3.11+:
```bash
cd backend
@@ -32,7 +56,7 @@ pip install -r requirements.txt
cd ..
```
**Frontend** (Node 18+):
**Frontend** — needs Node 18+:
```bash
cd frontend
@@ -40,61 +64,47 @@ npm install
cd ..
```
## Running the servers manually
`./dev.sh` runs both for you, but you can also start them in separate terminals:
**Backend** (terminal 1) — FastAPI on port 8000:
### 2. Launch
```bash
cd backend && source .venv/bin/activate
uvicorn konduktor.main:app --reload --port 8000
./dev.sh
```
**Frontend** (terminal 2) — Vite on port 5173:
Then open **http://localhost:5173** in your browser. Press `Ctrl-C` to stop.
```bash
cd frontend && npm run dev
```
### 3. Open your collection
The Vite dev server proxies `/api` to the backend on port 8000, so both must be
running. API docs (Swagger UI): **http://localhost:8000/docs**.
On launch, Konduktor offers to:
## Choosing your collection
- **Automatically** open the collection from your latest installed Traktor,
- reopen the **last collection** you used, or
- **browse** for a `collection.nml` yourself.
On launch, Konduktor asks you to pick a `collection.nml` — browse to it in the
in-app file picker (or paste a full path). You can switch collections any time
via the file name shown in the bottom-right status bar.
That's it — you're in.
To skip the picker and auto-load a file on startup (handy for development), set
`KONDUKTOR_NML`:
---
```bash
KONDUKTOR_NML=/path/to/collection.nml uvicorn konduktor.main:app --port 8000
```
## Saving back to Traktor
## Status
Playlist edits, tag changes, and prep tweaks all apply live in the app. When
you're happy, hit **Save to Traktor** to write them to `collection.nml`.
- ✅ **Phase 1** — backend core + read-only API
- ✅ **Phase 2** — track explorer UI (grid, search, filters, playlist browsing)
- ✅ **Phase 3** — playlist editing/creation (drag-reorder, add/remove, rename,
delete) with surgical, backup-first saves
- ⬜ **Phase 4** — polish + optional Tauri desktop packaging
> ⚠️ **Close Traktor before saving.** Traktor rewrites `collection.nml` when it
> quits, so if it's open it will overwrite your changes. Konduktor always writes
> a backup first (into a `backups/` folder next to your collection), but closing
> Traktor first is the safe habit.
## Editing & saving (Phase 3)
Want to experiment risk-free? Point Konduktor at a *copy* of your collection and
play around.
Playlist edits (create/rename/delete, add/remove, drag-reorder) are live in the
UI. Click **Save to Traktor** to write them to `collection.nml`.
---
> **Close Traktor before saving** — it overwrites `collection.nml` on exit, so
> it would clobber your changes otherwise.
## Good to know
**Safety guarantees:**
- Every save writes a timestamped `.bak` backup first, into a `backups/` folder
next to your collection.
- Saves are *surgical* — only the `<PLAYLISTS>` section is rewritten; the track
`COLLECTION` stays byte-for-byte identical.
- To try it against a copy, point `KONDUKTOR_NML` at one.
The backend test `backend/test_phase3.py` exercises the full write path against
a temp copy and asserts these guarantees.
- Konduktor is built on [`traktor-nml-utils`](https://github.com/MrPatben8/traktor-nml-utils)
and speaks Traktor's real file format — no import/export, no separate database.
- It's a web app today, with an eye toward a packaged desktop build (Tauri) and
a mobile version down the road.
- Under the hood: **FastAPI** (Python) backend + **React / TypeScript / Vite**
frontend. Curious about internals or contributing? See
[CLAUDE.md](CLAUDE.md) for the architecture and conventions.