Improved Rekordbox adapter

This commit is contained in:
patben8 committed 2026-09-19 09:57:26 +02:00
1 parent 43e712afbd
commit 30065a94fe
8 files changed
+658 -38

No files matched your search

+80
View File
@@ -237,5 +237,85 @@ with tempfile.TemporaryDirectory() as d:
len(final.playlist_tree()) == len(before_tree),
f"{len(final.playlist_tree())} vs {len(before_tree)}")
# ---- F: a cue write touches the cue row AND its mirror ---------------
print("== F: a hot cue write is localized, and keeps the mirror in step ==")
clean_copy(REAL, work, closing=[adapter, again, final, reopened])
before = dump(work)
adapter = RekordboxAdapter(work)
cue_track = next((t for t in adapter.tracks if t.bpm), adapter.tracks[0])
adapter.set_cue(cue_track.id, slot=6, start_sec=30.0, cue_type="cue", name="Probe")
adapter.save()
changes = diff(before, dump(work))
tables_touched = {t for t, _, _, _ in changes}
# djmdCue gains a row, contentCue's mirror is rewritten, the counter moves.
# Nothing else may move — in particular not djmdContent.
check("only the cue, its mirror and the counter change",
tables_touched == {"djmdCue", "contentCue", "agentRegistry"},
str(tables_touched))
cue_rows = [c for c in changes if c[0] == "djmdCue"]
check("exactly one cue row is inserted",
len(cue_rows) == 1 and cue_rows[0][2] == "INSERT", describe(cue_rows))
if cue_rows and cue_rows[0][2] == "INSERT":
row = cue_rows[0][3]
check("it is a hot cue in the slot asked for", row["Kind"] == 6, str(row["Kind"]))
check("positions are stored in ms AND frames at 150fps",
row["InMsec"] == 30000 and row["InFrame"] == 4500,
f"{row['InMsec']}/{row['InFrame']}")
check("a non-loop has no out-point", row["OutMsec"] == -1, str(row["OutMsec"]))
check("an uncoloured cue matches Rekordbox's own convention",
row["Color"] == -1 and row["ColorTableIndex"] is None,
f"{row['Color']}/{row['ColorTableIndex']}")
check("the cue points at its track's UUID",
row["ContentUUID"] == dump(work)["djmdContent"][cue_track.id]["UUID"])
# The mirror is the trap: leaving it stale is this platform's version of
# Traktor's companion-cue desync.
mirror = [c for c in changes if c[0] == "contentCue"]
check("the JSON mirror was rewritten", len(mirror) == 1, describe(mirror))
after = dump(work)
mirror_row = next(
(r for r in after["contentCue"].values() if r["ContentID"] == cue_track.id), None
)
check("a mirror row exists for the track", mirror_row is not None)
if mirror_row:
import json as _json
records = _json.loads(mirror_row["Cues"])
live = [
r for r in after["djmdCue"].values()
if r["ContentID"] == cue_track.id and not r["rb_local_deleted"]
]
check("the mirror holds one record per cue row",
len(records) == len(live), f"{len(records)} vs {len(live)}")
check("rb_cue_count agrees with both",
mirror_row["rb_cue_count"] == len(live),
f"{mirror_row['rb_cue_count']} vs {len(live)}")
check("the mirror's id is the track's UUID",
mirror_row["ID"] == after["djmdContent"][cue_track.id]["UUID"])
check("the new cue is in the mirror", any(r["Kind"] == 6 for r in records))
# ---- G: deleting a cue removes it from both places -------------------
print("== G: deleting a cue clears the row and the mirror ==")
adapter.delete_cue(cue_track.id, 6)
adapter.save()
after = dump(work)
live = [
r for r in after["djmdCue"].values()
if r["ContentID"] == cue_track.id and r["Kind"] == 6 and not r["rb_local_deleted"]
]
check("the cue row is gone", not live, str(len(live)))
mirror_row = next(
(r for r in after["contentCue"].values() if r["ContentID"] == cue_track.id), None
)
if mirror_row:
import json as _json
records = _json.loads(mirror_row["Cues"])
check("and gone from the mirror too", not any(r["Kind"] == 6 for r in records))
check("with rb_cue_count updated",
mirror_row["rb_cue_count"] == len(records),
f"{mirror_row['rb_cue_count']} vs {len(records)}")
adapter.close()
print("\nRESULT:", "FAILED" if failed else "ALL PASSED")
sys.exit(1 if failed else 0)