Hey all,
Let’s say I have a project that has multiple instances of an object Foo, that is an AudioProcessorValueTreeState::Listener.
Each Foo has an attribute called bar, that should be controllable independently. However, parameterChanged does not readily seem to allow for this.
Taking a look at the following, (please excuse my inability to figure out text formatting on this forum… is there a guide for it somewhere?)
void Foo::parameterChanged(const String ¶meterID, float newValue)
{
if(parameterID == “barparameter”)
{
bar = newValue;
}
}
it will not work- as every Foo will be updated by a barparameter changed. You could perhaps make multiple barparameter’s in your main processor and only assign a Foo to listen to one- except that won’t work, as a processor state needs unique parameter ID’s.
If you know you will have N instances of Foo, you could give each Foo a fooIDNum and do something like the following…
void Foo::parameterChanged(const String ¶meterID, float newValue)
{
if(parameterID == “barparameter0” && fooIDNum == 0)
{
bar = newValue;
}
if(parameterID == “barparameter1” && fooIDNum == 1)
{
bar = newValue;
}
–
if(parameterID == “barparameterN” && fooIDNum == N)
{
bar = newValue;
}
}
…but this quickly explodes in terms of duplicated code, and is tightly coupled to an individual project’s use of Foo objects.
if parameterChanged provided an actual AudioProcessorParameter* rather than a parameterID string, ‘type’ of control (a control that should update an attribute bar, in this case) could be determined by accessing the parameter’s attributes and going by something like name or label (making the label ‘barparameter’ per example and using code very similar to the first excerpt- but by the general label rather than unique parameter ID).
Is the only solution here to make Foo’s hold a pointer to the processor state, so that it can decode parameterID’s into an actual parameter?