-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBrowserValueTreeSynchroniser.cpp
47 lines (41 loc) · 1.46 KB
/
BrowserValueTreeSynchroniser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace tomduncalf
{
namespace BrowserIntegration
{
#define VALUE_TREE_SYNCHRONISER_BATCH_CHANGES 1
BrowserValueTreeSynchroniser::BrowserValueTreeSynchroniser (juce::ValueTree& vt, juce::Identifier id, BrowserIntegration& b)
: juce::ValueTreeSynchroniser (vt),
treeId (id),
browserIntegration (b)
{
startTimerHz (60);
}
void BrowserValueTreeSynchroniser::stateChanged (const void* encodedChange, size_t encodedChangeSize)
{
// TODO could filter out redundant multiple changes to a single parameter
// in a single batch here or elsewhere
auto change = juce::Base64::toBase64 (encodedChange, encodedChangeSize);
queuedChanges.add (change);
#if VALUE_TREE_SYNCHRONISER_BATCH_CHANGES
// Do nothing, the timer will pick this up
#else
flushUpdates();
#endif
}
void BrowserValueTreeSynchroniser::timerCallback()
{
flushUpdates();
}
void BrowserValueTreeSynchroniser::flushUpdates()
{
if (queuedChanges.size() > 0)
{
auto* dataObj = new juce::DynamicObject();
dataObj->setProperty ("treeId", treeId.toString());
dataObj->setProperty ("changes", queuedChanges);
browserIntegration.sendEventToBrowser ("valueTreeStateChange", dataObj);
queuedChanges.clear();
}
}
}// namespace BrowserIntegration
}// namespace tomduncalf