Skip to content

Commit

Permalink
volume-pulseaudio: add mixer and scontrol override options
Browse files Browse the repository at this point in the history
Fixes: #136
  • Loading branch information
kb100 committed Jan 15, 2018
1 parent e695795 commit b77e391
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
26 changes: 23 additions & 3 deletions volume-pulseaudio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,36 @@ bindsym XF86AudioMute exec amixer -q -D pulse sset Master toggle && pkill -RTMIN

where the number `1` in `-RTMIN+1` can be replaced to another signal number,
as long as it agrees what you put for `signal=` in your i3blocks config.
The previous lines also assume your mixer is "pulse" and your scontrol is "Master".
If yours are different, change them appropriately.

# Known bug

The script tries its best to guess your mixer and scontrol variables, which are needed for
scrolling up/down and muting with middle click to work.
However, there are an unknown number of edge cases and no known way to account for all of them.
Therefore, the `-m` and `-s`flags are provided to specify them manually.
In almost all cases, one of the following two will work

- `-m default -s Master`
- `-m pulse -s Master`

If neither of these works for you, try using `alsamixer`, `amixer`, and `amixer info` to guide your guesses,
and let us know what turned out to work.

# Options

```
Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a] [-H symb] [-M symb]
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-h]
Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a|-d] [-H symb] [-M symb]
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter]
[-m mixer] [-s scontrol] [-h]
Options:
-F, -f Output format (-F long format, -f short format) to use, amongst:
0 symb vol [index:name] (default long)
1 symb vol [name]
2 symb vol [index] (default short)
3 symb vol
-S Subscribe to volume events (requires persistent block, always uses long format)
-S Subscribe to volume events (requires persistent block, always uses long format)
-p Omit the percent sign (%) in volume
-a Use ALSA name if possible
-d Use device description instead of name if possible
Expand All @@ -52,5 +69,8 @@ Options:
-t Threshold for low audio level. Default: 0
-C Color for non-muted audio. Default: #ffffff
-c Color for muted audio. Default: #a0a0a0
-i Interval size of volume increase/decrease. Default: 5
-m Use the given mixer.
-s Use the given scontrol.
-h Show this help text
```
22 changes: 16 additions & 6 deletions volume-pulseaudio/volume-pulseaudio
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ USE_DESCRIPTION=0

SUBSCRIBE=0

while getopts F:Sf:padH:M:L:X:T:t:C:c:i:h opt; do
while getopts F:Sf:padH:M:L:X:T:t:C:c:i:m:s:h opt; do
case "$opt" in
S) SUBSCRIBE=1 ;;
F) LONG_FORMAT="$OPTARG" ;;
Expand All @@ -41,9 +41,12 @@ while getopts F:Sf:padH:M:L:X:T:t:C:c:i:h opt; do
C) DEFAULT_COLOR="$OPTARG" ;;
c) MUTED_COLOR="$OPTARG" ;;
i) AUDIO_INTERVAL="$OPTARG" ;;
m) MIXER="$OPTARG" ;;
s) SCONTROL="$OPTARG" ;;
h) printf \
"Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a|-d] [-H symb] [-M symb]
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter] [-h]
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter]
[-m mixer] [-s scontrol] [-h]
Options:
-F, -f\tOutput format (-F long format, -f short format) to use, amongst:
\t0\t symb vol [index:name]\t (default long)
Expand All @@ -63,17 +66,24 @@ Options:
-C\tColor for non-muted audio. Default: $DEFAULT_COLOR
-c\tColor for muted audio. Default: $MUTED_COLOR
-i\tInterval size of volume increase/decrease. Default: $AUDIO_INTERVAL
-m\tUse the given mixer.
-s\tUse the given scontrol.
-h\tShow this help text
" && exit 0;;
esac
done

MIXER="default"
if [[ "$(amixer info | head -1 | cut -d ' ' -f 2)" == "pulse" ]] ; then
MIXER="pulse"
if [[ -z "$MIXER" ]] ; then
MIXER="default"
if [[ "$(amixer info | head -1 | cut -d ' ' -f 2)" == "pulse" ]] ; then
MIXER="pulse"
fi
fi

if [[ -z "$SCONTROL" ]] ; then
SCONTROL=$(amixer -D "$MIXER" scontrols | sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | head -n1)
fi

SCONTROL=$(amixer -D "$MIXER" scontrols | sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | head -n1)
CAPABILITY=$(amixer -D $MIXER get $SCONTROL | sed -n "s/ Capabilities:.*cvolume.*/Capture/p")


Expand Down

0 comments on commit b77e391

Please sign in to comment.