From 0464a86faf722a29695d74634d762debd7409280 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Sat, 14 May 2011 18:36:46 -0400 Subject: [PATCH] [splittiming] More progress. --- src/NotesLoaderSM.cpp | 9 +- src/NotesLoaderSM.h | 7 ++ src/NotesLoaderSMA.cpp | 196 +++++++++++++++++++---------------------- src/NotesLoaderSMA.h | 3 + 4 files changed, 103 insertions(+), 112 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 598c0d40ff..360ceaf111 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -15,11 +15,6 @@ /** @brief The maximum file size for edits. */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB -/** - * @brief The highest allowable speed before Warps come in. - * - * This was brought in from StepMania 4's recent betas. */ -const float FAST_BPM_WARP = 9999999.f; void SMLoader::LoadFromSMTokens( RString sStepsType, @@ -251,9 +246,7 @@ bool SMLoader::ProcessBPMs( TimingData &out, const RString sParam ) highspeedBeat = -1; } { - BPMSegment new_seg; - new_seg.m_iStartRow = BeatToNoteRow(fBeat); - new_seg.SetBPM( fNewBPM ); + BPMSegment new_seg( BeatToNoteRow( fBeat ), fNewBPM ); out.AddBPMSegment( new_seg ); } } diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 8628d7dde2..d1c4feded0 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -8,6 +8,13 @@ class Song; class Steps; class TimingData; + +/** + * @brief The highest allowable speed before Warps come in. + * + * This was brought in from StepMania 4's recent betas. */ +const float FAST_BPM_WARP = 9999999.f; + /** @brief Reads a Song from an .SM file. */ namespace SMLoader { diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index 9e9d2ab7b6..0fd989a7b5 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -39,6 +39,91 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) return LoadFromSMAFile( sPath + aFileNames[0], out ); } +float SMALoader::RowToBeat( RString sLine, const int iRowsPerBeat ) +{ + if( sLine.Right(0).MakeUpper() == "R" ) + { + sLine = sLine.Left(sLine.size()-1); + return StringToFloat( sLine ) / iRowsPerBeat; + } + else + { + return StringToFloat( sLine ); + } +} + +bool SMALoader::ProcessBPMs( TimingData &out, const int iRowsPerBeat, const RString sParam ) +{ + vector 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); + 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); + out.AddWarpSegment( new_seg ); + highspeedBeat = -1; + } + { + BPMSegment new_seg( BeatToNoteRow( fBeat ), fNewBPM ); + out.AddBPMSegment( new_seg ); + } + } + } + } + + return bNotEmpty; +} + + void SMALoader::ProcessBeatsPerMeasure( TimingData &out, const RString sParam ) { vector vs1; @@ -364,7 +449,12 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) timing.m_fBeat0OffsetInSeconds = StringToFloat( sParams[1] ); } - + else if( sValueName=="BPMS" ) + { + TimingData &timing = (state == SMA_GETTING_STEP_INFO + ? pNewNotes->m_Timing : out.m_SongTiming); + ProcessBPMs( timing, iRowsPerBeat, sParams[1] ); + } else if( sValueName=="KEYSOUNDS" ) { @@ -400,7 +490,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) * We used to check for timing data in this section. That has * since been moved to a dedicated function. */ - else if( sValueName=="BPMS" || sValueName=="STOPS" || sValueName=="FREEZES" || sValueName=="DELAYS" || sValueName=="TIMESIGNATURES" || sValueName=="LEADTRACK" || sValueName=="TICKCOUNTS" ) + else if( sValueName=="STOPS" || sValueName=="FREEZES" || sValueName=="DELAYS" || sValueName=="TIMESIGNATURES" || sValueName=="LEADTRACK" || sValueName=="TICKCOUNTS" ) ; else LOG->UserLog( "Song file", sPath, "has an unexpected value named \"%s\".", sValueName.c_str() ); @@ -488,108 +578,6 @@ void SMALoader::LoadTimingFromSMAFile( const MsdFile &msd, TimingData &out ) } } - else if( sValueName=="BPMS" ) - { - vector arrayBPMChangeExpressions; - split( sParams[1], ",", arrayBPMChangeExpressions ); - - 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 #%s value \"%s\" (must have exactly one '='), ignored.", - sValueName.c_str(), arrayBPMChangeExpressions[b].c_str() ); - continue; - } - - float fBeat = 0; - RString beat = arrayBPMChangeValues[0]; - if( beat.Right(0).MakeUpper() == "R" ) - { - beat = beat.Left(beat.size()-1); - fBeat = StringToFloat( beat ) / rowsPerMeasure; - } - else - { - fBeat = StringToFloat(beat); - } - - //float fBeat = StringToFloat( arrayBPMChangeValues[0] ); - const float fNewBPM = StringToFloat( arrayBPMChangeValues[1] ); - // XXX: Remove Negatives Bug? - BPMSegment new_seg; - new_seg.m_iStartRow = BeatToNoteRow(fBeat); - new_seg.SetBPM( fNewBPM ); - - // convert negative BPMs into Warp segments - if( fNewBPM < 0.0f ) - { - vector arrayNextBPMChangeValues; - // get next bpm in sequence - if((b+1) < arrayBPMChangeExpressions.size()) - { - split( arrayBPMChangeExpressions[b+1], "=", arrayNextBPMChangeValues ); - const float fNextPositiveBeat = StringToFloat( arrayNextBPMChangeValues[0] ); - const float fNextPositiveBPM = StringToFloat( arrayNextBPMChangeValues[1] ); - - // tJumpPos = (tPosBPS-abs(negBPS)) + (gPosBPMPosition - fNegPosition) - float fDeltaBeat = ((fNextPositiveBPM/60.0f)-abs(fNewBPM/60.0f)) + (fNextPositiveBeat-fBeat); - //float fWarpLengthBeats = fNextPositiveBeat + fDeltaBeat; - WarpSegment wsTemp(BeatToNoteRow(fBeat),fDeltaBeat); - arrayWarpsFromNegativeBPMs.push_back(wsTemp); - - /* - LOG->Trace( ssprintf("==NotesLoSM negbpm==\nfnextposbeat = %f, fnextposbpm = %f,\nfdelta = %f, fwarpto = %f", - fNextPositiveBeat, - fNextPositiveBPM, - fDeltaBeat, - fWarpToBeat - ) ); - */ - /* - LOG->Trace( ssprintf("==Negative/Subtractive BPM in NotesLoader==\nNegBPM has noterow = %i, BPM = %f\nNextBPM @ noterow %i\nDelta value = %i noterows\nThis warp will have us end up at noterow %i", - BeatToNoteRow(fBeat), fNewBPM, - BeatToNoteRow(fNextPositiveBeat), - BeatToNoteRow(fDeltaBeat), - BeatToNoteRow(fWarpToBeat)) - ); - */ - //float fDeltaBeat = ((fNextPositiveBPM/60.0f)-abs(fNewBPM/60.0f)) + (fNextPositiveBeat-fBeat); - /* - LOG->Trace( ssprintf("==NotesLoader Delta as NoteRows==\nfDeltaBeat = %f (beat)\nfDeltaBeat = (NextBPMSeg %f - abs(fBPS %f)) + (nextStartRow %i - thisRow %i)", - fDeltaBeat,(fNextPositiveBPM/60.0f),abs(fNewBPM/60.0f),BeatToNoteRow(fNextPositiveBeat),BeatToNoteRow(fBeat)) - ); - */ - - out.AddBPMSegment( new_seg ); - - continue; - } - else - { - // last BPM is a negative one? ugh. -aj (MAX_NOTE_ROW exists btw) - out.AddBPMSegment( new_seg ); - } - } - - if(fNewBPM > 0.0f) - out.AddBPMSegment( new_seg ); - else - { - out.m_bHasNegativeBpms = true; - // only add Negative BPMs in quirks mode -aj - if( PREFSMAN->m_bQuirksMode ) - out.AddBPMSegment( new_seg ); - else - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid BPM change at beat %f, BPM %f.", fBeat, fNewBPM ); - } - } - } - - // Note: Even though it is possible to have Negative BPMs and Stops in // a song along with Warps, we should not support files that contain // both styles of warp tricks (Negatives vs. #WARPS). diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 4d59e79f0a..5c7300d133 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -42,6 +42,9 @@ namespace SMALoader bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ); void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); + bool ProcessBPMs( TimingData &out, const int iRowsPerBeat, const RString sParam ); + + float RowToBeat( RString sLine, const int iRowsPerBeat ); }; #endif