From a268860713ba78f67f23da943aacf81fd3b846f4 Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Wed, 18 Dec 2019 17:30:39 +0000 Subject: [PATCH] AU: Improved the behaviour of setting and recalling presets --- .../juce_AudioUnitPluginFormat.mm | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm index 475d5eaa2b2f..0136e58bafeb 100644 --- a/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm +++ b/modules/juce_audio_processors/format_types/juce_AudioUnitPluginFormat.mm @@ -1256,7 +1256,18 @@ void setCurrentProgram (int newIndex) override { AUPreset current; current.presetNumber = newIndex; - current.presetName = CFSTR(""); + + CFArrayRef presets; + UInt32 sz = sizeof (CFArrayRef); + + if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_FactoryPresets, + kAudioUnitScope_Global, 0, &presets, &sz) == noErr) + { + if (auto* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, newIndex)) + current.presetName = p->presetName; + + CFRelease (presets); + } AudioUnitSetProperty (audioUnit, kAudioUnitProperty_PresentPreset, kAudioUnitScope_Global, 0, ¤t, sizeof (AUPreset)); @@ -1270,12 +1281,25 @@ const String getProgramName (int index) override CFArrayRef presets; UInt32 sz = sizeof (CFArrayRef); - if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_FactoryPresets, - kAudioUnitScope_Global, 0, &presets, &sz) == noErr) + if (index == -1) + { + AUPreset current; + current.presetNumber = -1; + current.presetName = CFSTR(""); + + UInt32 prstsz = sizeof (AUPreset); + + AudioUnitGetProperty (audioUnit, kAudioUnitProperty_PresentPreset, + kAudioUnitScope_Global, 0, ¤t, &prstsz); + + s = String::fromCFString (current.presetName); + } + else if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_FactoryPresets, + kAudioUnitScope_Global, 0, &presets, &sz) == noErr) { for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i) { - if (const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i)) + if (auto* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i)) { if (p->presetNumber == index) { @@ -1808,14 +1832,23 @@ void eventCallback (const AudioUnitEvent& event, AudioUnitParameterValue newValu default: if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_ParameterList) + { updateHostDisplay(); + } else if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_PresentPreset) + { sendAllParametersChangedEvents(); + updateHostDisplay(); + } else if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_Latency) + { updateLatency(); + } else if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_BypassEffect) + { if (bypassParam != nullptr) bypassParam->setValueNotifyingHost (bypassParam->getValue()); + } break; }