From d7f7bf98fafc34278af8cdf915d00d2c82b2f217 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 9 Aug 2023 20:30:06 +0100 Subject: [PATCH] AU Client: Tweak saved version number of presets before restoring to allow restoring AUv3 state --- .../juce_audio_plugin_client_AU_1.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_1.mm b/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_1.mm index a781b0f60c..7d6f7aa822 100644 --- a/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_1.mm +++ b/modules/juce_audio_plugin_client/juce_audio_plugin_client_AU_1.mm @@ -785,6 +785,27 @@ public: // Remove the data entry from the state to prevent the superclass loading the parameters CFUniquePtr copyWithoutData (CFDictionaryCreateMutableCopy (nullptr, 0, (CFDictionaryRef) inData)); CFDictionaryRemoveValue (copyWithoutData.get(), CFSTR (kAUPresetDataKey)); + + auto* originalVersion = static_cast (CFDictionaryGetValue (copyWithoutData.get(), CFSTR (kAUPresetVersionKey))); + if (originalVersion != nullptr && CFGetTypeID (originalVersion) == CFNumberGetTypeID()) + { + SInt32 value = 0; + CFNumberGetValue (originalVersion, kCFNumberSInt32Type, &value); + + // Data with a version of "1" is generated by AUv3 plug-ins. + // This data appears to be compatible with RestoreState below, but RestoreState + // fails when "version" is not 0. + // We only overwrite the version if it is 1 so that if future preset versions are + // completely incompatible, RestoreState will be bypassed rather than passed data + // which could put the plugin into a broken state. + if (value == 1) + { + const SInt32 zero = 0; + CFUniquePtr newVersion (CFNumberCreate (nullptr, kCFNumberSInt32Type, &zero)); + CFDictionarySetValue (copyWithoutData.get(), CFSTR (kAUPresetVersionKey), newVersion.get()); + } + } + ComponentResult err = MusicDeviceBase::RestoreState (copyWithoutData.get()); if (err != noErr)