SVN commit 1250844 by esken: CCBUGS: 249508 Implement proper minimum volume level (and the volumeSpan() helper) M +1 -5 apps/kmix.cpp M +4 -2 core/mixer.cpp M +9 -4 core/mixer.h M +18 -1 core/volume.cpp M +9 -2 core/volume.h M +3 -6 dbus/dbuscontrolwrapper.cpp M +2 -2 gui/kmixdockwidget.cpp M +4 -4 gui/mdwslider.cpp M +3 -0 gui/osdwidget.cpp --- trunk/KDE/kdemultimedia/kmix/apps/kmix.cpp #1250843:1250844 @@ -1062,12 +1062,8 @@ if ( md == 0 ) return; // shouldn't happen, but lets play safe // Current volume Volume& vol = md->playbackVolume(); - int currentVolume = 0; - if ( vol.hasVolume() && vol.maxVolume() != 0 ) { - currentVolume = (vol.getAvgVolume(Volume::MMAIN)*100 )/( vol.maxVolume() ); - } - osdWidget->setCurrentVolume(currentVolume, md->isMuted()); + osdWidget->setCurrentVolume(vol.getAvgVolumePercent(Volume::MALL), md->isMuted()); osdWidget->show(); osdWidget->activateOSD(); //Enable the hide timer --- trunk/KDE/kdemultimedia/kmix/core/mixer.cpp #1250843:1250844 @@ -537,7 +537,8 @@ if (md != 0) { Volume& volP=md->playbackVolume(); if ( volP.hasVolume() ) { - double step = (volP.maxVolume()-volP.minVolume()+1) / Mixer::VOLUME_STEP_DIVISOR; + long volSpan = volP.volumeSpan(); + double step = volSpan / Mixer::VOLUME_STEP_DIVISOR; if ( step < 1 ) step = 1; if ( decrease ) step = -step; volP.changeAllVolumes(step); @@ -545,7 +546,8 @@ Volume& volC=md->captureVolume(); if ( volC.hasVolume() ) { - double step = (volC.maxVolume()-volC.minVolume()+1) / Mixer::VOLUME_STEP_DIVISOR; + long volSpan = volC.volumeSpan(); + double step = volSpan / Mixer::VOLUME_STEP_DIVISOR; if ( step < 1 ) step = 1; if ( decrease ) step = -step; volC.changeAllVolumes(step); --- trunk/KDE/kdemultimedia/kmix/core/mixer.h #1250843:1250844 @@ -97,10 +97,12 @@ /// Returns a detailed state message after errors. Only for diagnostic purposes, no i18n. QString& stateMessage() const; - /// Returns the name of the card/chip/hardware, as given by the driver. The name is NOT instance specific, - /// so if you install two identical soundcards, two of them will deliver the same mixerName(). - /// Use this method if you need an instance-UNspecific name, e.g. for finding an appropriate - /// mixer layout for this card, or as a prefix for constructing instance specific ID's like in id(). + /** + * Returns the name of the card/chip/hardware, as given by the driver. The name is NOT instance specific, + * so if you install two identical soundcards, two of them will deliver the same mixerName(). + * Use this method if you need an instance-UNspecific name, e.g. for finding an appropriate + * mixer layout for this card, or as a prefix for constructing instance specific ID's like in id(). + */ virtual QString getBaseName(); /// Wrapper to Mixer_Backend @@ -114,6 +116,9 @@ /// Returns an unique ID of the Mixer. It currently looks like ":::" QString& id(); + + // TODO nontranslated mixer names + /// The owner/creator of the Mixer can set an unique name here. This key should never displayed to /// the user, but can be used for referencing configuration items and such. --- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1250843:1250844 @@ -176,6 +176,11 @@ return _minVolume; } +long Volume::volumeSpan() { + return _maxVolume - _minVolume + 1; +} + + int Volume::percentage(long absoluteVolume) { int relativeVolume = 0; @@ -218,6 +223,18 @@ } +int Volume::getAvgVolumePercent(ChannelMask chmask) +{ + long volume = getAvgVolume(chmask); + // min=-100, max=200 => volSpane = 300 + // volume = -50 => volumePoistive = -50+min = 50 + long volSpan = volumeSpan(); + long volShiftedToPositive = volume + _minVolume; + int percent = ( volSpan == 0 ) ? 0 : ( 100 * volShiftedToPositive ) / volSpan; + + return percent; +} + int Volume::count() { return getVolumes().count(); } @@ -226,7 +243,7 @@ * returns a "sane" volume level. This means, it is a volume level inside the * valid bounds */ -long Volume::volrange( int vol ) +long Volume::volrange( long vol ) { if ( vol < _minVolume ) { return _minVolume; --- trunk/KDE/kdemultimedia/kmix/core/volume.h #1250843:1250844 @@ -110,13 +110,20 @@ long getVolume(ChannelID chid); long getAvgVolume(ChannelMask chmask); + int getAvgVolumePercent(ChannelMask chmask); + //long operator[](int); long maxVolume(); long minVolume(); + /** + * The number of valid volume levels, mathematically: maxVolume - minVolume + 1 + */ + long volumeSpan(); + int percentage(long ); int count(); - bool hasSwitch() { return _hasSwitch; } + bool hasSwitch() { return _hasSwitch; } // TODO { return _hasSwitch || hasVolume() ; } // "|| hasVolume()", because we simulate a switch, if it is not available as hardware. bool hasVolume() { return (_maxVolume != _minVolume); } bool isCapture() { return _isCapture; } // -<- Query thsi, to find out whether this is a capture or a playback volume @@ -151,7 +158,7 @@ private: void init( ChannelMask chmask, long maxVolume, long minVolume, bool hasSwitch, bool isCapture); - long volrange( int vol ); + long volrange( long vol ); bool _hasSwitch; bool _switchActivated; --- trunk/KDE/kdemultimedia/kmix/dbus/dbuscontrolwrapper.cpp #1250843:1250844 @@ -69,17 +69,14 @@ // - esken Volume& volP = m_md->playbackVolume(); Volume& volC = m_md->captureVolume(); - volP.setAllVolumes( (percentage * volP.maxVolume()) / 100 ); - volC.setAllVolumes( (percentage * volP.maxVolume()) / 100 ); + volP.setAllVolumes( volP.minVolume() + ((percentage * volP.volumeSpan()) / 100) ); + volC.setAllVolumes( volC.minVolume() + ((percentage * volC.volumeSpan()) / 100) ); m_md->mixer()->commitVolumeChange( m_md ); } int DBusControlWrapper::volume() { - Volume& vol = m_md->playbackVolume(); - return vol.maxVolume() - ? vol.getAvgVolume( Volume::MMAIN ) * 100 / vol.maxVolume() - : 0; + return m_md->playbackVolume().getAvgVolumePercent(Volume::MALL); } void DBusControlWrapper::increaseVolume() --- trunk/KDE/kdemultimedia/kmix/gui/kmixdockwidget.cpp #1250843:1250844 @@ -229,7 +229,7 @@ vol = md->captureVolume(); } if ( vol.hasVolume() ) { - val = (vol.getAvgVolume(Volume::MMAIN)*100 )/( vol.maxVolume() ); + val = vol.getAvgVolumePercent(Volume::MALL); } // create a new "virtual" value. With that we see "volume changes" as well as "muted changes" @@ -389,7 +389,7 @@ if ( md != 0 ) { Volume &vol = ( md->playbackVolume().hasVolume() ) ? md->playbackVolume() : md->captureVolume(); - int inc = vol.maxVolume() / Mixer::VOLUME_STEP_DIVISOR; + int inc = vol.volumeSpan() / Mixer::VOLUME_STEP_DIVISOR; if ( inc < 1 ) inc = 1; --- trunk/KDE/kdemultimedia/kmix/gui/mdwslider.cpp #1250843:1250844 @@ -542,12 +542,12 @@ QAbstractSlider* slider; if ( m_small ) { - slider = new KSmallSlider( minvol, maxvol, (maxvol-minvol) / Mixer::VOLUME_PAGESTEP_DIVISOR, + slider = new KSmallSlider( minvol, maxvol, (maxvol-minvol+1) / Mixer::VOLUME_PAGESTEP_DIVISOR, vol.getVolume( vc.chid ), _orientation, this ); } // small else { slider = new VolumeSlider( _orientation, this ); - slider->setMinimum(0); + slider->setMinimum(minvol); slider->setMaximum(maxvol); slider->setPageStep(maxvol / Mixer::VOLUME_PAGESTEP_DIVISOR); slider->setValue( maxvol - vol.getVolume( vc.chid ) ); @@ -935,7 +935,7 @@ void MDWSlider::increaseOrDecreaseVolume(bool decrease) { Volume& volP = m_mixdevice->playbackVolume(); - long inc = volP.maxVolume() / Mixer::VOLUME_STEP_DIVISOR; + long inc = volP.volumeSpan() / Mixer::VOLUME_STEP_DIVISOR; if ( inc == 0 ) inc = 1; if ( decrease ) inc *= -1; if ( mixDevice()->id() == "Headphone:0" ) @@ -951,7 +951,7 @@ volP.changeAllVolumes(inc); Volume& volC = m_mixdevice->captureVolume(); - inc = volC.maxVolume() / Mixer::VOLUME_STEP_DIVISOR; + inc = volC.volumeSpan() / Mixer::VOLUME_STEP_DIVISOR; if ( inc == 0 ) inc = 1; if ( decrease ) inc *= -1; volC.changeAllVolumes(inc); --- trunk/KDE/kdemultimedia/kmix/gui/osdwidget.cpp #1250843:1250844 @@ -110,6 +110,9 @@ m_hideTimer->start(); } +/** + * Set volume level in percent + */ void OSDWidget::setCurrentVolume(int volumeLevel, bool muted) { m_meter->setValue(volumeLevel);