Tiny Core Linux

Tiny Core Extensions => TCE Tips & Tricks => Topic started by: tobiaus on February 20, 2009, 12:52:01 AM

Title: nifty volume control for jwm
Post by: tobiaus on February 20, 2009, 12: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
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 20, 2009, 04: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.
Title: Re: nifty volume control for jwm
Post by: curaga on February 20, 2009, 04:58:27 AM
Actually ossmix does accept relative settings, for example "ossmix vol +10"
Title: Re: nifty volume control for jwm
Post by: tobiaus on February 20, 2009, 11:17:07 AM
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.
Title: Re: nifty volume control for jwm
Post by: Onyarian on February 20, 2009, 12: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
Title: Re: nifty volume control for jwm
Post by: jpeters on February 20, 2009, 02: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
Title: Re: nifty volume control for jwm
Post by: tobiaus on February 20, 2009, 05: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.

Title: Re: nifty volume control for jwm
Post by: mikshaw on February 20, 2009, 05: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.
Title: Re: nifty volume control for jwm
Post by: jpeters on February 20, 2009, 06:13:52 PM
Careful....this script could get flagged as an attempt to print $10 bills.
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 20, 2009, 07: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`
Title: Re: nifty volume control for jwm
Post by: jpeters on February 20, 2009, 09:35:08 PM
Very nice!!    At first I missed the delimiter  (.) (dirty, high resolution screen)....
Thanks.    Keep 'em coming!     
Title: Re: nifty volume control for jwm
Post by: Onyarian on February 21, 2009, 03: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
Title: Re: nifty volume control for jwm
Post by: tobiaus on February 21, 2009, 03: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.
Title: Re: nifty volume control for jwm
Post by: curaga on February 21, 2009, 05: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.
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 21, 2009, 05: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
Title: Re: nifty volume control for jwm
Post by: jpeters on February 21, 2009, 07:57:11 AM
...there's always sGmixer or some equivalent, if someone needs it.   Volume controls exist on most apps (including flash player). Adding a mike on/off button in .jwmrc-tray is useful when using skype.
Title: Re: nifty volume control for jwm
Post by: tobiaus on February 21, 2009, 09:06:52 AM
curaga: no worries, any old version of ossmix (or new version) should be fine. if the ones in tc do relative positions, less code is needed, if not, the script is more useful :)

mikshaw: no worries, you're probably right, but i thought i'd mention it. jpeters: flash apps yes, and xmms as well, but i've often found the want to change the volume before they start to make noise, particularly with online applets and youtube. also i often find i've turned ossmix down to 0 and the applet volume controls will only work from 0 times 0 to 100 times 0 then. my favorite volume control is the applet in xfce, it's always easy to reach quickly- the closest thing to it in any smaller distro is probably the murgalua dock app in flux-oriented versions of dsl. (but i prefer jwm.)
Title: Re: nifty volume control for jwm
Post by: jpeters on February 21, 2009, 10:02:42 AM
0 times 0 to 100 times 0 then.....

sounds a  bit like my retirement holdings...I wonder if there's a control for that....
Title: Re: nifty volume control for jwm
Post by: curaga on February 21, 2009, 10:56:35 AM
I've recently tried to create a native fltk/jwm dockapp for controlling a single channel.
It defaults to vmix0-vol, but can be used with any channel (I needed misc.front1).

Only works with OSS4, the binary is 28kb, and no external dependencies.
Once it gets good enough, it'll be added to the OSS extension.

TC binary preview:
http://www.ziddu.com/download/3594698/tc-mixer.gz.html

Comments please :)

edit: screenshot in action
(http://i42.tinypic.com/24pduds.png)

Right-click or middle-click to mute
Title: Re: nifty volume control for jwm
Post by: jpeters on February 21, 2009, 11:28:11 AM
Works nicely.  I'm curious how you get it on the tray...I don't see anything in .jwmrc-tray. Is there any way to get right-click options, say for mic vol?

edit: I see you DO have right-click features. Could I see the source code for how you do this? Thanks.
edit2  oh....loads to the dock automatically from the  program......I'll try something with tcl-tk......

edit: maybe there's no need for separate menu entries for OSS/sound on-off ?
Title: Re: nifty volume control for jwm
Post by: curaga on February 21, 2009, 02:54:03 PM
Source will be posted when I consider this ready :)

Yes, it uses the freedesktop-compliant dock of Jwm. The spec is here:
http://standards.freedesktop.org/systemtray-spec/systemtray-spec-latest.html

Menu entries - what do you mean? Soundon could also be started as an extension install script, but the menu entry would still be nice if one disables sound and wants to re-enable.

Edit: you can start two instances if you need one to control the mic vol. Not as clean as a right-click to change channels, but it works.
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 21, 2009, 04:59:07 PM
Volume controls within applications are often inconvenient.  I like to have a fairly even volume level from one application to the next, and using an application's volume control can end up making more work.  For example, xmms volume control changes the system volume rather than the volume for the application.  If i then load an app that has a lower volume I have to manually turn it up.  It ends up being similar to the crappy levels you experience with television...when the commercials come on you often have to turn down the volume because they're recorded at higher levels than the shows.

A few applications don't allow me to use my centralized volume via hotkey, though.  For example, UT (and I suspect a great many other games, though I don't have the experience to say for sure) prevents me from using my window manager's hotkeys, so if it's too loud or quiet I'm forced to do a number of clicks to access the in-game volume control.  That's annoying, so instead I start the game with a wrapper that sets the system volume to a compatible level before starting the game, and it works out fine.
Title: Re: nifty volume control for jwm
Post by: jpeters on February 21, 2009, 05:04:17 PM
Source will be posted when I consider this ready :)

Yes, it uses the freedesktop-compliant dock of Jwm. The spec is here:
http://standards.freedesktop.org/systemtray-spec/systemtray-spec-latest.html

The specs look  like visual  c++ stuff. I'll await your code to see how it works with  jwm.  

Quote
Menu entries - what do you mean? Soundon could also be started as an extension install script, but the menu entry would still be nice if one disables sound and wants to re-enable.

I was thinking having to turn the  sound on unusual, and with the icon it's simple to mute. Maybe there's some other reason needing to turn it on and off from the menu?  I load OSS (soundon) with my skype script on boot and leave it on.  

edit.  a drop down mixer might be a consideration also, instead of just volume.
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 21, 2009, 05:18:17 PM
Not that it matters, but I like to hear myself type.....
I'm not sure why turning OSS on and off is a desired feature, apart from the possibility that it crashes, which I've never seen in any distro I've ever used.
Personally I put this in bootlocal.sh, and it suits me just fine:
Code: [Select]
if [ -x /usr/sbin/soundon ]; then
/usr/sbin/soundon
fi
Title: Re: nifty volume control for jwm
Post by: curaga on February 22, 2009, 08:13:11 AM
So guys, with improvements the 0.5 version is ready.
There is one bug I know of - the first click might open the volume slider under a window. I'm starting to think this is a Jwm bug, since I'm sure I ask to be above correctly, and all tries after the first come up above windows right like they should. This means it's ready on my part; source shall be posted :p (source? you can't handle the source!)

Improvements from previous version:
- True options parsing
- Transparent background for the volume slider window
- Tooltip shows current level
- Right-click menu
- Multiple sound cards support

TC binary:
http://www.ziddu.com/download/3603351/tc-mixer.gz.html

Sources:
http://www.ziddu.com/download/3603304/tc-mixer-0.5.tgz.html
Title: Re: nifty volume control for jwm
Post by: jpeters on February 22, 2009, 04:59:14 PM
So guys, with improvements the 0.5 version is ready.
There is one bug I know of - the first click might open the volume slider under a window

I was worried some pixels went out on my screen when I got a black box....later I found a copy of the mixer icon next to it. This happens if you reload windows manager.

Don't loose sleep over this....but I've got the slider at 88% right now and XMMS playing, with tc-mixer offering the option to "UNMUTE"....the toggle is pretty easy to outsmart.  (edit: IMHO the first version without the balloon message....just fade when muted....is far superior....)

I really liked the simple right-click mute function on the former version. I can't think of why I need to exit the mixer enough to have to read and click every time I want a simple mute. (how about an options menu to choose colors for the icon?......NOT!..)

edit: maybe unconventional...but you could keep the neat right click mute on/off feature by putting the exit option under the slider.....no time lost, since you have to click on it anyway...  I like that feature enough to keep the older version...

Thanks for the source....basic C++ stuff. 

Edit:  oops...the icon moved off the dock, I guess when I changed windows.  It's sitting about 2 inches off the left corner of the screen.  I have the "MOI" version running...

Edit2:  I have a strong hunch there's some conflicts....I've had several freeze-ups related to sound since loading tc-mixer; last was when I clicked on the play button for xmms.  I rarely see a freeze on this system. 

Title: Re: nifty volume control for jwm
Post by: curaga on February 23, 2009, 12:58:52 AM
Heh, I know I should've disabled the slider when muted ;)
The middle-click mute still works like it did in 0.4, now just right-click has been reassigned.

Sound freezes.. hmm, I didn't see any when testing, but I'll see what I can do.
Title: Re: nifty volume control for jwm
Post by: jls on February 23, 2009, 01:54:27 AM
if I execute this command:
tc-mixer -channel vol

I got

Using channel vol
Not a valid channel name: vol

this is my ossmix output

tc@box:~$ ossmix
Selected mixer 0/AC97 Mixer (STAC9721)
Known controls are:
vol <both/leftvol>[:<rightvol>] (currently 75:75)
vol.rec ON|OFF (currently OFF)
pcm <both/leftvol>[:<rightvol>] (currently 75:75)
speaker <monovol> (currently 0)
line <both/leftvol>[:<rightvol>] (currently 32:32)
line.rec ON|OFF (currently OFF)
mic <monovol> (currently 0)
mic.rec ON|OFF (currently ON)
cd <both/leftvol>[:<rightvol>] (currently 75:75)
cd.rec ON|OFF (currently OFF)
igain <both/leftvol>[:<rightvol>] (currently 75:75)
aux1 <both/leftvol>[:<rightvol>] (currently 32:32)
aux1.rec ON|OFF (currently OFF)
phone <both/leftvol>[:<rightvol>] (currently 0:0)
phone.rec ON|OFF (currently OFF)
mono <monovol> (currently 75)
mono.rec ON|OFF (currently OFF)
video <both/leftvol>[:<rightvol>] (currently 0:0)
video.rec ON|OFF (currently OFF)
depth <monovol> (currently 0)
mixext.spkmode <FRONT|SPREAD> (currently SPREAD)
mixext.dualdac ON|OFF (currently ON)
vmix0-src <Fast|Low|Medium|High|High+|Production|OFF> (currently Fast)
vmix0-vol <monovol> (currently 25.0 dB)
vmix0-out1 <leftVU>:<rightVU>] (currently 126:126)
vmix0-in <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm1 <both/leftvol>[:<rightvol>] (currently 22.0:22.0 dB)
vmix0-out2 <leftVU>:<rightVU>] (currently 126:126)
vmix0-out.pcm2 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out3 <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm3 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out4 <leftVU>:<rightVU>] (currently 0:0)
vmix0-out.pcm4 <both/leftvol>[:<rightvol>] (currently 25.0:25.0 dB)
vmix0-out5 <leftVU>:<rightVU>] (currently 0:0)

If I do
tc-mixer -channel vmix0-out.pcm1
it works :'(
Title: Re: nifty volume control for jwm
Post by: curaga on February 23, 2009, 02:13:54 AM
@jls: please post the output of
Quote
ossmix -D | grep vol

Meanwhile, there's a new version :)

Changes:
*       Hopefully fixed sound freezes
*       Mute more intelligent
*       Re-dock switch for Jwm restarts

http://www.ziddu.com/download/3611784/tc-mixer.gz.html
http://rapidshare.de/files/45565682/tc-mixer-0.6.tgz.html
Title: Re: nifty volume control for jwm
Post by: jls on February 23, 2009, 03:02:48 AM
now it works just launching tc-mixer ;)
Title: Re: nifty volume control for jwm
Post by: jpeters on February 23, 2009, 03:10:29 AM
..a redocking menu..very unique. It still may be conflicting with the XMMS volume controls. If I slide them around, I can get the dropdown menu to stop working.  
Title: Re: nifty volume control for jwm
Post by: curaga on February 23, 2009, 03:54:25 AM
Did that get rid of the freezes?
Title: Re: nifty volume control for jwm
Post by: jls on February 23, 2009, 05:04:34 AM
I placed this line n /home/tc/.jwmrc:
<StartupCommand>tc-mixer</StartupCommand>
just above the line:
</JWM>
but the volume control doesn't start.
If I exit from X and type
startx
the the volume control appears

edit: actually the volume appears, but out of the tray. Sorry for the mistake
Title: Re: nifty volume control for jwm
Post by: curaga on February 23, 2009, 07:24:30 AM
Jwm needs to be started first, tc-mixer needs a delay before starting.

For example put this as /usr/bin/mixer.sh:
Quote
#!/bin/sh
sleep 1
exec tc-mixer
And then start this script from .jwmrc
Title: Re: nifty volume control for jwm
Post by: jpeters on February 23, 2009, 08:14:19 AM
Did that get rid of the freezes?

don't think so.  I put the computer on suspend, got some sleep myself, and this morning tried to load XMMS  with tc-mixer already in the tray......froze.  I don't recall many freezes prior to playing with tc-mixer. 

Title: Re: nifty volume control for jwm
Post by: curaga on February 23, 2009, 12:36:46 PM
Hmm.. Before the latest changes I had the mixer device always open. Then I changed it to only open when needed. Just now I took a look at several Window Maker dockapps, and they do it similarly, only when needed. I'm out of clues now as to what could cause a freeze; certainly didn't get any when playing in XMMS and changing the volume with both just after another. If you have any hints, please shout :)
Title: Re: nifty volume control for jwm
Post by: jpeters on February 23, 2009, 01:01:13 PM
I'll see if I can get any freezes without tc-mixer loaded, just to make sure. This brings back windoz memories,and why I like tiny.  I have mikshaw's script loaded to my keys...a few lines of code...fast, clean, no conflicts.  A simple slider in Borland, visual C++, etc., involves all these support files, messages back and forth to the windows manager, etc, etc.  Suddenly things stop working, and it's hard to figure out where the problem is. 

Edit: this line of thinking must be correct, because suddenly I became a "full member".  BTW, I've got multiple sound apps going simulateoulsy, while abusing the volume controls & the script control (while copying a score w/ lilypond)....but can't get it to freeze without tc-mixer loaded. 
Title: Re: nifty volume control for jwm
Post by: jls on February 23, 2009, 03:20:42 PM
I made /usr/bin/mixer.sh:
#!/bin/sh
sleep 1
exec tc-mixer

but it's not working, then when I install a new tce the volume goes out of the jwm tray
Title: Re: nifty volume control for jwm
Post by: mikshaw on February 23, 2009, 04:51:09 PM
Quote from: jpeters
this line of thinking must be correct, because suddenly I became a "full member".
You should know that member status as shown on the forums is most likely automatically set according to the number of posts you've made (currently 100, which is a common milestone).  While this can be a useful feature in separating people with true interest from those who are just spammers, it doesn't actually reflect your worth.  I'm guessing you should be aware that your participation and contribution here and previously on DSL is enough to let you know your worth.

Then again, if you were jest joking, well, then...roffle.
=o)
Title: Re: nifty volume control for jwm
Post by: jpeters on February 23, 2009, 06:18:49 PM
Quote from: jpeters
this line of thinking must be correct, because suddenly I became a "full member".
You should know that member status as shown on the forums is most likely automatically set according to the number of posts you've made (currently 100, which is a common milestone).  While this can be a useful feature in separating people with true interest from those who are just spammers, it doesn't actually reflect your worth.  I'm guessing you should be aware that your participation and contribution here and previously on DSL is enough to let you know your worth.

Then again, if you were jest joking, well, then...roffle.
=o)

duhh.......

Edit: I don't use a lot of smiley faces; assuming (rightly  or wrongly) that anyone smart enough to be on this board would immediately know something like the above.....
Title: Re: nifty volume control for jwm
Post by: softwaregurl on May 04, 2009, 09:38:54 AM
I was following this topic but just recently had the time to do my own version.
I hacked watcher again (thanks Curaga) so it reads /tmp/watcher2msg and displays the contents of that file instead if its not empty.  any app should be able to take advantage of this. I also renamed to watcher2 and put it in /usr/local/bin.
Code: [Select]
echo "testing" >/tmp/watcher2msgdisplays "testing" instead of the normal watcher stuff
Code: [Select]
echo "" >/tmp/watcher2msgclears that and goes back to the normal watcher stuff.
Watch out for the bug in this, if /tmp/watcher2msg does not exist there will be many error messages to stderr.
Code: [Select]
// Copyright 2008 Curaga
// A small app to be swallowed into JWM tray, to show cpu,mem,swap usage
// What do you know, mixing C with fltk C++ works just fine

// Licensed under the GPLv2, as scanf did not work for me, so
// I benefited from Open Source and copied the fgets block from
// wmbluemem :)
// Thank You Mihai Dr\ufffdghicioiu

// Changes from Softwaregurl:
// Moved letters after the values with percentages
// Gigabytes for swap and mem
// May 2009
// Reads a file and displays instead if not empty

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/filename.H>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char version[4]="1.5";

float timeout=1.5,mem=0,swap=0,cpu=0,used=0,oldused=0,cputotal=0,oldcputotal=0;
int arg_i=0, fontsize=10, mib=0;
char memind[2]="m",swapind[2]="m",newmsg[25];
FILE *meminfo,*cpuinfo,*msg;

void checkup(){
 unsigned long memtotal,memfree,buffers,cache,swaptotal,swapfree;
 unsigned long user,nice,sys,idle,iowait,irq,softirq,virt,virt2;
 char buf[60],buf2[190];
 char *p;
 int i;

  if((meminfo=fopen("/proc/meminfo","r"))==NULL){
    fprintf(stderr,"Error opening meminfo");
    exit(1);
  }
  if((cpuinfo=fopen("/proc/stat","r"))==NULL){
    fprintf(stderr,"Error opening stat");
    exit(1);
  }
  if((msg=fopen("/tmp/watcher2msg","r"))==NULL){
    fprintf(stderr,"Error opening msg");
  } else {
 fgets(newmsg, 25, msg);
 fclose(msg);
  }


 fgets(buf, 60, meminfo); strtok(buf, " "); p = strtok(NULL, " ");
 memtotal = strtol(p, NULL, 10);
 fgets(buf, 60, meminfo); strtok(buf, " "); p = strtok(NULL, " ");
 memfree = strtol(p, NULL, 10);
 fgets(buf, 60, meminfo); strtok(buf, " "); p = strtok(NULL, " ");
 buffers = strtol(p, NULL, 10);
 fgets(buf, 60, meminfo); strtok(buf, " "); p = strtok(NULL, " ");
 cache = strtol(p, NULL, 10);
 for(i = 1; i < 11; i++){
   fgets(buf, 60, meminfo);
   p=strtok(buf, " ");
   if(strcmp("SwapTotal:",p)==0) break;
 }
 p = strtok(NULL, " ");
 swaptotal = strtol(p, NULL, 10);
 fgets(buf, 60, meminfo); strtok(buf, " "); p = strtok(NULL, " ");
 swapfree = strtol(p, NULL, 10);
 fclose(meminfo);

 fgets(buf2,190,cpuinfo); strtok(buf2, " ");
 p=strtok(NULL, " "); user=strtol(p, NULL, 10);
 p=strtok(NULL, " "); nice=strtol(p, NULL, 10);
 p=strtok(NULL, " "); sys=strtol(p, NULL, 10);
 p=strtok(NULL, " "); idle=strtol(p, NULL, 10);
 p=strtok(NULL, " "); iowait=strtol(p, NULL, 10);
 p=strtok(NULL, " "); irq=strtol(p, NULL, 10);
 p=strtok(NULL, " "); softirq=strtol(p, NULL,10);
 p=strtok(NULL, " "); virt=strtol(p, NULL, 10);
 p=strtok(NULL, " "); virt2=strtol(p, NULL, 10);
 fclose(cpuinfo);

 used=(float)(user+nice+sys+irq+softirq+virt+virt2);
 cputotal=used+(float)idle+(float)iowait;

 cpu=((used-oldused)/(cputotal-oldcputotal))*(float)100;

 if(mib==1){
 mem=(float)(memtotal-(memfree+buffers+cache))/(float)1024;
 swap=(float)(swaptotal-swapfree)/(float)1024;
 }
 if(mib==2){
 mem=(float)(memfree+buffers+cache)/(float)1024;
 swap=(float)swapfree/(float)1024;
 }
 if(mib==0){
 mem=((float)(memtotal-(memfree+buffers+cache))/ (float) memtotal)*(float)100;
 swap=((float)(swaptotal-swapfree)/(float)swaptotal)*(float)100;
 }

 oldused=used;
 oldcputotal=cputotal;

 if(mem>999.9){
  mem=mem/1024;
  strcpy(memind,"g");
 }
 if(swap>999.9){
  swap=swap/1024;
  strcpy(swapind,"g");
 }
 if(swaptotal==0){
  swap=0;
 }
}

void tick(void* v){
 checkup();
 Fl_Box* box=(Fl_Box*)v;
 char yeah[25]="";
 if(mib) sprintf(yeah,"C%.1f%% M%.1f%s  S%.1f%s",cpu,mem,memind,swap,swapind);
 else sprintf(yeah,"%.1f%%C  %.1f%%M  %.1f%%S",cpu,mem,swap);
 if ( strlen (newmsg) > 1) box->copy_label(newmsg);
 else box->copy_label(yeah);
 Fl::repeat_timeout(timeout,tick,box);
}

int parser(int argc, char **argv, int &z){
 if(strcmp(argv[z], "-h")==0){
  printf("Watcher %s\n" \
  "(C) Curaga 2008\n" \
  "Fixes from softwaregurl\n\n" \
  "Switches: \n" \
  "\t-bg <color> background color \n" \
  "\t-fg <color> text color\n" \
  "\t-m show used MiB instead of percent on mem/swap\n" \
  "\t-r show remaining MiB instead of percent on mem/swap\n" \
  "\t-s <float> check every s secs, default %.2f\n" \
  "\t-f <size> use font size f (default %d)\n" \
  "The color can be either named (green) or rgb ('#00ff00')\n",version,
  timeout,fontsize);
  exit(0);
 }

 if(strcmp(argv[z], "-s")==0){
  timeout=strtof(argv[(z+1)],NULL);
  z+=2;
  return 1;
 }

 if(strcmp(argv[z], "-f")==0){
  fontsize=atoi(argv[(z+1)]);
  z+=2;
  return 1;
 }

 if(strcmp(argv[z], "-m")==0){
  mib=1;
  z++;
  return 1;
 }

 if(strcmp(argv[z], "-r")==0){
  mib=2;
  z++;
  return 1;
 }

 return 0;
}

int main(int argc, char **argv) {

  // Graphic stuff
  Fl_Window *window = new Fl_Window(124,18);
  Fl::args(argc,argv,arg_i,&parser);
  Fl_Box *box = new Fl_Box(FL_NO_BOX,0,0,124,18,"Starting...");
  box->labelsize(fontsize);
  window->end();
  window->show(argc, argv);

  Fl::add_timeout(timeout,tick,box);
  return Fl::run();
}
then this is what I wrote
Code: [Select]
#!/usr/bin/perl
#   adjvolume.pl adjusts volume by reading from a fifo
#   Copyright 2009 Softwaregurl
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA


#### set volume up-down commands $$$$
# ????? (yes, five question marks) indicates where to insert the channel name/number.
$cmds{'vup'}="amixer set ????? 2%+";
$cmds{'vdn'}="amixer set ????? 2%-";
#### set controls display & names/numbers $$$$
# list of control names to display
@cnmd = ('Master',
'PCM',
'Line In'
);
# list of control names/numbers corresponding to above
@ctnn = ('Master',
'PCM',
'Line'
);

print "commands\n";
sub adjvolume {
$syscmd="$cmds{$cmd} >/dev/null";
$syscmd=~ s|\?\?\?\?\?|$ctnn[$ctlnn]|g;
$err = system ("$syscmd >/tmp/adjvolumedata");
if ($err) { print "$err bad volume command $syscmd\n";}
undef ($err);
&rdadjvolumedata;
&printout;
}
sub rdadjvolumedata {
open (vol1, "/tmp/adjvolumedata") || &error0recover;
@adjvolumedata0=<vol1>;
close (vol1);
$adjvolumedata1=@adjvolumedata0;
$adjvolumedata1--;
$adjvolumedata2="$adjvolumedata0[$adjvolumedata1]";
chomp ($adjvolumedata2);
$adjvolumedata2 =~ s/[^0-9]+/ /g;
chop ($adjvolumedata2);
$adjvolumedata2 = "$adjvolumedata2\%";

$adjvolumedata1--;
$adjvolumedata3="$adjvolumedata0[$adjvolumedata1]";
chomp ($adjvolumedata3);
$adjvolumedata3 =~ s/[^0-9]+/ /g;
$adjvolumedata3 = "$adjvolumedata2";
$adjvolumedata2="$adjvolumedata2 $adjvolumedata3";

}
sub changec {
$ctlnn++;
if ($ctlnn >= $ncnmd) { $ctlnn=0;}
&printout;
}

sub proccmd {
if ($cmd eq "vup" || $cmd eq "vdn") { &adjvolume;}
if ($cmd eq "cdn") { &changec;}
}

sub printout {
print "$cnmd[$ctlnn], $adjvolumedata2\n";
$tmp0="echo \"$cnmd[$ctlnn], $adjvolumedata2\" >/tmp/watcher2msg";
system ($tmp0);
}

sub error0recover {
exit;
}

sub rddata {
for ($j=0;$j<9;$j=1) {
$cmd=<vol0>;
chomp ($cmd);
&proccmd;
if ($cmd eq "" ) {
                  sleep 2;
                 $nulltime++;
                 if ($nulltime > 4) {
                     $tmp0="echo \"\" >/tmp/watcher2msg";
                     system ($tmp0);
                     $nulltime=0;
                     }
                 }
}
}
$ncnmd=@cnmd;
open (vol0, "/tmp/adjvolumefifo") || &error0recover;
&rddata;
print "exiting\n";
exit;
it reads commands from /tmp/adjvolumefifo and sends output to /tmp/watcher2msg then clears it about 10 seconds later as well as writing to the terminal.  anything can send commands to it via the fifo.
and this is my .jwmrc-tray
Code: [Select]
<JWM>
   <!-- Additional tray attributes: autohide, width, border, layer, layout -->
   <Tray  x="0" y="0" height="20">

     <!-- Additional TaskList attribute: maxwidth -->
     <TaskList/>

     <!-- Additional TrayButton attribute: label -->
     <TrayButton label="_">showdesktop</TrayButton>

    <TrayButton label="^">exec:echo "vup" >>/tmp/adjvolumefifo </TrayButton>
    <TrayButton label="v">exec:echo "vdn" >>/tmp/adjvolumefifo </TrayButton>
   
    <TrayButton label="C">exec:echo "cdn" >>/tmp/adjvolumefifo </TrayButton>
    <TrayButton label="S">exec:echo "sel" >>/tmp/adjvolumefifo </TrayButton>

      <!-- Additional Pager attributes; width, height -->
      <Pager/>
      <!-- Additional Swallow attribute: height -->

      <Swallow name="watcher2" width="0"> watcher2 </Swallow>

      <Clock format="%a %d %b %k:%M"></Clock>

      <Dock/>

     <TrayButton label="X">exec:exittc</TrayButton>
   </Tray>
</JWM>
the "S" is for future use. it needs a fifo named /tmp/adjvolumefifo
Code: [Select]
mkfifo /tmp/adjvolumefifoI was backgrounding it in a terminal so I could see which control i'm on.  now I just do
Code: [Select]
/usr/local/mediaswg/bin/adjvolume.pl >/dev/null &to use it, C changes channel and the ^ and v adjust the level.  Set the first four variables for your card.  Output works with alsa and fits in watcher.
this requires perl5 and
Code: [Select]
[ -e /usr/bin/perl ] || sudo ln -s /usr/local/bin/perl /usr/bin/perlstill a few bugs to work out and more features I want but so far it works.
Title: Re: nifty volume control for jwm
Post by: tobiaus on May 04, 2009, 11:06:13 AM
hehe, it uses a daemon? that's fun.
Title: Re: nifty volume control for jwm
Post by: jls on May 05, 2009, 01:43:31 PM
In tc 1.4.1 I use the ossxmix from oss package of tc 2.0RC1
Title: Re: nifty volume control for jwm
Post by: tobiaus on May 05, 2009, 02:11:18 PM
In tc 1.4.1 I use the ossxmix from oss package of tc 2.0RC1

it's very good. i wish i could use it in ubuntu. i'm using wmix, which is good enough, but it will not dock in jwm, and whenever you close the window it says "kill this window? it may cause data to be lost!" which is a ridiculous message, not to mention annoying. killall wmix (so that it doesn't ask) too many times and x may close!

i use the same v ^ buttons in jwm that i made for tc, but ^ opens the stupid volume control, and v issues "killall -2 wmix." for whatever reason i should know, killall -2 is safer.

when testing 2.x (can't upgrade to it yet) i like to use ossxmix unless i have my buttons installed. i like how the buttons are "always open" even though they're not running anything. i also like the idea of assigning keys, like mikshaw would.
Title: Re: nifty volume control for jwm
Post by: jls on May 05, 2009, 04:23:59 PM
I was sying I'm using ossxmix in 1.4.1
Title: Re: nifty volume control for jwm
Post by: tobiaus on May 06, 2009, 01:13:49 PM
I was sying I'm using ossxmix in 1.4.1

oh! 1.4.1, i'm glad you said it twice, that's really good news.