From dff267eccd1d8b7a3a5091f9568d4ae6a4839b04 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 24 May 2007 21:35:03 +0000 Subject: [PATCH] move SoundVolume --- stepmania/src/PrefsManager.cpp | 8 -------- stepmania/src/PrefsManager.h | 5 ----- stepmania/src/RageSoundManager.cpp | 8 ++++---- stepmania/src/RageSoundManager.h | 2 +- stepmania/src/ScreenDebugOverlay.cpp | 26 ++++++++++++++++---------- stepmania/src/ScreenOptionsMaster.cpp | 2 +- stepmania/src/StepMania.cpp | 4 ++-- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index fdd41252d3..117d9259b3 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -240,7 +240,6 @@ PrefsManager::PrefsManager() : m_sLastSeenVideoDriver ( "LastSeenVideoDriver", "" ), m_sVideoRenderers ( "VideoRenderers", "" ), // StepMania.cpp sets these on first run: m_bSmoothLines ( "SmoothLines", false ), - m_fSoundVolume ( "SoundVolume", 1.0f ), m_iSoundWriteAhead ( "SoundWriteAhead", 0 ), m_iSoundDevice ( "SoundDevice", "" ), m_iSoundPreferredSampleRate ( "SoundPreferredSampleRate", 0 ), @@ -482,13 +481,6 @@ RString PrefsManager::GetPreferencesSection() const } -// wrappers -float PrefsManager::GetSoundVolume() -{ - // return a resonable volume to that users of this method don't have to handle invalid values - return clamp(m_fSoundVolume.Get(),0.0f,1.0f); -} - // lua start #include "LuaBinding.h" diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index ee598c1d0f..bf4f7c0292 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -216,7 +216,6 @@ public: Preference m_sLastSeenVideoDriver; Preference m_sVideoRenderers; // StepMania.cpp sets these on first run based on the card Preference m_bSmoothLines; - Preference m_fSoundVolume; Preference m_iSoundWriteAhead; Preference m_iSoundDevice; Preference m_iSoundPreferredSampleRate; @@ -244,10 +243,6 @@ public: #endif - // wrappers - float GetSoundVolume(); - - void ReadPrefsFromIni( const IniFile &ini, const RString &sSection, bool bIsStatic ); void ReadGamePrefsFromIni( const RString &sIni ); void ReadDefaultsFromIni( const IniFile &ini, const RString &sSection ); diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 04727ece97..5f87d9b8e1 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -178,12 +178,12 @@ void RageSoundManager::AddLoadedSound( const RString &sPath_, RageSoundReader_Pr m_mapPreloadedSounds[sPath] = pSound->Copy(); } -void RageSoundManager::SetMixVolume( float fMixVol ) -{ - ASSERT_M( fMixVol >= 0 && fMixVol <= 1, ssprintf("%f",fMixVol) ); +static Preference g_fSoundVolume( "SoundVolume", 1.0f ); +void RageSoundManager::SetMixVolume() +{ g_SoundManMutex.Lock(); /* lock for access to m_fMixVolume */ - m_fMixVolume = fMixVol; + m_fMixVolume = clamp( g_fSoundVolume.Get(), 0.0f, 1.0f ); g_SoundManMutex.Unlock(); /* finished with m_fMixVolume */ } diff --git a/stepmania/src/RageSoundManager.h b/stepmania/src/RageSoundManager.h index 31e1303191..98bd60148a 100644 --- a/stepmania/src/RageSoundManager.h +++ b/stepmania/src/RageSoundManager.h @@ -30,7 +30,7 @@ public: void Init(); float GetMixVolume() const { return m_fMixVolume; } - void SetMixVolume( float fMixVol ); + void SetMixVolume(); float GetVolumeOfNonCriticalSounds() const { return m_fVolumeOfNonCriticalSounds; } void SetVolumeOfNonCriticalSounds( float fVolumeOfNonCriticalSounds ); diff --git a/stepmania/src/ScreenDebugOverlay.cpp b/stepmania/src/ScreenDebugOverlay.cpp index 4f61763456..5b5cf4fa4e 100644 --- a/stepmania/src/ScreenDebugOverlay.cpp +++ b/stepmania/src/ScreenDebugOverlay.cpp @@ -457,11 +457,13 @@ static void SetSpeed() void ChangeVolume( float fDelta ) { - float fVol = PREFSMAN->m_fSoundVolume; + Preference *pRet = Preference::GetPreferenceByName("SoundVolume"); + + float fVol = pRet->Get(); fVol += fDelta; CLAMP( fVol, 0.0f, 1.0f ); - PREFSMAN->m_fSoundVolume.Set( fVol ); - SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); + pRet->Set( fVol ); + SOUNDMAN->SetMixVolume(); } @@ -725,11 +727,7 @@ class DebugLineShowMasks : public IDebugLine Preference *GetPref() { - IPreference *pPref = IPreference::GetPreferenceByName("ShowMasks"); - ASSERT( pPref ); - Preference *pRet = dynamic_cast *>(pPref); - ASSERT( pRet ); - return pRet; + return Preference::GetPreferenceByName("ShowMasks"); } }; @@ -1039,13 +1037,17 @@ class DebugLinePullBackCamera : public IDebugLine class DebugLineVolumeUp : public IDebugLine { virtual RString GetDisplayTitle() { return VOLUME_UP.GetValue(); } - virtual RString GetDisplayValue() { return ssprintf("%.0f%%",PREFSMAN->m_fSoundVolume.Get()*100); } + virtual RString GetDisplayValue() { return ssprintf("%.0f%%", GetPref()->Get()*100); } virtual bool IsEnabled() { return true; } virtual void DoAndMakeSystemMessage( RString &sMessageOut ) { ChangeVolume( +0.1f ); IDebugLine::DoAndMakeSystemMessage( sMessageOut ); } + Preference *GetPref() + { + return Preference::GetPreferenceByName("SoundVolume"); + } }; class DebugLineVolumeDown : public IDebugLine @@ -1057,7 +1059,11 @@ class DebugLineVolumeDown : public IDebugLine { ChangeVolume( -0.1f ); IDebugLine::DoAndMakeSystemMessage( sMessageOut ); - sMessageOut += " - " + ssprintf("%.0f%%",PREFSMAN->m_fSoundVolume.Get()*100); + sMessageOut += " - " + ssprintf("%.0f%%",GetPref()->Get()*100); + } + Preference *GetPref() + { + return Preference::GetPreferenceByName("SoundVolume"); } }; diff --git a/stepmania/src/ScreenOptionsMaster.cpp b/stepmania/src/ScreenOptionsMaster.cpp index 1610909bac..69f5a03f25 100644 --- a/stepmania/src/ScreenOptionsMaster.cpp +++ b/stepmania/src/ScreenOptionsMaster.cpp @@ -146,7 +146,7 @@ void ScreenOptionsMaster::HandleScreenMessage( const ScreenMessage SM ) if( m_iChangeMask & OPT_APPLY_SOUND ) { - SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); + SOUNDMAN->SetMixVolume(); } if( m_iChangeMask & OPT_APPLY_SONG ) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index f0e64db84d..218b6d27ad 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -229,7 +229,7 @@ static bool CheckVideoDefaultSettings(); void StepMania::ResetPreferences() { PREFSMAN->ResetToFactoryDefaults(); - SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); + SOUNDMAN->SetMixVolume(); CheckVideoDefaultSettings(); ApplyGraphicOptions(); } @@ -1015,7 +1015,7 @@ int main(int argc, char* argv[]) LOG->Info( "Sound writeahead has been overridden to %i", PREFSMAN->m_iSoundWriteAhead.Get() ); SOUNDMAN = new RageSoundManager; SOUNDMAN->Init(); - SOUNDMAN->SetMixVolume( PREFSMAN->GetSoundVolume() ); + SOUNDMAN->SetMixVolume(); SOUND = new GameSoundManager; BOOKKEEPER = new Bookkeeper; LIGHTSMAN = new LightsManager;