1
0
Fork 0
forked from hanez/xtc

Added tons of documentation headers to functions in source files.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:58:27 +01:00
commit 4eb2080933
43 changed files with 3953 additions and 43 deletions

View file

@ -3,6 +3,13 @@
#include <stdlib.h>
#include <string.h>
/**
* @brief Allocates an empty graph with the requested node capacity.
*
* @param max_nodes Maximum number of graph nodes.
* @param out_graph Receives the newly allocated graph; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_create(size_t max_nodes, xtc_graph **out_graph)
{
xtc_graph *graph;
@ -25,6 +32,11 @@ xtc_result xtc_graph_create(size_t max_nodes, xtc_graph **out_graph)
return XTC_OK;
}
/**
* @brief Releases graph storage; accepts NULL.
*
* @param graph Graph model; borrowed for this call.
*/
void xtc_graph_destroy(xtc_graph *graph)
{
if (graph != NULL) {
@ -34,6 +46,13 @@ void xtc_graph_destroy(xtc_graph *graph)
}
}
/**
* @brief Finds a graph's dense node index by stable identifier.
*
* @param graph Graph model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return Dense node index, or SIZE_MAX if absent.
*/
static size_t node_index(const xtc_graph *graph, size_t id)
{
size_t i;
@ -43,6 +62,15 @@ static size_t node_index(const xtc_graph *graph, size_t id)
return SIZE_MAX;
}
/**
* @brief Appends a node after checking type, value, capacity, and identifier availability.
*
* @param graph Graph model; borrowed for this call.
* @param type Node type to create.
* @param value Value to encode, write, or apply.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result add_node(xtc_graph *graph, xtc_node_type type, float value, size_t *out_node_id)
{
if (graph == NULL || out_node_id == NULL || !isfinite(value))
@ -56,11 +84,27 @@ static xtc_result add_node(xtc_graph *graph, xtc_node_type type, float value, si
return XTC_OK;
}
/**
* @brief Adds a gain node with a finite linear gain value.
*
* @param graph Graph model; borrowed for this call.
* @param gain Linear gain, 0 to 4 for track controls.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_gain(xtc_graph *graph, float gain, size_t *out_node_id)
{
return add_node(graph, XTC_NODE_GAIN, gain, out_node_id);
}
/**
* @brief Adds a sine oscillator node with a positive frequency in hertz.
*
* @param graph Graph model; borrowed for this call.
* @param frequency Oscillator frequency in hertz.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_oscillator(xtc_graph *graph, float frequency, size_t *out_node_id)
{
if (frequency < 0.0f)
@ -68,26 +112,63 @@ xtc_result xtc_graph_add_oscillator(xtc_graph *graph, float frequency, size_t *o
return add_node(graph, XTC_NODE_OSCILLATOR, frequency, out_node_id);
}
/**
* @brief Adds a pass-through node that records the last block's absolute peak.
*
* @param graph Graph model; borrowed for this call.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_meter(xtc_graph *graph, size_t *out_node_id)
{
return add_node(graph, XTC_NODE_METER, 0.0f, out_node_id);
}
/**
* @brief Adds a source node for the separately rendered MIDI instrument buffer.
*
* @param graph Graph model; borrowed for this call.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_instrument(xtc_graph *graph, size_t *out_node_id)
{
return add_node(graph, XTC_NODE_INSTRUMENT, 0.0f, out_node_id);
}
/**
* @brief Adds a source node for the separately rendered timeline audio buffer.
*
* @param graph Graph model; borrowed for this call.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_audio(xtc_graph *graph, size_t *out_node_id)
{
return add_node(graph, XTC_NODE_AUDIO, 0.0f, out_node_id);
}
/**
* @brief Adds an explicit output node included in the final mix.
*
* @param graph Graph model; borrowed for this call.
* @param out_node_id Receives the node id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_output(xtc_graph *graph, size_t *out_node_id)
{
return add_node(graph, XTC_NODE_OUTPUT, 0.0f, out_node_id);
}
/**
* @brief Copies the direction, signal type, and channel count of a node port.
*
* @param graph Graph model; borrowed for this call.
* @param node_id Stable node identifier.
* @param port_id Node port identifier.
* @param out_port Receives the port.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_port(const xtc_graph *graph, size_t node_id, size_t port_id, xtc_port_info *out_port)
{
xtc_node_type type;
@ -108,6 +189,13 @@ xtc_result xtc_graph_get_port(const xtc_graph *graph, size_t node_id, size_t por
return XTC_OK;
}
/**
* @brief Validates the graph and writes dense node indexes in topological order.
*
* @param graph Graph model; borrowed for this call.
* @param order Receives dense node indexes in topological order; must hold the graph node count.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_order(const xtc_graph *graph, size_t *order)
{
size_t indegree[XTC_MAX_NODES] = {0U};
@ -132,12 +220,28 @@ xtc_result xtc_graph_order(const xtc_graph *graph, size_t *order)
return tail == graph->node_count ? XTC_OK : XTC_ERR_GRAPH_CYCLE;
}
/**
* @brief Checks graph validity by attempting a topological ordering.
*
* @param graph Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_validate(const xtc_graph *graph)
{
size_t order[XTC_MAX_NODES];
return xtc_graph_order(graph, order);
}
/**
* @brief Adds a validated audio connection while preserving an acyclic graph.
*
* @param graph Graph model; borrowed for this call.
* @param source_node Stable source node identifier.
* @param source_port Source output port identifier.
* @param destination_node Stable destination node identifier.
* @param destination_port Destination input port identifier.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_connect_ports(xtc_graph *graph, size_t source_node, size_t source_port, size_t destination_node,
size_t destination_port)
{
@ -167,11 +271,27 @@ xtc_result xtc_graph_connect_ports(xtc_graph *graph, size_t source_node, size_t
return result;
}
/**
* @brief Connects a source's output port 1 to a destination's input port 0.
*
* @param graph Graph model; borrowed for this call.
* @param source_node Stable source node identifier.
* @param destination_node Stable destination node identifier.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_connect(xtc_graph *graph, size_t source_node, size_t destination_node)
{
return xtc_graph_connect_ports(graph, source_node, 1U, destination_node, 0U);
}
/**
* @brief Copies the graph's node and connection counts.
*
* @param graph Graph model; borrowed for this call.
* @param out_nodes Receives the nodes.
* @param out_connections Receives the connections.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_counts(const xtc_graph *graph, size_t *out_nodes, size_t *out_connections)
{
if (graph == NULL || out_nodes == NULL || out_connections == NULL)
@ -181,6 +301,14 @@ xtc_result xtc_graph_get_counts(const xtc_graph *graph, size_t *out_nodes, size_
return XTC_OK;
}
/**
* @brief Copies node metadata selected by dense list index.
*
* @param graph Graph model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param out_node Receives the node.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_node(const xtc_graph *graph, size_t index, xtc_node_info *out_node)
{
if (graph == NULL || out_node == NULL)
@ -193,6 +321,14 @@ xtc_result xtc_graph_get_node(const xtc_graph *graph, size_t index, xtc_node_inf
return XTC_OK;
}
/**
* @brief Copies connection metadata selected by dense list index.
*
* @param graph Graph model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param out_connection Receives the connection.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_connection(const xtc_graph *graph, size_t index, xtc_connection_info *out_connection)
{
if (graph == NULL || out_connection == NULL)
@ -206,6 +342,13 @@ xtc_result xtc_graph_get_connection(const xtc_graph *graph, size_t index, xtc_co
return XTC_OK;
}
/**
* @brief Sets whether rendering requires explicit output nodes rather than terminal-node fallback.
*
* @param graph Graph model; borrowed for this call.
* @param required One to require explicit output nodes, zero to allow terminal-node fallback.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_require_output_nodes(xtc_graph *graph, int required)
{
if (graph == NULL || (required != 0 && required != 1))
@ -214,6 +357,13 @@ xtc_result xtc_graph_require_output_nodes(xtc_graph *graph, int required)
return XTC_OK;
}
/**
* @brief Removes a node and all connections touching it.
*
* @param graph Graph model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result remove_node(xtc_graph *graph, size_t id)
{
size_t index = node_index(graph, id), i, count = 0U;
@ -235,6 +385,13 @@ static xtc_result remove_node(xtc_graph *graph, size_t id)
return XTC_OK;
}
/**
* @brief Removes the connection matching all source and destination port fields.
*
* @param graph Graph model; borrowed for this call.
* @param connection Connection identifying both node and port pairs.
* @return XTC_OK on success, or an error code describing the failure.
*/
static xtc_result disconnect_ports(xtc_graph *graph, const xtc_connection_info *connection)
{
size_t i;
@ -260,6 +417,15 @@ static xtc_result disconnect_ports(xtc_graph *graph, const xtc_connection_info *
return XTC_ERR_NOT_FOUND;
}
/**
* @brief Applies an edit to a new graph copy, leaving the source unchanged.
*
* @param source Graph model; borrowed for this call.
* @param edit Graph edit command.
* @param out_graph Receives the newly allocated graph; caller owns it on success.
* @param out_added_id Receives the added id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *edit, xtc_graph **out_graph,
size_t *out_added_id)
{
@ -331,6 +497,15 @@ xtc_result xtc_graph_apply_edit(const xtc_graph *source, const xtc_graph_edit *e
return XTC_OK;
}
/**
* @brief Adds a validated native effect or source descriptor to the graph.
*
* @param graph Graph model; borrowed for this call.
* @param descriptor Native processor descriptor.
* @param value Value to encode, write, or apply.
* @param out Receives the operation result.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_add_native(xtc_graph *graph, const xtc_native_descriptor *descriptor, float value, size_t *out)
{
xtc_result result = xtc_native_validate(descriptor);
@ -344,6 +519,14 @@ xtc_result xtc_graph_add_native(xtc_graph *graph, const xtc_native_descriptor *d
return result;
}
/**
* @brief Copies the native descriptor of a node selected by stable identifier.
*
* @param graph Graph model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param out Receives the operation result.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_native(const xtc_graph *graph, size_t id, xtc_native_descriptor *out)
{
size_t i;

View file

@ -26,5 +26,12 @@ struct xtc_graph {
xtc_edge *edges;
};
/**
* @brief Validates the graph and writes dense node indexes in topological order.
*
* @param graph Graph model; borrowed for this call.
* @param order Receives dense node indexes in topological order; must hold the graph node count.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_order(const xtc_graph *graph, size_t *order);
#endif