New Parameter API: potential big problems arising

The old way of doing things will still work (albeit it will hit you with an assertion). The new way of doing this would be something like this:

class WrapperProcessor
     : public AudioProcessor
{
public:
    WrapperProcessor (AudioPluginInstance* processorToUse)
        : AudioProcessor (getBusesPropertiesFromProcessor (processorToUse)),
          plugin (processorToUse)
    {
        updateParameter();
    }
    
    //==============================================================================
    .
    .
    .
    //==============================================================================
    class AudioParameterWrapper : public AudioProcessorParameter
    {
    public:
        AudioParameterWrapper (AudioProcessorParameter& paramToWrap)
            : wrap (paramToWrap)
        {}
        
        float getValue() const override                          { return wrap.getValue();        }
        void setValue (float newValue) override                  { wrap.setValue (newValue);      }
        float getDefaultValue() const override                   { return wrap.getDefaultValue(); }
        String getName (int maxLen) const override               { return wrap.getName (maxLen);  }
        String getLabel() const override                         { return wrap.getLabel();        }
        int getNumSteps() const override                         { return wrap.getNumSteps();     }
        bool isDiscrete() const override                         { return wrap.isDiscrete();      }
        
        String getText (float v, int len) const override         { return wrap.getText (v, len);        }
        float getValueForText (const String& t) const override   { return wrap.getValueForText (t);     }
        String getCurrentValueAsText() const override            { return wrap.getCurrentValueAsText(); }
        bool isOrientationInverted() const override              { return wrap.isOrientationInverted(); }
        bool isAutomatable() const override                      { return wrap.isAutomatable(); }
        bool isMetaParameter() const override                    { return wrap.isMetaParameter(); }
        Category getCategory() const override                    { return wrap.getCategory(); }
    private:
        AudioProcessorParameter& wrap;
        JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioParameterWrapper)
    };
    
    void updateParameter()
    {
        auto& params = plugin->getParameters();

        for (auto* param : params)
            addParameter (new AudioParameterWrapper(*param));
    }
    
    ScopedPointer<AudioProcessor> plugin;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WrapperProcessor)
};
3 Likes