From 35bc2ab6183aa815695e164805e0c041bf4eb4c6 Mon Sep 17 00:00:00 2001 From: rncbc Date: Tue, 16 Jan 2024 19:45:01 +0000 Subject: [PATCH] Avoid duplicated LV2_State_{Map,Free}_Path features to eg. lilv_state_new_from_instance(), when and if already provided by the caller/host (eg. qtractor). Resolves promised qtractor method to bundle all SFZ files to an archive/zip (*.qtz) session file, an old feature applicable to LV2 plugins. See also: https://github.com/rncbc/qtractor/issues/427 --- plugins/lv2/sfizz.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index 5655868d..721c0c76 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -1482,15 +1482,18 @@ restore(LV2_Handle instance, sfizz_plugin_t *self = (sfizz_plugin_t *)instance; LV2_State_Map_Path *map_path = NULL; - LV2_State_Free_Path *free_path = &sfizz_State_Free_Path; + LV2_State_Free_Path *free_path = NULL; for (const LV2_Feature *const *f = features; *f; ++f) { - if (!strcmp((*f)->URI, LV2_STATE__mapPath)) + if (!map_path && !strcmp((*f)->URI, LV2_STATE__mapPath)) map_path = (LV2_State_Map_Path *)(**f).data; - else if (!strcmp((*f)->URI, LV2_STATE__freePath)) + else if (!free_path && !strcmp((*f)->URI, LV2_STATE__freePath)) free_path = (LV2_State_Free_Path *)(**f).data; } + if (!free_path) + free_path = &sfizz_State_Free_Path; + // Set default values self->last_keyswitch = -1; sfizz_lv2_get_default_sfz_path(self, self->sfz_file_path, MAX_PATH_SIZE); @@ -1622,15 +1625,18 @@ save(LV2_Handle instance, sfizz_plugin_t *self = (sfizz_plugin_t *)instance; LV2_State_Map_Path *map_path = NULL; - LV2_State_Free_Path *free_path = &sfizz_State_Free_Path; + LV2_State_Free_Path *free_path = NULL; for (const LV2_Feature *const *f = features; *f; ++f) { - if (!strcmp((*f)->URI, LV2_STATE__mapPath)) + if (!map_path && !strcmp((*f)->URI, LV2_STATE__mapPath)) map_path = (LV2_State_Map_Path *)(**f).data; - else if (!strcmp((*f)->URI, LV2_STATE__freePath)) + else if (!free_path && !strcmp((*f)->URI, LV2_STATE__freePath)) free_path = (LV2_State_Free_Path *)(**f).data; } + if (!free_path) + free_path = &sfizz_State_Free_Path; + const char *path; // Save the file path