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 "RageLog.h"
|
||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "LRCFile.h"
|
|
||||||
#include "LyricsLoader.h"
|
#include "LyricsLoader.h"
|
||||||
|
#include "Regex.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -17,28 +18,32 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
|||||||
{
|
{
|
||||||
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.GetString() );
|
LOG->Trace( "LyricsLoader::LoadFromLRCFile(%s)", sPath.GetString() );
|
||||||
|
|
||||||
|
ifstream input(sPath);
|
||||||
LRCFile lrc;
|
if(input.bad())
|
||||||
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++ )
|
|
||||||
{
|
{
|
||||||
int iNumParams = lrc.GetNumParams(i);
|
LOG->Warn( "Error opening file '%s' for reading.", sPath.GetString() );
|
||||||
const LRCFile::value_t &sParams = lrc.GetValue(i);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CString sValueName = sParams[0];
|
string line;
|
||||||
CString sValueData = sParams[1];
|
|
||||||
|
|
||||||
if(iNumParams < 1)
|
RageColor CurrentColor(0,1,0,1);
|
||||||
{
|
|
||||||
LOG->Warn("Got \"%s\" tag with no parameters", sValueName.GetString());
|
while(input.good() && getline(input, line))
|
||||||
|
{
|
||||||
|
if(!line.compare(0, 2, "//"))
|
||||||
continue;
|
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
|
// handle the data
|
||||||
if( 0==stricmp(sValueName,"COLOUR") || 0==stricmp(sValueName,"COLOR") )
|
if( 0==stricmp(sValueName,"COLOUR") || 0==stricmp(sValueName,"COLOR") )
|
||||||
@@ -53,17 +58,16 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
|||||||
continue;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
/* If we've gotten this far, and no other statement caught
|
/* 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;
|
LyricSegment seg;
|
||||||
seg.m_Color = m_LastFoundColor;
|
seg.m_Color = CurrentColor;
|
||||||
seg.m_fStartTime = TimeToSeconds(sValueName);
|
seg.m_fStartTime = TimeToSeconds(sValueName);
|
||||||
seg.m_sLyric = sValueData;
|
seg.m_sLyric = sValueData;
|
||||||
|
|
||||||
@@ -82,23 +86,10 @@ bool LyricsLoader::LoadFromLRCFile( CString sPath, Song &out )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LyricsLoader::GetApplicableFiles( CString sPath, CStringArray &out )
|
/*
|
||||||
{
|
-----------------------------------------------------------------------------
|
||||||
GetDirListing( sPath + CString("*.dwi"), out );
|
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
||||||
}
|
Kevin Slaughter
|
||||||
|
Glenn Maynard
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
#ifndef LYRICS_LOADER_H
|
#ifndef LYRICS_LOADER_H
|
||||||
#define LYRICS_LOADER_H
|
#define LYRICS_LOADER_H
|
||||||
/*
|
/*
|
||||||
Declares for lyrics loader
|
* Loads lyrics from an LRC file.
|
||||||
By: Kevin Slaughter
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
//#include "GameInput.h"
|
|
||||||
|
|
||||||
class LyricsLoader {
|
class LyricsLoader {
|
||||||
//bool LoadFromLRCFile( CString sPath, Song &out );
|
|
||||||
public:
|
public:
|
||||||
void GetApplicableFiles( CString sPath, CStringArray &out );
|
|
||||||
bool Loadable( CString sPath );
|
|
||||||
bool LoadFromDir( CString sPath, Song &out );
|
|
||||||
bool LoadFromLRCFile( CString sPath, Song &out );
|
bool LoadFromLRCFile( CString sPath, Song &out );
|
||||||
private:
|
|
||||||
LyricSegment LySeg;
|
|
||||||
float fSecs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/*
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
||||||
|
Kevin Slaughter
|
||||||
|
Glenn Maynard
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user