SVN commit 1251007 by esken: CCBUGS: 249508 Implement proper minimum volume level (remove old buggy average calculation) M +5 -23 core/volume.cpp M +0 -2 core/volume.h M +3 -4 gui/kmixdockwidget.cpp --- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1251006:1251007 @@ -180,25 +180,6 @@ return _maxVolume - _minVolume + 1; } - -int Volume::percentage(long absoluteVolume) -{ - int relativeVolume = 0; - if ( _maxVolume == 0 ) - return 0; - - if ( absoluteVolume > _maxVolume ) - relativeVolume = 100; - else if ( absoluteVolume < _minVolume ) - relativeVolume = -100; - else if ( absoluteVolume > 0 ) - relativeVolume = ( 100*absoluteVolume) / _maxVolume; - else if ( absoluteVolume < 0 ) - relativeVolume = ( 100*absoluteVolume) / _minVolume; - - return relativeVolume; -} - long Volume::getVolume(ChannelID chid) { return _volumesL.value(chid).volume; } @@ -226,11 +207,12 @@ int Volume::getAvgVolumePercent(ChannelMask chmask) { long volume = getAvgVolume(chmask); - // min=-100, max=200 => volSpane = 300 - // volume = -50 => volumePoistive = -50+min = 50 + // min=-100, max=200 => volSpan = 301 + // volume = -50 => volShiftedToZero = -50+min = 50 long volSpan = volumeSpan(); - long volShiftedToPositive = volume + _minVolume; - int percent = ( volSpan == 0 ) ? 0 : ( 100 * volShiftedToPositive ) / volSpan; + long volShiftedToZero = volume - _minVolume; + int percent = ( volSpan == 0 ) ? 0 : ( 100 * volShiftedToZero ) / ( volSpan - 1); + kDebug() << "volSpan=" << volSpan << ", volume=" << volume << ", volShiftedToPositive=" << volShiftedToZero << ", percent=" << percent; return percent; } --- trunk/KDE/kdemultimedia/kmix/core/volume.h #1251006:1251007 @@ -119,8 +119,6 @@ * The number of valid volume levels, mathematically: maxVolume - minVolume + 1 */ long volumeSpan(); - - int percentage(long ); int count(); bool hasSwitch() { return _hasSwitch; } // TODO { return _hasSwitch || hasVolume() ; } // "|| hasVolume()", because we simulate a switch, if it is not available as hardware. --- trunk/KDE/kdemultimedia/kmix/gui/kmixdockwidget.cpp #1251006:1251007 @@ -223,7 +223,7 @@ { // Playback volume will be used for the DockIcon if available. // This heuristic is "good enough" for the DockIcon for now. - long val = 0; + int val = 0; Volume& vol = md->playbackVolume(); if (! vol.hasVolume() ) { vol = md->captureVolume(); @@ -271,8 +271,7 @@ if (! vol.hasVolume() ) { vol = md->captureVolume(); } - long absoluteVolume = vol.getAvgVolume(Volume::MALL); - int percentage = vol.percentage(absoluteVolume); + int percentage = vol.getAvgVolumePercent(Volume::MALL); if ( percentage <= 0 ) newPixmapType = '0'; // Hint: also negative-values else if ( percentage < 25 ) newPixmapType = '1'; else if ( percentage < 75 ) newPixmapType = '2'; @@ -396,7 +395,7 @@ long int cv = inc * (delta / 120 ); // kDebug() << "twe: " << cv << " : " << vol; if ( cv > 0 && md->isMuted()) - { // increasing form muted state: unmute and start with a low volume level + { // increasing from muted state: unmute and start with a low volume level md->setMuted(false); vol.setAllVolumes(cv); }