|
From: Lasse Kärkkäi. <tr...@us...> - 2009-07-19 21:32:00
|
Module: performous
Branch: master
Commit: e4d69bf121ef6604477c332210413df277797222
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Jul 20 00:29:37 2009 +0300
Find guitar track from some older format MIDI files too.
Guitar graph improvements and cleanup.
---
game/guitargraph.cc | 61 ++++++++++++++++++++++++++++++-----------------
game/songparser-ini.cc | 3 +-
2 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 79872fc..d7a27e7 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -1,31 +1,47 @@
#include "guitargraph.hh"
+namespace {
+ const float past = -0.3f;
+ const float future = 3.0f;
+ const float timescale = 30.0f;
+ // Note: t is difference from playback time so it must be in range [past, future]
+ float time2y(float t) { return -timescale * (t - past) / (future - past); }
+ float time2a(float t) { return 1.0f - t / future; } // Note: we want 1.0 alpha already at zero t.
+}
+
GuitarGraph::GuitarGraph(Song const& song): m_song(song), m_neck("guitarneck.svg") {}
void GuitarGraph::draw(double time) {
if (m_song.tracks.empty()) return; // Can't render without tracks (FIXME: actually screen_song should choose a track for us)
+ Dimensions dimensions(1.0); // FIXME: bogus aspect ratio (is this fixable?)
+ dimensions.screenBottom().fixedWidth(0.5f);
glutil::PushMatrix pmb;
- glTranslatef(0.0f, 0.3f, 0.0f);
+ glTranslatef(0.0f, dimensions.y2(), 0.0f);
glRotatef(80.0f, 1.0f, 0.0f, 0.0f);
- glScalef(0.1f, 0.1f, 0.1f);
- float ts = 12.0f;
- float future = 3.0f;
+ { float s = dimensions.w() / 5.0f; glScalef(s, s, s); }
{
UseTexture tex(m_neck);
glutil::Begin block(GL_QUADS);
- glTexCoord2f(0.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(-2.5f, -future * ts);
- glTexCoord2f(1.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(2.5f, -future * ts);
- glTexCoord2f(1.0f, -(time + 0.0f)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(2.5f, 0.0f * ts);
- glTexCoord2f(0.0f, -(time + 0.0f)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(-2.5f, 0.0f * ts);
- glColor3f(1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(-2.5f, time2y(future));
+ glTexCoord2f(1.0f, -(time + future)); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glVertex2f(2.5f, time2y(future));
+ glTexCoord2f(1.0f, -(time + past)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(2.5f, time2y(past));
+ glTexCoord2f(0.0f, -(time + past)); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertex2f(-2.5f, time2y(past));
}
+ {
+ glutil::Begin block(GL_QUADS);
+ glColor3f(1.0f, 1.0f, 1.0f);
+ glVertex2f(-2.5f, time2y(0.01f));
+ glVertex2f(2.5f, time2y(0.01f));
+ glVertex2f(2.5f, time2y(-0.01f));
+ glVertex2f(-2.5f, time2y(-0.01f));
+ }
enum Difficulty {
DIFFICULTY_SUPAEASY,
DIFFICULTY_EASY,
DIFFICULTY_MEDIUM,
DIFFICULTY_AMAZING,
DIFFICULTYCOUNT
- } level = DIFFICULTY_MEDIUM;
+ } level = DIFFICULTY_AMAZING;
int basepitch;
switch (level) {
@@ -45,23 +61,24 @@ void GuitarGraph::draw(double time) {
};
NoteMap const& nm = m_song.tracks.begin()->second;
for (int fret = 0; fret < 5; ++fret) {
+ float x = -2.0f + fret;
+ float w = 0.5f;
+ glutil::Color c = fretColors[fret];
NoteMap::const_iterator it = nm.find(basepitch + fret);
if (it == nm.end()) continue;
Durations const& durs = it->second;
+ glutil::Begin block(GL_QUADS);
for (Durations::const_iterator it2 = durs.begin(); it2 != durs.end(); ++it2) {
- glutil::Begin block(GL_QUADS);
- float tBeg = -(time - it2->begin);
- float tEnd = -(time - it2->end);
+ float tBeg = it2->begin - time;
+ float tEnd = it2->end - time;
if (tBeg > future) break;
- float x = -2.0f + fret;
- float w = 0.25f;
- glutil::Color c = fretColors[fret];
- c.a = 1.0f - tEnd / future; glColor4fv(c);
- glVertex2f(x - w, -tEnd * ts);
- glVertex2f(x + w, -tEnd * ts);
- c.a = 1.0f - tBeg / future; glColor4fv(c);
- glVertex2f(x + w, -tBeg * ts);
- glVertex2f(x - w, -tBeg * ts);
+ c.a = time2a(tBeg); glColor4fv(c);
+ glVertex2f(x - 0.5f * w, time2y(tEnd));
+ glVertex2f(x + 0.5f * w, time2y(tEnd));
+ c.a = time2a(tBeg); glColor4fv(c);
+ glVertex2f(x + w, time2y(tBeg));
+ glVertex2f(x - w, time2y(tBeg));
}
}
+ glColor3f(1.0f, 1.0f, 1.0f);
}
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index 15bcad5..c309689 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -45,7 +45,8 @@ void SongParser::iniParse() {
for (MidiFileParser::Tracks::const_iterator it = midi.tracks.begin(); it != midi.tracks.end(); ++it) {
// Figure out the track name
std::string name = it->name;
- if (midi.tracks.size() == 1) name = "GUITAR";
+ if (midi.tracks.size() == 1) name = "GUITAR"; // Original (old) FoF songs only have one track
+ else if (name == "T1 GEMS") name = "GUITAR"; // Some old MIDI files have a track named T1 GEMS
else if (name.substr(0, 5) != "PART ") continue;
else name.erase(0, 5);
// Process non-vocal tracks
|