sxmo_audio.sh drop alsa support

Now that we support Pipewire and Pulseaudio, and that we automatically
determine available output ports, this is useless and badly supported.
This commit is contained in:
Willow Barraco
2023-08-11 09:48:39 +02:00
parent c33408abb5
commit e0efe35a2d
3 changed files with 57 additions and 150 deletions

View File

@@ -24,150 +24,150 @@ notifyvol() {
} }
# adjust *output* vol/mute # adjust *output* vol/mute
pulsevolup() { volup() {
pactl set-sink-volume @DEFAULT_SINK@ +"${1:-5}%" pactl set-sink-volume @DEFAULT_SINK@ +"${1:-5}%"
} }
pulsevoldown() { voldown() {
pactl set-sink-volume @DEFAULT_SINK@ -"${1:-5}%" pactl set-sink-volume @DEFAULT_SINK@ -"${1:-5}%"
} }
pulsevoltogglemute() { voltogglemute() {
pactl set-sink-mute @DEFAULT_SINK@ toggle pactl set-sink-mute @DEFAULT_SINK@ toggle
} }
pulsevolismuted() { volismuted() {
pactl get-sink-mute @DEFAULT_SINK@ | grep -q "Mute: yes" pactl get-sink-mute @DEFAULT_SINK@ | grep -q "Mute: yes"
} }
pulsevolget() { volget() {
if pulsevolismuted; then if volismuted; then
printf "muted" printf "muted"
else else
pactl get-sink-volume @DEFAULT_SINK@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//' pactl get-sink-volume @DEFAULT_SINK@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//'
fi fi
} }
pulsevolset() { volset() {
pactl set-sink-volume @DEFAULT_SINK@ "$1"% pactl set-sink-volume @DEFAULT_SINK@ "$1"%
} }
# adjust *input* vol/mute # adjust *input* vol/mute
pulsemicvolup() { micvolup() {
pactl set-source-volume @DEFAULT_SOURCE@ +"${1:-5}%" pactl set-source-volume @DEFAULT_SOURCE@ +"${1:-5}%"
} }
pulsemicvoldown() { micvoldown() {
pactl set-source-volume @DEFAULT_SOURCE@ -"${1:-5}%" pactl set-source-volume @DEFAULT_SOURCE@ -"${1:-5}%"
} }
pulsemictogglemute() { mictogglemute() {
pactl set-source-mute @DEFAULT_SOURCE@ toggle pactl set-source-mute @DEFAULT_SOURCE@ toggle
} }
pulsemicismuted() { micismuted() {
pactl get-source-mute @DEFAULT_SOURCE@ | grep -q "Mute: yes" pactl get-source-mute @DEFAULT_SOURCE@ | grep -q "Mute: yes"
} }
pulsemicvolget() { micvolget() {
if pulsemicismuted; then if micismuted; then
printf "muted" printf "muted"
else else
pactl get-source-volume @DEFAULT_SOURCE@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//' pactl get-source-volume @DEFAULT_SOURCE@ | head -n1 | cut -d'/' -f2 | sed 's/ //g' | sed 's/\%//'
fi fi
} }
pulsemicvolset() { micvolset() {
pactl set-source-volume @DEFAULT_SOURCE@ "$1"% pactl set-source-volume @DEFAULT_SOURCE@ "$1"%
} }
# set the *active port* for output # set the *active port* for output
pulsedeviceset() { deviceset() {
pactl set-sink-port @DEFAULT_SINK@ "[Out] $1" pactl set-sink-port @DEFAULT_SINK@ "[Out] $1"
} }
# set the *active port* for input # set the *active port* for input
pulsedevicesetinput() { devicesetinput() {
pactl set-source-port @DEFAULT_SOURCE@ "[In] $1" pactl set-source-port @DEFAULT_SOURCE@ "[In] $1"
} }
# get the *active port* for input # get the *active port* for input
pulsedevicegetinput() { devicegetinput() {
[ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1" [ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1"
pactl --format=json list sources | jq -r ".[] | select(.name == \"$default_source\") | .active_port" | sed 's/\[In] //' pactl --format=json list sources | jq -r ".[] | select(.name == \"$default_source\") | .active_port" | sed 's/\[In] //'
} }
# get the *active port* for output # get the *active port* for output
pulsedeviceget() { deviceget() {
[ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1" [ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1"
pactl --format=json list sinks | jq -r ".[] | select(.name == \"$default_sink\") | .active_port" | sed 's/\[Out] //' pactl --format=json list sinks | jq -r ".[] | select(.name == \"$default_sink\") | .active_port" | sed 's/\[Out] //'
} }
# get the default sink # get the default sink
pulsedevicegetdefaultsink() { devicegetdefaultsink() {
pactl get-default-sink pactl get-default-sink
} }
# get the default source # get the default source
pulsedevicegetdefaultsource() { devicegetdefaultsource() {
pactl get-default-source pactl get-default-source
} }
pulsesourceset() { sourceset() {
pactl set-default-source "$1" pactl set-default-source "$1"
} }
pulsesinkset() { sinkset() {
pactl set-default-sink "$1" pactl set-default-sink "$1"
} }
# get a list of sinks # get a list of sinks
_pulsesinkssubmenu() { _sinkssubmenu() {
[ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1" [ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1"
pactl --format=json list sinks | jq -r '.[] | .name, .description' | while read -r line; do pactl --format=json list sinks | jq -r '.[] | .name, .description' | while read -r line; do
name="$line" name="$line"
read -r description read -r description
if [ "$default_sink" = "$name" ]; then if [ "$default_sink" = "$name" ]; then
printf "%s %s %s ^ pulsesinkset %s\n" "$icon_chk" "$icon_spk" "$description" "$name" printf "%s %s %s ^ sinkset %s\n" "$icon_chk" "$icon_spk" "$description" "$name"
else else
printf " %s %s ^ pulsesinkset %s\n" "$icon_spk" "$description" "$name" printf " %s %s ^ sinkset %s\n" "$icon_spk" "$description" "$name"
fi fi
done done
} }
# get a list of output ports # get a list of output ports
_pulseoutportssubmenu() { _outportssubmenu() {
[ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1" [ -z "$1" ] && default_sink="$(pactl get-default-sink)" || default_sink="$1"
active_out_port="$(pulsedeviceget "$default_sink")" active_out_port="$(deviceget "$default_sink")"
pactl --format=json list sinks | jq -r ".[] | select(.name == \"$default_sink\" ) | .ports[] | select(.availability != \"not available\" ) | .name" | sed 's/\[Out] //' | while read -r line; do pactl --format=json list sinks | jq -r ".[] | select(.name == \"$default_sink\" ) | .ports[] | select(.availability != \"not available\" ) | .name" | sed 's/\[Out] //' | while read -r line; do
[ "$active_out_port" = "$line" ] && icon="$icon_ton" || icon="$icon_tof" [ "$active_out_port" = "$line" ] && icon="$icon_ton" || icon="$icon_tof"
printf " %s %s ^ pulsedeviceset %s\n" "$icon" "$line" "$line" printf " %s %s ^ deviceset %s\n" "$icon" "$line" "$line"
done done
} }
# get a list of input sources # get a list of input sources
_pulsesourcessubmenu() { _sourcessubmenu() {
[ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1" [ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1"
pactl --format=json list sources | jq -r '.[] | select (.monitor_source == "") | .name, .description' | while read -r line; do pactl --format=json list sources | jq -r '.[] | select (.monitor_source == "") | .name, .description' | while read -r line; do
name="$line" name="$line"
read -r description read -r description
if [ "$default_source" = "$name" ]; then if [ "$default_source" = "$name" ]; then
printf "%s %s %s ^ pulsesourceset %s\n" "$icon_chk" "$icon_mic" "$description" "$name" printf "%s %s %s ^ sourceset %s\n" "$icon_chk" "$icon_mic" "$description" "$name"
else else
printf " %s %s ^ pulsesourceset %s\n" "$icon_mic" "$description" "$name" printf " %s %s ^ sourceset %s\n" "$icon_mic" "$description" "$name"
fi fi
done done
} }
# get a list of input ports # get a list of input ports
_pulseinportssubmenu() { _inportssubmenu() {
# if the Headset is NOT plugged in, then do not display Headset # if the Headset is NOT plugged in, then do not display Headset
# as a option, as clicking on it causes pulse to unset the source!! # as a option, as clicking on it causes pulse to unset the source!!
[ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1" [ -z "$1" ] && default_source="$(pactl get-default-source)" || default_source="$1"
active_in_port="$(pulsedevicegetinput "$default_source")" active_in_port="$(devicegetinput "$default_source")"
pactl --format=json list sources | jq -r ".[] | select(.name == \"$default_source\" ) | .ports[] | select(.availability != \"not available\" ) | .name" | sed 's/\[In] //' | while read -r line; do pactl --format=json list sources | jq -r ".[] | select(.name == \"$default_source\" ) | .ports[] | select(.availability != \"not available\" ) | .name" | sed 's/\[In] //' | while read -r line; do
[ "$active_in_port" = "$line" ] && icon="$icon_ton" || icon="$icon_tof" [ "$active_in_port" = "$line" ] && icon="$icon_ton" || icon="$icon_tof"
printf " %s %s ^ pulsedevicesetinput %s\n" "$icon" "$line" "$line" printf " %s %s ^ devicesetinput %s\n" "$icon" "$line" "$line"
done done
} }
@@ -197,136 +197,53 @@ _ringmodesubmenu() {
fi fi
} }
pulsemenuchoices() { menuchoices() {
cur_vol="$(pulsevolget)" cur_vol="$(volget)"
cur_mic_vol="$(pulsemicvolget)" cur_mic_vol="$(micvolget)"
default_sink_name="$(pulsedevicegetdefaultsink)" default_sink_name="$(devicegetdefaultsink)"
default_source_name="$(pulsedevicegetdefaultsource)" default_source_name="$(devicegetdefaultsource)"
grep . <<EOF grep . <<EOF
$icon_cls Close Menu ^ exit $icon_cls Close Menu ^ exit
Output: Output:
$(_pulsesinkssubmenu "$default_sink_name") $(_sinkssubmenu "$default_sink_name")
$( $(
if [ "$cur_vol" != "muted" ]; then if [ "$cur_vol" != "muted" ]; then
printf " %s Volume (%s%%) ^ pulsevolup\n" "$icon_aru" "$cur_vol" printf " %s Volume (%s%%) ^ volup\n" "$icon_aru" "$cur_vol"
printf " %s Volume (%s%%) ^ pulsevoldown\n" "$icon_ard" "$cur_vol" printf " %s Volume (%s%%) ^ voldown\n" "$icon_ard" "$cur_vol"
printf " %s Output Mute ^ pulsevoltogglemute\n" "$icon_tof" printf " %s Output Mute ^ voltogglemute\n" "$icon_tof"
else else
printf " %s Output Mute ^ pulsevoltogglemute\n" "$icon_ton" printf " %s Output Mute ^ voltogglemute\n" "$icon_ton"
fi fi
) )
$(_pulseoutportssubmenu "$default_sink_name") $(_outportssubmenu "$default_sink_name")
Input: Input:
$(_pulsesourcessubmenu "$default_source_name") $(_sourcessubmenu "$default_source_name")
$( $(
if [ "$cur_mic_vol" != "muted" ]; then if [ "$cur_mic_vol" != "muted" ]; then
printf " %s Volume (%s%%) ^ pulsemicvolup\n" "$icon_aru" "$cur_mic_vol" printf " %s Volume (%s%%) ^ micvolup\n" "$icon_aru" "$cur_mic_vol"
printf " %s Volume (%s%%) ^ pulsemicvoldown\n" "$icon_ard" "$cur_mic_vol" printf " %s Volume (%s%%) ^ micvoldown\n" "$icon_ard" "$cur_mic_vol"
printf " %s Input Mute ^ pulsemictogglemute\n" "$icon_tof" printf " %s Input Mute ^ mictogglemute\n" "$icon_tof"
else else
printf " %s Input Mute ^ pulsemictogglemute\n" "$icon_ton" printf " %s Input Mute ^ mictogglemute\n" "$icon_ton"
fi fi
) )
$(_pulseinportssubmenu "$default_source_name") $(_inportssubmenu "$default_source_name")
Call Options: Call Options:
$(_callaudiodsubmenu) $(_callaudiodsubmenu)
$(_ringmodesubmenu) $(_ringmodesubmenu)
EOF EOF
} }
alsacurrentdevice() {
if ! [ -f "$XDG_RUNTIME_DIR"/sxmo.audiocurrentdevice ]; then
alsadeviceset "$SPEAKER"
printf %s "$SPEAKER" > "$XDG_RUNTIME_DIR"/sxmo.audiocurrentdevice
fi
cat "$XDG_RUNTIME_DIR"/sxmo.audiocurrentdevice
}
amixerextractvol() {
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
}
alsavolup() {
amixer -c "${SXMO_ALSA_CONTROL_NAME:-0}" set "$(alsacurrentdevice)" "${1:-5}%+" | amixerextractvol | notifyvol -
}
alsavoldown() {
amixer -c "${SXMO_ALSA_CONTROL_NAME:-0}" set "$(alsacurrentdevice)" "${1:-5}%-" | amixerextractvol | notifyvol -
}
alsavolget() {
if [ -n "$(alsacurrentdevice)" ]; then
amixer -c "${SXMO_ALSA_CONTROL_NAME:-0}" get "$(alsacurrentdevice)" | amixerextractvol
fi
}
alsamicismuted() {
echo "alsamicismuted: Not implemented">&2
}
alsadeviceget() {
case "$(alsacurrentdevice)" in
"$SPEAKER")
printf "Speaker"
;;
"$HEADPHONE")
printf "Headphone"
;;
"$EARPIECE")
printf "Earpiece"
;;
esac
}
alsamenuchoices() {
CURRENTDEV="$(alsacurrentdevice)"
cat <<EOF
$icon_cls Close Menu ^ exit
$icon_hdp Headphones $([ "$CURRENTDEV" = "Headphone" ] && echo "$icon_chk") ^ alsadeviceset Headphones
$icon_spk Speaker $([ "$CURRENTDEV" = "Line Out" ] && echo "$icon_chk") ^ alsadeviceset Speaker
$icon_phn Earpiece $([ "$CURRENTDEV" = "Earpiece" ] && echo "$icon_chk") ^ alsadeviceset Earpiece
$icon_mut None $([ -z "$CURRENTDEV" ] && echo "$icon_chk") ^ alsadeviceset
$icon_aru Volume up ^ alsavolup
$icon_ard Volume down ^ alsavoldown
$(_ringmodesubmenu)
EOF
}
ispulse() {
command -v pactl > /dev/null 2>&1 || return 1
pactl info > /dev/null 2>&1 || return 1
}
if [ -z "$*" ]; then if [ -z "$*" ]; then
set -- menu set -- menu
fi fi
backend="$AUDIO_BACKEND"
if [ -z "$backend" ]; then
if ispulse; then
backend=pulse
else
backend=alsa
fi
fi
if [ "$backend" = "alsa" ]; then
# set some alsa specific things
SPEAKER="${SXMO_SPEAKER:-"Line Out"}"
HEADPHONE="${SXMO_HEADPHONE:-"Headphone"}"
EARPIECE="${SXMO_EARPIECE:-"Earpiece"}"
fi
cmd="$1" cmd="$1"
shift shift
case "$cmd" in case "$cmd" in
menu) menu)
while : ; do while : ; do
CHOICES="$("$backend"menuchoices)" CHOICES="$(menuchoices)"
PICKED="$( PICKED="$(
printf "%s\n" "$CHOICES" | printf "%s\n" "$CHOICES" |
cut -d'^' -f1 | cut -d'^' -f1 |
@@ -341,22 +258,22 @@ case "$cmd" in
vol) vol)
verb="$1" verb="$1"
shift shift
"$backend"vol"$verb" "$@" vol"$verb" "$@"
;; ;;
mic) mic)
verb="$1" verb="$1"
shift shift
"$backend"mic"$verb" "$@" mic"$verb" "$@"
;; ;;
device) device)
verb="$1" verb="$1"
shift shift
"$backend"device"$verb" "$1" device"$verb" "$1"
;; ;;
notify) notify)
notifyvol "$("${backend}volget")" notifyvol "$(volget)"
;; ;;
micnotify) micnotify)
notifyvol "$("${backend}micvolget")" notifyvol "$(micvolget)"
;; ;;
esac esac

