mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added full support for memory-cues
This commit is contained in:
1 parent
0ced274f73
commit
19a604f730
74 files changed
+2083
-274
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
@@ -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))
|
||||
@@ -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}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
])
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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."""
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 <GRID> 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(
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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] = []
|
||||
|
||||
@@ -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)
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user