diff options
author | David Robillard <d@drobilla.net> | 2012-05-31 06:23:57 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-31 06:23:57 +0000 |
commit | 7b20413c84b14d2c2bc1037bb08134dcdf152ddb (patch) | |
tree | c7c339d6c4d0d26b01e654163e7a8a203f62baf4 /src/product.c | |
parent | 46caaf6b96f185a4a25d1d12fc85720a03220e97 (diff) | |
download | blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.tar.gz blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.tar.bz2 blop.lv2-7b20413c84b14d2c2bc1037bb08134dcdf152ddb.zip |
Umm... commit pretty much all the work of the past few days. Again.
git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/blop.lv2@4488 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/product.c')
-rw-r--r-- | src/product.c | 126 |
1 files changed, 82 insertions, 44 deletions
diff --git a/src/product.c b/src/product.c index 0b892a1..3f83af9 100644 --- a/src/product.c +++ b/src/product.c @@ -18,16 +18,22 @@ */ #include <stdlib.h> +#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, @@ -63,77 +114,64 @@ instantiate(const LV2_Descriptor* descriptor, const LV2_Feature* const* features) { Product* plugin = (Product*)malloc(sizeof(Product)); + if (!plugin) { + return NULL; + } + + 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* |