Jamba C++ API  5.1.1
GUIOptionalParam< T > Class Template Reference

Represents an optional parameter (Jmb, Vst or no param at all). More...

#include <GUIOptionalParam.h>

Inherits Dereferenceable< GUIOptionalParam< T > >.

Classes

class  Value
 The purpose of this class is to copy the value so that it can be accessed via -> thus allowing to write param->x to access the underlying type (T) when it is a struct or a class. More...
 

Public Types

using class_type = GUIOptionalParam< T >
 
using Editor = std::unique_ptr< EditorType >
 
using EditorType = typename ITGUIParameter< T >::ITEditor
 
using ParamType = T
 

Public Member Functions

std::unique_ptr< FObjectCxconnect (Parameters::IChangeListener *iChangeListener) const
 Creates a connection between this parameter and the change listener: whenever the parameter changes, the listener will be notified of the changes (Parameters::IChangeListener::onParameterChange(ParamID)). More...
 
std::unique_ptr< FObjectCxconnect (Parameters::ChangeCallback iChangeCallback) const
 Creates a connection between this parameter and the callback: whenever the parameter changes, the callback will be invoked (std::function<void()>). More...
 
std::unique_ptr< EditorTypeedit ()
 Creates an editor to modify the parameter in a transactional fashion. More...
 
std::unique_ptr< EditorTypeedit (ParamType const &iValue)
 Shortcut api which creates an editor followed by ITEditor::setValue(ParamType const &) to set the parameter value to iValue. More...
 
bool exists () const
 Always return true because by definition an optional parameter always exist. More...
 
ParamID getParamID () const
 Each parameter has a unique ID returned by this method. More...
 
int32 getStepCount () const
 When a parameter is a discrete parameter (which means its underlying backing type is an int32 with values in the discrete range [0, getStepCount()]), this method will return the number of steps (> 0). More...
 
ParamType getValue () const
 
 GUIOptionalParam ()
 
 GUIOptionalParam (T const &iDefaultValue)
 
 GUIOptionalParam (std::shared_ptr< ITGUIParameter< T >> iParameter)
 
constexpr ParamType operator * () const
 allow writing *param to access the underlying value (or in other words, *param is the same param.value()) More...
 
constexpr Value operator -> () const
 allow writing param->x to access the underlying value when T is a struct or class More...
 
 operator ParamType () const
 Allow to use the param as the underlying ParamType. More...
 
GUIOptionalParamoperator= (T const &iValue)
 Allow to write param = 3 instead of param.update(3) for example. More...
 
tresult resetToDefault ()
 Resets the param to its default value. More...
 
tresult setValue (ParamType const &iValue)
 Unconditionally sets the value of the parameter to the value provided. More...
 
std::string toUTF8String (int32 iPrecision) const
 Returns the current value of the parameter as a string (which is properly UTF-8 encoded). More...
 
bool update (ParamType const &iValue)
 First check if the value provided (iValue) is different from the current value and if that is the case then updates it to the new value. More...
 
ParamType value () const
 Synonym to getValue() More...
 

Private Attributes

std::shared_ptr< ITGUIParameter< ParamType > > fParameter
 

Detailed Description

template<typename T>
class pongasoft::VST::GUI::Params::GUIOptionalParam< T >

Represents an optional parameter (Jmb, Vst or no param at all).

Like GUIVstParam and GUIJmbParam, this class is a wrapper around the underlying parameter. This parameter is used in very generic views that need to handle a Vst or Jmb parameter, as well as no parameter at all (which is for example the case when adding a brand new view in the VSTGUI editor) and still be functional.

You can obtain an instance of an optional parameter by calling any ParamAware::registerOptionalXXX (resp. ParamAware::registerOptionalDiscreteXX) method.

Note
Because GUIOptionalParam can represent a Vst parameter or a Jmb parameter, there are some restrictions on T itself (which do not exist if you use GUIJmbParam):
  • T must have empty constructor: T()
  • T have a copy constructor: T(T const &)
  • T must be copy assignable: T& operator=(T const &)

Member Typedef Documentation

◆ class_type

◆ Editor

using Editor = std::unique_ptr<EditorType>

◆ EditorType

using EditorType = typename ITGUIParameter<T>::ITEditor

◆ ParamType

using ParamType = T

Constructor & Destructor Documentation

◆ GUIOptionalParam() [1/3]

GUIOptionalParam ( )
inline

◆ GUIOptionalParam() [2/3]

