aboutsummaryrefslogtreecommitdiffstats
path: root/src/difference.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-09-16 16:59:35 +0000
committerDavid Robillard <d@drobilla.net>2012-09-16 16:59:35 +0000
commitd38365283adef399f2fc366f491a03b5fc3cf560 (patch)
treedf4c65825b6e4839fd48a08d09098bb88d0e90da /src/difference.c
parent3ae8043771d8b4a11492b74bc4c0a79a7487d0a5 (diff)
downloadblop.lv2-d38365283adef399f2fc366f491a03b5fc3cf560.tar.gz
blop.lv2-d38365283adef399f2fc366f491a03b5fc3cf560.tar.bz2
blop.lv2-d38365283adef399f2fc366f491a03b5fc3cf560.zip
Support latest options and morph extensions.
git-svn-id: http://svn.drobilla.net/lad/trunk/plugins/blop.lv2@4776 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/difference.c')
-rw-r--r--src/difference.c93
1 files changed, 53 insertions, 40 deletions
diff --git a/src/difference.c b/src/difference.c
index e886a09..9e76e0a 100644
--- a/src/difference.c
+++ b/src/difference.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include "lv2/lv2plug.in/ns/ext/morph/morph.h"
+#include "lv2/lv2plug.in/ns/ext/options/options.h"
#include "lv2/lv2plug.in/ns/lv2core/lv2.h"
#include "uris.h"
#include "vector_op.h"
@@ -63,51 +64,63 @@ 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)
+static uint32_t
+options_set(LV2_Handle instance,
+ const LV2_Options_Option* options)
{
Difference* plugin = (Difference*)instance;
-
- if (type != plugin->uris.lv2_ControlPort &&
- type != plugin->uris.lv2_CVPort) {
- return LV2_MORPH_ERR_BAD_TYPE;
+ uint32_t ret = 0;
+ for (const LV2_Options_Option* o = options; o->key; ++o) {
+ if (o->context != LV2_OPTIONS_PORT) {
+ ret |= LV2_OPTIONS_ERR_BAD_SUBJECT;
+ } else if (o->key != plugin->uris.morph_currentType) {
+ ret |= LV2_OPTIONS_ERR_BAD_KEY;
+ } else if (o->type != plugin->uris.atom_URID) {
+ ret |= LV2_OPTIONS_ERR_BAD_VALUE;
+ } else {
+ LV2_URID port_type = *(const LV2_URID*)(o->value);
+ if (port_type != plugin->uris.lv2_ControlPort &&
+ port_type != plugin->uris.lv2_CVPort) {
+ ret |= LV2_OPTIONS_ERR_BAD_VALUE;
+ continue;
+ }
+ switch (o->subject) {
+ case DIFFERENCE_MINUEND:
+ plugin->minuend_is_cv = (port_type == plugin->uris.lv2_CVPort);
+ break;
+ case DIFFERENCE_SUBTRAHEND:
+ plugin->subtrahend_is_cv = (port_type == plugin->uris.lv2_CVPort);
+ break;
+ default:
+ ret |= LV2_OPTIONS_ERR_BAD_SUBJECT;
+ }
+ }
}
-
- switch (port) {
- case DIFFERENCE_MINUEND:
- plugin->minuend_is_cv = (type == plugin->uris.lv2_CVPort);
- break;
- case DIFFERENCE_SUBTRAHEND:
- plugin->subtrahend_is_cv = (type == plugin->uris.lv2_CVPort);
- break;
- default:
- return LV2_MORPH_ERR_BAD_PORT;
- }
-
- plugin->difference_is_cv = (plugin->minuend_is_cv ||
- plugin->subtrahend_is_cv);
-
- return LV2_MORPH_SUCCESS;
+ plugin->difference_is_cv = plugin->minuend_is_cv || plugin->subtrahend_is_cv;
+ return ret;
}
-static LV2_URID
-port_type(LV2_Handle instance,
- uint32_t port,
- LV2_Morph_Property*const* properties)
+static uint32_t
+options_get(LV2_Handle instance,
+ LV2_Options_Option* options)
{
const Difference* plugin = (const Difference*)instance;
-
- switch (port) {
- case DIFFERENCE_DIFFERENCE:
- return (plugin->difference_is_cv
- ? plugin->uris.lv2_CVPort
- : plugin->uris.lv2_ControlPort);
- default:
- return 0;
+ uint32_t ret = 0;
+ for (LV2_Options_Option* o = options; o->key; ++o) {
+ if (o->context != LV2_OPTIONS_PORT ||
+ o->subject != DIFFERENCE_DIFFERENCE) {
+ ret |= LV2_OPTIONS_ERR_BAD_SUBJECT;
+ } else if (o->key != plugin->uris.morph_currentType) {
+ ret |= LV2_OPTIONS_ERR_BAD_KEY;
+ } else {
+ o->size = sizeof(LV2_URID);
+ o->type = plugin->uris.atom_URID;
+ o->value = (plugin->difference_is_cv
+ ? &plugin->uris.lv2_CVPort
+ : &plugin->uris.lv2_ControlPort);
+ }
}
+ return ret;
}
static LV2_Handle
@@ -147,9 +160,9 @@ run(LV2_Handle instance,
static const void*
extension_data(const char* uri)
{
- static const LV2_Morph_Interface morph = { morph_port, port_type };
- if (!strcmp(uri, LV2_MORPH__interface)) {
- return &morph;
+ static const LV2_Options_Interface options = { options_get, options_set };
+ if (!strcmp(uri, LV2_OPTIONS__interface)) {
+ return &options;
}
return NULL;
}