aboutsummaryrefslogtreecommitdiffstats
path: root/src/tracker.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-31 06:03:45 +0000
committerDavid Robillard <d@drobilla.net>2012-05-31 06:03:45 +0000
commit8b46fd1ff51b29cded517c9c2d166611e8c453fc (patch)
tree14a338294d302e663818570796bb5311297a9748 /src/tracker.c
parent9529f203c09d6dc8f4c2f12c3add9ec906f4bdba (diff)
downloadblop.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/tracker.c')
-rw-r--r--src/tracker.c155
1 files changed, 79 insertions, 76 deletions
diff --git a/src/tracker.c b/src/tracker.c
index cb93bf8..706c8a1 100644
--- a/src/tracker.c
+++ b/src/tracker.c
@@ -18,8 +18,10 @@
*/
#include <stdlib.h>
+#include "lv2/lv2plug.in/ns/ext/morph/morph.h"
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
#include "common.h"
+#include "uris.h"
#define TRACKER_GATE 0
#define TRACKER_HATTACK 1
@@ -30,15 +32,20 @@
#define TRACKER_OUTPUT 6
typedef struct {
- float* gate;
- float* hattack;
- float* hdecay;
- float* lattack;
- float* ldecay;
- float* input;
- float* output;
- float coeff;
- float last_value;
+ float* gate;
+ float* hattack;
+ float* hdecay;
+ float* lattack;
+ float* ldecay;
+ float* input;
+ float* output;
+ float coeff;
+ float last_value;
+ uint32_t hattack_is_cv;
+ uint32_t hdecay_is_cv;
+ uint32_t lattack_is_cv;
+ uint32_t ldecay_is_cv;
+ URIs uris;
} Tracker;
static void
@@ -79,6 +86,39 @@ 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)
+{
+ Tracker* plugin = (Tracker*)instance;
+
+ if (type != plugin->uris.lv2_ControlPort &&
+ type != plugin->uris.lv2_CVPort) {
+ return LV2_MORPH_ERR_BAD_TYPE;
+ }
+
+ switch (port) {
+ case TRACKER_HATTACK:
+ plugin->hattack_is_cv = (type == plugin->uris.lv2_CVPort);
+ break;
+ case TRACKER_HDECAY:
+ plugin->hdecay_is_cv = (type == plugin->uris.lv2_CVPort);
+ break;
+ case TRACKER_LATTACK:
+ plugin->lattack_is_cv = (type == plugin->uris.lv2_CVPort);
+ break;
+ case TRACKER_LDECAY:
+ plugin->ldecay_is_cv = (type == plugin->uris.lv2_CVPort);
+ break;
+ default:
+ return LV2_MORPH_ERR_BAD_PORT;
+ }
+
+ return LV2_MORPH_SUCCESS;
+}
+
static LV2_Handle
instantiate(const LV2_Descriptor* descriptor,
double sample_rate,
@@ -89,6 +129,13 @@ instantiate(const LV2_Descriptor* descriptor,
plugin->coeff = 2.0f * M_PI / (float)sample_rate;
+ plugin->hattack_is_cv = 0;
+ plugin->hdecay_is_cv = 0;
+ plugin->lattack_is_cv = 0;
+ plugin->ldecay_is_cv = 0;
+
+ map_uris(&plugin->uris, features);
+
return (LV2_Handle)plugin;
}
@@ -101,24 +148,24 @@ activate(LV2_Handle instance)
}
static void
-runTracker_gaaadaia_oa(LV2_Handle instance,
- uint32_t sample_count)
+run(LV2_Handle instance,
+ uint32_t sample_count)
{
Tracker* plugin = (Tracker*)instance;
/* Gate (array of floats of length sample_count) */
const float* gate = plugin->gate;
- /* Gate High Attack Rate (array of floats of length sample_count) */
+ /* Gate High Attack Rate (array of floats of length 1 or sample_count) */
const float* hattack = plugin->hattack;
- /* Gate High Decay Rate (array of floats of length sample_count) */
+ /* Gate High Decay Rate (array of floats of length 1 or sample_count) */
const float* hdecay = plugin->hdecay;
- /* Gate Low Attack Rate (array of floats of length sample_count) */
+ /* Gate Low Attack Rate (array of floats of length 1 or sample_count) */
const float* lattack = plugin->lattack;
- /* Gate Low Decay Rate (array of floats of length sample_count) */
+ /* Gate Low Decay Rate (array of floats of length 1 or sample_count) */
const float* ldecay = plugin->ldecay;
/* Input (array of floats of length sample_count) */
@@ -131,16 +178,18 @@ runTracker_gaaadaia_oa(LV2_Handle instance,
float coeff = plugin->coeff;
float last_value = plugin->last_value;
- float rate;
- float in;
-
for (uint32_t s = 0; s < sample_count; ++s) {
- in = input[s];
+ const float in = input[s];
+ const float ha = hattack[s * plugin->hattack_is_cv];
+ const float hd = hdecay[s * plugin->hdecay_is_cv];
+ const float la = lattack[s * plugin->lattack_is_cv];
+ const float ld = ldecay[s * plugin->ldecay_is_cv];
+ float rate;
if (gate[s] > 0.0f) {
- rate = in > last_value ? hattack[s] : hdecay[s];
+ rate = in > last_value ? ha : hd;
} else {
- rate = in > last_value ? lattack[s] : ldecay[s];
+ rate = in > last_value ? la : ld;
}
rate = f_min(1.0f, rate * coeff);
@@ -152,71 +201,25 @@ runTracker_gaaadaia_oa(LV2_Handle instance,
plugin->last_value = last_value;
}
-static void
-runTracker_gaacdcia_oa(LV2_Handle instance,
- uint32_t sample_count)
+static const void*
+extension_data(const char* uri)
{
- Tracker* plugin = (Tracker*)instance;
-
- /* Gate (array of floats of length sample_count) */
- const float* gate = plugin->gate;
-
- /* Gate High Attack Rate (float value) */
- float hattack = *(plugin->hattack);
-
- /* Gate High Decay Rate (float value) */
- float hdecay = *(plugin->hdecay);
-
- /* Gate Low Attack Rate (float value) */
- float lattack = *(plugin->lattack);
-
- /* Gate Low Decay Rate (float value) */
- float ldecay = *(plugin->ldecay);
-
- /* Input (array of floats of length sample_count) */
- const float* input = plugin->input;
-
- /* Output (array of floats of length sample_count) */
- float* output = plugin->output;
-
- /* Instance Data */
- float coeff = plugin->coeff;
- float last_value = plugin->last_value;
-
- float in;
- float rate;
-
- hattack = f_min(1.0f, hattack * coeff);
- hdecay = f_min(1.0f, hdecay * coeff);
- lattack = f_min(1.0f, lattack * coeff);
- ldecay = f_min(1.0f, ldecay * coeff);
-
- for (uint32_t s = 0; s < sample_count; ++s) {
- in = input[s];
-
- if (gate[s] > 0.0f) {
- rate = in > last_value ? hattack : hdecay;
- } else {
- rate = in > last_value ? lattack : ldecay;
- }
-
- last_value = last_value * (1.0f - rate) + in * rate;
-
- output[s] = last_value;
+ static const LV2_Morph_Interface morph = { morph_port, NULL };
+ if (!strcmp(uri, LV2_MORPH__interface)) {
+ return &morph;
}
-
- plugin->last_value = last_value;
+ return NULL;
}
static const LV2_Descriptor descriptor = {
- "http://drobilla.net/plugins/blip/tracker",
+ "http://drobilla.net/plugins/blop/tracker",
instantiate,
connect_port,
activate,
- runTracker_gaacdcia_oa,
+ run,
NULL,
cleanup,
- NULL,
+ extension_data,
};
LV2_SYMBOL_EXPORT const LV2_Descriptor*