Commit a2d83783 authored by Erwan Tulou's avatar 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.
parent d871c27f
...@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
(void)p_obj; (void)newVal; (void)p_obj; (void)newVal;
playlist_t* pPlaylist = getIntf()->p_sys->p_playlist; 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 ); SET_VOLUME( m_cVarVolume, volume, false );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0; bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted ); SET_BOOL( m_cVarMute, b_is_muted );
...@@ -798,7 +798,7 @@ void VlcProc::init_variables() ...@@ -798,7 +798,7 @@ void VlcProc::init_variables()
SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) ); SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) ); 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 ); SET_VOLUME( m_cVarVolume, volume, false );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0; bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted ); SET_BOOL( m_cVarMute, b_is_muted );
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@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 * 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 * it under the terms of the GNU General Public License as published by
...@@ -30,17 +31,18 @@ ...@@ -30,17 +31,18 @@
#include <vlc_aout_intf.h> #include <vlc_aout_intf.h>
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include "volume.hpp" #include "volume.hpp"
#include <math.h>
Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf ) Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
{ {
m_max = 200; // compute preferred step in [0.,1.] range
m_volumeMax = AOUT_VOLUME_DEFAULT * 2;
m_step = (float)config_GetInt( pIntf, "volume-step" ) m_step = (float)config_GetInt( pIntf, "volume-step" )
/ (float)m_volumeMax; / (float)AOUT_VOLUME_MAX;
// Initial value // set current volume from the playlist
float val = aout_VolumeGet( getIntf()->p_sys->p_playlist ) * 100.f; playlist_t* pPlaylist = pIntf->p_sys->p_playlist;
set( val, false ); int volume = var_GetInteger( pPlaylist, "volume" );
set( volume, false );
} }
...@@ -48,22 +50,34 @@ void Volume::set( float percentage, bool updateVLC ) ...@@ -48,22 +50,34 @@ void Volume::set( float percentage, bool updateVLC )
{ {
VarPercent::set( percentage ); VarPercent::set( percentage );
if( updateVLC ) 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 string Volume::getAsStringPercent() const
{ {
int value = (int)(m_max * VarPercent::get()); int value = lround( getVolume() * 100. );
// 0 <= value <= 200, so we need 4 chars // 0 <= value <= 200, so we need 4 chars
char str[4]; char str[4];
snprintf( str, 4, "%d", value ); snprintf( str, 4, "%i", value );
return string(str); return string(str);
} }
...@@ -37,19 +37,21 @@ public: ...@@ -37,19 +37,21 @@ public:
Volume( intf_thread_t *pIntf ); Volume( intf_thread_t *pIntf );
virtual ~Volume() { } virtual ~Volume() { }
virtual void set( float percentage, bool updateVLC = true ); virtual void set( float percentage, bool updateVLC );
virtual void set( int volume, bool updateVLC = true);
virtual void set( int volume, bool updateVLC );
virtual void set( float percentage ) { set( percentage, true ); } virtual void set( float percentage ) { set( percentage, true ); }
virtual float getVolume() const;
virtual float getStep() const { return m_step; } virtual float getStep() const { return m_step; }
virtual string getAsStringPercent() const; virtual string getAsStringPercent() const;
private: private:
// preferred volume step on [0., 1.]
float m_step; 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