1
0
Fork 0
forked from hanez/xtc
xtc/include/xtc/xtc_native.h

67 lines
2.9 KiB
C

#ifndef XTC_NATIVE_H
#define XTC_NATIVE_H
#include "xtc_midi.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XTC_NATIVE_ABI_VERSION 1U
#define XTC_NATIVE_ID_BYTES 64U
typedef enum {
XTC_NATIVE_EFFECT = 1,
XTC_NATIVE_SOURCE,
XTC_NATIVE_INSTRUMENT
} xtc_native_kind;
typedef struct {
const float *input; /* NULL is silence; may equal output. Borrowed for call. */
float *output; /* Write every frame, including silence. */
size_t frames;
uint64_t position; /* Absolute sample position, no wall clock. */
const xtc_midi_event *events; /* Instruments only, sorted block offsets. */
size_t event_count;
} xtc_native_block;
typedef struct {
unsigned int abi_version;
size_t struct_size; /* Must equal sizeof(xtc_native_descriptor) for ABI 1. */
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. */
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. */
void (*reset)(void *state);
xtc_result (*process)(void *state, const xtc_native_block *block);
/* Control thread after quiescence; 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,
xtc_native **out_processor);
void xtc_native_destroy(xtc_native *);
void xtc_native_reset(xtc_native *);
/* 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 *);
/* 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);
#ifdef __cplusplus
}
#endif
#endif