[vlc-commits] skins2: fix skins2 audio volume and adapt to latest change
Erwan Tulou
git at videolan.org
Sat Jul 21 15:15:17 CEST 2012
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jul 21 03:45:13 2012 +0200| [a2d83783991312cac5f3c6094ef8ed425c4bac8d] | committer: Erwan Tulou
skins2: fix skins2 audio volume and adapt to latest change
- 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a2d83783991312cac5f3c6094ef8ed425c4bac8d
---
modules/gui/skins2/src/vlcproc.cpp | 4 ++--
modules/gui/skins2/vars/volume.cpp | 36 +++++++++++++++++++++++++-----------
modules/gui/skins2/vars/volume.hpp | 10 ++++++----
3 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index 504514e..36b557b 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -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 );
diff --git a/modules/gui/skins2/vars/volume.cpp b/modules/gui/skins2/vars/volume.cpp
index dfd449b..baf417a 100644
--- a/modules/gui/skins2/vars/volume.cpp
+++ b/modules/gui/skins2/vars/volume.cpp
@@ -6,6 +6,7 @@
*
* Authors: Cyril Deguet <asmax at via.ecp.fr>
* Olivier Teulière <ipkiss at 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
@@ -30,17 +31,18 @@
#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);
}
diff --git a/modules/gui/skins2/vars/volume.hpp b/modules/gui/skins2/vars/volume.hpp
index 874085f..3651d71 100644
--- a/modules/gui/skins2/vars/volume.hpp
+++ b/modules/gui/skins2/vars/volume.hpp
@@ -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;
};
More information about the vlc-commits
mailing list