summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drumgizmo.cc9
-rw-r--r--src/drumgizmo.h3
-rw-r--r--src/drumkitloader.cc6
-rw-r--r--src/drumkitloader.h3
-rw-r--r--src/drumkitparser.cc5
-rw-r--r--src/drumkitparser.h3
-rw-r--r--src/instrument.cc4
-rw-r--r--src/instrument.h6
-rw-r--r--src/powerlist.cc3
-rw-r--r--src/powerlist.h4
-rw-r--r--src/random.cc6
-rw-r--r--src/random.h2
-rw-r--r--src/velocity.cc3
-rw-r--r--src/velocity.h4
14 files changed, 43 insertions, 18 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 1ccefc5..7d9d88c 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -50,7 +50,7 @@
DrumGizmo::DrumGizmo(Settings& settings,
AudioOutputEngine *o, AudioInputEngine *i)
- : loader(settings, kit, *i, resamplers)
+ : loader(settings, kit, *i, resamplers, rand)
, oe(o)
, ie(i)
, kit()
@@ -115,6 +115,11 @@ void DrumGizmo::setFreeWheel(bool freewheel)
}
}
+void DrumGizmo::setRandomSeed(unsigned int seed)
+{
+ rand.setSeed(seed);
+}
+
void DrumGizmo::run(int endpos)
{
size_t pos = 0;
@@ -143,6 +148,8 @@ void DrumGizmo::run(int endpos)
bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
{
+ std::lock_guard<std::mutex> guard(resamplers.mutex);
+
setFrameSize(nsamples);
ie->pre();
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index e25db2f..ea04603 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -70,6 +70,8 @@ public:
void setFreeWheel(bool freewheel);
+ void setRandomSeed(unsigned int seed);
+
private:
static constexpr int MAX_NUM_CHANNELS = 64;
static constexpr int RESAMPLER_OUTPUT_BUFFER = 4096;
@@ -101,4 +103,5 @@ protected:
std::vector<event_t> events;
Settings& settings;
SettingsGetter getter{settings};
+ Random rand;
};
diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc
index a9b87f0..814a98d 100644
--- a/src/drumkitloader.cc
+++ b/src/drumkitloader.cc
@@ -36,12 +36,14 @@
DrumKitLoader::DrumKitLoader(Settings& settings, DrumKit& kit,
AudioInputEngine& ie,
- Resamplers& resamplers)
+ Resamplers& resamplers,
+ Random& rand)
: settings(settings)
, getter(settings)
, kit(kit)
, ie(ie)
, resamplers(resamplers)
+ , rand(rand)
{
run();
run_semaphore.wait(); // Wait for the thread to actually start.
@@ -80,7 +82,7 @@ bool DrumKitLoader::loadkit(const std::string& file)
settings.drumkit_load_status.store(LoadStatus::Loading);
- DrumKitParser parser(settings, kit);
+ DrumKitParser parser(settings, kit, rand);
if(parser.parseFile(file))
{
ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
diff --git a/src/drumkitloader.h b/src/drumkitloader.h
index f99f439..cca11af 100644
--- a/src/drumkitloader.h
+++ b/src/drumkitloader.h
@@ -51,7 +51,7 @@ class DrumKitLoader
public:
//! The constrcutor starts the loader thread.
DrumKitLoader(Settings& settings, DrumKit& kit, AudioInputEngine& ie,
- Resamplers& resamplers);
+ Resamplers& resamplers, Random& rand);
//! The destructor signals the thread to stop and waits to merge before
//! returning (ie. deleting the object will garantuee that the thread has
@@ -91,4 +91,5 @@ protected:
AudioInputEngine& ie;
Resamplers& resamplers;
MemChecker memchecker;
+ Random& rand;
};
diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc
index 048a05b..073d240 100644
--- a/src/drumkitparser.cc
+++ b/src/drumkitparser.cc
@@ -34,10 +34,11 @@
#include "path.h"
#include "drumgizmo.h"
-DrumKitParser::DrumKitParser(Settings& settings, DrumKit& k)
+DrumKitParser::DrumKitParser(Settings& settings, DrumKit& k, Random& rand)
: kit(k)
, refs(REFSFILE)
, settings(settings)
+ , rand(rand)
{
}
@@ -183,7 +184,7 @@ void DrumKitParser::endTag(const std::string& name)
{
if(name == "instrument")
{
- Instrument* instrument = new Instrument(settings);
+ Instrument* instrument = new Instrument(settings, rand);
instrument->setGroup(instr_group);
InstrumentParser parser(*instrument);
diff --git a/src/drumkitparser.h b/src/drumkitparser.h
index 0adccb9..444b459 100644
--- a/src/drumkitparser.h
+++ b/src/drumkitparser.h
@@ -34,7 +34,7 @@ class DrumKitParser
: public SAXParser
{
public:
- DrumKitParser(Settings& setting, DrumKit& kit);
+ DrumKitParser(Settings& setting, DrumKit& kit, Random& rand);
virtual int parseFile(const std::string& filename) override;
@@ -53,4 +53,5 @@ private:
ConfigFile refs;
Settings& settings;
+ Random& rand;
};
diff --git a/src/instrument.cc b/src/instrument.cc
index cc052e9..9a4c0b7 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -30,8 +30,10 @@
#include "sample.h"
-Instrument::Instrument(Settings& settings)
+Instrument::Instrument(Settings& settings, Random& rand)
: settings(settings)
+ , rand(rand)
+ , powerlist(rand)
{
DEBUG(instrument, "new %p\n", this);
mod = 1.0;
diff --git a/src/instrument.h b/src/instrument.h
index a531aec..621dddb 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -42,7 +42,7 @@ class Instrument
{
friend class InstrumentParser;
public:
- Instrument(Settings& settings);
+ Instrument(Settings& settings, Random& rand);
~Instrument();
Sample* sample(level_t level, size_t pos);
@@ -69,7 +69,6 @@ private:
VersionStr version;
RangeMap<level_t, Sample*> samples;
- PowerList powerlist;
void addSample(level_t a, level_t b, Sample* s);
void finalise(); ///< Signal instrument that no more samples will be added.
@@ -79,7 +78,8 @@ private:
size_t lastpos;
float mod;
Settings& settings;
- Random rand;
+ Random& rand;
+ PowerList powerlist;
};
// typedef std::map< std::string, Instrument > Instruments;
diff --git a/src/powerlist.cc b/src/powerlist.cc
index f94dbb2..8fec8ce 100644
--- a/src/powerlist.cc
+++ b/src/powerlist.cc
@@ -51,7 +51,8 @@
#define SIZE 500
-PowerList::PowerList()
+PowerList::PowerList(Random& rand)
+ : rand(rand)
{
power_max = 0;
power_min = 100000000;
diff --git a/src/powerlist.h b/src/powerlist.h
index a3af475..53a42b8 100644
--- a/src/powerlist.h
+++ b/src/powerlist.h
@@ -34,7 +34,7 @@
class PowerList
{
public:
- PowerList();
+ PowerList(Random& rand);
void add(Sample* s);
void finalise(); ///< Call this when no more samples will be added.
@@ -49,7 +49,7 @@ private:
float power;
};
- Random rand;
+ Random& rand;
std::vector<PowerListItem> samples;
float power_max;
diff --git a/src/random.cc b/src/random.cc
index 1df9a62..3d94a25 100644
--- a/src/random.cc
+++ b/src/random.cc
@@ -31,11 +31,15 @@
Random::Random()
: Random(std::chrono::system_clock::now().time_since_epoch().count())
{
-
}
Random::Random(unsigned int seed)
{
+ setSeed(seed);
+}
+
+void Random::setSeed(unsigned int seed)
+{
generator.seed(seed);
}
diff --git a/src/random.h b/src/random.h
index 9eaefad..c7fd599 100644
--- a/src/random.h
+++ b/src/random.h
@@ -35,6 +35,8 @@ public:
Random();
Random(unsigned int seed);
+ void setSeed(unsigned int seed);
+
//! \return random int in range [<lower_bound>, <upper_bound>].
int intInRange(int lower_bound, int upper_bound);
diff --git a/src/velocity.cc b/src/velocity.cc
index c8faa32..2d9bf8f 100644
--- a/src/velocity.cc
+++ b/src/velocity.cc
@@ -28,10 +28,11 @@
#include <stdlib.h>
-Velocity::Velocity(unsigned int lower, unsigned int upper)
+Velocity::Velocity(unsigned int lower, unsigned int upper, Random& rand)
: lower{lower}
, upper{upper}
, samples{}
+ , rand(rand)
{
}
diff --git a/src/velocity.h b/src/velocity.h
index 19284a4..8392494 100644
--- a/src/velocity.h
+++ b/src/velocity.h
@@ -34,7 +34,7 @@
class Velocity
{
public:
- Velocity(unsigned int lower, unsigned int upper);
+ Velocity(unsigned int lower, unsigned int upper, Random& rand);
void addSample(Sample* sample, float probability);
Sample* getSample();
@@ -46,5 +46,5 @@ private:
typedef std::map<Sample*, float> Samples;
Samples samples;
- Random rand;
+ Random& rand;
};