Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
RTParameter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2023 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#include <pluginterfaces/vst/ivstaudioprocessor.h>
20
21#ifndef __PONGASOFT_VST_RT_PARAMETER_H__
22#define __PONGASOFT_VST_RT_PARAMETER_H__
23
25#include <pongasoft/logging/logging.h>
27
28namespace pongasoft::VST::RT {
29
36{
37public:
38 // Constructor
39 explicit RTRawVstParameter(std::shared_ptr<RawVstParamDef> iParamDef) :
40 fParamDef{std::move(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
81protected:
82 std::shared_ptr<RawVstParamDef> fParamDef;
83 ParamValue fNormalizedValue;
85};
86
91template<typename T>
93{
94public:
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
129protected:
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
136protected:
139};
140
141//------------------------------------------------------------------------
142// RTParameter::updateNormalizedValue - update fValue to the new value and return true if it changed
143//------------------------------------------------------------------------
144template<typename T>
145bool 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//------------------------------------------------------------------------
159template<typename T>
161{
163 {
165 return true;
166 }
167
168 return false;
169}
170
171//------------------------------------------------------------------------
172// RTParameter::update
173//------------------------------------------------------------------------
174template<typename T>
176{
177 fValue = iNewValue;
179}
180
181//------------------------------------------------------------------------
182// RTVstParam - wrapper to make writing the code much simpler and natural
183//------------------------------------------------------------------------
190template<typename T>
192{
193 using ParamType = T;
194
195public:
196 RTVstParam(RTVstParameter<T> *iPtr) : fPtr{iPtr} // NOLINT (not marked explicit on purpose)
197 {
198 DCHECK_F(fPtr != nullptr);
199 }
200
201 // getParamID
202 inline ParamID getParamID() const { return fPtr->getParamID(); }
203
204 // shortcut to normalize
205 inline ParamValue normalize(ParamType const &iValue) const { return fPtr->normalize(iValue); }
206
207 // shortcut to denormalize
208 inline ParamType denormalize(ParamValue iNormalizedValue) const { return fPtr->denormalize(iNormalizedValue); }
209
210 // getValue
211 inline T const &getValue() const { return fPtr->getValue(); }
212
213 // value -- synonym
214 inline T const &value() const { return fPtr->getValue(); }
215
217 inline ParamValue const &normalizedValue() const { return fPtr->getNormalizedValue(); }
218
224 inline void update(ParamType const &iNewValue) { fPtr->update(iNewValue); }
225
230 inline void update(ParamType const &iNewValue, ProcessData &oData)
231 {
232 update(iNewValue);
233 addToOutput(oData);
234 }
235
239 inline bool hasChanged() const { return fPtr->hasChanged(); }
240
244 inline tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
245
246 // allow to use the param as the underlying ParamType (ex: "if(param)" in the case ParamType is bool))
247 [[deprecated("Since 4.1.0 - use operator* or value() instead (ex: *fState.fBypass or fState.fBypass.value())")]]
248 inline operator ParamType const &() const { return fPtr->getValue(); }
249
251 constexpr ParamType const &operator *() const { return fPtr->getValue(); }
252
253 // allow writing param->xxx to access the underlying type directly (if not a primitive)
254 constexpr ParamType const *operator->() const { return &fPtr->getValue(); }
255
257 inline RTVstParam<T> &operator=(ParamType const &iValue) { update(iValue); return *this; }
258
259 // previous
260 inline ParamType const &previous() const { return fPtr->getPreviousValue(); }
261
262private:
264};
265
266template<typename T, size_t N>
267using RTVstParams = std::array<RTVstParam<T>, N>;
268
269//------------------------------------------------------------------------
270// RTRawVstParam - wrapper to make writing the code much simpler and natural
271//------------------------------------------------------------------------
277{
278public:
279 RTRawVstParam(RTRawVstParameter *iPtr) : fPtr{iPtr} // NOLINT (not marked explicit on purpose)
280 {
281 DCHECK_F(fPtr != nullptr);
282 }
283
284 // getParamID
285 inline ParamID getParamID() const { return fPtr->getParamID(); }
286
287 // getValue
288 inline ParamValue const &getValue() const { return fPtr->getNormalizedValue(); }
289
290 // value - synonym
291 inline ParamValue const &value() const { return fPtr->getNormalizedValue(); }
292
298 inline bool update(ParamValue const &iNewValue) { return fPtr->updateNormalizedValue(iNewValue); }
299
304 inline bool update(ParamValue const &iNewValue, ProcessData &oData)
305 {
306 if(update(iNewValue))
307 {
308 addToOutput(oData);
309 return true;
310 }
311 else
312 return false;
313 }
314
318 inline bool hasChanged() const { return fPtr->hasChanged(); }
319
323 inline tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
324
325 // allow to use the param as the ParamValue
326 [[deprecated("Since 4.1.0 - use operator* instead")]]
327 inline operator ParamValue const &() const { return fPtr->getNormalizedValue(); }
328
330 inline ParamValue operator *() const { return fPtr->getNormalizedValue(); }
331
333 inline RTRawVstParam &operator=(ParamValue const &iValue) { update(iValue); return *this; }
334
335 // previous
336 inline ParamValue const &previous() const { return fPtr->getPreviousNormalizedValue(); }
337
338private:
340};
341
342template<size_t N>
343using RTRawVstParams = std::array<RTRawVstParam, N>;
344
345}
346
347#endif // __PONGASOFT_VST_RT_PARAMETER_H__
Implements all the various equality and relational operators for the type T which is assumed to encap...
Definition Operators.h:56
bool hasChanged() const
Definition RTParameter.h:318
RTRawVstParam(RTRawVstParameter *iPtr)
Definition RTParameter.h:279
bool update(ParamValue const &iNewValue)
This method is typically called during the processing method when the plugin needs to update the valu...
Definition RTParameter.h:298
RTRawVstParameter * fPtr
Definition RTParameter.h:339
tresult addToOutput(ProcessData &oData)
Add the current normalized value as an output parameter changes which propagates the change to the vs...
Definition RTParameter.h:323
ParamValue const & getValue() const
Definition RTParameter.h:288
ParamID getParamID() const
Definition RTParameter.h:285
ParamValue operator*() const
allow writing *param to access the underlying value (or in other words, *param is the same param....
Definition RTParameter.h:330
ParamValue const & value() const
Definition RTParameter.h:291
ParamValue const & previous() const
Definition RTParameter.h:336
bool update(ParamValue const &iNewValue, ProcessData &oData)
This method is typically called during the processing method when the plugin needs to update the valu...
Definition RTParameter.h:304
RTRawVstParam & operator=(ParamValue const &iValue)
Allow to write param = 0.5.
Definition RTParameter.h:333
Base class which deals with the "raw"/untyped parameter and keep the normalized value (ParamValue in ...
Definition RTParameter.h:36
RTRawVstParameter(std::shared_ptr< RawVstParamDef > iParamDef)
Definition RTParameter.h:39
bool hasChanged() const
Definition RTParameter.h:73
RawVstParamDef const * getParamDef() const
Definition RTParameter.h:49
ParamValue const & getPreviousNormalizedValue() const
Definition RTParameter.h:63
tresult addToOutput(ProcessData &oData)
Add the current normalized value as an output parameter changes.
Definition RTParameter.cpp:30
ParamValue const & getNormalizedValue() const
Definition RTParameter.h:60
std::shared_ptr< RawVstParamDef > fParamDef
Definition RTParameter.h:82
virtual bool resetPreviousValue()
Called at the end of the frame so that previous value is set to current value for the next frame.
Definition RTParameter.cpp:66
ParamID getParamID() const
Definition RTParameter.h:46
ParamValue fNormalizedValue
Definition RTParameter.h:83
ParamValue fPreviousNormalizedValue
Definition RTParameter.h:84
virtual bool updateNormalizedValue(ParamValue iNormalizedValue)
Update the parameter with a new normalized value.
Definition RTParameter.cpp:50
ParamValue const & normalizedValue() const
Return the normalized value.
Definition RTParameter.h:217
ParamType denormalize(ParamValue iNormalizedValue) const
Definition RTParameter.h:208
bool hasChanged() const
Definition RTParameter.h:239
ParamValue normalize(ParamType const &iValue) const
Definition RTParameter.h:205
RTVstParam< T > & operator=(ParamType const &iValue)
Allow to write param = 3.0.
Definition RTParameter.h:257
tresult addToOutput(ProcessData &oData)
Add the current normalized value as an output parameter changes which propagates the change to the vs...
Definition RTParameter.h:244
constexpr ParamType const * operator->() const
Definition RTParameter.h:254
ParamType const & previous() const
Definition RTParameter.h:260
void update(ParamType const &iNewValue, ProcessData &oData)
This method is typically called during the processing method when the plugin needs to update the valu...
Definition RTParameter.h:230
constexpr ParamType const & operator*() const
allow writing *param to access the underlying value (or in other words, *param is the same param....
Definition RTParameter.h:251
void update(ParamType const &iNewValue)
This method is typically called during the processing method when the plugin needs to update the valu...
Definition RTParameter.h:224
ParamID getParamID() const
Definition RTParameter.h:202
T const & value() const
Definition RTParameter.h:214
T ParamType
Definition RTParameter.h:193
RTVstParam(RTVstParameter< T > *iPtr)
Definition RTParameter.h:196
T const & getValue() const
Definition RTParameter.h:211
RTVstParameter< T > * fPtr
Definition RTParameter.h:263
The typed version.
Definition RTParameter.h:93
RTVstParameter(VstParam< T > iParamDef)
Definition RTParameter.h:98
ParamType denormalize(ParamValue iNormalizedValue) const
Definition RTParameter.h:115
ParamValue normalize(ParamType const &iValue) const
Definition RTParameter.h:112
bool resetPreviousValue() override
Called at the end of the frame so that previous value is set to current value for the next frame.
Definition RTParameter.h:160
ParamType const & getPreviousValue() const
Definition RTParameter.h:127
ParamType fValue
Definition RTParameter.h:137
bool updateNormalizedValue(ParamValue iNormalizedValue) override
Update the parameter with a new normalized value.
Definition RTParameter.h:145
void update(ParamType const &iNewValue)
This method is typically called during the processing method when the plugin needs to update the valu...
Definition RTParameter.h:175
ParamType fPreviousValue
Definition RTParameter.h:138
T ParamType
Definition RTParameter.h:95
ParamType const & getValue() const
Definition RTParameter.h:124
VstParamDef< T > const * getParamDefT() const
Definition RTParameter.h:106
Base class for a raw vst parameter definition.
Definition ParamDef.h:92
Typed parameter definition.
Definition ParamDef.h:178
Definition RTJmbInParameter.h:26
std::array< RTRawVstParam, N > RTRawVstParams
Definition RTParameter.h:343
std::array< RTVstParam< T >, N > RTVstParams
Definition RTParameter.h:267
std::shared_ptr< VstParamDef< T > > VstParam
Definition ParamDef.h:509