[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-07-21 23:14:58
Message-ID: 20110721231458.7033CAC882 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1242590 by esken:

More refactoring of Volume/VolumeChannel. KMix works again.

 M  +0 -4      backends/mixer_alsa9.cpp  
 M  +1 -4      core/mixdevice.cpp  
 M  +7 -7      core/mixdevicecomposite.cpp  
 M  +2 -2      core/mixdevicecomposite.h  
 M  +49 -88    core/volume.cpp  
 M  +8 -2      core/volume.h  
 M  +5 -2      gui/mdwslider.cpp  


--- trunk/KDE/kdemultimedia/kmix/backends/mixer_alsa9.cpp #1242589:1242590
@@ -390,10 +390,6 @@
     Volume* vol = 0;
     long maxVolume = 0, minVolume = 0;
 
-    // --- Regular control (not enumerated) ---
-    Volume::ChannelMask chn = Volume::MNONE;
-
-
     // Add volumes
     if ( !capture && snd_mixer_selem_has_playback_volume(elem) ) {
         snd_mixer_selem_get_playback_volume_range( elem, &minVolume, &maxVolume );
--- trunk/KDE/kdemultimedia/kmix/core/mixdevice.cpp #1242589:1242590
@@ -88,10 +88,7 @@
  * the mixer hardware. A MixDevice has a type (e.g. PCM), a descriptive name
  * (for example "Master" or "Headphone" or "IEC 958 Output"),
  * can have a volume level (2 when stereo), can be recordable and muted.
- * The category tells which kind of control the MixDevice is.
- *
- * Hints: Meaning of "category" has changed. In future the MixDevice might contain \
                two
- * Volume objects, one for Output (Playback volume) and one for Input (Record \
volume). + * The ChannelType tells which kind of control the MixDevice is.
  */
 MixDevice::MixDevice(  Mixer* mixer, const QString& id, const QString& name, \
ChannelType type )  {
--- trunk/KDE/kdemultimedia/kmix/core/mixdevicecomposite.cpp #1242589:1242590
@@ -31,7 +31,7 @@
     setArtificial(true);
     _compositePlaybackVolume = new Volume( MixDeviceComposite::VolMax, 0, true, \
false);  _compositePlaybackVolume->addVolumeChannels(Volume::MMAIN);
-    _compositeCaptureVolume  = new Volume();
+//    _compositeCaptureVolume  = new Volume();
 
     QListIterator<MixDevice*> it(mds);
     while ( it.hasNext()) {
@@ -47,7 +47,7 @@
         _mds.removeAt(0);
     }
     delete _compositePlaybackVolume;
-    delete _compositeCaptureVolume;
+//    delete _compositeCaptureVolume;
 }
 
 
@@ -57,10 +57,10 @@
     return *_compositePlaybackVolume;
 }
 
-Volume& MixDeviceComposite::captureVolume()
-{
-    return *_compositeCaptureVolume;
-}
+// Volume& MixDeviceComposite::captureVolume()
+// {
+//     return *_compositeCaptureVolume;
+// }
 
 
 void MixDeviceComposite::update()
@@ -69,7 +69,7 @@
     volAvg = calculateVolume( Volume::PlaybackVT  );
     _compositePlaybackVolume->setAllVolumes(volAvg);
     volAvg = calculateVolume( Volume::CaptureVT );
-    _compositeCaptureVolume->setAllVolumes(volAvg);
+//     _compositeCaptureVolume->setAllVolumes(volAvg);
 
 }
 
--- trunk/KDE/kdemultimedia/kmix/core/mixdevicecomposite.h #1242589:1242590
@@ -93,7 +93,7 @@
    void update();
 
    virtual Volume& playbackVolume();
-   virtual Volume& captureVolume();
+   //virtual Volume& captureVolume();
 
 private:
    long calculateVolume(Volume::VolumeType vt);
@@ -104,7 +104,7 @@
    static const long VolMax;
 
    Volume* _compositePlaybackVolume;
-   Volume* _compositeCaptureVolume;
+ //  Volume* _compositeCaptureVolume;
 };
 
 #endif
--- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1242589:1242590
@@ -52,10 +52,9 @@
       "volumeRearCenter"
     };
     
-Volume::Volume()
-{
-    init( Volume::MNONE, 0, 0, false, false);
-}
+    // Forbidden/private. Only here because QMap requires it. 
+Volume::Volume() {}
+VolumeChannel::VolumeChannel() {}
 
 // @Deprecated  use method without chmask
 // Volume::Volume( ChannelMask chmask, long maxVolume, long minVolume, bool \
hasSwitch, bool isCapture  ) @@ -112,7 +111,7 @@
     _switchActivated = false;
 }
 
