Skip to content

Commit

Permalink
Avoid duplicated LV2_State_{Map,Free}_Path features to
Browse files Browse the repository at this point in the history
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 <region>
files to an archive/zip (*.qtz) session file, an old feature
applicable to LV2 plugins.

See also: rncbc/qtractor#427
  • Loading branch information
rncbc authored and paulfd committed Jan 16, 2024
1 parent 2a45d4b commit 35bc2ab
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/lv2/sfizz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 35bc2ab

Please sign in to comment.