summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audioinputenginemidi.cc2
-rw-r--r--src/configparser.cc2
-rw-r--r--src/midimapparser.cc28
-rw-r--r--src/midimapparser.h5
4 files changed, 26 insertions, 11 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index 3ac2a96..6e76f19 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -67,7 +67,7 @@ bool AudioInputEngineMidi::loadMidiMap(const std::string& file,
}
MidiMapParser midimap_parser;
- if(midimap_parser.parseFile(f))
+ if(!midimap_parser.parseFile(f))
{
return false;
}
diff --git a/src/configparser.cc b/src/configparser.cc
index 0227d15..30b981f 100644
--- a/src/configparser.cc
+++ b/src/configparser.cc
@@ -39,8 +39,6 @@ bool ConfigParser::parseString(const std::string& xml)
return false;
}
- //TODO: handle xml version
-
pugi::xml_node config_node = doc.child("config");
for(pugi::xml_node value_node : config_node.children("value"))
{
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;
}
diff --git a/src/midimapparser.h b/src/midimapparser.h
index 8ec76c0..d2f2ddd 100644
--- a/src/midimapparser.h
+++ b/src/midimapparser.h
@@ -26,14 +26,13 @@
*/
#pragma once
-#include "saxparser.h"
#include "midimapper.h"
class MidiMapParser
- : public SAXParser
{
public:
- void startTag(const std::string& name, const attr_t& attr) override;
+ //! Returns false on error, true on success.
+ bool parseFile(const std::string& filename);
midimap_t midimap;
};