diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-06-20 19:21:48 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-08-12 11:11:45 +0200 |
commit | 6adb14a7027c8d54827093c83fc80694d71fb6a7 (patch) | |
tree | cc02ac1bdb548b0b317999d727a12fa5a9973594 | |
parent | 1560674582102cd83197dccc79cb029fc843a48e (diff) |
Fix missing finalization of instruments on load. Fix relative instrument filenames according to the drumkit file. Make drumkit creator create version 2.0 drumkits. Reduce missing refs file to a warning.
-rw-r--r-- | src/dgxmlparser.cc | 11 | ||||
-rw-r--r-- | src/domloader.cc | 7 | ||||
-rw-r--r-- | src/domloader.h | 3 | ||||
-rw-r--r-- | src/drumkitloader.cc | 29 | ||||
-rw-r--r-- | src/drumkitparser.cc | 2 | ||||
-rw-r--r-- | src/path.cc | 21 | ||||
-rw-r--r-- | src/path.h | 3 | ||||
-rw-r--r-- | test/domloadertest.cc | 10 | ||||
-rw-r--r-- | test/drumkit_creator.cc | 15 |
9 files changed, 76 insertions, 25 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; +} @@ -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); diff --git a/test/domloadertest.cc b/test/domloadertest.cc index 69b9821..55d49a7 100644 --- a/test/domloadertest.cc +++ b/test/domloadertest.cc @@ -34,6 +34,7 @@ #include <random.h> #include "scopedfile.h" +#include "path.h" class DOMLoaderTest : public DGUnit @@ -99,13 +100,13 @@ public: " <channel name=\"SnareBottom\"/>\n" \ " </channels>\n" \ " <instruments>\n" \ - " <instrument name=\"Snare1\" file=\"") + scoped_instrument_file1.filename() + std::string("\">\n" \ + " <instrument name=\"Snare1\" file=\"") + getFile(scoped_instrument_file1.filename()) + std::string("\">\n" \ " <channelmap in=\"AmbLeft\" out=\"AmbLeft\" main=\"true\"/>\n" \ " <channelmap in=\"AmbRight\" out=\"AmbRight\" main=\"true\"/>\n" \ " <channelmap in=\"SnareTop\" out=\"SnareTop\"/>\n" \ " <channelmap in=\"SnareBottom\" out=\"SnareBottom\"/>\n" \ " </instrument>\n" \ - " <instrument name=\"Snare2\" file=\"") + scoped_instrument_file2.filename() + std::string("\">\n" \ + " <instrument name=\"Snare2\" file=\"") + getFile(scoped_instrument_file2.filename()) + std::string("\">\n" \ " <channelmap in=\"AmbLeft2\" out=\"AmbLeft\" main=\"true\"/>\n" \ " <channelmap in=\"AmbRight2\" out=\"AmbRight\" main=\"true\"/>\n" \ " <channelmap in=\"SnareTop2\" out=\"SnareTop\"/>\n" \ @@ -119,14 +120,15 @@ public: DrumkitDOM drumkitdom; std::vector<InstrumentDOM> instrumentdoms; DGUNIT_ASSERT(parseDrumkitFile(scoped_file.filename(), drumkitdom)); + auto basepath = getPath(scoped_file.filename()); for(const auto& ref: drumkitdom.instruments) { instrumentdoms.emplace_back(); - DGUNIT_ASSERT(parseInstrumentFile(ref.file, instrumentdoms.back())); + DGUNIT_ASSERT(parseInstrumentFile(basepath + "/" + ref.file, instrumentdoms.back())); } DOMLoader domloader(settings, random); - DGUNIT_ASSERT(domloader.loadDom(drumkitdom, instrumentdoms, drumkit)); + DGUNIT_ASSERT(domloader.loadDom(basepath, drumkitdom, instrumentdoms, drumkit)); // // Drumkit: diff --git a/test/drumkit_creator.cc b/test/drumkit_creator.cc index 7a0291c..d92f876 100644 --- a/test/drumkit_creator.cc +++ b/test/drumkit_creator.cc @@ -44,6 +44,7 @@ DrumkitCreator::~DrumkitCreator() { + return; for (const auto& file: created_files) { auto error = unlink(file.c_str()); @@ -304,18 +305,16 @@ void DrumkitCreator::createInstrument(const InstrumentData& data, std::size_t nu const std::string& dir) { std::string prefix = "<?xml version='1.0' encoding='UTF-8'?>\n" - "<instrument name=\"" + data.name + "\" version=\"2.0\">\n"; + "<instrument name=\"" + data.name + "\" version=\"2.0\">\n" + " <samples>\n"; // FIXME sampleref - std::string postfix = "<velocities>\n" - "<velocity lower=\"0\" upper=\"1\">\n" - "<sampleref probability=\"1\" name=\"stroke1\"/>\n" - "</velocity>\n" - "</velocities>\n" - "</instrument>\n"; + std::string postfix = " </samples>\n</instrument>\n"; std::string samples; + float power = 1.0f; for (const auto& sample: data.sample_data) { - samples += "<sample name=\"" + sample.name + "\">\n"; + samples += "<sample name=\"" + sample.name + "\" power=\"" + std::to_string(power) + "\">\n"; + power += 0.1f; for (std::size_t i = 0; i < sample.audiofiles.size(); ++i) { |