Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
ParamAwareViews.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#pragma once
20
21#include <unordered_map>
22#include <vector>
24#include <vstgui4/vstgui/lib/iviewlistener.h>
29
30namespace pongasoft::VST::GUI {
31
32using namespace VSTGUI;
33using namespace Params;
34
87class ParamAwareViews : private ViewListenerAdapter
88{
89public:
96 template<typename TView>
97 ParamAwareView<TView> *makeParamAware(TView *iView, GUIState *iGUIState);
98
102 void closeAll();
103
104private:
108 void viewWillDelete(CView *iView) override;
109
110private:
111 std::unordered_map<CView *, std::unique_ptr<ParamAware>> fParamAwareViews{};
112};
113
114//------------------------------------------------------------------------
115// ParamAwareViews::makeParamAware
116//------------------------------------------------------------------------
117template<typename TView>
119{
120 if(iView == nullptr)
121 return nullptr;
122
123 auto iter = fParamAwareViews.find(iView);
124
125 if(iter == fParamAwareViews.end())
126 {
127 iView->registerViewListener(this);
128 fParamAwareViews[iView] = std::make_unique<ParamAwareView<TView>>(iView);
129 fParamAwareViews[iView]->initState(iGUIState);
130 }
131
132 return static_cast<ParamAwareView<TView> *>(fParamAwareViews[iView].get());
133}
134
135
136}
Definition GUIState.h:43
This class manages the views that have been made "param aware".
Definition ParamAwareViews.h:88
void closeAll()
Close all previously established connections.
Definition ParamAwareViews.cpp:28
ParamAwareView< TView > * makeParamAware(TView *iView, GUIState *iGUIState)
Definition ParamAwareViews.h:118
void viewWillDelete(CView *iView) override
Called by VSTGUI when a view that was previously registered is being deleted => all its connections w...
Definition ParamAwareViews.cpp:36
std::unordered_map< CView *, std::unique_ptr< ParamAware > > fParamAwareViews
Definition ParamAwareViews.h:111
This subclass allows for registering callbacks to any kind of view without having to inherit from it.
Definition ParamAware.h:563
Definition GUIState.h:38
Definition DrawContext.cpp:25