|
From: Yoda-JM <yo...@us...> - 2009-08-18 08:23:08
|
Module: performous
Branch: master
Commit: f057711cc8c26430dbfbbb58240e2fc6c7cf0bc9
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Aug 18 10:22:21 2009 +0200
Added k/K key in screen sing to enable/disable vocals audio track
---
game/audio.cc | 22 +++++++++++-----------
game/audio.hh | 4 ++--
game/guitargraph.cc | 6 +++---
game/screen_sing.cc | 14 ++++++++++++--
game/songparser-ini.cc | 11 +++++++----
5 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index 083f7da..3e0ace5 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -85,7 +85,7 @@ void Audio::playMusic(std::map<std::string,std::string> const& filenames, bool p
for(std::map<std::string,std::string>::const_iterator it = filenames.begin() ; it != filenames.end() ; ++it ) {
try {
boost::shared_ptr<Stream> s(new Stream(it->second, m_rs.rate()));
- m_streams.push_back(s);
+ m_streams[it->first] = s;
ch->add(da::shared_ref(s));
s->seek(startPos);
} catch (std::runtime_error& e) {
@@ -122,31 +122,30 @@ void Audio::fadeout(double fadeTime) {
double Audio::getPosition() const {
da::lock_holder l = m_mixer.lock();
- return m_streams.empty() ? getNaN() : m_streams.front()->pos();
+ return m_streams.empty() ? getNaN() : m_streams.begin()->second->pos();
}
double Audio::getLength() const {
da::lock_holder l = m_mixer.lock();
- return m_streams.empty() ? getNaN() : m_streams.front()->duration();
+ return m_streams.empty() ? getNaN() : m_streams.begin()->second->duration();
}
bool Audio::isPlaying() const {
da::lock_holder l = m_mixer.lock();
- return m_streams.empty() ? false : !m_streams.front()->eof();
+ return m_streams.empty() ? false : !m_streams.begin()->second->eof();
}
void Audio::seek(double offset) {
da::lock_holder l = m_mixer.lock();
- for (size_t i = 0; i < m_streams.size(); ++i) {
- Stream& s = *m_streams[i];
- s.seek(clamp(s.pos() + offset, 0.0, s.duration()));
- }
+ for(std::map<std::string,boost::shared_ptr<Stream> >::iterator it = m_streams.begin() ; it != m_streams.end() ; ++it)
+ it->second->seek(clamp(it->second->pos() + offset, 0.0, it->second->duration()));
pause(false);
}
void Audio::seekPos(double pos) {
da::lock_holder l = m_mixer.lock();
- for (size_t i = 0; i < m_streams.size(); ++i) m_streams[i]->seek(pos);
+ for(std::map<std::string,boost::shared_ptr<Stream> >::iterator it = m_streams.begin() ; it != m_streams.end() ; ++it)
+ it->second->seek(pos);
pause(false);
}
@@ -156,8 +155,9 @@ void Audio::pause(bool state) {
m_mixer.pause(m_paused);
}
-void Audio::streamFade(unsigned num, double level) {
+void Audio::streamFade(std::string stream_id, double level) {
da::lock_holder l = m_mixer.lock();
- m_streams.at(num)->fade = level;
+ std::map<std::string,boost::shared_ptr<Stream> >::iterator it = m_streams.find(stream_id);
+ if( it != m_streams.end() ) it->second->fade = level;
}
diff --git a/game/audio.hh b/game/audio.hh
index 9432cd7..e7ed18e 100644
--- a/game/audio.hh
+++ b/game/audio.hh
@@ -98,7 +98,7 @@ class Audio {
void pause(bool state = true);
/// toggles synth playback (F4)
void toggleSynth(Notes const& notes) { m_notes = (m_notes ? NULL : ¬es); }
- void streamFade(unsigned num, double level);
+ void streamFade(std::string stream_id, double level);
unsigned int getSR() const { return m_rs.rate(); }
private:
bool m_paused;
@@ -106,7 +106,7 @@ class Audio {
da::settings m_rs;
da::volume m_volume;
da::mixer m_mixer;
- std::vector<boost::shared_ptr<Stream> > m_streams;
+ std::map<std::string,boost::shared_ptr<Stream> > m_streams;
std::string m_volumeSetting;
};
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 358cf36..379f8e7 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -70,10 +70,10 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, bool drums, unsigned tr
g_samplesG.push_back(Sample(getDataPath("sounds/guitar_fail6.ogg"), sr));
}
for (Tracks::const_iterator it = m_song.tracks.begin(); it != m_song.tracks.end(); ++it) {
- if (drums != (it->name == "DRUMS")) continue;
+ if (drums != (it->name == "drums")) continue;
m_tracks.push_back(&*it);
- if (it->name == "DRUMS") m_necks.push_back(new Texture("drumneck.svg"));
- else if (it->name == "BASS") m_necks.push_back(new Texture("bassneck.svg"));
+ if (it->name == "drums") m_necks.push_back(new Texture("drumneck.svg"));
+ else if (it->name == "bass") m_necks.push_back(new Texture("bassneck.svg"));
else m_necks.push_back(new Texture("guitarneck.svg"));
}
for (int i = 0; i < 6; ++i) m_hit[i].setRate(5.0);
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 1a85d41..d9f254a 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -55,7 +55,7 @@ void ScreenSing::instrumentLayout(double time) {
m_instruments[i].position((0.5 + i - 0.5 * s) * iw, iw);
}
typedef std::pair<unsigned, double> CountSum;
- std::map<unsigned, CountSum> volume; // stream number to (count, sum)
+ std::map<unsigned, CountSum> volume; // stream id to (count, sum)
for (Instruments::iterator it = m_instruments.begin(); it != m_instruments.end(); ++it) {
it->engine();
CountSum& cs = volume[it->stream() + 1];
@@ -73,8 +73,16 @@ void ScreenSing::instrumentLayout(double time) {
double level = 1.0;
CountSum cs = volume[i];
if (cs.first > 0) level = cs.second / cs.first;
- m_audio.streamFade(i, level); // +1 because 0 is bg
+ //m_audio.streamFade(i, level); // +1 because 0 is bg
}
+ /*
+ for( std::map<std::string,std::string>::iterator it = m_song->music.begin() ; it != m_song->music.end() ; ++it ) {
+ double level = 1.0;
+ CountSum cs = volume[it->first];
+ if (cs.first > 0) level = cs.second / cs.first;
+ m_audio.streamFade(it->first, level);
+ }
+ */
}
void ScreenSing::exit() {
@@ -161,6 +169,8 @@ void ScreenSing::manageEvent(SDL_Event event) {
else if (key == SDLK_RIGHT) m_audio.seek(5.0);
else if (key == SDLK_UP) m_audio.seek(30.0);
else if (key == SDLK_DOWN) { m_audio.seek(-30.0); seekback = true; }
+ else if (key == SDLK_k && event.key.keysym.mod & KMOD_SHIFT) { m_audio.streamFade("vocals", 1.0); }
+ else if (key == SDLK_k && !(event.key.keysym.mod & KMOD_SHIFT)) { m_audio.streamFade("vocals", 0.0); }
else if (key == SDLK_r && event.key.keysym.mod & KMOD_CTRL) {
exit(); m_song->reload(); enter();
m_audio.seek(time);
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index 9a495cb..74a99b1 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -73,15 +73,18 @@ 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"; // 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
+ 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);
if (name == "GUITAR COOP") continue; // TODO: do something with these? They don't work in current version
- if (name == "DRUM") name = "DRUMS";
+ if (name == "DRUM") name = "drums";
+ if (name == "DRUMS") name = "drums";
+ if (name == "BASS") name = "bass";
+ if (name == "GUITAR") name = "guitar";
// Process non-vocal tracks
if (name != "VOCALS") {
- bool drums = (name == "DRUMS");
+ bool drums = (name == "drums");
s.tracks.push_back(Track(name));
NoteMap& nm = s.tracks.back().nm;
for (MidiFileParser::NoteMap::const_iterator it2 = it->notes.begin(); it2 != it->notes.end(); ++it2) {
|