Fixed auto hotcue overlap and analysis locked hotcue

This commit is contained in:
patben8 committed 2026-09-24 14:05:35 +02:00
1 parent 46ce3db916
commit 6c123e2597
14 files changed
+132 -100

No files matched your search

+14 -7
View File
@@ -53,8 +53,10 @@ Two independent apps that talk over HTTP:
`breakdown_n` for n ≤ 3, `outro`, `last_beat`) plus an offset in BEATS; `breakdown_n` for n ≤ 3, `outro`, `last_beat`) plus an offset in BEATS;
`structure.analyse` finds the events, `auto_hotcues.plan` resolves the `structure.analyse` finds the events, `auto_hotcues.plan` resolves the
template and reports an outcome per slot (`placed` / `not_found` / template and reports an outcome per slot (`placed` / `not_found` /
`out_of_range` / `occupied` / `protected`) — "this track has no third drop" `out_of_range` / `occupied` / `protected` / `duplicate`) — "this track has
is an answer, not a silent gap. How it finds them: no third drop" is an answer, not a silent gap. Two slots resolving to the
same BEAT INDEX get one cue, in the lower slot (decided in slot order, so
request order cannot change who wins). How it finds them:
- **Everything is per bar ON THE TRACK'S GRID**, bar 1 = the first marker - **Everything is per bar ON THE TRACK'S GRID**, bar 1 = the first marker
(Traktor's convention). Bar-1 detection from audio was tried: it never (Traktor's convention). Bar-1 detection from audio was tried: it never
beat that rule, because DJ tracks start on a downbeat. beat that rule, because DJ tracks start on a downbeat.
@@ -429,8 +431,9 @@ serialization path.** It enforces:
that `<ENTRY>`** (C); a **hotcue create is localized + round-trips** with that `<ENTRY>`** (C); a **hotcue create is localized + round-trips** with
START stored in ms (D); a **grid-marker edit is localized + round-trips** (E); START stored in ms (D); a **grid-marker edit is localized + round-trips** (E);
**flexible (multi-marker) grids** add/move/delete reversibly, `delete_grid` **flexible (multi-marker) grids** add/move/delete reversibly, `delete_grid`
leaves no companion debris (I); **companion cues are protected** from hotcue leaves no companion debris (I); **companion cues are ordinary editable
commands (J); and real flexible grids in the collection project correctly (K). hotcues** — move/retype/delete work and never touch the grid marker (J); and
real flexible grids in the collection project correctly (K).
The guard that catches serialization regressions like the lxml reformatting bug. The guard that catches serialization regressions like the lxml reformatting bug.
- `test_phase3.py` — full create/add/reorder/rename/delete/save cycle stays - `test_phase3.py` — full create/add/reorder/rename/delete/save cycle stays
Traktor-valid, backup-first, COLLECTION byte-identical, original untouched. Traktor-valid, backup-first, COLLECTION byte-identical, original untouched.
@@ -570,7 +573,11 @@ frontend at `http://localhost:5173`.
marker with a white (`COLOR="#FFFFFF"`) `TYPE="0"` cue at the same position, marker with a white (`COLOR="#FFFFFF"`) `TYPE="0"` cue at the same position,
which occupies a **real hotcue slot** — but 60 of 7970 markers have none. which occupies a **real hotcue slot** — but 60 of 7970 markers have none.
Konduktor follows them, keeps them in sync, and **never invents one** (except Konduktor follows them, keeps them in sync, and **never invents one** (except
`place_grid_companion`, used only by Auto Grid). The `#FFFFFF` test is `place_grid_companion`, used only by Auto Grid). They are **not locked**:
Traktor 4 keeps a beatgrid without one, so a companion is an ordinary hotcue
the user may move, retype or delete — doing so simply ends the pairing
(it is no longer a white cue on a marker), and the grid is untouched. Grid
edits still drag or delete a companion that is still paired. The `#FFFFFF` test is
load-bearing: 49 uncoloured cues and 18 *loops* also sit within 1 ms of a load-bearing: 49 uncoloured cues and 18 *loops* also sit within 1 ms of a
marker and must not be dragged or deleted. `backend/konduktor/beatgrid.py` marker and must not be dragged or deleted. `backend/konduktor/beatgrid.py`
is the single shared definition of all of this. is the single shared definition of all of this.
@@ -817,8 +824,8 @@ diff — no COLLECTION splicing needed.
`delete_hotcue` removes a slot. (The adapter exposes these generically as `delete_hotcue` removes a slot. (The adapter exposes these generically as
`set_cue`/`set_cue_type`/`delete_cue`, taking a `cue_type` STRING — `cue`, `set_cue`/`set_cue_type`/`delete_cue`, taking a `cue_type` STRING — `cue`,
`fade_in`, `fade_out`, `load`, `loop` — which the Traktor adapter maps to the `fade_in`, `fade_out`, `load`, `loop` — which the Traktor adapter maps to the
integers below.) Hotcue commands **refuse a slot held by a grid integers below.) A grid marker's companion cue is an ordinary hotcue to these
marker's companion cue** (see "Beatgrid"). Beatgrid commands are marker-level: commands (see "Beatgrid"). Beatgrid commands are marker-level:
`add_grid_marker` (inherits the governing tempo when no BPM is given), `add_grid_marker` (inherits the governing tempo when no BPM is given),
`move_grid_marker` (clamped between its neighbours, drags the companion), `move_grid_marker` (clamped between its neighbours, drags the companion),
`set_grid_marker_bpm` (also serves ×2 / ÷2, which retempo the governing marker `set_grid_marker_bpm` (also serves ×2 / ÷2, which retempo the governing marker
@@ -123,8 +123,9 @@ def to_track_cues(entry) -> TrackCues:
The beatgrid is the FULL ordered marker list — a constant grid is a list of The beatgrid is the FULL ordered marker list — a constant grid is a list of
length one. Grid markers themselves are not cues; their companion cues are, length one. Grid markers themselves are not cues; their companion cues are,
because they occupy real hotcue slots, and each is tagged with the marker it because they occupy real hotcue slots. Each is tagged with the marker it sits
belongs to so the UI can show it as beatgrid-owned rather than editable. on, but is an ordinary, editable hotcue: Traktor 4 keeps a beatgrid without
one, so nothing depends on it staying put.
""" """
markers = beatgrid.grid_markers(entry) markers = beatgrid.grid_markers(entry)
comps = beatgrid.companions(entry) comps = beatgrid.companions(entry)
@@ -156,10 +157,8 @@ def to_track_cues(entry) -> TrackCues:
length=(c.len or 0.0) / 1000.0, length=(c.len or 0.0) / 1000.0,
slot=slot, slot=slot,
color=c.color, color=c.color,
# A grid marker's companion belongs to the beatgrid: the store editable=True,
# refuses hotcue commands on it, so say so up front. readonly_reason=None,
editable=marker is None,
readonly_reason="beatgrid_companion" if marker is not None else None,
grid_marker=marker, grid_marker=marker,
) )
) )
+1 -24
View File
@@ -468,21 +468,6 @@ class TraktorStore:
raise PlaylistError(f"Track not found: {track_id}") raise PlaylistError(f"Track not found: {track_id}")
return entry return entry
@staticmethod
def _reject_if_companion(entry: Entrytype, slot: int) -> None:
"""Refuse to touch a slot held by a grid marker's companion cue.
Traktor pairs most grid markers with a white cue in a real hotcue slot.
Overwriting, retyping or deleting one desyncs it from its marker, so the
beatgrid commands own these slots — move or delete the marker instead.
"""
cue = next((c for c in (entry.cue_v2 or []) if c.hotcue == slot), None)
if cue is not None and beatgrid.is_companion(entry, cue):
raise PlaylistError(
f"Hotcue {slot + 1} belongs to a beatgrid marker — "
"move or delete the marker instead"
)
def set_hotcue( def set_hotcue(
self, self,
track_id: str, track_id: str,
@@ -502,7 +487,6 @@ class TraktorStore:
raise PlaylistError(f"Unsupported cue type: {cue_type}") raise PlaylistError(f"Unsupported cue type: {cue_type}")
with self._lock: with self._lock:
entry = self._entry_or_raise(track_id) entry = self._entry_or_raise(track_id)
self._reject_if_companion(entry, slot)
start_ms = max(0.0, start_sec * 1000.0) # Traktor stores START/LEN in ms start_ms = max(0.0, start_sec * 1000.0) # Traktor stores START/LEN in ms
len_ms = max(0.0, length_sec * 1000.0) len_ms = max(0.0, length_sec * 1000.0)
existing = next( existing = next(
@@ -547,13 +531,8 @@ class TraktorStore:
occupied = { occupied = {
c.hotcue for c in (entry.cue_v2 or []) if c.hotcue is not None and c.hotcue >= 0 c.hotcue for c in (entry.cue_v2 or []) if c.hotcue is not None and c.hotcue >= 0
} }
# Companion slots belong to the beatgrid — never fill them, even
# with overwrite=True (occupied alone only guards them while False).
protected = {
c.hotcue for c in beatgrid.companions(entry).values() if c.hotcue is not None
}
for spec in specs: for spec in specs:
if spec.slot in protected or (not overwrite and spec.slot in occupied): if not overwrite and spec.slot in occupied:
continue continue
self.set_hotcue( self.set_hotcue(
track_id, track_id,
@@ -570,7 +549,6 @@ class TraktorStore:
raise PlaylistError(f"Unsupported cue type: {cue_type}") raise PlaylistError(f"Unsupported cue type: {cue_type}")
with self._lock: with self._lock:
entry = self._entry_or_raise(track_id) entry = self._entry_or_raise(track_id)
self._reject_if_companion(entry, slot)
cue = next((c for c in (entry.cue_v2 or []) if c.hotcue == slot), None) cue = next((c for c in (entry.cue_v2 or []) if c.hotcue == slot), None)
if cue is None: if cue is None:
raise PlaylistError(f"Hotcue {slot} is not set") raise PlaylistError(f"Hotcue {slot} is not set")
@@ -581,7 +559,6 @@ class TraktorStore:
def delete_hotcue(self, track_id: str, slot: int) -> None: def delete_hotcue(self, track_id: str, slot: int) -> None:
with self._lock: with self._lock:
entry = self._entry_or_raise(track_id) entry = self._entry_or_raise(track_id)
self._reject_if_companion(entry, slot)
before = entry.cue_v2 or [] before = entry.cue_v2 or []
entry.cue_v2 = [c for c in before if c.hotcue != slot] entry.cue_v2 = [c for c in before if c.hotcue != slot]
if len(entry.cue_v2) != len(before): # only count an actual removal if len(entry.cue_v2) != len(before): # only count an actual removal
+18 -3
View File
@@ -42,6 +42,7 @@ NOT_FOUND = "not_found" # the track has no such event (e.g. no third drop
OUT_OF_RANGE = "out_of_range" # the offset moves it before the start / past the end OUT_OF_RANGE = "out_of_range" # the offset moves it before the start / past the end
OCCUPIED = "occupied" # the slot holds a cue and overwrite was not asked for OCCUPIED = "occupied" # the slot holds a cue and overwrite was not asked for
PROTECTED = "protected" # the slot holds a cue the adapter will not replace PROTECTED = "protected" # the slot holds a cue the adapter will not replace
DUPLICATE = "duplicate" # a lower slot is already getting a cue on this beat
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -59,6 +60,7 @@ class SlotOutcome:
status: str status: str
start: float | None = None start: float | None = None
name: str | None = None name: str | None = None
duplicate_of: int | None = None # the slot that got this beat, for DUPLICATE
def cue_name(event: str, offset_beats: int) -> str: def cue_name(event: str, offset_beats: int) -> str:
@@ -75,11 +77,19 @@ def plan(
"""Decide every requested slot. """Decide every requested slot.
``existing`` maps each occupied slot to whether its cue is EDITABLE — a ``existing`` maps each occupied slot to whether its cue is EDITABLE — a
non-editable one (a Traktor grid marker's companion) is never replaced, even non-editable one (a cue the platform manages itself) is never replaced, even
when overwrite is ticked, because the adapter would refuse it anyway. when overwrite is ticked, because the adapter would refuse it anyway.
Two slots that resolve to the SAME BEAT get one cue, in the lower slot: a
second pad on the same beat is a wasted pad, and it happens by construction
(Build 2 is Breakdown 1 when two drops are close). Slots are decided in slot
order so "lower wins" holds whatever order the request lists them in, and
the comparison is on the beat INDEX — exact, where comparing seconds would
need a tolerance.
""" """
out: list[SlotOutcome] = [] out: list[SlotOutcome] = []
for r in requests: taken: dict[int, int] = {} # beat index -> the slot placing a cue there
for r in sorted(requests, key=lambda r: r.slot):
if r.slot in existing and not existing[r.slot]: if r.slot in existing and not existing[r.slot]:
out.append(SlotOutcome(r.slot, r.event, PROTECTED)) out.append(SlotOutcome(r.slot, r.event, PROTECTED))
continue continue
@@ -90,9 +100,14 @@ def plan(
if beat is None: if beat is None:
out.append(SlotOutcome(r.slot, r.event, NOT_FOUND)) out.append(SlotOutcome(r.slot, r.event, NOT_FOUND))
continue continue
t = structure.beat_time(beat + r.offset_beats) index = beat + r.offset_beats
t = structure.beat_time(index)
if t < 0 or t >= structure.duration: if t < 0 or t >= structure.duration:
out.append(SlotOutcome(r.slot, r.event, OUT_OF_RANGE)) out.append(SlotOutcome(r.slot, r.event, OUT_OF_RANGE))
continue continue
if index in taken:
out.append(SlotOutcome(r.slot, r.event, DUPLICATE, duplicate_of=taken[index]))
continue
taken[index] = r.slot
out.append(SlotOutcome(r.slot, r.event, PLACED, round(t, 4), cue_name(r.event, r.offset_beats))) out.append(SlotOutcome(r.slot, r.event, PLACED, round(t, 4), cue_name(r.event, r.offset_beats)))
return out return out
+1 -1
View File
@@ -131,7 +131,7 @@ class CuePoint(BaseModel):
# False when the adapter refuses commands on this cue — the UI gates on THIS # False when the adapter refuses commands on this cue — the UI gates on THIS
# rather than on any platform-specific reason. # rather than on any platform-specific reason.
editable: bool = True editable: bool = True
readonly_reason: Literal["beatgrid_companion", "platform_managed"] | None = None readonly_reason: Literal["platform_managed"] | None = None
# Index of the grid marker this cue mirrors, where the platform pairs them. # Index of the grid marker this cue mirrors, where the platform pairs them.
# A display hint only; None on platforms that do not. # A display hint only; None on platforms that do not.
grid_marker: int | None = None grid_marker: int | None = None
+4 -3
View File
@@ -823,9 +823,10 @@ def auto_hotcues(body: AutoHotcuesRequest) -> AutoHotcuesResult:
Each requested slot is bound to an event (``drop_1``, ``outro``, …) plus an Each requested slot is bound to an event (``drop_1``, ``outro``, …) plus an
offset in beats. Every slot reports an outcome — placed, not found, out of offset in beats. Every slot reports an outcome — placed, not found, out of
range, occupied (a cue is there and overwrite was not asked for) or range, occupied (a cue is there and overwrite was not asked for), protected
protected (a cue the adapter will not replace) — so the UI can say which (a cue the adapter will not replace) or duplicate (a lower slot already got
events this track does not have. Requires a beatgrid. that beat) — so the UI can say which events this track does not have.
Requires a beatgrid.
""" """
a = require_adapter() a = require_adapter()
cues = a.track_cues(body.track_id) cues = a.track_cues(body.track_id)
+2 -1
View File
@@ -88,7 +88,7 @@ AutoCueEvent = Literal[
"build_3", "drop_3", "breakdown_3", "build_3", "drop_3", "breakdown_3",
"outro", "last_beat", "outro", "last_beat",
] ]
AutoCueStatus = Literal["placed", "not_found", "out_of_range", "occupied", "protected"] AutoCueStatus = Literal["placed", "not_found", "out_of_range", "occupied", "protected", "duplicate"]
class AutoCueSlot(BaseModel): class AutoCueSlot(BaseModel):
@@ -111,6 +111,7 @@ class AutoCueOutcome(BaseModel):
status: AutoCueStatus status: AutoCueStatus
start: float | None = None # seconds, when placed start: float | None = None # seconds, when placed
name: str | None = None name: str | None = None
duplicate_of: int | None = None # for "duplicate": the slot that got this beat
+26
View File
@@ -154,6 +154,25 @@ check("an occupied slot is left alone by default", out[4].status == ah.OCCUPIED)
check("…and replaced when overwrite is asked for", out[5].status == ah.PLACED) check("…and replaced when overwrite is asked for", out[5].status == ah.PLACED)
check("a protected cue is never replaced, even with overwrite", out[6].status == ah.PROTECTED) check("a protected cue is never replaced, even with overwrite", out[6].status == ah.PROTECTED)
print("== plan: two slots on the same beat get ONE cue, in the lower slot ==")
dup = fake_structure({"drop_1": 128, "breakdown_1": 112, "build_2": 112})
out = {o.slot: o for o in ah.plan(dup, [
R(3, "breakdown_1"),
R(4, "build_2"), # the same beat as slot 3, by a different event
R(5, "drop_1", -16), # …and again, by an offset (128 - 16 = 112)
R(6, "drop_1", -15), # one beat later: a different beat, placed
], existing={})}
check("the lower slot keeps the beat", out[3].status == ah.PLACED)
check("a higher slot on the same beat is skipped", out[4].status == ah.DUPLICATE and out[4].duplicate_of == 3, str(out[4]))
check("…whichever event or offset got it there", out[5].status == ah.DUPLICATE and out[5].duplicate_of == 3, str(out[5]))
check("one beat apart is not a duplicate", out[6].status == ah.PLACED)
rev = {o.slot: o.status for o in ah.plan(dup, [R(4, "build_2"), R(3, "breakdown_1")], existing={})}
check("lower slot wins whatever order the request lists them in",
rev == {3: ah.PLACED, 4: ah.DUPLICATE}, str(rev))
kept = {o.slot: o.status for o in ah.plan(dup, [R(3, "breakdown_1"), R(4, "build_2")], existing={3: True})}
check("a slot that is NOT placed (occupied) does not claim its beat",
kept == {3: ah.OCCUPIED, 4: ah.PLACED}, str(kept))
flex = structure.Structure(beats=np.r_[np.arange(0, 10, 0.5), np.arange(10, 30, 1.0)], bar0=0, n_bars=10, duration=30) flex = structure.Structure(beats=np.r_[np.arange(0, 10, 0.5), np.arange(10, 30, 1.0)], bar0=0, n_bars=10, duration=30)
flex.events = {"drop_1": 24} # beat 24 is at 14 s (20 beats at 0.5 s, then 4 at 1.0 s) flex.events = {"drop_1": 24} # beat 24 is at 14 s (20 beats at 0.5 s, then 4 at 1.0 s)
o = ah.plan(flex, [R(0, "drop_1", -8)], {})[0] o = ah.plan(flex, [R(0, "drop_1", -8)], {})[0]
@@ -198,6 +217,13 @@ with tempfile.TemporaryDirectory() as d:
r2 = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f1, "event": "drop_1"}]}) r2 = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f1, "event": "drop_1"}]})
check("running again leaves the now-occupied slot alone", check("running again leaves the now-occupied slot alone",
r2.status_code == 200 and r2.json()["outcomes"][0]["status"] == "occupied", r2.text[:200]) r2.status_code == 200 and r2.json()["outcomes"][0]["status"] == "occupied", r2.text[:200])
f3, f4 = free_slots(a.track_cues(tid))[:2]
r = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [
{"slot": f3, "event": "first_beat"}, {"slot": f4, "event": "drop_1", "offset_beats": -64},
]})
oc = {o["slot"]: o for o in r.json()["outcomes"]} if r.status_code == 200 else {}
check("the route reports a same-beat slot as a duplicate of the lower one",
oc.get(f4, {}).get("status") == "duplicate" and oc[f4]["duplicate_of"] == f3, r.text[:300])
r = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f0, "event": "drop_1"}, {"slot": f0, "event": "outro"}]}) r = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f0, "event": "drop_1"}, {"slot": f0, "event": "outro"}]})
check("a slot requested twice is refused", r.status_code == 400) check("a slot requested twice is refused", r.status_code == 400)
r = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f0, "event": "the_best_bit"}]}) r = c.post("/api/tracks/cue/auto", json={"track_id": tid, "slots": [{"slot": f0, "event": "the_best_bit"}]})
+46 -36
View File
@@ -594,55 +594,65 @@ with tempfile.TemporaryDirectory() as d:
check("I: delete_grid keeps TEMPO", e3.tempo is not None and e3.tempo.bpm == orig_tempo) check("I: delete_grid keeps TEMPO", e3.tempo is not None and e3.tempo.bpm == orig_tempo)
# ---- Invariant J: companion cues are protected from hotcue edits ------- # ---- Invariant J: companion cues are ordinary, editable hotcues ---------
print("== J. grid companion cues cannot be clobbered by hotcue commands ==") # Traktor 4 keeps a beatgrid without its white beat-1 cue, so the cue is not
# the grid's to protect: every hotcue command works on it, and none of them may
# touch the grid marker it happened to sit on.
print("== J. grid companion cues are editable, and editing one leaves the grid alone ==")
with tempfile.TemporaryDirectory() as d: with tempfile.TemporaryDirectory() as d:
work = Path(d) / "collection.nml" work = Path(d) / "collection.nml"
shutil.copy2(REAL, work) shutil.copy2(REAL, work)
original = work.read_bytes()
store = TraktorStore(work) def fresh():
entry = next( st = TraktorStore(work)
e for e in store._nml.collection.entry if bg.companions(e).get(0) is not None e = next(e for e in st._nml.collection.entry if bg.companions(e).get(0) is not None)
) tid = f"{e.location.volume or ''}{e.location.dir or ''}{e.location.file or ''}"
track_id = f"{entry.location.volume or ''}{entry.location.dir or ''}{entry.location.file or ''}" return st, tid, bg.companions(e)[0].hotcue, [(m.start, m.grid.bpm) for m in bg.grid_markers(e)]
slot = bg.companions(entry)[0].hotcue
for label, fn in [ for label, fn in [
("set_hotcue", lambda: store.set_hotcue(track_id, slot, 5.0, 0)), ("set_hotcue moves it", lambda st, tid, slot: st.set_hotcue(tid, slot, 5.0, 0)),
("set_hotcue_type", lambda: store.set_hotcue_type(track_id, slot, 1)), ("set_hotcue_type retypes it", lambda st, tid, slot: st.set_hotcue_type(tid, slot, 1)),
("delete_hotcue", lambda: store.delete_hotcue(track_id, slot)), ("delete_hotcue deletes it", lambda st, tid, slot: st.delete_hotcue(tid, slot)),
]: ]:
store, track_id, slot, grid_before = fresh()
try: try:
fn() fn(store, track_id, slot)
check(f"J: {label} refuses a companion slot", False, "no error raised") ok = True
except PlaylistError: except PlaylistError as ex:
check(f"J: {label} refuses a companion slot", True) ok = False
check(f"J: {label}", False, str(ex))
if ok:
e = store.model_entry(track_id)
check(f"J: {label}", store.dirty is True)
check(f"J: …and the grid is unchanged ({label.split()[0]})",
[(m.start, m.grid.bpm) for m in bg.grid_markers(e)] == grid_before)
check(f"J: …and it is no longer the marker's companion ({label.split()[0]})",
0 not in bg.companions(e))
check("J: refusals leave the store clean", store.dirty is False) store, track_id, slot, _ = fresh()
store.save() from konduktor.adapters.traktor.projection import to_track_cues
check("J: save after refusals is byte-identical", work.read_bytes() == original) proj = to_track_cues(store.model_entry(track_id))
comp_cue = next(c for c in proj.cues if c.slot == slot)
check("J: the projection offers it as editable",
comp_cue.editable is True and comp_cue.readonly_reason is None)
# The guard must be narrow: a free slot in the same track still works. # Auto Hotcues treats it like any other occupied slot.
used = {c.hotcue for c in (entry.cue_v2 or []) if c.hotcue is not None and c.hotcue >= 0}
free = next(s_ for s_ in range(8) if s_ not in used)
store.set_hotcue(track_id, free, 12.0, 0)
check("J: a non-companion slot is still editable", store.dirty is True)
# Auto Hotcues must skip companion slots even when told to overwrite.
store2 = TraktorStore(work)
spec = type("S", (), {"slot": slot, "start": 42.0, "name": "X", "type": 0, "length": 0.0})() spec = type("S", (), {"slot": slot, "start": 42.0, "name": "X", "type": 0, "length": 0.0})()
store2.place_hotcues(track_id, [spec], overwrite=True) store.place_hotcues(track_id, [spec])
e2 = store2.model_entry(track_id) e = store.model_entry(track_id)
comp = bg.companions(e2).get(0) check("J: place_hotcues leaves it alone without overwrite",
check("J: place_hotcues(overwrite) skips a companion slot", bg.companions(e).get(0) is not None)
comp is not None and abs(comp.start - 42_000.0) > 1) store.place_hotcues(track_id, [spec], overwrite=True)
e = store.model_entry(track_id)
check("J: place_hotcues(overwrite) replaces it",
any(c.hotcue == slot and abs(c.start - 42_000.0) < 1 for c in (e.cue_v2 or [])))
# Deleting the grid releases the slot it was holding. # Deleting the grid still removes a companion that is still on its marker.
store2.delete_grid(track_id) store, track_id, slot, _ = fresh()
e2 = store2.model_entry(track_id) store.delete_grid(track_id)
e = store.model_entry(track_id)
check("J: delete_grid frees the companion's hotcue slot", check("J: delete_grid frees the companion's hotcue slot",
not any(c.hotcue == slot for c in (e2.cue_v2 or []))) not any(c.hotcue == slot for c in (e.cue_v2 or [])))
# ---- Invariant K: real flexible grids project correctly (read-only) ---- # ---- Invariant K: real flexible grids project correctly (read-only) ----
+6 -3
View File
@@ -120,7 +120,7 @@ export interface CuePoint {
/** False when the adapter refuses commands on this cue. Gate on THIS, never /** False when the adapter refuses commands on this cue. Gate on THIS, never
* on a platform-specific reason like grid_marker. */ * on a platform-specific reason like grid_marker. */
editable: boolean editable: boolean
readonly_reason: 'beatgrid_companion' | 'platform_managed' | null readonly_reason: 'platform_managed' | null
/** Index of the grid marker this cue mirrors, where the platform pairs them. /** Index of the grid marker this cue mirrors, where the platform pairs them.
* A display hint only; null on platforms that do not. */ * A display hint only; null on platforms that do not. */
grid_marker: number | null grid_marker: number | null
@@ -166,8 +166,10 @@ export interface AutoCueSlot {
/** What happened to one requested slot. `not_found`: the track has no such /** What happened to one requested slot. `not_found`: the track has no such
* event (e.g. no third drop); `out_of_range`: the offset moves it outside the * event (e.g. no third drop); `out_of_range`: the offset moves it outside the
* track; `occupied`: a cue is there and overwrite was off; `protected`: a cue * track; `occupied`: a cue is there and overwrite was off; `protected`: a cue
* the adapter will not replace (a grid marker's). */ * the adapter will not replace (a grid marker's); `duplicate`: a lower slot
export type AutoCueStatus = 'placed' | 'not_found' | 'out_of_range' | 'occupied' | 'protected' * already got a cue on the same beat (`duplicate_of`). */
export type AutoCueStatus =
| 'placed' | 'not_found' | 'out_of_range' | 'occupied' | 'protected' | 'duplicate'
export interface AutoCueOutcome { export interface AutoCueOutcome {
slot: number slot: number
@@ -175,6 +177,7 @@ export interface AutoCueOutcome {
status: AutoCueStatus status: AutoCueStatus
start: number | null start: number | null
name: string | null name: string | null
duplicate_of: number | null
} }
export interface AutoHotcuesResult { export interface AutoHotcuesResult {
+2 -1
View File
@@ -232,7 +232,8 @@ export function AutoCueDialog({ track, slotCount, slotLabel, existing, onClose,
<p className="mt-3 text-[11px] leading-relaxed text-faint"> <p className="mt-3 text-[11px] leading-relaxed text-faint">
Events are found on the beatgrid, counting bar 1 from its first marker — if drops land a Events are found on the beatgrid, counting bar 1 from its first marker — if drops land a
bar or two off, move the grid marker onto the first downbeat. Occupied slots are kept bar or two off, move the grid marker onto the first downbeat. Occupied slots are kept
unless you tick Replace. Your slot setup is remembered for the next track. unless you tick Replace. If two slots land on the same beat, only the lower one gets
the cue. Your slot setup is remembered for the next track.
</p> </p>
</div> </div>
+2 -5
View File
@@ -13,7 +13,6 @@ interface Props {
} }
const READONLY_LABELS: Record<string, string> = { const READONLY_LABELS: Record<string, string> = {
beatgrid_companion: 'Beatgrid marker — managed by the grid controls',
platform_managed: 'Managed by the DJ app — not editable here', platform_managed: 'Managed by the DJ app — not editable here',
} }
@@ -25,10 +24,8 @@ const READONLY_LABELS: Record<string, string> = {
* can implement momentary "cue preview" (play while held). Press creates when * can implement momentary "cue preview" (play while held). Press creates when
* empty and jumps/triggers when assigned; release ends any preview. * empty and jumps/triggers when assigned; release ends any preview.
* *
* A slot may be held by a grid marker's companion cue (Traktor writes one beside * A cue the adapter will not edit (`editable: false`) shows a lock and only
* most of its own markers). Those belong to the beatgrid, so they are shown with * seeks; the backend would refuse the edit, and showing that up front is better
* the marker colour and a ⊞ instead of a number, and pressing one only seeks —
* the backend refuses hotcue edits on them, and showing that up front is better
* than surfacing the refusal as an error. * than surfacing the refusal as an error.
*/ */
export function HotcueBar({ export function HotcueBar({
+5 -7
View File
@@ -648,12 +648,6 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify, fromDevic
const onSlotPress = async (slot: number) => { const onSlotPress = async (slot: number) => {
if (!track) return if (!track) return
const cue = hotcueAt(slot) const cue = hotcueAt(slot)
// A grid marker's companion cue holds this slot. It belongs to the beatgrid,
// so pressing it only seeks — never create, retype, select or preview.
if (cue?.grid_marker != null) {
seekManual(cue.start)
return
}
if (!cue) { if (!cue) {
if (refuseCueEdit()) return if (refuseCueEdit()) return
try { try {
@@ -710,8 +704,12 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify, fromDevic
const placed = by('placed').length const placed = by('placed').length
const missing = [...by('not_found'), ...by('out_of_range')].map((o) => eventLabel(o.event)) const missing = [...by('not_found'), ...by('out_of_range')].map((o) => eventLabel(o.event))
const kept = by('occupied').length + by('protected').length const kept = by('occupied').length + by('protected').length
const dupes = by('duplicate').map(
(o) => `${slotLabel(o.slot)} (same beat as ${slotLabel(o.duplicate_of ?? o.slot)})`,
)
const parts = [`Placed ${placed} hotcue${placed === 1 ? '' : 's'}`] const parts = [`Placed ${placed} hotcue${placed === 1 ? '' : 's'}`]
if (missing.length) parts.push(`not in this track: ${missing.join(', ')}`) if (missing.length) parts.push(`not in this track: ${missing.join(', ')}`)
if (dupes.length) parts.push(`skipped ${dupes.join(', ')}`)
if (kept) parts.push(`${kept} occupied slot${kept === 1 ? '' : 's'} kept`) if (kept) parts.push(`${kept} occupied slot${kept === 1 ? '' : 's'} kept`)
onNotify?.(placed ? 'success' : 'error', parts.join(' · ')) onNotify?.(placed ? 'success' : 'error', parts.join(' · '))
} }
@@ -740,7 +738,7 @@ export function PrepStrip({ track, playRequest = 0, onError, onNotify, fromDevic
const deleteHotcueSlot = async (slot: number) => { const deleteHotcueSlot = async (slot: number) => {
const existing = hotcueAt(slot) const existing = hotcueAt(slot)
if (!track || !existing) return // nothing to remove in an empty slot if (!track || !existing) return // nothing to remove in an empty slot
if (existing.grid_marker != null) return // beatgrid-owned: delete the marker instead if (!existing.editable) return // the adapter would refuse it
if (refuseCueEdit()) return if (refuseCueEdit()) return
try { try {
applyCueEdit(await api.deleteCue(track.id, slot)) applyCueEdit(await api.deleteCue(track.id, slot))
-3
View File
@@ -90,9 +90,6 @@ export function drawCues(
const flagH = Math.round(14 * dpr) const flagH = Math.round(14 * dpr)
const half = Math.floor(lineW / 2) const half = Math.floor(lineW / 2)
for (const cue of cues) { for (const cue of cues) {
// A grid marker's companion cue is drawn by drawBeatgrid; painting it here
// too would stack a flag on top of every marker line.
if (cue.grid_marker != null) continue
const color = cueColor(cue) const color = cueColor(cue)
const x = Math.round(timeToX(cue.start)) const x = Math.round(timeToX(cue.start))