Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions src/ofxAudioUnitCocoaUtilties.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@

#pragma mark Objective-C


#if __has_feature(objc_arc)
# define OF_OBJC_DEALLOC(obj)
# define OF_OBJC_RELEASE(obj) obj
# define OF_OBJC_RETAIN(obj) obj
# define OF_OBJC_AUTORELEASE(obj) obj
#else
# define OF_OBJC_DEALLOC(obj) [obj dealloc]
# define OF_OBJC_RELEASE(obj) [obj release]
# define OF_OBJC_RETAIN(obj) [obj retain]
# define OF_OBJC_AUTORELEASE(obj) [obj autorelease]
#endif

@interface ofxAudioUnitUIWindow : NSWindow
{
NSView * _AUView;
__strong NSView * _AUView;
}

- (id) initWithAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)useGeneric;
Expand All @@ -25,30 +38,30 @@ - (void) dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSViewFrameDidChangeNotification
object:_AUView];
[super dealloc];
OF_OBJC_RELEASE(_AUView);
OF_OBJC_DEALLOC(super);
}

// ----------------------------------------------------------
- (id) initWithAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)useGeneric
- (instancetype) initWithAudioUnit:(AudioUnit)unit forceGeneric:(BOOL)useGeneric
// ----------------------------------------------------------
{
if(useGeneric) {
[self initWithGenericViewForUnit:unit];
return [self initWithGenericViewForUnit:unit];
} else if([ofxAudioUnitUIWindow audioUnitHasCocoaView:unit]) {
if(![self initWithCocoaViewForUnit:unit]) {
return nil;
}
return [self initWithCocoaViewForUnit:unit];
} else if([ofxAudioUnitUIWindow audioUnitHasCarbonView:unit]) {
[self printUnsupportedCarbonMessage:unit];
return nil;
} else {
[self initWithGenericViewForUnit:unit];
return [self initWithGenericViewForUnit:unit];
}

return self;
}

// ----------------------------------------------------------
- (BOOL) initWithCocoaViewForUnit:(AudioUnit)unit
- (instancetype) initWithCocoaViewForUnit:(AudioUnit)unit
// ----------------------------------------------------------
{
// getting the size of the AU View info
Expand Down Expand Up @@ -76,11 +89,11 @@ - (BOOL) initWithCocoaViewForUnit:(AudioUnit)unit
if(success == noErr && cocoaViewInfo) {
CFURLRef cocoaViewBundlePath = cocoaViewInfo->mCocoaAUViewBundleLocation;
CFStringRef factoryClassName = cocoaViewInfo->mCocoaAUViewClass[0];
NSBundle * viewBundle = [NSBundle bundleWithURL:(NSURL *)cocoaViewBundlePath];
NSBundle * viewBundle = [NSBundle bundleWithURL:(__bridge NSURL *)cocoaViewBundlePath];

if(viewBundle) {
Class factoryClass = [viewBundle classNamed:(NSString *)factoryClassName];
id<AUCocoaUIBase> factoryInstance = [[[factoryClass alloc] init] autorelease];
Class factoryClass = [viewBundle classNamed:(__bridge NSString *)factoryClassName];
id<AUCocoaUIBase> factoryInstance = OF_OBJC_AUTORELEASE([[factoryClass alloc] init]);
AUView = [factoryInstance uiViewForAudioUnit:unit withSize:NSZeroSize];
}
}
Expand All @@ -89,28 +102,27 @@ - (BOOL) initWithCocoaViewForUnit:(AudioUnit)unit
}

if(AUView) {
[self initWithAudioUnitCocoaView:AUView];
return YES;
return [self initWithAudioUnitCocoaView:AUView];
} else {
NSLog(@"Failed to create AU view");
return NO;
return nil;
}
}

// ----------------------------------------------------------
- (void) initWithGenericViewForUnit:(AudioUnit)unit
- (instancetype) initWithGenericViewForUnit:(AudioUnit)unit
// ----------------------------------------------------------
{
AUGenericView * AUView = [[[AUGenericView alloc] initWithAudioUnit:unit] autorelease];
AUGenericView * AUView = OF_OBJC_AUTORELEASE([[AUGenericView alloc] initWithAudioUnit:unit]);
[AUView setShowsExpertParameters:YES];
[self initWithAudioUnitCocoaView:AUView];
return [self initWithAudioUnitCocoaView:AUView];
}

// ----------------------------------------------------------
- (void) initWithAudioUnitCocoaView:(NSView *)audioUnitView
- (instancetype) initWithAudioUnitCocoaView:(NSView *)audioUnitView
// ----------------------------------------------------------
{
_AUView = [audioUnitView retain];
_AUView = OF_OBJC_RETAIN(audioUnitView);
NSRect contentRect = NSMakeRect(0, 0, audioUnitView.frame.size.width, audioUnitView.frame.size.height);
self = [super initWithContentRect:contentRect
styleMask:(NSTitledWindowMask |
Expand All @@ -128,6 +140,7 @@ - (void) initWithAudioUnitCocoaView:(NSView *)audioUnitView
name:NSViewFrameDidChangeNotification
object:_AUView];
}
return self;
}

// ----------------------------------------------------------
Expand Down