clap

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

commit 7145a0423c735b3f2af96f2b27a7e29bccaf752a
parent 78394dd926f80c146c3723510c104af978b1cfaa
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Fri, 24 Oct 2014 17:02:27 +0200

Use get_parameter()

Diffstat:
Mexamples/clap-info/clap-info.c | 30+++++++++++++++++++++---------
Mexamples/thyns/plugin.c | 38+++++++++++++++++++++++++++++---------
Minclude/clap/clap.h | 34+++++++++++++++++++---------------
3 files changed, 69 insertions(+), 33 deletions(-)

diff --git a/examples/clap-info/clap-info.c b/examples/clap-info/clap-info.c @@ -62,15 +62,27 @@ int main(int argc, char **argv) continue; } - fprintf(stdout, " id: %s\n", plugin->id); - fprintf(stdout, " name: %s\n", plugin->name); - fprintf(stdout, " description: %s\n", plugin->description); - fprintf(stdout, " manufacturer: %s\n", plugin->manufacturer); - fprintf(stdout, " version: %s\n", plugin->version); - fprintf(stdout, " url: %s\n", plugin->url); - fprintf(stdout, " support: %s\n", plugin->support); - fprintf(stdout, " license: %s\n", plugin->license); - fprintf(stdout, " categories: %s\n", plugin->categories); + char buffer[256]; + +#define print_attr(Attr) \ + do { \ + plugin->get_attribute( \ + plugin, CLAP_ATTR_##Attr, buffer, sizeof (buffer)); \ + fprintf(stdout, " %s: %s\n", CLAP_ATTR_##Attr, buffer); \ + } while (0) + + print_attr(ID); + print_attr(NAME); + print_attr(DESCRIPTION); + print_attr(MANUFACTURER); + print_attr(VERSION); + print_attr(URL); + print_attr(SUPPORT); + print_attr(LICENSE); + print_attr(CATEGORIES); + +#undef print_attr + fprintf(stdout, " type:"); if (plugin->type & CLAP_PLUGIN_INSTRUMENT) fprintf(stdout, " instrument"); diff --git a/examples/thyns/plugin.c b/examples/thyns/plugin.c @@ -23,6 +23,34 @@ thyns_plugin_destroy(struct clap_plugin *plugin) } uint32_t +thyns_plugin_get_attribute(struct clap_plugin *plugin, + const char *attr, + char *buffer, + uint32_t size) +{ +#define attr(Attr, Value) \ + do { \ + if (!strcmp(Attr, attr)) { \ + snprintf(buffer, size, "%s", Value); \ + return sizeof (Value) - 1; \ + } \ + } while (0) + + attr(CLAP_ATTR_ID, "clap/thyns"); + attr(CLAP_ATTR_NAME, "Thyns"); + attr(CLAP_ATTR_DESCRIPTION, "Clap demo synth"); + attr(CLAP_ATTR_VERSION, "0.0.1"); + attr(CLAP_ATTR_MANUFACTURER, "Clap"); + attr(CLAP_ATTR_URL, "https://github.com/abique/clap"); + attr(CLAP_ATTR_SUPPORT, "https://github.com/abique/clap"); + attr(CLAP_ATTR_LICENSE, "MIT"); + attr(CLAP_ATTR_CATEGORIES, ""); + return 0; + +#undef attr +} + +uint32_t thyns_plugin_get_ports_configs_count(struct clap_plugin *plugin) { return 1; @@ -190,20 +218,12 @@ thyns_plugin_create(struct clap_host *host, p->plugin.clap_version = CLAP_VERSION; p->plugin.destroy = thyns_plugin_destroy; p->plugin.plugin_data = p; - snprintf(p->plugin.id, sizeof (p->plugin.id), "clap/thyns"); - snprintf(p->plugin.name, sizeof (p->plugin.name), "Thyns"); - snprintf(p->plugin.description, sizeof (p->plugin.description), "Clap demo synth"); - snprintf(p->plugin.version, sizeof (p->plugin.version), "0.0.1"); - snprintf(p->plugin.manufacturer, sizeof (p->plugin.manufacturer), "Clap"); - snprintf(p->plugin.url, sizeof (p->plugin.url), "https://github.com/abique/clap"); - snprintf(p->plugin.support, sizeof (p->plugin.support), "https://github.com/abique/clap"); - snprintf(p->plugin.license, sizeof (p->plugin.license), "MIT"); - snprintf(p->plugin.categories, sizeof (p->plugin.categories), ""); p->plugin.type = CLAP_PLUGIN_INSTRUMENT; p->plugin.chunk_size = 1; p->plugin.has_gui = false; p->plugin.supports_tuning = true; p->plugin.latency = 0; + p->plugin.get_attribute = thyns_plugin_get_attribute; p->plugin.get_ports_configs_count = thyns_plugin_get_ports_configs_count; p->plugin.get_ports_config = thyns_plugin_get_ports_config; p->plugin.get_port_info = thyns_plugin_get_port_info; diff --git a/include/clap/clap.h b/include/clap/clap.h @@ -67,6 +67,16 @@ enum clap_log_severity CLAP_LOG_FATAL = 4, }; +# define CLAP_ATTR_ID "clap/id" +# define CLAP_ATTR_NAME "clap/name" +# define CLAP_ATTR_DESCRIPTION "clap/description" +# define CLAP_ATTR_VERSION "clap/version" +# define CLAP_ATTR_MANUFACTURER "clap/manufacturer" +# define CLAP_ATTR_URL "clap/url" +# define CLAP_ATTR_SUPPORT "clap/support" +# define CLAP_ATTR_LICENSE "clap/license" +# define CLAP_ATTR_CATEGORIES "clap/categories" + /////////// // PORTS // /////////// @@ -328,27 +338,21 @@ struct clap_plugin void *host_data; // reserved pointer for the host void *plugin_data; // reserved pointer for the plugin - /* free plugin's resources */ - void (*destroy)(struct clap_plugin *plugin); - - /* plugin info */ - char id[CLAP_ID_SIZE]; - char name[CLAP_NAME_SIZE]; - char description[CLAP_DESC_SIZE]; - char version[CLAP_NAME_SIZE]; - char manufacturer[CLAP_NAME_SIZE]; - char url[CLAP_URL_SIZE]; - char support[CLAP_URL_SIZE]; // a link to the support - char license[CLAP_NAME_SIZE]; - char categories[CLAP_TAGS_SIZE]; // fm;analogue;delay;... - uint32_t type; // clap_plugin_type bitfield uint32_t chunk_size; + uint32_t latency; // latency in samples bool has_gui; bool supports_tuning; - uint32_t latency; // latency in samples + /* free plugin's resources */ + void (*destroy)(struct clap_plugin *plugin); + + /* returns the size of the original string, 0 if not string */ + uint32_t (*get_attribute)(struct clap_plugin *plugin, + const char *attr, + char *buffer, + uint32_t size); /* Audio ports. * The port configuration has to be done while the plugin is deactivated. */