summaryrefslogtreecommitdiff
path: root/src/midimapparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/midimapparser.cc')
-rw-r--r--src/midimapparser.cc36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/midimapparser.cc b/src/midimapparser.cc
index 8dabb05..2d4563a 100644
--- a/src/midimapparser.cc
+++ b/src/midimapparser.cc
@@ -26,27 +26,39 @@
*/
#include "midimapparser.h"
-MidiMapParser::MidiMapParser(std::string file)
+MidiMapParser::MidiMapParser(const std::string& file)
{
- fd = fopen(file.c_str(), "r");
+ fd = fopen(file.c_str(), "r");
}
MidiMapParser::~MidiMapParser()
{
- if(fd) fclose(fd);
+ if(fd)
+ {
+ fclose(fd);
+ }
}
-void MidiMapParser::startTag(std::string name, attr_t attr)
+void MidiMapParser::startTag(const std::string& name, attr_t& attr)
{
- if(name == "map") {
- if(attr.find("note") != attr.end() && attr.find("instr") != attr.end()) {
- midimap[atoi(attr["note"].c_str())] = attr["instr"];
- }
- }
+ if(name == "map")
+ {
+ if(attr.find("note") != attr.end() && attr.find("instr") != attr.end())
+ {
+ midimap[std::stoi(attr["note"])] = attr["instr"];
+ }
+ }
}
-int MidiMapParser::readData(char *data, size_t size)
+int MidiMapParser::readData(std::string& data, std::size_t size)
{
- if(!fd) return -1;
- return fread(data, 1, size, fd);
+ if(!fd)
+ {
+ return -1;
+ }
+
+ data.resize(size);
+ auto nr_of_bytes_read = fread((void*)data.data(), 1, size, fd);
+ data.resize(nr_of_bytes_read);
+ return nr_of_bytes_read;
}