aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/eg-sampler.lv2/sampler.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-02-13 22:16:43 +0000
committerDavid Robillard <d@drobilla.net>2012-02-13 22:16:43 +0000
commit3c21b71e86d50ef0d21b0cfb5e4e74cf168b934d (patch)
treed0ecc90992f7e7317e42fae611879d12fdcef370 /plugins/eg-sampler.lv2/sampler.c
parent432035026d8a74e550a41a0d811a0f089a97dcc1 (diff)
downloadlv2-3c21b71e86d50ef0d21b0cfb5e4e74cf168b934d.tar.xz
Add response port (not yet used).
Move message handling to separate function.
Diffstat (limited to 'plugins/eg-sampler.lv2/sampler.c')
-rw-r--r--plugins/eg-sampler.lv2/sampler.c77
1 files changed, 44 insertions, 33 deletions
diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c
index a69a4a3..a0b0224 100644
--- a/plugins/eg-sampler.lv2/sampler.c
+++ b/plugins/eg-sampler.lv2/sampler.c
@@ -250,6 +250,49 @@ cleanup(LV2_Handle instance)
free(instance);
}
+static bool
+handle_message(Sampler* plugin,
+ const LV2_Atom_Object* obj)
+{
+ if (obj->type != plugin->uris.msg_Set) {
+ fprintf(stderr, "Ignoring unknown message type %d\n", obj->type);
+ return false;
+ }
+
+ /* Get body of message */
+ const LV2_Atom_Object* body = NULL;
+ LV2_Atom_Object_Query q1[] = {
+ { plugin->uris.msg_body, (const LV2_Atom**)&body },
+ LV2_OBJECT_QUERY_END
+ };
+ lv2_object_get(obj, q1);
+
+ if (!body) { // TODO: check type
+ fprintf(stderr, "Malformed set message with no body.\n");
+ return;
+ }
+
+ /* Get filename from body */
+ const LV2_Atom* filename = NULL;
+ LV2_Atom_Object_Query q2[] = {
+ { plugin->uris.eg_filename, &filename },
+ LV2_OBJECT_QUERY_END
+ };
+ lv2_object_get((LV2_Atom_Object*)body, q2);
+
+ if (!filename) {
+ fprintf(stderr, "Ignored set message with no filename\n");
+ return;
+ }
+
+ char* str = (char*)LV2_ATOM_BODY(filename);
+ fprintf(stderr, "Request to load %s\n", str);
+ memcpy(plugin->pending_samp->filepath, str, filename->size);
+ zix_sem_post(&plugin->signal);
+
+ return true;
+}
+
static void
run(LV2_Handle instance,
uint32_t sample_count)
@@ -271,39 +314,7 @@ run(LV2_Handle instance,
}
} else if (ev->body.type == plugin->uris.atom_Resource
|| ev->body.type == plugin->uris.atom_Blank) {
- const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body;
- if (obj->type == plugin->uris.msg_Set) {
- const LV2_Atom_Object* body = NULL;
- LV2_Atom_Object_Query q1[] = {
- { plugin->uris.msg_body, (const LV2_Atom**)&body },
- LV2_OBJECT_QUERY_END
- };
- lv2_object_get(obj, q1);
-
- if (!body) { // TODO: check type
- fprintf(stderr, "Malformed set message with no body.\n");
- continue;
- }
-
- const LV2_Atom* filename = NULL;
- LV2_Atom_Object_Query q2[] = {
- { plugin->uris.eg_filename, &filename },
- LV2_OBJECT_QUERY_END
- };
- lv2_object_get((LV2_Atom_Object*)body, q2);
-
- if (!filename) {
- fprintf(stderr, "Ignored set message with no filename\n");
- continue;
- }
-
- char* str = (char*)LV2_ATOM_BODY(filename);
- fprintf(stderr, "Request to load %s\n", str);
- memcpy(plugin->pending_samp->filepath, str, filename->size);
- zix_sem_post(&plugin->signal);
- } else {
- fprintf(stderr, "Unknown message type %d\n", obj->id);
- }
+ handle_message(plugin, (LV2_Atom_Object*)&ev->body);
} else {
fprintf(stderr, "Unknown event type %d\n", ev->body.type);
}