LRC reading is so simple now that the LRCFile abstraction only
makes it much more complicated; merge it with LyricsLoader.
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
#include "RageLog.h"
|
||||
#include "RageException.h"
|
||||
#include "RageUtil.h"
|
||||
#include "LRCFile.h"
|
||||
#include "LyricsLoader.h"
|
||||
#include "Regex.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
@@ -17,28 +18,32 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
||||
{
|
||||
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.GetString() );
|
||||
|
||||
|
||||
LRCFile lrc;
|
||||
bool bResult = lrc.ReadFile( sPath );
|
||||
RageColor m_LastFoundColor(0,1,0,1);
|
||||
|
||||
if( !bResult )
|
||||
RageException::Throw( "Error opening file '%s' for reading.", sPath.GetString() );
|
||||
|
||||
// unsigned iLineCount = 0; // hush "variable not referenced"
|
||||
for( unsigned i=0; i<lrc.GetNumValues(); i++ )
|
||||
ifstream input(sPath);
|
||||
if(input.bad())
|
||||
{
|
||||
int iNumParams = lrc.GetNumParams(i);
|
||||
const LRCFile::value_t &sParams = lrc.GetValue(i);
|
||||
|
||||
CString sValueName = sParams[0];
|
||||
CString sValueData = sParams[1];
|
||||
LOG->Warn( "Error opening file '%s' for reading.", sPath.GetString() );
|
||||
return false;
|
||||
}
|
||||
|
||||
if(iNumParams < 1)
|
||||
{
|
||||
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.GetString());
|
||||
string line;
|
||||
|
||||
RageColor CurrentColor(0,1,0,1);
|
||||
|
||||
while(input.good() && getline(input, line))
|
||||
{
|
||||
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))
|
||||
continue;
|
||||
|
||||
CString &sValueName = matches[0];
|
||||
CString &sValueData = matches[1];
|
||||
StripCrnl(sValueData);
|
||||
|
||||
// handle the data
|
||||
if( 0==stricmp(sValueName,"COLOUR") || 0==stricmp(sValueName,"COLOR") )
|
||||
@@ -53,17 +58,16 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
||||
continue;
|
||||
}
|
||||
|
||||
m_LastFoundColor = RageColor(r / 256.0f, g / 256.0f, b / 256.0f, 1);
|
||||
CurrentColor = RageColor(r / 256.0f, g / 256.0f, b / 256.0f, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* If we've gotten this far, and no other statement caught
|
||||
this value before this does, assume it's a time value. */
|
||||
* this value before this does, assume it's a time value. */
|
||||
|
||||
LyricSegment seg;
|
||||
seg.m_Color = m_LastFoundColor;
|
||||
seg.m_Color = CurrentColor;
|
||||
seg.m_fStartTime = TimeToSeconds(sValueName);
|
||||
seg.m_sLyric = sValueData;
|
||||
|
||||
@@ -82,23 +86,10 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
||||
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 );
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
||||
Kevin Slaughter
|
||||
Glenn Maynard
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
#ifndef LYRICS_LOADER_H
|
||||
#define LYRICS_LOADER_H
|
||||
/*
|
||||
Declares for lyrics loader
|
||||
By: Kevin Slaughter
|
||||
*/
|
||||
* Loads lyrics from an LRC file.
|
||||
*/
|
||||
|
||||
#include "song.h"
|
||||
//#include "GameInput.h"
|
||||
|
||||
class LyricsLoader {
|
||||
//bool LoadFromLRCFile( CString sPath, Song &out );
|
||||
public:
|
||||
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||
bool Loadable( CString sPath );
|
||||
bool LoadFromDir( CString sPath, Song &out );
|
||||
bool LoadFromLRCFile( CString sPath, Song &out );
|
||||
private:
|
||||
LyricSegment LySeg;
|
||||
float fSecs;
|
||||
};
|
||||
|
||||
#endif
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
||||
Kevin Slaughter
|
||||
Glenn Maynard
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user