lv2: implement use of the freePath feature

This commit is contained in:
Jean Pierre Cimalando 2020-07-04 10:44:39 +02:00
parent d019bb1a93
commit a293ccdc09
2 changed files with 25 additions and 5 deletions

View file

@ -179,6 +179,20 @@ enum
SFIZZ_STRETCH_TUNING = 11, SFIZZ_STRETCH_TUNING = 11,
}; };
static void
sfizz_lv2_state_free_path(LV2_State_Free_Path_Handle handle,
char *path)
{
(void)handle;
free(path);
}
static LV2_State_Free_Path sfizz_State_Free_Path =
{
.handle = NULL,
.free_path = &sfizz_lv2_state_free_path,
};
static void static void
sfizz_lv2_map_required_uris(sfizz_plugin_t *self) sfizz_lv2_map_required_uris(sfizz_plugin_t *self)
{ {
@ -914,10 +928,13 @@ restore(LV2_Handle instance,
sfizz_plugin_t *self = (sfizz_plugin_t *)instance; sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
LV2_State_Map_Path *map_path = NULL; LV2_State_Map_Path *map_path = NULL;
LV2_State_Free_Path *free_path = &sfizz_State_Free_Path;
for (const LV2_Feature *const *f = features; *f; ++f) for (const LV2_Feature *const *f = features; *f; ++f)
{ {
if (!strcmp((*f)->URI, LV2_STATE__mapPath)) if (!strcmp((*f)->URI, LV2_STATE__mapPath))
map_path = (LV2_State_Map_Path *)(**f).data; map_path = (LV2_State_Map_Path *)(**f).data;
else if (!strcmp((*f)->URI, LV2_STATE__freePath))
free_path = (LV2_State_Free_Path *)(**f).data;
} }
// Fetch back the saved file path, if any // Fetch back the saved file path, if any
@ -940,7 +957,7 @@ restore(LV2_Handle instance,
sfizz_lv2_load_file(instance, path); sfizz_lv2_load_file(instance, path);
if (map_path) if (map_path)
free((char *)path); free_path->free_path(free_path->handle, (char *)path);
} }
value = retrieve(handle, self->sfizz_scala_file_uri, &size, &type, &val_flags); value = retrieve(handle, self->sfizz_scala_file_uri, &size, &type, &val_flags);
@ -967,7 +984,7 @@ restore(LV2_Handle instance,
} }
if (map_path) if (map_path)
free((char *)path); free_path->free_path(free_path->handle, (char *)path);
} }
value = retrieve(handle, self->sfizz_num_voices_uri, &size, &type, &val_flags); value = retrieve(handle, self->sfizz_num_voices_uri, &size, &type, &val_flags);
@ -1019,10 +1036,13 @@ save(LV2_Handle instance,
sfizz_plugin_t *self = (sfizz_plugin_t *)instance; sfizz_plugin_t *self = (sfizz_plugin_t *)instance;
LV2_State_Map_Path *map_path = NULL; LV2_State_Map_Path *map_path = NULL;
LV2_State_Free_Path *free_path = &sfizz_State_Free_Path;
for (const LV2_Feature *const *f = features; *f; ++f) for (const LV2_Feature *const *f = features; *f; ++f)
{ {
if (!strcmp((*f)->URI, LV2_STATE__mapPath)) if (!strcmp((*f)->URI, LV2_STATE__mapPath))
map_path = (LV2_State_Map_Path *)(**f).data; map_path = (LV2_State_Map_Path *)(**f).data;
else if (!strcmp((*f)->URI, LV2_STATE__freePath))
free_path = (LV2_State_Free_Path *)(**f).data;
} }
const char *path; const char *path;
@ -1042,7 +1062,7 @@ save(LV2_Handle instance,
self->atom_path_uri, self->atom_path_uri,
LV2_STATE_IS_POD); LV2_STATE_IS_POD);
if (map_path) if (map_path)
free((char *)path); free_path->free_path(free_path->handle, (char *)path);
// Save the scala file path // Save the scala file path
path = self->scala_file_path; path = self->scala_file_path;
@ -1061,7 +1081,7 @@ save(LV2_Handle instance,
self->atom_path_uri, self->atom_path_uri,
LV2_STATE_IS_POD); LV2_STATE_IS_POD);
if (map_path) if (map_path)
free((char *)path); free_path->free_path(free_path->handle, (char *)path);
// Save the number of voices // Save the number of voices
store(handle, store(handle,

View file

@ -67,7 +67,7 @@ midnam:update a lv2:Feature .
lv2:microVersion @LV2PLUGIN_VERSION_MICRO@ ; lv2:microVersion @LV2PLUGIN_VERSION_MICRO@ ;
lv2:requiredFeature urid:map, bufsize:boundedBlockLength, work:schedule ; lv2:requiredFeature urid:map, bufsize:boundedBlockLength, work:schedule ;
lv2:optionalFeature lv2:hardRTCapable, opts:options, state:mapPath ; lv2:optionalFeature lv2:hardRTCapable, opts:options, state:mapPath, state:freePath ;
lv2:extensionData opts:interface, state:interface, work:interface ; lv2:extensionData opts:interface, state:interface, work:interface ;
lv2:optionalFeature midnam:update ; lv2:optionalFeature midnam:update ;