import alsaaudio import sys,os class AlsaCardManager(): def __init__(self): print "[AlsaCardManager] INIT" self.debug=False #def __init__ def list_cards(self): print "[AlsaCardManager] Card List:" cards= alsaaudio.cards() count=0; for item in cards: #print ("%s %s"%(item, alsaaudio.mixers(count))) print "\t\t [%s]"%(count) self.get_card_info(count) count+=1 #def list_cards def get_card_info(self,id): print "[AlsaCardManager] [Card %s] info:"%id count2=0 card_name_written=False for mixer_name in alsaaudio.mixers(id): mixer=alsaaudio.Mixer(mixer_name,0,id) if (not card_name_written): print "[AlsaCardManager] Card name: %s"%mixer.cardname() card_name_written=True print "\t\t\t### %s"%mixer_name if len(mixer.getenum())>0: print "\t\t\t > %s sources: %s"%(mixer_name, mixer.getenum()) if len(mixer.switchcap())>0: print "\t\t\t > %s Switch Capabilities: %s"%(mixer_name,mixer.switchcap()) if len(mixer.volumecap())>0: print "\t\t\t > %s Volume Capabilities: %s"%(mixer_name,mixer.volumecap()) count2+=1 #def get_card_info def get_enums(self,id): list=[] for mixer_name in alsaaudio.mixers(id): mixer=alsaaudio.Mixer(mixer_name,0,id) if len(mixer.getenum())>0: list.append(mixer_name) #for name in list: # print name return list #def get_enums def get_switches(self,id,mixer_name): found=False for name in alsaaudio.mixers(id): if mixer_name==name: found=True if found: mixer=alsaaudio.Mixer(mixer_name,0,id) return mixer.switchcap() else: print "[AlsaCardManager][get_switches][!] Mixer not found." #def get_switches def get_volumes(self,id,mixer_name): found=False for name in alsaaudio.mixers(id): if mixer_name==name: found=True if found: mixer=alsaaudio.Mixer(mixer_name,0,id) return mixer.volumecap() else: print "[AlsaCardManager][get_volumes][!] Mixer not found." #def get_volumes def set_volume(self,id,mixer_name,volume,id_mixer=None): if id_mixer==None: id_mixer=0 mixer_found=False for name in alsaaudio.mixers(id): if mixer_name==name: mixer_found=True if mixer_found: mixer=alsaaudio.Mixer(mixer_name,id_mixer,id) mixer.setvolume(volume) #def set_volume def set_mute(self,id,mixer_name,mute,id_mixer=None): if id_mixer==None: id_mixer=0 mixer_found=False for name in alsaaudio.mixers(id): if mixer_name==name: mixer_found=True if mixer_found: mixer=alsaaudio.Mixer(mixer_name,id_mixer,id) mixer.setmute(mute) #def set_mute def set_enum(self,id,mixer_name,source,id_mixer=None): mixer_found=False if id_mixer==None: id_mixer=0 for name in alsaaudio.mixers(id): if mixer_name==name: mixer_found=True if not mixer_found: print "[AlsaCardManager][set_enum][!] Mixer not found." else: mixer=alsaaudio.Mixer(mixer_name,id_mixer,id) sources=mixer.getenum() active_source,sources_list=sources found=False if self.debug: print active_source for src in sources_list: print "> %s"%src sourceid="" counter=0 for src in sources_list: if src==source: found=True sourceid=counter if self.debug: print "Found ya" counter+=1 if not found: print "[AlsaCardManager][set_enum][!] Source not found." else: mixer.setenum(sourceid) #def set_enum def get_enum(self,id,mixer_name,id_mixer=None): found=False if id_mixer==None: id_mixer=0 for name in alsaaudio.mixers(id): if mixer_name==name: found=True if found: mixer=alsaaudio.Mixer(mixer_name,id_mixer,id) sources=mixer.getenum() active_source,sources_list=sources if self.debug: print sources_list return sources_list else: print "[AlsaCardManager][get_enum][!] Mixer not found." #def get_enum #class alsa_card_manager ''' if __name__=="__main__": acm=alsa_card_manager() '''