From 110d6feecf915bfb6c7326e29fca13a2450d9434 Mon Sep 17 00:00:00 2001 From: 2bit Date: Wed, 13 Sep 2023 15:53:20 +0900 Subject: [PATCH] draft --- src/ofxAudioUnitCocoaUtilties.mm | 53 ++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/ofxAudioUnitCocoaUtilties.mm b/src/ofxAudioUnitCocoaUtilties.mm index 389777b..2e221e2 100644 --- a/src/ofxAudioUnitCocoaUtilties.mm +++ b/src/ofxAudioUnitCocoaUtilties.mm @@ -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; @@ -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 @@ -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 factoryInstance = [[[factoryClass alloc] init] autorelease]; + Class factoryClass = [viewBundle classNamed:(__bridge NSString *)factoryClassName]; + id factoryInstance = OF_OBJC_AUTORELEASE([[factoryClass alloc] init]); AUView = [factoryInstance uiViewForAudioUnit:unit withSize:NSZeroSize]; } } @@ -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 | @@ -128,6 +140,7 @@ - (void) initWithAudioUnitCocoaView:(NSView *)audioUnitView name:NSViewFrameDidChangeNotification object:_AUView]; } + return self; } // ----------------------------------------------------------