Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
signal_graph_node.hpp
Go to the documentation of this file.
1#pragma once
2
3// Stable node vocabulary and retained node state for the Pulp host signal graph.
4
8
9#include <cstddef>
10#include <cstdint>
11#include <functional>
12#include <memory>
13#include <string>
14#include <string_view>
15#include <vector>
16
17namespace pulp::host {
18
19// ── Node types ──────────────────────────────────────────────────────────
20
21enum class NodeType {
22 AudioInput, // System audio input
23 AudioOutput, // System audio output
24 Plugin, // Plugin slot (VST3/AU/CLAP)
25 Gain, // Simple gain utility
26 MidiInput, // System MIDI input
27 MidiOutput, // System MIDI output
28 Custom, // String-keyed extension node
32};
33
34enum class PortKind : uint8_t { Audio, Sidechain, Midi, Event, Control, Param, Spectral };
35
36struct PortHandle {
39 bool output = false;
40 std::string name;
42 std::uint64_t owner = 0;
43 std::uint64_t incarnation = 0;
44};
45
58 std::string rule;
59 std::string suggested_fix;
60 std::string message() const {
61 return rule + (suggested_fix.empty() ? "" : "; " + suggested_fix);
62 }
63 explicit operator bool() const noexcept {
64 return code == Code::Ok;
65 }
66};
67
69
74
77 std::uint64_t reseed = 0;
78 std::size_t max_bytes = 64ull * 1024ull * 1024ull;
79};
80
83 // The crossfade shape for a live instance swap: the committed swap renders both the
84 // old and new instance for fade_ms and blends old->new along `curve` (click-free at
85 // both ends), so a swap between instances whose output differs does not step at the
86 // boundary. fade_ms == 0 disables the fade (an instant atomic switch at a block
87 // boundary — gap-free but a hard cut).
88 int fade_ms = 30;
90 float headroom_threshold = 0.75f;
91 std::size_t max_state_bytes = 64ull * 1024ull * 1024ull;
93 std::function<void(NodeId,
94 std::shared_ptr<PluginSlot> /*old_slot*/,
95 std::shared_ptr<PluginSlot> /*new_slot*/)>
97};
98
117
123
124// ── Graph Node ──────────────────────────────────────────────────────────
125
126struct GraphNode {
129 std::string name;
132
133 // For Plugin nodes, the loaded plugin slot. Held as shared_ptr so that
134 // published CompiledGraph snapshots can keep the plugin alive while the
135 // audio thread is still referencing a now-stale snapshot.
136 std::shared_ptr<PluginSlot> plugin;
137
138 // For Plugin nodes, the identity used to load it. Preserved even when
139 // the slot itself is null (e.g., plugin missing on this machine after a
140 // .pulpgraph load) so subsequent serializations retain the identity for
141 // later re-resolution.
143
144 // UI-thread-owned scalar state that needs to survive snapshot
145 // recompilation. compile_() copies these into per-snapshot NodeRuntime.
146 float gain = 1.0f;
147
148 // For Custom nodes, the registry identity that created the node. The
149 // version is serialized with the graph so older custom topologies can be
150 // distinguished from newer incompatible factories.
151 std::string custom_type_id;
153
154 // Opaque state for a stateful custom node. `custom_instance` is the live
155 // per-node object (RAII via the type's destroy), created on the UI
156 // thread in prepare() and captured into each compiled snapshot like a
157 // plugin shared_ptr so old audio snapshots stay alive. `custom_state_blob`
158 // is the serialized form, preserved even when the type is unresolved (so a
159 // round-trip through .pulpgraph keeps the state). `custom_state_pending`
160 // marks a freshly-loaded blob to apply to the instance exactly once.
161 std::shared_ptr<void> custom_instance;
162 std::vector<uint8_t> custom_state_blob;
164
165 // Cached, prepare-stable mirror of this node's transport-sensitivity
166 // capability. Resolved ONCE in compile_() — for a Plugin node from its
167 // slot's PluginSlot::wants_transport(), for a Custom node from whether its
168 // type registered a transport-aware callback — BEFORE the anticipation
169 // eligibility analysis runs, and read by BOTH the anticipation analyzer
170 // (which seeds AnticipationExclusion::TransportSensitive on a true value) and
171 // the routed binding resolution (which forwards the live transport to a
172 // true-valued node). The single shared read guarantees the partition and the
173 // bindings can never disagree. Prepare-stable: if a node's capability could
174 // change after compile, that requires a re-prepare for the graph to observe
175 // it — process() never re-polls the live slot per block.
177
179 bool hosted_editor_open = false;
180
181 std::vector<PortHandle> input_ports;
182 std::vector<PortHandle> output_ports;
183
184 std::optional<graph::SpectralIdentity> spectral_identity;
185 std::optional<graph::QualifiedSpectralStage> spectral_stage;
186
187 PortHandle in(std::string_view port) const;
188 PortHandle out(std::string_view port) const;
189};
190
191} // namespace pulp::host
std::uint32_t NodeId
Definition graph_types.hpp:7
std::uint32_t PortIndex
Definition graph_types.hpp:8
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
@ Midi
Definition sample_region_proof.hpp:17
@ Event
Definition sample_region_proof.hpp:18
LiveSwapCurve
Definition signal_graph_node.hpp:68
@ Smoothstep
Definition signal_graph_node.hpp:68
@ EqualPower
Definition signal_graph_node.hpp:68
@ None
Definition anticipation_eligibility.hpp:22
@ Sidechain
Definition anticipation_eligibility.hpp:28
PortKind
Definition signal_graph_node.hpp:34
@ Control
Definition signal_graph_node.hpp:34
@ Audio
Definition signal_graph_node.hpp:34
@ Param
Definition signal_graph_node.hpp:34
@ Spectral
Definition signal_graph_node.hpp:34
@ PrepareFailed
Definition sample_region_proof.hpp:131
@ LoadFailed
Definition node_pack.hpp:176
RetainedHistoryMode
Policy for stateful DSP cells when a live instance is replaced.
Definition signal_graph_node.hpp:73
@ Adopt
Definition signal_graph_node.hpp:73
@ Reseed
Definition signal_graph_node.hpp:73
@ Clear
Definition signal_graph_node.hpp:73
@ Refuse
Definition signal_graph_node.hpp:73
@ Crossfade
Definition signal_graph_node.hpp:73
LiveSwapFallbackReason
Definition signal_graph_node.hpp:99
@ PredicateExcluded
Definition signal_graph_node.hpp:114
@ StateRestoreFailed
Definition signal_graph_node.hpp:104
@ FeedbackNotSwappable
Definition signal_graph_node.hpp:111
@ OverBudget
Definition signal_graph_node.hpp:112
@ HistoryRefused
Definition signal_graph_node.hpp:105
@ NoLoadHistory
Definition signal_graph_node.hpp:113
@ None
Definition signal_graph_node.hpp:100
@ NotOptedIn
Definition signal_graph_node.hpp:101
@ UntrustedIdentity
Definition signal_graph_node.hpp:115
@ ShapeMismatch
Definition signal_graph_node.hpp:107
@ EditorOpen
Definition signal_graph_node.hpp:109
@ LatencyChanged
Definition signal_graph_node.hpp:108
@ StateTooLarge
Definition signal_graph_node.hpp:106
@ ParamContractMismatch
Definition signal_graph_node.hpp:110
NodeType
Definition signal_graph_node.hpp:21
@ SpectralStage
Definition signal_graph_node.hpp:30
@ Gain
Definition signal_graph_node.hpp:25
@ Plugin
Definition signal_graph_node.hpp:24
@ AudioOutput
Definition signal_graph_node.hpp:23
@ AudioInput
Definition signal_graph_node.hpp:22
@ Custom
Definition signal_graph_node.hpp:28
@ SpectralAnalysis
Definition signal_graph_node.hpp:29
@ MidiOutput
Definition signal_graph_node.hpp:27
@ SpectralSynthesis
Definition signal_graph_node.hpp:31
@ MidiInput
Definition signal_graph_node.hpp:26
Definition signal_graph_node.hpp:126
std::shared_ptr< PluginSlot > plugin
Definition signal_graph_node.hpp:136
std::vector< PortHandle > output_ports
Definition signal_graph_node.hpp:182
bool transport_sensitive
Definition signal_graph_node.hpp:176
std::string custom_type_id
Definition signal_graph_node.hpp:151
float gain
Definition signal_graph_node.hpp:146
std::vector< uint8_t > custom_state_blob
Definition signal_graph_node.hpp:162
std::shared_ptr< void > custom_instance
Definition signal_graph_node.hpp:161
std::vector< PortHandle > input_ports
Definition signal_graph_node.hpp:181
PortHandle in(std::string_view port) const
bool hosted_editor_open
Definition signal_graph_node.hpp:179
std::optional< graph::QualifiedSpectralStage > spectral_stage
Definition signal_graph_node.hpp:185
std::string name
Definition signal_graph_node.hpp:129
NodeLiveSwapPolicy live_swap_policy
Definition signal_graph_node.hpp:178
int num_output_ports
Definition signal_graph_node.hpp:131
NodeType type
Definition signal_graph_node.hpp:128
bool custom_state_pending
Definition signal_graph_node.hpp:163
std::optional< graph::SpectralIdentity > spectral_identity
Definition signal_graph_node.hpp:184
int num_input_ports
Definition signal_graph_node.hpp:130
NodeId id
Definition signal_graph_node.hpp:127
int custom_type_version
Definition signal_graph_node.hpp:152
PluginInfo plugin_info
Definition signal_graph_node.hpp:142
PortHandle out(std::string_view port) const
Definition signal_graph_node.hpp:46
std::string rule
Definition signal_graph_node.hpp:58
PortIndex port
Definition signal_graph_node.hpp:57
NodeId node
Definition signal_graph_node.hpp:56
std::string message() const
Definition signal_graph_node.hpp:60
Code code
Definition signal_graph_node.hpp:55
Code
Definition signal_graph_node.hpp:47
@ KindMismatch
Definition signal_graph_node.hpp:51
@ UnknownPort
Definition signal_graph_node.hpp:50
@ UnknownNode
Definition signal_graph_node.hpp:49
@ IllegalCycle
Definition signal_graph_node.hpp:52
@ Ok
Definition signal_graph_node.hpp:48
@ Duplicate
Definition signal_graph_node.hpp:53
std::string suggested_fix
Definition signal_graph_node.hpp:59
Definition signal_graph_node.hpp:118
NodeId offending_node
Definition signal_graph_node.hpp:120
std::string message
Definition signal_graph_node.hpp:121
LiveSwapFallbackReason reason
Definition signal_graph_node.hpp:119
Definition signal_graph_node.hpp:81
int fade_ms
Definition signal_graph_node.hpp:88
std::function< void(NodeId, std::shared_ptr< PluginSlot >, std::shared_ptr< PluginSlot >)> on_instance_swapped
Definition signal_graph_node.hpp:96
bool allow_live_instance_swap
Definition signal_graph_node.hpp:82
std::size_t max_state_bytes
Definition signal_graph_node.hpp:91
LiveSwapCurve curve
Definition signal_graph_node.hpp:89
float headroom_threshold
Definition signal_graph_node.hpp:90
RetainedHistoryPolicy retained_history
Definition signal_graph_node.hpp:92
Definition scanner.hpp:35
Definition signal_graph_node.hpp:36
bool output
Definition signal_graph_node.hpp:39
PortIndex index
Definition signal_graph_node.hpp:38
PortKind kind
Definition signal_graph_node.hpp:41
std::uint64_t incarnation
Definition signal_graph_node.hpp:43
std::string name
Definition signal_graph_node.hpp:40
NodeId node
Definition signal_graph_node.hpp:37
std::uint64_t owner
Definition signal_graph_node.hpp:42
Definition signal_graph_node.hpp:75
std::size_t max_bytes
Definition signal_graph_node.hpp:78
RetainedHistoryMode mode
Definition signal_graph_node.hpp:76
std::uint64_t reseed
Definition signal_graph_node.hpp:77