aboutsummaryrefslogtreecommitdiffstats
path: root/src/sync_pulse.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/sync_pulse.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/sync_pulse.c')
-rw-r--r--src/sync_pulse.c116
1 files changed, 56 insertions, 60 deletions
diff --git a/src/sync_pulse.c b/src/sync_pulse.c
index 96f90c7..14d9c8d 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,10 @@ instantiate(const LV2_Descriptor* descriptor,
{
SyncPulse* plugin = (SyncPulse*)malloc(sizeof(SyncPulse));
- plugin->srate = (float)sample_rate;
+ 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 +122,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 +143,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 +170,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*