-    QMap<Volume::ChannelID, VolumeChannel> Volume::getVolumes()
+    QMap<Volume::ChannelID, VolumeChannel> Volume::getVolumes() const
     {
       return _volumesL;
     }
@@ -129,23 +128,27 @@
 
 void Volume::changeAllVolumes( long step )
 {
-  foreach (VolumeChannel vc, _volumesL )
+  QMap<Volume::ChannelID, VolumeChannel>::iterator it = _volumesL.begin();
+  while (it != _volumesL.end())
   {
+    it.value().volume = volrange(it.value().volume + step);
+    ++it;
+    //VolumeChannel &vc = it.value();
+  }
+/*  foreach (const VolumeChannel& vc, _volumesL )
+  {
+    kDebug(67100) << &vc << " : " ; 
     vc.volume = volrange(vc.volume + step);
+    kDebug(67100) << &vc << " : " ; 
+  }*/
   }
-}
 
 
 // @ compatibility
 void Volume::setVolume( ChannelID chid, long vol)
 {
-    if ( chid>=0 && chid<=Volume::CHIDMAX ) {
-        // accepted. we don't care if we support the channel,
-        // because there is NO good action we could take.
-        // Anyway: getVolume() on an unsupported channel will return 0 all the time
-        _volumes[chid] = volrange(vol);
+  _volumesL[chid].volume = vol;
     }
-}
 
 /**
  * Copy the volume elements contained in v to this Volume object.
@@ -161,20 +164,18 @@
  * Only those elments are copied, that are supported in BOTH Volume objects
  * and match the ChannelMask given by chmask.
  */
