aboutsummaryrefslogtreecommitdiffstats
path: root/src/sync_square.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_square.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_square.c')
-rw-r--r--src/sync_square.c108
1 files changed, 52 insertions, 56 deletions
diff --git a/src/sync_square.c b/src/sync_square.c
index 51ceac5..e954a46 100644
--- a/src/sync_square.c
+++ b/src/sync_square.c
@@ -19,19 +19,23 @@
*/
#include <stdlib.h>
+#include "lv2/lv2plug.in/ns/ext/morph/morph.h"
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
+#include "uris.h"
#define SYNCSQUARE_FREQUENCY 0
#define SYNCSQUARE_GATE 1
#define SYNCSQUARE_OUTPUT 2
typedef struct {
- float* frequency;
- float* gate;
- float* output;
- float srate;
- float nyquist;
- float phase;
+ float* frequency;
+ float* gate;
+ float* output;
+ float srate;
+ float nyquist;
+ float phase;
+ uint32_t frequency_is_cv;
+ URIs uris;
} SyncSquare;
static void
@@ -60,6 +64,31 @@ 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)
+{
+ SyncSquare* plugin = (SyncSquare*)instance;
+
+ switch (port) {
+ case SYNCSQUARE_FREQUENCY:
+ if (type == plugin->uris.lv2_ControlPort) {
+ plugin->frequency_is_cv = 0;
+ } else if (type == plugin->uris.lv2_CVPort) {
+ plugin->frequency_is_cv = 1;
+ } else {
+ return LV2_MORPH_ERR_BAD_TYPE;
+ }
+ return LV2_MORPH_SUCCESS;
+ default:
+ return LV2_MORPH_ERR_BAD_PORT;
+ }
+
+ return LV2_MORPH_SUCCESS;
+}
+
static LV2_Handle
instantiate(const LV2_Descriptor* descriptor,
double sample_rate,
@@ -68,8 +97,10 @@ instantiate(const LV2_Descriptor* descriptor,
{
SyncSquare* plugin = (SyncSquare*)malloc(sizeof(SyncSquare));
- plugin->srate = (float)sample_rate;
- plugin->nyquist = (float)(sample_rate / 2);
+ plugin->srate = (float)sample_rate;
+ plugin->nyquist = (float)(sample_rate / 2.0f);
+ plugin->frequency_is_cv = 0;
+ map_uris(&plugin->uris, features);
return (LV2_Handle)plugin;
}
@@ -83,12 +114,12 @@ activate(LV2_Handle instance)
}
static void
-runSyncSquare_faga_oa(LV2_Handle instance,
- uint32_t sample_count)
+run(LV2_Handle instance,
+ uint32_t sample_count)
{
SyncSquare* plugin = (SyncSquare*)instance;
- /* Frequency (array of float of length sample_count) */
+ /* Frequency (array of float of length 1 or sample_count) */
const float* frequency = plugin->frequency;
/* Gate (array of float of length sample_count) */
@@ -102,11 +133,9 @@ runSyncSquare_faga_oa(LV2_Handle instance,
float srate = plugin->srate;
float nyquist = plugin->nyquist;
- float freq;
-
for (uint32_t s = 0; s < sample_count; ++s) {
if (gate[s] > 0.0f) {
- freq = frequency[s];
+ const float freq = frequency[s * plugin->frequency_is_cv];
if (phase < nyquist) {
output[s] = 1.0f;
@@ -129,58 +158,25 @@ runSyncSquare_faga_oa(LV2_Handle instance,
plugin->phase = phase;
}
-static void
-runSyncSquare_fcga_oa(LV2_Handle instance,
- uint32_t sample_count)
+static const void*
+extension_data(const char* uri)
{
- SyncSquare* plugin = (SyncSquare*)instance;
-
- /* Frequency (float value) */
- const float frequency = *(plugin->frequency);
-
- /* 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;
- float nyquist = plugin->nyquist;
-
- for (uint32_t s = 0; s < sample_count; ++s) {
- if (gate[s] > 0.0f) {
- if (phase < nyquist) {
- 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_square",
+ "http://drobilla.net/plugins/blop/sync_square",
instantiate,
connect_port,
activate,
- runSyncSquare_fcga_oa,
+ run,
NULL,
cleanup,
- NULL,
+ extension_data,
};
LV2_SYMBOL_EXPORT const LV2_Descriptor*