TracktionEngine
Public Member Functions | List of all members
tracktion::engine::ConstrainedCachedValue< Type > Class Template Reference

A CachedValue that can take a std::function to constrain its value. More...

Inherits juce::ValueTree::Listener.

Public Member Functions

 ConstrainedCachedValue ()
 Default constructor. More...
 
 ConstrainedCachedValue (juce::ValueTree &tree, const juce::Identifier &propertyID, juce::UndoManager *undoManager)
 Constructor. More...
 
 ConstrainedCachedValue (juce::ValueTree &tree, const juce::Identifier &propertyID, juce::UndoManager *undoManager, const Type &defaultToUse)
 Constructor. More...
 
void setConstrainer (std::function< Type(Type)> constrainerToUse)
 Sets a std::function to use to constain the value. More...
 
 operator Type () const noexcept
 Returns the current value of the property. More...
 
Type get () const noexcept
 Returns the current value of the property. More...
 
Type & operator* () noexcept
 Dereference operator. More...
 
Type * operator-> () noexcept
 Dereference operator. More...
 
template<typename OtherType >
bool operator== (const OtherType &other) const
 Returns true if the current value of the property (or the fallback value) is equal to other. More...
 
template<typename OtherType >
bool operator!= (const OtherType &other) const
 Returns true if the current value of the property (or the fallback value) is not equal to other. More...
 
juce::Value getPropertyAsValue ()
 Returns the current property as a Value object. More...
 
bool isUsingDefault () const
 Returns true if the current property does not exist and the CachedValue is using the fallback default value instead. More...
 
Type getDefault () const
 Returns the current fallback default value. More...
 
ConstrainedCachedValueoperator= (const Type &newValue)
 Sets the property. More...
 
void setValue (const Type &newValue, juce::UndoManager *undoManagerToUse)
 Sets the property. More...
 
void resetToDefault ()
 Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead. More...
 
void resetToDefault (juce::UndoManager *undoManagerToUse)
 Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead. More...
 
void setDefault (const Type &value)
 Resets the fallback default value. More...
 
void referTo (juce::ValueTree &tree, const juce::Identifier &property, juce::UndoManager *)
 Makes the CachedValue refer to the specified property inside the given ValueTree. More...
 
void referTo (juce::ValueTree &tree, const juce::Identifier &property, juce::UndoManager *, const Type &defaultVal)
 Makes the CachedValue refer to the specified property inside the given ValueTree, and specifies a fallback value to use if the property does not exist. More...
 
void forceUpdateOfCachedValue ()
 Force an update in case the referenced property has been changed from elsewhere. More...
 
juce::ValueTree & getValueTree () noexcept
 Returns a reference to the ValueTree containing the referenced property. More...
 
const juce::Identifier & getPropertyID () const noexcept
 Returns the property ID of the referenced property. More...
 

Detailed Description

template<typename Type>
class tracktion::engine::ConstrainedCachedValue< Type >

A CachedValue that can take a std::function to constrain its value.

Constructor & Destructor Documentation

◆ ConstrainedCachedValue() [1/3]

Default constructor.

Creates a default CachedValue not referring to any property. To initialise the object, call one of the referTo() methods.

◆ ConstrainedCachedValue() [2/3]

template<typename Type >
tracktion::engine::ConstrainedCachedValue< Type >::ConstrainedCachedValue ( juce::ValueTree &  tree,
const juce::Identifier &  propertyID,
juce::UndoManager *  undoManager 
)

Constructor.

Creates a CachedValue referring to a Value property inside a ValueTree. If you use this constructor, the fallback value will be a default-constructed instance of Type.

Parameters
treeThe ValueTree containing the property
propertyIDThe identifier of the property
undoManagerThe UndoManager to use when writing to the property

◆ ConstrainedCachedValue() [3/3]

template<typename Type >
tracktion::engine::ConstrainedCachedValue< Type >::ConstrainedCachedValue ( juce::ValueTree &  tree,
const juce::Identifier &  propertyID,
juce::UndoManager *  undoManager,
const Type &  defaultToUse 
)

Constructor.

Creates a default Cached Value referring to a Value property inside a ValueTree, and specifies a fallback value to use if the property does not exist.

Parameters
treeThe ValueTree containing the property
propertyIDThe identifier of the property
undoManagerThe UndoManager to use when writing to the property
defaultToUseThe fallback default value to use.