-void Volume::setVolume(const Volume &v, ChannelMask chmask) {
-    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
-        if ( _channelMaskEnum[i] & _chmask & (int)chmask ) {
-            // we are supposed to copy it
-            _volumes[i] = volrange(v._volumes[i]);
+void Volume::setVolume(const Volume &v, ChannelMask chmask)
+{
+  foreach (VolumeChannel vc, _volumesL )
+  {
+    ChannelID chid = vc.chid;
+    if ( v.getVolumes().contains(chid) && (Volume::_channelMaskEnum[chid] & chmask) \
) +    {
+      v.getVolumes()[chid].volume = vc.volume;
         }
-	else {
-	    // Safety first! Lets play safe here and put sane values in
-	    _volumes[i] = 0;
 	}
     }
 
-}
-
 long Volume::maxVolume() {
   return _maxVolume;
 }
@@ -201,61 +202,33 @@
    return relativeVolume;
 }
 
-
-// @ compatibility
-// long Volume::operator[](int id) {
-//   return getVolume( (Volume::ChannelID) id );
-// }
-
 long Volume::getVolume(ChannelID chid) {
-  long vol = 0;
-
-  if ( chid < 0 || chid > (Volume::CHIDMAX) ) {
-    // should throw exception here. I will return 0 instead
+  return _volumesL.value(chid).volume;
   }
-  else {
-    // check if channel is supported
-    int chmask = _channelMaskEnum[chid];
-    if ( (chmask & _chmask) != 0 ) {
-       // channel is supported
-      vol = _volumes[chid];
-    }
-    else {
-      // should throw exception here. I will return 0 instead
-    }
-  }
 
-  return vol;
-}
-
-long Volume::getAvgVolume(ChannelMask chmask) {
+long Volume::getAvgVolume(ChannelMask chmask)
+{
     int avgVolumeCounter = 0;
-    long long sumOfActiveVolumes = 0;
-    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
-        if ( (_channelMaskEnum[i] & _chmask) & (int)chmask ) {
-            avgVolumeCounter++;
-            sumOfActiveVolumes += _volumes[i];
+  long long sumOfActiveVolumes = _volumesL.size();
+  foreach (VolumeChannel vc, _volumesL )
+  {
+    if (Volume::_channelMaskEnum[vc.chid] & chmask )
+    {
+      sumOfActiveVolumes += vc.volume;
+      ++avgVolumeCounter;
         }
     }
     if (avgVolumeCounter != 0) {
         sumOfActiveVolumes /= avgVolumeCounter;
     }
-    else {
-        // just return 0;
-    }
+    // else: just return 0;
     return (long)sumOfActiveVolumes;
 }
 
 
 int Volume::count() {
-    int counter = 0;
-    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
-        if ( _channelMaskEnum[i] & _chmask ) {
-            counter++;
+  return getVolumes().count();
         }
-    }
-    return counter;
-}
 
 /**
   * returns a "sane" volume level. This means, it is a volume level inside the
@@ -277,18 +250,13 @@
 
 std::ostream& operator<<(std::ostream& os, const Volume& vol) {
     os << "(";
-    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
-	if ( i != 0 ) {
-	    os << ",";
-	}
-	if ( Volume::_channelMaskEnum[i] & vol._chmask ) {
-	    // supported channel: Print Volume
-	    os << vol._volumes[i];
-	}
-	else {
-	    // unsupported channel: Print "x"
-	    os << "x";
-	}
+
+    bool first = true;
+    foreach ( const VolumeChannel vc, vol.getVolumes() )
+    {
+	if ( !first )  os << ",";
+	else first = false;
+        os << vc.volume;
     } // all channels
     os << ")";
 
@@ -300,24 +268,17 @@
 
 QDebug operator<<(QDebug os, const Volume& vol) {
     os << "(";
-    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
-	if ( i != 0 ) {
-	    os << ",";
-	}
-	if ( Volume::_channelMaskEnum[i] & vol._chmask ) {
-	    // supported channel: Print Volume
-	    os << vol._volumes[i];
-	}
-	else {
-	    // unsupported channel: Print "x"
-	    os << "x";
-	}
+    bool first = true;
+    foreach ( VolumeChannel vc, vol.getVolumes() )
+    {
+	if ( !first )  os << ",";
+	else first = false;
+        os << vc.volume;
     } // all channels
     os << ")";
 
     os << " [" << vol._minVolume << "-" << vol._maxVolume;
     if ( vol._switchActivated ) { os << " : switch active ]"; } else { os << " : \
                switch inactive ]"; }
-//     if ( vol._muted ) { os << " : muted ]"; } else { os << " : playing ]"; }
 
     return os;
 }
--- trunk/KDE/kdemultimedia/kmix/core/volume.h #1242589:1242590
@@ -89,9 +89,11 @@
     // Volume( int channels, long maxVolume );
     // copy constructor
     Volume( const Volume &v );
+private:
     // constructor for dummy volumes
     Volume();
     
+public:
     /// @Deprecated
     void addVolumeChannels(ChannelMask chmask);
     
@@ -132,11 +134,10 @@
     // _channelMaskEnum[] and the following elements moved to public seection. \
                operator<<() could not
     // access it, when private. Strange, as operator<<() is declared friend.
     static int    _channelMaskEnum[9];
-    QMap<Volume::ChannelID, VolumeChannel> getVolumes();
+    QMap<Volume::ChannelID, VolumeChannel> getVolumes() const;
     
 protected:
     long          _chmask;
-    long          _volumes[CHIDMAX+1];
     QMap<Volume::ChannelID, VolumeChannel> _volumesL;
 
     long          _minVolume;
@@ -164,6 +165,11 @@
   VolumeChannel(Volume::ChannelID chid) { volume =0; this->chid = chid; }
   long volume;
   Volume::ChannelID chid;
+  
+// protected:
+//   friend class Volume;
+//   friend class MixDevice;
+  VolumeChannel(); // Only required for QMap
 };
 
 std::ostream& operator<<(std::ostream& os, const Volume& vol);
--- trunk/KDE/kdemultimedia/kmix/gui/mdwslider.cpp #1242589:1242590
@@ -513,7 +513,7 @@
 			    QString subcontrolTranslation = Volume::ChannelNameReadable[vc.chid]; \
                //Volume::getSubcontrolTranslation(chid);
 			    QWidget *subcontrolLabel = createLabel(this, subcontrolTranslation, \
volLayout, true);  ref_labels.append ( subcontrolLabel ); // add to list
-			if( first && isStereoLinked() ) {
+			if( !first && isStereoLinked() ) {
 				// show only one (the first) slider, when the user wants it so
 				subcontrolLabel->hide();
 			}			  
@@ -556,7 +556,7 @@
 				slider->setToolTip( captureTip );
 			}
 
-			if( first && isStereoLinked() ) {
+			if( !first && isStereoLinked() ) {
 				// show only one (the first) slider, when the user wants it so
 				slider->hide();
 			}
@@ -895,7 +895,9 @@
 	long inc = volP.maxVolume() / 20;
 	if ( inc == 0 )	inc = 1;
 	if ( decrease ) inc *= -1;
+	kDebug(67100) << &volP << " Before. decrease=" <<decrease << ": " << volP;
 	volP.changeAllVolumes(inc);
+	kDebug(67100) << &volP << "After . decrease=" <<decrease << ": " << volP;
 
 	Volume& volC = m_mixdevice->captureVolume();
 	inc = volC.maxVolume() / 20;
@@ -904,6 +906,7 @@
 	volC.changeAllVolumes(inc);
 
 	m_mixdevice->mixer()->commitVolumeChange(m_mixdevice);
+	kDebug(67100) << &volP << "Commit. decrease=" <<decrease << ": " << volP;
 }
 
 /**


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

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