Simple Alsa Volume Slider, plus other alsa treats

Window managers, icon programs, widgets, etc.
Post Reply
Message
Author
User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

Simple Alsa Volume Slider, plus other alsa treats

#1 Post 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
Last edited by johnywhy on Tue 11 Sep 2018, 05:34, edited 6 times in total.
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
mikeslr
Posts: 3890
Joined: Mon 16 Jun 2008, 21:20
Location: 500 seconds from Sol

Thanks

#2 Post 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

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

Re: Thanks

#3 Post 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)
Last edited by johnywhy on Sun 09 Sep 2018, 09:49, edited 1 time in total.
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Simple Alsa Volume Slider, plus other alsa treats

#4 Post 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 [^: /([|%)/

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#5 Post 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

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#6 Post by MochiMoppel »

In Slacko 5.6 awk is symlinked to gawk ( gawk-3.1.8 )

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#7 Post 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.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#8 Post 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

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#9 Post 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
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#10 Post 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

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#11 Post by MochiMoppel »

This works for me:

Code: Select all

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

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#12 Post by fredx181 »

MochiMoppel wrote:This works for me:

Code: Select all

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

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#13 Post 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.

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#14 Post 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
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

Re: Simple Alsa Volume Slider, plus other alsa treats

#15 Post 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)

Post Reply