aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/songloading
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-15 19:25:55 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:44 +0100
commit07ac699856b490c66e8052121f87ec5fc0a034f1 (patch)
tree88d280c15364a0877a98cc27cb42b9457b847e27 /src/base/songloading
parent3fe5cad2a98b81cb8ef65f3c4aa7873552ecd54c (diff)
downloadusdx-07ac699856b490c66e8052121f87ec5fc0a034f1.tar.gz
usdx-07ac699856b490c66e8052121f87ec5fc0a034f1.tar.xz
usdx-07ac699856b490c66e8052121f87ec5fc0a034f1.zip
added parsing of song lyric lines
Diffstat (limited to 'src/base/songloading')
-rw-r--r--src/base/songloading/songloader.cpp18
-rw-r--r--src/base/songloading/songloader.hpp3
-rw-r--r--src/base/songloading/songloading_strategy_txt.cpp74
3 files changed, 85 insertions, 10 deletions
diff --git a/src/base/songloading/songloader.cpp b/src/base/songloading/songloader.cpp
index 8bffa607..1b900bd4 100644
--- a/src/base/songloading/songloader.cpp
+++ b/src/base/songloading/songloader.cpp
@@ -73,4 +73,22 @@ namespace usdx
return it->second->load_header(filename);
}
+
+ Song* Songloader::load_song(Song* song)
+ {
+ std::string extension = "";
+
+ size_t found = song->get_filename().rfind('.');
+ if (found != std::string::npos) {
+ extension = song->get_filename().substr(found);
+ }
+
+ std::map<std::string, SongloadingStrategy*>::iterator it = strategies.find(extension);
+ if (it == strategies.end()) {
+ LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << extension << "'");
+ throw "Unknown file format.";
+ }
+
+ return it->second->load_song(song);
+ }
};
diff --git a/src/base/songloading/songloader.hpp b/src/base/songloading/songloader.hpp
index 8a5cbe03..41f7e034 100644
--- a/src/base/songloading/songloader.hpp
+++ b/src/base/songloading/songloader.hpp
@@ -53,7 +53,8 @@ namespace usdx
virtual ~Songloader(void);
- Song *load_header(std::string filename);
+ Song* load_header(std::string filename);
+ Song* load_song(Song* song);
};
};
diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp
index 841e6253..6b9a03b7 100644
--- a/src/base/songloading/songloading_strategy_txt.cpp
+++ b/src/base/songloading/songloading_strategy_txt.cpp
@@ -25,9 +25,11 @@
*/
#include <string>
+#include <sstream>
#include <algorithm>
#include "songloading_strategy_txt.hpp"
#include "utils/file.hpp"
+#include "utils/locale_independent_float.hpp"
namespace usdx
{
@@ -100,31 +102,81 @@ namespace usdx
Song* SongloadingStrategyTxt::load_song(Song *song)
{
+ LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename());
+
File file(song->get_filename());
std::string line;
+ char type;
+
+ int line_number = 0;;
while (file.stream().good()) {
- file.stream() >> line;
+ std::getline(file.stream(), line);
+ ++line_number;
- // do not remove spaces at line ending, that are maybe
- // spaces in lyrics
- ltrim(line);
+ std::istringstream linestream(line);
+ linestream >> std::skipws >> type;
- if (line[0] == '#') {
+ if (type == '#') {
// ignore, header already read
}
- else if (line[0] == 'E') {
+ else if (type == 'E') {
// song end
+ if (file.stream().eof()) {
+ LOG4CXX_WARN(log, "End marker found in line " << line_number <<
+ " before end of file: '" << song->get_filename() << "'.");
+ }
+
break;
}
- else if (line[0] == '-') {
+ else if (type == '-') {
// line break
+ int line_out, line_in = -1;
+
+ linestream >> line_out;
+ if (linestream.good()) {
+ linestream >> line_in;
+ LOG4CXX_DEBUG(log, "Found newline in line " <<
+ line_number << " with out of last line with "
+ << line_out << " and in of next line " << line_in);
+ }
+ else {
+ LOG4CXX_DEBUG(log, "Found newline in line " <<
+ line_number << " with out of last line with "
+ << line_out);
+ }
+
+// song.new_line(line_out, line_in);
}
- else if (line[0] == 'B') {
+ else if (type == 'B') {
// new bpm
+ int beat;
+ LocaleIndependentFloat new_bpm;
+
+ linestream >> beat >> new_bpm;
+ LOG4CXX_DEBUG(log, "Found new bpm in line " <<
+ line_number << " starting at beat: " <<
+ beat << " and new bpm of " << new_bpm.get_value());
+// song.new_bpm(new_beat, new_bpm);
}
- else {
+ else if (type == ':' || type == 'F' || type == '*') {
// normal line
+ int beat, length, height;
+ std::string lyric;
+
+ linestream >> beat >> length >> height >> std::noskipws;
+ linestream.ignore();
+ getline(linestream, lyric);
+
+ LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number <<
+ " at beat: " << beat << " with length: " << length <<
+ " at height: " << height);
+// song.new_note(beat, length, height, lyric);
+ }
+ else {
+ LOG4CXX_WARN(log, "Unknown line in song: '" << line <<
+ "' in file: " << song->get_filename() <<
+ " at line " << line_number);
}
}
@@ -133,6 +185,10 @@ namespace usdx
return song;
}
+/* void SongloadingStrategyTxt::parse_line(const std::string& line, const int line_num)
+ {
+ }
+*/
Song* SongloadingStrategyTxt::load_header(const std::string& filename)
{
File file(filename);