Files
konduktor/backend/konduktor/adapters/rekordbox/capabilities.py
T

117 lines
5.2 KiB
Python

"""What a Rekordbox library can persist.
**Track metadata and playlists are writable; cues and the beatgrid are not.**
The spike verified that Rekordbox accepts writes which maintain its USN columns
(see the handoff's Findings), and those two write paths use `pyrekordbox`, which
maintains them. Cues and the grid are separate hand-written stores and stay
false until milestone 3 — the capability system exists precisely so the UI never
offers an edit that will not persist.
A **cloud-synced** library reports `writable=False` regardless: Konduktor will
not write one at all.
Two facts are already known and encoded, because getting them wrong later would
be a silent data bug rather than a missing feature:
* a saved loop is a cue with an out-point, NOT a separate bank, so
``loops="cue_type"`` — the same answer as Traktor, and NOT the
``separate_bank`` the original plan assumed;
* cue colour is a PALETTE index (``djmdCue.ColorTableIndex``), not free RGB,
and the palette is a built-in table — `djmdColor` is the *track* colour
palette and is unrelated.
"""
from __future__ import annotations
from ...core.capabilities import (
Capabilities,
CueCapabilities,
GridCapabilities,
PlaylistCapabilities,
SaveCapabilities,
TrackCapabilities,
)
from . import memory_palette, palette, track_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
# slots numeric and lets the UI label them.
HOTCUE_SLOTS = 8
def capabilities_for(
path,
version: str | None = None,
*,
cloud_synced: bool = False,
editable_fields: list[str] | None = None,
) -> Capabilities:
# A cloud-synced library is refused PERMANENTLY, not pending a milestone:
# a local edit the server did not issue could propagate a broken sync state
# to the user's other machines, which version history cannot undo.
return Capabilities(
platform="rekordbox",
version=version,
writable=not cloud_synced,
readonly_cause="cloud_synced" if cloud_synced else None,
cues=CueCapabilities(
# 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",
memory_cues=True,
# 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
# measured, see `palette`), offered in rekordbox's own order.
color="palette",
palette=[palette.hex_for(code) for code in palette.SWATCHES],
named=True, # djmdCue.Comment
loops="cue_type",
),
# The grid is written into the track's ANLZ .DAT (PQTZ). Verified:
# Rekordbox reads the grid and its BPM readout from there, and leaves a
# Konduktor-written file alone. It has no per-track grid lock.
grid=GridCapabilities(editable=True, flexible=True, lockable=False),
tracks=TrackCapabilities(
rating_max=5, # Rekordbox stores 0-5 directly, unlike Traktor's /51
# Narrower than Traktor's: `producer` and `mix` have no Rekordbox
# column (its Composer is a different field), so they are absent
# rather than mapped onto something approximate.
editable_fields=sorted(editable_fields or []),
# A stem file is held (and played by Rekordbox as its mix);
# Konduktor's deck plays its stems.
media_kinds=["audio", "stem"],
removable=True,
addable=True,
key_writable=True,
# `djmdContent.ColorID`, rekordbox's eight (see `track_palette`).
colors=list(track_palette.SWATCHES),
# djmdMixerParam (measured, see `gain`).
auto_gain=True,
normalizable=True,
artwork=False,
artwork_note=None,
),
playlists=PlaylistCapabilities(folders=True, smart="read_only", reorder=True),
save=SaveCapabilities(
app_name="Rekordbox",
library_label="master.db",
# Rekordbox holds master.db open while running and cloud-syncs it,
# so a concurrent write is riskier than Traktor's overwrite-on-exit.
overwrite_risk="while_running",
# The artefact set is master.db + N ANLZ files + masterPlaylists6.xml,
# and history.py tracks a single blob. Also, restoring master.db
# wholesale would roll back Rekordbox's auth token and sampler state.
history=False,
),
)