summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-06-23 09:02:37 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-08-12 11:11:49 +0200
commit592f05fa549c7e680e502f569c27e71177361ad6 (patch)
tree31e884348253086cdc8ce9bd1aaee938e4d74374
parentd6ba6aac44a2a30920be6938bb61a6ff234729f8 (diff)
Remove the old instrument and drumkit parser code as well as version 1.0 kit handling (velocity range maps).
-rw-r--r--plugin/Makefile.mingw32.in2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/drumgizmo.cc1
-rw-r--r--src/drumkitparser.cc263
-rw-r--r--src/drumkitparser.h65
-rw-r--r--src/instrument.cc41
-rw-r--r--src/instrument.h3
-rw-r--r--src/instrumentparser.cc274
-rw-r--r--src/instrumentparser.h64
-rw-r--r--src/rangemap.h98
-rw-r--r--test/Makefile.am21
-rw-r--r--test/drumkitparsertest.cc135
-rw-r--r--test/instrumentparsertest.cc158
13 files changed, 8 insertions, 1121 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in
index b5202c0..52d573d 100644
--- a/plugin/Makefile.mingw32.in
+++ b/plugin/Makefile.mingw32.in
@@ -25,11 +25,9 @@ DG_SRC = \
@top_srcdir@/src/drumgizmo.cc \
@top_srcdir@/src/drumkit.cc \
@top_srcdir@/src/drumkitloader.cc \
- @top_srcdir@/src/drumkitparser.cc \
@top_srcdir@/src/events.cc \
@top_srcdir@/src/inputprocessor.cc \
@top_srcdir@/src/instrument.cc \
- @top_srcdir@/src/instrumentparser.cc \
@top_srcdir@/src/latencyfilter.cc \
@top_srcdir@/src/midimapparser.cc \
@top_srcdir@/src/midimapper.cc \
diff --git a/src/Makefile.am b/src/Makefile.am
index 960f17c..14da4d6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,11 +30,9 @@ nodist_libdg_la_SOURCES = \
drumgizmo.cc \
drumkit.cc \
drumkitloader.cc \
- drumkitparser.cc \
events.cc \
inputprocessor.cc \
instrument.cc \
- instrumentparser.cc \
latencyfilter.cc \
midimapparser.cc \
midimapper.cc \
@@ -72,12 +70,10 @@ EXTRA_DIST = \
drumgizmo.h \
drumkit.h \
drumkitloader.h \
- drumkitparser.h \
events.h \
inputfilter.h \
inputprocessor.h \
instrument.h \
- instrumentparser.h \
latencyfilter.h \
midimapparser.h \
midimapper.h \
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 5048e35..d389cc2 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -38,7 +38,6 @@
#include <hugin.hpp>
-#include "drumkitparser.h"
#include "audioinputenginemidi.h"
DrumGizmo::DrumGizmo(Settings& settings,
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
deleted file mode 100644
index 7966d06..0000000
--- a/src/drumkitparser.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * drumkitparser.cc
- *
- * Tue Jul 22 16:24:59 CEST 2008
- * Copyright 2008 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "drumkitparser.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <hugin.hpp>
-
-#include "cpp11fix.h"
-#include "instrumentparser.h"
-#include "path.h"
-#include "drumgizmo.h"
-
-DrumKitParser::DrumKitParser(Settings& settings, DrumKit& k, Random& rand)
- : kit(k)
- , refs(REFSFILE)
- , settings(settings)
- , rand(rand)
-{
-}
-
-int DrumKitParser::parseFile(const std::string& filename)
-{
- settings.has_bleed_control.store(false);
-
- auto edited_filename(filename);
-
- if(refs.load())
- {
- if((filename.size() > 1) && (filename[0] == '@'))
- {
- edited_filename = refs.getValue(filename.substr(1));
- }
- }
- else
- {
- WARN(drumkitparser, "Error reading refs.conf");
- }
-
- path = getPath(edited_filename);
- auto result = SAXParser::parseFile(edited_filename);
-
- if(result == 0)
- {
- kit._file = edited_filename;
- }
-
- return result;
-}
-
-void DrumKitParser::startTag(const std::string& name, const attr_t& attr)
-{
- if(name == "drumkit")
- {
- if(attr.find("name") != attr.end())
- {
- kit._name = attr.at("name");
- }
-
- if(attr.find("samplerate") != attr.end())
- {
- kit._samplerate = std::stoi(attr.at("samplerate"));
- }
- else
- {
- // If 'samplerate' attribute is missing, assume 44k1Hz
- // TODO: Ask instrument what samplerate is in the audiofiles...
- kit._samplerate = 44100;
- }
-
- if(attr.find("description") != attr.end())
- {
- kit._description = attr.at("description");
- }
-
- if(attr.find("version") != attr.end())
- {
- try
- {
- kit._version = VersionStr(attr.at("version"));
- }
- catch(const char *err)
- {
- ERR(kitparser, "Error parsing version number: %s, using 1.0\n", err);
- kit._version = VersionStr(1,0,0);
- }
- }
- else
- {
- WARN(kitparser, "Missing version number, assuming 1.0\n");
- kit._version = VersionStr(1,0,0);
- }
- }
-
- if(name == "channels")
- {
-
- }
-
- if(name == "channel")
- {
- if(attr.find("name") == attr.end())
- {
- ERR(kitparser, "Missing channel name.\n");
- return;
- }
-
- Channel c(attr.at("name"));
- c.num = kit.channels.size();
- kit.channels.push_back(c);
- }
-
- if(name == "instruments")
- {
-
- }
-
- if(name == "instrument")
- {
- if(attr.find("name") == attr.end())
- {
- ERR(kitparser, "Missing name in instrument tag.\n");
- return;
- }
-
- if(attr.find("file") == attr.end())
- {
- ERR(kitparser, "Missing file in instrument tag.\n");
- return;
- }
-
- instr_name = attr.at("name");
- instr_file = attr.at("file");
- if(attr.find("group") != attr.end())
- {
- instr_group = attr.at("group");
- }
- else
- {
- instr_group = "";
- }
- }
-
- if(name == "channelmap")
- {
- if(attr.find("in") == attr.end())
- {
- ERR(kitparser, "Missing 'in' in channelmap tag.\n");
- return;
- }
-
- if(attr.find("out") == attr.end())
- {
- ERR(kitparser, "Missing 'out' in channelmap tag.\n");
- return;
- }
-
- channel_attribute_t cattr{attr.at("out"), main_state_t::unset};
- if(attr.find("main") != attr.end())
- {
- cattr.main_state = (attr.at("main") == "true") ?
- main_state_t::is_main : main_state_t::is_not_main;
- if(cattr.main_state == main_state_t::is_main)
- {
- settings.has_bleed_control.store(true);
- }
- }
-
- channelmap[attr.at("in")] = cattr;
- }
-}
-
-void DrumKitParser::endTag(const std::string& name)
-{
- if(name == "instrument")
- {
- {
- // Scope the std::unique_ptr 'ptr' so we don't accidentally use it after
- // it is std::move'd to the instruments list.
- auto ptr = std::make_unique<Instrument>(settings, rand);
- ptr->setGroup(instr_group);
-
- InstrumentParser parser(*ptr, settings);
- parser.parseFile(path + "/" + instr_file);
-
- // Transfer ownership to the DrumKit object.
- kit.instruments.emplace_back(std::move(ptr));
- }
-
- auto& instrument = *kit.instruments.back();
-
- // Only use main attribute from drumkit file if at least one exists.
- main_state_t default_main_state = main_state_t::unset;
- for(const auto& channel: channelmap)
- {
- if(channel.second.main_state != main_state_t::unset)
- {
- default_main_state = main_state_t::is_not_main;
- }
- }
-
- // Assign kit channel numbers to instruments channels and reset
- // main_state attribute as needed.
- for(auto& instrument_channel: instrument.instrument_channels)
- {
- channel_attribute_t cattr{instrument_channel.name, main_state_t::unset};
- if(channelmap.find(instrument_channel.name) != channelmap.end())
- {
- cattr = channelmap[instrument_channel.name];
- }
-
- if(cattr.main_state == main_state_t::unset)
- {
- cattr.main_state = default_main_state;
- }
-
- if(cattr.main_state != main_state_t::unset)
- {
- instrument_channel.main = cattr.main_state;
- }
-
- for(auto cnt = 0u; cnt < kit.channels.size(); ++cnt)
- {
- if(kit.channels[cnt].name == cattr.cname)
- {
- instrument_channel.num = kit.channels[cnt].num;
- }
- }
-
- if(instrument_channel.num == NO_CHANNEL)
- {
- ERR(kitparser, "Missing channel '%s' in instrument '%s'\n",
- instrument_channel.name.c_str(), instrument.getName().c_str());
- }
- }
-
- channelmap.clear();
- }
-}
diff --git a/src/drumkitparser.h b/src/drumkitparser.h
deleted file mode 100644
index c77b1ff..0000000
--- a/src/drumkitparser.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * drumkitparser.h
- *
- * Tue Jul 22 16:24:58 CEST 2008
- * Copyright 2008 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#pragma once
-
-#include <string>
-
-#include "saxparser.h"
-#include "drumkit.h"
-#include "configfile.h"
-
-class DrumKitParser
- : public SAXParser
-{
-public:
- DrumKitParser(Settings& settings, DrumKit& kit, Random& rand);
- virtual ~DrumKitParser() = default;
-
- virtual int parseFile(const std::string& filename) override;
-
-protected:
- void startTag(const std::string& name, const attr_t& attributes) override;
- void endTag(const std::string& name) override;
-
-private:
- DrumKit& kit;
- std::string path;
-
- struct channel_attribute_t
- {
- std::string cname;
- main_state_t main_state;
- };
- std::unordered_map<std::string, channel_attribute_t> channelmap;
- std::string instr_file;
- std::string instr_name;
- std::string instr_group;
-
- ConfigFile refs;
- Settings& settings;
- Random& rand;
-};
diff --git a/src/instrument.cc b/src/instrument.cc
index c1cd4aa..05ac17d 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -56,46 +56,19 @@ bool Instrument::isValid() const
Sample* Instrument::sample(level_t level, size_t pos)
{
- Sample *sample = nullptr;
-
- if(version >= VersionStr("2.0"))
- {
- // Version 2.0
- sample = powerlist.get(level * mod);
- }
- else
- {
- // Version 1.0
- std::vector<Sample*> s = samples.get(level * mod);
- if(s.size() == 0)
- {
- return nullptr;
- }
-
- sample = rand.choose(s);
- }
-
- return sample;
-}
-
-void Instrument::addSample(level_t a, level_t b, Sample* s)
-{
- samples.insert(a, b, s);
+ return powerlist.get(level * mod);
}
void Instrument::finalise()
{
- if(version >= VersionStr("2.0"))
+ std::vector<Sample*>::iterator s = samplelist.begin();
+ while(s != samplelist.end())
{
- std::vector<Sample*>::iterator s = samplelist.begin();
- while(s != samplelist.end())
- {
- powerlist.add(*s);
- s++;
- }
-
- powerlist.finalise();
+ powerlist.add(*s);
+ s++;
}
+
+ powerlist.finalise();
}
const std::string& Instrument::getName() const
diff --git a/src/instrument.h b/src/instrument.h
index 20bcae4..ff33d6e 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -31,7 +31,6 @@
#include <memory>
#include <deque>
-#include "rangemap.h"
#include "powerlist.h"
#include "sample.h"
@@ -85,8 +84,6 @@ private:
VersionStr version;
- RangeMap<level_t, Sample*> samples;
-
void addSample(level_t a, level_t b, Sample* s);
void finalise(); ///< Signal instrument that no more samples will be added.
diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc
deleted file mode 100644
index 9a5e36d..0000000
--- a/src/instrumentparser.cc
+++ /dev/null
@@ -1,274 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * instrumentparser.cc
- *
- * Wed Mar 9 13:22:24 CET 2011
- * Copyright 2011 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "instrumentparser.h"
-
-#include <string.h>
-#include <stdio.h>
-
-#include <hugin.hpp>
-
-#include "settings.h"
-#include "cpp11fix.h"
-#include "path.h"
-
-#include "nolocale.h"
-
-InstrumentParser::InstrumentParser(Instrument& instrument, Settings& settings)
- : instrument(instrument)
- , settings(settings)
-{
-
-}
-
-int InstrumentParser::parseFile(const std::string& filename)
-{
- path = getPath(filename);
-
- return SAXParser::parseFile(filename);
-}
-
-void InstrumentParser::startTag(const std::string& name, const attr_t& attr)
-{
- if(name == "instrument")
- {
- if(attr.find("name") != attr.end())
- {
- instrument._name = attr.at("name");
- }
-
- if(attr.find("description") != attr.end())
- {
- instrument._description = attr.at("description");
- }
-
- if(attr.find("version") != attr.end())
- {
- try
- {
- instrument.version = VersionStr(attr.at("version"));
- }
- catch(const char* err)
- {
- ERR(instrparser, "Error parsing version number: %s, using 1.0\n", err);
- instrument.version = VersionStr(1,0,0);
- }
- }
- else
- {
- WARN(instrparser, "Missing version number, assuming 1.0\n");
- instrument.version = VersionStr(1,0,0);
- }
- }
-
- if(name == "channels")
- {
- }
-
- if(name == "channel")
- {
- if(attr.find("name") == attr.end())
- {
- ERR(instrparser,"Missing channel required attribute 'name'.\n");
- return;
- }
-
- InstrumentChannel* channel = addOrGetChannel(attr.at("name"));
- channel->main = main_state_t::is_not_main;
- if(attr.find("main") != attr.end())
- {
- channel->main = (attr.at("main") == "true") ?
- main_state_t::is_main : main_state_t::is_not_main;
- if(channel->main == main_state_t::is_main)
- {
- settings.has_bleed_control.store(true);
- }
- }
- }
-
- if(name == "samples")
- {
- }
-
- if(name == "sample")
- {
- if(attr.find("name") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'name'.\n");
- return;
- }
-
- float power;
- if(attr.find("power") == attr.end())
- {
- power = -1;
- }
- else
- {
- power = atof_nol(attr.at("power").c_str());
- DEBUG(instrparser, "Instrument power set to %f\n", power);
- }
-
- // TODO get rid of new or delete it properly
- sample = new Sample(attr.at("name"), power);
- }
-
- if(name == "audiofile")
- {
- if(sample == nullptr)
- {
- ERR(instrparser,"Missing Sample!\n");
- return;
- }
-
- if(attr.find("file") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'file'.\n");
- return;
- }
-
- if(attr.find("channel") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'channel'.\n");
- return;
- }
-
- std::size_t filechannel = 1; // default, override with optional attribute
- if(attr.find("filechannel") != attr.end())
- {
- filechannel = std::stoi(attr.at("filechannel"));
- if(filechannel < 1)
- {
- ERR(instrparser,"Invalid value for attribute 'filechannel'.\n");
- filechannel = 1;
- }
- }
-
- filechannel = filechannel - 1; // 1-based in file but zero-based internally.
-
- InstrumentChannel *instrument_channel = addOrGetChannel(attr.at("channel"));
-
- auto audio_file =
- std::make_unique<AudioFile>(path + "/" + attr.at("file"),
- filechannel,
- instrument_channel);
-
- sample->addAudioFile(instrument_channel, audio_file.get());
-
- // Transfer audio_file ownership to the instrument.
- instrument.audiofiles.push_back(std::move(audio_file));
- }
-
- if(name == "velocities")
- {
- }
-
- if(name == "velocity")
- {
- if(attr.find("lower") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'lower'.\n");
- return;
- }
-
- if(attr.find("upper") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'upper'.\n");
- return;
- }
-
- lower = atof_nol(attr.at("lower").c_str());
- upper = atof_nol(attr.at("upper").c_str());
- }
-
- if(name == "sampleref")
- {
- if(attr.find("name") == attr.end())
- {
- ERR(instrparser,"Missing required attribute 'name'.\n");
- return;
- }
-
- Sample* sample_ref = nullptr;
- for(auto& sample : instrument.samplelist)
- {
- if(sample->name == attr.at("name"))
- {
- sample_ref = sample;
- break;
- }
- }
-
- if(sample_ref == nullptr)
- {
- ERR(instrparser,"Sampleref pointed at non-existing sample.\n");
- return;
- }
-
- if(instrument.version == VersionStr("1.0"))
- {
- // Old "velocity group" algorithm needs this
- instrument.addSample(lower, upper, sample_ref);
- }
- }
-}
-
-void InstrumentParser::endTag(const std::string& name)
-{
- if(name == "sample")
- {
- if(sample == nullptr)
- {
- ERR(instrparser,"Missing Sample.\n");
- return;
- }
-
- instrument.samplelist.push_back(sample);
-
- sample = nullptr;
- }
-
- if(name == "instrument") {
- instrument.finalise();
- }
-}
-
-InstrumentChannel* InstrumentParser::addOrGetChannel(const std::string& name)
-{
- for(auto& channel : instrument.instrument_channels)
- {
- if(channel.name == name)
- {
- return &channel;
- }
- }
-
- instrument.instrument_channels.emplace_back(name);
- InstrumentChannel& channel = instrument.instrument_channels.back();
- channel.main = main_state_t::unset;
-
- return &channel;
-}
diff --git a/src/instrumentparser.h b/src/instrumentparser.h
deleted file mode 100644
index a40a184..0000000
--- a/src/instrumentparser.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * instrumentparser.h
- *
- * Wed Mar 9 13:22:24 CET 2011
- * Copyright 2011 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#pragma once
-
-#include "saxparser.h"
-#include "instrument.h"
-
-#include <memory>
-#include <vector>
-
-struct Settings;
-
-class InstrumentParser
- : public SAXParser
-{
-public:
- InstrumentParser(Instrument &instrument, Settings& settings);
- virtual ~InstrumentParser() = default;
-
- virtual int parseFile(const std::string& filename) override;
-
- std::vector<InstrumentChannel> channellist;
-
-protected:
- virtual void startTag(const std::string& name, const attr_t& attr) override;
- virtual void endTag(const std::string& name) override;
-
-private:
- InstrumentChannel* addOrGetChannel(const std::string& name);
-
- Instrument& instrument;
- Sample* sample{nullptr};
-
- std::string path;
-
- level_t lower{0};
- level_t upper{0};
-
- Settings& settings;
-};
diff --git a/src/rangemap.h b/src/rangemap.h
deleted file mode 100644
index e53cbe8..0000000
--- a/src/rangemap.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * rangemap.h
- *
- * Wed Sep 22 19:17:49 CEST 2010
- * Copyright 2010 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#pragma once
-
-#include <vector>
-#include <map>
-
-template <typename T1, typename T2> class RangeMap
-{
-public:
- void insert(T1 from, T1 to, T2 value);
- std::vector<T2> get(T1 from, T1 to);
- std::vector<T2> get(T1 at);
-
-private:
- friend class InstrumentParserTest;
- std::multimap<std::pair<T1, T1>, T2> values;
-};
-
-template <typename T1, typename T2>
-void RangeMap<T1, T2>::insert(T1 from, T1 to, T2 value)
-{
- if(from < to)
- {
- values.insert(std::make_pair(std::make_pair(from, to), value));
- }
- else
- {
- values.insert(std::make_pair(std::make_pair(to, from), value));
- }
-}
-
-template <typename T1, typename T2>
-std::vector<T2> RangeMap<T1, T2>::get(T1 from, T1 to)
-{
- std::vector<T2> res;
-
- typename std::multimap<std::pair<T1, T1>, T2>::iterator i = values.begin();
- while(i != values.end())
- {
- T1 a = i->first.first;
- T1 b = i->first.second;
- if((from >= a && to <= b) || // inside
- (from <= a && to >= b) || // containing
- (from <= a && to >= a && to <= b) || // overlapping lower
- (from >= a && from <= b && to >= b) // overlapping upper
- )
- {
- res.push_back(i->second);
- }
- i++;
- }
-
- return res;
-}
-
-template <typename T1, typename T2> std::vector<T2> RangeMap<T1, T2>::get(T1 at)
-{
- std::vector<T2> res;
-
- typename std::multimap<std::pair<T1, T1>, T2>::iterator i = values.begin();
- while(i != values.end())
- {
- T1 a = i->first.first;
- T1 b = i->first.second;
- if(at >= a && at <= b)
- {
- res.push_back(i->second);
- }
- i++;
- }
-
- return res;
-}
diff --git a/test/Makefile.am b/test/Makefile.am
index 1e3980a..32f158d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,7 +7,7 @@ TESTS = resource enginetest paintertest configfile audiocache \
audiocachefile audiocacheidmanager audiocacheeventhandler \
randomtest atomictest syncedsettingstest imagecachetest \
semaphoretest drumkitcreatortest bytesizeparsertest notifiertest \
- instrumentparsertest drumkitparsertest dgxmlparsertest domloadertest
+ dgxmlparsertest domloadertest
EXTRA_DIST = \
dgunit.h \
@@ -195,25 +195,6 @@ notifiertest_SOURCES = \
notifiertest.cc \
dgtest.cc
-instrumentparsertest_CXXFLAGS = -DOUTPUT=\"instrumentparsertest\" \
- -I$(top_srcdir)/src -I$(top_srcdir)/include
-instrumentparsertest_LDFLAGS = \
- $(top_srcdir)/src/libdg.la
-instrumentparsertest_SOURCES = \
- $(top_srcdir)/hugin/hugin.c \
- instrumentparsertest.cc \
- scopedfile.cc \
- dgtest.cc
-
-drumkitparsertest_CXXFLAGS = -DOUTPUT=\"drumkitparsertest\" \
- -I$(top_srcdir)/src -I$(top_srcdir)/include
-drumkitparsertest_LDFLAGS = $(top_srcdir)/src/libdg.la
-drumkitparsertest_SOURCES = \
- $(top_srcdir)/hugin/hugin.c \
- drumkitparsertest.cc \
- scopedfile.cc \
- dgtest.cc
-
dgxmlparsertest_CXXFLAGS = -DOUTPUT=\"dgxmlparsertest\" \
-I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_srcdir)/hugin \
-I$(top_srcdir)/pugixml/src
diff --git a/test/drumkitparsertest.cc b/test/drumkitparsertest.cc
deleted file mode 100644
index 10ffeb3..0000000
--- a/test/drumkitparsertest.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-/* -*- Mode: c++ -*- */
-/***************************************************************************
- * drumkitparsertest.cc
- *
- * Wed Jun 6 20:39:37 CEST 2018
- * Copyright 2018 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "dgunit.h"
-
-#include <drumkitparser.h>
-#include <drumkit.h>
-
-#include "scopedfile.h"
-
-class DrumkitParserTest
- : public DGUnit
-{
-public:
- DrumkitParserTest()
- {
- DGUNIT_TEST(DrumkitParserTest::testTest);
- }
-
- Settings settings;
- Random rand;
-
- //! This just creates some drumkit.
- void testTest()
- {
- ScopedFile scoped_instrument_file1(
- "<?xml version='1.0' encoding='UTF-8'?>\n" \
- "<instrument version=\"2.0\" name=\"Snare\">\n" \
- " <samples>\n" \
- " <sample name=\"Snare-1\" power=\"0.00985718\">\n" \
- " <audiofile channel=\"AmbLeft\" file=\"1-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight\" file=\"1-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom\" file=\"1-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop\" file=\"1-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " <sample name=\"Snare-2\" power=\"0.0124808\">\n" \
- " <audiofile channel=\"AmbLeft\" file=\"2-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight\" file=\"2-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom\" file=\"2-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop\" file=\"2-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " </samples>\n" \
- "</instrument>");
-
- ScopedFile scoped_instrument_file2(
- "<?xml version='1.0' encoding='UTF-8'?>\n" \
- "<instrument version=\"2.0\" name=\"Snare\">\n" \
- " <samples>\n" \
- " <sample name=\"Snare-1\" power=\"0.00985718\">\n" \
- " <audiofile channel=\"AmbLeft2\" file=\"1-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight2\" file=\"1-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom2\" file=\"1-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop2\" file=\"1-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " <sample name=\"Snare-2\" power=\"0.0124808\">\n" \
- " <audiofile channel=\"AmbLeft2\" file=\"2-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight2\" file=\"2-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom2\" file=\"2-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop2\" file=\"2-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " </samples>\n" \
- "</instrument>");
-
- ScopedFile scoped_file(
- std::string(
- "<?xml version='1.0' encoding='UTF-8'?>\n" \
- "<drumkit name=\"CrocellKit\" description=\"my description\" samplerate=\"48000\" version=\"2.0.0\">\n" \
- " <channels>\n" \
- " <channel name=\"AmbLeft\"/>\n" \
- " <channel name=\"AmbRight\"/>\n" \
- " <channel name=\"SnareTop\"/>\n" \
- " <channel name=\"SnareBottom\"/>\n" \
- " </channels>\n" \
- " <instruments>\n" \
- " <instrument name=\"Snare1\" file=\"") + 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" \
- " <channelmap in=\"AmbLeft2\" out=\"AmbLeft\" main=\"true\"/>\n" \
- " <channelmap in=\"AmbRight2\" out=\"AmbRight\" main=\"true\"/>\n" \
- " <channelmap in=\"SnareTop2\" out=\"SnareTop\"/>\n" \
- " <channelmap in=\"SnareBottom2\" out=\"SnareBottom\"/>\n" \
- " </instrument>\n" \
- " </instruments>\n" \
- "</drumkit>"));
-
- DrumKit drumkit;
- DrumKitParser parser(settings, drumkit, rand);
-
- DGUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename()));
-
- DGUNIT_ASSERT_EQUAL(std::size_t(2), drumkit.instruments.size());
- DGUNIT_ASSERT_EQUAL(std::size_t(4), drumkit.channels.size());
-
- DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), drumkit.channels[0].name);
- DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), drumkit.channels[1].name);
- DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), drumkit.channels[2].name);
- DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), drumkit.channels[3].name);
-
- DGUNIT_ASSERT_EQUAL(std::string("CrocellKit"), drumkit._name);
- DGUNIT_ASSERT_EQUAL(std::string("my description"), drumkit._description);
- DGUNIT_ASSERT_EQUAL(std::size_t(48000), drumkit._samplerate);
-
- DGUNIT_ASSERT(VersionStr("2.0.0") == drumkit._version);
- }
-};
-
-// Registers the fixture into the 'registry'
-static DrumkitParserTest test;
diff --git a/test/instrumentparsertest.cc b/test/instrumentparsertest.cc
deleted file mode 100644
index 2fb81d0..0000000
--- a/test/instrumentparsertest.cc
+++ /dev/null
@@ -1,158 +0,0 @@
-/* -*- Mode: c++ -*- */
-/***************************************************************************
- * instrumentparsertest.cc
- *
- * Wed Jun 6 12:11:16 CEST 2018
- * Copyright 2018 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of DrumGizmo.
- *
- * DrumGizmo is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DrumGizmo is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DrumGizmo; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "dgunit.h"
-
-#include <instrumentparser.h>
-#include "scopedfile.h"
-
-class InstrumentParserTest
- : public DGUnit
-{
-public:
- InstrumentParserTest()
- {
- DGUNIT_TEST(InstrumentParserTest::testTest);
- }
-
- Settings settings;
- Random rand;
-
- //! This just creates some drumkit.
- void testTest()
- {
- ScopedFile scoped_file(
- "<?xml version='1.0' encoding='UTF-8'?>\n" \
- "<instrument version=\"2.0\" name=\"Snare\">\n" \
- " <samples>\n" \
- " <sample name=\"Snare-1\" power=\"0.00985718\">\n" \
- " <audiofile channel=\"AmbLeft\" file=\"1-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight\" file=\"1-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom\" file=\"1-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop\" file=\"1-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " <sample name=\"Snare-2\" power=\"0.0124808\">\n" \
- " <audiofile channel=\"AmbLeft\" file=\"2-Snare.wav\" filechannel=\"1\"/>\n" \
- " <audiofile channel=\"AmbRight\" file=\"2-Snare.wav\" filechannel=\"2\"/>\n" \
- " <audiofile channel=\"SnareBottom\" file=\"2-Snare.wav\" filechannel=\"12\"/>\n" \
- " <audiofile channel=\"SnareTop\" file=\"2-Snare.wav\" filechannel=\"13\"/>\n" \
- " </sample>\n" \
- " </samples>\n" \
- "</instrument>");
- Instrument instrument(settings, rand);
- InstrumentParser parser(instrument, settings);
- DGUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename()));
-
- DGUNIT_ASSERT_EQUAL(std::string(""), instrument._group);
- DGUNIT_ASSERT_EQUAL(std::string("Snare"), instrument._name);
- DGUNIT_ASSERT_EQUAL(std::string(""), instrument._description);
-
- DGUNIT_ASSERT(VersionStr("2.0.0") == instrument.version);
-
- // NOTE: instrument.samples are the sample map belonging to version 1.0
- DGUNIT_ASSERT_EQUAL(std::size_t(2), instrument.samplelist.size());
- {
- const auto& sample = *instrument.samplelist[0];
- DGUNIT_ASSERT_EQUAL(std::string("Snare-1"), sample.name);
- DGUNIT_ASSERT_EQUAL(0.00985718f, sample.power);
- DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size());
- for(const auto& audiofile : sample.audiofiles)
- {
- DGUNIT_ASSERT_EQUAL(std::string("/tmp/1-Snare.wav"), audiofile.second->filename);
- switch(audiofile.second->filechannel)
- {
- // NOTE: Channel numbers are zero based - they are 1 based in the xml
- case 0:
- DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"),
- audiofile.second->instrument_channel->name);
- break;
- case 1:
- DGUNIT_ASSERT_EQUAL(std::string("AmbRight"),
- audiofile.second->instrument_channel->name);
- break;
- case 11:
- DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"),
- audiofile.second->instrument_channel->name);
- break;
- case 12:
- DGUNIT_ASSERT_EQUAL(std::string("SnareTop"),
- audiofile.second->instrument_channel->name);
- break;
- default:
- DGUNIT_ASSERT(false);
- break;
- }
- }
- }
-
- {
- const auto& sample = *instrument.samplelist[1];
- DGUNIT_ASSERT_EQUAL(std::string("Snare-2"), sample.name);
- DGUNIT_ASSERT_EQUAL(0.0124808f, sample.power);
- DGUNIT_ASSERT_EQUAL(std::size_t(4), sample.audiofiles.size());
- for(const auto& audiofile : sample.audiofiles)
- {
- DGUNIT_ASSERT_EQUAL(std::string("/tmp/2-Snare.wav"), audiofile.second->filename);
- switch(audiofile.second->filechannel)
- {
- // NOTE: Channel numbers are zero based - they are 1 based in the xml
- case 0:
- DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"),
- audiofile.second->instrument_channel->name);
- break;
- case 1:
- DGUNIT_ASSERT_EQUAL(std::string("AmbRight"),
- audiofile.second->instrument_channel->name);
- break;
- case 11:
- DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"),
- audiofile.second->instrument_channel->name);
- break;
- case 12:
- DGUNIT_ASSERT_EQUAL(std::string("SnareTop"),
- audiofile.second->instrument_channel->name);
- break;
- default:
- DGUNIT_ASSERT(false);
- break;
- }
- }
- }
-
-//DGUNIT_ASSERT(ref.samples.values == instrument.samples.values);
- //std::vector<Sample*> samplelist;
- //std::deque<InstrumentChannel> instrument_channels;
- //
- //size_t lastpos;
- //float mod;
- //Settings& settings;
- //Random& rand;
- //PowerList powerlist;
- }
-};
-
-// Registers the fixture into the 'registry'
-static InstrumentParserTest test;