Jamba  3.0.2
GUIParamCxAware.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 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
21 #include "GUIRawVstParameter.h"
22 #include "GUIJmbParameter.h"
23 #include "GUIVstParameter.h"
24 
25 namespace pongasoft {
26 namespace VST {
27 namespace GUI {
28 
29 class GUIState;
30 
31 namespace Params {
32 
33 class GUIParamCxMgr;
34 
39 {
40 public:
41  virtual ~GUIParamCxAware();
42 
46  GUIRawVstParam registerRawVstParam(ParamID iParamID, bool iSubscribeToChanges = true);
47 
51  GUIRawVstParam registerRawVstCallback(ParamID iParamID,
52  Parameters::ChangeCallback iChangeCallback,
53  bool iInvokeCallback = false);
54 
58  GUIRawVstParam registerParam(RawVstParam const &iParamDef, bool iSubscribeToChanges = true) {
59  return registerRawVstParam(iParamDef->fParamID, iSubscribeToChanges);
60  }
61 
66  Parameters::ChangeCallback iChangeCallback,
67  bool iInvokeCallback = false) {
68  return registerRawVstCallback(iParamDef->fParamID, std::move(iChangeCallback), iInvokeCallback);
69  }
70 
81  bool __internal__registerRawVstControl(int32_t iParamID, ParamValue &oControlValue, GUIRawVstParam &oGUIRawVstParam);
82 
83  // shortcut for BooleanParameter
84  GUIVstParam<bool> registerVstBooleanParam(ParamID iParamID, bool iSubscribeToChanges = true);
85 
86  // shortcut for PercentParameter
87  GUIVstParam<Percent> registerVstPercentParam(ParamID iParamID, bool iSubscribeToChanges = true);
88 
93  template<typename T>
94  GUIVstParam<T> registerVstParam(ParamID iParamID, bool iSubscribeToChanges = true);
95 
100  template<typename T>
101  GUIVstParam<T> registerVstCallback(ParamID iParamID,
102  Parameters::ChangeCallback iChangeCallback,
103  bool iInvokeCallback = false);
104 
115  template<typename T>
116  bool __internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam<T> &oGUIVstParam);
117 
122  template<typename T>
123  GUIVstParam<T> registerParam(VstParam<T> const &iParamDef, bool iSubscribeToChanges = true);
124 
131  template<typename T>
133  Parameters::ChangeCallback iChangeCallback,
134  bool iInvokeCallback = false);
135 
149  template<typename T>
150  bool registerCallback(VstParam<T> const &iParamDef,
152  bool iInvokeCallback = false);
153 
162  template<typename T>
164 
171  template<typename T>
173  Parameters::ChangeCallback iChangeCallback,
174  bool iInvokeCallback = false);
175 
186  template<typename T>
187  bool registerCallback(GUIJmbParam<T> &iParamDef,
189  bool iInvokeCallback = false);
190 
196  template<typename T>
197  GUIJmbParam<T> registerJmbParam(ParamID iParamID, bool iSubscribeToChanges = true);
198 
204  template<typename T>
205  GUIJmbParam<T> registerJmbCallback(ParamID iParamID,
206  Parameters::ChangeCallback iChangeCallback,
207  bool iInvokeCallback = false);
208 
212  virtual void initState(GUIState *iGUIState);
213 
217  virtual void registerParameters()
218  {
219  // subclasses implements this method
220  }
221 
224  void unregisterAll();
225 
231  bool unregisterParam(ParamID iParamID);
232 
239 
245  template<typename T>
247 
253  template<typename T>
255 
259  void onParameterChange(ParamID iParamID) override {}
260 
263  void invokeAll();
264 
265 protected:
266  // Access to parameters
267  std::unique_ptr<GUIParamCxMgr> fParamCxMgr{};
268 };
269 
276 template<typename TView>
278 {
279 public:
280  // required because we implement other registerCallback methods
282 
283  // defining the change listener callback
284  using ChangeListener = std::function<void(TView *, ParamID)>;
285 
286  // Constructor
287  explicit ViewGUIParamCxAware(TView *iView) : fView(iView), fListener{} {}
288 
294  {
295  fListener = std::move(iListener);
296  }
297 
308  template<typename T>
309  inline bool registerCallback(VstParam<T> const &iParamDef,
310  Parameters::ChangeCallback2<TView, GUIVstParam<T>> iChangeCallback,
311  bool iInvokeCallback = false)
312  {
313  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIVstParam<T> &iParam) {
314  cb2(view, iParam);
315  };
316 
317  return GUIParamCxAware::registerCallback<T>(iParamDef, std::move(callback), iInvokeCallback);
318  }
319 
330  template<typename T>
331  inline bool registerCallback(GUIJmbParam<T> &iParam,
332  Parameters::ChangeCallback2<TView, GUIJmbParam<T>> iChangeCallback,
333  bool iInvokeCallback = false)
334  {
335  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIJmbParam<T> &iParam) {
336  cb2(view, iParam);
337  };
338 
339  return GUIParamCxAware::registerCallback<T>(iParam, std::move(callback), iInvokeCallback);
340  }
341 
342  // onParameterChange => delegate to listener
343  void onParameterChange(ParamID iParamID) override
344  {
345  if(fListener)
346  fListener(fView, iParamID);
347  }
348 
349 private:
350  TView *fView;
352 };
353 
354 }
355 }
356 }
357 }
GUIRawVstParam registerRawVstParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.cpp:45
std::shared_ptr< VstParamDef< T > > VstParam
Definition: ParamDef.h:358
ViewGUIParamCxAware(TView *iView)
Definition: GUIParamCxAware.h:287
TView * fView
Definition: GUIParamCxAware.h:350
Definition: GUIState.h:39
ChangeListener fListener
Definition: GUIParamCxAware.h:351
Definition: GUIRawVstParameter.h:211
GUIVstParam< Percent > registerVstPercentParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.cpp:107
GUIVstParam< bool > registerVstBooleanParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.cpp:99
void registerListener(ChangeListener iListener)
Definition: GUIParamCxAware.h:293
Definition: Clock.h:22
void unregisterAll()
Definition: GUIParamCxAware.cpp:136
void onParameterChange(ParamID iParamID) override
Definition: GUIParamCxAware.h:259
std::function< void(TView *, ParamID)> ChangeListener
Definition: GUIParamCxAware.h:284
GUIRawVstParam registerRawVstCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.cpp:86
virtual void registerParameters()
Definition: GUIParamCxAware.h:217
void invokeAll()
Definition: GUIParamCxAware.cpp:145
Definition: GUIParamCxAware.h:277
Definition: GUIJmbParameter.h:230
bool unregisterParam(ParamID iParamID)
Definition: GUIParamCxAware.cpp:116
bool registerCallback(VstParam< T > const &iParamDef, Parameters::ChangeCallback2< TView, GUIVstParam< T >> iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:309
std::shared_ptr< RawVstParamDef > RawVstParam
Definition: ParamDef.h:359
std::function< void()> ChangeCallback
Definition: Parameters.h:57
virtual ~GUIParamCxAware()
Definition: GUIParamCxAware.cpp:29
bool __internal__registerRawVstControl(int32_t iParamID, ParamValue &oControlValue, GUIRawVstParam &oGUIRawVstParam)
Definition: GUIParamCxAware.cpp:56
Definition: GUIParamCxAware.h:38
bool __internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam< T > &oGUIVstParam)
Definition: GUIParamCxAware.hpp:188
virtual void initState(GUIState *iGUIState)
Definition: GUIParamCxAware.cpp:37
GUIVstParam< T > registerVstCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.hpp:45
GUIRawVstParam registerParam(RawVstParam const &iParamDef, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.h:58
std::unique_ptr< GUIParamCxMgr > fParamCxMgr
Definition: GUIParamCxAware.h:267
GUIRawVstParam registerCallback(RawVstParam const &iParamDef, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:65
bool registerCallback(GUIJmbParam< T > &iParam, Parameters::ChangeCallback2< TView, GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:331
GUIJmbParam< T > registerJmbParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.hpp:140
GUIJmbParam< T > registerJmbCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.hpp:152
GUIVstParam< T > registerVstParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.hpp:33
std::function< void(Param &)> ChangeCallback1
Definition: Parameters.h:63
void onParameterChange(ParamID iParamID) override
Definition: GUIParamCxAware.h:343
std::function< void(TView *, Param &)> ChangeCallback2
Definition: Parameters.h:69