Page 1 of 1

Simple Alsa Volume Slider, plus other alsa treats

Posted: Fri 07 Sep 2018, 18:25
by johnywhy
Alsa Volume Slider:

Image

Image

Closes on click-away.


Why?
Alsa audio system comes bundled with most (all?) Puppies (maybe most Linuxes too).
http://www.puppylinux.org/wikka/alsa

I uninstalled/disabled PulseAudio to save RAM (since pulse runs in the background continually). Tiny Alsa volume-control options are hard to find. The VolumeIcon that comes with DebianDog also runs a continuous background process. The excellent Retrovol also runs a continuous background process.

This alternative volume slider doesn't run a continuous background process.


Script

Code: Select all

#!/bin/sh
VolCur=$(amixer -M get Master | awk -v FS="[[%]" '/%/ {print $2}')
yad --scale --max-value 100 --value $VolCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value | while read VolNew 
	do amixer -M -q set Master ${VolNew}%
	done

Installation
- Save the script in /usr/local/bin/set-volume
- Make a panel or desktop launcher, which runs set-volume (full path shouldn't be needed)


Explanation
To get current volume. (this may need to change if alsa changes it's messaging in future alsa releases)
VolCur=`amixer -M get Master | grep '%'
https://linux.die.net/man/1/amixer

returns
Mono: Playback 81 [64%] [-34.50dB] [on]

use awk to get % volume.
awk -v FS="(\[|\%)" '{print $2}'`

set new volume
amixer -M -q set Master 25%

yad ref
http://manpages.ubuntu.com/manpages/xen ... yad.1.html


Requires
yad
yad for tahr: http://mirror.internode.on.net/pub/pupp ... ages-tahr/
yad for slacko: https://distro.ibiblio.org/puppylinux/p ... es-slacko/
yad tips: http://murga-linux.com/puppy/viewtopic.php?t=97458


Tips

i like to put it on a launcher with the Alsa Mixer Gui, so i can access the full mixer if needed:

Image

Image

The alsa mixer gui comes bundled with some (most?) Puppies.
https://packages.debian.org/stretch/alsamixergui


Alternate volume control/mixer
Retrovol
http://www.puppylinux.org/wikka/RetroVol

Alsa's own
If you can't use my script above, or alsamixergui, or Retrovol, you can use Alsa's built-in command-window mixer

Code: Select all

# alsamixer
Image


Volume slider
check out my brightness slider
http://murga-linux.com/puppy/viewtopic.php?t=114229


Enjoy!

thx MochiMoppel for improved awk

Thanks

Posted: Fri 07 Sep 2018, 20:31
by mikeslr
Hi johnywhy,

Thanks for your work on this. I knew there was a good reason to keep you interested in the Puppies and Dogs. :D I see you're already beginning to find your own projects to improve them. :lol:

mikesLr

Re: Thanks

Posted: Sat 08 Sep 2018, 08:20
by johnywhy
mikeslr wrote:Thanks for your work on this. I knew there was a good reason to keep you interested in the Puppies and Dogs.
thx mikeslr, but i've been a puppy lover for years. i'm such an OG 8)

Re: Simple Alsa Volume Slider, plus other alsa treats

Posted: Sat 08 Sep 2018, 09:55
by MochiMoppel
johnywhy wrote:Script

Code: Select all

#!/bin/sh
VolCur=`amixer -M get Master | grep '%' | awk -v FS="(\[|\%)" '{print $2}'`
yad --scale --max-value 100 --value $VolCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value | while read VolNew 
	do amixer -M -q set Master ${VolNew}%
	done
How did you test your posted script?

Code: Select all

awk: warning: escape sequence `\[' treated as plain `['
awk: warning: escape sequence `\%' treated as plain `%'
awk: fatal: Unmatched [ or [^: /([|%)/

Posted: Sat 08 Sep 2018, 10:33
by fredx181
MochiMoppel wrote:How did you test your posted script?
Code:
awk: warning: escape sequence `\[' treated as plain `['
awk: warning: escape sequence `\%' treated as plain `%'
awk: fatal: Unmatched [ or [^: /([|%)/
Could be because your awk is symlink to busybox.
Works well for me with "full" awk, got similar error when using busybox awk.

Fred

Posted: Sat 08 Sep 2018, 10:45
by MochiMoppel
In Slacko 5.6 awk is symlinked to gawk ( gawk-3.1.8 )

Posted: Sat 08 Sep 2018, 10:51
by fredx181
MochiMoppel wrote:In Slacko 5.6 awk is symlinked to gawk ( gawk-3.1.8 )
Ah, for me it's symlink to mawk, and script works with that, a bit strange that it doesn't work with gawk.

Posted: Sat 08 Sep 2018, 11:15
by fredx181
This should be more portable then, I think, code to get $VolCur by forum member misko_2083

Code: Select all

#!/bin/sh
vol=$(amixer get Master | grep "\[on\]")
vol=( $vol )
# fredx181, check if pulseaudio is running, set VolCur accordingly.
[ $(pidof pulseaudio) ] && VolCur=$(echo ${vol[4]} | sed 's/[][%]//g') || VolCur=$(echo ${vol[3]} | sed 's/[][%]//g')
yad --scale --max-value 100 --value $VolCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value | while read VolNew
   do amixer -M -q set Master ${VolNew}%
   done
EDIT: This works for me with busybox awk as well as with awk symlinked to mawk:

Code: Select all

VolCur=`amixer sget Master | grep '%' | awk -F'[][]' '{ print $2 }'`
yad --scale --max-value 100 --value $VolCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value | while read VolNew
   do amixer -M -q set Master ${VolNew}%
   done
Fred

Posted: Sat 08 Sep 2018, 11:35
by johnywhy
thx for doing a tweak, Fred!

but a little confused. Your comments mention issues with awk, but your code mentions pulse.

imo, if you can spare the resources to run Pulse (with it's background process), then you can spare the resources to use Pulse volume control (with it's background process).

the intent of my slider is for when you don't want to/can't have either.

THX

Posted: Sat 08 Sep 2018, 11:45
by fredx181
johnywhy wrote:thx for doing a tweak, Fred!

but a little confused. Your comments mention issues with awk, but your code mentions pulse.

imo, if you can spare the resources to run Pulse (with it's background process), then you can spare the resources to use Pulse volume control (with it's background process).

the intent of my slider is for when you don't want to/can't have either.

THX
It's just in case pulseaudio is in use, then it works also, that's why checking for pid of pulseaudio, but anyway here's also without that check (assuming just alsa in use)

Code: Select all

vol=$(amixer get Master | grep "\[on\]")
vol=( $vol )
VolCur=$(echo ${vol[3]} | sed 's/[][%]//g')
yad --scale --max-value 100 --value $VolCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --close-on-unfocus --hide-value | while read VolNew
   do amixer -M -q set Master ${VolNew}%
   done
Fred

Posted: Sat 08 Sep 2018, 11:53
by MochiMoppel
This works for me:

Code: Select all

VolCur=$(amixer -M get Master | awk -v FS="[[%]" '/%/ {print $2}')

Posted: Sat 08 Sep 2018, 11:58
by fredx181
MochiMoppel wrote:This works for me:

Code: Select all

VolCur=$(amixer -M get Master | awk -v FS="[[%]" '/%/ {print $2}')
For me too.

Posted: Sat 08 Sep 2018, 13:17
by MochiMoppel
Good.

Just for the record the same with sed.

Code: Select all

VolCur=$(amixer -M get Master | sed -nr 's/.*\[([0-9]+)%.*/\1/p')
I think awk wins the beauty contest.

Posted: Sun 09 Sep 2018, 09:53
by johnywhy
MochiMoppel wrote:think awk wins the beauty contest.
definitely. and prettier than my first try.
i put the new awk into the OP.

THX

Re: Simple Alsa Volume Slider, plus other alsa treats

Posted: Wed 10 Oct 2018, 08:43
by greengeek
johnywhy wrote:To get current volume. (this may need to change if alsa changes it's messaging in future alsa releases)
VolCur=`amixer -M get Master | grep '%'
https://linux.die.net/man/1/amixer

returns
Mono: Playback 81 [64%] [-34.50dB] [on]
What is the reason for querying Mono level? It shows 60% on my system, when Retrovol shows Master vol at 100%. i'm confused (not an uncommon occurrence)