Saturday 11 May 2013

Getting Parameter Values from the Plug-In

The host has two way in which it can ask for the value of a given parameter. The 'getParameter' and 'getParameterText' functions.

The getParameter Function:

If the host calls this function it is expecting a float value in the range of 0 to 1 to be returned.

Currently your code for this function should look like this:
float GainPluginAudioProcessor::getParameter (int index)
{
    return 0.0f;
}
As with the 'getParameterName' function we have an input argument so the host can select which parameter it wants information about. We only have one parameter so we can ignore this.

We need to change this so that it returns the value stored in our 'gain' variable. We do this like so:
float GainPluginAudioProcessor::getParameter (int index)
{
    return gain;
}
Hopefully this change should be fairly self explanatory.

The getParameterText Function:

If the host calls this function it is expecting a string containing the value of our parameter. It will display this string in the interface it will build for our plugin. If we are scaling the value outside the range of 0 to 1 (say it is the frequency of an EQ band) we can return a value here that will make more sense to the user (something in the range 20 - 20000 say). We can also add units onto the end of the string (such as Hz).

The code you currently have for this function should look something like this:
const String GainPluginAudioProcessor::getParameterText (int index)
{
    return String::empty;
}
We don't need to scale the parameter values in our plug-in. All we need to do for this function is convert the float stored in our 'gain' variable to a string.

To do that we can change the code to this:
const String GainPluginAudioProcessor::getParameterText (int index)
{
    return String (gain);
}
Without going into too much detail, 'String (gain)' takes the value stored in 'gain' and converts it into a string. Our function then returns this string to the host so it can use it in its display.

The host can now ask our plug-in for the current value of its parameters. Save these changes to your project and we will move on.

Next we will look at how to tell the plug-in what to do when the host tries to set its parameters.

Have a nice day now!
Sean

No comments:

Post a Comment