From 19a604f730eb01df7e1fcdf1d9d329d353c4d630 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Fri, 16 Oct 2026 14:50:46 +0200 Subject: [PATCH] Added full support for memory-cues --- CLAUDE.md | 107 +++++++-- .../onelibrary-memory-edits/README.md | 38 ++++ .../after/black-bloc.DAT | Bin 0 -> 6872 bytes .../after/black-bloc.EXT | Bin 0 -> 2532 bytes .../onelibrary-memory-edits/after/doomed.DAT | Bin 0 -> 6182 bytes .../onelibrary-memory-edits/after/doomed.EXT | Bin 0 -> 886 bytes .../onelibrary-memory-edits/after/formula.DAT | Bin 0 -> 6148 bytes .../onelibrary-memory-edits/after/formula.EXT | Bin 0 -> 912 bytes .../onelibrary-memory-edits/after/lift-it.DAT | Bin 0 -> 5200 bytes .../onelibrary-memory-edits/after/lift-it.EXT | Bin 0 -> 2312 bytes .../after/sell-my-soul.DAT | Bin 0 -> 5952 bytes .../after/sell-my-soul.EXT | Bin 0 -> 900 bytes .../onelibrary-memory-edits/after/wtf.DAT | Bin 0 -> 5902 bytes .../onelibrary-memory-edits/after/wtf.EXT | Bin 0 -> 2384 bytes .../before/black-bloc.DAT | Bin 0 -> 6816 bytes .../before/black-bloc.EXT | Bin 0 -> 2488 bytes .../onelibrary-memory-edits/before/doomed.DAT | Bin 0 -> 6238 bytes .../onelibrary-memory-edits/before/doomed.EXT | Bin 0 -> 974 bytes .../before/formula.DAT | Bin 0 -> 6092 bytes .../before/formula.EXT | Bin 0 -> 868 bytes .../before/lift-it.DAT | Bin 0 -> 4752 bytes .../before/lift-it.EXT | Bin 0 -> 1960 bytes .../before/sell-my-soul.DAT | Bin 0 -> 5952 bytes .../before/sell-my-soul.EXT | Bin 0 -> 888 bytes .../onelibrary-memory-edits/before/wtf.DAT | Bin 0 -> 5902 bytes .../onelibrary-memory-edits/before/wtf.EXT | Bin 0 -> 2384 bytes .../konduktor/adapters/onelibrary/adapter.py | 55 ++++- .../adapters/onelibrary/capabilities.py | 12 +- backend/konduktor/adapters/onelibrary/cues.py | 31 ++- .../konduktor/adapters/onelibrary/export.py | 30 ++- .../adapters/onelibrary/memory_cues.py | 102 +++++++++ .../adapters/onelibrary/projection.py | 4 +- .../konduktor/adapters/onelibrary/store.py | 57 ++++- .../konduktor/adapters/rekordbox/adapter.py | 74 ++++-- .../konduktor/adapters/rekordbox/anlz_file.py | 35 ++- .../adapters/rekordbox/anlz_writer.py | 55 ++++- .../adapters/rekordbox/capabilities.py | 21 +- .../konduktor/adapters/rekordbox/cue_types.py | 4 + .../konduktor/adapters/rekordbox/export.py | 24 +- .../adapters/rekordbox/memory_palette.py | 95 ++++++++ .../adapters/rekordbox/projection.py | 30 ++- backend/konduktor/adapters/rekordbox/store.py | 97 +++++++- backend/konduktor/adapters/remote/adapter.py | 16 ++ backend/konduktor/adapters/traktor/adapter.py | 94 ++++++-- .../adapters/traktor/capabilities.py | 7 +- .../konduktor/adapters/traktor/projection.py | 47 +++- backend/konduktor/adapters/traktor/store.py | 99 ++++++-- backend/konduktor/core/adapter.py | 23 ++ backend/konduktor/core/capabilities.py | 11 +- backend/konduktor/core/cue_colors.py | 5 +- backend/konduktor/core/edit_journal.py | 28 ++- backend/konduktor/core/model.py | 8 +- backend/konduktor/main.py | 43 ++++ backend/konduktor/remote_protocol.py | 7 +- backend/konduktor/schemas.py | 27 +++ backend/test_export_pioneer.py | 28 +++ backend/test_import.py | 48 ++-- backend/test_onelibrary_adapter.py | 6 +- backend/test_onelibrary_anlz.py | 129 ++++++++++- backend/test_rekordbox_adapter.py | 12 +- backend/test_rekordbox_fidelity.py | 115 ++++++++++ backend/test_remote_adapter.py | 9 + backend/test_remote_protocol.py | 10 + backend/test_save_fidelity.py | 114 ++++++++++ backend/test_traktor_adapter.py | 60 ++++- frontend/src/api.ts | 34 ++- frontend/src/components/HotcueBar.tsx | 46 +--- frontend/src/components/LoopControls.tsx | 27 +-- frontend/src/components/MemoryCueStrip.tsx | 132 +++++++++++ frontend/src/components/ModeSwitch.tsx | 38 ++++ frontend/src/components/PrepStrip.tsx | 214 ++++++++++++++++-- frontend/src/components/RenameField.tsx | 42 ++++ frontend/src/lib/cues.ts | 5 +- frontend/src/lib/shortcuts.ts | 2 + 74 files changed, 2083 insertions(+), 274 deletions(-) create mode 100644 backend/fixtures/onelibrary-memory-edits/README.md create mode 100644 backend/fixtures/onelibrary-memory-edits/after/black-bloc.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/black-bloc.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/doomed.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/doomed.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/formula.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/formula.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/lift-it.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/lift-it.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/sell-my-soul.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/sell-my-soul.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/wtf.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/after/wtf.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/black-bloc.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/black-bloc.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/doomed.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/doomed.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/formula.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/formula.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/lift-it.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/lift-it.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/sell-my-soul.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/sell-my-soul.EXT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/wtf.DAT create mode 100644 backend/fixtures/onelibrary-memory-edits/before/wtf.EXT create mode 100644 backend/konduktor/adapters/onelibrary/memory_cues.py create mode 100644 backend/konduktor/adapters/rekordbox/memory_palette.py create mode 100644 frontend/src/components/MemoryCueStrip.tsx create mode 100644 frontend/src/components/ModeSwitch.tsx create mode 100644 frontend/src/components/RenameField.tsx diff --git a/CLAUDE.md b/CLAUDE.md index f5903d5..64b0926 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -315,8 +315,19 @@ Two independent apps that talk over HTTP: cue at `Kind=4` lands on no pad and Rekordbox shows it as a memory cue. Get this wrong and cues silently move to the wrong pad or vanish from the bank. Point cues AND loops both write; `cue_types` owns the translation. - **Memory cues stay preserved-but-uneditable** (Rekordbox is the only - platform with them — the two-platform promotion rule). + **Memory cues are editable** (`add_memory_cue` / `rename_` / + `set_memory_cue_color` / `delete_memory_cue`, addressed by `CuePoint.id` + = `djmdCue.ID`; decided and MEASURED 2026-10-16, kit M1 in + [the discussion](.claude/discussions/discuss-memory-cues-2026-10-16.md)): + `Kind=0`, no ANLZ write, **at most 10 per track** (rekordbox stops + storing the 11th SILENTLY, so the store refuses it with a reason), and + a colour of their OWN — 8 colours (`memory_palette.py`, display RGB + sampled from rekordbox's menu), the 0-based code in **`Color`** with + `ColorTableIndex` NULL (the opposite of a hot cue), `-1` never coloured, + **255** after "No Color", and an unnamed memory LOOP has `Comment=''`. + `_sync_content_cue` writes the mirror in **ROW order** (`rowid`), as + rekordbox does — not by position. A cue on the reserved `Kind=4` is + shown as a memory cue but is not one, so it is not editable. **Hot cue colour is writable** (`set_cue_color`, `PATCH /api/tracks/cue/color`) from `palette.SWATCHES` — all 16 of rekordbox's swatches, MEASURED (the teal-green, 0x13 #00FF30, came last: rekordbox @@ -392,8 +403,19 @@ Two independent apps that talk over HTTP: A pad keeps its colour and (unless given one) its name through a move or retype. An `.EXT` without `PCO2` gets both lists seeded from its `PCOB`s on the first edit — readers prefer `PCO2`, so a one-pad list would hide the rest. - A track with no analysis files refuses cue/grid edits. Memory cues stay - preserved-but-uneditable. + A track with no analysis files refuses cue/grid edits. + **Memory cues are editable** the way rekordbox 7 edits them on a stick + (kit M2; rekordbox's own bytes are `fixtures/onelibrary-memory-edits`): + `memory_cues.py` does the list edits — ONLY the analysis files change (the + database and both pdbs keep every row); the `.DAT` `PCOB` memory list + PREPENDS a new cue and is relinked as a whole (status 0, bytes 24–27 = + prev/next list index, `anlz_writer.relinked_memory_pcpts`), the `.EXT` + `PCO2` memory list APPENDS it in rekordbox's compact 44-byte form; colour = + `PCP2` byte 28, 1-based (`memory_palette.anlz_byte`), name = the `PCP2` + comment, which grows the entry by its length; cap 10. The id is + content-derived (`cues.memory_cue_id`: stored time, kind, loop end), the + same in both lists. When rekordbox rewrites a `.DAT` it also re-sorts the + untouched hot `PCOB` ascending; Konduktor changes only the list it edits. **`device_library.py` keeps the stick's legacy `export.pdb` in step** at every Save (rekordbox's own edits let its playlists drift — measured). The stick's own pdb is EDITED (`pdb.PdbEditor`), not regenerated: ids are @@ -1045,8 +1067,9 @@ Two independent apps that talk over HTTP: persists; a toggle under the zoom buttons draws the RAW signal instead of bars — `lib/rawWave.ts`, below; persisted as `mainWaveRaw`) over `OverviewWaveform`, which frames the main view's visible range around the - playhead (it takes `secPerView` for exactly that). **Controls**: play, CUE, `LoopControls`, then EITHER - `HotcueBar` OR — in **Grid mode** — `GridEditStrip`, then `TempoControls` + playhead (it takes `secPerView` for exactly that). **Controls**: play, CUE, `LoopControls`, then + (where `cues.memory_cues`) the **Hot / Mem** switch (`ModeSwitch`, the same component as BEAT / MAN), then + `HotcueBar`, `MemoryCueStrip` (Mem) OR — in **Grid mode** — `GridEditStrip`, then `TempoControls` (±0.01 / ±0.25, ÷2 ×2, tap, lock) and the Grid toggle. The row is a **container** and gives way in stages instead of overlapping: each pad queries its own width and drops its name below 4rem (the bank never goes @@ -1070,6 +1093,20 @@ Two independent apps that talk over HTTP: and only jump the playhead when no loop is engaged. The move sets the new loop BEFORE seeking: `PlaybackEngine.seek` honours the loop in force, so seeking first wraps the playhead back into the old loop. + - **Memory cues** (decided 2026-10-16, [the discussion](.claude/discussions/discuss-memory-cues-2026-10-16.md)): + Mem mode replaces the pads with `MemoryCueStrip` — chips in TIME order, + scrolling sideways, labelled by name else `m:ss.s`, after a + Memory button + (at the snapped playhead, or the engaged loop as a memory loop; + disabled with the reason past `max_memory_cues`). **Clicking a chip is + CDJ CALL, not a trigger**: jump there and make it the CUE point (paused + stays paused), a memory loop engaging as a loop pad does (`enterCue`). + Right-click: Type (point types, where the platform has more than one — + Traktor; `set_memory_cue_type`, a loop is not retyped), Colour + (`memory_palette`), Rename… (the shared `RenameField`), Delete — no move + (rekordbox has none: a move is delete + add). An uncoloured memory cue + draws in its TYPE colour, exactly as a hot cue does (`cueColor` / + `core/cue_colors.effective_color`). Digit keys stay on hot cues. The mode + persists as `cueBankMode`. - **Hotcue edits live on the pad's right-click menu** (type as one-click choices, a colour swatch grid + Default where `cues.color` is `palette` — `ContextMenu`'s `swatches` item, Rename…, Delete); there is no standalone @@ -1100,9 +1137,12 @@ Two independent apps that talk over HTTP: `cues.palette`; a `free` platform gets no picker yet), the rating scale (`tracks.rating_max`), the grid Lock button (`grid.lockable`). Per-node playlist flags (`can_rename`, `can_delete`, `can_add_tracks`) gate the sidebar and the context menu's "Add to" — each on its OWN flag, - since a platform may allow renaming but not deleting. Carried but deliberately unused until a second adapter - exists: `slot_labels: 'letter'`, `loops: 'separate_bank'`, and - memory-cue *editing* (one-platform features stay preserved-but-uneditable). + since a platform may allow renaming but not deleting. Memory cues: the deck's + Hot / Mem toggle shows on `cues.memory_cues`, + Memory refuses past + `cues.max_memory_cues`, and a memory cue's swatches are `cues.memory_palette` + where `cues.memory_color` is `palette` (its own 8, not `palette`'s 16). + Carried but deliberately unused until a second adapter + exists: `slot_labels: 'letter'`, `loops: 'separate_bank'`. - `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). @@ -1176,6 +1216,10 @@ serialization path.** It enforces: moving back is byte-identical; a folder moves with its subtree and answers its new path id; into its own descendant / beside a namesake is refused with nothing changed; a smart playlist moves by its path id; a no-op is not dirty. + And **memory cues** (P): add / rename / delete change only that ``'s + cue lines, in Traktor's shape (`HOTCUE="-1"`, `n.n.`), add + delete + round-trips byte for byte, new cues (hot ones too) are INSERTED by START, + and a pad + memory cue at one START project once, as the pad. 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; @@ -1276,7 +1320,13 @@ serialization path.** It enforces: and the counter, pointing at its OWN row (found by meaning, not name); a missing key adds one `djmdKey` row as rekordbox creates its own — its spelling, `Seq` NULL, its own USN (so through the ORM; a raw insert is - left unstamped) — which the next `set_key` reuses. + left unstamped) — which the next `set_key` reuses. And **memory cues** (G2): + M1's measured row shapes (point: `Color -1`, CTI NULL; loop: `255/0`, + `Comment ''`), colour in `Color` (Blue 6) with CTI NULL, No Color = 255, the + mirror in ROW order, rename touching only `Comment` (+ the USN pyrekordbox + stamps on every cue write — rekordbox's own leave it NULL, and it has + accepted ours), the 11th refused with nothing changed, delete removing the + row outright. - `test_onelibrary_adapter.py` — the third adapter against the same contract. Unlike the Rekordbox tests it needs **nothing installed and nothing plugged in**: it runs against `fixtures/onelibrary/`, a real rekordbox 7 export trimmed @@ -1307,10 +1357,15 @@ serialization path.** It enforces: new `PQTZ` keeps the marker where it was (rekordbox's own halving moved its anchor 6 ms; within 10 ms). Then fidelity on the demo drive: nothing on the drive before Save, only the touched tags change (in place, order kept), a - moved pad keeps colour and name, memory cues refused, swatches only, a + moved pad keeps colour and name, swatches only, a same-tempo marker collapses (a per-beat grid has no markers), another app's ANLZ write refused, an `.EXT` with no `PCO2` keeps every pad, a track with no - analysis files refuses. + analysis files refuses. And **memory cues against rekordbox's own edits** + (`fixtures/onelibrary-memory-edits`): add a cue, add a loop, add up to 10, recolour, + comment and delete, each replayed with `memory_cues` on `before/` and equal + to `after/` tag for tag (the `.DAT` hot list compared as a set — rekordbox + re-sorts it); then through the adapter on the demo drive: palette, cap, + NotFound, nothing before Save, and Save changing only the two memory lists. - `test_onelibrary_pdb.py` — the Device Library rebuild on Goober's own `export.pdb`: every track row reads (rows end at their last string; stale heap tails ignored), a no-op rebuild returns None and a no-op save leaves the @@ -1327,7 +1382,9 @@ serialization path.** It enforces: and files only at Save, renumbers playlists and prunes empty folders. - `test_import.py` — the import feature end to end: a drive's tracks into a temp copy of the real collection. Asserts the prep survives (hot cues keep their - PAD, memory cues fill spare ones, the flexible grid crosses intact, no + PAD, memory cues arrive as Traktor memory cues (`HOTCUE="-1"`; one on a + pad's START shows once, as the pad), a hot cue displaced with no spare pad + becomes a memory cue instead of being dropped, the flexible grid crosses intact, no companion cue is invented), that the existing 8,485 entries render byte-identically, that the job registry runs/fails/cancels, and that a cancelled import leaves **no orphaned audio and an untouched collection**. @@ -1590,6 +1647,16 @@ frontend at `http://localhost:5173`. load-bearing: 49 uncoloured cues and 18 *loops* also sit within 1 ms of a marker and must not be dragged or deleted. `backend/konduktor/beatgrid.py` is the single shared definition of all of this. + - **Memory cues are `CUE_V2`s on no pad** (`HOTCUE="-1"`) WITHOUT a `` + — a grid marker is also `HOTCUE="-1"`, and the `` child is the only + test (`projection.is_memory_cue`). Measured in Traktor 4.5 (kit M3, + 2026-10-16): any type, no limit, drawn on the waveform, reached with the + cue panel's ‹ ›, a name shown in the cue panel, and a Konduktor-written one + kept byte for byte. MAP puts a pad on one and leaves the memory cue at the + same START; Traktor draws ONE marker, so the projection shows the pad only. + Their id is content-derived (`m::::`). Traktor keeps + `CUE_V2` sorted by START, so the store INSERTS new cues in place + (`_insert_cue`) rather than appending. - **Playlist tree**: recurse `nml.playlists.node.subnodes.node`. A node's `.type` is `FOLDER`, `PLAYLIST`, or `SMARTLIST`. Smart playlists are rule-based and have no static entry list. `PlaylistNode.id` is the playlist's stable `UUID`; @@ -1787,9 +1854,11 @@ that number and nothing else — everything derives from it: that swap so `SaveBar` still saves collection edits. While a device's capabilities load the fallback is read-only, never the collection's — guessing "writable" for one frame would offer an edit bound for the wrong - library. Lossiness follows the settled rule: memory cues become hot cues in - spare pads (earliest first), cue colour is dropped (Traktor derives it from - type). + library. Lossiness follows the settled rule: memory cues stay memory cues + (Traktor's `HOTCUE="-1"`; until 2026-10-16 they were promoted to spare + pads), a hot cue whose pad is taken moves to a spare pad, else becomes a + memory cue; cue colour is dropped (Traktor derives it from type). Into + Rekordbox / OneLibrary only the first 10 memory cues cross (rekordbox's cap). - ✅ OneLibrary adapter — **reading and editing done**, at parity with the Rekordbox adapter (2026-10-01, [decisions](.claude/discussions/discuss-onelibrary-editing-2026-10-01.md)). A OneLibrary USB drive opens, projects, browses and searches: tracks, @@ -1798,8 +1867,7 @@ that number and nothing else — everything derives from it: files, each rule matching rekordbox's measured edit), the `export.pdb` rebuild on save, adding/removing tracks (the library places the audio), Save via a working copy, and "Open for editing…" on a Devices row — all verified in - rekordbox 7. Same gaps as Rekordbox: cover-art writing, memory-cue editing, - stem conversion. All format research — including the schema, which has no + rekordbox 7. Same gaps as Rekordbox: cover-art writing, stem conversion. All format research — including the schema, which has no public spec — is in [.claude/handoffs/onelibrary-adapter.md](.claude/handoffs/onelibrary-adapter.md). - 🟡 **Export/conversion** — **in progress.** Both the design AND the user flow are settled; see @@ -1962,7 +2030,8 @@ that number and nothing else — everything derives from it: 0x2C060E. **Parity with the OneLibrary target is done and verified in Rekordbox 7**: cue colours (palette code in `djmdCue.ColorTableIndex`, `Color` -1 — coloured loops included), memory cues (`store.add_memory_cue`, - export-only: the adapter still refuses memory-cue edits), and artwork + the same write as the adapter's memory-cue edit: colour in `Color` from the + memory palette, the first 10 per track), and artwork (`share/PIONEER/Artwork///artwork.jpg` fit to 800 px plus `_m` 240 / `_s` 80 letterboxed, `ImagePath` -> artwork.jpg). The exporter writes cues through `store.set_cue`/`add_memory_cue`, which share `_write_cue` with diff --git a/backend/fixtures/onelibrary-memory-edits/README.md b/backend/fixtures/onelibrary-memory-edits/README.md new file mode 100644 index 0000000..a26579c --- /dev/null +++ b/backend/fixtures/onelibrary-memory-edits/README.md @@ -0,0 +1,38 @@ +# Memory-cue edits rekordbox 7 made on a stick + +Analysis files of six tracks on a OneLibrary test stick written by +rekordbox, before and after **rekordbox 7 itself** edited their MEMORY cues +(kit M2, 2026-10-16; the stick was backed up first and restored afterwards). +`test_onelibrary_anlz.py` replays each edit with Konduktor's helpers on +`before/` and compares the memory lists with `after/` byte for byte. + +Only `PPTH`, `PQTZ`, `PCOB`, `PCO2` and `PQT2` are kept, byte for byte — the +waveforms were dropped, as in `onelibrary-goober/`. There is no database and +no audio: `exportLibrary.db` and both pdbs had NO row change for any of these +edits (memory cues on a stick live only in the analysis files). + +| File | Track | Edit (one per track) | +|---|---|---| +| `black-bloc` | Justin Hawkes – Black Bloc (VIP) | memory cue ADDED at 2:11.206 | +| `formula` | RL Grime & Juelz – Formula (IMANU Remix) | 4-beat memory LOOP added at 1:20.378 | +| `lift-it` | Tian – Lift It (Hexa Remix) | 8 memory cues added (2 → 10, the cap) | +| `wtf` | Result – WTF (Phace Remix) | the memory loop at 1:53 recoloured Blue | +| `sell-my-soul` | Bensley, Justin Hawkes & Kumarion – Sell My Soul | comment "Loopy" on the memory loop at 1:18 | +| `doomed` | Nemean – Doomed | the memory loop at 2:01 DELETED | + +What they show (the full write-up is in +`.claude/discussions/discuss-memory-cues-2026-10-16.md`, kit M2): +- `.DAT` `PCOB` memory list: a new entry is PREPENDED; every entry has status 0 + and bytes 24–27 = previous / next index in the list (`ffff` at the ends), so + any add or delete relinks the whole list; the header i32 at offset 20 is + count − 1. +- `.EXT` `PCO2` memory list: a new entry is APPENDED in rekordbox's compact + 44-byte form; the others stay byte-identical. The `.EXT`'s `PCOB` memory list + stays empty. +- When rekordbox rewrites a `.DAT` (any memory add or delete), it ALSO + re-sorts the untouched hot-cue `PCOB` into ascending pad order (an export + writes it highest pad first); the entries themselves are unchanged. + Konduktor changes only the list it edits, so the test compares that tag's + entries regardless of order. +- Colour: `PCP2` byte 28, 1-based (Blue = 7), 0 = none. Comment: UTF-16BE + NUL + at byte 44, `len_comment` at 40. Neither touches the `.DAT`. diff --git a/backend/fixtures/onelibrary-memory-edits/after/black-bloc.DAT b/backend/fixtures/onelibrary-memory-edits/after/black-bloc.DAT new file mode 100644 index 0000000000000000000000000000000000000000..73bc20de36d48b477c528758dcc9ac3408defbd1 GIT binary patch literal 6872 zcma*s3p~~LAII_EIfqhGN+~fS5hJB6U6e}~rd-MxBTMN*N~CE@#OR_dT{NXkW4f@6 zlu}BXQdVP1Sw>1JX_{`v{D01C|2-bN{2!11kMG6rdEVdiJs#)rIG^+Txy-e35ClO> z5Qf)?qeT4a>E(xui<`YTQ5D-)V%sg433kFNVWqG}@R#?Y;+YS`S)kZf37?3)jSwR0 zav@ag|7j}(KOsyA66Jky?0L*`F*8E27Z!@?KylSj@h?-c*$OMfbBn}t%vXu?5yEJ} zU2qUw1S4ULxJs}vUJzVd-MqxT4HJL&iK8GW^>i{-L1H&noR|pGo>8({koAnxhk`=S zs9=jL9>RNd;!2))pOd)qAiUoyT;)1GzzA23!v{9vYSZz-2k;?p@uBYcusnSDAN$i> zfoomGwGD8c81f_PaXl-1JWQo)S_@OQt%O-JHmqHwc&__)cqc``o! zSKPt{e=i%i?2AuYicc=Zr;fm_HsI6l;?@&!o87o=8$M$$KJzF(yEksX78)i!yM3 zDZXR@zVs}9@Oh6h&SL1y^MZTPCk`0AN>NID+cjfZ*TYft0hL-2JW_@_7U^(Od+ zEqLTZJjxc2K7?=T#A7}2&kFE(HGK0be9Luwn-QK6hi`Ah6Rq*j58ylB;=A1O-Ff(4 zRXjNe-***HF~Il7;0NmQgI4&V6g=$}o<1Kxd;-rp*9#!DCDmoMUF z+W3_S{Avw;Z32FMCtlHt-*CilX5p2Jc-2Du$Mg6tP5gE^UQ>+JEL zGw=o}e%}{wJc~aZhBt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*dcb{(8<~KKR`;_)kOed!cw8^|h?t z6mQsy-+zQZm_hzw8s5}}KlZ|#PvK7o<1MT4XBGH!WBiwRyzK%0s}0_M5P#W$zxKf2 zb|oQwBc1j|3p%eBWO zg6y#%)&-`nP?^m+N_T;*KTq u{fpn({(Zf_yzW19J!^`^(PKd-epbrF&x^ku|Lge#$$$S}g2}%<-+ur>G0md@ literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/after/black-bloc.EXT b/backend/fixtures/onelibrary-memory-edits/after/black-bloc.EXT new file mode 100644 index 0000000000000000000000000000000000000000..f60afa9c065c6ca39e9d8c9222d1b099c7f1d020 GIT binary patch literal 2532 zcmeH{y-EW?5Xb*}7Ztk{3L=83f@1tY8{3$|L=abvVxyp9A$~-RA8+6j1cX!;Vrk`L z_y#r>7FJ?mWuyPu7_zsQ+r7WH>&5(2SPjk^n$QfrPM1DhjQlAYov!_$;l7Z9G<+TpMHYBa#8PFc8XJ_RuyUZ zo!SsUE|6)OL*rVcWpOid*l;~uHRI~#qVyB{wOjg0lJI1P%1u#ckl>sc8wUJj&s2ZE z*%P(uSG+fGUftlcVXH;l@nqJks*gxJblWC5c6@5pjmaSe;*K4w?+D`F?C!nwX>r*=tBlj1VGANF7RbLnv!Wltd;JSt8Vpp|KR%ql^ru zDEm4XjD768!PvKv`|G^saqnZ6KW-ksbIzlu-}`$!{BvH%*sEiAP19^O&AOrfY|#Id zJeq!tMqdy8g@t}4=vSoXq`7Mm+GuT@Hq`VOrT?a{{whqrBD5I&v7`RC#%Uw9DE;y8 zHcAWDqP1{cy!3@|{Ti&_W2ZUlS7&`8!t}c#T2uXbjOMIq#@@bx`pMRsW;H>7*0gdZ z59+vPaDS`6sHUlsXG4T0CC}=xR;uK=R2{r@EMDdeUakplHXSej3tsUnywZH!{622s zhF4yKS9y+G_Qb1Z;Z`4U>%O?nX1qpO+;$LNb0=QA3T_vQ*V%{Hv&HL2;|)&WjT+(h zQ*eh1c;n`HlO){n7VhMV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-memory-edits/after/doomed.EXT b/backend/fixtures/onelibrary-memory-edits/after/doomed.EXT new file mode 100644 index 0000000000000000000000000000000000000000..cf775faf55f8100461814f7f67fff8d6e771a30d GIT binary patch literal 886 zcmbVKJxc>Y5Pf@>E7DmAkziqEA*f)QwDBw=__0M20)k-BLQFhKVyv|ie~Vopzal@v z(ti=(OoEgWWoE<;0I=pYx>1+^hL?4HUk>C+S+^HQf z(xmr5BzU2%an%s_7|>>OU3Bn_9y1qY=n*&Evx9x&gbazsZgIf*2^GM{m&dHUMZ6QD zE0}Tk*f;1?HL65JXjXC#;WvV-5AijgGG<>vQ)KxSG+3<$S>w<}%gW=tsT^m))e+_S- vy!d?0<1ONAUA=D3+d9kRMR{dfd25TiL|40F@1_S{Fy9tX%B{8hC^DHJ_mppB literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/after/formula.DAT b/backend/fixtures/onelibrary-memory-edits/after/formula.DAT new file mode 100644 index 0000000000000000000000000000000000000000..37251d922eca337f1af26c9e0aaa6396c3cd977c GIT binary patch literal 6148 zcma*rd05TMAHeZB=Oo!8lw=K2l#nGtT9iVYLJ@_CN>M55${J;l$WqE0vhVwrt*qJi zosd1Ucjuh<{XM_u`rZ3Hzxh71e7~>rnKS2m=8u{2=xOI7gs3fqp_Z%_@=}+Y>Eh|J+4MwWIWR16Z)B20>x z=ppJ0XE9m~m-j)k-B@N(0RI72?KS@dhjKhNZYkKfLiC+*BVo8;v);fSa4+7Sr+OPw^J^c+2H@s~>o4U%bs< z@2_1|+&Ua@e-^hfBfeuI-sv%JYm0YThTDC`9eU%A+i|BVxN|7p?F{bP81FtA@9_Y4 z>x8>6#yvjcUcK;MTX3IBc<&K-pOd(6L)>oy-tR8%-vJ-62p{+n5A?tXZN!I^$AgC9 zLv!(9V|@4@_=sD0XgfS?0Y36Q9^rg zPw0+M$i^pW;gbXLDTnaHTKKeBeEL;9xfMQRHa_zeKD!$}XEi=giKh&}=kLc;4e^E1 z_@V-Qu_e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3L z1pL|^{6>5HW-5N`1AfOHzng>KFNZ%Eia$J#Kdy&AiN~Mb#Gkjt3+Ll6-r=u$;6>~3 zH`@5y!T7r)_=h_9$FX?vHT<&`UNRT|@*4l0`Ss<8doWdG_F#{Xk4Yb zqH$Fjxweq=TBSV;FZ&WN=Zu$Mg;x}KC4XFZA6}&ft`~(@y@Xe9j_W7m2G4OrN4#bh zZuASU-4Cy`8?RR#uRjVmK94tShBumyn>@jr*x{xbxY>8SSzp|IC*E8Sw;YML$j4im z;#O1f){pSEws^axxb+vjgAZ=A4ewML?;MKTp2qD=aQjKP!+pGKN8D*K?)(XN@xom< z<2@?kJ%{6NCvlGkxMu?HbqDuukNYgddw<0Hy5qh%c)xOZ|Dm}5aeQEXJRlwqyonEP ziw~KP2ff3G^~8hM<0G{3kimH95qxAFJbWA;aUCCRg-6cCqh8}|(6e4Va zx-IQ*>9;tg24%1RjmypZKjKvX6Q{^6`RBO5jb9z6j#d6P4o!FJUnfVbkcSQO|B-ub ih1^g7mi{eH-6wH!Po<|#wq^uzC_ADjsH))5!cV?C!tN zsgsklqobSPQlB@+NldR$6Q1P#$o=vr7hNq^0L%gY9cRTZqiI@4`!uGhXX+8F2+_hN zI*849&B!)(*fr{?A)53s|9bg>^uOwJp{+OKD1phHN_25pA9gB`TmyR&omd z2fW^!*d}fb7EhR_$vVc@=*$q(;jDznJtQV~bV3DxxKfGL7Dslnl8)(ceZy7#FH^6> zExll3vcvTZ7yUsVw>Ug?sv7S)T$OT@hdk~S-v3c=cIWssyZa+|4p082dU}N#G_$wM ox8mH=_}a6Ka|Qy)1@80CkbN`BY;l)leOm9vH`HeGTV;@1Kly%bdjJ3c literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/after/lift-it.DAT b/backend/fixtures/onelibrary-memory-edits/after/lift-it.DAT new file mode 100644 index 0000000000000000000000000000000000000000..263bdc61a18158a51178bcf6c954428c4340d7bc GIT binary patch literal 5200 zcmb8z30Tef9>?+D`ISl`BF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_$UY)3SDbDI$N*BFLgH*js!>hPaPuzG3ZgLkl^}@|o;&q;&x8B{l|E#?{SB&xZ`}h%}w0N4R5y; zZ~qW?_QhRR;~ih(ormIGHsIY1@$RGW9%Xn>bKEro?^TZXw#NHR!QGDF?yYf;MBMW% z?(Ks6q~U$5a9>y4ZwcQ2F7EGz5BwY-^b4*Xga;JkL#pw>U_59mKFkyk4#z{j#z!>5 zM@HkLD)BKkcxVD1b`lSF!pF|V$6dlFbi*SS;1h4+k#2a@GCcYb9_xq4t;Q#lKV>}m zQ%)s+%IUT68KbFBAb-l4+(nMwYX^U0rbp*OxLkN%6vpE8U5DYMC+GKc&rmxj=PStdd{qqn^U0rbHThE(kUwQ1`BN6PiDc6xd<$Cg`+(7=6B_Gg#({lQ6 zCV$GUoBS#FOr-zb3i_9mKjl91r>r1< z%KZ-bfh77@p3`~__EgUwny68(hDHs8YISJ6w1H}^p09|WzhBp@&eV_S+d>TMs9P)h z%kj55sYliI&$^Pa|3{s{f7NM1j=#I^?f#|inUC%;RipOb_Mr#eyHh*Xu>UTn-resn z@B5EBwUE>~N7txM6;apLv_^I67czDBYid+yAZk(9!mCDghQf$CtEw8+)e^?kSWoEgsk{F)Dl@2if)D7=`G0-x!sP9JD_*|q^?n0_q8xev literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/after/lift-it.EXT b/backend/fixtures/onelibrary-memory-edits/after/lift-it.EXT new file mode 100644 index 0000000000000000000000000000000000000000..46f28522d29eeb18dce1f7e4594c8cd5ed8bb363 GIT binary patch literal 2312 zcmbVL4NR6*6n@TgP(#xgBb5gnmN=MqDUkfBh46U&NRpT z$uWjG=Fb@UGcte1OvlJFMw%nj7$Y5#*_^W+simFwb2R#d?W_CloO|AL&VBB=_qoTF znKBi?Q-J?tHj90Z_6(QHonc0R$u^U@V4m`EX4w>K%qr?bHWf~D_*u0d4?B;sU98q4_+8%8gik&T>>VxNCdWMr{{y6&yGLRCR z#X+<^9G`O^IVOJp!gVU?GoF29r#?Y1(+gKUxH7xdQ?D0pVgr0e_QItH7oRNZ4|nW? z*S)G5_}2?p9^$?l+aIn!I{!nxy?4$C&+bDXxpUCrQYL%~yPw{7YOlxZmIki9H{x{$ z12A0RZhvR!UE|B#2Y0-a{}6Y0aDTY{=LW9!J$F>6@42C=zUPMT^F23msPDNkg}&#; zo$ohyhTG{u>v2D)2OZ++%#hSSOy7l{&HUm!a|dWaYON>cgxh5-iuIrl;#@f_gYlYH z@g~!y8n=+4Wo%}M6ypp+buJHch|EI+{574`(k*d#Uz;_A#d1bMv0M-95YCeZ@y9G( z&vwSi26P}^-{KjD%5r>#F*=V8^p{zv(RPjF2I-J^Y}7CHX_m-Y8G{wNpT99fYVbRz z=>~Q%UN)i=30lIl43hacf?+z9yX3Y^$H&^C@!Tk#l7RQLLH#*jj>s_N>Mq{qblHs_ zWa)45xEBn6xFtcG!=v`9Eg^)r2(xpGv7W1((mClh27 zt{_oYvW4MNidIDE0v;nJ6SexIzQE0LMH2C$wrDs@rBx!ZOn0+~nNo{8$kNTc%1N>X zU3gJT*~AgD5XbR^X0lf9NEY_!Rh`5w(j~Dd(_=b6A2^Q2J%jnOUaVvj3#5Np4V|)EfPlg4NP zPGO|FStHkEGPdgljp7<mw`6E}>}B|ObhQivvu)@;@rqd7PL zKb^u&a#3PXp{I2e3#CbdQKa=s=EwnKG)>ESkug$%ONiA%V>DQb(2Njcbf?^qG*s#L z8p8^?WQ?xUCJknh92Y;#(Ve`(G^xT(r0ZH<=0sVCAB@r2Jjg*Z2Zu0N(^zGUrlVRf j>qKL;SwaTr(Vy^~77fs&NnCH;{r`G&pWKoRr$_$=F7%+e literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/after/sell-my-soul.DAT b/backend/fixtures/onelibrary-memory-edits/after/sell-my-soul.DAT new file mode 100644 index 0000000000000000000000000000000000000000..c0b35bc6387f3097911e31de7c9a6811f47676ca GIT binary patch literal 5952 zcma*r2~^JM9>DSc`#efDYRVL$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t@xfxyJ+6Rd;& zHcD)`{&>^2z{EhRom=-9VF}<_pwpnbA-C$@?l-9Jm|8q= z<)FIi>k2RX_YhQf@Xc3(y1M^mP+j`EsQ$92y5Z>fzx~Rsx@jdn)x~2ET-N>9ZvU3} z+CLTV`7J^B-;%mmNau55civ6R9dGXcE`nEr-i;Noy1=X+pCK6jkL$pURQC+#L}-z_ z&04gla3>Rgv;8c8)c01|bVcZ#`B{F=c5LQ2Nx?x3))=mrYm$vZZPKxvCi^80qxF4W zWw@-sSxncd+{aiMg-_92!&o34MrLTOkt1cB^uj=WgJD*GfBqqKxqjLb)ekuR{8 zF)|X{&`U$POwJfNUu%pUAzLLJ(VEB8a#7~usFB0Dg<&!P@9HUbbG9_19g}pkk^N*1 zE`gfH25FOI>^AaI78?mH)gx@>c&WxA4Aa%@mK(Ad?Rr9!SS9rmkBz#4e=tYd(1lsL zi*+0#<=BBp&1Ru=$_yOR0~*INsgww;)D=9(>5_?NJZoeH`$!Si>5rPi3~7=v*rD6? zVIxa%6$>?;$2nT2U>{8K+ zk8zYtMlA*zxmGSq29{}~j^re%k%36mcX-LjJp6zuI)Qr_EeY6yhm6dXlSaBh%1eWIQ*K5`|)IV;589u#w~SBLyR6HGbAkoykMeB1xz+GJ>n*Jgy^0 z>%Galyvc8|%bWb2H+iQwxlB9FP>bT;7q>ZO+N2Ub{R0vXMi)g%bQ&1O?DX&=Q6;X u+~Q5H^d?&dc$1sG$raw@b>3vl0B`bsZ*r+OdAT#$Wq>!i#G9P&O#Ta!=gFY} literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/before/black-bloc.DAT b/backend/fixtures/onelibrary-memory-edits/before/black-bloc.DAT new file mode 100644 index 0000000000000000000000000000000000000000..c22ca518fca0f959024bc9ff4cb465edb12f302f GIT binary patch literal 6816 zcma*s3pmyH1IO{7bB+>`QX-~E#FA2$E=rV`a)~ikSxOfrB2CkUWl1SZ7fmVCm=a@j zQA!t0iPe}AW2BUlrs-zPe$M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SN&H`vF!iI_3q<8f1i+@`1iSg?ti;HBQ}lRKXO+5i8e#)LY_vPa!aXW z9ywHSiW-iMuF|tjt3;{biaLXH?iNv{4(^q4hzp!>XO**@De_Jdc^vR|iPS1rvy?2# z^c~UHv@5ien8FTLpfQa(QqHgh=-hgiv5itRMTvZI=$tOlW?o2BVidD0dkXFw)I(Zq ztdiJ8>}<8Ee-;87}Ux|IcmJ98V@ECs1=Z@|N!83*61iR^PHytSbFhk+$Ee z4FTi=sg60cuZ3EAqaZ!P9vqY&k-(UR7`X-N6k?oXGZTOtA6iHx%$}$%x9+?<%jyQ7 zZCkD3jwdrtLw$tWf!kh^Wk;tr?3gT)FYd^(N545S7U^jW<^HJ&VO+WO8y4CNppPuP=nd#%+^h0l`fBi4} E1|G~30ssI2 literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/before/doomed.DAT b/backend/fixtures/onelibrary-memory-edits/before/doomed.DAT new file mode 100644 index 0000000000000000000000000000000000000000..21501fe3b5096deb3e0c2dfa787066dfc0566cc0 GIT binary patch literal 6238 zcma*rc~s5$AII_U{k(0VCWfXcvTI08jK~t9kX)7Y3!$tfQ4*P??2+vkLlcTnlx1Wa zOOc(yVC-Yx4aU9=e&2ha=gj&2{N{JgFXt}jK73!F+wq6{yvAxnm`V(vYmaN~RH5biOi_%7DqqRZi`xyO|p8B&0{T8Lg>G$pQzcpGLrp4&@ z|82vyP%T!A)Wug{h}3Tb^lKb7XZ_YeUx+flHc)G%KaSK~HO<%~AXq=yR?}?8>W`XM z#&oBSX$H?X`jf9TWqLG3X<~X*hqMx=#}YO0lJR({(|DPNxW#0=>~DDaZ*j{xxYa$} z+5@k!7_ayYuhbQOjz-@ctcI)t}rE&ZIxWjh5dPUqZ9IsJ~*RscJ$KrL4lZJTw9i+lLQwzz4_TLyqIa>fzxN@rVm}G;Cu_#z*C@k%`XBc9Ok1Gf0VQTU-F_>o%p(eLnMXYk|B_=&0b z$*cG&H~jQG{LFp)YWV*`g+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end/fixtures/onelibrary-memory-edits/before/formula.DAT b/backend/fixtures/onelibrary-memory-edits/before/formula.DAT new file mode 100644 index 0000000000000000000000000000000000000000..c437f13810bad6cfef4eff655d9023a0d6d604bd GIT binary patch literal 6092 zcma*r2~DQ^?Vu*+qVN$$A zFVRFeiLqj&ybhA}<}$fT4U)f_AnRr_Im*bf(xYWtpu9E~E~2;W$4&O!MD`IRZKQ}5 zCZe^hMF>kFJUqSqw1cN4Vi*HsX;L@Tg&U^ie#f5gr?dkH3z`wZr4*@3=>LEO-K0ZAbpK%pWX^YRCgU@=6&vC}*uEXam@zg>1f&+M3U3^hA zzPJcqVvaAJg)e)7XY{~Vtj1TC;h6*R)%)w-&%~{{)FH4#P4mw zA5_L4j=&$~<4+9mrxWpKxA7Mp@s|tnSMTv+H~dWwUQ!W%Hw=G&6#v)={}hLRzJZsv z$G^_UzrDqO^u&K=;lIn{WkWQs5Qj9bP}bMDLKUlVMY*fER$IKnT)bj2UfCJ1vJS7N z#I*p9~3tMU3}c*B8sqkVW2J=`D?Z+ZbYG{udQ z@#fEPV|(0W72fhEZt9Dh?Z(Y(;T92in{&9O3EnOVZ~qwY*d4dZz&m}%t^46!cHrG= z;5K1+_X6Cm1#UkTcX)t1cEz2R;?AYGt2f?r8{WGb?luZ{KZSc5;$D;SKKF2+&UoL& zc)w4$uP5%e86Q{$_aA`|%Eto?@W6@qklXk$D?BI-AO0Q>cEd;J;2{<9&>%eQ7#`jT zkBGy^+`uE-<58)2bO|2Q6OYZpCzQwIhT!ps@re!agjjsiRXnjRK4mUGwHQxw!Kbgs zla+YNV0>mCKD!=1XBl?+Af%wvW_;NiwBNAV6 z5npA7XC~vTpW$om@pY^4^}p~eKRkOko>L3YjlegZ!?(1=w@$~mJ;rx*$9HDnyT0Rl z`r&(b;`?>*17Ubx0e+|jet0T=ZTZ#*5?eH#hK-_V_#2*NXQg_{U!Or)>O7dE!fl;9n2p-y7gR#^XP);lJDB zWpg#I6vY}>DqS?LRIS&zvb+k{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w-jjo literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/before/lift-it.DAT b/backend/fixtures/onelibrary-memory-edits/before/lift-it.DAT new file mode 100644 index 0000000000000000000000000000000000000000..387e99b53cdd23f69d5af2c06cd73e3075581907 GIT binary patch literal 4752 zcma*r4_J=(9>?+D^D7|~k>qb7lth%t()5oaJgHWx&?-u)DCv}?sZ}dPji{yJ2oY*( z7?zHj|9|HHaAcVOV;F{`-Ouyhahwfk9-oN|m>ALREt)AfQDTL@Q zgwZnPs8W73v-YD_`+6vg_R9EN8JS|Ra20VPRwRlD?VO;T@le*uB2-ulGvOnR5g&l;yu5>d;N-= zPsDp~#QO@|A^`7Kg%8ljEyHlDy|{HJe9&y%rV$^~3%5KY#{JIY{)6#=96azk9^`-r7vLfH@o8@O^in+ZIUY6<58sH-Q2r-0-=mp< zcw{v`s|_9vQ=Q}Bvvd}|xLG92Hw58u%l zuZqR1zr%N$;WdB5Yrn^L4a9e6;Crs%d+qUkOY!};@w(CYfmL|@FZjW6c*A8#eeO7{t_Hy&@f9&hyq*Z0HQY{T2N z#0{q7hP&_%9dM&rc*lR>#@+GG^Kg^nxM@GU>q5NSMZAYC-ZK~P^&@WnKHmFtyw5}2 zVhrA|4DbH}w^ZX+n{jK24+_Fgl-mZrsNR_l?H= z4&wgZ@ql@F;0ZjaKOUTphg`&`+2Yf4@z5K1m?Iv(0*`oz&m4nCmf=w^@n~;6rUH+Z zcw7)3zZ0L^4o{eYCw_}3nc(x|@#MpJN^d+h6<=@`PqW4seu}666JPWmp0Nziyo+Z! z~#z4Z;s(;q}+>gYV%D%kaj#_#qeka0!0o8Gg(QKfVD! z@fJVjkDuOwpJ|Ps4aLvx!7p^gFUH`P8t}_K@heIA)sy(O0eI6V`1K#~8^iFMdHAiH z`0Y{not60ANBI4*_=7L;hri*ECgYE{;7@e%r@{EM8vMBd{$eKnvJQV`ioc$Nzd3@x z?SnTj(7F`ov@WHM)}>CC)}`(>TyF&4ayj1W9i>m3rn*1q?$)B=>{3%O~ z@inpZFC%}-wd7B^j{GUtlRxDKE3RLjLH~{9Pq~@=DJ#gIatrxWR(?SLZL8?No%|`Q z$e*&B{3*X8f65wP`qx&{e;4^v?k0cAJ>*Zhm;5RBMbUqMJ^ky*pYj0tQ`VC|)Rgyx(ww5l=XAzFEE3Ou1%YtR43 z^rt$hC8g`TI#C(^f7EIA@!!`I{)7Lz?%n=#v^7F#uBrOdJ|OKrgi31nuRL=q_wYx} UyTkvg)7*jfzLj@1f3=U_0g(RWLjV8( literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/before/lift-it.EXT b/backend/fixtures/onelibrary-memory-edits/before/lift-it.EXT new file mode 100644 index 0000000000000000000000000000000000000000..95807e3f0e782b8f51650cac96e85d87d6694858 GIT binary patch literal 1960 zcmbVL3ryEl6#l;NppKcw82K2PkwY2m5H=3bt*8T0Adw%EK``vTTcWx*v zeHehpfp*({rhkDBk5DKl(~T&XH7<+L4;d)LEEM6ju%6?dOt*`Xi>DEX987m>mU~}v zJ;S9CZ@Ny$OiadH6nLa%O&k(^$BVur&++0gEUbI~gBOQUj$GjJVkDriTd(6;Ae50k z*mLRP5^@PLyXM$gOY{#>Gcd?}yv- z&a17mdhl;6T>g#wa=-iGM&j&$$hW2D_$++7?x{HxaLK+O!|T)1r`|oSs`TL8TOzIQ z-~f&b+`Qi%TJ}8592%Ju^oaLhM9?EaVt$Lj$oSp$O+@&t&%bqdl;vksgkwSY40~d> z?X)(Uz};+%SFBuDG?W`~6`59|I>mA}j-Z=O&~CNkL{uZvhH3*ZFbVHkoyBT4kFXo& z*lug5iL7QMM%xmdQ4*J;3CZ?`j;I^w;7fG3iKTfOyAF&h|VTq{hZ;m%NLzV@saR!STf9nm%o&|;2P{f?tYNe>x>C(bc#o^2E8p$yLgKuvCWz-RjZuQG_1Dc)=LX`!Wo@rTlI%VaXbEWMpx;A(zqHI zG00}CM$w#xgNU(F+Rod|K_y^mTJ4M`;BBk1Xieim#vtDry{#NpdQT3w1v;SwE<_{x z*mNCqM)Pq9oh(Nid69##)=pT07P66jP->srW6I|tXLO9M(a##hwYY?ITj-4TVJS`` z(HX52I0jXay`Xix_CJK)^eU?BFgNrbyfju*%gIWWztyga7Kq%sZJ`9WjKX?R^W_wWg+Si>x{1F zWe!2PeP@X(<0)r!vDI2v6>>i#Fy7YdvWBo6S1{BT>9qQDF}`<3$7!e9a6ERQtqoDR pGddI-?6mcFM(Y^+fH(Rhp0UCQywOxG@z?$T-sm=7WoGb3{{q+DYk2?w literal 0 HcmV?d00001 diff --git a/backend/fixtures/onelibrary-memory-edits/before/sell-my-soul.DAT b/backend/fixtures/onelibrary-memory-edits/before/sell-my-soul.DAT new file mode 100644 index 0000000000000000000000000000000000000000..c0b35bc6387f3097911e31de7c9a6811f47676ca GIT binary patch literal 5952 zcma*r2~^JM9>DSc`#efDYRVL$c%u-dnlwTtEtI07rkbJ@N=l8QBxQuiHW-Y3vUAI* z!C(s6*TLAwzGWTzWF6f9`+o0n?wvdLoLlF=^nQAN{hxC>?>XN$td~y@MNw=NrD0d~ zs!_jnXZ=@LSVW+DW3C=m>QSb+D1J(YlCBI_2IMLKUcd6=;q2#D%A0<=O6eUYN z|F@+niOL9Ns4Bkt30X>-dd*dw6s;1Zif&bkIz_7lDhcYmR8_OopIWL%uzqENIzL7K z3|hrmeKlPDjWqRJtMpRmXq9&A^sf|mMG5O25u-k{wW3&Q)vKZy=}uy)qVapF-dHO_ zchwA2r0yyXDRp$$IxTR6JlyaUZsd#`7vUyX@OqxO=?vWLE^h9NTP(!u|AAZf!mU=~ z4c_6_QFxyA53!JTj7 zE?scfxwzXS+&vI)UxItQ!aMZAJxlRUb@0ypaIa1H=VrKfGTyZs_icpxW#aya@a`?} zfYEs1X*{SM9$bX?yn=^#;-NF~uzPqPKRkRP9`Oer*$agLPd<*PIO0PJ@znG9P|ngG8Xw;XpOA?c9mXfwy8*r< z4zJ#f@A??uJs97!6W`Yu-=BpaID#Lt#}DV@N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mV?d00001 diff --git a/backend/konduktor/adapters/onelibrary/adapter.py b/backend/konduktor/adapters/onelibrary/adapter.py index 46919d8..30c165b 100644 --- a/backend/konduktor/adapters/onelibrary/adapter.py +++ b/backend/konduktor/adapters/onelibrary/adapter.py @@ -26,7 +26,7 @@ from ...core.capabilities import Capabilities from ...core.model import GridMarker, HotcueChip, PlaylistNode, Track, TrackCues from ...core.pathmap import PathMapping, common_dir_prefix from ...core.query import TrackIndex -from ..rekordbox import palette +from ..rekordbox import memory_palette, palette from ..rekordbox.cue_types import WRITABLE_CUE_TYPES from ...exporter import MANIFEST_NAME from . import capabilities as caps @@ -457,10 +457,8 @@ class OneLibraryAdapter: ) -> TrackCues: self._require_writable("Editing cues") if role != "hotcue": - # Preserved-but-uneditable, exactly as in the Rekordbox adapter. - raise Unsupported( - "Memory cues are shown but cannot be edited — only hot cues are writable" - ) + # A memory cue has no slot to set; it has its own commands. + raise InvalidCommand("Memory cues are added with add_memory_cue, not set_cue") self._check_cue_type(cue_type) self._store.set_cue(track_id, slot=slot, start_sec=start_sec, cue_type=cue_type, length_sec=length_sec, name=name) @@ -494,6 +492,53 @@ class OneLibraryAdapter: self._store.place_cues(track_id, cues, overwrite=overwrite) return self._refresh_cues(track_id) + # ---- commands: memory cues -------------------------------------------- + @staticmethod + def _memory_byte(color: str | None) -> int: + if color is None: + return 0 + code = memory_palette.code_for(color) + if code is None: + raise InvalidCommand(f"{color!r} is not one of rekordbox's memory cue colours") + return memory_palette.anlz_byte(code) + + def add_memory_cue( + self, + track_id: str, + *, + start_sec: float, + cue_type: str, + length_sec: float = 0.0, + name: str | None = None, + color: str | None = None, + ) -> TrackCues: + self._require_writable("Editing cues") + self._check_cue_type(cue_type) + self._store.add_memory_cue(track_id, start_sec=start_sec, cue_type=cue_type, + length_sec=length_sec, name=name, + color_id=self._memory_byte(color)) + return self._refresh_cues(track_id) + + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> TrackCues: + self._require_writable("Editing cues") + self._store.rename_memory_cue(track_id, cue_id, name) + return self._refresh_cues(track_id) + + def set_memory_cue_type(self, track_id: str, cue_id: str, cue_type: str) -> TrackCues: + # rekordbox has one point type, so there is nothing to choose; a memory + # cue is a cue or a loop by its length. + raise Unsupported("rekordbox memory cues have no type to change") + + def set_memory_cue_color(self, track_id: str, cue_id: str, color: str | None) -> TrackCues: + self._require_writable("Editing cues") + self._store.set_memory_cue_color(track_id, cue_id, self._memory_byte(color)) + return self._refresh_cues(track_id) + + def delete_memory_cue(self, track_id: str, cue_id: str) -> TrackCues: + self._require_writable("Deleting cues") + self._store.delete_memory_cue(track_id, cue_id) + return self._refresh_cues(track_id) + # ---- commands: beatgrid ----------------------------------------------- @staticmethod def _markers_from(markers: list) -> list: diff --git a/backend/konduktor/adapters/onelibrary/capabilities.py b/backend/konduktor/adapters/onelibrary/capabilities.py index b524361..a185c28 100644 --- a/backend/konduktor/adapters/onelibrary/capabilities.py +++ b/backend/konduktor/adapters/onelibrary/capabilities.py @@ -36,8 +36,8 @@ from ...core.capabilities import ( SaveCapabilities, TrackCapabilities, ) -from ..rekordbox import palette -from ..rekordbox.cue_types import WRITABLE_CUE_TYPES +from ..rekordbox import memory_palette, palette +from ..rekordbox.cue_types import MAX_MEMORY_CUES, WRITABLE_CUE_TYPES # Pads A-H. Unlike `djmdCue.Kind`, the ANLZ slot number is a dense 1-based index, # so the bank really is 1..8 (see `cues.py`). @@ -61,10 +61,12 @@ def capabilities_for( editable=True, hotcue_slots=HOTCUE_SLOTS, slot_labels="letter", - # OneLibrary carries memory cues, as Rekordbox does: projected and - # preserved, NOT editable (the two-platform rule, as in Rekordbox). + # Memory cues, editable as in Rekordbox — in the ANLZ files, the + # way rekordbox 7 edits them on a stick (measured, kit M2). memory_cues=True, - max_memory_cues=None, + max_memory_cues=MAX_MEMORY_CUES, + memory_color="palette", + memory_palette=list(memory_palette.SWATCHES), types=WRITABLE_CUE_TYPES, color="palette", palette=[palette.hex_for(code) for code in palette.SWATCHES], diff --git a/backend/konduktor/adapters/onelibrary/cues.py b/backend/konduktor/adapters/onelibrary/cues.py index bc356b0..5cb392d 100644 --- a/backend/konduktor/adapters/onelibrary/cues.py +++ b/backend/konduktor/adapters/onelibrary/cues.py @@ -37,7 +37,7 @@ from __future__ import annotations import logging from ...core.model import CuePoint -from ..rekordbox import palette +from ..rekordbox import memory_palette, palette log = logging.getLogger(__name__) @@ -112,6 +112,13 @@ def _to_cue(entry, *, with_color: bool, editable: bool = False) -> CuePoint | No slot = None if role == "memory" else hot_cue - 1 comment = getattr(entry, "comment", None) + if role == "memory": + # A memory cue's colour is byte 28 (`memory_palette`), not the hot-cue + # code + RGB tail, which stays zero on one. + color = (memory_palette.hex_for(memory_palette.from_anlz_byte( + int(getattr(entry, "color_id", 0) or 0))) if with_color else None) + else: + color = _color(entry) if with_color else None return CuePoint( name=(str(comment) or None) if comment else None, type="loop" if length > 0 else "cue", @@ -119,16 +126,26 @@ def _to_cue(entry, *, with_color: bool, editable: bool = False) -> CuePoint | No start=start_ms / 1000.0, length=length, slot=slot, - color=_color(entry) if with_color else None, - # Hot cues are editable on a drive opened for editing (the caller says - # so). MEMORY cues never are — preserved-but-uneditable, as in the - # Rekordbox adapter (the two-platform rule). - editable=editable and role == "hotcue", - readonly_reason=None if editable and role == "hotcue" else "platform_managed", + color=color, + # Editable on a drive opened for editing (the caller says so), memory + # cues included; browsing a device is read-only. + editable=editable, + readonly_reason=None if editable else "platform_managed", grid_marker=None, + id=memory_cue_id(entry) if role == "memory" else None, ) +def memory_cue_id(entry) -> str: + """A memory cue's `CuePoint.id`: its STORED position, kind and loop end. + + Content-derived, so it is the same on every read and in both lists (`PCOB` + in the .DAT, `PCO2` in the .EXT, which order the same cues differently); + an index would not be. Two memory cues identical in all three are one cue + to `_dedupe` already, so the first match is the one meant.""" + return f"m:{int(entry.time)}:{_entry_kind(getattr(entry, 'type', ENTRY_CUE))}:{int(getattr(entry, 'loop_time', NO_LOOP))}" + + def _entries(anlz, tag_type: str) -> list: """Every entry of every `tag_type` tag in one parsed ANLZ file. diff --git a/backend/konduktor/adapters/onelibrary/export.py b/backend/konduktor/adapters/onelibrary/export.py index a5ed86f..4c8dc9e 100644 --- a/backend/konduktor/adapters/onelibrary/export.py +++ b/backend/konduktor/adapters/onelibrary/export.py @@ -44,7 +44,8 @@ from pathlib import Path from ...core.export import ExportPayload, ExportTrack, WrittenLibrary from ...core.cue_colors import effective_color from ..rekordbox import anlz_writer as W -from ..rekordbox import artwork, palette, timebase +from ..rekordbox import artwork, memory_palette, palette, timebase +from ..rekordbox.cue_types import MAX_MEMORY_CUES from ..rekordbox.beatgrid import beats_from_markers from ..rekordbox.projection import render_key from .capabilities import capabilities_for @@ -359,15 +360,28 @@ class OneLibraryExporter: too far along. """ out: list[dict] = [] - for cue in (item.cues.cues if item.cues else []): + memory = 0 + for cue in sorted(item.cues.cues if item.cues else [], key=lambda c: c.start): is_loop = cue.type == "loop" or cue.length > 0 - # A hot cue carries what Konduktor SHOWS — stored colour, else the - # type's (blue cue, green loop) — as a rekordbox palette CODE, which - # is what rekordbox draws from; "unset" draws its own defaults. A - # memory cue keeps rekordbox's own "unset". - code, rgb = palette.code_for(cue.color if cue.role == "memory" else effective_color(cue)) + is_memory = cue.role == "memory" or cue.slot is None + if is_memory: + # rekordbox keeps 10 (earliest first; the rest are dropped, per + # the lossiness rule). A memory cue's colour is PCP2 byte 28 from + # its own 8-colour palette; the hot-cue code + RGB stay zero. + if memory >= MAX_MEMORY_CUES: + continue + memory += 1 + code, rgb = 0, (0, 0, 0) + color_id = memory_palette.anlz_byte(memory_palette.nearest_code(cue.color)) + else: + # What Konduktor SHOWS — stored colour, else the type's (blue cue, + # green loop) — as a rekordbox palette CODE, which is what + # rekordbox draws from; "unset" draws its own defaults. + code, rgb = palette.code_for(effective_color(cue)) + color_id = 0 out.append({ - "hot_cue": 0 if cue.role == "memory" or cue.slot is None else cue.slot + 1, + "color_id": color_id, + "hot_cue": 0 if is_memory else cue.slot + 1, "kind": 2 if is_loop else 1, "time_ms": int(round(timebase.to_pioneer(cue.start, off) * 1000)), "loop_ms": (int(round(timebase.to_pioneer(cue.start + cue.length, off) * 1000)) diff --git a/backend/konduktor/adapters/onelibrary/memory_cues.py b/backend/konduktor/adapters/onelibrary/memory_cues.py new file mode 100644 index 0000000..c0b9567 --- /dev/null +++ b/backend/konduktor/adapters/onelibrary/memory_cues.py @@ -0,0 +1,102 @@ +"""Memory-cue edits on a track's two analysis files, the way rekordbox 7 makes them. + +Pure functions over parsed `AnlzFile`s, so they are pinned byte for byte +against rekordbox's own edits (`fixtures/onelibrary-memory-edits`, kit M2, +2026-10-16) without a drive; the store adds the drive, the time base and Save. + +A stick keeps memory cues ONLY in the analysis files — the database and both +pdbs keep every row — in two lists kept in OPPOSITE orders: + + * `.DAT` `PCOB` memory: a new cue is PREPENDED, and the whole list is + relinked (`anlz_writer.relinked_memory_pcpts`: status 0, prev/next + indexes) on any add or delete; header field = count − 1. + * `.EXT` `PCO2` memory: a new cue is APPENDED in the compact 44-byte form; + every other entry keeps its bytes. The `.EXT`'s own `PCOB` memory list + stays empty. + +A colour is `PCP2` byte 28 and a name the `PCP2` comment; neither touches the +`.DAT`. A cue is addressed by `cues.memory_cue_id` (stored time, kind, loop +end), which is the same in both lists. +""" +from __future__ import annotations + +from ..rekordbox import anlz_file +from ..rekordbox import anlz_writer as W +from .cues import memory_cue_id + +DAT_ORDER = ("PPTH", "PVBR", "PQTZ", "PWAV", "PWV2", "PCOB") +EXT_ORDER = ("PPTH", "PWV3", "PCOB", "PCO2") + + +def entries(f: anlz_file.AnlzFile, kind: str) -> list[bytes]: + """The raw entries of a file's `kind` (PCOB / PCO2) MEMORY list.""" + i = f.find(kind, anlz_file.LIST_MEMORY) + return anlz_file.raw_entries(f.tags[i]) if i is not None else [] + + +def count(ext: anlz_file.AnlzFile) -> int: + return len(entries(ext, "PCO2")) + + +def _matches(entry: bytes, cue_id: str) -> bool: + return memory_cue_id(anlz_file.decode_entry(entry)) == cue_id + + +def _put(dat, ext, pcob: list[bytes] | None, pco2: list[bytes] | None) -> None: + if pcob is not None: + dat.put("PCOB", W.pcob_tag(anlz_file.LIST_MEMORY, W.relinked_memory_pcpts(pcob)), + list_kind=anlz_file.LIST_MEMORY, after=DAT_ORDER) + if pco2 is not None: + ext.put("PCO2", W.pco2_tag(anlz_file.LIST_MEMORY, pco2), + list_kind=anlz_file.LIST_MEMORY, after=EXT_ORDER) + + +def add(dat, ext, *, kind: int, time_ms: int, loop_ms: int | None, beats: int | None, + name: str | None = None, color_id: int = 0) -> None: + """Add one memory cue (kind 1 cue, 2 loop): prepended to the `.DAT`'s list, + appended — compact unless named — to the `.EXT`'s.""" + pcp2 = W.pcp2_compact_entry(kind=kind, time_ms=time_ms, loop_ms=loop_ms, + beats=beats, color_id=color_id) + if name: + pcp2 = anlz_file.entry_with_comment(pcp2, name) + pcpt = W.pcpt_entry(hot_cue=0, kind=kind, time_ms=time_ms, loop_ms=loop_ms) + _put(dat, ext, [pcpt] + entries(dat, "PCOB"), entries(ext, "PCO2") + [pcp2]) + + +def _index(ext, cue_id: str) -> tuple[list[bytes], int | None]: + pco2 = entries(ext, "PCO2") + return pco2, next((n for n, e in enumerate(pco2) if _matches(e, cue_id)), None) + + +def rename(ext, cue_id: str, name: str | None) -> bool: + """Rename in the `.EXT` only; False if no such cue.""" + pco2, i = _index(ext, cue_id) + if i is None: + return False + pco2[i] = anlz_file.entry_with_comment(pco2[i], name) + _put(None, ext, None, pco2) + return True + + +def recolour(ext, cue_id: str, color_id: int) -> bool: + """Byte 28 of the cue's `PCP2` entry, nothing else; False if no such cue.""" + pco2, i = _index(ext, cue_id) + if i is None: + return False + pco2[i] = anlz_file.entry_with_color_id(pco2[i], color_id) + _put(None, ext, None, pco2) + return True + + +def delete(dat, ext, cue_id: str) -> bool: + """Out of both lists (the `.DAT`'s relinked); False if no such cue.""" + pco2, i = _index(ext, cue_id) + if i is None: + return False + del pco2[i] + pcob = entries(dat, "PCOB") + j = next((n for n, e in enumerate(pcob) if _matches(e, cue_id)), None) + if j is not None: + del pcob[j] + _put(dat, ext, pcob if j is not None else None, pco2) + return True diff --git a/backend/konduktor/adapters/onelibrary/projection.py b/backend/konduktor/adapters/onelibrary/projection.py index 50e2213..b42286a 100644 --- a/backend/konduktor/adapters/onelibrary/projection.py +++ b/backend/konduktor/adapters/onelibrary/projection.py @@ -114,7 +114,7 @@ def to_track_cues(cues: list, grid_markers: list[GridMarker]) -> TrackCues: `cues` are already generic — see `store.cues` for why that boundary sits where it does — so this is the assembly point rather than a translation. - Nothing here is editable: a OneLibrary drive is read-only in Konduktor, and - `capabilities.writable` says so at the library level. + Each cue already says whether it is editable (the store knows whether the + drive was opened for editing or is only being browsed). """ return TrackCues(grid_markers=grid_markers, grid_locked=False, cues=list(cues)) diff --git a/backend/konduktor/adapters/onelibrary/store.py b/backend/konduktor/adapters/onelibrary/store.py index 67b2c63..8c16570 100644 --- a/backend/konduktor/adapters/onelibrary/store.py +++ b/backend/konduktor/adapters/onelibrary/store.py @@ -54,8 +54,9 @@ from ...core.edit_journal import EditJournal from ...core.grid_edit import ReplaceGridCommands from ...core.model import CuePoint from ... import paths -from . import beatgrid, cues as cue_reader +from . import beatgrid, cues as cue_reader, memory_cues from ..rekordbox import anlz_file, palette, timebase +from ..rekordbox.cue_types import MAX_MEMORY_CUES from ..rekordbox import anlz_writer as W from ..rekordbox import beatgrid as rb_beatgrid from .layout import DriveLayout @@ -916,6 +917,60 @@ class OneLibraryStore(ReplaceGridCommands): self._replace_hot(track_id, hot, None, None) self._journal.record("cue", "delete", track_id, f"slot:{slot}") + # ---- memory cues ------------------------------------------------------- + # The list edits — and what rekordbox was measured doing — are in + # `memory_cues`; here: the drive, the time base, the cap and the journal. + MAX_MEMORY_CUES = MAX_MEMORY_CUES # rekordbox stops storing at 10, silently (measured) + + def _memory_files(self, track_id: str): + dat, ext = self._editing(track_id) + self._ensure_pco2(dat, ext) + return dat, ext + + def add_memory_cue(self, track_id: str, *, start_sec: float, cue_type: str, + length_sec: float = 0.0, name: str | None = None, + color_id: int = 0) -> None: + """Add a memory cue (a memory loop with a length) the way rekordbox does. + + `color_id` is `PCP2` byte 28 (`memory_palette.anlz_byte`), 0 = none.""" + from .export import _loop_beats + + if start_sec < 0: + raise InvalidCommand("A cue cannot be before the start of the track") + dat, ext = self._memory_files(track_id) + if memory_cues.count(ext) >= self.MAX_MEMORY_CUES: + raise InvalidCommand( + f"rekordbox keeps at most {self.MAX_MEMORY_CUES} memory cues per track" + ) + is_loop = cue_type == "loop" and length_sec > 0 + off = self._offset(track_id) + time_ms = int(round(timebase.to_pioneer(start_sec, off) * 1000)) + loop_ms = int(round(timebase.to_pioneer(start_sec + length_sec, off) * 1000)) if is_loop else None + grid = self.anlz_grid(track_id) + beats = (_loop_beats(start_sec, length_sec, list(zip(grid[2], grid[1], grid[0]))) + if is_loop and grid else None) + memory_cues.add(dat, ext, kind=2 if is_loop else 1, time_ms=time_ms, loop_ms=loop_ms, + beats=beats, name=name, color_id=color_id) + self._journal.record("cue", "add", track_id, "memory") + + def _memory_edit(self, track_id: str, cue_id: str, op: str, edit) -> None: + dat, ext = self._memory_files(track_id) + if not edit(dat, ext): + raise NotFound(f"No memory cue {cue_id!r} on this track") + self._journal.record("cue", op, track_id, "memory") + + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> None: + self._memory_edit(track_id, cue_id, "modify", + lambda _d, ext: memory_cues.rename(ext, cue_id, name)) + + def set_memory_cue_color(self, track_id: str, cue_id: str, color_id: int) -> None: + self._memory_edit(track_id, cue_id, "modify", + lambda _d, ext: memory_cues.recolour(ext, cue_id, color_id)) + + def delete_memory_cue(self, track_id: str, cue_id: str) -> None: + self._memory_edit(track_id, cue_id, "delete", + lambda dat, ext: memory_cues.delete(dat, ext, cue_id)) + def hot_slots(self, track_id: str) -> set[int]: """Occupied 0-based slots (pending edits included).""" return {c.slot for c in self.cues(track_id) if c.role == "hotcue" and c.slot is not None} diff --git a/backend/konduktor/adapters/rekordbox/adapter.py b/backend/konduktor/adapters/rekordbox/adapter.py index 4f67706..045deeb 100644 --- a/backend/konduktor/adapters/rekordbox/adapter.py +++ b/backend/konduktor/adapters/rekordbox/adapter.py @@ -27,7 +27,7 @@ from ...core.model import GridMarker, PlaylistNode, Track, TrackCues from ...core.pathmap import PathMapping, common_dir_prefix from ...core.query import TrackIndex from . import capabilities as caps -from . import palette, projection, timebase +from . import memory_palette, palette, projection, timebase from ...core import add_analysis from .store import RekordboxStore @@ -303,12 +303,8 @@ class RekordboxAdapter: ) -> TrackCues: self._require_writable("Editing cues") if role != "hotcue": - # Rekordbox is the ONLY platform with memory cues, so under the - # two-platform promotion rule they stay preserved-but-uneditable: - # they are projected and shown, never written. - raise Unsupported( - "Memory cues are shown but cannot be edited — only hot cues are writable" - ) + # A memory cue has no slot to set; it has its own commands. + raise InvalidCommand("Memory cues are added with add_memory_cue, not set_cue") self._check_cue_type(cue_type) self._store.set_cue( track_id, slot=slot, start_sec=start_sec, cue_type=cue_type, @@ -339,6 +335,53 @@ class RekordboxAdapter: self._store.delete_cue(track_id, slot) return self._refresh_cues(track_id) + # ---- commands: memory cues -------------------------------------------- + def _memory_code(self, color: str | None) -> int | None: + if color is None: + return None + code = memory_palette.code_for(color) + if code is None: + raise InvalidCommand(f"{color!r} is not one of rekordbox's memory cue colours") + return code + + def add_memory_cue( + self, + track_id: str, + *, + start_sec: float, + cue_type: str, + length_sec: float = 0.0, + name: str | None = None, + color: str | None = None, + ) -> TrackCues: + self._require_writable("Editing cues") + self._check_cue_type(cue_type) + self._store.add_memory_cue( + track_id, start_sec=start_sec, cue_type=cue_type, length_sec=length_sec, + name=name, color_code=self._memory_code(color), + ) + return self._refresh_cues(track_id) + + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> TrackCues: + self._require_writable("Editing cues") + self._store.rename_memory_cue(track_id, cue_id, name) + return self._refresh_cues(track_id) + + def set_memory_cue_type(self, track_id: str, cue_id: str, cue_type: str) -> TrackCues: + # rekordbox has one point type, so there is nothing to choose; a memory + # cue is a cue or a loop by its length. + raise Unsupported("rekordbox memory cues have no type to change") + + def set_memory_cue_color(self, track_id: str, cue_id: str, color: str | None) -> TrackCues: + self._require_writable("Editing cues") + self._store.set_memory_cue_color(track_id, cue_id, self._memory_code(color)) + return self._refresh_cues(track_id) + + def delete_memory_cue(self, track_id: str, cue_id: str) -> TrackCues: + self._require_writable("Deleting cues") + self._store.delete_memory_cue(track_id, cue_id) + return self._refresh_cues(track_id) + def place_cues(self, track_id: str, cues: list, *, overwrite: bool = False) -> TrackCues: self._require_writable("Placing cues") for cue in cues: @@ -521,20 +564,25 @@ class RekordboxAdapter: def _place_imported_cues(self, track_id: str, cues) -> None: """Hot cues on their own pads; memory cues — and a hot cue with no - free pad — as memory cues. Colour as the nearest palette swatch.""" + free pad — as memory cues, up to rekordbox's 10 (earliest first; the + rest are dropped, per the lossiness rule). Colour as the nearest swatch + of the palette the cue lands in: a hot cue's 16, a memory cue's 8.""" taken: set[int] = set() + memory = 0 for cue in sorted(cues.cues or [], key=lambda c: c.start): cue_type = "loop" if getattr(cue, "length", 0) else "cue" - code, _rgb = palette.code_for(cue.color) common = dict(start_sec=cue.start, cue_type=cue_type, length_sec=getattr(cue, "length", 0.0) or 0.0, - name=getattr(cue, "name", None), color_code=code or None) + name=getattr(cue, "name", None)) slot = cue.slot if cue.role == "hotcue" else None if slot is not None and 0 <= slot < caps.HOTCUE_SLOTS and slot not in taken: - self._store.set_cue(track_id, slot=slot, **common) + code, _rgb = palette.code_for(cue.color) + self._store.set_cue(track_id, slot=slot, color_code=code or None, **common) taken.add(slot) - else: - self._store.add_memory_cue(track_id, **common) + elif memory < self._store.MAX_MEMORY_CUES: + self._store.add_memory_cue( + track_id, color_code=memory_palette.nearest_code(cue.color), **common) + memory += 1 def remove_tracks(self, track_ids: list[str]) -> int: # What goes with a track was measured in Rekordbox 7 — see the store. diff --git a/backend/konduktor/adapters/rekordbox/anlz_file.py b/backend/konduktor/adapters/rekordbox/anlz_file.py index d8c4dee..f5753fa 100644 --- a/backend/konduktor/adapters/rekordbox/anlz_file.py +++ b/backend/konduktor/adapters/rekordbox/anlz_file.py @@ -158,6 +158,9 @@ class CueEntry: color_green: int | None = None color_blue: int | None = None len_entry: int = 0 + #: `PCP2` byte 28: a MEMORY cue's colour, 1-based, 0 = none (also present + #: in the compact 44-byte form, which has no hot-cue colour tail). + color_id: int = 0 def raw_entries(tag: Tag) -> list[bytes]: @@ -197,6 +200,35 @@ def entry_with_colour(entry: bytes, code: int, rgb: tuple[int, int, int]) -> byt return entry[:at] + bytes([code & 0xFF, *rgb]) + entry[at + 4:] +def entry_color_id(entry: bytes) -> int: + """A `PCP2` entry's byte 28 — a MEMORY cue's colour, 1-based, 0 = none.""" + return entry[28] if len(entry) > 28 and entry[:4] == b"PCP2" else 0 + + +def entry_with_color_id(entry: bytes, value: int) -> bytes: + """A `PCP2` entry with ONLY byte 28 changed — what rekordbox does to recolour + a memory cue (measured: that one byte, in any entry length, compact too).""" + return entry[:28] + bytes([value & 0xFF]) + entry[29:] + + +def entry_with_comment(entry: bytes, name: str | None) -> bytes: + """A `PCP2` entry renamed, every other byte kept. + + Measured on a memory loop (rekordbox 7, 2026-10-16): the comment goes in at + byte 44 as UTF-16BE plus a NUL, `len_comment` (byte 40) counts it, and the + entry GROWS by exactly that much — 88 -> 100 for "Loopy" — the colour tail + and padding following it unchanged. A compact 44-byte entry has no tail, so + it first takes a full entry's (4 colour bytes + 40 zeros); that case is + unmeasured.""" + if len(entry) < 44: + raise AnlzError("A PCP2 entry shorter than 44 bytes has no comment field") + old_len = struct.unpack_from(">I", entry, 40)[0] + tail = entry[44 + old_len:] if len(entry) > 44 else bytes(44) + comment = (name.encode("utf-16-be") + b"\0\0") if name else b"" + head = entry[:8] + struct.pack(">I", 44 + len(comment) + len(tail)) + entry[12:40] + return head + struct.pack(">I", len(comment)) + comment + tail + + def entry_without_loop_beats(entry: bytes) -> bytes: """A `PCP2` entry with its loop length in beats cleared to 0/0 — what rekordbox does to every loop when the grid changes (measured: 32/1 -> 0/0), @@ -245,7 +277,8 @@ def _pco2(data: bytes) -> list[CueEntry]: hot_cue, = struct.unpack_from(">I", data, off + 12) kind = data[off + 16] time, loop = struct.unpack_from(">II", data, off + 20) - e = CueEntry(hot_cue=hot_cue, type=kind, time=time, loop_time=loop, len_entry=n) + e = CueEntry(hot_cue=hot_cue, type=kind, time=time, loop_time=loop, len_entry=n, + color_id=data[off + 28] if n > 28 else 0) if n >= 44: e.loop_numerator, e.loop_denominator, len_comment = struct.unpack_from(">HHI", data, off + 36) colour_at = off + 44 + len_comment diff --git a/backend/konduktor/adapters/rekordbox/anlz_writer.py b/backend/konduktor/adapters/rekordbox/anlz_writer.py index 681e437..ad78956 100644 --- a/backend/konduktor/adapters/rekordbox/anlz_writer.py +++ b/backend/konduktor/adapters/rekordbox/anlz_writer.py @@ -315,7 +315,7 @@ def flat_preview_tags() -> list[bytes]: def pcp2_entry(*, hot_cue: int, kind: int, time_ms: int, loop_ms: int | None, rgb: tuple[int, int, int] | None, beats: int | None, code: int = 0, - comment: str | None = None) -> bytes: + comment: str | None = None, color_id: int = 0) -> bytes: """One `PCP2` entry, byte-for-byte as rekordbox 7 writes it. Two constants in here are rekordbox's, not the documented struct's: the @@ -328,6 +328,9 @@ def pcp2_entry(*, hot_cue: int, kind: int, time_ms: int, loop_ms: int | None, Konduktor's reader and pyrekordbox's agree with. No reference cue carries one, so that detail is documented rather than measured. The entry stays the exported 88 bytes unless the name needs more. + + `color_id` is byte 28: a MEMORY cue's colour, 1-based (`memory_palette`), + 0 = none. A hot cue's colour is the code + RGB tail instead. """ comment_bytes = (comment.encode("utf-16-be") + b"\0\0") if comment else b"" red, green, blue = rgb or (0, 0, 0) @@ -336,7 +339,7 @@ def pcp2_entry(*, hot_cue: int, kind: int, time_ms: int, loop_ms: int | None, ">4sIIIBxHIIBB6xHHI", b"PCP2", 16, length, hot_cue, kind, 1000, int(time_ms), NO_LOOP if loop_ms is None else int(loop_ms), - 0, 1, beats or 0, 1 if beats else 0, len(comment_bytes), + color_id & 0xFF, 1, beats or 0, 1 if beats else 0, len(comment_bytes), # The colour is the palette CODE, then RGB: rekordbox draws from the code # (`palette`); a code of 0 draws its default colour whatever the RGB says. ) + comment_bytes + struct.pack(">4B", code & 0xFF, red, green, blue) + bytes( @@ -344,6 +347,41 @@ def pcp2_entry(*, hot_cue: int, kind: int, time_ms: int, loop_ms: int | None, ) +#: rekordbox's COMPACT `PCP2` entry: the first 44 bytes of a full one — no +#: comment and no colour tail. What rekordbox 7 appends when it ADDS a memory cue +#: on a stick (measured 2026-10-16, `fixtures/onelibrary-memory-edits`). +PCP2_COMPACT_LEN = 44 + + +def pcp2_compact_entry(*, kind: int, time_ms: int, loop_ms: int | None, + beats: int | None, color_id: int = 0, hot_cue: int = 0) -> bytes: + """A compact 44-byte `PCP2` entry, byte for byte as rekordbox 7 writes one + for a memory cue it adds: the same fields as `pcp2_entry` up to + `len_comment` (0), including the `1000` and the `1` after byte 28.""" + return struct.pack( + ">4sIIIBxHIIBB6xHHI", + b"PCP2", 16, PCP2_COMPACT_LEN, hot_cue, kind, 1000, + int(time_ms), NO_LOOP if loop_ms is None else int(loop_ms), + color_id & 0xFF, 1, beats or 0, 1 if beats else 0, 0, + ) + + +def relinked_memory_pcpts(entries: list[bytes]) -> list[bytes]: + """A `PCOB` MEMORY list's entries with their link fields rewritten, as + rekordbox 7 leaves them after ANY add or delete (measured 2026-10-16, + `fixtures/onelibrary-memory-edits`): status (bytes 16-19) 0, and bytes 24-27 the + previous / next entry's INDEX IN THE LIST, 0xFFFF at either end — so every + entry changes when one is added or removed. rekordbox's exports agree on any + list of two or more; a lone exported entry is status 4, 0xFFFF/0xFFFF.""" + n = len(entries) + out = [] + for i, e in enumerate(entries): + prev = i - 1 if i > 0 else 0xFFFF + nxt = i + 1 if i < n - 1 else 0xFFFF + out.append(e[:16] + struct.pack(">I", 0) + e[20:24] + struct.pack(">HH", prev, nxt) + e[28:]) + return out + + def pcpt_entry(*, hot_cue: int, kind: int, time_ms: int, loop_ms: int | None) -> bytes: """One `PCPT` entry, byte-for-byte as rekordbox 7 writes it. @@ -378,18 +416,25 @@ def pco2_tag(cue_type: int, entries: list[bytes]) -> bytes: def _pcob(cue_type: int, chosen: list[dict]) -> bytes: - return pcob_tag(cue_type, [ + entries = [ pcpt_entry(hot_cue=c["hot_cue"], kind=c["kind"], time_ms=c["time_ms"], loop_ms=c["loop_ms"]) for c in chosen - ]) + ] + if cue_type == 0 and len(entries) > 1: + # A memory list of two or more is linked, status 0 — what rekordbox's + # own exports (two test sticks) and edits hold. A lone entry keeps the + # status 4 / 0xFFFF form the reference export pins. + entries = relinked_memory_pcpts(entries) + return pcob_tag(cue_type, entries) def _pco2(cue_type: int, chosen: list[dict]) -> bytes: return pco2_tag(cue_type, [ pcp2_entry(hot_cue=c["hot_cue"], kind=c["kind"], time_ms=c["time_ms"], loop_ms=c["loop_ms"], rgb=c.get("rgb"), beats=c.get("beats"), - code=c.get("code", 0), comment=c.get("comment")) + code=c.get("code", 0), comment=c.get("comment"), + color_id=c.get("color_id", 0)) for c in chosen ]) diff --git a/backend/konduktor/adapters/rekordbox/capabilities.py b/backend/konduktor/adapters/rekordbox/capabilities.py index da130e1..d232b9b 100644 --- a/backend/konduktor/adapters/rekordbox/capabilities.py +++ b/backend/konduktor/adapters/rekordbox/capabilities.py @@ -30,8 +30,8 @@ from ...core.capabilities import ( SaveCapabilities, TrackCapabilities, ) -from . import palette -from .cue_types import WRITABLE_CUE_TYPES +from . import memory_palette, palette +from .cue_types import MAX_MEMORY_CUES, WRITABLE_CUE_TYPES # Rekordbox's addressable hot cue bank. The pads are labelled A-H; the stored # slot number is NOT a plain letter index (see cue_types), so the adapter keeps @@ -55,18 +55,19 @@ def capabilities_for( writable=not cloud_synced, readonly_cause="cloud_synced" if cloud_synced else None, cues=CueCapabilities( - # Hot cues are writable: djmdCue rows plus the contentCue JSON - # mirror, kept in step. MEMORY cues stay preserved-but-uneditable — - # Rekordbox is the only platform that has them, and the two-platform - # promotion rule says a one-platform concept does not become an - # editing feature. + # Hot AND memory cues are writable: djmdCue rows plus the + # contentCue JSON mirror, kept in step (memory cues: measured + # 2026-10-16, kit M1). editable=True, hotcue_slots=HOTCUE_SLOTS, slot_labels="letter", - # Rekordbox is the only platform with memory cues, so they are - # projected and PRESERVED but not editable (two-platform rule). memory_cues=True, - max_memory_cues=None, # unlimited + # rekordbox stops storing at 10, silently; the store refuses the 11th. + max_memory_cues=MAX_MEMORY_CUES, + # A memory cue's colour is its own 8-colour palette (`Color`, not + # `ColorTableIndex`) — see `memory_palette`. + memory_color="palette", + memory_palette=list(memory_palette.SWATCHES), # Both cue types write; Rekordbox has no fade/load types. types=WRITABLE_CUE_TYPES, # A hot cue's colour is one of rekordbox's 16 swatches (all diff --git a/backend/konduktor/adapters/rekordbox/cue_types.py b/backend/konduktor/adapters/rekordbox/cue_types.py index 62c8387..383ac05 100644 --- a/backend/konduktor/adapters/rekordbox/cue_types.py +++ b/backend/konduktor/adapters/rekordbox/cue_types.py @@ -36,6 +36,10 @@ has an out-point, so a loop can sit in a hot cue slot or be a memory cue. from __future__ import annotations MEMORY_KIND = 0 +#: rekordbox stores at most this many memory cues per track — on the computer +#: AND on a stick — and enforces it SILENTLY (measured 2026-10-16: MEMORY simply +#: stops storing), so Konduktor refuses the next one itself, with a reason. +MAX_MEMORY_CUES = 10 # Rekordbox has no fade-in/fade-out/load cues; those are Traktor-only. CUE_TYPES = ["cue", "loop"] diff --git a/backend/konduktor/adapters/rekordbox/export.py b/backend/konduktor/adapters/rekordbox/export.py index 129e5f9..de074e5 100644 --- a/backend/konduktor/adapters/rekordbox/export.py +++ b/backend/konduktor/adapters/rekordbox/export.py @@ -58,7 +58,7 @@ from sqlalchemy import text from ...core.export import ExportPayload, ExportTrack, WrittenLibrary from ...core.cue_colors import effective_color -from . import new_content, palette +from . import memory_palette, new_content, palette from . import timebase from .beatgrid import beats_from_markers from .capabilities import capabilities_for @@ -199,24 +199,30 @@ class RekordboxExporter: from .adapter import RekordboxAdapter adapter = RekordboxAdapter(library) - # The store, not the adapter's commands: the adapter refuses memory cues - # (editing them in a user's library is off-limits) and takes no colour. - # Building a NEW library is neither an edit nor lossy by choice, so the - # exporter writes both — through the same `_write_cue` every edit uses. + # The store, not the adapter's commands: the adapter's set_cue takes no + # colour and its memory-cue command takes only a swatch. A NEW library + # maps any source colour to the nearest one instead — through the same + # `_write_cue` every edit uses. store = adapter._store try: for item in payload.tracks: track_id = ids.get(item.source_id) if track_id is None or not item.cues: continue - for cue in item.cues.cues: + memory = 0 + for cue in sorted(item.cues.cues, key=lambda c: c.start): if cue.role == "memory" or cue.slot is None: - # rekordbox's own "unset" for a memory cue with no colour. - code, _rgb = palette.code_for(cue.color) + # rekordbox keeps 10 (earliest first; the rest are + # dropped, per the lossiness rule). Colour: the memory + # palette's nearest swatch, else rekordbox's "unset". + if memory >= store.MAX_MEMORY_CUES: + continue store.add_memory_cue( track_id, start_sec=cue.start, cue_type=cue.type, - length_sec=cue.length, name=cue.name, color_code=code or None, + length_sec=cue.length, name=cue.name, + color_code=memory_palette.nearest_code(cue.color), ) + memory += 1 continue # What Konduktor SHOWS — stored colour, else the type's (blue # cue, green loop) — as a palette code, which is what diff --git a/backend/konduktor/adapters/rekordbox/memory_palette.py b/backend/konduktor/adapters/rekordbox/memory_palette.py new file mode 100644 index 0000000..7e32d13 --- /dev/null +++ b/backend/konduktor/adapters/rekordbox/memory_palette.py @@ -0,0 +1,95 @@ +"""rekordbox's MEMORY-cue colours — a palette of its own, not the hot cues'. + +rekordbox 7 offers a memory cue eight colours plus "No Color" (Pink, Red, +Orange, Yellow, Green, Aqua, Blue, Purple — the same eight names as its track +colours), against sixteen swatches for a hot cue. MEASURED 2026-10-16 (kits M1 / +M2 in `.claude/discussions/discuss-memory-cues-2026-10-16.md`), by colouring +memory cues one per colour, in that order, in rekordbox itself: + + * `master.db`: the code is `djmdCue.Color`, **0-based** in menu order (Pink 0 + … Purple 7) and `ColorTableIndex` stays NULL — the opposite of a hot cue, + which keeps its code in `ColorTableIndex` with `Color = -1`. "No colour" is + `-1` on a cue never coloured and **255** on one set back to "No Color". + * the ANLZ `.EXT`: `PCP2` byte 28, **1-based** (Blue = 7), 0 = none. The + hot-cue colour tail after the comment stays zero on a memory cue. + +The RGB values are DISPLAY colours only — nothing stores them. They were +sampled from the dots in rekordbox 7's own colour menu (a screenshot), so they +are what rekordbox shows, not what it writes. +""" +from __future__ import annotations + +import colorsys + +from .palette import _parse + +#: code (0-based, master.db) -> display RGB, in rekordbox's menu order. +COLOURS: list[tuple[str, tuple[int, int, int]]] = [ + ("Pink", (0xE5, 0x77, 0xEF)), + ("Red", (0xE1, 0x31, 0x21)), + ("Orange", (0xEA, 0xA3, 0x49)), + ("Yellow", (0xF2, 0xE2, 0x57)), + ("Green", (0x65, 0xDB, 0x41)), + ("Aqua", (0x55, 0xBB, 0xF1)), + ("Blue", (0x1F, 0x4E, 0xED)), + ("Purple", (0x8A, 0x1D, 0xED)), +] + +#: `master.db`'s `Color` for a memory cue set back to "No Color" (measured); +#: a cue never coloured keeps -1. Both read as uncoloured. +CLEARED = 255 + +#: Below this saturation a colour is white/grey, which the palette cannot show. +_GREY = 0.2 + + +def _hex(rgb: tuple[int, int, int]) -> str: + return f"#{rgb[0]:02X}{rgb[1]:02X}{rgb[2]:02X}" + + +#: The swatches a user can pick — what `capabilities.cues.memory_palette` offers. +SWATCHES: list[str] = [_hex(rgb) for _name, rgb in COLOURS] + + +def hex_for(code: int | None) -> str | None: + """`#RRGGBB` for a stored 0-based code; None for -1, 255 or anything unknown.""" + if code is None or not 0 <= code < len(COLOURS): + return None + return _hex(COLOURS[code][1]) + + +def code_for(color: str | None) -> int | None: + """The 0-based code of an EXACT swatch (a user's pick), else None.""" + rgb = _parse(color) if color else None + return next((i for i, (_n, value) in enumerate(COLOURS) if value == rgb), None) + + +def nearest_code(color: str | None) -> int | None: + """The swatch nearest in hue to any `#RRGGBB` — for a colour arriving from + another platform (an import, an export). None for no colour or a grey.""" + exact = code_for(color) + if exact is not None: + return exact + rgb = _parse(color) if color else None + if rgb is None: + return None + h, _l, s = colorsys.rgb_to_hls(*(v / 255 for v in rgb)) + if s < _GREY or max(rgb) - min(rgb) < 40: + return None + + def hue_gap(i: int) -> float: + ph = colorsys.rgb_to_hls(*(v / 255 for v in COLOURS[i][1]))[0] + d = abs(ph - h) + return min(d, 1 - d) + + return min(range(len(COLOURS)), key=hue_gap) + + +def anlz_byte(code: int | None) -> int: + """`PCP2` byte 28 for a 0-based code: code + 1, and 0 for none.""" + return 0 if code is None else code + 1 + + +def from_anlz_byte(value: int) -> int | None: + """The 0-based code from `PCP2` byte 28 (0 = none).""" + return value - 1 if 1 <= value <= len(COLOURS) else None diff --git a/backend/konduktor/adapters/rekordbox/projection.py b/backend/konduktor/adapters/rekordbox/projection.py index cbb558f..f4900a8 100644 --- a/backend/konduktor/adapters/rekordbox/projection.py +++ b/backend/konduktor/adapters/rekordbox/projection.py @@ -7,8 +7,8 @@ from __future__ import annotations from ...core import musical_key from ...core.model import CuePoint, GridMarker, HotcueChip, Track, TrackCues -from . import beatgrid, palette, timebase -from .cue_types import cue_type, role_and_slot +from . import beatgrid, memory_palette, palette, timebase +from .cue_types import cue_type, kind_for, role_and_slot # Rekordbox names keys musically ("Abm", "F", "Ebm") — but its key table also # holds whatever text a track's key TAG carried when it was imported, so a real @@ -140,10 +140,10 @@ def to_track_cues(cue_rows: list, grid: tuple | None, time_offset: float = 0.0) `editable` says whether the adapter will accept a command on THIS cue, which is the only thing the UI gates on. Every hot cue is editable, loops included. - **Memory cues are not**: Rekordbox is the only platform that has them, so - under the two-platform promotion rule they are shown and never written. A cue - sitting on the reserved `Kind` occupies no pad and is projected the same way, - because that is how Rekordbox itself displays one. + So is every memory cue (`Kind` 0), addressed by its row id (`CuePoint.id`) + since it has no pad. A cue sitting on the reserved `Kind` 4 occupies no pad + either and is SHOWN as a memory cue, because that is how Rekordbox itself + displays one — but it is not one, so it is not editable. """ markers: list[GridMarker] = [] if grid is not None: @@ -158,7 +158,9 @@ def to_track_cues(cue_rows: list, grid: tuple | None, time_offset: float = 0.0) length = 0.0 if out_msec is not None and out_msec > 0: length = max(0.0, (out_msec - in_msec) / 1000.0) - editable = role == "hotcue" + memory = role == "memory" + # Kind 4 (reserved) displays as a memory cue but is not one. + editable = not memory or getattr(c, "Kind", None) == kind_for("memory", None) cues.append( CuePoint( name=(getattr(c, "Comment", None) or None), @@ -169,15 +171,27 @@ def to_track_cues(cue_rows: list, grid: tuple | None, time_offset: float = 0.0) start=timebase.from_pioneer(in_msec / 1000.0, time_offset), length=length, slot=slot, - color=_cue_color(c), + color=_memory_cue_color(c) if memory else _cue_color(c), editable=editable, readonly_reason=None if editable else "platform_managed", grid_marker=None, + # A memory cue is addressed by its row id (`CuePoint.id`). + id=str(c.ID) if memory and editable and getattr(c, "ID", None) is not None else None, ) ) return TrackCues(grid_markers=markers, grid_locked=False, cues=cues) +def _memory_cue_color(row) -> str | None: + """A memory cue keeps its 0-based `memory_palette` code in `Color` (-1 and + 255 = none). A row Konduktor wrote before that was measured carries a + hot-cue code in `ColorTableIndex` instead; read it rather than lose it.""" + colour = memory_palette.hex_for(getattr(row, "Color", None)) + if colour is None and (getattr(row, "OutMsec", -1) or -1) <= 0: + colour = palette.hex_for(getattr(row, "ColorTableIndex", None)) + return colour + + def _cue_color(row) -> str | None: """Rekordbox stores a PALETTE CODE (`ColorTableIndex`), not an RGB value; `Color` is -1 on a coloured cue. A loop's uncoloured convention is code 0.""" diff --git a/backend/konduktor/adapters/rekordbox/store.py b/backend/konduktor/adapters/rekordbox/store.py index 7264e32..50ae5dd 100644 --- a/backend/konduktor/adapters/rekordbox/store.py +++ b/backend/konduktor/adapters/rekordbox/store.py @@ -47,8 +47,8 @@ from ...core.adapter import ( from ...core.edit_journal import EditJournal from ...core.grid_edit import ReplaceGridCommands from ...core.pathmap import PathMapping, stored_form -from . import timebase -from .cue_types import beat_loop_size, kind_for, role_and_slot +from . import memory_palette, timebase +from .cue_types import MAX_MEMORY_CUES, beat_loop_size, kind_for, role_and_slot log = logging.getLogger(__name__) @@ -1147,6 +1147,25 @@ class RekordboxStore(ReplaceGridCommands): ) self._journal.record("cue", "add" if existing is None else "modify", track_id, f"slot:{slot}") + MAX_MEMORY_CUES = MAX_MEMORY_CUES # see `cue_types` + + def memory_cue_rows(self, track_id: str) -> list: + """A track's memory cues (`Kind` 0), in row order.""" + t = self._tables + return list( + self._db.session.query(t.DjmdCue) + .filter(t.DjmdCue.ContentID == str(track_id)) + .filter(t.DjmdCue.Kind == kind_for("memory", None)) + .filter(t.DjmdCue.rb_local_deleted == 0) + ) + + def _memory_cue_row(self, track_id: str, cue_id: str): + """The memory cue whose `djmdCue.ID` is `cue_id` (`CuePoint.id`).""" + row = next((c for c in self.memory_cue_rows(track_id) if str(c.ID) == str(cue_id)), None) + if row is None: + raise NotFound(f"No memory cue {cue_id!r} on this track") + return row + def add_memory_cue( self, track_id: str, @@ -1156,23 +1175,59 @@ class RekordboxStore(ReplaceGridCommands): length_sec: float = 0.0, name: str | None = None, color_code: int | None = None, + enforce_cap: bool = True, ) -> None: - """Add a MEMORY cue (`Kind` 0) — for the exporter building a new library. + """Add a MEMORY cue (`Kind` 0); a memory loop when `length_sec` > 0. - The adapter never calls this: editing memory cues in a user's library - stays refused under the two-platform promotion rule. A new export is not - an edit, and dropping the source's memory cues would lose prep. + `color_code` is a 0-based `memory_palette` code — NOT a hot-cue palette + code: a memory cue keeps its colour in `Color`, not `ColorTableIndex`. + `enforce_cap` refuses the 11th (an edit); the exporter, building a + library from a source that may hold more, trims before calling. """ + if enforce_cap and len(self.memory_cue_rows(track_id)) >= self.MAX_MEMORY_CUES: + raise InvalidCommand( + f"rekordbox keeps at most {self.MAX_MEMORY_CUES} memory cues per track" + ) self._write_cue( track_id, None, kind=kind_for("memory", None), start_sec=start_sec, cue_type=cue_type, length_sec=length_sec, name=name, color_code=color_code, ) self._journal.record("cue", "add", track_id, "memory") + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> None: + """A memory cue's name is rekordbox's `Comment`; only that column changes.""" + cue = self._memory_cue_row(track_id, cue_id) + is_loop = (cue.OutMsec or 0) > 0 + # An unnamed memory LOOP is '' (measured); an unnamed point cue NULL. + cue.Comment = name or ("" if is_loop else None) + self._db.flush() + self._sync_content_cue(track_id) + self._journal.record("cue", "modify", track_id, "memory") + + def set_memory_cue_color(self, track_id: str, cue_id: str, color_code: int | None) -> None: + """Recolour a memory cue; None = rekordbox's "No Color" (255, measured).""" + cue = self._memory_cue_row(track_id, cue_id) + self._apply_memory_color(cue, color_code, (cue.OutMsec or 0) > 0, cleared=True) + self._db.flush() + self._sync_content_cue(track_id) + self._journal.record("cue", "modify", track_id, "memory") + + def delete_memory_cue(self, track_id: str, cue_id: str) -> None: + """Delete the row outright, as rekordbox does (never `rb_local_deleted`).""" + cue = self._memory_cue_row(track_id, cue_id) + self._db.delete(cue) + self._db.flush() + self._sync_content_cue(track_id) + self._journal.record("cue", "delete", track_id, "memory") + def _write_cue(self, track_id: str, cue, *, kind: int, start_sec: float, cue_type: str, length_sec: float, name: str | None, color_code: int | None) -> None: """Fill one `djmdCue` row (a new one when `cue` is None) and resync the - `contentCue` mirror — the single definition of a cue row's fields.""" + `contentCue` mirror — the single definition of a cue row's fields. + + `color_code` is a hot-cue palette code on a hot cue and a 0-based + `memory_palette` code on a memory cue (`Kind` 0): the two keep their + colour in different columns.""" if start_sec < 0: raise InvalidCommand("A cue cannot be before the start of the track") row = self.content(track_id) @@ -1217,8 +1272,13 @@ class RekordboxStore(ReplaceGridCommands): cue.BeatLoopSize = None cue.ActiveLoop = None cue.CueMicrosec = None - self._apply_color(cue, color_code, is_loop) - cue.Comment = name or None + if kind == kind_for("memory", None): + self._apply_memory_color(cue, color_code, is_loop) + # Measured: an unnamed memory LOOP has Comment '', a point cue NULL. + cue.Comment = name or ("" if is_loop else None) + else: + self._apply_color(cue, color_code, is_loop) + cue.Comment = name or None self._db.flush() self._sync_content_cue(track_id) @@ -1240,6 +1300,21 @@ class RekordboxStore(ReplaceGridCommands): cue.Color = -1 cue.ColorTableIndex = None + @staticmethod + def _apply_memory_color(cue, code: int | None, is_loop: bool, *, cleared: bool = False) -> None: + """A MEMORY cue's colour columns (measured 2026-10-16, kit M1): the + 0-based `memory_palette` code in `Color`, `ColorTableIndex` untouched by + colour — NULL on a point cue, 0 on a loop (rekordbox's loop marker). + Uncoloured is -1 on a new point cue, 255 on a loop and on any cue set + back to "No Color" (`cleared`).""" + cue.ColorTableIndex = 0 if is_loop else None + if code is not None: + cue.Color = int(code) + elif cleared or is_loop: + cue.Color = memory_palette.CLEARED + else: + cue.Color = -1 + def set_cue_color(self, track_id: str, slot: int, color_code: int | None) -> None: """Recolour the cue in `slot`; None makes it uncoloured. Touches only the colour columns, so the position does not take a time-base round trip.""" @@ -1308,11 +1383,13 @@ class RekordboxStore(ReplaceGridCommands): """ t = self._tables row = self.content(track_id) + # In ROW order, as rekordbox writes it (measured: a memory cue added at + # 1:55 is listed after older ones at 2:04 and 3:26), not by position. cues = ( self._db.session.query(t.DjmdCue) .filter(t.DjmdCue.ContentID == str(track_id)) .filter(t.DjmdCue.rb_local_deleted == 0) - .order_by(t.DjmdCue.InMsec) + .order_by(text("djmdCue.rowid")) .all() ) fields = ( diff --git a/backend/konduktor/adapters/remote/adapter.py b/backend/konduktor/adapters/remote/adapter.py index fb85628..8ef10cd 100644 --- a/backend/konduktor/adapters/remote/adapter.py +++ b/backend/konduktor/adapters/remote/adapter.py @@ -234,6 +234,22 @@ class RemoteAdapter: def place_cues(self, track_id, cues, *, overwrite=False): return self._call("place_cues", track_id=track_id, cues=list(cues), overwrite=overwrite) + def add_memory_cue(self, track_id, *, start_sec, cue_type, length_sec=0.0, name=None, color=None): + return self._call("add_memory_cue", track_id=track_id, start_sec=start_sec, + cue_type=cue_type, length_sec=length_sec, name=name, color=color) + + def rename_memory_cue(self, track_id, cue_id, name): + return self._call("rename_memory_cue", track_id=track_id, cue_id=cue_id, name=name) + + def set_memory_cue_type(self, track_id, cue_id, cue_type): + return self._call("set_memory_cue_type", track_id=track_id, cue_id=cue_id, cue_type=cue_type) + + def set_memory_cue_color(self, track_id, cue_id, color): + return self._call("set_memory_cue_color", track_id=track_id, cue_id=cue_id, color=color) + + def delete_memory_cue(self, track_id, cue_id): + return self._call("delete_memory_cue", track_id=track_id, cue_id=cue_id) + def add_grid_marker(self, track_id, start_sec, bpm=None): return self._call("add_grid_marker", track_id=track_id, start_sec=start_sec, bpm=bpm) diff --git a/backend/konduktor/adapters/traktor/adapter.py b/backend/konduktor/adapters/traktor/adapter.py index d49cfaa..1f51ffb 100644 --- a/backend/konduktor/adapters/traktor/adapter.py +++ b/backend/konduktor/adapters/traktor/adapter.py @@ -197,10 +197,11 @@ class TraktorAdapter: Lossiness follows the settled rule — degrade to the nearest equivalent, drop only where none exists: - * **Memory cues become hot cues in spare slots.** Traktor has no - memory cues, and every Traktor cue occupies a slot. Filling the - leftovers preserves the positions a DJ actually marked; when the - bank is full the rest are dropped, because there is nowhere left. + * **Memory cues stay memory cues** — Traktor's cues on no pad + (HOTCUE="-1"), decided 2026-10-16 once Traktor was measured keeping + them. They used to be promoted to spare pads. + * **A hot cue whose pad is taken** moves to a spare pad, else becomes a + memory cue — never dropped. * **Cue colour is dropped.** Traktor derives a cue's colour from its type, so a free RGB value has nowhere to go. @@ -250,29 +251,43 @@ class TraktorAdapter: self._place_imported_cue(track_id, cue.slot, cue) taken.add(cue.slot) - # Everything without a pad of its own competes for what is left: memory - # cues, which Traktor has no equivalent for, and any hot cue whose pad - # was already occupied. Earliest first, so that when the bank runs out - # it is the late cues that are lost rather than an arbitrary set — and - # a displaced hot cue is moved rather than dropped, because losing one - # silently is much worse than having it turn up on the wrong pad. - leftovers = displaced + [c for c in (cues.cues or []) if c.role != "hotcue"] + # A hot cue whose pad was taken (or is past the bank) moves to a spare + # pad, earliest first, because muscle memory is most of what a hot cue + # layout is; once the bank is full it becomes a memory cue rather than + # being lost. Memory cues cross as memory cues. spare = (s for s in range(slots) if s not in taken) - for cue in sorted(leftovers, key=lambda c: c.start): + for cue in sorted(displaced, key=lambda c: c.start): slot = next(spare, None) if slot is None: - break # bank full: the rest are dropped, per the lossiness rule - self._place_imported_cue(track_id, slot, cue) + self._place_imported_memory_cue(track_id, cue) + else: + self._place_imported_cue(track_id, slot, cue) + for cue in sorted((c for c in (cues.cues or []) if c.role != "hotcue" or c.slot is None), + key=lambda c: c.start): + self._place_imported_memory_cue(track_id, cue) + + @staticmethod + def _imported_type(cue) -> str: + """A loop stays a loop; Traktor's own point types (fade, load) survive.""" + if getattr(cue, "length", 0): + return "loop" + return cue.type if cue.type in ("cue", "fade_in", "fade_out", "load") else "cue" def _place_imported_cue(self, track_id: str, slot: int, cue) -> None: - cue_type = "loop" if getattr(cue, "length", 0) else "cue" - if cue_type not in CUE_TYPE_TO_NATIVE: - return self.set_cue( track_id, slot=slot, start_sec=cue.start, - cue_type=cue_type, + cue_type=self._imported_type(cue), + length_sec=getattr(cue, "length", 0.0) or 0.0, + name=getattr(cue, "name", None), + ) + + def _place_imported_memory_cue(self, track_id: str, cue) -> None: + self.add_memory_cue( + track_id, + start_sec=cue.start, + cue_type=self._imported_type(cue), length_sec=getattr(cue, "length", 0.0) or 0.0, name=getattr(cue, "name", None), ) @@ -296,8 +311,8 @@ class TraktorAdapter: name: str | None = None, ) -> TrackCues: if role != "hotcue": - # Memory cues are a Rekordbox concept; every Traktor cue holds a slot. - raise Unsupported("Traktor cues always occupy a hotcue slot") + # A memory cue has no slot to set; it has its own commands. + raise InvalidCommand("Memory cues are added with add_memory_cue, not set_cue") with _translate(): self._store.set_hotcue( track_id, slot, start_sec, self._native_cue_type(cue_type), length_sec, name @@ -318,6 +333,45 @@ class TraktorAdapter: self._store.delete_hotcue(track_id, slot) return self._refresh(track_id) + # ---- memory cues: cues on no pad (HOTCUE="-1") ---------------------------- + def add_memory_cue( + self, + track_id: str, + *, + start_sec: float, + cue_type: str, + length_sec: float = 0.0, + name: str | None = None, + color: str | None = None, + ) -> TrackCues: + # Traktor colours a cue by its type, so a colour has nowhere to go; an + # import passes none, and the capabilities offer none. + if color is not None: + raise Unsupported("Traktor colours cues by their type") + with _translate(): + self._store.add_memory_cue( + track_id, start_sec, self._native_cue_type(cue_type), length_sec, name + ) + return self._refresh(track_id) + + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> TrackCues: + with _translate(): + self._store.rename_memory_cue(track_id, cue_id, name) + return self._refresh(track_id) + + def set_memory_cue_type(self, track_id: str, cue_id: str, cue_type: str) -> TrackCues: + with _translate(): + self._store.set_memory_cue_type(track_id, cue_id, self._native_cue_type(cue_type)) + return self._refresh(track_id) + + def set_memory_cue_color(self, track_id: str, cue_id: str, color: str | None) -> TrackCues: + raise Unsupported("Traktor colours cues by their type") + + def delete_memory_cue(self, track_id: str, cue_id: str) -> TrackCues: + with _translate(): + self._store.delete_memory_cue(track_id, cue_id) + return self._refresh(track_id) + def place_cues(self, track_id: str, cues: list, *, overwrite: bool = False) -> TrackCues: native = [ SimpleNamespace( diff --git a/backend/konduktor/adapters/traktor/capabilities.py b/backend/konduktor/adapters/traktor/capabilities.py index c4c0488..a089c45 100644 --- a/backend/konduktor/adapters/traktor/capabilities.py +++ b/backend/konduktor/adapters/traktor/capabilities.py @@ -46,8 +46,11 @@ def capabilities_for(path: Path, editable_fields: list[str]) -> Capabilities: editable=True, hotcue_slots=8, slot_labels="number", - # Traktor has no memory cues — every cue occupies a bank slot. - memory_cues=False, + # Memory cues are CUE_V2s on no pad (HOTCUE="-1"), any type, no + # limit (measured in Traktor 4.5, 2026-10-16). No colour: by type. + memory_cues=True, + max_memory_cues=None, + memory_color="none", types=CUE_TYPES, # Traktor colours a cue by its TYPE; the only COLOR it stores is a # grid marker's white companion, so there is nothing to pick. diff --git a/backend/konduktor/adapters/traktor/projection.py b/backend/konduktor/adapters/traktor/projection.py index ef07f80..667f5fd 100644 --- a/backend/konduktor/adapters/traktor/projection.py +++ b/backend/konduktor/adapters/traktor/projection.py @@ -175,6 +175,39 @@ def to_track(e) -> Track: ) +def is_memory_cue(c) -> bool: + """A cue on no pad that is not a grid marker — Traktor's memory cue. + + Traktor stores it as an ordinary CUE_V2 with HOTCUE="-1", any type, drawn + on the waveform and reached with the cue panel's ‹ › (measured in Traktor + 4.5, 2026-10-16). A grid marker is ALSO HOTCUE="-1"; its child is + what tells them apart — never its name or position. + """ + return getattr(c, "grid", None) is None and (c.hotcue is None or c.hotcue < 0) + + +def memory_cue_id(c, n: int) -> str: + """`CuePoint.id` for a memory cue: its stored START, TYPE and LEN, plus `n` + — how many identical memory cues come before it (Traktor allows several at + one START). Content-derived, so it is the same on every read.""" + return f"m:{c.start or 0.0:.6f}:{c.type}:{c.len or 0.0:.6f}:{n}" + + +def with_memory_ids(entry) -> list: + """(cue, its memory id or None) for every CUE_V2 of an entry, in order.""" + seen: dict[str, int] = {} + out = [] + for c in entry.cue_v2 or []: + if not is_memory_cue(c): + out.append((c, None)) + continue + base = memory_cue_id(c, 0) + n = seen.get(base, 0) + seen[base] = n + 1 + out.append((c, memory_cue_id(c, n))) + return out + + def to_track_cues(entry, offset_ms: float = 0.0) -> TrackCues: """Project an ENTRY's beatgrid + cues. @@ -200,10 +233,17 @@ def to_track_cues(entry, offset_ms: float = 0.0) -> TrackCues: ) for i, m in enumerate(markers) ] + # A pad MAP put on a memory cue leaves the memory cue in place at the same + # START (measured in Traktor 4.5); Traktor draws ONE marker, so the pad + # stands for both (decided 2026-10-16). + pad_starts = {c.start for c in entry.cue_v2 or [] + if getattr(c, "grid", None) is None and c.hotcue is not None and c.hotcue >= 0} cues = [] - for c in entry.cue_v2 or []: + for c, memory_id in with_memory_ids(entry): if getattr(c, "grid", None) is not None: continue # a grid marker is projected as a beatgrid marker, not a cue + if memory_id is not None and c.start in pad_starts: + continue marker = marker_of.get(id(c)) slot = c.hotcue if c.hotcue is not None and c.hotcue >= 0 else None cues.append( @@ -212,8 +252,8 @@ def to_track_cues(entry, offset_ms: float = 0.0) -> TrackCues: # An unknown TYPE is projected as a plain cue rather than dropped: # preserving a cue we cannot name beats hiding it from the user. type=NATIVE_TO_CUE_TYPE.get(c.type, "cue"), - # Every Traktor cue lives in the hotcue bank. - role="hotcue", + # A cue on no pad (HOTCUE="-1") is a memory cue. + role="hotcue" if slot is not None else "memory", start=timebase.from_traktor_ms(c.start or 0.0, offset_ms), length=(c.len or 0.0) / 1000.0, slot=slot, @@ -221,6 +261,7 @@ def to_track_cues(entry, offset_ms: float = 0.0) -> TrackCues: editable=True, readonly_reason=None, grid_marker=marker, + id=memory_id, ) ) return TrackCues( diff --git a/backend/konduktor/adapters/traktor/store.py b/backend/konduktor/adapters/traktor/store.py index eb89e28..244feb4 100644 --- a/backend/konduktor/adapters/traktor/store.py +++ b/backend/konduktor/adapters/traktor/store.py @@ -56,7 +56,7 @@ from ...schemas import PlaylistNode from . import beatgrid, timebase from .locations import os_path_to_location, resolve_path from ...core import musical_key -from .projection import iso_date, musical_key_value, traktor_date +from .projection import iso_date, musical_key_value, traktor_date, with_memory_ids # Traktor's POPM frame owner: an ID3 rating is per-owner, so writing under # this email is what makes the stars show up in Traktor itself. @@ -770,21 +770,7 @@ class TraktorStore: if name is not None: existing.name = name else: - if entry.cue_v2 is None: - entry.cue_v2 = [] - entry.cue_v2.append( - CueV2Type( - name=name or "n.n.", # Traktor's default name for a manual cue - displ_order=0, - type=cue_type, - start=start_ms, - len=len_ms, - repeats=-1, - hotcue=slot, - color=None, - grid=None, - ) - ) + self._insert_cue(entry, self._new_cue(cue_type, start_ms, len_ms, slot, name)) # "add" only when it's a genuinely new hotcue; repositioning/retyping # an existing slot is a "modify" (keeps the net add/remove count honest). self._note( @@ -816,6 +802,87 @@ class TraktorStore: name=getattr(spec, "name", None), ) + @staticmethod + def _new_cue(cue_type: int, start_ms: float, len_ms: float, hotcue: int, + name: str | None) -> CueV2Type: + """A CUE_V2 as Traktor writes one by hand — on a pad, or on none + (`hotcue` -1, a memory cue: the same element, measured in Traktor 4.5).""" + return CueV2Type( + name=name or "n.n.", # Traktor's default name for a manual cue + displ_order=0, + type=cue_type, + start=start_ms, + len=len_ms, + repeats=-1, + hotcue=hotcue, + color=None, + grid=None, + ) + + @staticmethod + def _insert_cue(entry: Entrytype, cue: CueV2Type) -> None: + """Insert a new cue at its place BY START, after every cue at or before + it — Traktor keeps CUE_V2 sorted by START (8485/8485 reference entries, + and its own saves), so a later Traktor save moves nothing. Nothing else + moves either, unlike a re-sort of an entry another tool left unsorted.""" + if entry.cue_v2 is None: + entry.cue_v2 = [] + at = len(entry.cue_v2) + while at > 0 and (entry.cue_v2[at - 1].start or 0.0) > (cue.start or 0.0): + at -= 1 + entry.cue_v2.insert(at, cue) + + # ---- memory cues: CUE_V2 on no pad (HOTCUE="-1"), not a grid marker ----- + # Measured in Traktor 4.5 (2026-10-16, kit M3): any type, no limit, drawn + # on the waveform and reached with the cue panel's ‹ ›, a name shown in the + # cue panel — and a cue written here survives Traktor's own save byte for + # byte. Addressed by `projection.memory_cue_id`. + def _memory_cue(self, entry: Entrytype, cue_id: str) -> CueV2Type: + cue = next((c for c, mid in with_memory_ids(entry) if mid == cue_id), None) + if cue is None: + raise PlaylistError(f"Memory cue {cue_id!r} not found on this track") + return cue + + def add_memory_cue(self, track_id: str, start_sec: float, cue_type: int, + length_sec: float = 0.0, name: str | None = None) -> None: + if cue_type not in self.CREATABLE_TYPES: + raise PlaylistError(f"Unsupported cue type: {cue_type}") + with self._lock: + entry = self._entry_or_raise(track_id) + start_ms = timebase.to_traktor_ms(start_sec, self.time_offset_ms(entry)) + len_ms = max(0.0, length_sec * 1000.0) + self._insert_cue(entry, self._new_cue(cue_type, start_ms, len_ms, -1, name)) + self._note("hotcue", "add", track_id, "memory") + self.dirty = True + + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> None: + with self._lock: + entry = self._entry_or_raise(track_id) + self._memory_cue(entry, cue_id).name = name or "n.n." + self._note("hotcue", "modify", track_id, "memory") + self.dirty = True + + def set_memory_cue_type(self, track_id: str, cue_id: str, cue_type: int) -> None: + """A point type only, as for a hot cue: a loop is not retyped.""" + if cue_type not in self.POINT_CUE_TYPES: + raise PlaylistError(f"Unsupported cue type: {cue_type}") + with self._lock: + entry = self._entry_or_raise(track_id) + cue = self._memory_cue(entry, cue_id) + if cue.type not in self.POINT_CUE_TYPES: + raise PlaylistError("A memory loop keeps its type") + cue.type = cue_type + self._note("hotcue", "modify", track_id, "memory") + self.dirty = True + + def delete_memory_cue(self, track_id: str, cue_id: str) -> None: + with self._lock: + entry = self._entry_or_raise(track_id) + cue = self._memory_cue(entry, cue_id) + entry.cue_v2 = [c for c in entry.cue_v2 if c is not cue] + self._note("hotcue", "delete", track_id, "memory") + self.dirty = True + def set_hotcue_type(self, track_id: str, slot: int, cue_type: int) -> None: """Change the type of the existing hotcue in `slot` (keeps its position).""" if cue_type not in self.POINT_CUE_TYPES: diff --git a/backend/konduktor/core/adapter.py b/backend/konduktor/core/adapter.py index 5ccf296..5a067b6 100644 --- a/backend/konduktor/core/adapter.py +++ b/backend/konduktor/core/adapter.py @@ -318,6 +318,29 @@ class LibraryAdapter(Protocol): def delete_cue(self, track_id: str, slot: int) -> TrackCues: ... def place_cues(self, track_id: str, cues: list, *, overwrite: bool = False) -> TrackCues: ... + # ---- commands: memory cues -------------------------------------------- + # Cues on no pad, addressed by `CuePoint.id`. Gated on `cues.memory_cues`. + # Past `cues.max_memory_cues` -> InvalidCommand; an unknown id -> NotFound; + # `color` is from `cues.memory_palette` (Unsupported where memory_color is + # "none"). There is deliberately no move: rekordbox has none either, so a + # move is a delete and an add. + def add_memory_cue( + self, + track_id: str, + *, + start_sec: float, + cue_type: str, + length_sec: float = 0.0, + name: str | None = None, + color: str | None = None, + ) -> TrackCues: ... + def rename_memory_cue(self, track_id: str, cue_id: str, name: str | None) -> TrackCues: ... + # A POINT type from `cues.types` (Traktor: cue / fade in / fade out / load); + # a loop is not retyped. Unsupported where the platform has one point type. + def set_memory_cue_type(self, track_id: str, cue_id: str, cue_type: str) -> TrackCues: ... + def set_memory_cue_color(self, track_id: str, cue_id: str, color: str | None) -> TrackCues: ... + def delete_memory_cue(self, track_id: str, cue_id: str) -> TrackCues: ... + # ---- commands: beatgrid --------------------------------------------- def add_grid_marker(self, track_id: str, start_sec: float, bpm: float | None = None) -> TrackCues: ... def move_grid_marker(self, track_id: str, index: int, start_sec: float) -> TrackCues: ... diff --git a/backend/konduktor/core/capabilities.py b/backend/konduktor/core/capabilities.py index abd065c..561f2e3 100644 --- a/backend/konduktor/core/capabilities.py +++ b/backend/konduktor/core/capabilities.py @@ -45,10 +45,17 @@ class CueCapabilities(BaseModel): editable: bool = False hotcue_slots: int = 8 # size of the addressable bank; 0 = no bank slot_labels: Literal["number", "letter"] = "number" - # Memory cues are Rekordbox-only today, so they are modelled and PRESERVED - # but not editable anywhere yet (the two-platform promotion rule). + # Cues on no pad, listed in time order and called CDJ-style (decided + # 2026-10-16). Editable wherever `editable` is: every platform that has them + # can store them (Rekordbox, OneLibrary, and Traktor's HOTCUE="-1"). memory_cues: bool = False + # Per track; None = no limit. rekordbox stops storing at 10 WITHOUT saying + # so, so the adapter refuses the 11th itself. max_memory_cues: int | None = None + # A memory cue's colour is its own palette, not `palette` (rekordbox offers + # 8 colours for memory cues against 16 for hot cues). + memory_color: Literal["none", "palette"] = "none" + memory_palette: list[str] = [] types: list[CueType] = ["cue"] color: Literal["none", "free", "palette"] = "none" palette: list[str] = [] diff --git a/backend/konduktor/core/cue_colors.py b/backend/konduktor/core/cue_colors.py index a7f613d..ba6195c 100644 --- a/backend/konduktor/core/cue_colors.py +++ b/backend/konduktor/core/cue_colors.py @@ -25,9 +25,8 @@ MEMORY_COLOR = "#9AA1B2" # grey def effective_color(cue: CuePoint) -> str: - """`#RRGGBB` — the stored colour, or the type's.""" + """`#RRGGBB` — the stored colour, or the type's: hot and memory cues alike + (a memory cue's type colours it too, decided 2026-10-16).""" if cue.color: return cue.color.upper() - if cue.role == "memory": - return MEMORY_COLOR return TYPE_COLORS.get(cue.type, MEMORY_COLOR) diff --git a/backend/konduktor/core/edit_journal.py b/backend/konduktor/core/edit_journal.py index 951d54f..5775656 100644 --- a/backend/konduktor/core/edit_journal.py +++ b/backend/konduktor/core/edit_journal.py @@ -167,21 +167,23 @@ class EditJournal: else: parts.append(f"{verb} {len(names)} {noun}s") - # --- hotcues: net change in count, scoped by how many tracks were touched --- - hc_add = hc_del = 0 - hc_tracks: set[str] = set() + # --- cues: net change in count, scoped by how many tracks were touched. + # Memory cues (detail "memory") are counted apart from hotcues, so a + # session of memory-cue edits is not described as hotcue work. + counts = {kind: [0, 0, set()] for kind in ("hotcue", "memory cue")} grid_edit: set[str] = set() grid_del: set[str] = set() lock_on: set[str] = set() lock_off: set[str] = set() for c in self.changes: if c.scope == "cue": + bucket = counts["memory cue" if c.detail == "memory" else "hotcue"] if c.target: - hc_tracks.add(c.target) + bucket[2].add(c.target) if c.op == "add": - hc_add += 1 + bucket[0] += 1 elif c.op == "delete": - hc_del += 1 + bucket[1] += 1 elif c.scope == "grid": # "delete" is the ONLY deletion op. Everything else — including # ops added later — counts as an edit, because mis-labelling an @@ -190,15 +192,17 @@ class EditJournal: elif c.scope == "lock": (lock_on if c.op == "on" else lock_off).add(c.target or "") - if hc_tracks: - net = hc_add - hc_del - scope = f" across {tracks(len(hc_tracks))}" if len(hc_tracks) > 1 else "" + for noun, (added, deleted, touched) in counts.items(): + if not touched: + continue + net = added - deleted + scope = f" across {tracks(len(touched))}" if len(touched) > 1 else "" if net > 0: - parts.append(f"added {net} hotcue{'' if net == 1 else 's'}{scope}") + parts.append(f"added {net} {noun}{'' if net == 1 else 's'}{scope}") elif net < 0: - parts.append(f"removed {-net} hotcue{'' if -net == 1 else 's'}{scope}") + parts.append(f"removed {-net} {noun}{'' if -net == 1 else 's'}{scope}") else: # net zero but there was activity (moves / retypes / add-then-delete) - parts.append(f"adjusted hotcues{scope}") + parts.append(f"adjusted {noun}s{scope}") # --- beatgrids & lock: per-track counts --- if grid_edit: diff --git a/backend/konduktor/core/model.py b/backend/konduktor/core/model.py index c6c9716..d1a91e7 100644 --- a/backend/konduktor/core/model.py +++ b/backend/konduktor/core/model.py @@ -144,8 +144,8 @@ PlaylistNode.model_rebuild() class CuePoint(BaseModel): name: str | None = None type: CueType = "cue" - # "memory" cues have no bank slot. Only Rekordbox has them, so they are - # modelled and preserved but not yet editable anywhere. + # A "memory" cue has no bank slot: Rekordbox's / OneLibrary's memory cues, + # Traktor's cues on no pad (HOTCUE="-1"). Addressed by `id`, not `slot`. role: CueRole = "hotcue" start: float # seconds length: float # seconds (>0 for loops) @@ -158,6 +158,10 @@ class CuePoint(BaseModel): # Index of the grid marker this cue mirrors, where the platform pairs them. # A display hint only; None on platforms that do not. grid_marker: int | None = None + # The handle the memory-cue commands take (None on a hot cue, which is + # addressed by slot). Opaque and adapter-defined; an edit of THIS cue may + # change it, which is fine because every command returns fresh TrackCues. + id: str | None = None class GridMarker(BaseModel): diff --git a/backend/konduktor/main.py b/backend/konduktor/main.py index 82797ab..01805ee 100644 --- a/backend/konduktor/main.py +++ b/backend/konduktor/main.py @@ -102,6 +102,10 @@ from .schemas import ( SetCue, SetCueColor, SetCueType, + AddMemoryCue, + RenameMemoryCue, + SetMemoryCueColor, + SetMemoryCueType, SetGridLock, Stats, Track, @@ -1842,6 +1846,45 @@ def delete_cue(track_id: str, slot: int) -> TrackCues: return require_adapter().delete_cue(track_id, slot) +# Memory cues — cues on no pad, addressed by CuePoint.id (gated on +# capabilities.cues.memory_cues; the adapter refuses past max_memory_cues). +@app.post("/api/tracks/memory-cue", response_model=TrackCues) +def add_memory_cue(body: AddMemoryCue) -> TrackCues: + """Add a memory cue (a memory loop when `length` > 0).""" + return require_adapter().add_memory_cue( + body.track_id, + start_sec=body.start, + cue_type=body.type, + length_sec=body.length, + name=body.name, + color=body.color, + ) + + +@app.patch("/api/tracks/memory-cue", response_model=TrackCues) +def rename_memory_cue(body: RenameMemoryCue) -> TrackCues: + """Name a memory cue (rekordbox calls it the comment); None/"" clears it.""" + return require_adapter().rename_memory_cue(body.track_id, body.cue_id, body.name or None) + + +@app.patch("/api/tracks/memory-cue/type", response_model=TrackCues) +def edit_memory_cue_type(body: SetMemoryCueType) -> TrackCues: + """Change a memory cue's point type (keeps its position).""" + return require_adapter().set_memory_cue_type(body.track_id, body.cue_id, body.type) + + +@app.patch("/api/tracks/memory-cue/color", response_model=TrackCues) +def edit_memory_cue_color(body: SetMemoryCueColor) -> TrackCues: + """Recolour a memory cue from capabilities.cues.memory_palette (None = uncoloured).""" + return require_adapter().set_memory_cue_color(body.track_id, body.cue_id, body.color) + + +@app.delete("/api/tracks/memory-cue", response_model=TrackCues) +def delete_memory_cue(track_id: str, cue_id: str) -> TrackCues: + """Remove a memory cue.""" + return require_adapter().delete_memory_cue(track_id, cue_id) + + @app.post("/api/tracks/grid/marker", response_model=TrackCues) def add_grid_marker(body: AddGridMarker) -> TrackCues: """Add a beatgrid marker. Omitting `bpm` inherits the governing tempo.""" diff --git a/backend/konduktor/remote_protocol.py b/backend/konduktor/remote_protocol.py index 4319e1e..e1b39d4 100644 --- a/backend/konduktor/remote_protocol.py +++ b/backend/konduktor/remote_protocol.py @@ -36,7 +36,9 @@ from .core.model import AutoHotcue, Track, TrackCues #: method, the major for anything an older client would misread. #: 1.1 — `move_playlist` (sidebar drag and drop). #: 1.2 — `/v1/folder/*`: the content folder browsed as a Files tree. -API_VERSION: tuple[int, int] = (1, 2) +#: 1.3 — memory cues: `add_memory_cue`, `rename_memory_cue`, +#: `set_memory_cue_type`, `set_memory_cue_color`, `delete_memory_cue`. +API_VERSION: tuple[int, int] = (1, 3) #: How long a session survives without a heartbeat, and how often the holder #: sends one. Long enough to ride out a Wi-Fi blip or a switch to the fallback @@ -76,7 +78,8 @@ _READ = ( _MUTATING = ( "create_playlist", "create_folder", "rename_playlist", "delete_playlist", "move_playlist", "set_playlist_entries", "remove_tracks", "set_track_metadata", "set_key", "set_cue", - "set_cue_type", "set_cue_color", "delete_cue", "place_cues", "add_grid_marker", + "set_cue_type", "set_cue_color", "delete_cue", "place_cues", "add_memory_cue", + "rename_memory_cue", "set_memory_cue_type", "set_memory_cue_color", "delete_memory_cue", "add_grid_marker", "move_grid_marker", "set_grid_marker_bpm", "delete_grid_marker", "replace_grid", "set_analysed_grid", "delete_grid", "set_grid_lock", "add_tracks", ) diff --git a/backend/konduktor/schemas.py b/backend/konduktor/schemas.py index 721586e..f42746b 100644 --- a/backend/konduktor/schemas.py +++ b/backend/konduktor/schemas.py @@ -200,6 +200,33 @@ class SetCueColor(BaseModel): color: str | None = None # a capabilities.cues.palette entry; None = uncoloured +class AddMemoryCue(BaseModel): + track_id: str + start: float # seconds + type: CueType = "cue" + length: float = 0.0 # seconds (>0 for a memory loop) + name: str | None = None + color: str | None = None # a capabilities.cues.memory_palette entry + + +class RenameMemoryCue(BaseModel): + track_id: str + cue_id: str # CuePoint.id + name: str | None = None # None / "" = unnamed + + +class SetMemoryCueType(BaseModel): + track_id: str + cue_id: str + type: CueType # a point type from capabilities.cues.types + + +class SetMemoryCueColor(BaseModel): + track_id: str + cue_id: str + color: str | None = None # a capabilities.cues.memory_palette entry; None = uncoloured + + class StemEngineInstall(BaseModel): # None = this computer's default engine; "windows-x64-cuda" to take the GPU one. target: str | None = None diff --git a/backend/test_export_pioneer.py b/backend/test_export_pioneer.py index dd8796a..b376596 100644 --- a/backend/test_export_pioneer.py +++ b/backend/test_export_pioneer.py @@ -424,6 +424,7 @@ print("\n== cue colours cross as rekordbox PALETTE CODES ==") # rekordbox draws a hot cue from the palette code, not the RGB: an export writing # code 0 had every cue drawn in rekordbox's defaults (green cues, orange loops). # The table was measured from a rekordbox 7 export of all 16 swatches. +from konduktor.adapters.rekordbox import anlz_file as A_ # noqa: E402 from konduktor.adapters.rekordbox import palette # noqa: E402 check("a measured swatch keeps its exact code and RGB", @@ -451,6 +452,33 @@ entry = W.cue_tags([{"hot_cue": 1, "kind": 1, "time_ms": 1000, "loop_ms": None, check("the code is packed where rekordbox 7 puts it — byte 44, before the RGB", entry[20 + 44:20 + 48] == bytes([0x16, 0x1A, 0xFF, 0x00]), entry[64:68].hex()) +# Memory cues (kit M2, 2026-10-16): colour is PCP2 byte 28 from the 8-colour +# memory palette, a list of two or more is LINKED in the .DAT, and rekordbox +# keeps 10. +from konduktor.adapters.rekordbox import memory_palette # noqa: E402 + +many_memory = [CuePoint(type="cue", role="memory", start=float(i), length=0.0, slot=None, + color="#E13121" if i == 0 else None) for i in range(12)] +mem_dicts = OneLibraryExporter._cue_dicts( + ExportTrack(track=cued, destination=Path("t.wav"), + cues=TrackCues(track_id="t", cues=many_memory, grid_markers=[])), [], 0.0) +check("rekordbox keeps 10 memory cues: the earliest 10 are exported", + len(mem_dicts) == 10 and [d["time_ms"] for d in mem_dicts] == [i * 1000 for i in range(10)], + [d["time_ms"] for d in mem_dicts]) +check("a memory cue's colour is byte 28 from its own palette (Red = 2); no hot-cue code", + (mem_dicts[0]["color_id"], mem_dicts[0]["code"]) == (memory_palette.anlz_byte(1), 0), + (mem_dicts[0]["color_id"], mem_dicts[0]["code"])) +dat_tags = W.cue_tags(mem_dicts[:3], extended=False) +mem_pcob = A_.raw_entries(A_.Tag("PCOB", dat_tags[1])) +check("a memory PCOB of two or more is linked, status 0, as rekordbox writes it", + [(e[16:20].hex(), e[24:28].hex()) for e in mem_pcob] + == [("00000000", "ffff0001"), ("00000000", "00000002"), ("00000000", "0001ffff")], + [(e[16:20].hex(), e[24:28].hex()) for e in mem_pcob]) +ext_tags = W.cue_tags(mem_dicts[:1], extended=True) +pco2_mem = A_.raw_entries(A_.Tag("PCO2", ext_tags[3])) +check("and the colour lands in PCP2 byte 28", + len(pco2_mem) == 1 and pco2_mem[0][28] == memory_palette.anlz_byte(1), pco2_mem and pco2_mem[0][24:32].hex()) + print("\n== artwork crosses the way rekordbox 7 writes it ==") # Measured on a rekordbox 7 export: PIONEER/Artwork/00001/{a,b}{,_m}.jpg at # 80 and 240 px (a == b byte for byte), baseline JPEG q85 4:2:0, non-square art diff --git a/backend/test_import.py b/backend/test_import.py index ca781c0..f553744 100644 --- a/backend/test_import.py +++ b/backend/test_import.py @@ -139,15 +139,29 @@ check("every hot cue keeps the pad it was on", check("a loop stays a loop, with its length", got_by_slot[0].type == "loop" and abs(got_by_slot[0].length - 1.875) < 0.001) -# Traktor has no memory cues, so they degrade into spare pads rather than being -# dropped — the settled lossiness rule. +# Memory cues cross AS memory cues — Traktor's cues on no pad (HOTCUE="-1"), +# decided 2026-10-16 once Traktor was measured keeping them. They used to be +# promoted to spare pads. n_memory = sum(1 for c in src_cues.cues if c.role != "hotcue") -check("memory cues are preserved in spare slots, not dropped", - len(got.cues) == len(src_hot) + n_memory, f"{len(got.cues)} cues") -check("and they do not overwrite a hot cue", - len({c.slot for c in got.cues}) == len(got.cues)) -check("every imported cue occupies a real pad", - all(c.role == "hotcue" and c.slot is not None for c in got.cues)) +padless = [c for c in dest._store.model_entry(ids[0]).cue_v2 + if c.grid is None and c.hotcue == -1] +check("every memory cue is written as a memory cue (a CUE_V2 on no pad)", + len(padless) == n_memory and n_memory > 0, f"{len(padless)} of {n_memory}") +check("and no extra pad is taken", + sorted(c.slot for c in got.cues if c.role == "hotcue") == sorted(src_hot)) +# The demo track's memory loop starts exactly where pad A's loop does. Traktor +# draws a pad and a memory cue at one START as ONE marker (measured), so the +# projection shows it once, as the pad (decided 2026-10-16). +pad_starts = {round(c.start, 3) for c in got.cues if c.role == "hotcue"} +got_memory = [c for c in got.cues if c.role == "memory"] +check("a memory cue is shown unless a pad sits on its START", + len(got_memory) + sum(1 for c in padless + if round((c.start - dest._store.time_offset_ms( + dest._store.model_entry(ids[0]))) / 1000, 3) in pad_starts) + == n_memory, + f"{len(got_memory)} shown, pads at {sorted(pad_starts)}") +check("a shown memory cue has no pad and an id", + all(c.slot is None and c.id for c in got_memory)) # `set_analysed_grid` would place Traktor's beat-1 companion on pad A. That both # invents a cue the source never had and displaces the imported pad A cue — it @@ -230,7 +244,9 @@ many = TrackCues( grid_markers=[GridMarker(start=0.0, bpm=120.0)], cues=[CuePoint(type="cue", role="hotcue", start=float(i), length=0.0, slot=i) for i in range(8)] - + [CuePoint(type="cue", role="memory", start=99.0, length=0.0, slot=None)], + + [CuePoint(type="cue", role="memory", start=99.0, length=0.0, slot=None), + # A pad past Traktor's bank: displaced, and with no spare pad left. + CuePoint(type="cue", role="hotcue", start=50.0, length=0.0, slot=9)], ) crowded_id = dest2.add_tracks([NewTrack( track=Track(id="ignored", title="Crowded", bpm=120.0), @@ -238,11 +254,15 @@ crowded_id = dest2.add_tracks([NewTrack( cues=many, )])[0] crowded = dest2.track_cues(crowded_id) -check("the bank is filled but not overflowed", len(crowded.cues) == 8, str(len(crowded.cues))) -check("the hot cues are the ones that survived", - sorted(c.slot for c in crowded.cues) == list(range(8))) -check("the memory cue that would not fit is dropped, not misplaced", - all(c.start < 99.0 for c in crowded.cues)) +crowded_hot = [c for c in crowded.cues if c.role == "hotcue"] +check("the bank is filled but not overflowed", len(crowded_hot) == 8, str(len(crowded_hot))) +check("the hot cues keep their own pads", + sorted(c.slot for c in crowded_hot) == list(range(8)) + and all(c.start == float(c.slot) for c in crowded_hot)) +check("the memory cue stays a memory cue, and a displaced hot cue with no spare " + "pad becomes one — nothing is dropped", + sorted(round(c.start) for c in crowded.cues if c.role == "memory") == [50, 99], + str([(c.role, c.start) for c in crowded.cues])) print("== the source slot ==") # A source is a library read FROM, open alongside the loaded one. The whole slot diff --git a/backend/test_onelibrary_adapter.py b/backend/test_onelibrary_adapter.py index 5dad24d..1bad03b 100644 --- a/backend/test_onelibrary_adapter.py +++ b/backend/test_onelibrary_adapter.py @@ -317,8 +317,10 @@ memory = [c for c in cues.cues if c.role == "memory"] check("the memory cue is preserved", len(memory) == 1) check("it has no slot", memory[0].slot is None) check("it is the same loop, at the same place", abs(memory[0].start - (40.0 - OFF)) < 0.001) -check("on an editable drive every hot cue is editable, no memory cue is", - all(c.editable == (c.role == "hotcue") for c in cues.cues)) +check("on an editable drive every cue is editable, memory cues included", + all(c.editable for c in cues.cues)) +check("a memory cue is addressed by a content-derived id", + memory[0].id is not None and memory[0].id.startswith("m:"), str(memory[0].id)) _browse = OneLibraryAdapter(DRIVE, read_only=True) check("on a browsing drive no cue is editable", all(not c.editable for c in _browse.track_cues(one.id).cues)) diff --git a/backend/test_onelibrary_anlz.py b/backend/test_onelibrary_anlz.py index a8de8d4..c93bf9c 100644 --- a/backend/test_onelibrary_anlz.py +++ b/backend/test_onelibrary_anlz.py @@ -131,8 +131,8 @@ dat = dat_of(a, TRACK_1) ext = dat.with_suffix(".EXT") original = {p: p.read_bytes() for p in (dat, ext)} cues = {c.slot: c for c in a.track_cues(TRACK_1).cues if c.role == "hotcue"} -check("hot cues are editable, memory cues are not", - all(c.editable == (c.role == "hotcue") for c in a.track_cues(TRACK_1).cues)) +check("hot cues and memory cues are editable on a drive opened for editing", + all(c.editable for c in a.track_cues(TRACK_1).cues)) a.set_cue(TRACK_1, slot=5, start_sec=10.0, cue_type="cue", name="Drop") a.set_cue_color(TRACK_1, 5, "#FF0045") @@ -154,8 +154,8 @@ check("a pad can be deleted (pad D, which lives in the .EXT's PCOB)", check("deleting an empty pad is NotFound", _raises(lambda: a.delete_cue(TRACK_1, 7), NotFound)) check("a pad beyond the bank is refused", _raises(lambda: a.set_cue(TRACK_1, slot=8, start_sec=1.0, cue_type="cue"), InvalidCommand)) -check("memory cues are not editable", - _raises(lambda: a.set_cue(TRACK_1, slot=0, start_sec=1.0, cue_type="cue", role="memory"), Unsupported)) +check("set_cue refuses role=memory (memory cues have their own commands)", + _raises(lambda: a.set_cue(TRACK_1, slot=0, start_sec=1.0, cue_type="cue", role="memory"), InvalidCommand)) check("a colour must be one of rekordbox's swatches", _raises(lambda: a.set_cue_color(TRACK_1, 5, "#123456"), InvalidCommand)) a.place_cues(TRACK_1, [CuePoint(slot=1, start=30.0, length=0.0, type="cue"), @@ -256,6 +256,127 @@ check("a 44-byte compact entry has no colour bytes to patch", / "nemean.EXT", "PCO2", A.LIST_MEMORY)))[-1], 9, (1, 2, 3)) is None) +# ---- memory cues: rekordbox's own edits, byte for byte -------------------------- +# `fixtures/onelibrary-memory-edits`: six memory-cue edits rekordbox 7 made on a stick +# (kit M2, 2026-10-16), one per track. Each is replayed with `memory_cues` — the +# code the store runs — on `before/`, and the memory lists must equal `after/`. +print("== memory cues: the same edit as rekordbox 7 made, the same bytes ==") +from konduktor.adapters.onelibrary import memory_cues as M # noqa: E402 +from konduktor.adapters.onelibrary.cues import memory_cue_id # noqa: E402 + +MEMORY_EDITS = HERE / "fixtures" / "onelibrary-memory-edits" + + +def memory_edit(name: str): + return (A.parse_file(MEMORY_EDITS / "before" / f"{name}.DAT"), + A.parse_file(MEMORY_EDITS / "before" / f"{name}.EXT")) + + +def same_as_rekordbox(name: str, dat, ext) -> bool: + """Both files equal rekordbox's, tag for tag — except that when rekordbox + rewrites a `.DAT` it also re-sorts the UNTOUCHED hot-cue `PCOB` into + ascending pad order (measured: same entries, pads 3-2-1 -> 1-2-3). + Konduktor changes only the list it edits, so that one tag must hold the + same entries in either order.""" + want_dat = A.parse_file(MEMORY_EDITS / "after" / f"{name}.DAT") + want_ext = A.parse_file(MEMORY_EDITS / "after" / f"{name}.EXT") + if ext.to_bytes() != want_ext.to_bytes() or len(dat.tags) != len(want_dat.tags): + return False + for got, want in zip(dat.tags, want_dat.tags): + if (got.type, got.list_kind) == ("PCOB", A.LIST_HOT): + if sorted(A.raw_entries(got)) != sorted(A.raw_entries(want)): + return False + elif got.data != want.data: + return False + return dat.header[:8] == want_dat.header[:8] and len(dat.to_bytes()) == len(want_dat.to_bytes()) + + +def id_at(ext, time_ms: int) -> str: + return next(memory_cue_id(A.decode_entry(e)) for e in M.entries(ext, "PCO2") + if A.decode_entry(e).time == time_ms) + + +dat, ext = memory_edit("black-bloc") +M.add(dat, ext, kind=1, time_ms=131206, loop_ms=None, beats=None) +check("add a memory cue: .DAT prepended + relinked, .EXT appended compact — both FILES " + "equal rekordbox's", same_as_rekordbox("black-bloc", dat, ext)) + +dat, ext = memory_edit("formula") +M.add(dat, ext, kind=2, time_ms=80378, loop_ms=81773, beats=4) +check("add a memory loop (4 beats): rekordbox's bytes", same_as_rekordbox("formula", dat, ext)) + +dat, ext = memory_edit("lift-it") +for t in (3353, 4733, 6112, 7491, 8871, 10250, 11629, 13009): + M.add(dat, ext, kind=1, time_ms=t, loop_ms=None, beats=None) +check("add eight, up to rekordbox's cap of 10: rekordbox's bytes", + same_as_rekordbox("lift-it", dat, ext) and M.count(ext) == 10) + +dat, ext = memory_edit("wtf") +check("recolour Blue: only PCP2 byte 28 (= 7), rekordbox's bytes", + M.recolour(ext, id_at(ext, 113186), 7) and same_as_rekordbox("wtf", dat, ext)) + +dat, ext = memory_edit("sell-my-soul") +check("a comment grows the PCP2 entry by its length (88 -> 100): rekordbox's bytes", + M.rename(ext, id_at(ext, 78645), "Loopy") and same_as_rekordbox("sell-my-soul", dat, ext)) + +dat, ext = memory_edit("doomed") +check("delete: out of both lists, the survivor relinked: rekordbox's bytes", + M.delete(dat, ext, id_at(ext, 121402)) and same_as_rekordbox("doomed", dat, ext)) +check("an unknown id finds nothing", not M.delete(dat, ext, "m:1:1:4294967295")) + +print("== memory cues through the adapter, on the demo drive ==") +from konduktor.adapters.rekordbox import memory_palette # noqa: E402 + +drive = copy_of(DEMO, "Memo") +a = OneLibraryAdapter(drive) +dat = dat_of(a, TRACK_1) +ext = dat.with_suffix(".EXT") +original = {p: p.read_bytes() for p in (dat, ext)} +caps = a.capabilities().cues +check("capabilities: memory cues, cap 10, the 8-colour palette", + caps.memory_cues and caps.max_memory_cues == 10 and caps.memory_color == "palette" + and caps.memory_palette == memory_palette.SWATCHES) +before_mem = [c for c in a.track_cues(TRACK_1).cues if c.role == "memory"] +tc = a.add_memory_cue(TRACK_1, start_sec=12.0, cue_type="cue", name="Break", + color=memory_palette.SWATCHES[1]) +new = [c for c in tc.cues if c.role == "memory" and c not in before_mem] +check("add_memory_cue: named, coloured (Red), editable, with an id", + len(new) == 1 and new[0].name == "Break" and new[0].color == memory_palette.SWATCHES[1] + and new[0].editable and new[0].id, str(new)) +check("nothing reaches the drive before Save", all(p.read_bytes() == b for p, b in original.items())) +tc = a.rename_memory_cue(TRACK_1, new[0].id, "Breakdown") +tc = a.set_memory_cue_color(TRACK_1, new[0].id, None) +got = next(c for c in tc.cues if c.id == new[0].id) +check("rename and clear the colour", got.name == "Breakdown" and got.color is None, str(got)) +check("a hot-cue swatch is not a memory colour", + _raises(lambda: a.set_memory_cue_color(TRACK_1, new[0].id, "#00FF30"), InvalidCommand)) +check("an unknown id is NotFound", + _raises(lambda: a.delete_memory_cue(TRACK_1, "m:1:1:4294967295"), NotFound)) +while sum(c.role == "memory" for c in a.track_cues(TRACK_1).cues) < 10: + n = sum(c.role == "memory" for c in a.track_cues(TRACK_1).cues) + a.add_memory_cue(TRACK_1, start_sec=100.0 + n, cue_type="cue") +check("the 11th is refused", _raises(lambda: a.add_memory_cue(TRACK_1, start_sec=1.0, + cue_type="cue"), InvalidCommand)) +a.delete_memory_cue(TRACK_1, new[0].id) +check("delete removes it", all(c.id != new[0].id for c in a.track_cues(TRACK_1).cues)) +hot_before = {c.slot: (c.start, c.color) for c in a.track_cues(TRACK_1).cues if c.role == "hotcue"} +a.save() +def changed_tags(path: Path) -> set: + now, was = tags_by_key(path), tags_by_key(original[path]) + return {k for k in set(now) | set(was) if now.get(k) != was.get(k)} + + +check("Save: the .DAT changes only in its memory PCOB", + changed_tags(dat) == {("PCOB", A.LIST_MEMORY)}, str(changed_tags(dat))) +check("the .EXT only in its memory PCO2", + changed_tags(ext) == {("PCO2", A.LIST_MEMORY)}, str(changed_tags(ext))) +b = OneLibraryAdapter(drive) +check("reopened: the hot cues are untouched and 9 memory cues remain", + {c.slot: (c.start, c.color) for c in b.track_cues(TRACK_1).cues if c.role == "hotcue"} + == hot_before and sum(c.role == "memory" for c in b.track_cues(TRACK_1).cues) == 9) +b.close() +a.close() + print() print("RESULT:", "FAILED" if failed else "ALL PASSED") sys.exit(1 if failed else 0) diff --git a/backend/test_rekordbox_adapter.py b/backend/test_rekordbox_adapter.py index f5e4614..439dc53 100644 --- a/backend/test_rekordbox_adapter.py +++ b/backend/test_rekordbox_adapter.py @@ -216,8 +216,9 @@ with tempfile.TemporaryDirectory() as d: # writable hot cue with a padlock. check("ordinary hot cues are editable", all(c.editable for c in tc.cues if c.role == "hotcue" and c.type != "loop")) - check("memory cues are preserved but not editable", - all(not c.editable for c in tc.cues if c.role == "memory")) + check("memory cues are editable and addressed by id", + all(c.editable and c.id for c in tc.cues + if c.role == "memory" and c.readonly_reason is None)) check("loops are editable like any other hot cue", all(c.editable for c in tc.cues if c.type == "loop" and c.role == "hotcue")) check("an uneditable cue always says why", @@ -427,11 +428,10 @@ with tempfile.TemporaryDirectory() as d: check("a Traktor-only cue type is Unsupported", _raises(lambda: adapter.set_cue(cue_track.id, slot=2, start_sec=1.0, cue_type="fade_in"), Unsupported)) - # Rekordbox is the ONLY platform with memory cues, so they stay - # preserved-but-uneditable under the two-platform promotion rule. - check("memory cues are shown but not writable", + # A memory cue has no slot; set_cue is for pads only. + check("set_cue refuses role=memory (memory cues have their own commands)", _raises(lambda: adapter.set_cue(cue_track.id, slot=1, start_sec=1.0, - cue_type="cue", role="memory"), Unsupported)) + cue_type="cue", role="memory"), InvalidCommand)) # Slot 0 is the FIRST pad, not an error: it is Kind=1 natively. tc = adapter.set_cue(cue_track.id, slot=0, start_sec=1.0, cue_type="cue") first = [c for c in tc.cues if c.slot == 0] diff --git a/backend/test_rekordbox_fidelity.py b/backend/test_rekordbox_fidelity.py index 8fd0ae9..4fbf088 100644 --- a/backend/test_rekordbox_fidelity.py +++ b/backend/test_rekordbox_fidelity.py @@ -97,6 +97,14 @@ def diff(before: dict, after: dict, ignore_columns=("updated_at", "created_at")) return changes +def _raises(fn, exc) -> bool: + try: + fn() + except exc: + return True + return False + + def describe(changes) -> str: return "; ".join(f"{t}/{pk} {kind}" for t, pk, kind, _ in changes) or "(none)" @@ -446,6 +454,113 @@ with tempfile.TemporaryDirectory() as d: f"{mirror_row['rb_cue_count']} vs {len(records)}") adapter.close() + # ---- G2: memory cues, as rekordbox 7 writes them (kit M1, 2026-10-16) --- + print("== G2: memory cues: row shapes, colour column, mirror order, the cap of 10 ==") + import json as _json + from konduktor.adapters.rekordbox import memory_palette as _mp + from konduktor.core.adapter import InvalidCommand as _Invalid + + clean_copy(REAL, work, closing=[adapter]) + adapter = RekordboxAdapter(work) + mem_track = next((t for t in adapter.tracks if t.bpm), adapter.tracks[0]) + for c in [c for c in adapter.track_cues(mem_track.id).cues if c.role == "memory" and c.id]: + adapter.delete_memory_cue(mem_track.id, c.id) + adapter.save() + + def memory_rows(snapshot): + return {pk: r for pk, r in snapshot["djmdCue"].items() + if r["ContentID"] == mem_track.id and r["Kind"] == 0} + + before = dump(work) + adapter.add_memory_cue(mem_track.id, start_sec=60.0, cue_type="cue") + adapter.add_memory_cue(mem_track.id, start_sec=20.0, cue_type="loop", length_sec=2.0) + adapter.save() + changes = diff(before, dump(work)) + check("adding memory cues changes only djmdCue, contentCue and the counter", + {t for t, _, _, _ in changes} == {"djmdCue", "contentCue", "agentRegistry"}, + describe(changes)) + after = dump(work) + rows = sorted(memory_rows(after).values(), key=lambda r: r["InMsec"]) + point = next((r for r in rows if r["OutMsec"] == -1), None) + loop = next((r for r in rows if r["OutMsec"] > 0), None) + check("a memory point cue: Kind 0, Color -1, ColorTableIndex NULL, Comment NULL", + point is not None and (point["Color"], point["ColorTableIndex"], point["Comment"]) + == (-1, None, None), str(point and (point["Color"], point["ColorTableIndex"], point["Comment"]))) + check("a memory loop: Color 255, ColorTableIndex 0, Comment '', ActiveLoop 0, CueMicrosec 0", + loop is not None and (loop["Color"], loop["ColorTableIndex"], loop["Comment"], + loop["ActiveLoop"], loop["CueMicrosec"]) == (255, 0, "", 0, 0), + str(loop and (loop["Color"], loop["ColorTableIndex"], loop["Comment"]))) + check("its BeatLoopSize is (beats << 16) | 1", + loop is not None and loop["BeatLoopSize"] and loop["BeatLoopSize"] & 0xFFFF == 1) + + mirror = next(r for r in after["contentCue"].values() if r["ContentID"] == mem_track.id) + ids_in_mirror = [str(r["ID"]) for r in _json.loads(mirror["Cues"])] + live = [r for r in after["djmdCue"].values() if r["ContentID"] == mem_track.id] + check("the mirror lists cues in ROW order, as rekordbox does — the 20 s loop " + "added second comes after the 60 s cue", + ids_in_mirror.index(str(loop["ID"])) > ids_in_mirror.index(str(point["ID"])), + str(ids_in_mirror)) + check("rb_cue_count counts memory cues too", mirror["rb_cue_count"] == len(live)) + + cues = {c.id: c for c in adapter.track_cues(mem_track.id).cues if c.role == "memory"} + point_id = str(point["ID"]) + check("a memory cue projects with its row id, editable", + point_id in cues and cues[point_id].editable) + blue = _mp.SWATCHES[6] + adapter.set_memory_cue_color(mem_track.id, point_id, blue) + adapter.save() + row = memory_rows(dump(work))[point_id] + check("a colour is the 0-based code in Color (Blue = 6), ColorTableIndex NULL", + (row["Color"], row["ColorTableIndex"]) == (6, None), + str((row["Color"], row["ColorTableIndex"]))) + check("and projects back as that swatch", + next(c.color for c in adapter.track_cues(mem_track.id).cues if c.id == point_id) == blue) + adapter.set_memory_cue_color(mem_track.id, point_id, None) + adapter.save() + row = memory_rows(dump(work))[point_id] + check("No Color writes 255, as rekordbox does after a colour is cleared", + (row["Color"], row["ColorTableIndex"]) == (255, None), + str((row["Color"], row["ColorTableIndex"]))) + check("rekordbox memory cues have no type to choose", + _raises(lambda: adapter.set_memory_cue_type(mem_track.id, point_id, "load"), Exception)) + check("a hot-cue swatch is not a memory colour", + _raises(lambda: adapter.set_memory_cue_color(mem_track.id, point_id, "#00FF30"), _Invalid)) + before = dump(work) + adapter.rename_memory_cue(mem_track.id, point_id, "This is a comment") + adapter.save() + changes = diff(before, dump(work)) + cue_change = [c for c in changes if c[0] == "djmdCue"] + # pyrekordbox's commit stamps the row's USN too, as on every hot-cue write + # (rekordbox's own edits leave a cue row's USN NULL; it has accepted ours). + check("a rename changes only that row's Comment (and its USN)", + len(cue_change) == 1 and set(cue_change[0][3]) <= {"Comment", "rb_local_usn"} + and "Comment" in cue_change[0][3], + str(cue_change and cue_change[0][3])) + + while sum(1 for c in adapter.track_cues(mem_track.id).cues if c.role == "memory") < 10: + adapter.add_memory_cue(mem_track.id, start_sec=float( + 1 + sum(1 for c in adapter.track_cues(mem_track.id).cues if c.role == "memory")), + cue_type="cue") + adapter.save() + before = dump(work) + check("the 11th memory cue is refused (rekordbox would drop it silently)", + _raises(lambda: adapter.add_memory_cue(mem_track.id, start_sec=99.0, cue_type="cue"), + _Invalid)) + adapter.save() + check("and nothing changed", not diff(before, dump(work))) + + before = dump(work) + adapter.delete_memory_cue(mem_track.id, point_id) + adapter.save() + after = dump(work) + changes = [c for c in diff(before, after) if c[0] == "djmdCue"] + check("a delete removes the row outright (not rb_local_deleted)", + len(changes) == 1 and changes[0][2] == "DELETE", describe(changes)) + mirror = next(r for r in after["contentCue"].values() if r["ContentID"] == mem_track.id) + check("and its mirror entry", + point_id not in {str(r["ID"]) for r in _json.loads(mirror["Cues"])}) + adapter.close() + # ---- H: a grid write touches ONE tag of ONE file --------------------- print("== H: a beatgrid write is localized to the .DAT's PQTZ tag ==") from pyrekordbox.anlz import AnlzFile diff --git a/backend/test_remote_adapter.py b/backend/test_remote_adapter.py index f7ad125..460d21e 100644 --- a/backend/test_remote_adapter.py +++ b/backend/test_remote_adapter.py @@ -179,6 +179,15 @@ with tempfile.TemporaryDirectory() as d: r = c.post("/api/tracks/cue", json={"track_id": target, "slot": 4, "start": 1.0, "type": "cue"}) check("a hotcue goes to the server", r.status_code == 200 and any(cu["slot"] == 4 for cu in server_adapter.track_cues(target).model_dump()["cues"]), r.text[:200]) + r = c.post("/api/tracks/memory-cue", json={"track_id": target, "start": 2.0, "type": "cue"}) + mem = [cu for cu in server_adapter.track_cues(target).model_dump()["cues"] if cu["role"] == "memory"] + check("a memory cue goes to the server (protocol 1.3)", r.status_code == 200 and len(mem) == 1 + and any(cu["id"] == mem[0]["id"] for cu in r.json()["cues"]), r.text[:200]) + r = c.patch("/api/tracks/memory-cue", json={"track_id": target, "cue_id": mem[0]["id"], + "name": "Remote memo"}) + check("…and is renamed there, by id", r.status_code == 200 and any( + cu["name"] == "Remote memo" for cu in server_adapter.track_cues(target).model_dump()["cues"] + if cu["role"] == "memory"), r.text[:200]) check("the state says unsaved", c.get("/api/state").json()["dirty"] is True) versions = len(history.list_history(work)) r = c.post("/api/save").json() diff --git a/backend/test_remote_protocol.py b/backend/test_remote_protocol.py index be0dada..1cbebb6 100644 --- a/backend/test_remote_protocol.py +++ b/backend/test_remote_protocol.py @@ -70,6 +70,16 @@ got = through_json("set_cue", {"track_id": "a", "slot": 2, "start_sec": 1.5, "cu "length_sec": 4.0, "name": None}) check("set_cue's arguments survive", got == {"track_id": "a", "slot": 2, "start_sec": 1.5, "cue_type": "loop", "length_sec": 4.0, "name": None}, got) +got = through_json("add_memory_cue", {"track_id": "a", "start_sec": 2.5, "cue_type": "loop", + "length_sec": 2.0, "name": "Break", "color": "#1F4EED"}) +check("add_memory_cue's arguments survive", + got == {"track_id": "a", "start_sec": 2.5, "cue_type": "loop", "length_sec": 2.0, + "name": "Break", "color": "#1F4EED"}, got) +got = through_json("set_memory_cue_type", {"track_id": "a", "cue_id": "m:1", "cue_type": "load"}) +check("set_memory_cue_type's arguments survive", + got == {"track_id": "a", "cue_id": "m:1", "cue_type": "load"}, got) +got = through_json("delete_memory_cue", {"track_id": "a", "cue_id": "m:1:1:4294967295"}) +check("a memory cue id survives", got == {"track_id": "a", "cue_id": "m:1:1:4294967295"}, got) got = through_json("replace_grid", {"track_id": "a", "markers": [(0.1, 128.0), (60.0, 130.0)]}) check("a grid's (start, bpm) tuples survive", got["markers"] == [(0.1, 128.0), (60.0, 130.0)], got) cue = AutoHotcue(slot=1, start=12.0, name="Drop") diff --git a/backend/test_save_fidelity.py b/backend/test_save_fidelity.py index 1c1af1a..522de90 100644 --- a/backend/test_save_fidelity.py +++ b/backend/test_save_fidelity.py @@ -55,6 +55,14 @@ def playlist_block_span(data: bytes, uuid: str): return start, end +def _raises_playlist(fn) -> bool: + try: + fn() + except PlaylistError: + return True + return False + + def tag_lines(b: bytes) -> list[str]: return b.replace(b"><", b">\n<").decode("utf-8", "replace").splitlines() @@ -1191,5 +1199,111 @@ with tempfile.TemporaryDirectory() as d: check("O: moving a node onto its own place is not an edit", not fresh.dirty) +# ---- P: memory cues (CUE_V2 on no pad) are localized + reversible ------------ +# Measured in Traktor 4.5 (2026-10-16): a memory cue is set_hotcue's element with +# HOTCUE="-1", and Traktor keeps a Konduktor-written one byte for byte. Cues are +# inserted in START order, as Traktor itself writes them. +print("\n== P. memory cues: add / rename / delete, localized, in START order ==") +from konduktor.adapters.traktor import projection as _proj # noqa: E402 + +with tempfile.TemporaryDirectory() as d: + work = Path(d) / "collection.nml" + shutil.copy2(REAL, work) + original = work.read_bytes() + store = TraktorStore(work) + entry = store._nml.collection.entry[0] + loc = entry.location + tid = f"{loc.volume or ''}{loc.dir or ''}{loc.file or ''}" + off = store.time_offset_ms(entry) + + store.add_memory_cue(tid, 42.5, 0) + store.add_memory_cue(tid, 30.0, 5, 2.0, "Intro loop") + store.save() + edited = work.read_bytes() + os_, oe = _entry_span_by_file(original, loc.file) + es_, ee = _entry_span_by_file(edited, loc.file) + check("everything outside the ENTRY is byte-identical", + original[:os_] + b"@@" + original[oe:] == edited[:es_] + b"@@" + edited[ee:]) + added = [l for l in tag_lines(edited[es_:ee]) if l not in tag_lines(original[os_:oe])] + check("the ENTRY gains exactly the two memory cue lines", + len(added) == 2 and all('HOTCUE="-1"' in l and " 1)", + diff_count(renamed, retyped) == 2 and b'TYPE="1" START=' in retyped, + str(diff_count(renamed, retyped))) + + store = TraktorStore(work) + entry = store._nml.collection.entry[0] + for c in [c for c in _proj.to_track_cues(entry, off).cues if c.role == "memory"]: + store.delete_memory_cue(tid, c.id) + store.save() + check("add + delete round-trips to the original bytes", work.read_bytes() == original) + + store = TraktorStore(work) + check("an unknown memory cue id is refused", + _raises_playlist(lambda: store.delete_memory_cue(tid, "m:1.000000:0:0.000000:0"))) + + # A new HOT cue is inserted in START order too (it used to be appended). + entry = store._nml.collection.entry[0] + store.set_hotcue(tid, next(s for s in range(8) + if s not in {c.hotcue for c in entry.cue_v2}), 0.001, 0) + starts = [c.start or 0.0 for c in entry.cue_v2] + check("a new hot cue is inserted by START too", starts == sorted(starts), str(starts)) + +# A pad MAPPED onto a memory cue: Traktor keeps both cues at one START and draws +# one marker; Konduktor shows it once, as the pad. +with tempfile.TemporaryDirectory() as d: + work = Path(d) / "collection.nml" + shutil.copy2(REAL, work) + store = TraktorStore(work) + entry = store._nml.collection.entry[0] + loc = entry.location + tid = f"{loc.volume or ''}{loc.dir or ''}{loc.file or ''}" + off = store.time_offset_ms(entry) + store.add_memory_cue(tid, 77.0, 0) + store.add_memory_cue(tid, 88.0, 0) + free = next(s for s in range(8) if s not in {c.hotcue for c in entry.cue_v2}) + store.set_hotcue(tid, free, 77.0, 0) + tc = _proj.to_track_cues(entry, off) + check("a pad and a memory cue at one START show once, as the pad", + [round(c.start, 3) for c in tc.cues if c.role == "memory"] == [88.0] + and any(c.slot == free and round(c.start, 3) == 77.0 for c in tc.cues), + str([(c.role, c.slot, c.start) for c in tc.cues])) + check("both cues stay in the file", + sum(1 for c in entry.cue_v2 if c.grid is None and c.hotcue == -1) == 2) + print("\nRESULT:", "FAILED" if failed else "ALL PASSED") sys.exit(1 if failed else 0) diff --git a/backend/test_traktor_adapter.py b/backend/test_traktor_adapter.py index 236e2ac..49cc37e 100644 --- a/backend/test_traktor_adapter.py +++ b/backend/test_traktor_adapter.py @@ -22,13 +22,21 @@ REAL = Path(__file__).resolve().parents[1] / "collection.nml" import traktor_nml_utils as tnu # noqa: E402 from konduktor.adapters.traktor.adapter import TraktorAdapter # noqa: E402 -from konduktor.core.adapter import LibraryAdapter, Unsupported # noqa: E402 +from konduktor.core.adapter import InvalidCommand, LibraryAdapter, NotFound, Unsupported # noqa: E402 from konduktor.core.model import AutoHotcue # noqa: E402 from konduktor.core.pathmap import PathMapping # noqa: E402 failed = False +def _raises(fn, exc) -> bool: + try: + fn() + except exc: + return True + return False + + def check(label, cond, detail=""): global failed print(f" [{'PASS' if cond else 'FAIL'}] {label}" + (f" — {detail}" if detail and not cond else "")) @@ -84,7 +92,9 @@ with tempfile.TemporaryDirectory() as d: caps.writable is True and caps.readonly_cause is None) check("version read from the NML header", caps.version == "20", str(caps.version)) check("8 hotcue slots", caps.cues.hotcue_slots == 8) - check("no memory cues on Traktor", caps.cues.memory_cues is False) + check("memory cues: Traktor's cues on no pad, no limit, no colour", + caps.cues.memory_cues is True and caps.cues.max_memory_cues is None + and caps.cues.memory_color == "none") check("loops are a cue type, not a separate bank", caps.cues.loops == "cue_type") # Traktor colours a cue by its type, so no colour picker may be offered. check("no cue colours to pick", caps.cues.color == "none" and caps.cues.palette == []) @@ -142,15 +152,55 @@ with tempfile.TemporaryDirectory() as d: next(c.type for c in adapter.track_cues(tid2).cues if c.slot == free) == "load") try: adapter.set_cue(tid2, slot=free, start_sec=1.0, cue_type="cue", role="memory") - check("memory cues are refused on Traktor", False, "no error raised") - except Unsupported: - check("memory cues are refused on Traktor", True) + check("set_cue refuses role=memory (memory cues have their own commands)", False, + "no error raised") + except InvalidCommand: + check("set_cue refuses role=memory (memory cues have their own commands)", True) try: adapter.set_cue_color(tid2, free, "#FF0000") check("cue colour is refused on Traktor", False, "no error raised") except Unsupported: check("cue colour is refused on Traktor", True) + # memory cues — Traktor's cues on no pad (HOTCUE="-1") + count_before = adapter.track(tid2).cue_count + tc = adapter.add_memory_cue(tid2, start_sec=33.0, cue_type="fade_in") + mem = [c for c in tc.cues if c.role == "memory"] + check("add_memory_cue returns fresh cues with the memory cue, by id", + len(mem) == 1 and mem[0].slot is None and mem[0].id and mem[0].type == "fade_in" + and abs(mem[0].start - 33.0) < 0.001, str(mem)) + check("the hot cue bank is untouched (count and chips)", + adapter.track(tid2).hotcue_count == before + 1 + and adapter.track(tid2).cue_count == count_before + 1) + tc = adapter.rename_memory_cue(tid2, mem[0].id, "Vocal in") + renamed = next(c for c in tc.cues if c.role == "memory") + check("rename_memory_cue names it", renamed.name == "Vocal in") + tc = adapter.set_memory_cue_type(tid2, renamed.id, "load") + renamed = next(c for c in tc.cues if c.role == "memory") + check("set_memory_cue_type changes its type, keeping position and name", + (renamed.type, renamed.name, round(renamed.start, 3)) == ("load", "Vocal in", 33.0), + str(renamed)) + check("a memory loop is not retyped", + _raises(lambda: adapter.set_memory_cue_type( + tid2, next(c.id for c in adapter.add_memory_cue( + tid2, start_sec=40.0, cue_type="loop", length_sec=2.0).cues + if c.role == "memory" and c.type == "loop"), "cue"), InvalidCommand)) + adapter.delete_memory_cue(tid2, next(c.id for c in adapter.track_cues(tid2).cues + if c.role == "memory" and c.type == "loop")) + check("a memory cue colour is refused (Traktor colours by type)", + _raises(lambda: adapter.set_memory_cue_color(tid2, renamed.id, "#FF0000"), Unsupported)) + check("adding one with a colour is refused too", + _raises(lambda: adapter.add_memory_cue(tid2, start_sec=1.0, cue_type="cue", + color="#FF0000"), Unsupported)) + tc = adapter.delete_memory_cue(tid2, renamed.id) + check("delete_memory_cue removes it", not any(c.role == "memory" for c in tc.cues)) + check("an unknown id is NotFound", + _raises(lambda: adapter.delete_memory_cue(tid2, renamed.id), NotFound)) + adapter.add_memory_cue(tid2, start_sec=34.0, cue_type="cue") + summary = adapter._store._journal.summary() + check("the history message names memory cues, apart from hotcues", + "memory cue" in summary, summary) + # grid grid_before = len(adapter.track_cues(tid2).grid_markers) adapter.add_grid_marker(tid2, adapter.track_cues(tid2).grid_markers[0].start + 40.0) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 38f8319..cdeca39 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -125,8 +125,8 @@ export type TrackField = export interface CuePoint { name: string | null type: CueType - /** Memory cues have no bank slot. Only Rekordbox has them, so they are - * preserved and shown but not editable anywhere yet. */ + /** A memory cue has no bank slot (Rekordbox / OneLibrary memory cues, + * Traktor's cues on no pad) and is addressed by `id`, not `slot`. */ role: CueRole start: number // seconds length: number // seconds (>0 for loops) @@ -139,6 +139,10 @@ export interface CuePoint { /** Index of the grid marker this cue mirrors, where the platform pairs them. * A display hint only; null on platforms that do not. */ grid_marker: number | null + /** The handle the memory-cue commands take; null on a hot cue (addressed by + * slot). Opaque, and may change when THIS cue is edited — always use the + * fresh TrackCues a command returns. */ + id: string | null } /** One beatgrid marker. Its position in the list IS its index/identity. */ @@ -208,7 +212,11 @@ export interface CueCapabilities { hotcue_slots: number slot_labels: 'number' | 'letter' memory_cues: boolean + /** Per track; null = no limit. rekordbox stops at 10 without saying so. */ max_memory_cues: number | null + /** A memory cue's colours are its own palette, not `palette`. */ + memory_color: 'none' | 'palette' + memory_palette: string[] types: CueType[] color: 'none' | 'free' | 'palette' palette: string[] @@ -1141,6 +1149,28 @@ export const api = { 'DELETE', `/api/tracks/cue?track_id=${encodeURIComponent(trackId)}&slot=${slot}`, ), + /** A memory cue (a memory loop when `length` > 0). Refused past + * `capabilities.cues.max_memory_cues`. */ + addMemoryCue: (trackId: string, start: number, type: CueType, length = 0) => + send('POST', '/api/tracks/memory-cue', { track_id: trackId, start, type, length }), + /** `cueId` is `CuePoint.id`; null / '' clears the name. */ + renameMemoryCue: (trackId: string, cueId: string, name: string | null) => + send('PATCH', '/api/tracks/memory-cue', { track_id: trackId, cue_id: cueId, name }), + /** A point type from `capabilities.cues.types`; a memory loop is not retyped. */ + setMemoryCueType: (trackId: string, cueId: string, type: CueType) => + send('PATCH', '/api/tracks/memory-cue/type', { track_id: trackId, cue_id: cueId, type }), + /** From `capabilities.cues.memory_palette`; null = uncoloured. */ + setMemoryCueColor: (trackId: string, cueId: string, color: string | null) => + send('PATCH', '/api/tracks/memory-cue/color', { + track_id: trackId, + cue_id: cueId, + color, + }), + deleteMemoryCue: (trackId: string, cueId: string) => + send( + 'DELETE', + `/api/tracks/memory-cue?track_id=${encodeURIComponent(trackId)}&cue_id=${encodeURIComponent(cueId)}`, + ), /** Retempo and/or move one marker. `index` is its position in grid_markers; * a move is clamped between its neighbours rather than reordering them. */ setGridMarker: (trackId: string, index: number, patch: { bpm?: number; start?: number }) => diff --git a/frontend/src/components/HotcueBar.tsx b/frontend/src/components/HotcueBar.tsx index a72c8ca..e3af859 100644 --- a/frontend/src/components/HotcueBar.tsx +++ b/frontend/src/components/HotcueBar.tsx @@ -1,7 +1,8 @@ -import { useRef, useState, type CSSProperties } from 'react' +import type { CSSProperties } from 'react' import type { CuePoint } from '../api' import { CUE_TYPE_LABELS, cueColor, cueIcon, withAlpha } from '../lib/cues' import { Icon } from '../lib/icons' +import { RenameField } from './RenameField' interface Props { cues: CuePoint[] @@ -155,7 +156,7 @@ export function HotcueBar({ * backlit controller pad reads. Selection brightens the tint and rings it in * the colour itself, so it stays legible whichever colour the cue is. */ -function padStyle(color: string, selected: boolean): CSSProperties { +export function padStyle(color: string, selected: boolean): CSSProperties { return { // The cue colour sits on a DARK GROUND (the last layer), not on bare glass: // over a bright or warm ambient wash a thin tint alone came out the same hue @@ -178,47 +179,8 @@ function padStyle(color: string, selected: boolean): CSSProperties { /** A cue colour lifted toward white, for the pad's number: the raw colour is * too dark to read as text on its own tint (blue especially). */ -function lighten(hex: string, amount = 0.35): string { +export function lighten(hex: string, amount = 0.35): string { const v = parseInt(hex.slice(1, 7), 16) const mix = (c: number) => Math.round(c + (255 - c) * amount) return `rgb(${mix(v >> 16)},${mix((v >> 8) & 255)},${mix(v & 255)})` } - -/** The pad's name, edited in place. Enter or clicking away commits; Esc cancels. */ -function RenameField({ - initial, - onCommit, - onCancel, -}: { - initial: string - onCommit: (name: string) => void - onCancel: () => void -}) { - const [val, setVal] = useState(initial) - // Enter commits and unmounts the field, which can fire a trailing blur. - const done = useRef(false) - const finish = (commit: boolean) => { - if (done.current) return - done.current = true - if (commit && val.trim() !== initial) onCommit(val.trim()) - else onCancel() - } - return ( - setVal(e.target.value)} - onFocus={(e) => e.currentTarget.select()} - onBlur={() => finish(true)} - // The pad is a button: keep its press/preview handlers out of the field. - onPointerDown={(e) => e.stopPropagation()} - onPointerUp={(e) => e.stopPropagation()} - onKeyDown={(e) => { - e.stopPropagation() // digits and Space must type, not trigger the deck - if (e.key === 'Enter') finish(true) - else if (e.key === 'Escape') finish(false) - }} - className="w-full min-w-0 rounded bg-well px-1 text-[11px] leading-4 text-text outline-none ring-1 ring-accent" - /> - ) -} diff --git a/frontend/src/components/LoopControls.tsx b/frontend/src/components/LoopControls.tsx index ca26b2b..ef4ad13 100644 --- a/frontend/src/components/LoopControls.tsx +++ b/frontend/src/components/LoopControls.tsx @@ -1,4 +1,5 @@ import { Icon } from '../lib/icons' +import { ModeSwitch } from './ModeSwitch' /** One size, 1/32 → 32 beats, shared by beat loops AND beat jump: the number a * DJ has in their head ("4 beats") should not differ between the two. */ @@ -90,25 +91,17 @@ export function LoopControls({ // A beat jump needs a grid; moving a manual loop does not. const canMove = ready && (loopActive || hasGrid) - const tab = (m: LoopMode, text: string, title: string) => ( - - ) - return (
-
- {tab('beat', 'BEAT', 'Beat loops, sized in beats')} - {tab('manual', 'MAN', 'Manual loops: set IN and OUT')} -
+ {mode === 'beat' ? (
diff --git a/frontend/src/components/MemoryCueStrip.tsx b/frontend/src/components/MemoryCueStrip.tsx new file mode 100644 index 0000000..fccd7c6 --- /dev/null +++ b/frontend/src/components/MemoryCueStrip.tsx @@ -0,0 +1,132 @@ +import type { CuePoint } from '../api' +import { cueColor, cueIcon } from '../lib/cues' +import { Icon } from '../lib/icons' +import { lighten, padStyle } from './HotcueBar' +import { RenameField } from './RenameField' + +interface Props { + /** The track's cues; only the memory cues are shown, in time order. */ + cues: CuePoint[] + /** The deck's CUE point, so the memory cue it sits on reads as selected. */ + cuePoint: number + onCall: (cue: CuePoint) => void + /** Right-click: the deck opens its Rename / Colour / Delete menu. */ + onMenu: (cue: CuePoint, x: number, y: number) => void + onAdd: () => void + /** Why + MEMORY cannot add one (read-only library, the platform's cap), or null. */ + addRefusal: string | null + /** The memory cue whose name is being edited in place, if any. */ + renamingId: string | null + onRenameCommit: (cue: CuePoint, name: string) => void + onRenameCancel: () => void +} + +/** `m:ss.s` — a chip's label when the cue has no name. */ +function shortTime(secs: number): string { + const m = Math.floor(secs / 60) + const s = secs - m * 60 + return `${m}:${s.toFixed(1).padStart(4, '0')}` +} + +/** `m:ss.mmm` — the full position, for the chip's tooltip. */ +function fullTime(secs: number): string { + const m = Math.floor(secs / 60) + const s = secs - m * 60 + return `${m}:${s.toFixed(3).padStart(6, '0')}` +} + +const named = (cue: CuePoint) => !!cue.name && cue.name !== 'n.n.' + +/** + * The memory-cue bank: what the hot cue pads become in Memory mode. Memory cues + * have no pads, so this is + Memory, then a strip of chips in TIME order, + * scrolling sideways when it outgrows the row. + * + * Clicking a chip CALLS the cue, CDJ-style: the deck jumps there and makes it + * the CUE point (a memory loop also engages) — unlike a hot cue pad, it is not + * a trigger to perform with. Right-click edits it, as on a pad. + */ +export function MemoryCueStrip({ + cues, + cuePoint, + onCall, + onMenu, + onAdd, + addRefusal, + renamingId, + onRenameCommit, + onRenameCancel, +}: Props) { + const memory = cues.filter((c) => c.role === 'memory').sort((a, b) => a.start - b.start) + return ( + // At least one chip always shows (~6rem): the row's breakpoints fold the + // tempo group before the strip gets that narrow. +
+ +
{ + if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) e.currentTarget.scrollLeft += e.deltaY + }} + > + {memory.length === 0 && ( + + No memory cues — + Memory stores one at the playhead + + )} + {memory.map((cue) => { + const color = cueColor(cue) + const selected = Math.abs(cue.start - cuePoint) < 0.0015 + const locked = !cue.editable + const key = cue.id ?? `${cue.start}:${cue.type}` + return ( + + ) + })} +
+
+ ) +} diff --git a/frontend/src/components/ModeSwitch.tsx b/frontend/src/components/ModeSwitch.tsx new file mode 100644 index 0000000..47d6c43 --- /dev/null +++ b/frontend/src/components/ModeSwitch.tsx @@ -0,0 +1,38 @@ +/** + * The deck's two-way mode switch: two small stacked tabs in a well, the chosen + * one lit. BEAT / MAN (loops) and HOT / MEM (the cue bank) are both this. + */ +export function ModeSwitch({ + label, + value, + options, + onChange, +}: { + /** Names the group for assistive tech ("Loop mode", "Cue bank"). */ + label: string + value: T + options: { value: T; text: string; title: string }[] + onChange: (value: T) => void +}) { + return ( +
+ {options.map((o) => ( + + ))} +
+ ) +} diff --git a/frontend/src/components/PrepStrip.tsx b/frontend/src/components/PrepStrip.tsx index 94d5ddc..ab362f5 100644 --- a/frontend/src/components/PrepStrip.tsx +++ b/frontend/src/components/PrepStrip.tsx @@ -32,6 +32,8 @@ import { TrackInfoDialog } from './TrackInfoDialog' import { ContextMenu, type MenuItem } from './ContextMenu' import { BpmReadout, GridEditStrip, TempoControls, TempoFold } from './GridControls' import { HotcueBar } from './HotcueBar' +import { MemoryCueStrip } from './MemoryCueStrip' +import { ModeSwitch } from './ModeSwitch' import { LoopControls, LOOP_SIZES, type LoopMode } from './LoopControls' import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC, type StemLane } from './MainWaveform' import { OverviewWaveform } from './OverviewWaveform' @@ -156,6 +158,10 @@ export function PrepStrip({ const [gridMode, setGridMode] = useState(false) const [padMenu, setPadMenu] = useState<{ slot: number; x: number; y: number } | null>(null) const [renamingSlot, setRenamingSlot] = useState(null) + // Hot / Memory: which bank the pads' place in the row shows (persisted). + const [bankMode, setBankMode] = useState<'hot' | 'memory'>('hot') + const [memoryMenu, setMemoryMenu] = useState<{ cue: CuePoint; x: number; y: number } | null>(null) + const [renamingMemory, setRenamingMemory] = useState(null) // Loop state (transient — persisted only when saved as a hotcue later). const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null) @@ -220,6 +226,18 @@ export function PrepStrip({ writePrefs({ beatSize }) }, [beatSize, writePrefs]) + // Hot / Memory bank, remembered the same way (decided 2026-10-16). + const bankHydratedRef = useRef(false) + useEffect(() => { + if (bankHydratedRef.current || !prefsQuery.data) return + bankHydratedRef.current = true + if ((prefsQuery.data as { cueBankMode?: unknown }).cueBankMode === 'memory') setBankMode('memory') + }, [prefsQuery.data]) + useEffect(() => { + if (!bankHydratedRef.current) return // don't clobber saved prefs pre-hydration + writePrefs({ cueBankMode: bankMode }) + }, [bankMode, writePrefs]) + const getCtx = (): AudioContext => { if (!audioCtxRef.current) { audioCtxRef.current = new (window.AudioContext ?? @@ -267,6 +285,8 @@ export function PrepStrip({ setSelectedSlot(null) setPadMenu(null) setRenamingSlot(null) + setMemoryMenu(null) + setRenamingMemory(null) setLoopRegion(null) setLoopActive(false) setActiveBeats(null) @@ -830,11 +850,18 @@ export function PrepStrip({ const eng = playbackRef.current if (!eng || !eng.ready) return getCtx() - // A loop hotcue jumps to its start AND engages a loop of its length — the - // new loop FIRST, so the seek is not wrapped back into the old one. The loop - // controls follow it: a beat-sized loop takes over the shared size (so −/+ - // resize THIS loop), and one of no preset size shows in MAN, where its - // toggle is. + enterCue(cue) + seek(cue.start) + // Paused at press → momentary preview: play while held. + if (!eng.playing) beginPreview(`hc:${slot}`, cue.start) + } + + // Before jumping to a cue: a loop cue engages a loop of its length — the new + // loop FIRST, so the seek is not wrapped back into the old one. The loop + // controls follow it: a beat-sized loop takes over the shared size (so −/+ + // resize THIS loop), and one of no preset size shows in MAN, where its toggle + // is. A point cue outside an engaged loop leaves it. + const enterCue = (cue: CuePoint) => { if (cue.type === 'loop' && cue.length > 0) { const beats = beatsForLoop(cue.start, cue.length) engagLoop(cue.start, cue.start + cue.length, beats) @@ -847,9 +874,6 @@ export function PrepStrip({ } else { leaveLoopFor(cue.start) } - seek(cue.start) - // Paused at press → momentary preview: play while held. - if (!eng.playing) beginPreview(`hc:${slot}`, cue.start) } // Hotcue slot released (mouse/touch up, or key up). Ends its momentary preview. @@ -937,6 +961,125 @@ export function PrepStrip({ } } + // ---- memory cues -------------------------------------------------------- + // Cues on no pad, listed in time order (MemoryCueStrip). Calling one is + // CDJ-style: jump there and make it the CUE point — paused stays paused, + // playing keeps playing; a memory loop also engages (decided 2026-10-16). + const showMemory = caps.cues.memory_cues && bankMode === 'memory' + const memoryPalette = caps.cues.memory_color === 'palette' ? caps.cues.memory_palette : [] + const memoryCount = cueData?.cues.filter((c) => c.role === 'memory' && c.editable).length ?? 0 + const memoryCap = caps.cues.max_memory_cues + const memoryAddRefusal = !canEditCues + ? (readOnlyNotice(caps) ?? `Cues cannot be edited on ${caps.save.app_name} libraries yet.`) + : memoryCap != null && memoryCount >= memoryCap + ? `${caps.save.app_name} keeps at most ${memoryCap} memory cues per track` + : null + + const callMemoryCue = (cue: CuePoint) => { + const eng = playbackRef.current + if (!eng || !eng.ready) return + getCtx() + enterCue(cue) + seek(cue.start) + setCuePoint(cue.start) + } + + // + Memory: at the (snapped) playhead, or the engaged loop as a memory loop. + const addMemoryCue = async () => { + if (!track) return + if (memoryAddRefusal) { + onError?.(memoryAddRefusal) + return + } + try { + if (loopActive && loopRegion) { + const len = loopRegion.end - loopRegion.start + applyCueEdit(await api.addMemoryCue(track.id, loopRegion.start, 'loop', len)) + } else { + const t = snapTime(playbackRef.current?.getPosition() ?? current) + applyCueEdit(await api.addMemoryCue(track.id, t, 'cue')) + } + } catch (e) { + onError?.((e as Error).message) + } + } + + const editMemoryCue = async (edit: () => Promise) => { + if (!track || refuseCueEdit()) return + try { + applyCueEdit(await edit()) + } catch (e) { + onError?.((e as Error).message) + } + } + + const memoryMenuItems = (cue: CuePoint): MenuItem[] => { + const id = cue.id + const locked = !cue.editable || id == null + const items: MenuItem[] = [] + // Its type as one-click choices, as on a pad — where the platform has more + // than one point type (Traktor); a loop stays a loop. + if (cue.type === 'loop') { + items.push({ heading: 'Memory loop' }) + } else if (pointCueTypes.length > 1) { + items.push({ heading: 'Memory cue · Type' }) + for (const t of pointCueTypes) { + const color = cueTypeColor(t) + items.push({ + label: CUE_TYPE_LABELS[t], + icon: ( + + ), + hint: t === cue.type ? '✓' : undefined, + disabled: locked, + onClick: () => + t !== cue.type && + id != null && + void editMemoryCue(() => api.setMemoryCueType(track!.id, id, t)), + }) + } + } else { + items.push({ heading: 'Memory cue' }) + } + if (memoryPalette.length > 0) { + items.push({ separator: true }) + items.push({ heading: 'Colour' }) + items.push({ + swatches: memoryPalette, + selected: cue.color, + disabled: locked, + onPick: (color) => + color !== cue.color && + id != null && + void editMemoryCue(() => api.setMemoryCueColor(track!.id, id, color)), + }) + } + if (locked) items.push({ heading: 'Managed by the DJ app — not editable here' }) + items.push({ separator: true }) + items.push({ + label: 'Rename…', + disabled: locked, + onClick: () => !refuseCueEdit() && setRenamingMemory(id), + }) + items.push({ + label: 'Delete', + danger: true, + disabled: locked, + onClick: () => id != null && void editMemoryCue(() => api.deleteMemoryCue(track!.id, id)), + }) + return items + } + + const renameMemoryCue = (cue: CuePoint, name: string) => { + setRenamingMemory(null) + if (cue.id == null) return + const id = cue.id + void editMemoryCue(() => api.renameMemoryCue(track!.id, id, name || null)) + } + // ---- beatgrid --------------------------------------------------------- // Which marker the grid controls act on is derived from the playhead — there // is no separate selection state to keep in sync. @@ -1471,10 +1614,11 @@ export function PrepStrip({ A container, so the row gives way in stages as the window narrows instead of the pads sliding under the tempo group: the pads drop their names first (each pad queries its own width, see HotcueBar), - then below 74rem the tempo group folds into one BPM button, and below - 60rem the Grid toggle keeps only its icon. Those are the row's + then below 77rem the tempo group folds into one BPM button, and below + 63rem the Grid toggle keeps only its icon. Those are the row's measured widths just before the pad bank would hit its minimum (with - a lockable grid's extra Lock button), so move them with the controls. */} + a lockable grid's extra Lock button, and the Hot / Mem toggle's + ~3rem with its gap), so move them with the controls. */}
+ {memoryMenu && ( + setMemoryMenu(null)} + /> + )} {padMenu && ( void + onCancel: () => void +}) { + const [val, setVal] = useState(initial) + // Enter commits and unmounts the field, which can fire a trailing blur. + const done = useRef(false) + const finish = (commit: boolean) => { + if (done.current) return + done.current = true + if (commit && val.trim() !== initial) onCommit(val.trim()) + else onCancel() + } + return ( + setVal(e.target.value)} + onFocus={(e) => e.currentTarget.select()} + onBlur={() => finish(true)} + // The pad is a button: keep its press/preview handlers out of the field. + onPointerDown={(e) => e.stopPropagation()} + onPointerUp={(e) => e.stopPropagation()} + onKeyDown={(e) => { + e.stopPropagation() // digits and Space must type, not trigger the deck + if (e.key === 'Enter') finish(true) + else if (e.key === 'Escape') finish(false) + }} + className="w-full min-w-0 rounded bg-well px-1 text-[11px] leading-4 text-text outline-none ring-1 ring-accent" + /> + ) +} diff --git a/frontend/src/lib/cues.ts b/frontend/src/lib/cues.ts index adfd2d7..29bf986 100644 --- a/frontend/src/lib/cues.ts +++ b/frontend/src/lib/cues.ts @@ -11,7 +11,7 @@ const TYPE_COLORS: Record = { load: '#ffd23d', // yellow loop: '#3ddc84', // green } -const MEMORY_COLOR = '#9aa1b2' // gray +const MEMORY_COLOR = '#9aa1b2' // gray: an unknown type export const CUE_TYPE_LABELS: Record = { cue: 'Cue', @@ -43,7 +43,8 @@ const TYPE_ICONS: Record = { */ export function cueColor(cue: CuePoint): string { if (cue.color) return cue.color - if (cue.role === 'memory') return MEMORY_COLOR + // A memory cue's type colours it just as a hot cue's does (decided + // 2026-10-16) — Traktor draws both by type. Mirrors `core/cue_colors.py`. return TYPE_COLORS[cue.type] ?? MEMORY_COLOR } diff --git a/frontend/src/lib/shortcuts.ts b/frontend/src/lib/shortcuts.ts index 5bfe6bf..e7abe21 100644 --- a/frontend/src/lib/shortcuts.ts +++ b/frontend/src/lib/shortcuts.ts @@ -143,6 +143,8 @@ export const MOUSE: { title: string; rows: MouseGesture[] }[] = [ { gesture: 'Click', on: 'stem button', text: 'Mute or unmute that stem' }, { mod: 'mod', gesture: 'Click', on: 'stem button', text: 'Solo that stem' }, { gesture: 'Right-click', on: 'pad', text: 'Hotcue type, colour, rename, delete' }, + { gesture: 'Click', on: 'memory cue', text: 'Jump there and make it the CUE point (a memory loop engages)' }, + { gesture: 'Right-click', on: 'memory cue', text: 'Memory cue type, colour, rename, delete' }, ], }, {