Signed-off-by: falkTX <falktx@falktx.com>pull/421/head
@@ -506,93 +506,11 @@ struct ParameterEnumerationValue { | |||
#endif | |||
}; | |||
/** | |||
Collection of parameter enumeration values.@n | |||
Handy class to handle the lifetime and count of all enumeration values. | |||
*/ | |||
struct ParameterEnumerationValues { | |||
uint8_t count; | |||
bool deleteLater; | |||
const ParameterEnumerationValue* ptr; | |||
constexpr ParameterEnumerationValues() noexcept | |||
: count(0), | |||
deleteLater(false), | |||
ptr(nullptr) {} | |||
constexpr ParameterEnumerationValues(uint32_t c, const ParameterEnumerationValue* v) noexcept | |||
: count(c), | |||
deleteLater(false), | |||
ptr(v) {} | |||
// constexpr | |||
~ParameterEnumerationValues() noexcept | |||
{ | |||
if (deleteLater) | |||
delete[] ptr; | |||
} | |||
const ParameterEnumerationValue& operator[](const uint8_t index) const noexcept | |||
{ | |||
return ptr[index]; | |||
} | |||
template<uint8_t numValues> | |||
ParameterEnumerationValues& operator=(const ParameterEnumerationValue values[numValues]) noexcept | |||
{ | |||
if (deleteLater) | |||
delete[] ptr; | |||
count = numValues; | |||
ptr = values; | |||
deleteLater = true; | |||
return *this; | |||
} | |||
ParameterEnumerationValues& operator=(const ParameterEnumerationValues& other) noexcept | |||
{ | |||
if (deleteLater) | |||
delete[] ptr; | |||
count = 0; | |||
ptr = nullptr; | |||
deleteLater = false; | |||
if (other.ptr != nullptr && other.count != 0) | |||
{ | |||
ParameterEnumerationValue* ptr2; | |||
try { | |||
ptr2 = new ParameterEnumerationValue[other.count]; | |||
} DISTRHO_SAFE_EXCEPTION_RETURN("ParameterEnumerationValues::recreate", *this); | |||
for (uint8_t i=0; i<other.count; ++i) | |||
{ | |||
ptr2[i].value = other.ptr[i].value; | |||
ptr2[i].label = other.ptr[i].label; | |||
} | |||
count = other.count; | |||
ptr = ptr2; | |||
deleteLater = true; | |||
} | |||
return *this; | |||
} | |||
private: | |||
#ifdef DISTRHO_PROPER_CPP11_SUPPORT | |||
ParameterEnumerationValues(const ParameterEnumerationValues&) = delete; | |||
#else | |||
ParameterEnumerationValues(const ParameterEnumerationValues&); | |||
#endif | |||
}; | |||
/** | |||
Details around parameter enumeration values.@n | |||
Wraps ParameterEnumerationValues and provides a few extra details to the host about these values. | |||
*/ | |||
struct ParameterEnumerationDetails { | |||
struct ParameterEnumerationValues { | |||
/** | |||
Number of elements allocated in @values. | |||
*/ | |||
@@ -609,24 +527,36 @@ struct ParameterEnumerationDetails { | |||
Array of @ParameterEnumerationValue items.@n | |||
This pointer must be null or have been allocated on the heap with `new ParameterEnumerationValue[count]`. | |||
*/ | |||
ParameterEnumerationValues values; | |||
const ParameterEnumerationValue* values; | |||
/** | |||
Default constructor, for zero enumeration values. | |||
*/ | |||
constexpr ParameterEnumerationDetails() noexcept | |||
constexpr ParameterEnumerationValues() noexcept | |||
: count(0), | |||
restrictedMode(false), | |||
values() {} | |||
values(nullptr), | |||
deleteLater(true) {} | |||
/** | |||
Constructor using custom values.@n | |||
The pointer to @values must have been allocated on the heap with `new`. | |||
*/ | |||
constexpr ParameterEnumerationDetails(uint32_t c, bool r, const ParameterEnumerationValue* v) noexcept | |||
constexpr ParameterEnumerationValues(uint32_t c, bool r, const ParameterEnumerationValue* v) noexcept | |||
: count(c), | |||
restrictedMode(r), | |||
values(c, v) {} | |||
values(v), | |||
deleteLater(false) {} | |||
// constexpr | |||
~ParameterEnumerationValues() noexcept | |||
{ | |||
if (deleteLater) | |||
delete[] values; | |||
} | |||
private: | |||
bool deleteLater; | |||
}; | |||
/** | |||
@@ -683,9 +613,8 @@ struct Parameter { | |||
/** | |||
Enumeration details.@n | |||
Can be used to give meaning to parameter values, working as an enumeration. | |||
@todo rename to enumDetails | |||
*/ | |||
ParameterEnumerationDetails enumValues; | |||
ParameterEnumerationValues enumValues; | |||
/** | |||
Designation for this parameter. | |||
@@ -31,12 +31,11 @@ bool d_nextCanRequestParameterValueChanges = false; | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Static fallback data, see DistrhoPluginInternal.hpp */ | |||
const String PluginExporter::sFallbackString; | |||
/* */ AudioPortWithBusId PluginExporter::sFallbackAudioPort; | |||
const ParameterRanges PluginExporter::sFallbackRanges; | |||
const ParameterEnumerationDetails PluginExporter::sFallbackEnumDetails; | |||
const ParameterEnumerationValues PluginExporter::sFallbackEnumValues; | |||
const PortGroupWithId PluginExporter::sFallbackPortGroup; | |||
const String PluginExporter::sFallbackString; | |||
/* */ AudioPortWithBusId PluginExporter::sFallbackAudioPort; | |||
const ParameterRanges PluginExporter::sFallbackRanges; | |||
const ParameterEnumerationValues PluginExporter::sFallbackEnumValues; | |||
const PortGroupWithId PluginExporter::sFallbackPortGroup; | |||
/* ------------------------------------------------------------------------------------------------------------ | |||
* Plugin */ | |||
@@ -1181,9 +1181,9 @@ public: | |||
for (uint32_t i=0; i < enumValues.count; ++i) | |||
{ | |||
if (d_isEqual(static_cast<double>(enumValues.ptr[i].value), value)) | |||
if (d_isEqual(static_cast<double>(enumValues.values[i].value), value)) | |||
{ | |||
d_strncpy(display, enumValues.ptr[i].label, size); | |||
d_strncpy(display, enumValues.values[i].label, size); | |||
return true; | |||
} | |||
} | |||
@@ -1203,9 +1203,9 @@ public: | |||
for (uint32_t i=0; i < enumValues.count; ++i) | |||
{ | |||
if (std::strcmp(display, enumValues.ptr[i].label) == 0) | |||
if (std::strcmp(display, enumValues.values[i].label) == 0) | |||
{ | |||
*value = enumValues.ptr[i].value; | |||
*value = enumValues.values[i].value; | |||
return true; | |||
} | |||
} | |||
@@ -704,18 +704,11 @@ public: | |||
return fData->parameters[index].description; | |||
} | |||
const ParameterEnumerationDetails& getParameterEnumDetails(const uint32_t index) const noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackEnumDetails); | |||
return fData->parameters[index].enumValues; | |||
} | |||
const ParameterEnumerationValues& getParameterEnumValues(const uint32_t index) const noexcept | |||
{ | |||
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->parameterCount, sFallbackEnumValues); | |||
return fData->parameters[index].enumValues.values; | |||
return fData->parameters[index].enumValues; | |||
} | |||
const ParameterRanges& getParameterRanges(const uint32_t index) const noexcept | |||
@@ -1052,12 +1045,11 @@ private: | |||
// ------------------------------------------------------------------- | |||
// Static fallback data, see DistrhoPlugin.cpp | |||
static const String sFallbackString; | |||
static /* */ AudioPortWithBusId sFallbackAudioPort; | |||
static const ParameterRanges sFallbackRanges; | |||
static const ParameterEnumerationDetails sFallbackEnumDetails; | |||
static const ParameterEnumerationValues sFallbackEnumValues; | |||
static const PortGroupWithId sFallbackPortGroup; | |||
static const String sFallbackString; | |||
static /* */ AudioPortWithBusId sFallbackAudioPort; | |||
static const ParameterRanges sFallbackRanges; | |||
static const ParameterEnumerationValues sFallbackEnumValues; | |||
static const PortGroupWithId sFallbackPortGroup; | |||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginExporter) | |||
}; | |||
@@ -820,16 +820,16 @@ void lv2_generate_ttl(const char* const basename) | |||
} | |||
// enumeration | |||
const ParameterEnumerationDetails& enumDetails(plugin.getParameterEnumDetails(i)); | |||
const ParameterEnumerationValues& enumValues(plugin.getParameterEnumValues(i)); | |||
if (enumDetails.count > 0) | |||
if (enumValues.count > 0) | |||
{ | |||
if (enumDetails.count >= 2 && enumDetails.restrictedMode) | |||
if (enumValues.count >= 2 && enumValues.restrictedMode) | |||
pluginString += " lv2:portProperty lv2:enumeration ;\n"; | |||
for (uint8_t j=0; j < enumDetails.count; ++j) | |||
for (uint8_t j=0; j < enumValues.count; ++j) | |||
{ | |||
const ParameterEnumerationValue& enumValue(enumDetails.values[j]); | |||
const ParameterEnumerationValue& enumValue(enumValues.values[j]); | |||
if (j == 0) | |||
pluginString += " lv2:scalePoint [\n"; | |||
@@ -851,7 +851,7 @@ void lv2_generate_ttl(const char* const basename) | |||
pluginString += " rdf:value " + String(enumValue.value) + " ;\n"; | |||
} | |||
if (j+1 == enumDetails.count) | |||
if (j+1 == enumValues.count) | |||
pluginString += " ] ;\n"; | |||
else | |||
pluginString += " ] ,\n"; | |||
@@ -527,10 +527,10 @@ public: | |||
for (uint8_t i = 0; i < enumValues.count; ++i) | |||
{ | |||
if (d_isNotEqual(value, enumValues.ptr[i].value)) | |||
if (d_isNotEqual(value, enumValues.values[i].value)) | |||
continue; | |||
strncpy((char*)ptr, enumValues.ptr[i].label.buffer(), 24); | |||
strncpy((char*)ptr, enumValues.values[i].label.buffer(), 24); | |||
return 1; | |||
} | |||
@@ -1711,7 +1711,7 @@ public: | |||
// set up flags | |||
int32_t flags = 0; | |||
const ParameterEnumerationDetails& enumDetails(fPlugin.getParameterEnumDetails(index)); | |||
const ParameterEnumerationValues& enumValues(fPlugin.getParameterEnumValues(index)); | |||
const ParameterRanges& ranges(fPlugin.getParameterRanges(index)); | |||
const uint32_t hints = fPlugin.getParameterHints(index); | |||
@@ -1737,10 +1737,10 @@ public: | |||
else if (hints & kParameterIsInteger) | |||
step_count = ranges.max - ranges.min; | |||
if (enumDetails.count >= 2 && enumDetails.restrictedMode) | |||
if (enumValues.count >= 2 && enumValues.restrictedMode) | |||
{ | |||
flags |= V3_PARAM_IS_LIST; | |||
step_count = enumDetails.count - 1; | |||
step_count = enumValues.count - 1; | |||
} | |||
info->flags = flags; | |||
@@ -1810,9 +1810,9 @@ public: | |||
for (uint32_t i=0; i < enumValues.count; ++i) | |||
{ | |||
if (d_isEqual(enumValues.ptr[i].value, value)) | |||
if (d_isEqual(enumValues.values[i].value, value)) | |||
{ | |||
strncpy_utf16(output, enumValues.ptr[i].label, 128); | |||
strncpy_utf16(output, enumValues.values[i].label, 128); | |||
return V3_OK; | |||
} | |||
} | |||
@@ -1874,9 +1874,9 @@ public: | |||
for (uint32_t i=0; i < enumValues.count; ++i) | |||
{ | |||
if (strcmp_utf16(input, enumValues.ptr[i].label)) | |||
if (strcmp_utf16(input, enumValues.values[i].label)) | |||
{ | |||
*output = ranges.getNormalizedValue(enumValues.ptr[i].value); | |||
*output = ranges.getNormalizedValue(enumValues.values[i].value); | |||
return V3_OK; | |||
} | |||
} | |||