20 #include <base/source/fobject.h> 56 virtual tresult
writeToStream(IBStreamer &oStreamer)
const = 0;
92 using FObject::update;
98 fValue{iParamDef->fDefaultValue}
130 if constexpr(Utils::is_operator_not_eq_defined<ParamType>)
151 template<
class ValueModifier>
154 if(iValueModifier(&
fValue))
171 if constexpr(std::is_copy_assignable_v<ParamType>)
179 DLOG_F(ERROR,
"%s is not copy_assignable. Call updateIf instead.",
typeid(
ParamType).name());
190 fValue = std::move(iValue);
258 std::unique_ptr<EditorType>
edit()
override 260 return std::make_unique<DefaultEditorImpl<T>>(
this,
getValue());
273 return std::make_unique<GUIParamCx>(
getJmbParamID(), const_cast<GUIJmbParameter *>(
this), iChangeListener);
281 return std::make_unique<FObjectCxCallback>(const_cast<GUIJmbParameter *>(
this), std::move(iChangeCallback));
296 static std::shared_ptr<GUIJmbParameter<T>>
castToJmb(std::shared_ptr<IGUIParameter> iParam)
359 if(res == kResultFalse)
360 DLOG_F(WARNING,
"Cannot convert current value of Jmb param [%d] to a discrete value",
getParamID());
369 if(
getValue(discreteValue) == kResultOk)
371 iGetter(discreteValue);
378 bool update(int32
const &iDiscreteValue)
override 380 int32 currentDiscreteValue;
381 tresult res =
getValue(currentDiscreteValue);
385 if(iDiscreteValue != currentDiscreteValue)
387 if(
setValue(iDiscreteValue) == kResultOk)
396 tresult
setValue(int32
const &iDiscreteValue)
override 398 int32 currentDiscreteValue;
399 tresult res =
getValue(currentDiscreteValue);
402 if(iDiscreteValue != currentDiscreteValue)
405 if constexpr(std::is_copy_assignable_v<T>)
408 if(
fConverter->convertFromDiscreteValue(iDiscreteValue, jmbValue) == kResultOk)
411 DLOG_F(WARNING,
"Cannot convert discrete value [%d] to a [%s] value of Jmb param [%d]",
429 std::unique_ptr<EditorType>
edit()
override 431 int32 currentDiscreteValue;
432 tresult res =
getValue(currentDiscreteValue);
434 return std::make_unique<DefaultEditorImpl<int32>>(
this, currentDiscreteValue);
457 auto converter = getParamDefT()->getDiscreteConverter();
459 if(converter && converter->getStepCount() > 0)
461 std::move(converter));
468 if constexpr(Utils::is_static_cast_defined<int32, T> && Utils::is_static_cast_defined<T, int32>)
470 converter = std::make_shared<StaticCastDiscreteConverter<T>>(iStepCount);
472 std::move(converter));
476 DLOG_F(WARNING,
"Jmb param [%d] (type [%s]) cannot be converted to a discrete parameter",
478 Utils::typeString<T>().c_str());
500 using Editor = std::unique_ptr<EditorType>;
504 fPtr{std::move(iPtr)}
520 inline bool update(T
const &iNewValue) { DCHECK_F(
exists());
return fPtr->update(iNewValue); }
526 template<
class ValueModifier>
527 inline bool updateIf(ValueModifier
const &iValueModifier) { DCHECK_F(
exists());
return fPtr->updateIf(iValueModifier); }
559 [[deprecated(
"Since 4.1.0 - use operator* or .value() instead (ex: if(*param) {...} or if(param.value()) {...}")]]
560 inline operator T
const &()
const { DCHECK_F(
exists());
return fPtr->getValue(); }
599 std::shared_ptr<GUIJmbParameter<T>>
fPtr;
ParamID getParamID() const override
Each parameter has a unique ID returned by this method.
Definition: GUIJmbParameter.h:110
std::unique_ptr< EditorType > edit() override
Creates an editor to modify the parameter in a transactional fashion.
Definition: GUIJmbParameter.h:429
bool updateIf(ValueModifier const &iValueModifier)
Use this flavor of update if you want to modify the value itself.
Definition: GUIJmbParameter.h:527
bool update(T const &iNewValue)
This method is typically called by a view to change the value of the parameter.
Definition: GUIJmbParameter.h:520
void broadcast(T const &iValue)
Definition: GUIJmbParameter.h:575
std::shared_ptr< IJmbParamDef > fParamDef
Definition: GUIJmbParameter.h:77
tresult accessValue(typename ITGUIParameter< T >::ValueAccessor const &iGetter) const override
Definition: GUIJmbParameter.h:245
typename ITGUIParameter< T >::ITEditor EditorType
Definition: GUIJmbParameter.h:90
Base class for a Jamba (Jmb) GUI parameter.
Definition: GUIJmbParameter.h:40
Abstraction for allocating and sending a message.
Definition: MessageProducer.h:33
Simple wrapper class with better api.
Definition: Messaging.h:42
std::function< void()> ChangeCallback
A callback that will be invoked for changes.
Definition: Parameters.h:55
UTF8String ParamType
Definition: GUIJmbParameter.h:498
Represents a gui parameter with its underlying backing type T (aka ParamType).
Definition: IGUIParameter.h:33
tresult getValue(int32 &oDiscreteValue) const
Because converting the current Jmb value to an int32 may fail this api returns kResultOk if it works ...
Definition: GUIJmbParameter.h:355
ParamID getParamID() const override
Each parameter has a unique ID returned by this method.
Definition: GUIJmbParameter.h:321
IMessageProducer * fMessageProducer
Definition: GUIJmbParameter.h:78
JmbParamDef< T > const * getParamDefT() const
Definition: GUIJmbParameter.h:115
tresult resetToDefault() override
Resets the param to its default value.
Definition: GUIJmbParameter.h:197
tresult readFromStream(IBStreamer &iStreamer) override
Definition: GUIJmbParameter.h:203
bool update(int32 const &iDiscreteValue) override
First check if the value provided (iValue) is different from the current value and if that is the cas...
Definition: GUIJmbParameter.h:378
Interface defining a message handler.
Definition: MessageHandler.h:30
void writeToStream(std::ostream &oStream) const override
Definition: GUIJmbParameter.h:218
tresult broadcast() const
Definition: GUIJmbParameter.cpp:29
IGUIJmbParameter(std::shared_ptr< IJmbParamDef > iParamDef)
Definition: GUIJmbParameter.h:44
GUIJmbParam< T > & operator=(GUIJmbParam< T > const &iOther)=default
Assignment operator: fMyParam = registerParam(...);
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const override
Definition: GUIJmbParameter.h:279
tresult accessValue(ValueAccessor const &iGetter) const override
API to access the underlying value.
Definition: GUIJmbParameter.h:366
GUIJmbParam< T > & operator=(T const &iValue)
Allow to write param = 3.0.
Definition: GUIJmbParameter.h:569
tresult setValue(ParamType &&iValue)
Sets the value.
Definition: GUIJmbParameter.h:188
Implements all the various equality and relational operators for the type T which is assumed to encap...
Definition: Operators.h:54
std::function< void(T const &)> ValueAccessor
API to access the value of the param.
Definition: IGUIParameter.h:182
void setValue(T const &iNewValue)
The difference with update is that it does not check for equality (case when T is not comparable)
Definition: GUIJmbParameter.h:532
tresult writeToMessage(Message &oMessage) const override
Definition: GUIJmbParameter.h:239
Editor edit()
Definition: GUIJmbParameter.h:541
T ParamType
Definition: GUIJmbParameter.h:89
void setMessageProducer(IMessageProducer *iMessageProducer)
Definition: GUIJmbParameter.h:74
constexpr T const & operator *() const
allow writing *param to access the underlying value (or in other words, *param is the same param....
Definition: GUIJmbParameter.h:563
tresult resetToDefault()
Resets the param to its default value.
Definition: GUIJmbParameter.h:550
typename GUIDiscreteParameter::ITEditor EditorType
Definition: GUIJmbParameter.h:308
std::string toUTF8String(int32 iPrecision) const override
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition: GUIJmbParameter.h:440
Definition: GUIState.h:36
tresult handleMessage(Message const &iMessage) override
Definition: GUIJmbParameter.h:68
tresult setValue(int32 const &iDiscreteValue) override
Unconditionally sets the value of the parameter to the value provided.
Definition: GUIJmbParameter.h:396
bool updateIf(ValueModifier const &iValueModifier)
Use this flavor of update if you want to modify the value itself.
Definition: GUIJmbParameter.h:152
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener)
Definition: GUIJmbParameter.h:593
constexpr T const * operator->() const
Definition: GUIJmbParameter.h:566
std::shared_ptr< GUIJmbParameter< T > > fPtr
Definition: GUIJmbParameter.h:599
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition: GUIJmbParameter.h:495
std::shared_ptr< GUIJmbParameter< T > > fJmbParameter
Definition: GUIJmbParameter.h:446
virtual tresult writeToMessage(Message &oMessage) const =0
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const override
Creates a connection between this parameter and the change listener: whenever the parameter changes,...
Definition: GUIJmbParameter.h:333
bool exists() const
Definition: GUIJmbParameter.h:511
std::shared_ptr< GUIDiscreteParameter > asDiscreteParameter(int32 iStepCount) override
Converts this parameter into a discrete parameter.
Definition: GUIJmbParameter.h:345
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const override
Definition: GUIJmbParameter.h:271
std::unique_ptr< EditorType > Editor
Definition: GUIJmbParameter.h:500
tresult resetToDefault() override
Resets the parameter to its default value.
Definition: GUIJmbParameter.h:423
This is the templated version providing serializer methods, very similar to the GUIVstParameter conce...
Definition: GUIJmbParameter.h:86
T const & getValue() const
Definition: GUIJmbParameter.h:553
int32 getStepCount() const override
When a parameter is a discrete parameter (which means its underlying backing type is an int32 with va...
Definition: GUIJmbParameter.h:327
~GUIJmbParameter() override
Definition: GUIJmbParameter.h:104
bool update(ParamType const &iValue) override
Update the parameter with a value.
Definition: GUIJmbParameter.h:125
GUIJmbParam(std::shared_ptr< GUIJmbParameter< T >> iPtr=nullptr)
Definition: GUIJmbParameter.h:503
ParamType const & getValue() const
Definition: GUIJmbParameter.h:252
typename GUIJmbParameter< UTF8String >::EditorType EditorType
Definition: GUIJmbParameter.h:499
std::shared_ptr< GUIDiscreteParameter > asDiscreteParameter(int32 iStepCount) override
Converts this parameter into a discrete parameter.
Definition: GUIJmbParameter.h:454
void broadcast(T &&iValue)
Definition: GUIJmbParameter.h:582
Interface that defines a converter from a type T to an int32 given a number of steps (provided by get...
Definition: ParamSerializers.h:45
ParamType fValue
Definition: GUIJmbParameter.h:288
virtual tresult writeToStream(IBStreamer &oStreamer) const =0
GUIJmbParameter(std::shared_ptr< JmbParamDef< T >> iParamDef)
Definition: GUIJmbParameter.h:95
IJmbParamDef const * getParamDef() const
Definition: GUIJmbParameter.h:47
Wraps a GUIJmbParameter<T> to interpret it as a discrete parameter using the converter.
Definition: GUIJmbParameter.h:305
int32 getStepCount() const override
When a parameter is a discrete parameter (which means its underlying backing type is an int32 with va...
Definition: GUIJmbParameter.h:112
tresult writeToStream(IBStreamer &oStreamer) const override
Definition: GUIJmbParameter.h:212
ParamID getJmbParamID() const
Definition: GUIJmbParameter.h:50
tresult setValue(ParamType const &iValue) override
Sets the value.
Definition: GUIJmbParameter.h:166
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback)
Definition: GUIJmbParameter.h:596
static std::shared_ptr< GUIJmbParameter< T > > castToJmb(std::shared_ptr< IGUIParameter > iParam)
Convenient function to cast a generic IGUIParameter to a GUIJmbParameter<T>.
Definition: GUIJmbParameter.h:296
ParamID getParamID() const
Definition: GUIJmbParameter.h:514
Editor edit(T const &iValue)
Definition: GUIJmbParameter.h:546
GUIDiscreteJmbParameter(std::shared_ptr< GUIJmbParameter< T >> iJmbParameter, std::shared_ptr< IDiscreteConverter< T >> iConverter)
Definition: GUIJmbParameter.h:311
void setValue(T &&iNewValue)
The difference with update is that it does not check for equality (case when T is not comparable)
Definition: GUIJmbParameter.h:537
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const override
Creates a connection between this parameter and the callback: whenever the parameter changes,...
Definition: GUIJmbParameter.h:339
Defines the API for the editor which can be obtained by calling ITGUIParameter::edit().
Definition: IGUIParameter.h:236
std::string toUTF8String(int32 iPrecision) const
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition: GUIJmbParameter.h:590
virtual tresult readFromStream(IBStreamer &iStreamer)=0
T const & value() const
Synonym to getValue()
Definition: GUIJmbParameter.h:556
std::shared_ptr< IDiscreteConverter< T > > fConverter
Definition: GUIJmbParameter.h:447
Base class for all non vst parameters (need to provide serialization/deserialization)
Definition: ParamDef.h:316
tresult broadcast() const
Definition: GUIJmbParameter.h:572
std::string toUTF8String(int32 iPrecision) const override
Returns the current value of the parameter as a string (which is properly UTF-8 encoded).
Definition: GUIJmbParameter.h:224
virtual tresult readFromMessage(Message const &iMessage)=0
Base class for jamba parameters (non templated)
Definition: ParamDef.h:279
std::unique_ptr< EditorType > edit() override
Creates an editor to modify the parameter in a transactional fashion.
Definition: GUIJmbParameter.h:258
ParamType & getValue()
Definition: GUIJmbParameter.h:255
Interface to implement to receive parameter changes.
Definition: Parameters.h:43
tresult readFromMessage(Message const &iMessage) override
Definition: GUIJmbParameter.h:230