|
From: knittl <kn...@us...> - 2009-08-03 08:39:45
|
Module: performous
Branch: master
Commit: b01db5d540f8ebe69e6680cf53143efdfedb8401
Author: Lasse Karkkainen <tro...@tr...>
Date: Fri Jul 31 23:23:40 2009 +0300
Making chords.
---
game/guitargraph.cc | 41 +++++++++++++++++++++++++++++++++++++++++
game/guitargraph.hh | 8 ++++++--
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 098030d..9d847b3 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -332,3 +332,44 @@ void GuitarGraph::drawBar(double time, float h) {
glVertex2f(2.5f, time2y(time - h));
}
+void GuitarGraph::updateChords() {
+ m_chords.clear();
+ Durations::size_type pos[5] = {}, size[5] = {};
+ Durations const* durations[5] = {};
+ for (int fret = 0; fret < 5; ++fret) {
+ NoteMap const& nm = m_song.tracks[m_instrument].nm;
+ int basepitch = diffv[m_level].basepitch;
+ NoteMap::const_iterator it = nm.find(basepitch + fret);
+ if (it == nm.end()) continue;
+ durations[fret] = &it->second;
+ }
+ while (true) {
+ // Find the earliest
+ double t = getInf();
+ for (int fret = 0; fret < 5; ++fret) {
+ if (pos[fret] == size[fret]) continue;
+ Durations const& dur = *durations[fret];
+ t = std::min(t, dur[pos[fret]].begin);
+ }
+ // Quit processing if none were left
+ if (t == getInf()) break;
+ // Construct a chord
+ Chord c;
+ c.begin = t;
+ for (int fret = 0; fret < 5; ++fret) {
+ if (pos[fret] == size[fret]) continue;
+ Durations const& dur = *durations[fret];
+ Duration const& d = dur[pos[fret]++];
+ if (d.begin > t) continue;
+ c.fret[fret] = true;
+ c.dur[fret] = &d;
+ ++c.polyphony;
+ }
+ if (c.polyphony == 1) {
+ c.tappable = true;
+ if (m_chords.empty() || m_chords.back() == c) c.tappable = false;
+ }
+ m_chords.push_back(c);
+ }
+}
+
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index eb79a25..a7ce016 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -13,10 +13,14 @@ struct Chord {
double begin;
bool fret[5];
Duration const* dur[5];
- bool chord;
+ int polyphony;
bool tappable;
bool tapped;
int tapScore;
+ Chord(): begin(), polyphony(), tappable(), tapped(), tapScore() {
+ std::fill(fret, fret + 5, false);
+ std::fill(dur, dur + 5, static_cast<Duration const*>(NULL));
+ }
};
static inline bool operator==(Chord const& a, Chord const& b) {
@@ -53,7 +57,7 @@ class GuitarGraph {
void difficultyAuto();
bool difficulty(Difficulty level);
SvgTxtTheme m_text;
- void updateChords() {}
+ void updateChords();
std::vector<Chord> m_chords;
typedef std::map<Duration const*, int> NoteStatus;
NoteStatus m_notes;
|