Commit 52840752 authored by Erwan Tulou's avatar 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
parent 815340f6
...@@ -36,11 +36,10 @@ ...@@ -36,11 +36,10 @@
#define RANGE 40 #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);
} }
...@@ -299,7 +298,8 @@ void CtrlSliderCursor::CmdScroll::execute() ...@@ -299,7 +298,8 @@ void CtrlSliderCursor::CmdScroll::execute()
{ {
int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection(); int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection();
m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir, m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir,
m_pParent->m_rVariable.get() ) ); m_pParent->m_rVariable.get(),
m_pParent->m_rVariable.getStep()) );
} }
...@@ -486,7 +486,8 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) ...@@ -486,7 +486,8 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
else if( rEvent.getAsString().find( "scroll" ) != string::npos ) else if( rEvent.getAsString().find( "scroll" ) != string::npos )
{ {
int dir = static_cast<EvtScroll*>(&rEvent)->getDirection(); 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() ) );
} }
} }
......
...@@ -696,7 +696,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -696,7 +696,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
audio_volume_t volume; audio_volume_t volume;
aout_VolumeGet( pPlaylist, &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 ); SET_BOOL( m_cVarMute, volume == 0 );
} }
...@@ -799,7 +799,7 @@ void VlcProc::init_variables() ...@@ -799,7 +799,7 @@ void VlcProc::init_variables()
audio_volume_t volume; audio_volume_t volume;
aout_VolumeGet( pPlaylist, &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 ); SET_BOOL( m_cVarMute, volume == 0 );
update_equalizer(); update_equalizer();
......
...@@ -45,6 +45,9 @@ public: ...@@ -45,6 +45,9 @@ public:
virtual void set( float percentage ); virtual void set( float percentage );
virtual float get() const { return m_value; } virtual float get() const { return m_value; }
/// Get the variable preferred step
virtual float getStep() const { return .05f; }
private: private:
/// Variable type /// Variable type
static const string m_type; static const string m_type;
......
...@@ -33,11 +33,23 @@ ...@@ -33,11 +33,23 @@
Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf ) 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 // Initial value
audio_volume_t val; audio_volume_t val;
aout_VolumeGet( getIntf()->p_sys->p_playlist, &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 ) ...@@ -50,15 +62,21 @@ void Volume::set( float percentage, bool updateVLC )
VarPercent::set( percentage ); VarPercent::set( percentage );
if( updateVLC ) if( updateVLC )
aout_VolumeSet( getIntf()->p_sys->p_playlist, 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 string Volume::getAsStringPercent() const
{ {
int value = (int)(100. * VarPercent::get()); int value = (int)(m_max * VarPercent::get());
// 0 <= value <= 100, so we need 4 chars // 0 <= value <= 400, so we need 4 chars
char str[4]; char str[4];
snprintf( str, 4, "%d", value ); snprintf( str, 4, "%d", value );
return string(str); return string(str);
......
...@@ -37,11 +37,19 @@ public: ...@@ -37,11 +37,19 @@ public:
Volume( intf_thread_t *pIntf ); Volume( intf_thread_t *pIntf );
virtual ~Volume() { } 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 void set( float percentage ) { set( percentage, true ); }
virtual float getStep() const { return m_step; }
virtual string getAsStringPercent() const; virtual string getAsStringPercent() const;
private:
float m_step;
int m_max;
int m_volumeMax;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment