Fixed Rekordbox hotcue issues

This commit is contained in:
patben8 committed 2026-09-19 12:40:05 +02:00
1 parent 5aeb9956cd
commit 00dd3fe766
9 files changed
+327 -89

No files matched your search

@@ -249,13 +249,6 @@ class RekordboxAdapter:
# ---- commands: cues ---------------------------------------------------
def _check_cue_type(self, cue_type: str) -> None:
if cue_type == "loop":
# Reading loops is fine; writing one is not. A cue row with an
# out-point does not land in the slot its Kind names — verified in
# Rekordbox — so it would silently become an uneditable memory cue.
raise Unsupported(
"Saved loops can be read but not yet written to Rekordbox libraries"
)
if cue_type not in caps.WRITABLE_CUE_TYPES:
raise Unsupported(f"Rekordbox has no cue type {cue_type!r}")
@@ -66,7 +66,7 @@ def capabilities_for(
# projected and PRESERVED but not editable (two-platform rule).
memory_cues=True,
max_memory_cues=None, # unlimited
# Loops are READ but not written — see cue_types.WRITABLE_CUE_TYPES.
# Both cue types write; Rekordbox has no fade/load types.
types=WRITABLE_CUE_TYPES,
color="palette",
palette=[], # TODO milestone 2: the built-in cue colour table
@@ -5,7 +5,24 @@ library (see the handoff's Findings section):
* ``Kind == 0`` -> a MEMORY cue: no bank slot, and Rekordbox allows any
number of them.
* ``Kind >= 1`` -> a HOT CUE occupying bank slot ``Kind``.
* ``Kind >= 1`` -> a HOT CUE.
**``Kind`` is 1-based AND it skips 4.** Konduktor's generic model numbers bank
slots from zero — slot 0 is the pad the UI labels "A", which is also how Traktor
stores its ``HOTCUE`` attribute. Rekordbox's first pad is ``Kind=1``, and the
value ``4`` is reserved: the bank runs 1, 2, 3, 5, 6, 7, 8, 9.
Measured, not guessed. A loop was written at every ``Kind`` from 1 to 8, ten
seconds apart, and read off a real deck:
Kind 1 2 3 4 5 6 7 8 9
pad A B C - D E F G H
``Kind=4`` appears on no pad at all; Rekordbox shows such a cue as a memory cue.
That one gap explains two earlier puzzles: a Rekordbox-authored loop on pad F
stored ``Kind=7``, and a Konduktor cue written as ``Kind=4`` vanished from the
bank. Getting this wrong silently moves cues to the wrong pad — or loses them
from the bank entirely.
**``Kind`` is treated as an opaque slot id.** Setting cues on pads A and C
stored 1 and 3, but the pad in the 6th position stored 7, so the slot -> letter
@@ -23,36 +40,42 @@ MEMORY_KIND = 0
# Rekordbox has no fade-in/fade-out/load cues; those are Traktor-only.
CUE_TYPES = ["cue", "loop"]
# What Konduktor will WRITE, which is currently narrower than what it reads.
#
# A loop is projected and displayed correctly, but writing one is disabled: a
# cue row carrying `OutMsec` does NOT land in the hot cue slot its `Kind` names.
# Verified in Rekordbox 7 — a row written with `Kind=4` plus an out-point showed
# up as a MEMORY cue with pad D left empty, while an identical row without an
# out-point landed on pad B exactly as `Kind=2` predicts. Rekordbox's own 4-beat
# loop on pad F (the 6th pad) stores `Kind=7`, so loops evidently use a different
# slot encoding that has not been measured yet.
#
# Writing one anyway would silently create a MEMORY cue — which Konduktor
# deliberately cannot edit or delete — on a platform with no version history.
# Preserving a loop we cannot place is strictly better than misplacing it.
WRITABLE_CUE_TYPES = ["cue"]
# What Konduktor will write. Loops were disabled for a while because a loop
# written at `Kind=4` disappeared from the bank — which turned out to be the
# reserved-Kind gap above, not anything to do with loops. Both types write.
WRITABLE_CUE_TYPES = ["cue", "loop"]
# The Kind value that is not a bank slot. Everything at or above it is shifted
# by one relative to the pad index.
RESERVED_KIND = 4
def role_and_slot(kind: int | None) -> tuple[str, int | None]:
"""(role, slot) for a native ``Kind``."""
if kind is None or kind == MEMORY_KIND:
"""(role, 0-based slot) for a native ``Kind``.
A cue at `RESERVED_KIND` occupies no pad, so it is projected as a memory cue
— which is how Rekordbox itself displays one.
"""
if kind is None or kind == MEMORY_KIND or int(kind) == RESERVED_KIND:
return "memory", None
return "hotcue", int(kind)
kind = int(kind)
return "hotcue", kind - 1 if kind < RESERVED_KIND else kind - 2
def kind_for(role: str, slot: int | None) -> int:
"""The native ``Kind`` for a generic (role, slot). Inverse of `role_and_slot`."""
"""The native ``Kind`` for a generic (role, 0-based slot).
Inverse of `role_and_slot`; skips `RESERVED_KIND`.
"""
if role == "memory":
return MEMORY_KIND
if slot is None:
raise ValueError("a hot cue needs a slot")
return int(slot)
slot = int(slot)
if slot < 0:
raise ValueError(f"a hot cue slot cannot be negative, got {slot}")
return slot + 1 if slot < RESERVED_KIND - 1 else slot + 2
def cue_type(out_msec: int | None) -> str:
@@ -133,8 +133,13 @@ def to_track_cues(cue_rows: list, grid: tuple[list[float], list[float]] | None)
into the generic marker list. Rekordbox pairs nothing with a grid marker, so
`companion` is always None — that is a Traktor convention.
Every cue is projected as `editable=False` in this milestone, because the
adapter refuses every command; the UI gates on that flag alone.
`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.
"""
markers: list[GridMarker] = []
if grid is not None:
@@ -146,20 +151,22 @@ def to_track_cues(cue_rows: list, grid: tuple[list[float], list[float]] | None)
role, slot = role_and_slot(getattr(c, "Kind", None))
out_msec = getattr(c, "OutMsec", None)
in_msec = getattr(c, "InMsec", 0) or 0
kind = cue_type(out_msec)
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"
cues.append(
CuePoint(
name=(getattr(c, "Comment", None) or None),
type=cue_type(out_msec),
type=kind,
role=role,
start=in_msec / 1000.0,
length=length,
slot=slot,
color=_cue_color(c),
editable=False,
readonly_reason="platform_managed",
editable=editable,
readonly_reason=None if editable else "platform_managed",
grid_marker=None,
)
)
+19 -7
View File
@@ -33,12 +33,13 @@ from datetime import datetime
from pathlib import Path
from sqlalchemy import func, select, text
from sqlalchemy.exc import OperationalError
from sqlalchemy.orm import joinedload
from ...core.adapter import InvalidCommand, LibraryNotSupported, NotFound, SaveOutcome
from ...core.edit_journal import EditJournal
from ...core.pathmap import PathMapping
from .cue_types import beat_loop_size
from .cue_types import beat_loop_size, kind_for
log = logging.getLogger(__name__)
@@ -485,6 +486,16 @@ class RekordboxStore:
rb_database.get_rekordbox_pid = lambda *a, **kw: 0
try:
self._db.commit(autoinc=True)
except OperationalError as ex:
# Suppressing pyrekordbox's veto does not remove SQLite's own lock:
# a running Rekordbox really does hold the database, and the raw
# error is an unhelpful 500. Say what happened and what to do.
if "locked" not in str(ex).lower():
raise
raise InvalidCommand(
"Rekordbox has the library open, so it cannot be written right "
"now. Close Rekordbox and save again — your changes are still here."
) from ex
finally:
rb_database.get_rekordbox_pid = original
@@ -519,12 +530,12 @@ class RekordboxStore:
return int(msec * RekordboxStore._FPS / 1000)
def _cue_row(self, track_id: str, slot: int):
"""The hot cue occupying `slot` on this track, or None."""
"""The hot cue occupying the 0-based generic `slot`, or None."""
t = self._tables
return (
self._db.session.query(t.DjmdCue)
.filter(t.DjmdCue.ContentID == str(track_id))
.filter(t.DjmdCue.Kind == int(slot))
.filter(t.DjmdCue.Kind == kind_for("hotcue", slot))
.filter(t.DjmdCue.rb_local_deleted == 0)
.first()
)
@@ -565,13 +576,14 @@ class RekordboxStore:
"""Create or replace the cue in `slot`. A loop is a cue with a length."""
if start_sec < 0:
raise InvalidCommand("A cue cannot be before the start of the track")
if int(slot) < 1:
raise InvalidCommand("Hot cue slots start at 1")
if int(slot) < 0:
raise InvalidCommand(f"Hot cue slot cannot be negative, got {slot}")
row = self.content(track_id)
in_ms = int(round(start_sec * 1000))
is_loop = cue_type == "loop" and length_sec > 0
out_ms = int(round((start_sec + length_sec) * 1000)) if is_loop else -1
kind = kind_for("hotcue", slot)
existing = self._cue_row(track_id, slot)
op = "add" if existing is None else "modify"
cue = existing
@@ -584,7 +596,7 @@ class RekordboxStore:
# the id of its contentCue mirror row.
ContentUUID=str(row.UUID),
UUID=str(uuid.uuid4()),
Kind=int(slot),
Kind=kind,
rb_data_status=0,
rb_local_data_status=0,
rb_local_deleted=0,
@@ -600,7 +612,7 @@ class RekordboxStore:
cue.OutFrame = self._frames(out_ms) if is_loop else 0
cue.OutMpegFrame = 0
cue.OutMpegAbs = 0
cue.Kind = int(slot)
cue.Kind = kind
if is_loop:
beats = self._loop_beats(track_id, start_sec, length_sec)
cue.BeatLoopSize = beat_loop_size(beats) if beats else None