Is it smart to use APVTS::Listener::parameterChanged with many parameters

Hello, great thanks for all your support.
it’s true that my way with unique first character of String ParameterID was very painfull.

So you inspired me to write other solution (similar to what Daniel showed). But I made it much simpler (I mean not better but less code lines). But I am not sure if it’s secure. I didn’t use any security to check if pointers aren’t null and no jassert.

And actually it’s a shame, but I still not sure how to use parameterGestureChanged. As you can see it’s empty method in my template. But template works, so what’s the problem. But I suppose there is some important reason they made it pure virtual method.

And also I didn’t implemented any AsyncUpdater, I am not sure if it’s important. At the moment it looks like everything works fine. But probably I don’t see bigger picture.

So I am not sure if it’s good solution. If you could give me some feedback I would be very appretiate.

This is my class template:

template<typename ValueType>
class ParameterAttachment : public AudioProcessorParameter::Listener
{
public:
    ParameterAttachment(RangedAudioParameter *rap, std::function<void(ValueType)> func) : rangedAudioParameter(rap), onParameterChanged(func)
    {
        rangedAudioParameter->addListener(this);
    };
    
private:
    void parameterValueChanged(int parameterIndex, float newValue) override
    {
        onParameterChanged(rangedAudioParameter->getNormalisableRange().convertFrom0to1(rangedAudioParameter->getValue()));
    }
    
    void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override
    {
        
    }
    
    RangedAudioParameter* rangedAudioParameter = nullptr;
    std::function<void(ValueType)> onParameterChanged;
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterAttachment)
};

To use it you need only two lines of code. First declaration in processor class body, like:
ParameterAttachment<const float&> inputGainAttachment;

And then in inicialisation list of AudioProcessor, like that:

inputGainAttachment(myAPVTS.getParameter(INPUT_GAIN_ID),
                    [&] (const float& _input) { setInputGain (_input);  })

And that’s all.

Probably you will also notice there is no Atomic values which could be used in processBlock, but I provided it inside of all std::function<void(ValueType)>. So I am not affraid about that.

But maybe there are other hazards in my code.

1 Like