Author |
Message |
johnywhy

Joined: 20 Aug 2011 Posts: 882
|
Posted: Fri 07 Sep 2018, 14:25 Post subject:
Simple Alsa Volume Slider, plus other alsa treats |
|
Alsa Volume Slider:
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: | #!/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/xenial/man1/yad.1.html
Requires
yad
yad for tahr: http://mirror.internode.on.net/pub/puppylinux/pet_packages-tahr/
yad for slacko: https://distro.ibiblio.org/puppylinux/pet_packages-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:
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
Volume slider
check out my brightness slider
http://murga-linux.com/puppy/viewtopic.php?t=114229
Enjoy!
thx MochiMoppel for improved awk
_________________ Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Last edited by johnywhy on Tue 11 Sep 2018, 01:34; edited 6 times in total
|
Back to top
|
|
 |
mikeslr

Joined: 16 Jun 2008 Posts: 3543 Location: 500 seconds from Sol
|
Posted: Fri 07 Sep 2018, 16:31 Post subject:
Thanks |
|
Hi johnywhy,
Thanks for your work on this. I knew there was a good reason to keep you interested in the Puppies and Dogs. I see you're already beginning to find your own projects to improve them.
mikesLr
|
Back to top
|
|
 |
johnywhy

Joined: 20 Aug 2011 Posts: 882
|
Posted: Sat 08 Sep 2018, 04:20 Post subject:
Re: Thanks |
|
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
_________________ Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Last edited by johnywhy on Sun 09 Sep 2018, 05:49; edited 1 time in total
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 1943 Location: Japan
|
Posted: Sat 08 Sep 2018, 05:55 Post subject:
Re: Simple Alsa Volume Slider, plus other alsa treats |
|
johnywhy wrote: | Script
Code: | #!/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: | awk: warning: escape sequence `\[' treated as plain `['
awk: warning: escape sequence `\%' treated as plain `%'
awk: fatal: Unmatched [ or [^: /([|%)/ |
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4207 Location: holland
|
Posted: Sat 08 Sep 2018, 06:33 Post subject:
|
|
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
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 1943 Location: Japan
|
Posted: Sat 08 Sep 2018, 06:45 Post subject:
|
|
In Slacko 5.6 awk is symlinked to gawk ( gawk-3.1.8 )
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4207 Location: holland
|
Posted: Sat 08 Sep 2018, 06:51 Post subject:
|
|
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.
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4207 Location: holland
|
Posted: Sat 08 Sep 2018, 07:15 Post subject:
|
|
This should be more portable then, I think, code to get $VolCur by forum member misko_2083
Code: | #!/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: | 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
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
johnywhy

Joined: 20 Aug 2011 Posts: 882
|
Posted: Sat 08 Sep 2018, 07:35 Post subject:
|
|
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
_________________ Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4207 Location: holland
|
Posted: Sat 08 Sep 2018, 07:45 Post subject:
|
|
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: | 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
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 1943 Location: Japan
|
Posted: Sat 08 Sep 2018, 07:53 Post subject:
|
|
This works for me:
Code: | VolCur=$(amixer -M get Master | awk -v FS="[[%]" '/%/ {print $2}') |
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4207 Location: holland
|
Posted: Sat 08 Sep 2018, 07:58 Post subject:
|
|
MochiMoppel wrote: | This works for me:
Code: | VolCur=$(amixer -M get Master | awk -v FS="[[%]" '/%/ {print $2}') |
|
For me too.
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 1943 Location: Japan
|
Posted: Sat 08 Sep 2018, 09:17 Post subject:
|
|
Good.
Just for the record the same with sed.
Code: | VolCur=$(amixer -M get Master | sed -nr 's/.*\[([0-9]+)%.*/\1/p') | I think awk wins the beauty contest.
|
Back to top
|
|
 |
johnywhy

Joined: 20 Aug 2011 Posts: 882
|
Posted: Sun 09 Sep 2018, 05:53 Post subject:
|
|
MochiMoppel wrote: | think awk wins the beauty contest. |
definitely. and prettier than my first try.
i put the new awk into the OP.
THX
_________________ Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
|
Back to top
|
|
 |
greengeek

Joined: 20 Jul 2010 Posts: 5624 Location: Republic of Novo Zelande
|
Posted: Wed 10 Oct 2018, 04:43 Post subject:
Re: Simple Alsa Volume Slider, plus other alsa treats |
|
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)
|
Back to top
|
|
 |
|