summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc10
-rw-r--r--src/drumgizmo.h8
-rw-r--r--src/drumkitloader.cc16
-rw-r--r--src/drumkitloader.h4
-rw-r--r--src/drumkitparser.cc7
-rw-r--r--src/drumkitparser.h3
-rw-r--r--src/instrument.cc76
-rw-r--r--src/instrument.h7
-rw-r--r--src/settings.h94
9 files changed, 123 insertions, 102 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 853e93d..4109249 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -46,18 +46,20 @@
#include "nolocale.h"
-DrumGizmo::DrumGizmo(AudioOutputEngine *o, AudioInputEngine *i)
+DrumGizmo::DrumGizmo(Settings& settings,
+ AudioOutputEngine *o, AudioInputEngine *i)
: MessageReceiver(MSGRCV_ENGINE)
- , loader()
+ , loader(settings)
, oe(o)
, ie(i)
, framesize(0)
, freewheel(false)
, events{}
+ , settings(settings)
{
is_stopping = false;
audioCache.init(10000); // start thread
-
+
events.reserve(1000);
}
@@ -81,7 +83,7 @@ bool DrumGizmo::loadkit(std::string file)
// Delete all Channels, Instruments, Samples and AudioFiles.
kit.clear();
- DrumKitParser parser(kit);
+ DrumKitParser parser(settings, kit);
if(parser.parseFile(file))
{
ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 632d5fc..63348da 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -50,6 +50,8 @@
#include "configfile.h"
+#include "settings.h"
+
#define MAX_NUM_CHANNELS 64
#define REFSFILE "refs.conf"
#define RESAMPLER_INPUT_BUFFER 64
@@ -58,7 +60,8 @@ class DrumGizmo
: public MessageReceiver
{
public:
- DrumGizmo(AudioOutputEngine *outputengine, AudioInputEngine *inputengine);
+ DrumGizmo(Settings& settings,
+ AudioOutputEngine *outputengine, AudioInputEngine *inputengine);
virtual ~DrumGizmo();
bool loadkit(std::string kitfile);
@@ -106,6 +109,7 @@ protected:
size_t framesize;
bool freewheel;
-
+
std::vector<event_t> events;
+ Settings& settings;
};
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index ff489ea..3cb4b68 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -31,9 +31,10 @@
#include "drumkitparser.h"
#include "drumgizmo.h"
-DrumKitLoader::DrumKitLoader()
+DrumKitLoader::DrumKitLoader(Settings& settings)
: semaphore("drumkitloader")
, framesize(0)
+ , settings(settings)
{
run();
run_semaphore.wait(); // Wait for the thread to actually start.
@@ -187,11 +188,14 @@ void DrumKitLoader::thread_main()
if(loaded % fraction == 0 || loaded == total_num_audiofiles)
{
- LoadStatusMessage *ls = new LoadStatusMessage();
- ls->number_of_files = total_num_audiofiles;
- ls->numer_of_files_loaded = loaded;
- ls->current_file = filename;
- msghandler.sendMessage(MSGRCV_UI, ls);
+ //LoadStatusMessage *ls = new LoadStatusMessage();
+ //ls->number_of_files = total_num_audiofiles;
+ //ls->numer_of_files_loaded = loaded;
+ //ls->current_file = filename;
+ //msghandler.sendMessage(MSGRCV_UI, ls);
+ settings.number_of_files.store(total_num_audiofiles);
+ settings.number_of_files_loaded.store(loaded);
+ //settings.current_file.store(filename);
}
}
diff --git a/src/drumkitloader.h b/src/drumkitloader.h
index 3656839..2410074 100644
--- a/src/drumkitloader.h
+++ b/src/drumkitloader.h
@@ -34,6 +34,7 @@
#include "mutex.h"
#include "drumkit.h"
+#include "settings.h"
//! This class is responsible for loading the drumkits in its own thread.
//! All interaction calls are simply modifying queues and not doing any
@@ -45,7 +46,7 @@ class DrumKitLoader
{
public:
//! The constrcutor starts the loader thread.
- DrumKitLoader();
+ DrumKitLoader(Settings& settings);
//! The destructor signals the thread to stop and waits to merge before
//! returning (ie. deleting the object will garantuee that the thread has
@@ -82,4 +83,5 @@ protected:
size_t fraction{1};
size_t loaded{0};
size_t framesize{0};
+ Settings& settings;
};
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index ab2cb45..09f82e8 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -34,9 +34,10 @@
#include "path.h"
#include "drumgizmo.h"
-DrumKitParser::DrumKitParser(DrumKit& kit)
- : kit(kit)
+DrumKitParser::DrumKitParser(Settings& setting, DrumKit& k)
+ : kit(k)
, refs(REFSFILE)
+ , settings(settings)
{
}
@@ -182,7 +183,7 @@ void DrumKitParser::endTag(const std::string& name)
{
if(name == "instrument")
{
- Instrument* instrument = new Instrument();
+ Instrument* instrument = new Instrument(settings);
instrument->setGroup(instr_group);
InstrumentParser parser(*instrument);
diff --git a/src/drumkitparser.h b/src/drumkitparser.h
index b0c8d8f..0adccb9 100644
--- a/src/drumkitparser.h
+++ b/src/drumkitparser.h
@@ -34,7 +34,7 @@ class DrumKitParser
: public SAXParser
{
public:
- DrumKitParser(DrumKit& kit);
+ DrumKitParser(Settings& setting, DrumKit& kit);
virtual int parseFile(const std::string& filename) override;
@@ -52,4 +52,5 @@ private:
std::string instr_group;
ConfigFile refs;
+ Settings& settings;
};
diff --git a/src/instrument.cc b/src/instrument.cc
index 9f18233..3348a4f 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -34,7 +34,8 @@
#include "sample.h"
#include "configuration.h"
-Instrument::Instrument()
+Instrument::Instrument(Settings& settings)
+ : settings(settings)
{
DEBUG(instrument, "new %p\n", this);
mod = 1.0;
@@ -65,28 +66,41 @@ Sample* Instrument::sample(level_t level, size_t pos)
{
Sample *sample = NULL;
- if(Conf::enable_velocity_modifier == false) {
+ // 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();
+
+ 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 = (float)rand() / (float)RAND_MAX; // random number: [0;1]
+ r -= 0.5; // random number [-0.5;0.5]
+ r *= velocity_randomiser_weight * 2; // ex. random number [-0.1;0.1]
level += r;
if(level > 1.0)
{
level = 1.0;
}
+
if(level < 0.0)
{
level = 0.0;
}
}
- if(Conf::enable_velocity_modifier) {
+ if(enable_velocity_modifier)
+ {
mod += (pos - lastpos) /
- (Conf::samplerate * Conf::velocity_modifier_falloff);
+ (samplerate * velocity_modifier_falloff);
if(mod > 1.0)
{
mod = 1.0;
@@ -98,7 +112,8 @@ 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)
@@ -106,13 +121,14 @@ Sample* Instrument::sample(level_t level, size_t pos)
return NULL;
}
- sample = rand.choose(s);
+ size_t idx = rand()%(s.size());
+ sample = s[idx];
}
- if(Conf::enable_velocity_modifier)
+ if(enable_velocity_modifier)
{
lastpos = pos;
- mod *= Conf::velocity_modifier_weight;
+ mod *= velocity_modifier_weight;
}
return sample;
@@ -157,41 +173,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*/
diff --git a/src/instrument.h b/src/instrument.h
index de5546b..7c8c52d 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -36,13 +36,14 @@
#include "versionstr.h"
#include "random.h"
-class InstrumentParser;
+#include "settings.h"
+
class Instrument
{
friend class InstrumentParser;
public:
- Instrument();
+ Instrument(Settings& settings);
~Instrument();
Sample* sample(level_t level, size_t pos);
@@ -78,6 +79,8 @@ private:
size_t lastpos;
float mod;
+ Settings& settings;
+};
Random rand;
};
diff --git a/src/settings.h b/src/settings.h
index 74c432d..4eb7dba 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -27,14 +27,40 @@
#pragma once
#include <atomic>
+#include <string>
#include <cassert>
+class MyString {
+public:
+ std::string value;
+};
+
+//! Engine settings
+struct Settings
+{
+ std::atomic<bool> enable_velocity_modifier;
+ std::atomic<float> velocity_modifier_falloff;
+ std::atomic<float> velocity_modifier_weight;
+
+ std::atomic<bool> enable_velocity_randomiser;
+ std::atomic<float> velocity_randomiser_weight;
+
+ std::atomic<double> samplerate;
+
+ std::atomic<bool> enable_resampling;
+
+ std::atomic<int> number_of_files;
+ std::atomic<int> number_of_files_loaded;
+ //std::atomic<std::string> current_file;
+
+};
+
+//! Getter utility class.
template <typename T> class SettingRef
{
public:
SettingRef(std::atomic<T>& value)
- : value{value}
- , cache{}
+ : value(value)
{
// string isn't lock free either
assert((std::is_same<T, std::string>::value || value.is_lock_free()));
@@ -57,20 +83,7 @@ private:
std::atomic<T> cache;
};
-struct Settings
-{
- std::atomic<bool> enable_velocity_modifier;
- std::atomic<float> velocity_modifier_falloff;
- std::atomic<float> velocity_modifier_weight;
-
- std::atomic<bool> enable_velocity_randomiser;
- std::atomic<float> velocity_randomiser_weight;
-
- std::atomic<int> samplerate;
-
- std::atomic<bool> enable_resampling;
-};
-
+//! Combined getter class.
struct SettingsGetter
{
SettingRef<bool> enable_velocity_modifier;
@@ -80,10 +93,14 @@ struct SettingsGetter
SettingRef<bool> enable_velocity_randomiser;
SettingRef<float> velocity_randomiser_weight;
- SettingRef<int> samplerate;
+ SettingRef<double> samplerate;
SettingRef<bool> enable_resampling;
+ SettingRef<int> number_of_files;
+ SettingRef<int> number_of_files_loaded;
+ //SettingRef<std::string> current_file;
+
SettingsGetter(Settings& settings)
: enable_velocity_modifier{settings.enable_velocity_modifier}
, velocity_modifier_falloff{settings.velocity_modifier_falloff}
@@ -92,6 +109,9 @@ struct SettingsGetter
, velocity_randomiser_weight{settings.velocity_randomiser_weight}
, samplerate{settings.samplerate}
, enable_resampling{settings.enable_resampling}
+ , number_of_files{settings.number_of_files}
+ , number_of_files_loaded{settings.number_of_files_loaded}
+ //, current_file{settings.current_file}
{
}
};
@@ -99,29 +119,35 @@ struct SettingsGetter
// lovely reminder: NO, GLOCKE. NOOOO!!
/*
enum class IntParams {
- Foo = 0
+ Foo = 0
};
-struct Settings {
- std::array<std::atomic<int>, 5> ints;
+struct Settings
+{
+ std::array<std::atomic<int>, 5> ints;
- Settings()
- : ints{} {
- //get(IntParams::Foo).store(3);
- }
+ Settings()
+ : ints{}
+ {
+ //get(IntParams::Foo).store(3);
+ }
- std::atomic<int>& get(IntParams param) {
- return ints[(size_t)param];
- }
+ std::atomic<int>& get(IntParams param)
+ {
+ return ints[(size_t)param];
+ }
};
-struct SettingsGetter {
- std::vector<SettingRef<int>> ints;
+struct SettingsGetter
+{
+ std::vector<SettingRef<int>> ints;
- SettingsGetter(Settings& parent) {
- for (auto& atomic: parent.ints) {
- ints.emplace_back(atomic);
- }
- }
+ SettingsGetter(Settings& parent)
+ {
+ for(auto& atomic: parent.ints)
+ {
+ ints.emplace_back(atomic);
+ }
+ }
};
*/