Jamba C++ API
5.1.1
|
This class manages the views that have been made "param aware". More...
#include <ParamAwareViews.h>
Inherits ViewListenerAdapter.
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 {} |
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); }); } };
void closeAll | ( | ) |
Close all previously established connections.
ParamAwareView< TView > * makeParamAware | ( | 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 |