summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy35
-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.cc33
-rw-r--r--src/sample_selection.h3
-rw-r--r--src/settings.h2
9 files changed, 103 insertions, 13 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..d3437d7
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,35 @@
+---
+Checks: "*,
+ -abseil-*,
+ -altera-*,
+ -android-*,
+ -fuchsia-*,
+ -google-*,
+ -llvm*,
+ -modernize-use-trailing-return-type,
+ -zircon-*,
+ -readability-else-after-return,
+ -readability-static-accessed-through-instance,
+ -readability-avoid-const-params-in-decls,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -misc-non-private-member-variables-in-classes,
+ -misc-include-cleaner,
+ -cppcoreguidelines-avoid-do-while,
+ -bugprone-easily-swappable-parameters,
+ -hicpp-uppercase-literal-suffix,
+ -readability-uppercase-literal-suffix,
+"
+WarningsAsErrors: ''
+HeaderFilterRegex: ''
+FormatStyle: none
+
+CheckOptions:
+ - key: readability-identifier-length.IgnoredVariableNames
+ value: 'x|y|z'
+ - key: readability-identifier-length.IgnoredParameterNames
+ value: 'x|y|z'
+
+
+
+
+
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 b7b6bcd..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();
@@ -89,6 +91,7 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo
instrument_power_span = 1.0;
}
+#if 0
// start with most promising power value and then stop when reaching far values
// which cannot become opt anymore
auto closest_it = std::lower_bound(samples.begin(), samples.end(), power);
@@ -147,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;
@@ -165,6 +168,30 @@ const Sample* SampleSelection::get(float power, float instrument_power_span, flo
++count;
}
while (up_value_lb <= value_opt || down_value_lb <= value_opt);
+#else
+ for(std::size_t current_index = 0; current_index < samples.size(); ++current_index)
+ {
+ 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) / 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;
+
+ if (value < value_opt)
+ {
+ index_opt = current_index;
+ power_opt = samples[current_index].power;
+ pos_opt = samples[current_index].sample->getPosition();
+ value_opt = value;
+ random_opt = random;
+ close_opt = close;
+ diverse_opt = diverse;
+ closepos_opt = closepos;
+ }
+ }
+ int count{}; // not used
+#endif
DEBUG(rand, "Chose sample with index: %d, value: %f, power: %f, position: %f, random: %f, close: %f, diverse: %f, closepos: %f, count: %d", (int)index_opt, value_opt, power_opt, pos_opt, random_opt, close_opt, diverse_opt, closepos_opt, (int)count);
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;
diff --git a/src/settings.h b/src/settings.h
index 58b17f3..074c7bc 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -78,7 +78,7 @@ struct Settings
static float constexpr velocity_stddev_default = .45f;
static float constexpr position_stddev_default = .45f;
static float constexpr sample_selection_f_close_default = .85f;
- static float constexpr sample_selection_f_position_default = .016f;
+ static float constexpr sample_selection_f_position_default = .85f;
static float constexpr sample_selection_f_diverse_default = .16f;
static float constexpr sample_selection_f_random_default = .07f;
Atomic<float> velocity_modifier_falloff{velocity_modifier_falloff_default};