From b6bf776716064bd96166e65dd2ebb1663d5aeddd Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 13:46:30 -0400 Subject: [PATCH 01/11] New branch: [notesloader] Time to better unify our files and refactor properly. --- src/GameSoundManager.cpp | 10 ++++++---- src/NotesLoader.cpp | 17 ++++++++++------- src/NotesLoaderSM.h | 8 +++++--- src/NotesLoaderSMA.h | 3 ++- src/NotesLoaderSSC.cpp | 13 +------------ src/NotesLoaderSSC.h | 6 ++++-- src/ScreenGameplaySyncMachine.cpp | 6 ++++-- src/ScreenHowToPlay.cpp | 6 ++++-- src/ScreenServiceAction.cpp | 3 ++- src/Song.cpp | 8 +++++--- src/SongManager.cpp | 9 ++++++--- src/Steps.cpp | 6 ++++-- 12 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index a9e71fce24..8b878c50ef 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -142,8 +142,10 @@ static void StartMusic( MusicToPlay &ToPlay ) { LOG->Trace( "Found '%s'", ToPlay.m_sTimingFile.c_str() ); Song song; - if( GetExtension(ToPlay.m_sTimingFile) == ".ssc" && - SSCLoader::LoadFromSSCFile(ToPlay.m_sTimingFile, song) ) + SSCLoader loaderSSC; + SMLoader loaderSM; + if(GetExtension(ToPlay.m_sTimingFile) == ".ssc" && + loaderSSC.LoadFromSSCFile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; @@ -152,8 +154,8 @@ static void StartMusic( MusicToPlay &ToPlay ) if( pStepsCabinetLights ) pStepsCabinetLights->GetNoteData( ToPlay.m_LightsData ); } - else if( GetExtension(ToPlay.m_sTimingFile) == ".sm" && - SMLoader::LoadFromSMFile(ToPlay.m_sTimingFile, song) ) + else if(GetExtension(ToPlay.m_sTimingFile) == ".sm" && + loaderSM.LoadFromSMFile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; diff --git a/src/NotesLoader.cpp b/src/NotesLoader.cpp index 88f68787aa..983f35cedb 100644 --- a/src/NotesLoader.cpp +++ b/src/NotesLoader.cpp @@ -32,20 +32,23 @@ bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set &Bl vector list; BlacklistedImages.clear(); - SSCLoader::GetApplicableFiles( sPath, list ); + SSCLoader loaderSSC; + loaderSSC.GetApplicableFiles( sPath, list ); if( !list.empty() ) { - if( !SSCLoader::LoadFromDir( sPath, out ) ) + if( !loaderSSC.LoadFromDir( sPath, out ) ) return false; - SSCLoader::TidyUpData( out, false ); + loaderSSC.TidyUpData( out, false ); return true; } - SMALoader::GetApplicableFiles( sPath, list ); + SMALoader loaderSMA; + loaderSMA.GetApplicableFiles( sPath, list ); if (!list.empty() ) - return SMALoader::LoadFromDir( sPath, out ); - SMLoader::GetApplicableFiles( sPath, list ); + return loaderSMA.LoadFromDir( sPath, out ); + SMLoader loaderSM; + loaderSM.GetApplicableFiles( sPath, list ); if (!list.empty() ) - return SMLoader::LoadFromDir( sPath, out ); + return loaderSM.LoadFromDir( sPath, out ); DWILoader::GetApplicableFiles( sPath, list ); if( !list.empty() ) return DWILoader::LoadFromDir( sPath, out, BlacklistedImages ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 94dfdd2dfe..0d947ea28a 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -16,8 +16,9 @@ class TimingData; const float FAST_BPM_WARP = 9999999.f; /** @brief Reads a Song from an .SM file. */ -namespace SMLoader +struct SMLoader { + virtual ~SMLoader() {} void LoadFromSMTokens( RString sStepsType, RString sDescription, RString sDifficulty, RString sMeter, RString sRadarValues, RString sNoteData, Steps &out ); @@ -29,7 +30,8 @@ namespace SMLoader bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ); + virtual bool LoadFromBGChangesString(BackgroundChange &change, + const RString &sBGChangeExpression ); bool ProcessBPMs( TimingData &, const RString ); @@ -41,7 +43,7 @@ namespace SMLoader const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); void ProcessInstrumentTracks( Song &out, const RString &sParam ); -} +}; #endif diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index c9e3dfa811..fec87e8fce 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -2,6 +2,7 @@ #define NOTES_LOADER_SMA_H #include "GameConstantsAndTypes.h" +#include "NotesLoaderSM.h" #include "BackgroundUtil.h" class MsdFile; @@ -20,7 +21,7 @@ enum SMALoadingStates }; /** @brief Reads a Song from a .SMA file. */ -namespace SMALoader +struct SMALoader : public SMLoader { void LoadFromSMATokens( RString sStepsType, RString sDescription, diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index 04a4fdc167..b9180850ae 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -19,17 +19,6 @@ */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB -/** - * @brief Attempt to load any background changes in use by this song. - * @param change a reference to the background change. - * @param sBGChangeExpression a reference to the list of changes to be made. - * @return its success or failure. - */ -bool LoadFromBGSSCChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) -{ - return SMLoader::LoadFromBGChangesString( change, sBGChangeExpression ); -} - bool SSCLoader::LoadFromDir( const RString &sPath, Song &out ) { vector aFileNames; @@ -421,7 +410,7 @@ bool SSCLoader::LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCach for( unsigned b=0; bGetPathO("ScreenGameplaySyncMachine","music"); // Allow themers to use either a .ssc or .sm file for this. -aj + SSCLoader loaderSSC; + SMLoader loaderSM; if(sFile.Right(4) == ".ssc") - SSCLoader::LoadFromSSCFile( sFile, m_Song ); + loaderSSC.LoadFromSSCFile( sFile, m_Song ); else - SMLoader::LoadFromSMFile( sFile, m_Song ); + loaderSM.LoadFromSMFile( sFile, m_Song ); m_Song.SetSongDir( Dirname(sFile) ); m_Song.TidyUpData(); diff --git a/src/ScreenHowToPlay.cpp b/src/ScreenHowToPlay.cpp index b38848bb7d..64ce65815c 100644 --- a/src/ScreenHowToPlay.cpp +++ b/src/ScreenHowToPlay.cpp @@ -135,10 +135,12 @@ void ScreenHowToPlay::Init() // Allow themers to use either a .ssc or .sm file for this. -aj RString sStepsPath = THEME->GetPathO(m_sName, "steps"); + SSCLoader loaderSSC; + SMLoader loaderSM; if( sStepsPath.Right(4) == ".ssc" ) - SSCLoader::LoadFromSSCFile( sStepsPath, m_Song, false ); + loaderSSC.LoadFromSSCFile( sStepsPath, m_Song, false ); else - SMLoader::LoadFromSMFile( sStepsPath, m_Song, false ); + loaderSM.LoadFromSMFile( sStepsPath, m_Song, false ); m_Song.AddAutoGenNotes(); const Style* pStyle = GAMESTATE->GetCurrentStyle(); diff --git a/src/ScreenServiceAction.cpp b/src/ScreenServiceAction.cpp index 13e1222260..c28086a72c 100644 --- a/src/ScreenServiceAction.cpp +++ b/src/ScreenServiceAction.cpp @@ -197,7 +197,8 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile iNumErrored++; // Test whether the song we need for this edit is present and ignore this edit if not present. - if( !SSCLoader::LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) ) + SSCLoader loaderSSC; + if( !loaderSSC.LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) ) { iNumIgnored++; continue; diff --git a/src/Song.cpp b/src/Song.cpp index e6196ac12e..d547a02e47 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -235,12 +235,14 @@ bool Song::LoadFromSongDir( RString sDir ) if( bUseCache ) { // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); - bool bLoadedFromSSC = SSCLoader::LoadFromSSCFile( sCacheFilePath, *this, true ); + SSCLoader loaderSSC; + bool bLoadedFromSSC = loaderSSC.LoadFromSSCFile( sCacheFilePath, *this, true ); if( !bLoadedFromSSC ) { // load from .sm - SMLoader::LoadFromSMFile( sCacheFilePath, *this, true ); - SMLoader::TidyUpData( *this, true ); + SMLoader loaderSM; + loaderSM.LoadFromSMFile( sCacheFilePath, *this, true ); + loaderSM.TidyUpData( *this, true ); } } else diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 48a7d3c5eb..e25374c739 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -1655,12 +1655,15 @@ void SongManager::LoadStepEditsFromProfileDir( const RString &sProfileDir, Profi for( int i=0; iWarn( "Couldn't load \"%s\"", m_sFilename.c_str() ); return; From e00b7f36160b9bd04c4c9f94f98e843e034fb81b Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:01:55 -0400 Subject: [PATCH 02/11] [notesloader] Some refactoring done. --- src/NotesLoaderSM.cpp | 23 +++++++++++++++++++---- src/NotesLoaderSM.h | 29 +++++++++++++++++++++++++++-- src/NotesLoaderSMA.cpp | 33 ++------------------------------- src/NotesLoaderSMA.h | 12 +----------- src/NotesLoaderSSC.cpp | 10 +++++++--- 5 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index f18c556056..68a0f7d089 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -16,7 +16,22 @@ /** @brief The maximum file size for edits. */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB -void SMLoader::LoadFromSMTokens( +float SMLoader::RowToBeat( RString line, const int rowsPerBeat ) +{ + RString backup = line; + Trim(line, "r"); + Trim(line, "R"); + if( backup != line ) + { + return StringToFloat( line ) / rowsPerBeat; + } + else + { + return StringToFloat( line ); + } +} + +void SMLoader::LoadFromTokens( RString sStepsType, RString sDescription, RString sDifficulty, @@ -34,7 +49,7 @@ void SMLoader::LoadFromSMTokens( Trim( sDifficulty ); Trim( sNoteData ); - // LOG->Trace( "Steps::LoadFromSMTokens()" ); + // LOG->Trace( "Steps::LoadFromTokens()" ); // insert stepstype hacks from GameManager.cpp here? -aj out.m_StepsType = GAMEMAN->StringToStepsType( sStepsType ); @@ -719,7 +734,7 @@ bool SMLoader::LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache } Steps* pNewNotes = out.CreateSteps(); - LoadFromSMTokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], @@ -853,7 +868,7 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath return true; Steps* pNewNotes = pSong->CreateSteps(); - LoadFromSMTokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], *pNewNotes); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 0d947ea28a..3c635a2fb8 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -19,8 +19,6 @@ const float FAST_BPM_WARP = 9999999.f; struct SMLoader { virtual ~SMLoader() {} - void LoadFromSMTokens( RString sStepsType, RString sDescription, RString sDifficulty, - RString sMeter, RString sRadarValues, RString sNoteData, Steps &out ); bool LoadFromDir( const RString &sPath, Song &out ); void TidyUpData( Song &song, bool bFromCache ); @@ -43,6 +41,33 @@ struct SMLoader const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); void ProcessInstrumentTracks( Song &out, const RString &sParam ); + + /** + * @brief Convert a row value to the proper beat value. + * + * This is primarily used for assistance with converting SMA files. + * @param line The line that contains the value. + * @param rowsPerBeat the number of rows per beat according to the original file. + * @return the converted beat value. */ + float RowToBeat(RString line, const int rowsPerBeat); + +protected: + /** + * @brief Process the different tokens we have available to get NoteData. + * @param stepsType The current StepsType. + * @param description The description of the chart. + * @param difficulty The difficulty (in words) of the chart. + * @param meter the difficulty (in numbers) of the chart. + * @param radarValues the calculated radar values. + * @param noteData the note data itself. + * @param out the Steps getting the data. */ + virtual void LoadFromTokens(RString sStepsType, + RString sDescription, + RString sDifficulty, + RString sMeter, + RString sRadarValues, + RString sNoteData, + Steps &out); }; #endif diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index c902b1f103..069724542a 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -39,19 +39,6 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) return LoadFromSMAFile( sPath + aFileNames[0], out ); } -float SMALoader::RowToBeat( RString sLine, const int iRowsPerBeat ) -{ - if( sLine.find("R") || sLine.find("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; @@ -391,22 +378,6 @@ void SMALoader::ProcessFakes( TimingData &out, const int iRowsPerBeat, const RSt } } - -void SMALoader::LoadFromSMATokens( - RString sStepsType, - RString sDescription, - RString sDifficulty, - RString sMeter, - RString sRadarValues, - RString sNoteData, - Steps &out -) -{ - SMLoader::LoadFromSMTokens( sStepsType, sDescription, - sDifficulty, sMeter, sRadarValues, - sNoteData, out ); -} - void SMALoader::TidyUpData( Song &song, bool bFromCache ) { SMLoader::TidyUpData( song, bFromCache ); @@ -706,7 +677,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) continue; } - LoadFromSMATokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], @@ -815,7 +786,7 @@ bool SMALoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePat return true; Steps* pNewNotes = pSong->CreateSteps(); - LoadFromSMATokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], *pNewNotes); diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index fec87e8fce..31026f5089 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -22,15 +22,7 @@ enum SMALoadingStates /** @brief Reads a Song from a .SMA file. */ struct SMALoader : public SMLoader -{ - void LoadFromSMATokens( RString sStepsType, - RString sDescription, - RString sDifficulty, - RString sMeter, - RString sRadarValues, - RString sNoteData, - Steps &out ); - +{ bool LoadFromDir( const RString &sPath, Song &out ); void TidyUpData( Song &song, bool bFromCache ); @@ -50,8 +42,6 @@ struct SMALoader : public SMLoader void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ); - - float RowToBeat( RString sLine, const int iRowsPerBeat ); }; #endif diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index b9180850ae..54c7e208b5 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -872,9 +872,13 @@ bool SSCLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePat else { pNewNotes = pSong->CreateSteps(); - SMLoader::LoadFromSMTokens( - sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], - *pNewNotes); + LoadFromTokens(sParams[1], + sParams[2], + sParams[3], + sParams[4], + sParams[5], + sParams[6], + *pNewNotes); } pNewNotes->SetLoadedFromProfile( slot ); From d2be04719d2849e69dc0e3b8b654cf177a315ed3 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:19:12 -0400 Subject: [PATCH 03/11] [notesloader] More refactoring. --- src/NotesLoaderSM.cpp | 18 ++--- src/NotesLoaderSM.h | 33 ++++++-- src/NotesLoaderSMA.cpp | 177 +---------------------------------------- src/NotesLoaderSMA.h | 3 - 4 files changed, 39 insertions(+), 192 deletions(-) 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 ); From e37fe84d6a6dfdf9e29a916d03b9356466026401 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:32:14 -0400 Subject: [PATCH 04/11] [notesloader] Simplify. --- src/NotesLoaderSM.cpp | 27 ++++---- src/NotesLoaderSM.h | 28 ++++++-- src/NotesLoaderSMA.cpp | 148 +---------------------------------------- src/NotesLoaderSMA.h | 7 -- 4 files changed, 36 insertions(+), 174 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 574dc17fc4..bb465057d4 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -94,11 +94,6 @@ void SMLoader::LoadFromTokens( out.TidyUpData(); } -void SMLoader::GetApplicableFiles( const RString &sPath, vector &out ) -{ - GetDirListing( sPath + RString("*.sm"), out ); -} - void SMLoader::ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam ) { BackgroundLayer iLayer = BACKGROUND_LAYER_1; @@ -357,10 +352,10 @@ void SMLoader::ProcessDelays( TimingData &out, const RString line, const int row } } -void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam ) +void SMLoader::ProcessTimeSignatures( TimingData &out, const RString line, const int rowsPerBeat ) { vector vs1; - split( sParam, ",", vs1 ); + split( line, ",", vs1 ); FOREACH_CONST( RString, vs1, s1 ) { @@ -373,9 +368,9 @@ void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam ) continue; } - const float fBeat = StringToFloat( vs2[0] ); + const float fBeat = RowToBeat( vs2[0], rowsPerBeat ); - TimeSignatureSegment seg( BeatToNoteRow( fBeat ), StringToInt( vs2[1] ), StringToInt( vs2[2] )); + TimeSignatureSegment seg( fBeat, StringToInt( vs2[1] ), StringToInt( vs2[2] )); if( fBeat < 0 ) { @@ -399,10 +394,10 @@ void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam ) } } -void SMLoader::ProcessTickcounts( TimingData &out, const RString sParam ) +void SMLoader::ProcessTickcounts( TimingData &out, const RString line, const int rowsPerBeat ) { vector arrayTickcountExpressions; - split( sParam, ",", arrayTickcountExpressions ); + split( line, ",", arrayTickcountExpressions ); for( unsigned f=0; f aBGChangeValues; @@ -896,6 +892,11 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath } +void SMLoader::GetApplicableFiles( const RString &sPath, vector &out ) +{ + GetDirListing( sPath + RString("*.sm"), out ); +} + void SMLoader::TidyUpData( Song &song, bool bFromCache ) { /* diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 21b5e20398..a3da6ecde1 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -21,13 +21,13 @@ struct SMLoader virtual ~SMLoader() {} bool LoadFromDir( const RString &sPath, Song &out ); - void TidyUpData( Song &song, bool bFromCache ); + virtual void TidyUpData( Song &song, bool bFromCache ); bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); void GetApplicableFiles( const RString &sPath, vector &out ); - bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); - bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); + virtual bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); + virtual bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); + virtual bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); virtual bool LoadFromBGChangesString(BackgroundChange &change, const RString &sBGChangeExpression ); @@ -49,15 +49,29 @@ struct SMLoader const RString line, const int rowsPerBeat = -1); /** - * @brief Process the Stop Segments from the string. + * @brief Process the Delay 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. */ void ProcessDelays(TimingData & out, const RString line, const int rowsPerBeat = -1); - void ProcessTimeSignatures( TimingData & out, const RString line ); - void ProcessTickcounts( TimingData & out, const RString line ); + /** + * @brief Process the Time Signature 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. */ + void ProcessTimeSignatures(TimingData & out, + const RString line, + const int rowsPerBeat = -1); + /** + * @brief Process the Tickcount 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. */ + void ProcessTickcounts(TimingData & out, + const RString line, + const int rowsPerBeat = -1); void ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index d11600ba4b..c5cf98952d 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -19,12 +19,6 @@ */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB -bool SMALoader::LoadFromBGChangesString( BackgroundChange &change, - const RString &sBGChangeExpression ) -{ - return SMLoader::LoadFromBGChangesString(change, sBGChangeExpression); -} - bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) { vector aFileNames; @@ -39,31 +33,6 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) return LoadFromSMAFile( sPath + aFileNames[0], out ); } -void SMALoader::ProcessTickcounts( TimingData &out, const int iRowsPerBeat, const RString sParam ) -{ - vector arrayTickcountExpressions; - split( sParam, ",", arrayTickcountExpressions ); - - for( unsigned f=0; f arrayTickcountValues; - split( arrayTickcountExpressions[f], "=", arrayTickcountValues ); - if( arrayTickcountValues.size() != 2 ) - { - // XXX: Hard to tell which file caused this. - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #TICKCOUNTS value \"%s\" (must have exactly one '='), ignored.", - arrayTickcountExpressions[f].c_str() ); - continue; - } - - const float fTickcountBeat = RowToBeat( arrayTickcountValues[0], iRowsPerBeat ); - int iTicks = clamp(atoi( arrayTickcountValues[1] ), 0, ROWS_PER_BEAT); - - TickcountSegment new_seg( BeatToNoteRow(fTickcountBeat), iTicks ); - out.AddTickcountSegment( new_seg ); - } -} - void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ) { vector arrayMultiplierExpressions; @@ -207,11 +176,6 @@ void SMALoader::ProcessFakes( TimingData &out, const int iRowsPerBeat, const RSt } } -void SMALoader::TidyUpData( Song &song, bool bFromCache ) -{ - SMLoader::TidyUpData( song, bFromCache ); -} - bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) { LOG->Trace( "Song::LoadFromSMAFile(%s)", sPath.c_str() ); @@ -456,7 +420,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessTickcounts( timing, iRowsPerBeat, sParams[1] ); + ProcessTickcounts( timing, sParams[1], iRowsPerBeat ); } else if( sValueName=="SPEED" ) @@ -532,116 +496,6 @@ void SMALoader::GetApplicableFiles( const RString &sPath, vector &out ) GetDirListing( sPath + RString("*.sma"), out ); } -bool SMALoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ) -{ - LOG->Trace( "SMALoader::LoadEditFromFile(%s)", sEditFilePath.c_str() ); - - int iBytes = FILEMAN->GetFileSizeInBytes( sEditFilePath ); - if( iBytes > MAX_EDIT_STEPS_SIZE_BYTES ) - { - LOG->UserLog( "Edit file", sEditFilePath, "is unreasonably large. It won't be loaded." ); - return false; - } - - MsdFile msd; - if( !msd.ReadFile( sEditFilePath, true ) ) // unescape - { - LOG->UserLog( "Edit file", sEditFilePath, "couldn't be opened: %s", msd.GetError().c_str() ); - return false; - } - - return LoadEditFromMsd( msd, sEditFilePath, slot, bAddStepsToSong ); -} - -bool SMALoader::LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ) -{ - MsdFile msd; - msd.ReadFromString( sBuffer, true ); // unescape - return LoadEditFromMsd( msd, sEditFilePath, slot, true ); -} - -bool SMALoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ) -{ - Song* pSong = NULL; - - for( unsigned i=0; iUserLog( "Edit file", sEditFilePath, "has more than one #SONG tag." ); - return false; - } - - RString sSongFullTitle = sParams[1]; - sSongFullTitle.Replace( '\\', '/' ); - - pSong = SONGMAN->FindSong( sSongFullTitle ); - if( pSong == NULL ) - { - LOG->UserLog( "Edit file", sEditFilePath, "requires a song \"%s\" that isn't present.", sSongFullTitle.c_str() ); - return false; - } - - if( pSong->GetNumStepsLoadedFromProfile(slot) >= MAX_EDITS_PER_SONG_PER_PROFILE ) - { - LOG->UserLog( "Song file", sSongFullTitle, "already has the maximum number of edits allowed for ProfileSlotP%d.", slot+1 ); - return false; - } - } - - else if( sValueName=="NOTES" ) - { - if( pSong == NULL ) - { - LOG->UserLog( "Edit file", sEditFilePath, "doesn't have a #SONG tag preceeding the first #NOTES tag." ); - return false; - } - - if( iNumParams < 7 ) - { - LOG->UserLog( "Edit file", sEditFilePath, "has %d fields in a #NOTES tag, but should have at least 7.", iNumParams ); - continue; - } - - if( !bAddStepsToSong ) - return true; - - Steps* pNewNotes = pSong->CreateSteps(); - LoadFromTokens( - sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], - *pNewNotes); - - pNewNotes->SetLoadedFromProfile( slot ); - pNewNotes->SetDifficulty( Difficulty_Edit ); - pNewNotes->SetFilename( sEditFilePath ); - - if( pSong->IsEditAlreadyLoaded(pNewNotes) ) - { - LOG->UserLog( "Edit file", sEditFilePath, "is a duplicate of another edit that was already loaded." ); - SAFE_DELETE( pNewNotes ); - return false; - } - - pSong->AddSteps( pNewNotes ); - return true; // Only allow one Steps per edit file! - } - else - { - LOG->UserLog( "Edit file", sEditFilePath, "has an unexpected value \"%s\".", sValueName.c_str() ); - } - } - - return true; -} - /** * @file * @author Aldo Fregoso, Jason Felds (c) 2009-2011 diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 500e3de3f2..494646026e 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -24,18 +24,11 @@ enum SMALoadingStates struct SMALoader : public SMLoader { bool LoadFromDir( const RString &sPath, Song &out ); - void TidyUpData( Song &song, bool bFromCache ); bool LoadFromSMAFile( const RString &sPath, Song &out ); void GetApplicableFiles( const RString &sPath, vector &out ); - bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); - bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ); - void ProcessBeatsPerMeasure( TimingData &out, 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 ); void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ); From 48eefc770010ae40b8373549e310763bc4076c92 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:45:30 -0400 Subject: [PATCH 05/11] [notesloader] Have common ground. --- src/NotesLoaderSM.cpp | 100 ++++++++++++++++++++++++++++++----------- src/NotesLoaderSM.h | 21 ++++++++- src/NotesLoaderSMA.cpp | 13 ++---- src/NotesLoaderSMA.h | 2 +- src/NotesLoaderSSC.cpp | 56 +---------------------- src/NotesLoaderSSC.h | 9 +--- 6 files changed, 101 insertions(+), 100 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index bb465057d4..bdb8a332ea 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -16,6 +16,33 @@ /** @brief The maximum file size for edits. */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB +bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) +{ + vector aFileNames; + GetApplicableFiles( sPath, aFileNames ); + + if( aFileNames.size() > 1 ) + { + LOG->UserLog( "Song", sPath, "has more than one SM file. There can be only one (unless you are using TougaKiryuu's AnimeMix files somehow, which assume a different version of StepMania)!" ); + return false; + /* + for( unsigned i=0; i= 1 ); + + return LoadFromSMFile( sPath + aFileNames[0], out ); +} + float SMLoader::RowToBeat( RString line, const int rowsPerBeat ) { RString backup = line; @@ -419,6 +446,52 @@ void SMLoader::ProcessTickcounts( TimingData &out, const RString line, const int } } +void SMLoader::ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat ) +{ + vector vs1; + split( line, ",", vs1 ); + + FOREACH_CONST( RString, vs1, s1 ) + { + vector vs2; + split( *s1, "=", vs2 ); + + if( vs2[0] == 0 && vs2.size() == 2 ) // First one always seems to have 2. + { + vs2.push_back("0"); + } + + if( vs2.size() == 3 ) // use beats by default. + { + vs2.push_back("0"); + } + + if( vs2.size() < 4 ) + { + LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with %i values.", (int)vs2.size() ); + continue; + } + + const float fBeat = RowToBeat( vs2[0], rowsPerBeat ); + + SpeedSegment seg( fBeat, StringToFloat( vs2[1] ), StringToFloat( vs2[2] )); + seg.SetUnit(StringToInt(vs2[3])); + + if( fBeat < 0 ) + { + LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with beat %f.", fBeat ); + continue; + } + + if( seg.GetLength() < 0 ) + { + LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with beat %f, length %f.", fBeat, seg.GetLength() ); + continue; + } + + out.AddSpeedSegment( seg ); + } +} bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) { @@ -754,33 +827,6 @@ bool SMLoader::LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache return true; } -bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) -{ - vector aFileNames; - GetApplicableFiles( sPath, aFileNames ); - - if( aFileNames.size() > 1 ) - { - LOG->UserLog( "Song", sPath, "has more than one SM file. There can be only one (unless you are using TougaKiryuu's AnimeMix files somehow, which assume a different version of StepMania)!" ); - return false; - /* - for( unsigned i=0; i= 1 ); - - return LoadFromSMFile( sPath + aFileNames[0], out ); -} - bool SMLoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ) { LOG->Trace( "SMLoader::LoadEditFromFile(%s)", sEditFilePath.c_str() ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index a3da6ecde1..e63e80acdb 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -21,6 +21,11 @@ struct SMLoader virtual ~SMLoader() {} bool LoadFromDir( const RString &sPath, Song &out ); + /** + * @brief Perform some cleanup on the loaded song. + * @param song a reference to the song that may need cleaning up. + * @param bFromCache a flag to determine if this song is loaded from a cache file. + */ virtual void TidyUpData( Song &song, bool bFromCache ); bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); @@ -72,7 +77,21 @@ struct SMLoader void ProcessTickcounts(TimingData & out, const RString line, const int rowsPerBeat = -1); - void ProcessBGChanges( Song &out, const RString &sValueName, + + /** + * @brief Process the Speed 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. */ + virtual void ProcessSpeeds(TimingData & out, + const RString line, + const int rowsPerBeat = -1); + + virtual void ProcessCombos(TimingData & out, + const RString line, + const int rowsPerBeat = -1) {} + + virtual void ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); void ProcessInstrumentTracks( Song &out, const RString &sParam ); diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index c5cf98952d..f5b726626f 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -91,15 +91,10 @@ void SMALoader::ProcessBeatsPerMeasure( TimingData &out, const RString sParam ) } } -float BeatToSeconds(float fromBeat, RString toSomething) -{ - return 0; -} - -void SMALoader::ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RString sParam ) +void SMALoader::ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat ) { vector vs1; - split( sParam, ",", vs1 ); + split( line, ",", vs1 ); FOREACH_CONST( RString, vs1, s1 ) { @@ -120,7 +115,7 @@ void SMALoader::ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RS continue; } - const float fBeat = RowToBeat( vs2[0], iRowsPerBeat ); + const float fBeat = RowToBeat( vs2[0], rowsPerBeat ); RString backup = vs2[2]; Trim(vs2[2], "s"); @@ -429,7 +424,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) ? pNewNotes->m_Timing : out.m_SongTiming); RString tmp = sParams[1]; Trim( tmp ); - ProcessSpeeds( timing, iRowsPerBeat, tmp ); + ProcessSpeeds( timing, tmp, iRowsPerBeat ); } else if( sValueName=="MULTIPLIER" ) diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 494646026e..a38a07752f 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -30,7 +30,7 @@ struct SMALoader : public SMLoader void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); - void ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RString sParam ); + virtual void ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat ); void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ); }; diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index 54c7e208b5..1482054bb9 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -97,10 +97,10 @@ void SSCLoader::ProcessLabels( TimingData &out, const RString sParam ) } } -void SSCLoader::ProcessCombos( TimingData &out, const RString sParam ) +void SSCLoader::ProcessCombos( TimingData &out, const RString line, const int rowsPerBeat ) { vector arrayComboExpressions; - split( sParam, ",", arrayComboExpressions ); + split( line, ",", arrayComboExpressions ); for( unsigned f=0; f vs1; - split( sParam, ",", vs1 ); - - FOREACH_CONST( RString, vs1, s1 ) - { - vector vs2; - split( *s1, "=", vs2 ); - - if( vs2[0] == 0 && vs2.size() == 2 ) // First one always seems to have 2. - { - vs2.push_back("0"); - } - - if( vs2.size() == 3 ) // use beats by default. - { - vs2.push_back("0"); - } - - if( vs2.size() < 4 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with %i values.", (int)vs2.size() ); - continue; - } - - const float fBeat = StringToFloat( vs2[0] ); - - SpeedSegment seg( fBeat, StringToFloat( vs2[1] ), StringToFloat( vs2[2] )); - seg.SetUnit(StringToInt(vs2[3])); - - if( fBeat < 0 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with beat %f.", fBeat ); - continue; - } - - if( seg.GetLength() < 0 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an speed change with beat %f, length %f.", fBeat, seg.GetLength() ); - continue; - } - - out.AddSpeedSegment( seg ); - } -} - void SSCLoader::ProcessScrolls( TimingData &out, const RString sParam ) { vector vs1; @@ -906,11 +859,6 @@ bool SSCLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePat return bSSCFormat; } -void SSCLoader::TidyUpData( Song &song, bool bFromCache ) -{ - SMLoader::TidyUpData(song, bFromCache); -} - /* * (c) 2011 Jason Felds * All rights reserved. diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index d3ffe6c12c..29cf560458 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -70,18 +70,11 @@ struct SSCLoader : public SMLoader * @return its success or failure. */ bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - /** - * @brief Perform some cleanup on the loaded song. - * @param song a reference to the song that may need cleaning up. - * @param bFromCache a flag to determine if this song is loaded from a cache file. - */ - void TidyUpData( Song &song, bool bFromCache ); void ProcessWarps( TimingData &, const RString, const float ); void ProcessLabels( TimingData &, const RString ); - void ProcessCombos( TimingData &, const RString ); - void ProcessSpeeds( TimingData &, const RString ); + virtual void ProcessCombos( TimingData &, const RString, const int = -1 ); void ProcessScrolls( TimingData &, const RString ); void ProcessFakes( TimingData &, const RString ); }; From dec615a2e7c8d10b9d8a499d562b429cbd178903 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:53:58 -0400 Subject: [PATCH 06/11] [notesloader] Handle fakes on their own. --- src/NotesLoaderSM.cpp | 29 +++++++++++++++++++++++++++++ src/NotesLoaderSM.h | 9 +++++++++ src/NotesLoaderSMA.cpp | 31 +------------------------------ src/NotesLoaderSMA.h | 1 - src/NotesLoaderSSC.cpp | 29 ----------------------------- src/NotesLoaderSSC.h | 1 - 6 files changed, 39 insertions(+), 61 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index bdb8a332ea..859ff6951e 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -493,6 +493,35 @@ void SMLoader::ProcessSpeeds( TimingData &out, const RString line, const int row } } +void SMLoader::ProcessFakes( TimingData &out, const RString line, const int rowsPerBeat ) +{ + vector arrayFakeExpressions; + split( line, ",", arrayFakeExpressions ); + + for( unsigned b=0; b arrayFakeValues; + split( arrayFakeExpressions[b], "=", arrayFakeValues ); + // XXX: Hard to tell which file caused this. + if( arrayFakeValues.size() != 2 ) + { + LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #FAKES value \"%s\" (must have exactly one '='), ignored.", + arrayFakeExpressions[b].c_str() ); + continue; + } + + const float fBeat = RowToBeat( arrayFakeValues[0], rowsPerBeat ); + const float fNewBeat = StringToFloat( arrayFakeValues[1] ); + + if(fNewBeat > 0) + out.AddFakeSegment( FakeSegment(fBeat, fNewBeat) ); + else + { + LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid Fake at beat %f, BPM %f.", fBeat, fNewBeat ); + } + } +} + bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) { vector aBGChangeValues; diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index e63e80acdb..0a85448022 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -91,6 +91,15 @@ struct SMLoader const RString line, const int rowsPerBeat = -1) {} + /** + * @brief Process the Fake 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. */ + virtual void ProcessFakes(TimingData & out, + const RString line, + const int rowsPerBeat = -1); + virtual void ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index f5b726626f..aa148933bc 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -142,35 +142,6 @@ void SMALoader::ProcessSpeeds( TimingData &out, const RString line, const int ro } } -void SMALoader::ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ) -{ - vector arrayFakeExpressions; - split( sParam, ",", arrayFakeExpressions ); - - for( unsigned b=0; b arrayFakeValues; - split( arrayFakeExpressions[b], "=", arrayFakeValues ); - // XXX: Hard to tell which file caused this. - if( arrayFakeValues.size() != 2 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #FAKES value \"%s\" (must have exactly one '='), ignored.", - arrayFakeExpressions[b].c_str() ); - continue; - } - - const float fBeat = RowToBeat( arrayFakeValues[0], iRowsPerBeat ); - const float fNewBeat = StringToFloat( arrayFakeValues[1] ); - - if(fNewBeat > 0) - out.AddFakeSegment( FakeSegment(fBeat, fNewBeat) ); - else - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid Fake at beat %f, BPM %f.", fBeat, fNewBeat ); - } - } -} - bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) { LOG->Trace( "Song::LoadFromSMAFile(%s)", sPath.c_str() ); @@ -438,7 +409,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) { TimingData &timing = (state == SMA_GETTING_STEP_INFO ? pNewNotes->m_Timing : out.m_SongTiming); - ProcessFakes( timing, iRowsPerBeat, sParams[1] ); + ProcessFakes( timing, sParams[1], iRowsPerBeat ); } else if( sValueName=="METERTYPE" ) diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index a38a07752f..223b489571 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -31,7 +31,6 @@ struct SMALoader : public SMLoader void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); virtual void ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat ); - void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ); }; #endif diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index 1482054bb9..f4bce60d21 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -149,35 +149,6 @@ void SSCLoader::ProcessScrolls( TimingData &out, const RString sParam ) } } -void SSCLoader::ProcessFakes( TimingData &out, const RString sParam ) -{ - vector arrayFakeExpressions; - split( sParam, ",", arrayFakeExpressions ); - - for( unsigned b=0; b arrayFakeValues; - split( arrayFakeExpressions[b], "=", arrayFakeValues ); - // XXX: Hard to tell which file caused this. - if( arrayFakeValues.size() != 2 ) - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #FAKES value \"%s\" (must have exactly one '='), ignored.", - arrayFakeExpressions[b].c_str() ); - continue; - } - - const float fBeat = StringToFloat( arrayFakeValues[0] ); - const float fNewBeat = StringToFloat( arrayFakeValues[1] ); - - if(fNewBeat > 0) - out.AddFakeSegment( FakeSegment(fBeat, fNewBeat) ); - else - { - LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid Fake at beat %f, BPM %f.", fBeat, fNewBeat ); - } - } -} - bool SSCLoader::LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCache ) { diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index 29cf560458..88fc17842a 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -76,7 +76,6 @@ struct SSCLoader : public SMLoader void ProcessLabels( TimingData &, const RString ); virtual void ProcessCombos( TimingData &, const RString, const int = -1 ); void ProcessScrolls( TimingData &, const RString ); - void ProcessFakes( TimingData &, const RString ); }; #endif From 68fd21fdc8159a973c1a5ee533f0d5a3b9b5d2f5 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 15:14:47 -0400 Subject: [PATCH 07/11] [notesloader] More cleanup. Need to test something in gameplay before continuing. --- src/NotesLoaderSM.cpp | 10 ---------- src/NotesLoaderSM.h | 7 ++++++- src/NotesLoaderSMA.h | 12 +++++++++++- src/NotesLoaderSSC.cpp | 3 +-- src/NotesLoaderSSC.h | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 859ff6951e..e75e1c5998 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -25,19 +25,9 @@ bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) { LOG->UserLog( "Song", sPath, "has more than one SM file. There can be only one (unless you are using TougaKiryuu's AnimeMix files somehow, which assume a different version of StepMania)!" ); return false; - /* - for( unsigned i=0; i= 1 ); return LoadFromSMFile( sPath + aFileNames[0], out ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 0a85448022..4a1f3bc7c0 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -29,7 +29,12 @@ struct SMLoader virtual void TidyUpData( Song &song, bool bFromCache ); bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); - void GetApplicableFiles( const RString &sPath, vector &out ); + /** + * @brief Retrieve the list of .sm files. + * @param sPath a const reference to the path on the hard drive to check. + * @param out a vector of files found in the path. + */ + virtual void GetApplicableFiles( const RString &sPath, vector &out ); virtual bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); virtual bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); virtual bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 223b489571..040b1e9d38 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -26,10 +26,20 @@ struct SMALoader : public SMLoader bool LoadFromDir( const RString &sPath, Song &out ); bool LoadFromSMAFile( const RString &sPath, Song &out ); - void GetApplicableFiles( const RString &sPath, vector &out ); + /** + * @brief Retrieve the list of .sma files. + * @param sPath a const reference to the path on the hard drive to check. + * @param out a vector of files found in the path. + */ + virtual void GetApplicableFiles( const RString &sPath, vector &out ); void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); + /** + * @brief Process the Speed 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. */ virtual void ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat ); }; diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index f4bce60d21..b5644b8243 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -30,8 +30,7 @@ bool SSCLoader::LoadFromDir( const RString &sPath, Song &out ) return false; } - ASSERT( aFileNames.size() == 1 ); // Ensure one was found entirely. - + ASSERT( aFileNames.size() == 1 ); return LoadFromSSCFile( sPath + aFileNames[0], out ); } diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index 88fc17842a..7a5cd3f172 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -52,7 +52,7 @@ struct SSCLoader : public SMLoader * @param sPath a const reference to the path on the hard drive to check. * @param out a vector of files found in the path. */ - void GetApplicableFiles( const RString &sPath, vector &out ); + virtual void GetApplicableFiles( const RString &sPath, vector &out ); /** * @brief Attempt to load an edit from the hard drive. * @param sEditFilePath a path on the hard drive to check. From 1e296ed0bf27fcd37ca99ff7d9282e701a5ec85c Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 21:27:47 -0400 Subject: [PATCH 08/11] [notesloader] More virtuals. --- src/GameSoundManager.cpp | 4 ++-- src/NotesLoaderSM.cpp | 4 ++-- src/NotesLoaderSM.h | 9 ++++++++- src/NotesLoaderSMA.cpp | 4 ++-- src/NotesLoaderSMA.h | 2 +- src/NotesLoaderSSC.cpp | 4 ++-- src/NotesLoaderSSC.h | 2 +- src/ScreenGameplaySyncMachine.cpp | 4 ++-- src/ScreenHowToPlay.cpp | 4 ++-- src/Song.cpp | 4 ++-- src/Steps.cpp | 4 ++-- 11 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index 8b878c50ef..27933d5d82 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -145,7 +145,7 @@ static void StartMusic( MusicToPlay &ToPlay ) SSCLoader loaderSSC; SMLoader loaderSM; if(GetExtension(ToPlay.m_sTimingFile) == ".ssc" && - loaderSSC.LoadFromSSCFile(ToPlay.m_sTimingFile, song) ) + loaderSSC.LoadFromSimfile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; @@ -155,7 +155,7 @@ static void StartMusic( MusicToPlay &ToPlay ) pStepsCabinetLights->GetNoteData( ToPlay.m_LightsData ); } else if(GetExtension(ToPlay.m_sTimingFile) == ".sm" && - loaderSM.LoadFromSMFile(ToPlay.m_sTimingFile, song) ) + loaderSM.LoadFromSimfile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index e75e1c5998..4e1b073a9b 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -30,7 +30,7 @@ bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) ASSERT( aFileNames.size() == 1 ); //ASSERT( aFileNames.size() >= 1 ); - return LoadFromSMFile( sPath + aFileNames[0], out ); + return LoadFromSimfile( sPath + aFileNames[0], out ); } float SMLoader::RowToBeat( RString line, const int rowsPerBeat ) @@ -598,7 +598,7 @@ bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString return aBGChangeValues.size() >= 2; } -bool SMLoader::LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache ) +bool SMLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache ) { LOG->Trace( "Song::LoadFromSMFile(%s)", sPath.c_str() ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 4a1f3bc7c0..f2c964a43a 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -28,7 +28,14 @@ struct SMLoader */ virtual void TidyUpData( Song &song, bool bFromCache ); - bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); + /** + * @brief Attempt to load the specified sm file. + * @param sPath a const reference to the path on the hard drive to check. + * @param out a reference to the Song that will retrieve the song information. + * @param bFromCache a check to see if we are getting certain information from the cache file. + * @return its success or failure. + */ + virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); /** * @brief Retrieve the list of .sm files. * @param sPath a const reference to the path on the hard drive to check. diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index aa148933bc..a52c7db68b 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -30,7 +30,7 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) return false; } ASSERT( aFileNames.size() == 1 ); - return LoadFromSMAFile( sPath + aFileNames[0], out ); + return LoadFromSimfile( sPath + aFileNames[0], out ); } void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ) @@ -142,7 +142,7 @@ void SMALoader::ProcessSpeeds( TimingData &out, const RString line, const int ro } } -bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) +bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache ) { LOG->Trace( "Song::LoadFromSMAFile(%s)", sPath.c_str() ); diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 040b1e9d38..71d307642b 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -25,7 +25,7 @@ struct SMALoader : public SMLoader { bool LoadFromDir( const RString &sPath, Song &out ); - bool LoadFromSMAFile( const RString &sPath, Song &out ); + virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); /** * @brief Retrieve the list of .sma files. * @param sPath a const reference to the path on the hard drive to check. diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index b5644b8243..ddac4631fe 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -31,7 +31,7 @@ bool SSCLoader::LoadFromDir( const RString &sPath, Song &out ) } ASSERT( aFileNames.size() == 1 ); - return LoadFromSSCFile( sPath + aFileNames[0], out ); + return LoadFromSimfile( sPath + aFileNames[0], out ); } void SSCLoader::ProcessWarps( TimingData &out, const RString sParam, const float fVersion ) @@ -149,7 +149,7 @@ void SSCLoader::ProcessScrolls( TimingData &out, const RString sParam ) } -bool SSCLoader::LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCache ) +bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache ) { LOG->Trace( "Song::LoadFromSSCFile(%s)", sPath.c_str() ); diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index 7a5cd3f172..e535f8ac48 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -46,7 +46,7 @@ struct SSCLoader : public SMLoader * @param bFromCache a check to see if we are getting certain information from the cache file. * @return its success or failure. */ - bool LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCache = false ); + virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); /** * @brief Retrieve the list of .ssc files. * @param sPath a const reference to the path on the hard drive to check. diff --git a/src/ScreenGameplaySyncMachine.cpp b/src/ScreenGameplaySyncMachine.cpp index f1202c3c13..3f72cd1976 100644 --- a/src/ScreenGameplaySyncMachine.cpp +++ b/src/ScreenGameplaySyncMachine.cpp @@ -24,9 +24,9 @@ void ScreenGameplaySyncMachine::Init() SSCLoader loaderSSC; SMLoader loaderSM; if(sFile.Right(4) == ".ssc") - loaderSSC.LoadFromSSCFile( sFile, m_Song ); + loaderSSC.LoadFromSimfile( sFile, m_Song ); else - loaderSM.LoadFromSMFile( sFile, m_Song ); + loaderSM.LoadFromSimfile( sFile, m_Song ); m_Song.SetSongDir( Dirname(sFile) ); m_Song.TidyUpData(); diff --git a/src/ScreenHowToPlay.cpp b/src/ScreenHowToPlay.cpp index 64ce65815c..bb5e021db2 100644 --- a/src/ScreenHowToPlay.cpp +++ b/src/ScreenHowToPlay.cpp @@ -138,9 +138,9 @@ void ScreenHowToPlay::Init() SSCLoader loaderSSC; SMLoader loaderSM; if( sStepsPath.Right(4) == ".ssc" ) - loaderSSC.LoadFromSSCFile( sStepsPath, m_Song, false ); + loaderSSC.LoadFromSimfile( sStepsPath, m_Song, false ); else - loaderSM.LoadFromSMFile( sStepsPath, m_Song, false ); + loaderSM.LoadFromSimfile( sStepsPath, m_Song, false ); m_Song.AddAutoGenNotes(); const Style* pStyle = GAMESTATE->GetCurrentStyle(); diff --git a/src/Song.cpp b/src/Song.cpp index d547a02e47..5bb35928f5 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -236,12 +236,12 @@ bool Song::LoadFromSongDir( RString sDir ) { // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); SSCLoader loaderSSC; - bool bLoadedFromSSC = loaderSSC.LoadFromSSCFile( sCacheFilePath, *this, true ); + bool bLoadedFromSSC = loaderSSC.LoadFromSimfile( sCacheFilePath, *this, true ); if( !bLoadedFromSSC ) { // load from .sm SMLoader loaderSM; - loaderSM.LoadFromSMFile( sCacheFilePath, *this, true ); + loaderSM.LoadFromSimfile( sCacheFilePath, *this, true ); loaderSM.TidyUpData( *this, true ); } } diff --git a/src/Steps.cpp b/src/Steps.cpp index e78bed9c3f..ee7a27c98f 100644 --- a/src/Steps.cpp +++ b/src/Steps.cpp @@ -243,12 +243,12 @@ void Steps::Decompress() const // We have data on disk and not in memory. Load it. Song s; SSCLoader loaderSSC; - bool bLoadedFromSSC = loaderSSC.LoadFromSSCFile(m_sFilename, s, true); + bool bLoadedFromSSC = loaderSSC.LoadFromSimfile(m_sFilename, s, true); if( !bLoadedFromSSC ) { // try reading from .sm instead SMLoader loaderSM; - if( !loaderSM.LoadFromSMFile(m_sFilename, s, true) ) + if( !loaderSM.LoadFromSimfile(m_sFilename, s, true) ) { LOG->Warn( "Couldn't load \"%s\"", m_sFilename.c_str() ); return; From 1ec548442d833469d76ef83d83e1051211526b94 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 21:34:04 -0400 Subject: [PATCH 09/11] [notesloader] Take advantage of const members. --- src/NotesLoaderSM.h | 13 +++++++++++++ src/NotesLoaderSMA.h | 1 + src/NotesLoaderSSC.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index f2c964a43a..168b7e411f 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -18,6 +18,10 @@ const float FAST_BPM_WARP = 9999999.f; /** @brief Reads a Song from an .SM file. */ struct SMLoader { + SMLoader() : fileExt(".sm") {} + + SMLoader(RString ext) : fileExt(ext) {} + virtual ~SMLoader() {} bool LoadFromDir( const RString &sPath, Song &out ); @@ -143,6 +147,15 @@ protected: RString sRadarValues, RString sNoteData, Steps &out); + + /** + * @brief Retrieve the file extension associated with this loader. + * @return the file extension. */ + RString GetFileExtension() const { return fileExt; } + +private: + /** @brief The file extension in use. */ + const RString fileExt; }; #endif diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index 71d307642b..dad853fa19 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -23,6 +23,7 @@ enum SMALoadingStates /** @brief Reads a Song from a .SMA file. */ struct SMALoader : public SMLoader { + SMALoader() : SMLoader(".sma") {} bool LoadFromDir( const RString &sPath, Song &out ); virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index e535f8ac48..e400b94bb7 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -32,6 +32,8 @@ const float VERSION_SPLIT_TIMING = 0.7f; */ struct SSCLoader : public SMLoader { + SSCLoader() : SMLoader(".ssc") {} + /** * @brief Attempt to load a song from a specified path. * @param sPath a const reference to the path on the hard drive to check. From bb642827a8fd6bde6a9367af0bcc56bc9c326815 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 21:41:56 -0400 Subject: [PATCH 10/11] [notesloader] More abstracting. --- src/NotesLoaderSM.cpp | 9 +++------ src/NotesLoaderSM.h | 11 ++++++++++- src/NotesLoaderSMA.cpp | 19 ------------------- src/NotesLoaderSMA.h | 1 - src/NotesLoaderSSC.cpp | 20 -------------------- src/NotesLoaderSSC.h | 7 ------- 6 files changed, 13 insertions(+), 54 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 4e1b073a9b..5e5ae1292a 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -13,9 +13,6 @@ #include "Attack.h" #include "PrefsManager.h" -/** @brief The maximum file size for edits. */ -const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB - bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) { vector aFileNames; @@ -23,13 +20,13 @@ bool SMLoader::LoadFromDir( const RString &sPath, Song &out ) if( aFileNames.size() > 1 ) { - LOG->UserLog( "Song", sPath, "has more than one SM file. There can be only one (unless you are using TougaKiryuu's AnimeMix files somehow, which assume a different version of StepMania)!" ); + // Need to break this up first. + RString tmp = "Song " + sPath + " has more than one"; + LOG->UserLog(tmp, this->GetFileExtension(), "file. There can only be one!"); return false; } ASSERT( aFileNames.size() == 1 ); - //ASSERT( aFileNames.size() >= 1 ); - return LoadFromSimfile( sPath + aFileNames[0], out ); } diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 168b7e411f..0e03988b58 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -15,6 +15,9 @@ class TimingData; * This was brought in from StepMania 4's recent betas. */ const float FAST_BPM_WARP = 9999999.f; +/** @brief The maximum file size for edits. */ +const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB + /** @brief Reads a Song from an .SM file. */ struct SMLoader { @@ -24,7 +27,13 @@ struct SMLoader virtual ~SMLoader() {} - bool LoadFromDir( const RString &sPath, Song &out ); + /** + * @brief Attempt to load a song from a specified path. + * @param sPath a const reference to the path on the hard drive to check. + * @param out a reference to the Song that will retrieve the song information. + * @return its success or failure. + */ + virtual bool LoadFromDir( const RString &sPath, Song &out ); /** * @brief Perform some cleanup on the loaded song. * @param song a reference to the song that may need cleaning up. diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index a52c7db68b..930f718ec6 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -14,25 +14,6 @@ #include "Steps.h" #include "Attack.h" -/** - * @brief A custom .edit file can only be so big before we have to reject it. - */ -const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB - -bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) -{ - vector aFileNames; - GetApplicableFiles( sPath, aFileNames ); - - if( aFileNames.size() > 1 ) - { - LOG->UserLog( "Song", sPath, "has more than one SMA file. Only one SMA file is allowed per song." ); - return false; - } - ASSERT( aFileNames.size() == 1 ); - return LoadFromSimfile( sPath + aFileNames[0], out ); -} - void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ) { vector arrayMultiplierExpressions; diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index dad853fa19..ecebd82676 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -24,7 +24,6 @@ enum SMALoadingStates struct SMALoader : public SMLoader { SMALoader() : SMLoader(".sma") {} - bool LoadFromDir( const RString &sPath, Song &out ); virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); /** diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index ddac4631fe..6c32cc6c9e 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -14,26 +14,6 @@ #include "Attack.h" #include "PrefsManager.h" -/** - * @brief A custom .edit file can only be so big before we have to reject it. - */ -const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB - -bool SSCLoader::LoadFromDir( const RString &sPath, Song &out ) -{ - vector aFileNames; - GetApplicableFiles( sPath, aFileNames ); - - if( aFileNames.size() > 1 ) - { - LOG->UserLog( "Song", sPath, "has more than one SSC file. Only one SSC file is allowed per song." ); - return false; - } - - ASSERT( aFileNames.size() == 1 ); - return LoadFromSimfile( sPath + aFileNames[0], out ); -} - void SSCLoader::ProcessWarps( TimingData &out, const RString sParam, const float fVersion ) { vector arrayWarpExpressions; diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index e400b94bb7..fc6332f731 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -34,13 +34,6 @@ struct SSCLoader : public SMLoader { SSCLoader() : SMLoader(".ssc") {} - /** - * @brief Attempt to load a song from a specified path. - * @param sPath a const reference to the path on the hard drive to check. - * @param out a reference to the Song that will retrieve the song information. - * @return its success or failure. - */ - bool LoadFromDir( const RString &sPath, Song &out ); /** * @brief Attempt to load the specified ssc file. * @param sPath a const reference to the path on the hard drive to check. From 4830ecc730c09941e46bd2e220ff202d9208ee28 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 22:00:10 -0400 Subject: [PATCH 11/11] [notesreader] Ready to test again. --- src/NotesLoaderSM.cpp | 2 +- src/NotesLoaderSMA.cpp | 5 ----- src/NotesLoaderSMA.h | 7 +------ src/NotesLoaderSSC.cpp | 5 ----- src/NotesLoaderSSC.h | 7 +------ 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 5e5ae1292a..35562c1efd 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -956,7 +956,7 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath void SMLoader::GetApplicableFiles( const RString &sPath, vector &out ) { - GetDirListing( sPath + RString("*.sm"), out ); + GetDirListing( sPath + RString("*" + this->GetFileExtension() ), out ); } void SMLoader::TidyUpData( Song &song, bool bFromCache ) diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index 930f718ec6..44f6f5026f 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -438,11 +438,6 @@ bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach return true; } -void SMALoader::GetApplicableFiles( const RString &sPath, vector &out ) -{ - GetDirListing( sPath + RString("*.sma"), out ); -} - /** * @file * @author Aldo Fregoso, Jason Felds (c) 2009-2011 diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index ecebd82676..f38acac470 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -26,12 +26,7 @@ struct SMALoader : public SMLoader SMALoader() : SMLoader(".sma") {} virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); - /** - * @brief Retrieve the list of .sma files. - * @param sPath a const reference to the path on the hard drive to check. - * @param out a vector of files found in the path. - */ - virtual void GetApplicableFiles( const RString &sPath, vector &out ); + void ProcessBeatsPerMeasure( TimingData &out, const RString sParam ); void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index 6c32cc6c9e..3c13899ff7 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -557,11 +557,6 @@ bool SSCLoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach return true; } -void SSCLoader::GetApplicableFiles( const RString &sPath, vector &out ) -{ - GetDirListing( sPath + RString("*.ssc"), out ); -} - bool SSCLoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ) { LOG->Trace( "SSCLoader::LoadEditFromFile(%s)", sEditFilePath.c_str() ); diff --git a/src/NotesLoaderSSC.h b/src/NotesLoaderSSC.h index fc6332f731..3031932841 100644 --- a/src/NotesLoaderSSC.h +++ b/src/NotesLoaderSSC.h @@ -42,12 +42,7 @@ struct SSCLoader : public SMLoader * @return its success or failure. */ virtual bool LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache = false ); - /** - * @brief Retrieve the list of .ssc files. - * @param sPath a const reference to the path on the hard drive to check. - * @param out a vector of files found in the path. - */ - virtual void GetApplicableFiles( const RString &sPath, vector &out ); + /** * @brief Attempt to load an edit from the hard drive. * @param sEditFilePath a path on the hard drive to check.