21 : tree_(tree), property_name_(property_name), value_(default_value), default_(default_value) {
24 listener_id_ = tree_->add_listener(
26 if (prop == property_name_)
27 update_from_variant(new_val);
33 if (tree_ && listener_id_ >= 0)
34 tree_->remove_listener(listener_id_);
38 const T&
get()
const {
return value_; }
39 operator const T&()
const {
return value_; }
49 void set(
const T& new_value) {
50 if (tree_ && value_ == new_value && tree_->has(property_name_))
62 auto val = tree_->get(property_name_);
63 update_from_variant(val);
67 bool is_bound()
const {
return tree_ !=
nullptr; }
73 : tree_(std::move(other.tree_)), property_name_(std::move(other.property_name_)),
74 value_(std::move(other.value_)), default_(std::move(other.default_)) {
76 if (tree_ && other.listener_id_ >= 0) {
77 tree_->remove_listener(other.listener_id_);
78 other.listener_id_ = -1;
79 listener_id_ = tree_->add_listener(
81 if (prop == property_name_)
82 update_from_variant(new_val);
89 std::string property_name_;
92 int listener_id_ = -1;
105 return std::holds_alternative<std::monostate>(val);
112template<>
inline void CachedProperty<bool>::update_from_variant(
const PropertyValue& val) {
114 else if (
auto* b = std::get_if<bool>(&val)) value_ = *b;
116template<>
inline void CachedProperty<int64_t>::update_from_variant(
const PropertyValue& val) {
118 else if (
auto* i = std::get_if<int64_t>(&val)) value_ = *i;
120template<>
inline void CachedProperty<double>::update_from_variant(
const PropertyValue& val) {
122 else if (
auto* d = std::get_if<double>(&val)) value_ = *
d;
123 else if (
auto* i = std::get_if<int64_t>(&val)) value_ =
static_cast<double>(*i);
125template<>
inline void CachedProperty<std::string>::update_from_variant(
const PropertyValue& val) {
127 else if (
auto* s = std::get_if<std::string>(&val)) value_ = *
s;
void refresh()
Force refresh from the tree.
Definition cached_property.hpp:60
CachedProperty & operator=(const CachedProperty &)=delete
const T & get() const
Get the cached value (no variant extraction — fast).
Definition cached_property.hpp:38
~CachedProperty()
Definition cached_property.hpp:32
bool is_bound() const
Whether bound to a tree.
Definition cached_property.hpp:67
CachedProperty(CachedProperty &&other) noexcept
Definition cached_property.hpp:72
CachedProperty(StateTree::Ptr tree, std::string_view property_name, T default_value=T{})
Bind to a tree node and property name.
Definition cached_property.hpp:20
CachedProperty(const CachedProperty &)=delete
CachedProperty & operator=(const T &new_value)
Definition cached_property.hpp:57
void set(const T &new_value)
Set the value (updates both cache and tree).
Definition cached_property.hpp:49
Reactive tree node — each node has a type name, properties, and children.
Definition state_tree.hpp:293
std::shared_ptr< StateTree > Ptr
Definition state_tree.hpp:295
@ d
Definition pitch.hpp:22
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
std::variant< std::monostate, bool, int64_t, double, std::string, PropertyArrayValue, PropertyObjectValue > PropertyValue
Property value — can hold scalar values plus immutable recursive arrays and string-keyed objects.
Definition state_tree.hpp:66
bool property_is_absent(const PropertyValue &val)
Definition cached_property.hpp:104
@ s
Definition input_events.hpp:41