clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit aac2f93b97d7302659bc733a7d6e1f874ad3f46e
parent f662d50b3465dc08e692ace433ac5de3e0608681
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon, 20 Sep 2021 14:45:26 +0200

Split clap.h into smaller files

Diffstat:
Ainclude/clap/audio-buffer.h | 21+++++++++++++++++++++
Minclude/clap/clap.h | 239+------------------------------------------------------------------------------
Ainclude/clap/host.h | 38++++++++++++++++++++++++++++++++++++++
Ainclude/clap/plugin.h | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainclude/clap/process.h | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 270 insertions(+), 238 deletions(-)

diff --git a/include/clap/audio-buffer.h b/include/clap/audio-buffer.h @@ -0,0 +1,20 @@ +#pragma once + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct clap_audio_buffer { + // Either data32 or data64 pointer will be set. + float ** data32; + double **data64; + uint32_t channel_count; + uint32_t latency; // latency from/to the audio interface + uint64_t constant_mask; // mask & (1 << N) to test if channel N is constant +} clap_audio_buffer; + +#ifdef __cplusplus +} +#endif +\ No newline at end of file diff --git a/include/clap/clap.h b/include/clap/clap.h @@ -32,241 +32,4 @@ #include "macros.h" #include "version.h" #include "string-sizes.h" -#include "events.h" - -#ifdef __cplusplus -extern "C" { -#endif - -///////////// -// PROCESS // -///////////// - -enum { - // Processing failed. The output buffer must be discarded. - CLAP_PROCESS_ERROR = 0, - - // Processing succeed, keep processing. - CLAP_PROCESS_CONTINUE = 1, - - // Processing succeed, keep processing if the output is not quiet. - CLAP_PROCESS_CONTINUE_IF_NOT_QUIET = 2, - - // Processing succeed, but no more processing is required, - // until next event or variation in audio input. - CLAP_PROCESS_SLEEP = 3, -}; -typedef int32_t clap_process_status; - -typedef struct clap_audio_buffer { - // Either data32 or data64 pointer will be set. - float ** data32; - double **data64; - uint32_t channel_count; - uint32_t latency; // latency from/to the audio interface - uint64_t constant_mask; // mask & (1 << N) to test if channel N is constant -} clap_audio_buffer; - -typedef struct clap_process { - uint64_t steady_time; // a steady sample time counter, requiered - uint32_t frames_count; // number of frame to process - - // time info at sample 0 - // If null, then this is a free running host, no transport events will be provided - const clap_event_transport *transport; - - // Audio buffers, they must have the same count as specified - // by clap_plugin_audio_ports->get_count(). - // The index maps to clap_plugin_audio_ports->get_info(). - // - // If a plugin does not implement clap_plugin_audio_ports, - // then it gets a default stereo input and output. - const clap_audio_buffer *audio_inputs; - const clap_audio_buffer *audio_outputs; - uint32_t audio_inputs_count; - uint32_t audio_outputs_count; - - /* events */ - const clap_event_list *in_events; - const clap_event_list *out_events; -} clap_process; - -////////// -// HOST // -////////// - -typedef struct clap_host { - clap_version clap_version; // initialized to CLAP_VERSION - - void *host_data; // reserved pointer for the host - - // name and version are mandatory. - const char *name; // eg: "Bitwig Studio" - const char *vendor; // eg: "Bitwig GmbH" - const char *url; // eg: "https://bitwig.com" - const char *version; // eg: "3.3.8" - - // Query an extension. - // [thread-safe] - const void *(*get_extension)(const struct clap_host *host, const char *extension_id); - - // Request the host to deactivate and then reactivate the plugin. - // The operation may be delayed by the host. - // [thread-safe] - void (*request_restart)(const struct clap_host *host); - - // Request the host to activate and start processing the plugin. - // This is useful if you have external IO and need to wake up the plugin from "sleep". - // [thread-safe] - void (*request_process)(const struct clap_host *host); -} clap_host; - -//////////// -// PLUGIN // -//////////// - -/* bitfield - * This gives an hint to the host what the plugin might do. */ -enum { - /* Instruments can play notes, and generate audio */ - CLAP_PLUGIN_INSTRUMENT = (1 << 0), - - /* Audio effects, process audio input and produces audio. - * Exemple: delay, reverb, compressor. */ - CLAP_PLUGIN_AUDIO_EFFECT = (1 << 1), - - /* Event effects, takes events as input and produces events. - * Exemple: arpegiator */ - CLAP_PLUGIN_EVENT_EFFECT = (1 << 2), // can be seen as midi effect - - // Analyze audio and/or events. - // If this is the only type reported by the plugin, the host can assume that it wont change the - // audio and event signal. - CLAP_PLUGIN_ANALYZER = (1 << 3), -}; -typedef int32_t clap_plugin_type; - -typedef struct clap_plugin_descriptor { - clap_version clap_version; // initialized to CLAP_VERSION - - const char *id; // eg: "com.u-he.diva" - const char *name; // eg: "Diva" - const char *vendor; // eg: "u-he" - const char *url; // eg: "https://u-he.com/products/diva/" - const char *manual_url; // eg: "https://dl.u-he.com/manuals/plugins/diva/Diva-user-guide.pdf" - const char *support_url; // eg: "https://u-he.com/support/" - const char *version; // eg: "1.4.4" - const char *description; // eg: "The spirit of analogue" - - // Arbitrary list of keywords, separated by `;' - // They can be matched by the host search engine and used to classify the plugin. - // Some examples: - // "master;eq;spectrum" - // "compressor;analog;character" - // "reverb;plate;cathedral" - // "kick;analog;808;roland" - // "analog;character;roland;moog" - // "chip;chiptune;gameboy;nintendo;sega" - const char *keywords; - - uint64_t plugin_type; // bitfield of clap_plugin_type -} clap_plugin_descriptor; - -typedef struct clap_plugin { - const clap_plugin_descriptor *desc; - - void *plugin_data; // reserved pointer for the plugin - - // Must be called after creating the plugin. - // If init returns false, the host must destroy the plugin instance. - bool (*init)(const struct clap_plugin *plugin); - - /* Free the plugin and its resources. - * It is not required to deactivate the plugin prior to this call. */ - void (*destroy)(const struct clap_plugin *plugin); - - /* activation/deactivation - * [main-thread] */ - bool (*activate)(const struct clap_plugin *plugin, double sample_rate); - void (*deactivate)(const struct clap_plugin *plugin); - - // Set to true before processing, and to false before sending the plugin to sleep. - // [audio-thread] - bool (*start_processing)(const struct clap_plugin *plugin); - void (*stop_processing)(const struct clap_plugin *plugin); - - /* process audio, events, ... - * [audio-thread] */ - clap_process_status (*process)(const struct clap_plugin *plugin, const clap_process *process); - - /* Query an extension. - * The returned pointer is owned by the plugin. - * [thread-safe] */ - const void *(*get_extension)(const struct clap_plugin *plugin, const char *id); -} clap_plugin; - -///////////////// -// ENTRY POINT // -///////////////// - -typedef struct clap_plugin_invalidation_source { - // Directory containing the file(s) to scan - const char *directory; - - // globing pattern, in the form *.dll - const char *filename_glob; - - // should the directory be scanned recursively? - bool recursive_scan; -} clap_plugin_invalidation_source; - -// This interface is the entry point of the dynamic library. -// -// There is an invalidation mechanism for the set of plugins which is based on files. -// The host can watch the plugin DSO's mtime and a set of files's mtime provided by -// get_clap_invalidation_source(). -// -// The set of plugins must not change, except during a call to refresh() by the host. -// -// Every methods must be thread-safe. -struct clap_plugin_entry { - clap_version clap_version; // initialized to CLAP_VERSION - - bool (*init)(const char *plugin_path); - void (*deinit)(void); - - /* Get the number of plugins available. - * [thread-safe] */ - uint32_t (*get_plugin_count)(void); - - /* Retrieves a plugin descriptor by its index. - * Returns null in case of error. - * The descriptor does not need to be freed. - * [thread-safe] */ - const clap_plugin_descriptor *(*get_plugin_descriptor)(uint32_t index); - - /* Create a clap_plugin by its plugin_id. - * The returned pointer must be freed by calling plugin->destroy(plugin); - * The plugin is not allowed to use the host callbacks in the create method. - * Returns null in case of error. - * [thread-safe] */ - const clap_plugin *(*create_plugin)(const clap_host *host, const char *plugin_id); - - // Get the number of invalidation sources. - uint32_t (*get_invalidation_sources_count)(void); - - // Get the invalidation source by its index. - // [thread-safe] - const clap_plugin_invalidation_source *(*get_invalidation_sources)(uint32_t index); - - // In case the host detected a invalidation event, it can call refresh() to let the - // plugin_entry scan the set of plugins available. - void (*refresh)(void); -}; - -/* Entry point */ -CLAP_EXPORT extern const struct clap_plugin_entry clap_plugin_entry; - -#ifdef __cplusplus -} -#endif +#include "plugin.h" diff --git a/include/clap/host.h b/include/clap/host.h @@ -0,0 +1,37 @@ +#pragma once + +#include "version.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct clap_host { + clap_version clap_version; // initialized to CLAP_VERSION + + void *host_data; // reserved pointer for the host + + // name and version are mandatory. + const char *name; // eg: "Bitwig Studio" + const char *vendor; // eg: "Bitwig GmbH" + const char *url; // eg: "https://bitwig.com" + const char *version; // eg: "3.3.8" + + // Query an extension. + // [thread-safe] + const void *(*get_extension)(const struct clap_host *host, const char *extension_id); + + // Request the host to deactivate and then reactivate the plugin. + // The operation may be delayed by the host. + // [thread-safe] + void (*request_restart)(const struct clap_host *host); + + // Request the host to activate and start processing the plugin. + // This is useful if you have external IO and need to wake up the plugin from "sleep". + // [thread-safe] + void (*request_process)(const struct clap_host *host); +} clap_host; + +#ifdef __cplusplus +} +#endif +\ No newline at end of file diff --git a/include/clap/plugin.h b/include/clap/plugin.h @@ -0,0 +1,155 @@ +#pragma once + +#include "macros.h" +#include "host.h" +#include "process.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* bitfield + * This gives an hint to the host what the plugin might do. */ +enum { + /* Instruments can play notes, and generate audio */ + CLAP_PLUGIN_INSTRUMENT = (1 << 0), + + /* Audio effects, process audio input and produces audio. + * Exemple: delay, reverb, compressor. */ + CLAP_PLUGIN_AUDIO_EFFECT = (1 << 1), + + /* Event effects, takes events as input and produces events. + * Exemple: arpegiator */ + CLAP_PLUGIN_EVENT_EFFECT = (1 << 2), // can be seen as midi effect + + // Analyze audio and/or events. + // If this is the only type reported by the plugin, the host can assume that it wont change the + // audio and event signal. + CLAP_PLUGIN_ANALYZER = (1 << 3), +}; +typedef int32_t clap_plugin_type; + +typedef struct clap_plugin_descriptor { + clap_version clap_version; // initialized to CLAP_VERSION + + const char *id; // eg: "com.u-he.diva" + const char *name; // eg: "Diva" + const char *vendor; // eg: "u-he" + const char *url; // eg: "https://u-he.com/products/diva/" + const char *manual_url; // eg: "https://dl.u-he.com/manuals/plugins/diva/Diva-user-guide.pdf" + const char *support_url; // eg: "https://u-he.com/support/" + const char *version; // eg: "1.4.4" + const char *description; // eg: "The spirit of analogue" + + // Arbitrary list of keywords, separated by `;' + // They can be matched by the host search engine and used to classify the plugin. + // Some examples: + // "master;eq;spectrum" + // "compressor;analog;character" + // "reverb;plate;cathedral" + // "kick;analog;808;roland" + // "analog;character;roland;moog" + // "chip;chiptune;gameboy;nintendo;sega" + const char *keywords; + + uint64_t plugin_type; // bitfield of clap_plugin_type +} clap_plugin_descriptor; + +typedef struct clap_plugin { + const clap_plugin_descriptor *desc; + + void *plugin_data; // reserved pointer for the plugin + + // Must be called after creating the plugin. + // If init returns false, the host must destroy the plugin instance. + bool (*init)(const struct clap_plugin *plugin); + + /* Free the plugin and its resources. + * It is not required to deactivate the plugin prior to this call. */ + void (*destroy)(const struct clap_plugin *plugin); + + /* activation/deactivation + * [main-thread] */ + bool (*activate)(const struct clap_plugin *plugin, double sample_rate); + void (*deactivate)(const struct clap_plugin *plugin); + + // Set to true before processing, and to false before sending the plugin to sleep. + // [audio-thread] + bool (*start_processing)(const struct clap_plugin *plugin); + void (*stop_processing)(const struct clap_plugin *plugin); + + /* process audio, events, ... + * [audio-thread] */ + clap_process_status (*process)(const struct clap_plugin *plugin, const clap_process *process); + + /* Query an extension. + * The returned pointer is owned by the plugin. + * [thread-safe] */ + const void *(*get_extension)(const struct clap_plugin *plugin, const char *id); +} clap_plugin; + +///////////////// +// ENTRY POINT // +///////////////// + +typedef struct clap_plugin_invalidation_source { + // Directory containing the file(s) to scan + const char *directory; + + // globing pattern, in the form *.dll + const char *filename_glob; + + // should the directory be scanned recursively? + bool recursive_scan; +} clap_plugin_invalidation_source; + +// This interface is the entry point of the dynamic library. +// +// There is an invalidation mechanism for the set of plugins which is based on files. +// The host can watch the plugin DSO's mtime and a set of files's mtime provided by +// get_clap_invalidation_source(). +// +// The set of plugins must not change, except during a call to refresh() by the host. +// +// Every methods must be thread-safe. +struct clap_plugin_entry { + clap_version clap_version; // initialized to CLAP_VERSION + + bool (*init)(const char *plugin_path); + void (*deinit)(void); + + /* Get the number of plugins available. + * [thread-safe] */ + uint32_t (*get_plugin_count)(void); + + /* Retrieves a plugin descriptor by its index. + * Returns null in case of error. + * The descriptor does not need to be freed. + * [thread-safe] */ + const clap_plugin_descriptor *(*get_plugin_descriptor)(uint32_t index); + + /* Create a clap_plugin by its plugin_id. + * The returned pointer must be freed by calling plugin->destroy(plugin); + * The plugin is not allowed to use the host callbacks in the create method. + * Returns null in case of error. + * [thread-safe] */ + const clap_plugin *(*create_plugin)(const clap_host *host, const char *plugin_id); + + // Get the number of invalidation sources. + uint32_t (*get_invalidation_sources_count)(void); + + // Get the invalidation source by its index. + // [thread-safe] + const clap_plugin_invalidation_source *(*get_invalidation_sources)(uint32_t index); + + // In case the host detected a invalidation event, it can call refresh() to let the + // plugin_entry scan the set of plugins available. + void (*refresh)(void); +}; + +/* Entry point */ +CLAP_EXPORT extern const struct clap_plugin_entry clap_plugin_entry; + +#ifdef __cplusplus +} +#endif diff --git a/include/clap/process.h b/include/clap/process.h @@ -0,0 +1,54 @@ +#pragma once + +#include "events.h" +#include "audio-buffer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + // Processing failed. The output buffer must be discarded. + CLAP_PROCESS_ERROR = 0, + + // Processing succeed, keep processing. + CLAP_PROCESS_CONTINUE = 1, + + // Processing succeed, keep processing if the output is not quiet. + CLAP_PROCESS_CONTINUE_IF_NOT_QUIET = 2, + + // Processing succeed, but no more processing is required, + // until next event or variation in audio input. + CLAP_PROCESS_SLEEP = 3, +}; +typedef int32_t clap_process_status; + + + +typedef struct clap_process { + uint64_t steady_time; // a steady sample time counter, requiered + uint32_t frames_count; // number of frame to process + + // time info at sample 0 + // If null, then this is a free running host, no transport events will be provided + const clap_event_transport *transport; + + // Audio buffers, they must have the same count as specified + // by clap_plugin_audio_ports->get_count(). + // The index maps to clap_plugin_audio_ports->get_info(). + // + // If a plugin does not implement clap_plugin_audio_ports, + // then it gets a default stereo input and output. + const clap_audio_buffer *audio_inputs; + const clap_audio_buffer *audio_outputs; + uint32_t audio_inputs_count; + uint32_t audio_outputs_count; + + /* events */ + const clap_event_list *in_events; + const clap_event_list *out_events; +} clap_process; + +#ifdef __cplusplus +} +#endif +\ No newline at end of file