summaryrefslogtreecommitdiff
path: root/src/instrument.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/instrument.cc')
-rw-r--r--src/instrument.cc39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/instrument.cc b/src/instrument.cc
index ac6aa28..af96ab6 100644
--- a/src/instrument.cc
+++ b/src/instrument.cc
@@ -29,6 +29,7 @@
#include <hugin.hpp>
#include "sample.h"
+#include "position_power.h"
Instrument::Instrument(Settings& settings, Random& rand)
: settings(settings)
@@ -36,7 +37,6 @@ Instrument::Instrument(Settings& settings, Random& rand)
, sample_selection(settings, rand, powerlist)
{
DEBUG(instrument, "new %p\n", this);
- mod = 1.0;
lastpos = 0;
magic = this;
@@ -55,17 +55,19 @@ bool Instrument::isValid() const
}
// FIXME: very bad variable naming of parameters
-const Sample* Instrument::sample(level_t level, 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(level * mod, position, pos);
+ return sample_selection.get(power, instrument_power_range,
+ position, instrument_position_range, pos);
}
else
{
// Version 1.0
- auto s = samples.get(level * mod);
+ auto s = samples.get(power);
if(s.size() == 0)
{
return nullptr;
@@ -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);
+ }
}
}
@@ -130,28 +144,21 @@ 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 positionPower(samplelist, position);
}
else
{
- return 1.0f;
+ return { 0.0f, 1.0f };
}
}
-float Instrument::getMinPower() const
+Instrument::PowerRange Instrument::getPositionRange() const
{
- if(version >= VersionStr("2.0"))
- {
- return powerlist.getMinPower();
- }
- else
- {
- return 0.0f;
- }
+ return position_range;
}
const std::vector<Choke>& Instrument::getChokes()