|
From: rainbyte <rai...@us...> - 2012-07-17 10:45:18
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 17 23:33:42 2012 +0200
Support for UltraStar TXT multiplayer duet note parsing.
Needs more testing.
---
game/songparser-txt.cc | 15 ++++++++++++---
game/songparser.cc | 9 +++++++++
game/songparser.hh | 1 +
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/game/songparser-txt.cc b/game/songparser-txt.cc
index 06221b3..6744eaf 100644
--- a/game/songparser-txt.cc
+++ b/game/songparser-txt.cc
@@ -30,12 +30,12 @@ void SongParser::txtParse() {
std::string line;
VocalTrack vocal(TrackName::LEAD_VOCAL);
while (getline(line) && txtParseField(line)) {} // Parse the header again
- if (m_bpm != 0.0) addBPM(0, m_bpm);
+ resetNoteParsingState();
while (txtParseNote(line, vocal) && getline(line)) {} // Parse notes
// Workaround for the terminating : 1 0 0 line, written by some converters
if (!vocal.notes.empty() && vocal.notes.back().type != Note::SLEEP
&& vocal.notes.back().begin == vocal.notes.back().end) vocal.notes.pop_back();
- m_song.insertVocalTrack(TrackName::LEAD_VOCAL, vocal);
+ m_song.insertVocalTrack(vocal.name, vocal);
}
bool SongParser::txtParseField(std::string const& line) {
@@ -80,7 +80,16 @@ bool SongParser::txtParseNote(std::string line, VocalTrack &vocal) {
addBPM(ts, bpm);
return true;
}
- if (line[0] == 'P') return true; //We ignore player information for now (multiplayer hack)
+ if (line[0] == 'P') {
+ if (line.size() < 2) throw std::runtime_error("Invalid player info line");
+ if (line[1] == '1') return true;
+ else if (line[1] == '2') {
+ m_song.insertVocalTrack(vocal.name, vocal);
+ vocal = VocalTrack(TrackName::HARMONIC_1);
+ resetNoteParsingState();
+ }
+ return true;
+ }
Note n;
n.type = Note::Type(iss.get());
unsigned int ts = m_prevts;
diff --git a/game/songparser.cc b/game/songparser.cc
index ac9f3f6..f3a2862 100644
--- a/game/songparser.cc
+++ b/game/songparser.cc
@@ -117,6 +117,15 @@ SongParser::SongParser(Song& s):
s.loadStatus = Song::HEADER;
}
+void SongParser::resetNoteParsingState() {
+ m_prevtime = 0;
+ m_prevts = 0;
+ m_relativeShift = 0;
+ m_tsPerBeat = 0;
+ m_tsEnd = 0;
+ m_bpms.clear();
+ if (m_bpm != 0.0) addBPM(0, m_bpm);
+}
void SongParser::finalize() {
std::vector<std::string> tracks = m_song.getVocalTrackNames();
diff --git a/game/songparser.hh b/game/songparser.hh
index 7355a33..0347559 100644
--- a/game/songparser.hh
+++ b/game/songparser.hh
@@ -48,6 +48,7 @@ class SongParser {
void smParse();
bool smParseField(std::string line);
Notes smParseNotes(std::string line);
+ void resetNoteParsingState();
double m_prevtime;
unsigned int m_prevts;
unsigned int m_relativeShift;
|