diff options
author | Jason Nader <jason.nader@protonmail.com> | 2020-12-08 13:55:31 +0900 |
---|---|---|
committer | PulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org> | 2021-05-17 15:35:07 +0000 |
commit | 75390822b4d31aa626ee0bb9ee6274dbc1cff32c (patch) | |
tree | fdcd6e8b52e84a453ca869b2a8bbf4609320171c | |
parent | 0e4a92ca699d000667db218c88f4c4387e5f930c (diff) | |
download | pulseaudio-75390822b4d31aa626ee0bb9ee6274dbc1cff32c.tar.gz |
pactl: add `get-sink-volume` command
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/430>
-rw-r--r-- | man/pactl.1.xml.in | 5 | ||||
-rw-r--r-- | src/utils/pactl.c | 39 |
2 files changed, 43 insertions, 1 deletions
diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in index fbc486e08..b95afa724 100644 --- a/man/pactl.1.xml.in +++ b/man/pactl.1.xml.in @@ -193,6 +193,11 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. </option> <option> + <p><opt>get-sink-volume</opt> <arg>SINK</arg></p> + <optdesc><p>Get the volume of the specified sink (identified by its symbolic name or numerical index) displayed in the same format as the `info` command.</p></optdesc> + </option> + + <option> <p><opt>set-sink-volume</opt> <arg>SINK</arg> <arg>VOLUME [VOLUME ...]</arg></p> <optdesc><p>Set the volume of the specified sink (identified by its symbolic name or numerical index). <arg>VOLUME</arg> can be specified as an integer (e.g. 2000, 16384), a linear factor (e.g. 0.4, 1.100), a percentage diff --git a/src/utils/pactl.c b/src/utils/pactl.c index e905f03e0..e7f71ee4b 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -125,6 +125,7 @@ static enum { SET_DEFAULT_SINK, SET_SOURCE_PORT, SET_DEFAULT_SOURCE, + GET_SINK_VOLUME, SET_SINK_VOLUME, SET_SOURCE_VOLUME, SET_SINK_INPUT_VOLUME, @@ -1046,6 +1047,27 @@ static void fill_volume(pa_cvolume *cv, unsigned supported) { } static void get_sink_volume_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) { + if (is_last < 0) { + pa_log(_("Failed to get sink information: %s"), pa_strerror(pa_context_errno(c))); + quit(1); + return; + } + + if (is_last) + return; + + pa_assert(i); + + char cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX]; + printf(("Volume: %s\n" + " balance %0.2f\n"), + pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true), + pa_cvolume_get_balance(&i->volume, &i->channel_map)); + + complete_action(); +} + +static void set_sink_volume_callback(pa_context *c, const pa_sink_info *i, int is_last, void *userdata) { pa_cvolume cv; if (is_last < 0) { @@ -1538,10 +1560,14 @@ static void context_state_callback(pa_context *c, void *userdata) { o = pa_context_set_source_output_mute(c, source_output_idx, mute, simple_callback, NULL); break; - case SET_SINK_VOLUME: + case GET_SINK_VOLUME: o = pa_context_get_sink_info_by_name(c, sink_name, get_sink_volume_callback, NULL); break; + case SET_SINK_VOLUME: + o = pa_context_get_sink_info_by_name(c, sink_name, set_sink_volume_callback, NULL); + break; + case SET_SOURCE_VOLUME: o = pa_context_get_source_info_by_name(c, source_name, get_source_volume_callback, NULL); break; @@ -1737,6 +1763,7 @@ static void help(const char *argv0) { printf("%s %s %s %s\n", argv0, _("[options]"), "get-default-(sink|source)", _("NAME")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-default-(sink|source)", _("NAME")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-port", _("NAME|#N PORT")); + printf("%s %s %s %s\n", argv0, _("[options]"), "get-(sink|source)-volume", _("NAME|#N")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-volume", _("NAME|#N VOLUME [VOLUME ...]")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink-input|source-output)-volume", _("#N VOLUME [VOLUME ...]")); printf("%s %s %s %s\n", argv0, _("[options]"), "set-(sink|source)-mute", _("NAME|#N 1|0|toggle")); @@ -2059,6 +2086,16 @@ int main(int argc, char *argv[]) { source_name = pa_xstrdup(argv[optind+1]); + } else if (pa_streq(argv[optind], "get-sink-volume")) { + action = GET_SINK_VOLUME; + + if (argc < optind+2) { + pa_log(_("You have to specify a sink name/index")); + goto quit; + } + + sink_name = pa_xstrdup(argv[optind+1]); + } else if (pa_streq(argv[optind], "set-sink-volume")) { action = SET_SINK_VOLUME; |