xtc/include/xtc/xtc_plugin.h

69 lines
3.9 KiB
C

#ifndef XTC_PLUGIN_H
#define XTC_PLUGIN_H
#include "xtc_processor.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XTC_PLUGIN_CONTROLS 16U
#define XTC_PLUGIN_POINTS 32U
/* Absolute project ticks. Mode belongs to segment starting at this point:
* 0 linear, 1 hold/step. Outside a lane hold first/last; later ticks win when
* sample rounding collides. Integer/toggle controls require mode 1. */
typedef struct { uint64_t tick; unsigned int port, step; float value; } xtc_plugin_point;
/* Plain copied model: no library handles or callback pointers. Absolute trusted
* module path, descriptor index + unique ID + label checked again on compile.
* Controls are actual LADSPA port indices, in ascending order. */
typedef struct {
char path[512], label[64];
unsigned int index, unique_id, inputs, control_count;
unsigned int ports[XTC_PLUGIN_CONTROLS];
float values[XTC_PLUGIN_CONTROLS];
unsigned int tempo, point_count; /* milli-BPM, 20000..300000 */
xtc_plugin_point points[XTC_PLUGIN_POINTS];
} xtc_plugin_spec;
/* Copied discovery metadata, never descriptor/module pointers. LADSPA provides
* no standardized units; unit is empty. Flags describe input control hints. */
#define XTC_PLUGIN_INTEGER 1U
#define XTC_PLUGIN_TOGGLED 2U
#define XTC_PLUGIN_LOGARITHMIC 4U
#define XTC_PLUGIN_SAMPLE_RATE 8U
#define XTC_PLUGIN_BOUNDED_BELOW 16U
#define XTC_PLUGIN_BOUNDED_ABOVE 32U
typedef struct {
char name[128], maker[128], copyright[128];
unsigned int hard_realtime;
xtc_parameter_info parameters[XTC_PLUGIN_CONTROLS];
unsigned int flags[XTC_PLUGIN_CONTROLS];
} xtc_plugin_details;
/* Control-thread identity/layout verification and copied human-readable hints. */
xtc_result xtc_plugin_describe(const xtc_plugin_spec *spec, double rate, xtc_plugin_details *out);
/* Reset static values to defaults, removing automation for the chosen port.
* UINT32_MAX resets all controls. Failure leaves spec unchanged. */
xtc_result xtc_plugin_reset(xtc_plugin_spec *spec, double rate, unsigned int port);
/* Replace identity/controls at a stable node ID; only identical audio layouts
* are accepted, preserving all wires. Metadata-only; compile before adoption. */
xtc_result xtc_graph_replace_plugin(xtc_graph *graph, size_t id, const xtc_plugin_spec *spec);
typedef struct xtc_plugin xtc_plugin;
/* Control thread only. Probe explicitly enumerates a file by descriptor index;
* NOT_FOUND means end, UNSUPPORTED means descriptor/layout unsupported. Loading
* trusted libraries can execute arbitrary constructors. Never probe in audio. */
xtc_result xtc_plugin_probe(const char *path, unsigned int index, double rate, xtc_plugin_spec *out);
/* Control-thread parameter names, computed ranges/defaults at this sample rate.
* Output has spec->control_count entries; IDs are LADSPA port indices. */
xtc_result xtc_plugin_parameters(const xtc_plugin_spec *spec, double rate, xtc_parameter_info out[XTC_PLUGIN_CONTROLS]);
/* Metadata-only validation: never opens libraries. */
xtc_result xtc_plugin_spec_validate(const xtc_plugin_spec *spec);
xtc_result xtc_plugin_create(const xtc_plugin_spec *spec, double rate, size_t frames, xtc_plugin **out);
void xtc_plugin_destroy(xtc_plugin *plugin); /* control, after quiescence */
/* Single audio owner. No loading/allocation/I/O in host process; trusted run()
* must obey realtime rules. No MIDI; max one mono input and one mono output.
* Transport reset retains LADSPA delay history (no realtime reset contract). */
xtc_result xtc_plugin_process_at(xtc_plugin *plugin, const float *input, float *output, size_t frames, uint64_t position);
xtc_result xtc_plugin_process(xtc_plugin *plugin, const float *input, float *output, size_t frames);
xtc_result xtc_graph_add_plugin(xtc_graph *graph, const xtc_plugin_spec *spec, size_t *id);
xtc_result xtc_graph_get_plugin(const xtc_graph *graph, size_t id, xtc_plugin_spec *out);
xtc_result xtc_graph_set_plugin(xtc_graph *graph, size_t id, const xtc_plugin_spec *spec);
#ifdef __cplusplus
}
#endif
#endif