Jamba
3.0.2
|
#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 {} |
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); }); } };
void pongasoft::VST::GUI::ViewCxMgr::closeAll | ( | ) |
Close all previously established connections
ViewGUIParamCxAware< TView > * pongasoft::VST::GUI::ViewCxMgr::registerConnectionFor | ( | TView * | iView, |
GUIState * | iGUIState | ||
) |
TView | should be a subclass of VSTGUI::CView |
|
overrideprivate |
Called by VSTGUI when a view that was previously registered is being deleted => all its connections will be closed
|
private |