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 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. This class can be used to watch for all changes to the state of a ValueTree,
  23. and to convert them to a transmittable binary encoding.
  24. The purpose of this class is to allow two or more ValueTrees to be remotely
  25. synchronised by transmitting encoded changes over some kind of transport
  26. mechanism.
  27. To use it, you'll need to implement a subclass of ValueTreeSynchroniser
  28. and implement the stateChanged() method to transmit the encoded change (maybe
  29. via a network or other means) to a remote destination, where it can be
  30. applied to a target tree.
  31. @tags{DataStructures}
  32. */
  33. class JUCE_API ValueTreeSynchroniser : private ValueTree::Listener
  34. {
  35. public:
  36. /** Creates a ValueTreeSynchroniser that watches the given tree.
  37. After creating an instance of this class and somehow attaching it to
  38. a target tree, you probably want to call sendFullSyncCallback() to
  39. get them into a common starting state.
  40. */
  41. ValueTreeSynchroniser (const ValueTree& tree);
  42. /** Destructor. */
  43. ~ValueTreeSynchroniser() override;
  44. /** This callback happens when the ValueTree changes and the given state-change message
  45. needs to be applied to any other trees that need to stay in sync with it.
  46. The data is an opaque blob of binary that you should transmit to wherever your
  47. target tree lives, and use applyChange() to apply this to the target tree.
  48. */
  49. virtual void stateChanged (const void* encodedChange, size_t encodedChangeSize) = 0;
  50. /** Forces the sending of a full state message, which may be large, as it
  51. encodes the entire ValueTree.
  52. This will internally invoke stateChanged() with the encoded version of the state.
  53. */
  54. void sendFullSyncCallback();
  55. /** Applies an encoded change to the given destination tree.
  56. When you implement a receiver for changes that were sent by the stateChanged()
  57. message, this is the function that you'll need to call to apply them to the
  58. target tree that you want to be synced.
  59. */
  60. static bool applyChange (ValueTree& target,
  61. const void* encodedChangeData, size_t encodedChangeDataSize,
  62. UndoManager* undoManager);
  63. /** Returns the root ValueTree that is being observed. */
  64. const ValueTree& getRoot() noexcept { return valueTree; }
  65. private:
  66. ValueTree valueTree;
  67. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  68. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  69. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  70. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  71. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueTreeSynchroniser)
  72. };
  73. } // namespace juce