Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
state_tree_sync.hpp
Go to the documentation of this file.
1#pragma once
2
3// StateTreeSynchroniser — delta-based sync of StateTree over IPC.
4// Encodes property changes and child mutations as compact deltas,
5// sends over an InterprocessConnection, and applies on the remote side.
6
8#include <vector>
9#include <cstdint>
10#include <functional>
11#include <utility>
12
13namespace pulp::state {
14
16enum class SyncDeltaType : uint8_t {
22};
23
25struct SyncDelta {
27 std::string path; // Dot-separated path to the node
28 std::string key; // Property name (for property ops) or child type (for child ops)
29 PropertyValue value; // New value (for PropertySet)
30 int child_index = -1; // Index (for ChildAdd/ChildRemove; source index for ChildMove)
31};
32
35public:
37
42
44 void detach();
45
47 std::vector<SyncDelta> take_deltas();
48
50 static std::vector<uint8_t> encode(const std::vector<SyncDelta>& deltas);
51
53 static std::vector<SyncDelta> decode(const uint8_t* data, size_t size);
54
56 static void apply(StateTree& tree, const std::vector<SyncDelta>& deltas);
57
58private:
60 void attach_node(StateTree& node);
61
63 void attach_subtree(StateTree& node);
64
69 void detach_subtree(StateTree& node);
70
71 StateTree::Ptr tree_;
72 std::vector<SyncDelta> pending_;
73
74 // Per-node listener registrations — recorded so detach() can remove
75 // listeners from every observed node, not just the root.
76 std::vector<std::pair<StateTree*, int>> property_listener_ids_;
77 std::vector<std::pair<StateTree*, int>> child_added_listener_ids_;
78 std::vector<std::pair<StateTree*, int>> child_removed_listener_ids_;
79 std::vector<std::pair<StateTree*, int>> child_moved_listener_ids_;
80};
81
82} // namespace pulp::state
void attach(StateTree::Ptr tree)
Attach to a tree and start recording changes.
std::vector< SyncDelta > take_deltas()
Get pending deltas since last call (clears the buffer).
static std::vector< SyncDelta > decode(const uint8_t *data, size_t size)
Decode binary deltas.
void detach()
Detach and stop recording.
static std::vector< uint8_t > encode(const std::vector< SyncDelta > &deltas)
Encode deltas as binary for transmission.
static void apply(StateTree &tree, const std::vector< SyncDelta > &deltas)
Apply deltas to a tree.
Reactive tree node — each node has a type name, properties, and children.
Definition state_tree.hpp:293
std::shared_ptr< StateTree > Ptr
Definition state_tree.hpp:295
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
SyncDeltaType
Delta types for tree synchronization.
Definition state_tree_sync.hpp:16
@ ChildAdd
Definition state_tree_sync.hpp:19
@ ChildRemove
Definition state_tree_sync.hpp:20
@ ChildMove
Reorder within one parent: child_index -> int64 value.
Definition state_tree_sync.hpp:21
@ PropertySet
Definition state_tree_sync.hpp:17
@ PropertyRemove
Definition state_tree_sync.hpp:18
std::variant< std::monostate, bool, int64_t, double, std::string, PropertyArrayValue, PropertyObjectValue > PropertyValue
Property value — can hold scalar values plus immutable recursive arrays and string-keyed objects.
Definition state_tree.hpp:66
A single change to synchronize.
Definition state_tree_sync.hpp:25
std::string key
Definition state_tree_sync.hpp:28
SyncDeltaType type
Definition state_tree_sync.hpp:26
std::string path
Definition state_tree_sync.hpp:27
PropertyValue value
Definition state_tree_sync.hpp:29
int child_index
Definition state_tree_sync.hpp:30