diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-20 01:19:55 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-25 13:24:33 +0900 |
commit | b06d352d14d9d917ff23288dd6a9433e4e75f7df (patch) | |
tree | 5518cf17eab0c4d4f3d76e02c610deccbea63339 /kmix/mixer.cpp | |
parent | c0249fdb66a93f3fd3b413f8c05d455f05ae8cdb (diff) | |
download | tdemultimedia-b06d352d14d9d917ff23288dd6a9433e4e75f7df.tar.gz tdemultimedia-b06d352d14d9d917ff23288dd6a9433e4e75f7df.zip |
KMix: 1) added direct DCOP access to the user selected mixer/device channel used as master.
2) fixed bug with volume update
3) unlinked global keyboard shortcuts for volume control to avoid
clashing with kmilo. A user can still link them manually if needed.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kmix/mixer.cpp')
-rw-r--r-- | kmix/mixer.cpp | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/kmix/mixer.cpp b/kmix/mixer.cpp index 9e3aa359..0cc4fbcf 100644 --- a/kmix/mixer.cpp +++ b/kmix/mixer.cpp @@ -514,6 +514,9 @@ void Mixer::setVolume( int deviceidx, int percentage ) // @todo The next call doesn't handle negative volumes correctly. vol.setAllVolumes( (percentage*vol.maxVolume())/100 ); _mixerBackend->writeVolumeToHW(deviceidx, vol); + // Make sure volume reading is synced + readSetFromHWforceUpdate(); + TQTimer::singleShot(50, this, TQT_SLOT(readSetFromHW())); } /** @@ -579,12 +582,15 @@ void Mixer::setAbsoluteVolume( int deviceidx, long absoluteVolume ) { Volume vol=mixdev->getVolume(); vol.setAllVolumes( absoluteVolume ); _mixerBackend->writeVolumeToHW(deviceidx, vol); + // Make sure volume reading is synced + readSetFromHWforceUpdate(); + TQTimer::singleShot(50, this, TQT_SLOT(readSetFromHW())); } // @dcop , especially for use in KMilo -long Mixer::absoluteVolume( int deviceidx ) +long Mixer::absoluteVolume(int deviceidx) { - MixDevice *mixdev= mixDeviceByType( deviceidx ); + MixDevice *mixdev= mixDeviceByType(deviceidx); if (!mixdev) return 0; Volume vol=mixdev->getVolume(); @@ -593,9 +599,9 @@ long Mixer::absoluteVolume( int deviceidx ) } // @dcop , especially for use in KMilo -long Mixer::absoluteVolumeMax( int deviceidx ) +long Mixer::absoluteVolumeMax(int deviceidx) { - MixDevice *mixdev= mixDeviceByType( deviceidx ); + MixDevice *mixdev= mixDeviceByType(deviceidx); if (!mixdev) return 0; Volume vol=mixdev->getVolume(); @@ -604,9 +610,9 @@ long Mixer::absoluteVolumeMax( int deviceidx ) } // @dcop , especially for use in KMilo -long Mixer::absoluteVolumeMin( int deviceidx ) +long Mixer::absoluteVolumeMin(int deviceidx) { - MixDevice *mixdev= mixDeviceByType( deviceidx ); + MixDevice *mixdev= mixDeviceByType(deviceidx); if (!mixdev) return 0; Volume vol=mixdev->getVolume(); @@ -626,44 +632,54 @@ int Mixer::masterVolume() } // @dcop -void Mixer::increaseVolume( int deviceidx ) +void Mixer::increaseVolume(int deviceidx, int percentage) { - MixDevice *mixdev= mixDeviceByType( deviceidx ); - if (mixdev != 0) + MixDevice *mixdev= mixDeviceByType(deviceidx); + if (mixdev && percentage > 0) { Volume vol = mixdev->getVolume(); - long inc = vol.maxVolume() / 20; - if (inc == 0) - { - inc = 1; - } - for (int i = 0; i < vol.count(); i++) + long maxVol = vol.maxVolume(); + if (maxVol > 0) { - long newVal = (vol[i]) + inc; - mixdev->setVolume(i, newVal < vol.maxVolume() ? newVal : vol.maxVolume()); + for (int i = 0; i < vol.count(); i++) + { + double perc = 100.0 * vol[i] / maxVol; + perc += percentage; + if (perc > 100.0) + { + perc = 100.0; + } + long newVal = (long)(perc * maxVol / 100.0); + mixdev->setVolume(i, newVal); + } + commitVolumeChange(mixdev); } - commitVolumeChange(mixdev); } } // @dcop -void Mixer::decreaseVolume( int deviceidx ) +void Mixer::decreaseVolume(int deviceidx, int percentage) { - MixDevice *mixdev= mixDeviceByType( deviceidx ); - if (mixdev != 0) + MixDevice *mixdev= mixDeviceByType(deviceidx); + if (mixdev && percentage > 0) { Volume vol = mixdev->getVolume(); - long inc = vol.maxVolume() / 20; - if (inc == 0) - { - inc = 1; - } - for (int i = 0; i < vol.count(); i++) + long maxVol = vol.maxVolume(); + if (maxVol > 0) { - long newVal = (vol[i]) - inc; - mixdev->setVolume(i, newVal > 0 ? newVal : 0); + for (int i = 0; i < vol.count(); i++) + { + double perc = 100.0 * vol[i] / maxVol; + perc -= percentage; + if (perc < 0.0) + { + perc = 0.0; + } + long newVal = (long)(perc * maxVol / 100.0); + mixdev->setVolume(i, newVal); + } + commitVolumeChange(mixdev); } - commitVolumeChange(mixdev); } } |