aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/eg-sampler.lv2/uris.h
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/eg-sampler.lv2/uris.h')
-rw-r--r--plugins/eg-sampler.lv2/uris.h70
1 files changed, 60 insertions, 10 deletions
diff --git a/plugins/eg-sampler.lv2/uris.h b/plugins/eg-sampler.lv2/uris.h
index 8c8801a..6584c13 100644
--- a/plugins/eg-sampler.lv2/uris.h
+++ b/plugins/eg-sampler.lv2/uris.h
@@ -32,9 +32,10 @@
typedef struct {
LV2_URID atom_Blank;
LV2_URID atom_Resource;
+ LV2_URID atom_eventTransfer;
LV2_URID eg_applySample;
- LV2_URID eg_freeSample;
LV2_URID eg_file;
+ LV2_URID eg_freeSample;
LV2_URID midi_Event;
LV2_URID msg_Set;
LV2_URID msg_body;
@@ -44,15 +45,64 @@ typedef struct {
static inline void
map_sampler_uris(LV2_URID_Map* map, SamplerURIs* uris)
{
- uris->atom_Blank = map->map(map->handle, NS_ATOM "Blank");
- uris->atom_Resource = map->map(map->handle, NS_ATOM "Resource");
- uris->eg_applySample = map->map(map->handle, APPLY_SAMPLE_URI);
- uris->eg_file = map->map(map->handle, FILE_URI);
- uris->eg_freeSample = map->map(map->handle, FREE_SAMPLE_URI);
- uris->midi_Event = map->map(map->handle, MIDI_EVENT_URI);
- uris->msg_Set = map->map(map->handle, LV2_MESSAGE_Set);
- uris->msg_body = map->map(map->handle, LV2_MESSAGE_body);
- uris->state_Path = map->map(map->handle, LV2_STATE_PATH_URI);
+ uris->atom_Blank = map->map(map->handle, NS_ATOM "Blank");
+ uris->atom_Resource = map->map(map->handle, NS_ATOM "Resource");
+ uris->atom_eventTransfer = map->map(map->handle, NS_ATOM "eventTransfer");
+ uris->eg_applySample = map->map(map->handle, APPLY_SAMPLE_URI);
+ uris->eg_file = map->map(map->handle, FILE_URI);
+ uris->eg_freeSample = map->map(map->handle, FREE_SAMPLE_URI);
+ uris->midi_Event = map->map(map->handle, MIDI_EVENT_URI);
+ uris->msg_Set = map->map(map->handle, LV2_MESSAGE_Set);
+ uris->msg_body = map->map(map->handle, LV2_MESSAGE_body);
+ uris->state_Path = map->map(map->handle, LV2_STATE_PATH_URI);
+}
+
+static inline bool
+is_object_type(const SamplerURIs* uris, LV2_URID type)
+{
+ return type == uris->atom_Resource
+ || type == uris->atom_Blank;
+}
+
+static inline const LV2_Atom*
+get_msg_file_uri(const SamplerURIs* uris,
+ const LV2_Atom_Object* obj)
+{
+ /* Message should look like this:
+ * [
+ * a msg:Set ;
+ * msg:body [
+ * eg-sampler:file <file://hal/home/me/foo.wav> ;
+ * ] ;
+ * ]
+ */
+
+ if (obj->type != uris->msg_Set) {
+ fprintf(stderr, "Ignoring unknown message type %d\n", obj->type);
+ return NULL;
+ }
+
+ /* Get body of message. */
+ const LV2_Atom_Object* body = NULL;
+ lv2_object_getv(obj, uris->msg_body, &body, 0);
+ if (!body) {
+ fprintf(stderr, "Malformed set message has no body.\n");
+ return NULL;
+ }
+ if (!is_object_type(uris, body->atom.type)) {
+ fprintf(stderr, "Malformed set message has non-object body.\n");
+ return NULL;
+ }
+
+ /* Get file URI from body. */
+ const LV2_Atom* file_uri = NULL;
+ lv2_object_getv(body, uris->eg_file, &file_uri, 0);
+ if (!file_uri) {
+ fprintf(stderr, "Ignored set message with no file URI.\n");
+ return NULL;
+ }
+
+ return file_uri;
}
#endif /* SAMPLER_URIS_H */