Saturday 11 May 2013

The getParameterName Function

Look a bit further down the code now until you find a bit like this:
const String GainPluginAudioProcessor::getParameterName (int index)
{
    return String::empty;
}
This function returns the name of a parameter to the host.

There are a couple of extra bits to the syntax of this function which we haven't seen yet. Firstly is the 'const' part at the beginning. The meaning of this is, again, beyond the scope of this discussion. Read some C/C++ literature and all will become apparent.

The more important part in what is inside the round brackets after the function name. In here we will find the arguments to the function. Arguments allow a function to have an input as well as an output.

The host can call this 'getParameterName' function in order to get the name of a specific parameter. To do this the host must specify which parameter it wants the name of. This is done by using an input argument.

Inside the round brackets in the first line of code we see (int index). This means that our function has one input argument. It will be an integer value (indicated by the 'int' part) and we will refer to it as 'index'. Remember the 'getNumParameters' function had an empty set of round brackets. That is how we show that a function has no input arguments.

If our plug-in had multiple parameters the host could get the name of a specific one by calling the 'getParameterName' function with that parameter's index number as an argument. Say we had three parameters, we could get the name of the first one by asking for the name of the parameter with index 0 (getParameterName (0)). For the second parameter we use index 1 and for the third parameter, index 2. Note that the indexing starts to 0 rather than 1, this is again a fundamental part of C/C++ programming.

We also need to note that this function returns a 'String', this is a data type which holds some text.

So this first line of code is telling us that our plug-in has a function called 'getParameterName' which takes one argument (an integer called index) and then returns a string of text.

As our gain plug-in only has one parameter we don't need to worry about the input argument to the function. The host knows we only have one parameter so will only call the 'getParameterName' function with the input argument 0. Because of this our code inside the curly brackets can be one line that returns the name of our parameter.

Currently, the code above returns an empty string (String::empty). The syntax of that may seem weird at the moment but as you become more familiar with C++ and JUCE it will make sense.

We need to change it to look like this:
const String GainPluginAudioProcessor::getParameterName (int index)
{
    return "Gain";
}
Double quotes are used to enclose strings in C/C++. So our function will now return a string which says 'Gain'. When the host asks for the parameter name it will get 'Gain' in return. We are a step closer to having our plug-in. Save these changes to your project and we can move on.

Have a nice day now!
Sean

No comments:

Post a Comment