2002-09-06 23:24:40 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
|
|
#include "NotesLoaderKSF.h"
|
|
|
|
|
|
|
|
|
|
#include "RageException.h"
|
|
|
|
|
#include "MsdFile.h"
|
|
|
|
|
#include "RageLog.h"
|
2002-09-07 11:43:36 +00:00
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "NoteData.h"
|
|
|
|
|
#include "NoteTypes.h"
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
bool KSFLoader::LoadFromKSFFile( const CString &sPath, Notes &out )
|
|
|
|
|
{
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Trace( "Notes::LoadFromKSFFile( '%s' )", sPath.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
MsdFile msd;
|
|
|
|
|
bool bResult = msd.ReadFile( sPath );
|
|
|
|
|
if( !bResult )
|
2002-10-29 07:58:44 +00:00
|
|
|
throw RageException( "Error opening file '%s'.", sPath.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
int iTickCount = -1; // this is the value we read for TICKCOUNT
|
|
|
|
|
CString iStep; // this is the value we read for STEP
|
|
|
|
|
|
|
|
|
|
for( int i=0; i<msd.m_iNumValues; i++ )
|
|
|
|
|
{
|
2002-09-15 07:03:32 +00:00
|
|
|
CString* sParams = msd.m_sParams[i];
|
2002-09-06 23:24:40 +00:00
|
|
|
CString sValueName = sParams[0];
|
|
|
|
|
|
|
|
|
|
// handle the data
|
|
|
|
|
if( 0==stricmp(sValueName,"TICKCOUNT") )
|
|
|
|
|
iTickCount = atoi(sParams[1]);
|
|
|
|
|
|
|
|
|
|
else if( 0==stricmp(sValueName,"STEP") )
|
|
|
|
|
iStep = sParams[1];
|
|
|
|
|
else if( 0==stricmp(sValueName,"DIFFICULTY") )
|
|
|
|
|
out.m_iMeter = atoi(sParams[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( iTickCount == -1 )
|
|
|
|
|
{
|
|
|
|
|
iTickCount = 2;
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Warn( "%s:\nTICKCOUNT not found; defaulting to %i", sPath.GetString(), iTickCount );
|
2002-09-06 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NoteData notedata; // read it into here
|
|
|
|
|
|
|
|
|
|
CStringArray asRows;
|
|
|
|
|
iStep.TrimLeft();
|
|
|
|
|
split( iStep, "\n", asRows, true );
|
|
|
|
|
|
|
|
|
|
int iHoldStartRow[13];
|
|
|
|
|
for( int t=0; t<13; t++ )
|
|
|
|
|
iHoldStartRow[t] = -1;
|
|
|
|
|
|
2002-10-31 03:01:35 +00:00
|
|
|
for( unsigned r=0; r<asRows.size(); r++ )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
|
|
|
|
CString& sRowString = asRows[r];
|
|
|
|
|
|
|
|
|
|
if( sRowString == "" )
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
|
|
|
|
/* All 2s indicates the end of the song. */
|
|
|
|
|
if( sRowString == "2222222222222" )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
ASSERT( sRowString.GetLength() == 13 ); // why 13 notes per row. Beats me!
|
|
|
|
|
|
|
|
|
|
// the length of a note in a row depends on TICKCOUNT
|
|
|
|
|
float fBeatThisRow = r/(float)iTickCount;
|
|
|
|
|
int row = BeatToNoteRow(fBeatThisRow);
|
|
|
|
|
for( int t=0; t<13; t++ )
|
|
|
|
|
{
|
|
|
|
|
if( sRowString[t] == '4' )
|
|
|
|
|
{
|
|
|
|
|
/* Remember when each hold starts; ignore the middle. */
|
|
|
|
|
if( iHoldStartRow[t] == -1 )
|
|
|
|
|
iHoldStartRow[t] = r;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( iHoldStartRow[t] != -1 ) // this ends the hold
|
|
|
|
|
{
|
|
|
|
|
HoldNote hn = {
|
|
|
|
|
t, /* button */
|
|
|
|
|
iHoldStartRow[t]/(float)iTickCount, /* start */
|
|
|
|
|
(r-1)/(float)iTickCount /* end */
|
|
|
|
|
};
|
|
|
|
|
notedata.AddHoldNote( hn );
|
|
|
|
|
iHoldStartRow[t] = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-25 04:59:26 +00:00
|
|
|
/* XXXXX: don't do this, translate explicitly, so the TAP_* constants
|
|
|
|
|
* can be changed */
|
|
|
|
|
notedata.SetTapNote(t, row, sRowString[t]);
|
2002-09-06 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CString sDir, sFName, sExt;
|
|
|
|
|
splitrelpath( sPath, sDir, sFName, sExt );
|
|
|
|
|
sFName.MakeLower();
|
|
|
|
|
|
|
|
|
|
out.m_sDescription = sFName;
|
|
|
|
|
if( sFName.Find("crazy")!=-1 )
|
|
|
|
|
{
|
2002-09-29 05:06:18 +00:00
|
|
|
out.m_Difficulty = DIFFICULTY_HARD;
|
2002-09-06 23:24:40 +00:00
|
|
|
if(!out.m_iMeter) out.m_iMeter = 8;
|
|
|
|
|
}
|
|
|
|
|
else if( sFName.Find("hard")!=-1 )
|
|
|
|
|
{
|
2002-09-29 05:06:18 +00:00
|
|
|
out.m_Difficulty = DIFFICULTY_MEDIUM;
|
2002-09-06 23:24:40 +00:00
|
|
|
if(!out.m_iMeter) out.m_iMeter = 5;
|
|
|
|
|
}
|
|
|
|
|
else if( sFName.Find("easy")!=-1 )
|
|
|
|
|
{
|
2002-09-29 05:06:18 +00:00
|
|
|
out.m_Difficulty = DIFFICULTY_EASY;
|
2002-09-06 23:24:40 +00:00
|
|
|
if(!out.m_iMeter) out.m_iMeter = 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-09-29 05:06:18 +00:00
|
|
|
out.m_Difficulty = DIFFICULTY_MEDIUM;
|
2002-09-06 23:24:40 +00:00
|
|
|
if(!out.m_iMeter) out.m_iMeter = 5;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-09 23:15:43 +00:00
|
|
|
notedata.m_iNumTracks = 5;
|
|
|
|
|
out.m_NotesType = NOTES_TYPE_PUMP_SINGLE;
|
|
|
|
|
|
2002-09-06 23:24:40 +00:00
|
|
|
if( sFName.Find("double") != -1 )
|
|
|
|
|
{
|
|
|
|
|
notedata.m_iNumTracks = 10;
|
|
|
|
|
out.m_NotesType = NOTES_TYPE_PUMP_DOUBLE;
|
2002-09-09 23:15:43 +00:00
|
|
|
} else if( sFName.Find("_2") != -1 ) {
|
2002-09-12 07:50:20 +00:00
|
|
|
notedata.m_iNumTracks = 10;
|
|
|
|
|
out.m_NotesType = NOTES_TYPE_PUMP_COUPLE;
|
2002-09-06 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out.m_sSMNoteData = notedata.GetSMNoteDataString();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-11 05:15:46 +00:00
|
|
|
void KSFLoader::GetApplicableFiles( CString sPath, CStringArray &out )
|
|
|
|
|
{
|
|
|
|
|
GetDirListing( sPath + CString("*.ksf"), out );
|
|
|
|
|
}
|
2002-09-06 23:24:40 +00:00
|
|
|
|
2002-09-11 05:15:46 +00:00
|
|
|
bool KSFLoader::LoadFromDir( CString sDir, Song &out )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Trace( "Song::LoadFromKSFDir(%s)", sDir.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
CStringArray arrayKSFFileNames;
|
|
|
|
|
GetDirListing( sDir + CString("*.ksf"), arrayKSFFileNames );
|
|
|
|
|
|
2002-10-31 03:01:35 +00:00
|
|
|
if( arrayKSFFileNames.empty() )
|
2002-10-29 07:58:44 +00:00
|
|
|
throw RageException( "Couldn't find any KSF files in '%s'", sDir.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
// load the Notes from the rest of the KSF files
|
2002-10-31 03:01:35 +00:00
|
|
|
for( unsigned i=0; i<arrayKSFFileNames.size(); i++ )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
|
|
|
|
Notes* pNewNotes = new Notes;
|
|
|
|
|
LoadFromKSFFile( out.m_sSongDir + arrayKSFFileNames[i], *pNewNotes );
|
|
|
|
|
out.m_apNotes.Add( pNewNotes );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CString sPath = out.m_sSongDir + arrayKSFFileNames[0];
|
|
|
|
|
|
|
|
|
|
MsdFile msd;
|
|
|
|
|
bool bResult = msd.ReadFile( sPath );
|
|
|
|
|
if( !bResult )
|
2002-10-29 07:58:44 +00:00
|
|
|
throw RageException( "Error opening file '%s'.", sPath.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
|
2002-10-31 03:01:35 +00:00
|
|
|
// XXX msd::iNumValues should be unsigned
|
|
|
|
|
for( i=0; i<unsigned(msd.m_iNumValues); i++ )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
2002-09-15 07:03:32 +00:00
|
|
|
CString* sParams = msd.m_sParams[i];
|
2002-09-06 23:24:40 +00:00
|
|
|
CString sValueName = sParams[0];
|
|
|
|
|
|
|
|
|
|
// handle the data
|
|
|
|
|
if( 0==stricmp(sValueName,"TITLE") )
|
|
|
|
|
{
|
|
|
|
|
//title is usually in format "artist - songtitle"
|
|
|
|
|
CStringArray asBits;
|
|
|
|
|
split( sParams[1], " - ", asBits, false );
|
|
|
|
|
|
|
|
|
|
/* It's often "artist - songtitle - difficulty". Ignore
|
|
|
|
|
* the difficulty, since we get that from the filename. */
|
2002-10-31 03:01:35 +00:00
|
|
|
if( asBits.size() == 3 &&
|
2002-09-06 23:24:40 +00:00
|
|
|
(!stricmp(asBits[2], "double") ||
|
|
|
|
|
!stricmp(asBits[2], "easy") ||
|
|
|
|
|
!stricmp(asBits[2], "normal") ||
|
|
|
|
|
!stricmp(asBits[2], "hard") ||
|
|
|
|
|
!stricmp(asBits[2], "crazy")) )
|
|
|
|
|
{
|
|
|
|
|
asBits.RemoveAt(2);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-31 03:01:35 +00:00
|
|
|
if( asBits.size() == 2 )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
|
|
|
|
out.m_sArtist = asBits[0];
|
|
|
|
|
out.m_sMainTitle = asBits[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out.m_sMainTitle = asBits[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( int j=0; j<out.m_sMainTitle.GetLength(); j++ )
|
|
|
|
|
{
|
|
|
|
|
char c = out.m_sMainTitle[j];
|
|
|
|
|
if( c < 0 ) // this title has a foreign char
|
|
|
|
|
{
|
|
|
|
|
CStringArray asBits;
|
|
|
|
|
split( sDir, "\\", asBits, true);
|
2002-10-31 03:01:35 +00:00
|
|
|
CString sSongFolderName = asBits[ asBits.size()-1 ];
|
2002-10-24 20:15:24 +00:00
|
|
|
asBits.clear();
|
2002-09-06 23:24:40 +00:00
|
|
|
|
|
|
|
|
split( sSongFolderName, " - ", asBits, false );
|
2002-10-31 03:01:35 +00:00
|
|
|
if( asBits.size() == 2 )
|
2002-09-06 23:24:40 +00:00
|
|
|
{
|
|
|
|
|
out.m_sArtist = asBits[0];
|
|
|
|
|
out.m_sMainTitle = asBits[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out.m_sMainTitle = asBits[0];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if( 0==stricmp(sValueName,"BPM") )
|
|
|
|
|
out.AddBPMSegment( BPMSegment(0, (float)atof(sParams[1])) );
|
|
|
|
|
|
|
|
|
|
else if( 0==stricmp(sValueName,"STARTTIME") )
|
|
|
|
|
out.m_fBeat0OffsetInSeconds = -(float)atof(sParams[1])/100;
|
|
|
|
|
else if( 0==stricmp(sValueName,"TICKCOUNT") ||
|
|
|
|
|
0==stricmp(sValueName,"STEP") ||
|
|
|
|
|
0==stricmp(sValueName,"DIFFICULTY"))
|
2002-09-12 07:50:20 +00:00
|
|
|
; /* Handled in LoadFromKSFFile; don't warn. */
|
2002-09-06 23:24:40 +00:00
|
|
|
else
|
2002-10-29 07:58:44 +00:00
|
|
|
LOG->Trace( "Unexpected value named '%s'", sValueName.GetString() );
|
2002-09-06 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// search for music with song in the file name
|
|
|
|
|
CStringArray arrayPossibleMusic;
|
|
|
|
|
GetDirListing( out.m_sSongDir + CString("song.mp3"), arrayPossibleMusic );
|
|
|
|
|
GetDirListing( out.m_sSongDir + CString("song.ogg"), arrayPossibleMusic );
|
|
|
|
|
GetDirListing( out.m_sSongDir + CString("song.wav"), arrayPossibleMusic );
|
|
|
|
|
|
2002-10-31 03:01:35 +00:00
|
|
|
if( !arrayPossibleMusic.empty() ) // we found a match
|
2002-09-06 23:24:40 +00:00
|
|
|
out.m_sMusicFile = arrayPossibleMusic[0];
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|