diff --git a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm index 0238deb33e..546b61cee7 100644 --- a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm +++ b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm @@ -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;