Skip to content

Commit

Permalink
AirWin Lifecycle problem (#4906)
Browse files Browse the repository at this point in the history
FIx a lifecycle problem with the AirWindows Param Name mapper

Closes #4522
  • Loading branch information
baconpaul authored Aug 24, 2021
1 parent f1c9b48 commit 5aeb964
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
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;
};

0 comments on commit 5aeb964

Please sign in to comment.