mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Refactored library system to support different libraries (adapters)
This commit is contained in:
1 parent
dd97f27ac7
commit
08c9b8121d
31 files changed
+3405
-2385
No files matched your search
@@ -0,0 +1,133 @@
|
||||
"""The adapter contract: what the app needs from a DJ library, generically.
|
||||
|
||||
Konduktor's save model is **projection + command replay**. The generic model is
|
||||
a READ PROJECTION; edits are commands an adapter replays onto its RETAINED
|
||||
NATIVE MODEL, which stays the write target. The generic model is never
|
||||
serialized back over a library — that is what preserves byte-exact saves, and
|
||||
it is also the only model that works for formats you cannot regenerate at all
|
||||
(a Rekordbox SQLite row, a Serato tag inside an audio file).
|
||||
|
||||
Two rules keep this honest:
|
||||
|
||||
* **No native type appears in any signature here.** If a concept cannot be
|
||||
expressed generically it does not belong on the protocol.
|
||||
* **Every mutating command returns its refreshed projection.** That makes the
|
||||
refresh an adapter-internal invariant rather than something each route has
|
||||
to remember; a forgotten refresh is a silently stale UI that no byte-level
|
||||
test would catch.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Protocol, runtime_checkable
|
||||
|
||||
from .capabilities import Capabilities
|
||||
from .model import Facets, PlaylistNode, Stats, Track, TrackCues, TrackPage
|
||||
from .pathmap import PathMapping
|
||||
|
||||
|
||||
class AdapterError(Exception):
|
||||
"""Base for every failure an adapter reports to the HTTP layer."""
|
||||
|
||||
|
||||
class LibraryNotSupported(AdapterError):
|
||||
"""No driver can open this path, or it failed to parse."""
|
||||
|
||||
|
||||
class NotFound(AdapterError):
|
||||
"""Unknown track, playlist or marker index."""
|
||||
|
||||
|
||||
class InvalidCommand(AdapterError):
|
||||
"""Well-formed request the library cannot accept (bad slot, BPM <= 0, ...)."""
|
||||
|
||||
|
||||
class Unsupported(AdapterError):
|
||||
"""The platform cannot represent this edit at all."""
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class LibraryAdapter(Protocol):
|
||||
"""One open library. Stateful; exactly one is loaded at a time."""
|
||||
|
||||
platform: str
|
||||
path: Path
|
||||
|
||||
# ---- identity -------------------------------------------------------
|
||||
def capabilities(self) -> Capabilities: ...
|
||||
def reload(self) -> None: ...
|
||||
|
||||
# ---- read projection -------------------------------------------------
|
||||
def tracks(self) -> list[Track]: ...
|
||||
def track(self, track_id: str) -> Track | None: ...
|
||||
def query_tracks(self, **kw) -> TrackPage: ...
|
||||
def facets(self) -> Facets: ...
|
||||
def stats(self, playlist_count: int) -> Stats: ...
|
||||
def playlist_tree(self) -> list[PlaylistNode]: ...
|
||||
def playlist_entries(self, node_id: str) -> list[str] | None: ...
|
||||
def playlist_tracks(self, node_id: str) -> list[Track] | None: ...
|
||||
def track_cues(self, track_id: str) -> TrackCues | None: ...
|
||||
|
||||
# ---- commands: playlists --------------------------------------------
|
||||
def create_playlist(self, name: str, parent_id: str | None = None) -> str: ...
|
||||
def rename_playlist(self, node_id: str, name: str) -> None: ...
|
||||
def delete_playlist(self, node_id: str) -> None: ...
|
||||
def set_playlist_entries(self, node_id: str, track_ids: list[str]) -> int: ...
|
||||
|
||||
# ---- commands: track metadata / art ---------------------------------
|
||||
def set_track_metadata(self, track_id: str, fields: dict) -> Track | None: ...
|
||||
def set_cover_art(self, track_id: str, data: bytes, mime: str) -> None: ...
|
||||
def cover_art(self, track_id: str) -> tuple[bytes, str] | None: ...
|
||||
|
||||
# ---- commands: cues --------------------------------------------------
|
||||
def set_cue(
|
||||
self,
|
||||
track_id: str,
|
||||
*,
|
||||
slot: int,
|
||||
start_sec: float,
|
||||
cue_type: str,
|
||||
length_sec: float = 0.0,
|
||||
role: str = "hotcue",
|
||||
name: str | None = None,
|
||||
) -> TrackCues: ...
|
||||
def set_cue_type(self, track_id: str, slot: int, cue_type: str) -> TrackCues: ...
|
||||
def delete_cue(self, track_id: str, slot: int) -> TrackCues: ...
|
||||
def place_cues(self, track_id: str, cues: list, *, overwrite: bool = False) -> TrackCues: ...
|
||||
|
||||
# ---- commands: beatgrid ---------------------------------------------
|
||||
def add_grid_marker(self, track_id: str, start_sec: float, bpm: float | None = None) -> TrackCues: ...
|
||||
def move_grid_marker(self, track_id: str, index: int, start_sec: float) -> TrackCues: ...
|
||||
def set_grid_marker_bpm(self, track_id: str, index: int, bpm: float) -> TrackCues: ...
|
||||
def delete_grid_marker(self, track_id: str, index: int) -> TrackCues: ...
|
||||
def replace_grid(self, track_id: str, markers: list[tuple[float, float]]) -> TrackCues: ...
|
||||
def set_analysed_grid(self, track_id: str, markers: list[tuple[float, float]]) -> TrackCues: ...
|
||||
def delete_grid(self, track_id: str) -> TrackCues: ...
|
||||
def set_grid_lock(self, track_id: str, locked: bool) -> TrackCues: ...
|
||||
|
||||
# ---- audio / paths ---------------------------------------------------
|
||||
def audio_path(self, track_id: str) -> Path | None: ...
|
||||
def set_path_mapping(self, mapping: PathMapping) -> None: ...
|
||||
def path_prefix_suggestions(self) -> dict: ...
|
||||
def remap_preview(self, mapping: PathMapping) -> dict: ...
|
||||
def remap_locations(self, mapping: PathMapping) -> int: ...
|
||||
|
||||
# ---- save -------------------------------------------------------------
|
||||
@property
|
||||
def dirty(self) -> bool: ...
|
||||
def save(self): ...
|
||||
def snapshot(self) -> bytes: ...
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class LibraryDriver(Protocol):
|
||||
"""Opens libraries of one platform. Stateless; one instance per platform."""
|
||||
|
||||
platform: str
|
||||
display_name: str
|
||||
suffixes: tuple[str, ...]
|
||||
|
||||
def can_open(self, path: Path) -> bool: ...
|
||||
def open(self, path: Path) -> LibraryAdapter: ...
|
||||
def detect(self) -> list: ...
|
||||
def describe(self, path: Path) -> object: ...
|
||||
Reference in new issue
Block a user