Files
itgmania212121/src/NotesLoaderSMA.cpp
T

491 lines
14 KiB
C++
Raw Normal View History

2011-03-17 01:47:30 -04:00
#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"
#include "Attack.h"
2011-03-17 01:47:30 -04:00
void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam )
{
vector<RString> arrayMultiplierExpressions;
split( sParam, ",", arrayMultiplierExpressions );
for( unsigned f=0; f<arrayMultiplierExpressions.size(); f++ )
{
vector<RString> arrayMultiplierValues;
split( arrayMultiplierExpressions[f], "=", arrayMultiplierValues );
2011-07-09 02:28:15 -04:00
unsigned size = arrayMultiplierValues.size();
if( size < 2 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
2011-07-09 02:28:15 -04:00
"has an invalid #MULTIPLIER value \"%s\" (must have at least one '='), ignored.",
arrayMultiplierExpressions[f].c_str() );
continue;
}
const float fComboBeat = RowToBeat( arrayMultiplierValues[0], iRowsPerBeat );
const int iCombos = StringToInt( arrayMultiplierValues[1] ); // always true.
2011-07-09 02:28:15 -04:00
// hoping I'm right here: SMA files can use 6 values after the row/beat.
const int iMisses = (size == 2 || size == 4 ?
iCombos :
StringToInt(arrayMultiplierValues[2]));
out.AddSegment( ComboSegment(BeatToNoteRow(fComboBeat), iCombos, iMisses) );
}
}
2011-05-14 18:04:31 -04:00
void SMALoader::ProcessBeatsPerMeasure( TimingData &out, const RString sParam )
{
vector<RString> vs1;
split( sParam, ",", vs1 );
2019-06-22 12:35:38 -07:00
for (RString const &s1 : vs1)
2011-05-14 18:04:31 -04:00
{
vector<RString> vs2;
2019-06-22 12:35:38 -07:00
split( s1, "=", vs2 );
2011-05-14 18:04:31 -04:00
if( vs2.size() < 2 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
"has an invalid beats per measure change with %i values.",
static_cast<int>(vs2.size()) );
2011-05-14 18:04:31 -04:00
continue;
}
const float fBeat = StringToFloat( vs2[0] );
const int iNumerator = StringToInt( vs2[1] );
2011-05-14 18:04:31 -04:00
if( fBeat < 0 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
2011-06-14 13:35:59 -04:00
"has an invalid time signature change with beat %f.",
fBeat );
2011-05-14 18:04:31 -04:00
continue;
}
if( iNumerator < 1 )
2011-05-14 18:04:31 -04:00
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
"has an invalid time signature change with beat %f, iNumerator %i.",
fBeat, iNumerator );
2011-05-14 18:04:31 -04:00
continue;
}
out.AddSegment( TimeSignatureSegment(BeatToNoteRow(fBeat), iNumerator) );
2011-05-14 18:04:31 -04:00
}
}
2011-06-09 14:45:30 -04:00
void SMALoader::ProcessSpeeds( TimingData &out, const RString line, const int rowsPerBeat )
2011-05-15 15:24:36 -04:00
{
vector<RString> vs1;
2011-06-09 14:45:30 -04:00
split( line, ",", vs1 );
2012-10-20 05:12:05 -05:00
2019-06-22 12:35:38 -07:00
for (std::vector<RString>::const_iterator s1 = vs1.begin(); s1 != vs1.end(); ++s1)
2011-05-15 15:24:36 -04:00
{
vector<RString> vs2;
2011-05-29 23:55:03 -04:00
vs2.clear(); // trying something.
RString loopTmp = *s1;
Trim( loopTmp );
split( loopTmp, "=", vs2 );
2011-05-15 15:24:36 -04:00
2011-05-29 22:44:01 -04:00
if( vs2.size() == 2 ) // First one always seems to have 2.
2011-05-15 15:24:36 -04:00
{
2012-10-20 05:12:05 -05:00
// Aldo_MX: 4 is the default value in SMA, although SM5 requires 0 for the first segment :/
vs2.push_back(s1 == vs1.begin() ? "0" : "4");
2011-05-15 15:24:36 -04:00
}
if( vs2.size() < 3 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
"has an speed change with %i values.",
static_cast<int>(vs2.size()) );
2011-05-15 15:24:36 -04:00
continue;
}
2011-06-09 14:45:30 -04:00
const float fBeat = RowToBeat( vs2[0], rowsPerBeat );
2011-06-04 23:44:26 -04:00
RString backup = vs2[2];
Trim(vs2[2], "s");
Trim(vs2[2], "S");
const float fRatio = StringToFloat( vs2[1] );
const float fDelay = StringToFloat( vs2[2] );
SpeedSegment::BaseUnit unit = ((backup != vs2[2]) ?
SpeedSegment::UNIT_SECONDS : SpeedSegment::UNIT_BEATS);
2011-05-15 15:24:36 -04:00
if( fBeat < 0 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
"has an speed change with beat %f.",
fBeat );
2011-05-15 15:24:36 -04:00
continue;
}
if( fDelay < 0 )
2011-05-15 15:24:36 -04:00
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
this->GetSongTitle(),
"has an speed change with beat %f, length %f.",
fBeat, fDelay );
2011-05-15 15:24:36 -04:00
continue;
}
out.AddSegment( SpeedSegment(BeatToNoteRow(fBeat), fRatio, fDelay, unit) );
2011-05-15 15:24:36 -04:00
}
}
2011-06-09 21:27:47 -04:00
bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCache )
2011-03-17 01:47:30 -04:00
{
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;
}
2011-05-14 17:41:08 -04:00
out.m_SongTiming.m_sFile = sPath; // songs still have their fallback timing.
2011-07-17 16:06:40 -04:00
out.m_sSongFileName = sPath;
2011-05-14 17:41:08 -04:00
2019-06-22 12:35:38 -07:00
Steps* pNewNotes = nullptr;
2011-05-14 17:41:08 -04:00
int iRowsPerBeat = -1; // Start with an invalid value: needed for checking.
vector< pair<float, float> > vBPMChanges, vStops;
2011-03-17 01:47:30 -04:00
for( unsigned i=0; i<msd.GetNumValues(); i++ )
{
int iNumParams = msd.GetNumParams(i);
const MsdFile::value_t &sParams = msd.GetValue(i);
RString sValueName = sParams[0];
sValueName.MakeUpper();
// handle the data
/* Don't use GetMainAndSubTitlesFromFullTitle; that's only for heuristically
* splitting other formats that *don't* natively support #SUBTITLE. */
if( sValueName=="TITLE" )
2011-06-14 13:35:59 -04:00
{
2011-03-17 01:47:30 -04:00
out.m_sMainTitle = sParams[1];
2011-06-14 13:35:59 -04:00
this->SetSongTitle(sParams[1]);
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="SUBTITLE" )
out.m_sSubTitle = sParams[1];
else if( sValueName=="ARTIST" )
out.m_sArtist = sParams[1];
else if( sValueName=="TITLETRANSLIT" )
out.m_sMainTitleTranslit = sParams[1];
else if( sValueName=="SUBTITLETRANSLIT" )
out.m_sSubTitleTranslit = sParams[1];
else if( sValueName=="ARTISTTRANSLIT" )
out.m_sArtistTranslit = sParams[1];
else if( sValueName=="GENRE" )
out.m_sGenre = sParams[1];
else if( sValueName=="CREDIT" )
out.m_sCredit = sParams[1];
else if( sValueName=="BANNER" )
out.m_sBannerFile = sParams[1];
else if( sValueName=="BACKGROUND" )
out.m_sBackgroundFile = sParams[1];
else if( sValueName=="PREVIEW" )
out.m_sPreviewVidFile = sParams[1];
2011-03-17 01:47:30 -04:00
// Save "#LYRICS" for later, so we can add an internal lyrics tag.
else if( sValueName=="LYRICSPATH" )
out.m_sLyricsFile = sParams[1];
else if( sValueName=="CDTITLE" )
out.m_sCDTitleFile = sParams[1];
else if( sValueName=="MUSIC" )
out.m_sMusicFile = sParams[1];
else if( sValueName=="INSTRUMENTTRACK" )
{
SMLoader::ProcessInstrumentTracks( out, sParams[1] );
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="MUSICLENGTH" )
{
continue;
}
else if( sValueName=="LASTBEATHINT" )
2011-06-30 01:11:38 -04:00
{
// can't identify at this position: ignore.
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="MUSICBYTES" )
; /* ignore */
2011-06-30 01:11:38 -04:00
// Cache tags: ignore.
else if (sValueName=="FIRSTBEAT" || sValueName=="LASTBEAT" ||
sValueName=="SONGFILENAME" || sValueName=="HASMUSIC" ||
sValueName=="HASBANNER" )
2011-03-17 01:47:30 -04:00
{
;
}
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=="LISTSORT" )
{
;
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="DISPLAYBPM" )
{
// #DISPLAYBPM:[xxx][xxx:xxx]|[*];
if( sParams[1] == "*" )
out.m_DisplayBPMType = DISPLAY_BPM_RANDOM;
2011-03-17 01:47:30 -04:00
else
{
out.m_DisplayBPMType = DISPLAY_BPM_SPECIFIED;
2011-03-17 01:47:30 -04:00
out.m_fSpecifiedBPMMin = StringToFloat( sParams[1] );
if( sParams[2].empty() )
out.m_fSpecifiedBPMMax = out.m_fSpecifiedBPMMin;
else
out.m_fSpecifiedBPMMax = StringToFloat( sParams[2] );
}
}
2011-05-14 18:04:31 -04:00
else if( sValueName=="SMAVERSION" )
{
; // ignore it.
}
else if( sValueName=="ROWSPERBEAT" )
{
/* This value is used to help translate the timings
* the SMA format uses. Starting with the second
* appearance, it delimits NoteData. Right now, this
* value doesn't seem to be editable in SMA. When it
* becomes so, make adjustments to this code. */
if( iRowsPerBeat < 0 )
{
vector<RString> arrayBeatChangeExpressions;
split( sParams[1], ",", arrayBeatChangeExpressions );
vector<RString> arrayBeatChangeValues;
split( arrayBeatChangeExpressions[0], "=", arrayBeatChangeValues );
iRowsPerBeat = StringToInt(arrayBeatChangeValues[1]);
2011-05-14 18:04:31 -04:00
}
else
{
// This should generally return song timing
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2013-05-17 16:43:53 -04:00
ProcessBPMsAndStops(timing, vBPMChanges, vStops);
2011-05-14 18:04:31 -04:00
}
}
else if( sValueName=="BEATSPERMEASURE" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-05-14 18:04:31 -04:00
ProcessBeatsPerMeasure( timing, sParams[1] );
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="SELECTABLE" )
{
2011-05-11 16:48:51 -04:00
if(sParams[1].EqualsNoCase("YES"))
2011-03-17 01:47:30 -04:00
out.m_SelectionDisplay = out.SHOW_ALWAYS;
2011-05-11 16:48:51 -04:00
else if(sParams[1].EqualsNoCase("NO"))
2011-03-17 01:47:30 -04:00
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
2011-05-11 16:48:51 -04:00
else if(sParams[1].EqualsNoCase("ROULETTE"))
2011-03-17 01:47:30 -04:00
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 */
2011-05-11 16:48:51 -04:00
else if(sParams[1].EqualsNoCase("ES") || sParams[1].EqualsNoCase("OMES"))
2011-03-17 01:47:30 -04:00
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else if( StringToInt(sParams[1]) > 0 )
2011-03-17 01:47:30 -04:00
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
sPath,
"has an unknown #SELECTABLE value, \"%s\"; ignored.",
sParams[1].c_str() );
2011-03-17 01:47:30 -04:00
}
else if( sValueName.Left(strlen("BGCHANGES"))=="BGCHANGES" || sValueName=="ANIMATIONS" )
{
SMLoader::ProcessBGChanges( out, sValueName, sPath, sParams[1]);
2011-03-17 01:47:30 -04:00
}
else if( sValueName=="FGCHANGES" )
{
2019-10-12 11:41:39 -04:00
std::vector<std::vector<RString> > aFGChanges;
ParseBGChangesString(sParams[1], aFGChanges, out.GetSongDir());
2019-10-12 11:41:39 -04:00
for (const auto &b : aFGChanges)
2011-03-17 01:47:30 -04:00
{
BackgroundChange change;
2019-10-12 11:41:39 -04:00
if (LoadFromBGChangesVector(change, b))
out.AddForegroundChange(change);
2011-03-17 01:47:30 -04:00
}
}
else if( sValueName=="OFFSET" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
timing.m_fBeat0OffsetInSeconds = StringToFloat( sParams[1] );
}
2011-05-14 18:36:46 -04:00
else if( sValueName=="BPMS" )
{
vBPMChanges.clear();
ParseBPMs( vBPMChanges, sParams[1], iRowsPerBeat );
2011-05-14 18:36:46 -04:00
}
2011-05-14 18:44:43 -04:00
else if( sValueName=="STOPS" || sValueName=="FREEZES" )
{
vStops.clear();
ParseStops( vStops, sParams[1], iRowsPerBeat );
2011-05-14 18:44:43 -04:00
}
2011-05-14 18:44:43 -04:00
else if( sValueName=="DELAYS" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-06-09 14:19:12 -04:00
ProcessDelays( timing, sParams[1], iRowsPerBeat );
2011-05-14 18:44:43 -04:00
}
else if( sValueName=="TICKCOUNT" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-06-09 14:32:14 -04:00
ProcessTickcounts( timing, sParams[1], iRowsPerBeat );
}
else if( sValueName=="SPEED" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-05-29 23:55:03 -04:00
RString tmp = sParams[1];
Trim( tmp );
2011-06-09 14:45:30 -04:00
ProcessSpeeds( timing, tmp, iRowsPerBeat );
}
else if( sValueName=="MULTIPLIER" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-05-29 22:44:23 -04:00
ProcessMultipliers( timing, iRowsPerBeat, sParams[1] );
}
else if( sValueName=="FAKES" )
{
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2011-06-09 14:53:58 -04:00
ProcessFakes( timing, sParams[1], iRowsPerBeat );
}
2011-05-14 19:09:23 -04:00
else if( sValueName=="METERTYPE" )
{
; // We don't use this...yet.
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="KEYSOUNDS" )
{
split( sParams[1], ",", out.m_vsKeysoundFile );
}
2011-03-17 01:47:30 -04:00
// Attacks loaded from file
else if( sValueName=="ATTACKS" )
{
2011-06-24 11:27:20 -04:00
ProcessAttackString(out.m_sAttackString, sParams);
ProcessAttacks(out.m_Attacks, sParams);
2011-03-17 01:47:30 -04:00
}
2011-03-17 01:47:30 -04:00
else if( sValueName=="NOTES" || sValueName=="NOTES2" )
{
if( iNumParams < 7 )
{
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
sPath,
"has %d fields in a #NOTES tag, but should have at least 7.",
iNumParams );
2011-03-17 01:47:30 -04:00
continue;
}
pNewNotes = new Steps(&out);
2011-06-09 14:01:55 -04:00
LoadFromTokens(
2011-03-17 01:47:30 -04:00
sParams[1],
sParams[2],
sParams[3],
sParams[4],
sParams[5],
sParams[6],
*pNewNotes );
2011-07-17 16:06:40 -04:00
pNewNotes->SetFilename(sPath);
2011-03-17 01:47:30 -04:00
out.AddSteps( pNewNotes );
// Handle timing changes and convert negative bpms/stops
TimingData &timing = ( pNewNotes ? pNewNotes->m_Timing : out.m_SongTiming);
2013-05-17 16:43:53 -04:00
ProcessBPMsAndStops(timing, vBPMChanges, vStops);
2011-03-17 01:47:30 -04:00
}
else if( sValueName=="TIMESIGNATURES" || sValueName=="LEADTRACK" )
2011-03-17 01:47:30 -04:00
;
else
2011-06-14 13:35:59 -04:00
LOG->UserLog("Song file",
sPath,
"has an unexpected value named \"%s\".",
sValueName.c_str() );
2011-03-17 01:47:30 -04:00
}
2011-05-16 23:44:06 -04:00
TidyUpData(out, false);
2011-03-17 01:47:30 -04:00
return true;
}
/**
* @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.
*/