cello
JUCE ValueTrees for Humans
Loading...
Searching...
No Matches
cello_sync.h
1/*
2 Copyright (c) 2023 Brett g Porter
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
9 The above copyright notice and this permission notice shall be included in all
10 copies or substantial portions of the Software.
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 SOFTWARE.
18*/
19
20#pragma once
21
22#include <deque>
23#include <juce_core/juce_core.h>
24#include <juce_data_structures/juce_data_structures.h>
25
26namespace cello
27{
28
29class Object;
30
31class UpdateQueue
32{
33public:
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;
40
44 int getPendingUpdateCount () const;
45
49 void performAllUpdates ();
50
55 void performNextUpdate ();
56
57protected:
58 void pushUpdate (juce::MemoryBlock&& update);
59
60private:
62 Object& dest;
64 juce::Thread* destThread;
66 juce::CriticalSection mutex;
68 std::deque<juce::MemoryBlock> queue;
69};
70
81class Sync : public UpdateQueue,
82 public juce::ValueTreeSynchroniser
83{
84public:
94 Sync (Object& producer, Object& consumer, juce::Thread* thread);
95
96 Sync (const Sync&) = delete;
97 Sync& operator= (const Sync&) = delete;
98
99private:
110 void stateChanged (const void* encodedChange, size_t encodedChangeSize) override;
111};
112
113} // namespace cello
Definition cello_object.h:34
Sync(Object &producer, Object &consumer, juce::Thread *thread)
Construct a new Sync object.
Definition cello_sync.cpp:81
void performAllUpdates()
Execute each of the updates that are ready.
Definition cello_sync.cpp:38
int getPendingUpdateCount() const
Definition cello_sync.cpp:32
void performNextUpdate()
Pop the next event from the queue and apply the change to the destination value tree.
Definition cello_sync.cpp:44