[vlc-commits] skins2: use the 0-400% range for volume

Erwan Tulou git at videolan.org
Fri Feb 25 20:10:45 CET 2011


vlc/vlc-1.1 | branch: master | Erwan Tulou <erwan10 at videolan.org> | Fri Feb 25 20:00:23 2011 +0100| [0663e1730e3c2813e76f7063f1f64128f86e0a56] | committer: Erwan Tulou

skins2: use the 0-400% range for volume

This patch makes volume more consistent with the rest of vlc :
 - volume is now advertised on a 0-400% range instead of a misleading
   0-100% range. This fixes the discrepancy between volume displayed
   within the skins and volume displayed via OSD
 - "qt-volume-complete" and "volume-step" are now taken into account,
   which makes skins2 more consistent with qt4

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=0663e1730e3c2813e76f7063f1f64128f86e0a56
---

 modules/gui/skins2/controls/ctrl_slider.cpp |   11 ++++++-----
 modules/gui/skins2/src/vlcproc.cpp          |    4 ++--
 modules/gui/skins2/utils/var_percent.hpp    |    3 +++
 modules/gui/skins2/vars/volume.cpp          |   26 ++++++++++++++++++++++----
 modules/gui/skins2/vars/volume.hpp          |   10 +++++++++-
 5 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/modules/gui/skins2/controls/ctrl_slider.cpp b/modules/gui/skins2/controls/ctrl_slider.cpp
index 995cf75..ecc4548 100644
--- a/modules/gui/skins2/controls/ctrl_slider.cpp
+++ b/modules/gui/skins2/controls/ctrl_slider.cpp
@@ -36,11 +36,10 @@
 
 
 #define RANGE 40
-#define SCROLL_STEP 0.05f
 
-static inline float scroll( bool up, float pct )
+static inline float scroll( bool up, float pct, float step )
 {
-    return pct + (up? SCROLL_STEP : -SCROLL_STEP);
+    return pct + (up? step : -step);
 }
 
 
@@ -259,7 +258,8 @@ void CtrlSliderCursor::CmdScroll::execute()
     // XXX Two of these in this file, figure out where it really belongs.
     int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection();
     m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir,
-                                        m_pParent->m_rVariable.get() ) );
+                                        m_pParent->m_rVariable.get(),
+                                        m_pParent->m_rVariable.getStep()) );
 }
 
 
@@ -405,7 +405,8 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
     {
         // XXX Two of these in this file, figure out where it really belongs.
         int dir = static_cast<EvtScroll*>(&rEvent)->getDirection();
-        m_rVariable.set( scroll( EvtScroll::kUp == dir, m_rVariable.get() ) );
+        m_rVariable.set( scroll( EvtScroll::kUp == dir,
+                                 m_rVariable.get(), m_rVariable.getStep() ) );
     }
 }
 
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index ad2624ac..37cb3c4 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -641,7 +641,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
 
     audio_volume_t volume;
     aout_VolumeGet( pPlaylist, &volume );
-    SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
+    SET_VOLUME( m_cVarVolume, volume, false );
     SET_BOOL( m_cVarMute, volume == 0 );
 }
 
@@ -737,7 +737,7 @@ void VlcProc::init_variables()
 
     audio_volume_t volume;
     aout_VolumeGet( pPlaylist, &volume );
-    SET_VOLUME( m_cVarVolume, (double)volume / AOUT_VOLUME_MAX, false );
+    SET_VOLUME( m_cVarVolume, volume, false );
     SET_BOOL( m_cVarMute, volume == 0 );
 
     update_equalizer();
diff --git a/modules/gui/skins2/utils/var_percent.hpp b/modules/gui/skins2/utils/var_percent.hpp
index 5f5ca3c..829a12b 100644
--- a/modules/gui/skins2/utils/var_percent.hpp
+++ b/modules/gui/skins2/utils/var_percent.hpp
@@ -45,6 +45,9 @@ public:
     virtual void set( float percentage );
     virtual float get() const { return m_value; }
 
+    /// Get the variable preferred step
+    virtual float getStep() const { return .05f; }
+
 private:
     /// Variable type
     static const string m_type;
diff --git a/modules/gui/skins2/vars/volume.cpp b/modules/gui/skins2/vars/volume.cpp
index 2809c0d..6aacfe6 100644
--- a/modules/gui/skins2/vars/volume.cpp
+++ b/modules/gui/skins2/vars/volume.cpp
@@ -33,11 +33,23 @@
 
 Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
 {
+    m_step = (float)config_GetInt( pIntf, "volume-step" ) / AOUT_VOLUME_MAX;
+    if( var_InheritBool( pIntf, "qt-volume-complete" ) )
+    {
+        m_max = 400;
+        m_volumeMax = AOUT_VOLUME_MAX;
+    }
+    else
+    {
+        m_max = 200;
+        m_volumeMax = AOUT_VOLUME_MAX / 2;
+    }
+
     // Initial value
     audio_volume_t val;
 
     aout_VolumeGet( getIntf()->p_sys->p_playlist, &val );
-    VarPercent::set( val / AOUT_VOLUME_MAX );
+    set( val, false );
 }
 
 
@@ -50,15 +62,21 @@ void Volume::set( float percentage, bool updateVLC )
         VarPercent::set( percentage );
         if( updateVLC )
             aout_VolumeSet( getIntf()->p_sys->p_playlist,
-                            (int)(get() * AOUT_VOLUME_MAX) );
+                            (int)(get() * m_volumeMax) );
     }
 }
 
 
+void Volume::set( int val, bool updateVLC )
+{
+    set( (float)val / m_volumeMax, updateVLC );
+}
+
+
 string Volume::getAsStringPercent() const
 {
-    int value = (int)(100. * VarPercent::get());
-    // 0 <= value <= 100, so we need 4 chars
+    int value = (int)(m_max * VarPercent::get());
+    // 0 <= value <= 400, so we need 4 chars
     char str[4];
     snprintf( str, 4, "%d", value );
     return string(str);
diff --git a/modules/gui/skins2/vars/volume.hpp b/modules/gui/skins2/vars/volume.hpp
index 7a12e60..874085f 100644
--- a/modules/gui/skins2/vars/volume.hpp
+++ b/modules/gui/skins2/vars/volume.hpp
@@ -37,11 +37,19 @@ public:
     Volume( intf_thread_t *pIntf );
     virtual ~Volume() { }
 
-    virtual void set( float percentage, bool updateVLC );
+    virtual void set( float percentage, bool updateVLC = true );
+    virtual void set( int volume, bool updateVLC = true);
 
     virtual void set( float percentage ) { set( percentage, true ); }
 
+    virtual float getStep() const { return m_step; }
+
     virtual string getAsStringPercent() const;
+
+private:
+    float m_step;
+    int m_max;
+    int m_volumeMax;
 };
 
 



More information about the vlc-commits mailing list