Files
itgmania212121/stepmania/src/LyricsLoader.cpp
T

105 lines
2.7 KiB
C++
Raw Normal View History

2003-03-08 08:53:08 +00:00
#include "global.h"
/*
Loader for lyrics files
By: Kevin Slaughter
*/
#include "RageLog.h"
#include "RageException.h"
#include "RageUtil.h"
#include "LRCFile.h"
#include "LyricsLoader.h"
#include <map>
using namespace std;
bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
{
2003-03-19 21:30:12 +00:00
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.GetString() );
2003-03-08 08:53:08 +00:00
LRCFile lrc;
bool bResult = lrc.ReadFile( sPath );
2003-03-19 21:30:12 +00:00
RageColor m_LastFoundColor(0,1,0,1);
2003-03-08 08:53:08 +00:00
if( !bResult )
RageException::Throw( "Error opening file '%s' for reading.", sPath.GetString() );
2003-03-09 01:31:15 +00:00
// unsigned iLineCount = 0; // hush "variable not referenced"
2003-03-08 08:53:08 +00:00
for( unsigned i=0; i<lrc.GetNumValues(); i++ )
{
int iNumParams = lrc.GetNumParams(i);
const LRCFile::value_t &sParams = lrc.GetValue(i);
CString sValueName = sParams[0];
CString sValueData = sParams[1];
if(iNumParams < 1)
{
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.GetString());
continue;
}
// handle the data
if( 0==stricmp(sValueName,"COLOUR") || 0==stricmp(sValueName,"COLOR") )
2003-03-08 08:53:08 +00:00
{
// set color var here for this segment
2003-03-19 21:41:53 +00:00
int r, g, b;
2003-03-19 21:30:12 +00:00
int result = sscanf( sValueData.GetString(), "0x%2x%2x%2x", &r, &g, &b );
if(result != 3)
{
LOG->Trace( "The color value '%s' in '%s' is invalid.",
2003-03-19 21:41:53 +00:00
sValueData.GetString(), sPath.GetString() );
2003-03-19 21:30:12 +00:00
continue;
}
2003-03-19 21:41:53 +00:00
m_LastFoundColor = RageColor(r / 256.0f, g / 256.0f, b / 256.0f, 1);
2003-03-08 08:53:08 +00:00
continue;
}
else
{
/* If we've gotten this far, and no other statement caught
this value before this does, assume it's a time value. */
2003-03-08 08:53:08 +00:00
2003-03-19 21:30:12 +00:00
LyricSegment seg;
seg.m_Color = m_LastFoundColor;
seg.m_fStartTime = TimeToSeconds(sValueName);
seg.m_sLyric = sValueData;
2003-03-08 08:53:08 +00:00
2003-03-19 21:30:12 +00:00
/* Er, huh? This won't do anything (replace \ with \). What's wrong
* with using \ in lyrics? */
seg.m_sLyric.Replace( "\\", "\\" ); // to avoid possible screw-ups
// if someone uses a \ for whatever
// reason in their lyrics -- Miryokuteki
2003-03-19 21:30:12 +00:00
seg.m_sLyric.Replace( "|","\n" ); // Pipe symbols denote a new line in LRC files
out.AddLyricSegment( seg );
2003-03-08 08:53:08 +00:00
}
}
return true;
}
void LyricsLoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.dwi"), out );
}
bool LyricsLoader::LoadFromDir( CString sPath, Song &out )
{
CStringArray aFileNames;
GetApplicableFiles( sPath, aFileNames );
if( aFileNames.size() > 1 )
RageException::Throw( "There is more than one DWI file in '%s'. There should be only one!", sPath.GetString() );
/* We should have exactly one; if we had none, we shouldn't have been
* called to begin with. */
ASSERT( aFileNames.size() == 1 );
return LoadFromLRCFile( sPath + aFileNames[0], out );
}