diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-18 00:59:50 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-25 13:37:57 +0900 |
commit | 92f069b7da22a6bc3be2c6f2903a7166ae58bc45 (patch) | |
tree | cf413afe59db83f3df9ae9ed4bcd81f286b30319 /kmix | |
parent | 9859df0541de6016cacea2032d5fe75e98b53a0b (diff) | |
download | tdemultimedia-92f069b7da22a6bc3be2c6f2903a7166ae58bc45.tar.gz tdemultimedia-92f069b7da22a6bc3be2c6f2903a7166ae58bc45.zip |
KMix: fixed handling of slider's mute/unmute and wheel events. Fixed mixer's increase/decrease volume logic.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit c0249fdb66a93f3fd3b413f8c05d455f05ae8cdb)
Diffstat (limited to 'kmix')
-rw-r--r-- | kmix/mixer.cpp | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/kmix/mixer.cpp b/kmix/mixer.cpp index 2b48f512..d020ef47 100644 --- a/kmix/mixer.cpp +++ b/kmix/mixer.cpp @@ -528,6 +528,11 @@ void Mixer::setVolume( int deviceidx, int percentage ) void Mixer::commitVolumeChange( MixDevice* md ) { _mixerBackend->writeVolumeToHW(md->num(), md->getVolume() ); _mixerBackend->setEnumIdHW(md->num(), md->enumId() ); + + // Muting/unmuting PulseAudio directly does not send back any notification to the mixer + // so we make sure we always update the tray icon after each operation. + readSetFromHWforceUpdate(); + TQTimer::singleShot(50, this, TQT_SLOT(readSetFromHW())); } // @dcop only @@ -625,51 +630,42 @@ int Mixer::masterVolume() void Mixer::increaseVolume( int deviceidx ) { MixDevice *mixdev= mixDeviceByType( deviceidx ); - if (mixdev != 0) { - Volume vol=mixdev->getVolume(); - double fivePercent = (vol.maxVolume()-vol.minVolume()+1) / 20; - for (unsigned int i=Volume::CHIDMIN; i <= Volume::CHIDMAX; i++) { - int volToChange = vol.getVolume((Volume::ChannelID)i); - if ( fivePercent < 1 ) fivePercent = 1; - volToChange += (int)fivePercent; - vol.setVolume((Volume::ChannelID)i, volToChange); - } - _mixerBackend->writeVolumeToHW(deviceidx, vol); + if (mixdev != 0) + { + Volume vol = mixdev->getVolume(); + long inc = vol.maxVolume() / 20; + if (inc == 0) + { + inc = 1; + } + for (int i = 0; i < vol.count(); i++) + { + long newVal = (vol[i]) + inc; + mixdev->setVolume(i, newVal < vol.maxVolume() ? newVal : vol.maxVolume()); + } + commitVolumeChange(mixdev); } - - /* see comment at the end of decreaseVolume() - int vol=volume(deviceidx); - setVolume(deviceidx, vol+5); - */ } // @dcop void Mixer::decreaseVolume( int deviceidx ) { MixDevice *mixdev= mixDeviceByType( deviceidx ); - if (mixdev != 0) { - Volume vol=mixdev->getVolume(); - double fivePercent = (vol.maxVolume()-vol.minVolume()+1) / 20; - for (unsigned int i=Volume::CHIDMIN; i <= Volume::CHIDMAX; i++) { - int volToChange = vol.getVolume((Volume::ChannelID)i); - //std::cout << "Mixer::decreaseVolume(): before: volToChange " <<i<< "=" <<volToChange << std::endl; - if ( fivePercent < 1 ) fivePercent = 1; - volToChange -= (int)fivePercent; - //std::cout << "Mixer::decreaseVolume(): after: volToChange " <<i<< "=" <<volToChange << std::endl; - vol.setVolume((Volume::ChannelID)i, volToChange); - //int volChanged = vol.getVolume((Volume::ChannelID)i); - //std::cout << "Mixer::decreaseVolume(): check: volChanged " <<i<< "=" <<volChanged << std::endl; - } // for - _mixerBackend->writeVolumeToHW(deviceidx, vol); + if (mixdev != 0) + { + Volume vol = mixdev->getVolume(); + long inc = vol.maxVolume() / 20; + if (inc == 0) + { + inc = 1; + } + for (int i = 0; i < vol.count(); i++) + { + long newVal = (vol[i]) - inc; + mixdev->setVolume(i, newVal > 0 ? newVal : 0); + } + commitVolumeChange(mixdev); } - - /************************************************************ - It is important, not to implement this method like this: - int vol=volume(deviceidx); - setVolume(deviceidx, vol-5); - It creates too big rounding errors. If you don't beleive me, then - do a decreaseVolume() and increaseVolume() with "vol.maxVolume() == 31". - ***********************************************************/ } // @dcop @@ -699,16 +695,8 @@ void Mixer::toggleMute( int deviceidx ) MixDevice *mixdev= mixDeviceByType( deviceidx ); if (!mixdev) return; - bool previousState= mixdev->isMuted(); - - mixdev->setMuted( !previousState ); - - _mixerBackend->writeVolumeToHW(deviceidx, mixdev->getVolume()); - - // Muting/unmuting PulseAudio directly does not send back any notification to the mixer - // so we make sure we always update the tray icon after each operation. - readSetFromHWforceUpdate(); - TQTimer::singleShot(50, this, TQT_SLOT(readSetFromHW())); + mixdev->setMuted(!mixdev->isMuted()); + commitVolumeChange(mixdev); } // @dcop only |