summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2014-03-19 21:11:31 +0100
committerJonas Suhr Christensen <jsc@umbraculum.org>2014-03-19 21:11:31 +0100
commitaa656f19d015febb1174c0c91cb1711657280c70 (patch)
treebedcde25df2bd4e9f1286047d2e47071bda0d94a
parentd6f325454d47546d56525cf64c528f35f8dec430 (diff)
Using power defined in xml if any.
-rw-r--r--src/instrumentparser.cc11
-rw-r--r--src/powerlist.cc20
-rw-r--r--src/sample.cc3
-rw-r--r--src/sample.h3
4 files changed, 27 insertions, 10 deletions
diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc
index 6580b09..c66608b 100644
--- a/src/instrumentparser.cc
+++ b/src/instrumentparser.cc
@@ -79,7 +79,16 @@ void InstrumentParser::startTag(std::string name,
DEBUG(instrparser,"Missing required attribute 'name'.\n");
return;
}
- s = new Sample(attr["name"]);
+
+ float power;
+ if(attr.find("power") == attr.end()) {
+ power = -1;
+ } else {
+ power = atof(attr["power"].c_str());
+ DEBUG(instrparser, "Instrument power set to %f\n", power);
+ }
+
+ s = new Sample(attr["name"], power);
}
if(name == "audiofile") {
diff --git a/src/powerlist.cc b/src/powerlist.cc
index 4f02892..cf843a3 100644
--- a/src/powerlist.cc
+++ b/src/powerlist.cc
@@ -168,16 +168,22 @@ void PowerList::finalise()
master->load();
float power = 0;
- size_t s = 0;
- for(; s < SIZE && s < master->size; s++) {
- power += master->data[s] * master->data[s];
- }
+ if(sample->power == -1) { // Power not defined. Calculate it!
+ DEBUG(powerlist, "Calculating power\n");
+ size_t s = 0;
+ for(; s < SIZE && s < master->size; s++) {
+ power += master->data[s] * master->data[s];
+ }
- power = sqrt(power);
+ power = sqrt(power);
- if(power > power_max) power_max = power;
+ if(power > power_max) power_max = power;
- item.power = power;
+ item.power = power;
+ } else { // Power defined in xml
+ DEBUG(powerlist, "Using power from xml\n");
+ power = sample->power;
+ }
DEBUG(rand, " - power: %f\n", power);
diff --git a/src/sample.cc b/src/sample.cc
index be897c7..d50137d 100644
--- a/src/sample.cc
+++ b/src/sample.cc
@@ -31,9 +31,10 @@
#include <sndfile.h>
-Sample::Sample(std::string name)
+Sample::Sample(std::string name, float power)
{
this->name = name;
+ this->power = power;
}
Sample::~Sample()
diff --git a/src/sample.h b/src/sample.h
index cd3e111..61a3468 100644
--- a/src/sample.h
+++ b/src/sample.h
@@ -40,7 +40,7 @@ class Sample {
friend class InstrumentParser;
friend class PowerList;
public:
- Sample(std::string name);
+ Sample(std::string name, float power);
~Sample();
AudioFile *getAudioFile(InstrumentChannel *c);
@@ -49,6 +49,7 @@ private:
void addAudioFile(InstrumentChannel *c, AudioFile *a);
std::string name;
+ float power;
AudioFiles audiofiles;
};