|
From: Lasse Kärkkäi. <tr...@us...> - 2010-01-13 00:49:33
|
Module: performous
Branch: master
Commit: 4d06600a670fb77b8746938c71d6a928ccc85481
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Jan 13 02:49:21 2010 +0200
Add beats processing to songparser.hh, fixing an issue created by my songparser fix.
---
game/dancegraph.cc | 4 ++--
game/songparser-sm.cc | 5 ++---
game/songparser.hh | 10 +++++++++-
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index 20afdcb..172a539 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -392,11 +392,11 @@ void DanceGraph::drawBeats(double time) {
for (Song::Beats::const_iterator it = m_song.beats.begin(); it != m_song.beats.end() && tBeg < future; ++it, texCoord += texCoordStep, tBeg = tEnd) {
tEnd = *it - time;
//if (tEnd < past) continue;
- if (tEnd > future) {
+ /*if (tEnd > future) {
// Crop the end off
texCoord -= texCoordStep * (tEnd - future) / (tEnd - tBeg);
tEnd = future;
- }
+ }*/
glutil::Color c(1.0f, 1.0f, 1.0f, time2a(tEnd));
glNormal3f(0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, texCoord); glVertex2f(-w, time2y(tEnd));
glNormal3f(0.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, texCoord); glVertex2f(w, time2y(tEnd));
diff --git a/game/songparser-sm.cc b/game/songparser-sm.cc
index 5ad8433..c1281ba 100644
--- a/game/songparser-sm.cc
+++ b/game/songparser-sm.cc
@@ -68,6 +68,7 @@ void SongParser::smParse() {
// Convert stops to the format required in Song
s.stops.resize(m_stops.size());
for (std::size_t i = 0; i < m_stops.size(); ++i) s.stops[i] = stopConvert(m_stops[i]);
+ m_tsPerBeat = 4;
}
bool SongParser::smParseField(std::string line) {
@@ -256,8 +257,6 @@ Notes SongParser::smParseNotes(std::string line) {
}
chords.push_back(chord);
}
- //The code reaches here only when all data is read from the file.
- // Add song beat markers
- for (uint32_t ts = 0, end = 16 * measure; ts < end; ts += 4) m_song.beats.push_back(tsTime(ts));
+ m_tsEnd = std::max(m_tsEnd, measure * 16);
return notes;
}
diff --git a/game/songparser.hh b/game/songparser.hh
index 5a195ad..8165d94 100644
--- a/game/songparser.hh
+++ b/game/songparser.hh
@@ -20,7 +20,9 @@ class SongParser {
m_prevtime(),
m_prevts(),
m_relativeShift(),
- m_maxScore()
+ m_maxScore(),
+ m_tsPerBeat(),
+ m_tsEnd()
{
enum { NONE, TXT, INI, SM } type = NONE;
// Read the file, determine the type and do some initial validation checks
@@ -81,6 +83,10 @@ class SongParser {
// Set begin/end times
if (!s.notes.empty()) s.beginTime = s.notes.front().begin, s.endTime = s.notes.back().end;
m_song.m_scoreFactor = 1.0 / m_maxScore;
+ if (m_tsPerBeat) {
+ // Add song beat markers
+ for (unsigned ts = 0; ts < m_tsEnd; ts += m_tsPerBeat) m_song.beats.push_back(tsTime(ts));
+ }
}
private:
Song& m_song;
@@ -113,6 +119,8 @@ class SongParser {
};
typedef std::vector<BPM> bpms_t;
bpms_t m_bpms;
+ unsigned m_tsPerBeat; ///< The ts increment per beat
+ unsigned m_tsEnd; ///< The ending ts of the song
void addBPM(double ts, double bpm) {
if (!(bpm >= 1.0 && bpm < 1e12)) throw std::runtime_error("Invalid BPM value");
if (!m_bpms.empty() && m_bpms.back().ts >= ts) {
|