mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Stem tracks are now correctly labeled in the song list
This commit is contained in:
1 parent
d7f8768d4c
commit
702e5d86a6
9 files changed
+100
-16
No files matched your search
@@ -336,6 +336,10 @@ Two independent apps that talk over HTTP:
|
|||||||
big collection unchanged, though every one of those is NI's default
|
big collection unchanged, though every one of those is NI's default
|
||||||
layout. Without it the entry read as plain audio (Type column, playlist
|
layout. Without it the entry read as plain audio (Type column, playlist
|
||||||
`TYPE="TRACK"`) while the deck, which reads the file, played stems.
|
`TYPE="TRACK"`) while the deck, which reads the file, played stems.
|
||||||
|
Rekordbox and OneLibrary have no such element, so their projections take
|
||||||
|
`media_kind` from the FILE (`stem_file.is_stem_file`, only `.m4a`/`.mp4`
|
||||||
|
opened, ~0.7 ms each, cached per path in `RekordboxStore.is_stem`) — the
|
||||||
|
same mismatch otherwise: Type said audio while the deck played stems.
|
||||||
- `importer.py` also serves the folder add: `reference=True` adds each file
|
- `importer.py` also serves the folder add: `reference=True` adds each file
|
||||||
where it is (nothing to copy or roll back), and every planned file the
|
where it is (nothing to copy or roll back), and every planned file the
|
||||||
destination already points at (matched on `audio_path`, never the display
|
destination already points at (matched on `audio_path`, never the display
|
||||||
@@ -854,7 +858,9 @@ serialization path.** It enforces:
|
|||||||
out-of-range / non-stem requests 404; the cache reuses, follows an edited
|
out-of-range / non-stem requests 404; the cache reuses, follows an edited
|
||||||
file, evicts LRU but never what it just wrote; the folder origin serves too
|
file, evicts LRU but never what it just wrote; the folder origin serves too
|
||||||
and lists the file as a stem track; a stem file ADDED from a folder gets
|
and lists the file as a stem track; a stem file ADDED from a folder gets
|
||||||
`<STEMS>` and a `TYPE="STEM"` playlist key, the MP3 beside it neither.
|
`<STEMS>` and a `TYPE="STEM"` playlist key, the MP3 beside it neither. On a
|
||||||
|
Rekordbox copy, an added stem file projects as a stem track (also after a
|
||||||
|
reopen) and the deck is offered its stems.
|
||||||
- `test_traktor_adapter.py` — the **generic layer**: one parse per open, the
|
- `test_traktor_adapter.py` — the **generic layer**: one parse per open, the
|
||||||
projection refreshing after every command family, cue-type translation,
|
projection refreshing after every command family, cue-type translation,
|
||||||
capabilities, and `set_analysed_grid` vs `replace_grid`. `test_save_fidelity`
|
capabilities, and `set_analysed_grid` vs `replace_grid`. `test_save_fidelity`
|
||||||
|
|||||||
@@ -50,12 +50,14 @@ class OneLibraryAdapter:
|
|||||||
|
|
||||||
# ---- projection maintenance -----------------------------------------
|
# ---- projection maintenance -----------------------------------------
|
||||||
def _rebuild(self) -> None:
|
def _rebuild(self) -> None:
|
||||||
self._index.rebuild(
|
from ...core.stem_file import is_stem_file
|
||||||
[
|
|
||||||
projection.to_track(row, self._drive_path(row))
|
tracks = []
|
||||||
for row in self._store.iter_content()
|
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:
|
def _drive_path(self, row) -> str | None:
|
||||||
resolved = self._store.layout.resolve(getattr(row, "path", 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(
|
tracks=TrackCapabilities(
|
||||||
rating_max=5, # stored 0-5 directly, as in master.db
|
rating_max=5, # stored 0-5 directly, as in master.db
|
||||||
editable_fields=[],
|
editable_fields=[],
|
||||||
media_kinds=["audio"],
|
media_kinds=["audio", "stem"],
|
||||||
# `artwork` gates EDITING, and a drive is read-only here. Reading
|
# `artwork` gates EDITING, and a drive is read-only here. Reading
|
||||||
# works: `store.cover_art` follows `content.image_id` -> `image.path`.
|
# works: `store.cover_art` follows `content.image_id` -> `image.path`.
|
||||||
artwork=False,
|
artwork=False,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def _bpm(row) -> float | None:
|
|||||||
return round(int(raw) / 100.0, 2)
|
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.
|
"""Project one ``Content`` row.
|
||||||
|
|
||||||
**The three count fields are approximations here**, and deliberately so. Cues
|
**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,
|
hotcue_count=0,
|
||||||
grid_marker_count=1 if (bpm and has_analysis) else 0,
|
grid_marker_count=1 if (bpm and has_analysis) else 0,
|
||||||
grid_locked=False, # OneLibrary has no grid lock
|
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()
|
kinds = self._store.cue_kinds()
|
||||||
self._index.rebuild(
|
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()
|
for row in self._store.iter_content()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -68,7 +69,8 @@ class RekordboxAdapter:
|
|||||||
"""
|
"""
|
||||||
kinds = self._store.cue_kinds()
|
kinds = self._store.cue_kinds()
|
||||||
row = self._store.content(track_id)
|
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:
|
def close(self) -> None:
|
||||||
"""Release the database connection.
|
"""Release the database connection.
|
||||||
@@ -202,6 +204,8 @@ class RekordboxAdapter:
|
|||||||
|
|
||||||
def set_path_mapping(self, mapping: PathMapping) -> None:
|
def set_path_mapping(self, mapping: PathMapping) -> None:
|
||||||
self._store.set_path_mapping(mapping)
|
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:
|
def unresolved_path_groups(self) -> list:
|
||||||
"""Not checked yet: the open-time missing-files check is Traktor-only
|
"""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:
|
for item, audio, measured, markers, art in prepared:
|
||||||
track_id = self._store.add_track(
|
track_id = self._store.add_track(
|
||||||
audio, item.track, measured=measured, with_grid=bool(markers), art=art)
|
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:
|
if markers:
|
||||||
self._store.replace_grid(track_id, markers)
|
self._store.replace_grid(track_id, markers)
|
||||||
if item.cues is not None:
|
if item.cues is not None:
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ def capabilities_for(
|
|||||||
# column (its Composer is a different field), so they are absent
|
# column (its Composer is a different field), so they are absent
|
||||||
# rather than mapped onto something approximate.
|
# rather than mapped onto something approximate.
|
||||||
editable_fields=sorted(editable_fields or []),
|
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,
|
removable=True,
|
||||||
addable=True,
|
addable=True,
|
||||||
artwork=False,
|
artwork=False,
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ def _name_of(related) -> str | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def to_track(row, cue_kinds=()) -> Track:
|
def to_track(row, cue_kinds=(), *, stem: bool = False) -> Track:
|
||||||
"""Project one ``DjmdContent`` row.
|
"""Project one ``DjmdContent`` row.
|
||||||
|
|
||||||
`cue_kinds` is this track's ``(Kind, OutMsec, ColorTableIndex)`` from the store's single
|
`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,
|
hotcues=chips,
|
||||||
grid_marker_count=1 if (_bpm(row) and getattr(row, "AnalysisDataPath", None)) else 0,
|
grid_marker_count=1 if (_bpm(row) and getattr(row, "AnalysisDataPath", None)) else 0,
|
||||||
grid_locked=False, # Rekordbox has no per-track grid lock
|
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
|
except Exception as ex: # noqa: BLE001 — surfaced as a clean 4xx
|
||||||
raise LibraryNotSupported(f"Could not open Rekordbox library: {ex}") from ex
|
raise LibraryNotSupported(f"Could not open Rekordbox library: {ex}") from ex
|
||||||
self._grid_cache.clear()
|
self._grid_cache.clear()
|
||||||
|
self._stem_cache: dict[str, bool] = {}
|
||||||
self._content_cache: list | None = None
|
self._content_cache: list | None = None
|
||||||
self._by_id: dict[str, object] | None = None
|
self._by_id: dict[str, object] | None = None
|
||||||
|
|
||||||
@@ -373,6 +374,20 @@ class RekordboxStore:
|
|||||||
def set_path_mapping(self, mapping: PathMapping) -> None:
|
def set_path_mapping(self, mapping: PathMapping) -> None:
|
||||||
self._mapping = mapping or PathMapping()
|
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
|
@property
|
||||||
def path_mapping(self) -> PathMapping:
|
def path_mapping(self) -> PathMapping:
|
||||||
return self._mapping
|
return self._mapping
|
||||||
|
|||||||
@@ -187,5 +187,55 @@ with TestClient(main.app) as c:
|
|||||||
re.search(r'<PRIMARYKEY TYPE="STEM" KEY="[^"]*Other\.stem\.m4a"', saved) is not None
|
re.search(r'<PRIMARYKEY TYPE="STEM" KEY="[^"]*Other\.stem\.m4a"', saved) is not None
|
||||||
and re.search(r'<PRIMARYKEY TYPE="TRACK" KEY="[^"]*Other\.mp3"', saved) is not None)
|
and re.search(r'<PRIMARYKEY TYPE="TRACK" KEY="[^"]*Other\.mp3"', saved) is not None)
|
||||||
|
|
||||||
|
# Rekordbox has no <STEMS>: the FILE decides, so the Type column agrees
|
||||||
|
# with the deck, which plays a stem file's stems on every platform.
|
||||||
|
print("== adding a stem file to a Rekordbox library ==")
|
||||||
|
from konduktor.adapters.rekordbox import discovery as rb_discovery
|
||||||
|
|
||||||
|
found = rb_discovery.detect_libraries()
|
||||||
|
if not found:
|
||||||
|
print(" (skipped: no Rekordbox library on this machine)")
|
||||||
|
else:
|
||||||
|
rb_src = Path(found[0]["path"]).parent
|
||||||
|
rb_dir = ROOT / "rekordbox"
|
||||||
|
rb_dir.mkdir()
|
||||||
|
for name in ("master.db", "masterPlaylists6.xml"):
|
||||||
|
if (rb_src / name).exists():
|
||||||
|
shutil.copy2(rb_src / name, rb_dir / name)
|
||||||
|
if (rb_src / "share").is_dir():
|
||||||
|
shutil.copytree(rb_src / "share", rb_dir / "share")
|
||||||
|
rb_stem_dir = ROOT / "ForRekordbox"
|
||||||
|
rb_stem_dir.mkdir()
|
||||||
|
rb_stem = rb_stem_dir / "Rb.stem.m4a"
|
||||||
|
shutil.copy2(stem, rb_stem)
|
||||||
|
rb_plain = make_mp3(rb_stem_dir / "Rb.mp3", seed=11)
|
||||||
|
r = c.post("/api/library/open", json={"path": str(rb_dir / "master.db")})
|
||||||
|
check("(setup) a Rekordbox copy opens", r.status_code == 200, r.text[:300])
|
||||||
|
assert c.get("/api/folder/tracks", params={"path": str(rb_stem_dir)}).status_code == 200
|
||||||
|
job = c.post("/api/folder/add", json={"track_ids": [str(rb_stem), str(rb_plain)],
|
||||||
|
"mode": "reference"}).json()
|
||||||
|
while job["state"] == "running":
|
||||||
|
time.sleep(0.05)
|
||||||
|
job = c.get(f"/api/jobs/{job['id']}").json()
|
||||||
|
check("(setup) the add finishes", job["state"] == "done", str(job))
|
||||||
|
rb_new_stem, rb_new_plain = (job.get("result") or {}).get("track_ids") or [None, None]
|
||||||
|
|
||||||
|
def rb_kinds():
|
||||||
|
items = c.get("/api/tracks", params={"limit": 20000}).json()["items"]
|
||||||
|
return {t["id"]: t["media_kind"] for t in items}
|
||||||
|
|
||||||
|
kinds = rb_kinds()
|
||||||
|
check("the added stem file is a stem track, the MP3 beside it audio",
|
||||||
|
kinds.get(rb_new_stem) == "stem" and kinds.get(rb_new_plain) == "audio",
|
||||||
|
f"{kinds.get(rb_new_stem)} {kinds.get(rb_new_plain)}")
|
||||||
|
r = c.post("/api/library/open", json={"path": str(rb_dir / "master.db")})
|
||||||
|
kinds = rb_kinds()
|
||||||
|
check("…and still after a reopen",
|
||||||
|
kinds.get(rb_new_stem) == "stem" and kinds.get(rb_new_plain) == "audio",
|
||||||
|
f"{kinds.get(rb_new_stem)} {kinds.get(rb_new_plain)}")
|
||||||
|
r = c.get("/api/tracks/stems", params={"track_id": rb_new_stem})
|
||||||
|
check("and the deck is offered its stems",
|
||||||
|
r.status_code == 200 and len(r.json()["stems"]) == 4, r.text[:200])
|
||||||
|
|
||||||
print("\nRESULT:", "FAILED" if failed else "ALL PASSED")
|
print("\nRESULT:", "FAILED" if failed else "ALL PASSED")
|
||||||
sys.exit(1 if failed else 0)
|
sys.exit(1 if failed else 0)
|
||||||
Reference in new issue
Block a user