diff --git a/stepmania/src/NotesLoaderBMS.cpp b/stepmania/src/NotesLoaderBMS.cpp index 4c59db7898..27160a787c 100644 --- a/stepmania/src/NotesLoaderBMS.cpp +++ b/stepmania/src/NotesLoaderBMS.cpp @@ -188,6 +188,22 @@ static StepsType DetermineStepsType( int iPlayer, const NoteData &nd ) } } +float BMSLoader::GetBeatsPerMeasure( int iMeasure ) const +{ + map::const_iterator time_sig = m_MeasureToTimeSig.find( iMeasure ); + if( time_sig != m_MeasureToTimeSig.end() ) + return 4.0f * time_sig->second; + return 4.0f; +} + +int BMSLoader::GetMeasureStartRow( int iMeasureNo ) const +{ + int iRowNo = 0; + for( int i = 0; i < iMeasureNo; ++i ) + iRowNo += BeatToNoteRow( GetBeatsPerMeasure(i) ); + return iRowNo; +} + bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out, const map &mapWavIdToKeysoundIndex ) { LOG->Trace( "Steps::LoadFromBMSFile( '%s' )", sPath.c_str() ); @@ -279,6 +295,9 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out, const map vTapNotes; @@ -310,8 +329,7 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Steps &out, const mapTrace( "Inserting new temp BPM change at beat %f, BPM %f", NoteRowToBeat(iStepIndex), fNewBPM ); + m_MeasureToTimeSig[iMeasureNo] = (float) atof(value_data); break; } case 3: { // bpm change // A 03: is a set of hex pairs in the same layout as a normal // (note-defining) line, where each non-0 hex pair is a BPM // change at that point. + float fBeatsPerMeasure = GetBeatsPerMeasure( iMeasureNo ); + int iRowsPerMeasure = BeatToNoteRow( fBeatsPerMeasure ); + int totalPairs = value_data.GetLength() / 2; - for( int i = 0; i < totalPairs*2; i+=2 ) + for( int i = 0; i < totalPairs; ++i ) { - CString sPair = value_data.substr(i,2); + CString sPair = value_data.substr(i*2,2); int iBPM = 0; if( sscanf( sPair, "%x", &iBPM ) == 1 && iBPM != 0 ) { - int iRow = iStepIndex+(1/(totalPairs*ROWS_PER_MEASURE)); + int iRow = iStepIndex + (i * iRowsPerMeasure) / totalPairs; float fBeat = NoteRowToBeat( iRow ); out.SetBPMAtBeat( fBeat, (float) iBPM ); LOG->Trace( "Inserting new BPM change at beat %f, BPM %i", fBeat, iBPM ); diff --git a/stepmania/src/NotesLoaderBMS.h b/stepmania/src/NotesLoaderBMS.h index 795fdf9c5e..32b2f6f85e 100644 --- a/stepmania/src/NotesLoaderBMS.h +++ b/stepmania/src/NotesLoaderBMS.h @@ -13,6 +13,10 @@ class BMSLoader: public NotesLoader void SlideDuplicateDifficulties( Song &p ); + map m_MeasureToTimeSig; + float GetBeatsPerMeasure( int iMeasure ) const; + int GetMeasureStartRow( int iMeasureNo ) const; + public: void GetApplicableFiles( CString sPath, CStringArray &out ); bool LoadFromDir( CString sDir, Song &out );