Separate functions for BPM/stop parsing and processing

This commit is contained in:
Devin J. Pohly
2013-05-09 00:00:14 -04:00
parent 536768c91b
commit adb0d5d4a1
4 changed files with 66 additions and 32 deletions
+17 -11
View File
@@ -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<float, float> > &out, const RString line, const int rowsPerBeat )
{
vector<RString> arrayBPMChangeExpressions;
split( line, ",", arrayBPMChangeExpressions );
vector< pair<float, float> > vBPMChanges;
for( unsigned b=0; b<arrayBPMChangeExpressions.size(); b++ )
{
vector<RString> 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<float, float> > &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<float, float> > &out, const RString line, const int rowsPerBeat )
{
vector<RString> arrayFreezeExpressions;
split( line, ",", arrayFreezeExpressions );
vector< pair<float, float> > vStops;
for( unsigned f=0; f<arrayFreezeExpressions.size(); f++ )
{
vector<RString> 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<float, float> > &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<float, float> > vBPMChanges;
ParseBPMs(vBPMChanges, sParams[1]);
ProcessBPMs(out.m_SongTiming, vBPMChanges);
}
else if( sValueName=="STOPS" || sValueName=="FREEZES" )
{
ProcessStops(out.m_SongTiming, sParams[1]);
vector< pair<float, float> > vStops;
ParseStops(vStops, sParams[1]);
ProcessStops(out.m_SongTiming, vStops);
}
else if( sValueName=="DELAYS" )
+25 -13
View File
@@ -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<float, float> > &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<float, float> > &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<float, float> > &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<float, float> > &vStops);
/**
* @brief Process the Delay Segments from the string.
* @param out the TimingData being modified.
+6 -2
View File
@@ -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<float, float> > 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<float, float> > vStops;
ParseStops( vStops, sParams[1], iRowsPerBeat );
ProcessStops( timing, vStops );
}
else if( sValueName=="DELAYS" )
+18 -6
View File
@@ -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<float, float> > 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<float, float> > 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<float, float> > 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<float, float> > 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<float, float> > 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<float, float> > vStops;
SMLoader::ParseStops(vStops, sParams[1]);
SMLoader::ProcessStops(stepsTiming, vStops);
bSSCFormat = true;
}