Jamba  3.0.2
RTParameter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #include <pluginterfaces/vst/ivstaudioprocessor.h>
19 
20 #ifndef __PONGASOFT_VST_RT_PARAMETER_H__
21 #define __PONGASOFT_VST_RT_PARAMETER_H__
22 
23 #include <pongasoft/VST/ParamDef.h>
24 #include <pongasoft/logging/logging.h>
25 
26 namespace pongasoft {
27 namespace VST {
28 namespace RT {
29 
36 {
37 public:
38  // Constructor
39  explicit RTRawVstParameter(std::shared_ptr<RawVstParamDef> iParamDef) :
40  fParamDef{iParamDef},
41  fNormalizedValue{fParamDef->fDefaultValue},
43  {}
44 
45  // getParamID
46  ParamID getParamID() const { return fParamDef->fParamID; }
47 
48  // getParamDef
49  inline RawVstParamDef const *getParamDef() const { return fParamDef.get(); }
50 
57  virtual bool updateNormalizedValue(ParamValue iNormalizedValue);
58 
59  // getNormalizedValue
60  inline ParamValue const &getNormalizedValue() const { return fNormalizedValue; }
61 
62  // getPreviousNormalizedValue
63  inline ParamValue const &getPreviousNormalizedValue() const { return fPreviousNormalizedValue; }
64 
68  tresult addToOutput(ProcessData &oData);
69 
73  inline bool hasChanged() const { return fNormalizedValue != fPreviousNormalizedValue; }
74 
79  virtual bool resetPreviousValue();
80 
81 protected:
82  std::shared_ptr<RawVstParamDef> fParamDef;
83  ParamValue fNormalizedValue;
85 };
86 
91 template<typename T>
93 {
94 public:
95  using ParamType = T;
96 
97  // Constructor
98  explicit RTVstParameter(VstParam<T> iParamDef) :
99  RTRawVstParameter(iParamDef),
102  {
103  }
104 
105  // getParamDef
106  inline VstParamDef<T> const *getParamDefT() const
107  {
108  return static_cast<VstParamDef<T> const *>(getParamDef());
109  }
110 
111  // shortcut to normalize
112  inline ParamValue normalize(ParamType const &iValue) const { return getParamDefT()->normalize(iValue); }
113 
114  // shortcut to denormalize
115  inline ParamType denormalize(ParamValue iNormalizedValue) const { return getParamDefT()->denormalize(iNormalizedValue); }
116 
121  void update(ParamType const &iNewValue);
122 
123  // getValue
124  inline ParamType const &getValue() const { return fValue; }
125 
126  // getPreviousValue
127  inline ParamType const &getPreviousValue() const { return fPreviousValue; }
128 
129 protected:
130  // Override the base class to update the denormalized value as well
131  bool updateNormalizedValue(ParamValue iNormalizedValue) override;
132 
133  // Override the base class to update the denormalized value as well
134  bool resetPreviousValue() override;
135 
136 protected:
139 };
140 
141 //------------------------------------------------------------------------
142 // RTParameter::updateNormalizedValue - update fValue to the new value and return true if it changed
143 //------------------------------------------------------------------------
144 template<typename T>
145 bool RTVstParameter<T>::updateNormalizedValue(ParamValue iNormalizedValue)
146 {
147  if(RTRawVstParameter::updateNormalizedValue(iNormalizedValue))
148  {
149  fValue = denormalize(iNormalizedValue);
150  return true;
151  }
152 
153  return false;
154 }
155 
156 //------------------------------------------------------------------------
157 // RTParameter::resetPreviousValue
158 //------------------------------------------------------------------------
159 template<typename T>
161 {
163  {
164  fPreviousValue = fValue;
165  return true;
166  }
167 
168  return false;
169 }
170 
171 //------------------------------------------------------------------------
172 // RTParameter::update
173 //------------------------------------------------------------------------
174 template<typename T>
175 void RTVstParameter<T>::update(const ParamType &iNewValue)
176 {
177  fValue = iNewValue;
178  fNormalizedValue = normalize(fValue);
179 }
180 
181 //------------------------------------------------------------------------
182 // RTVstParam - wrapper to make writing the code much simpler and natural
183 //------------------------------------------------------------------------
190 template<typename T>
192 {
193  using ParamType = T;
194 
195 public:
197  {}
198 
199  // getParamID
200  inline ParamID getParamID() const { return fPtr->getParamID(); }
201 
202  // shortcut to normalize
203  inline ParamValue normalize(ParamType const &iValue) const { return fPtr->normalize(iValue); }
204 
205  // shortcut to denormalize
206  inline ParamType denormalize(ParamValue iNormalizedValue) const { return fPtr->denormalize(iNormalizedValue); }
207 
208  // getValue
209  inline T const &getValue() const { return fPtr->getValue(); }
210 
211  // value -- synonym
212  inline T const &value() const { return fPtr->getValue(); }
213 
219  inline void update(ParamType const &iNewValue) { fPtr->update(iNewValue); }
220 
225  inline void update(ParamType const &iNewValue, ProcessData &oData)
226  {
227  update(iNewValue);
228  addToOutput(oData);
229  }
230 
234  inline bool hasChanged() const { return fPtr->hasChanged(); }
235 
239  inline tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
240 
241  // allow to use the param as the underlying ParamType (ex: "if(param)" in the case ParamType is bool))
242  inline operator ParamType const &() const { return fPtr->getValue(); }
243 
244  // allow writing param->xxx to access the underlying type directly (if not a primitive)
245  inline ParamType const *operator->() const { return &fPtr->getValue(); }
246 
247  // previous
248  inline ParamType const &previous() const { return fPtr->getPreviousValue(); }
249 
250 private:
252 };
253 
254 //------------------------------------------------------------------------
255 // RTRawVstParam - wrapper to make writing the code much simpler and natural
256 //------------------------------------------------------------------------
262 {
263 public:
265  {}
266 
267  // getParamID
268  inline ParamID getParamID() const { return fPtr->getParamID(); }
269 
270  // getValue
271  inline ParamValue const &getValue() const { return fPtr->getNormalizedValue(); }
272 
273  // value - synonym
274  inline ParamValue const &value() const { return fPtr->getNormalizedValue(); }
275 
281  inline void update(ParamValue const &iNewValue) { fPtr->updateNormalizedValue(iNewValue); }
282 
287  inline void update(ParamValue const &iNewValue, ProcessData &oData)
288  {
289  update(iNewValue);
290  addToOutput(oData);
291  }
292 
296  inline bool hasChanged() const { return fPtr->hasChanged(); }
297 
301  inline tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
302 
303  // allow to use the param as the ParamValue
304  inline operator ParamValue const &() const { return fPtr->getNormalizedValue(); }
305 
306  // previous
307  inline ParamValue const &previous() const { return fPtr->getPreviousNormalizedValue(); }
308 
309 private:
311 };
312 
313 }
314 }
315 }
316 
317 #endif // __PONGASOFT_VST_RT_PARAMETER_H__
ParamType denormalize(ParamValue iNormalizedValue) const
Definition: RTParameter.h:206
Definition: RTParameter.h:191
RTRawVstParam(RTRawVstParameter *iPtr)
Definition: RTParameter.h:264
std::shared_ptr< VstParamDef< T > > VstParam
Definition: ParamDef.h:358
RTRawVstParameter(std::shared_ptr< RawVstParamDef > iParamDef)
Definition: RTParameter.h:39
tresult addToOutput(ProcessData &oData)
Definition: RTParameter.h:301
RawVstParamDef const * getParamDef() const
Definition: RTParameter.h:49
bool hasChanged() const
Definition: RTParameter.h:296
bool updateNormalizedValue(ParamValue iNormalizedValue) override
Definition: RTParameter.h:145
ParamID getParamID() const
Definition: RTParameter.h:268
VstParamDef< T > const * getParamDefT() const
Definition: RTParameter.h:106
ParamType fPreviousValue
Definition: RTParameter.h:138
Definition: Clock.h:22
RTVstParam(RTVstParameter< T > *iPtr)
Definition: RTParameter.h:196
T ParamType
Definition: RTParameter.h:95
bool hasChanged() const
Definition: RTParameter.h:73
ParamType const & getValue() const
Definition: RTParameter.h:124
ParamID getParamID() const
Definition: RTParameter.h:200
virtual bool updateNormalizedValue(ParamValue iNormalizedValue)
Definition: RTParameter.cpp:49
tresult addToOutput(ProcessData &oData)
Definition: RTParameter.cpp:29
RTVstParameter< T > * fPtr
Definition: RTParameter.h:251
void update(ParamType const &iNewValue)
Definition: RTParameter.h:175
ParamValue const & getValue() const
Definition: RTParameter.h:271
ParamType const & previous() const
Definition: RTParameter.h:248
T ParamType
Definition: RTParameter.h:193
ParamType fValue
Definition: RTParameter.h:137
ParamValue const & previous() const
Definition: RTParameter.h:307
ParamValue normalize(ParamType const &iValue) const
Definition: RTParameter.h:203
void update(ParamValue const &iNewValue)
Definition: RTParameter.h:281
tresult addToOutput(ProcessData &oData)
Definition: RTParameter.h:239
ParamType denormalize(ParamValue iNormalizedValue) const
Definition: RTParameter.h:115
ParamType const * operator->() const
Definition: RTParameter.h:245
ParamValue normalize(ParamType const &iValue) const
Definition: RTParameter.h:112
bool resetPreviousValue() override
Definition: RTParameter.h:160
std::shared_ptr< RawVstParamDef > fParamDef
Definition: RTParameter.h:82
T const & value() const
Definition: RTParameter.h:212
void update(ParamType const &iNewValue, ProcessData &oData)
Definition: RTParameter.h:225
ParamValue fPreviousNormalizedValue
Definition: RTParameter.h:84
ParamValue const & getNormalizedValue() const
Definition: RTParameter.h:60
bool hasChanged() const
Definition: RTParameter.h:234
ParamValue fNormalizedValue
Definition: RTParameter.h:83
Definition: ParamDef.h:72
Definition: RTParameter.h:261
ParamValue const & value() const
Definition: RTParameter.h:274
void update(ParamType const &iNewValue)
Definition: RTParameter.h:219
ParamID getParamID() const
Definition: RTParameter.h:46
Definition: RTParameter.h:35
virtual bool resetPreviousValue()
Definition: RTParameter.cpp:65
Definition: RTParameter.h:92
RTVstParameter(VstParam< T > iParamDef)
Definition: RTParameter.h:98
Definition: ParamDef.h:129
void update(ParamValue const &iNewValue, ProcessData &oData)
Definition: RTParameter.h:287
T const & getValue() const
Definition: RTParameter.h:209
ParamValue const & getPreviousNormalizedValue() const
Definition: RTParameter.h:63
RTRawVstParameter * fPtr
Definition: RTParameter.h:310
ParamType const & getPreviousValue() const
Definition: RTParameter.h:127