Jamba  3.2.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 
56  bool registerParam(int32_t iParamID, GUIRawVstParam &oGUIRawVstParam);
57 
61  GUIRawVstParam registerRawVstCallback(ParamID iParamID,
62  Parameters::ChangeCallback iChangeCallback,
63  bool iInvokeCallback = false);
64 
68  GUIRawVstParam registerParam(RawVstParam const &iParamDef, bool iSubscribeToChanges = true) {
69  return registerRawVstParam(iParamDef->fParamID, iSubscribeToChanges);
70  }
71 
76  Parameters::ChangeCallback iChangeCallback,
77  bool iInvokeCallback = false) {
78  return registerRawVstCallback(iParamDef->fParamID, std::move(iChangeCallback), iInvokeCallback);
79  }
80 
91  bool __internal__registerRawVstControl(int32_t iParamID, ParamValue &oControlValue, GUIRawVstParam &oGUIRawVstParam);
92 
93  // shortcut for BooleanParameter
94  GUIVstParam<bool> registerVstBooleanParam(ParamID iParamID, bool iSubscribeToChanges = true);
95 
96  // shortcut for PercentParameter
97  GUIVstParam<Percent> registerVstPercentParam(ParamID iParamID, bool iSubscribeToChanges = true);
98 
103  template<typename T>
104  GUIVstParam<T> registerVstParam(ParamID iParamID, bool iSubscribeToChanges = true);
105 
110  template<typename T>
111  GUIVstParam<T> registerVstCallback(ParamID iParamID,
112  Parameters::ChangeCallback iChangeCallback,
113  bool iInvokeCallback = false);
114 
125  template<typename T>
126  bool __internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam<T> &oParam);
127 
138  bool __internal__registerVstControl(int32_t iParamID, ParamValue &oControlValue, GUIRawVstParam &oParam);
139 
144  template<typename T>
145  GUIVstParam<T> registerParam(VstParam<T> const &iParamDef, bool iSubscribeToChanges = true);
146 
153  template<typename T>
155  Parameters::ChangeCallback iChangeCallback,
156  bool iInvokeCallback = false);
157 
171  template<typename T>
172  bool registerCallback(VstParam<T> const &iParamDef,
174  bool iInvokeCallback = false);
175 
184  template<typename T>
186 
193  template<typename T>
195  Parameters::ChangeCallback iChangeCallback,
196  bool iInvokeCallback = false);
197 
208  template<typename T>
209  bool registerCallback(GUIJmbParam<T> &iParamDef,
211  bool iInvokeCallback = false);
212 
218  template<typename T>
219  GUIJmbParam<T> registerJmbParam(ParamID iParamID, bool iSubscribeToChanges = true);
220 
226  template<typename T>
227  GUIJmbParam<T> registerJmbCallback(ParamID iParamID,
228  Parameters::ChangeCallback iChangeCallback,
229  bool iInvokeCallback = false);
230 
234  virtual void initState(GUIState *iGUIState);
235 
239  virtual void registerParameters()
240  {
241  // subclasses implements this method
242  }
243 
246  void unregisterAll();
247 
253  bool unregisterParam(ParamID iParamID);
254 
261 
267  template<typename T>
269 
275  template<typename T>
277 
281  void onParameterChange(ParamID iParamID) override {}
282 
285  void invokeAll();
286 
287 protected:
288  // Access to parameters
289  std::unique_ptr<GUIParamCxMgr> fParamCxMgr{};
290 };
291 
298 template<typename TView>
300 {
301 public:
302  // required because we implement other registerCallback methods
304 
305  // defining the change listener callback
306  using ChangeListener = std::function<void(TView *, ParamID)>;
307 
308  // Constructor
309  explicit ViewGUIParamCxAware(TView *iView) : fView(iView), fListener{} {}
310 
316  {
317  fListener = std::move(iListener);
318  }
319 
330  template<typename T>
331  inline bool registerCallback(VstParam<T> const &iParamDef,
332  Parameters::ChangeCallback2<TView, GUIVstParam<T>> iChangeCallback,
333  bool iInvokeCallback = false)
334  {
335  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIVstParam<T> &iParam) {
336  cb2(view, iParam);
337  };
338 
339  return GUIParamCxAware::registerCallback<T>(iParamDef, std::move(callback), iInvokeCallback);
340  }
341 
352  template<typename T>
353  inline bool registerCallback(GUIJmbParam<T> &iParam,
354  Parameters::ChangeCallback2<TView, GUIJmbParam<T>> iChangeCallback,
355  bool iInvokeCallback = false)
356  {
357  auto callback = [view = this->fView, cb2 = std::move(iChangeCallback)] (GUIJmbParam<T> &iParam) {
358  cb2(view, iParam);
359  };
360 
361  return GUIParamCxAware::registerCallback<T>(iParam, std::move(callback), iInvokeCallback);
362  }
363 
364  // onParameterChange => delegate to listener
365  void onParameterChange(ParamID iParamID) override
366  {
367  if(fListener)
368  fListener(fView, iParamID);
369  }
370 
371 protected:
372  TView *fView;
374 };
375 
376 }
377 }
378 }
379 }
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:309
TView * fView
Definition: GUIParamCxAware.h:372
Definition: GUIState.h:39
ChangeListener fListener
Definition: GUIParamCxAware.h:373
Definition: GUIRawVstParameter.h:216
GUIVstParam< Percent > registerVstPercentParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.cpp:117
GUIVstParam< bool > registerVstBooleanParam(ParamID iParamID, bool iSubscribeToChanges=true)
Definition: GUIParamCxAware.cpp:109
void registerListener(ChangeListener iListener)
Definition: GUIParamCxAware.h:315
Definition: Clock.h:22
void unregisterAll()
Definition: GUIParamCxAware.cpp:146
void onParameterChange(ParamID iParamID) override
Definition: GUIParamCxAware.h:281
std::function< void(TView *, ParamID)> ChangeListener
Definition: GUIParamCxAware.h:306
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:96
virtual void registerParameters()
Definition: GUIParamCxAware.h:239
void invokeAll()
Definition: GUIParamCxAware.cpp:155
Definition: GUIParamCxAware.h:299
Definition: GUIJmbParameter.h:237
bool unregisterParam(ParamID iParamID)
Definition: GUIParamCxAware.cpp:126
bool registerCallback(VstParam< T > const &iParamDef, Parameters::ChangeCallback2< TView, GUIVstParam< T >> iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:331
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:65
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:68
std::unique_ptr< GUIParamCxMgr > fParamCxMgr
Definition: GUIParamCxAware.h:289
GUIRawVstParam registerCallback(RawVstParam const &iParamDef, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:75
bool registerCallback(GUIJmbParam< T > &iParam, Parameters::ChangeCallback2< TView, GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback=false)
Definition: GUIParamCxAware.h:353
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:365
bool registerParam(int32_t iParamID, GUIRawVstParam &oGUIRawVstParam)
Definition: GUIParamCxAware.cpp:56
std::function< void(TView *, Param &)> ChangeCallback2
Definition: Parameters.h:69