|
From: Lasse Kärkkäi. <tr...@us...> - 2009-12-23 11:13:07
|
Module: performous
Branch: master
Commit: 50f7d8fe38eb16975236550a65998c117b368ee4
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Dec 23 13:12:54 2009 +0200
Fix non-integer and duplicate TS BPM handling. This allows more songs to load and fixes sync issues with a lot of songs.
---
game/songparser.hh | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/game/songparser.hh b/game/songparser.hh
index 02372bc..1e05a05 100644
--- a/game/songparser.hh
+++ b/game/songparser.hh
@@ -107,19 +107,22 @@ class SongParser {
double m_maxScore;
std::vector<std::pair<double,double> > m_stops;
struct BPM {
- BPM(double _begin, unsigned int _ts, double bpm): begin(_begin), step(0.25 * 60.0 / bpm), ts(_ts) {}
+ BPM(double _begin, double _ts, double bpm): begin(_begin), step(0.25 * 60.0 / bpm), ts(_ts) {}
double begin; // Time in seconds
double step; // Seconds per quarter note
- unsigned int ts;
+ double ts;
};
typedef std::vector<BPM> bpms_t;
bpms_t m_bpms;
- void addBPM(unsigned int ts, double bpm) {
- if (!m_bpms.empty() && m_bpms.back().ts >= ts) throw std::runtime_error("Invalid BPM timestamp");
+ 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) {
+ if (m_bpms.back().ts < ts) throw std::runtime_error("Invalid BPM timestamp");
+ m_bpms.pop_back(); // Some ITG songs contain repeated BPM definitions...
+ }
m_bpms.push_back(BPM(tsTime(ts), ts, bpm));
}
- double tsTime(unsigned int ts) const {
+ double tsTime(double ts) const {
if (m_bpms.empty()) {
if (ts != 0) throw std::runtime_error("BPM data missing");
return m_gap;
|