/
/
/
1"""Provider implementation for the MilkDrop Visualizer plugin."""
2
3from __future__ import annotations
4
5from typing import TYPE_CHECKING
6
7from music_assistant_models.config_entries import ConfigEntry
8from music_assistant_models.enums import ConfigEntryType
9
10from music_assistant.models.plugin import PluginProvider
11
12from .relay import MilkdropRelay
13from .tap import CONF_COLOR_TINT, DEFAULT_COLOR_TINT
14
15if TYPE_CHECKING:
16 from music_assistant_models.config_entries import ProviderConfig
17 from music_assistant_models.enums import ProviderFeature
18 from music_assistant_models.provider import ProviderManifest
19
20 from music_assistant.mass import MusicAssistant
21
22
23class MilkdropVisualizerProvider(PluginProvider):
24 """Streams waveform frames from what a player is playing to the web frontend."""
25
26 def __init__(
27 self,
28 mass: MusicAssistant,
29 manifest: ProviderManifest,
30 config: ProviderConfig,
31 supported_features: set[ProviderFeature],
32 ) -> None:
33 """Initialize the provider."""
34 super().__init__(mass, manifest, config, supported_features)
35 self._relay = MilkdropRelay(self)
36
37 async def get_config_entries(self) -> tuple[ConfigEntry, ...]:
38 """Return the (options) config entries for the MilkDrop Visualizer provider."""
39 return (
40 ConfigEntry(
41 key=CONF_COLOR_TINT,
42 type=ConfigEntryType.BOOLEAN,
43 default_value=DEFAULT_COLOR_TINT,
44 required=False,
45 advanced=True,
46 ),
47 )
48
49 async def loaded_in_mass(self) -> None:
50 """Register the relay route once fully loaded."""
51 await super().loaded_in_mass()
52 self._relay.setup()
53
54 async def unload(self, is_removed: bool = False) -> None:
55 """
56 Handle unload/close of the provider.
57
58 :param is_removed: True when the provider is removed from the configuration.
59 """
60 await self._relay.close()
61