Volume in Status Bar

From awesome
Jump to: navigation, search

Volume in Status Bar

In my system I've a /proc/asound/card0/codec97#0/ac97#0-0+regs file that stores the current volume values. I think that on other systems have similar file.

So, if you run this:

$ cat '/proc/asound/card0/codec97#0/ac97#0-0+regs' > a
$ alsamixer # change the specified chanell's volume
$ cat '/proc/asound/card0/codec97#0/ac97#0-0+regs' > b
$ diff a b

you'll know what is the desired channel's register (e.g. PCM, Headphone, Master,...). My PCM channel is reg. 0:18 and the Main is 0:04.

In that file (and my system) the volumes are two pair byte (left and right). The left and right volumes are always equal (by me) so the first pair byte is enough.

Please note: the lower value is the louder and the highest value is quieter.

The awk-script:

#!/bin/awk -f
function print_data()
{
   data =  "0 widget_tell pb_volume_pcm " pcm_vol "\n"\
           "0 widget_tell pb_volume_master " master_vol"\n"
   print data;
}
BEGIN {
  INTERVAL = 1;             # in seconds
}
{ 
 while (!system("sleep " INTERVAL))
 {

   while ( (getline < "/proc/asound/card0/codec97#0/ac97#0-0+regs")>0 ) {
               if ($1~/0:18/) {
                       hex=strtonum("0x"$3);
                       pcm_vol=(31-hex/256)*100;
                       pcm_vol/=31;
               } else if ($1~/0:04/) {
                       hex=strtonum("0x"$3);
                       master_vol=(31-hex/256)*100;
                       master_vol/=31;
               }
       }
   close("/proc/asound/card0/codec97#0/ac97#0-0+regs");
 }
}

You must have pb_volume_pcm and pb_volume_master progress bars - of course.

Remark: you can use this method to handle "output signal level" so you can create "volume meter". Of course, in this case you must send information in every (about) 0.1 sec (10 fps). Example screenshot, see the bottom statusbar, about center, before "Offspring - Want you so bad" text.

Personal tools