summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2020-10-16 17:46:58 +0200
committerMax Kellermann <max@musicpd.org>2020-10-16 17:51:51 +0200
commit871bf3b88f20b51118f9a61a2bbec7ba1324378e (patch)
tree9bd546bbebb5f802ece2dc0b5d051ef69c37b9e3
parent08360e401d4f9be61a62f9d8974b48f973e6dfab (diff)
command: add command "getvol"
Closes https://github.com/MusicPlayerDaemon/MPD/issues/979
-rw-r--r--NEWS2
-rw-r--r--doc/protocol.rst10
-rw-r--r--src/command/AllCommands.cxx1
-rw-r--r--src/command/OtherCommands.cxx12
-rw-r--r--src/command/OtherCommands.hxx3
5 files changed, 28 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 834d89afe..a14cbd699 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
ver 0.23 (not yet released)
+* protocol
+ - new command "getvol"
ver 0.22.1 (not yet released)
* output
diff --git a/doc/protocol.rst b/doc/protocol.rst
index bcbe16155..164ac0b9c 100644
--- a/doc/protocol.rst
+++ b/doc/protocol.rst
@@ -522,6 +522,16 @@ Playback options
Sets volume to ``VOL``, the range of
volume is 0-100.
+:command:`getvol`
+
+ Read the volume. The result is a ``volume:`` line like in
+ :ref:`status <command_status>`. If there is no mixer, MPD will
+ emit an empty response. Example::
+
+ getvol
+ volume: 42
+ OK
+
:command:`single {STATE}` [#since_0_15]_
Sets single state to ``STATE``,
``STATE`` should be ``0``, ``1`` or ``oneshot`` [#since_0_20]_.
diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx
index 560d69c87..e139b367c 100644
--- a/src/command/AllCommands.cxx
+++ b/src/command/AllCommands.cxx
@@ -113,6 +113,7 @@ static constexpr struct command commands[] = {
#ifdef ENABLE_CHROMAPRINT
{ "getfingerprint", PERMISSION_READ, 1, 1, handle_getfingerprint },
#endif
+ { "getvol", PERMISSION_READ, 0, 0, handle_getvol },
{ "idle", PERMISSION_READ, 0, -1, handle_idle },
{ "kill", PERMISSION_ADMIN, -1, -1, handle_kill },
#ifdef ENABLE_DATABASE
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 2bf858d90..5673fcedd 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -319,6 +319,18 @@ handle_rescan(Client &client, Request args, Response &r)
}
CommandResult
+handle_getvol(Client &client, Request, Response &r)
+{
+ auto &partition = client.GetPartition();
+
+ const auto volume = volume_level_get(partition.outputs);
+ if (volume >= 0)
+ r.Format("volume: %i\n", volume);
+
+ return CommandResult::OK;
+}
+
+CommandResult
handle_setvol(Client &client, Request args, Response &r)
{
unsigned level = args.ParseUnsigned(0, 100);
diff --git a/src/command/OtherCommands.hxx b/src/command/OtherCommands.hxx
index 2fe28f2d8..58288f11f 100644
--- a/src/command/OtherCommands.hxx
+++ b/src/command/OtherCommands.hxx
@@ -48,6 +48,9 @@ CommandResult
handle_rescan(Client &client, Request request, Response &response);
CommandResult
+handle_getvol(Client &client, Request request, Response &response);
+
+CommandResult
handle_setvol(Client &client, Request request, Response &response);
CommandResult