From e55fa544107c7a143c8a576a3033945a22da8368 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 12 Oct 2022 20:29:42 -0400 Subject: [PATCH] soundboard: improve volume sliders --- src/.config/sxhkd/sxhkdrc | 26 +++++++++++---- src/.local/bin/deskutils/soundboard/sb-msg | 2 +- src/.local/bin/deskutils/soundboard/sb-vol | 39 +++++++++++++++++++--- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/.config/sxhkd/sxhkdrc b/src/.config/sxhkd/sxhkdrc index 619b3d0..45fdbf0 100644 --- a/src/.config/sxhkd/sxhkdrc +++ b/src/.config/sxhkd/sxhkdrc @@ -22,9 +22,11 @@ super + grave ln -sr $SB_DIR $SB_DIR/cur;\ sb-ls.sh -# list current directory contents +# list currently playing + volume KP_Enter - sb-ls.sh + find $SB_DIR/ -name "sb-socket*" | sb-vol + +# list current directory contents # super + shift + ` super + asciitilde sb-ls.sh @@ -52,16 +54,28 @@ ctrl + shift + KP_{Insert,End,Down,Next,Left,Begin,Right,Home,Up,Prior} ls $SB_DIR/cur/sb-socket$snd_id-* | sb-msg "set loop inf" # reduce volume of current dir -ctrl + KP_Subtract +ctrl + shift + KP_Subtract snd_id="{0-9}";\ ls $SB_DIR/cur/sb-socket* | sb-msg "add volume -5";\ - sb-vol + ls $SB_DIR/cur/sb-socket* | sb-vol # increase volume of current dir -ctrl + KP_Add +ctrl + shift + KP_Add snd_id="{0-9}";\ ls $SB_DIR/cur/sb-socket* | sb-msg "add volume +5";\ - sb-vol + ls $SB_DIR/cur/sb-socket* | sb-vol + +# reduce volume of specific sound +ctrl + KP_Subtract; KP_{Insert,End,Down,Next,Left,Begin,Right,Home,Up,Prior} + snd_id="{0-9}";\ + ls $SB_DIR/cur/sb-socket$snd_id-* | sb-msg "add volume -10";\ + ls $SB_DIR/cur/sb-socket$snd_id-* | sb-vol + +# increase volume of specific sound +ctrl + KP_Add; KP_{Insert,End,Down,Next,Left,Begin,Right,Home,Up,Prior} + snd_id="{0-9}";\ + ls $SB_DIR/cur/sb-socket$snd_id-* | sb-msg "add volume +10";\ + ls $SB_DIR/cur/sb-socket$snd_id-* | sb-vol # stop all sounds shift + KP_Delete diff --git a/src/.local/bin/deskutils/soundboard/sb-msg b/src/.local/bin/deskutils/soundboard/sb-msg index 961206e..4746bfc 100755 --- a/src/.local/bin/deskutils/soundboard/sb-msg +++ b/src/.local/bin/deskutils/soundboard/sb-msg @@ -2,5 +2,5 @@ # Given a list of mpv sockets through stdin, send a message to all of them while read -r socket; do - printf "$1\n" | socat - $socket + printf "$1\n" | socat - $socket | grep "{.*" done diff --git a/src/.local/bin/deskutils/soundboard/sb-vol b/src/.local/bin/deskutils/soundboard/sb-vol index e7d41c9..70f78e2 100755 --- a/src/.local/bin/deskutils/soundboard/sb-vol +++ b/src/.local/bin/deskutils/soundboard/sb-vol @@ -1,10 +1,39 @@ #!/bin/sh -# Get the highest volume in the current directory, and present it as a notification. +# Get volumes of mpv sockets piped through stdin -RES=$(ls $SB_DIR/cur/sb-socket* | \ - sb-msg '{ "command": ["get_property", "volume"], "request_id": 100 }' |\ - jq .data | sort | head -n 1 | awk '{ printf("%.0f\n", $0) }') +SOCKETS="" + +while read x; do + SOCKETS=$(printf "%s\n%s" "$SOCKETS" "$x") +done +SOCKETS=$(printf %s "$SOCKETS" | sed "/^$/d") + +VOLS=$(echo "$SOCKETS" |\ + sb-msg '{ "command": ["get_property", "volume"], "request_id": 1336 }' |\ + jq .data | awk '{ printf("%.0f\n", $0) }') + +PATHS=$(echo "$SOCKETS" |\ + sb-msg '{ "command": ["get_property", "path"], "request_id": 1337 }' |\ + jq -r .data) +NAMES="" +for x in $PATHS; do + NAMES="$NAMES $(basename $x)" +done + +CNT=$(echo $PATHS | wc -w) +if [ "$CNT" = 0 ]; then + exit +fi CUR_DIR="$(basename $(readlink $SB_DIR/cur))" -notify-send -a "soundboard" -r 13371337 "$(printf "%s\nVolume set to %s\n" "$CUR_DIR" "$RES")" +zip () { + awk '{for(i=1; i<=NF/2; i++) {j=NF/2+i; printf "%s %s%\n",$i,$j;}}' +} + +PROMPT=$(printf '%s\n%s' "$CUR_DIR" "$(echo "$NAMES" $VOLS | zip | column --table --output-width 20)") + +notify-send \ + -a "soundboard" \ + -r 13371337 \ + "$(printf "%s" "$PROMPT")"