aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/eg-sampler.lv2/sampler.c94
-rw-r--r--plugins/eg-sampler.lv2/sampler_ui.c40
-rw-r--r--plugins/eg-sampler.lv2/uris.h62
3 files changed, 77 insertions, 119 deletions
diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c
index 904f026..043f629 100644
--- a/plugins/eg-sampler.lv2/sampler.c
+++ b/plugins/eg-sampler.lv2/sampler.c
@@ -63,11 +63,10 @@ enum {
static const char* default_sample_file = "monosample.wav";
typedef struct {
- SF_INFO info; /**< Info about sample from sndfile */
- float* data; /**< Sample data in float */
- char* uri; /**< URI of file */
- const char* path; /**< Path of file (pointer into uri) */
- size_t uri_len; /**< Length of uri. */
+ SF_INFO info; /**< Info about sample from sndfile */
+ float* data; /**< Sample data in float */
+ char* path; /**< Path of file */
+ size_t path_len; /**< Length of path */
} Sample;
typedef struct {
@@ -110,41 +109,10 @@ typedef struct {
Sample* sample;
} SampleMessage;
-static bool
-parse_file_uri(const char* uri,
- const char** host, size_t* host_len,
- const char** path, size_t* path_len)
-{
- if (strncmp(uri, "file://", strlen("file://"))) {
- return false;
- }
-
- *host = uri + strlen("file://");
- const char* host_end = *host;
- for (; *host_end && *host_end != '/'; ++host_end) {}
-
- *host_len = host_end - *host;
- *path = host_end;
- *path_len = (uri + strlen(uri)) - host_end;
-
- return true;
-}
-
static Sample*
-load_sample(Sampler* plugin, const char* uri)
+load_sample(Sampler* plugin, const char* path)
{
- const size_t uri_len = strlen(uri);
- const char* host = NULL;
- const char* path = NULL;
- size_t host_len = 0;
- size_t path_len = 0;
- if (!parse_file_uri(uri, &host, &host_len, &path, &path_len)) {
- fprintf(stderr, "Request to load bad file URI %s\n", uri);
- return NULL;
- }
-
- /* Probably should check if the host is local here, but we'll just
- blissfully attempt to load the path on this machine... */
+ const size_t path_len = strlen(path);
printf("Loading sample %s\n", path);
Sample* const sample = (Sample*)malloc(sizeof(Sample));
@@ -168,11 +136,10 @@ load_sample(Sampler* plugin, const char* uri)
sf_close(sndfile);
/* Fill sample struct and return it. */
- sample->data = data;
- sample->uri = (char*)malloc(uri_len + 1);
- sample->path = sample->uri + (path - uri);
- sample->uri_len = uri_len;
- memcpy(sample->uri, uri, uri_len + 1);
+ sample->data = data;
+ sample->path = (char*)malloc(path_len + 1);
+ sample->path_len = path_len;
+ memcpy(sample->path, path, path_len + 1);
return sample;
}
@@ -181,14 +148,14 @@ static bool
handle_set_message(Sampler* plugin,
const LV2_Atom_Object* obj)
{
- /* Get file URI from message */
- const LV2_Atom* file_uri = get_msg_file_uri(&plugin->uris, obj);
- if (!file_uri) {
+ /* Get file path from message */
+ const LV2_Atom* file_path = get_msg_file_path(&plugin->uris, obj);
+ if (!file_path) {
return false;
}
/* Load sample. */
- Sample* sample = load_sample(plugin, LV2_ATOM_BODY(file_uri));
+ Sample* sample = load_sample(plugin, LV2_ATOM_BODY(file_path));
if (sample) {
/* Loaded sample, send it to run() to be applied. */
const SampleMessage msg = {
@@ -206,10 +173,12 @@ handle_set_message(Sampler* plugin,
void
free_sample(Sample* sample)
{
- fprintf(stderr, "Freeing %s\n", sample->uri);
- free(sample->uri);
- free(sample->data);
- free(sample);
+ if (sample) {
+ fprintf(stderr, "Freeing %s\n", sample->path);
+ free(sample->path);
+ free(sample->data);
+ free(sample);
+ }
}
void*
@@ -441,23 +410,10 @@ run(LV2_Handle instance,
plugin->sample = m.sample;
/* Send a notification that we're using a new sample. */
-
lv2_atom_forge_audio_time(&plugin->forge, 0, 0);
-
- LV2_Atom_Forge_Frame set_frame;
- lv2_atom_forge_blank(&plugin->forge, &set_frame, 1, uris->msg_Set);
-
- lv2_atom_forge_property_head(&plugin->forge, uris->msg_body, 0);
- LV2_Atom_Forge_Frame body_frame;
- lv2_atom_forge_blank(&plugin->forge, &body_frame, 2, 0);
-
- lv2_atom_forge_property_head(&plugin->forge, uris->eg_file, 0);
- lv2_atom_forge_uri(&plugin->forge,
- (const uint8_t*)plugin->sample->uri,
- plugin->sample->uri_len);
-
- lv2_atom_forge_pop(&plugin->forge, &body_frame);
- lv2_atom_forge_pop(&plugin->forge, &set_frame);
+ write_set_filename_msg(&plugin->forge, uris,
+ plugin->sample->path,
+ plugin->sample->path_len);
} else {
fprintf(stderr, "Unknown message from worker\n");
@@ -476,7 +432,7 @@ save(LV2_Handle instance,
{
LV2_State_Map_Path* map_path = NULL;
for (int i = 0; features[i]; ++i) {
- if (!strcmp(features[i]->URI, LV2_STATE_MAP_PATH_URI)) {
+ if (!strcmp(features[i]->URI, LV2_STATE__mapPath)) {
map_path = (LV2_State_Map_Path*)features[i]->data;
}
}
@@ -489,7 +445,7 @@ save(LV2_Handle instance,
plugin->uris.eg_file,
apath,
strlen(plugin->sample->path) + 1,
- plugin->uris.state_Path,
+ plugin->uris.atom_Path,
LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE);
free(apath);
diff --git a/plugins/eg-sampler.lv2/sampler_ui.c b/plugins/eg-sampler.lv2/sampler_ui.c
index 056f0bb..2c039a5 100644
--- a/plugins/eg-sampler.lv2/sampler_ui.c
+++ b/plugins/eg-sampler.lv2/sampler_ui.c
@@ -75,46 +75,18 @@ on_load_clicked(GtkWidget* widget,
/* Got what we need, destroy the dialog. */
gtk_widget_destroy(dialog);
- /* Build a complete file URI with hostname, e.g. file://hal/home/me/foo.wav
- This is to precisely specify the file location, even if the plugin is
- running on a different host (which is entirely possible). Plugins
- should do this even though some hosts may not support such setups.
- */
- const char* hostname = g_get_host_name();
- char* file_uri = g_filename_to_uri(filename, hostname, NULL);
- const size_t file_uri_len = strlen(file_uri);
-
#define OBJ_BUF_SIZE 1024
uint8_t obj_buf[OBJ_BUF_SIZE];
lv2_atom_forge_set_buffer(&ui->forge, obj_buf, OBJ_BUF_SIZE);
- /* Send [
- * a msg:Set ;
- * msg:body [
- * eg-sampler:filename <file://hal/home/me/foo.wav> ;
- * ] ;
- * ]
- */
- LV2_Atom_Forge_Frame set_frame;
- LV2_Atom* set = (LV2_Atom*)lv2_atom_forge_blank(
- &ui->forge, &set_frame, 1, ui->uris.msg_Set);
-
- lv2_atom_forge_property_head(&ui->forge, ui->uris.msg_body, 0);
- LV2_Atom_Forge_Frame body_frame;
- lv2_atom_forge_blank(&ui->forge, &body_frame, 2, 0);
-
- lv2_atom_forge_property_head(&ui->forge, ui->uris.eg_file, 0);
- lv2_atom_forge_uri(&ui->forge, (const uint8_t*)file_uri, file_uri_len);
-
- ui->write(ui->controller, 0, lv2_atom_total_size(set),
- ui->uris.atom_eventTransfer,
- set);
+ LV2_Atom* msg = write_set_filename_msg(&ui->forge, &ui->uris,
+ filename, strlen(filename));
- lv2_atom_forge_pop(&ui->forge, &body_frame);
- lv2_atom_forge_pop(&ui->forge, &set_frame);
+ ui->write(ui->controller, 0, lv2_atom_total_size(msg),
+ ui->uris.atom_eventTransfer,
+ msg);
g_free(filename);
- g_free(file_uri);
}
static LV2UI_Handle
@@ -186,7 +158,7 @@ port_event(LV2UI_Handle handle,
LV2_Atom* atom = (LV2_Atom*)buffer;
if (atom->type == ui->uris.atom_Blank) {
LV2_Atom_Object* obj = (LV2_Atom_Object*)atom;
- const LV2_Atom* file_uri = get_msg_file_uri(&ui->uris, obj);
+ const LV2_Atom* file_uri = get_msg_file_path(&ui->uris, obj);
if (!file_uri) {
fprintf(stderr, "Unknown message sent to UI.\n");
return;
diff --git a/plugins/eg-sampler.lv2/uris.h b/plugins/eg-sampler.lv2/uris.h
index 6584c13..97cefca 100644
--- a/plugins/eg-sampler.lv2/uris.h
+++ b/plugins/eg-sampler.lv2/uris.h
@@ -31,6 +31,7 @@
typedef struct {
LV2_URID atom_Blank;
+ LV2_URID atom_Path;
LV2_URID atom_Resource;
LV2_URID atom_eventTransfer;
LV2_URID eg_applySample;
@@ -39,22 +40,21 @@ typedef struct {
LV2_URID midi_Event;
LV2_URID msg_Set;
LV2_URID msg_body;
- LV2_URID state_Path;
} SamplerURIs;
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->atom_eventTransfer = map->map(map->handle, NS_ATOM "eventTransfer");
+ uris->atom_Blank = map->map(map->handle, LV2_ATOM__Blank);
+ uris->atom_Path = map->map(map->handle, LV2_ATOM__Path);
+ uris->atom_Resource = map->map(map->handle, LV2_ATOM__Resource);
+ uris->atom_eventTransfer = map->map(map->handle, LV2_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);
+ uris->msg_Set = map->map(map->handle, LV2_MESSAGE__Set);
+ uris->msg_body = map->map(map->handle, LV2_MESSAGE__body);
}
static inline bool
@@ -64,15 +64,45 @@ is_object_type(const SamplerURIs* uris, LV2_URID type)
|| type == uris->atom_Blank;
}
+static inline LV2_Atom*
+write_set_filename_msg(LV2_Atom_Forge* forge,
+ const SamplerURIs* uris,
+ const char* filename,
+ const size_t filename_len)
+{
+ /* Send [
+ * a msg:Set ;
+ * msg:body [
+ * eg-sampler:filename </home/me/foo.wav> ;
+ * ] ;
+ * ]
+ */
+ LV2_Atom_Forge_Frame set_frame;
+ LV2_Atom* set = (LV2_Atom*)lv2_atom_forge_blank(
+ forge, &set_frame, 1, uris->msg_Set);
+
+ lv2_atom_forge_property_head(forge, uris->msg_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_path(forge, (const uint8_t*)filename, filename_len);
+
+ lv2_atom_forge_pop(forge, &body_frame);
+ lv2_atom_forge_pop(forge, &set_frame);
+
+ return set;
+}
+
static inline const LV2_Atom*
-get_msg_file_uri(const SamplerURIs* uris,
- const LV2_Atom_Object* obj)
+get_msg_file_path(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> ;
+ * eg-sampler:file </home/me/foo.wav> ;
* ] ;
* ]
*/
@@ -94,15 +124,15 @@ get_msg_file_uri(const SamplerURIs* uris,
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");
+ /* Get file path from body. */
+ const LV2_Atom* file_path = NULL;
+ lv2_object_getv(body, uris->eg_file, &file_path, 0);
+ if (!file_path) {
+ fprintf(stderr, "Ignored set message with no file PATH.\n");
return NULL;
}
- return file_uri;
+ return file_path;
}
#endif /* SAMPLER_URIS_H */