Allolib  1.0
C++ Components For Interactive Multimedia
al::ParameterWrapper< ParameterType > Class Template Reference

The ParameterWrapper class provides a generic thread safe Parameter class from the ParameterType template parameter. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/ui/al_Parameter.hpp>

Inheritance diagram for al::ParameterWrapper< ParameterType >:
al::ParameterMeta

Public Types

typedef const std::function< ParameterType(ParameterType)> ParameterProcessCallback
 
typedef const std::function< void(ParameterType)> ParameterChangeCallback
 
typedef const std::function< void(ParameterType, ValueSource *)> ParameterChangeCallbackSrc
 
typedef const std::function< void(ValueSource *)> ParameterMetaChangeCallbackSrc
 

Public Member Functions

 ParameterWrapper (std::string parameterName, std::string group="", ParameterType defaultValue=ParameterType())
 ParameterWrapper. More...
 
 ParameterWrapper (std::string parameterName, std::string Group, ParameterType defaultValue, ParameterType min, ParameterType max)
 
 ParameterWrapper (const ParameterWrapper &param)
 
virtual void set (ParameterType value, ValueSource *src=nullptr)
 set the parameter's value More...
 
virtual void reset ()
 reset value to default value
 
virtual void setNoCalls (ParameterType value, void *blockReceiver=nullptr)
 set the parameter's value without calling callbacks More...
 
void setLocking (ParameterType value)
 set the parameter's value forcing a lock More...
 
virtual ParameterType get ()
 get the parameter's value More...
 
virtual ParameterType getPrevious ()
 Get previous value. More...
 
void min (ParameterType minValue, ValueSource *src=nullptr)
 set the minimum value for the parameter More...
 
ParameterType min () const
 
void max (ParameterType maxValue, ValueSource *src=nullptr)
 set the maximum value for the parameter More...
 
ParameterType max () const
 
void setDefault (const ParameterType &defaultValue)
 
ParameterType getDefault () const
 
void setProcessingCallback (ParameterProcessCallback cb)
 setProcessingCallback sets a callback to be called whenever the parameter value changes More...
 
void registerChangeCallback (ParameterChangeCallback cb)
 registerChangeCallback adds a callback to be called when the value changes More...
 
void registerChangeCallback (ParameterChangeCallbackSrc cb)
 
void registerMetaChangeCallback (ParameterMetaChangeCallbackSrc cb)
 
void setSynchronousCallbacks (bool synchronous=true)
 Determines whether value change callbacks are called synchronously. More...
 
bool hasChange ()
 
bool processChange ()
 call change callbacks if value has changed since last call
 
std::vector< ParameterWrapper< ParameterType > * > operator<< (ParameterWrapper< ParameterType > &newParam)
 
std::vector< ParameterWrapper< ParameterType > * > & operator<< (std::vector< ParameterWrapper< ParameterType > * > &paramVector)
 
 operator ParameterType ()
 
ParameterWrapper< ParameterType > operator= (const ParameterType value)
 
std::string getFullAddress ()
 return the full OSC address for the parameter More...
 
std::string getName ()
 getName returns the name of the parameter
 
std::string displayName ()
 returns the text that should accompany parameters when displayed
 
void displayName (std::string displayName)
 sets the text that should accompany parameters when displayed
 
std::string getGroup ()
 getGroup returns the name of the group for the parameter
 
virtual float toFloat ()
 Generic function to return the value of the parameter as a float. More...
 
virtual bool fromFloat (float value)
 Generic function to set the parameter from a single float value. More...
 
void setHint (std::string hintName, float hintValue)
 
float getHint (std::string hintName, bool *exists=nullptr)
 
virtual void getFields (std::vector< ParameterField > &)
 
virtual void setFields (std::vector< ParameterField > &)
 
virtual void sendValue (osc::Send &sender, std::string prefix="")
 
virtual void sendMeta (osc::Send &sender, std::string bundleName="", std::string id="")
 
void set (ParameterMeta *p)
 

Protected Member Functions

void runChangeCallbacksSynchronous (ParameterType &value, ValueSource *src)
 

Protected Attributes

ParameterType mMin
 
ParameterType mMax
 
ParameterType mValue
 
ParameterType mValueCache
 
ParameterType mDefault
 
std::shared_ptr< ParameterProcessCallback > mProcessCallback
 
bool mChanged {false}
 
std::string mFullAddress
 
std::string mParameterName
 
std::string mDisplayName
 
std::string mGroup
 
std::map< std::string, float > mHints
 

Detailed Description

template<class ParameterType>
class al::ParameterWrapper< ParameterType >

The ParameterWrapper class provides a generic thread safe Parameter class from the ParameterType template parameter.

Definition at line 369 of file al_Parameter.hpp.

Constructor & Destructor Documentation

◆ ParameterWrapper()

template<class ParameterType >
al::ParameterWrapper< ParameterType >::ParameterWrapper ( std::string  parameterName,
std::string  group = "",
ParameterType  defaultValue = ParameterType() 
)

ParameterWrapper.

Parameters
parameterNameThe name of the parameter
GroupThe group the parameter belongs to
defaultValueThe initial value for the parameter
prefixAn address prefix that is prepended to the parameter's OSC address
minMinimum value for the parameter
maxMaximum value for the parameter

The mechanism used to protect data is locking a mutex within the set() function and doing try_lock() on the mutex to update a cached value in the get() function. In the worst case this might incur some jitter when reading the value.

