marioortizmanero / polybar-pulseaudio-control

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

Error flash on volume change - line 231 #7

Closed rbw-lpp closed 4 years ago

rbw-lpp commented 4 years ago

Hi,

Changing the volume causes the following error message to display: /pulseaudio-control.sh: line 231: [: : integer expression expected If I run the script from the command line I get the following awk errors as well:

./pulseaudio-control.sh --listen
awk: line 1: regular expression compile failed (missing operand)
* index:
awk: line 1: regular expression compile failed (missing operand)
* index:
./pulseaudio-control.sh: line 231: [: : integer expression expected
# 24%   # 

From what I understand the error is related to the custom sink icons - I didn't set any (didn't event modify the script) but I don't really care about them.

marioortizmanero commented 4 years ago

What bash version are you using? Can I get your output from pacmd list-sinks, too? I can't reproduce it myself.

The line where the error happens is this:

# Uses custom sink icon if the array contains one
local sinksLen=${#CUSTOM_SINK_ICONS[@]}
if [ "$activeSink" -le "$((sinksLen - 1))" ]; then  # <--- here
    sinkIcon=${CUSTOM_SINK_ICONS[$activeSink]}
else
    sinkIcon=$DEFAULT_SINK_ICON
fi

and the error points out that activeSink is empty, probably because it couldn't be obtained earlier with this, at line 134:

local activeSink=$(echo "$sinksList" | grep "\* index" | awk -F': ' '{print $2}')

sinksList is obtained with:

local sinksList=$(pacmd list-sinks | grep -e 'index' -e 'device.description')

Meaning that it failed when trying to obtain the list with the available sinks... But there are awk errors previously, so it might be the activeSink line instead.

rbw-lpp commented 4 years ago

Thanks! Bash version:

bash --version                        
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)

pacmd list-sinks

pacmd list-sinks
2 sink(s) available.
    index: 0
    name: <alsa_output.usb-DisplayLink_Dell_D1000_USB3.0_Dock_1702070322-02.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9049
    volume: front-left: 7864 /  12% / -55.25 dB,   front-right: 7864 /  12% / -55.25 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 2006.65 ms
    max request: 375 KiB
    max rewind: 375 KiB
    monitor source: 0
    sample spec: s16le 2ch 48000Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 2000.00 ms; range is 0.50 .. 2000.00 ms
    card: 0 <alsa_card.usb-DisplayLink_Dell_D1000_USB3.0_Dock_1702070322-02>
    module: 7
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "USB Audio"
        alsa.id = "USB Audio"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "1"
        alsa.card_name = "Dell D1000 USB3.0 Dock"
        alsa.long_card_name = "DisplayLink Dell D1000 USB3.0 Dock at usb-0000:00:14.0-4.2, super speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:14.0-usb-0:4.2:1.2"
        sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4.2/2-4.2:1.2/sound/card1"
        udev.id = "usb-DisplayLink_Dell_D1000_USB3.0_Dock_1702070322-02"
        device.bus = "usb"
        device.vendor.id = "17e9"
        device.vendor.name = "DisplayLink"
        device.product.id = "436c"
        device.product.name = "Dell D1000 USB3.0 Dock"
        device.serial = "DisplayLink_Dell_D1000_USB3.0_Dock_1702070322"
        device.string = "front:1"
        device.buffering.buffer_size = "384000"
        device.buffering.fragment_size = "192000"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analog Stereo"
        device.description = "Dell D1000 USB3.0 Dock Analog Stereo"
        alsa.mixer_name = "USB Mixer"
        alsa.components = "USB17e9:436c"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    ports:
        analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
            properties:

    active port: <analog-output>
  * index: 1
    name: <alsa_output.pci-0000_00_1f.3.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9039
    volume: front-left: 49479 /  75% / -7.32 dB,   front-right: 49479 /  75% / -7.32 dB
            balance 0.00
    base volume: 65536 / 100% / 0.00 dB
    volume steps: 65537
    muted: no
    current latency: 371.67 ms
    max request: 64 KiB
    max rewind: 64 KiB
    monitor source: 2
    sample spec: s16le 2ch 44100Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 0
    configured latency: 371.52 ms; range is 0.50 .. 371.52 ms
    card: 1 <alsa_card.pci-0000_00_1f.3>
    module: 8
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "ALC3246 Analog"
        alsa.id = "ALC3246 Analog"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "0"
        alsa.card_name = "HDA Intel PCH"
        alsa.long_card_name = "HDA Intel PCH at 0xed3c0000 irq 147"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1f.3"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "a348"
        device.form_factor = "internal"
        device.string = "front:0"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analog Stereo"
        device.description = "Built-in Audio Analog Stereo"
        alsa.mixer_name = "Realtek ALC3246"
        alsa.components = "HDA:10ec0256,10280818,00100002 HDA:8086280b,80860101,00100000"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-speakers"
        analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
            properties:
                device.icon_name = "audio-headphones"
    active port: <analog-output-speaker>

When I run the sinksList manually:

sinksList=$(pacmd list-sinks | grep -e 'index' -e 'device.description')
echo $sinksList                                                        
    index: 0
        device.description = "Dell D1000 USB3.0 Dock Analog Stereo"
  * index: 1
        device.description = "Built-in Audio Analog Stereo"

And then activeSink:

activeSink=$(echo "$sinksList" | grep "\* index" | awk -F': ' '{print $2}')
echo $activeSink
1
rbw-lpp commented 4 years ago

I've also started getting a syntax error:

awk: line 1: regular expression compile failed (missing operand)
* index:
awk: line 1: regular expression compile failed (missing operand)
* index:
./pulseaudio-control.sh: line 220: ((: 12
75: syntax error in expression (error token is "75")
./pulseaudio-control.sh: line 220: ((: 12
75: syntax error in expression (error token is "75")
./pulseaudio-control.sh: line 220: ((: 12
75: syntax error in expression (error token is "75")
./pulseaudio-control.sh: line 231: [: : integer expression expected
12
75%   # 
marioortizmanero commented 4 years ago

Hmm I use bash 5 myself, so I downloaded bash 4 to test it. But it seems to work correctly (even with sh, actually):

~/Programming/polybar-pulseaudio-control master
❯ bash4 pulseaudio-control.bash --listen
%{F#6b6b6b}# 8%   # 0%{F-}
^C
~/Programming/polybar-pulseaudio-control master
❯ bash4 --version
GNU bash, version 4.4.23(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Your syntax error lines are the following:

local volSplit=$(( MAX_VOL / iconsLen ))
for (( i=1; i<=iconsLen; i++ )); do
    if (( i*volSplit >= curVol )); then
        volIcon="${VOLUME_ICONS[$((i-1))]}"
        break
    fi
done

Meaning that if ((condition)) isn't supported by your bash version. You can try the compat branch to check if the changes I've made fix any errors (probably the syntax errors and awk).

rbw-lpp commented 4 years ago

I've tried the compat branch and it works without issues now - both the syntax errors and no awk errors as well.

I've seen that you have a PR https://github.com/marioortizmanero/polybar-pulseaudio-control/pull/8 , so after it's merged we can close this issue :)

I use zsh and bash version was the one that comes installed with Ubuntu 18.04 so it's weird that it works with bash4.4.23 but has issues with bash4.4.20 , but then I do have an affinity of finding weird bugs.

marioortizmanero commented 4 years ago

Great!

Yeah the bug was really weird, but these if ((condition)) were unnecessary anyway, so it's been useful to clean it up a bit.

Thanks for the help! Closing this now.

rbw-lpp commented 4 years ago

Great, thanks and have a nice day :)