Skip to content

Commit

Permalink
Add options to config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Mar 10, 2024
1 parent 493c3a2 commit b9004c5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
22 changes: 10 additions & 12 deletions music_assistant/common/models/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,14 @@ class CoreConfig(Config):
advanced=True,
)

CONF_ENTRY_SYNC_ADJUST = (
ConfigEntry(
key=CONF_SYNC_ADJUST,
type=ConfigEntryType.INTEGER,
range=(-500, 500),
default_value=0,
label="Audio synchronization delay correction",
description="If this player is playing audio synced with other players "
"and you always hear the audio too early or late on this player, "
"you can shift the audio a bit.",
advanced=True,
),
CONF_ENTRY_SYNC_ADJUST = ConfigEntry(
key=CONF_SYNC_ADJUST,
type=ConfigEntryType.INTEGER,
range=(-500, 500),
default_value=0,
label="Audio synchronization delay correction",
description="If this player is playing audio synced with other players "
"and you always hear the audio too early or late on this player, "
"you can shift the audio a bit.",
advanced=True,
)
4 changes: 3 additions & 1 deletion music_assistant/server/providers/airplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
CONF_ALAC_ENCODE = "alac_encode"
CONF_VOLUME_START = "volume_start"
CONF_PASSWORD = "password"


PLAYER_CONFIG_ENTRIES = (
CONF_ENTRY_CROSSFADE,
CONF_ENTRY_CROSSFADE_DURATION,
Expand All @@ -78,7 +80,7 @@
CONF_ENTRY_SYNC_ADJUST,
ConfigEntry(
key=CONF_PASSWORD,
type=ConfigEntryType.STRING,
type=ConfigEntryType.SECURE_STRING,
default_value=None,
required=False,
label="Device password",
Expand Down
54 changes: 46 additions & 8 deletions music_assistant/server/providers/slimproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from aioslimproto.client import TransitionType as SlimTransition
from aioslimproto.models import EventType as SlimEventType
from aioslimproto.models import Preset as SlimPreset
from aioslimproto.models import VisualisationType as SlimVisualisationType
from aioslimproto.server import SlimServer

from music_assistant.common.models.config_entries import (
CONF_ENTRY_CROSSFADE,
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_ENFORCE_MP3,
CONF_ENTRY_EQ_BASS,
CONF_ENTRY_EQ_MID,
Expand Down Expand Up @@ -94,17 +96,37 @@ class SyncPlayPoint:
CONF_CLI_TELNET = "cli_telnet"
CONF_CLI_JSON = "cli_json"
CONF_DISCOVERY = "discovery"
CONF_DISPLAY = "display"
CONF_VISUALIZATION = "visualization"

DEFAULT_PLAYER_VOLUME = 20
DEFAULT_SLIMPROTO_PORT = 3483
DEFAULT_VISUALIZATION = SlimVisualisationType.SPECTRUM_ANALYZER.value


CONF_ENTRY_CROSSFADE_DURATION = ConfigEntry(
key=CONF_CROSSFADE_DURATION,
type=ConfigEntryType.INTEGER,
range=(1, 10),
default_value=8,
label="Crossfade duration",
description="Duration in seconds of the crossfade between tracks (if enabled)",
CONF_ENTRY_DISPLAY = ConfigEntry(
key=CONF_DISPLAY,
type=ConfigEntryType.BOOLEAN,
default_value=True,
required=False,
label="Enable display support",
description="Enable/disable native display support on " "squeezebox or squeezelite32 hardware.",
advanced=True,
)
CONF_ENTRY_VISUALIZATION = ConfigEntry(
key=CONF_VISUALIZATION,
type=ConfigEntryType.STRING,
default_value=DEFAULT_VISUALIZATION,
options=tuple(
ConfigValueOption(title=x.name.replace("_", " ").title(), value=x.value)
for x in SlimVisualisationType
),
required=False,
label="Visualization type",
description="The type of visualization to show on the display "
"during playback if the device supports this.",
advanced=True,
depends_on=CONF_DISPLAY,
)


Expand Down Expand Up @@ -269,6 +291,8 @@ async def get_player_config_entries(self, player_id: str) -> tuple[ConfigEntry]:
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_ENFORCE_MP3,
CONF_ENTRY_SYNC_ADJUST,
CONF_ENTRY_DISPLAY,
CONF_ENTRY_VISUALIZATION,
)
)

Expand All @@ -278,6 +302,7 @@ def on_player_config_changed(self, config: PlayerConfig, changed_keys: set[str])

if slimplayer := self.slimproto.get_player(config.player_id):
self.mass.create_task(self._set_preset_items(slimplayer))
self.mass.create_task(self._set_display(slimplayer))

async def cmd_stop(self, player_id: str) -> None:
"""Send STOP command to given player."""
Expand Down Expand Up @@ -812,8 +837,9 @@ async def _handle_connected(self, slimplayer: SlimClient) -> None:
"""Handle a slimplayer connected event."""
player_id = slimplayer.player_id
self.logger.info("Player %s connected", slimplayer.name or player_id)
# set presets
# set presets and display
await self._set_preset_items(slimplayer)
await self._set_display(slimplayer)
# update all attributes
await self._handle_player_update(slimplayer)
# update existing players so they can update their `can_sync_with` field
Expand Down Expand Up @@ -877,3 +903,15 @@ async def _set_preset_items(self, slimplayer: SlimClient) -> None:
else:
break
slimplayer.presets = preset_items

async def _set_display(self, slimplayer: SlimClient) -> None:
"""Set the display config for a player."""
display_enabled = self.mass.config.get_raw_player_config_value(
slimplayer.player_id, CONF_DISPLAY, True
)
visualization = self.mass.config.get_raw_player_config_value(
slimplayer.player_id, CONF_VISUALIZATION, DEFAULT_VISUALIZATION
)
await slimplayer.configure_display(
visualisation=SlimVisualisationType(visualization), disabled=not display_enabled
)

0 comments on commit b9004c5

Please sign in to comment.