Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
27 changes: 19 additions & 8 deletions src/Client/IPlayerClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -132,22 +131,34 @@ ValueTask<PlayerState> GetPlayerState(
ValueTask SetMuted(BoolSwitch isMuted, CancellationToken cancellationToken = default);

/// <summary>
/// Sets volume.
/// Sets volume to absolute value.
/// </summary>
/// <param name="volume">New volume value.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Request task.</returns>
ValueTask SetVolume(double volume, CancellationToken cancellationToken = default);
ValueTask SetVolumeAbsolute(double volume, CancellationToken cancellationToken = default);

/// <summary>
/// Adjust volume in one step.
/// Sets volume relative to current value.
/// </summary>
/// <param name="volume">New volume value.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Request task.</returns>
ValueTask SetVolumeRelative(double volume, CancellationToken cancellationToken = default);

/// <summary>
/// Increases volume.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Request task.</returns>
ValueTask VolumeUp(CancellationToken cancellationToken = default);

/// <summary>
/// Decreases volume.
/// </summary>
/// <param name="direction">
/// Determines change direction: 1 for volume increase, -1 for volume decrease.
/// </param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Request task.</returns>
ValueTask VolumeStep(int direction, CancellationToken cancellationToken = default);
ValueTask VolumeDown(CancellationToken cancellationToken = default);

/// <summary>
/// Sets player option.
Expand Down
18 changes: 15 additions & 3 deletions src/Client/PlayerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,30 @@ public async ValueTask SetMuted(BoolSwitch isMuted, CancellationToken cancellati
}

/// <inheritdoc />
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);
}

/// <inheritdoc />
public async ValueTask VolumeStep(int direction, CancellationToken cancellationToken = default)
public async ValueTask SetVolumeRelative(double volume, CancellationToken cancellationToken = default)
{
await SetPlayerState(new SetPlayerStateRequest { VolumeStep = direction }, cancellationToken)
await SetPlayerState(new SetPlayerStateRequest { RelativeVolume = volume }, cancellationToken)
.ConfigureAwait(false);
}

/// <inheritdoc />
public async ValueTask VolumeUp(CancellationToken cancellationToken = default)
{
await _handler.Post("api/player/volume/up", null, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc />
public async ValueTask VolumeDown(CancellationToken cancellationToken = default)
{
await _handler.Post("api/player/volume/down", null, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc />
public async ValueTask SetOption(SetOptionRequest request, CancellationToken cancellationToken = default)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Client/SetPlayerStateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ namespace Beefweb.Client;
public sealed class SetPlayerStateRequest
{
/// <summary>
/// New volume value.
/// New absolute volume value.
/// </summary>
public double? Volume { get; set; }

/// <summary>
/// New relative volume value.
/// </summary>
public double? RelativeVolume { get; set; }

/// <summary>
/// Adjust volume in one step: 1 for volume increase, -1 for volume decrease.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Client/VolumeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum VolumeType

/// <summary>
/// Similar to <see cref="Linear"/>,
/// but only <see cref="SetPlayerStateRequest.VolumeStep"/> is allowed to change volume.
/// but only <see cref="IPlayerClient.VolumeUp"/> and <see cref="IPlayerClient.VolumeDown"/>
/// methods are allowed to change volume.
/// </summary>
UpDown,
}
6 changes: 3 additions & 3 deletions src/CommandLineTool/Commands/VolumeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down