Files
itgmania212121/stepmania/src/LyricsLoader.cpp
T

109 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 "LyricsLoader.h"
#include "ThemeManager.h"
2003-07-22 07:47:27 +00:00
#include "RageFile.h"
2003-03-08 08:53:08 +00:00
#include <map>
using namespace std;
#define LYRICS_DEFAULT_COLOR THEME->GetMetricC("ScreenGameplay","LyricsDefaultColor")
2003-03-25 01:14:53 +00:00
static int CompareLyricSegments(const LyricSegment &seg1, const LyricSegment &seg2)
{
return seg1.m_fStartTime < seg2.m_fStartTime;
}
2003-03-08 08:53:08 +00:00
bool LyricsLoader::LoadFromLRCFile(const CString& sPath, Song& out)
2003-03-08 08:53:08 +00:00
{
2003-04-25 00:27:30 +00:00
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.c_str() );
2003-03-08 08:53:08 +00:00
2003-12-03 23:11:48 +00:00
RageFile input( sPath );
if (!input.IsOpen())
{
LOG->Warn("Error opening file '%s' for reading.", sPath.c_str());
return false;
}
RageColor CurrentColor = LYRICS_DEFAULT_COLOR;
2003-03-25 01:14:53 +00:00
out.m_LyricSegments.clear();
2003-12-11 21:09:30 +00:00
while( 1 )
2003-03-08 08:53:08 +00:00
{
2003-12-11 21:09:30 +00:00
CString line;
int ret = input.GetLine( line );
if( ret == 0 )
break;
if( ret == -1 )
{
LOG->Warn("Error reading %s: %s", input.GetPath().c_str(), input.GetError().c_str() );
break;
}
if(!line.compare(0, 2, "//"))
continue;
/* "[data1] data2". Ignore whitespace at the beginning of the line. */
static Regex x("^ *\\[([^]]+)\\] *(.*)$");
vector<CString> matches;
if(!x.Compare(line, matches))
2003-03-08 08:53:08 +00:00
continue;
2003-07-10 00:35:46 +00:00
ASSERT( matches.size() == 2 );
CString &sValueName = matches[0];
CString &sValueData = matches[1];
StripCrnl(sValueData);
2003-03-08 08:53:08 +00:00
// 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-04-25 00:27:30 +00:00
int result = sscanf( sValueData.c_str(), "0x%2x%2x%2x", &r, &g, &b );
2003-03-19 21:30:12 +00:00
if(result != 3)
{
LOG->Trace( "The color value '%s' in '%s' is invalid.",
sValueData.c_str(), sPath.c_str() );
2003-03-19 21:30:12 +00:00
continue;
}
CurrentColor = RageColor(r / 256.0f, g / 256.0f, b / 256.0f, 1);
2003-03-08 08:53:08 +00:00
continue;
}
2003-03-08 08:53:08 +00:00
{
/* 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 = CurrentColor;
2004-02-22 19:51:46 +00:00
seg.m_fStartTime = HHMMSSToSeconds(sValueName);
2003-03-19 21:30:12 +00:00
seg.m_sLyric = sValueData;
2003-03-08 08:53:08 +00:00
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
}
}
2003-03-25 01:14:53 +00:00
sort( out.m_LyricSegments.begin(), out.m_LyricSegments.end(), CompareLyricSegments );
2003-07-10 01:56:52 +00:00
LOG->Trace( "LyricsLoader::LoadFromLRCFile done" );
2003-03-08 08:53:08 +00:00
return true;
}
/*
-----------------------------------------------------------------------------
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
Kevin Slaughter
Glenn Maynard
-----------------------------------------------------------------------------
*/