Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_ValueTreeSynchroniser.h 4.0KB

9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_VALUETREESYNCHRONISER_H_INCLUDED
  18. #define JUCE_VALUETREESYNCHRONISER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. This class can be used to watch for all changes to the state of a ValueTree,
  22. and to convert them to a transmittable binary encoding.
  23. The purpose of this class is to allow two or more ValueTrees to be remotely
  24. synchronised by transmitting encoded changes over some kind of transport
  25. mechanism.
  26. To use it, you'll need to implement a subclass of ValueTreeSynchroniser
  27. and implement the stateChanged() method to transmit the encoded change (maybe
  28. via a network or other means) to a remote destination, where it can be
  29. applied to a target tree.
  30. */
  31. class JUCE_API ValueTreeSynchroniser : private ValueTree::Listener
  32. {
  33. public:
  34. /** Creates a ValueTreeSynchroniser that watches the given tree.
  35. After creating an instance of this class and somehow attaching it to
  36. a target tree, you probably want to call sendFullSyncCallback() to
  37. get them into a common starting state.
  38. */
  39. ValueTreeSynchroniser (const ValueTree& tree);
  40. /** Destructor. */
  41. virtual ~ValueTreeSynchroniser();
  42. /** This callback happens when the ValueTree changes and the given state-change message
  43. needs to be applied to any other trees that need to stay in sync with it.
  44. The data is an opaque blob of binary that you should transmit to wherever your
  45. target tree lives, and use applyChange() to apply this to the target tree.
  46. */
  47. virtual void stateChanged (const void* encodedChange, size_t encodedChangeSize) = 0;
  48. /** Forces the sending of a full state message, which may be large, as it
  49. encodes the entire ValueTree.
  50. This will internally invoke stateChanged() with the encoded version of the state.
  51. */
  52. void sendFullSyncCallback();
  53. /** Applies an encoded change to the given destination tree.
  54. When you implement a receiver for changes that were sent by the stateChanged()
  55. message, this is the function that you'll need to call to apply them to the
  56. target tree that you want to be synced.
  57. */
  58. static bool applyChange (ValueTree& target,
  59. const void* encodedChangeData, size_t encodedChangeDataSize,
  60. UndoManager* undoManager);
  61. /** Returns the root ValueTree that is being observed. */
  62. const ValueTree& getRoot() noexcept { return valueTree; }
  63. private:
  64. ValueTree valueTree;
  65. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  66. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  67. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  68. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  69. void valueTreeParentChanged (ValueTree&) override;
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueTreeSynchroniser)
  71. };
  72. #endif // JUCE_VALUETREESYNCHRONISER_H_INCLUDED