(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 );
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 );
*
* 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 );
}
{
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);
}
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;
};