summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dgxmlparser.cc11
-rw-r--r--src/domloader.cc7
-rw-r--r--src/domloader.h3
-rw-r--r--src/drumkitloader.cc29
-rw-r--r--src/drumkitparser.cc2
-rw-r--r--src/path.cc21
-rw-r--r--src/path.h3
7 files changed, 63 insertions, 13 deletions
diff --git a/src/dgxmlparser.cc b/src/dgxmlparser.cc
index 3fdedc2..8fdcec4 100644
--- a/src/dgxmlparser.cc
+++ b/src/dgxmlparser.cc
@@ -105,9 +105,10 @@ bool parseDrumkitFile(const std::string& filename, DrumkitDOM& dom)
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(filename.c_str());
res &= !result.status;
-
- if(!res) {
- printf("PugiXml error %d\n", (int) result.offset);
+ if(!res)
+ {
+ ERR(dgxmlparser, "XML parse error: '%s' %d", filename.data(),
+ (int) result.offset);
return false;
}
@@ -156,6 +157,10 @@ bool parseInstrumentFile(const std::string& filename, InstrumentDOM& dom)
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(filename.data());
res &= !result.status;
+ if(!res)
+ {
+ ERR(dgxmlparser, "XML parse error: '%s'", filename.data());
+ }
//TODO: handle version
pugi::xml_node instrument = doc.child("instrument");
diff --git a/src/domloader.cc b/src/domloader.cc
index 1498917..e095acb 100644
--- a/src/domloader.cc
+++ b/src/domloader.cc
@@ -49,7 +49,8 @@ DOMLoader::DOMLoader(Settings& settings, Random& random)
{
}
-bool DOMLoader::loadDom(const DrumkitDOM& dom,
+bool DOMLoader::loadDom(const std::string& basepath,
+ const DrumkitDOM& dom,
const std::vector<InstrumentDOM>& instrumentdoms,
DrumKit& drumkit)
{
@@ -91,7 +92,7 @@ bool DOMLoader::loadDom(const DrumkitDOM& dom,
instrument->version = instrumentdom.version;
instrument->_description = instrumentdom.description;
- auto path = getPath(instrumentref.file);
+ auto path = getPath(basepath + "/" + instrumentref.file);
for(const auto& sampledom : instrumentdom.samples)
{
auto sample = new Sample(sampledom.name, sampledom.power);
@@ -164,6 +165,8 @@ bool DOMLoader::loadDom(const DrumkitDOM& dom,
}
}
+ instrument->finalise();
+
// Transfer ownership to the DrumKit object.
drumkit.instruments.emplace_back(std::move(instrument));
diff --git a/src/domloader.h b/src/domloader.h
index ea0aad2..2901560 100644
--- a/src/domloader.h
+++ b/src/domloader.h
@@ -42,7 +42,8 @@ class DOMLoader
public:
DOMLoader(Settings& settings, Random& random);
- bool loadDom(const DrumkitDOM& dom,
+ bool loadDom(const std::string& basepath,
+ const DrumkitDOM& dom,
const std::vector<InstrumentDOM>& instrumentdoms,
DrumKit& drumkit);
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index 0cef31b..2ad6b0e 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -127,23 +127,42 @@ bool DrumKitLoader::loadkit(const std::string& file)
}
else
{
- ERR(drumkitparser, "Error reading refs.conf");
+ WARN(drumkitparser, "Error reading refs.conf");
}
DrumkitDOM drumkitdom;
std::vector<InstrumentDOM> instrumentdoms;
std::string path = getPath(edited_filename);
- bool parseerror = parseDrumkitFile(edited_filename, drumkitdom);
+ bool parseerror = false;
+ bool ret = parseDrumkitFile(edited_filename, drumkitdom);
+ if(!ret)
+ {
+ WARN(drumkitloader, "Drumkit file parser error: '%s'",
+ edited_filename.data());
+ }
+
+ parseerror |= !ret;
for(const auto& ref : drumkitdom.instruments)
{
instrumentdoms.emplace_back();
- parseerror &= parseInstrumentFile(path + "/" + ref.file, instrumentdoms.back());
+ bool ret = parseInstrumentFile(path + "/" + ref.file, instrumentdoms.back());
+ if(!ret)
+ {
+ WARN(drumkitloader, "Instrument file parser error: '%s'",
+ edited_filename.data());
+ }
+
+ parseerror |= !ret;
}
DOMLoader domloader(settings, rand);
- parseerror &= domloader.loadDom(drumkitdom, instrumentdoms, kit);
-
+ ret = domloader.loadDom(path, drumkitdom, instrumentdoms, kit);
+ if(!ret)
+ {
+ WARN(drumkitloader, "DOMLoader error");
+ }
+ parseerror |= !ret;
if(parseerror)
{
ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index d86957e..7966d06 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -58,7 +58,7 @@ int DrumKitParser::parseFile(const std::string& filename)
}
else
{
- ERR(drumkitparser, "Error reading refs.conf");
+ WARN(drumkitparser, "Error reading refs.conf");
}
path = getPath(edited_filename);
diff --git a/src/path.cc b/src/path.cc
index c2e7910..993f9a6 100644
--- a/src/path.cc
+++ b/src/path.cc
@@ -40,7 +40,7 @@ std::string getPath(const std::string& file)
#ifdef __MINGW32__
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
- _splitpath(file.c_str(), drive, dir, NULL, NULL);
+ _splitpath(file.c_str(), drive, dir, nullptr, nullptr);
path = std::string(drive) + dir;
#else
// POSIX
@@ -51,3 +51,22 @@ std::string getPath(const std::string& file)
return path;
}
+
+std::string getFile(const std::string& file)
+{
+ std::string path;
+
+#ifdef __MINGW32__
+ char fname[_MAX_FNAME];
+ char ext[_MAX_EXT];
+ _splitpath(file.c_str(), nullptr, nullptr, fname, ext);
+ path = std::string(fname) + "." + ext;
+#else
+ // POSIX
+ char* buffer = strdup(file.c_str());
+ path = basename(buffer);
+ free(buffer);
+#endif
+
+ return path;
+}
diff --git a/src/path.h b/src/path.h
index 50ff842..270a58a 100644
--- a/src/path.h
+++ b/src/path.h
@@ -30,3 +30,6 @@
//! \returns path component of full filename with path.
std::string getPath(const std::string& file);
+
+//! \returns path component of full filename with path.
+std::string getFile(const std::string& file);