Show
Ignore:
Timestamp:
04/02/12 05:21:03 (12 years ago)
Author:
jwoithe
Message:

Patch from Philippe Carriere. This is just a simple re-writing of updatePanels, intended to have no effects on the behaviour of ffado-mixer. Sub-functions will be used in a future, additional, 'refresh currents' panels function.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/support/mixer-qt4/ffado/panelmanager.py

    r1934 r2109  
    211211            self.emit(SIGNAL("connectionLost")) 
    212212 
    213     def updatePanels(self): 
    214         log.debug("PanelManager::updatePanels()") 
    215         nbDevices = self.devmgr.getNbDevices() 
    216         #self.statusBar().showMessage("Reconfiguring the mixer panels...") 
    217  
    218         # list of panels present 
    219         guids_with_tabs = self.panels.keys() 
    220  
    221         # build list of guids on the bus now 
    222         guids_present = [] 
    223         guid_indexes = {} 
    224         for idx in range(nbDevices): 
    225             path = self.devmgr.getDeviceName(idx) 
    226             cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
    227             guid = cfgrom.getGUID() 
    228             guids_present.append(guid) 
    229             guid_indexes[guid] = idx 
    230  
    231         # figure out what to remove 
    232         # the special panel (generic) 
    233         # that has (pseudo-)GUID 0 
    234         # is also automatically removed 
    235         to_remove = [] 
    236         for guid in guids_with_tabs: 
    237             if not guid in guids_present: 
    238                 to_remove.append(guid) 
    239                 log.debug("going to remove %s" % str(guid)) 
    240             else: 
    241                 log.debug("going to keep %s" % str(guid)) 
    242  
    243         # figure out what to add 
    244         to_add = [] 
    245         for guid in guids_present: 
    246             if not guid in guids_with_tabs: 
    247                 to_add.append(guid) 
    248                 log.debug("going to add %s" % str(guid)) 
    249  
    250         # update the widget 
    251         for guid in to_remove: 
    252             print "Removing widget for device" + guid 
    253             w = self.panels[guid] 
    254             del self.panels[guid] # remove from the list 
    255             idx = self.tabs.indexOf(w) 
    256             self.tabs.removeTab(idx) 
    257             w.deleteLater() 
    258  
    259         for guid in to_add: 
    260             # retrieve the device manager index 
    261             idx = guid_indexes[guid] 
    262             path = self.devmgr.getDeviceName(idx) 
    263             log.debug("Adding device %d: %s" % (idx, path)) 
    264  
    265             cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
    266             vendorId = cfgrom.getVendorId() 
    267             modelId = cfgrom.getModelId() 
    268             unitVersion = cfgrom.getUnitVersion() 
    269             guid = cfgrom.getGUID() 
    270             vendorName = cfgrom.getVendorName() 
    271             modelName = cfgrom.getModelName() 
    272             log.debug(" Found (%s, %X, %X) %s %s" % (str(guid), vendorId, modelId, vendorName, modelName)) 
    273  
    274             # check whether this has already been registered at ffado.org 
    275             reg = ffado_registration(FFADO_VERSION, int(guid, 16), 
     213    def removePanel(self, guid): 
     214        print "Removing widget for device" + guid 
     215        w = self.panels[guid] 
     216        del self.panels[guid] # remove from the list 
     217        idx = self.tabs.indexOf(w) 
     218        self.tabs.removeTab(idx) 
     219        w.deleteLater() 
     220 
     221    def addPanel(self, idx): 
     222        path = self.devmgr.getDeviceName(idx) 
     223        log.debug("Adding device %d: %s" % (idx, path)) 
     224 
     225        cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
     226        vendorId = cfgrom.getVendorId() 
     227        modelId = cfgrom.getModelId() 
     228        unitVersion = cfgrom.getUnitVersion() 
     229        guid = cfgrom.getGUID() 
     230        vendorName = cfgrom.getVendorName() 
     231        modelName = cfgrom.getModelName() 
     232        log.debug(" Found (%s, %X, %X) %s %s" % (str(guid), vendorId, modelId, vendorName, modelName)) 
     233 
     234        # check whether this has already been registered at ffado.org 
     235        reg = ffado_registration(FFADO_VERSION, int(guid, 16), 
    276236                                     vendorId, modelId, 
    277237                                     vendorName, modelName) 
    278             reg.check_for_registration() 
    279  
    280             # The MOTU devices use unitVersion to differentiate models.  For the 
    281             # moment though we don't need to know precisely which model we're 
    282             # using. 
    283             if vendorId == 0x1f2: 
    284                 modelId = 0x00000000 
    285  
    286             # The RME devices use unitVersion to differentiate models.  
    287             # Therefore in the configuration file we use the config file's 
    288             # modelid field to store the unit version.  As a result we must 
    289             # override the modelId with the unit version here so the correct 
    290             # configuration file entry (and hense mixer widget) is identified. 
    291             if vendorId == 0xa35: 
    292                 modelId = unitVersion; 
    293  
    294             dev = self.devices.getDeviceById( vendorId, modelId ) 
    295  
    296             w = QWidget( ) 
    297             l = QVBoxLayout( w ) 
    298  
    299             # create a control object 
    300             hw = ControlInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
    301             clockselect = ClockSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
    302             samplerateselect = SamplerateSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
    303             streamingstatus = StreamingStatusInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
    304             nickname = TextInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path+"/Generic/Nickname" ) 
    305  
    306            
    307             # Generic elements for all mixers follow here: 
    308            
    309             globalmixer = GlobalMixer( w ) 
    310             globalmixer.configrom = cfgrom 
    311             globalmixer.clockselect = clockselect 
    312             globalmixer.samplerateselect = samplerateselect 
    313             globalmixer.streamingstatus = streamingstatus 
    314             globalmixer.nickname = nickname 
    315             globalmixer.hw = hw 
    316             globalmixer.initValues() 
    317             l.addWidget( globalmixer, 1 ) 
    318  
    319            
    320             # Line to separate 
    321            
    322             l.addWidget( HLine( w ) ) 
    323  
    324            
    325             # Specific (or dummy) mixer widgets get loaded in the following 
    326            
    327             if 'mixer' in dev and dev['mixer'] != None: 
    328                 mixerapp = dev['mixer'] 
    329                 exec( """ 
     238        reg.check_for_registration() 
     239 
     240        # The MOTU devices use unitVersion to differentiate models.  For the 
     241        # moment though we don't need to know precisely which model we're 
     242        # using. 
     243        if vendorId == 0x1f2: 
     244            modelId = 0x00000000 
     245 
     246        # The RME devices use unitVersion to differentiate models.  
     247        # Therefore in the configuration file we use the config file's 
     248        # modelid field to store the unit version.  As a result we must 
     249        # override the modelId with the unit version here so the correct 
     250        # configuration file entry (and hense mixer widget) is identified. 
     251        if vendorId == 0xa35: 
     252            modelId = unitVersion; 
     253 
     254        dev = self.devices.getDeviceById( vendorId, modelId ) 
     255 
     256        w = QWidget( ) 
     257        l = QVBoxLayout( w ) 
     258 
     259        # create a control object 
     260        hw = ControlInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
     261        clockselect = ClockSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
     262        samplerateselect = SamplerateSelectInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
     263        streamingstatus = StreamingStatusInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path ) 
     264        nickname = TextInterface( FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+"/DeviceManager/"+path+"/Generic/Nickname" ) 
     265 
     266       
     267        # Generic elements for all mixers follow here: 
     268       
     269        globalmixer = GlobalMixer( w ) 
     270        globalmixer.configrom = cfgrom 
     271        globalmixer.clockselect = clockselect 
     272        globalmixer.samplerateselect = samplerateselect 
     273        globalmixer.streamingstatus = streamingstatus 
     274        globalmixer.nickname = nickname 
     275        globalmixer.hw = hw 
     276        globalmixer.initValues() 
     277        l.addWidget( globalmixer, 1 ) 
     278 
     279       
     280        # Line to separate 
     281       
     282        l.addWidget( HLine( w ) ) 
     283 
     284       
     285        # Specific (or dummy) mixer widgets get loaded in the following 
     286       
     287        if 'mixer' in dev and dev['mixer'] != None: 
     288            mixerapp = dev['mixer'] 
     289            exec( """ 
    330290import ffado.mixer.%s 
    331291mixerwidget = ffado.mixer.%s.%s( w ) 
    332292""" % (mixerapp.lower(), mixerapp.lower(), mixerapp) ) 
    333             else: 
    334                 mixerwidget = Dummy( w ) 
    335                 mixerapp = modelName+" (Dummy)" 
    336  
    337             # 
    338             # The same for all mixers 
    339             # 
    340             l.addWidget( mixerwidget, 10 ) 
    341             mixerwidget.configrom = cfgrom 
    342             mixerwidget.clockselect = clockselect 
    343             mixerwidget.samplerateselect = samplerateselect 
    344             mixerwidget.streamingstatus = streamingstatus 
    345             mixerwidget.nickname = nickname 
    346             mixerwidget.hw = hw 
    347             if 'buildMixer' in dir(mixerwidget): 
    348                 mixerwidget.buildMixer() 
    349             if 'initValues' in dir(mixerwidget): 
    350                 mixerwidget.initValues() 
    351             if 'getDisplayTitle' in dir(mixerwidget): 
    352                 title = mixerwidget.getDisplayTitle() 
    353             else: 
    354                 title = mixerapp 
    355  
    356             globalmixer.setName(title) 
    357             self.tabs.addTab( w, title ) 
    358             self.panels[guid] = w 
    359  
     293        else: 
     294            mixerwidget = Dummy( w ) 
     295            mixerapp = modelName+" (Dummy)" 
     296 
     297        # 
     298        # The same for all mixers 
     299        # 
     300        l.addWidget( mixerwidget, 10 ) 
     301        mixerwidget.configrom = cfgrom 
     302        mixerwidget.clockselect = clockselect 
     303        mixerwidget.samplerateselect = samplerateselect 
     304        mixerwidget.streamingstatus = streamingstatus 
     305        mixerwidget.nickname = nickname 
     306        mixerwidget.hw = hw 
     307        if 'buildMixer' in dir(mixerwidget): 
     308            mixerwidget.buildMixer() 
     309        if 'initValues' in dir(mixerwidget): 
     310            mixerwidget.initValues() 
     311        if 'getDisplayTitle' in dir(mixerwidget): 
     312            title = mixerwidget.getDisplayTitle() 
     313        else: 
     314            title = mixerapp 
     315 
     316        globalmixer.setName(title) 
     317        self.tabs.addTab( w, title ) 
     318        self.panels[guid] = w 
     319 
     320    def displayPanels(self): 
    360321        # if there is no panel, add the no-device message 
    361322        # else make sure it is not present 
     
    378339                self.tabs.addTab( w, "Generic Mixer" ) 
    379340                self.panels[GUID_GENERIC_MIXER] = w 
     341     
     342    def updatePanels(self): 
     343        log.debug("PanelManager::updatePanels()") 
     344        nbDevices = self.devmgr.getNbDevices() 
     345        #self.statusBar().showMessage("Reconfiguring the mixer panels...") 
     346 
     347        # list of panels present 
     348        guids_with_tabs = self.panels.keys() 
     349 
     350        # build list of guids on the bus now 
     351        guids_present = [] 
     352        guid_indexes = {} 
     353        for idx in range(nbDevices): 
     354            path = self.devmgr.getDeviceName(idx) 
     355            cfgrom = ConfigRomInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH+'/DeviceManager/'+path) 
     356            guid = cfgrom.getGUID() 
     357            guids_present.append(guid) 
     358            guid_indexes[guid] = idx 
     359 
     360        # figure out what to remove 
     361        # the special panel (generic) 
     362        # that has (pseudo-)GUID 0 
     363        # is also automatically removed 
     364        to_remove = [] 
     365        for guid in guids_with_tabs: 
     366            if not guid in guids_present: 
     367                to_remove.append(guid) 
     368                log.debug("going to remove %s" % str(guid)) 
     369            else: 
     370                log.debug("going to keep %s" % str(guid)) 
     371 
     372        # figure out what to add 
     373        to_add = [] 
     374        for guid in guids_present: 
     375            if not guid in guids_with_tabs: 
     376                to_add.append(guid) 
     377                log.debug("going to add %s" % str(guid)) 
     378 
     379        # update the widget 
     380        for guid in to_remove: 
     381            self.removePanel(guid) 
     382 
     383        for guid in to_add: 
     384            # retrieve the device manager index 
     385            idx = guid_indexes[guid] 
     386            self.addPanel(idx) 
     387 
     388        self.displayPanels() 
    380389 
    381390# vim: et