[fmtools/f15/master] Better volume control.

Paulo Roma Cavalcanti roma at fedoraproject.org
Wed Mar 16 16:07:18 UTC 2011


commit 8cfc145c75f5fb4a957f8a2f5dd9ceaddfad4e44
Author: Paulo Roma Cavalcanti <promac at gmail.com>
Date:   Wed Mar 16 13:06:57 2011 -0300

    Better volume control.

 fmtools.spec |    5 ++++-
 tkradio.py   |   26 ++++++++++++++++++--------
 2 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/fmtools.spec b/fmtools.spec
index a7dafb5..1000c79 100644
--- a/fmtools.spec
+++ b/fmtools.spec
@@ -3,7 +3,7 @@
 Summary: Simple Video for Linux radio card programs
 Name:    fmtools
 Version: 2.0.1
-Release: 7%{?dist}
+Release: 8%{?dist}
 License: GPLv2+
 Group:   Applications/Multimedia
 URL:     http://benpfaff.org/fmtools
@@ -98,6 +98,9 @@ rm -rf %{buildroot}
 
 %changelog
 
+* Sun Mar 13 2011 Paulo Roma <roma at lcg.ufrj.br> 2.0.1-8
+- Using Master for controling the volume.
+
 * Tue Mar 10 2011 Paulo Roma <roma at lcg.ufrj.br> 2.0.1-7
 - Restoring the saved state (persistency).
 
diff --git a/tkradio.py b/tkradio.py
index 4dfd572..fe29a02 100644
--- a/tkradio.py
+++ b/tkradio.py
@@ -4,7 +4,7 @@
 # Date: 23/12/2009
 # The radio is turned off on exit.
 
-import os, sys, string, pickle
+import os, sys, string, pickle, math
 import datetime, time
 from threading import Thread
 from subprocess import Popen, PIPE
@@ -77,6 +77,8 @@ FM    = "/usr/bin/fm"         # fmtools
 OGG   = "/usr/bin/oggenc"     # vorbis-tools
 RPNG  = "/usr/share/pixmaps/radio.png"
 RGIF  = "/usr/share/fmtools/radio.gif"
+#CHANNEL = "PCM"
+CHANNEL = "Master"
 
 class IRRec(Thread):
    """Class for interacting with lirc."""
@@ -311,11 +313,19 @@ def mute():
         btmute.set ( "Off" )
         btm.config(state=NORMAL)
 
+def setVolume ( v ):
+    os.system(MIXER + " -q -c 0 set " + CHANNEL + " " + str(v) + "%")
+
+def getVolume ( ):
+    vol = os.popen (MIXER + " -c 0 get " + CHANNEL + " | " + GREP + " -E \"%\"").readline()
+    i = str.find (vol,"%")
+    j = str.find (vol,"[",0,i)
+    return int(vol[j+1:i])
+
 def on_move(value=0):
     """Use slider position to set the volume."""
 
-    v = scale.get()
-    os.system(MIXER + " -q -c 0 set PCM "+str(v)+"%")
+    setVolume ( scale.get() )
 
 def volup ():
     """Increase the volume."""
@@ -323,7 +333,7 @@ def volup ():
     v = scale.get() + 5
     if ( v > 100 ): v = 100
     scale.set ( v )
-    os.system(MIXER + " -q -c 0 set PCM "+str(v)+"%")
+    setVolume ( v )
 
 def voldown():
     """Decrease the volume."""
@@ -331,7 +341,7 @@ def voldown():
     v = scale.get() - 5
     if ( v < 0 ): v = 0
     scale.set ( v )
-    os.system(MIXER + " -q -c 0 set PCM "+str(v)+"%")
+    setVolume ( v )
 
 def enter ():
     "Enter a new frequency."""
@@ -462,7 +472,7 @@ class radioState:
       """Holds the state of the clock (used for persistency)."""
 
       def __init__ ( self, intial_station ):
-          self.volume   = 100
+          self.volume   = getVolume()
           self.loop     = "OFF"
           self.mute     = False
           self.station  = intial_station
@@ -549,9 +559,9 @@ def main (argv=None):
 
     # sets the recording type: alsa or pulse
     if ( set_rec_type() ):        
-         Label(top, text = 'volume: pulse').pack()
+         Label(top, text = 'pulse: '+CHANNEL).pack()
     else:
-         Label(top, text = 'volume: alsa').pack()
+         Label(top, text = 'alsa: '+CHANNEL).pack()
 
     # make tuner buttons
     for st in fmstations:


More information about the scm-commits mailing list