Thanks all for the interesting insights!
My take on the first approach (flag + timer) was this (it’s for a IR convolution plugin)…
class ImpulseLoaderAsync : private Timer
{
public:
ImpulseLoaderAsync();
void changeImpulseAsync (int newImpulse);
const bool isNowChanging() { return nowChangingImpulseAsync; }
private:
int currentImpulse {-1}; // force initial load
bool nowChangingImpulseAsync {false}; // the flag
void timerCallback() override;
void changeImpulse (int newImpulse);
};
.cpp…
#include "ImpulseLoaderAsync.h"
ImpulseLoaderAsync::ImpulseLoaderAsync()
{
startTimer (500);
}
void ImpulseLoaderAsync::changeImpulseAsync (int newImpulse)
{
if (newImpulse != currentImpulse)
{
currentImpulse = newImpulse;
nowChangingImpulseAsync = true;
}
}
// private:
void ImpulseLoaderAsync::timerCallback()
{
if (nowChangingImpulseAsync)
{
changeImpulse (currentImpulse);
nowChangingImpulseAsync = false;
}
}
void ImpulseLoaderAsync::changeImpulse (int newImpulse)
{
switch (newImpulse)
{
// big switch statement where I load the impulse
}
}
Note, I bypassed the DSP (in my case convolution) whenever the changeImpulseAsync() flag is set.
In the processBlock()…
impulseLoaderAsync.changeImpulseAsync (newImpulse);
if (*bypassParam < 0.5f && impulseLoaderAsync.isNowChanging() != true) // bypass while changing impulse also
{
//... the DSP
How does all this look to you guys best practice-wise?
Thanks!