Assign LFOs their respective ID numbers

This commit is contained in:
Jean Pierre Cimalando 2020-11-15 16:32:35 +01:00
parent d8dcb2e56f
commit 04ff815cab
5 changed files with 21 additions and 7 deletions

View file

@ -114,7 +114,8 @@ int main(int argc, char* argv[])
std::vector<std::unique_ptr<sfz::LFO>> lfos(numLfos); std::vector<std::unique_ptr<sfz::LFO>> lfos(numLfos);
for (size_t l = 0; l < numLfos; ++l) { for (size_t l = 0; l < numLfos; ++l) {
sfz::LFO* lfo = new sfz::LFO(bufferPool); const NumericId<sfz::LFO> id { static_cast<int>(l) };
sfz::LFO* lfo = new sfz::LFO(id, bufferPool);
lfos[l].reset(lfo); lfos[l].reset(lfo);
lfo->setSampleRate(sampleRate); lfo->setSampleRate(sampleRate);
lfo->configure(&desc[l]); lfo->configure(&desc[l]);

View file

@ -18,14 +18,16 @@
namespace sfz { namespace sfz {
struct LFO::Impl { struct LFO::Impl {
explicit Impl(BufferPool& bufferPool, BeatClock* beatClock) explicit Impl(NumericId<LFO> id, BufferPool& bufferPool, BeatClock* beatClock)
: bufferPool_(bufferPool), : id_(id),
bufferPool_(bufferPool),
beatClock_(beatClock), beatClock_(beatClock),
sampleRate_(config::defaultSampleRate), sampleRate_(config::defaultSampleRate),
desc_(&LFODescription::getDefault()) desc_(&LFODescription::getDefault())
{ {
} }
NumericId<LFO> id_;
BufferPool& bufferPool_; BufferPool& bufferPool_;
BeatClock* beatClock_ = nullptr; BeatClock* beatClock_ = nullptr;
float sampleRate_ = 0; float sampleRate_ = 0;
@ -41,8 +43,8 @@ struct LFO::Impl {
std::array<int, config::maxLFOSubs> sampleHoldState_ {{}}; std::array<int, config::maxLFOSubs> sampleHoldState_ {{}};
}; };
LFO::LFO(BufferPool& bufferPool, BeatClock* beatClock) LFO::LFO(NumericId<LFO> id, BufferPool& bufferPool, BeatClock* beatClock)
: impl_(new Impl(bufferPool, beatClock)) : impl_(new Impl(id, bufferPool, beatClock))
{ {
} }
@ -50,6 +52,11 @@ LFO::~LFO()
{ {
} }
NumericId<LFO> LFO::getId() const noexcept
{
return impl_->id_;
}
void LFO::setSampleRate(double sampleRate) void LFO::setSampleRate(double sampleRate)
{ {
impl_->sampleRate_ = sampleRate; impl_->sampleRate_ = sampleRate;

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once #pragma once
#include "utility/NumericId.h"
#include <absl/types/span.h> #include <absl/types/span.h>
#include <memory> #include <memory>
@ -52,10 +53,13 @@ struct LFODescription;
class LFO { class LFO {
public: public:
explicit LFO( explicit LFO(
NumericId<LFO> id,
BufferPool& bufferPool, BufferPool& bufferPool,
BeatClock* beatClock = nullptr); BeatClock* beatClock = nullptr);
~LFO(); ~LFO();
NumericId<LFO> getId() const noexcept;
/** /**
Sets the sample rate. Sets the sample rate.
*/ */

View file

@ -1480,7 +1480,8 @@ void Voice::setMaxLFOsPerVoice(size_t numLFOs)
impl.lfos_.resize(numLFOs); impl.lfos_.resize(numLFOs);
for (size_t i = 0; i < numLFOs; ++i) { for (size_t i = 0; i < numLFOs; ++i) {
auto lfo = absl::make_unique<LFO>(resources.bufferPool, &resources.beatClock); const NumericId<LFO> id { static_cast<int>(i) };
auto lfo = absl::make_unique<LFO>(id, resources.bufferPool, &resources.beatClock);
lfo->setSampleRate(impl.sampleRate_); lfo->setSampleRate(impl.sampleRate_);
impl.lfos_[i] = std::move(lfo); impl.lfos_[i] = std::move(lfo);
} }

View file

@ -26,7 +26,8 @@ static bool computeLFO(DataPoints& dp, const fs::path& sfzPath, double sampleRat
std::vector<std::unique_ptr<sfz::LFO>> lfos(numLfos); std::vector<std::unique_ptr<sfz::LFO>> lfos(numLfos);
for (size_t l = 0; l < numLfos; ++l) { for (size_t l = 0; l < numLfos; ++l) {
sfz::LFO* lfo = new sfz::LFO(resources.bufferPool); const NumericId<sfz::LFO> id { static_cast<int>(l) };
sfz::LFO* lfo = new sfz::LFO(id, resources.bufferPool);
lfos[l].reset(lfo); lfos[l].reset(lfo);
lfo->setSampleRate(sampleRate); lfo->setSampleRate(sampleRate);
lfo->configure(&desc[l]); lfo->configure(&desc[l]);