[JUCE API] Making Tempo Delay Button(2)

SangHoon You·2025년 4월 11일
0

JUCE API

목록 보기
8/17

ControlPanel accepts the ToggleButton as a member

PanelControl::PanelControl()
:mTempoButton(mAudioprocessor.getmApvts(),
MyParamId::Control::Tempo.getParamID(),
MyHelper::CmdId::Tempo)

To detect the change of button, we use the Listener class.

class PanelDelay  : public PanelBase,
                    private juce::Button::Listener

ToggleButton is derived from Button, we can use the Button class's Listener. And I want to use Listener only in the derived class, the access specifier was set to private.


It is important to add PanelDelay as a listener of ToggleButton.
  1. Get the ToggleButton from the PanelControl
juce::Button& PanelControl::getTempoButton() noexcept
{
    return mTempoButton;
}

PanelDelay(const juce::String& inTitle,
               EulerDelayAudioProcessor& inAudioprocessor,
               juce::Button& inButton);

  1. Pass that ToggelButton through the PluginEditor
AudioProcessorEditor()
: mPanelControl("Control"),
  mPanelDelay("Delay", mPanelControl.getTempoButton())

  1. Receive that ToggleButton as a member in PanelDelay
PanelDelay::PanelDelay()
: mTempoButton(inButton)

Is is important to set the state of ToggleButton as a reference.




class JUCE_API  Listener
    {
    public:

        /** Called when the button is clicked. */
        virtual void buttonClicked (Button*) = 0;
    };

Listener class has a buttonClicked() as a pure virtual function, we have to define that.


void PanelDelay::buttonClicked (juce::Button* inButton)
{
    switch(inButton->getCommandID())
    {
        case MyHelper::CmdId::Tempo: //
        {
            setVisibleParam(inButton->getToggleState());
            break;
        }
        
        default: break;
    }
}

If we add PanelDelay as a lisnter for many buttons, we should identify which botton has changed when buttonClicked() is called. By using specific ID of button, we can recognize.

Finally, setVisibleParam() is the function of what would be displayed at PanelDelay in GUI.


void PanelDelay::setVisibleParam (const bool inState) noexcept
{
    for(int i=0;i<2;++i)
    {
        mLabelTime[i].setVisible(!inState);
        mKnobTime[i].setVisible(!inState);
        
        mLabelNote[i].setVisible(inState);
        mKnobNote[i].setVisible(inState);
    }
}

Just get the bool object as a parameter, we can directly pass that to the setvisible() function.

profile
Audio Plugin Developer

0개의 댓글