Jamba C++ API  4.0.0
ParamAwareViews Class Reference

This class manages the views that have been made "param aware". More...

#include <ParamAwareViews.h>

Inherits IViewListenerAdapter.

Public Member Functions

void closeAll ()
 Close all previously established connections. More...
 
template<typename TView >
ParamAwareView< TView > * makeParamAware (TView *iView, GUIState *iGUIState)
 

Private Member Functions

void viewWillDelete (CView *iView) override
 Called by VSTGUI when a view that was previously registered is being deleted => all its connections will be closed. More...
 

Private Attributes

std::unordered_map< CView *, std::unique_ptr< ParamAware > > fParamAwareViews {}
 

Detailed Description

This class manages the views that have been made "param aware".

This means that callbacks can be registered against a view (CView). The idea is to be able to register callbacks for the life of a view without having to inherit from the view to implement a similar behavior (which is much more involved).

Example1 usage:

TextButtonView *button = ....;
fState->makeParamAware(button)->registerCallback<int>(fParams->fMyParam,
  [] (TextButtonView *iButton, GUIVstParam<int> &iParam) {
  iButton->setMouseEnabled(iParam > 3);
});

This examples sets up a callback on the button view, so that when the (Vst) parameter "my param" changes, the callback is invoked. Since the view and the parameter are part of the callback API, it is easy to implement simple behaviors like this. Usually this can be done from the main controller (or sub controller) in the verifyView method.

Example2 usage:

TextButtonView *button = ....;
auto pa = fState->makeParamAware(button);
pa->registerParam(fParams->fMyVstParam);
pa->registerParam(fState->fMyJmbParam);
pa->registerListener([this] (TextButtonView *iButton, ParamID iParamID) {
  if(iParamID == fParams->fMyVstParam.getParamID())
    // do something... iButton->xxx
  if(iParamID == fParams->fState->fMyJmbParam())
    // do something else... iButton->xxx
 });
 pa->invokeAll(); // optionally invoke the listener right away to initialize the button

This examples sets up the button view as being interested in changes to 2 parameters and when they change, the listener will be invoked.

An alternative would be to inherit from the view which is more work (especially if the only purpose is add a simple callback like behavior):

class MyView : public TextButtonView, StateAware<MyGUIState>
{
  public:
    // constructor
    MyView(...);

    void registerParameters() override
    {
       registerVstCallback(fParams->fMyParam, [this] (GUIVstParam<int> &iParam) {
         setMouseEnabled(iParam > 3);
       });
    }
};

Member Function Documentation

◆ closeAll()

void closeAll ( )

Close all previously established connections.

◆ makeParamAware()

ParamAwareView< TView > * makeParamAware ( TView *  iView,
GUIState iGUIState 
)
Template Parameters
TViewshould be a subclass of VSTGUI::CView
Returns
a pointer (owned by this class) to an object for registering callbacks, listener and params. Note: You should not keep this pointer around. It is owned by this class and will automatically be deleted when the view goes away.

◆ viewWillDelete()

void viewWillDelete ( CView *  iView)
overrideprivate

Called by VSTGUI when a view that was previously registered is being deleted => all its connections will be closed.

Member Data Documentation

◆ fParamAwareViews

std::unordered_map<CView *, std::unique_ptr<ParamAware> > fParamAwareViews {}
private

The documentation for this class was generated from the following files: