Skip to content

Commit

Permalink
New commands outputlist and output
Browse files Browse the repository at this point in the history
- `outputlist` is a more compact version of the outputs command that does not print attributes.
- `output {ID}` prints the details of specified output id.

Clients usually prints a list of outputs and after the user selects an output, it shows the details.
  • Loading branch information
jcorporation committed Nov 8, 2024
1 parent 7774c33 commit fc93511
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ver 0.24 (not yet released)
- volume command is no longer deprecated
- new "available" and "reset" subcommands for tagtypes
- searching stored playlists respond now with song position
- new commands outputlist and output
* database
- attribute "added" shows when each song was added to the database
- fix integer overflows with 64-bit inode numbers
Expand Down
7 changes: 7 additions & 0 deletions doc/protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,13 @@ Audio output devices
- ``outputname``: Name of the output. It can be any.
- ``outputenabled``: Status of the output. 0 if disabled, 1 if enabled.

:command:`outputlist`
Shows information about all outputs. This is a more compact version of
the `outputs` command that does not print attributes.

:command:`output {ID}`
Shows information about specified output.

.. _command_outputset:

:command:`outputset {ID} {NAME} {VALUE}`
Expand Down
2 changes: 2 additions & 0 deletions src/command/AllCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ static constexpr struct command commands[] = {
{ "newpartition", PERMISSION_ADMIN, 1, 1, handle_newpartition },
{ "next", PERMISSION_PLAYER, 0, 0, handle_next },
{ "notcommands", PERMISSION_NONE, 0, 0, handle_not_commands },
{ "output", PERMISSION_READ, 1, 1, handle_device },
{ "outputlist", PERMISSION_READ, 0, 0, handle_devicelist },
{ "outputs", PERMISSION_READ, 0, 0, handle_devices },
{ "outputset", PERMISSION_ADMIN, 3, 3, handle_outputset },
{ "partition", PERMISSION_READ, 1, 1, handle_partition },
Expand Down
26 changes: 26 additions & 0 deletions src/command/OutputCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,29 @@ handle_devices(Client &client, [[maybe_unused]] Request args, Response &r)
printAudioDevices(r, client.GetPartition().outputs);
return CommandResult::OK;
}

CommandResult
handle_device(Client &client, [[maybe_unused]] Request args, Response &r)
{
assert(args.size() == 1);

const unsigned idx = args.ParseUnsigned(0);

auto &outputs = client.GetPartition().outputs;
if (idx >= outputs.Size()) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
}

printAudioDevice(r, outputs, idx, true);
return CommandResult::OK;
}

CommandResult
handle_devicelist(Client &client, [[maybe_unused]] Request args, Response &r)
{
assert(args.empty());

printAudioDeviceList(r, client.GetPartition().outputs);
return CommandResult::OK;
}
6 changes: 6 additions & 0 deletions src/command/OutputCommands.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ handle_outputset(Client &client, Request request, Response &response);
CommandResult
handle_devices(Client &client, Request request, Response &response);

CommandResult
handle_device(Client &client, Request request, Response &response);

CommandResult
handle_devicelist(Client &client, Request request, Response &response);

#endif
32 changes: 23 additions & 9 deletions src/output/Print.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ void
printAudioDevices(Response &r, const MultipleOutputs &outputs)
{
for (unsigned i = 0, n = outputs.Size(); i != n; ++i) {
const auto &ao = outputs.Get(i);
printAudioDevice(r, outputs, i, true);
}
}

r.Fmt(FMT_STRING("outputid: {}\n"
"outputname: {}\n"
"plugin: {}\n"
"outputenabled: {}\n"),
i,
ao.GetName(), ao.GetPluginName(),
(unsigned)ao.IsEnabled());
void
printAudioDevice(Response &r, const MultipleOutputs &outputs, unsigned idx, bool attributes)
{
const auto &ao = outputs.Get(idx);

r.Fmt(FMT_STRING("outputid: {}\n"
"outputname: {}\n"
"plugin: {}\n"
"outputenabled: {}\n"),
idx,
ao.GetName(), ao.GetPluginName(),
(unsigned)ao.IsEnabled());
if (attributes)
for (const auto &[attribute, value] : ao.GetAttributes())
r.Fmt(FMT_STRING("attribute: {}={}\n"),
attribute, value);
attribute, value);
}

void
printAudioDeviceList(Response &r, const MultipleOutputs &outputs)
{
for (unsigned i = 0, n = outputs.Size(); i != n; ++i) {
printAudioDevice(r, outputs, i, false);
}
}
4 changes: 4 additions & 0 deletions src/output/Print.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ class MultipleOutputs;

void
printAudioDevices(Response &r, const MultipleOutputs &outputs);
void
printAudioDevice(Response &r, const MultipleOutputs &outputs, unsigned idx, bool attributes);
void
printAudioDeviceList(Response &r, const MultipleOutputs &outputs);

#endif

0 comments on commit fc93511

Please sign in to comment.