23#include <juce_core/juce_core.h>
24#include <juce_data_structures/juce_data_structures.h>
34 UpdateQueue (
Object& consumer, juce::Thread* thread);
35 virtual ~UpdateQueue () {}
36 UpdateQueue (
const UpdateQueue&) =
delete;
37 UpdateQueue& operator= (
const UpdateQueue&) =
delete;
38 UpdateQueue (UpdateQueue&&) =
delete;
39 UpdateQueue& operator= (UpdateQueue&&) =
delete;
66 void pushUpdate (juce::MemoryBlock&& update);
85 juce::Thread* destThread;
87 juce::CriticalSection mutex;
89 std::deque<juce::MemoryBlock> queue;
110 const char* data {
nullptr };
113 SyncData () =
default;
114 SyncData (
const void* data_,
size_t size_)
115 : data (
static_cast<const char*
> (data_))
119 bool operator== (
const SyncData& other)
const
121 if (size != other.size)
123 for (
size_t i { 0 }; i < size; ++i)
124 if (data[i] != other.data[i])
128 bool operator!= (
const SyncData& other)
const {
return !(*
this == other); }
131class Sync :
public UpdateQueue,
132 public juce::ValueTreeSynchroniser
149 Sync& operator= (
const Sync&) =
delete;
162 void stateChanged (
const void* encodedChange,
size_t encodedChangeSize)
override;
164 void startUpdate (
void* data,
size_t size)
override;
165 void endUpdate ()
override;
221 void startUpdate (Sync* sync,
void* data,
size_t size);
227 void endUpdate (Sync* sync);
237 bool shouldHandleUpdate (Sync* sync,
void* data,
size_t size)
const;
Definition cello_object.h:34
Class to manage bi-directional sync between two Objects in different threads, preventing feedback loo...
Definition cello_sync.h:176
void performNextUpdate(juce::Thread *thread)
Perform the next update for the given thread.
Definition cello_sync.cpp:163
SyncController(Object &obj1, juce::Thread *threadForObj1, Object &obj2, juce::Thread *threadForObj2)
Construct a new SyncController object.
Definition cello_sync.cpp:125
void performAllUpdates(juce::Thread *thread)
Perform all updates for the given thread.
Definition cello_sync.cpp:174
Sync(Object &producer, Object &consumer, juce::Thread *thread, SyncController *controller=nullptr)
Construct a new Sync object.
Definition cello_sync.cpp:88
bool isDestinationThread(juce::Thread *thread) const
Check if the given thread is the destination thread for this update queue.
Definition cello_sync.h:63
void performAllUpdates()
Execute each of the updates that are ready.
Definition cello_sync.cpp:38
virtual void endUpdate()=0
Called when the update is complete. clear the update data.
int getPendingUpdateCount() const
Definition cello_sync.cpp:32
virtual void startUpdate(void *data, size_t size)=0
Called when a new update is pushed onto the queue. We use this to prevent feedback loops.
void performNextUpdate()
Pop the next event from the queue and apply the change to the destination value tree.
Definition cello_sync.cpp:44
Data structure for holding synchronization update information.
Definition cello_sync.h:109