]> git.sesse.net Git - vlc/commitdiff
skins2: fix skins2 audio volume and adapt to latest change
authorErwan Tulou <erwan10@videolan.org>
Sat, 21 Jul 2012 01:45:13 +0000 (03:45 +0200)
committerErwan Tulou <erwan10@videolan.org>
Sat, 21 Jul 2012 13:05:41 +0000 (15:05 +0200)
   - use the overall volume managed by the playlist rather than
     aout_volumeGet() that now only works when a aout is running.
     This is no problem since the skins2 volume slider functionally
     reflects this overall volume managed by the playlist anyway.
   - stick to what include/vlc_aout_intf.h lets us know about volume
     boundaries(as of today, AOUT_VOLUME_DEFAULT and AOUT_VOLUME_MAX)
     and infer volume to be in the [0., AOUT_VOLUME_MAX/AOUT_VOLUME_DEFAULT]
     range as requested by some functions taking a float as parameter.

modules/gui/skins2/src/vlcproc.cpp
modules/gui/skins2/vars/volume.cpp
modules/gui/skins2/vars/volume.hpp

index 504514e61049676fd3ade80a7cfb584cc96d2606..36b557bea3101b43bdec9f74edde2ff1630b7bf1 100644 (file)
@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
     (void)p_obj; (void)newVal;
     playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
 
-    float volume = aout_VolumeGet( pPlaylist ) * 100.f;
+    int volume = var_GetInteger( pPlaylist, "volume" );
     SET_VOLUME( m_cVarVolume, volume, false );
     bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
     SET_BOOL( m_cVarMute, b_is_muted );
@@ -798,7 +798,7 @@ void VlcProc::init_variables()
     SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
     SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
 
-    float volume = aout_VolumeGet( pPlaylist ) * 100.f;
+    int volume = var_GetInteger( pPlaylist, "volume" );
     SET_VOLUME( m_cVarVolume, volume, false );
     bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
     SET_BOOL( m_cVarMute, b_is_muted );
index dfd449b22380e47d8ff8aaaafab2080d7118e02b..baf417a7a0ff872b4f7fb206df78feb2198e2c85 100644 (file)
@@ -6,6 +6,7 @@
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Erwan Tulou      <erwan10 aT videolan Dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <vlc_aout_intf.h>
 #include <vlc_playlist.h>
 #include "volume.hpp"
+#include <math.h>
 
 Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
 {
-    m_max = 200;
-    m_volumeMax = AOUT_VOLUME_DEFAULT * 2;
+    // compute preferred step in [0.,1.] range
     m_step = (float)config_GetInt( pIntf, "volume-step" )
-           / (float)m_volumeMax;
+             / (float)AOUT_VOLUME_MAX;
 
-    // Initial value
-    float val = aout_VolumeGet( getIntf()->p_sys->p_playlist ) * 100.f;
-    set( val, false );
+    // set current volume from the playlist
+    playlist_t* pPlaylist = pIntf->p_sys->p_playlist;
+    int volume = var_GetInteger( pPlaylist, "volume" );
+    set( volume, false );
 }
 
 
@@ -48,22 +50,34 @@ void Volume::set( float percentage, bool updateVLC )
 {
     VarPercent::set( percentage );
     if( updateVLC )
-        aout_VolumeSet( getIntf()->p_sys->p_playlist, get() * m_volumeMax );
+    {
+        playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
+        aout_VolumeSet( pPlaylist, getVolume() );
+    }
 }
 
 
-void Volume::set( int val, bool updateVLC )
+void Volume::set( int volume, bool updateVLC )
 {
-    set( (float)val / m_volumeMax, updateVLC );
+    // volume is kept by the playlist in [0,AOUT_VOLUME_MAX] range
+    // this class keeps it in [0.,1.] range
+    set( (float)volume/(float)AOUT_VOLUME_MAX, updateVLC );
+}
+
+
+float Volume::getVolume() const
+{
+    // translate from [0.,1.] into [0.,AOUT_VOLUME_MAX/AOUT_VOLUME_DEFAULT]
+    return get() * AOUT_VOLUME_MAX/AOUT_VOLUME_DEFAULT;
 }
 
 
 string Volume::getAsStringPercent() const
 {
-    int value = (int)(m_max * VarPercent::get());
+    int value = lround( getVolume() * 100. );
     // 0 <= value <= 200, so we need 4 chars
     char str[4];
-    snprintf( str, 4, "%d", value );
+    snprintf( str, 4, "%i", value );
     return string(str);
 }
 
index 874085f7521974c995ba79fb4dc25099da29887c..3651d7171be52dda7caa803bd89cf2f521aa6d5e 100644 (file)
@@ -37,19 +37,21 @@ public:
     Volume( intf_thread_t *pIntf );
     virtual ~Volume() { }
 
-    virtual void set( float percentage, bool updateVLC = true );
-    virtual void set( int volume, bool updateVLC = true);
+    virtual void set( float percentage, bool updateVLC );
+
+    virtual void set( int volume, bool updateVLC );
 
     virtual void set( float percentage ) { set( percentage, true ); }
 
+    virtual float getVolume() const;
+
     virtual float getStep() const { return m_step; }
 
     virtual string getAsStringPercent() const;
 
 private:
+    // preferred volume step on [0., 1.]
     float m_step;
-    int m_max;
-    int m_volumeMax;
 };