aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--doc/protocol.xml14
-rw-r--r--src/AllCommands.cxx1
-rw-r--r--src/OutputCommand.cxx27
-rw-r--r--src/OutputCommand.hxx7
-rw-r--r--src/OutputCommands.cxx16
-rw-r--r--src/OutputCommands.hxx3
7 files changed, 70 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 46ee9dbb1..fb4145c30 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
ver 0.18 (2012/??/??)
+* protocol:
+ - new command "toggleoutput"
* innput:
- soup: plugin removed
* decoder:
diff --git a/doc/protocol.xml b/doc/protocol.xml
index c03388a24..50e58db63 100644
--- a/doc/protocol.xml
+++ b/doc/protocol.xml
@@ -1876,6 +1876,20 @@ OK
</para>
</listitem>
</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">
<term>
<cmdsynopsis>
diff --git a/src/AllCommands.cxx b/src/AllCommands.cxx
index 8f651ec04..cd06c323b 100644
--- a/src/AllCommands.cxx
+++ b/src/AllCommands.cxx
@@ -159,6 +159,7 @@ static const struct command commands[] = {
{ "swap", PERMISSION_CONTROL, 2, 2, handle_swap },
{ "swapid", PERMISSION_CONTROL, 2, 2, handle_swapid },
{ "tagtypes", PERMISSION_READ, 0, 0, handle_tagtypes },
+ { "toggleoutput", PERMISSION_ADMIN, 1, 1, handle_toggleoutput },
{ "unsubscribe", PERMISSION_READ, 1, 1, handle_unsubscribe },
{ "update", PERMISSION_CONTROL, 0, 1, handle_update },
{ "urlhandlers", PERMISSION_READ, 0, 0, handle_urlhandlers },
diff --git a/src/OutputCommand.cxx b/src/OutputCommand.cxx
index bf051babf..f6b35c6ed 100644
--- a/src/OutputCommand.cxx
+++ b/src/OutputCommand.cxx
@@ -84,3 +84,30 @@ audio_output_disable_index(unsigned idx)
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;
+}
diff --git a/src/OutputCommand.hxx b/src/OutputCommand.hxx
index 74eaf8f1c..46fab92c5 100644
--- a/src/OutputCommand.hxx
+++ b/src/OutputCommand.hxx
@@ -41,4 +41,11 @@ audio_output_enable_index(unsigned idx);
bool
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
diff --git a/src/OutputCommands.cxx b/src/OutputCommands.cxx
index 7d626477a..5e4a145da 100644
--- a/src/OutputCommands.cxx
+++ b/src/OutputCommands.cxx
@@ -65,6 +65,22 @@ handle_disableoutput(Client *client, G_GNUC_UNUSED int argc, char *argv[])
}
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,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{
diff --git a/src/OutputCommands.hxx b/src/OutputCommands.hxx
index 4f7082bfb..5642a0680 100644
--- a/src/OutputCommands.hxx
+++ b/src/OutputCommands.hxx
@@ -31,6 +31,9 @@ enum command_return
handle_disableoutput(Client *client, int argc, char *argv[]);
enum command_return
+handle_toggleoutput(Client *client, int argc, char *argv[]);
+
+enum command_return
handle_devices(Client *client, int argc, char *argv[]);
#endif