Hosted AudioUnit editors not updating (fix included)

7 posts / 0 new
Last post
NiallM
Offline
Last seen: 8 months 1 week ago
Joined: 6 Sep 2004 - 10:28
Hosted AudioUnit editors not updating (fix included)

I've got an issue where the editors of AudioUnit plugins hosted in my Pedalboard app don't get updated when their parameters change (either via preset selection or with individual parameters being changed via MIDI). I don't have any problems with VST plugins.

I've tried calling repaint() on the editor, but that doesn't seem to work either. Is there something specific I need to do to update AudioUnit editors?

(I should note that I'm still on OSX 10.6 and XCode 3; I was hoping I could hold off on upgrading until I got this latest release out)

(also, doing some testing it turns out previous versions of my Pedalboard had the same issue, I just hadn't noticed it; so it's not a recent thing)

Edited by: NiallM on 21 Jun 2012 - 10:50
jules
Offline
Last seen: 10 hours 10 min ago
Joined: 29 Apr 2013 - 18:37
Re: Hosted AudioUnit editors not updating

Sounds odd. Have you tried it in different hosts?

NiallM
Offline
Last seen: 8 months 1 week ago
Joined: 6 Sep 2004 - 10:28
Re: Hosted AudioUnit editors not updating

Well, running the plugins I've been testing with (the default Apple ones, plus AudioDamage's Fuzz+) in AULab, their editors update as expected when you change their preset. I don't think it's a problem with specific plugins though?

(to be clear, my app's a host, not a plugin)

jules
Offline
Last seen: 10 hours 10 min ago
Joined: 29 Apr 2013 - 18:37
Re: Hosted AudioUnit editors not updating

Quote:
(to be clear, my app's a host, not a plugin)

Ok, gotcha.

Sorry.. don't really know then. It's the plugin's job to redraw its interface, I don't know what else you could do to make them do that..

NiallM
Offline
Last seen: 8 months 1 week ago
Joined: 6 Sep 2004 - 10:28
Re: Hosted AudioUnit editors not updating

Okay, it took some painful digging through apple's woeful documentation to figure this out, but the problem is that AudioUnitSetParameter does not notify the plugin's editor that a parameter has changed. To fix it, I've made the following changes to juce_AudioUnitPluginFormat.mm:

void setParameter (int index, float newValue)
    {
        const ScopedLock sl (lock);

        if (audioUnit != 0 && isPositiveAndBelow (index, parameterIds.size()))
		{
			AudioUnitEvent ev;

            AudioUnitSetParameter (audioUnit,
                                   (UInt32) parameterIds.getUnchecked (index),
                                   kAudioUnitScope_Global, 0,
                                   newValue, 0);

			ev.mEventType = kAudioUnitEvent_ParameterValueChange;
			ev.mArgument.mParameter.mAudioUnit = audioUnit;
			ev.mArgument.mParameter.mParameterID = (UInt32) parameterIds.getUnchecked (index);
			ev.mArgument.mParameter.mScope = kAudioUnitScope_Global;
			ev.mArgument.mParameter.mElement = 0;

			//Notify any listeners (i.e. the plugin's editor) that the parameter's been changed.
			AUEventListenerNotify(NULL, NULL, &ev);
		}
    }

And then to get the editor to update when the preset is changed, I did this (it's a bit hacky; I think there should be a way to do this with a single AUEventListenerNotify call, but I couldn't get that to work):
void setCurrentProgram (int newIndex)
    {
        AUPreset current;
        current.presetNumber = newIndex;
        current.presetName = CFSTR("");

        AudioUnitSetProperty (audioUnit, kAudioUnitProperty_PresentPreset,
                              kAudioUnitScope_Global, 0, &current, sizeof (AUPreset));
		
		for(int i=0;i<getNumParameters();++i)
			setParameter(i, getParameter(i));
    }

void setCurrentProgramStateInformation (const void* data, int sizeInBytes)
    {
        CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
                                                                    (const UInt8*) data,
                                                                    sizeInBytes,
                                                                    kCFAllocatorNull);
        CFReadStreamOpen (stream);

        CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
        CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
                                                                         stream,
                                                                         0,
                                                                         kCFPropertyListImmutable,
                                                                         &format,
                                                                         0);
        CFRelease (stream);

        if (propertyList != 0)
		{
            AudioUnitSetProperty (audioUnit,
                                  kAudioUnitProperty_ClassInfo,
                                  kAudioUnitScope_Global,
                                  0, &propertyList, sizeof (propertyList));

			for(int i=0;i<getNumParameters();++i)
				setParameter(i, getParameter(i));
		}
    }

[edit]The technical note that details this (partly).[/edit]
jules
Offline
Last seen: 10 hours 10 min ago
Joined: 29 Apr 2013 - 18:37
Re: Hosted AudioUnit editors not updating (fix included)

Thanks! Just taking a look at this, and have checked something in - would appreciate you trying it out and letting me know if it works!

NiallM
Offline
Last seen: 8 months 1 week ago
Joined: 6 Sep 2004 - 10:28
Re: Hosted AudioUnit editors not updating (fix included)

Just had a chance to check out your changes. It's working perfectly, thanks!