summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2024-08-04 09:21:22 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2024-08-04 09:21:22 +0200
commite84e9938345bb124eb2d47a73fb324e95ac652be (patch)
treec319a12e7e1729e6d6821b415d3f812c7dd81224 /src
parentaf48a660a3410c3a63cab324fd8a345b648f821d (diff)
Diffstat (limited to 'src')
-rw-r--r--src/DGDOM.h2
-rw-r--r--src/dgxmlparser.cc4
-rw-r--r--src/inputprocessor.cc9
-rw-r--r--src/instrument.cc23
-rw-r--r--src/instrument.h5
-rw-r--r--src/sample_selection.cc10
-rw-r--r--src/sample_selection.h3
7 files changed, 43 insertions, 13 deletions
diff --git a/src/DGDOM.h b/src/DGDOM.h
index a03f0ef..b4e861f 100644
--- a/src/DGDOM.h
+++ b/src/DGDOM.h
@@ -59,7 +59,7 @@ struct SampleDOM
{
std::string name;
double power; // >= v2.0 only
- double position; // >=v2.0 only
+ double position; // >= v2.0 only
bool normalized; // >= v2.0 only
std::vector<AudioFileDOM> audiofiles;
};
diff --git a/src/dgxmlparser.cc b/src/dgxmlparser.cc
index bd9af66..837cc4e 100644
--- a/src/dgxmlparser.cc
+++ b/src/dgxmlparser.cc
@@ -365,8 +365,8 @@ bool parseInstrumentFile(const std::string& filename, InstrumentDOM& dom, LogFun
res &= attrcpy(dom.samples.back().position, sample, "position",
logger, filename, true);
// Clamp to [0; 1] range.
- dom.samples.back().position =
- std::min(1.0, std::max(dom.samples.back().position, 0.0));
+ //dom.samples.back().position =
+ // std::min(1.0, std::max(dom.samples.back().position, 0.0));
dom.samples.back().normalized = false; // optional - defaults to false
res &= attrcpy(dom.samples.back().normalized, sample, "normalized",
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index 67a0ec2..29c4ac5 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -37,7 +37,7 @@
#include "staminafilter.h"
#include "velocityfilter.h"
#include "positionfilter.h"
-
+#include <iostream>
#include "cpp11fix.h"
class VelocityStorer
@@ -252,7 +252,12 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos,
const auto power_range = instr->getPowers(event.position);
const auto power_span = power_range.max - power_range.min;
const auto note_power = power_range.min + event.velocity * power_span;
- const auto sample = instr->sample(note_power, power_span, event.position, event.offset + pos);
+
+ const auto position_range = instr->getPositionRange();
+ const auto position_span = position_range.max - position_range.min;
+ const auto note_position = position_range.min + event.position * position_span;
+
+ const auto sample = instr->sample(note_power, power_span, note_position, position_span, event.offset + pos);
if(sample == nullptr)
{
diff --git a/src/instrument.cc b/src/instrument.cc
index 07b3ddf..af96ab6 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -55,12 +55,14 @@ bool Instrument::isValid() const
}
// FIXME: very bad variable naming of parameters
-const Sample* Instrument::sample(float power, float instrument_power_range, float position, std::size_t pos)
+const Sample* Instrument::sample(float power, float instrument_power_range, float position,
+ float instrument_position_range, std::size_t pos)
{
if(version >= VersionStr("2.0"))
{
// Version 2.0
- return sample_selection.get(power, instrument_power_range, position, pos);
+ return sample_selection.get(power, instrument_power_range,
+ position, instrument_position_range, pos);
}
else
{
@@ -93,6 +95,18 @@ void Instrument::finalise()
powerlist.finalise();
sample_selection.finalise();
+
+ position_range.min = std::numeric_limits<double>::max();
+ position_range.max = std::numeric_limits<double>::min();
+ if(samplelist.empty())
+ {
+ position_range = {0,1};
+ }
+ for(const auto& sample : samplelist)
+ {
+ position_range.min = std::min(sample->getPosition(), position_range.min);
+ position_range.max = std::max(sample->getPosition(), position_range.max);
+ }
}
}
@@ -142,6 +156,11 @@ Instrument::PowerRange Instrument::getPowers(float position) const
}
}
+Instrument::PowerRange Instrument::getPositionRange() const
+{
+ return position_range;
+}
+
const std::vector<Choke>& Instrument::getChokes()
{
return chokes;
diff --git a/src/instrument.h b/src/instrument.h
index 5f79882..35f4e5b 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -50,7 +50,8 @@ public:
~Instrument();
// FIXME: variable naming
- const Sample* sample(float power, float instrument_power_range, float position, std::size_t pos);
+ const Sample* sample(float power, float instrument_power_range, float position,
+ float instrument_position_range, std::size_t pos);
std::size_t getID() const;
const std::string& getName() const;
@@ -74,6 +75,7 @@ public:
double max;
};
PowerRange getPowers(float position) const;
+ PowerRange getPositionRange() const;
const std::vector<Choke>& getChokes();
@@ -107,6 +109,7 @@ private:
PowerList powerlist;
std::vector<Choke> chokes;
SampleSelection sample_selection;
+ PowerRange position_range{};
};
using Instruments = std::vector<std::unique_ptr<Instrument>>;
diff --git a/src/sample_selection.cc b/src/sample_selection.cc
index 4bd1979..5c19ae1 100644
--- a/src/sample_selection.cc
+++ b/src/sample_selection.cc
@@ -33,6 +33,7 @@
#include "settings.h"
#include <algorithm>
+#include <iostream>
namespace
{
@@ -58,7 +59,8 @@ void SampleSelection::finalise()
// FIXME: For the position, weird hacks via the powerlist are necessary. Refactor!
// FIXME: bad variable naming
-const Sample* SampleSelection::get(float power, float instrument_power_span, float position, std::size_t pos)
+const Sample* SampleSelection::get(float power, float instrument_power_span,
+ float position, float instrument_positon_span, std::size_t pos)
{
const auto& samples = powerlist.getPowerListItems();
if(!samples.size())
@@ -75,7 +77,7 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo
float closepos_opt = 0.;
float random_opt = 0.;
float diverse_opt = 0.;
-
+ std::cout << "Input position: " << position << " power: " << power << "\n";
// Note the magic values in front of the settings factors.
const float f_close = 4.*settings.sample_selection_f_close.load();
const float f_position = 4.*settings.sample_selection_f_position.load();
@@ -148,7 +150,7 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo
auto random = rand.floatInRange(0.,1.);
auto close = (samples[current_index].power - power)/instrument_power_span;
auto diverse = 1./(1. + (float)(pos - last[current_index])/settings.samplerate);
- auto closepos = samples[current_index].sample->getPosition() - position;
+ auto closepos = (samples[current_index].sample->getPosition() - position) / instrument_positon_span;
// note that the value below for close and closepos is actually the weighted squared l2 distance in 2d
auto value = f_close*pow2(close) + f_position*pow2(closepos) + f_diverse*diverse + f_random*random;
@@ -172,7 +174,7 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo
auto random = rand.floatInRange(0.,1.);
auto close = (samples[current_index].power - power)/instrument_power_span;
auto diverse = 1./(1. + (float)(pos - last[current_index])/settings.samplerate);
- auto closepos = samples[current_index].sample->getPosition() - position;
+ auto closepos = (samples[current_index].sample->getPosition() - position) / instrument_positon_span;
// note that the value below for close and closepos is actually the weighted squared l2 distance in 2d
auto value = f_close*pow2(close) + f_position*pow2(closepos) + f_diverse*diverse + f_random*random;
diff --git a/src/sample_selection.h b/src/sample_selection.h
index c7ac709..be93bd8 100644
--- a/src/sample_selection.h
+++ b/src/sample_selection.h
@@ -40,7 +40,8 @@ public:
SampleSelection(Settings& settings, Random& rand, const PowerList& powerlist);
void finalise();
- const Sample* get(float power, float instrument_power_span, float position, std::size_t pos);
+ const Sample* get(float power, float instrument_power_span, float position,
+ float instrument_position_span, std::size_t pos);
private:
Settings& settings;