From adb0d5d4a1cdcdd874c3cf096f6468d4d1d3959b Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 9 May 2013 00:00:14 -0400 Subject: [PATCH] Separate functions for BPM/stop parsing and processing --- src/NotesLoaderSM.cpp | 28 +++++++++++++++++----------- src/NotesLoaderSM.h | 38 +++++++++++++++++++++++++------------- src/NotesLoaderSMA.cpp | 8 ++++++-- src/NotesLoaderSSC.cpp | 24 ++++++++++++++++++------ 4 files changed, 66 insertions(+), 32 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index a811e40fd2..6e222d2f54 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -210,13 +210,11 @@ void SMLoader::ProcessInstrumentTracks( Song &out, const RString &sParam ) } } -bool SMLoader::ProcessBPMs( TimingData &out, const RString line, const int rowsPerBeat ) +void SMLoader::ParseBPMs( vector< pair > &out, const RString line, const int rowsPerBeat ) { vector arrayBPMChangeExpressions; split( line, ",", arrayBPMChangeExpressions ); - vector< pair > vBPMChanges; - for( unsigned b=0; b arrayBPMChangeValues; @@ -233,9 +231,12 @@ bool SMLoader::ProcessBPMs( TimingData &out, const RString line, const int rowsP const float fBeat = RowToBeat( arrayBPMChangeValues[0], rowsPerBeat ); const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] ); - vBPMChanges.push_back( make_pair(fBeat, fNewBPM) ); + out.push_back( make_pair(fBeat, fNewBPM) ); } +} +bool SMLoader::ProcessBPMs( TimingData &out, const vector< pair > &vBPMChanges ) +{ // prepare storage variables for negative BPMs -> Warps. float negBeat = -1; float negBPM = 1; @@ -289,13 +290,11 @@ bool SMLoader::ProcessBPMs( TimingData &out, const RString line, const int rowsP return bNotEmpty; } -void SMLoader::ProcessStops( TimingData &out, const RString line, const int rowsPerBeat ) +void SMLoader::ParseStops( vector< pair > &out, const RString line, const int rowsPerBeat ) { vector arrayFreezeExpressions; split( line, ",", arrayFreezeExpressions ); - vector< pair > vStops; - for( unsigned f=0; f arrayFreezeValues; @@ -312,9 +311,12 @@ void SMLoader::ProcessStops( TimingData &out, const RString line, const int rows const float fFreezeBeat = RowToBeat( arrayFreezeValues[0], rowsPerBeat ); const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ); - vStops.push_back( make_pair(fFreezeBeat, fFreezeSeconds) ); + out.push_back( make_pair(fFreezeBeat, fFreezeSeconds) ); } - +} + +void SMLoader::ProcessStops( TimingData &out, const vector< pair > &vStops ) +{ // Prepare variables for negative stop conversion. float negBeat = -1; float negPause = 0; @@ -798,12 +800,16 @@ bool SMLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache } else if( sValueName=="BPMS" ) { - ProcessBPMs(out.m_SongTiming, sParams[1]); + vector< pair > vBPMChanges; + ParseBPMs(vBPMChanges, sParams[1]); + ProcessBPMs(out.m_SongTiming, vBPMChanges); } else if( sValueName=="STOPS" || sValueName=="FREEZES" ) { - ProcessStops(out.m_SongTiming, sParams[1]); + vector< pair > vStops; + ParseStops(vStops, sParams[1]); + ProcessStops(out.m_SongTiming, vStops); } else if( sValueName=="DELAYS" ) diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 91bafe26e8..0fa2dbc013 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -69,22 +69,34 @@ struct SMLoader const RString &sBGChangeExpression ); /** - * @brief Process the BPM Segments from the string. - * @param out the TimingData being modified. - * @param line the string in question. - * @param rowsPerBeat the number of rows per beat for this purpose. - * @return true if there was at least one segment found, false otherwise. */ - bool ProcessBPMs(TimingData & out, - const RString line, - const int rowsPerBeat = -1); - /** - * @brief Process the Stop Segments from the string. - * @param out the TimingData being modified. + * @brief Parse BPM Changes data from a string. + * @param out the vector to put the data in. * @param line the string in question. * @param rowsPerBeat the number of rows per beat for this purpose. */ + void ParseBPMs(vector< pair > &out, + const RString line, + const int rowsPerBeat = -1); + /** + * @brief Process the BPM Segments from the string. + * @param out the TimingData being modified. + * @param vBPMChanges the vector of BPM Changes data. + * @return true if there was at least one segment found, false otherwise. */ + bool ProcessBPMs(TimingData & out, + const vector< pair > &vBPMChanges); + /** + * @brief Parse Stops data from a string. + * @param out the vector to put the data in. + * @param line the string in question. + * @param rowsPerBeat the number of rows per beat for this purpose. */ + void ParseStops(vector< pair > &out, + const RString line, + const int rowsPerBeat = -1); + /** + * @brief Process the Stop Segments from the data. + * @param out the TimingData being modified. + * @param vStops the vector of Stops data. */ void ProcessStops(TimingData & out, - const RString line, - const int rowsPerBeat = -1); + const vector< pair > &vStops); /** * @brief Process the Delay Segments from the string. * @param out the TimingData being modified. diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index 43d5d08b50..d5ca88124a 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -365,14 +365,18 @@ bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessBPMs( timing, sParams[1], iRowsPerBeat ); + vector< pair > vBPMChanges; + ParseBPMs( vBPMChanges, sParams[1], iRowsPerBeat ); + ProcessBPMs( timing, vBPMChanges ); } else if( sValueName=="STOPS" || sValueName=="FREEZES" ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessStops( timing, sParams[1], iRowsPerBeat ); + vector< pair > vStops; + ParseStops( vStops, sParams[1], iRowsPerBeat ); + ProcessStops( timing, vStops ); } else if( sValueName=="DELAYS" ) diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index c55d556137..107570d24f 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -473,7 +473,9 @@ bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach * if the steps do not have their own timing. */ else if( sValueName=="STOPS" ) { - SMLoader::ProcessStops(out.m_SongTiming, sParams[1]); + vector< pair > vStops; + SMLoader::ParseStops(vStops, sParams[1]); + SMLoader::ProcessStops(out.m_SongTiming, vStops); } else if( sValueName=="DELAYS" ) { @@ -482,7 +484,9 @@ bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach else if( sValueName=="BPMS" ) { - SMLoader::ProcessBPMs(out.m_SongTiming, sParams[1]); + vector< pair > vBPMChanges; + SMLoader::ParseBPMs(vBPMChanges, sParams[1]); + SMLoader::ProcessBPMs(out.m_SongTiming, vBPMChanges); } else if( sValueName=="WARPS" ) // Older versions allowed em here. @@ -659,7 +663,9 @@ bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach { if (out.m_fVersion >= VERSION_SPLIT_TIMING) { - if( SMLoader::ProcessBPMs(stepsTiming, sParams[1]) ) + vector< pair > vBPMChanges; + SMLoader::ParseBPMs(vBPMChanges, sParams[1]); + if( SMLoader::ProcessBPMs(stepsTiming, vBPMChanges) ) bHasOwnTiming = true; } } @@ -668,7 +674,9 @@ bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach { if (out.m_fVersion >= VERSION_SPLIT_TIMING) { - SMLoader::ProcessStops(stepsTiming, sParams[1]); + vector< pair > vStops; + SMLoader::ParseStops(vStops, sParams[1]); + SMLoader::ProcessStops(stepsTiming, vStops); bHasOwnTiming = true; } } @@ -945,14 +953,18 @@ bool SSCLoader::LoadEditFromMsd(const MsdFile &msd, else if( sValueName=="BPMS" ) { - if( SMLoader::ProcessBPMs(stepsTiming, sParams[1]) ) + vector< pair > vBPMChanges; + SMLoader::ParseBPMs(vBPMChanges, sParams[1]); + if( SMLoader::ProcessBPMs(stepsTiming, vBPMChanges) ) bHasOwnTiming = true; bSSCFormat = true; } else if( sValueName=="STOPS" ) { - SMLoader::ProcessStops(stepsTiming, sParams[1]); + vector< pair > vStops; + SMLoader::ParseStops(vStops, sParams[1]); + SMLoader::ProcessStops(stepsTiming, vStops); bSSCFormat = true; }