diff options
author | Steve McIntyre <steve@einval.com> | 2023-04-07 18:49:10 +0100 |
---|---|---|
committer | Steve McIntyre <steve@einval.com> | 2023-04-07 18:49:10 +0100 |
commit | bc5a9c67e963cf71762d4a1ecab42c36ece4c6a8 (patch) | |
tree | b159b9d37ff009a7ce2c4c762906c0064b304d8a | |
parent | 5b45bd98f40453c090606d864a7e8f0d8d09c30d (diff) | |
download | steve-scripts-bc5a9c67e963cf71762d4a1ecab42c36ece4c6a8.zip |
Change to use pactl rather than aumix
-rwxr-xr-x | audio_volume | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/audio_volume b/audio_volume index 6d4e251..4473fbd 100755 --- a/audio_volume +++ b/audio_volume @@ -1,6 +1,6 @@ #!/bin/sh # -# Script to manage audio buttons on x220 +# Script to manage audio buttons on thinkpad # INPUT="$@" @@ -9,48 +9,44 @@ if [ "$INPUT"x = ""x ]; then INPUT=state fi +SINK="$(pactl list short sinks | awk '/RUNNING/ {print $2}')" +FULL_VOLUME=99999 + +# Call pactl and parse the output. There are two volume levels, for +# left and right. Assume we're balanced and just read the left value +sink_volume () { + pactl list sinks | awk " + /Name: $SINK/ { this_sink=1 } + /Volume:/ { if (this_sink) { vol=\$3; print vol; this_sink=0 } } + " +} + case "$INPUT" in --help) - echo "$0: control and remeber mixer settings" - echo "$0: <start>|+N|-N|mute" + echo "$0: control volume settings" + echo "$0: state|+N|-N|mute" ;; +*|-*) # Volume up/down - LEVEL=$(aumix -v q | awk '{print $3}') - LEVEL=$(($LEVEL $INPUT)) - if [ $LEVEL -gt 100 ]; then - LEVEL=100 + OLD_LEVEL=$(sink_volume) + CHANGE=$(($INPUT * $FULL_VOLUME / 100)) + NEW_LEVEL=$(($OLD_LEVEL + $CHANGE)) + if [ $NEW_LEVEL -gt $FULL_VOLUME ]; then + NEW_LEVEL=$FULL_VOLUME fi - if [ $LEVEL -lt 0 ]; then - LEVEL=0 + if [ $NEW_LEVEL -lt 0 ]; then + NEW_LEVEL=0 fi - echo "$0: got $INPUT, setting audio level $LEVEL" - aumix -v $LEVEL -S + pactl set-sink-volume "$SINK" "$NEW_LEVEL" + echo "$0: got $INPUT, old audio level $OLD_LEVEL, setting audio level $NEW_LEVEL" ;; mute) # Toggle mute on/off - # Are we currently muted? - LEVEL=$(aumix -v q | awk '{print $3}') - if [ $LEVEL -eq 0 ]; then - # yes, go back to our last stored volume - echo "$0: Unmuting, restoring old audio levels" - aumix -L - else - echo "$0: Muting, storing old level of $LEVEL and going to audio level 0" - aumix -S - aumix -v 0 - fi - ;; - init) - # Read the current level from hardware and write it to our - # settings file - LEVEL=$(aumix -v q | awk '{print $3}') - echo "$0: saving audio level $LEVEL" - aumix -S + pactl set-sink-mute "$SINK" toggle ;; state) # Just print the current level - LEVEL=$(aumix -v q | awk '{print $3}') + LEVEL=$(sink_volume) echo "$0: got audio level $LEVEL" ;; *) |