Phase 23: refine routing inspection, signal-flow layout and atomic wire insertion

This commit is contained in:
Johannes Findeisen 2026-10-27 16:00:29 +01:00
commit ba5c2503a7
15 changed files with 533 additions and 22 deletions

View file

@ -498,6 +498,14 @@ xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *e
case XTC_EDIT_DISCONNECT:
result = disconnect_ports(graph, &edit->data.connection);
break;
case XTC_EDIT_INSERT_GAIN: {
const xtc_connection_info *c = &edit->data.connection;
result = disconnect_ports(graph, c);
if (result == XTC_OK) result = xtc_graph_add_gain(graph, 1.0f, &added_id);
if (result == XTC_OK) result = xtc_graph_connect_ports(graph, c->source_node, c->source_port, added_id, 0);
if (result == XTC_OK) result = xtc_graph_connect_ports(graph, added_id, 1, c->destination_node, c->destination_port);
break;
}
default:
result = XTC_ERR_INVALID_ARGUMENT;
break;
@ -506,7 +514,7 @@ xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *e
xtc_graph_destroy(graph);
return result;
}
if (out_added_id != NULL && edit->kind == XTC_EDIT_ADD_NODE)
if (out_added_id != NULL && (edit->kind == XTC_EDIT_ADD_NODE || edit->kind == XTC_EDIT_INSERT_GAIN))
*out_added_id = added_id;
*out_graph = graph;
return XTC_OK;
@ -588,3 +596,45 @@ xtc_result xtc_graph_set_plugin(xtc_graph *g, size_t id, const xtc_plugin_spec *
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;
}
xtc_result xtc_graph_analyze(const xtc_graph *graph, xtc_routing_info *items, size_t capacity, size_t *count)
{
xtc_routing_info info[XTC_MAX_NODES] = {{0}};
size_t order[XTC_MAX_NODES], i, j;
int explicit_outputs = 0;
xtc_result result;
if (!graph || !count || (!items && graph->node_count)) return XTC_ERR_INVALID_ARGUMENT;
if (capacity < graph->node_count) return XTC_ERR_CAPACITY;
result = xtc_graph_order(graph, order);
if (result != XTC_OK) return result;
for (i = 0; i < graph->node_count; ++i) {
info[i].id = graph->nodes[i].id;
if (graph->nodes[i].type == XTC_NODE_OUTPUT) explicit_outputs = 1;
}
for (i = 0; i < graph->edge_count; ++i) {
++info[graph->edges[i].source].outputs;
++info[graph->edges[i].destination].inputs;
}
for (i = 0; i < graph->node_count; ++i) {
xtc_port_info port;
info[i].external_input = !info[i].inputs && xtc_graph_get_port(graph, info[i].id, 0, &port) == XTC_OK;
info[i].reaches_output = graph->nodes[i].type == XTC_NODE_OUTPUT ||
(!explicit_outputs && !graph->require_output_nodes && !info[i].outputs);
}
for (i = 0; i < graph->node_count; ++i) {
size_t node = order[i];
for (j = 0; j < graph->edge_count; ++j) if (graph->edges[j].source == node) {
size_t destination = graph->edges[j].destination;
if (info[destination].level <= info[node].level) info[destination].level = info[node].level + 1;
}
}
for (i = graph->node_count; i > 0; --i) {
size_t node = order[i-1];
if (info[node].reaches_output)
for (j = 0; j < graph->edge_count; ++j) if (graph->edges[j].destination == node)
info[graph->edges[j].source].reaches_output = 1;
}
if (graph->node_count) memcpy(items, info, graph->node_count * sizeof(*items));
*count = graph->node_count;
return XTC_OK;
}