aboutsummaryrefslogtreecommitdiffstats
path: root/src/sync_pulse.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-31 06:23:57 +0000
committerDavid Robillard <d@drobilla.net>2012-05-31 06:23:57 +0000
commit7b20413c84b14d2c2bc1037bb08134dcdf152ddb (patch)
treec7c339d6c4d0d26b01e654163e7a8a203f62baf4 /src/sync_pulse.c
parent46caaf6b96f185a4a25d1d12fc85720a03220e97 (diff)
downloadblop.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/sync_pulse.c')
-rw-r--r--src/sync_pulse.c118
1 files changed, 58 insertions, 60 deletions
diff --git a/src/sync_pulse.c b/src/sync_pulse.c
index 96f90c7..732faa9 100644
--- a/src/sync_pulse.c
+++ b/src/sync_pulse.c
@@ -19,7 +19,9 @@
*/
#include <stdlib.h>
+#include "lv2/lv2plug.in/ns/ext/morph/morph.h"
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
+#include "uris.h"
#include "common.h"
#define SYNCPULSE_FREQUENCY 0
@@ -28,12 +30,15 @@
#define SYNCPULSE_OUTPUT 3
typedef struct {
- float* frequency;
- float* pulsewidth;
- float* gate;
- float* output;
- float srate;
- float phase;
+ float* frequency;
+ float* pulsewidth;
+ float* gate;
+ float* output;
+ float srate;
+ float phase;
+ uint32_t frequency_is_cv;
+ uint32_t pulsewidth_is_cv;
+ URIs uris;
} SyncPulse;
static void
@@ -65,6 +70,33 @@ 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)
+{
+ SyncPulse* plugin = (SyncPulse*)instance;
+
+ if (type != plugin->uris.lv2_ControlPort &&
+ type != plugin->uris.lv2_CVPort) {
+ return LV2_MORPH_ERR_BAD_TYPE;
+ }
+
+ switch (port) {
+ case SYNCPULSE_FREQUENCY:
+ plugin->frequency_is_cv = (type == plugin->uris.lv2_CVPort);
+ break;
+ case SYNCPULSE_PULSEWIDTH:
+ plugin->pulsewidth_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,
@@ -73,7 +105,12 @@ instantiate(const LV2_Descriptor* descriptor,
{
SyncPulse* plugin = (SyncPulse*)malloc(sizeof(SyncPulse));
- plugin->srate = (float)sample_rate;
+ if (plugin) {
+ plugin->srate = (float)sample_rate;
+ plugin->frequency_is_cv = 0;
+ plugin->pulsewidth_is_cv = 0;
+ map_uris(&plugin->uris, features);
+ }
return (LV2_Handle)plugin;
}
@@ -87,8 +124,8 @@ activate(LV2_Handle instance)
}
static void
-runSyncPulse_fapaga_oa(LV2_Handle instance,
- uint32_t sample_count)
+run(LV2_Handle instance,
+ uint32_t sample_count)
{
SyncPulse* plugin = (SyncPulse*)instance;
@@ -108,13 +145,11 @@ runSyncPulse_fapaga_oa(LV2_Handle instance,
float phase = plugin->phase;
float srate = plugin->srate;
- float freq;
- float pwidth;
-
for (uint32_t s = 0; s < sample_count; ++s) {
if (gate[s] > 0.0f) {
- freq = frequency[s];
- pwidth = f_clip(pulsewidth[s], 0.0f, 1.0f) * srate;
+ const float freq = frequency[s * plugin->frequency_is_cv];
+ const float pw = pulsewidth[s * plugin->pulsewidth_is_cv];
+ const float pwidth = f_clip(pw, 0.0f, 1.0f) * srate;
if (phase < pwidth) {
output[s] = 1.0f;
@@ -137,62 +172,25 @@ runSyncPulse_fapaga_oa(LV2_Handle instance,
plugin->phase = phase;
}
-static void
-runSyncPulse_fcpcga_oa(LV2_Handle instance,
- uint32_t sample_count)
+static const void*
+extension_data(const char* uri)
{
- SyncPulse* plugin = (SyncPulse*)instance;
-
- /* Frequency (float value) */
- const float frequency = *(plugin->frequency);
-
- /* Pulse Width (float value) */
- float pulsewidth = f_clip(*(plugin->pulsewidth), 0.0f, 1.0f);
-
- /* Gate (array of float of length sample_count) */
- const float* gate = plugin->gate;
-
- /* Output (pointer to float value) */
- float* output = plugin->output;
-
- /* Instance Data */
- float phase = plugin->phase;
- float srate = plugin->srate;
-
- pulsewidth *= srate;
-
- for (uint32_t s = 0; s < sample_count; ++s) {
- if (gate[s] > 0.0f) {
- if (phase < pulsewidth) {
- output[s] = 1.0f;
- } else {
- output[s] = -1.0f;
- }
-
- phase += frequency;
- if (phase < 0.0f) {
- phase += srate;
- } else if (phase > srate) {
- phase -= srate;
- }
- } else {
- output[s] = 0.0f;
- phase = 0.0f;
- }
+ static const LV2_Morph_Interface morph = { morph_port, NULL };
+ if (!strcmp(uri, LV2_MORPH__interface)) {
+ return &morph;
}
-
- plugin->phase = phase;
+ return NULL;
}
static const LV2_Descriptor descriptor = {
- "http://drobilla.net/plugins/blip/sync_pulse",
+ "http://drobilla.net/plugins/blop/sync_pulse",
instantiate,
connect_port,
activate,
- runSyncPulse_fcpcga_oa,
+ run,
NULL,
cleanup,
- NULL,
+ extension_data,
};
LV2_SYMBOL_EXPORT const LV2_Descriptor*