Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
GUIOptionalParam.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 <pluginterfaces/vst/vsttypes.h>
22#include <pongasoft/logging/logging.h>
24#include "IGUIParameter.h"
25#include "GUIVstParameter.h"
26#include "GUIJmbParameter.h"
27#include "GUIValParameter.h"
28
30
31using namespace Steinberg::Vst;
32
48template<typename T>
49class GUIOptionalParam: public Utils::Operators::Dereferenceable<GUIOptionalParam<T>>
50{
51 static_assert(std::is_default_constructible_v<T>, "T must have a default/empty constructor: T()");
52 static_assert(std::is_copy_constructible_v<T>, "T must have a copy constructor: T(T const &)");
53 static_assert(std::is_copy_assignable_v<T>, "T must be copy assignable: T& operator=(T const &)");
54
55public:
57 using ParamType = T;
59 using Editor = std::unique_ptr<EditorType>;
60
61public:
66 class Value {
67 public:
68 constexpr T const *operator ->() const { return &fValue; }
69 friend class GUIOptionalParam<T>;
70 private:
71 explicit Value(T const &iValue) : fValue{iValue} {}
73 };
74
75public:
76 // Constructor
79
80 // Constructor
81 explicit GUIOptionalParam(T const &iDefaultValue) :
82 fParameter{VstUtils::make_sfo<GUIValParameter<T>>(UNDEFINED_PARAM_ID, iDefaultValue)} {}
83
84 // Constructor
85 explicit GUIOptionalParam(std::shared_ptr<ITGUIParameter<T>> iParameter) : fParameter{std::move(iParameter) } {
86 DCHECK_F(fParameter != nullptr);
87 }
88
91 inline bool exists() const { return true; }
92
95 inline ParamID getParamID() const { return fParameter->getParamID(); }
96
100 inline ParamType getValue() const
101 {
102 ParamType res;
103 fParameter->accessValue([&res](auto const &iValue) { res = iValue; });
104 return res;
105 }
106
108 inline ParamType value() const { return getValue(); }
109
112 inline bool update(ParamType const &iValue)
113 {
114 return fParameter->update(iValue);
115 }
116
119 inline tresult setValue(ParamType const &iValue)
120 {
121 return fParameter->setValue(iValue);
122 }
123
126 inline tresult resetToDefault() { fParameter->resetToDefault(); }
127
130 inline std::unique_ptr<EditorType> edit()
131 {
132 return fParameter->edit();
133 }
134
137 inline std::unique_ptr<EditorType> edit(ParamType const &iValue)
138 {
139 return fParameter->edit(iValue);
140 }
141
144 inline int32 getStepCount() const { return fParameter->getStepCount(); }
145
147 constexpr ParamType operator *() const { return getValue(); }
148
150 constexpr Value operator ->() const { return Value{getValue()}; }
151
157 [[deprecated("Since 4.1.0 - use operator* or value() instead (ex: if(*param) {...} or if(param.value() {...})")]]
158 inline operator ParamType() const { return getValue(); } // NOLINT
159
162 inline GUIOptionalParam &operator=(T const &iValue) { update(iValue); return *this; }
163
166 inline std::string toUTF8String(int32 iPrecision) const { return fParameter->toUTF8String(iPrecision); }
167
170 inline std::unique_ptr<FObjectCx> connect(Parameters::IChangeListener *iChangeListener) const
171 {
172 return fParameter->connect(iChangeListener);
173 }
174
177 inline std::unique_ptr<FObjectCx> connect(Parameters::ChangeCallback iChangeCallback) const
178 {
179 return fParameter->connect(iChangeCallback);
180 }
181
182private:
183 std::shared_ptr<ITGUIParameter<ParamType>> fParameter;
184};
185
186
187template<typename T>
188using GUIOptionalParamEditor = std::unique_ptr<typename GUIOptionalParam<T>::EditorType>;
189
192
193}
Implements all the various equality and relational operators for the type T which is assumed to encap...
Definition Operators.h:56
constexpr T const * operator->() const
Definition GUIOptionalParam.h:68
Value(T const &iValue)
Definition GUIOptionalParam.h:71
T fValue
Definition GUIOptionalParam.h:72
Represents an optional parameter (Jmb, Vst or no param at all).
Definition GUIOptionalParam.h:50
std::unique_ptr< EditorType > edit()
Creates an editor to modify the parameter in a transactional fashion.
Definition GUIOptionalParam.h:130
int32 getStepCount() const
When a parameter is a discrete parameter (which means its underlying backing type is an int32 with va...
Definition GUIOptionalParam.h:144
std::unique_ptr< EditorType > edit(ParamType const &iValue)
Shortcut api which creates an editor followed by ITEditor::setValue(ParamType const &) to set the par...
Definition GUIOptionalParam.h:137
constexpr ParamType operator*() const
allow writing *param to access the underlying value (or in other words, *param is the same param....
Definition GUIOptionalParam.h:147
GUIOptionalParam(T const &iDefaultValue)
Definition GUIOptionalParam.h:81
std::string toUTF8String(int32 iPrecision) const
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition GUIOptionalParam.h:166
GUIOptionalParam< T > class_type
Definition GUIOptionalParam.h:56
ParamID getParamID() const
Each parameter has a unique ID returned by this method.
Definition GUIOptionalParam.h:95
ParamType value() const
Synonym to getValue().
Definition GUIOptionalParam.h:108
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const
Creates a connection between this parameter and the callback: whenever the parameter changes,...
Definition GUIOptionalParam.h:177
GUIOptionalParam()
Definition GUIOptionalParam.h:77
bool exists() const
Always return true because by definition an optional parameter always exist.
Definition GUIOptionalParam.h:91
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const
Creates a connection between this parameter and the change listener: whenever the parameter changes,...
Definition GUIOptionalParam.h:170
bool update(ParamType const &iValue)
First check if the value provided (iValue) is different from the current value and if that is the cas...
Definition GUIOptionalParam.h:112
GUIOptionalParam(std::shared_ptr< ITGUIParameter< T > > iParameter)
Definition GUIOptionalParam.h:85
ParamType getValue() const
Definition GUIOptionalParam.h:100
tresult setValue(ParamType const &iValue)
Unconditionally sets the value of the parameter to the value provided.
Definition GUIOptionalParam.h:119
std::shared_ptr< ITGUIParameter< ParamType > > fParameter
Definition GUIOptionalParam.h:183
T ParamType
Definition GUIOptionalParam.h:57
constexpr Value operator->() const
allow writing param->x to access the underlying value when T is a struct or class
Definition GUIOptionalParam.h:150
typename ITGUIParameter< T >::ITEditor EditorType
Definition GUIOptionalParam.h:58
tresult resetToDefault()
Resets the param to its default value.
Definition GUIOptionalParam.h:126
std::unique_ptr< EditorType > Editor
Definition GUIOptionalParam.h:59
GUIOptionalParam & operator=(T const &iValue)
Allow to write param = 3 instead of param.update(3) for example.
Definition GUIOptionalParam.h:162
This parameter is not tied to any parameter definition/registration and is primarily used by the opti...
Definition GUIValParameter.h:38
Defines the API for the editor which can be obtained by calling ITGUIParameter::edit().
Definition IGUIParameter.h:238
Represents a gui parameter with its underlying backing type T (aka ParamType).
Definition IGUIParameter.h:172
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::unique_ptr< typename GUIOptionalParam< T >::EditorType > GUIOptionalParamEditor
Definition GUIOptionalParam.h:188
GUIOptionalParam< ParamValue > GUIRawOptionalParam
Definition GUIOptionalParam.h:190
GUIOptionalParamEditor< ParamValue > GUIRawOptionalParamEditor
Definition GUIOptionalParam.h:191
Definition ExpiringDataCache.h:28
constexpr ParamID UNDEFINED_PARAM_ID
Constant used throughout the code to test whether the ParamID represents a valid id or an undefined o...
Definition Types.h:48