# Hosted AudioUnit editors not updating (fix included)

**URL:** <https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832>\
**Category:** Audio Plugins\
**Created:** [June 14, 2012, 9:43am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832 "2012-06-14T09:43:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [June 14, 2012, 9:43am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/1 "2012-06-14T09:43:23Z")

</div>

I’ve got an issue where the editors of AudioUnit plugins hosted in my [Pedalboard](http://www.niallmoody.com/apps/pedalboard2) 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)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 14, 2012, 12:44pm UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/2 "2012-06-14T12:44:06Z")

</div>

Sounds odd. Have you tried it in different hosts?

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [June 15, 2012, 10:21am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/3 "2012-06-15T10:21:04Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 15, 2012, 10:31am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/4 "2012-06-15T10:31:35Z")

</div>

> [@](#):
>
> (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…

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [June 21, 2012, 9:50am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/5 "2012-06-21T09:50:01Z")

</div>

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:

[code]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);
	}
}

```

[/code]  
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):

[code]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));
}[/code]

```

[code]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));
	}
}[/code]

```

[edit][The technical note that details this (partly).](https://developer.apple.com/library/mac/#technotes/tn2104/_index.html)[/edit]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 25, 2012, 11:09am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/6 "2012-06-25T11:09:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![NiallM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/niallm/32/293_2.png) [@NiallM](https://forum.juce.com/u/NiallM)\
**Post date:** [June 28, 2012, 8:45am UTC](https://forum.juce.com/t/hosted-audiounit-editors-not-updating-fix-included/8832/7 "2012-06-28T08:45:39Z")

</div>

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