From ecebae5e6b1935b5ccebbc46538ab0a1e58379bf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 10 Jan 2013 06:14:13 +0000 Subject: Expose sampler parameter to host. Update to new definition of patch:Set. --- plugins/eg-sampler.lv2/sampler.c | 4 +-- plugins/eg-sampler.lv2/sampler.ttl | 14 ++++++-- plugins/eg-sampler.lv2/uris.h | 70 ++++++++++++++++++++------------------ 3 files changed, 50 insertions(+), 38 deletions(-) (limited to 'plugins/eg-sampler.lv2') diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c index eb6b496..5bb4e54 100644 --- a/plugins/eg-sampler.lv2/sampler.c +++ b/plugins/eg-sampler.lv2/sampler.c @@ -423,7 +423,7 @@ save(LV2_Handle instance, char* apath = map_path->abstract_path(map_path->handle, self->sample->path); store(handle, - self->uris.eg_file, + self->uris.eg_sample, apath, strlen(self->sample->path) + 1, self->uris.atom_Path, @@ -449,7 +449,7 @@ restore(LV2_Handle instance, const void* value = retrieve( handle, - self->uris.eg_file, + self->uris.eg_sample, &size, &type, &valflags); if (value) { diff --git a/plugins/eg-sampler.lv2/sampler.ttl b/plugins/eg-sampler.lv2/sampler.ttl index 60bf901..446f5a3 100644 --- a/plugins/eg-sampler.lv2/sampler.ttl +++ b/plugins/eg-sampler.lv2/sampler.ttl @@ -19,11 +19,18 @@ @prefix doap: . @prefix foaf: . @prefix lv2: . +@prefix patch: . +@prefix rdfs: . @prefix state: . @prefix ui: . @prefix urid: . @prefix work: . + + a lv2:Parameter ; + rdfs:label "sample" ; + rdfs:range atom:Path . + a lv2:Plugin ; doap:name "Example Sampler" ; @@ -35,12 +42,14 @@ lv2:extensionData state:interface , work:interface ; ui:ui ; + patch:writable ; lv2:port [ a lv2:InputPort , atom:AtomPort ; atom:bufferType atom:Sequence ; atom:supports , - ; + patch:Message ; + lv2:designation lv2:control ; lv2:index 0 ; lv2:symbol "control" ; lv2:name "Control" @@ -48,7 +57,8 @@ a lv2:OutputPort , atom:AtomPort ; atom:bufferType atom:Sequence ; - atom:supports ; + atom:supports patch:Message ; + lv2:designation lv2:control ; lv2:index 1 ; lv2:symbol "notify" ; lv2:name "Notify" diff --git a/plugins/eg-sampler.lv2/uris.h b/plugins/eg-sampler.lv2/uris.h index 2efccf9..e2ec6d0 100644 --- a/plugins/eg-sampler.lv2/uris.h +++ b/plugins/eg-sampler.lv2/uris.h @@ -23,7 +23,7 @@ #include "lv2/lv2plug.in/ns/ext/state/state.h" #define EG_SAMPLER_URI "http://lv2plug.in/plugins/eg-sampler" -#define EG_SAMPLER__file EG_SAMPLER_URI "#file" +#define EG_SAMPLER__sample EG_SAMPLER_URI "#sample" #define EG_SAMPLER__applySample EG_SAMPLER_URI "#applySample" #define EG_SAMPLER__freeSample EG_SAMPLER_URI "#freeSample" @@ -32,13 +32,15 @@ typedef struct { LV2_URID atom_Path; LV2_URID atom_Resource; LV2_URID atom_Sequence; + LV2_URID atom_URID; LV2_URID atom_eventTransfer; LV2_URID eg_applySample; - LV2_URID eg_file; + LV2_URID eg_sample; LV2_URID eg_freeSample; LV2_URID midi_Event; LV2_URID patch_Set; - LV2_URID patch_body; + LV2_URID patch_property; + LV2_URID patch_value; } SamplerURIs; static inline void @@ -48,13 +50,15 @@ map_sampler_uris(LV2_URID_Map* map, SamplerURIs* uris) uris->atom_Path = map->map(map->handle, LV2_ATOM__Path); uris->atom_Resource = map->map(map->handle, LV2_ATOM__Resource); uris->atom_Sequence = map->map(map->handle, LV2_ATOM__Sequence); + uris->atom_URID = map->map(map->handle, LV2_ATOM__URID); uris->atom_eventTransfer = map->map(map->handle, LV2_ATOM__eventTransfer); uris->eg_applySample = map->map(map->handle, EG_SAMPLER__applySample); - uris->eg_file = map->map(map->handle, EG_SAMPLER__file); uris->eg_freeSample = map->map(map->handle, EG_SAMPLER__freeSample); + uris->eg_sample = map->map(map->handle, EG_SAMPLER__sample); uris->midi_Event = map->map(map->handle, LV2_MIDI__MidiEvent); uris->patch_Set = map->map(map->handle, LV2_PATCH__Set); - uris->patch_body = map->map(map->handle, LV2_PATCH__body); + uris->patch_property = map->map(map->handle, LV2_PATCH__property); + uris->patch_value = map->map(map->handle, LV2_PATCH__value); } static inline bool @@ -66,12 +70,10 @@ is_object_type(const SamplerURIs* uris, LV2_URID type) /** * Write a message like the following to @p forge: - * [ + * [] * a patch:Set ; - * patch:body [ - * eg-sampler:file ; - * ] ; - * ] + * patch:property eg:sample ; + * patch:value . */ static inline LV2_Atom* write_set_file(LV2_Atom_Forge* forge, @@ -79,31 +81,26 @@ write_set_file(LV2_Atom_Forge* forge, const char* filename, const size_t filename_len) { - LV2_Atom_Forge_Frame set_frame; + LV2_Atom_Forge_Frame frame; LV2_Atom* set = (LV2_Atom*)lv2_atom_forge_blank( - forge, &set_frame, 1, uris->patch_Set); + forge, &frame, 1, uris->patch_Set); - lv2_atom_forge_property_head(forge, uris->patch_body, 0); - LV2_Atom_Forge_Frame body_frame; - lv2_atom_forge_blank(forge, &body_frame, 2, 0); - - lv2_atom_forge_property_head(forge, uris->eg_file, 0); + lv2_atom_forge_property_head(forge, uris->patch_property, 0); + lv2_atom_forge_urid(forge, uris->eg_sample); + lv2_atom_forge_property_head(forge, uris->patch_value, 0); lv2_atom_forge_path(forge, filename, filename_len); - lv2_atom_forge_pop(forge, &body_frame); - lv2_atom_forge_pop(forge, &set_frame); + lv2_atom_forge_pop(forge, &frame); return set; } /** * Get the file path from a message like: - * [ + * [] * a patch:Set ; - * patch:body [ - * eg-sampler:file ; - * ] ; - * ] + * patch:property eg:sample ; + * patch:value . */ static inline const LV2_Atom* read_set_file(const SamplerURIs* uris, @@ -114,23 +111,28 @@ read_set_file(const SamplerURIs* uris, return NULL; } - /* Get body of message. */ - const LV2_Atom_Object* body = NULL; - lv2_atom_object_get(obj, uris->patch_body, &body, 0); - if (!body) { + /* Get property URI. */ + const LV2_Atom* property = NULL; + lv2_atom_object_get(obj, uris->patch_property, &property, 0); + if (!property) { 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"); + } else if (property->type != uris->atom_URID) { + fprintf(stderr, "Malformed set message has non-URID property.\n"); + return NULL; + } else if (((LV2_Atom_URID*)property)->body != uris->eg_sample) { + fprintf(stderr, "Set message for unknown property.\n"); return NULL; } - /* Get file path from body. */ + /* Get value. */ const LV2_Atom* file_path = NULL; - lv2_atom_object_get(body, uris->eg_file, &file_path, 0); + lv2_atom_object_get(obj, uris->patch_value, &file_path, 0); if (!file_path) { - fprintf(stderr, "Ignored set message with no file path.\n"); + fprintf(stderr, "Malformed set message has no value.\n"); + return NULL; + } else if (file_path->type != uris->atom_Path) { + fprintf(stderr, "Set message value is not a Path.\n"); return NULL; } -- cgit v1.2.1