Allolib
1.0
C++ Components For Interactive Multimedia
|
Public Types | |
typedef const std::function< float(float)> | ParameterProcessCallback |
typedef const std::function< void(float)> | ParameterChangeCallback |
typedef const std::function< void(float, ValueSource *)> | ParameterChangeCallbackSrc |
typedef const std::function< void(ValueSource *)> | ParameterMetaChangeCallbackSrc |
Public Member Functions | |
Parameter (std::string parameterName, std::string group="", float defaultValue=0, float min=-99999.0, float max=99999.0) | |
Parameter. More... | |
Parameter (std::string parameterName, float defaultValue, float min=-99999.0, float max=99999.0) | |
Parameter (std::string parameterName, std::string Group, float defaultValue, std::string prefix, float min=-99999.0, float max=99999.0) | |
Parameter (const al::Parameter ¶m) | |
virtual void | set (float value, ValueSource *src=nullptr) override |
set the parameter's value More... | |
virtual void | setNoCalls (float value, void *blockReceiver=nullptr) override |
set the parameter's value without calling callbacks More... | |
virtual float | get () override |
get the parameter's value More... | |
virtual float | toFloat () override |
Generic function to return the value of the parameter as a float. More... | |
virtual bool | fromFloat (float value) override |
Generic function to set the parameter from a single float value. More... | |
float | operator= (const float value) |
virtual void | getFields (std::vector< ParameterField > &fields) override |
virtual void | setFields (std::vector< ParameterField > &fields) override |
virtual void | sendValue (osc::Send &sender, std::string prefix="") override |
virtual void | sendMeta (osc::Send &sender, std::string bundleName="", std::string id="") override |
void | set (ParameterMeta *p) |
virtual void | reset () |
reset value to default value | |
void | setLocking (float value) |
set the parameter's value forcing a lock More... | |
virtual float | getPrevious () |
Get previous value. More... | |
void | min (float minValue, ValueSource *src=nullptr) |
set the minimum value for the parameter More... | |
float | min () const |
void | max (float maxValue, ValueSource *src=nullptr) |
set the maximum value for the parameter More... | |
float | max () const |
void | setDefault (const float &defaultValue) |
float | 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< float > * > | operator<< (ParameterWrapper< float > &newParam) |
std::vector< ParameterWrapper< float > * > & | operator<< (std::vector< ParameterWrapper< float > * > ¶mVector) |
operator float () | |
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 | |
void | setHint (std::string hintName, float hintValue) |
float | getHint (std::string hintName, bool *exists=nullptr) |
Protected Member Functions | |
void | runChangeCallbacksSynchronous (float &value, ValueSource *src) |
The Parameter class.
The Parameter class offers a simple way to encapsulate float values. It is not inherently thread safe, but since floats are atomic on most platforms it is safe in practice.
Parameters are created with:
Then values can be set from a low priority thread:
And read back from a high priority thread:
The values are clamped between a minimum and maximum set using the min() and max() functions.
The ParameterServer class allows exposing Parameter objects via OSC.
Definition at line 696 of file al_Parameter.hpp.
al::Parameter::Parameter | ( | std::string | parameterName, |
std::string | group = "" , |
||
float | defaultValue = 0 , |
||
float | min = -99999.0 , |
||
float | max = 99999.0 |
||
) |
parameterName | The name of the parameter |
Group | The group the parameter belongs to |
defaultValue | The initial value for the parameter |
min | Minimum value for the parameter |
max | Maximum value for the parameter |
This Parameter class is designed for parameters that can be expressed as a single float. It realies on float being atomic on the platform so there is no locking. This is a safe assumption for most platforms today.
|
inlineoverridevirtual |
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 from al::ParameterMeta.
Reimplemented in al::ParameterBool.
Definition at line 755 of file al_Parameter.hpp.
|
overridevirtual |
get the parameter's value
This function is thread-safe and can be called from any number of threads
Reimplemented from al::ParameterWrapper< float >.
Reimplemented in al::ParameterBool.
|
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.
|
virtualinherited |
Get previous value.
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 479 of file al_Parameter.hpp.
|
inlineinherited |
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.
|
inlineinherited |
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.
|
inherited |
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.
cb |
Definition at line 553 of file al_Parameter.hpp.
|
overridevirtual |
set the parameter's value
This function is thread-safe and can be called from any number of threads It does not block and relies on the atomicity of float.
Reimplemented from al::ParameterWrapper< float >.
|
inlineinherited |
set the parameter's value forcing a lock
No callbacks are called.
Definition at line 457 of file al_Parameter.hpp.
|
overridevirtual |
set the parameter's value without calling callbacks
This function is thread-safe and can be called from any number of threads. 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.
Reimplemented from al::ParameterWrapper< float >.
|
inherited |
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.
cb | The callback function |
Definition at line 542 of file al_Parameter.hpp.
|
inlineinherited |
Determines whether value change callbacks are called synchronously.
synchronous | If 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.
|
inlineoverridevirtual |
Generic function to return the value of the parameter as a float.
If not implemented, it will return 0.
Reimplemented from al::ParameterMeta.
Reimplemented in al::ParameterBool.
Definition at line 753 of file al_Parameter.hpp.