1
0
Fork 0
forked from hanez/xtc

Phase 4: Add modular graph editor and transactional graph edits

This commit is contained in:
Johannes Findeisen 2026-10-26 23:55:35 +01:00
commit 5c41d7f6da
27 changed files with 1023 additions and 64 deletions

View file

@ -18,6 +18,7 @@ typedef struct {
unsigned int buffer_frames;
unsigned int xruns; /* Wraps modulo UINT_MAX + 1. */
unsigned int processed_blocks;
unsigned int submitted_revision, active_revision;
int running;
int server_lost;
int sample_rate_changed; /* Sticky: close/reopen and resubmit to recover. */
@ -36,7 +37,9 @@ xtc_result xtc_backend_open(const xtc_backend_config *config, xtc_backend **out_
xtc_result xtc_backend_close(xtc_backend *backend);
xtc_result xtc_backend_start(xtc_backend *backend);
xtc_result xtc_backend_stop(xtc_backend *backend);
/* Submit allowed stopped or running. Copies graph; capacity = pending slot busy. */
/* Copies graph. While running, capacity means pending slot busy.
* While stopped, transactionally replaces all retained plans (counters/revisions
* restart); failed compilation leaves the previous engine intact. */
xtc_result xtc_backend_submit(xtc_backend *backend, const xtc_graph *graph);
void xtc_backend_collect(xtc_backend *backend);
/* Snapshot fields are individually coherent, not a transactional snapshot. */

View file

@ -42,8 +42,39 @@ typedef struct {
} xtc_port_info;
/* Control-thread API. Limits: 256 nodes, mono audio only. IDs are stable
* insertion indexes. Output parameters are written only on success, except
* create/compile which set their output pointer to NULL on failure. */
* monotonically assigned identifiers; removed IDs are never reused. Output
* parameters are written only on success, except create/compile/apply_edit
* which set their output pointer to NULL on failure. */
typedef struct { size_t id; xtc_node_type type; float value; } xtc_node_info;
typedef struct {
size_t source_node, source_port, destination_node, destination_port;
} xtc_connection_info;
typedef enum {
XTC_EDIT_ADD_NODE = 1, XTC_EDIT_REMOVE_NODE,
XTC_EDIT_CONNECT, XTC_EDIT_DISCONNECT
} xtc_graph_edit_kind;
typedef struct {
xtc_graph_edit_kind kind;
union {
struct { xtc_node_type type; float value; } add;
size_t node_id;
xtc_connection_info connection;
} data;
} xtc_graph_edit;
/* Read-only snapshots; indexes enumerate dense lists, distinct from stable IDs.
* No borrowed pointers into graph storage are exposed. */
xtc_result xtc_graph_get_counts(const xtc_graph *graph, size_t *out_nodes, size_t *out_connections);
xtc_result xtc_graph_get_node(const xtc_graph *graph, size_t index, xtc_node_info *out_node);
xtc_result xtc_graph_get_connection(const xtc_graph *graph, size_t index, xtc_connection_info *out_connection);
/* Set required=1 for explicit output nodes only (none means silence).
* Default 0 retains terminal-node fallback for original offline callers. */
xtc_result xtc_graph_require_output_nodes(xtc_graph *graph, int required);
/* Transactional command: on success caller owns a new graph; source unchanged.
* Failure sets *out_graph=NULL, leaves source and out_added_id unchanged.
* out_added_id is optional and written only for successful ADD_NODE. */
xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *edit,
xtc_graph **out_graph, size_t *out_added_id);
xtc_result xtc_graph_create(size_t max_nodes, xtc_graph **out_graph);
void xtc_graph_destroy(xtc_graph *graph);
xtc_result xtc_graph_add_gain(xtc_graph *graph, float gain, size_t *out_node_id);
@ -70,7 +101,8 @@ void xtc_plan_destroy(xtc_plan *plan);
* No allocation, I/O, locking or graph validation. NULL input means silence.
* output must hold frame_count floats; input may equal output. On invalid
* arguments output and DSP state are unchanged. Zero frames is a no-op.
* Sums explicit output nodes; if absent, sums terminal nodes for compatibility.
* Sums explicit output nodes; if absent, sums terminal nodes for compatibility
* unless require_output_nodes is set. Empty graphs produce silence.
* Unconnected gain/meter/output inputs receive external input. */
xtc_result xtc_plan_process(xtc_plan *plan, const float *input, float *output,
size_t frame_count);

View file

@ -9,6 +9,7 @@ typedef struct xtc_realtime xtc_realtime;
typedef struct {
unsigned int processed_blocks; /* Wraps modulo UINT_MAX + 1. */
xtc_result last_result;
unsigned int submitted_revision, active_revision; /* Wrap like block counter. */
} xtc_realtime_status;
/* Control thread only. A single control producer and single audio consumer.