summaryrefslogtreecommitdiff
path: root/src/drumkitparser.cc
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2016-03-23 18:24:29 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-03-29 22:19:49 +0200
commit8c585aa006741b95c1175afcdb01cdd3d8d2d7db (patch)
tree66c482877189c0d63708caffa0e614caf1b8f228 /src/drumkitparser.cc
parent01e216f82e24e7668a892e5a912ccbf1369ae255 (diff)
Do the file related actions in SAXParser.
Diffstat (limited to 'src/drumkitparser.cc')
-rw-r--r--src/drumkitparser.cc56
1 files changed, 16 insertions, 40 deletions
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index 2d0262d..595cd41 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -34,17 +34,21 @@
#include "path.h"
#include "drumgizmo.h"
-DrumKitParser::DrumKitParser(const std::string& file, DrumKit& k)
- : kit(k)
+DrumKitParser::DrumKitParser(DrumKit& kit)
+ : kit(kit)
, refs(REFSFILE)
{
- std::string kitfile = file;
+}
+
+int DrumKitParser::parseFile(const std::string& filename)
+{
+ auto edited_filename(filename);
if(refs.load())
{
- if(file.size() > 1 && file[0] == '@')
+ if(filename.size() > 1 && filename[0] == '@')
{
- kitfile = refs.getValue(file.substr(1));
+ edited_filename = refs.getValue(filename.substr(1));
}
}
else
@@ -52,28 +56,14 @@ DrumKitParser::DrumKitParser(const std::string& file, DrumKit& k)
ERR(drumkitparser, "Error reading refs.conf");
}
- // instr = NULL;
- path = getPath(kitfile);
-
- fd = fopen(kitfile.c_str(), "r");
-
- // DEBUG(kitparser, "Parsing drumkit in %s\n", kitfile.c_str());
-
- if(!fd)
- {
- return;
- }
-
- kit._file = file;
-}
+ path = getPath(edited_filename);
+ auto result = SAXParser::parseFile(filename);
-DrumKitParser::~DrumKitParser()
-{
- if(fd)
- {
- fclose(fd);
+ if (result == 0) {
+ kit._file = edited_filename;
}
+ return result;
}
void DrumKitParser::startTag(const std::string& name, const attr_t& attr)
@@ -193,8 +183,8 @@ void DrumKitParser::endTag(const std::string& name)
Instrument* i = new Instrument();
i->setGroup(instr_group);
// Instrument &i = kit.instruments[kit.instruments.size() - 1];
- InstrumentParser parser(path + "/" + instr_file, *i);
- parser.parse();
+ InstrumentParser parser(*i);
+ parser.parseFile(path + "/" + instr_file);
kit.instruments.push_back(i);
// Assign kit channel numbers to instruments channels.
@@ -233,17 +223,3 @@ void DrumKitParser::endTag(const std::string& name)
channelmap.clear();
}
}
-
-int DrumKitParser::readData(std::string& data, std::size_t size)
-{
- 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;
- return fread((char*)data.c_str(), 1, size, fd);
-}