WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: nifty volume control for jwm  (Read 32705 times)

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
nifty volume control for jwm
« on: February 20, 2009, 03:52:01 AM »
put these lines in ~/.jwmrc-tray

Code: [Select]
     <TrayButton label="v">exec:/usr/local/bin/vola -down 10</TrayButton>
     <TrayButton label="^">exec:/usr/local/bin/vola -up 10</TrayButton>

i like to put that code before the pager. you don't need the "10" - that's from when i intended to get real numbers from the script and use math, that would take parsing more than tokens.

save this script (you'll need sudo) as /usr/local/bin/vola (this is probably against all tinycore's conventions, the reason for choosing /usr/local/bin is that's where the leafpad tcz puts the symlink to leafpad.) i like to think this betrays what a noob i am at coding scripts, but i'm proud of it, even if i shouldn't be. you may want to change it to suit your own needs. it seems to be reasonably fast. no idea what happens if you're using alsa or alsa-oss, but i've changed the volume using ossmix vol number since the first time i ran youtube in tc.

Code: [Select]
#!/bin/sh
for u in `ossmix vol` ; do
v=$u
done
if [ "$1" == "-up" ]; then
case "$v" in
 "0:0" ) ossmix vol 10 ;;
 "10:10" ) ossmix vol 20 ;;
 "20:20" ) ossmix vol 30 ;;
 "30:30" ) ossmix vol 40 ;;
 "40:40" ) ossmix vol 50 ;;
 "50:50" ) ossmix vol 60 ;;
 "60:60" ) ossmix vol 70 ;;
 "70:70" ) ossmix vol 80 ;;
 "80:80" ) ossmix vol 90 ;;
 "90:90" ) ossmix vol 100 ;;
 "100:100" ) ossmix vol ;;
 * ) ossmix vol 50 ;;
esac
fi
if [ "$1" == "-down" ]; then
case "$v" in
 "0:0" ) ossmix vol ;;
 "10:10" ) ossmix vol 0 ;;
 "20:20" ) ossmix vol 10 ;;
 "30:30" ) ossmix vol 20 ;;
 "40:40" ) ossmix vol 30 ;;
 "50:50" ) ossmix vol 40 ;;
 "60:60" ) ossmix vol 50 ;;
 "70:70" ) ossmix vol 60 ;;
 "80:80" ) ossmix vol 70 ;;
 "90:90" ) ossmix vol 80 ;;
 "100:100" ) ossmix vol 90 ;;
 * ) ossmix vol 50 ;;
esac
fi

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: nifty volume control for jwm
« Reply #1 on: February 20, 2009, 07:49:36 AM »
I don't know anything about ossmix, but it seems like your script could be much more compact.  Perosnally I use a script that calls rexima (not in TC base or extensions...yet).
Code: [Select]
case $1 in
down|dn|-) exec rexima vol - ;;
up|+) exec rexima vol + ;;
esac
Of course this has only  one argument, so it might not be as flexible as you'd need for your purposes...I just have "volume up" and "volume dn" linked to hotkeys.
If ossmix doesn't accept relative settings (+ and -, for example) I guess it wouldn't apply.

Also I guess I could have used rexima directly in the hotkeys, but I opted for a script so it could be applied to multiple window managers and be easily changed in one place if I changed the mixer application.
« Last Edit: February 20, 2009, 07:52:06 AM by mikshaw »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11048
Re: nifty volume control for jwm
« Reply #2 on: February 20, 2009, 07:58:27 AM »
Actually ossmix does accept relative settings, for example "ossmix vol +10"
The only barriers that can stop you are the ones you create yourself.

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
Re: nifty volume control for jwm
« Reply #3 on: February 20, 2009, 02:17:07 PM »
ohhh, yes if ossmix lets you do -10 + 10 you don't need the script at all, just the buttons.

typical! other things worth nothing is that i looked for tcb tips and tricks ("no, not tce!") because it "only" uses jwm, but since there's no sound in tc without an extension, i should have used tce tips. (it was late.) i like using .jwmrc-keys, i should should put ca "u" and ca "d" for ossmix +10, -10 also. or maybe i'll use 5 this time. thanks, as usual to you both.

Offline Onyarian

  • Sr. Member
  • ****
  • Posts: 337
Re: nifty volume control for jwm
« Reply #4 on: February 20, 2009, 03:15:34 PM »
Thanks tobiaus, your trick is very useful.

I don't now if this helps someone but I have made some modifications to this trick because it doesn't work to me, the output of my ossmix is different and it doesn't accept the +10 or -10 form.

