|
From: Yoda-JM <yo...@us...> - 2009-08-18 07:02:41
|
Module: performous
Branch: master
Commit: 129bc5cdbf8b0b727e7742da042369f2d97a24c9
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Aug 18 09:02:04 2009 +0200
Changed song music vector to map
---
game/audio.cc | 12 +++++++-----
game/audio.hh | 2 +-
game/screen_songs.cc | 2 +-
game/screen_songs.hh | 4 ++--
game/song.hh | 2 +-
game/songparser-ini.cc | 26 ++++++++++++++++++++------
game/songparser-txt.cc | 4 ++--
7 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index 0b4171b..083f7da 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -77,19 +77,19 @@ void Audio::play(Sample const& s, std::string const& volumeSetting) {
m_mixer.add(da::shared_ref(acc));
}
-void Audio::playMusic(std::vector<std::string> const& filenames, bool preview, double fadeTime, double startPos) {
+void Audio::playMusic(std::map<std::string,std::string> const& filenames, bool preview, double fadeTime, double startPos) {
if (!isOpen()) return;
da::lock_holder l = m_mixer.lock();
fadeout(fadeTime);
boost::shared_ptr<da::chain> ch(new da::chain());
- for(std::vector<std::string>::const_iterator it = filenames.begin() ; it != filenames.end() ; ++it ) {
+ 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, m_rs.rate()));
+ boost::shared_ptr<Stream> s(new Stream(it->second, m_rs.rate()));
m_streams.push_back(s);
ch->add(da::shared_ref(s));
s->seek(startPos);
} catch (std::runtime_error& e) {
- std::cerr << "Error loading " << *it << " (" << e.what() << ")" << std::endl;
+ std::cerr << "Error loading " << it->second << " (" << e.what() << ")" << std::endl;
continue;
}
}
@@ -101,7 +101,9 @@ void Audio::playMusic(std::vector<std::string> const& filenames, bool preview, d
}
void Audio::playMusic(std::string const& filename, bool preview, double fadeTime, double startPos) {
- playMusic(std::vector<std::string>(1, filename), preview, fadeTime, startPos);
+ std::map<std::string,std::string> tmp;
+ tmp["unidentified"] = filename;
+ playMusic(tmp, preview, fadeTime, startPos);
}
void Audio::stopMusic() {
diff --git a/game/audio.hh b/game/audio.hh
index 5c8f093..9432cd7 100644
--- a/game/audio.hh
+++ b/game/audio.hh
@@ -67,7 +67,7 @@ class Audio {
*/
void playMusic(std::string const& filename, bool preview = false, double fadeTime = 0.5, double startPos = -0.2);
/// plays a list of songs
- void playMusic(std::vector<std::string> const& filenames, bool preview = false, double fadeTime = 0.5, double startPos = -0.2);
+ void playMusic(std::map<std::string,std::string> const& filenames, bool preview = false, double fadeTime = 0.5, double startPos = -0.2);
/// plays a sample
void play(Sample const& s, std::string const& volumeSetting);
/// get pause status
diff --git a/game/screen_songs.cc b/game/screen_songs.cc
index df89a53..eb9d27c 100644
--- a/game/screen_songs.cc
+++ b/game/screen_songs.cc
@@ -170,7 +170,7 @@ void ScreenSongs::draw() {
if (m_video.get()) m_video->render(time);
if (!m_jukebox) theme->bg.draw();
std::string songbg, video;
- std::vector<std::string> music;
+ std::map<std::string,std::string> music;
double videoGap = 0.0;
std::ostringstream oss_song, oss_order;
// Test if there are no songs
diff --git a/game/screen_songs.hh b/game/screen_songs.hh
index 5e9a6b9..f314455 100644
--- a/game/screen_songs.hh
+++ b/game/screen_songs.hh
@@ -33,8 +33,8 @@ class ScreenSongs : public Screen {
boost::scoped_ptr<Surface> m_songbg;
boost::scoped_ptr<Video> m_video;
boost::scoped_ptr<ThemeSongs> theme;
- std::vector<std::string> m_playing;
- std::vector<std::string> m_playReq;
+ std::map<std::string,std::string> m_playing;
+ std::map<std::string,std::string> m_playReq;
AnimValue m_playTimer;
TextInput m_search;
boost::scoped_ptr<Surface> m_emptyCover;
diff --git a/game/song.hh b/game/song.hh
index 677cd62..968c889 100644
--- a/game/song.hh
+++ b/game/song.hh
@@ -52,7 +52,7 @@ class Song: boost::noncopyable {
std::string text; ///< songtext
std::string creator; ///< creator
std::string language; ///< language
- std::vector<std::string> music; ///< music files (background, guitar, rhythm/bass, drums, vocals)
+ std::map<std::string,std::string> music; ///< music files (background, guitar, rhythm/bass, drums, vocals)
std::string cover; ///< cd cover
std::string background; ///< background image
std::string video; ///< video
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index c61196d..9a495cb 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -16,9 +16,9 @@ namespace {
void eraseLast(std::string& s, char ch = ' ') {
if (!s.empty() && *s.rbegin() == ch) s.erase(s.size() - 1);
}
- void testAndAdd(Song& s, std::string const& filename) {
+ void testAndAdd(Song& s, std::string const& trackid, std::string const& filename) {
std::string f = s.path + filename;
- if (boost::filesystem::exists(f)) s.music.push_back(f);
+ if (boost::filesystem::exists(f)) s.music[trackid] = f;
}
}
@@ -39,7 +39,12 @@ void SongParser::iniParse() {
if (s.title.empty() || s.artist.empty()) throw std::runtime_error("Required header fields missing");
boost::regex midifile("(.*\\.mid)$", boost::regex_constants::icase);
- boost::regex audiofile("(.*\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_background("(song\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_guitar("(guitar\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_drums("(drums\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_bass("(rhythm\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_vocals("(vocals\\.ogg)$", boost::regex_constants::icase);
+ boost::regex audiofile_other("(.*\\.ogg)$", boost::regex_constants::icase);
boost::cmatch match;
std::string midifilename("notes.mid");
@@ -48,9 +53,18 @@ void SongParser::iniParse() {
std::string name = p.leaf(); // File basename (notes.txt)
if (regex_match(name.c_str(), match, midifile)) {
midifilename = name;
- }
- if (regex_match(name.c_str(), match, audiofile)) {
- testAndAdd(s, name);
+ } else if (regex_match(name.c_str(), match, audiofile_background)) {
+ testAndAdd(s, "background", name);
+ } else if (regex_match(name.c_str(), match, audiofile_guitar)) {
+ testAndAdd(s, "guitar", name);
+ } else if (regex_match(name.c_str(), match, audiofile_bass)) {
+ testAndAdd(s, "bass", name);
+ } else if (regex_match(name.c_str(), match, audiofile_drums)) {
+ testAndAdd(s, "drums", name);
+ } else if (regex_match(name.c_str(), match, audiofile_vocals)) {
+ testAndAdd(s, "vocals", name);
+ } else if (regex_match(name.c_str(), match, audiofile_other)) {
+ std::cout << "Found unknown ogg file: " << name << std::endl;
}
}
diff --git a/game/songparser-txt.cc b/game/songparser-txt.cc
index cd8743b..93ff15f 100644
--- a/game/songparser-txt.cc
+++ b/game/songparser-txt.cc
@@ -53,8 +53,8 @@ bool SongParser::txtParseField(std::string const& line) {
else if (key == "GENRE") m_song.genre = value.substr(value.find_first_not_of(" "));
else if (key == "CREATOR") m_song.creator = value.substr(value.find_first_not_of(" "));
else if (key == "COVER") m_song.cover = value;
- else if (key == "MP3") m_song.music.push_back(m_song.path + value);
- else if (key == "VOCALS") m_song.music.push_back(m_song.path + value);
+ else if (key == "MP3") m_song.music["background"] = m_song.path + value;
+ else if (key == "VOCALS") m_song.music["vocals"] = m_song.path + value;
else if (key == "VIDEO") m_song.video = value;
else if (key == "BACKGROUND") m_song.background = value;
else if (key == "START") assign(m_song.start, value);
|