diff --git a/Xcode/stepmania.xcodeproj/project.pbxproj b/Xcode/stepmania.xcodeproj/project.pbxproj index 97d4084dcc..676ef76ec3 100644 --- a/Xcode/stepmania.xcodeproj/project.pbxproj +++ b/Xcode/stepmania.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ 1215D7A208C6559A00B87D8B /* ScreenGameplayNormal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1215D7A008C6559A00B87D8B /* ScreenGameplayNormal.cpp */; }; 2B30D6821315EA7E00044B68 /* MouseDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2B30D6801315EA7E00044B68 /* MouseDevice.cpp */; }; 2B30D6831315EA7E00044B68 /* MouseDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B30D6811315EA7E00044B68 /* MouseDevice.h */; }; + 2B76698B132FF71500586512 /* NotesLoaderSMA.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B766989132FF71500586512 /* NotesLoaderSMA.h */; }; + 2B76698C132FF71500586512 /* NotesLoaderSMA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2B76698A132FF71500586512 /* NotesLoaderSMA.cpp */; }; 2BA7925E1304F20D002BD8E1 /* NotesLoaderSSC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BA7925A1304F20D002BD8E1 /* NotesLoaderSSC.cpp */; }; 2BA7925F1304F20D002BD8E1 /* NotesLoaderSSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 2BA7925B1304F20D002BD8E1 /* NotesLoaderSSC.h */; }; 2BA792601304F20D002BD8E1 /* NotesWriterSSC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BA7925C1304F20D002BD8E1 /* NotesWriterSSC.cpp */; }; @@ -1776,6 +1778,8 @@ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 2B30D6801315EA7E00044B68 /* MouseDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseDevice.cpp; sourceTree = ""; }; 2B30D6811315EA7E00044B68 /* MouseDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseDevice.h; sourceTree = ""; }; + 2B766989132FF71500586512 /* NotesLoaderSMA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NotesLoaderSMA.h; path = ../src/NotesLoaderSMA.h; sourceTree = SOURCE_ROOT; }; + 2B76698A132FF71500586512 /* NotesLoaderSMA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NotesLoaderSMA.cpp; path = ../src/NotesLoaderSMA.cpp; sourceTree = SOURCE_ROOT; }; 2BA7925A1304F20D002BD8E1 /* NotesLoaderSSC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NotesLoaderSSC.cpp; path = ../src/NotesLoaderSSC.cpp; sourceTree = SOURCE_ROOT; }; 2BA7925B1304F20D002BD8E1 /* NotesLoaderSSC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NotesLoaderSSC.h; path = ../src/NotesLoaderSSC.h; sourceTree = SOURCE_ROOT; }; 2BA7925C1304F20D002BD8E1 /* NotesWriterSSC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NotesWriterSSC.cpp; path = ../src/NotesWriterSSC.cpp; sourceTree = SOURCE_ROOT; }; @@ -3154,6 +3158,7 @@ AA6EFDC804770AF1005F316C /* DataStructures */, AA6EFE5704770C7E005F316C /* FileTypes */, AA6E00FE047711FF005F316C /* GlobalSingletons */, + 2B766980132FF62B00586512 /* NoteParsing */, 29B97315FDCFA39411CA2CEA /* Other Source */, AA8B6C7804AFD82B00D02EE9 /* pcre */, AA6EFDBB04770A83005F316C /* Rage */, @@ -3201,6 +3206,37 @@ name = Frameworks; sourceTree = ""; }; + 2B766980132FF62B00586512 /* NoteParsing */ = { + isa = PBXGroup; + children = ( + AA6EFDED04770C79005F316C /* NotesLoader.cpp */, + AA6EFDEE04770C79005F316C /* NotesLoader.h */, + AA6EFDEF04770C79005F316C /* NotesLoaderBMS.cpp */, + AA6EFDF004770C79005F316C /* NotesLoaderBMS.h */, + AA6EFDF104770C79005F316C /* NotesLoaderDWI.cpp */, + AA6EFDF204770C79005F316C /* NotesLoaderDWI.h */, + AA6EFDF304770C79005F316C /* NotesLoaderKSF.cpp */, + AA6EFDF404770C79005F316C /* NotesLoaderKSF.h */, + 3688B8510BD42DAA004186AD /* NotesLoaderMidi.cpp */, + 3688B8520BD42DAA004186AD /* NotesLoaderMidi.h */, + EE2153A710A75BEE0074B01B /* NotesLoaderPMS.cpp */, + EE2153A810A75BEE0074B01B /* NotesLoaderPMS.h */, + AA6EFDF504770C79005F316C /* NotesLoaderSM.cpp */, + AA6EFDF604770C79005F316C /* NotesLoaderSM.h */, + 2B76698A132FF71500586512 /* NotesLoaderSMA.cpp */, + 2B766989132FF71500586512 /* NotesLoaderSMA.h */, + 2BA7925A1304F20D002BD8E1 /* NotesLoaderSSC.cpp */, + 2BA7925B1304F20D002BD8E1 /* NotesLoaderSSC.h */, + AA6EFDF704770C79005F316C /* NotesWriterDWI.cpp */, + AA6EFDF804770C79005F316C /* NotesWriterDWI.h */, + AA6EFDF904770C79005F316C /* NotesWriterSM.cpp */, + AA6EFDFA04770C79005F316C /* NotesWriterSM.h */, + 2BA7925C1304F20D002BD8E1 /* NotesWriterSSC.cpp */, + 2BA7925D1304F20D002BD8E1 /* NotesWriterSSC.h */, + ); + name = NoteParsing; + sourceTree = ""; + }; AA60E0BB067992D7008ADC41 /* Threads */ = { isa = PBXGroup; children = ( @@ -3776,28 +3812,6 @@ AA4F38C104E2D0B700D02EE9 /* NoteDataUtil.h */, AA6EFDE704770C79005F316C /* NoteDataWithScoring.cpp */, AA6EFDE804770C79005F316C /* NoteDataWithScoring.h */, - AA6EFDED04770C79005F316C /* NotesLoader.cpp */, - AA6EFDEE04770C79005F316C /* NotesLoader.h */, - AA6EFDEF04770C79005F316C /* NotesLoaderBMS.cpp */, - AA6EFDF004770C79005F316C /* NotesLoaderBMS.h */, - AA6EFDF104770C79005F316C /* NotesLoaderDWI.cpp */, - AA6EFDF204770C79005F316C /* NotesLoaderDWI.h */, - AA6EFDF304770C79005F316C /* NotesLoaderKSF.cpp */, - AA6EFDF404770C79005F316C /* NotesLoaderKSF.h */, - 3688B8510BD42DAA004186AD /* NotesLoaderMidi.cpp */, - 3688B8520BD42DAA004186AD /* NotesLoaderMidi.h */, - EE2153A710A75BEE0074B01B /* NotesLoaderPMS.cpp */, - EE2153A810A75BEE0074B01B /* NotesLoaderPMS.h */, - AA6EFDF504770C79005F316C /* NotesLoaderSM.cpp */, - AA6EFDF604770C79005F316C /* NotesLoaderSM.h */, - 2BA7925A1304F20D002BD8E1 /* NotesLoaderSSC.cpp */, - 2BA7925B1304F20D002BD8E1 /* NotesLoaderSSC.h */, - AA6EFDF704770C79005F316C /* NotesWriterDWI.cpp */, - AA6EFDF804770C79005F316C /* NotesWriterDWI.h */, - AA6EFDF904770C79005F316C /* NotesWriterSM.cpp */, - AA6EFDFA04770C79005F316C /* NotesWriterSM.h */, - 2BA7925C1304F20D002BD8E1 /* NotesWriterSSC.cpp */, - 2BA7925D1304F20D002BD8E1 /* NotesWriterSSC.h */, AA6EFDFB04770C79005F316C /* NoteTypes.cpp */, AA6EFDFC04770C79005F316C /* NoteTypes.h */, AA80C75707F20D6600C99272 /* OptionRowHandler.cpp */, @@ -4935,6 +4949,7 @@ 2BA7925F1304F20D002BD8E1 /* NotesLoaderSSC.h in Headers */, 2BA792611304F20D002BD8E1 /* NotesWriterSSC.h in Headers */, 2B30D6831315EA7E00044B68 /* MouseDevice.h in Headers */, + 2B76698B132FF71500586512 /* NotesLoaderSMA.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6180,6 +6195,7 @@ 2BA7925E1304F20D002BD8E1 /* NotesLoaderSSC.cpp in Sources */, 2BA792601304F20D002BD8E1 /* NotesWriterSSC.cpp in Sources */, 2B30D6821315EA7E00044B68 /* MouseDevice.cpp in Sources */, + 2B76698C132FF71500586512 /* NotesLoaderSMA.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/Makefile.am b/src/Makefile.am index 28eb71d84d..ed823447e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -147,7 +147,8 @@ NoteTypes.cpp NoteTypes.h NotesLoader.cpp NotesLoader.h \ NotesLoaderBMS.cpp NotesLoaderBMS.h NotesLoaderDWI.cpp NotesLoaderDWI.h \ NotesLoaderKSF.cpp NotesLoaderKSF.h NotesLoaderMidi.cpp NotesLoaderMidi.h \ NotesLoaderPMS.cpp NotesLoaderPMS.h NotesLoaderSM.cpp NotesLoaderSM.h \ -NotesLoaderSSC.cpp NotesLoaderSSC.h NotesWriterDWI.cpp NotesWriterDWI.h \ +NotesLoaderSSC.cpp NotesLoaderSSC.h NotesLoaderSMA.cpp NotesLoaderSMA.h \ +NotesWriterDWI.cpp NotesWriterDWI.h \ NotesWriterSM.cpp NotesWriterSM.h NotesWriterSSC.cpp NotesWriterSSC.h \ OptionRowHandler.cpp OptionRowHandler.h OptionsList.cpp OptionsList.h \ PlayerAI.cpp PlayerAI.h PlayerNumber.cpp PlayerNumber.h PlayerOptions.cpp PlayerOptions.h \ diff --git a/src/MsdFile.h b/src/MsdFile.h index 229f329082..f6257f5cf1 100644 --- a/src/MsdFile.h +++ b/src/MsdFile.h @@ -1,9 +1,7 @@ -/** @brief MsdFile - Read .SSC, .SM, .DWI, and .MSD files. */ - #ifndef MSDFILE_H #define MSDFILE_H -/** @brief The class that reads the various .SSC, .SM, .DWI, and .MSD files. */ +/** @brief The class that reads the various .SSC, .SM, .SMA, .DWI, and .MSD files. */ class MsdFile { public: diff --git a/src/NotesLoader.cpp b/src/NotesLoader.cpp index 0d257c3c81..68bb973b5a 100644 --- a/src/NotesLoader.cpp +++ b/src/NotesLoader.cpp @@ -2,6 +2,7 @@ #include "NotesLoader.h" #include "NotesLoaderSM.h" #include "NotesLoaderSSC.h" +#include "NotesLoaderSMA.h" #include "NotesLoaderDWI.h" #include "NotesLoaderBMS.h" #include "NotesLoaderPMS.h" @@ -42,6 +43,9 @@ bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set &Bl SMLoader::GetApplicableFiles( sPath, list ); if (!list.empty() ) return SMLoader::LoadFromDir( sPath, out ); + SMALoader::GetApplicableFiles( sPath, list ); + if (!list.empty() ) + return SMALoader::LoadFromDir( sPath, out ); DWILoader::GetApplicableFiles( sPath, list ); if( !list.empty() ) return DWILoader::LoadFromDir( sPath, out, BlacklistedImages ); diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index c2aa663825..6caafaf379 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -424,7 +424,7 @@ void SMLoader::LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ) } } -bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) +bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) { vector aBGChangeValues; split( sBGChangeExpression, "=", aBGChangeValues, false ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 4864c74411..3886586062 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -2,6 +2,7 @@ #define NotesLoaderSM_H #include "GameConstantsAndTypes.h" +#include "BackgroundUtil.h" class MsdFile; class Song; @@ -23,6 +24,7 @@ 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 ); } #endif diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp new file mode 100644 index 0000000000..2d60122764 --- /dev/null +++ b/src/NotesLoaderSMA.cpp @@ -0,0 +1,764 @@ +#include "global.h" +#include "NotesLoaderSMA.h" +#include "BackgroundUtil.h" +#include "GameManager.h" +#include "MsdFile.h" +#include "NoteTypes.h" +#include "NotesLoaderSM.h" // may need this. +#include "PrefsManager.h" +#include "RageFileManager.h" +#include "RageLog.h" +#include "RageUtil.h" +#include "Song.h" +#include "SongManager.h" +#include "Steps.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 + +void SMALoader::LoadFromSMATokens( + RString sStepsType, + RString sDescription, + RString sDifficulty, + RString sMeter, + RString sRadarValues, + RString sNoteData, + Steps &out +) +{ + // we're loading from disk, so this is by definition already saved: + out.SetSavedToDisk( true ); + + Trim( sStepsType ); + Trim( sDescription ); + Trim( sDifficulty ); + Trim( sNoteData ); + + // LOG->Trace( "Steps::LoadFromSMTokens()" ); + + // insert stepstype hacks from GameManager.cpp here? -aj + out.m_StepsType = GAMEMAN->StringToStepsType( sStepsType ); + out.SetDescription( sDescription ); + out.SetCredit( sDescription ); // this is often used for both. + out.SetDifficulty( DwiCompatibleStringToDifficulty(sDifficulty) ); + + sDescription.MakeLower(); + + // Handle hacks that originated back when StepMania didn't have + // Difficulty_Challenge. (At least v1.64, possibly v3.0 final...) + if( out.GetDifficulty() == Difficulty_Hard ) + { + // HACK: SMANIAC used to be Difficulty_Hard with a special description. + if( sDescription == "smaniac" ) + out.SetDifficulty( Difficulty_Challenge ); + + // HACK: CHALLENGE used to be Difficulty_Hard with a special description. + if( sDescription == "challenge" ) + out.SetDifficulty( Difficulty_Challenge ); + } + + out.SetMeter( atoi(sMeter) ); + vector saValues; + split( sRadarValues, ",", saValues, true ); + int categories = NUM_RadarCategory - 1; // Fakes aren't counted in the radar values. + if( saValues.size() == (unsigned)categories * NUM_PLAYERS ) + { + RadarValues v[NUM_PLAYERS]; + FOREACH_PlayerNumber( pn ) + { + // Can't use the foreach anymore due to flexible radar lines. + for( RadarCategory rc = (RadarCategory)0; rc < categories; + enum_add( rc, 1 ) ) + { + v[pn][rc] = StringToFloat( saValues[pn*categories + rc] ); + } + } + out.SetCachedRadarValues( v ); + } + + out.SetSMNoteData( sNoteData ); + + out.TidyUpData(); +} + +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. There can be only one!" ); + return false; + } + ASSERT( aFileNames.size() == 1 ); + return LoadFromSMAFile( sPath + aFileNames[0], out ); +} + +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() ); + + MsdFile msd; + if( !msd.ReadFile( sPath, true ) ) // unescape + { + LOG->UserLog( "Song file", sPath, "couldn't be opened: %s", msd.GetError().c_str() ); + return false; + } + + out.m_Timing.m_sFile = sPath; + LoadTimingFromSMAFile( msd, out.m_Timing ); + + for( unsigned i=0; i vs1; + split( sParams[1], ",", vs1 ); + FOREACH_CONST( RString, vs1, s ) + { + vector vs2; + split( *s, "=", vs2 ); + if( vs2.size() >= 2 ) + { + InstrumentTrack it = StringToInstrumentTrack( vs2[0] ); + if( it != InstrumentTrack_Invalid ) + out.m_sInstrumentTrackFile[it] = vs2[1]; + } + } + } + + else if( sValueName=="MUSICLENGTH" ) + { + continue; + } + + else if( sValueName=="LASTBEATHINT" ) + out.m_fSpecifiedLastBeat = StringToFloat( sParams[1] ); + + else if( sValueName=="MUSICBYTES" ) + ; /* ignore */ + + /* We calculate these. Some SMs in circulation have bogus values for + * these, so make sure we always calculate it ourself. */ + else if( sValueName=="FIRSTBEAT" ) + { + ; + } + else if( sValueName=="LASTBEAT" ) + { + ; } + else if( sValueName=="SONGFILENAME" ) + { + ; + } + else if( sValueName=="HASMUSIC" ) + { + ; + } + else if( sValueName=="HASBANNER" ) + { + ; + } + + else if( sValueName=="SAMPLESTART" ) + out.m_fMusicSampleStartSeconds = HHMMSSToSeconds( sParams[1] ); + + else if( sValueName=="SAMPLELENGTH" ) + out.m_fMusicSampleLengthSeconds = HHMMSSToSeconds( sParams[1] ); + + // SamplePath is used when the song has a separate preview clip. -aj + //else if( sValueName=="SAMPLEPATH" ) + //out.m_sMusicSamplePath = sParams[1]; + + else if( sValueName=="DISPLAYBPM" ) + { + // #DISPLAYBPM:[xxx][xxx:xxx]|[*]; + if( sParams[1] == "*" ) + out.m_DisplayBPMType = Song::DISPLAY_RANDOM; + else + { + out.m_DisplayBPMType = Song::DISPLAY_SPECIFIED; + out.m_fSpecifiedBPMMin = StringToFloat( sParams[1] ); + if( sParams[2].empty() ) + out.m_fSpecifiedBPMMax = out.m_fSpecifiedBPMMin; + else + out.m_fSpecifiedBPMMax = StringToFloat( sParams[2] ); + } + } + + else if( sValueName=="SELECTABLE" ) + { + if(!stricmp(sParams[1],"YES")) + out.m_SelectionDisplay = out.SHOW_ALWAYS; + else if(!stricmp(sParams[1],"NO")) + out.m_SelectionDisplay = out.SHOW_NEVER; + // ROULETTE from 3.9. It was removed since UnlockManager can serve + // the same purpose somehow. This, of course, assumes you're using + // unlocks. -aj + else if(!stricmp(sParams[1],"ROULETTE")) + out.m_SelectionDisplay = out.SHOW_ALWAYS; + /* The following two cases are just fixes to make sure simfiles that + * used 3.9+ features are not excluded here */ + else if(!stricmp(sParams[1],"ES") || !stricmp(sParams[1],"OMES")) + out.m_SelectionDisplay = out.SHOW_ALWAYS; + else if( atoi(sParams[1]) > 0 ) + out.m_SelectionDisplay = out.SHOW_ALWAYS; + else + LOG->UserLog( "Song file", sPath, "has an unknown #SELECTABLE value, \"%s\"; ignored.", sParams[1].c_str() ); + } + + else if( sValueName.Left(strlen("BGCHANGES"))=="BGCHANGES" || sValueName=="ANIMATIONS" ) + { + BackgroundLayer iLayer = BACKGROUND_LAYER_1; + if( sscanf(sValueName, "BGCHANGES%d", &*ConvertValue(&iLayer)) == 1 ) + enum_add(iLayer, -1); // #BGCHANGES2 = BACKGROUND_LAYER_2 + + bool bValid = iLayer>=0 && iLayerUserLog( "Song file", sPath, "has a #BGCHANGES tag \"%s\" that is out of range.", sValueName.c_str() ); + } + else + { + vector aBGChangeExpressions; + split( sParams[1], ",", aBGChangeExpressions ); + + for( unsigned b=0; b aFGChangeExpressions; + split( sParams[1], ",", aFGChangeExpressions ); + + for( unsigned b=0; b sBits; + split( sParams[j], "=", sBits, false ); + + // Need an identifer and a value for this to work + if( sBits.size() < 2 ) + continue; + + TrimLeft( sBits[0] ); + TrimRight( sBits[0] ); + + if( !sBits[0].CompareNoCase("TIME") ) + attack.fStartSecond = strtof( sBits[1], NULL ); + else if( !sBits[0].CompareNoCase("LEN") ) + attack.fSecsRemaining = strtof( sBits[1], NULL ); + else if( !sBits[0].CompareNoCase("END") ) + end = strtof( sBits[1], NULL ); + else if( !sBits[0].CompareNoCase("MODS") ) + { + attack.sModifiers = sBits[1]; + + if( end != -9999 ) + { + attack.fSecsRemaining = end - attack.fStartSecond; + end = -9999; + } + + if( attack.fSecsRemaining < 0.0f ) + attack.fSecsRemaining = 0.0f; + + out.m_Attacks.push_back( attack ); + } + } + } + + else if( sValueName=="NOTES" || sValueName=="NOTES2" ) + { + if( iNumParams < 7 ) + { + LOG->UserLog( "Song file", sPath, "has %d fields in a #NOTES tag, but should have at least 7.", iNumParams ); + continue; + } + + Steps* pNewNotes = new Steps; + LoadFromSMATokens( + sParams[1], + sParams[2], + sParams[3], + sParams[4], + sParams[5], + sParams[6], + *pNewNotes ); + + out.AddSteps( pNewNotes ); + } + /* + * We used to check for timing data in this section. That has + * since been moved to a dedicated function. + */ + else if( sValueName=="OFFSET" || sValueName=="BPMS" || 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() ); + } + + return true; +} + +void SMALoader::GetApplicableFiles( const RString &sPath, vector &out ) +{ + GetDirListing( sPath + RString("*.sma"), out ); +} + +bool SMALoader::LoadTimingFromFile( const RString &fn, TimingData &out ) +{ + MsdFile msd; + if( !msd.ReadFile( fn, true ) ) // unescape + { + LOG->UserLog( "Song file", fn, "couldn't be loaded: %s", msd.GetError().c_str() ); + return false; + } + + out.m_sFile = fn; + LoadTimingFromSMAFile( msd, out ); + return true; +} + +void SMALoader::LoadTimingFromSMAFile( const MsdFile &msd, TimingData &out ) +{ + out.m_fBeat0OffsetInSeconds = 0; + out.m_BPMSegments.clear(); + out.m_StopSegments.clear(); + out.m_WarpSegments.clear(); + out.m_vTimeSignatureSegments.clear(); + + vector arrayWarpsFromNegativeBPMs; + //vector arrayWarpsFromNegativeStops; + int rowsPerMeasure = 0; + bool encountered = false; + + for( unsigned i=0; i arrayFreezeExpressions; + split( sParams[1], ",", arrayFreezeExpressions ); + + 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 #%s value \"%s\" (must have exactly one '='), ignored.", + sValueName.c_str(), arrayFreezeExpressions[f].c_str() ); + continue; + } + + float fFreezeBeat = 0; + RString beat = arrayFreezeValues[0]; + if( beat.Right(0).MakeUpper() == "R" ) + { + beat = beat.Left(beat.size()-1); + fFreezeBeat = StringToFloat( beat ) / rowsPerMeasure; + } + else + { + fFreezeBeat = StringToFloat(beat); + } + + //float fFreezeBeat = StringToFloat( arrayBPMChangeValues[0] ); + const float fFreezeSeconds = StringToFloat( arrayFreezeValues[1] ); + StopSegment new_seg( BeatToNoteRow(fFreezeBeat), fFreezeSeconds ); + // XXX: Remove Negatives Bug? + new_seg.m_iStartRow = BeatToNoteRow(fFreezeBeat); + new_seg.m_fStopSeconds = fFreezeSeconds; + + if(fFreezeSeconds > 0.0f) + { + // LOG->Trace( "Adding a freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds ); + out.AddStopSegment( new_seg ); + } + else + { + // negative stops (hi JS!) -aj + if( PREFSMAN->m_bQuirksMode ) + { + // LOG->Trace( "Adding a negative freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds ); + out.AddStopSegment( new_seg ); + } + else + LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid stop at beat %f, length %f.", fFreezeBeat, fFreezeSeconds ); + } + } + } + + 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). + // If Warps have been populated from Negative BPMs, then go through that + // instead of using the data in the Warps tag. This should be above, + // but it breaks compiling so... + if(arrayWarpsFromNegativeBPMs.size() > 0) + { + // zomg we already have some warps... + for( unsigned j=0; jTrace( "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 = new Steps; + LoadFromSMATokens( + 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; +} + +bool SMALoader::LoadFromBGChangesString( BackgroundChange &change, + const RString &sBGChangeExpression ) +{ + return SMLoader::LoadFromBGChangesString(change, sBGChangeExpression); +} + +/** + * @file + * @author Aldo Fregoso, Jason Felds (c) 2009-2011 + * @section LICENSE + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h new file mode 100644 index 0000000000..0fceb3977d --- /dev/null +++ b/src/NotesLoaderSMA.h @@ -0,0 +1,63 @@ +#ifndef NOTES_LOADER_SMA_H +#define NOTES_LOADER_SMA_H + +#include "GameConstantsAndTypes.h" +#include "BackgroundUtil.h" + +class MsdFile; +class Song; +class Steps; +class TimingData; + +/** @brief Reads a Song from a .SMA file. */ +namespace SMALoader +{ + 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 ); + + bool LoadFromSMAFile( const RString &sPath, Song &out ); + void GetApplicableFiles( const RString &sPath, vector &out ); + bool LoadTimingFromFile( const RString &fn, TimingData &out ); + void LoadTimingFromSMAFile( const MsdFile &msd, TimingData &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 ); +}; + +#endif + +/** + * @file + * @author Aldo Fregoso, Jason Felds (c) 2009-2011 + * @section LICENSE + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/src/Song.cpp b/src/Song.cpp index 706c06a3ff..74da16a269 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -738,26 +738,37 @@ void Song::TidyUpData() * filename, and should always be the title of the song (unlike KSFs). */ m_sSongFileName = m_sSongDir; vector asFileNames; - GetDirListing( m_sSongDir+"*.ssc", asFileNames ); - if( !asFileNames.empty() ) - { - m_sSongFileName += asFileNames[0]; - } - else + do { + GetDirListing( m_sSongDir+"*.ssc", asFileNames ); + if( !asFileNames.empty() ) + { + m_sSongFileName += asFileNames[0]; + break; + } + + GetDirListing( m_sSongDir+"*.sma", asFileNames ); + if (!asFileNames.empty() ) + { + m_sSongFileName += SetExtension( asFileNames[0], "ssc" ); + break; + } + GetDirListing( m_sSongDir+"*.sm", asFileNames ); if( !asFileNames.empty() ) + { m_sSongFileName += SetExtension( asFileNames[0], "ssc" ); - else { - GetDirListing( m_sSongDir+"*.dwi", asFileNames ); - if( !asFileNames.empty() ) { - m_sSongFileName += SetExtension( asFileNames[0], "ssc" ); - } else { - m_sSongFileName += Basename(m_sSongDir); - m_sSongFileName += ".ssc"; - } + break; } - } + + GetDirListing( m_sSongDir+"*.dwi", asFileNames ); + if( !asFileNames.empty() ) { + m_sSongFileName += SetExtension( asFileNames[0], "ssc" ); + break; + } + m_sSongFileName += Basename(m_sSongDir); + m_sSongFileName += ".ssc"; + } while(0); } // If no time signature specified, assume 4/4 time for the whole song. diff --git a/src/StepMania-net2003.vcproj b/src/StepMania-net2003.vcproj index 2a0cbf18f1..1c23b151c9 100644 --- a/src/StepMania-net2003.vcproj +++ b/src/StepMania-net2003.vcproj @@ -969,10 +969,10 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ RelativePath="NotesLoaderKSF.h"> + RelativePath="NotesLoaderMidi.cpp"> + RelativePath="NotesLoaderMidi.h"> @@ -986,6 +986,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + diff --git a/src/StepMania-net2005.vcproj b/src/StepMania-net2005.vcproj index 8e593ab5a9..18b6ef034f 100644 --- a/src/StepMania-net2005.vcproj +++ b/src/StepMania-net2005.vcproj @@ -1291,11 +1291,11 @@ > + + + + diff --git a/src/StepMania-net2008.vcproj b/src/StepMania-net2008.vcproj index db3c4a01c2..1d7851fe9c 100644 --- a/src/StepMania-net2008.vcproj +++ b/src/StepMania-net2008.vcproj @@ -1433,11 +1433,11 @@ > + + + +