Skip to content

Commit

Permalink
VOLUME_INC -> VOLUME_STEP for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
marioortizmanero committed Oct 25, 2020
1 parent 4dcb5cd commit 710a9d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pulseaudio-control.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ICON_SINK=
NOTIFICATIONS="no"
OSD="no"
SINK_NICKNAMES_PROP=
VOLUME_INC=2
VOLUME_STEP=2
VOLUME_MAX=130
declare -A SINK_NICKNAMES
declare -a ICONS_VOLUME
Expand Down Expand Up @@ -110,15 +110,15 @@ function volUp() {
return 1
fi
getCurVol "$curSink"
local maxLimit=$((VOLUME_MAX - VOLUME_INC))
local maxLimit=$((VOLUME_MAX - VOLUME_STEP))

# Checking the volume upper bounds so that if VOLUME_MAX was 100% and the
# increase percentage was 3%, a 99% volume would top at 100% instead
# of 102%. If the volume is above the maximum limit, nothing is done.
if [ "$curVol" -le "$VOLUME_MAX" ] && [ "$curVol" -ge "$maxLimit" ]; then
pactl set-sink-volume "$curSink" "$VOLUME_MAX%"
elif [ "$curVol" -lt "$maxLimit" ]; then
pactl set-sink-volume "$curSink" "+$VOLUME_INC%"
pactl set-sink-volume "$curSink" "+$VOLUME_STEP%"
fi

if [ $OSD = "yes" ]; then showOSD "$curSink"; fi
Expand All @@ -133,7 +133,7 @@ function volDown() {
echo "PulseAudio not running"
return 1
fi
pactl set-sink-volume "$curSink" "-$VOLUME_INC%"
pactl set-sink-volume "$curSink" "-$VOLUME_STEP%"

if [ $OSD = "yes" ]; then showOSD "$curSink"; fi
if [ $AUTOSYNC = "yes" ]; then volSync; fi
Expand Down Expand Up @@ -342,7 +342,7 @@ Options: [defaults]
--volume-max <int> maximum volume to which to allow
increasing [$VOLUME_MAX]
--volume-step <int> step size when inc/decrementing volume
[$VOLUME_INC]
[$VOLUME_STEP]
--sink-blacklist <name>[,<name>...] sinks to ignore when switching [none]
--sink-nicknames-from <prop> pacmd property to use for sink names,
unless overriden by --sink-nickname.
Expand Down Expand Up @@ -427,7 +427,7 @@ while [[ "$1" = --* ]]; do
VOLUME_MAX="$val"
;;
--volume-step)
VOLUME_INC="$val"
VOLUME_STEP="$val"
;;
--sink-blacklist)
IFS=, read -r -a SINK_BLACKLIST <<< "$val"
Expand Down
8 changes: 4 additions & 4 deletions tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ function setup() {
# Increases the volume from zero to a set maximum step by step, making
# sure that the results are expected.
VOLUME_MAX=350
VOLUME_INC=5
VOLUME_STEP=5
local vol=0
getCurSink
pactl set-sink-volume "$curSink" "$vol%"
for i in {1..100}; do
volUp
getCurVol "$curSink"
if [ "$vol" -lt $VOLUME_MAX ]; then
vol=$((vol + VOLUME_INC))
vol=$((vol + VOLUME_STEP))
fi
echo "Real volume is $curVol, expected $vol"
[ "$curVol" -eq $vol ]
Expand All @@ -97,7 +97,7 @@ function setup() {
# Decreases the volume to 0 step by step, making sure that the results
# are expected.
VOLUME_MAX=350
VOLUME_INC=5
VOLUME_STEP=5
# It shouldn't matter that the current volume exceeds the maximum volume
local vol=375
getCurSink
Expand All @@ -106,7 +106,7 @@ function setup() {
volDown
getCurVol "$curSink"
if [ "$vol" -gt 0 ]; then
vol=$((vol - VOLUME_INC))
vol=$((vol - VOLUME_STEP))
fi
echo "Real volume is $curVol, expected $vol"
[ "$curVol" -eq $vol ]
Expand Down

0 comments on commit 710a9d1

Please sign in to comment.