marioortizmanero / polybar-pulseaudio-control

A feature-full Polybar module to control PulseAudio
MIT License
471 stars 49 forks source link

Make sure only one integer value is returned #33

Closed mntzrr closed 4 years ago

mntzrr commented 4 years ago

Occasionally, an integer value of 100, in addition of the active volume level, is returned which breaks all conditional statements where an integer expression is expected.

++ pacmd list-sinks
++ awk '/\* index:/{print $3}'
+ curSink=2
+ getCurVol 2
++ pacmd list-sinks
++ grep -A 15 'index: 2'
++ grep volume:
++ awk -F : '{print $3}'
++ grep -o -P '.{0,3}%'
++ sed 's/.$//'
++ tr -d ' '
++ grep -E -v 'base volume:'
+ curVol='93
100'
+ getIsMuted 2
++ pacmd list-sinks
++ grep -A 15 'index: 2'
++ awk '/muted/{print $2}'
+ isMuted='yes
no'
+ local iconsLen=2
+ '[' 2 -ne 0 ']'
+ local volSplit=75
++ seq 1 2
+ for i in $(seq 1 "$iconsLen")
+ '[' 75 -ge '93
100' ']'
./pulseaudio-control.bash: line 285: [: 93
100: integer expression expected
+ for i in $(seq 1 "$iconsLen")
+ '[' 150 -ge '93
100' ']'
./pulseaudio-control.bash: line 285: [: 93
100: integer expression expected
+ getNickname 2
+ getSinkName 2
++ pactl list sinks short
marioortizmanero commented 4 years ago

Hello!

Sorry for the delay, I was on holiday. What does this second volume value mean? Is it OK to ignore it? I can't reproduce it with my own setup, you might know more about it. Or is it just "front-left" and "front-right"? This is what I get:

$ pacmd list-sinks | grep -A 15 'index: '"1"'' | grep 'volume:' | grep -E -v 'base volume:'
    volume: front-left: 19985 /  30% / -30.95 dB,   front-right: 19985 /  30% / -30.95 dB

This script just returns the "front-left" volume currently, but I'm not sure if that's an issue for anyone really. Can you make sure we're talking about the same thing before I merge?

Thanks :)

mntzrr commented 4 years ago

I can't really reproduce it always. It used to happen randomly and often at the start of system and continuing from suspend/sleep. I am sure it has nothing to do with Polybar itself, I checked this by running the getCurVol function in Terminal.

Once I introduced exit in the AWK expression, this issue has never happened again. I believe it is a safe change. We are simply exiting after processing the third word on the first line. This would imply that the second value must be in the second line. In that case, that would be the base volume but that should have already been removed. I am not really sure why this is happening either since I don't modify the volume of either channels individually.

Welcome back! I hope you've had a good holiday :)

marioortizmanero commented 4 years ago

Okay seems good to me then, thanks for the PR. And have a good summer as well! :)