summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-10-10 17:31:35 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2019-10-14 22:04:13 +0200
commit05270cd4abe1cc61fb680b801676436f10069413 (patch)
tree7bf77d0753c8a9822c2a7ff06016c8f73cddb186
parent1f7d744819968aec3c82035f730558cb73e0bd18 (diff)
Added 'normalized' attribute to sample tag.
-rw-r--r--src/DGDOM.h1
-rw-r--r--src/dgxmlparser.cc13
-rw-r--r--src/domloader.cc3
-rw-r--r--src/inputprocessor.cc4
-rw-r--r--src/sample.cc8
-rw-r--r--src/sample.h4
6 files changed, 28 insertions, 5 deletions
diff --git a/src/DGDOM.h b/src/DGDOM.h
index 1adf391..b6c52ac 100644
--- a/src/DGDOM.h
+++ b/src/DGDOM.h
@@ -59,6 +59,7 @@ struct SampleDOM
{
std::string name;
double power; // >= v2.0 only
+ bool normalized; // >= v2.0 only
std::vector<AudioFileDOM> audiofiles;
};
diff --git a/src/dgxmlparser.cc b/src/dgxmlparser.cc
index 7f62a64..b924cc8 100644
--- a/src/dgxmlparser.cc
+++ b/src/dgxmlparser.cc
@@ -94,6 +94,17 @@ static bool assign(main_state_t& dest, const std::string& val)
return true;
}
+static bool assign(bool& dest, const std::string& val)
+{
+ if(val == "true" || val == "false")
+ {
+ dest = val == "true";
+ return true;
+ }
+
+ return false;
+}
+
template<typename T>
static bool attrcpy(T& dest, const pugi::xml_node& src, const std::string& attr, LogFunction logger, const std::string& filename, bool opt = false)
{
@@ -343,6 +354,8 @@ bool parseInstrumentFile(const std::string& filename, InstrumentDOM& dom, LogFun
else
{
res &= attrcpy(dom.samples.back().power, sample, "power", logger, filename);
+ dom.samples.back().normalized = false;
+ res &= attrcpy(dom.samples.back().normalized, sample, "normalized", logger, filename, true);
}
for(pugi::xml_node audiofile: sample.children("audiofile"))
diff --git a/src/domloader.cc b/src/domloader.cc
index a718ade..97c1d6b 100644
--- a/src/domloader.cc
+++ b/src/domloader.cc
@@ -98,7 +98,8 @@ bool DOMLoader::loadDom(const std::string& basepath,
auto path = getPath(basepath + "/" + instrumentref.file);
for(const auto& sampledom : instrumentdom.samples)
{
- auto sample = new Sample(sampledom.name, sampledom.power);
+ auto sample = new Sample(sampledom.name, sampledom.power,
+ sampledom.normalized);
for(const auto& audiofiledom : sampledom.audiofiles)
{
InstrumentChannel *instrument_channel =
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index eb45f4b..e8f4cc7 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -208,9 +208,9 @@ bool InputProcessor::processOnset(event_t& event,
{
//DEBUG(inputprocessor, "Adding event %d.\n", event.offset);
auto evt = new EventSample(ch.num, 1.0, af, instr->getGroup(),
- instrument_id);
+ instrument_id);
evt->offset = (event.offset + pos) * resample_ratio;
- if(settings.normalized_samples.load())
+ if(settings.normalized_samples.load() && sample->getNormalized())
{
evt->scale *= event.velocity;
}
diff --git a/src/sample.cc b/src/sample.cc
index 4d0443d..9af2c08 100644
--- a/src/sample.cc
+++ b/src/sample.cc
@@ -28,9 +28,10 @@
#include <sndfile.h>
-Sample::Sample(const std::string& name, double power)
+Sample::Sample(const std::string& name, double power, bool normalized)
: name{name}
, power{power}
+ , normalized(normalized)
, audiofiles{}
{
}
@@ -67,3 +68,8 @@ double Sample::getPower() const
{
return power;
}
+
+bool Sample::getNormalized() const
+{
+ return normalized;
+}
diff --git a/src/sample.h b/src/sample.h
index 223648f..6c31b6b 100644
--- a/src/sample.h
+++ b/src/sample.h
@@ -37,12 +37,13 @@ using AudioFiles = std::map<const InstrumentChannel*, AudioFile*>;
class Sample
{
public:
- Sample(const std::string& name, double power);
+ Sample(const std::string& name, double power, bool normalized = false);
~Sample();
AudioFile* getAudioFile(const Channel& channel) const;
double getPower() const;
+ bool getNormalized() const;
private:
friend class DOMLoader;
@@ -54,5 +55,6 @@ private:
std::string name;
double power;
+ bool normalized;
AudioFiles audiofiles;
};