Skip to content

Instantly share code, notes, and snippets.

@falkTX
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falkTX/31b0b6955a60bff9501c to your computer and use it in GitHub Desktop.
Save falkTX/31b0b6955a60bff9501c to your computer and use it in GitHub Desktop.
lv2 c++
// ------------------------------------------------------------------------------------------------------
// State
template<class FeatureStruct>
struct Feature
{
// pointer to feature struct
const FeatureStruct* self;
// wherever host supports this feature
bool valid;
// constructor
Feature(const LV2_Feature* const* features, const char* const uri)
: self(nullptr),
valid(false)
{
for (int i = 0; features[i] != nullptr; ++i)
{
if (std::strcmp(features[i]->URI, uri) != 0)
continue;
self = (const FeatureStruct*)features[i]->data;
valid = true;
break;
}
}
// destructor (needs to be declared for virtual classes)
virtual ~Feature() {}
};
// ------------------------------------------------------------------------------------------------------
// State
struct State_Make_Path : Feature<LV2_State_Make_Path>
{
// constructor
State_Make_Path(const LV2_Feature* const* features)
: Feature<LV2_State_Make_Path>(features, LV2_URID__map) {}
// docs for state make_path here
char* makePath(const char* path)
{
LV2_CHECK_FEATURE_RETURN(stateMakePath, nullptr);
return self->path(self->handle, path);
}
};
// ------------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment