Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
GUIRawVstParameter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2020 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#pragma once
20
21#include "IGUIParameter.h"
24#include "VstParameters.h"
25#include "GUIParamCx.h"
26
27#include <string>
28
30
31template<typename T>
32class GUIVstParameter;
33
40class GUIRawVstParameter : public ITGUIParameter<ParamValue>
41{
42public:
43 using ParamType = ParamValue;
45
46public:
60 class Editor : public EditorType
61 {
62 public:
63 Editor(ParamID iParamID, VstParametersSPtr iVstParameters);
64
65 ~Editor() override { rollback(); }
66
67 // disabling copy
68 Editor(Editor const &) = delete;
69 Editor& operator=(Editor const &) = delete;
70
74 tresult setValue(ParamValue const &iValue) override;
75
80 bool updateValue(ParamValue const &iValue) override;
81
82 /*
83 * Call when you are done with the modifications.
84 * This has no effect if rollback() has already been called
85 */
86 tresult commit() override;
87
88 // importing superclass commit methods
90
95 tresult rollback() override;
96
97 private:
98 ParamID fParamID;
100
103 };
104
105public:
106 // Constructor
107 GUIRawVstParameter(ParamID iParamID,
108 VstParametersSPtr iVstParameters,
109 std::shared_ptr<RawVstParamDef> iParamDef);
110
111 // Destructor
113// {
114// DLOG_F(INFO, "RawParameter::~RawParameter(%d)", fParamID);
115// }
116
117 // getParamID
118 inline ParamID getParamID() const override
119 {
120 return fParamID;
121 }
122
123 // accessValue
124 tresult accessValue(ValueAccessor const &iGetter) const override
125 {
126 iGetter(getValue());
127 return kResultOk;
128 }
129
133 inline ParamValue getValue() const
134 {
135 return fVstParameters->getParamNormalized(fParamID);
136 }
137
141 inline int32 getStepCount() const override
142 {
143 auto parameterInfo = fVstParameters->getParameterInfo(fParamID);
144 if(parameterInfo)
145 return parameterInfo->stepCount;
146 else
147 return 0;
148 }
149
153 void toString(String128 oString)
154 {
155 fParamDef->toString(getValue(), oString);
156 }
157
161 Steinberg::String toString()
162 {
163 String128 s;
164 toString(s);
165 return Steinberg::String(s);
166 }
167
168 // toUTF8String
169 std::string toUTF8String(int32 iPrecision) const override
170 {
171 return fParamDef->toUTF8String(getValue(), iPrecision);
172 }
173
179 bool update(ParamValue const &iValue) override
180 {
181 auto const previousValue = getValue();
182 if(previousValue != iValue)
183 {
184 setValue(iValue);
185 return true;
186 }
187 return false;
188 }
189
194 inline tresult setValue(ParamValue const &iValue) override
195 {
197 editor.setValue(iValue);
198 return editor.commit();
199 }
200
203 tresult resetToDefault() override
204 {
205 return setValue(fParamDef->fDefaultValue);
206 }
207
211 std::unique_ptr<EditorType> edit() override
212 {
213 return std::make_unique<Editor>(fParamID, fVstParameters);
214 }
215
219 using ITGUIParameter<ParamValue>::edit;
220
224 std::unique_ptr<FObjectCx> connect(Parameters::IChangeListener *iChangeListener) const override
225 {
226 return fVstParameters->connect(fParamID, iChangeListener);
227 }
228
232 std::unique_ptr<FObjectCx> connect(Parameters::ChangeCallback iChangeCallback) const override
233 {
234 return fVstParameters->connect(fParamID, std::move(iChangeCallback));
235 }
236
241 template<typename T>
242 std::shared_ptr<GUIVstParameter<T>> asVstParameter();
243
251 std::shared_ptr<GUIDiscreteParameter> asDiscreteParameter(int32 iStepCount) override;
252
253private:
254 ParamID fParamID;
256 std::shared_ptr<RawVstParamDef> fParamDef;
257};
258
259//-------------------------------------------------------------------------------
260// GUIRawVstParam - wrapper to make writing the code much simpler and natural
261//-------------------------------------------------------------------------------
267{
268public:
269 using ParamType = ParamValue;
271 using Editor = std::unique_ptr<EditorType>;
272
273public:
274 // Constructor
275 GUIRawVstParam(std::shared_ptr<GUIRawVstParameter> iPtr = nullptr) : // NOLINT (not marked explicit on purpose)
276 fPtr{std::move(iPtr)}
277 {}
278
280 GUIRawVstParam &operator=(GUIRawVstParam const &iOther) = default;
281
282 // exists
283 inline bool exists() const { return (bool) fPtr; }
284
285 // getParamID
286 inline ParamID getParamID() const { DCHECK_F(exists()); return fPtr->getParamID(); }
287
291 inline ParamValue getValue() const { DCHECK_F(exists()); return fPtr->getValue(); }
292
294 inline ParamValue value() const { DCHECK_F(exists()); return fPtr->getValue(); }
295
301 bool update(ParamValue const &iValue) { DCHECK_F(exists()); return fPtr->update(iValue); }
302
307 tresult setValue(ParamValue const &iValue) { DCHECK_F(exists()); return fPtr->setValue(iValue); }
308
311 inline tresult resetToDefault() { DCHECK_F(exists()); return fPtr->resetToDefault(); }
312
316 tresult copyValueFrom(GUIRawVstParam const &iParam) { DCHECK_F(exists()); return setValue(iParam.getValue()); }
317
321 inline int32 getStepCount() const { DCHECK_F(exists()); return fPtr->getStepCount(); }
322
326 void toString(String128 oString) { fPtr->toString(oString); }
327
331 Steinberg::String toString() { DCHECK_F(exists()); return fPtr->toString(); }
332
336 Editor edit() { DCHECK_F(exists()); return fPtr->edit(); }
337
343 Editor edit(ParamValue const &iValue) { DCHECK_F(exists()); return fPtr->edit(iValue); }
344
346 inline ParamValue operator *() const { DCHECK_F(exists()); return fPtr->getValue(); }
347
349 [[deprecated("Since 4.1.0 - use operator* or .value() instead (ex: if(*param) {...} or if(param.value()) {...}")]]
350 inline operator ParamValue() const { DCHECK_F(exists()); return fPtr->getValue(); } // NOLINT
351
353 inline GUIRawVstParam &operator=(ParamValue const &iValue) { DCHECK_F(exists()); fPtr->setValue(iValue); return *this; }
354
357 inline std::string toUTF8String(int32 iPrecision) const { DCHECK_F(exists()); return fPtr->toUTF8String(iPrecision); }
358
362 inline std::unique_ptr<FObjectCx> connect(Parameters::IChangeListener *iChangeListener) const { DCHECK_F(exists()); return fPtr->connect(iChangeListener); }
363
367 inline std::unique_ptr<FObjectCx> connect(Parameters::ChangeCallback iChangeCallback) const { DCHECK_F(exists()); return fPtr->connect(std::move(iChangeCallback)); }
368
369private:
370 std::shared_ptr<GUIRawVstParameter> fPtr;
371};
372
373//------------------------------------------------------------------------
374// shortcut notations
375//------------------------------------------------------------------------
376using GUIRawVstParamEditor = std::unique_ptr<GUIRawVstParameter::EditorType>;
377
378}
Implements all the various equality and relational operators for the type T which is assumed to encap...
Definition Operators.h:56
Editor edit(ParamValue const &iValue)
Shortcut to create an editor and set the value to it.
Definition GUIRawVstParameter.h:343
GUIRawVstParam(std::shared_ptr< GUIRawVstParameter > iPtr=nullptr)
Definition GUIRawVstParameter.h:275
int32 getStepCount() const
Definition GUIRawVstParameter.h:321
ParamValue ParamType
Definition GUIRawVstParameter.h:269
GUIRawVstParam & operator=(GUIRawVstParam const &iOther)=default
Assignment operator: fMyParam = registerParam(...);.
std::string toUTF8String(int32 iPrecision) const
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition GUIRawVstParameter.h:357
ParamValue value() const
Synonym to getValue().
Definition GUIRawVstParameter.h:294
bool update(ParamValue const &iValue)
Update the parameter with a value.
Definition GUIRawVstParameter.h:301
void toString(String128 oString)
Populates the oString with a string representation of this parameter.
Definition GUIRawVstParameter.h:326
ParamID getParamID() const
Definition GUIRawVstParameter.h:286
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const
Definition GUIRawVstParameter.h:367
ParamValue operator*() const
allow writing *param to access the underlying value (or in other words, *param is the same param....
Definition GUIRawVstParameter.h:346
bool exists() const
Definition GUIRawVstParameter.h:283
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const
Definition GUIRawVstParameter.h:362
tresult copyValueFrom(GUIRawVstParam const &iParam)
Shortcut to copy the value from another param to this one.
Definition GUIRawVstParameter.h:316
GUIRawVstParam & operator=(ParamValue const &iValue)
Allow to write param = 0.5.
Definition GUIRawVstParameter.h:353
tresult setValue(ParamValue const &iValue)
Sets the value of this parameter.
Definition GUIRawVstParameter.h:307
tresult resetToDefault()
Resets the param to its default value.
Definition GUIRawVstParameter.h:311
std::unique_ptr< EditorType > Editor
Definition GUIRawVstParameter.h:271
GUIRawVstParameter::EditorType EditorType
Definition GUIRawVstParameter.h:270
Editor edit()
Definition GUIRawVstParameter.h:336
std::shared_ptr< GUIRawVstParameter > fPtr
Definition GUIRawVstParameter.h:370
Steinberg::String toString()
Returns a string representation of this parameter.
Definition GUIRawVstParameter.h:331
ParamValue getValue() const
Definition GUIRawVstParameter.h:291
Wrapper to edit a single parameter.
Definition GUIRawVstParameter.h:61
tresult commit() override
Commits all the changes applied to the parameter.
Definition GUIRawVstParameter.cpp:69
ParamID fParamID
Definition GUIRawVstParameter.h:98
tresult rollback() override
Call this if you want to revert to the original value of the parameter (when the editor is created).
Definition GUIRawVstParameter.cpp:83
bool fIsEditing
Definition GUIRawVstParameter.h:102
Editor(ParamID iParamID, VstParametersSPtr iVstParameters)
Definition GUIRawVstParameter.cpp:27
ParamValue fInitialParamValue
Definition GUIRawVstParameter.h:101
~Editor() override
Technically the destructor must only call rollback(), but due to the fact that it is a virtual method...
Definition GUIRawVstParameter.h:65
VstParametersSPtr fVstParameters
Definition GUIRawVstParameter.h:99
tresult setValue(ParamValue const &iValue) override
Change the value of the parameter.
Definition GUIRawVstParameter.cpp:40
bool updateValue(ParamValue const &iValue) override
Change the value of the parameter.
Definition GUIRawVstParameter.cpp:55
ITGUIParameter< ParamValue >::ITEditor EditorType
Definition GUIRawVstParameter.h:44
std::string toUTF8String(int32 iPrecision) const override
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition GUIRawVstParameter.h:169
ParamID fParamID
Definition GUIRawVstParameter.h:254
int32 getStepCount() const override
Definition GUIRawVstParameter.h:141
bool update(ParamValue const &iValue) override
Update the parameter with a value.
Definition GUIRawVstParameter.h:179
ParamValue ParamType
Definition GUIRawVstParameter.h:43
ParamID getParamID() const override
Each parameter has a unique ID returned by this method.
Definition GUIRawVstParameter.h:118
std::shared_ptr< GUIDiscreteParameter > asDiscreteParameter(int32 iStepCount) override
This implementation will adapt this parameter to be interpreted as a discrete parameter.
Definition GUIRawVstParameter.cpp:145
tresult resetToDefault() override
Resets the parameter to its default value.
Definition GUIRawVstParameter.h:203
std::shared_ptr< RawVstParamDef > fParamDef
Definition GUIRawVstParameter.h:256
void toString(String128 oString)
Populates the oString with a string representation of this parameter.
Definition GUIRawVstParameter.h:153
VstParametersSPtr fVstParameters
Definition GUIRawVstParameter.h:255
GUIRawVstParameter(ParamID iParamID, VstParametersSPtr iVstParameters, std::shared_ptr< RawVstParamDef > iParamDef)
Definition GUIRawVstParameter.cpp:98
std::unique_ptr< EditorType > edit() override
Definition GUIRawVstParameter.h:211
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const override
Definition GUIRawVstParameter.h:232
tresult accessValue(ValueAccessor const &iGetter) const override
API to access the underlying value.
Definition GUIRawVstParameter.h:124
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const override
Definition GUIRawVstParameter.h:224
std::shared_ptr< GUIVstParameter< T > > asVstParameter()
Converts to a typed parameter.
Definition GUIVstParameter.h:429
tresult setValue(ParamValue const &iValue) override
Sets the value of this parameter.
Definition GUIRawVstParameter.h:194
Steinberg::String toString()
Returns a string representation of this parameter.
Definition GUIRawVstParameter.h:161
ParamValue getValue() const
Definition GUIRawVstParameter.h:133
This class wraps a GUIRawVstParameter to deal with any type T.
Definition GUIVstParameter.h:34
Defines the API for the editor which can be obtained by calling ITGUIParameter::edit().
Definition IGUIParameter.h:238
virtual tresult commit(ParamType const &iValue)
Shortcut method which calls setValue(ParamType const &) followed by commit().
Definition IGUIParameter.h:264
Represents a gui parameter with its underlying backing type T (aka ParamType).
Definition IGUIParameter.h:172
std::function< void(ParamValue const &)> ValueAccessor
Definition IGUIParameter.h:183
Interface to implement to receive parameter changes.
Definition Parameters.h:45
std::function< void()> ChangeCallback
A callback that will be invoked for changes.
Definition Parameters.h:56
Definition GUIState.h:38
std::shared_ptr< VstParameters > VstParametersSPtr
Definition VstParameters.h:96
std::unique_ptr< GUIRawVstParameter::EditorType > GUIRawVstParamEditor
Definition GUIRawVstParameter.h:376