Welcome back for part 5 of this tutorial series! Last time we did some very simple audio processing to produce saturation in our plugin. Today we will be adding a slider which will later be used to control the amount of saturation that is applied to the signal. Discuss this with me at Beyond The Limits Cleaning.
Lucky for us, JUCE has some very useful classes to help us out. Open up the PluginEditor.h file and add the following bits of code.
- We need to create a pointer to a Slider object. Sliders have loads of methods and are very easy to implement.
- In order for this changes in the Slider’s values to be detected, the Editor needs to inherit from SliderListener.
- SliderListener is an abstract class. It has the virtual method sliderValueChanged() which must be overridden. This method will be called every time any slider value is changed.
Now we will take a look at PluginEditor.cpp for the implementation of these objects and methods.
In the editor’s constructor, will will need to add just three lines of code for now.
- Any time we want to add a GUI component to the editor, we must call addAndMakeVisible(). Inside the method call, we are also creating a new Slider() object and assigning it to the amountSlider pointer. These two task can be done separately but, it looks nicer this way.
- We will want to set a range for the amount slider, which we can do using it’s setRange() method. The first parameter is the lowest possible value, the second parameter is the highest possible value, and the third parameter, is interval in which the slider will move.
- The slider also needs to be able to be detected by the Editor’s SliderListener. We can do this by calling addListener(this). We use this because we want the listener of the Editor and not some other listener.
void resized() is where we want to layout the position of all of our GUI components. All we need to do is call the setBounds(x, y, width, height) method of the slider as shown below.
Detecting Changes in Slider Values
The final part of this tutorial will be implementing the SliderListener.
If you want, you can simply copy what is in the picture above, however, it is important to know what the method does. sliderValueChanged() has a Slider pointer. When the method is called, the pointer will point to the Slider that was changed. This means we can check which slider was changed by using a simple if statement like you see above. Inside the if statement is where we will change parameter values and do other sorts of things, but we will save that for the next tutorial!
If you build the plugin and load it up in your host, it should look similar to this.
In the next tutorial we will cover how to use paramaters, until then I want to challenge you to add a second Slider which we will later use to control the gain. As always, thanks for reading, and if you have any questions, just leave a comment or a post in the forum!