diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 68a0f7d089..574dc17fc4 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -186,10 +186,10 @@ void SMLoader::ProcessInstrumentTracks( Song &out, const RString &sParam ) } } -bool SMLoader::ProcessBPMs( TimingData &out, const RString sParam ) +bool SMLoader::ProcessBPMs( TimingData &out, const RString line, const int rowsPerBeat ) { vector arrayBPMChangeExpressions; - split( sParam, ",", arrayBPMChangeExpressions ); + split( line, ",", arrayBPMChangeExpressions ); // prepare storage variables for negative BPMs -> Warps. float negBeat = -1; @@ -211,7 +211,7 @@ bool SMLoader::ProcessBPMs( TimingData &out, const RString sParam ) bNotEmpty = true; - const float fBeat = StringToFloat( arrayBPMChangeValues[0] ); + const float fBeat = RowToBeat( arrayBPMChangeValues[0], rowsPerBeat ); const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] ); if( fNewBPM < 0.0f ) @@ -257,10 +257,10 @@ bool SMLoader::ProcessBPMs( TimingData &out, const RString sParam ) return bNotEmpty; } -void SMLoader::ProcessStops( TimingData &out, const RString sParam ) +void SMLoader::ProcessStops( TimingData &out, const RString line, const int rowsPerBeat ) { vector arrayFreezeExpressions; - split( sParam, ",", arrayFreezeExpressions ); + split( line, ",", arrayFreezeExpressions ); // Prepare variables for negative stop conversion. float negBeat = -1; @@ -278,7 +278,7 @@ void SMLoader::ProcessStops( TimingData &out, const RString sParam ) continue; } - const float fFreezeBeat = StringToFloat( arrayFreezeValues[0] ); + const float fFreezeBeat = RowToBeat( arrayFreezeValues[0], rowsPerBeat ); const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ); // Process the prior stop. @@ -323,10 +323,10 @@ void SMLoader::ProcessStops( TimingData &out, const RString sParam ) } } -void SMLoader::ProcessDelays( TimingData &out, const RString sParam ) +void SMLoader::ProcessDelays( TimingData &out, const RString line, const int rowsPerBeat ) { vector arrayDelayExpressions; - split( sParam, ",", arrayDelayExpressions ); + split( line, ",", arrayDelayExpressions ); for( unsigned f=0; f arrayBPMChangeExpressions; - split( sParam, ",", arrayBPMChangeExpressions ); - - // prepare storage variables for negative BPMs -> Warps. - float negBeat = -1; - float negBPM = 1; - float highspeedBeat = -1; - bool bNotEmpty = false; - - for( unsigned b=0; b arrayBPMChangeValues; - split( arrayBPMChangeExpressions[b], "=", arrayBPMChangeValues ); - // XXX: Hard to tell which file caused this. - if( arrayBPMChangeValues.size() != 2 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #BPMs value \"%s\" (must have exactly one '='), ignored.", - arrayBPMChangeExpressions[b].c_str() ); - continue; - } - - bNotEmpty = true; - - const float fBeat = RowToBeat( arrayBPMChangeValues[0], iRowsPerBeat ); - const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] ); - - if( fNewBPM < 0.0f ) - { - out.m_bHasNegativeBpms = true; - negBeat = fBeat; - negBPM = fNewBPM; - } - else if( fNewBPM > 0.0f ) - { - // add in a warp. - if( negBPM < 0 ) - { - float endBeat = fBeat + (fNewBPM / -negBPM) * (fBeat - negBeat); - WarpSegment new_seg(negBeat, endBeat - negBeat); - out.AddWarpSegment( new_seg ); - - negBeat = -1; - negBPM = 1; - } - // too fast. make it a warp. - if( fNewBPM > FAST_BPM_WARP ) - { - highspeedBeat = fBeat; - } - else - { - // add in a warp. - if( highspeedBeat > 0 ) - { - WarpSegment new_seg(highspeedBeat, fBeat - highspeedBeat); - out.AddWarpSegment( new_seg ); - highspeedBeat = -1; - } - { - BPMSegment new_seg( BeatToNoteRow( fBeat ), fNewBPM ); - out.AddBPMSegment( new_seg ); - } - } - } - } - - return bNotEmpty; -} - -void SMALoader::ProcessStops( TimingData &out, const int iRowsPerBeat, const RString sParam ) -{ - vector arrayFreezeExpressions; - split( sParam, ",", arrayFreezeExpressions ); - - // Prepare variables for negative stop conversion. - float negBeat = -1; - float negPause = 0; - - for( unsigned f=0; f arrayFreezeValues; - split( arrayFreezeExpressions[f], "=", arrayFreezeValues ); - if( arrayFreezeValues.size() != 2 ) - { - // XXX: Hard to tell which file caused this. - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #STOPS value \"%s\" (must have exactly one '='), ignored.", - arrayFreezeExpressions[f].c_str() ); - continue; - } - - const float fFreezeBeat = RowToBeat( arrayFreezeValues[0], iRowsPerBeat ); - const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ); - - // Process the prior stop. - if( negPause > 0 ) - { - BPMSegment oldBPM = out.GetBPMSegmentAtRow(BeatToNoteRow(negBeat)); - float fSecondsPerBeat = 60 / oldBPM.GetBPM(); - float fSkipBeats = negPause / fSecondsPerBeat; - - if( negBeat + fSkipBeats > fFreezeBeat ) - fSkipBeats = fFreezeBeat - negBeat; - - WarpSegment ws( negBeat, fSkipBeats); - out.AddWarpSegment( ws ); - - negBeat = -1; - negPause = 0; - } - - if( fFreezeSeconds < 0.0f ) - { - negBeat = fFreezeBeat; - negPause = -fFreezeSeconds; - } - else if( fFreezeSeconds > 0.0f ) - { - StopSegment ss( BeatToNoteRow(fFreezeBeat), fFreezeSeconds ); - out.AddStopSegment( ss ); - } - - } - - // Process the prior stop if there was one. - if( negPause > 0 ) - { - BPMSegment oldBPM = out.GetBPMSegmentAtRow(BeatToNoteRow(negBeat)); - float fSecondsPerBeat = 60 / oldBPM.GetBPM(); - float fSkipBeats = negPause / fSecondsPerBeat; - - WarpSegment ws( negBeat, fSkipBeats); - out.AddWarpSegment( ws ); - } -} - -void SMALoader::ProcessDelays( TimingData &out, const int iRowsPerBeat, const RString sParam ) -{ - vector arrayDelayExpressions; - split( sParam, ",", arrayDelayExpressions ); - - for( unsigned f=0; f arrayDelayValues; - split( arrayDelayExpressions[f], "=", arrayDelayValues ); - if( arrayDelayValues.size() != 2 ) - { - // XXX: Hard to tell which file caused this. - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #DELAYS value \"%s\" (must have exactly one '='), ignored.", - arrayDelayExpressions[f].c_str() ); - continue; - } - - const float fFreezeBeat = RowToBeat( arrayDelayValues[0], iRowsPerBeat ); - const float fFreezeSeconds = StringToFloat( arrayDelayValues[1] ); - - StopSegment new_seg( fFreezeBeat, fFreezeSeconds, true ); - // XXX: Remove Negatives Bug? - new_seg.SetBeat(fFreezeBeat); - new_seg.SetPause(fFreezeSeconds); - - // LOG->Trace( "Adding a delay segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds ); - - if(fFreezeSeconds > 0.0f) - out.AddStopSegment( new_seg ); - else - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid delay at beat %f, length %f.", fFreezeBeat, fFreezeSeconds ); - } -} - void SMALoader::ProcessTickcounts( TimingData &out, const int iRowsPerBeat, const RString sParam ) { vector arrayTickcountExpressions; @@ -606,21 +435,21 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessBPMs( timing, iRowsPerBeat, sParams[1] ); + ProcessBPMs( timing, sParams[1], iRowsPerBeat ); } else if( sValueName=="STOPS" || sValueName=="FREEZES" ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessStops( timing, iRowsPerBeat, sParams[1] ); + ProcessStops( timing, sParams[1], iRowsPerBeat ); } else if( sValueName=="DELAYS" ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessDelays( timing, iRowsPerBeat, sParams[1] ); + ProcessDelays( timing, sParams[1], iRowsPerBeat ); } else if( sValueName=="TICKCOUNT" ) diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 31026f5089..500e3de3f2 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -35,9 +35,6 @@ struct SMALoader : public SMLoader bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ); void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); - bool ProcessBPMs( TimingData &out, const int iRowsPerBeat, const RString sParam ); - void ProcessStops( TimingData &out, const int iRowsPerBeat, const RString sParam ); - void ProcessDelays( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessTickcounts( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RString sParam );