Implement a timer
Wednesday 5 August 2020
We're going to implement the timer class on the deckGUI component so that it can automatically keep calling that get position function on the DJAudioPlayer, and pass it over to WaveformDisplay.
So the waveform position, the playhead, gets continually updated as the track is playing.
1. Go to DeckGUI.h. We need to inherit from the Timer class.
class DeckGUI : public juce::Component,
2. Timer is an abstract class, which means it has a pure virtual function in it. So you can't actually use Timer directly as a class. You have to inherit from it and implement the concrete version of its pure virtual functions. In public in DeckGUI.h we type
void timerCallback() override;
3. We need to go to DeckGUI.cpp and implement it.
4. The thread doesn't start by itself, we need to start and stop it. So in the constructor DeckGUI::DeckGUI
startTimer(500);We've now got this function built into our class because we inherited it from the Timer class. The 500 refers to the number of msec that we want to call it, so it will call every 1/2 sec here.
5. In the destructor function ("to be polite!") we will stop the timer.
6. Go back to DeckGUI::timerCallback() and add
If you build and compile it works. We could reduce the 500 to make it look a bit smoother.
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
- 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
- Adding a GUI widget to the JUCE app
- Introduction to JUCE