21#include <base/source/fobject.h>
93 using FObject::update;
99 fValue{iParamDef->fDefaultValue}
152 template<
class ValueModifier>
155 if(iValueModifier(&
fValue))
172 if constexpr(std::is_copy_assignable_v<ParamType>)
180 DLOG_F(ERROR,
"%s is not copy_assignable. Call updateIf instead.",
typeid(
ParamType).name());
191 fValue = std::move(iValue);
259 std::unique_ptr<EditorType>
edit()
override
261 return std::make_unique<DefaultEditorImpl<T>>(
this,
getValue());
282 return std::make_unique<FObjectCxCallback>(
const_cast<GUIJmbParameter *
>(
this), std::move(iChangeCallback));
297static std::shared_ptr<GUIJmbParameter<T>>
castToJmb(std::shared_ptr<IGUIParameter> iParam)
299 return std::dynamic_pointer_cast<GUIJmbParameter<T>>(iParam);
360 if(res == kResultFalse)
361 DLOG_F(WARNING,
"Cannot convert current value of Jmb param [%d] to a discrete value",
getParamID());
370 if(
getValue(discreteValue) == kResultOk)
372 iGetter(discreteValue);
379 bool update(int32
const &iDiscreteValue)
override
381 int32 currentDiscreteValue;
382 tresult res =
getValue(currentDiscreteValue);
386 if(iDiscreteValue != currentDiscreteValue)
388 if(
setValue(iDiscreteValue) == kResultOk)
397 tresult
setValue(int32
const &iDiscreteValue)
override
399 int32 currentDiscreteValue;
400 tresult res =
getValue(currentDiscreteValue);
403 if(iDiscreteValue != currentDiscreteValue)
406 if constexpr(std::is_copy_assignable_v<T>)
409 if(
fConverter->convertFromDiscreteValue(iDiscreteValue, jmbValue) == kResultOk)
412 DLOG_F(WARNING,
"Cannot convert discrete value [%d] to a [%s] value of Jmb param [%d]",
430 std::unique_ptr<EditorType>
edit()
override
432 int32 currentDiscreteValue;
433 tresult res =
getValue(currentDiscreteValue);
435 return std::make_unique<DefaultEditorImpl<int32>>(
this, currentDiscreteValue);
458 auto converter =
getParamDefT()->getDiscreteConverter();
460 if(converter && converter->getStepCount() > 0)
462 std::move(converter));
471 converter = std::make_shared<StaticCastDiscreteConverter<T>>(iStepCount);
473 std::move(converter));
477 DLOG_F(WARNING,
"Jmb param [%d] (type [%s]) cannot be converted to a discrete parameter",
501 using Editor = std::unique_ptr<EditorType>;
505 fPtr{std::move(iPtr)}
521 inline bool update(T
const &iNewValue) { DCHECK_F(
exists());
return fPtr->update(iNewValue); }
527 template<
class ValueModifier>
528 inline bool updateIf(ValueModifier
const &iValueModifier) { DCHECK_F(
exists());
return fPtr->updateIf(iValueModifier); }
560 [[deprecated(
"Since 4.1.0 - use operator* or .value() instead (ex: if(*param) {...} or if(param.value()) {...}")]]
561 inline operator T
const &()
const { DCHECK_F(
exists());
return fPtr->getValue(); }
600 std::shared_ptr<GUIJmbParameter<T>>
fPtr;
Implements all the various equality and relational operators for the type T which is assumed to encap...
Definition Operators.h:56
tresult setValue(int32 const &iDiscreteValue) override
Definition GUIJmbParameter.h:397
std::string toUTF8String(int32 iPrecision) const override
Definition GUIJmbParameter.h:441
std::shared_ptr< GUIJmbParameter< T > > fJmbParameter
Definition GUIJmbParameter.h:447
std::shared_ptr< IDiscreteConverter< T > > fConverter
Definition GUIJmbParameter.h:448
int32 getStepCount() const override
Definition GUIJmbParameter.h:328
ParamID getParamID() const override
Definition GUIJmbParameter.h:322
std::shared_ptr< GUIDiscreteParameter > asDiscreteParameter(int32 iStepCount) override
Definition GUIJmbParameter.h:346
tresult resetToDefault() override
Definition GUIJmbParameter.h:424
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:356
std::unique_ptr< EditorType > edit() override
Definition GUIJmbParameter.h:430
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const override
Definition GUIJmbParameter.h:340
tresult accessValue(ValueAccessor const &iGetter) const override
Definition GUIJmbParameter.h:367
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const override
Definition GUIJmbParameter.h:334
GUIDiscreteJmbParameter(std::shared_ptr< GUIJmbParameter< T > > iJmbParameter, std::shared_ptr< IDiscreteConverter< T > > iConverter)
Definition GUIJmbParameter.h:312
bool update(int32 const &iDiscreteValue) override
Definition GUIJmbParameter.h:379
typename GUIDiscreteParameter::ITEditor EditorType
Definition GUIJmbParameter.h:309
std::shared_ptr< GUIJmbParameter< T > > fPtr
Definition GUIJmbParameter.h:600
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener)
Definition GUIJmbParameter.h:594
bool updateIf(ValueModifier const &iValueModifier)
Use this flavor of update if you want to modify the value itself.
Definition GUIJmbParameter.h:528
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:538
constexpr T const * operator->() const
Definition GUIJmbParameter.h:567
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:533
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:591
bool update(T const &iNewValue)
This method is typically called by a view to change the value of the parameter.
Definition GUIJmbParameter.h:521
Editor edit(T const &iValue)
Definition GUIJmbParameter.h:547
typename GUIJmbParameter< T >::EditorType EditorType
Definition GUIJmbParameter.h:500
GUIJmbParam< T > & operator=(GUIJmbParam< T > const &iOther)=default
Assignment operator: fMyParam = registerParam(...);.
GUIJmbParam< T > & operator=(T const &iValue)
Allow to write param = 3.0.
Definition GUIJmbParameter.h:570
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:564
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback)
Definition GUIJmbParameter.h:597
ParamID getParamID() const
Definition GUIJmbParameter.h:515
void broadcast(T &&iValue)
Definition GUIJmbParameter.h:583
bool exists() const
Definition GUIJmbParameter.h:512
T const & value() const
Synonym to getValue().
Definition GUIJmbParameter.h:557
T ParamType
Definition GUIJmbParameter.h:499
tresult resetToDefault()
Resets the param to its default value.
Definition GUIJmbParameter.h:551
std::unique_ptr< EditorType > Editor
Definition GUIJmbParameter.h:501
T const & getValue() const
Definition GUIJmbParameter.h:554
void broadcast(T const &iValue)
Definition GUIJmbParameter.h:576
Editor edit()
Definition GUIJmbParameter.h:542
tresult broadcast() const
Definition GUIJmbParameter.h:573
GUIJmbParam(std::shared_ptr< GUIJmbParameter< T > > iPtr=nullptr)
Definition GUIJmbParameter.h:504
This is the templated version providing serializer methods, very similar to the GUIVstParameter conce...
Definition GUIJmbParameter.h:88
bool updateIf(ValueModifier const &iValueModifier)
Use this flavor of update if you want to modify the value itself.
Definition GUIJmbParameter.h:153
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:225
GUIJmbParameter(std::shared_ptr< JmbParamDef< T > > iParamDef)
Definition GUIJmbParameter.h:96
ParamType & getValue()
Definition GUIJmbParameter.h:256
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:113
ParamID getParamID() const override
Each parameter has a unique ID returned by this method.
Definition GUIJmbParameter.h:111
tresult writeToMessage(Message &oMessage) const override
Definition GUIJmbParameter.h:240
tresult readFromStream(IBStreamer &iStreamer) override
Definition GUIJmbParameter.h:204
~GUIJmbParameter() override
Definition GUIJmbParameter.h:105
ParamType fValue
Definition GUIJmbParameter.h:289
std::shared_ptr< GUIDiscreteParameter > asDiscreteParameter(int32 iStepCount) override
Converts this parameter into a discrete parameter.
Definition GUIJmbParameter.h:455
tresult resetToDefault() override
Resets the param to its default value.
Definition GUIJmbParameter.h:198
tresult setValue(ParamType const &iValue) override
Sets the value.
Definition GUIJmbParameter.h:167
tresult writeToStream(IBStreamer &oStreamer) const override
Definition GUIJmbParameter.h:213
std::unique_ptr< EditorType > edit() override
Creates an editor to modify the parameter in a transactional fashion.
Definition GUIJmbParameter.h:259
std::unique_ptr< FObjectCx > connect(Parameters::ChangeCallback iChangeCallback) const override
Definition GUIJmbParameter.h:280
JmbParamDef< T > const * getParamDefT() const
Definition GUIJmbParameter.h:116
bool update(ParamType const &iValue) override
Update the parameter with a value.
Definition GUIJmbParameter.h:126
std::unique_ptr< FObjectCx > connect(Parameters::IChangeListener *iChangeListener) const override
Definition GUIJmbParameter.h:272
T ParamType
Definition GUIJmbParameter.h:90
typename ITGUIParameter< T >::ITEditor EditorType
Definition GUIJmbParameter.h:91
ParamType const & getValue() const
Definition GUIJmbParameter.h:253
tresult accessValue(typename ITGUIParameter< T >::ValueAccessor const &iGetter) const override
Definition GUIJmbParameter.h:246
tresult readFromMessage(Message const &iMessage) override
Definition GUIJmbParameter.h:231
void writeToStream(std::ostream &oStream) const override
Definition GUIJmbParameter.h:219
tresult setValue(ParamType &&iValue)
Sets the value.
Definition GUIJmbParameter.h:189
ParamID getJmbParamID() const
Definition GUIJmbParameter.h:51
tresult handleMessage(Message const &iMessage) override
Definition GUIJmbParameter.h:69
IJmbParamDef const * getParamDef() const
Definition GUIJmbParameter.h:48
IGUIJmbParameter(std::shared_ptr< IJmbParamDef > iParamDef)
Definition GUIJmbParameter.h:45
virtual tresult writeToStream(IBStreamer &oStreamer) const =0
IMessageProducer * fMessageProducer
Definition GUIJmbParameter.h:79
virtual tresult readFromMessage(Message const &iMessage)=0
void setMessageProducer(IMessageProducer *iMessageProducer)
Definition GUIJmbParameter.h:75
virtual void writeToStream(std::ostream &oStream) const =0
virtual tresult writeToMessage(Message &oMessage) const =0
virtual tresult readFromStream(IBStreamer &iStreamer)=0
std::shared_ptr< IJmbParamDef > fParamDef
Definition GUIJmbParameter.h:78
tresult broadcast() const
Definition GUIJmbParameter.cpp:30
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
std::function< void(T const &)> ValueAccessor
API to access the value of the param.
Definition IGUIParameter.h:183
Interface that defines a converter from a type T to an int32 given a number of steps (provided by get...
Definition ParamSerializers.h:47
Base class for jamba parameters (non templated).
Definition ParamDef.h:281
Interface defining a message handler.
Definition MessageHandler.h:32
Abstraction for allocating and sending a message.
Definition MessageProducer.h:35
Base class for all non vst parameters (need to provide serialization/deserialization).
Definition ParamDef.h:318
Simple wrapper class with better api.
Definition Messaging.h:46
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
constexpr auto is_operator_not_eq_defined
Allows to detect whether a type defines operator!= at compile time.
Definition Metaprogramming.h:70
std::string typeString()
typeid(T).name() does not account for const or reference.
Definition Metaprogramming.h:121
constexpr auto is_static_cast_defined
Allows to detect (at compilation time) whether the call static_cast<To>(from) (where from is of type ...
Definition Metaprogramming.h:94
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:297