Attention! For Japanese customers, my Japanese blog might help.

Aug 4, 2016

Display a custom UI of my own v3 AudioUnit in host applications

This is the sequel article of previous one.

I was looking for the reason why my v3 AudioUnit can not display a custom UI in host apps such as AUv3Host or Hosting AU...

As as result, It is seemed that my AU needs to set preferredContentSize property.
In FilterDemo, the property seems to be set in viewDidLoad in FilterDemoViewController.
So, I also set the property as follows:
- (void) viewDidLoad {
    [super viewDidLoad];
    
    self.preferredContentSize = NSMakeSize(480272);
}
By the way, in the code which was generated when we added AudioUnit App Extension,
viewDidLoad implementation was
- (void) viewDidLoad {
    [super viewDidLoad];
    
    if (!audioUnit) {
        return;
    }
    
    // Get the parameter tree and add observers for any parameters that the UI needs to keep in sync with the AudioUnit
}
However,  because the audioUnit instance was always nil, the program immediately returns from viewDidLoad.
The audioUnit object is set in createAudioUnitWithComponentDescription:error:, which conforms to AUAudioUnitFactory protocol as follows:
- (AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
    audioUnit = [[MyAudioUnit allocinitWithComponentDescription:desc error:error];
    
    return audioUnit;
}
But, because viewDidLoad is called earlier than when createAudioUnitWithComponentDescription:error: is called, audioUnit property remains nil in viewDidLoad.

I doubt that codes automatically generated by AudioUnit App Extension target are strange (not qualified as standard AudioUnit).

I have wasted a time because I suspected auto layout or other factors.

Next, I want to add UIs to the custom view.