From d9ae94e89318d416763304451fe01e5649085f64 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 25 Oct 2024 01:59:22 +0200 Subject: [PATCH] Use dynamic step size for volume up/down --- music_assistant/server/controllers/players.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/music_assistant/server/controllers/players.py b/music_assistant/server/controllers/players.py index b36519a7a..f2ca3ac17 100644 --- a/music_assistant/server/controllers/players.py +++ b/music_assistant/server/controllers/players.py @@ -398,7 +398,15 @@ async def cmd_volume_up(self, player_id: str) -> None: - player_id: player_id of the player to handle the command. """ - new_volume = min(100, self._players[player_id].volume_level + 5) + if not (player := self.get(player_id)): + return + if player.volume_level < 5 or player.volume_level > 95: + step_size = 1 + elif player.volume_level < 20 or player.volume_level > 80: + step_size = 2 + else: + step_size = 5 + new_volume = min(100, self._players[player_id].volume_level + step_size) await self.cmd_volume_set(player_id, new_volume) @api_command("players/cmd/volume_down") @@ -408,7 +416,15 @@ async def cmd_volume_down(self, player_id: str) -> None: - player_id: player_id of the player to handle the command. """ - new_volume = max(0, self._players[player_id].volume_level - 5) + if not (player := self.get(player_id)): + return + if player.volume_level < 5 or player.volume_level > 95: + step_size = 1 + elif player.volume_level < 20 or player.volume_level > 80: + step_size = 2 + else: + step_size = 5 + new_volume = max(0, self._players[player_id].volume_level - step_size) await self.cmd_volume_set(player_id, new_volume) @api_command("players/cmd/group_volume")