Hi all,
I am trying to port into a plugin the juce example for audio applications about a simple file player: https://docs.juce.com/master/tutorial_playing_sound_files.html
I want to have an editor subcomponent dedicated to the buttons for opening and playing the files and I want to use a value tree state. I can’t understand where and how to associate properly to a button a function when the button is clicked.
I have created a GUI subcomponent in a separate file PanelFilePlayer.h:
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
class PanelFilePlayer : public Component
{
public:
PanelFilePlayer (AudioProcessorValueTreeState& valueTreeState)
{
addAndMakeVisible (openButton);
openButton.setButtonText ("Open...");
openButton.onClick = [this] { openButtonClicked(); };
openButtonAttachment.reset (new ButtonAttachment (valueTreeState, "open_button_panel_file_player", openButton));
}
~PanelFilePlayer(){
openButtonAttachment.reset();
}
void paint (Graphics& g) override
{
g.fillAll(Colours::darkblue);
Rectangle<int> PanelFilePlayerArea (getLocalBounds());
g.setColour (Colours::whitesmoke);
g.drawRect (PanelFilePlayerArea, 3.0f);
}
void resized() override
{
openButton .setBounds (10, 10, getWidth() - 20, 20);
}
private:
typedef AudioProcessorValueTreeState::ButtonAttachment ButtonAttachment;
TextButton openButton;
std::unique_ptr<ButtonAttachment> openButtonAttachment;
};
The PanelFilePlayer.h is included in the PluginEditor.h. Now, I wonder where the function openButtonClicked()
should be placed?
Ideally would like to place all functions related to the buttons (including those for thread safety) in a separate .h file (let’s call it FilePlayer.h). Such functions however are related to the audio system so somehow they should interact with the PluginProcessor.cpp.
In the file PluginProcessor.cpp I put these sections:
MyFilePlayerPluginAudioProcessor::MyFilePlayerPluginAudioProcessor()
: AudioProcessor (BusesProperties().withOutput ("Output", AudioChannelSet::stereo(), true)),
parametersPanelFilePlayer (*this, nullptr, Identifier ("ParametersPanelFilePlayer"), createParameterLayoutPanelFilePlayer())
{
openButtonParameterPanelFilePlayer = parametersPanelFilePlayer.getRawParameterValue ("open_button_panel_file_player");
}
AudioProcessorValueTreeState::ParameterLayout MyFilePlayerPluginAudioProcessor::createParameterLayoutPanelFilePlayer()
{
std::vector<std::unique_ptr<RangedAudioParameter>> params;
auto openButtonParam = std::make_unique<AudioParameterBool> ("open_button_panel_file_player", // parameterID
"Open Button", // parameter name
false); // default value
params.push_back(std::move(openButtonParam));
return {params.begin(), params.end()};
}
void MyFilePlayerPluginAudioProcessor::updateParameters()
{
//openButtonParameterPanelFilePlayer->onClick = [this] { openButtonClicked(); };
//This gives the error: No member named 'onClick' in 'std::__1::atomic<float>'
}
I am a bit lost at conceptual level… can anyone be so kind to tell me what I am doing wrong?