summaryrefslogtreecommitdiff
path: root/libs/plugins
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-12-19 22:28:40 +0100
committerRobin Gareus <robin@gareus.org>2018-12-19 22:28:40 +0100
commit1528df2f5a2f2eaee4a3f1e48fc90abd6b1de46f (patch)
tree992a8538e55afd588f22ebf9b6b575a5980d10ed /libs/plugins
parent3a5da6fdc42bf58016e1cfe2b9ef1c6277cab302 (diff)
Compliant LV2 state path-mapping
lv2 state mandates that > The plugin MUST use this function [ absolute_path] in order to > actually open or otherwise use any paths loaded from plugin state. Previously the plugin uses the value directly. Also > The caller is responsible for freeing the returned value with free(). is now implemented on systems other than windows (where this is not possible, since the memory must be free()ed in the same module where it was allocated.
Diffstat (limited to 'libs/plugins')
-rw-r--r--libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc b/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
index b9ccf2de2c..393c29b117 100644
--- a/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
+++ b/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
@@ -731,6 +731,10 @@ save (LV2_Handle instance,
apath, strlen (apath) + 1,
self->atom_Path, LV2_STATE_IS_POD);
+#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
+ free (apath);
+#endif
+
return LV2_STATE_SUCCESS;
}
@@ -747,15 +751,32 @@ restore (LV2_Handle instance,
return LV2_STATE_ERR_UNKNOWN;
}
+ LV2_State_Map_Path* map_path = NULL;
+
+ for (int i = 0; features[i]; ++i) {
+ if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
+ map_path = (LV2_State_Map_Path*) features[i]->data;
+ }
+ }
+
+ if (!map_path) {
+ return LV2_STATE_ERR_NO_FEATURE;
+ }
+
size_t size;
uint32_t type;
uint32_t valflags;
const void* value = retrieve (handle, self->afs_sf2file, &size, &type, &valflags);
if (value) {
- strncpy (self->queue_sf2_file_path, (const char*) value, 1023);
+ char* apath = map_path->absolute_path (map_path->handle, (const char*) value);
+ strncpy (self->queue_sf2_file_path, apath, 1023);
+ printf ("XXX %s -> %s\n", (const char*) value, apath);
self->queue_sf2_file_path[1023] = '\0';
self->queue_reinit = true;
+#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
+ free (apath);
+#endif
}
return LV2_STATE_SUCCESS;
}