diff options
author | Max Kellermann <max@duempel.org> | 2013-08-04 23:20:56 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-04 23:21:23 +0200 |
commit | 9e715089a4279d08b7cc8d7fbdb3eb8696230e65 (patch) | |
tree | e075d02a6355e58d2241109eb30009b6b5baa2bc /src | |
parent | 1a852bc365971960b0c8fd180f71a14396c81d8c (diff) |
Commands: new command "toggleoutput"
Diffstat (limited to 'src')
-rw-r--r-- | src/AllCommands.cxx | 1 | ||||
-rw-r--r-- | src/OutputCommand.cxx | 27 | ||||
-rw-r--r-- | src/OutputCommand.hxx | 7 | ||||
-rw-r--r-- | src/OutputCommands.cxx | 16 | ||||
-rw-r--r-- | src/OutputCommands.hxx | 3 |
5 files changed, 54 insertions, 0 deletions
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 |