|
From: Yoda-JM <yo...@us...> - 2010-04-13 06:52:26
|
Module: performous
Branch: master
Commit: 568299eef43ca91ef2684f4139a334a77b0313f2
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Apr 13 08:51:27 2010 +0200
Moved song out of Player and Engine class (we only need a vocal track here)
---
game/engine.hh | 16 ++++++++--------
game/player.cc | 20 ++++++++++----------
game/player.hh | 6 +++---
game/screen_sing.cc | 2 +-
4 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/game/engine.hh b/game/engine.hh
index 9295aaa..f1c7882 100644
--- a/game/engine.hh
+++ b/game/engine.hh
@@ -24,7 +24,7 @@ namespace {
/// performous engine
class Engine {
Audio& m_audio;
- Song& m_song;
+ VocalTrack& m_vocals;
size_t m_time;
volatile bool m_quit;
Database& m_database;
@@ -38,19 +38,19 @@ class Engine {
* @param audio A reference will be stored in order to monitor playback time.
* @param anBegin Analyzers to use (beginning iterator)
* @param anEnd Analyzers to use (ending iterator)
- * @param song Song to play
+ * @param vocals Song to play
**/
- template <typename FwdIt> Engine(Audio& audio, Song& song, FwdIt anBegin, FwdIt anEnd, Database& database):
- m_audio(audio), m_song(song), m_time(), m_quit(), m_database(database)
+ template <typename FwdIt> Engine(Audio& audio, VocalTrack& vocals, FwdIt anBegin, FwdIt anEnd, Database& database):
+ m_audio(audio), m_vocals(vocals), m_time(), m_quit(), m_database(database)
{
// clear old player information
m_database.cur.clear();
m_database.scores.clear();
// Only add players if the vocal track has sensible length (not NaN or extremely long)
- if (song.vocals.endTime < 10000.0) {
+ if (vocals.endTime < 10000.0) {
// Calculate the space required for pitch frames
- size_t frames = song.vocals.endTime / Engine::TIMESTEP;
- while (anBegin != anEnd) m_database.cur.push_back(Player(song, *anBegin++, frames));
+ size_t frames = vocals.endTime / Engine::TIMESTEP;
+ while (anBegin != anEnd) m_database.cur.push_back(Player(vocals, *anBegin++, frames));
size_t player = 0;
for (std::list<Player>::iterator it = m_database.cur.begin(); it != m_database.cur.end(); ++it, ++player) it->m_color = playerColors[player % playerColorsSize];
}
@@ -66,7 +66,7 @@ class Engine {
double t = m_audio.getPosition() - config["audio/round-trip"].f();
double timeLeft = m_time * TIMESTEP - t;
if (timeLeft > 0.0) { boost::thread::sleep(now() + std::min(TIMESTEP, timeLeft)); continue; }
- for (Notes::const_iterator it = m_song.vocals.notes.begin(); it != m_song.vocals.notes.end(); ++it) it->power = 0.0f;
+ for (Notes::const_iterator it = m_vocals.notes.begin(); it != m_vocals.notes.end(); ++it) it->power = 0.0f;
std::for_each(m_database.cur.begin(), m_database.cur.end(), boost::bind(&Player::update, _1));
++m_time;
}
diff --git a/game/player.cc b/game/player.cc
index 85f8a8b..2b862ad 100644
--- a/game/player.cc
+++ b/game/player.cc
@@ -3,11 +3,11 @@
#include "engine.hh" // just for Engine::TIMESTEP
-Player::Player(Song& song, Analyzer& analyzer, size_t frames):
- m_song(song), m_analyzer(analyzer), m_pitch(frames, std::make_pair(getNaN(),
+Player::Player(VocalTrack& vocals, Analyzer& analyzer, size_t frames):
+ m_vocals(vocals), m_analyzer(analyzer), m_pitch(frames, std::make_pair(getNaN(),
-getInf())), m_pos(), m_score(), m_noteScore(), m_lineScore(), m_maxLineScore(),
m_prevLineScore(-1), m_feedbackFader(0.0, 2.0), m_activitytimer(),
- m_scoreIt(m_song.vocals.notes.begin())
+ m_scoreIt(m_vocals.notes.begin())
{ }
void Player::update() {
@@ -24,13 +24,13 @@ void Player::update() {
}
double endTime = Engine::TIMESTEP * m_pos;
// Iterate over all the notes that are considered for this timestep
- while (m_scoreIt != m_song.vocals.notes.end()) {
+ while (m_scoreIt != m_vocals.notes.end()) {
if (endTime < m_scoreIt->begin) break; // The note begins later than on this timestep
// If tone was detected, calculate score
if (t) {
- double note = m_song.vocals.scale.getNote(t->freq);
+ double note = m_vocals.scale.getNote(t->freq);
// Add score
- double score_addition = m_song.vocals.m_scoreFactor * m_scoreIt->score(note, beginTime, endTime);
+ double score_addition = m_vocals.m_scoreFactor * m_scoreIt->score(note, beginTime, endTime);
m_score += score_addition;
m_noteScore += score_addition;
m_lineScore += score_addition;
@@ -45,11 +45,11 @@ void Player::update() {
}
if (endTime < m_scoreIt->end) break; // The note continues past this timestep
// Set accuracy
- m_scoreIt->accuracy = std::max(m_scoreIt->accuracy, m_noteScore / m_song.vocals.m_scoreFactor / m_scoreIt->maxScore());
+ m_scoreIt->accuracy = std::max(m_scoreIt->accuracy, m_noteScore / m_vocals.m_scoreFactor / m_scoreIt->maxScore());
m_noteScore = 0; // Reset noteScore as we are moving on to the next one
++m_scoreIt;
}
- if (m_scoreIt == m_song.vocals.notes.end()) calcRowRank();
+ if (m_scoreIt == m_vocals.notes.end()) calcRowRank();
m_score = clamp(m_score, 0.0, 1.0);
}
@@ -60,8 +60,8 @@ void Player::calcRowRank() {
Notes::const_reverse_iterator maxScoreIt(m_scoreIt);
// FIXME: MacOSX needs the following cast to compile correctly
// it is related to the fact that OSX default compiler is 4.0.1 that is buggy when not casting
- while ((maxScoreIt != static_cast<Notes::const_reverse_iterator>(m_song.vocals.notes.rend())) && (maxScoreIt->type != Note::SLEEP)) {
- m_maxLineScore += m_song.vocals.m_scoreFactor * maxScoreIt->maxScore();
+ while ((maxScoreIt != static_cast<Notes::const_reverse_iterator>(m_vocals.notes.rend())) && (maxScoreIt->type != Note::SLEEP)) {
+ m_maxLineScore += m_vocals.m_scoreFactor * maxScoreIt->maxScore();
maxScoreIt++;
}
if (m_maxLineScore > 0) {
diff --git a/game/player.hh b/game/player.hh
index d313827..2d7ef01 100644
--- a/game/player.hh
+++ b/game/player.hh
@@ -13,8 +13,8 @@ class Song;
/// player class
struct Player {
- /// currently playing song
- Song& m_song;
+ /// currently playing vocals track
+ VocalTrack& m_vocals;
/// sound analyzer
Analyzer& m_analyzer;
/// player color for bars, waves, scores
@@ -42,7 +42,7 @@ struct Player {
/// score iterator
Notes::const_iterator m_scoreIt;
/// constructor
- Player(Song& song, Analyzer& analyzer, size_t frames);
+ Player(VocalTrack& vocals, Analyzer& analyzer, size_t frames);
/// prepares analyzer
void prepare() { m_analyzer.process(); }
/// updates player stats
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 9bbb3dd..5527cae 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -102,7 +102,7 @@ void ScreenSing::enter() {
// Startup delay for instruments is longer than for singing only
double setup_delay = (m_instruments.empty() && m_dancers.empty() ? -1.0 : -8.0);
m_audio.playMusic(m_song->music, false, 0.0, setup_delay);
- m_engine.reset(new Engine(m_audio, *m_song, analyzers.begin(), analyzers.end(), m_database));
+ m_engine.reset(new Engine(m_audio, m_song->vocals, analyzers.begin(), analyzers.end(), m_database));
}
/// Manages the instrument drawing
|