Phase 15: host trusted LADSPA processors with persisted graph state

This commit is contained in:
Johannes Findeisen 2026-10-27 04:00:27 +01:00
commit f72314b5a3
24 changed files with 1046 additions and 70 deletions

View file

@ -180,6 +180,7 @@ xtc_result xtc_graph_get_port(const xtc_graph *graph, size_t node_id, size_t por
type = graph->nodes[node_id].type;
if (port_id > 1U ||
(port_id == 0U && (type == XTC_NODE_OSCILLATOR || type == XTC_NODE_AUDIO || type == XTC_NODE_INSTRUMENT ||
(type == XTC_NODE_PLUGIN && !graph->nodes[node_id].plugin.inputs) ||
(type == XTC_NODE_NATIVE && graph->nodes[node_id].native.kind != XTC_NATIVE_EFFECT))) ||
(port_id == 1U && type == XTC_NODE_OUTPUT))
return XTC_ERR_NOT_FOUND;
@ -417,6 +418,27 @@ static xtc_result disconnect_ports(xtc_graph *graph, const xtc_connection_info *
return XTC_ERR_NOT_FOUND;
}
/* Independent control-thread model copy; no plugin code is loaded. */
xtc_result xtc_graph_clone(const xtc_graph *source, xtc_graph **out)
{
xtc_graph *graph;
xtc_result result;
if (!out) return XTC_ERR_INVALID_ARGUMENT;
*out = NULL;
if (!source) return XTC_ERR_INVALID_ARGUMENT;
result = xtc_graph_create(source->max_nodes, &graph);
if (result != XTC_OK)
return result;
graph->node_count = source->node_count;
graph->edge_count = source->edge_count;
graph->next_id = source->next_id;
graph->require_output_nodes = source->require_output_nodes;
memcpy(graph->nodes, source->nodes, source->node_count * sizeof(*graph->nodes));
memcpy(graph->edges, source->edges, source->edge_count * sizeof(*graph->edges));
*out = graph;
return XTC_OK;
}
/**
* @brief Applies an edit to a new graph copy, leaving the source unchanged.
*
@ -437,15 +459,8 @@ xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *e
*out_graph = NULL;
if (source == NULL || edit == NULL)
return XTC_ERR_INVALID_ARGUMENT;
result = xtc_graph_create(source->max_nodes, &graph);
if (result != XTC_OK)
return result;
graph->node_count = source->node_count;
graph->edge_count = source->edge_count;
graph->next_id = source->next_id;
graph->require_output_nodes = source->require_output_nodes;
memcpy(graph->nodes, source->nodes, source->node_count * sizeof(*graph->nodes));
memcpy(graph->edges, source->edges, source->edge_count * sizeof(*graph->edges));
result = xtc_graph_clone(source,&graph);
if (result != XTC_OK) return result;
switch (edit->kind) {
case XTC_EDIT_ADD_NODE:
switch (edit->data.add.type) {
@ -540,3 +555,36 @@ xtc_result xtc_graph_get_native(const xtc_graph *graph, size_t id, xtc_native_de
*out = graph->nodes[i].native;
return XTC_OK;
}
xtc_result xtc_graph_add_plugin(xtc_graph *g, const xtc_plugin_spec *s, size_t *id)
{
xtc_result r = xtc_plugin_spec_validate(s);
if (r != XTC_OK) return r;
r = add_node(g,XTC_NODE_PLUGIN,0,id);
if (r == XTC_OK) g->nodes[g->node_count-1].plugin = *s;
return r;
}
xtc_result xtc_graph_get_plugin(const xtc_graph *g, size_t id, xtc_plugin_spec *out)
{
size_t i;
if (!g || !out) return XTC_ERR_INVALID_ARGUMENT;
i = node_index(g,id);
if (i == SIZE_MAX) return XTC_ERR_NOT_FOUND;
if (g->nodes[i].type != XTC_NODE_PLUGIN) return XTC_ERR_INVALID_ARGUMENT;
*out = g->nodes[i].plugin; return XTC_OK;
}
xtc_result xtc_graph_set_plugin(xtc_graph *g, size_t id, const xtc_plugin_spec *s)
{
size_t i;
xtc_result r = xtc_plugin_spec_validate(s);
if (!g || r != XTC_OK) return XTC_ERR_INVALID_ARGUMENT;
i = node_index(g,id);
if (i == SIZE_MAX) return XTC_ERR_NOT_FOUND;
if (g->nodes[i].type != XTC_NODE_PLUGIN) return XTC_ERR_INVALID_ARGUMENT;
/* Parameter edits cannot replace identity/layout or invalidate wiring. */
if (strcmp(s->path,g->nodes[i].plugin.path) || strcmp(s->label,g->nodes[i].plugin.label) ||
s->index != g->nodes[i].plugin.index || s->unique_id != g->nodes[i].plugin.unique_id ||
s->inputs != g->nodes[i].plugin.inputs || s->control_count != g->nodes[i].plugin.control_count ||
memcmp(s->ports,g->nodes[i].plugin.ports,s->control_count*sizeof(*s->ports))) return XTC_ERR_UNSUPPORTED;
g->nodes[i].plugin = *s; return XTC_OK;
}

View file

@ -3,6 +3,7 @@
#include "xtc/xtc_engine.h"
#include "xtc/xtc_native.h"
#include "xtc/xtc_plugin.h"
#define XTC_MAX_NODES 256U
#define XTC_MAX_FRAMES 65536U
@ -12,6 +13,7 @@ typedef struct {
float value;
size_t id;
xtc_native_descriptor native;
xtc_plugin_spec plugin;
} xtc_node;
typedef struct {