aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-25 00:11:10 +0200
committerMax Kellermann <max@duempel.org>2013-10-25 00:20:36 +0200
commit961c7d0f7853d28eddffd74d4a874c3e6a85ee9c (patch)
tree65f2705d3ff037107f05a35f61ea555b4d1f780b /src/command
parentc1ba47beee9c084e2a592e54dcda3f470e26ec47 (diff)
downloadmpd-961c7d0f7853d28eddffd74d4a874c3e6a85ee9c.tar.gz
mpd-961c7d0f7853d28eddffd74d4a874c3e6a85ee9c.tar.xz
mpd-961c7d0f7853d28eddffd74d4a874c3e6a85ee9c.zip
OtherCommands: re-add the "volume" command
This command was removed by commit 206392ad (MPD 0.16), even though it was been proven useful for some very simple clients. On request, I add it to the protocol again.
Diffstat (limited to 'src/command')
-rw-r--r--src/command/AllCommands.cxx1
-rw-r--r--src/command/OtherCommands.cxx33
-rw-r--r--src/command/OtherCommands.hxx3
3 files changed, 37 insertions, 0 deletions
diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx
index 2271aeff2..b83b42a29 100644
--- a/src/command/AllCommands.cxx
+++ b/src/command/AllCommands.cxx
@@ -161,6 +161,7 @@ static const struct command commands[] = {
{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
{ "update", PERMISSION_CONTROL, 0, 1, handle_update },
{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
+ { "volume", PERMISSION_CONTROL, 1, 1, handle_volume },
};
static const unsigned num_commands = sizeof(commands) / sizeof(commands[0]);
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 55391af16..510ef89e7 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -237,6 +237,39 @@ handle_setvol(Client &client, gcc_unused int argc, char *argv[])
}
CommandResult
+handle_volume(Client &client, gcc_unused int argc, char *argv[])
+{
+ int relative;
+ if (!check_int(client, &relative, argv[1]))
+ return CommandResult::ERROR;
+
+ if (relative < -100 || relative > 100) {
+ command_error(client, ACK_ERROR_ARG, "Invalid volume value");
+ return CommandResult::ERROR;
+ }
+
+ const int old_volume = volume_level_get();
+ if (old_volume < 0) {
+ command_error(client, ACK_ERROR_SYSTEM, "No mixer");
+ return CommandResult::ERROR;
+ }
+
+ int new_volume = old_volume + relative;
+ if (new_volume < 0)
+ new_volume = 0;
+ else if (new_volume > 100)
+ new_volume = 100;
+
+ if (new_volume != old_volume && !volume_level_change(new_volume)) {
+ command_error(client, ACK_ERROR_SYSTEM,
+ "problems setting volume");
+ return CommandResult::ERROR;
+ }
+
+ return CommandResult::OK;
+}
+
+CommandResult
handle_stats(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
diff --git a/src/command/OtherCommands.hxx b/src/command/OtherCommands.hxx
index fe3e145c4..20201e8b9 100644
--- a/src/command/OtherCommands.hxx
+++ b/src/command/OtherCommands.hxx
@@ -52,6 +52,9 @@ CommandResult
handle_setvol(Client &client, int argc, char *argv[]);
CommandResult
+handle_volume(Client &client, int argc, char *argv[]);
+
+CommandResult
handle_stats(Client &client, int argc, char *argv[]);
CommandResult