summaryrefslogtreecommitdiff
path: root/src/midimapparser.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-07-25 21:24:38 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-08-12 11:13:57 +0200
commitf2fa9543a11fd5551aa619160d5a02b886fb1bbb (patch)
tree6c6adcd10be04aca81b283f82920dbd0b880467e /src/midimapparser.cc
parent7543b64a995c1a2d3eb598c049919729016ba252 (diff)
Rewrite MidiMapParser to use pugixml.
Diffstat (limited to 'src/midimapparser.cc')
-rw-r--r--src/midimapparser.cc28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/midimapparser.cc b/src/midimapparser.cc
index cc97280..059dfec 100644
--- a/src/midimapparser.cc
+++ b/src/midimapparser.cc
@@ -26,14 +26,32 @@
*/
#include "midimapparser.h"
-void MidiMapParser::startTag(const std::string& name, const attr_t& attr)
+#include <pugixml.hpp>
+#include <hugin.hpp>
+
+bool MidiMapParser::parseFile(const std::string& filename)
{
- if(name == "map")
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load_file(filename.data());
+ if(result.status)
+ {
+ ERR(midimapparser, "XML parse error: %d", (int)result.offset);
+ return false;
+ }
+
+ pugi::xml_node midimap_node = doc.child("midimap");
+ for(pugi::xml_node map_node : midimap_node.children("map"))
{
- if((attr.find("note") != attr.end()) &&
- (attr.find("instr") != attr.end()))
+ constexpr int bad_value = 10000;
+ auto note = map_node.attribute("note").as_int(bad_value);
+ auto instr = map_node.attribute("instr").as_string();
+ if(std::string(instr) == "" || note == bad_value)
{
- midimap[std::stoi(attr.at("note"))] = attr.at("instr");
+ continue;
}
+
+ midimap[note] = instr;
}
+
+ return true;
}