Jamba  3.0.2
GUIParamCxAware.hpp
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 
20 #include "GUIParamCxAware.h"
21 #include "GUIParamCxMgr.h"
22 
23 namespace pongasoft {
24 namespace VST {
25 namespace GUI {
26 namespace Params {
27 
28 
29 //------------------------------------------------------------------------
30 // GUIParamCxAware::registerVstParam
31 //------------------------------------------------------------------------
32 template<typename T>
33 GUIVstParam<T> GUIParamCxAware::registerVstParam(ParamID iParamID, bool iSubscribeToChanges)
34 {
35  if(fParamCxMgr)
36  return fParamCxMgr->registerVstParam<T>(iParamID, iSubscribeToChanges ? this : nullptr);
37  else
38  return GUIVstParam<T>{};
39 }
40 
41 //------------------------------------------------------------------------
42 // GUIParamCxAware::registerVstCallback
43 //------------------------------------------------------------------------
44 template<typename T>
46  Parameters::ChangeCallback iChangeCallback,
47  bool iInvokeCallback)
48 {
49  if(fParamCxMgr)
50  return fParamCxMgr->registerVstCallback<T>(iParamID, std::move(iChangeCallback), iInvokeCallback);
51  else
52  return GUIVstParam<T>{};
53 }
54 
55 //------------------------------------------------------------------------
56 // GUIParamCxAware::registerParam
57 //------------------------------------------------------------------------
58 template<typename T>
59 GUIVstParam<T> GUIParamCxAware::registerParam(VstParam<T> const &iParamDef, bool iSubscribeToChanges)
60 {
61  if(fParamCxMgr)
62  return fParamCxMgr->registerVstParam(iParamDef, iSubscribeToChanges ? this : nullptr);
63  else
64  return GUIVstParam<T>{};
65 }
66 
67 //------------------------------------------------------------------------
68 // GUIParamCxAware::registerCallback
69 //------------------------------------------------------------------------
70 template<typename T>
73  Parameters::ChangeCallback iChangeCallback,
74  bool iInvokeCallback)
75 {
76  if(fParamCxMgr)
77  return fParamCxMgr->registerVstCallback(iParamDef, std::move(iChangeCallback), iInvokeCallback);
78  else
79  return GUIVstParam<T>{};
80 }
81 
82 //------------------------------------------------------------------------
83 // GUIParamCxAware::registerCallback
84 //------------------------------------------------------------------------
85 template<typename T>
88  bool iInvokeCallback)
89 {
90  return fParamCxMgr ? fParamCxMgr->registerVstCallback(iParamDef, std::move(iChangeCallback), iInvokeCallback) : false;
91 }
92 
93 //------------------------------------------------------------------------
94 // GUIParamCxAware::registerParam
95 //------------------------------------------------------------------------
96 template<typename T>
98 {
99  if(fParamCxMgr)
100  return fParamCxMgr->registerJmbParam(iParamDef, this);
101  else
102  return GUIJmbParam<T>{};
103 }
104 
105 //------------------------------------------------------------------------
106 // GUIParamCxAware::registerCallback
107 //------------------------------------------------------------------------
108 template<typename T>
110  Parameters::ChangeCallback iChangeCallback,
111  bool iInvokeCallback)
112 {
113  if(fParamCxMgr)
114  return fParamCxMgr->registerJmbCallback(iParamDef, std::move(iChangeCallback), iInvokeCallback);
115  else
116  return GUIJmbParam<T>{};
117 }
118 
119 //------------------------------------------------------------------------
120 // GUIParamCxAware::registerCallback
121 //------------------------------------------------------------------------
122 template<typename T>
125  bool iInvokeCallback)
126 {
127  if(fParamCxMgr)
128  {
129  fParamCxMgr->registerJmbCallback(iParamDef, std::move(iChangeCallback), iInvokeCallback);
130  return true;
131  }
132  else
133  return false;
134 }
135 
136 //------------------------------------------------------------------------
137 // GUIParamCxAware::registerJmbParam
138 //------------------------------------------------------------------------
139 template<typename T>
140 GUIJmbParam<T> GUIParamCxAware::registerJmbParam(ParamID iParamID, bool iSubscribeToChanges)
141 {
142  if(fParamCxMgr)
143  return fParamCxMgr->registerJmbParam<T>(iParamID, iSubscribeToChanges ? this : nullptr);
144  else
145  return GUIJmbParam<T>{};
146 }
147 
148 //------------------------------------------------------------------------
149 // GUIParamCxAware::registerJmbCallback
150 //------------------------------------------------------------------------
151 template<typename T>
153  Parameters::ChangeCallback iChangeCallback,
154  bool iInvokeCallback)
155 {
156  if(fParamCxMgr)
157  return fParamCxMgr->registerJmbCallback<T>(iParamID, std::move(iChangeCallback), iInvokeCallback);
158  else
159  return GUIJmbParam<T>{};
160 }
161 
162 //------------------------------------------------------------------------
163 // GUIParamCxAware::unregisterParam
164 //------------------------------------------------------------------------
165 template<typename T>
167 {
168  if(iParam.exists())
169  fParamCxMgr->unregisterParam(iParam.getParamID());
170  return GUIVstParam<T>{};
171 }
172 
173 //------------------------------------------------------------------------
174 // GUIParamCxAware::unregisterParam
175 //------------------------------------------------------------------------
176 template<typename T>
178 {
179  if(iParam.exists())
180  fParamCxMgr->unregisterParam(iParam.getParamID());
181  return GUIJmbParam<T>{};
182 }
183 
184 //------------------------------------------------------------------------
185 // GUIParamCxAware::__internal__registerVstControl
186 //------------------------------------------------------------------------
187 template<typename T>
188 bool GUIParamCxAware::__internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam<T> &oGUIVstParam)
189 {
190  if(!fParamCxMgr)
191  return false; // not set yet
192 
193  if(iParamID < 0)
194  {
195  if(oGUIVstParam.exists())
196  {
197  oControlValue = oGUIVstParam.getValue();
198  oGUIVstParam = unregisterParam(oGUIVstParam);
199  }
200  }
201  else
202  {
203  if(!oGUIVstParam.exists() || oGUIVstParam.getParamID() != iParamID)
204  {
205  oGUIVstParam = registerVstParam<T>(static_cast<ParamID>(iParamID));
206  return true;
207  }
208  }
209 
210  return false;
211 }
212 
213 
214 }
215 }
216 }
217 }
T getValue() const
Definition: GUIVstParameter.h:259
std::shared_ptr< VstParamDef< T > > VstParam
Definition: ParamDef.h:358
Definition: Clock.h:22
Definition: GUIVstParameter.h:233
ParamID getParamID() const
Definition: GUIVstParameter.h:254
bool exists() const
Definition: GUIJmbParameter.h:238
Definition: GUIJmbParameter.h:230
bool unregisterParam(ParamID iParamID)
Definition: GUIParamCxAware.cpp:116
ParamID getParamID() const
Definition: GUIJmbParameter.h:241
std::function< void()> ChangeCallback
Definition: Parameters.h:57
bool exists() const
Definition: GUIVstParameter.h:251
bool __internal__registerVstControl(int32_t iParamID, T &oControlValue, GUIVstParam< T > &oGUIVstParam)
Definition: GUIParamCxAware.hpp:188
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
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