OpenShot Library | libopenshot-audio 0.2.0
juce_ValueTreeSynchroniser.h
1
2/** @weakgroup juce_data_structures-values
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33
34//==============================================================================
35/**
36 This class can be used to watch for all changes to the state of a ValueTree,
37 and to convert them to a transmittable binary encoding.
38
39 The purpose of this class is to allow two or more ValueTrees to be remotely
40 synchronised by transmitting encoded changes over some kind of transport
41 mechanism.
42
43 To use it, you'll need to implement a subclass of ValueTreeSynchroniser
44 and implement the stateChanged() method to transmit the encoded change (maybe
45 via a network or other means) to a remote destination, where it can be
46 applied to a target tree.
47
48 @tags{DataStructures}
49*/
51{
52public:
53 /** Creates a ValueTreeSynchroniser that watches the given tree.
54
55 After creating an instance of this class and somehow attaching it to
56 a target tree, you probably want to call sendFullSyncCallback() to
57 get them into a common starting state.
58 */
59 ValueTreeSynchroniser (const ValueTree& tree);
60
61 /** Destructor. */
62 ~ValueTreeSynchroniser() override;
63
64 /** This callback happens when the ValueTree changes and the given state-change message
65 needs to be applied to any other trees that need to stay in sync with it.
66 The data is an opaque blob of binary that you should transmit to wherever your
67 target tree lives, and use applyChange() to apply this to the target tree.
68 */
69 virtual void stateChanged (const void* encodedChange, size_t encodedChangeSize) = 0;
70
71 /** Forces the sending of a full state message, which may be large, as it
72 encodes the entire ValueTree.
73
74 This will internally invoke stateChanged() with the encoded version of the state.
75 */
76 void sendFullSyncCallback();
77
78 /** Applies an encoded change to the given destination tree.
79
80 When you implement a receiver for changes that were sent by the stateChanged()
81 message, this is the function that you'll need to call to apply them to the
82 target tree that you want to be synced.
83 */
84 static bool applyChange (ValueTree& target,
85 const void* encodedChangeData, size_t encodedChangeDataSize,
86 UndoManager* undoManager);
87
88 /** Returns the root ValueTree that is being observed. */
89 const ValueTree& getRoot() noexcept { return valueTree; }
90
91private:
92 ValueTree valueTree;
93
94 void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
95 void valueTreeChildAdded (ValueTree&, ValueTree&) override;
96 void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
97 void valueTreeChildOrderChanged (ValueTree&, int, int) override;
98 void valueTreeParentChanged (ValueTree&) override;
99
100 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueTreeSynchroniser)
101};
102
103} // namespace juce
104
105/** @}*/
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
Represents a string identifier, designed for accessing properties by name.
Manages a list of undo/redo commands.
This class can be used to watch for all changes to the state of a ValueTree, and to convert them to a...
const ValueTree & getRoot() noexcept
Returns the root ValueTree that is being observed.
virtual void stateChanged(const void *encodedChange, size_t encodedChangeSize)=0
This callback happens when the ValueTree changes and the given state-change message needs to be appli...
Listener class for events that happen to a ValueTree.
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
#define JUCE_API
This macro is added to all JUCE public class declarations.