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

@ -11,9 +11,20 @@ extern "C" {
typedef struct xtc_app xtc_app;
/* Creates an application context. On success, *out_app is caller-owned. */
/**
* @brief Allocates an application handle.
*
* @param out_app Receives the newly allocated app; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_app_create(xtc_app **out_app);
/* Destroys an application context; NULL is accepted. */
/**
* @brief Releases an application handle; accepts NULL.
*
* @param app Application handle.
*/
void xtc_app_destroy(xtc_app *app);
#ifdef __cplusplus

View file

@ -14,21 +14,78 @@ typedef struct xtc_recorder xtc_recorder;
* mono, 1..768000 Hz. Absolute canonical references, <=511 bytes.
* Adds a timeline source -> output route if no timeline source exists.
* Transactional; track must exist. Duration rounds up to a musical tick. */
/**
* @brief Imports a WAV reference as a clip and ensures a timeline output route exists.
*
* @param project Project model; borrowed for this call.
* @param track Stable track identifier.
* @param path NUL-terminated file or asset path.
* @param start_tick Start position in musical ticks.
* @param out_clip Receives the clip.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_import_audio(xtc_project *project, uint64_t track, const char *path, uint64_t start_tick,
uint64_t *out_clip);
/* Empty path makes a region silent; nonempty path must be absolute. Does not
* open the file. Missing references survive save/load for later relinking. */
/**
* @brief Sets an absolute audio asset reference, or clears it to make a region silent.
*
* @param project Project model; borrowed for this call.
* @param clip Stable clip identifier.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_clip_asset(xtc_project *project, uint64_t clip, const char *path);
/* Immutable/preloaded plan. At most 64 distinct assets, 16M mono frames/asset,
* 64M total frames, 256 MiB file and 4096 chunk input limits. Missing/invalid assets become silence with explicit
* issues. OOM/capacity fails creation. No file access during render. */
/**
* @brief Preloads audio assets and compiles an immutable arrangement snapshot for rendering.
*
* @param project Project model; borrowed for this call.
* @param rate Sample rate in hertz.
* @param out_plan Receives the newly allocated plan; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_audio_plan_create(const xtc_project *project, unsigned int rate, xtc_audio_plan **out_plan);
/**
* @brief Releases preloaded samples and arrangement state; accepts NULL.
*
* @param plan Preloaded arrangement plan.
*/
void xtc_audio_plan_destroy(xtc_audio_plan *plan);
/**
* @brief Returns the number of asset issues and optionally the first affected path.
*
* @param plan Preloaded arrangement plan.
* @param out_first_path Receives the first path.
* @return Number of unique asset issues; zero for a NULL plan.
*/
size_t xtc_audio_plan_issues(const xtc_audio_plan *plan, const char **out_first_path);
/* Single consumer; output replaced with overlap-summed mono at unity gain.
* Linear rate conversion, no time stretching. Output must have frames floats. */
/* Stereo outputs must be distinct; NULL right selects mono gain-only rendering. */
xtc_result xtc_audio_plan_render_stereo(const xtc_audio_plan *, uint64_t, float *left, float *right, size_t);
/**
* @brief Replaces output with the overlap-summed timeline mix, applying track gain and pan.
*
* @param plan Preloaded arrangement plan.
* @param position Absolute sample position at the start of the block.
* @param left Destination left-channel buffer.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_audio_plan_render_stereo(const xtc_audio_plan * plan, uint64_t position, float *left, float *right, size_t frames);
/**
* @brief Renders the timeline to a mono output buffer using track gain without pan.
*
* @param plan Preloaded arrangement plan.
* @param position Absolute sample position at the start of the block.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position, float *output, size_t frames);
/* Control-thread creation opens a same-directory temporary float32 WAV.
* Ring capacity 1..2097152 frames. One callback producer, one control consumer.
@ -37,11 +94,51 @@ xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position,
* drains, finalizes and atomically renames even on overflow (partial recovery).
* No source/recorder is freed until destroy, which also removes unfinished temp.
* Counts and sticky error can be observed while producing. */
/**
* @brief Allocates a bounded recording ring and opens a temporary mono float32 WAV file.
*
* @param path NUL-terminated file or asset path.
* @param rate Sample rate in hertz.
* @param capacity Recording ring capacity in frames, from 1 to 2097152.
* @param out_recorder Receives the newly allocated recorder; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_recorder_create(const char *path, unsigned int rate, size_t capacity, xtc_recorder **out_recorder);
/**
* @brief Enqueues an entire audio block without blocking; overflow sets a sticky error.
*
* @param recorder Recorder handle.
* @param input Borrowed input sample buffer.
* @param frames Number of audio frames.
*/
void xtc_recorder_push(xtc_recorder *recorder, const float *input, size_t frames);
/**
* @brief Writes queued samples to the temporary WAV file on the control thread.
*
* @param recorder Recorder handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_recorder_drain(xtc_recorder *recorder);
/**
* @brief Drains and finalizes the WAV file, then renames it after producer quiescence.
*
* @param recorder Recorder handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_recorder_finish(xtc_recorder *recorder);
/**
* @brief Copies the number of accepted frames and returns the sticky recording status.
*
* @param recorder Recorder handle.
* @param out_frames Receives the frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_recorder_status(const xtc_recorder *recorder, uint64_t *out_frames);
/**
* @brief Releases recorder storage and removes any unfinished temporary file; accepts NULL.
*
* @param recorder Recorder handle.
*/
void xtc_recorder_destroy(xtc_recorder *recorder);
#ifdef __cplusplus

View file

@ -44,46 +44,178 @@ typedef struct {
* Returns IO if server/client setup fails. On failure *out_backend is NULL,
* except if cleanup itself fails: a non-NULL handle must be closed/retried;
* only close is permitted on that partially initialized handle. */
/**
* @brief Opens a JACK client and registers its ports without starting the server or connecting routes.
*
* @param config Backend kind, client name, block capacity, and output channel configuration.
* @param out_backend Receives the newly allocated backend; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_open(const xtc_backend_config *config, xtc_backend **out_backend);
/* Stop/close establish callback quiescence before state can be destroyed.
* On failure the handle remains owned by caller; retry close. NULL close OK. */
/**
* @brief Quiesces callbacks and releases the backend; failed cleanup leaves the handle owned by the caller.
*
* @param backend Backend handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_close(xtc_backend *backend);
/**
* @brief Activates the backend and enables audio processing.
*
* @param backend Backend handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_start(xtc_backend *backend);
/**
* @brief Deactivates the backend and establishes callback quiescence.
*
* @param backend Backend handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_stop(xtc_backend *backend);
/* Stopped only; changes transport clock, not oscillator phase. */
/**
* @brief Changes the stopped backend's sample position and resets MIDI voices.
*
* @param backend Backend handle.
* @param sample Absolute sample position.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_seek(xtc_backend *backend, uint64_t sample);
/* 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. */
/**
* @brief Compiles and submits a graph while preserving the previous engine on failure.
*
* @param backend Backend handle.
* @param graph Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_submit(xtc_backend *backend, const xtc_graph *graph);
/* Stopped only. Preloads immutable audio and submits graph before committing.
* Asset issues are silent and reported in status/asset_issue. Other failures
* retain the previous plans. Arrangement edits are adopted on the next prepare. */
/**
* @brief Preloads project audio and MIDI and submits its graph while stopped.
*
* @param backend Backend handle.
* @param project Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_prepare_project(xtc_backend *backend, const xtc_project *project);
/**
* @brief Returns the first asset issue path, or an empty string when none is available.
*
* @param backend Backend handle.
* @return Borrowed path string, or an empty string if no issue is available.
*/
const char *xtc_backend_asset_issue(const xtc_backend *backend);
/* Borrowed recorder, set/detach only while stopped. Stop before finish/destroy. */
/* Control-thread panic is delivered at a block boundary via lock-free counter.
* Stops, seeks, xruns and event overflow also clear instrument voices. */
/**
* @brief Requests an instrument panic at the next audio block boundary.
*
* @param backend Backend handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_panic(xtc_backend *backend);
/**
* @brief Returns the borrowed name of the backend's MIDI input port.
*
* @param backend Backend handle.
* @param out_name Receives the name.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_midi_port_name(const xtc_backend *backend, const char **out_name);
/**
* @brief Attaches or detaches a borrowed recorder while the backend is stopped.
*
* @param backend Backend handle.
* @param recorder Recorder handle.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_set_recorder(xtc_backend *backend, xtc_recorder *recorder);
/**
* @brief Reclaims retired realtime plans on the control thread.
*
* @param backend Backend handle.
*/
void xtc_backend_collect(xtc_backend *backend);
/* Snapshot fields are individually coherent, not a transactional snapshot. */
/**
* @brief Copies individually coherent backend counters and transport state.
*
* @param backend Backend handle.
* @param out_status Receives the status.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_get_status(const xtc_backend *backend, xtc_backend_status *out_status);
/* Borrowed names valid until close. Direction is the client's own port. */
/* Output channel 0 is legacy output, channel 1 is output_right in stereo. */
xtc_result xtc_backend_output_name(const xtc_backend *, size_t channel, const char **out_name);
/**
* @brief Returns the borrowed name of an output channel port.
*
* @param backend Backend handle.
* @param channel Output channel index: 0 for primary, 1 for stereo right.
* @param out_name Receives the name.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_output_name(const xtc_backend * backend, size_t channel, const char **out_name);
/**
* @brief Returns the borrowed name of the mono input or primary output port.
*
* @param backend Backend handle.
* @param direction Local port direction.
* @param out_name Receives the name.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_port_name(const xtc_backend *backend, xtc_port_direction direction, const char **out_name);
/* Enumerates available mono audio ports (devices and software routes). Visitor
* receives a borrowed name valid only during call; return nonzero to stop.
* Control-thread only. JACK NULL list means no matching ports. */
/**
* @brief Inspects one available audio port during control-thread enumeration.
*
* @param name Borrowed port name, valid only during this callback.
* @param context Opaque pointer supplied to xtc_backend_visit_ports().
* @return Nonzero to stop enumeration, zero to continue.
*/
typedef int (*xtc_backend_port_visitor)(const char *name, void *context);
/**
* @brief Visits available audio ports matching the requested direction until the visitor stops.
*
* @param backend Backend handle.
* @param direction Local port direction.
* @param visitor Visitor called with each borrowed port name.
* @param context Opaque callback context.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_visit_ports(xtc_backend *backend, xtc_port_direction direction, xtc_backend_port_visitor visitor,
void *context);
/* Connect/disconnect this client's port with a remote opposite-direction port.
* own_direction INPUT receives remote output; OUTPUT sends to remote input.
* Explicit user choice only; no automatic physical routing. */
/**
* @brief Connects this client's port to a remote port with the opposite direction.
*
* @param backend Backend handle.
* @param own_direction Local port direction.
* @param remote_name Borrowed remote port name.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_connect(xtc_backend *backend, xtc_port_direction own_direction, const char *remote_name);
/**
* @brief Disconnects this client's port from a remote port.
*
* @param backend Backend handle.
* @param own_direction Local port direction.
* @param remote_name Borrowed remote port name.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_backend_disconnect(xtc_backend *backend, xtc_port_direction own_direction, const char *remote_name);
#ifdef __cplusplus

View file

@ -81,35 +81,172 @@ typedef struct {
/* Read-only snapshots; indexes enumerate dense lists, distinct from stable IDs.
* No borrowed pointers into graph storage are exposed. */
/**
* @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);
/**
* @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);
/**
* @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);
/* Set required=1 for explicit output nodes only (none means silence).
* Default 0 retains terminal-node fallback for original offline callers. */
/**
* @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);
/* 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. */
/**
* @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);
/**
* @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);
/**
* @brief Releases graph storage; accepts NULL.
*
* @param graph Graph model; borrowed for this call.
*/
void xtc_graph_destroy(xtc_graph *graph);
/**
* @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);
/**
* @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);
/* Port 0 is input; port 1 is output. Oscillators, audio sources and instruments have only output 1;
* output nodes have only input 0. All ports carry mono audio. */
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
/* Compile copies graph state; caller owns the plan. Sample rate must be
* finite and positive, oscillator frequencies <= Nyquist. max_frames: 1..65536.
* Editing/destroying the graph never changes an existing plan. */
/**
* @brief Allocates an independent execution plan with preallocated processing buffers.
*
* @param graph Graph model; borrowed for this call.
* @param sample_rate Sample rate in hertz.
* @param max_frames Maximum frames per processing block.
* @param out_plan Receives the newly allocated plan; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t max_frames, xtc_plan **out_plan);
/**
* @brief Releases a compiled plan and its processing state; accepts NULL.
*
* @param plan Compiled graph plan and its single-owner runtime state.
*/
void xtc_plan_destroy(xtc_plan *plan);
/* Single processing owner, no concurrent calls (including meter reads/reset).
* No allocation, I/O, locking or graph validation. NULL input means silence.
@ -122,22 +259,96 @@ void xtc_plan_destroy(xtc_plan *plan);
/* Stereo graph with paired source buffers and a mono external input duplicated
* to both sides. Output buffers must be distinct and must not alias sources.
* Stereo oscillator phase advances once per frame. NULL right selects mono. */
xtc_result xtc_plan_process_stereo(xtc_plan *, const float *input, const float *audio_left, const float *audio_right,
/**
* @brief Processes a block with separate stereo timeline and instrument sources.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param audio_left Borrowed left timeline source buffer; NULL means silence.
* @param audio_right Borrowed right timeline source buffer; NULL means silence.
* @param midi_left Borrowed left instrument source buffer; NULL means silence.
* @param midi_right Borrowed right instrument source buffer; NULL means silence.
* @param left Destination left-channel buffer.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_stereo(xtc_plan * plan, const float *input, const float *audio_left, const float *audio_right,
const float *midi_left, const float *midi_right, float *left, float *right,
size_t frames);
/**
* @brief Processes a mono block with separate timeline and instrument sources.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param instrument Borrowed instrument source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_sources(xtc_plan *plan, const float *input, const float *timeline, const float *instrument,
float *output, size_t frames);
/* timeline is a separate mono input for XTC_NODE_AUDIO, NULL means silence. */
/**
* @brief Processes a mono block with timeline audio and no instrument source.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_audio(xtc_plan *plan, const float *input, const float *timeline, float *output,
size_t frames);
/**
* @brief Processes a mono block with external input and no timeline or instrument sources.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frame_count Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process(xtc_plan *plan, const float *input, float *output, size_t frame_count);
/* Resets oscillator phases and meters, without allocation. */
/**
* @brief Resets oscillator phases, meters, and native processor state without allocating.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_reset(xtc_plan *plan);
/* Last block absolute peak, valid for meter nodes only. */
/**
* @brief Copies the last block's absolute peak for a meter node.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param node_id Stable node identifier.
* @param out_peak Receives the peak.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_meter_peak(const xtc_plan *plan, size_t node_id, float *out_peak);
/**
* @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);
/* Allocating compatibility helper: compiles at 48000 Hz and processes once.
* Requires non-NULL input/output and finite input_gain. Not for callbacks. */
/**
* @brief Compiles at 48000 Hz, applies input gain, renders once, and releases temporary state.
*
* @param graph Graph model; borrowed for this call.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frame_count Number of audio frames.
* @param input_gain Finite linear gain applied to external input before processing.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_process_offline(xtc_graph *graph, const float *input, float *output, size_t frame_count,
float input_gain);

View file

@ -32,36 +32,149 @@ typedef struct xtc_midi_plan xtc_midi_plan;
/* Control-thread model APIs, stable note IDs; deletion cascades from clips/tracks.
* MIDI clips cannot reference audio. Creation transactionally adds an instrument
* source -> output route if no instrument exists. Other clip edits stay shared. */
/**
* @brief Adds a MIDI clip and ensures an instrument output route exists.
*
* @param project Project model; borrowed for this call.
* @param track Stable track identifier.
* @param start Start position in musical ticks.
* @param length Duration in musical ticks.
* @param out_id Receives the id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_midi_clip(xtc_project *project, uint64_t track, uint64_t start, uint64_t length,
uint64_t *out_id);
/**
* @brief Copies the number of notes in the project.
*
* @param project Project model; borrowed for this call.
* @param out_count Receives the count.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_note_count(const xtc_project *project, size_t *out_count);
/**
* @brief Copies a note snapshot selected by dense list index.
*
* @param project Project model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param out_note Receives the note.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_note(const xtc_project *project, size_t index, xtc_note_info *out_note);
/**
* @brief Adds a validated MIDI note with a new stable identifier.
*
* @param project Project model; borrowed for this call.
* @param clip Stable clip identifier.
* @param start Start position in musical ticks.
* @param length Duration in musical ticks.
* @param pitch MIDI note number, 0 to 127.
* @param velocity MIDI note velocity, 1 to 127.
* @param channel MIDI channel, 0 to 15.
* @param out_id Receives the id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_note(xtc_project *project, uint64_t clip, uint64_t start, uint64_t length,
unsigned int pitch, unsigned int velocity, unsigned int channel, uint64_t *out_id);
/**
* @brief Replaces a note's source range, pitch, velocity, and channel after validation.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param start Start position in musical ticks.
* @param length Duration in musical ticks.
* @param pitch MIDI note number, 0 to 127.
* @param velocity MIDI note velocity, 1 to 127.
* @param channel MIDI channel, 0 to 15.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_edit_note(xtc_project *project, uint64_t id, uint64_t start, uint64_t length, unsigned int pitch,
unsigned int velocity, unsigned int channel);
/**
* @brief Removes a note selected by stable identifier.
*
* @param project Project 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.
*/
xtc_result xtc_project_remove_note(xtc_project *project, uint64_t id);
/* Complete 3-byte note on/off and CC120/123 only. Velocity-zero on -> off.
* Unsupported messages return UNSUPPORTED; malformed supported messages INVALID.
* Output unchanged on error. No running-status/SysEx/pedal/program/bend support. */
/**
* @brief Decodes a complete note or all-notes-off MIDI message into a block event.
*
* @param bytes Borrowed MIDI message bytes.
* @param size Number of message bytes.
* @param offset Sample offset within the current block.
* @param out_event Receives the event.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_midi_decode(const unsigned char *bytes, size_t size, unsigned int offset, xtc_midi_event *out_event);
/* Control-thread compile; immutable ranges plus exclusively audio-owned runtime.
* Rejects >32 simultaneous scheduled notes. Separate 32 live voices steal oldest.
* Constant-tempo sine instrument, velocity *0.1, above-Nyquist notes silent. */
/**
* @brief Compiles scheduled notes and mixer state into a bounded sine-instrument plan.
*
* @param project Project model; borrowed for this call.
* @param sample_rate Sample rate in hertz.
* @param out_plan Receives the newly allocated plan; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_midi_plan_create(const xtc_project *project, unsigned int sample_rate, xtc_midi_plan **out_plan);
/**
* @brief Releases scheduled notes and instrument state; accepts NULL.
*
* @param plan Instrument plan and its single-owner runtime state.
*/
void xtc_midi_plan_destroy(xtc_midi_plan *plan);
/* Audio owner or stopped only. Reset clears live notes and panic suppression.
* Panic silences live notes and scheduled notes already started at position;
* later scheduled notes can start. MIDI CC120/123 affects its own channel. */
/**
* @brief Clears live voices, scheduling continuity, and panic suppression.
*
* @param plan Instrument plan and its single-owner runtime state.
*/
void xtc_midi_plan_reset(xtc_midi_plan *plan);
/**
* @brief Silences live voices and suppresses scheduled notes already started at the given position.
*
* @param plan Instrument plan and its single-owner runtime state.
* @param position Absolute sample position at the start of the block.
*/
void xtc_midi_plan_panic(xtc_midi_plan *plan, uint64_t position);
/* No allocation, I/O, locks or GUI. Events sorted by offset, equal offsets retain
* caller order, count<=256, frames<=65536. Invalid input leaves state/output alone.
* Renders [position,position+frames); discontinuity clears live voices, chases
* scheduled notes at their correct phase. Note-off is immediate (no envelope). */
/* Distinct stereo outputs; NULL right retains mono (gain only). */
xtc_result xtc_midi_plan_render_stereo(xtc_midi_plan *, uint64_t, const xtc_midi_event *, size_t, float *left,
float *right, size_t);
/**
* @brief Renders scheduled and live MIDI with sample-offset events and track gain and pan.
*
* @param p Instrument plan and its single-owner runtime state.
* @param position Absolute sample position at the start of the block.
* @param events Borrowed MIDI events sorted by sample offset.
* @param count Number of MIDI events.
* @param left Destination left-channel buffer.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_midi_plan_render_stereo(xtc_midi_plan * p, uint64_t position, const xtc_midi_event * events, size_t count, float *left,
float *right, size_t frames);
/**
* @brief Renders scheduled and live MIDI to mono without stereo pan attenuation.
*
* @param plan Instrument plan and its single-owner runtime state.
* @param position Absolute sample position at the start of the block.
* @param events Borrowed MIDI events sorted by sample offset.
* @param count Number of MIDI events.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_midi_plan_render(xtc_midi_plan *plan, uint64_t position, const xtc_midi_event *events, size_t count,
float *output, size_t frames);

View file

@ -25,11 +25,53 @@ typedef struct {
* Linear pan: center unity on both outputs; hard pan attenuates opposite side.
* Automation replaces the corresponding static value, linear between points,
* holds first/last outside the lane. Duplicate track/parameter/tick replaces. */
xtc_result xtc_project_set_mix(xtc_project *, uint64_t track, float gain, float pan, int mute, int solo);
xtc_result xtc_project_set_automation(xtc_project *, const xtc_automation_point *);
xtc_result xtc_project_remove_automation(xtc_project *, uint64_t track, xtc_automation_parameter, uint64_t tick);
xtc_result xtc_project_automation_count(const xtc_project *, size_t *);
xtc_result xtc_project_get_automation(const xtc_project *, size_t, xtc_automation_point *);
/**
* @brief Sets a track's gain, pan, mute, and solo controls after validation.
*
* @param p Project model; borrowed for this call.
* @param track Stable track identifier.
* @param gain Linear gain, 0 to 4 for track controls.
* @param pan Pan position from -1 (left) to 1 (right).
* @param mute Track mute flag, 0 or 1.
* @param solo Track solo flag, 0 or 1.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_mix(xtc_project * p, uint64_t track, float gain, float pan, int mute, int solo);
/**
* @brief Inserts an automation point, replacing any point at the same track, parameter, and tick.
*
* @param p Project model; borrowed for this call.
* @param a Automation point to read or update.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_automation(xtc_project * p, const xtc_automation_point * a);
/**
* @brief Removes the automation point at the specified track, parameter, and tick.
*
* @param p Project model; borrowed for this call.
* @param track Stable track identifier.
* @param param Automation lane selector.
* @param tick Musical position in ticks.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_remove_automation(xtc_project * p, uint64_t track, xtc_automation_parameter param, uint64_t tick);
/**
* @brief Copies the number of automation points in the project.
*
* @param p Project model; borrowed for this call.
* @param n Receives the item count.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_automation_count(const xtc_project * p, size_t * n);
/**
* @brief Copies an automation point selected by dense list index.
*
* @param p Project model; borrowed for this call.
* @param i Zero-based index in the dense list.
* @param a Automation point to read or update.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_automation(const xtc_project * p, size_t i, xtc_automation_point * a);
/* Control-thread snapshot history; 32 edits plus baseline, no assets/DSP/GUI.
* record clones before changing history; failure retains all history. checkout
* clones adjacent state without moving cursor; accept only after installation.
@ -37,11 +79,45 @@ xtc_result xtc_project_get_automation(const xtc_project *, size_t, xtc_automatio
* Reset by creating a new history for New/Open. */
typedef struct xtc_history xtc_history;
xtc_result xtc_history_create(const xtc_project *, xtc_history **);
void xtc_history_destroy(xtc_history *);
xtc_result xtc_history_record(xtc_history *, const xtc_project *);
xtc_result xtc_history_checkout(const xtc_history *, int redo, xtc_project **);
xtc_result xtc_history_accept(xtc_history *, int redo);
/**
* @brief Creates snapshot history with an independent copy of the initial project.
*
* @param p Project model; borrowed for this call.
* @param out Receives the newly allocated object; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_create(const xtc_project * p, xtc_history ** out);
/**
* @brief Releases all retained snapshots and history storage; accepts NULL.
*
* @param h Snapshot history handle.
*/
void xtc_history_destroy(xtc_history * h);
/**
* @brief Appends a project snapshot, discarding redo states and evicting the oldest state if full.
*
* @param h Snapshot history handle.
* @param p Project model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_record(xtc_history * h, const xtc_project * p);
/**
* @brief Clones the adjacent undo or redo state without moving the history cursor.
*
* @param h Snapshot history handle.
* @param redo Zero for undo, one for redo.
* @param out Receives the newly allocated object; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_checkout(const xtc_history * h, int redo, xtc_project ** out);
/**
* @brief Moves the history cursor after the checked-out project has been installed.
*
* @param h Snapshot history handle.
* @param redo Zero for undo, one for redo.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_history_accept(xtc_history * h, int redo);
#ifdef __cplusplus
}

View file

@ -31,34 +31,110 @@ typedef struct {
char identifier[XTC_NATIVE_ID_BYTES]; /* Nonempty printable ASCII, terminated. */
xtc_native_kind kind;
/* Control thread. On error, any non-NULL *state is destroyed by host. */
/**
* @brief Allocates and prepares plugin state on the control thread.
*
* @param sample_rate Processing rate in hertz.
* @param max_frames Maximum frames per processing block.
* @param parameter Initial processor parameter.
* @param state Receives plugin state; the host destroys non-NULL state even on failure.
* @return XTC_OK on success, or a preparation error.
*/
xtc_result (*prepare)(double sample_rate, size_t max_frames, float parameter, void **state);
/* Single audio owner (or stopped). No allocation/free, I/O, locks or GUI. */
/**
* @brief Resets plugin state without allocation, I/O, locking, or GUI calls.
*
* @param state Plugin state owned exclusively by the audio consumer, or stopped.
*/
void (*reset)(void *state);
/**
* @brief Processes one block without allocation, I/O, locking, or GUI calls.
*
* @param state Plugin state owned exclusively by the audio consumer.
* @param block Borrowed buffers and events; write every output frame, including silence.
* @return XTC_OK on success, or a processing error that makes the host silence the block.
*/
xtc_result (*process)(void *state, const xtc_native_block *block);
/* Control thread after quiescence; must accept NULL. */
/**
* @brief Releases plugin state on the control thread after callback quiescence.
*
* @param state Plugin state to release; must accept NULL.
*/
void (*destroy)(void *state);
} xtc_native_descriptor;
typedef struct xtc_native xtc_native;
/* Descriptors are copied; callback code must remain loaded through destruction.
* Trusted statically linked C code, not a sandbox or stable shared-library ABI. */
xtc_result xtc_native_validate(const xtc_native_descriptor *);
xtc_result xtc_native_create(const xtc_native_descriptor *, double rate, size_t max_frames, float parameter,
/**
* @brief Checks the native descriptor's ABI, identifier, kind, and required callbacks.
*
* @param d Native processor descriptor.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_native_validate(const xtc_native_descriptor * d);
/**
* @brief Copies a native descriptor and prepares a processor instance on the control thread.
*
* @param d Native processor descriptor.
* @param rate Sample rate in hertz.
* @param max_frames Maximum frames per processing block.
* @param parameter Native parameter or automation lane selector, as applicable.
* @param out_processor Receives the newly allocated processor; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_native_create(const xtc_native_descriptor * d, double rate, size_t max_frames, float parameter,
xtc_native **out_processor);
void xtc_native_destroy(xtc_native *);
void xtc_native_reset(xtc_native *);
/**
* @brief Destroys native state and releases the host wrapper; accepts NULL.
*
* @param p Native processor instance.
*/
void xtc_native_destroy(xtc_native * p);
/**
* @brief Resets native state and transport continuity; accepts NULL.
*
* @param p Native processor instance.
*/
void xtc_native_reset(xtc_native * p);
/* Bounded, single-owner, realtime-safe host path (callbacks must obey contract).
* Invalid arguments leave state/output unchanged. Zero frames is a no-op.
* Discontinuity resets before processing. Callback failure silences this block
* and resets the processor. Successful nonfinite output samples become zero. */
xtc_result xtc_native_process(xtc_native *, const xtc_native_block *);
/**
* @brief Processes a bounded native block, resetting on discontinuity and silencing callback failures.
*
* @param p Native processor instance.
* @param b Borrowed processing buffers and block metadata.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_native_process(xtc_native * p, const xtc_native_block * b);
/* Graph accepts effects/sources; creates independent L/R instances on compile.
* For instruments, process events explicitly then feed the existing instrument
* source buffer through xtc_plan_process_sources/stereo. Graph add returns
* UNSUPPORTED for instrument descriptors (no event port in current topology).
* Native graphs are session-only: project save returns UNSUPPORTED. */
xtc_result xtc_graph_add_native(xtc_graph *, const xtc_native_descriptor *, float parameter, size_t *out_id);
xtc_result xtc_graph_get_native(const xtc_graph *, size_t node_id, xtc_native_descriptor *out_descriptor);
/**
* @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 parameter Native parameter or automation lane selector, as applicable.
* @param out_id Receives the id.
* @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 parameter, size_t *out_id);
/**
* @brief Copies the native descriptor of a node selected by stable identifier.
*
* @param graph Graph model; borrowed for this call.
* @param node_id Stable node identifier.
* @param out_descriptor Receives the descriptor.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_get_native(const xtc_graph * graph, size_t node_id, xtc_native_descriptor *out_descriptor);
#ifdef __cplusplus
}

View file

@ -33,39 +33,191 @@ typedef struct {
/* Single control-thread ownership. Names: nonempty UTF-8, <=63 bytes, no ASCII controls.
* IDs are monotonic, never reused, UINT64_MAX reserved. Snapshots are copies. */
/**
* @brief Allocates an empty project with an output-only graph policy and 120 BPM tempo.
*
* @param out_project Receives the newly allocated project; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_create(xtc_project **out_project);
/**
* @brief Releases a project and its graph; accepts NULL.
*
* @param project Project model; borrowed for this call.
*/
void xtc_project_destroy(xtc_project *project);
/**
* @brief Allocates an independent copy of project metadata and its graph.
*
* @param project Project model; borrowed for this call.
* @param out_project Receives the newly allocated project; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_clone(const xtc_project *project, xtc_project **out_project);
/**
* @brief Copies the current track and clip counts.
*
* @param project Project model; borrowed for this call.
* @param out_tracks Receives the tracks.
* @param out_clips Receives the clips.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_counts(const xtc_project *project, size_t *out_tracks, size_t *out_clips);
/**
* @brief Copies a track snapshot selected by dense list index.
*
* @param project Project model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param out_track Receives the track.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_track(const xtc_project *project, size_t index, xtc_track_info *out_track);
/**
* @brief Copies a clip snapshot selected by dense list index.
*
* @param project Project model; borrowed for this call.
* @param index Zero-based index in the dense list.
* @param out_clip Receives the clip.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_get_clip(const xtc_project *project, size_t index, xtc_clip_info *out_clip);
/**
* @brief Copies a clip snapshot selected by stable identifier.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param out_clip Receives the clip.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_find_clip(const xtc_project *project, uint64_t id, xtc_clip_info *out_clip);
/**
* @brief Appends a track with unity gain and a new stable identifier.
*
* @param project Project model; borrowed for this call.
* @param name NUL-terminated name.
* @param out_id Receives the id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_track(xtc_project *project, const char *name, uint64_t *out_id);
/* Removing a track also removes its clips. */
/**
* @brief Removes a track and its clips, notes, and automation.
*
* @param project Project 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.
*/
xtc_result xtc_project_remove_track(xtc_project *project, uint64_t id);
/**
* @brief Appends a silent region on an existing track with a new stable identifier.
*
* @param project Project model; borrowed for this call.
* @param track_id Stable destination track identifier.
* @param name NUL-terminated name.
* @param start_tick Start position in musical ticks.
* @param length_tick Duration in musical ticks.
* @param out_id Receives the id.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_add_clip(xtc_project *project, uint64_t track_id, const char *name, uint64_t start_tick,
uint64_t length_tick, uint64_t *out_id);
/**
* @brief Removes a clip and its notes.
*
* @param project Project 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.
*/
xtc_result xtc_project_remove_clip(xtc_project *project, uint64_t id);
/* Atomic move/trim: source bounds remain unchanged, no destructive edits. */
/**
* @brief Atomically moves or trims a clip within its existing source bounds.
*
* @param project Project model; borrowed for this call.
* @param id Stable identifier of the object to find or edit.
* @param track_id Stable destination track identifier.
* @param start_tick Start position in musical ticks.
* @param length_tick Duration in musical ticks.
* @param offset_tick Offset into the clip source in ticks.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_edit_clip(xtc_project *project, uint64_t id, uint64_t track_id, uint64_t start_tick,
uint64_t length_tick, uint64_t offset_tick);
/* Borrowed opaque graph valid until project mutation/destruction. set_graph
* copies before replacing; max 64 nodes, preserving IDs, edges and output policy. */
/**
* @brief Returns the project's borrowed graph, or NULL for a NULL project.
*
* @param project Project model; borrowed for this call.
* @return Borrowed graph valid until project mutation or destruction, or NULL for NULL.
*/
const xtc_graph *xtc_project_graph(const xtc_project *project);
/**
* @brief Copies and validates a graph before replacing the project's graph.
*
* @param project Project model; borrowed for this call.
* @param graph Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_graph(xtc_project *project, const xtc_graph *graph);
/* Constant tempo in milli-BPM: 20000..300000, default 120000. */
/**
* @brief Returns the constant tempo in milli-BPM, or zero for a NULL project.
*
* @param project Project model; borrowed for this call.
* @return Tempo in milli-BPM, or zero for NULL.
*/
unsigned int xtc_project_tempo(const xtc_project *project);
/**
* @brief Sets the constant tempo within the range 20000 to 300000 milli-BPM.
*
* @param project Project model; borrowed for this call.
* @param milli_bpm Tempo in thousandths of a beat per minute.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_set_tempo(xtc_project *project, unsigned int milli_bpm);
/* Floor conversion, no accumulated drift. Rate: 1..768000. Tick <= MAX_TICK.
* Excess sample/tick positions return capacity; outputs unchanged on error. */
/**
* @brief Converts a musical tick to an absolute sample position, rounding down.
*
* @param project Project model; borrowed for this call.
* @param tick Musical position in ticks.
* @param sample_rate Sample rate in hertz.
* @param out_sample Receives the sample.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_tick_to_sample(const xtc_project *project, uint64_t tick, unsigned int sample_rate,
uint64_t *out_sample);
/**
* @brief Converts an absolute sample position to a musical tick, rounding down.
*
* @param project Project model; borrowed for this call.
* @param sample Absolute sample position.
* @param sample_rate Sample rate in hertz.
* @param out_tick Receives the tick.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_sample_to_tick(const xtc_project *project, uint64_t sample, unsigned int sample_rate,
uint64_t *out_tick);
/* Control-thread I/O. Versioned, bounded format; see docs/PROJECT_FORMAT.md.
* Load is transactional. Save fsyncs a same-directory temporary and renames it;
* failures before rename preserve the previous destination. No asset I/O. */
/**
* @brief Saves a versioned project through a synced temporary file and atomic rename.
*
* @param project Project model; borrowed for this call.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_save(const xtc_project *project, const char *path);
/**
* @brief Loads and validates a project before transactionally replacing the current state.
*
* @param project Project model; borrowed for this call.
* @param path NUL-terminated file or asset path.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_project_load(xtc_project *project, const char *path);
#ifdef __cplusplus

View file

@ -18,27 +18,103 @@ typedef struct {
/* Control thread only. A single control producer and single audio consumer.
* C99 with GCC/Clang lock-free __atomic builtins is required; unsupported
* targets return XTC_ERR_UNSUPPORTED. No ownership is shared with callers. */
/**
* @brief Allocates the single-producer, single-consumer realtime engine.
*
* @param sample_rate Sample rate in hertz.
* @param max_frames Maximum frames per processing block.
* @param out_engine Receives the newly allocated engine; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_create(double sample_rate, size_t max_frames, xtc_realtime **out_engine);
/* Requires the audio consumer to have stopped and joined. */
/**
* @brief Releases the engine after the audio consumer has stopped; accepts NULL.
*
* @param engine Realtime engine handle.
*/
void xtc_realtime_destroy(xtc_realtime *engine);
/* Compiles/copies a graph. One pending plan allowed; full mailbox returns
* XTC_ERR_CAPACITY without changing the active or pending plan. */
/**
* @brief Compiles and publishes a graph to the single pending-plan slot.
*
* @param engine Realtime engine handle.
* @param graph Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_submit(xtc_realtime *engine, const xtc_graph *graph);
/* Frees acknowledged retired state, never the audio thread's active plan. */
/**
* @brief Frees acknowledged retired plans on the control thread.
*
* @param engine Realtime engine handle.
*/
void xtc_realtime_collect(xtc_realtime *engine);
/**
* @brief Copies processing counters, plan revisions, and the last processing result.
*
* @param engine Realtime engine handle.
* @param out_status Receives the status.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_get_status(const xtc_realtime *engine, xtc_realtime_status *out_status);
/* Audio consumer only. Adopts at most one plan per block, without allocation,
* freeing, locks or I/O. No plan means silence. On failure writes silence.
* frame_count must be <= configured max_frames and output must hold it.
* Oversized buffers are silenced too; callers must bound their own frame count.
* NULL input means silence. Zero frames is a no-op. */
xtc_result xtc_realtime_process_stereo(xtc_realtime *, const float *input, const float *audio_left,
/**
* @brief Adopts a pending plan and processes stereo sources without allocation or locking.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param audio_left Borrowed left timeline source buffer; NULL means silence.
* @param audio_right Borrowed right timeline source buffer; NULL means silence.
* @param midi_left Borrowed left instrument source buffer; NULL means silence.
* @param midi_right Borrowed right instrument source buffer; NULL means silence.
* @param left Destination left-channel buffer.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_stereo(xtc_realtime * engine, const float *input, const float *audio_left,
const float *audio_right, const float *midi_left, const float *midi_right,
float *left, float *right, size_t frames);
/**
* @brief Processes mono timeline and instrument sources through the realtime engine.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param instrument Borrowed instrument source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_sources(xtc_realtime *engine, const float *input, const float *timeline,
const float *instrument, float *output, size_t frames);
/**
* @brief Processes a mono block with timeline audio and no instrument source.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_audio(xtc_realtime *engine, const float *input, const float *timeline, float *output,
size_t frames);
/**
* @brief Processes a mono block with external input only.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frame_count Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process(xtc_realtime *engine, const float *input, float *output, size_t frame_count);
#ifdef __cplusplus

View file

@ -21,6 +21,12 @@ typedef enum {
XTC_ERR_FORMAT
} xtc_result;
/**
* @brief Returns a short human-readable name for a result code.
*
* @param result Result code to describe.
* @return Borrowed static string; never NULL.
*/
const char *xtc_result_string(xtc_result result);
#ifdef __cplusplus