AU presets load-save problem + fix


#1

Hi Jules,

the audiounit wrapper has an error loading and saving presets since the changes for supporting both presets and banks. I am using 1.44 but I assume this is still the same for juce 1.45.

Since AU saves individual presets and not banks the wrapper methods should be changed as follows:

ComponentResult SaveState (CFPropertyListRef* outData)
{
ComponentResult err = AUMIDIEffectBase::SaveState (outData);

    if (err != noErr)
        return err;

    jassert (CFGetTypeID (*outData) == CFDictionaryGetTypeID());

    CFMutableDictionaryRef dict = (CFMutableDictionaryRef) *outData;

    if (juceFilter != 0)
    {
        JUCE_NAMESPACE::MemoryBlock state;
        //juceFilter->getStateInformation (state);
		//kk corrected to save au presets properly
		juceFilter->getCurrentProgramStateInformation(state);

        if (state.getSize() > 0)
        {
            CFDataRef ourState = CFDataCreate (kCFAllocatorDefault, (const uint8*) state, state.getSize());
            CFDictionarySetValue (dict, CFSTR("jucePluginState"), ourState);
            CFRelease (ourState);
        }
    }

    return noErr;
}

ComponentResult RestoreState (CFPropertyListRef inData)
{
    ComponentResult err = AUMIDIEffectBase::RestoreState (inData);

    if (err != noErr)
        return err;

    if (juceFilter != 0)
    {
        CFDictionaryRef dict = (CFDictionaryRef) inData;
        CFDataRef data = 0;

        if (CFDictionaryGetValueIfPresent (dict, CFSTR("jucePluginState"),
                                           (const void**) &data))
        {
            if (data != 0)
            {
                const int numBytes = (int) CFDataGetLength (data);
                const uint8* const rawBytes = CFDataGetBytePtr (data);

                if (numBytes > 0)
                    //juceFilter->setStateInformation (rawBytes, numBytes);
					// kk corrected to load correctly au presets
					juceFilter->setCurrentProgramStateInformation (rawBytes, numBytes);

            }
        }
    }

    return noErr;
}

The vst wrapper methods are correct. Just for reference

VstInt32 getChunk (void** data, bool onlyStoreCurrentProgramData)
{
chunkMemory.setSize (0);
if (onlyStoreCurrentProgramData)
filter->getCurrentProgramStateInformation (chunkMemory);
else
filter->getStateInformation (chunkMemory);

    *data = (void*) chunkMemory;

    // because the chunk is only needed temporarily by the host (or at least you'd
    // hope so) we'll give it a while and then free it in the timer callback.
    chunkMemoryTime = JUCE_NAMESPACE::Time::getApproximateMillisecondCounter();

    return chunkMemory.getSize();
}

you will need also to change the demo plugin to use the
getCurrentProgramStateInformation
for the preset example included.

Regards
Kyriacos


#2

Ok, thanks Kyriacos, I’ll tweak that!


#3