|
From: Tapio V. <aa...@us...> - 2011-03-02 10:02:45
|
Author: Tapio Vierros <tap...@gm...>
Date: Wed Mar 2 12:01:50 2011 +0200
Allow opening .mid file directly instead of .ini
---
songparser-ini.cc | 5 +++++
songparser.cc | 4 +++-
songparser.hh | 2 ++
3 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/songparser-ini.cc b/songparser-ini.cc
index 371241a..46ed24e 100644
--- a/songparser-ini.cc
+++ b/songparser-ini.cc
@@ -14,6 +14,11 @@ bool SongParser::iniCheck(QString const& data) {
return data.startsWith("[song]");
}
+/// 'Magick' to check if this file looks like correct format
+bool SongParser::midiCheck(QString const& data) {
+ return data.startsWith("MThd");
+}
+
/// Parser
void SongParser::iniParse() {
// Some defaults
diff --git a/songparser.cc b/songparser.cc
index a01e013..a5f1029 100644
--- a/songparser.cc
+++ b/songparser.cc
@@ -28,7 +28,7 @@ SongParser::SongParser(Song& s):
m_tsPerBeat(),
m_tsEnd()
{
- enum { NONE, TXT, XML, INI, SM } type = NONE;
+ enum { NONE, TXT, XML, INI, MIDI, SM } type = NONE;
// Read the file, determine the type and do some initial validation checks
QFile file(m_song.path + m_song.filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
@@ -45,6 +45,7 @@ SongParser::SongParser(Song& s):
else if (txtCheck(data)) type = TXT;
else if (xmlCheck(data)) type = XML;
else if (iniCheck(data)) type = INI;
+ else if (midiCheck(data)) type = MIDI;
else throw SongParserException("Does not look like a song file (wrong header)", 1, true);
m_stream.setString(&data);
@@ -54,6 +55,7 @@ SongParser::SongParser(Song& s):
if (type == TXT) txtParse();
else if (type == XML) xmlParse();
else if (type == INI) iniParse();
+ else if (type == MIDI) midParse();
else if (type == SM) smParse();
} catch (std::runtime_error& e) {
throw SongParserException(e.what(), m_linenum);
diff --git a/songparser.hh b/songparser.hh
index 2aa7cc0..b3a3502 100644
--- a/songparser.hh
+++ b/songparser.hh
@@ -38,7 +38,9 @@ class SongParser {
static bool xmlCheck(QString const& data);
void xmlParse();
+ // Frets on Fire MIDI
static bool iniCheck(QString const& data);
+ static bool midiCheck(QString const& data);
void iniParse();
void iniParseField(QString const& line);
void midParse();
|