summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Bisballe Jensen <larsbisballe@gmail.com>2014-10-22 13:57:32 +0200
committerLars Bisballe Jensen <larsbisballe@gmail.com>2014-10-22 13:57:32 +0200
commite8b14d33517b3eae27e6420c63396180ba8e2731 (patch)
treec43d3955e93c9a55cc9b1031bac5bc455ca95215
parentbfe5e49afa09b80730ea43854040e84cd29e9ad2 (diff)
Parser should now work
-rw-r--r--src/drumgizmo.cc3
-rw-r--r--src/drumkitparser.cc143
-rw-r--r--src/drumkitparser.h6
3 files changed, 85 insertions, 67 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index d6a48de..220f3e9 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -63,7 +63,10 @@ bool DrumGizmo::loadkit(std::string file)
// Delete all Channels, Instruments, Samples and AudioFiles.
kit.clear();
+ printf("1\n");
DrumKitParser parser(file, kit);
+ printf("2\n");
+
if(parser.parse()) {
ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
return false;
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index 2f5ea5e..36f76fc 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -57,9 +57,13 @@ DrumKitParser::~DrumKitParser()
if(fd) fclose(fd);
}
+void DrumKitParser::characterData(std::string &data)
+{
+ this->data += data;
+}
+
void DrumKitParser::startTag(std::string name,
- std::map<std::string, std::string> attr,
- std::string &data)
+ std::map<std::string, std::string> attr)
{
if(name == "drumkit") {
if(attr.find("version") != attr.end()) {
@@ -69,19 +73,72 @@ void DrumKitParser::startTag(std::string name,
ERR(kitparser, "Error parsing version number: %s, using 1.0\n", err);
kit._version = VersionStr(1,0,0);
}
+ meta.version = attr["version"];
} else {
WARN(kitparser, "Missing version number, assuming 1.0\n");
kit._version = VersionStr(1,0,0);
+ meta.version = "Version not found";
}
- meta.version = kit._version;
}
if(name == "metadata") {
in_metadata = true;
}
+ if(name == "channels") {}
+
+ if(name == "channel") {
+ if(attr.find("id") == attr.end()) {
+ DEBUG(kitparser, "Missing channel id.\n");
+ return;
+ }
+ ch_id = attr["id"];
+ in_channel = true;
+ }
+
+ if(name == "instruments") {}
+
+ if(name == "instrument") {
+ if(attr.find("id") == attr.end()) {
+ DEBUG(kitparser, "Missing id in instrument tag.\n");
+ return;
+ }
+ if(attr.find("file") == attr.end()) {
+ DEBUG(kitparser, "Missing file in instrument tag.\n");
+ return;
+ }
+
+ instr_id = attr["id"];
+ instr_file = attr["file"];
+ if(attr.find("group") != attr.end()) instr_group = attr["group"];
+ else instr_group = "";
+
+ in_instrument = true;
+ }
+
+ if(in_instrument) {
+ if(name == "channelmap") {
+ if(attr.find("in") == attr.end()) {
+ DEBUG(kitparser, "Missing 'in' in channelmap tag.\n");
+ return;
+ }
+
+ if(attr.find("out") == attr.end()) {
+ DEBUG(kitparser, "Missing 'out' in channelmap tag.\n");
+ return;
+ }
+
+ channelmap[attr["in"]] = attr["out"];
+ }
+ }
+
+}
+
+void DrumKitParser::endTag(std::string name)
+{
if(in_metadata) {
if(name == "name") {
+ //FIXME: data is never "", find a new way to check for empty data
if(data != "") {
kit._name = data;
} else {
@@ -94,8 +151,8 @@ void DrumKitParser::startTag(std::string name,
kit._description = data;
} else {
kit._description = "No drumkit " + name + " found";
- meta.description = kit._description;
}
+ meta.description = kit._description;
}
if(name == "notes") {
if(data != "") {
@@ -131,17 +188,10 @@ void DrumKitParser::startTag(std::string name,
}
}
- if(name == "channels") {}
-
- if(name == "channel") {
- if(attr.find("id") == attr.end()) {
- DEBUG(kitparser, "Missing channel id.\n");
- return;
- }
- ch_id = attr["id"];
- in_channel = true;
+ if(name == "metadata") {
+ in_metadata = false;
}
-
+
if(in_channel) {
if(name == "name") {
if(data != "") {
@@ -159,24 +209,16 @@ void DrumKitParser::startTag(std::string name,
}
}
- if(name == "instruments") {}
-
- if(name == "instrument") {
- if(attr.find("id") == attr.end()) {
- DEBUG(kitparser, "Missing id in instrument tag.\n");
- return;
- }
- if(attr.find("file") == attr.end()) {
- DEBUG(kitparser, "Missing file in instrument tag.\n");
- return;
- }
+ if(name == "channel") {
+ Channel c(ch_id);
+ c.name = ch_name;
+ c.microphone = ch_microphone;
+ c.num = kit.channels.size();
+ kit.channels.push_back(c);
- instr_id = attr["id"];
- instr_file = attr["file"];
- if(attr.find("group") != attr.end()) instr_group = attr["group"];
- else instr_group = "";
+ meta.channels.push_back(std::pair<std::string, std::string>(ch_name, ch_microphone));
- in_instrument = true;
+ in_channel = false;
}
if(in_instrument) {
@@ -187,7 +229,7 @@ void DrumKitParser::startTag(std::string name,
instr_name = "No instrument " + name + " found";
}
}
-
+
if(name == "description") {
if(data != "") {
instr_description = data;
@@ -195,42 +237,10 @@ void DrumKitParser::startTag(std::string name,
instr_description = "No instrument " + name + " found";
}
}
-
- if(name == "channelmap") {
- if(attr.find("in") == attr.end()) {
- DEBUG(kitparser, "Missing 'in' in channelmap tag.\n");
- return;
- }
-
- if(attr.find("out") == attr.end()) {
- DEBUG(kitparser, "Missing 'out' in channelmap tag.\n");
- return;
- }
-
- channelmap[attr["in"]] = attr["out"];
- }
}
-}
-
-void DrumKitParser::endTag(std::string name)
-{
- if(name == "metadata") {
- in_metadata = false;
- }
-
- if(name == "channel") {
- Channel c(ch_id);
- c.name = ch_name;
- c.microphone = ch_microphone;
- c.num = kit.channels.size();
- kit.channels.push_back(c);
-
- meta.channels.push_back(std::pair<std::string, std::string>(ch_name, ch_microphone));
-
- in_channel = false;
- }
-
+
if(name == "instrument") {
+
Instrument *i = new Instrument();
i->setName(instr_name);
i->setDescription(instr_description);
@@ -268,6 +278,9 @@ void DrumKitParser::endTag(std::string name)
channelmap.clear();
in_instrument = false;
}
+
+ // reset element data string
+ data = "";
}
int DrumKitParser::readData(char *data, size_t size)
diff --git a/src/drumkitparser.h b/src/drumkitparser.h
index 6b24fa5..3703737 100644
--- a/src/drumkitparser.h
+++ b/src/drumkitparser.h
@@ -47,9 +47,9 @@ public:
DrumKitParser(const std::string &kitfile, DrumKit &kit);
~DrumKitParser();
+ void characterData(std::string &data);
void startTag(std::string name,
- std::map< std::string, std::string> attributes,
- std::string &data);
+ std::map< std::string, std::string> attributes);
void endTag(std::string name);
MetaData getMetaData();
@@ -57,6 +57,8 @@ protected:
int readData(char *data, size_t size);
private:
+ std::string data;
+
FILE *fd;
DrumKit &kit;