Re: Crashing when loading 3rd party AU
Re: Crashing when loading 3rd party AU
- Subject: Re: Crashing when loading 3rd party AU
- From: Chris Reed <email@hidden>
- Date: Thu, 17 Oct 2002 11:00:37 -0500
On Thursday, October 17, 2002, at 05:27 am, Doug Wyatt wrote:
On Wednesday, Oct 16, 2002, at 18:07 America/New_York, Robert Grant
wrote:
Unfortunately none of these are exposing presets and I've yet to
figure out how to
create a window in Cocoa that's suitable for their Carbon views. Any
assistance in that
area would be appreciated.
http://developer.apple.com/techpubs/macosx/Essentials/CarbonCocoaDoc/
cci_chap3/index.html
(Coincidentally I was just looking at this yesterday morning)
Doug
And more specifically, here's my AUEditController class. It's a
subclass of NSWindowController that creates a carbon edit window for an
AudioUnit and then creates an NSWindow object for the carbon window,
which it then sets as the window controller's window.
Note: this is not completely tested and polished code! And there are
some problems that have yet to be worked out with the custom GUI code
in Urs Heckmann's Rumblence AU. But the core code here is pretty much
copied from AUViewTest.
-chris
@interface AUEditController : NSWindowController
{
AudioUnit editUnit;
AudioUnitCarbonView editView;
WindowRef carbonWindow;
}
+ editorForAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)forceGeneric;
- initWithAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)forceGeneric;
@end
@implementation AUEditController
+ editorForAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)forceGeneric
{
return [[[[self class] alloc] initWithAudioUnit:unit
forceGeneric:forceGeneric] autorelease];
}
- initWithAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)forceGeneric
{
self = [super initWithWindow:nil];
if (self)
{
editUnit = unit;
OSStatus err;
ComponentDescription desc;
// set up to use generic UI component
desc.componentType = kAudioUnitCarbonViewComponentType;
desc.componentSubType = 'gnrc';
desc.componentManufacturer = 'appl';
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
if (!forceGeneric) {
// ask the AU for its first editor component
UInt32 propertySize;
err = AudioUnitGetPropertyInfo(editUnit,
kAudioUnitProperty_GetUIComponentList,
kAudioUnitScope_Global, 0, &propertySize, NULL);
if (!err) {
int nEditors = propertySize / sizeof(ComponentDescription);
ComponentDescription *editors = new ComponentDescription[nEditors];
err = AudioUnitGetProperty(editUnit,
kAudioUnitProperty_GetUIComponentList,
kAudioUnitScope_Global, 0, editors, &propertySize);
if (!err)
// just pick the first one for now
desc = editors[0];
delete[] editors;
}
}
Component editComponent = FindNextComponent(NULL, &desc);
OpenAComponent(editComponent, &editView);
if (!editView)
[NSException raise:NSGenericException format:@"could not open audio
unit editor component"];
// load the carbon window from the bundle
static CFBundleRef bundleRef = NULL;
static IBNibRef nibRef = NULL;
if (!bundleRef)
bundleRef = CFBundleGetMainBundle();
if (!nibRef)
{
err = CreateNibReferenceWithCFBundle(bundleRef,
CFSTR("CarbonEditorWindow"), &nibRef);
if (err!=noErr)
NSLog(@"failed to create carbon nib reference");
}
// CFRelease(bundleRef);
err = CreateWindowFromNib(nibRef, CFSTR("EditWindow"),
&carbonWindow);
if (err != noErr)
{
NSLog(@"failed to create carbon window from nib");
return nil;
}
// DisposeNibReference(nibRef);
// create the edit view
ControlRef rootControl;
GetRootControl(carbonWindow, &rootControl);
if (!rootControl)
{
NSLog(@"could not get root control of carbon window");
return nil;
}
Rect bounds;
ControlRef viewPane;
GetControlBounds(rootControl, &bounds);
Float32Point location = { 0., 0. };
Float32Point size = { Float32(bounds.right), Float32(bounds.bottom) };
AudioUnitCarbonViewCreate(editView, editUnit, carbonWindow,
rootControl, &location, &size, &viewPane);
// resize window
GetControlBounds(viewPane, &bounds);
size.x = bounds.right-bounds.left;
size.y = bounds.bottom-bounds.top;
SizeWindow(carbonWindow, short(size.x + 0.5), short(size.y + 0.5),
true);
// create the cocoa window for the carbon one and make it visible
NSWindow *cocoaWindow = [[NSWindow alloc]
initWithWindowRef:carbonWindow];
[self setWindow:cocoaWindow];
[cocoaWindow setIsVisible:YES];
}
return self;
}
- (void)dealloc
{
[self setWindow:nil];
if (editView)
CloseComponent(editView);
if (carbonWindow)
DisposeWindow(carbonWindow);
[super dealloc];
}
@end
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.