From 8b46fd1ff51b29cded517c9c2d166611e8c453fc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 31 May 2012 06:03:45 +0000 Subject: Blip => Blop. I give up trying to give ports new names. git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/blop.lv2@4484 a436a847-0d15-0410-975c-d299462d15a1 --- src/product.c | 123 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 44 deletions(-) (limited to 'src/product.c') diff --git a/src/product.c b/src/product.c index 0b892a1..10872ab 100644 --- a/src/product.c +++ b/src/product.c @@ -18,16 +18,22 @@ */ #include +#include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "uris.h" #define PRODUCT_MULTIPLICAND 0 #define PRODUCT_MULTIPLIER 1 #define PRODUCT_PRODUCT 2 typedef struct { - float* input1; - float* input2; - float* output; + float* input1; + float* input2; + float* output; + uint32_t input1_is_cv; + uint32_t input2_is_cv; + uint32_t output_is_cv; + URIs uris; } Product; static void @@ -56,6 +62,51 @@ connect_port(LV2_Handle instance, } } +static LV2_Morph_Status +morph_port(LV2_Handle instance, + uint32_t port, + LV2_URID type, + const LV2_Morph_Property*const* properties) +{ + Product* plugin = (Product*)instance; + + if (type != plugin->uris.lv2_ControlPort && + type != plugin->uris.lv2_CVPort) { + return LV2_MORPH_ERR_BAD_TYPE; + } + + switch (port) { + case PRODUCT_MULTIPLICAND: + plugin->input1_is_cv = (type == plugin->uris.lv2_CVPort); + break; + case PRODUCT_MULTIPLIER: + plugin->input2_is_cv = (type == plugin->uris.lv2_CVPort); + break; + default: + return LV2_MORPH_ERR_BAD_PORT; + } + + plugin->output_is_cv = plugin->input1_is_cv || plugin->input2_is_cv; + return LV2_MORPH_SUCCESS; +} + +static LV2_URID +port_type(LV2_Handle instance, + uint32_t port, + LV2_Morph_Property*const* properties) +{ + Product* plugin = (Product*)instance; + + switch (port) { + case PRODUCT_PRODUCT: + return (plugin->output_is_cv + ? plugin->uris.lv2_CVPort + : plugin->uris.lv2_ControlPort); + default: + return 0; + } +} + static LV2_Handle instantiate(const LV2_Descriptor* descriptor, double sample_rate, @@ -64,76 +115,60 @@ instantiate(const LV2_Descriptor* descriptor, { Product* plugin = (Product*)malloc(sizeof(Product)); + plugin->input1_is_cv = 0; + plugin->input2_is_cv = 0; + plugin->output_is_cv = 0; + + map_uris(&plugin->uris, features); + return (LV2_Handle)plugin; } static void -runProduct_iaia_oa(LV2_Handle instance, - uint32_t sample_count) +run(LV2_Handle instance, + uint32_t sample_count) { Product* plugin = (Product*)instance; - /* First Input (array of floats of length sample_count) */ + /* First Input (array of floats of length 1 or sample_count) */ const float* input1 = plugin->input1; - /* Second Input (array of floats of length sample_count) */ + /* Second Input (array of floats of length 1 or sample_count) */ const float* input2 = plugin->input2; /* Output (array of floats of length sample_count) */ float* output = plugin->output; - for (uint32_t s = 0; s < sample_count; ++s) { - output[s] = input1[s] * input2[s]; + if (!plugin->output_is_cv) { /* TODO: Avoid this branch */ + sample_count = 1; } -} - -static void -runProduct_iaic_oa(LV2_Handle instance, - uint32_t sample_count) -{ - Product* plugin = (Product*)instance; - - /* First Input (array of floats of length sample_count) */ - const float* input1 = plugin->input1; - - /* Second Input (float value) */ - const float input2 = *(plugin->input2); - - /* Output (array of floats of length sample_count) */ - float* output = plugin->output; for (uint32_t s = 0; s < sample_count; ++s) { - output[s] = input1[s] * input2; + const float in1 = input1[s * plugin->input1_is_cv]; + const float in2 = input2[s * plugin->input2_is_cv]; + output[s] = in1 * in2; } } -static void -runProduct_icic_oc(LV2_Handle instance, - uint32_t sample_count) +static const void* +extension_data(const char* uri) { - Product* plugin = (Product*)instance; - - /* First Input (float value) */ - const float input1 = *(plugin->input1); - - /* Second Input (float value) */ - const float input2 = *(plugin->input2); - - /* Output (pointer to float value) */ - float* output = plugin->output; - - output[0] = input1 * input2; + static const LV2_Morph_Interface morph = { morph_port, port_type }; + if (!strcmp(uri, LV2_MORPH__interface)) { + return &morph; + } + return NULL; } static const LV2_Descriptor descriptor = { - "http://drobilla.net/plugins/blip/product", + "http://drobilla.net/plugins/blop/product", instantiate, connect_port, NULL, - runProduct_iaia_oa, + run, NULL, cleanup, - NULL, + extension_data, }; LV2_SYMBOL_EXPORT const LV2_Descriptor* -- cgit v1.2.1