Adding a slider listener
Wednesday 29 July 2020
The setup for this is very similar to adding the button - it goes in the same places in .h and .cpp but some of the syntax is different.
1. First step is to go into MainComponent.h. We need to add another inheritance relationship. So I have changed
class MainComponent : public juce::AudioAppComponent,
public juce::Button::Listener
to
class MainComponent : public juce::AudioAppComponent,
public juce::Button::Listener,
public juce::Slider::Listener
I've added juce:: to Slider::Listener - the video didn't mention it but looks like a feature of Juce 6.
2. Because I am now inheriting from Button::Listener I need to implement that function. So in the public section of that class (below void resized) I will enter:
/** implement Slider::Listener */
void sliderValueChanged(juce::Slider *slider) override;
3. Next I need to go to the MainComponent.cpp file and implement it by adding code at the bottom:
void MainComponent::sliderValueChanged(juce::Slider* slider)
{
if (slider == &volSlider)
{
DBG("Vol slider moved to " << slider->getValue());
}
}
4. In the constructor MainComponent::MainComponent() in MainComponent.cpp where we configure the GUI, we can add more code to register the event:
volSlider.addListener(this);
More posts in cpp
- Add a component ID and converting between ints and strings
- Implement a play button and add a listener
- Implement paintRowBackground and paintCell
- Add a vector to store a list of files
- Add a TableListBox
- Create a PlaylistComponent in the Projucer project
- Threads
- Implement a timer
- Add getPosition and setPosition functions
- Refactor DJAudioPlayer to use app-scope formatManager
- Draw the thumbnail
- Hook up the load button to trigger the AudioThumbnail load
- The AudioThumbnail class in the API
- Creating a new component - WaveformDisplay
- Implementing drag and drop triggers
- Use a MixerAudioSource to play more than one file at a time
- Implement the listener interfaces to DeckGUI
- Creating a DeckGUI class
- setPosition control
- Implementing setGain and setSpeed
- Add audio playback functionality
- Writing the DJAudioPlayer class
- Creating a new JUCE class with Projucer
- Refactoring our code
- Using ResamplingAudioPlayer to implement variable speed playback
- Add stop, start and volume functionality
- Add a file chooser
- Audio file playback in JUCE
- Realtime sound synthesis in JUCE
- Adding a slider listener
- Introduction to event listeners
- Macros
- Inheritance
- Adding a GUI widget to the JUCE app
- Introduction to JUCE