[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kmix
From:       Christian Esken <esken () kde ! org>
Date:       2011-01-02 21:09:20
Message-ID: 20110102210920.5A56DAC8B1 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1210982 by esken:

Better master control handling.

 M  +3 -0      CMakeLists.txt  
 M  +19 -17    apps/kmix.cpp  
 M  +8 -5      apps/kmixd.cpp  
 M  +47 -26    core/mixer.cpp  
 M  +5 -3      core/mixer.h  
 M  +5 -2      core/mixertoolbox.cpp  
 M  +0 -3      gui/dialogaddview.cpp  
 M  +1 -1      gui/dialogselectmaster.cpp  
 M  +0 -10     gui/kmixdockwidget.cpp  
 M  +1 -0      tests/CMakeLists.txt  


--- trunk/KDE/kdemultimedia/kmix/CMakeLists.txt #1210981:1210982
@@ -52,6 +52,7 @@
    gui/osdwidget.cpp
    core/mixertoolbox.cpp
    core/kmixdevicemanager.cpp
+   core/MasterControl.cpp
    core/mixer.cpp
    core/mixset.cpp
    core/mixdevice.cpp
@@ -82,6 +83,7 @@
 
  set(kded_kmixd_SRCS ${kmix_adaptor_SRCS}
     apps/kmixd.cpp 
+    core/MasterControl.cpp
     core/mixer.cpp 
     core/mixset.cpp 
     core/mixdevice.cpp 
@@ -117,6 +119,7 @@
 
 set(kmixctrl_KDEINIT_SRCS ${kmix_adaptor_SRCS}
    apps/kmixctrl.cpp 
+   core/MasterControl.cpp
    core/mixer.cpp 
    core/mixset.cpp 
    core/mixdevice.cpp 
--- trunk/KDE/kdemultimedia/kmix/apps/kmix.cpp #1210981:1210982
@@ -53,6 +53,7 @@
 
 // KMix
 #include "gui/guiprofile.h"
+#include "core/MasterControl.h"
 #include "core/mixertoolbox.h"
 #include "apps/kmix.h"
 #include "core/kmixdevicemanager.h"
@@ -300,14 +301,12 @@
     config.writeEntry( "DefaultCardOnStart", m_defaultCardOnStart );
     config.writeEntry( "ConfigVersion", KMIX_CONFIG_VERSION );
     config.writeEntry( "AutoUseMultimediaKeys", m_autouseMultimediaKeys );
-    Mixer* mixerMasterCard = Mixer::getGlobalMasterMixer();
-    if ( mixerMasterCard != 0 ) {
-        config.writeEntry( "MasterMixer", mixerMasterCard->id() );
+
+    MasterControl& master = Mixer::getGlobalMasterPreferred();
+    if ( master.isValid()) {
+        config.writeEntry( "MasterMixer", master.getCard() );
+        config.writeEntry( "MasterMixerDevice", master.getControl() );
     }
-    MixDevice* mdMaster = Mixer::getGlobalMasterMD();
-    if ( mdMaster != 0 ) {
-        config.writeEntry( "MasterMixerDevice", mdMaster->id() );
-    }
     QString mixerIgnoreExpression = \
MixerToolBox::instance()->mixerIgnoreExpression();  config.writeEntry( \
"MixerIgnoreExpression", mixerIgnoreExpression );  
@@ -408,7 +407,7 @@
     QString mixerMasterCard = config.readEntry( "MasterMixer", "" );
     QString masterDev = config.readEntry( "MasterMixerDevice", "" );
     //if ( ! mixerMasterCard.isEmpty() && ! masterDev.isEmpty() ) {
-    Mixer::setGlobalMaster(mixerMasterCard, masterDev);
+    Mixer::setGlobalMaster(mixerMasterCard, masterDev, true);
     //}
     QString mixerIgnoreExpression = config.readEntry( "MixerIgnoreExpression", \
                "Modem" );
     MixerToolBox::instance()->setMixerIgnoreExpression(mixerIgnoreExpression);
@@ -730,15 +729,15 @@
     } // if config version < 3
 }
 
-void KMixWindow::plugged( const char* driverName, const QString& /*udi*/, QString& \
dev) +void KMixWindow::plugged( const char* driverName, const QString& udi, QString& \
dev)  {
-    //     kDebug(67100) << "Plugged: dev=" << dev << "(" << driverName << ") udi=" \
<< udi << "\n"; +    kDebug() << "Plugged: dev=" << dev << "(" << driverName << ") \
udi=" << udi << "\n";  QString driverNameString;
     driverNameString = driverName;
     int devNum = dev.toInt();
     Mixer *mixer = new Mixer( driverNameString, devNum );
     if ( mixer != 0 ) {
-        kDebug(67100) << "Plugged: dev=" << dev << "\n";
+        kDebug() << "Plugged: dev=" << dev << "\n";
         MixerToolBox::instance()->possiblyAddMixer(mixer);
         recreateGUI(true, mixer->id(), true);
     }
@@ -751,12 +750,12 @@
 
 void KMixWindow::unplugged( const QString& udi)
 {
-    //     kDebug(67100) << "Unplugged: udi=" <<udi << "\n";
+    kDebug() << "Unplugged: udi=" <<udi << "\n";
     for (int i=0; i<Mixer::mixers().count(); ++i) {
         Mixer *mixer = (Mixer::mixers())[i];
         //         kDebug(67100) << "Try Match with:" << mixer->udi() << "\n";
         if (mixer->udi() == udi ) {
-            kDebug(67100) << "Unplugged Match: Removing udi=" <<udi << "\n";
+            kDebug() << "Unplugged Match: Removing udi=" <<udi << "\n";
             //KMixToolBox::notification("MasterFallback", "aaa");
             bool globalMasterMixerDestroyed = ( mixer == \
Mixer::getGlobalMasterMixer() );  // Part 1) Remove Tab
@@ -774,19 +773,22 @@
             MixDevice* md = Mixer::getGlobalMasterMD();
             if ( globalMasterMixerDestroyed || md == 0 ) {
                 // We don't know what the global master should be now.
-                // So lets play stupid, and just select the recommendended master of \
the first device +                // So lets play stupid, and just select the \
recommended master of the first device  if ( Mixer::mixers().count() > 0 ) {
-                    QString localMaster = \
                ((Mixer::mixers())[0])->getLocalMasterMD()->id();
-                    Mixer::setGlobalMaster( ((Mixer::mixers())[0])->id(), \
localMaster); +                    MixDevice *master = \
((Mixer::mixers())[0])->getLocalMasterMD(); +                    if ( md != 0 ) {
+                        QString localMaster = master->id();
+                        Mixer::setGlobalMaster( ((Mixer::mixers())[0])->id(), \
localMaster, false);  
                     QString text;
                     text = i18n("The soundcard containing the master device was \
                unplugged. Changing to control %1 on card %2.", 
-                            \
((Mixer::mixers())[0])->getLocalMasterMD()->readableName(), +                         \
master->readableName(),  ((Mixer::mixers())[0])->readableName()
                     );
                     KMixToolBox::notification("MasterFallback", text);
                 }
             }
+            }
             if ( Mixer::mixers().count() == 0 ) {
                 QString text;
                 text = i18n("The last soundcard was unplugged.");
--- trunk/KDE/kdemultimedia/kmix/apps/kmixd.cpp #1210981:1210982
@@ -219,7 +219,7 @@
    QString mixerMasterCard = config.readEntry( "MasterMixer", "" );
    QString masterDev = config.readEntry( "MasterMixerDevice", "" );
    //if ( ! mixerMasterCard.isEmpty() && ! masterDev.isEmpty() ) {
-      Mixer::setGlobalMaster(mixerMasterCard, masterDev);
+      Mixer::setGlobalMaster(mixerMasterCard, masterDev, true);
    //}
    QString mixerIgnoreExpression = config.readEntry( "MixerIgnoreExpression", \
"Modem" );  MixerToolBox::instance()->setMixerIgnoreExpression(mixerIgnoreExpression);
 @@ -299,19 +299,22 @@
             MixDevice* md = Mixer::getGlobalMasterMD();
             if ( globalMasterMixerDestroyed || md == 0 ) {
                 // We don't know what the global master should be now.
-                // So lets play stupid, and just select the recommendended master of \
the first device +                // So lets play stupid, and just select the \
recommended master of the first device  if ( Mixer::mixers().count() > 0 ) {
-                    QString localMaster = \
                ((Mixer::mixers())[0])->getLocalMasterMD()->id();
-                    Mixer::setGlobalMaster( ((Mixer::mixers())[0])->id(), \
localMaster); +                    MixDevice *master = \
((Mixer::mixers())[0])->getLocalMasterMD(); +                    if ( md != 0 ) {
+                        QString localMaster = master->id();
+                        Mixer::setGlobalMaster( ((Mixer::mixers())[0])->id(), \
localMaster, false);  
                     QString text;
                     text = i18n("The soundcard containing the master device was \
                unplugged. Changing to control %1 on card %2.", 
-                            \
((Mixer::mixers())[0])->getLocalMasterMD()->readableName(), +                         \
master->readableName(),  ((Mixer::mixers())[0])->readableName()
                                 );
 //                    KMixToolBox::notification("MasterFallback", text);
                 }
             }
+            }
             if ( Mixer::mixers().count() == 0 ) {
                 QString text;
                 text = i18n("The last soundcard was unplugged.");
--- trunk/KDE/kdemultimedia/kmix/core/mixer.cpp #1210981:1210982
@@ -37,8 +37,8 @@
  */
 
 QList<Mixer *> Mixer::s_mixers;
-QString Mixer::_globalMasterCard;
-QString Mixer::_globalMasterCardDevice;
+MasterControl Mixer::_globalMasterCurrent;
+MasterControl Mixer::_globalMasterPreferred;
 
 
 int Mixer::numDrivers()
@@ -378,53 +378,74 @@
 QString& Mixer::udi(){
     return _mixerBackend->udi();
 }
-void Mixer::setGlobalMaster(QString& ref_card, QString& ref_control)
+
+/**
+ * Set the global master, which is shown in the dock area and which is accesible via \
the + * DBUS masterVolume() method.
+ *
+ * The parameters are taken over as-is, this means without checking for validity.
+ * This allows the User to define a master card that is not always available
+ * (e.g. it is an USB hotplugging device). Also you can set the master at any time \
you + * like, e.g. after reading the KMix configuration file and before actually \
constructing + * the Mixer instances (hint: this method is static!).
+ *
+ * @param ref_card The card id
+ * @param ref_control The control id. The corresponding control must be present in \
the card. + * @param preferred Whether this is the preferred master (auto-selected on \
coldplug and hotplug). + */
+void Mixer::setGlobalMaster(QString ref_card, QString ref_control, bool preferred)
 {
-  // The value is taken over without checking on existence. This allows the User to \
                define
-  // a MasterCard that is not always available (e.g. it is an USB hotplugging \
                device).
-  // Also you can set the master at any time you like, e.g. after reading the KMix \
                configuration file
-  // and before actually constructing the Mixer instances (hint: this mehtod is \
                static!).
-  _globalMasterCard       = ref_card;
-  _globalMasterCardDevice = ref_control;
+    kDebug() << "ref_card=" << ref_card << ", ref_control=" << ref_control << ", \
preferred=" << preferred; +    _globalMasterCurrent.set(ref_card, ref_control);
+    if ( preferred )
+        _globalMasterPreferred.set(ref_card, ref_control);
   kDebug() << "Mixer::setGlobalMaster() card=" <<ref_card<< " control=" << \
ref_control;  }
 
 Mixer* Mixer::getGlobalMasterMixerNoFalback()
 {
-   Mixer *mixer = 0;
-   if(Mixer::mixers().count() == 0)
+   foreach ( Mixer* mixer, Mixer::mixers())
+   {
+      if ( mixer != 0 && mixer->id() == _globalMasterCurrent.getCard() )
       return mixer;
-
-   for (int i=0; i< Mixer::mixers().count(); ++i )
-   {
-      Mixer* mixerTmp = Mixer::mixers()[i];
-      if ( mixerTmp != 0 && mixerTmp->id() == _globalMasterCard ) {
-         //kDebug() << "Mixer::masterCard() found " << _globalMasterCard;
-         mixer = mixerTmp;
-         break;
       }
+   return 0;
    }
-   return mixer;
-}
 
 Mixer* Mixer::getGlobalMasterMixer()
 {
    Mixer *mixer = getGlobalMasterMixerNoFalback();
    if ( mixer == 0 && Mixer::mixers().count() > 0 ) {
-      // produce fallback
-      mixer = Mixer::mixers()[0];
-      _globalMasterCard = mixer->id();
-      kDebug() << "Mixer::masterCard() fallback to  " << _globalMasterCard;
+      mixer = Mixer::mixers()[0];       // produce fallback
    }
    //kDebug() << "Mixer::masterCard() returns " << mixer->id();
    return mixer;
 }
 
+
+/**
+ * Return the preferred global master.
+ * If there is no preferred global master, returns the current master instead.
+ */
+MasterControl& Mixer::getGlobalMasterPreferred()
+{
+    if ( _globalMasterPreferred.isValid() ) {
+        kDebug() << "Returning preferred master";
+        return _globalMasterPreferred;
+    }
+    else {
+        kDebug() << "Returning current master";
+        return _globalMasterCurrent;
+    }
+}
+
+
 MixDevice* Mixer::getGlobalMasterMD()
 {
    return getGlobalMasterMD(true);
 }
 
+
 MixDevice* Mixer::getGlobalMasterMD(bool fallbackAllowed)
 {
    MixDevice* md = 0;
@@ -437,7 +458,7 @@
       for(int i=0; i < mixer->_mixerBackend->m_mixDevices.count() ; i++ )
       {
          md = mixer->_mixerBackend->m_mixDevices[i];
-         if ( md->id() == _globalMasterCardDevice ) {
+         if ( md->id() == _globalMasterCurrent.getControl() ) {
             //kDebug() << "Mixer::masterCardDevice() found " << \
_globalMasterCardDevice;  break;
          }
--- trunk/KDE/kdemultimedia/kmix/core/mixer.h #1210981:1210982
@@ -32,6 +32,7 @@
 
 #include "core/volume.h"
 class Mixer_Backend;
+#include "core/MasterControl.h"
 #include "mixset.h"
 #include "core/mixdevice.h"
 
@@ -123,11 +124,12 @@
     different MasterCard's at the moment (but actually KMixPanelApplet does not \
                read/save this yet).
     At the moment it is only used for selecting the Mixer to use in KMix's DockIcon.
     ******************************************/
-    static void setGlobalMaster(QString& ref_card, QString& ref_control);
+    static void setGlobalMaster(QString ref_card, QString ref_control, bool \
preferred);  static MixDevice* getGlobalMasterMD();
     static MixDevice* getGlobalMasterMD(bool fallbackAllowed);
     static Mixer* getGlobalMasterMixer();
     static Mixer* getGlobalMasterMixerNoFalback();
+    static MasterControl& getGlobalMasterPreferred();
 
     /******************************************
     The recommended master of this Mixer.
@@ -197,8 +199,8 @@
     QString _id;
     QString _masterDevicePK;
     int    _cardInstance;
-    static QString _globalMasterCard;
-    static QString _globalMasterCardDevice;
+    static MasterControl _globalMasterCurrent;
+    static MasterControl _globalMasterPreferred;
 
     QString m_dbusName;
     bool m_dynamic;
--- trunk/KDE/kdemultimedia/kmix/core/mixertoolbox.cpp #1210981:1210982
@@ -177,10 +177,13 @@
       // not one defined in the kmixrc.
       // So lets just set the first card as master card.
       if ( Mixer::mixers().count() > 0 ) {
-         QString controlId = Mixer::mixers().first()->getLocalMasterMD()->id();
-         Mixer::setGlobalMaster( Mixer::mixers().first()->id(), controlId);
+         MixDevice* master = Mixer::mixers().first()->getLocalMasterMD();
+         if ( master != 0 ) {
+             QString controlId = master->id();
+             Mixer::setGlobalMaster( Mixer::mixers().first()->id(), controlId, \
true);  }
    }
+   }
    else {
       // setGlobalMaster was already set after reading the configuration.
       // So we must make the local master consistent
--- trunk/KDE/kdemultimedia/kmix/gui/dialogaddview.cpp #1210981:1210982
@@ -229,9 +229,6 @@
          return; // can not happen
       }
       else {
-          //mixer->setLocalMasterMD( control_id );
-          //Mixer::setGlobalMaster(mixer->id(), control_id);
-          //emit newMasterSelected( mixer->id(), control_id );
           kDebug() << "We should now create a new view " << viewName << " for mixer \
" << mixer->id();  resultMixerId = mixer->id();
           resultViewName = viewName;
--- trunk/KDE/kdemultimedia/kmix/gui/dialogselectmaster.cpp #1210981:1210982
@@ -223,7 +223,7 @@
       }
       else {
           mixer->setLocalMasterMD( control_id );
-          Mixer::setGlobalMaster(mixer->id(), control_id);
+          Mixer::setGlobalMaster(mixer->id(), control_id, true);
           emit newMasterSelected( mixer->id(), control_id );
       }
    }
--- trunk/KDE/kdemultimedia/kmix/gui/kmixdockwidget.cpp #1210981:1210982
@@ -191,17 +191,7 @@
       use deleteLater(), as we are executing in a SLOT currently.
     */
    _kmixMainWindow->updateDocking();
-/*
-    Mixer *mixer = MixerToolBox::instance()->find(mixerID);
-    if ( mixer == 0 ) {
-        kError(67100) << "KMixDockWidget::createPage(): Invalid Mixer (mixerID=" << \
                mixerID << ")" << endl;
-        return; // can not happen
    }
-   m_mixer = mixer;
-   //Mixer::setGlobalMaster(mixer->id(), control_id); // We must save this \
                information "somewhere".
-   createMasterVolWidget();
-*/
-}
 
 
 void
--- trunk/KDE/kdemultimedia/kmix/tests/CMakeLists.txt #1210981:1210982
@@ -12,6 +12,7 @@
 
 kde4_add_executable(profiletest ${profiletest_SRCS} 
     ${CMAKE_CURRENT_SOURCE_DIR}/../gui/guiprofile.cpp 
+    ${CMAKE_CURRENT_SOURCE_DIR}/../core/MasterControl.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../core/mixer.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../core/mixdevice.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../core/volume.cpp


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic