|
From: Yoda-JM <yo...@us...> - 2009-08-17 17:42:28
|
Module: performous
Branch: master
Commit: 7c7b394fd27491db5e87e6371f6805ad7ea49d89
Author: Vincent Le Ligeour <yo...@us...>
Date: Mon Aug 17 19:41:37 2009 +0200
Used regexp for instrument midi/audio files
---
game/songparser-ini.cc | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/game/songparser-ini.cc b/game/songparser-ini.cc
index cb74918..c61196d 100644
--- a/game/songparser-ini.cc
+++ b/game/songparser-ini.cc
@@ -1,6 +1,7 @@
#include "songparser.hh"
#include <boost/filesystem.hpp>
+#include <boost/regex.hpp>
#include "midifile.hh"
/// @file
@@ -36,12 +37,24 @@ void SongParser::iniParse() {
else if (key == "artist") s.artist = value;
}
if (s.title.empty() || s.artist.empty()) throw std::runtime_error("Required header fields missing");
- testAndAdd(s, "song.ogg");
- testAndAdd(s, "guitar.ogg");
- testAndAdd(s, "rhythm.ogg");
- testAndAdd(s, "drums.ogg");
- testAndAdd(s, "vocals.ogg");
- MidiFileParser midi(s.path + "/notes.mid");
+
+ boost::regex midifile("(.*\\.mid)$", boost::regex_constants::icase);
+ boost::regex audiofile("(.*\\.ogg)$", boost::regex_constants::icase);
+ boost::cmatch match;
+ std::string midifilename("notes.mid");
+
+ for (boost::filesystem::directory_iterator dirIt(s.path), dirEnd; dirIt != dirEnd; ++dirIt) {
+ boost::filesystem::path p = dirIt->path();
+ 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);
+ }
+ }
+
+ MidiFileParser midi(s.path + "/" + midifilename);
for (uint32_t ts = 0, end = midi.ts_last + midi.division; ts < end; ts += midi.division) s.beats.push_back(midi.get_seconds(ts));
for (MidiFileParser::Tracks::const_iterator it = midi.tracks.begin(); it != midi.tracks.end(); ++it) {
// Figure out the track name
|