Add pactl support
This commit is contained in:
parent
d85fe4b419
commit
f12dbece18
@ -1,17 +1,31 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Has some undocumented features but they're functional (as far as I know)
|
|
||||||
# and system-independent. just shortcuts for me really.
|
|
||||||
|
|
||||||
argv0="$0"
|
argv0="$0"
|
||||||
|
|
||||||
! which stris >/dev/null 2>/dev/null \
|
# ADDING A NEW SOUND SERVER/CLIENT/WHATEVERIDK
|
||||||
&& printf "%b: Missing stris.\n" \
|
# `volume a` and `volume s` are the system dependent functions.
|
||||||
|
|
||||||
|
# `volume a $2` must set the volume to $2, an integer value. This should be a
|
||||||
|
# percentage, 100% being the loudest possible volume that can be output by
|
||||||
|
# hardware without quality loss. Percentages above 100% will be allowable in
|
||||||
|
# software if using percentage units. If percentage units are implausible to
|
||||||
|
# implement, system units are okay (e.g. 0-$arbitrary scale versus 0-100).
|
||||||
|
|
||||||
|
# `volume s` must output the current volume in integer form in whatever units
|
||||||
|
# are being used by `volume a` on the given system.
|
||||||
|
|
||||||
|
! command -v stris >/dev/null 2>/dev/null \
|
||||||
|
&& printf "%b: Missing stris.\n" "$argv0" \
|
||||||
&& exit 1 \
|
&& exit 1 \
|
||||||
|| true
|
|| true
|
||||||
|
|
||||||
VOLUME_TMP_FILE="$HOME/.volume-previous"
|
VOLUME_TMP_FILE="$HOME/.volume-previous"
|
||||||
|
|
||||||
|
unknown_system(){
|
||||||
|
printf "%s: Unknown system.\n" "$argv0" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
printf "\
|
printf "\
|
||||||
Usage: %b [function] (argument)\n" "$argv0"
|
Usage: %b [function] (argument)\n" "$argv0"
|
||||||
@ -36,28 +50,57 @@ works the same as \"%b h\".
|
|||||||
|| argv1=s
|
|| argv1=s
|
||||||
|
|
||||||
case "$argv1" in
|
case "$argv1" in
|
||||||
(+) # shortcut
|
#
|
||||||
|
# SYSTEM DEPENDENT
|
||||||
|
#
|
||||||
|
(a*)
|
||||||
|
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
||||||
|
|
||||||
|
if [ "$(uname)" = "NetBSD" ]; then
|
||||||
|
# NetBSD 9.2 STABLE 2021-07
|
||||||
|
audioctl -w play.gain=$2 >/dev/null
|
||||||
|
|
||||||
|
elif command -v pactl >/dev/null; then
|
||||||
|
# pactl 15.0 compiled+linked with libpulse 15.0.0
|
||||||
|
pactl set-sink-volume @DEFAULT_SINK@ $2%
|
||||||
|
|
||||||
|
else unknown_system; fi
|
||||||
|
exit 0 ;;
|
||||||
|
(s*)
|
||||||
|
[ -z "$2" ] || usage
|
||||||
|
|
||||||
|
if [ "$(uname)" = "NetBSD" ]; then
|
||||||
|
# hacky
|
||||||
|
audioctl -a \
|
||||||
|
| grep "play\.gain" \
|
||||||
|
| cut -d '=' -f 2
|
||||||
|
|
||||||
|
elif command -v pactl >/dev/null; then
|
||||||
|
# really hacky, gets the job done
|
||||||
|
# gets the volume % of Lchan specifically
|
||||||
|
pactl get-sink-volume @DEFAULT_SINK@ \
|
||||||
|
| sed q \
|
||||||
|
| cut -d '/' -f 2 \
|
||||||
|
| xargs echo \
|
||||||
|
| sed s/'%'//
|
||||||
|
|
||||||
|
else unknown_system; fi
|
||||||
|
exit 0 ;;
|
||||||
|
#
|
||||||
|
# SYSTEM independent
|
||||||
|
#
|
||||||
|
(+)
|
||||||
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||||
&& "$argv0" r "$2" \
|
&& "$argv0" r "$2" \
|
||||||
|| usage
|
|| usage
|
||||||
;;
|
;;
|
||||||
(-) # shortcut
|
(-)
|
||||||
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||||
&& "$argv0" r -"$2" \
|
&& "$argv0" r -"$2" \
|
||||||
|| usage
|
|| usage
|
||||||
;;
|
;;
|
||||||
(a*)
|
|
||||||
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
|
||||||
case "$(uname)" in
|
|
||||||
(NetBSD)
|
|
||||||
# 9.2 STABLE 2021-07
|
|
||||||
audioctl -w play.gain=$2 >/dev/null
|
|
||||||
;;
|
|
||||||
(*) unknown_system
|
|
||||||
esac
|
|
||||||
exit 0 ;;
|
|
||||||
(h*) usage ;;
|
(h*) usage ;;
|
||||||
(m*) # system independent
|
(m*)
|
||||||
[ -z "$2" ] || usage
|
[ -z "$2" ] || usage
|
||||||
# restore previous volume if there is one
|
# restore previous volume if there is one
|
||||||
if [ -e "$VOLUME_TMP_FILE" ]; then
|
if [ -e "$VOLUME_TMP_FILE" ]; then
|
||||||
@ -74,8 +117,8 @@ case "$argv1" in
|
|||||||
|
|
||||||
# dd used rather than shell redirect so it's easy to determine
|
# dd used rather than shell redirect so it's easy to determine
|
||||||
# whether or not the file write worked
|
# whether or not the file write worked
|
||||||
if ! printf "%b" "$("$argv0" s)" | dd of="$VOLUME_TMP_FILE" \
|
if ! printf "%b" "$("$argv0" s)" \
|
||||||
2>/dev/null
|
| dd >"$VOLUME_TMP_FILE" 2>/dev/null
|
||||||
then
|
then
|
||||||
printf "Error writing to file.\n" >/dev/stderr
|
printf "Error writing to file.\n" >/dev/stderr
|
||||||
false
|
false
|
||||||
@ -86,22 +129,15 @@ case "$argv1" in
|
|||||||
printf "Muted.\n"
|
printf "Muted.\n"
|
||||||
|
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
(r*) # system independent
|
(r*)
|
||||||
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" \
|
||||||
|
|| usage
|
||||||
|
|
||||||
if ! newval=$(add $("$argv0" s) $2) || ! stris int "$newval"; then
|
if ! newval=$(add $("$argv0" s) $2) || ! stris int "$newval"; then
|
||||||
printf "%b: Error finding new value for volume.\n"
|
printf "%b: Error finding new value for volume.\n" "$argv0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
"$argv0" a $newval
|
"$argv0" a $newval
|
||||||
exit $? ;;
|
exit $? ;;
|
||||||
(s*)
|
|
||||||
[ -z "$2" ] || usage
|
|
||||||
case "$(uname)" in
|
|
||||||
(NetBSD)
|
|
||||||
audioctl -a | grep "play\.gain" | cut -d '=' -f 2
|
|
||||||
;;
|
|
||||||
(*) unknown_system
|
|
||||||
esac
|
|
||||||
exit 0 ;;
|
|
||||||
(*) usage
|
(*) usage
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user