Jamba  3.1.0
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> &oParam);
117 
128  bool __internal__registerVstControl(int32_t iParamID, ParamValue &oControlValue, GUIRawVstParam &oParam);
129 
134  template<typename T>
135  GUIVstParam<T> registerParam(VstParam<T> const &iParamDef, bool iSubscribeToChanges = true);
136 
143  template<typename T>
145  Parameters::ChangeCallback iChangeCallback,
146  bool iInvokeCallback = false);
147 
161  template<typename T>
162  bool registerCallback(VstParam<T> const &iParamDef,
164  bool iInvokeCallback = false);
165 
174  template<typename T>
176 
183  template<typename T>
185  Parameters::ChangeCallback iChangeCallback,
186  bool iInvokeCallback = false);
187 
198  template<typename T>
199  bool registerCallback(GUIJmbParam<T> &iParamDef,
201  bool iInvokeCallback = false);
202 
208  template<typename T>
209  GUIJmbParam<T> registerJmbParam(ParamID iParamID, bool iSubscribeToChanges = true);
210 
216  template<typename T>
217  GUIJmbParam<T> registerJmbCallback(ParamID iParamID,
218  Parameters::ChangeCallback iChangeCallback,
219  bool iInvokeCallback = false);
220 
224  virtual void initState(GUIState *iGUIState);
225 
229  virtual void registerParameters()
230  {
231  // subclasses implements this method
232  }
233 
236  void unregisterAll();
237 
243  bool unregisterParam(ParamID iParamID);
244 
251 
257  template<typename T>
259 
265  template<typename T>
267 
271  void onParameterChange(ParamID iParamID) override {}
272 
275  void invokeAll();
276 
277 protected:
278  // Access to parameters
279  std::unique_ptr<GUIParamCxMgr> fParamCxMgr{};
280 };
281 
288 template<typename TView>
290 {
291 public:
292  // required because we implement other registerCallback methods
294 
295  // defining the change listener callback
296  using ChangeListener = std::function<void(TView *, ParamID)>;
297 
298  // Constructor
299  explicit ViewGUIParamCxAware(TView *iView) : fView(iView), fListener{} {}
300 
306  {
307  fListener = std::move(iListener);
308  }
309 
320  template<typename T>
321  inline bool registerCallback(VstParam<T> const &iParamDef,
322  Parameters::ChangeCallback2<TView, GUIVstParam<T>> iChangeCallback,
323  bool iInvokeCallback = false)
324  {
325  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIVstParam<T> &iParam) {
326  cb2(view, iParam);
327  };
328 
329  return GUIParamCxAware::registerCallback<T>(iParamDef, std::move(callback), iInvokeCallback);
330  }
331 
342  template<typename T>
343  inline bool registerCallback(GUIJmbParam<T> &iParam,
344  Parameters::ChangeCallback2<TView, GUIJmbParam<T>> iChangeCallback,
345  bool iInvokeCallback = false)
346  {
347  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIJmbParam<T> &iParam) {
348  cb2(view, iParam);
349  };
350 
351  return GUIParamCxAware::registerCallback<T>(iParam, std::move(callback), iInvokeCallback);
352  }
353 
354  // onParameterChange => delegate to listener
355  void onParameterChange(ParamID iParamID) override
356  {
357  if(fListener)
358  fListener(fView, iParamID);
359  }
360 
361 protected:
362  TView *fView;
364 };
365 
366 }
367 }
368 }
369 }
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:299
TView * fView
Definition: GUIParamCxAware.h:362
Definition: GUIState.h:39
ChangeListener fListener
Definition: GUIParamCxAware.h:363
Definition: GUIRawVstParameter.h:216
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:305
Definition: Clock.h:22
void unregisterAll()
Definition: GUIParamCxAware.cpp:136
void onParameterChange(ParamID iParamID) override
Definition: GUIParamCxAware.h:271
std::function< void(TView *, ParamID)> ChangeListener
Definition: GUIParamCxAware.h:296
bool __internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam< T > &oParam)
Definition: GUIParamCxAware.hpp:188
GUIRawVstParam registerRawVstCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.cpp:86
virtual void registerParameters()
Definition: GUIParamCxAware.h:229
void invokeAll()
Definition: GUIParamCxAware.cpp:145
Definition: GUIParamCxAware.h:289
Definition: GUIJmbParameter.h:237
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:321
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
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:279
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:343
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:355
std::function< void(TView *, Param &)> ChangeCallback2
Definition: Parameters.h:69