Need Help With AudioProcessorParameter


#1

Hello,

I'm having a little trouble trying to figure out how to use AudioProcessorParameter. I was able to use the old way of doing it pretty easily, but now I'm a bit lost.

So there's a couple things I'm confused about, but I'll just start with what I need to know right now. So say I have a class I made ( called DirectFormFilter) and I need to call a member function (like DirectFormFilter::setCutoff) that needs to be set by the parameter. How and where would I do this at?

With the old way, I would do something like this to set the filter's cutoff or something like that:


void MyAudioProcessor::setParameter (int index, float newValue) 
{ 
    switch (index) {  
    case kCutoffFreqParam: 
        cutoff = newValue; 
        directFormFilter.setCutoff(cutoff); 
        break; 
    default: 
        break; 
    }
}

How could I do something like this with the new AudioProcessorParameter? It seems like a much different way of doing things. I'm trying to understand how it's done from the updated "audio plugin demo", but I'm just not getting it. It would be great if some things, like the similarities/differences about the old and new way, were explained a little. 

 

 


#2

It's really not that different, instead of getting your parameter update call on 
void MyAudioProcessor::setParameter (int index, float newValue), you will now receive it on AudioProcessorParameter::setValue from where you can pass it on to your DirectFormFilter. Look at line 151 in PlugInProcessor.cpp. This function will be called when the parameter updates. If you need to know which parameter has been changed in that method, then you can derive sub-classes of FloatParameter for the various different parameters and only overload the setValue method. For example, for the CutOffFreq you could add the following code after the definition of FloatParameter:

class CutOffFreqParam : public FloatParameter
{
public:
     CutOffFreqParam (DirectFormFilter& formFilter) 
         : FloatParameter (4000.0f, "Cutoff Frequency"),
           directFormFilter (formFilter) {}

     void setValue (float newValue) override
     {
         // call the base class
         FloatParameter::setValue (newValue);
      
         // do whatever you need to do when cut-off is updated
         directFormFilter.setCutoff(cutoff);
     }   
private:
     DirectFormFilter& directFormFilter;
};

 

Then add the above parameter to your plug-in by adding the following at this line:

addParameter (cutoff = new CutOffFreqParam (directFormFilter));

Another possibility (that doesn't require subclassing FloatParameter) is to add an index member variable to FloatParameter which you pass as a contructor parameter. You can then check the index in FloatParameter::setValue and call the appropriate functions.

I hope this helps!


#3

Awesome man! Yes, that helps so much! You're right, that's not too different than before. I was thinking about it in a completely different way. Thank you, that cleared it right up for me. :) Hopefully your explanation will help other noobs figure it out too. I think I might like this way more. It could be a good thing not having to clutter up the processor class with parameter code.


#4

I have another question. How would I access the AudioProcessor from the FloatParameter class so I could call something like directFormFilter.setCutoff() (directFormFilter being an object in my AudioProcessor). I'm kind of confused on how to do that. The only thing I can think of is to make FloatParameter a nested class in my AudioProcessor, but even then I seem to have trouble calling the DirectFormFilter::setCutoff() in setValue() even then. Man, I thought I had it figured out, but I keep running into problems. 


#5

This is why I passed the directFromFilter object as a parameter to the constructor of CutOffFreqParam which then stores a copy of it as a member variable. You can pass anything you want to the constructor - also an instance of your AudioProcessor class


#6

Ahh I get it now. Somehow I completely gazed over that part. Thank you for helping. :) I figured I better go ahead and figure out how to use AudioProcessorParameter and not get use to the older way of doing things. I got that part working now. I really appreciate the help. It's awesome how helpful this forum can be.