diff --git a/stepmania/src/AutoKeysounds.cpp b/stepmania/src/AutoKeysounds.cpp index b69879cb5e..a947f87463 100644 --- a/stepmania/src/AutoKeysounds.cpp +++ b/stepmania/src/AutoKeysounds.cpp @@ -2,16 +2,31 @@ #include "AutoKeysounds.h" #include "GameState.h" #include "song.h" +#include "RageSoundReader_Chain.h" +#include "RageSoundManager.h" +#include "RageLog.h" void AutoKeysounds::Load( PlayerNumber pn, const NoteData& ndAutoKeysoundsOnly ) { m_ndAutoKeysoundsOnly[pn] = ndAutoKeysoundsOnly; - +} + +void AutoKeysounds::FinishLoading() +{ + m_sSound.Unload(); + + /* Load the BGM. */ + RageSoundReader_Chain *pChain = new RageSoundReader_Chain; + + Song* pSong = GAMESTATE->m_pCurSong; + pChain->SetPreferredSampleRate( SOUNDMAN->GetDriverSampleRate(44100) ); + pChain->AddSound( pSong->GetMusicPath(), 0, 0 ); + // // Load sounds. // - Song* pSong = GAMESTATE->m_pCurSong; CString sSongDir = pSong->GetSongDir(); +/* m_vKeysounds.clear(); m_vKeysounds.resize( pSong->m_vsKeysoundFile.size() ); for( unsigned i=0; im_vsKeysoundFile[i]; RageSound& sound = m_vKeysounds[i]; sound.Load( sKeysoundFilePath ); + + } +*/ + + /* + * Add all current autoplay sounds in both players to the chain. If a sound is + * common to both players, don't pan it; otherwise pan it to that player's side. + */ + int iNumTracks = m_ndAutoKeysoundsOnly[GAMESTATE->m_MasterPlayerNumber].GetNumTracks(); + for( int t = 0; t < iNumTracks; t++ ) + { + int iRow = 0; + while(1) + { + /* Find the next row that either player has a note on. */ + int iNextRow = 999999999; + FOREACH_EnabledPlayer(pn) + { + int iNextRowForPlayer = iRow; + if( m_ndAutoKeysoundsOnly[pn].GetNextTapNoteRowForTrack( t, iNextRowForPlayer ) ) + iNextRow = min( iNextRow, iNextRowForPlayer ); + } + + if( iNextRow == 999999999 ) + break; + iRow = iNextRow; + + TapNote tn[NUM_PLAYERS]; + FOREACH_EnabledPlayer(pn) + tn[pn] = m_ndAutoKeysoundsOnly[pn].GetTapNote( t, iRow ); + + /* Do all enabled players have the same note here? (Having no note at all + * counts as having a different note.) */ + bool bSoundIsGlobal = true; + { + PlayerNumber pn = GetNextEnabledPlayer((PlayerNumber)-1); + const TapNote t = tn[pn]; + pn = GetNextEnabledPlayer(pn); + while( pn != PLAYER_INVALID ) + { + if( tn[pn].type != TapNote::autoKeysound || tn[pn].bKeysound != t.bKeysound ) + bSoundIsGlobal = false; + pn = GetNextEnabledPlayer(pn); + } + } + + FOREACH_EnabledPlayer(pn) + { + if( tn[pn] == TAP_EMPTY ) + continue; + + ASSERT( tn[pn].type == TapNote::autoKeysound ); + if( tn[pn].bKeysound ) + { + CString sKeysoundFilePath = sSongDir + pSong->m_vsKeysoundFile[tn[pn].iKeysoundIndex]; + float fSeconds = pSong->m_Timing.GetElapsedTimeFromBeat( NoteRowToBeat(iRow) ); + + float fPan = 0; + if( !bSoundIsGlobal ) + fPan = (pn == PLAYER_1)? -1.0f:+1.0f; + pChain->AddSound( sKeysoundFilePath, fSeconds, fPan ); + } + } + } + } + + pChain->Finish(); + + m_sSound.LoadSoundReader( pChain ); } void AutoKeysounds::Update( float fDelta ) @@ -27,6 +111,7 @@ void AutoKeysounds::Update( float fDelta ) // // Play keysounds for crossed rows. // +/* bool bCrossedABeat = false; { float fPositionSeconds = GAMESTATE->m_fMusicSeconds; @@ -59,6 +144,7 @@ void AutoKeysounds::Update( float fDelta ) iRowLastCrossed = iRowNow; } +*/ } /* diff --git a/stepmania/src/AutoKeysounds.h b/stepmania/src/AutoKeysounds.h index a6eea26366..00671909d6 100644 --- a/stepmania/src/AutoKeysounds.h +++ b/stepmania/src/AutoKeysounds.h @@ -12,10 +12,13 @@ class AutoKeysounds public: void Load( PlayerNumber pn, const NoteData& ndAutoKeysoundsOnly ); void Update( float fDelta ); - + void FinishLoading(); + RageSound *GetSound() { return &m_sSound; } + protected: NoteData m_ndAutoKeysoundsOnly[NUM_PLAYERS]; vector m_vKeysounds; + RageSound m_sSound; }; #endif diff --git a/stepmania/src/ScreenDemonstration.cpp b/stepmania/src/ScreenDemonstration.cpp index 82952fe112..c650f2dd4e 100644 --- a/stepmania/src/ScreenDemonstration.cpp +++ b/stepmania/src/ScreenDemonstration.cpp @@ -78,7 +78,8 @@ void ScreenDemonstration::HandleScreenMessage( const ScreenMessage SM ) break; case SM_GoToNextScreen: - m_soundMusic.Stop(); + if( m_pSoundMusic ) + m_pSoundMusic->Stop(); GAMESTATE->Reset(); SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); // turn volume back on SCREENMAN->SetNewScreen( NEXT_SCREEN ); diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 5c3882b4fe..6614b4c012 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -95,6 +95,8 @@ void ScreenGameplay::Init() else LIGHTSMAN->SetLightsMode( LIGHTSMODE_GAMEPLAY ); + m_pSoundMusic = NULL; + /* We do this ourself. */ SOUND->HandleSongTimer( false ); @@ -782,7 +784,7 @@ ScreenGameplay::~ScreenGameplay() SAFE_DELETE( m_pInventory[p] ); } SAFE_DELETE( m_pCombinedLifeMeter ); - m_soundMusic.StopPlaying(); + m_pSoundMusic->StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ @@ -984,6 +986,9 @@ void ScreenGameplay::LoadNextSong() GAMESTATE->m_PlayerController[p] = PC_HUMAN; } + m_AutoKeysounds.FinishLoading(); + m_pSoundMusic = m_AutoKeysounds.GetSound(); + m_textSongTitle.SetText( GAMESTATE->m_pCurSong->m_sMainTitle ); /* XXX: set it to the current BPM, not the range */ @@ -1036,8 +1041,6 @@ void ScreenGameplay::LoadNextSong() LL.LoadFromLRCFile(GAMESTATE->m_pCurSong->GetLyricsPath(), *GAMESTATE->m_pCurSong); - m_soundMusic.Load( GAMESTATE->m_pCurSong->GetMusicPath() ); - /* Set up song-specific graphics. */ @@ -1143,7 +1146,7 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi //used for syncing up songs. NSMAN->StartRequest(1); - m_soundMusic.Play( &p ); + m_pSoundMusic->Play( &p ); /* Make sure GAMESTATE->m_fMusicSeconds is set up. */ GAMESTATE->m_fMusicSeconds = -5000; @@ -1224,11 +1227,11 @@ void ScreenGameplay::PlayAnnouncer( CString type, float fSeconds ) void ScreenGameplay::UpdateSongPosition( float fDeltaTime ) { - if( !m_soundMusic.IsPlaying() ) + if( !m_pSoundMusic->IsPlaying() ) return; RageTimer tm; - const float fSeconds = m_soundMusic.GetPositionSeconds( NULL, &tm ); + const float fSeconds = m_pSoundMusic->GetPositionSeconds( NULL, &tm ); const float fAdjust = SOUND->GetFrameTimingAdjustment( fDeltaTime ); GAMESTATE->UpdateSongPosition( fSeconds+fAdjust, GAMESTATE->m_pCurSong->m_Timing, tm+fAdjust ); } @@ -1717,7 +1720,7 @@ void ScreenGameplay::Input( const DeviceInput& DeviceI, const InputEventType typ * We're doing #3. I'm not sure which is best. */ - m_soundMusic.StopPlaying(); + m_pSoundMusic->StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ this->ClearMessageQueue(); @@ -2312,7 +2315,7 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) case SM_BeginFailed: m_DancingState = STATE_OUTRO; - m_soundMusic.StopPlaying(); + m_pSoundMusic->StopPlaying(); m_soundAssistTick.StopPlaying(); /* Stop any queued assist ticks. */ TweenOffScreen(); m_Failed.StartTransitioning( SM_GoToScreenAfterFail ); @@ -2385,7 +2388,7 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) } break; case SM_StopMusic: - m_soundMusic.Stop(); + m_pSoundMusic->Stop(); break; } } diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index 9ab6563a20..103d3b219d 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -177,7 +177,7 @@ protected: bool m_bDemonstration; RageSound m_soundAssistTick; - RageSound m_soundMusic; + RageSound *m_pSoundMusic; BeginnerHelper m_BeginnerHelper; diff --git a/stepmania/src/ScreenJukebox.cpp b/stepmania/src/ScreenJukebox.cpp index fc37fbe54f..8a7ab3fcfa 100644 --- a/stepmania/src/ScreenJukebox.cpp +++ b/stepmania/src/ScreenJukebox.cpp @@ -207,7 +207,8 @@ void ScreenJukebox::HandleScreenMessage( const ScreenMessage SM ) m_Out.StartTransitioning( SM_GoToNextScreen ); return; case SM_GoToNextScreen: - m_soundMusic.Stop(); + if( m_pSoundMusic ) + m_pSoundMusic->Stop(); SCREENMAN->SetNewScreen( "ScreenJukebox" ); return; }