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.
This commit is contained in:
Max Kellermann 2013-10-25 00:11:10 +02:00
parent c1ba47beee
commit 961c7d0f78
5 changed files with 57 additions and 0 deletions

1
NEWS
View File

@ -5,6 +5,7 @@ ver 0.18 (2012/??/??)
* protocol: * protocol:
- new command "toggleoutput" - new command "toggleoutput"
- search for album artist falls back to the artist tag - search for album artist falls back to the artist tag
- re-add the "volume" command
* input: * input:
- curl: enable https - curl: enable https
- soup: plugin removed - soup: plugin removed

View File

@ -768,6 +768,25 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry id="command_volume">
<term>
<cmdsynopsis>
<command>volume</command>
<arg choice="req"><replaceable>CHANGE</replaceable></arg>
</cmdsynopsis>
</term>
<listitem>
<para>
Changes volume by amount <varname>CHANGE</varname>.
</para>
<note>
<para>
<command>volume</command> is deprecated, use
<command>setvol</command> instead.
</para>
</note>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</section> </section>

View File

@ -161,6 +161,7 @@ static const struct command commands[] = {
{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe }, { "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
{ "update", PERMISSION_CONTROL, 0, 1, handle_update }, { "update", PERMISSION_CONTROL, 0, 1, handle_update },
{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers }, { "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
{ "volume", PERMISSION_CONTROL, 1, 1, handle_volume },
}; };
static const unsigned num_commands = sizeof(commands) / sizeof(commands[0]); static const unsigned num_commands = sizeof(commands) / sizeof(commands[0]);

View File

@ -236,6 +236,39 @@ handle_setvol(Client &client, gcc_unused int argc, char *argv[])
return CommandResult::OK; 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 CommandResult
handle_stats(Client &client, handle_stats(Client &client,
gcc_unused int argc, gcc_unused char *argv[]) gcc_unused int argc, gcc_unused char *argv[])

View File

@ -51,6 +51,9 @@ handle_rescan(Client &client, int argc, char *argv[]);
CommandResult CommandResult
handle_setvol(Client &client, int argc, char *argv[]); handle_setvol(Client &client, int argc, char *argv[]);
CommandResult
handle_volume(Client &client, int argc, char *argv[]);
CommandResult CommandResult
handle_stats(Client &client, int argc, char *argv[]); handle_stats(Client &client, int argc, char *argv[]);