First my notebook is an Aspire One. I load at boot OSS.tcem and have in bootlocal.sh the soundon command.
my ossmix command is:
Quote
Selected mixer 0/High Definition Audio ALC268
Known controls are:
jack.int-speaker.mode <mix|input> (currently mix)
jack.int-speaker.mute ON|OFF (currently OFF)
jack.int-speaker.speaker <both/leftvol>[:<rightvol>] (currently 57.9:57.9 dB)
jack.int-speaker.speaker-mute ON|OFF (currently OFF)
jack.green.mode <mix|input> (currently mix)
jack.green.mute ON|OFF (currently OFF)
jack.green.headphone <both/leftvol>[:<rightvol>] (currently 57.9:57.9 dB)
jack.green.mute.headphone ON|OFF (currently OFF)
jack.green.mute.speaker ON|OFF (currently OFF)
jack.pink.mode <speaker|input> (currently speaker)
jack.pink <both/leftvol>[:<rightvol>] (currently 39.9:39.9 dB)
jack.pink.mute ON|OFF (currently OFF)
record.select.select1 <both/leftvol>[:<rightvol>] (currently 43.4:43.4 dB)
record.select.select2 <both/leftvol>[:<rightvol>] (currently 43.4:43.4 dB)
record.select.select3 <speaker|dmic> (currently dmic)
vmix0-channels <Stereo|Multich> (currently Stereo)
vmix0-src <Fast|Low|Medium|High|High+|Production|OFF> (currently Fast)
vmix0-vol <monovol> (currently 25.0 dB)
vmix0-out1 <leftVU>:<rightVU>] (currently 105:104)
vmix0-in <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm4 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out2 <leftVU>:<rightVU>] (currently 112:111)
vmix0-out.pcm5 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out3 <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm6 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out4 <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm7 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out5 <leftVU>:<rightVU>] (currently 0:0)
so the sound goes from 0 to 25, and not from 0 to 100

the .jwmrc-tray:
Quote
     <TrayButton label="v">exec:/usr/local/bin/vola -down</TrayButton>
     <TrayButton label="^">exec:/usr/local/bin/vola -up</TrayButton>

the output to ossmix  vmix0-vol:
Quote
tc@box:~$ ossmix vmix0-vol
Value of mixer control vmix0-vol is currently set to 25.0 (dB)

and the vola with this modification:
Quote
#!/bin/sh
u=`ossmix vmix0-vol`
#for u in `ossmix vmix0-vol` ; do
v=$u
#done
if [ "$1" == "-up" ]; then
case "$v" in
 "Value of mixer control vmix0-vol is currently set to 0.0 (dB)" ) ossmix vmix0-vol 5 ;;
 "Value of mixer control vmix0-vol is currently set to 5.0 (dB)" ) ossmix vmix0-vol 10 ;;
 "Value of mixer control vmix0-vol is currently set to 10.0 (dB)" ) ossmix vmix0-vol 15 ;;
 "Value of mixer control vmix0-vol is currently set to 15.0 (dB)" ) ossmix vmix0-vol 20 ;;
 "Value of mixer control vmix0-vol is currently set to 20.0 (dB)" ) ossmix vmix0-vol 25 ;;
 "Value of mixer control vmix0-vol is currently set to 25.0 (dB)" ) ossmix vmix0-vol  ;;
esac
fi
if [ "$1" == "-down" ]; then
case "$v" in
 "Value of mixer control vmix0-vol is currently set to 0.0 (dB)" ) ossmix vmix0-vol ;;
 "Value of mixer control vmix0-vol is currently set to 5.0 (dB)" ) ossmix vmix0-vol 0 ;;
 "Value of mixer control vmix0-vol is currently set to 10.0 (dB)" ) ossmix vmix0-vol 5 ;;
 "Value of mixer control vmix0-vol is currently set to 15.0 (dB)" ) ossmix vmix0-vol 10 ;;
 "Value of mixer control vmix0-vol is currently set to 20.0 (dB)" ) ossmix vmix0-vol 15 ;;
 "Value of mixer control vmix0-vol is currently set to 25.0 (dB)" ) ossmix vmix0-vol 20 ;;
esac
fi

