From 982a134d2ccf075d1c93eaa0dfde37eaae51cabc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 27 May 2007 06:22:20 +0000 Subject: [PATCH] apply the music rate to the sample music --- stepmania/src/GameSoundManager.cpp | 22 ++++++++++++++++++++-- stepmania/src/GameSoundManager.h | 2 ++ stepmania/src/ScreenSelectMusic.cpp | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/stepmania/src/GameSoundManager.cpp b/stepmania/src/GameSoundManager.cpp index af93530f1b..0a96618836 100644 --- a/stepmania/src/GameSoundManager.cpp +++ b/stepmania/src/GameSoundManager.cpp @@ -48,6 +48,7 @@ struct MusicPlaying { bool m_bTimingDelayed; bool m_bHasTiming; + bool m_bApplyMusicRate; /* The timing data that we're currently using. */ TimingData m_Timing; NoteData m_Lights; @@ -62,6 +63,7 @@ struct MusicPlaying m_NewTiming.AddBPMSegment( BPMSegment(0,120) ); m_bHasTiming = false; m_bTimingDelayed = false; + m_bApplyMusicRate = false; m_Music = Music; } @@ -87,7 +89,7 @@ struct MusicToPlay NoteData m_LightsData; bool bForceLoop; float fStartSecond, fLengthSeconds, fFadeInLengthSeconds, fFadeOutLengthSeconds; - bool bAlignBeat; + bool bAlignBeat, bApplyMusicRate; MusicToPlay() { HasTiming = false; @@ -123,7 +125,9 @@ static void StartMusic( MusicToPlay &ToPlay ) { g_Mutex->Unlock(); RageSound *pSound = new RageSound; - pSound->Load( ToPlay.m_sFile, false ); + RageSoundLoadParams params; + params.m_bSupportRateChanging = ToPlay.bApplyMusicRate; + pSound->Load( ToPlay.m_sFile, false, ¶ms ); g_Mutex->Lock(); NewMusic = new MusicPlaying( pSound ); @@ -232,6 +236,7 @@ static void StartMusic( MusicToPlay &ToPlay ) if( ToPlay.HasTiming ) NewMusic->m_NewTiming = ToPlay.m_TimingData; NewMusic->m_bTimingDelayed = true; + NewMusic->m_bApplyMusicRate = ToPlay.bApplyMusicRate; // NewMusic->m_Music->Load( ToPlay.m_sFile, false ); RageSoundParams p; @@ -468,6 +473,17 @@ void GameSoundManager::Update( float fDeltaTime ) { { g_Mutex->Lock(); + if( g_Playing->m_bApplyMusicRate ) + { + RageSoundParams p = g_Playing->m_Music->GetParams(); + float fRate = GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate; + if( p.m_fSpeed != fRate ) + { + p.m_fSpeed = fRate; + g_Playing->m_Music->SetParams( p ); + } + } + bool bIsPlaying = g_Playing->m_Music->IsPlaying(); g_Mutex->Unlock(); if( !bIsPlaying && g_bWasPlayingOnLastUpdate && !g_FallbackMusic.sFile.empty() ) @@ -664,6 +680,7 @@ void GameSoundManager::PlayMusic( params.fFadeInLengthSeconds = fFadeInLengthSeconds; params.fFadeOutLengthSeconds = fFadeOutLengthSeconds; params.bAlignBeat = bAlignBeat; + params.bApplyMusicRate = false; PlayMusic( params ); } @@ -693,6 +710,7 @@ void GameSoundManager::PlayMusic( PlayMusicParams params, PlayMusicParams Fallba ToPlay.fFadeInLengthSeconds = params.fFadeInLengthSeconds; ToPlay.fFadeOutLengthSeconds = params.fFadeOutLengthSeconds; ToPlay.bAlignBeat = params.bAlignBeat; + ToPlay.bApplyMusicRate = params.bApplyMusicRate; /* Add the MusicToPlay to the g_MusicsToPlay queue. */ g_Mutex->Lock(); diff --git a/stepmania/src/GameSoundManager.h b/stepmania/src/GameSoundManager.h index 3fbab08a2c..92fe9c9840 100644 --- a/stepmania/src/GameSoundManager.h +++ b/stepmania/src/GameSoundManager.h @@ -27,6 +27,7 @@ public: fFadeInLengthSeconds = 0; fFadeOutLengthSeconds = 0; bAlignBeat = true; + bApplyMusicRate = false; } RString sFile; @@ -37,6 +38,7 @@ public: float fFadeInLengthSeconds; float fFadeOutLengthSeconds; bool bAlignBeat; + bool bApplyMusicRate; }; void PlayMusic( PlayMusicParams params, PlayMusicParams FallbackMusic = PlayMusicParams() ); void PlayMusic( diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index cc11ca8615..235781b5b5 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -306,6 +306,7 @@ void ScreenSelectMusic::CheckBackgroundRequests( bool bForce ) PlayParams.fLengthSeconds = m_fSampleLengthSeconds; PlayParams.fFadeOutLengthSeconds = 1.5f; PlayParams.bAlignBeat = ALIGN_MUSIC_BEATS; + PlayParams.bApplyMusicRate = true; GameSoundManager::PlayMusicParams FallbackMusic; FallbackMusic.sFile = m_sLoopMusicPath;