View File

@@ -62,15 +62,6 @@ SXMO_LED_GREEN_TYPE | LED device type, i.e., the part after the colon in the pa
SXMO_SWAY_SCALE | Screen scale for hidpi screens. Can be fractional [SWAY-ONLY]. SXMO_SWAY_SCALE | Screen scale for hidpi screens. Can be fractional [SWAY-ONLY].
### Music-related
SXMO_SPEAKER | Audio device name for the main speaker [default: Speaker]
SXMO_EARPIECE | Audio device name for the earpiece speaker [default: Earpiece]
SXMO_HEADPHONE | Audio device name for the headphones [default: Headphone]
SXMO_ALSA_CONTROL_NAME | Alsa audio control name [default: 0]
### Input-related ### Input-related
SXMO_TOUCHSCREEN_ID | ID (from xinput) for the touchscreen device [DWM-ONLY] [default: 10] SXMO_TOUCHSCREEN_ID | ID (from xinput) for the touchscreen device [DWM-ONLY] [default: 10]

View File

@@ -5,7 +5,6 @@
export SXMO_SYS_FILES="/sys/power/state /sys/devices/platform/soc/1f00000.rtc/power/wakeup /sys/power/mem_sleep /dev/rtc0 /sys/devices/platform/soc/1f03400.rsb/sunxi-rsb-3a3/axp221-pek/power/wakeup" export SXMO_SYS_FILES="/sys/power/state /sys/devices/platform/soc/1f00000.rtc/power/wakeup /sys/power/mem_sleep /dev/rtc0 /sys/devices/platform/soc/1f03400.rsb/sunxi-rsb-3a3/axp221-pek/power/wakeup"
export SXMO_TOUCHSCREEN_ID=8 export SXMO_TOUCHSCREEN_ID=8
export SXMO_MONITOR="DSI-1" export SXMO_MONITOR="DSI-1"
export SXMO_ALSA_CONTROL_NAME=PinePhone
export SXMO_SWAY_SCALE="2" export SXMO_SWAY_SCALE="2"
export SXMO_POWER_BUTTON="0:0:axp20x-pek" export SXMO_POWER_BUTTON="0:0:axp20x-pek"
export SXMO_VOLUME_BUTTON="1:1:1c21800.lradc" export SXMO_VOLUME_BUTTON="1:1:1c21800.lradc"