Implemented beatgrid and cuepoint display in waveform

This commit is contained in:
Ben committed 2026-07-04 17:01:18 +02:00
1 parent 5454784cff
commit f88f1932dc
7 files changed
+246 -9

No files matched your search

+33
View File
@@ -18,6 +18,7 @@ from .playlist_store import PlaylistError, PlaylistStore
from .schemas import (
CollectionStatus,
CreatePlaylist,
CuePoint,
EditState,
EditTrack,
Facets,
@@ -31,6 +32,7 @@ from .schemas import (
SetEntries,
Stats,
Track,
TrackCues,
TrackPage,
)
@@ -328,6 +330,37 @@ def track_audio(track_id: str) -> FileResponse:
return FileResponse(path, media_type=mime)
@app.get("/api/tracks/cues", response_model=TrackCues)
def track_cues(track_id: str) -> TrackCues:
"""Beatgrid + cue/loop markers for a track (read-only, from the NML)."""
entry = require_store().model_entry(track_id)
if entry is None:
raise HTTPException(404, "Track not found")
grid_anchor: float | None = None
grid_bpm: float | None = None
cues: list[CuePoint] = []
for c in entry.cue_v2 or []:
grid = getattr(c, "grid", None)
start_sec = (c.start or 0.0) / 1000.0 # Traktor stores cue START in ms
if grid is not None:
if grid_anchor is None:
grid_anchor = start_sec
grid_bpm = grid.bpm
continue # grid markers are represented by the beatgrid, not as cues
cues.append(
CuePoint(
name=c.name,
type=c.type if c.type is not None else 0,
start=start_sec,
length=(c.len or 0.0) / 1000.0,
hotcue=c.hotcue if c.hotcue is not None else -1,
color=c.color,
)
)
bpm = grid_bpm if grid_bpm is not None else (entry.tempo.bpm if entry.tempo else None)
return TrackCues(bpm=bpm, grid_anchor=grid_anchor, cues=cues)
@app.put("/api/tracks/art")
async def set_track_art(track_id: str = Form(...), file: UploadFile = File(...)) -> dict:
"""Stage replacement cover art for a track (written to the file on save)."""
+15
View File
@@ -118,6 +118,21 @@ class SaveResult(BaseModel):
file_tags: list[FileTagOutcome] = []
class CuePoint(BaseModel):
name: str | None = None
type: int # Traktor: 0 cue, 1 fade-in, 2 fade-out, 3 load, 4 grid, 5 loop
start: float # seconds
length: float # seconds (>0 for loops)
hotcue: int # -1 if not assigned to a hotcue slot
color: str | None = None # "#RRGGBB" if set
class TrackCues(BaseModel):
bpm: float | None = None # beatgrid BPM (from the grid marker; falls back to tempo)
grid_anchor: float | None = None # seconds — first grid marker (beat 1 of the grid)
cues: list[CuePoint] = [] # cue/loop markers (grid markers excluded)
class EditState(BaseModel):
dirty: bool # unsaved in-memory playlist changes exist
nml_path: str