Member Function Documentation

◆ setConstrainer()

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::setConstrainer ( std::function< Type(Type)>  constrainerToUse)

Sets a std::function to use to constain the value.

You must call this before setting any of the values.

◆ operator Type()

template<typename Type >
tracktion::engine::ConstrainedCachedValue< Type >::operator Type ( ) const
noexcept

Returns the current value of the property.

If the property does not exist, returns the fallback default value.

This is the same as calling get().

◆ get()

template<typename Type >
Type tracktion::engine::ConstrainedCachedValue< Type >::get ( ) const
noexcept

Returns the current value of the property.

If the property does not exist, returns the fallback default value.

Referenced by tracktion::engine::LatencyPlugin::getLatencySeconds().

◆ operator*()

template<typename Type >
Type& tracktion::engine::ConstrainedCachedValue< Type >::operator* ( )
noexcept

Dereference operator.

Provides direct access to the property.

◆ operator->()

template<typename Type >
Type* tracktion::engine::ConstrainedCachedValue< Type >::operator-> ( )
noexcept

Dereference operator.

Provides direct access to members of the property if it is of object type.

◆ operator==()

template<typename Type >
template<typename OtherType >
bool tracktion::engine::ConstrainedCachedValue< Type >::operator== ( const OtherType &  other) const

Returns true if the current value of the property (or the fallback value) is equal to other.

◆ operator!=()

template<typename Type >
template<typename OtherType >
bool tracktion::engine::ConstrainedCachedValue< Type >::operator!= ( const OtherType &  other) const

Returns true if the current value of the property (or the fallback value) is not equal to other.

◆ getPropertyAsValue()

template<typename Type >
juce::Value tracktion::engine::ConstrainedCachedValue< Type >::getPropertyAsValue

Returns the current property as a Value object.

◆ isUsingDefault()

template<typename Type >
bool tracktion::engine::ConstrainedCachedValue< Type >::isUsingDefault

Returns true if the current property does not exist and the CachedValue is using the fallback default value instead.

◆ getDefault()

template<typename Type >
Type tracktion::engine::ConstrainedCachedValue< Type >::getDefault ( ) const

Returns the current fallback default value.

◆ operator=()

template<typename Type >
ConstrainedCachedValue< Type > & tracktion::engine::ConstrainedCachedValue< Type >::operator= ( const Type &  newValue)

Sets the property.

This will actually modify the property in the referenced ValueTree.

◆ setValue()

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::setValue ( const Type &  newValue,
juce::UndoManager *  undoManagerToUse 
)

Sets the property.

This will actually modify the property in the referenced ValueTree.

◆ resetToDefault() [1/2]

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::resetToDefault

Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.

◆ resetToDefault() [2/2]

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::resetToDefault ( juce::UndoManager *  undoManagerToUse)

Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.

◆ setDefault()

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::setDefault ( const Type &  value)

Resets the fallback default value.

◆ referTo() [1/2]

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::referTo ( juce::ValueTree &  tree,
const juce::Identifier &  property,
juce::UndoManager *  um 
)

Makes the CachedValue refer to the specified property inside the given ValueTree.

◆ referTo() [2/2]

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::referTo ( juce::ValueTree &  tree,
const juce::Identifier &  property,
juce::UndoManager *  um,
const Type &  defaultVal 
)

Makes the CachedValue refer to the specified property inside the given ValueTree, and specifies a fallback value to use if the property does not exist.

◆ forceUpdateOfCachedValue()

template<typename Type >
void tracktion::engine::ConstrainedCachedValue< Type >::forceUpdateOfCachedValue

Force an update in case the referenced property has been changed from elsewhere.

Note: The CachedValue is a ValueTree::Listener and therefore will be informed of changes of the referenced property anyway (and update itself). But this may happen asynchronously. forceUpdateOfCachedValue() forces an update immediately.

◆ getValueTree()

template<typename Type >
juce::ValueTree& tracktion::engine::ConstrainedCachedValue< Type >::getValueTree ( )
noexcept

Returns a reference to the ValueTree containing the referenced property.

◆ getPropertyID()

template<typename Type >
const juce::Identifier& tracktion::engine::ConstrainedCachedValue< Type >::getPropertyID ( ) const
noexcept

Returns the property ID of the referenced property.


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