Skip to content

Commit

Permalink
LV2: check feature arrays for duplicated entries (which is a host bug)
Browse files Browse the repository at this point in the history
 - rncbc/qtractor#427

Signed-off-by: Stefan Westerfeld <[email protected]>
  • Loading branch information
swesterfeld committed Dec 16, 2023
1 parent 923d71c commit ad351b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lv2/smlv2common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#endif

#include <string>
#include <set>

#define SPECTMORPH_URI "http://spectmorph.org/plugins/spectmorph"
#define SPECTMORPH_UI_URI SPECTMORPH_URI "#ui"
Expand Down Expand Up @@ -102,6 +103,23 @@ public:
uris.time_speed = map->map (map->handle, LV2_TIME__speed);
uris.time_Position = map->map (map->handle, LV2_TIME__Position);
}
static void
detect_repeated_features (const LV2_Feature* const* features)
{
std::set<std::string> has_feature;
for (int i = 0; features[i]; i++)
{
if (has_feature.count (features[i]->URI))
{
fprintf (stderr, "SpectMorph: LV2 Plugin: feature '%s' is provided more than once by host\n", features[i]->URI);
fprintf (stderr, " -> this is a host bug, possibly related to https://github.com/rncbc/qtractor/issues/427\n");
}
else
{
has_feature.insert (features[i]->URI);
}
}
}
};

}
Expand Down
6 changes: 6 additions & 0 deletions lv2/smlv2plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ instantiate (const LV2_Descriptor* descriptor,

LV2Plugin *self = new LV2Plugin (rate);

LV2Common::detect_repeated_features (features);

LV2_URID_Map* map = NULL;
for (int i = 0; features[i]; i++)
{
Expand Down Expand Up @@ -285,6 +287,8 @@ save(LV2_Handle instance,
{
LV2Plugin* self = static_cast <LV2Plugin *> (instance);

LV2Common::detect_repeated_features (features);

LV2_State_Map_Path *map_path = nullptr;
#ifdef LV2_STATE__freePath
LV2_State_Free_Path *free_path = nullptr;
Expand Down Expand Up @@ -370,6 +374,8 @@ restore(LV2_Handle instance,
uint32_t valflags;
const void* value;

LV2Common::detect_repeated_features (features);

LV2_State_Map_Path *map_path = nullptr;
#ifdef LV2_STATE__freePath
LV2_State_Free_Path *free_path = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions lv2/smlv2ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ instantiate(const LV2UI_Descriptor* descriptor,

LV2_DEBUG ("instantiate called for ui\n");

LV2Common::detect_repeated_features (features);

LV2Plugin *plugin = nullptr;
PuglNativeWindow parent_win_id = 0;
LV2_URID_Map* map = nullptr;
Expand Down

0 comments on commit ad351b0

Please sign in to comment.