![]() |
cello
JUCE ValueTrees for Humans
|
A class to abstract away the issues around storing and retrieving a value from a ValueTree. Designed to make working with VT values more like working with regular class/struct members. More...
#include <cello_value.h>
Classes | |
class | Cached |
A utility class to maintain the last known value of a cello::Value object – each call that fetches from a Value does two things that may be more costly than we like in some cases: More... | |
Public Types | |
using | ValidatePropertyFn = std::function<T (const T&)> |
We define the signature of a 'validator' function that can validate/modify/replace values as your application requires. | |
Public Member Functions | |
Value (Object &data, const juce::Identifier &id_, T initVal={}) | |
Construct a new Value object. | |
Value & | operator= (const T &val) |
Assign a new value, setting it in the underlying tree and perhaps notifying listeners. | |
void | set (const T &val) |
Set property value in the tree. If the onSet validator function has been configured, the val argument will be passed through that function (and possibly modified) before being stored into the tree. | |
operator T () const | |
Get the current value of this property from the tree. | |
T | get () const |
Get the current value of this property from the tree. | |
Cached | getCached () |
void | excludeListener (juce::ValueTree::Listener *listener) |
A listener to exclude from property change updates. | |
void | onPropertyChange (PropertyUpdateFn callback) |
Register (or clear) a callback function to execute when this value changes. | |
![]() | |
juce::Identifier | getId () const |
![]() | |
void | forceUpdate (bool shouldForceUpdate) |
If passed true, any call that sets any Value property on this Object will result in a property change update callback being executed. Default (false) behavior only performs this callback when the underlying value is changed. | |
bool | shouldForceUpdate () const |
Public Attributes | |
ValidatePropertyFn | onSet |
validator function called before setting this Value. | |
ValidatePropertyFn | onGet |
validator function called when retrieving this Value. This function is called with the current stored value, and might return a different value. | |
Static Public Attributes | |
static float | epsilon { 0.001f } |
Additional Inherited Members | |
![]() | |
ValueBase (const juce::Identifier &id_) | |
ctor is protected – you can't create an object of type ValueBase directly, this only exists so we have a common base type that's shared by all the templated Value<T> classes. | |
![]() | |
const juce::Identifier | id |
identifier of this value/property. | |
A class to abstract away the issues around storing and retrieving a value from a ValueTree. Designed to make working with VT values more like working with regular class/struct members.
Data types to be stored as Values must:
operator !=
(so we can execute change callbacks)juce::var
type, or define a juce::VariantConverter
structure to round-trip through a juce::var
NOTE that we have a special case for floating point types – we compare the old and new versions of the value with a small epsilon value to let your code control how 'close' two floating point values must be to be considered equivalent. There's a static epsilon
member of this class that you can set as needed in your application; the default is 0.001.
T | Data type handled by this Value. |
using cello::Value< T >::ValidatePropertyFn = std::function<T (const T&)> |
We define the signature of a 'validator' function that can validate/modify/replace values as your application requires.
These will be called (if present) whenever this value is set or retrieved.
|
inline |
Construct a new Value object.
data | The cello::Object that owns this Value |
id | Identifier of the data |
initVal | default initialized state for this value. |
|
inline |
A listener to exclude from property change updates.
listener |
|
inline |
Get the current value of this property from the tree.
|
inline |
|
inline |
Register (or clear) a callback function to execute when this value changes.
callback |
|
inline |
Get the current value of this property from the tree.
|
inline |
Assign a new value, setting it in the underlying tree and perhaps notifying listeners.
val |
this.x = this.y = 42;
|
inline |
Set property value in the tree. If the onSet
validator function has been configured, the val
argument will be passed through that function (and possibly modified) before being stored into the tree.
val |
|
inlinestatic |
when setting a floating point value, delta must be larger than this to cause a property change callback.