Definition at line 1458 of file al_Parameter.hpp.

Member Function Documentation

◆ fromFloat()

virtual bool al::ParameterMeta::fromFloat ( float  value)
inlinevirtualinherited

Generic function to set the parameter from a single float value.

Will only have effect on parameters that have a single internal value and have implemented this function. Returns true if paramter is able to set value from float

Reimplemented in al::ParameterChoice, al::ParameterMenu, al::ParameterString, al::Trigger, al::ParameterBool, al::ParameterInt, and al::Parameter.

Definition at line 303 of file al_Parameter.hpp.

◆ get()

template<class ParameterType >
ParameterType al::ParameterWrapper< ParameterType >::get
virtual

get the parameter's value

This function is thread-safe and can be called from any number of threads

Returns
the parameter value

Reimplemented in al::ParameterBool, and al::Parameter.

Definition at line 1500 of file al_Parameter.hpp.

◆ getFullAddress()

std::string al::ParameterMeta::getFullAddress ( )
inlineinherited

return the full OSC address for the parameter

The parameter needs to be registered to a ParameterServer to listen to OSC values on this address

Definition at line 267 of file al_Parameter.hpp.

◆ getPrevious()

template<class ParameterType >
ParameterType al::ParameterWrapper< ParameterType >::getPrevious
virtual

Get previous value.

Returns

This function is only useful when queried from a value callback. It will represent the previous value of the parameter in that case.

Definition at line 1510 of file al_Parameter.hpp.

◆ max()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::max ( ParameterType  maxValue,
ValueSource src = nullptr 
)
inline

set the maximum value for the parameter

The value returned by the get() function will be clamped and will not go over the value set by this function.

Definition at line 501 of file al_Parameter.hpp.

◆ min()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::min ( ParameterType  minValue,
ValueSource src = nullptr 
)
inline

set the minimum value for the parameter

The value returned by the get() function will be clamped and will not go under the value set by this function.

Definition at line 487 of file al_Parameter.hpp.

◆ registerChangeCallback()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::registerChangeCallback ( ParameterChangeCallback  cb)

registerChangeCallback adds a callback to be called when the value changes

This function appends the callback to a list of callbacks to be called whenever a value changes.

Parameters
cb

Definition at line 1522 of file al_Parameter.hpp.

◆ set()

template<class ParameterType >
virtual void al::ParameterWrapper< ParameterType >::set ( ParameterType  value,
ValueSource src = nullptr 
)
inlinevirtual

set the parameter's value

This function is thread-safe and can be called from any number of threads. It blocks to lock a mutex so its use in critical contexts should be avoided.

Reimplemented in al::ParameterInt, and al::Parameter.

Definition at line 405 of file al_Parameter.hpp.

◆ setLocking()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::setLocking ( ParameterType  value)
inline

set the parameter's value forcing a lock

No callbacks are called.

Definition at line 457 of file al_Parameter.hpp.

◆ setNoCalls()

template<class ParameterType >
virtual void al::ParameterWrapper< ParameterType >::setNoCalls ( ParameterType  value,
void *  blockReceiver = nullptr 
)
inlinevirtual

set the parameter's value without calling callbacks

This function is thread-safe and can be called from any number of threads. It blocks to lock a mutex so its use in critical contexts should be avoided. The processing callback is called, but the callbacks registered with registerChangeCallback() are not called. This is useful to avoid infinite recursion when a widget sets the parameter that then sets the widget.

This function marks the parameter as changed, so you can process callbacks by calling processChange()

Reimplemented in al::ParameterInt, and al::Parameter.

Definition at line 436 of file al_Parameter.hpp.

◆ setProcessingCallback()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::setProcessingCallback ( typename ParameterWrapper< ParameterType >::ParameterProcessCallback  cb)

setProcessingCallback sets a callback to be called whenever the parameter value changes

Setting a callback can be useful when specific actions need to be taken whenever a parameter changes, but it can also be used to modify the value of the incoming parameter value before it is stored in the parameter. The registered callback must return the value to be stored in the parameter. Only one callback may be registered here.

Parameters
cbThe callback function
Returns
the transformed value

Definition at line 1515 of file al_Parameter.hpp.

◆ setSynchronousCallbacks()

template<class ParameterType >
void al::ParameterWrapper< ParameterType >::setSynchronousCallbacks ( bool  synchronous = true)
inline

Determines whether value change callbacks are called synchronously.

Parameters
synchronousIf set to true, parameter change callbacks are called directly from the setter function, i.e. as soon as the parameter value changes. This behavior might be problematic in some cases, for example when an OSC message triggers a change in the opengl state. This will cause a crash as the opengl functions need to be called from the opengl context instead of from a thread in the network context. By setting this to false and then calling runChangeCallbacks within the opengl thread will call the callbacks whenever the value has changed, but at the right time, in the right context.

Definition at line 573 of file al_Parameter.hpp.

◆ toFloat()

virtual float al::ParameterMeta::toFloat ( )
inlinevirtualinherited

Generic function to return the value of the parameter as a float.

If not implemented, it will return 0.

Reimplemented in al::ParameterChoice, al::ParameterMenu, al::ParameterString, al::Trigger, al::ParameterBool, al::ParameterInt, and al::Parameter.

Definition at line 294 of file al_Parameter.hpp.


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