Jamba  3.0.2
pongasoft::VST::GUI::ViewCxMgr Class Reference

#include <ViewCxMgr.h>

Inherits IViewListenerAdapter.

Public Member Functions

void closeAll ()
 
template<typename TView >
ViewGUIParamCxAware< TView > * registerConnectionFor (TView *iView, GUIState *iGUIState)
 

Private Member Functions

void viewWillDelete (CView *iView) override
 

Private Attributes

std::unordered_map< CView *, std::unique_ptr< GUIParamCxAware > > fViewConnections {}
 

Detailed Description

This class will manage the callbacks 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->registerConnectionFor(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 cx = fState->registerConnectionFor(button); cx->registerParam(fParams->fMyVstParam); cx->registerParam(fState->fMyJmbParam); cx->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 }); cx->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, PluginAccessor<MyGUIState> { public: // constructor MyView(...);

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

Member Function Documentation

◆ closeAll()

void pongasoft::VST::GUI::ViewCxMgr::closeAll ( )

Close all previously established connections

◆ registerConnectionFor()

template<typename TView >
ViewGUIParamCxAware< TView > * pongasoft::VST::GUI::ViewCxMgr::registerConnectionFor ( 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 pongasoft::VST::GUI::ViewCxMgr::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

◆ fViewConnections

std::unordered_map<CView *, std::unique_ptr<GUIParamCxAware> > pongasoft::VST::GUI::ViewCxMgr::fViewConnections {}
private

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