Merge pull request #766 from paulfd/cache-targetids
Cache ids for faster lookup
This commit is contained in:
commit
db98d51e11
2 changed files with 18 additions and 5 deletions
|
|
@ -31,6 +31,9 @@ struct LFO::Impl {
|
||||||
|
|
||||||
// control
|
// control
|
||||||
const LFODescription* desc_ = nullptr;
|
const LFODescription* desc_ = nullptr;
|
||||||
|
ModMatrix::TargetId beatsKeyId;
|
||||||
|
ModMatrix::TargetId freqKeyId;
|
||||||
|
ModMatrix::TargetId phaseKeyId;
|
||||||
|
|
||||||
// state
|
// state
|
||||||
size_t delayFramesLeft_ = 0;
|
size_t delayFramesLeft_ = 0;
|
||||||
|
|
@ -57,7 +60,12 @@ void LFO::setSampleRate(double sampleRate)
|
||||||
|
|
||||||
void LFO::configure(const LFODescription* desc)
|
void LFO::configure(const LFODescription* desc)
|
||||||
{
|
{
|
||||||
impl_->desc_ = desc ? desc : &LFODescription::getDefault();
|
Impl& impl = *impl_;
|
||||||
|
ModMatrix& modMatrix = impl.resources_.modMatrix;
|
||||||
|
impl.desc_ = desc ? desc : &LFODescription::getDefault();
|
||||||
|
impl.beatsKeyId = modMatrix.findTarget(desc->beatsKey);
|
||||||
|
impl.freqKeyId = modMatrix.findTarget(desc->freqKey);
|
||||||
|
impl.phaseKeyId = modMatrix.findTarget(desc->phaseKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LFO::start(unsigned triggerDelay)
|
void LFO::start(unsigned triggerDelay)
|
||||||
|
|
@ -336,9 +344,9 @@ void LFO::generatePhase(unsigned nth, absl::Span<float> phases)
|
||||||
const float* phaseMod = nullptr;
|
const float* phaseMod = nullptr;
|
||||||
// Note(jpc) we might switch between beats and frequency, if host
|
// Note(jpc) we might switch between beats and frequency, if host
|
||||||
// switches play state on and off; continually generate both.
|
// switches play state on and off; continually generate both.
|
||||||
beatsMod = modMatrix.getModulationByKey(desc.beatsKey);
|
beatsMod = modMatrix.getModulation(impl.beatsKeyId);
|
||||||
freqMod = modMatrix.getModulationByKey(desc.freqKey);
|
freqMod = modMatrix.getModulation(impl.freqKeyId);
|
||||||
phaseMod = modMatrix.getModulationByKey(desc.phaseKey);
|
phaseMod = modMatrix.getModulation(impl.phaseKeyId);
|
||||||
|
|
||||||
if (beatClock.isPlaying() && beats > 0) {
|
if (beatClock.isPlaying() && beats > 0) {
|
||||||
// generate using the beat clock
|
// generate using the beat clock
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ struct ModMatrix::Impl {
|
||||||
struct ConnectionData {
|
struct ConnectionData {
|
||||||
float sourceDepth_ {};
|
float sourceDepth_ {};
|
||||||
ModKey sourceDepthMod_ {};
|
ModKey sourceDepthMod_ {};
|
||||||
|
TargetId sourceDepthModId_ {};
|
||||||
float velToDepth_ {};
|
float velToDepth_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -207,6 +208,10 @@ bool ModMatrix::connect(SourceId sourceId, TargetId targetId, float sourceDepth,
|
||||||
Impl::ConnectionData& conn = target.connectedSources[sourceIndex];
|
Impl::ConnectionData& conn = target.connectedSources[sourceIndex];
|
||||||
conn.sourceDepth_ = sourceDepth;
|
conn.sourceDepth_ = sourceDepth;
|
||||||
conn.sourceDepthMod_ = sourceDepthMod;
|
conn.sourceDepthMod_ = sourceDepthMod;
|
||||||
|
|
||||||
|
if (sourceDepthMod)
|
||||||
|
conn.sourceDepthModId_ = registerTarget(sourceDepthMod);
|
||||||
|
|
||||||
conn.velToDepth_ = velToDepth;
|
conn.velToDepth_ = velToDepth;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -414,7 +419,7 @@ float* ModMatrix::getModulation(TargetId targetId)
|
||||||
sourceDepth += triggerValue * velToDepth;
|
sourceDepth += triggerValue * velToDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* sourceDepthMod = getModulationByKey(sourcesPos->second.sourceDepthMod_);
|
const float* sourceDepthMod = getModulation(sourcesPos->second.sourceDepthModId_);
|
||||||
|
|
||||||
if (isFirstSource) {
|
if (isFirstSource) {
|
||||||
if (sourceDepth == 1 && !sourceDepthMod)
|
if (sourceDepth == 1 && !sourceDepthMod)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue