
To change these delay time mode, We should add the button.
ToggleButton() -> ControlPanel() -> DelayPanel() -> PluginEditor()
#include <JuceHeader.h>
class MyParamToggleButton : public juce::TextButton
{
public:
MyParamToggleButton(juce::AudioProcessorValueTreeState& inApvts,
const juce::String& inParamId,
const int inCmdId);
~MyParamToggleButton() override;
private:
juce::AudioProcessorValueTreeState::ButtonAttachment mAttatchment;
void updateTextButton() noexcept;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyParamToggleButton)
};
This is togglenbutton's header file.
class JUCE_API ButtonAttachment
{
public:
ButtonAttachment (AudioProcessorValueTreeState& stateToUse,
const String& parameterID,
Button& button);
MyParamToggleButton::MyParamToggleButton()
:mAttatchment(inApvts, inParamId, *this)
In order to connect this button to specific parameter, we need Apvts and Parameter's ID for creating the Attatchment object.
void MyParamToggleButton::updateTextButton() noexcept
{
setButtonText(getToggleState() ? "ON" : "OFF");
}
std::make_unique<juce::AudioParameterBool>(MyParamId::Control::Tempo,"Tempo",false));
updateTextButton() is set up the text of the button depending on the parameter state. Initially, I set up the Tempo's parameter as bool.
MyParamToggleButton::MyParamToggleButton()
{
setClickingTogglesState(true);
updateTextButton();
setCommandToTrigger(nullptr, inCmdId, false);
onClick = [this]()
{
updateTextButton();
};
}
By setting setClickingTogglesState() as true, we cand use the feature that change the state ON or OFF when the button is clicked.
And also, we have to show the initial state of button, so constructor includes the updateTextButton().
setCommandToTrigger() is set the unique ID of button to identify from other buttons.
class JUCE_API Button
{
public:
std::function<void()> onClick;
}
onClick is Lamda function of Button, which is called when the button is clicked. We can use this function because TextButton inherits from Button. (ToggleButton::TextButton::Button)
And onClick is Button's funtion, so we have to add 'this' to the capture to call the onClick() when ToggleButton is clicked.
Whenever ToggleButton is clicked through the
setClickingTogglesState(true) change the parameter. We should update that as text by updateTextButton().