From 961c7d0f7853d28eddffd74d4a874c3e6a85ee9c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 25 Oct 2013 00:11:10 +0200 Subject: 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. --- src/command/OtherCommands.cxx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/command/OtherCommands.cxx') 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 @@ -236,6 +236,39 @@ handle_setvol(Client &client, gcc_unused int argc, char *argv[]) return CommandResult::OK; } +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[]) -- cgit v1.2.3