Jamba C++ API  4.1.0
GUIParamCxMgr.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 <vector>
22 
24 
32 {
33 public:
37  inline bool existsVst(ParamID iParamID) const { return fGUIState->existsVst(iParamID); }
38 
42  inline bool existsJmb(ParamID iParamID) const { return fGUIState->existsJmb(iParamID); }
43 
46  void unregisterAll();
47 
48  //------------------------------------------------------------------------
49  // Base Param
50  //------------------------------------------------------------------------
51 
52  // registerBaseParam / ParamID / IChangeListener
53  IGUIParam registerBaseParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener = nullptr);
54 
55  // registerBaseCallback / ParamID / ChangeCallback
56  inline IGUIParam registerBaseCallback(ParamID iParamID,
57  Parameters::ChangeCallback iChangeCallback,
58  bool iInvokeCallback)
59  {
60  return __registerCallback(registerBaseParam(iParamID), std::move(iChangeCallback), iInvokeCallback);
61  }
62 
63  // registerBaseCallback / ParamID / ChangeCallback1<IGUIParam>
64  inline IGUIParam registerBaseCallback(ParamID iParamID,
66  bool iInvokeCallback)
67  {
68  return __registerCallback1(registerBaseParam(iParamID), std::move(iChangeCallback), iInvokeCallback);
69  }
70 
71  //------------------------------------------------------------------------
72  // Optional Param
73  //------------------------------------------------------------------------
74 
75  // registerOptionalParam / ParamID / IChangeListener
76  template<typename T>
78  Parameters::IChangeListener *iChangeListener = nullptr);
79 
80  // registerOptionalCallback / ParamID / ChangeCallback
81  template<typename T>
83  Parameters::ChangeCallback iChangeCallback,
84  bool iInvokeCallback) {
85  return __registerCallback(registerOptionalParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
86  }
87 
88  // registerOptionalCallback / ParamID / ChangeCallback1<GUIOptionalParam<T>>
89  template<typename T>
92  bool iInvokeCallback) {
93  return __registerCallback1(registerOptionalParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
94  }
95 
96  //------------------------------------------------------------------------
97  // Optional Discrete Param
98  //------------------------------------------------------------------------
99 
100  // registerOptionalDiscreteParam / ParamID / IChangeListener
102  int32 iStepCount,
103  Parameters::IChangeListener *iChangeListener = nullptr);
104 
105  // registerOptionalDiscreteCallback / ParamID / ChangeCallback
107  int32 iStepCount,
108  Parameters::ChangeCallback iChangeCallback,
109  bool iInvokeCallback) {
110  return __registerCallback(registerOptionalDiscreteParam(iParamID, iStepCount), std::move(iChangeCallback), iInvokeCallback);
111  }
112 
113  // registerOptionalDiscreteCallback / ParamID / ChangeCallback1<GUIOptionalParam<int32>>
115  int32 iStepCount,
117  bool iInvokeCallback) {
118  return __registerCallback1(registerOptionalDiscreteParam(iParamID, iStepCount), std::move(iChangeCallback), iInvokeCallback);
119  }
120 
121  //------------------------------------------------------------------------
122  // Raw Vst Param
123  //------------------------------------------------------------------------
124 
125  // registerRawVstParam / ParamID / IChangeListener
126  GUIRawVstParam registerRawVstParam(ParamID iParamID,
127  Parameters::IChangeListener *iChangeListener = nullptr);
128 
129  // registerRawVstCallback / ParamID / ChangeCallback
130  inline GUIRawVstParam registerRawVstCallback(ParamID iParamID,
131  Parameters::ChangeCallback iChangeCallback,
132  bool iInvokeCallback)
133  {
134  return __registerCallback(registerRawVstParam(iParamID), std::move(iChangeCallback), iInvokeCallback);
135  }
136 
137  // registerRawVstCallback / ParamID / ChangeCallback1<GUIRawVstParam>
138  inline GUIRawVstParam registerRawVstCallback(ParamID iParamID,
140  bool iInvokeCallback)
141  {
142  return __registerCallback1(registerRawVstParam(iParamID), std::move(iChangeCallback), iInvokeCallback);
143  }
144 
145  //------------------------------------------------------------------------
146  // Vst Param (Typed)
147  //------------------------------------------------------------------------
148 
149  // registerVstParam / ParamID / IChangeListener
150  template<typename T>
151  GUIVstParam<T> registerVstParam(ParamID iParamID,
152  Parameters::IChangeListener *iChangeListener = nullptr);
153 
154  // registerVstParam / ParamID / ChangeCallback
155  template<typename T>
156  inline GUIVstParam<T> registerVstCallback(ParamID iParamID,
157  Parameters::ChangeCallback iChangeCallback,
158  bool iInvokeCallback)
159  {
160  return __registerCallback(registerVstParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
161  }
162 
163  // registerVstParam / ParamID / ChangeCallback1<GUIVstParam<T>>
164  template<typename T>
165  inline GUIVstParam<T> registerVstCallback(ParamID iParamID,
167  bool iInvokeCallback)
168  {
169  return __registerCallback1(registerVstParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
170  }
171 
172  //------------------------------------------------------------------------
173  // Jmb Param (Typed)
174  //------------------------------------------------------------------------
175 
176  // registerJmbParam / ParamID / IChangeListener
177  template<typename T>
178  GUIJmbParam<T> registerJmbParam(ParamID iParamID,
179  Parameters::IChangeListener *iChangeListener = nullptr);
180 
181  // registerJmbParam / ParamID / ChangeCallback
182  template<typename T>
183  inline GUIJmbParam<T> registerJmbCallback(ParamID iParamID,
184  Parameters::ChangeCallback iChangeCallback,
185  bool iInvokeCallback)
186  {
187  return __registerCallback(registerJmbParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
188  }
189 
190  // registerJmbParam / ParamID / ChangeCallback1<GUIJmbParam<T>>
191  template<typename T>
192  inline GUIJmbParam<T> registerJmbCallback(ParamID iParamID,
194  bool iInvokeCallback)
195  {
196  return __registerCallback1(registerJmbParam<T>(iParamID), std::move(iChangeCallback), iInvokeCallback);
197  }
198 
199  // getGUIState
200  inline GUIState *getGUIState() const { return fGUIState; };
201 
204  void invokeAll();
205 
206  friend class GUI::GUIState;
207 
208 protected:
209  explicit GUIParamCxMgr(GUIState *iGUIState) : fGUIState{iGUIState}
210  {
211  DCHECK_F(fGUIState != nullptr);
212  }
213 
214  template<typename TParam>
215  inline TParam __registerListener(TParam iParam, Parameters::IChangeListener *iChangeListener)
216  {
217  if(iParam.exists() && iChangeListener)
218  fParamCxs.emplace_back(iParam.connect(iChangeListener));
219  return iParam;
220  }
221 
222  template<typename TParam>
223  TParam __registerCallback(TParam iParam, Parameters::ChangeCallback iCallback, bool iInvokeCallback);
224 
225  template<typename TParam>
226  TParam __registerCallback1(TParam iParam, Parameters::ChangeCallback1<TParam> iCallback, bool iInvokeCallback);
227 
228 private:
229  // the gui state
231 
232  // Maintains the connections for the listeners and callbacks... will be automatically discarded in the destructor
233  std::vector<std::unique_ptr<FObjectCx>> fParamCxs{};
234 };
235 
236 }
237 
238 // Include template implementation code
239 #include "GUIParamCxMgr.hpp"
bool existsJmb(ParamID iParamID) const
Definition: GUIState.h:67
IGUIParam registerBaseParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.cpp:87
GUIRawVstParam registerRawVstCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:130
Definition: GUIState.h:40
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition: GUIRawVstParameter.h:258
std::function< void()> ChangeCallback
A callback that will be invoked for changes.
Definition: Parameters.h:55
std::vector< std::unique_ptr< FObjectCx > > fParamCxs
Definition: GUIParamCxMgr.h:233
IGUIParam registerBaseCallback(ParamID iParamID, Parameters::ChangeCallback1< IGUIParam > iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:64
TParam __registerCallback1(TParam iParam, Parameters::ChangeCallback1< TParam > iCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.hpp:120
GUIVstParam< T > registerVstCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:156
bool existsVst(ParamID iParamID) const
Definition: GUIState.h:62
GUIState * fGUIState
Definition: GUIParamCxMgr.h:230
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition: GUIVstParameter.h:272
GUIOptionalParam< T > registerOptionalCallback(ParamID iParamID, Parameters::ChangeCallback1< GUIOptionalParam< T >> iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:90
TParam __registerListener(TParam iParam, Parameters::IChangeListener *iChangeListener)
Definition: GUIParamCxMgr.h:215
GUIVstParam< T > registerVstCallback(ParamID iParamID, Parameters::ChangeCallback1< GUIVstParam< T >> iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:165
Definition: GUIState.h:36
GUIOptionalParam< int32 > registerOptionalDiscreteCallback(ParamID iParamID, int32 iStepCount, Parameters::ChangeCallback1< GUIOptionalParam< int32 >> iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:114
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition: GUIJmbParameter.h:489
GUIVstParam< T > registerVstParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.hpp:63
bool existsJmb(ParamID iParamID) const
Definition: GUIParamCxMgr.h:42
GUIOptionalParam< T > registerOptionalParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.hpp:26
GUIOptionalParam< int32 > registerOptionalDiscreteCallback(ParamID iParamID, int32 iStepCount, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:106
GUIOptionalParam< T > registerOptionalCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:82
std::function< void(Param &)> ChangeCallback1
A callback which will be invoked for changes with the param as an argument.
Definition: Parameters.h:61
GUIJmbParam< T > registerJmbCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:183
GUIParamCxMgr(GUIState *iGUIState)
Definition: GUIParamCxMgr.h:209
void invokeAll()
Invoke all registered callbacks and listeners.
Definition: GUIParamCxMgr.cpp:25
bool existsVst(ParamID iParamID) const
Definition: GUIParamCxMgr.h:37
IGUIParam registerBaseCallback(ParamID iParamID, Parameters::ChangeCallback iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:56
Maintains the connections established between parameters and its listeners/callbacks.
Definition: GUIParamCxMgr.h:31
GUIOptionalParam< int32 > registerOptionalDiscreteParam(ParamID iParamID, int32 iStepCount, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.cpp:44
GUIJmbParam< T > registerJmbParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.hpp:74
void unregisterAll()
Unregisters all parameters.
Definition: GUIParamCxMgr.cpp:36
GUIRawVstParam registerRawVstCallback(ParamID iParamID, Parameters::ChangeCallback1< GUIRawVstParam > iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:138
GUIJmbParam< T > registerJmbCallback(ParamID iParamID, Parameters::ChangeCallback1< GUIJmbParam< T >> iChangeCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.h:192
Wrapper instance returned by ParamAware::registerBaseParam() methods.
Definition: IGUIParameter.h:397
GUIState * getGUIState() const
Definition: GUIParamCxMgr.h:200
TParam __registerCallback(TParam iParam, Parameters::ChangeCallback iCallback, bool iInvokeCallback)
Definition: GUIParamCxMgr.hpp:97
GUIRawVstParam registerRawVstParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition: GUIParamCxMgr.cpp:97
Interface to implement to receive parameter changes.
Definition: Parameters.h:43
Represents an optional parameter (Jmb, Vst or no param at all).
Definition: GUIOptionalParam.h:48