1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AU Host: Avoid caching parameter value strings when getNumSteps() returns a large value

This commit is contained in:
reuk 2025-06-03 14:45:22 +01:00
parent 15f05443d0
commit b349531966
No known key found for this signature in database

View file

@ -627,7 +627,8 @@ public:
valueLabel (label),
defaultValue (normaliseParamValue (defaultParameterValue))
{
auValueStrings = Parameter::getAllValueStrings();
if (getNumSteps() <= maxStringsToCache)
auValueStrings = getDiscreteValueStrings();
}
float getValue() const override
@ -747,7 +748,15 @@ public:
StringArray getAllValueStrings() const override
{
return auValueStrings;
if (! auValueStrings.isEmpty())
return auValueStrings;
// If this is hit, the returned array of strings is going to be very large!
// Consider alternative approaches - perhaps you could fetch value strings
// one-at-a-time to avoid needing to have all the strings in memory simultaneously.
jassert (getNumSteps() <= maxStringsToCache);
return getDiscreteValueStrings();
}
String getParameterID() const override
@ -787,6 +796,23 @@ public:
void setLabel (String&& newLabel) { valueLabel = std::move (newLabel); }
private:
static constexpr auto maxStringsToCache = 10'000;
StringArray getDiscreteValueStrings() const
{
if (! isDiscrete())
return {};
StringArray result;
const auto maxIndex = getNumSteps() - 1;
for (int i = 0; i < getNumSteps(); ++i)
result.add (getText ((float) i / (float) maxIndex, 1024));
return result;
}
AudioUnitPluginInstance& pluginInstance;
const UInt32 paramID;
String name;