Jamba C++ API 8.0.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
20#ifndef __PONGASOFT_VST_RT_PARAMETER_H__
21#define __PONGASOFT_VST_RT_PARAMETER_H__
22
23#include <pluginterfaces/vst/ivstaudioprocessor.h>
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
46 virtual ~RTRawVstParameter() = default;
47
48 // getParamID
49 ParamID getParamID() const { return fParamDef->fParamID; }
50
51 // getParamDef
52 RawVstParamDef const *getParamDef() const { return fParamDef.get(); }
53
60 virtual bool updateNormalizedValue(ParamValue iNormalizedValue);
61
62 // getNormalizedValue
63 ParamValue const &getNormalizedValue() const { return fNormalizedValue; }
64
65 // getPreviousNormalizedValue
66 ParamValue const &getPreviousNormalizedValue() const { return fPreviousNormalizedValue; }
67
71 tresult addToOutput(ProcessData &oData) const;
72
77
82 virtual bool resetPreviousValue();
83
84protected:
85 std::shared_ptr<RawVstParamDef> fParamDef;
86 ParamValue fNormalizedValue;
88};
89
94template<typename T>
96{
97public:
98 using ParamType = T;
99
100 // Constructor
101 explicit RTVstParameter(VstParam<T> iParamDef) :
102 RTRawVstParameter(iParamDef),
105 {
106 }
107
108 // getParamDef
110 {
111 return static_cast<VstParamDef<T> const *>(getParamDef());
112 }
113
114 // shortcut to normalize
115 ParamValue normalize(ParamType const &iValue) const { return getParamDefT()->normalize(iValue); }
116
117 // shortcut to denormalize
118 ParamType denormalize(ParamValue iNormalizedValue) const { return getParamDefT()->denormalize(iNormalizedValue); }
119
124 void update(ParamType const &iNewValue);
125
126 // getValue
127 ParamType const &getValue() const { return fValue; }
128
129 // getPreviousValue
130 ParamType const &getPreviousValue() const { return fPreviousValue; }
131
132protected:
133 // Override the base class to update the denormalized value as well
134 bool updateNormalizedValue(ParamValue iNormalizedValue) override;
135
136 // Override the base class to update the denormalized value as well
137 bool resetPreviousValue() override;
138
139protected:
142};
143
144//------------------------------------------------------------------------
145// RTParameter::updateNormalizedValue - update fValue to the new value and return true if it changed
146//------------------------------------------------------------------------
147template<typename T>
148bool RTVstParameter<T>::updateNormalizedValue(ParamValue iNormalizedValue)
149{
150 if(RTRawVstParameter::updateNormalizedValue(iNormalizedValue))
151 {
152 fValue = denormalize(iNormalizedValue);
153 return true;
154 }
155
156 return false;
157}
158
159//------------------------------------------------------------------------
160// RTParameter::resetPreviousValue
161//------------------------------------------------------------------------
162template<typename T>
164{
166 {
168 return true;
169 }
170
171 return false;
172}
173
174//------------------------------------------------------------------------
175// RTParameter::update
176//------------------------------------------------------------------------
177template<typename T>
179{
180 fValue = iNewValue;
182}
183
184//------------------------------------------------------------------------
185// RTVstParam - wrapper to make writing the code much simpler and natural
186//------------------------------------------------------------------------
193template<typename T>
195{
196 using ParamType = T;
197
198public:
199 RTVstParam(RTVstParameter<T> *iPtr) : fPtr{iPtr} // NOLINT (not marked explicit on purpose)
200 {
201 DCHECK_F(fPtr != nullptr);
202 }
203
204 // getParamID
205 ParamID getParamID() const { return fPtr->getParamID(); }
206
207 // shortcut to normalize
208 ParamValue normalize(ParamType const &iValue) const { return fPtr->normalize(iValue); }
209
210 // shortcut to denormalize
211 ParamType denormalize(ParamValue iNormalizedValue) const { return fPtr->denormalize(iNormalizedValue); }
212
213 // getValue
214 T const &getValue() const { return fPtr->getValue(); }
215
216 // value -- synonym
217 T const &value() const { return fPtr->getValue(); }
218
220 ParamValue const &normalizedValue() const { return fPtr->getNormalizedValue(); }
221
227 void update(ParamType const &iNewValue) { fPtr->update(iNewValue); }
228
233 void update(ParamType const &iNewValue, ProcessData &oData)
234 {
235 update(iNewValue);
236 addToOutput(oData);
237 }
238
242 bool hasChanged() const { return fPtr->hasChanged(); }
243
247 tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
248
250 constexpr ParamType const &operator *() const { return fPtr->getValue(); }
251
252 // allow writing param->xxx to access the underlying type directly (if not a primitive)
253 constexpr ParamType const *operator->() const { return &fPtr->getValue(); }
254
256 RTVstParam &operator=(ParamType const &iValue) { update(iValue); return *this; }
257
258 // previous
259 ParamType const &previous() const { return fPtr->getPreviousValue(); }
260
261private:
263};
264
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 ParamID getParamID() const { return fPtr->getParamID(); }
286
287 // getValue
288 ParamValue const &getValue() const { return fPtr->getNormalizedValue(); }
289
290 // value - synonym
291 ParamValue const &value() const { return fPtr->getNormalizedValue(); }
292
298 bool update(ParamValue const &iNewValue) { return fPtr->updateNormalizedValue(iNewValue); }
299
304 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 bool hasChanged() const { return fPtr->hasChanged(); }
319
323 tresult addToOutput(ProcessData &oData) { return fPtr->addToOutput(oData); }
324
326 ParamValue operator *() const { return fPtr->getNormalizedValue(); }
327
329 RTRawVstParam &operator=(ParamValue const &iValue) { update(iValue); return *this; }
330
331 // previous
332 ParamValue const &previous() const { return fPtr->getPreviousNormalizedValue(); }
333
334private:
336};
337
339template<size_t N>
340using RTRawVstParams = std::array<RTRawVstParam, N>;
341
342}
343
344#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:335
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:326
ParamValue const & value() const
Definition RTParameter.h:291
ParamValue const & previous() const
Definition RTParameter.h:332
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:329
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:76
tresult addToOutput(ProcessData &oData) const
Add the current normalized value as an output parameter changes.
Definition RTParameter.cpp:29
RawVstParamDef const * getParamDef() const
Definition RTParameter.h:52
ParamValue const & getPreviousNormalizedValue() const
Definition RTParameter.h:66
ParamValue const & getNormalizedValue() const
Definition RTParameter.h:63
std::shared_ptr< RawVstParamDef > fParamDef
Definition RTParameter.h:85
virtual bool resetPreviousValue()
Called at the end of the frame so that the previous value is set to the current value for the next fr...
Definition RTParameter.cpp:65
ParamID getParamID() const
Definition RTParameter.h:49
ParamValue fNormalizedValue
Definition RTParameter.h:86
ParamValue fPreviousNormalizedValue
Definition RTParameter.h:87
virtual bool updateNormalizedValue(ParamValue iNormalizedValue)
Update the parameter with a new normalized value.
Definition RTParameter.cpp:49
virtual ~RTRawVstParameter()=default
Destructor (needed for polymorphic base type).
ParamValue const & normalizedValue() const
Return the normalized value.
Definition RTParameter.h:220
ParamType denormalize(ParamValue iNormalizedValue) const
Definition RTParameter.h:211
bool hasChanged() const
Definition RTParameter.h:242
ParamValue normalize(ParamType const &iValue) const
Definition RTParameter.h:208
tresult addToOutput(ProcessData &oData)
Add the current normalized value as an output parameter changes which propagates the change to the vs...
Definition RTParameter.h:247
constexpr ParamType const * operator->() const
Definition RTParameter.h:253
RTVstParam & operator=(ParamType const &iValue)
Allow writing param = 3.0.
Definition RTParameter.h:256
ParamType const & previous() const
Definition RTParameter.h:259
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:233
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:250
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:227
ParamID getParamID() const
Definition RTParameter.h:205
T const & value() const
Definition RTParameter.h:217
T ParamType
Definition RTParameter.h:196
RTVstParam(RTVstParameter< T > *iPtr)
Definition RTParameter.h:199
T const & getValue() const
Definition RTParameter.h:214
RTVstParameter< T > * fPtr
Definition RTParameter.h:262
The typed version.
Definition RTParameter.h:96
RTVstParameter(VstParam< T > iParamDef)
Definition RTParameter.h:101
ParamType denormalize(ParamValue iNormalizedValue) const
Definition RTParameter.h:118
ParamValue normalize(ParamType const &iValue) const
Definition RTParameter.h:115
bool resetPreviousValue() override
Called at the end of the frame so that the previous value is set to the current value for the next fr...
Definition RTParameter.h:163
ParamType const & getPreviousValue() const
Definition RTParameter.h:130
ParamType fValue
Definition RTParameter.h:140
bool updateNormalizedValue(ParamValue iNormalizedValue) override
Update the parameter with a new normalized value.
Definition RTParameter.h:148
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:178
ParamType fPreviousValue
Definition RTParameter.h:141
T ParamType
Definition RTParameter.h:98
ParamType const & getValue() const
Definition RTParameter.h:127
VstParamDef< T > const * getParamDefT() const
Definition RTParameter.h:109
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
An array of RTRawVstParam.
Definition RTParameter.h:340
std::array< RTVstParam< T >, N > RTVstParams
An array of RTVstParam.
Definition RTParameter.h:267
std::shared_ptr< VstParamDef< T > > VstParam
Definition ParamDef.h:509