Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AirWin Lifecycle problem #4906

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/common/dsp/effects/airwindows/AirWindowsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@

constexpr int subblock_factor = 3; // divide block by 2^this

std::vector<AirWinBaseClass::Registration> AirWindowsEffect::fxreg;
std::vector<int> AirWindowsEffect::fxregOrdering;
AirWindowsEffect::AWFxSelectorMapper AirWindowsEffect::mapper;

AirWindowsEffect::AirWindowsEffect(SurgeStorage *storage, FxStorage *fxdata, pdata *pd)
: Effect(storage, fxdata, pd)
{
if (fxreg.empty())
{
fxreg = AirWinBaseClass::pluginRegistry();
fxregOrdering = AirWinBaseClass::pluginRegistryOrdering();
}

for (int i = 0; i < n_fx_params - 1; i++)
{
param_lags[i].newValue(0);
param_lags[i].instantize();
param_lags[i].setRate(0.004 * (BLOCK_SIZE >> subblock_factor));
}

mapper = std::make_unique<AWFxSelectorMapper>(this);
}

AirWindowsEffect::~AirWindowsEffect() {}
Expand All @@ -39,15 +47,7 @@ const char *AirWindowsEffect::group_label(int id)
if (airwin)
{
static char txt[1024];

if (mapper)
{
strncpy(txt, mapper->nameAtStreamedIndex(fxdata->p[0].val.i).c_str(), 1023);
}
else
{
airwin->getEffectName(txt);
}
strncpy(txt, mapper.nameAtStreamedIndex(fxdata->p[0].val.i).c_str(), 1023);
return (const char *)txt;
}
else
Expand Down Expand Up @@ -86,8 +86,6 @@ void AirWindowsEffect::init_ctrltypes()
** of our FX hasn't changed.
*/
Effect::init_ctrltypes();
fxreg = AirWinBaseClass::pluginRegistry();
fxregOrdering = AirWinBaseClass::pluginRegistryOrdering();

fxdata->p[0].set_name("FX");
fxdata->p[0].set_type(ct_airwindows_fx);
Expand Down Expand Up @@ -116,7 +114,7 @@ void AirWindowsEffect::resetCtrlTypes(bool useStreamedValues)
fxdata->p[0].posy_offset = 1;
fxdata->p[0].val_max.i = fxreg.size() - 1;

fxdata->p[0].set_user_data(mapper.get());
fxdata->p[0].set_user_data(&mapper);
if (airwin)
{
for (int i = 0; i < airwin->paramCount && i < n_fx_params - 1; ++i)
Expand Down
20 changes: 9 additions & 11 deletions src/common/dsp/effects/airwindows/AirWindowsEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@ class alignas(16) AirWindowsEffect : public Effect
std::unique_ptr<AirWinBaseClass> airwin;
int lastSelected = -1;

std::vector<AirWinBaseClass::Registration> fxreg;
std::vector<int> fxregOrdering;
static std::vector<AirWinBaseClass::Registration> fxreg;
static std::vector<int> fxregOrdering;

struct AWFxSelectorMapper : public ParameterDiscreteIndexRemapper
static struct AWFxSelectorMapper : public ParameterDiscreteIndexRemapper
{
AWFxSelectorMapper(AirWindowsEffect *fx) { this->fx = fx; };
AWFxSelectorMapper() {}

virtual int remapStreamedIndexToDisplayIndex(int i) const override
{
return fx->fxreg[i].displayOrder;
return fxreg[i].displayOrder;
}
virtual std::string nameAtStreamedIndex(int i) const override { return fx->fxreg[i].name; }
virtual std::string nameAtStreamedIndex(int i) const override { return fxreg[i].name; }
virtual bool hasGroupNames() const override { return true; }

virtual std::string groupNameAtStreamedIndex(int i) const override
{
return fx->fxreg[i].groupName;
return fxreg[i].groupName;
}

bool supportsTotalIndexOrdering() const override { return true; }

const std::vector<int> totalIndexOrdering() const override { return fx->fxregOrdering; }
const std::vector<int> totalIndexOrdering() const override { return fxregOrdering; }
AirWindowsEffect *fx;
};
} mapper;

struct AWFxParamFormatter : public ParameterExternalFormatter
{
Expand Down Expand Up @@ -145,6 +145,4 @@ class alignas(16) AirWindowsEffect : public Effect
};

std::array<std::unique_ptr<AWFxParamFormatter>, n_fx_params - 1> fxFormatters;

std::unique_ptr<AWFxSelectorMapper> mapper;
};