Author: Adam Evyčędo <git@apiote.xyz>
select sound card
.config/sh/functions | 24 +++++++++++++++++++----- .config/wob/wob.ini | 3 +++
diff --git a/.config/sh/functions b/.config/sh/functions index d564344eb921f63c875ecea7fd2a0bfb807ec989..42c96e13ada9289ed7b7b5606b3759919c8fb10d 100644 --- a/.config/sh/functions +++ b/.config/sh/functions @@ -253,6 +253,16 @@ # testme ffmpeg -i input.mp4 -c:a copy -c:v libsvtav1 -preset 10 -r 25 -threads 16 -crf 17 svtav1_test.mp4 #ffmpeg -i "$1" -crf "$Q" -threads 16 -b:v 0 -c:v libaom-av1 -r 25 -strict experimental -tile-columns 2 -pix_fmt yuv420p "${1%%.*}.av1.webm" } +selectSoundCard() { + if [ -f /tmp/asoundrc_usb ] && [ "$(cat /tmp/asoundrc_usb)" != '' ]; then + echo 'PCM' + exit 0 + fi + # TODO if headphones connected -> echo 'Headphone'; exit 0 + # TODO if hdmi connected -> echo ?; exit 0 + echo 'Speaker' +} + volume() { if command -v pactl >/dev/null 2>&1; then if [ "$1" = '+' ]; then @@ -271,16 +281,16 @@ echo "$volume" >/tmp/wob.sock fi printf '' >/tmp/wob.sock else + # shellcheck disable=2012 output=$(basename "$(ls -l ~/.config/alsa/asoundrc-default | cut -d '>' -f2 | tr -d ' ')") if [ "$output" = 'null' ]; then amixer -M sset Master on amixer -M sset Master 100% cmd='-M sset' - ctl='Master' - elif [ "$output" = 'asoundrc-bluealsa' ] - then + ctl=$(selectSoundCard) + elif [ "$output" = 'asoundrc-bluealsa' ]; then cmd='-D bluealsa sset' - ctl=$(amixer -D bluealsa scontrols | grep 'A2DP' | sed -E "s/^[^']*'//" | sed "s/',0//") + ctl="\"$(amixer -D bluealsa scontrols | grep 'A2DP' | sed -E "s/^[^']*'//" | sed "s/',0//")\"" else exit 1 fi @@ -292,7 +302,11 @@ result=$(eval "amixer $cmd $ctl 5%-") elif [ "$1" = 't' ]; then result=$(eval "amixer $cmd $ctl toggle") fi - echo "$result" | sed -En 's/.*\[([0-9]+)%\].*/\1/p' | head -n1 > /tmp/wob.sock + result=$(echo "$result" | sed -En 's/.*\[([0-9]+)%\].*/\1/p' | head -n1) + if amixer sget "$ctl" | grep -qF '[off]'; then + result="$result muted" + fi + echo "$result" >/tmp/wob.sock sleep 1 printf '' >/tmp/wob.sock fi diff --git a/.config/wob/wob.ini b/.config/wob/wob.ini index 1b1067b118398fbb9bc0ff9357c10b0412786b48..d3fbbdca819c6071eb8a2e4db176175c7397fc05 100644 --- a/.config/wob/wob.ini +++ b/.config/wob/wob.ini @@ -1 +1,4 @@ anchor = bottom + +[style.muted] +border_color = 892B30