Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 14 Nov 2018, 17:27
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Simple Alsa Volume Slider, plus other alsa treats
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [15 Posts]  
Author Message
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: 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
Code:
# alsamixer





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
View user's profile Send private message 
mikeslr


Joined: 16 Jun 2008
Posts: 2773
Location: 500 seconds from Sol

PostPosted: 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. Very Happy I see you're already beginning to find your own projects to improve them. Laughing

mikesLr
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: 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 Cool

_________________
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
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1677
Location: Japan

PostPosted: 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
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: 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
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1677
Location: Japan

PostPosted: Sat 08 Sep 2018, 06:45    Post subject:  

In Slacko 5.6 awk is symlinked to gawk ( gawk-3.1.8 )
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: 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
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: 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
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: 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
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: 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
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1677
Location: Japan

PostPosted: 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
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: 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
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1677
Location: Japan

PostPosted: 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
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 872

PostPosted: 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
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5275
Location: Republic of Novo Zelande

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [15 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1280s ][ Queries: 12 (0.0338s) ][ GZIP on ]