I'm trying to develop v3 Audio Unit Extensions for MacOS. I'll have several of these and so I'd like to create a reusable window/panel architecture that contains buttons like Process, Cancel, Bypass... these buttons should be the same for any audio unit chosen. I want to load the audio unit UI within a container view in that window/panel template. Something like the following:
Window/Panel Template
...............................................
| |
| ................................ |
| | | |
| | container view | |
| | AU UI goes here | |
| | | |
| ............................... |
| |
| Button 1. Button 2 |
...............................................
I'm instantiating the audio unit successfully and calling requestViewControllerWithCompletionHandler to get the Audio Unit UI. Then I'm adding the returned auViewController as a childViewController to the window's view controller and adding the auViewController.view as a subview of the containerView. This doesn't work and I can't figure out why. The returned auViewController is of type AURemoteAudioUnitViewController... not my audio unit's view controller class. Note sure if that has anything to do with it, but I don't seem to be touching my class at all. The code is below.
Note that, if I set the window controller's contentViewController to the auViewController returned by requestViewControllerWithCompletionHandler (i.e. auwindowController.contentViewController = auViewController) it does work. I can see the audio unit's UI and control the sound using params in real-time. All seems to be fine except that I can't seem to figure out how to embed the audio unit UI into a view container of another window. Am I going about this the wrong way? Any help would be greatly appreciated!
// CODE
[AVAudioUnit instantiateWithComponentDescription: description options: kAudioComponentInstantiationLoadOutOfProcess
completionHandler:^(AVAudioUnit* audioUnit, NSError *error)
{
if(error == noErr)
{
if(YES == [[audioUnit AUAudioUnit] providesUserInterface])
{
[[audioUnit AUAudioUnit] requestViewControllerWithCompletionHandler: ^(AUViewControllerBase *auViewController)
{
NSStoryboard *austoryboard = [NSStoryboard storyboardWithName:@"AUPluginWindow" bundle:nil];
AUWindowController *auwindowController = [austoryboard instantiateControllerWithIdentifier:@"AUWindowController"];
AUPanelViewController *aupanelViewController = (AUPanelViewController*)auwindowController.contentViewController;
NSWindow *auWindow = [auwindowController window];
[auWindow setFrame: NSMakeRect(100, 100, 600, 300) display: YES];
[auWindow makeKeyAndOrderFront: self];
// get containerView - IBOutlet in AUPanelViewController
NSView *containerView = [aupanelViewController getContainerView];
// Add the AudioUnitViewController as child to the window's view controller
[aupanelViewController addChildViewController: auViewController];
[[auViewController view] setFrame: containerView.bounds ];
// add audio unit view as subview to containerView
[containerView addSubview: auViewController.view];
}];
}
}
else
NSLog(@"Error instantiating audio unit");
}];
Window/Panel Template
...............................................
| |
| ................................ |
| | | |
| | container view | |
| | AU UI goes here | |
| | | |
| ............................... |
| |
| Button 1. Button 2 |
...............................................
I'm instantiating the audio unit successfully and calling requestViewControllerWithCompletionHandler to get the Audio Unit UI. Then I'm adding the returned auViewController as a childViewController to the window's view controller and adding the auViewController.view as a subview of the containerView. This doesn't work and I can't figure out why. The returned auViewController is of type AURemoteAudioUnitViewController... not my audio unit's view controller class. Note sure if that has anything to do with it, but I don't seem to be touching my class at all. The code is below.
Note that, if I set the window controller's contentViewController to the auViewController returned by requestViewControllerWithCompletionHandler (i.e. auwindowController.contentViewController = auViewController) it does work. I can see the audio unit's UI and control the sound using params in real-time. All seems to be fine except that I can't seem to figure out how to embed the audio unit UI into a view container of another window. Am I going about this the wrong way? Any help would be greatly appreciated!
// CODE
[AVAudioUnit instantiateWithComponentDescription: description options: kAudioComponentInstantiationLoadOutOfProcess
completionHandler:^(AVAudioUnit* audioUnit, NSError *error)
{
if(error == noErr)
{
if(YES == [[audioUnit AUAudioUnit] providesUserInterface])
{
[[audioUnit AUAudioUnit] requestViewControllerWithCompletionHandler: ^(AUViewControllerBase *auViewController)
{
NSStoryboard *austoryboard = [NSStoryboard storyboardWithName:@"AUPluginWindow" bundle:nil];
AUWindowController *auwindowController = [austoryboard instantiateControllerWithIdentifier:@"AUWindowController"];
AUPanelViewController *aupanelViewController = (AUPanelViewController*)auwindowController.contentViewController;
NSWindow *auWindow = [auwindowController window];
[auWindow setFrame: NSMakeRect(100, 100, 600, 300) display: YES];
[auWindow makeKeyAndOrderFront: self];
// get containerView - IBOutlet in AUPanelViewController
NSView *containerView = [aupanelViewController getContainerView];
// Add the AudioUnitViewController as child to the window's view controller
[aupanelViewController addChildViewController: auViewController];
[[auViewController view] setFrame: containerView.bounds ];
// add audio unit view as subview to containerView
[containerView addSubview: auViewController.view];
}];
}
}
else
NSLog(@"Error instantiating audio unit");
}];