-
Notifications
You must be signed in to change notification settings - Fork 3
/
pa-vol.sh
executable file
·88 lines (77 loc) · 2.52 KB
/
pa-vol.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# CHANGES, RE-VIEWS/WRITES, IMPROVEMENTS:
# mhasko: functions; VOL-steps;
# gashapon: autodectect default sink
# konrad: more reliable way to autodetect default sink
# get default sink name
SINK_NAME=$(pacmd dump | perl -a -n -e 'print $F[1] if /set-default-sink/')
# try this line instead of the one above if you got problems with the detection of your default sink.
#SINK_NAME=$(pactl stat | grep "alsa_output" | perl -a -n -e 'print $F[2]')
SOURCE_NAME=$(pacmd dump | perl -a -n -e 'print $F[1] if /set-default-source/')
# set max allowed volume; 0x10000 = 100%
VOL_MAX="0x10000"
STEPS="16" # 2^n
VOL_STEP=$((VOL_MAX / STEPS))
VOL_NOW=`pacmd dump | grep -P "^set-sink-volume $SINK_NAME\s+" | perl -p -n -e 's/.+\s(.x.+)$/$1/'`
MUTE_STATE=`pacmd dump | grep -P "^set-sink-mute $SINK_NAME\s+" | perl -p -n -e 's/.+\s(yes|no)$/$1/'`
MIC_MUTE_STATE=`pacmd dump | grep -P "^set-source-mute $SINK_NAME\s+" | perl -p -n -e 's/.+\s(yes|no)$/$1/'`
function plus() {
VOL_NEW=$((VOL_NOW + VOL_STEP))
if [ $VOL_NEW -gt $((VOL_MAX)) ]; then
VOL_NEW=$((VOL_MAX))
fi
pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
}
function minus() {
VOL_NEW=$((VOL_NOW - VOL_STEP))
if [ $(($VOL_NEW)) -lt $((0x00000)) ]; then
VOL_NEW=$((0x00000))
fi
pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
}
function mute() {
pactl set-sink-mute $SINK_NAME toggle
}
function micmute() {
pactl set-source-mute $SOURCE_NAME toggle
}
function get() {
BAR=""
if [ $MUTE_STATE = yes ]; then
BAR="mute"
ITERATOR=$((STEPS / 2 - 2))
while [ $ITERATOR -gt 0 ]; do
BAR=" ${BAR} "
ITERATOR=$((ITERATOR - 1))
done
else
DENOMINATOR=$((VOL_MAX / STEPS))
LINES=$((VOL_NOW / DENOMINATOR))
DOTS=$((STEPS - LINES))
while [ $LINES -gt 0 ]; do
BAR="${BAR}|"
LINES=$((LINES - 1))
done
while [ $DOTS -gt 0 ]; do
BAR="${BAR}."
DOTS=$((DOTS - 1))
done
fi
echo "$BAR"
}
case "$1" in
plus)
plus
;;
minus)
minus
;;
mute)
mute
;;
get)
get
;;
micmute)
micmute
esac