Stem tracks are now correctly labeled in the song list

This commit is contained in:
patben8 committed 2026-10-01 13:25:13 +02:00
1 parent d7f8768d4c
commit 702e5d86a6
9 files changed
+100 -16

No files matched your search

@@ -50,12 +50,14 @@ class OneLibraryAdapter:
# ---- projection maintenance -----------------------------------------
def _rebuild(self) -> None:
self._index.rebuild(
[
projection.to_track(row, self._drive_path(row))
for row in self._store.iter_content()
]
)
from ...core.stem_file import is_stem_file
tracks = []
for row in self._store.iter_content():
path = self._drive_path(row)
tracks.append(projection.to_track(
row, path, stem=bool(path) and is_stem_file(path)))
self._index.rebuild(tracks)
def _drive_path(self, row) -> str | None:
resolved = self._store.layout.resolve(getattr(row, "path", None))
@@ -69,7 +69,7 @@ def capabilities_for(device_name: str | None = None, version: str | None = None)
tracks=TrackCapabilities(
rating_max=5, # stored 0-5 directly, as in master.db
editable_fields=[],
media_kinds=["audio"],
media_kinds=["audio", "stem"],
# `artwork` gates EDITING, and a drive is read-only here. Reading
# works: `store.cover_art` follows `content.image_id` -> `image.path`.
artwork=False,
@@ -54,7 +54,7 @@ def _bpm(row) -> float | None:
return round(int(raw) / 100.0, 2)
def to_track(row, drive_path: str | None = None) -> Track:
def to_track(row, drive_path: str | None = None, *, stem: bool = False) -> Track:
"""Project one ``Content`` row.
**The three count fields are approximations here**, and deliberately so. Cues
@@ -104,7 +104,8 @@ def to_track(row, drive_path: str | None = None) -> Track:
hotcue_count=0,
grid_marker_count=1 if (bpm and has_analysis) else 0,
grid_locked=False, # OneLibrary has no grid lock
media_kind="audio",
# What the FILE is, as the deck plays it — see the Rekordbox projection.
media_kind="stem" if stem else "audio",
)
@@ -46,7 +46,8 @@ class RekordboxAdapter:
kinds = self._store.cue_kinds()
self._index.rebuild(
[
projection.to_track(row, kinds.get(str(row.ID), ()))
projection.to_track(row, kinds.get(str(row.ID), ()),
stem=self._store.is_stem(str(row.ID)))
for row in self._store.iter_content()
]
)
@@ -68,7 +69,8 @@ class RekordboxAdapter:
"""
kinds = self._store.cue_kinds()
row = self._store.content(track_id)
self._index.replace(projection.to_track(row, kinds.get(str(row.ID), ())))
self._index.replace(projection.to_track(row, kinds.get(str(row.ID), ()),
stem=self._store.is_stem(str(row.ID))))
def close(self) -> None:
"""Release the database connection.
@@ -202,6 +204,8 @@ class RekordboxAdapter:
def set_path_mapping(self, mapping: PathMapping) -> None:
self._store.set_path_mapping(mapping)
# The FILE decides a track's media kind, and the mapping moves files.
self._rebuild()
def unresolved_path_groups(self) -> list:
"""Not checked yet: the open-time missing-files check is Traktor-only
@@ -465,7 +469,8 @@ class RekordboxAdapter:
for item, audio, measured, markers, art in prepared:
track_id = self._store.add_track(
audio, item.track, measured=measured, with_grid=bool(markers), art=art)
self._index.add(projection.to_track(self._store.content(track_id), ()))
self._index.add(projection.to_track(self._store.content(track_id), (),
stem=self._store.is_stem(track_id)))
if markers:
self._store.replace_grid(track_id, markers)
if item.cues is not None:
@@ -86,7 +86,9 @@ def capabilities_for(
# column (its Composer is a different field), so they are absent
# rather than mapped onto something approximate.
editable_fields=sorted(editable_fields or []),
media_kinds=["audio"],
# 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,
artwork=False,
@@ -97,7 +97,7 @@ def _name_of(related) -> str | None:
return None
def to_track(row, cue_kinds=()) -> Track:
def to_track(row, cue_kinds=(), *, stem: bool = False) -> Track:
"""Project one ``DjmdContent`` row.
`cue_kinds` is this track's ``(Kind, OutMsec, ColorTableIndex)`` from the store's single
@@ -156,7 +156,10 @@ def to_track(row, cue_kinds=()) -> Track:
hotcues=chips,
grid_marker_count=1 if (_bpm(row) and getattr(row, "AnalysisDataPath", None)) else 0,
grid_locked=False, # Rekordbox has no per-track grid lock
media_kind="audio",
# What the FILE is (`store.is_stem`): Rekordbox itself plays a stem
# file's mix, but Konduktor's deck plays its stems, and the Type column
# must not disagree with the deck.
media_kind="stem" if stem else "audio",
)
@@ -140,6 +140,7 @@ class RekordboxStore:
except Exception as ex: # noqa: BLE001 — surfaced as a clean 4xx
raise LibraryNotSupported(f"Could not open Rekordbox library: {ex}") from ex
self._grid_cache.clear()
self._stem_cache: dict[str, bool] = {}
self._content_cache: list | None = None
self._by_id: dict[str, object] | None = None
@@ -373,6 +374,20 @@ class RekordboxStore:
def set_path_mapping(self, mapping: PathMapping) -> None:
self._mapping = mapping or PathMapping()
def is_stem(self, track_id: str) -> bool:
"""Whether the track's FILE is a native-instruments stem file — read
from its contents (only `.m4a`/`.mp4` are opened, ~0.7 ms each), and
cached per path, since the projection asks for every track at open."""
from ...core.stem_file import is_stem_file
path = self.audio_path(track_id)
if path is None:
return False
key = str(path)
if key not in self._stem_cache:
self._stem_cache[key] = is_stem_file(path)
return self._stem_cache[key]
@property
def path_mapping(self) -> PathMapping:
return self._mapping