This is the only form that works correctly for me.
Perhaps the next that I will do is to divide vola in more fraccions as from 5 to 5

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: nifty volume control for jwm
« Reply #5 on: February 20, 2009, 05:09:21 PM »
Any way to use the same .jwmrc button with separate commands for right and left mouse clicks?
(I'd like to save a button for turning my mike on and off).  Thanks

Edit:  You could also issue different volume controls for right /vs left mouse click
« Last Edit: February 20, 2009, 05:11:32 PM by jpeters »

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
Re: nifty volume control for jwm
« Reply #6 on: February 20, 2009, 08:14:55 PM »
very interesting onyarian, i wonder if ossmix has been updated... no, i just downloaded it from apps browser yesterday. i'm glad you found a way to use it though!

jpeters: i've never heard of getting jwm to distinguish left/right mouse from the tray, that would be cool. originally i thought of making the buttons more narrow, using 8x16 or fewer pixel icons instead of text, i was happy with the two buttons though. you could easily make it go up to 100 and then cycle back to 0 if you wanted to use only one button that way.


Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: nifty volume control for jwm
« Reply #7 on: February 20, 2009, 08:53:58 PM »
A modification of the above, mainly done as a distraction from my own current puzzles.
The result should be the same.
Code: [Select]
u=`ossmix vmix0-vol`
#v=`echo $u | sed 's/.*\([0-9]\{1,3\}\)\.0.*/\1/'` # can't get the regex right
v=`echo $u | awk '{print $10}'|cut -d. -f1` #grab just the value
max=25 #maximum level
step=5

case "$1" in
"-up")
  case "$v" in
   $max) a="" ;;
      *) let a=$v+$step ;;
  esac ;;
"-down")
  case "$v" in
      0) a="" ;;
      *) let a=$v-$step ;;
  esac ;;
esac

ossmix vmix0-vol $a
I had originally tried to use a single sed command to extract the current level, but I can't seem to get the regular expression right to work for both 25 and 5

This assumes that the decimal is always a single digit (it cuts it off)...it'll break otherwise.  EDIT: I don't think that's true anymore.
It also assumes that step will be set at a number that is evenly divisible into max.  I haven't tested what will happen otherwise.
« Last Edit: February 21, 2009, 08:25:12 AM by mikshaw »

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: nifty volume control for jwm
« Reply #8 on: February 20, 2009, 09:13:52 PM »
Careful....this script could get flagged as an attempt to print $10 bills.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: nifty volume control for jwm
« Reply #9 on: February 20, 2009, 10:13:58 PM »
=o)

Also the first two lines could easily be condensed into a single line to save a process.  I was originally testing it with a "Value of mixer control..." string and never thougt to combine them afterwards.
Code: [Select]
v=`ossmix vmix0-vol | awk '{print $10}'|cut -d. -f1`

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: nifty volume control for jwm
« Reply #10 on: February 21, 2009, 12:35:08 AM »
Very nice!!    At first I missed the delimiter  (.) (dirty, high resolution screen)....
Thanks.    Keep 'em coming!     

Offline Onyarian

  • Sr. Member
  • ****
  • Posts: 337
Re: nifty volume control for jwm
« Reply #11 on: February 21, 2009, 06:14:03 AM »
Great, mikshaw!

Your code works perfectly and is much more polished than mine, I'm just an apprentice.

I replaced step=5 with step=1 to have 25 sound levels.  :D
« Last Edit: February 21, 2009, 06:19:47 AM by Onyarian »

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
Re: nifty volume control for jwm
« Reply #12 on: February 21, 2009, 06:37:25 AM »
on the matter of making this an extension, mikshaw, i wonder if the following is possible: 1. a simple method of making this work using either ossmix, or something also-oss compatible (for skype users) or rexima... possibly it could detect rexima, then look for the also-oss compatible option, then choose ossmix if it does not find the others. the findings could then export to a variable or .rc file to keep the detection from slowing down the script? (my version of it is very fast.)

i mention this because i think your version is probably flexible enough to be used across three controls, this is a guess. then if this is possible, the other question would be your opinion on the best way to add two lines to the middle of .jwmrc-tray. i can write a script to do that, but it would be uglier than the script i started this thread with, plus i wouldn't dare writing an extension that touched part of .jwmrc's config... not when i've received such strong feedback about how thinking out loud on the forum might destroy .wbar's.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11048
Re: nifty volume control for jwm
« Reply #13 on: February 21, 2009, 08:01:04 AM »
Oops, sorry guys, the man pages online had already been updated to 4.1 :p
Relative levels will work when the OSS extension gets updated.
The only barriers that can stop you are the ones you create yourself.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: nifty volume control for jwm
« Reply #14 on: February 21, 2009, 08:37:13 AM »
tobiaus: It could be modified easily enough to work for multiple mixers, but I don't know if that's ideal.  I assume it doesn't even work with the version of ossmix that you use, which would be a reasonable thing to expect.

The output of various commands tends to be unique with the possible exception of application clones or forks, and this script relies on a specific output format.  Adding code for other mixers is likely to make that single script larger than the combined size of multiple single-mixer scripts, and use more resources than a single-mixer script.

I'm not saying it wouldn't work, but I'm not sure it would work well enough to be worthwhile.  wwwoowwwoooooo