Hello so currently I am trying to test out putting the AudioWaveformTutorial into an Audio Plugin (end goal is to be able to have the user to import their own sound library to the plugin). Currently I have the following header file included in the PluginEditor.cpp .
#ifndef H_SAMPLELIBRARY
#define H_SAMPLELIBRARY
> class SampleLibrary : public AudioAppComponent,
> private ChangeListener,
> private ButtonListener
> {
> public:
> SampleLibrary()
> :state (Stopped),
> thumbnailCache (5), //AudioThumbnailCache number of thumbnails to store
> thumbnail (512, formatManager, thumbnailCache) //AudioThumbnail how many source samples to create
> {
> formatManager.registerBasicFormats();
> transportSource.addChangeListener(this);
> thumbnail.addChangeListener (this);
>
> setAudioChannels (2,2);
> }
> ~SampleLibrary()
> {
> shutdownAudio();
> }
> void prepareToPlay (int samplesPerBlockExpected, double sampleRate)
> {
> transportSource.prepareToPlay (samplesPerBlockExpected, sampleRate);
> }
> void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
> {
> if (readerSource == nullptr)
> bufferToFill.clearActiveBufferRegion();
> else
> transportSource.getNextAudioBlock(bufferToFill);
> }
> void releaseResources()
> {
> transportSource.releaseResources();
> }
> void changeListenerCallback (ChangeBroadcaster* source)
> {
> if (source == &transportSource) transportSourceChanged();
> if (source == &thumbnail) thumbnailChanged();
> }
> void buttonClicked (Button* button) override
> {
> if (button == &openButton) openButtonClicked();
> if (button == &playButton) playButtonClicked();
> if (button == &stopButton) stopButtonClicked();
> }
>
> private:
> enum TransportState
> {
> Stopped,
> Starting,
> Playing,
> Stopping
> };
> void changeState (TransportState newState)
> {
> if (state != newState)
> {
> state = newState;
> switch (state)
> {
> case Stopped:
> stopButton.setEnabled (false);
> playButton.setEnabled (true);
> transportSource.setPosition (0.0);
> break;
> case Starting:
> playButton.setEnabled (false);
> transportSource.start();
> break;
> case Playing:
> stopButton.setEnabled (true);
> break;
> case Stopping:
> transportSource.stop();
> break;
> default:
> jassertfalse;
> break;
> }
> }
> }
> void transportSourceChanged()
> {
> changeState (transportSource.isPlaying() ? Playing : Stopped);
> }
> void thumbnailChanged()
> {
> repaint();
> }
> void paintIfNoFileLoaded (Graphics& g, const Rectangle<int>& thumbnailBounds)
> {
> g.setColour (Colours::darkgrey);
> g.fillRect (thumbnailBounds);
> g.setColour (Colours::white);
> g.drawFittedText ("No File Loaded", thumbnailBounds, Justification::centred, 1.0f);
> }
> void paintIfFileLoaded (Graphics& g, const Rectangle<int>& thumbnailBounds)
> {
> g.setColour (Colours::white);
> g.fillRect (thumbnailBounds);
> g.setColour (Colours::red); // [8]
> thumbnail.drawChannels (g, // [9]
> thumbnailBounds,
> 0.0, // start time
> thumbnail.getTotalLength(), // end time
> 1.0f); // vertical zoom
> }
> void openButtonClicked()
> {
> FileChooser chooser ("Select a Wave file to play...",
> File::nonexistent,
> "*.wav");
> if (chooser.browseForFileToOpen())
> {
> File file (chooser.getResult());
> AudioFormatReader* reader = formatManager.createReaderFor (file);
> if (reader != nullptr)
> {
> ScopedPointer<AudioFormatReaderSource> newSource = new AudioFormatReaderSource (reader, true);
> transportSource.setSource (newSource, 0, nullptr, reader->sampleRate);
> playButton.setEnabled (true);
> thumbnail.setSource (new FileInputSource (file)); // [7]
> readerSource = newSource.release();
> }
> }
> }
> void playButtonClicked()
> {
> changeState (Starting);
> }
> void stopButtonClicked()
> {
> changeState (Stopping);
> }
> //==========================================================================
> TextButton openButton;
> TextButton playButton;
> TextButton stopButton;
> AudioFormatManager formatManager; // [3]
> ScopedPointer<AudioFormatReaderSource> readerSource;
> AudioTransportSource transportSource;
> TransportState state;
> AudioThumbnailCache thumbnailCache; // [1]
> AudioThumbnail thumbnail; // [2]
> };
the current errors I have are:
- several “undeclared identifiers” (shutdownAudio, transportSource, etc.)
- “expected class name” for the public AudioAppComponent