Commit 9e715089 authored by Max Kellermann's avatar Max Kellermann

Commands: new command "toggleoutput"

parent 1a852bc3
ver 0.18 (2012/??/??) ver 0.18 (2012/??/??)
* protocol:
- new command "toggleoutput"
* innput: * innput:
- soup: plugin removed - soup: plugin removed
* decoder: * decoder:
......
...@@ -1876,6 +1876,20 @@ OK ...@@ -1876,6 +1876,20 @@ OK
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry id="command_toggleoutput">
<term>
<cmdsynopsis>
<command>toggleoutput</command>
<arg choice="req"><replaceable>ID</replaceable></arg>
</cmdsynopsis>
</term>
<listitem>
<para>
Turns an output on or off, depending on the current
state.
</para>
</listitem>
</varlistentry>
<varlistentry id="command_outputs"> <varlistentry id="command_outputs">
<term> <term>
<cmdsynopsis> <cmdsynopsis>
......
...@@ -159,6 +159,7 @@ static const struct command commands[] = { ...@@ -159,6 +159,7 @@ static const struct command commands[] = {
{ "swap", PERMISSION_CONTROL, 2, 2, handle_swap }, { "swap", PERMISSION_CONTROL, 2, 2, handle_swap },
{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid }, { "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes }, { "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
{ "toggleoutput", PERMISSION_ADMIN, 1, 1, handle_toggleoutput },
{ "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 },
......
...@@ -84,3 +84,30 @@ audio_output_disable_index(unsigned idx) ...@@ -84,3 +84,30 @@ audio_output_disable_index(unsigned idx)
return true; return true;
} }
bool
audio_output_toggle_index(unsigned idx)
{
struct audio_output *ao;
if (idx >= audio_output_count())
return false;
ao = audio_output_get(idx);
const bool enabled = ao->enabled = !ao->enabled;
idle_add(IDLE_OUTPUT);
if (!enabled) {
Mixer *mixer = ao->mixer;
if (mixer != nullptr) {
mixer_close(mixer);
idle_add(IDLE_MIXER);
}
}
ao->player_control->UpdateAudio();
++audio_output_state_version;
return true;
}
...@@ -41,4 +41,11 @@ audio_output_enable_index(unsigned idx); ...@@ -41,4 +41,11 @@ audio_output_enable_index(unsigned idx);
bool bool
audio_output_disable_index(unsigned idx); audio_output_disable_index(unsigned idx);
/**
* Toggles an audio output. Returns false if the specified output
* does not exist.
*/
bool
audio_output_toggle_index(unsigned idx);
#endif #endif
...@@ -65,6 +65,22 @@ handle_disableoutput(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -65,6 +65,22 @@ handle_disableoutput(Client *client, G_GNUC_UNUSED int argc, char *argv[])
} }
enum command_return enum command_return
handle_toggleoutput(Client *client, gcc_unused int argc, char *argv[])
{
unsigned device;
if (!check_unsigned(client, &device, argv[1]))
return COMMAND_RETURN_ERROR;
if (!audio_output_toggle_index(device)) {
command_error(client, ACK_ERROR_NO_EXIST,
"No such audio output");
return COMMAND_RETURN_ERROR;
}
return COMMAND_RETURN_OK;
}
enum command_return
handle_devices(Client *client, handle_devices(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
......
...@@ -31,6 +31,9 @@ enum command_return ...@@ -31,6 +31,9 @@ enum command_return
handle_disableoutput(Client *client, int argc, char *argv[]); handle_disableoutput(Client *client, int argc, char *argv[]);
enum command_return enum command_return
handle_toggleoutput(Client *client, int argc, char *argv[]);
enum command_return
handle_devices(Client *client, int argc, char *argv[]); handle_devices(Client *client, int argc, char *argv[]);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment