The Red Penguin

The AudioThumbnail class in the API


Tuesday 4 August 2020

1. We start by going to private: in MainComponent.h and adding:
juce::AudioFormatManager formatManager;
juce::AudioThumbnailCache thumbCache{100};
(I already had the first line in my code!) We added 100 so it can cache 100 thumbnails.

2. How do we get this data into the DeckGUI? I want to change the constructor so it can take these two bits of data. In DeckGUI.h change DeckGUI(DJAudioPlayer* player); to:
DeckGUI(DJAudioPlayer* player,
juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse);
(I added juce:: which was not in the video)

3. We need to update DeckGUI.cpp too so it has the correct arguments coming into the constructor so where it previously said DeckGUI::DeckGUI(DJAudioPlayer* _player) : player(_player), change to
DeckGUI::DeckGUI(DJAudioPlayer* _player,
juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse
) : player(_player)

4. Now the DeckGUI is ready to receive the data, and the data exists in the MainComponent, so we just need to make that connection between the two, so in MainComponent.h we change DeckGUI deckGUI1{&player1}; to
DeckGUI deckGUI1{&player1, formatManager, thumbCache};
and likewise for player2.

5. The next step is to get the data down from the DeckGUI to the WaveformDisplay. So we go to WaveformDisplay.h and in public change WaveformDisplay(); to
    WaveformDisplay(juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse);

6. In WaveformDisplay.cpp change WaveformDisplay::WaveformDisplay() to
WaveformDisplay::WaveformDisplay(juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse)

7. Now WaveformDisplay is ready to receive the data so we need to send the data from DeckGUI. We need to use an initialisation list to pass this data down. In DeckGUI.cpp we need to change
DeckGUI::DeckGUI(DJAudioPlayer* _player,
juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse
) : player(_player)
to
DeckGUI::DeckGUI(DJAudioPlayer* _player,
juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse
) : player(_player),
waveformDisplay(formatManagerToUse, cacheToUse)

8. In private: in WaveformDisplay.h add
    juce::AudioThumbnail audioThumb;

9. We need to create another initialisation list in WaveformDisplay.cpp like this:
WaveformDisplay::WaveformDisplay(juce::AudioFormatManager& formatManagerToUse,
juce::AudioThumbnailCache& cacheToUse) :
audioThumb(1000, formatManagerToUse, cacheToUse)
The 1000 refers to the number of points we are using to plot the waveform.

We should now be able to compile and build this.