Hey all, will try to keep this short and sweet. Could really use some guidance here, intermediate level experience here.
My codebase is built on the old way of doing APVTS, i.e using createAndAddParameter(). Due to some bugs I can’t wrap my head around, I’m updating this to reflect the recommended implementation.
I ran into a confusing situation. My previous code has two parameters that depend on each other, guiFreqRange_min_Hz and guiFreqRange_max_Hz. These can be changed by the user to zoom a UI component in/out.
Here’s my existing & outdated relevant code, as confusing as it is. Basically, addFloatParameter has a call to createAndAddParameter here.
const float minDiff = 0.001f;
addFloatParameter(ids.guiFreqRange_min_Hz, "GUI Frequency Range Min",
guiFreqRange_Hz.getStart(),
NormalisableRange<float>(guiFreqRange_Hz.getStart(), guiFreqRange_Hz.getEnd() - 10.f,
nullptr, nullptr,
[&eq, minDiff](float rMin, float rMax, float v)
{
// this check prevents a crash when first initializing parameter
if (eq.state->getParameter(ids.guiFreqRange_max_Hz) != nullptr)
{
auto max = eq.pm->getFloatParamValue(ids.guiFreqRange_max_Hz);
if (fabsf(v - max) < minDiff)
v = jmax(rMin, v - minDiff);
if (fabsf(v - max) < minDiff)
eq.pm->setFloatParamValue(ids.guiFreqRange_max_Hz, jmin(max + minDiff, rMax));
}
return v;
}),
nullptr, nullptr, false, true);
Given the new way of doing APVTS, I don’t see a way I can dynamically do the above mentioned crash-preventing check, given that “max” and “min” depend on each other.
If I’ve read correctly, ParameterLayout cannot call any apvts object to check its value, because it is called before the APVTS constructor.
Could someone please fill in the missing info I have here? Let me try to sum up my question here…
“How do I perform a safety check on a value using the newest APVTS methodology?”
Thanks in advance! Much love.
Zonk
EDIT: Realizing it would quite obviously make sense to do this check inside parameterChanged or some other Listener class…