summaryrefslogtreecommitdiff
path: root/src/instrument.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-04-16 13:33:53 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-04-16 13:33:53 +0200
commit4eb252df04ab237c8638d45bcbf028859dc6a110 (patch)
tree8bffddf62b4271336a6e0121fef8133327654000 /src/instrument.cc
parentef68248bf70a027595803b08433a7a2c74e20fd0 (diff)
parent35e804b984c28131fe13d229c5a0867762c6e8cf (diff)
Merge branch 'settings'
Diffstat (limited to 'src/instrument.cc')
-rw-r--r--src/instrument.cc82
1 files changed, 26 insertions, 56 deletions
diff --git a/src/instrument.cc b/src/instrument.cc
index 9f18233..cc052e9 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -26,15 +26,12 @@
*/
#include "instrument.h"
-#include <stdlib.h>
-#include <stdio.h>
-
#include <hugin.hpp>
#include "sample.h"
-#include "configuration.h"
-Instrument::Instrument()
+Instrument::Instrument(Settings& settings)
+ : settings(settings)
{
DEBUG(instrument, "new %p\n", this);
mod = 1.0;
@@ -45,7 +42,7 @@ Instrument::Instrument()
Instrument::~Instrument()
{
- magic = NULL;
+ magic = nullptr;
DEBUG(instrument, "delete %p\n", this);
std::vector<AudioFile*>::iterator i = audiofiles.begin();
@@ -63,16 +60,26 @@ bool Instrument::isValid() const
Sample* Instrument::sample(level_t level, size_t pos)
{
- Sample *sample = NULL;
+ // Read out all values from settings.
+ auto enable_velocity_randomiser = settings.enable_velocity_randomiser.load();
+ auto velocity_randomiser_weight = settings.velocity_randomiser_weight.load();
+ auto samplerate = settings.samplerate.load();
+ auto velocity_modifier_falloff = settings.velocity_modifier_falloff.load();
+ auto enable_velocity_modifier = settings.enable_velocity_modifier.load();
+ auto velocity_modifier_weight = settings.velocity_modifier_weight.load();
+
+ Sample *sample = nullptr;
- if(Conf::enable_velocity_modifier == false) {
+ if(enable_velocity_modifier == false)
+ {
mod = 1.0;
lastpos = 0;
}
- if(Conf::enable_velocity_randomiser) {
- float r = rand.floatInRange(-1.0*Conf::velocity_randomiser_weight,
- Conf::velocity_randomiser_weight);
+ if(enable_velocity_randomiser)
+ {
+ float r = rand.floatInRange(-1.0 * velocity_randomiser_weight,
+ velocity_randomiser_weight);
level += r;
if(level > 1.0)
{
@@ -84,9 +91,9 @@ Sample* Instrument::sample(level_t level, size_t pos)
}
}
- if(Conf::enable_velocity_modifier) {
- mod += (pos - lastpos) /
- (Conf::samplerate * Conf::velocity_modifier_falloff);
+ if(enable_velocity_modifier)
+ {
+ mod += (pos - lastpos) / (samplerate * velocity_modifier_falloff);
if(mod > 1.0)
{
mod = 1.0;
@@ -98,21 +105,22 @@ Sample* Instrument::sample(level_t level, size_t pos)
// Version 2.0
sample = powerlist.get(level * mod);
}
- else {
+ else
+ {
// Version 1.0
std::vector<Sample*> s = samples.get(level * mod);
if(s.size() == 0)
{
- return NULL;
+ return nullptr;
}
sample = rand.choose(s);
}
- if(Conf::enable_velocity_modifier)
+ if(enable_velocity_modifier)
{
lastpos = pos;
- mod *= Conf::velocity_modifier_weight;
+ mod *= velocity_modifier_weight;
}
return sample;
@@ -157,41 +165,3 @@ void Instrument::setGroup(const std::string& g)
{
_group = g;
}
-
-#ifdef TEST_INSTRUMENT
-// deps: channel.cc sample.cc audiofile.cc
-// cflags: $(SNDFILE_CFLAGS)
-// libs: $(SNDFILE_LIBS)
-#include "test.h"
-
-TEST_BEGIN;
-
-Instrument i("test");
-
-Sample* a = new Sample();
-i.addSample(0.0, 1.0, a);
-
-Sample* b = new Sample();
-i.addSample(0.0, 1.0, b);
-
-Sample* c = new Sample();
-i.addSample(1.5, 1.7, c);
-
-TEST_EQUAL(i.sample(0.0), b, "?");
-TEST_EQUAL(i.sample(0.0), a, "?");
-TEST_EQUAL(i.sample(0.0), b, "?");
-TEST_EQUAL(i.sample(0.0), b, "?");
-TEST_EQUAL(i.sample(0.0), b, "?");
-TEST_EQUAL(i.sample(0.0), b, "?");
-TEST_EQUAL(i.sample(0.0), a, "?");
-TEST_EQUAL(i.sample(0.0), a, "?");
-
-TEST_EQUAL(i.sample(2.0), NULL, "?");
-
-TEST_EQUAL(i.sample(1.6), c, "?");
-TEST_EQUAL(i.sample(1.6), c, "?");
-TEST_EQUAL(i.sample(1.6), c, "?");
-
-TEST_END;
-
-#endif /*TEST_INSTRUMENT*/