pulseaudio-equalizer/pulseaudio-equalizer-use-pactl.patch

128 lines
7.1 KiB
Diff

--- a/bin/pulseaudio-equalizer.in
+++ b/bin/pulseaudio-equalizer.in
@@ -111,20 +111,20 @@ fi
# Get sink names and volumes
PA_LADSPA_SINK="ladspa_output.$PA_LADSPA_PLUGIN.$PA_LADSPA_LABEL"
-PA_CURRENT_SINK=$(pacmd stat | grep --color=never 'Default sink name' | sed 's/Default sink name: //g')
-PA_CURRENT_VOLUME=$(pacmd list | grep --color=never -A20 "<$PA_CURRENT_SINK>" | grep --color=never -m1 'volume: ' | grep --color=never -Po '(\d+)%' | awk 'NR==1{sub(/%/,"",$1); print $1}')
+PA_CURRENT_SINK="$(pactl get-default-sink)"
+PA_CURRENT_VOLUME="$(pactl get-sink-volume "$PA_CURRENT_SINK" | grep --color=never -Eo '([[:digit:]]+)%' | awk 'NR==1{sub(/%/,"",$1); print $1}')"
PA_REAL_VOLUME=$((PA_CURRENT_VOLUME*65536/100))
PA_REAL_PREAMP_FLOAT=$(echo "$PA_PREAMP*65536" | bc)
PA_REAL_PREAMP=${PA_REAL_PREAMP_FLOAT/\.*}
-PA_CURRENT_MUTE=$(pacmd list-sinks | grep --color=never -A20 "<$PA_CURRENT_SINK>" | grep -m1 'muted: ' | sed 's/[\t]muted: no/0/g' | sed 's/[\t]muted: yes/1/g')
+PA_CURRENT_MUTE="$(pactl get-sink-mute "$PA_CURRENT_SINK" | sed -e 's/Mute: no/0/g;s/Mute: yes/1/g')"
# Check if equalizer is running and get accurate master sink name
if [ "$PA_CURRENT_SINK" = "$PA_LADSPA_SINK" ]; then
PA_EQUALIZER_STATUS=1
- PA_MASTER_SINK=$(pacmd info | grep --color=never -A30 "<$PA_CURRENT_SINK>" | grep --color=never -m1 'device.master_device = ' | sed 's/device.master_device = //g' | sed 's/"//g' | sed 's/^[ \t]*//')
+ PA_MASTER_SINK="$(pactl list short modules | grep --color=never "module-ladspa-sink.*sink_name=$PA_CURRENT_SINK" | tr ' ' '\n' | sed '/^sink_master/!d;s/^sink_master=//')"
else
PA_EQUALIZER_STATUS=0
- PA_MASTER_SINK=$(pacmd stat | grep --color=never 'Default sink name' | sed 's/Default sink name: //g')
+ PA_MASTER_SINK="$(pactl get-default-sink)"
fi
# Check if equalizer is set as persistent
@@ -365,66 +365,62 @@ if [ "$1" = 'disable' ] || [ "$1" = 'ena
echo '-------------------------------------'
echo 'Current operation: disabling equalizer'
echo '-------------------------------------'
- echo -n >/tmp/eqcommands.sh
# Unload & reload stream-restore module
echo 'Unloading & reloading stream-restore module...'
- echo >>/tmp/eqcommands.sh "unload-module $(pacmd list | grep -B1 -m1 'name: <module-stream-restore>' | grep ' index: ' | sed 's/ index: //g')"
- echo >>/tmp/eqcommands.sh 'load-module module-stream-restore'
-
- # Unload LADSPA sink module (if it is already loaded)
- echo 'Unloading module-ladspa-sink...'
- echo >>/tmp/eqcommands.sh "unload-module $(pacmd list | grep -B1 -m1 'name: <module-ladspa-sink>' | grep ' index: ' | sed 's/ index: //g')"
+ pactl unload-module module-stream-restore
+ pactl load-module module-stream-restore >/dev/null
# Move active client sinks to ALSA sink
echo "Moving active PulseAudio clients to ALSA sink ($PA_MASTER_SINK)..."
- echo >>/tmp/eqcommands.sh "$(pacmd "list-sink-inputs" | grep 'index: ' | sed 's/ index: /move-sink-input /g' | sed "s/$/ $PA_MASTER_SINK/g")"
+ pactl list short sink-inputs | awk '{print $1}' | while read -r INPUT; do
+ pactl move-sink-input "$INPUT" "$PA_MASTER_SINK"
+ done
+
+ # Unload LADSPA sink module (if it is already loaded)
+ echo 'Unloading module-ladspa-sink...'
+ pactl unload-module module-ladspa-sink
# Transfer current mute/sink volume to ALSA sink
echo "Transferring current mute ($PA_CURRENT_MUTE) & volume ($PA_CURRENT_VOLUME%) to ALSA sink ($PA_MASTER_SINK)..."
- echo >>/tmp/eqcommands.sh "set-default-sink $PA_MASTER_SINK"
- echo >>/tmp/eqcommands.sh "set-sink-volume $PA_MASTER_SINK $PA_REAL_VOLUME"
- echo >>/tmp/eqcommands.sh "set-sink-mute $PA_MASTER_SINK $PA_CURRENT_MUTE"
-
- # Execute all queued commands (for potential speed benefit)...
- pacmd </tmp/eqcommands.sh >/dev/null
+ pactl set-default-sink "$PA_MASTER_SINK"
+ pactl set-sink-volume "$PA_MASTER_SINK" "$PA_REAL_VOLUME"
+ pactl set-sink-mute "$PA_MASTER_SINK" "$PA_CURRENT_MUTE"
fi
if [ "$1" = 'enable' ]; then
echo '-------------------------------------'
echo 'Current operation: enabling equalizer'
echo '-------------------------------------'
- echo -n >/tmp/eqcommands.sh
# Unload & reload stream-restore module with restore_device option disabled (to ensure that previously cached per-client sinks are not used)
echo 'Unloading & reloading stream-restore module...'
- echo >>/tmp/eqcommands.sh "unload-module $(pacmd list | grep -B1 -m1 'name: <module-stream-restore>' | grep ' index: ' | sed 's/ index: //g')"
- echo >>/tmp/eqcommands.sh 'load-module module-stream-restore restore_device=false'
+ pactl unload-module module-stream-restore
+ pactl load-module module-stream-restore restore_device=false >/dev/null
# Load LADSPA sink module
echo 'Loading module-ladspa-sink...'
- echo >>/tmp/eqcommands.sh "load-module module-ladspa-sink sink_name=$PA_LADSPA_SINK master=$PA_MASTER_SINK plugin=$PA_LADSPA_PLUGIN label=$PA_LADSPA_LABEL control=$PA_LADSPA_CONTROLS"
+ pactl load-module module-ladspa-sink "sink_name=$PA_LADSPA_SINK" "sink_master=$PA_MASTER_SINK" "plugin=$PA_LADSPA_PLUGIN" "label=$PA_LADSPA_LABEL" "control=$PA_LADSPA_CONTROLS" >/dev/null
# Transfer current sink mute/volume to LADSPA sink
echo "Transferring current mute ($PA_CURRENT_MUTE) & volume ($PA_CURRENT_VOLUME%) to LADSPA sink ($PA_LADSPA_SINK)..."
- echo >>/tmp/eqcommands.sh "set-sink-volume $PA_LADSPA_SINK $PA_REAL_VOLUME"
- echo >>/tmp/eqcommands.sh "set-sink-mute $PA_LADSPA_SINK $PA_CURRENT_MUTE"
+ pactl set-sink-volume "$PA_LADSPA_SINK" "$PA_REAL_VOLUME"
+ pactl set-sink-mute "$PA_LADSPA_SINK" "$PA_CURRENT_MUTE"
# Unmute & set preamp level on ALSA sink (as LADSPA sink will act as primary volume control)
echo "Setting ALSA sink ($PA_MASTER_SINK) preamp (${PA_PREAMP}x)..."
- #echo >>/tmp/eqcommands.sh "set-sink-volume $PA_MASTER_SINK $PA_REAL_PREAMP"
- echo >>/tmp/eqcommands.sh "set-sink-mute $PA_MASTER_SINK 0"
+ #pactl set-sink-volume "$PA_MASTER_SINK" "$PA_REAL_PREAMP"
+ pactl set-sink-mute "$PA_MASTER_SINK" 0
# Set the LADSPA sink as the default
echo "Setting LADSPA sink ($PA_LADSPA_SINK) as default sink..."
- echo >>/tmp/eqcommands.sh "set-default-sink $PA_LADSPA_SINK"
+ pactl set-default-sink "$PA_LADSPA_SINK"
# Move currently active client sinks to LADSPA sink
echo "Moving active PulseAudio clients to LADSPA sink ($PA_LADSPA_SINK)..."
- echo >>/tmp/eqcommands.sh "$(pacmd "list-sink-inputs" | grep 'index: ' | sed 's/ index: /move-sink-input /g' | sed "s/$/ $PA_LADSPA_SINK/g")"
-
- # Execute all queued commands (for potential speed benefit)...
- pacmd </tmp/eqcommands.sh >/dev/null
+ pactl list short sink-inputs | awk '{print $1}' | while read -r INPUT; do
+ pactl move-sink-input "$INPUT" "$PA_LADSPA_SINK"
+ done
fi
if [ -z "$1" ] || [ "$1" = '' ] || [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
@@ -455,7 +451,7 @@ if [ "$1" = 'status' ]; then
fi
# Refresh current sink status and display equalizer information
-PA_CURRENT_SINK="$(pacmd stat | grep "Default sink name" | sed 's/Default sink name: //g')"
+PA_CURRENT_SINK="$(pactl get-default-sink)"
if [ "$PA_CURRENT_SINK" = "$PA_LADSPA_SINK" ]; then
echo '-------------------------------------'
echo 'Equalizer status: [enabled]'