From b06d352d14d9d917ff23288dd6a9433e4e75f7df Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 20 May 2020 01:19:55 +0900 Subject: 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 --- kmix/mixer.cpp | 76 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 30 deletions(-) (limited to 'kmix/mixer.cpp') 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); } } -- cgit v1.2.3