11 #ifndef VALUE_TREE_CLONE_H_INCLUDED
12 #define VALUE_TREE_CLONE_H_INCLUDED
22 typedef ReferenceCountedObjectPtr<ValueTreeCopy> Ptr;
25 t = copyFrom.createCopy();
28 ValueTree& getReference() {
return t; }
47 public ValueTree::Listener
51 class ValueTreeLinkCache
54 ValueTree operator[] (
const ValueTree& t)
56 for (
auto& s : updateMap)
58 if (s.main == t)
return s.copy;
61 return ValueTree::invalid;
69 void add (
const ValueTree& src,
const ValueTree& copy)
74 updateMap.push_back (x);
81 std::vector<MapEntry> updateMap;
100 jobsForCriticalThread (q)
113 sourceTree.removeListener (
this);
115 sourceTree.addListener (
this);
120 void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded)
125 void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved)
130 void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved)
135 void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) {}
144 updatePropertymap (sourceTree, t->getReference());
146 sendReplaceValueTree (t);
151 void valueTreePropertyChanged (ValueTree& tree,
const Identifier& property)
159 if (! isPropertyChangedOperationLockFree (tree, property))
166 ValueTree target = linkCache[tree];
168 var v = tree[property];
177 (GarbageCollector::getInstance()->isInList (v.getObject()))
181 sendUpdateProperty (target, property, v);
186 bool isPropertyChangedOperationLockFree (ValueTree& tree,
const Identifier& property)
188 if (tree[property].isString())
return false;
190 ValueTree t = linkCache[tree];
192 if (t == ValueTree::invalid)
198 return (t.hasProperty (property));
203 void updatePropertymap (ValueTree& src, ValueTree& copy)
206 recreatePropertyUpdateMap (sourceTree, copy);
209 void recreatePropertyUpdateMap (ValueTree src, ValueTree copy)
211 for (
int i = 0; i < src.getNumChildren(); ++i)
213 recreatePropertyUpdateMap (src.getChild (i), copy.getChild (i));
216 linkCache.add (src, copy);
219 void sendUpdateProperty (ValueTree& target,
const Identifier& property,
const var& value)
221 jobsForCriticalThread.
callf (std::bind (&CriticalThreadValueTree::updatePropertyOnCriticalThread,
223 target, property, value));
226 void updatePropertyOnCriticalThread (ValueTree target, Identifier property, var value)
228 target.setProperty (property, value,
nullptr);
234 ValueTreeCopy::Ptr p = t;
235 jobsForCriticalThread.
callf (std::bind (&CriticalThreadValueTree::replaceValueTree,
240 void replaceValueTree (
typename ValueTreeCopy::Ptr replacementTree)
243 DBG (
"replacing tree with: " + replacementTree->getReference().toXmlString());
247 ValueTreeLinkCache linkCache;
249 ValueTree sourceTree;
254 #endif // VALUE_TREE_CLONE_H_INCLUDED
void setSource(ValueTree source)
set the source tree to copy. This is set initally by the constructor, so you may not need to call thi...
Definition: value_tree_clone.h:111
A GarbageCollectedObject wrapper around a ValueTree. You shouldn't have to create one of these direct...
Definition: value_tree_clone.h:18
ValueTreeCopy::Ptr readonly
The output - the clone of the ValueTree.
Definition: value_tree_clone.h:90
Allows a function call to be executed on a different thread, in a fast lock-safe and thread-safe mann...
Definition: nonblocking_call_queue.h:37
bool callf(Functor const &f)
Calls a function, via the queue, on a different thread.
Definition: nonblocking_call_queue.h:99
Maintain a clone of a ValueTree on a critical thread.
Definition: value_tree_clone.h:46
CriticalThreadValueTree(ValueTree source, LockFreeCallQueue &q)
Configure the CriticalThreadValueTree.
Definition: value_tree_clone.h:99
Allows objects to be created and destroyed on a non-critical thread but passed over to a critical thr...
Definition: garbage_collected_object.h:139
void syncAll()
Synchronise. You shouldn't have to call this. It should be called automatically from the non-critical...
Definition: value_tree_clone.h:139
Definition: value_tree_clone.h:77