diff options
author | David Robillard <d@drobilla.net> | 2012-05-31 06:03:45 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-31 06:03:45 +0000 |
commit | 8b46fd1ff51b29cded517c9c2d166611e8c453fc (patch) | |
tree | 14a338294d302e663818570796bb5311297a9748 /src/fmod.c | |
parent | 9529f203c09d6dc8f4c2f12c3add9ec906f4bdba (diff) | |
download | blop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.tar.gz blop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.tar.bz2 blop.lv2-8b46fd1ff51b29cded517c9c2d166611e8c453fc.zip |
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
Diffstat (limited to 'src/fmod.c')
-rw-r--r-- | src/fmod.c | 162 |
1 files changed, 75 insertions, 87 deletions
@@ -18,17 +18,23 @@ */ #include <stdlib.h> +#include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" #include "math_func.h" +#include "uris.h" #define FMOD_FREQUENCY 0 #define FMOD_MODULATOR 1 #define FMOD_OUTPUT 2 typedef struct { - float* frequency; - float* modulator; - float* output; + float* frequency; + float* modulator; + float* output; + uint32_t frequency_is_cv; + uint32_t modulator_is_cv; + uint32_t output_is_cv; + URIs uris; } Fmod; static void @@ -57,129 +63,111 @@ connect_port(LV2_Handle instance, } } -static LV2_Handle -instantiate(const LV2_Descriptor* descriptor, - double sample_rate, - const char* bundle_path, - const LV2_Feature* const* features) -{ - Fmod* plugin = (Fmod*)malloc(sizeof(Fmod)); - - return (LV2_Handle)plugin; -} - -static void -runFmod_fama_oa(LV2_Handle instance, - uint32_t sample_count) +static LV2_Morph_Status +morph_port(LV2_Handle instance, + uint32_t port, + LV2_URID type, + const LV2_Morph_Property*const* properties) { Fmod* plugin = (Fmod*)instance; - /* Frequency to Modulate (array of floats of length sample_count) */ - const float* frequency = plugin->frequency; - - /* LFO Input (array of floats of length sample_count) */ - const float* modulator = plugin->modulator; - - /* Output Frequency (array of floats of length sample_count) */ - float* output = plugin->output; - - float freq; - float mod; - float scale; - - for (uint32_t s = 0; s < sample_count; ++s) { - freq = frequency[s]; - mod = modulator[s]; - - scale = (float)EXPF(M_LN2 * mod); + if (type != plugin->uris.lv2_ControlPort && + type != plugin->uris.lv2_CVPort) { + return LV2_MORPH_ERR_BAD_TYPE; + } - output[s] = scale * freq; + switch (port) { + case FMOD_FREQUENCY: + plugin->frequency_is_cv = (type == plugin->uris.lv2_CVPort); + break; + case FMOD_MODULATOR: + plugin->modulator_is_cv = (type == plugin->uris.lv2_CVPort); + break; + default: + return LV2_MORPH_ERR_BAD_PORT; } + + return LV2_MORPH_SUCCESS; } -static void -runFmod_famc_oa(LV2_Handle instance, - uint32_t sample_count) +static LV2_URID +port_type(LV2_Handle instance, + uint32_t port, + LV2_Morph_Property*const* properties) { Fmod* plugin = (Fmod*)instance; - /* Frequency to Modulate (array of floats of length sample_count) */ - const float* frequency = plugin->frequency; - - /* Shift (Octaves) (float value) */ - const float modulator = *(plugin->modulator); - - /* Output Frequency (array of floats of length sample_count) */ - float* output = plugin->output; + switch (port) { + case FMOD_FREQUENCY: + return (plugin->output_is_cv + ? plugin->uris.lv2_CVPort + : plugin->uris.lv2_ControlPort); + default: + return 0; + } +} - float freq; - float scale = (float)EXPF(M_LN2 * modulator); +static LV2_Handle +instantiate(const LV2_Descriptor* descriptor, + double sample_rate, + const char* bundle_path, + const LV2_Feature* const* features) +{ + Fmod* plugin = (Fmod*)malloc(sizeof(Fmod)); - for (uint32_t s = 0; s < sample_count; ++s) { - freq = frequency[s]; + plugin->frequency_is_cv = 0; + plugin->modulator_is_cv = 0; - output[s] = scale * freq; - } + return (LV2_Handle)plugin; } static void -runFmod_fcma_oa(LV2_Handle instance, - uint32_t sample_count) +run(LV2_Handle instance, + uint32_t sample_count) { Fmod* plugin = (Fmod*)instance; - /* Frequency to Modulate (float value) */ - const float frequency = *(plugin->frequency); + /* Frequency to Modulate (array of floats of length 1 or sample_count) */ + const float* frequency = plugin->frequency; - /* LFO Input (array of floats of length sample_count) */ + /* LFO Input (array of floats of length 1 or sample_count) */ const float* modulator = plugin->modulator; - /* Output Frequency (array of floats of length sample_count) */ + /* Output Frequency (array of floats of length 1 or sample_count) */ float* output = plugin->output; - float mod; - float scale; + if (!plugin->output_is_cv) { /* TODO: Avoid this branch */ + sample_count = 1; + } for (uint32_t s = 0; s < sample_count; ++s) { - mod = modulator[s]; - - scale = (float)EXPF(M_LN2 * mod); + const float freq = frequency[s * plugin->frequency_is_cv]; + const float mod = modulator[s * plugin->modulator_is_cv]; + const float scale = (float)EXPF(M_LN2 * mod); - output[s] = scale * frequency; + output[s] = scale * freq; } } -static void -runFmod_fcmc_oc(LV2_Handle instance, - uint32_t sample_count) +static const void* +extension_data(const char* uri) { - Fmod* plugin = (Fmod*)instance; - - /* Frequency to Modulate (float value) */ - const float frequency = *(plugin->frequency); - - /* Shift (Octaves) (float value) */ - const float modulator = *(plugin->modulator); - - /* Output Frequency (pointer to float value) */ - float* output = plugin->output; - - float scale; - - scale = (float)EXPF(M_LN2 * modulator); - - output[0] = scale * frequency; + 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/fmod", + "http://drobilla.net/plugins/blop/fmod", instantiate, connect_port, NULL, - runFmod_fcmc_oc, + run, NULL, cleanup, - NULL, + extension_data, }; LV2_SYMBOL_EXPORT const LV2_Descriptor* |