GUIOptionalParam ( T const &  iDefaultValue)
inlineexplicit

◆ GUIOptionalParam() [3/3]

GUIOptionalParam ( std::shared_ptr< ITGUIParameter< T >>  iParameter)
inlineexplicit

Member Function Documentation

◆ connect() [1/2]

std::unique_ptr<FObjectCx> connect ( Parameters::IChangeListener iChangeListener) const
inline

Creates a connection between this parameter and the change listener: whenever the parameter changes, the listener will be notified of the changes (Parameters::IChangeListener::onParameterChange(ParamID)).

Note
This method is usually invoked by the framework but it may be used in the rare cases when the caller requires to handle the duration of the connection in a more granular fashion
Parameters
iChangeListenerthe listener that will be notified on parameter changes. nullptr is allowed and will be a noop.
Returns
the connection between this parameter and the listener and is maintained for as long as this pointer exists

◆ connect() [2/2]

std::unique_ptr<FObjectCx> connect ( Parameters::ChangeCallback  iChangeCallback) const
inline

Creates a connection between this parameter and the callback: whenever the parameter changes, the callback will be invoked (std::function<void()>).

Note
This method is usually invoked by the framework but it may be used in the rare cases when the caller requires to handle the duration of the connection in a more granular fashion
Parameters
iChangeCallbackthe callback that will be invoked on parameter changes.
Returns
the connection between this parameter and the callback and is maintained for as long as this pointer exists

◆ edit() [1/2]

std::unique_ptr<EditorType> edit ( )
inline

Creates an editor to modify the parameter in a transactional fashion.

See also
ITGUIParameter::ITEditor

◆ edit() [2/2]

std::unique_ptr<EditorType> edit ( ParamType const &  iValue)
inline

Shortcut api which creates an editor followed by ITEditor::setValue(ParamType const &) to set the parameter value to iValue.

◆ exists()

bool exists ( ) const
inline

Always return true because by definition an optional parameter always exist.

◆ getParamID()

ParamID getParamID ( ) const
inline

Each parameter has a unique ID returned by this method.

Note
Some parameters (in particular GUIOptionalParam) may return pongasoft::VST::UNDEFINED_PARAM_ID

◆ getStepCount()

int32 getStepCount ( ) const
inline

When a parameter is a discrete parameter (which means its underlying backing type is an int32 with values in the discrete range [0, getStepCount()]), this method will return the number of steps (> 0).

Note
Although a parameter may not be a discrete parameter itself, the method asDiscreteParameter(int32) may be able to convert/adapt it to one.
Returns
the number of steps which is > 0 if and only if this parameter is a discrete parameter.

◆ getValue()

ParamType getValue ( ) const
inline
Returns
the current value of the parameter as a T

◆ operator *()

constexpr ParamType operator * ( ) const
inline

allow writing *param to access the underlying value (or in other words, *param is the same param.value())

◆ operator ->()

constexpr Value operator -> ( ) const
inline

allow writing param->x to access the underlying value when T is a struct or class

◆ operator ParamType()

operator ParamType ( ) const
inline

Allow to use the param as the underlying ParamType.

Example: if(param) in the case T is bool

◆ operator=()

GUIOptionalParam& operator= ( T const &  iValue)
inline

Allow to write param = 3 instead of param.update(3) for example.

◆ resetToDefault()

tresult resetToDefault ( )
inline

Resets the param to its default value.

◆ setValue()

tresult setValue ( ParamType const &  iValue)
inline

Unconditionally sets the value of the parameter to the value provided.

Parameters
iValuethe value to set
Returns
kResultOk if successful

◆ toUTF8String()

std::string toUTF8String ( int32  iPrecision) const
inline

Returns the current value of the parameter as a string (which is properly UTF-8 encoded).

Parameters
iPrecisionif iPrecision < 0 the parameter is free to use whichever precision is tied to the parameter otherwise it should use the one provided

◆ update()

bool update ( ParamType const &  iValue)
inline

First check if the value provided (iValue) is different from the current value and if that is the case then updates it to the new value.

Note
If the type T does not provide a way to compare the value, then this call will delegate to setValue(ParamType const &) and return true.
Parameters
iValuethe value to update
Returns
true if the value was updated

◆ value()

ParamType value ( ) const
inline

Synonym to getValue()

Member Data Documentation

◆ fParameter

std::shared_ptr<ITGUIParameter<ParamType> > fParameter
private

The documentation for this class was generated from the following file: