Web frontend

This commit is contained in:
2026-08-27 12:32:20 +02:00
parent d44c24ec97
commit edb6e5e027
97 changed files with 9535 additions and 195 deletions

View File

@@ -24,10 +24,12 @@ from musicmouse.events import (
ButtonEvent,
NextTrackRequested,
PauseRequested,
PlayAlbumRequested,
PlayRequested,
PrevTrackRequested,
RfidTokenRead,
RotaryTurned,
SeekRequested,
SetVolumeRequested,
TouchButtonPressed,
TouchButtonReleased,
@@ -169,6 +171,25 @@ class SimulatorDriver:
self.app.bus.emit(SetVolumeRequested(volume=volume, source="simulator"))
await self.settle()
async def play_album(self, title: str, track_index: int = 0) -> None:
"""Start a library album by title - what the web front-end does."""
album = next(
(a for a in self.app.library.albums if a.title.lower() == title.lower()), None
)
if album is None:
known = ", ".join(sorted(a.title for a in self.app.library.albums))
raise ScriptError(f"unknown album {title!r} (known: {known})")
self.app.bus.emit(
PlayAlbumRequested(
album_id=album.id, track_index=track_index, source="simulator"
)
)
await self.settle()
async def seek(self, position: float) -> None:
self.app.bus.emit(SeekRequested(position=position, source="simulator"))
await self.settle()
# -------------------------------------------------------------------- time
async def wait(self, seconds: float) -> None:
@@ -213,6 +234,13 @@ class SimulatorDriver:
return self.app.mouse.active_figure or "none"
case "playlist":
return player.playlist.name if player.playlist else "none"
case "album":
album = self.app.library.get(
player.playlist.album_id if player.playlist else None
)
return album.title if album else "none"
case "position":
return f"{player.position:.1f}"
case "track":
return str(player.track_index)
case "title":
@@ -227,8 +255,8 @@ class SimulatorDriver:
return type(effect).__name__ if effect is not None else "none"
case _:
raise ScriptError(
f"unknown property {key!r} (try: playing, figure, playlist, track, "
f"title, volume, brightness, ring, mouse, shelf)"
f"unknown property {key!r} (try: playing, figure, playlist, album, "
f"track, title, position, volume, brightness, ring, mouse, shelf)"
)
# ------------------------------------------------------------------ scripts
@@ -275,6 +303,10 @@ class SimulatorDriver:
await self.emit_pause()
case ("volume", [level]):
await self.set_volume(_int(level))
case ("album", [*words]) if words:
await self.play_album(" ".join(words))
case ("seek", [position]):
await self.seek(Duration.parse(position).seconds)
case ("disconnect", []):
await self.disconnect()
case ("reconnect", []):