From ec1ae383d66a61af3808355ac3e3304894809b41 Mon Sep 17 00:00:00 2001 From: Hyperblast Date: Sun, 23 Feb 2025 08:04:23 +0500 Subject: [PATCH 1/3] refactor volume api according to backend changes --- src/Client/IPlayerClient.cs | 27 +++++++++++++------ src/Client/PlayerClient.cs | 21 ++++++++++++++- src/Client/SetPlayerStateRequest.cs | 7 ++++- src/Client/VolumeType.cs | 3 ++- src/CommandLineTool/Commands/VolumeCommand.cs | 6 ++--- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/Client/IPlayerClient.cs b/src/Client/IPlayerClient.cs index 98c71d4..69837e0 100644 --- a/src/Client/IPlayerClient.cs +++ b/src/Client/IPlayerClient.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -132,22 +131,34 @@ ValueTask GetPlayerState( ValueTask SetMuted(BoolSwitch isMuted, CancellationToken cancellationToken = default); /// - /// Sets volume. + /// Sets volume to absolute value. /// /// New volume value. /// Cancellation token. /// Request task. - ValueTask SetVolume(double volume, CancellationToken cancellationToken = default); + ValueTask SetVolumeAbsolute(double volume, CancellationToken cancellationToken = default); /// - /// Adjust volume in one step. + /// Sets volume relative to current value. + /// + /// New volume value. + /// Cancellation token. + /// Request task. + ValueTask SetVolumeRelative(double volume, CancellationToken cancellationToken = default); + + /// + /// Increases volume. + /// + /// Cancellation token. + /// Request task. + ValueTask VolumeUp(CancellationToken cancellationToken = default); + + /// + /// Decreases volume. /// - /// - /// Determines change direction: 1 for volume increase, -1 for volume decrease. - /// /// Cancellation token. /// Request task. - ValueTask VolumeStep(int direction, CancellationToken cancellationToken = default); + ValueTask VolumeDown(CancellationToken cancellationToken = default); /// /// Sets player option. diff --git a/src/Client/PlayerClient.cs b/src/Client/PlayerClient.cs index 68162b0..d09ea0e 100644 --- a/src/Client/PlayerClient.cs +++ b/src/Client/PlayerClient.cs @@ -164,11 +164,30 @@ public async ValueTask SetMuted(BoolSwitch isMuted, CancellationToken cancellati } /// - public async ValueTask SetVolume(double volume, CancellationToken cancellationToken = default) + public async ValueTask SetVolumeAbsolute(double volume, CancellationToken cancellationToken = default) { await SetPlayerState(new SetPlayerStateRequest { Volume = volume }, cancellationToken).ConfigureAwait(false); } + /// + public async ValueTask SetVolumeRelative(double volume, CancellationToken cancellationToken = default) + { + await SetPlayerState(new SetPlayerStateRequest { RelativeVolume = volume }, cancellationToken) + .ConfigureAwait(false); + } + + /// + public async ValueTask VolumeUp(CancellationToken cancellationToken = default) + { + await _handler.Post("api/player/volume/up", null, cancellationToken).ConfigureAwait(false); + } + + /// + public async ValueTask VolumeDown(CancellationToken cancellationToken = default) + { + await _handler.Post("api/player/volume/down", null, cancellationToken).ConfigureAwait(false); + } + /// public async ValueTask VolumeStep(int direction, CancellationToken cancellationToken = default) { diff --git a/src/Client/SetPlayerStateRequest.cs b/src/Client/SetPlayerStateRequest.cs index 1a835ef..c22187e 100644 --- a/src/Client/SetPlayerStateRequest.cs +++ b/src/Client/SetPlayerStateRequest.cs @@ -10,10 +10,15 @@ namespace Beefweb.Client; public sealed class SetPlayerStateRequest { /// - /// New volume value. + /// New absolute volume value. /// public double? Volume { get; set; } + /// + /// New relative volume value. + /// + public double? RelativeVolume { get; set; } + /// /// Adjust volume in one step: 1 for volume increase, -1 for volume decrease. /// diff --git a/src/Client/VolumeType.cs b/src/Client/VolumeType.cs index 3eb870d..a190dee 100644 --- a/src/Client/VolumeType.cs +++ b/src/Client/VolumeType.cs @@ -22,7 +22,8 @@ public enum VolumeType /// /// Similar to , - /// but only is allowed to change volume. + /// but only and + /// methods are allowed to change volume. /// UpDown, } diff --git a/src/CommandLineTool/Commands/VolumeCommand.cs b/src/CommandLineTool/Commands/VolumeCommand.cs index 6f3d5ce..193af2f 100644 --- a/src/CommandLineTool/Commands/VolumeCommand.cs +++ b/src/CommandLineTool/Commands/VolumeCommand.cs @@ -33,13 +33,13 @@ public override async Task OnExecuteAsync(CancellationToken ct) if (Up) { - await Client.VolumeStep(1, ct); + await Client.VolumeUp(ct); return; } if (Down) { - await Client.VolumeStep(-1, ct); + await Client.VolumeDown(ct); return; } @@ -62,7 +62,7 @@ public override async Task OnExecuteAsync(CancellationToken ct) _ => throw new InvalidOperationException("Unknown volume type " + volumeInfo.Type), }; - await Client.SetVolume(newVolume, ct); + await Client.SetVolumeAbsolute(newVolume, ct); } private static double CalculateVolumeLinear(VolumeInfo volumeInfo, VolumeChange volumeChange, bool isRelative) From 1016ae1b5dd04d8eb2a4e2556932dd5f4ab8fe30 Mon Sep 17 00:00:00 2001 From: Hyperblast Date: Sun, 23 Feb 2025 08:16:49 +0500 Subject: [PATCH 2/3] remove old code --- src/Client/PlayerClient.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Client/PlayerClient.cs b/src/Client/PlayerClient.cs index d09ea0e..eb2e98b 100644 --- a/src/Client/PlayerClient.cs +++ b/src/Client/PlayerClient.cs @@ -188,13 +188,6 @@ public async ValueTask VolumeDown(CancellationToken cancellationToken = default) await _handler.Post("api/player/volume/down", null, cancellationToken).ConfigureAwait(false); } - /// - public async ValueTask VolumeStep(int direction, CancellationToken cancellationToken = default) - { - await SetPlayerState(new SetPlayerStateRequest { VolumeStep = direction }, cancellationToken) - .ConfigureAwait(false); - } - /// public async ValueTask SetOption(SetOptionRequest request, CancellationToken cancellationToken = default) { From 24eebec6b4abd69b881d54c1a080a61580240ba7 Mon Sep 17 00:00:00 2001 From: Hyperblast Date: Sun, 23 Feb 2025 08:20:55 +0500 Subject: [PATCH 3/3] change log fixes --- ChangeLog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 28051d0..51ae281 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,6 @@ # Changes in v0.3 (not released) -- Add support for VolumeStep and VolumeType.UpDown -- Add support for output configuration +- Add support for UpDown volume type and new volume commands +- Add support for output device configuration - Add support for PlayOrPause command # Changes in v0.2 (released 2025-02-14)