#!/usr/bin/python2.2 # author : mirko koenig # 26.04.2001 # released under GPL http://www.gnu.org/copyleft/gpl.html # # short manual # # mutemix uses aumix on commmandline for its actions. # mute all : to mute all channels # scales : to control volume of a channel # 1st button under scale : to mute this channel # 2nt button under scale : to make this channel the rec device. # button only appears, when channel can be a rec device # load/save : mutemix saves/loads every file to/from $HOME/.mutemix/ # except you don't type in a filename in the file dialog, then # mutemix will save/load to/from the standart aumix save-/loadfile # if the directory $HOME/.mutemix/ does not exist, then it will be created from Tkinter import * import os,string,sys root = Tk(className="mutemix") root.title("MuteMix") class devicegui: recdevicename = StringVar() def __init__( self, devname, rootframe, cmdlineoption="", volume=0, isrecdevice=0 ): self.option = cmdlineoption # command line option with leading '-' or '--' self.ismuted = IntVar() # 0 = not muted, 1 = muted self.rootframe = Frame( rootframe ) #frame that inherits the scale, mutebtn, recbtn self.label = Label( self.rootframe, text=devname ) self.volbar = Scale( self.rootframe, relief=GROOVE, showvalue=0 ) self.mutebtn = Checkbutton( self.rootframe, relief=FLAT, variable=self.ismuted, command=self.mutepressed ) # bind to events self.volbar.bind( "", self.updatevol ) # pack it self.rootframe.pack( side=LEFT, fill=Y ) self.label.pack() self.volbar.pack() self.mutebtn.pack() # create rec button if device is a rec device if isrecdevice == 1: self.recbtn = Radiobutton( self.rootframe, relief=FLAT, variable=self.recdevicename, value=devname, command=self.setrec ) self.recbtn.pack() self.setvolume( volume ) def setvolume( self, volume ): self.volbar.set( value=( 100 - int( volume ) ) ) def updatevol( self, event=None ): if self.ismuted.get() != 1: if self.option != "": os.system( "aumix " + self.option + " %d" % ( 100 - self.volbar.get() ) ) def mutepressed( self, event=None ): if self.ismuted.get() == 1: self.mute() else: self.unmute() def unmute( self ): self.mutebtn.deselect() self.updatevol() def mute( self, event=None ): self.mutebtn.select() if self.option != "": os.system( "aumix " + self.option + " 0" ) def setrec( self, event=None ): self.recbtn.select() if self.option != "": os.system( "aumix " + self.option + " R" ) ######################################## # variable section ######################################## devices = {} mutethemall = IntVar() dir = os.path.expanduser( "~/.mutemix" ) device_options = { 'vol': '-v', 'bass': '-b', 'treble': '-t', 'synth': '-s', 'pcm': '-w', 'speaker': '-p', 'line': '-l', 'mic': '-m', 'cd': '-c', 'mix': '-x', 'pcm2': '-W', 'rec': '-r', 'igain': '-i', 'ogain': '-o', 'line1': '-1', 'line2': '-2', 'line3': '-3', 'digital1': '--digital1', 'digital2': '--digital2', 'digital3': '--digital3', 'phin': '--phonein', 'phout': '--phoneout', 'video': '--video', 'radio': '--radio', 'monitor': '--monitor' } # cmdline options of aumix ######################################## # check if ~/.mutemix allready exists ######################################## def checkdir(): if not os.path.isdir( dir ): os.mkdir( dir ) ######################################## # read the mixer settings and create mutemix devices ######################################## def aumix2mutemix(): mixer = os.popen( "aumix -q" ).readlines() # get mixer info for lines in mixer: devname = string.split( lines )[0] volume = string.split( lines )[1][:-1] tmp = string.split( lines )[-1] if tmp == 'P' or tmp == 'R': devices[ devname ] = devicegui( devname, volframe, device_options[ devname ], volume, 1 ) if tmp =='R': devices[ devname ].setrec() else: devices[ devname ] = devicegui( devname, volframe, device_options[ devname ], volume, 0 ) ######################################## # read volumes and set them ######################################## def read_aumix(): mixer = os.popen( "aumix -q" ).readlines() # get mixer info for lines in mixer: volume = string.split( lines )[1][:-1] devname = string.split( lines )[0] if devname in devices.keys(): devices[ devname ].setvolume( volume ) ######################################## # mute all channels ######################################## def muteall( event=None ): if mutethemall.get() == 1: for x in devices.keys(): devices[x].mute() else: for x in devices.keys(): devices[x].unmute() ######################################## # save values ######################################## def save( event=None ): savefile = filename.get() if savefile != "": os.system( "aumix -f " + dir + os.sep + savefile + " -S" ) else: os.system( "aumix -S" ) # save to default file file_select_dlg.destroy() ######################################## # load values ######################################## def load( event=None ): loadfile = filename.get() if loadfile != "": os.system( "aumix -f " + dir + os.sep + loadfile + " -L" ) else: os.system( "aumix -L" ) # load from default file read_aumix() file_select_dlg.destroy() ######################################## # dummy for the button events ######################################## def loadpressed( event=None ): file_select( 0 ) def savepressed( event=None ): file_select( 1 ) ######################################## # file selection dialog ######################################## def file_select( savefile ): global file_select_dlg file_select_dlg = Toplevel( ) file_select_dlg.transient( root ) file_select_dlg.grab_set() file_select_dlg.title( "File Dialog" ) dlgframe = Frame( file_select_dlg ) dlgframe.pack() global filename filename = StringVar() Label( dlgframe, text="file name :" ).pack() Entry( dlgframe, textvariable=filename, relief=GROOVE ).pack() if savefile == 1: Button( dlgframe, text="OK", relief=GROOVE, command=save ).pack() else: Button( dlgframe, text="OK", relief=GROOVE, command=load ).pack() Button( dlgframe, text="Cancel", relief=GROOVE, command=file_select_dlg.destroy ).pack() file_select_dlg.wait_window() if len( sys.argv ) > 1: if sys.argv[1] == '--help' or sys.argv[1] == '-h': print "author : mirko koenig" print "version 1.0" print "26.04.2001" print "released under GPL http://www.gnu.org/copyleft/gpl.html" print "" print "short manual :" print print "mutemix uses aumix on commmandline for its actions." print print "mute all : to mute all channels" print print "scales : to control volume of a channel" print print "1st button under scale : to mute this channel" print print "2nt button under scale : to make this channel the rec device." print " button only appears, when channel can be a rec device" print print "load/save : mutemix saves/loads every file to/from $HOME/.mutemix/" print " except you don't type in a filename in the file dialog, then" print " mutemix will save/load to/from the standart aumix save-/loadfile" print " if the directory $HOME/.mutemix/ does not exist, then it will be created" else: print "so such option. only -h or --help are options" else: menuframe = Frame( root ) menuframe.pack() volframe = Frame( root ) volframe.pack() Button( menuframe, text="Exit", relief=GROOVE, command=root.destroy ).pack( side=LEFT ) Checkbutton( menuframe, text="Mute all", relief=FLAT, variable=mutethemall, command=muteall ).pack( side=LEFT ) Button( menuframe, text="Load", relief=GROOVE, command=loadpressed ).pack( side=LEFT ) Button( menuframe, text="Save", relief=GROOVE, command=savepressed ).pack( side=LEFT ) ######################################## # start here ######################################## checkdir() aumix2mutemix() root.mainloop()