summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-04-05 10:15:47 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2023-04-05 10:15:47 +0200
commitdb3f435e27d06d889871860c81aeb139eeff53d5 (patch)
tree726bfa4927c51b838201b51fc60de373351667be
parent00aea74f7f0a3c3759d7d807002cc5ca19ec0593 (diff)
-rw-r--r--src/inputprocessor.cc7
-rw-r--r--src/instrument.cc18
-rw-r--r--src/instrument.h11
-rw-r--r--src/powerlist.h10
-rw-r--r--src/sample_selection.cc4
5 files changed, 25 insertions, 25 deletions
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index fa3498c..7679e82 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -249,10 +249,9 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos,
// Apply directed chokes to mute other instruments if needed
applyDirectedChoke(settings, kit, *instr, event, events_ds, pos);
- auto const power_max = instr->getMaxPower();
- auto const power_min = instr->getMinPower();
- float const power_span = power_max - power_min;
- float const instrument_level = power_min + event.velocity*power_span;
+ auto power = instr->getPowers(event.position);
+ const float power_span = power.max - power.min;
+ const float instrument_level = power.min + event.velocity * power_span;
// FIXME: bad variable naming of parameters
const auto sample = instr->sample(instrument_level, event.position, event.offset + pos);
diff --git a/src/instrument.cc b/src/instrument.cc
index ac6aa28..30f3423 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -130,27 +130,15 @@ std::size_t Instrument::getNumberOfFiles() const
return audiofiles.size();
}
-float Instrument::getMaxPower() const
+Instrument::PowerRange Instrument::getPowers(float position) const
{
if(version >= VersionStr("2.0"))
{
- return powerlist.getMaxPower();
+ return { powerlist.getMaxPower(), powerlist.getMaxPower() };
}
else
{
- return 1.0f;
- }
-}
-
-float Instrument::getMinPower() const
-{
- if(version >= VersionStr("2.0"))
- {
- return powerlist.getMinPower();
- }
- else
- {
- return 0.0f;
+ return { 0.0f, 1.0f };
}
}
diff --git a/src/instrument.h b/src/instrument.h
index 89918de..49a9a74 100644
--- a/src/instrument.h
+++ b/src/instrument.h
@@ -68,8 +68,15 @@ public:
//! Get the number of audio files (as in single channel) in this instrument.
std::size_t getNumberOfFiles() const;
- float getMaxPower() const;
- float getMinPower() const;
+ struct PowerRange
+ {
+ float min;
+ float max;
+ };
+ PowerRange getPowers(float position) const;
+
+ //float getMaxPower() const;
+ //float getMinPower() const;
const std::vector<Choke>& getChokes();
diff --git a/src/powerlist.h b/src/powerlist.h
index ffbd6ba..b1fd1fd 100644
--- a/src/powerlist.h
+++ b/src/powerlist.h
@@ -44,7 +44,13 @@ struct PowerListItem
return this->power < power;
}
};
-using PowerListItems = std::vector<PowerListItem>;
+class PowerListItems
+ : public std::vector<PowerListItem>
+{
+public:
+ float getMaxPower() const;
+ float getMinPower() const;
+};
class PowerList
{
@@ -54,7 +60,7 @@ public:
void add(Sample* s);
void finalise(); ///< Call this when no more samples will be added.
- const PowerListItems& getPowerListItems() const;
+ const PowerListItems& getPowerListItems(float position) const;
float getMaxPower() const;
float getMinPower() const;
diff --git a/src/sample_selection.cc b/src/sample_selection.cc
index eb13e55..c6d8eea 100644
--- a/src/sample_selection.cc
+++ b/src/sample_selection.cc
@@ -58,7 +58,7 @@ void SampleSelection::finalise()
// FIXME: bad variable naming
const Sample* SampleSelection::get(level_t level, float position, std::size_t pos)
{
- const auto& samples = powerlist.getPowerListItems();
+ const auto& samples = powerlist.getPowerListItems(position);
if(!samples.size())
{
return nullptr; // No samples to choose from.
@@ -80,7 +80,7 @@ const Sample* SampleSelection::get(level_t level, float position, std::size_t po
const float f_diverse = (1./2.)*settings.sample_selection_f_diverse.load();
const float f_random = (1./3.)*settings.sample_selection_f_random.load();
- float power_range = powerlist.getMaxPower() - powerlist.getMinPower();
+ float power_range = samples.getMaxPower() - samples.getMinPower();
// If all power values are the same then power_range is invalid but we want
// to avoid division by zero.
if (power_range == 0.) { power_range = 1.0; }