diff options
Diffstat (limited to 'src/midimapparser.cc')
-rw-r--r-- | src/midimapparser.cc | 28 |
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; } |