diff --git a/addons/ofxiOS/src/core/ofxiOSAppDelegate.h b/addons/ofxiOS/src/core/ofxiOSAppDelegate.h index 14e525e2285..0e8c1e530df 100644 --- a/addons/ofxiOS/src/core/ofxiOSAppDelegate.h +++ b/addons/ofxiOS/src/core/ofxiOSAppDelegate.h @@ -44,10 +44,10 @@ NSInteger currentScreenIndex; } -@property (nonatomic, retain) UIWindow * window; -@property (nonatomic, retain) UIWindow * externalWindow; -@property (nonatomic, retain) UIViewController * uiViewController; -@property (readonly, assign) NSInteger currentScreenIndex; +@property (nonatomic, strong) UIWindow * window; +@property (nonatomic, strong) UIWindow * externalWindow; +@property (nonatomic, strong) UIViewController * uiViewController; +@property (readonly) NSInteger currentScreenIndex; - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url; diff --git a/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm b/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm index d4fca9b81a0..67aab9449f4 100644 --- a/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm +++ b/addons/ofxiOS/src/core/ofxiOSAppDelegate.mm @@ -29,12 +29,13 @@ * * ***********************************************************************/ -#include "ofxiOSAppDelegate.h" +#import "ofxiOSAppDelegate.h" #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) -#include "ofxiOSViewController.h" -#include "ofxiOSExternalDisplay.h" +#import "ofxiOSViewController.h" +#import "ofxiOSGLKViewController.h" +#import "ofxiOSExternalDisplay.h" #include "ofxiOSExtras.h" #include "ofxiOSAlerts.h" #include "ofxiOSEAGLView.h" @@ -45,22 +46,17 @@ @implementation ofxiOSAppDelegate -@synthesize window; -@synthesize externalWindow; @synthesize currentScreenIndex; -@synthesize uiViewController; - - (void)dealloc { self.window = nil; self.externalWindow = nil; self.uiViewController = nil; - [super dealloc]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { - self.window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] autorelease]; + self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; [self.window makeKeyAndVisible]; currentScreenIndex = 0; @@ -145,11 +141,11 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application { case METAL_KIT: NSLog(@"No MetalKit yet supported for openFrameworks: Falling back to GLKit"); case GL_KIT: - self.uiViewController = (UIViewController*)[[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease]; + self.uiViewController = (UIViewController *)[[ofxiOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil]; break; case CORE_ANIMATION: default: - self.uiViewController = [[[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease]; + self.uiViewController = [[ofxiOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil]; break; } @@ -172,14 +168,22 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application { } if(!bDoesHWOrientation) { - if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) { - [self.uiViewController rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false]; - } + if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) { + ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController; + [controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false]; + } else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) { + ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController; + [controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false]; + } } else { [[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:NO]; - if([self.uiViewController respondsToSelector:@selector(rotateToInterfaceOrientation:animated:)]) { - [self.uiViewController rotateToInterfaceOrientation:interfaceOrientation animated:false]; - } + if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) { + ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController; + [controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false]; + } else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) { + ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController; + [controller rotateToInterfaceOrientation:UIInterfaceOrientationPortrait animated:false]; + } ofSetOrientation(requested); } @@ -239,11 +243,17 @@ - (void)receivedRotate:(NSNotification*)notification { if( [[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending ) { //iOS7- if(deviceOrientation != UIDeviceOrientationUnknown && deviceOrientation != UIDeviceOrientationFaceUp && deviceOrientation != UIDeviceOrientationFaceDown ) { - if([self.uiViewController respondsToSelector:@selector(isReadyToRotate)]) { - if([self.uiViewController isReadyToRotate]) { - ofxiOSAlerts.deviceOrientationChanged( deviceOrientation ); - } - } + if([self.uiViewController isKindOfClass:ofxiOSViewController.class]) { + ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController; + if([controller isReadyToRotate]) { + ofxiOSAlerts.deviceOrientationChanged( deviceOrientation ); + } + } else if([self.uiViewController isKindOfClass:ofxiOSGLKViewController.class]) { + ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController; + if([controller isReadyToRotate]) { + ofxiOSAlerts.deviceOrientationChanged( deviceOrientation ); + } + } } }else { ofxiOSAlerts.deviceOrientationChanged( deviceOrientation ); @@ -293,7 +303,7 @@ - (BOOL)createExternalWindowWithPreferredMode { externalScreenFrame = CGRectZero; externalScreenFrame.size = CGSizeMake(w, h); - self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease]; + self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame]; self.externalWindow.screen = externalScreen; self.externalWindow.clipsToBounds = YES; self.externalWindow.hidden = NO; @@ -331,7 +341,7 @@ - (BOOL)createExternalWindowWithScreenModeIndex:(NSInteger)screenModeIndex { externalScreenFrame = CGRectZero; externalScreenFrame.size = CGSizeMake(w, h); - self.externalWindow = [[[UIWindow alloc] initWithFrame:externalScreenFrame] autorelease]; + self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreenFrame]; self.externalWindow.screen = externalScreen; self.externalWindow.clipsToBounds = YES; self.externalWindow.hidden = NO; diff --git a/addons/ofxiOS/src/core/ofxiOSEAGLView.h b/addons/ofxiOS/src/core/ofxiOSEAGLView.h index 8887a3614d4..2546bc1f335 100644 --- a/addons/ofxiOS/src/core/ofxiOSEAGLView.h +++ b/addons/ofxiOS/src/core/ofxiOSEAGLView.h @@ -17,7 +17,7 @@ class ofAppiOSWindow; @interface ofxiOSEAGLView : EAGLView { @protected - NSMutableDictionary * activeTouches; + NSMutableDictionary *activeTouches; glm::vec2 * screenSize; // because glm::vec2 is forward declared, glm::vec2 * windowSize; // these values have to be pointers. glm::vec2 * windowPos; @@ -29,8 +29,8 @@ class ofAppiOSWindow; + (ofxiOSEAGLView *) getInstance; -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (void)setup; - (void)updateDimensions; - (void)destroy; diff --git a/addons/ofxiOS/src/core/ofxiOSEAGLView.mm b/addons/ofxiOS/src/core/ofxiOSEAGLView.mm index 7620ac65182..60c7a677e0e 100644 --- a/addons/ofxiOS/src/core/ofxiOSEAGLView.mm +++ b/addons/ofxiOS/src/core/ofxiOSEAGLView.mm @@ -34,12 +34,11 @@ + (ofxiOSEAGLView *) getInstance { return _instanceRef; } -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr { - [self initWithFrame:frame andApp:appPtr sharegroup:nil]; - return self; +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr { + return [self initWithFrame:frame andApp:appPtr sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup { +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup { window = dynamic_pointer_cast(ofGetMainLoop()->getCurrentWindow()); @@ -128,8 +127,7 @@ - (void)destroy { app = NULL; window = NULL; - [activeTouches release]; - + activeTouches = nil; delete screenSize; screenSize = NULL; delete windowSize; @@ -146,7 +144,6 @@ - (void)destroy { - (void)dealloc { [self destroy]; - [super dealloc]; } - (void)layoutSubviews { @@ -248,7 +245,7 @@ -(void) resetTouches { [activeTouches removeAllObjects]; } -- (void)touchesBegan:(NSSet *)touches +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ if(!bInit || !bSetup) { @@ -259,12 +256,12 @@ - (void)touchesBegan:(NSSet *)touches for(UITouch *touch in touches) { int touchIndex = 0; - while([[activeTouches allValues] containsObject:[NSNumber numberWithInt:touchIndex]]){ + while([[activeTouches allValues] containsObject:@(touchIndex)]){ touchIndex++; } - [activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]]; - + [activeTouches setObject:[NSNumber numberWithInt:touchIndex] + forKey:[NSValue valueWithPointer:(__bridge void *)touch]]; CGPoint touchPoint = [touch locationInView:self]; touchPoint.x *= scaleFactor; // this has to be done because retina still returns points in 320x240 but with high percision @@ -300,7 +297,7 @@ - (void)touchesMoved:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; CGPoint touchPoint = [touch locationInView:self]; @@ -332,9 +329,9 @@ - (void)touchesEnded:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; - [activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]]; + [activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]]; CGPoint touchPoint = [touch locationInView:self]; @@ -367,7 +364,7 @@ - (void)touchesCancelled:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; CGPoint touchPoint = [touch locationInView:self]; diff --git a/addons/ofxiOS/src/core/ofxiOSGLKView.h b/addons/ofxiOS/src/core/ofxiOSGLKView.h index 290c0ec0dff..5a930f51fc2 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKView.h +++ b/addons/ofxiOS/src/core/ofxiOSGLKView.h @@ -18,7 +18,7 @@ class ofAppiOSWindow; @interface ofxiOSGLKView : EAGLKView { @protected - NSMutableDictionary * activeTouches; + NSMutableDictionary * activeTouches; glm::vec2 * screenSize; // because glm::vec2 is forward declared, glm::vec2 * windowSize; // these values have to be pointers. glm::vec2 * windowPos; @@ -30,11 +30,11 @@ class ofAppiOSWindow; + (ofxiOSGLKView *) getInstance; -- (id)initWithFrame:(CGRect)frame - andApp:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame - andApp:(ofxiOSApp *)app - sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame + andApp:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame + andApp:(ofxiOSApp *)app + sharegroup:(EAGLSharegroup *)sharegroup; - (void)setup; - (void)update; - (void)draw; diff --git a/addons/ofxiOS/src/core/ofxiOSGLKView.mm b/addons/ofxiOS/src/core/ofxiOSGLKView.mm index 6025f3f2c71..7aac2d06616 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKView.mm +++ b/addons/ofxiOS/src/core/ofxiOSGLKView.mm @@ -34,11 +34,11 @@ + (ofxiOSGLKView *) getInstance { return _instanceRef; } -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr { +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr { return [self initWithFrame:frame andApp:appPtr sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{ +- (instancetype)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{ window = dynamic_pointer_cast(ofGetMainLoop()->getCurrentWindow()); @@ -128,8 +128,7 @@ - (void)destroy { app = NULL; window = NULL; - [activeTouches release]; - + activeTouches = nil; delete screenSize; screenSize = NULL; delete windowSize; @@ -146,7 +145,6 @@ - (void)destroy { - (void)dealloc { [self destroy]; - [super dealloc]; } - (void)layoutSubviews { @@ -270,7 +268,7 @@ - (void)touchesBegan:(NSSet *)touches touchIndex++; } - [activeTouches setObject:[NSNumber numberWithInt:touchIndex] forKey:[NSValue valueWithPointer:touch]]; + [activeTouches setObject:@(touchIndex) forKey:[NSValue valueWithPointer:(__bridge void *)touch]]; CGPoint touchPoint = [touch locationInView:self]; @@ -307,7 +305,7 @@ - (void)touchesMoved:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; CGPoint touchPoint = [touch locationInView:self]; @@ -339,9 +337,9 @@ - (void)touchesEnded:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; - [activeTouches removeObjectForKey:[NSValue valueWithPointer:touch]]; + [activeTouches removeObjectForKey:[NSValue valueWithPointer:(__bridge void *)touch]]; CGPoint touchPoint = [touch locationInView:self]; @@ -374,7 +372,7 @@ - (void)touchesCancelled:(NSSet *)touches } for(UITouch *touch in touches){ - int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:touch]] intValue]; + int touchIndex = [[activeTouches objectForKey:[NSValue valueWithPointer:(__bridge void *)touch]] intValue]; CGPoint touchPoint = [touch locationInView:self]; diff --git a/addons/ofxiOS/src/core/ofxiOSGLKViewController.h b/addons/ofxiOS/src/core/ofxiOSGLKViewController.h index 622f82ff719..6feec8efb63 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKViewController.h +++ b/addons/ofxiOS/src/core/ofxiOSGLKViewController.h @@ -21,10 +21,10 @@ class ofxiOSApp; @interface ofxiOSGLKViewController : GLKViewController -@property (nonatomic, retain) ofxiOSGLKView * glView; +@property (nonatomic, strong) ofxiOSGLKView * glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (UIInterfaceOrientation)currentInterfaceOrientation; - (void)setCurrentInterfaceOrientation:(UIInterfaceOrientation) orient; diff --git a/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm b/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm index 8d91ed88b56..be14fb59118 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm +++ b/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm @@ -27,11 +27,11 @@ @implementation ofxiOSGLKViewController @synthesize glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { return [self initWithFrame:frame app:app sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ currentInterfaceOrientation = pendingInterfaceOrientation = UIInterfaceOrientationPortrait; if((self = [super init])) { currentInterfaceOrientation = pendingInterfaceOrientation = self.interfaceOrientation; @@ -43,7 +43,7 @@ - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegrou bFirstUpdate = NO; bAnimated = NO; - self.glView = [[[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease]; + self.glView = [[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup]; self.glView.delegate = self; } @@ -54,8 +54,6 @@ - (void) dealloc { [self.glView removeFromSuperview]; self.glView.delegate = nil; self.glView = nil; - - [super dealloc]; } - (void)viewDidLoad { diff --git a/addons/ofxiOS/src/core/ofxiOSViewController.h b/addons/ofxiOS/src/core/ofxiOSViewController.h index 6e87d0a505e..dec71de8b31 100644 --- a/addons/ofxiOS/src/core/ofxiOSViewController.h +++ b/addons/ofxiOS/src/core/ofxiOSViewController.h @@ -15,10 +15,10 @@ class ofxiOSApp; @interface ofxiOSViewController : UIViewController -@property (nonatomic, retain) ofxiOSEAGLView * glView; +@property (nonatomic, strong) ofxiOSEAGLView * glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (UIInterfaceOrientation)currentInterfaceOrientation; - (void)setCurrentInterfaceOrientation:(UIInterfaceOrientation) orient; diff --git a/addons/ofxiOS/src/core/ofxiOSViewController.mm b/addons/ofxiOS/src/core/ofxiOSViewController.mm index fcf4d99d34b..9b1382e78ee 100644 --- a/addons/ofxiOS/src/core/ofxiOSViewController.mm +++ b/addons/ofxiOS/src/core/ofxiOSViewController.mm @@ -25,14 +25,11 @@ @interface ofxiOSViewController() { @implementation ofxiOSViewController -@synthesize glView; - -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { - [self initWithFrame:frame app:app sharegroup:nil]; - return self; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { + return [self initWithFrame:frame app:app sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ currentInterfaceOrientation = pendingInterfaceOrientation = UIInterfaceOrientationPortrait; if((self = [super init])) { currentInterfaceOrientation = pendingInterfaceOrientation = self.interfaceOrientation; @@ -43,7 +40,7 @@ - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegrou } bFirstUpdate = NO; bAnimated = NO; - self.glView = [[[ofxiOSEAGLView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease]; + self.glView = [[ofxiOSEAGLView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup]; [self.glView setMultipleTouchEnabled:ofxiOSGetOFWindow()->isMultiTouch()]; self.glView.delegate = self; @@ -57,8 +54,6 @@ - (void) dealloc { [self.glView removeFromSuperview]; self.glView.delegate = nil; self.glView = nil; - - [super dealloc]; } - (void)viewDidLoad { diff --git a/addons/ofxiOS/src/gl/EAGLKView.h b/addons/ofxiOS/src/gl/EAGLKView.h index 4f18592e9ca..5d0b68f2f1f 100644 --- a/addons/ofxiOS/src/gl/EAGLKView.h +++ b/addons/ofxiOS/src/gl/EAGLKView.h @@ -12,6 +12,7 @@ #import #import "ESRenderer.h" +/// ???: inherit GLKViewDelegate? @protocol EAGLKViewDelegate @optional - (void)glViewAnimationStarted; @@ -35,17 +36,19 @@ ESRendererVersion rendererVersion; } -@property (nonatomic, assign) id delegate; +/// TODO: need to give protocol explicity. +/// ???: can we assume EAGLKViewDelegate is inherit GLKViewDelegate? +@property (nonatomic, weak) id delegate; -- (id)initWithFrame:(CGRect)frame -andPreferedRenderer:(ESRendererVersion)rendererVersion - andAA:(bool)msaaEnabled - andRetina:(bool)retinaEnabled - andRetinaScale:(CGFloat)retinaScale - sharegroup:(EAGLSharegroup*)sharegroup - colorFormat:(GLKViewDrawableColorFormat)colorFormat - depthFormat:(GLKViewDrawableDepthFormat)depthFormat - stencilFormat:(GLKViewDrawableStencilFormat)stencilFormat; +- (instancetype)initWithFrame:(CGRect)frame + andPreferedRenderer:(ESRendererVersion)rendererVersion + andAA:(bool)msaaEnabled + andRetina:(bool)retinaEnabled + andRetinaScale:(CGFloat)retinaScale + sharegroup:(EAGLSharegroup*)sharegroup + colorFormat:(GLKViewDrawableColorFormat)colorFormat + depthFormat:(GLKViewDrawableDepthFormat)depthFormat + stencilFormat:(GLKViewDrawableStencilFormat)stencilFormat; diff --git a/addons/ofxiOS/src/gl/EAGLKView.m b/addons/ofxiOS/src/gl/EAGLKView.m index f9c427ab748..6de6dd8bb9d 100644 --- a/addons/ofxiOS/src/gl/EAGLKView.m +++ b/addons/ofxiOS/src/gl/EAGLKView.m @@ -25,15 +25,15 @@ + (Class) layerClass { return [CAEAGLLayer class]; } -- (id)initWithFrame:(CGRect)frame -andPreferedRenderer:(ESRendererVersion)version - andAA:(bool)msaaEnabled - andRetina:(bool)retinaEnabled - andRetinaScale:(CGFloat)retinaScale - sharegroup:(EAGLSharegroup*)sharegroup - colorFormat:(GLKViewDrawableColorFormat)colorFormat - depthFormat:(GLKViewDrawableDepthFormat)depthFormat - stencilFormat:(GLKViewDrawableStencilFormat)stencilFormat { +- (instancetype)initWithFrame:(CGRect)frame + andPreferedRenderer:(ESRendererVersion)version + andAA:(bool)msaaEnabled + andRetina:(bool)retinaEnabled + andRetinaScale:(CGFloat)retinaScale + sharegroup:(EAGLSharegroup*)sharegroup + colorFormat:(GLKViewDrawableColorFormat)colorFormat + depthFormat:(GLKViewDrawableDepthFormat)depthFormat + stencilFormat:(GLKViewDrawableStencilFormat)stencilFormat { if((self = [super initWithFrame:frame])) { @@ -80,7 +80,7 @@ - (id)initWithFrame:(CGRect)frame if(!self.context){ NSLog(@"Critical Error - ofiOS GLKView.m could not start any type of OpenGLES renderer"); - [self release]; + self = nil; return nil; } } @@ -116,7 +116,6 @@ - (void) destroy { - (void) dealloc{ [self destroy]; - [super dealloc]; } - (void) setup { diff --git a/addons/ofxiOS/src/gl/EAGLView.h b/addons/ofxiOS/src/gl/EAGLView.h index 0c9f9563a62..8559c802f29 100644 --- a/addons/ofxiOS/src/gl/EAGLView.h +++ b/addons/ofxiOS/src/gl/EAGLView.h @@ -47,9 +47,6 @@ // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. @interface EAGLView : UIView { -@public - id delegate; - @protected id renderer; CGFloat scaleFactor; @@ -74,19 +71,19 @@ NSLock * glLock; } -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; @property (readonly, nonatomic, getter=isAnimating) BOOL animating; -@property (nonatomic) float animationFrameInterval; -@property (nonatomic) float animationFrameRate; +@property (nonatomic, assign) float animationFrameInterval; +@property (nonatomic, assign) float animationFrameRate; -- (id)initWithFrame:(CGRect)frame -andPreferedRenderer:(ESRendererVersion)rendererVersion - andDepth:(bool)depth - andAA:(bool)msaaEnabled - andNumSamples:(int)samples - andRetina:(bool)retinaEnabled - andRetinaScale:(CGFloat)retinaScale - sharegroup:(EAGLSharegroup*)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame + andPreferedRenderer:(ESRendererVersion)rendererVersion + andDepth:(bool)depth + andAA:(bool)msaaEnabled + andNumSamples:(int)samples + andRetina:(bool)retinaEnabled + andRetinaScale:(CGFloat)retinaScale + sharegroup:(EAGLSharegroup*)sharegroup; - (void)startAnimation; - (void)stopAnimation; diff --git a/addons/ofxiOS/src/gl/EAGLView.m b/addons/ofxiOS/src/gl/EAGLView.m index 7a7409e0d5f..87bcb8d4f20 100644 --- a/addons/ofxiOS/src/gl/EAGLView.m +++ b/addons/ofxiOS/src/gl/EAGLView.m @@ -57,14 +57,14 @@ + (Class) layerClass { return [CAEAGLLayer class]; } -- (id)initWithFrame:(CGRect)frame -andPreferedRenderer:(ESRendererVersion)version - andDepth:(bool)depth - andAA:(bool)msaaEnabled - andNumSamples:(int)samples - andRetina:(bool)retinaEnabled - andRetinaScale:(CGFloat)retinaScale - sharegroup:(EAGLSharegroup*)sharegroup { +- (instancetype)initWithFrame:(CGRect)frame + andPreferedRenderer:(ESRendererVersion)version + andDepth:(bool)depth + andAA:(bool)msaaEnabled + andNumSamples:(int)samples + andRetina:(bool)retinaEnabled + andRetinaScale:(CGFloat)retinaScale + sharegroup:(EAGLSharegroup*)sharegroup { if((self = [super initWithFrame:frame])) { @@ -123,7 +123,7 @@ - (id)initWithFrame:(CGRect)frame if(!renderer){ NSLog(@"Critical Error - ofiOS EAGLView.m could not start any type of OpenGLES renderer"); - [self release]; + self = nil; return nil; } @@ -169,15 +169,13 @@ - (void) destroy { return; } [self stopAnimation]; - [renderer release]; - [glLock release]; - + renderer = nil; + glLock = nil; bInit = NO; } - (void) dealloc{ [self destroy]; - [super dealloc]; } - (void) drawView:(id)sender { diff --git a/addons/ofxiOS/src/gl/ES1Renderer.h b/addons/ofxiOS/src/gl/ES1Renderer.h index 28a5b49e479..437116911ce 100644 --- a/addons/ofxiOS/src/gl/ES1Renderer.h +++ b/addons/ofxiOS/src/gl/ES1Renderer.h @@ -26,11 +26,11 @@ bool bResize; } -- (id)initWithDepth:(bool)depth - andAA:(bool)msaa - andMSAASamples:(int)samples - andRetina:(bool)retina - sharegroup:(EAGLSharegroup*)sharegroup; +- (instancetype)initWithDepth:(bool)depth + andAA:(bool)msaa + andMSAASamples:(int)samples + andRetina:(bool)retina + sharegroup:(EAGLSharegroup*)sharegroup; - (void)startRender; - (void)finishRender; - (void)destroyFramebuffer; diff --git a/addons/ofxiOS/src/gl/ES1Renderer.m b/addons/ofxiOS/src/gl/ES1Renderer.m index 477b864c467..9d783340d32 100644 --- a/addons/ofxiOS/src/gl/ES1Renderer.m +++ b/addons/ofxiOS/src/gl/ES1Renderer.m @@ -5,11 +5,11 @@ @implementation ES1Renderer // Create an OpenGL ES 1.1 context -- (id)init { +- (instancetype)init { return [self initWithDepth:false andAA:false andMSAASamples:0 andRetina:false sharegroup:nil]; } -- (id)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples andRetina:(bool)retina sharegroup:(EAGLSharegroup*)sharegroup{ +- (instancetype)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples andRetina:(bool)retina sharegroup:(EAGLSharegroup*)sharegroup{ if((self = [super init])) { @@ -24,7 +24,7 @@ - (id)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples and if(!context || ![EAGLContext setCurrentContext:context]) { NSLog(@"OpenGL ES1 failed"); - [self release]; + self = nil; return nil; } @@ -176,10 +176,7 @@ - (void)dealloc { [EAGLContext setCurrentContext:nil]; } - [context release]; context = nil; - - [super dealloc]; } - (NSInteger)getWidth { diff --git a/addons/ofxiOS/src/gl/ES2Renderer.h b/addons/ofxiOS/src/gl/ES2Renderer.h index 6b233ad0e74..608fb2edbb5 100644 --- a/addons/ofxiOS/src/gl/ES2Renderer.h +++ b/addons/ofxiOS/src/gl/ES2Renderer.h @@ -26,11 +26,11 @@ bool bResize; } -- (id)initWithDepth:(bool)depth - andAA:(bool)msaa - andMSAASamples:(int)samples - andRetina:(bool)retina - sharegroup:(EAGLSharegroup*)sharegroup; +- (instancetype)initWithDepth:(bool)depth + andAA:(bool)msaa + andMSAASamples:(int)samples + andRetina:(bool)retina + sharegroup:(EAGLSharegroup*)sharegroup; - (void)startRender; - (void)finishRender; - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer; diff --git a/addons/ofxiOS/src/gl/ES2Renderer.m b/addons/ofxiOS/src/gl/ES2Renderer.m index 68c8d2d7530..20ebc27d65a 100644 --- a/addons/ofxiOS/src/gl/ES2Renderer.m +++ b/addons/ofxiOS/src/gl/ES2Renderer.m @@ -5,11 +5,11 @@ @implementation ES2Renderer // Create an OpenGL ES 2.0 context -- (id)init { +- (instancetype)init { return [self initWithDepth:false andAA:false andMSAASamples:0 andRetina:false sharegroup:nil]; } -- (id)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples andRetina:(bool)retina sharegroup:(EAGLSharegroup*)sharegroup{ +- (instancetype)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples andRetina:(bool)retina sharegroup:(EAGLSharegroup*)sharegroup{ if((self = [super init])) { depthEnabled = depth; msaaEnabled = msaa; @@ -22,7 +22,7 @@ - (id)initWithDepth:(bool)depth andAA:(bool)msaa andMSAASamples:(int)samples and if(!context || ![EAGLContext setCurrentContext:context]) { NSLog(@"OpenGL ES2 failed"); - [self release]; + self = nil; return nil; } @@ -172,10 +172,7 @@ - (void)dealloc { [EAGLContext setCurrentContext:nil]; } - [context release]; context = nil; - - [super dealloc]; } - (NSInteger)getWidth { diff --git a/addons/ofxiOS/src/sound/AVSoundPlayer.h b/addons/ofxiOS/src/sound/AVSoundPlayer.h index 3b3abe8e9a8..48907378255 100644 --- a/addons/ofxiOS/src/sound/AVSoundPlayer.h +++ b/addons/ofxiOS/src/sound/AVSoundPlayer.h @@ -16,13 +16,11 @@ - (void)soundPlayerError:(NSError *)error; @end -@interface AVSoundPlayer : NSObject { - id delegate; -} +@interface AVSoundPlayer : NSObject -@property(nonatomic, assign) id delegate; -@property(nonatomic, retain) AVAudioPlayer * player; -@property(nonatomic, retain) NSTimer * timer; +@property(nonatomic, weak) id delegate; +@property(nonatomic, strong) AVAudioPlayer * player; +@property(nonatomic, strong) NSTimer * timer; - (BOOL)loadWithFile:(NSString*)file; - (BOOL)loadWithPath:(NSString*)path; diff --git a/addons/ofxiOS/src/sound/AVSoundPlayer.m b/addons/ofxiOS/src/sound/AVSoundPlayer.m index 8c9b93ae71a..e17e938265d 100644 --- a/addons/ofxiOS/src/sound/AVSoundPlayer.m +++ b/addons/ofxiOS/src/sound/AVSoundPlayer.m @@ -14,11 +14,7 @@ @interface AVSoundPlayer() { @implementation AVSoundPlayer -@synthesize delegate; -@synthesize player; -@synthesize timer; - -- (id)init { +- (instancetype)init { self = [super init]; if(self) { bMultiPlay = NO; @@ -61,7 +57,6 @@ - (void) setupSharedSession { - (void)dealloc { [self unloadSound]; - [super dealloc]; } //----------------------------------------------------------- load / unload. @@ -81,8 +76,8 @@ - (BOOL)loadWithURL:(NSURL*)url { [self unloadSound]; [self setupSharedSession]; NSError * error = nil; - self.player = [[[AVAudioPlayer alloc] initWithContentsOfURL:url - error:&error] autorelease]; + self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url + error:&error]; if([self.player respondsToSelector:@selector(setEnableRate:)]) { [self.player setEnableRate:YES]; } diff --git a/addons/ofxiOS/src/sound/SoundInputStream.m b/addons/ofxiOS/src/sound/SoundInputStream.m index 1eb2658c2bc..fb8639044f8 100644 --- a/addons/ofxiOS/src/sound/SoundInputStream.m +++ b/addons/ofxiOS/src/sound/SoundInputStream.m @@ -84,9 +84,9 @@ static OSStatus soundInputStreamRenderCallback(void *inRefCon, //---------------------------------------------------------------- @implementation SoundInputStream -- (id)initWithNumOfChannels:(NSInteger)value0 - withSampleRate:(NSInteger)value1 - withBufferSize:(NSInteger)value2 { +- (instancetype)initWithNumOfChannels:(NSInteger)value0 + withSampleRate:(NSInteger)value1 + withBufferSize:(NSInteger)value2 { self = [super initWithNumOfChannels:value0 withSampleRate:value1 withBufferSize:value2]; @@ -99,7 +99,6 @@ - (id)initWithNumOfChannels:(NSInteger)value0 - (void)dealloc { [self stop]; - [super dealloc]; } - (void)start { diff --git a/addons/ofxiOS/src/sound/SoundOutputStream.m b/addons/ofxiOS/src/sound/SoundOutputStream.m index 0089249d5bb..8539a8ba461 100644 --- a/addons/ofxiOS/src/sound/SoundOutputStream.m +++ b/addons/ofxiOS/src/sound/SoundOutputStream.m @@ -23,7 +23,7 @@ static OSStatus soundOutputStreamRenderCallback(void *inRefCon, UInt32 inNumberFrames, AudioBufferList *ioData) { - SoundOutputStream * stream = (SoundOutputStream *)inRefCon; + SoundOutputStream * stream = (__bridge SoundOutputStream *)inRefCon; AudioBuffer * audioBuffer = &ioData->mBuffers[0]; // clearing the buffer before handing it off to the user @@ -51,9 +51,9 @@ @interface SoundOutputStream() { @implementation SoundOutputStream -- (id)initWithNumOfChannels:(NSInteger)value0 - withSampleRate:(NSInteger)value1 - withBufferSize:(NSInteger)value2 { +- (instancetype)initWithNumOfChannels:(NSInteger)value0 + withSampleRate:(NSInteger)value1 + withBufferSize:(NSInteger)value2 { self = [super initWithNumOfChannels:value0 withSampleRate:value1 withBufferSize:value2]; @@ -66,7 +66,6 @@ - (id)initWithNumOfChannels:(NSInteger)value0 - (void)dealloc { [self stop]; - [super dealloc]; } - (void)start { @@ -128,7 +127,7 @@ - (void)start { //---------------------------------------------------------- render callback. - AURenderCallbackStruct callback = {soundOutputStreamRenderCallback, self}; + AURenderCallbackStruct callback = {soundOutputStreamRenderCallback, (__bridge void * _Nullable)(self)}; [self checkStatus:AudioUnitSetProperty(audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, diff --git a/addons/ofxiOS/src/sound/SoundStream.h b/addons/ofxiOS/src/sound/SoundStream.h index d8c59bd922f..92c1adf29ba 100644 --- a/addons/ofxiOS/src/sound/SoundStream.h +++ b/addons/ofxiOS/src/sound/SoundStream.h @@ -30,7 +30,6 @@ typedef enum { @end @interface SoundStream : NSObject { - id delegate; SoundStreamType streamType; NSInteger numOfChannels; NSInteger sampleRate; @@ -40,7 +39,7 @@ typedef enum { BOOL bInterruptedWhileRunning; } -@property (nonatomic, assign) id delegate; +@property (nonatomic, strong) id delegate; @property (readonly) SoundStreamType streamType; @property (readonly) NSInteger numOfChannels; @property (readonly) NSInteger sampleRate; @@ -49,9 +48,9 @@ typedef enum { @property (readonly) AudioUnit audioUnit; @property (assign) BOOL bInterruptedWhileRunning; -- (id)initWithNumOfChannels:(NSInteger)numOfChannels - withSampleRate:(NSInteger)sampleRate - withBufferSize:(NSInteger)bufferSize; +- (instancetype)initWithNumOfChannels:(NSInteger)numOfChannels + withSampleRate:(NSInteger)sampleRate + withBufferSize:(NSInteger)bufferSize; - (void)start; - (void)stop; diff --git a/addons/ofxiOS/src/sound/SoundStream.m b/addons/ofxiOS/src/sound/SoundStream.m index a4423effda8..95e3b746819 100644 --- a/addons/ofxiOS/src/sound/SoundStream.m +++ b/addons/ofxiOS/src/sound/SoundStream.m @@ -15,7 +15,6 @@ @interface SoundStream() { @implementation SoundStream -@synthesize delegate; @synthesize streamType; @synthesize numOfChannels; @synthesize sampleRate; @@ -24,9 +23,9 @@ @implementation SoundStream @synthesize audioUnit; @synthesize bInterruptedWhileRunning; -- (id)initWithNumOfChannels:(NSInteger)value0 - withSampleRate:(NSInteger)value1 - withBufferSize:(NSInteger)value2 { +- (instancetype)initWithNumOfChannels:(NSInteger)value0 + withSampleRate:(NSInteger)value1 + withBufferSize:(NSInteger)value2 { self = [super init]; if(self) { numOfChannels = value0; @@ -51,9 +50,7 @@ - (id)initWithNumOfChannels:(NSInteger)value0 } - (void)dealloc { - [super dealloc]; - - + self.delegate = nil; if([SoundStream shouldUseAudioSessionNotifications]) { [[NSNotificationCenter defaultCenter] removeObserver:self name:AVAudioSessionInterruptionNotification diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm index 2c1a0ad5ef7..8632fda22b1 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm +++ b/addons/ofxiOS/src/sound/ofxiOSSoundPlayer.mm @@ -25,16 +25,15 @@ } string filePath = ofToDataPath(fileName); - soundPlayer = [[AVSoundPlayer alloc] init]; - BOOL bOk = [(AVSoundPlayer *)soundPlayer loadWithPath:[NSString stringWithUTF8String:filePath.c_str()]]; + soundPlayer = (__bridge void *)[[AVSoundPlayer alloc] init]; + BOOL bOk = [(__bridge AVSoundPlayer *)soundPlayer loadWithPath:[NSString stringWithUTF8String:filePath.c_str()]]; return bOk; } void ofxiOSSoundPlayer::unload() { if(soundPlayer != NULL) { - [(AVSoundPlayer *)soundPlayer unloadSound]; - [(AVSoundPlayer *)soundPlayer release]; + [(__bridge AVSoundPlayer *)soundPlayer unloadSound]; soundPlayer = NULL; } } @@ -43,35 +42,35 @@ if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer play]; + [(__bridge AVSoundPlayer *)soundPlayer play]; } void ofxiOSSoundPlayer::stop() { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer stop]; + [(__bridge AVSoundPlayer *)soundPlayer stop]; } void ofxiOSSoundPlayer::setVolume(float value) { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer volume:value]; + [(__bridge AVSoundPlayer *)soundPlayer volume:value]; } void ofxiOSSoundPlayer::setPan(float value) { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer pan:value]; + [(__bridge AVSoundPlayer *)soundPlayer pan:value]; } void ofxiOSSoundPlayer::setSpeed(float value) { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer speed:value]; + [(__bridge AVSoundPlayer *)soundPlayer speed:value]; } void ofxiOSSoundPlayer::setPaused(bool bPause) { @@ -79,9 +78,9 @@ return; } if(bPause) { - [(AVSoundPlayer *)soundPlayer pause]; + [(__bridge AVSoundPlayer *)soundPlayer pause]; } else { - [(AVSoundPlayer *)soundPlayer play]; + [(__bridge AVSoundPlayer *)soundPlayer play]; } } @@ -89,7 +88,7 @@ if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer loop:bLoop]; + [(__bridge AVSoundPlayer *)soundPlayer loop:bLoop]; } void ofxiOSSoundPlayer::setMultiPlay(bool bMultiPlay) { @@ -97,70 +96,70 @@ if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer multiPlay:bMultiPlay]; + [(__bridge AVSoundPlayer *)soundPlayer multiPlay:bMultiPlay]; } void ofxiOSSoundPlayer::setPosition(float position) { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer position:position]; + [(__bridge AVSoundPlayer *)soundPlayer position:position]; } void ofxiOSSoundPlayer::setPositionMS(int positionMS) { if(soundPlayer == NULL) { return; } - [(AVSoundPlayer *)soundPlayer positionMs:positionMS]; + [(__bridge AVSoundPlayer *)soundPlayer positionMs:positionMS]; } float ofxiOSSoundPlayer::getPosition() const{ if(soundPlayer == NULL) { return 0; } - return [(AVSoundPlayer *)soundPlayer position]; + return [(__bridge AVSoundPlayer *)soundPlayer position]; } int ofxiOSSoundPlayer::getPositionMS() const { if(soundPlayer == NULL) { return 0; } - return [(AVSoundPlayer *)soundPlayer positionMs]; + return [(__bridge AVSoundPlayer *)soundPlayer positionMs]; } bool ofxiOSSoundPlayer::isPlaying() const{ if(soundPlayer == NULL) { return false; } - return [(AVSoundPlayer *)soundPlayer isPlaying]; + return [(__bridge AVSoundPlayer *)soundPlayer isPlaying]; } float ofxiOSSoundPlayer::getSpeed() const{ if(soundPlayer == NULL) { return 0; } - return [(AVSoundPlayer *)soundPlayer speed]; + return [(__bridge AVSoundPlayer *)soundPlayer speed]; } float ofxiOSSoundPlayer::getPan() const{ if(soundPlayer == NULL) { return 0; } - return [(AVSoundPlayer *)soundPlayer pan]; + return [(__bridge AVSoundPlayer *)soundPlayer pan]; } bool ofxiOSSoundPlayer::isLoaded() const{ if(soundPlayer == NULL) { return false; } - return [(AVSoundPlayer *)soundPlayer isLoaded]; + return [(__bridge AVSoundPlayer *)soundPlayer isLoaded]; } float ofxiOSSoundPlayer::getVolume() const{ if(soundPlayer == NULL) { return false; } - return [(AVSoundPlayer *)soundPlayer volume]; + return [(__bridge AVSoundPlayer *)soundPlayer volume]; } void * ofxiOSSoundPlayer::getAVSoundPlayer() { diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundStream.mm b/addons/ofxiOS/src/sound/ofxiOSSoundStream.mm index bce137f6896..ad0bec9ee74 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundStream.mm +++ b/addons/ofxiOS/src/sound/ofxiOSSoundStream.mm @@ -47,13 +47,13 @@ //------------------------------------------------------------------------------ void ofxiOSSoundStream::setInput(ofBaseSoundInput * soundInput) { settings.setInListener(soundInput); - [(ofxiOSSoundStreamDelegate *)[(id)soundInputStream delegate] setInput: settings.inCallback]; + [(ofxiOSSoundStreamDelegate *)[(__bridge id)soundInputStream delegate] setInput: settings.inCallback]; } //------------------------------------------------------------------------------ void ofxiOSSoundStream::setOutput(ofBaseSoundOutput * soundOutput) { settings.setOutListener(soundOutput); - [(ofxiOSSoundStreamDelegate *)[(id)soundOutputStream delegate] setOutput: settings.outCallback]; + [(ofxiOSSoundStreamDelegate *)[(__bridge id)soundOutputStream delegate] setOutput: settings.outCallback]; } //------------------------------------------------------------------------------ @@ -63,21 +63,21 @@ this->settings = settings; if(settings.numInputChannels > 0) { - soundInputStream = [[SoundInputStream alloc] initWithNumOfChannels:settings.numInputChannels + soundInputStream = (__bridge void *)[[SoundInputStream alloc] initWithNumOfChannels:settings.numInputChannels withSampleRate:settings.sampleRate withBufferSize:settings.bufferSize]; ofxiOSSoundStreamDelegate * delegate = [[ofxiOSSoundStreamDelegate alloc] initWithSoundInputFn:settings.inCallback]; - ((SoundInputStream *)soundInputStream).delegate = delegate; - [(SoundInputStream *)soundInputStream start]; + ((__bridge SoundInputStream *)soundInputStream).delegate = delegate; + [(__bridge SoundInputStream *)soundInputStream start]; } if(settings.numOutputChannels > 0) { - soundOutputStream = [[SoundOutputStream alloc] initWithNumOfChannels:settings.numOutputChannels + soundOutputStream = (__bridge void *)[[SoundOutputStream alloc] initWithNumOfChannels:settings.numOutputChannels withSampleRate:settings.sampleRate withBufferSize:settings.bufferSize]; ofxiOSSoundStreamDelegate * delegate = [[ofxiOSSoundStreamDelegate alloc] initWithSoundOutputFn:settings.outCallback]; - ((SoundInputStream *)soundOutputStream).delegate = delegate; - [(SoundInputStream *)soundOutputStream start]; + ((__bridge SoundInputStream *)soundOutputStream).delegate = delegate; + [(__bridge SoundInputStream *)soundOutputStream start]; } bool bOk = (soundInputStream != NULL) || (soundOutputStream != NULL); @@ -87,40 +87,36 @@ //------------------------------------------------------------------------------ void ofxiOSSoundStream::start(){ if(soundInputStream != NULL) { - [(SoundInputStream *)soundInputStream start]; + [(__bridge SoundInputStream *)soundInputStream start]; } if(soundOutputStream != NULL) { - [(SoundOutputStream *)soundOutputStream start]; + [(__bridge SoundOutputStream *)soundOutputStream start]; } } //------------------------------------------------------------------------------ void ofxiOSSoundStream::stop(){ if(soundInputStream != NULL) { - [(SoundInputStream *)soundInputStream stop]; + [(__bridge SoundInputStream *)soundInputStream stop]; } if(soundOutputStream != NULL) { - [(SoundOutputStream *)soundOutputStream stop]; + [(__bridge SoundOutputStream *)soundOutputStream stop]; } } //------------------------------------------------------------------------------ void ofxiOSSoundStream::close(){ if(soundInputStream != NULL) { - [((SoundInputStream *)soundInputStream).delegate release]; - [(SoundInputStream *)soundInputStream setDelegate:nil]; - [(SoundInputStream *)soundInputStream stop]; - [(SoundInputStream *)soundInputStream release]; + [(__bridge SoundInputStream *)soundInputStream setDelegate:nil]; + [(__bridge SoundInputStream *)soundInputStream stop]; soundInputStream = NULL; } if(soundOutputStream != NULL) { - [((SoundOutputStream *)soundInputStream).delegate release]; - [(SoundOutputStream *)soundInputStream setDelegate:nil]; - [(SoundOutputStream *)soundOutputStream stop]; - [(SoundOutputStream *)soundOutputStream release]; + [(__bridge SoundOutputStream *)soundOutputStream setDelegate:nil]; + [(__bridge SoundOutputStream *)soundOutputStream stop]; soundOutputStream = NULL; } diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.h b/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.h index 1819cd75e58..d9598e9e20b 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.h +++ b/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.h @@ -13,11 +13,11 @@ class ofSoundBuffer; @interface ofxiOSSoundStreamDelegate : NSObject -- (id)initWithSoundInputFn:(std::function)input; -- (id)initWithSoundOutputFn:(std::function)output; +- (instancetype)initWithSoundInputFn:(std::function)input; +- (instancetype)initWithSoundOutputFn:(std::function)output; - (void)setInput:(std::function)input; - (void)setOutput:(std::function)output; @end -#define ofxiPhoneSoundStreamDelegate ofxiOSSoundStreamDelegate \ No newline at end of file +#define ofxiPhoneSoundStreamDelegate ofxiOSSoundStreamDelegate diff --git a/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.mm b/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.mm index 6c89913151f..ee850f352ae 100644 --- a/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.mm +++ b/addons/ofxiOS/src/sound/ofxiOSSoundStreamDelegate.mm @@ -20,12 +20,12 @@ @interface ofxiOSSoundStreamDelegate() { @implementation ofxiOSSoundStreamDelegate -- (id)init { +- (instancetype)init { self = [super init]; if(self) { inputBuffer = std::shared_ptr(new ofSoundBuffer); outputBuffer = std::shared_ptr(new ofSoundBuffer); - tickCount = 0; + tickCount = 0; } return self; } @@ -33,10 +33,9 @@ - (id)init { - (void)dealloc { inCallback = nullptr; outCallback = nullptr; - [super dealloc]; } -- (id)initWithSoundInputFn:(std::function)fn { +- (instancetype)initWithSoundInputFn:(std::function)fn { self = [self init]; if(self) { inCallback = fn; @@ -44,7 +43,7 @@ - (id)initWithSoundInputFn:(std::function)fn { return self; } -- (id)initWithSoundOutputFn:(std::function)fn { +- (instancetype)initWithSoundOutputFn:(std::function)fn { self = [self init]; if(self) { outCallback = fn; diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.h b/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.h index 754ea798a99..fd19acd40f2 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.h +++ b/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.h @@ -19,8 +19,8 @@ @interface ofxtvOSAppDelegate : NSObject { } -@property (nonatomic, retain) UIWindow * window; -@property (nonatomic, retain) UIViewController * uiViewController; +@property (nonatomic, strong) UIWindow * window; +@property (nonatomic, strong) UIViewController * uiViewController; - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url; diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.mm b/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.mm index bf6faef4b30..a943574a0f6 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.mm +++ b/addons/ofxiOS/src/tvOS/ofxtvOSAppDelegate.mm @@ -8,6 +8,7 @@ #include "ofxtvOSAppDelegate.h" #include "ofxtvOSViewController.h" +#include "ofxtvOSGLKViewController.h" #include "ofxiOSExtras.h" #include "ofxiOSAlerts.h" #include "ofxiOSEAGLView.h" @@ -24,12 +25,11 @@ @implementation ofxtvOSAppDelegate - (void)dealloc { self.window = nil; self.uiViewController = nil; - [super dealloc]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { - self.window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] autorelease]; + self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; [self.window makeKeyAndVisible]; // set the root application path @@ -45,11 +45,11 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application { case METAL_KIT: NSLog(@"No MetalKit yet supported for openFrameworks: Falling back to GLKit"); case GL_KIT: - self.uiViewController = (UIViewController*)[[[ofxtvOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease]; + self.uiViewController = (UIViewController *)[[ofxtvOSGLKViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil]; break; case CORE_ANIMATION: default: - self.uiViewController = [[[ofxtvOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil] autorelease]; + self.uiViewController = [[ofxtvOSViewController alloc] initWithFrame:frame app:(ofxiOSApp *)ofGetAppPtr() sharegroup:nil]; break; } self.window.rootViewController = self.uiViewController; diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.h b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.h index 68546d50ba1..8a62b1d1f6c 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.h +++ b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.h @@ -18,8 +18,8 @@ class ofxiOSApp; @property (nonatomic, retain) ofxiOSGLKView * glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (void)setPreferredFPS:(int)fps; - (EAGLSharegroup *)getSharegroup; diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm index a01b95a0003..221ef497cb0 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm +++ b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm @@ -15,13 +15,13 @@ @implementation ofxtvOSGLKViewController @synthesize glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { return [self initWithFrame:frame app:app sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup { +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup { if((self = [super init])) { - self.glView = [[[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease]; + self.glView = [[ofxiOSGLKView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup]; self.glView.delegate = self; } @@ -32,8 +32,6 @@ - (void) dealloc { [self.glView removeFromSuperview]; self.glView.delegate = nil; self.glView = nil; - - [super dealloc]; } - (void)viewDidLoad { @@ -139,7 +137,7 @@ - (void)viewWillLayoutSubviews { - (void)handleTap:(UITapGestureRecognizer *)sender { if([self.view respondsToSelector:@selector(handleTap:)]) { - [self.glView handleTap:sender]; + [self.glView performSelector:@selector(handleTap:) withObject:sender]; } } diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSViewController.h b/addons/ofxiOS/src/tvOS/ofxtvOSViewController.h index 56f53a3ce97..d823fb12175 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSViewController.h +++ b/addons/ofxiOS/src/tvOS/ofxtvOSViewController.h @@ -18,8 +18,8 @@ class ofxiOSApp; @property (nonatomic, retain) ofxiOSEAGLView * glView; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; @end diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSViewController.mm b/addons/ofxiOS/src/tvOS/ofxtvOSViewController.mm index 1eced93be7a..e82bb5fec8c 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSViewController.mm +++ b/addons/ofxiOS/src/tvOS/ofxtvOSViewController.mm @@ -15,15 +15,13 @@ @interface ofxtvOSViewController() { @implementation ofxtvOSViewController -@synthesize glView; - -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { return [self initWithFrame:frame app:app sharegroup:nil]; } -- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup { +- (instancetype)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup { if((self = [super init])) { - self.glView = [[[ofxiOSEAGLView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup] autorelease]; + self.glView = [[ofxiOSEAGLView alloc] initWithFrame:frame andApp:app sharegroup:sharegroup]; self.glView.delegate = self; } @@ -35,8 +33,6 @@ - (void) dealloc { [self.glView removeFromSuperview]; self.glView.delegate = nil; self.glView = nil; - - [super dealloc]; } - (void)viewDidLoad { @@ -101,7 +97,8 @@ - (void)viewWillLayoutSubviews { - (void)handleTap:(UITapGestureRecognizer *)sender { if([self.view respondsToSelector:@selector(handleTap:)]) { - [self.glView handleTap:sender]; + [self.glView performSelector:@selector(handleTap:) + withObject:sender]; } } diff --git a/addons/ofxiOS/src/utils/ofxiOSCoreLocation.h b/addons/ofxiOS/src/utils/ofxiOSCoreLocation.h index 975bdf38ce9..9d7c119832f 100644 --- a/addons/ofxiOS/src/utils/ofxiOSCoreLocation.h +++ b/addons/ofxiOS/src/utils/ofxiOSCoreLocation.h @@ -49,7 +49,7 @@ @property (nonatomic, readonly) double trueHeading; @property (nonatomic, readonly) double headingAccuracy; -- (id) init; +- (instancetype) init; - (void) dealloc; - (bool) startHeading; diff --git a/addons/ofxiOS/src/utils/ofxiOSCoreLocation.mm b/addons/ofxiOS/src/utils/ofxiOSCoreLocation.mm index a21043a9798..2585894b97e 100644 --- a/addons/ofxiOS/src/utils/ofxiOSCoreLocation.mm +++ b/addons/ofxiOS/src/utils/ofxiOSCoreLocation.mm @@ -33,7 +33,6 @@ //-------------------------------------------------------------- ofxiOSCoreLocation::~ofxiOSCoreLocation() { - [coreLoc release]; } //-------------------------------------------------------------- @@ -158,7 +157,7 @@ @implementation ofxiOSCoreLocationDelegate @synthesize lat, lng, hAccuracy, alt, vAccuracy, distMoved, x, y, z, magneticHeading, trueHeading, headingAccuracy; //-------------------------------------------------------------- -- (id) init +- (instancetype) init { if(self = [super init]) { @@ -188,9 +187,7 @@ - (id) init //-------------------------------------------------------------- - (void)dealloc { - [locationManager release]; - - [super dealloc]; + locationManager = nil; } //-------------------------------------------------------------- @@ -298,7 +295,7 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error //thx apple { - NSMutableString *errorString = [[[NSMutableString alloc] init] autorelease]; + NSMutableString *errorString = [[NSMutableString alloc] init]; if ([error domain] == kCLErrorDomain) { @@ -344,4 +341,4 @@ - (void)locationManager:(CLLocationManager *)manager @end -#endif \ No newline at end of file +#endif diff --git a/addons/ofxiOS/src/utils/ofxiOSCoreMotion.mm b/addons/ofxiOS/src/utils/ofxiOSCoreMotion.mm index 571b5357b8a..0980eb6c18f 100755 --- a/addons/ofxiOS/src/utils/ofxiOSCoreMotion.mm +++ b/addons/ofxiOS/src/utils/ofxiOSCoreMotion.mm @@ -1,7 +1,6 @@ #include "ofxiOSCoreMotion.h" - ofxiOSCoreMotion::ofxiOSCoreMotion() { motionManager = [[CMMotionManager alloc] init]; @@ -18,13 +17,11 @@ ofxiOSCoreMotion::~ofxiOSCoreMotion() { - [referenceAttitude release]; referenceAttitude = nil; [motionManager stopAccelerometerUpdates]; [motionManager stopGyroUpdates]; [motionManager stopMagnetometerUpdates]; [motionManager stopDeviceMotionUpdates]; - [motionManager release]; motionManager = nil; } @@ -121,10 +118,9 @@ if(toCurrentReferenceFrame) { CMDeviceMotion *deviceMotion = motionManager.deviceMotion; CMAttitude *attitude = deviceMotion.attitude; - referenceAttitude = [attitude retain]; + referenceAttitude = attitude; } else { if(referenceAttitude != nil) { - [referenceAttitude release]; referenceAttitude = nil; } } diff --git a/addons/ofxiOS/src/utils/ofxiOSExtras.h b/addons/ofxiOS/src/utils/ofxiOSExtras.h index a52d0bbbf38..21bb62b2182 100644 --- a/addons/ofxiOS/src/utils/ofxiOSExtras.h +++ b/addons/ofxiOS/src/utils/ofxiOSExtras.h @@ -190,6 +190,15 @@ bool ofxiOSUIImageToOFTexture(UIImage * uiImage, ofTexture & outTexture, int tar bool ofxiOSCGImageToPixels(CGImageRef & ref, unsigned char * pixels); #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) + +/// TODO: define protocol for ofxiOSScreenGrab, and give protocol explicitly for argument of ofxiOSScreenGrab +//@protocol ofxiOSSaveDelegate +// +//@optional +//- (void)saveComplete; +// +//@end + // save current opengl screen to photos app // based on code from http://www.bit-101.com/blog/?p=1861 void ofxiOSScreenGrab(id delegate); diff --git a/addons/ofxiOS/src/utils/ofxiOSExtras.mm b/addons/ofxiOS/src/utils/ofxiOSExtras.mm index 653f147ed38..0f0cb0d9fd1 100644 --- a/addons/ofxiOS/src/utils/ofxiOSExtras.mm +++ b/addons/ofxiOS/src/utils/ofxiOSExtras.mm @@ -33,8 +33,10 @@ #include "ofxiOSExtras.h" #include #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) -#include "ofxiOSAppDelegate.h" -#include "ofxiOSViewController.h" + +#import "ofxiOSAppDelegate.h" +#import "ofxiOSViewController.h" +#import "ofxiOSGLKViewController.h" #elif TARGET_OS_TV #include "ofxtvOSAppDelegate.h" #include "ofxtvOSViewController.h" @@ -534,30 +536,27 @@ string ofxiOSGetClipboardString() { /******************** ofxiOSScreenGrab *********************/ -@interface SaveDelegate : NSObject { - id delegate; -} -@property (retain, nonatomic) id delegate; +/// TODO: rename SaveDelegate to ofxiOSSaveDelegateObject (SaveDelegate is too general name, and basically XXXDelegate is name for Protocol). +/// maybe this change will safety because SaveDelegate is private class +@interface SaveDelegate : NSObject +/// TODO: give protocol explicitly +@property (nonatomic, strong) id delegate; @end @implementation SaveDelegate -@synthesize delegate; // callback for UIImageWriteToSavedPhotosAlbum - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { ofLogVerbose("ofxiOSExtras") << "didFinishSavingWithError: save finished"; - if([delegate respondsToSelector: @selector(saveComplete)]) { - [delegate performSelector:@selector(saveComplete)]; + if([self.delegate respondsToSelector: @selector(saveComplete)]) { + [self.delegate performSelector:@selector(saveComplete)]; } - - [self release]; } -(void)dealloc { - [delegate release]; - [super dealloc]; + self.delegate = nil; } @end @@ -571,6 +570,7 @@ void releaseData(void *info, const void *data, size_t dataSize) { } #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) +/// ???: need to change argument to give Protocol id explicitly? void ofxiOSScreenGrab(id delegate) { CGRect rect = [[UIScreen mainScreen] bounds]; diff --git a/addons/ofxiOS/src/utils/ofxiOSImagePicker.h b/addons/ofxiOS/src/utils/ofxiOSImagePicker.h index c957f6896a8..68be12c2700 100644 --- a/addons/ofxiOS/src/utils/ofxiOSImagePicker.h +++ b/addons/ofxiOS/src/utils/ofxiOSImagePicker.h @@ -27,7 +27,8 @@ class canLoadPixels //----------------------------------------------------------- overlay. @interface ofxiOSImagePickerOverlayView : UIView -@property (nonatomic, retain) id delegate; +/// TODO: give protocol explicitly. +@property (nonatomic, strong) id delegate; - (void)initUI; - (void)takePhoto:(id)sender; @end @@ -47,7 +48,7 @@ class canLoadPixels canLoadPixels * cppPixelLoader; } -- (id) initWithPicker:(canLoadPixels *) _picker; +- (instancetype) initWithPicker:(canLoadPixels *) _picker; - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo; diff --git a/addons/ofxiOS/src/utils/ofxiOSImagePicker.mm b/addons/ofxiOS/src/utils/ofxiOSImagePicker.mm index b0e3f7680ee..be9a4887797 100644 --- a/addons/ofxiOS/src/utils/ofxiOSImagePicker.mm +++ b/addons/ofxiOS/src/utils/ofxiOSImagePicker.mm @@ -32,7 +32,6 @@ //-------------------------------------------------------------- ofxiOSImagePicker::~ofxiOSImagePicker(){ close(); - [imagePicker release]; } //-------------------------------------------------------------- @@ -180,7 +179,7 @@ //---------------------------------------------------------------- @implementation ofxiOSImagePickerDelegate -- (id) initWithPicker:(canLoadPixels *) _picker +- (instancetype) initWithPicker:(canLoadPixels *) _picker { if(self = [super init]) { @@ -219,22 +218,18 @@ - (void)dealloc { _imagePicker.delegate = nil; [_imagePicker.view removeFromSuperview]; - [_imagePicker release]; + _imagePicker = nil; if(_image) { - [_image release]; _image = nil; } if(overlay) { overlay.delegate = nil; - [overlay release]; overlay = nil; } cppPixelLoader = NULL; - - [super dealloc]; } //---------------------------------------------------------------- @@ -242,14 +237,14 @@ - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { - _image = [[self scaleAndRotateImage:image] retain]; + _image = [self scaleAndRotateImage:image]; cppPixelLoader->loadPixels(); } - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - _image = [[self scaleAndRotateImage:[info objectForKey:UIImagePickerControllerOriginalImage]] retain]; + _image = [self scaleAndRotateImage:[info objectForKey:UIImagePickerControllerOriginalImage]]; cppPixelLoader->loadPixels(); } @@ -369,7 +364,6 @@ - (void) hideCameraOverlay { if(overlay) { overlay.delegate = nil; - [overlay release]; overlay = nil; } } @@ -528,7 +522,7 @@ @implementation ofxiOSImagePickerOverlayView @synthesize delegate; -- (id)initWithFrame:(CGRect)frame{ +- (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self initUI]; } diff --git a/addons/ofxiOS/src/utils/ofxiOSKeyboard.h b/addons/ofxiOS/src/utils/ofxiOSKeyboard.h index a73a3003c8e..9001f716542 100644 --- a/addons/ofxiOS/src/utils/ofxiOSKeyboard.h +++ b/addons/ofxiOS/src/utils/ofxiOSKeyboard.h @@ -23,7 +23,7 @@ int _yOriginal; int fieldLength; } -- (id) init: (int)x y:(int)y width:(int)w height:(int)h; +- (instancetype) init:(int)x y:(int)y width:(int)w height:(int)h; - (void) showText; - (void) hideText; - (const char *) getText; diff --git a/addons/ofxiOS/src/utils/ofxiOSKeyboard.mm b/addons/ofxiOS/src/utils/ofxiOSKeyboard.mm index caee3efc5c4..b02cb203d26 100644 --- a/addons/ofxiOS/src/utils/ofxiOSKeyboard.mm +++ b/addons/ofxiOS/src/utils/ofxiOSKeyboard.mm @@ -34,7 +34,6 @@ //-------------------------------------------------------------- ofxiOSKeyboard::~ofxiOSKeyboard() { - [keyboard release]; } @@ -192,7 +191,7 @@ - (BOOL)textFieldShouldReturn:(UITextField*)textField } //-------------------------------------------------------------- -- (id) init:(int)x y:(int)y width:(int)w height:(int)h +- (instancetype) init:(int)x y:(int)y width:(int)w height:(int)h { if(self = [super init]) { @@ -288,8 +287,7 @@ - (void) updateOrientation //-------------------------------------------------------------- - (void)dealloc { - [_textField release]; - [super dealloc]; + _textField = nil; } //-------------------------------------------------------------- @@ -421,7 +419,7 @@ - (void) setFieldLength: (int)len //-------------------------------------------------------------- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { - NSMutableString *newValue = [[textField.text mutableCopy] autorelease]; + NSMutableString *newValue = [textField.text mutableCopy]; [newValue replaceCharactersInRange:range withString:string]; ofLogVerbose("ofxiOSKeyboard") << "shouldChangeCharactersInRange: " << [newValue length] << " " << fieldLength; diff --git a/addons/ofxiOS/src/utils/ofxiOSMapKit.h b/addons/ofxiOS/src/utils/ofxiOSMapKit.h index 63ae6e33cdd..4500d10f603 100644 --- a/addons/ofxiOS/src/utils/ofxiOSMapKit.h +++ b/addons/ofxiOS/src/utils/ofxiOSMapKit.h @@ -36,6 +36,7 @@ #import #include "ofConstants.h" #include "ofxiOSMapKitListener.h" +#import "ofxiOSMapKitDelegate.h" #include "glm/vec2.hpp" #include "ofRectangle.h" #include @@ -140,7 +141,7 @@ class ofxiOSMapKit : public ofxiOSMapKitListener { MKMapView *getMKMapView(); protected: - + ofxiOSMapKitDelegate *mapKitDelegate; MKMapView *mapView; std::list listeners; diff --git a/addons/ofxiOS/src/utils/ofxiOSMapKit.mm b/addons/ofxiOS/src/utils/ofxiOSMapKit.mm index cd249662df0..da4c09d1e30 100644 --- a/addons/ofxiOS/src/utils/ofxiOSMapKit.mm +++ b/addons/ofxiOS/src/utils/ofxiOSMapKit.mm @@ -40,6 +40,7 @@ #include "glm/common.hpp" ofxiOSMapKit::ofxiOSMapKit() { + mapKitDelegate = nil; mapView = nil; } @@ -63,7 +64,6 @@ ofLogVerbose("ofxiOSMapKit") << "close(): releasing MKMapView"; mapView.delegate = nil; [mapView removeFromSuperview]; - [mapView release]; mapView = nil; } } @@ -221,7 +221,8 @@ if(isOpen()) { ofLogVerbose("ofxiOSMapKit") << "addListener(): adding ofxiOSMapKitDelegate"; if(mapView.delegate == nil) { - mapView.delegate = [[ofxiOSMapKitDelegate alloc] initWithMapKit:this]; + mapKitDelegate = [[ofxiOSMapKitDelegate alloc] initWithMapKit:this]; + mapView.delegate = mapKitDelegate; } listeners.push_back(o); } diff --git a/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.h b/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.h index 15ed0aff400..639ce591d6a 100644 --- a/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.h +++ b/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.h @@ -41,7 +41,7 @@ class ofxiOSMapKit; ofxiOSMapKit* mapKit; } --(id)initWithMapKit:(ofxiOSMapKit*)mk; +-(instancetype)initWithMapKit:(ofxiOSMapKit*)mk; -(void)dealloc; - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated; diff --git a/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.mm b/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.mm index bcab0a62528..aa3b9848f70 100644 --- a/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.mm +++ b/addons/ofxiOS/src/utils/ofxiOSMapKitDelegate.mm @@ -38,7 +38,7 @@ @implementation ofxiOSMapKitDelegate --(id)initWithMapKit:(ofxiOSMapKit*)mk { +-(instancetype)initWithMapKit:(ofxiOSMapKit*)mk { if(self = [super init]) { mapKit = mk; ofLogVerbose("ofxiOSMapKitDelegate") << "initWithMapKit"; @@ -48,7 +48,6 @@ -(id)initWithMapKit:(ofxiOSMapKit*)mk { -(void)dealloc { ofLogVerbose("ofxiOSMapKitDelegate") << "dealloc"; - [super dealloc]; } diff --git a/addons/ofxiOS/src/video/AVFoundationVideoGrabber.mm b/addons/ofxiOS/src/video/AVFoundationVideoGrabber.mm index b225faee12c..935117f2d34 100644 --- a/addons/ofxiOS/src/video/AVFoundationVideoGrabber.mm +++ b/addons/ofxiOS/src/video/AVFoundationVideoGrabber.mm @@ -33,7 +33,7 @@ @implementation iOSVideoGrabber #pragma mark - #pragma mark Initialization -- (id)init { +- (instancetype)init { self = [super init]; if (self) { captureInput = nil; @@ -109,7 +109,6 @@ - (BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h{ dispatch_queue_t queue; queue = dispatch_queue_create("cameraQueue", NULL); [captureOutput setSampleBufferDelegate:self queue:queue]; - dispatch_release(queue); // Set the video output to store frame in BGRA (It is supposed to be faster) NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; @@ -122,7 +121,7 @@ - (BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h{ if(self.captureSession) { self.captureSession = nil; } - self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; + self.captureSession = [[AVCaptureSession alloc] init]; [self.captureSession beginConfiguration]; @@ -330,7 +329,6 @@ - (void)dealloc { if(captureOutput.sampleBufferDelegate != nil) { [captureOutput setSampleBufferDelegate:nil queue:NULL]; } - [captureOutput release]; captureOutput = nil; } @@ -346,7 +344,6 @@ - (void)dealloc { CGImageRelease(currentFrame); currentFrame = nil; } - [super dealloc]; } - (void)eraseGrabberPtr { @@ -376,7 +373,6 @@ - (void)eraseGrabberPtr { // Stop and release the the iOSVideoGrabber [grabber stopCapture]; [grabber eraseGrabberPtr]; - [grabber release]; grabber = nil; } clear(); diff --git a/addons/ofxiOS/src/video/AVFoundationVideoPlayer.h b/addons/ofxiOS/src/video/AVFoundationVideoPlayer.h index f2046d669e3..e2175ec8ae6 100644 --- a/addons/ofxiOS/src/video/AVFoundationVideoPlayer.h +++ b/addons/ofxiOS/src/video/AVFoundationVideoPlayer.h @@ -35,18 +35,16 @@ @end //---------------------------------------------------------- video player. -@interface AVFoundationVideoPlayer : NSObject { - id delegate; -} - -@property (nonatomic, assign) id delegate; -@property (nonatomic, retain) UIView * playerView; -@property (nonatomic, retain) AVPlayer * player; -@property (nonatomic, retain) AVPlayerItem * playerItem; -@property (nonatomic, retain) AVAsset * asset; -@property (nonatomic, retain) AVAssetReader * assetReader; -@property (nonatomic, retain) AVAssetReaderTrackOutput * assetReaderVideoTrackOutput; -@property (nonatomic, retain) AVAssetReaderTrackOutput * assetReaderAudioTrackOutput; +@interface AVFoundationVideoPlayer : NSObject + +@property (nonatomic, weak) id delegate; +@property (nonatomic, strong) UIView * playerView; +@property (nonatomic, strong) AVPlayer * player; +@property (nonatomic, strong) AVPlayerItem * playerItem; +@property (nonatomic, strong) AVAsset * asset; +@property (nonatomic, strong) AVAssetReader * assetReader; +@property (nonatomic, strong) AVAssetReaderTrackOutput * assetReaderVideoTrackOutput; +@property (nonatomic, strong) AVAssetReaderTrackOutput * assetReaderAudioTrackOutput; - (BOOL)loadWithFile:(NSString*)file; - (BOOL)loadWithPath:(NSString*)path; diff --git a/addons/ofxiOS/src/video/AVFoundationVideoPlayer.m b/addons/ofxiOS/src/video/AVFoundationVideoPlayer.m index 44d1e755cb7..da195f32f0c 100644 --- a/addons/ofxiOS/src/video/AVFoundationVideoPlayer.m +++ b/addons/ofxiOS/src/video/AVFoundationVideoPlayer.m @@ -39,7 +39,6 @@ - (void)setPlayer:(AVPlayer*)player { - (void)dealloc { self.player = nil; - [super dealloc]; } @end @@ -90,17 +89,17 @@ @implementation AVFoundationVideoPlayer { static const NSString * ItemStatusContext; -- (id)init { +- (instancetype)init { self = [super init]; if(self) { /** * initialise video player view to full screen by default. * later the view frame can be changed if need be. */ - self.playerView = [[[AVFoundationVideoPlayerView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease]; + self.playerView = [[AVFoundationVideoPlayerView alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.playerView.backgroundColor = [UIColor blackColor]; - self.player = [[[AVPlayer alloc] init] autorelease]; + self.player = [[AVPlayer alloc] init]; [(AVFoundationVideoPlayerView *)self.playerView setPlayer:_player]; [_player addObserver:self @@ -162,7 +161,6 @@ - (void)dealloc { [_player removeObserver:self forKeyPath:kRateKey]; self.player = nil; - [_player release]; [self.assetReader cancelReading]; self.assetReader = nil; @@ -179,8 +177,6 @@ - (void)dealloc { CFRelease(audioSampleBuffer); audioSampleBuffer = nil; } - - [super dealloc]; } //---------------------------------------------------------- position / size. @@ -306,7 +302,7 @@ - (BOOL)createAssetReaderWithTimeRange:(CMTimeRange)timeRange { self.assetReader.timeRange = timeRange; //------------------------------------------------------------ add video output. - NSMutableDictionary * videoOutputSettings = [[[NSMutableDictionary alloc] init] autorelease]; + NSMutableDictionary * videoOutputSettings = [[NSMutableDictionary alloc] init]; [videoOutputSettings setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]; @@ -635,17 +631,17 @@ - (void)addTimeObserverToPlayer { double interval = 1.0 / (double)timeObserverFps; - timeObserver = [[_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(interval, NSEC_PER_SEC) - queue:dispatch_get_main_queue() usingBlock: + __block typeof(self) weak_self = self; + timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(interval, NSEC_PER_SEC) + queue:dispatch_get_main_queue() usingBlock: ^(CMTime time) { - [self update]; - }] retain]; + [weak_self update]; + }]; } - (void)removeTimeObserverFromPlayer { if(timeObserver) { [_player removeTimeObserver:timeObserver]; - [timeObserver release]; timeObserver = nil; } } diff --git a/addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm b/addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm index 9d62660829e..b4698517fd6 100644 --- a/addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm +++ b/addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm @@ -41,12 +41,12 @@ bool ofxiOSVideoPlayer::load(string name) { if(!videoPlayer) { - videoPlayer = [[AVFoundationVideoPlayer alloc] init]; - [(AVFoundationVideoPlayer *)videoPlayer setWillBeUpdatedExternally:YES]; + videoPlayer = (__bridge void *)[[AVFoundationVideoPlayer alloc] init]; + [(__bridge AVFoundationVideoPlayer *)videoPlayer setWillBeUpdatedExternally:YES]; } NSString * videoPath = [NSString stringWithUTF8String:ofToDataPath(name).c_str()]; - [(AVFoundationVideoPlayer*)videoPlayer loadWithPath:videoPath]; + [(__bridge AVFoundationVideoPlayer*)videoPlayer loadWithPath:videoPath]; bResetPixels = true; bUpdatePixels = true; @@ -84,8 +84,7 @@ videoTexture.clear(); - ((AVFoundationVideoPlayer *)videoPlayer).delegate = nil; - [(AVFoundationVideoPlayer *)videoPlayer release]; + ((__bridge AVFoundationVideoPlayer *)videoPlayer).delegate = nil; if(bTextureCacheSupported == true) { killTextureCache(); @@ -135,8 +134,8 @@ return; } - [(AVFoundationVideoPlayer *)videoPlayer update]; - bFrameNew = [(AVFoundationVideoPlayer *)videoPlayer isNewFrame]; // check for new frame staright after the call to update. + [(__bridge AVFoundationVideoPlayer *)videoPlayer update]; + bFrameNew = [(__bridge AVFoundationVideoPlayer *)videoPlayer isNewFrame]; // check for new frame staright after the call to update. if(bFrameNew) { /** @@ -156,7 +155,7 @@ ofLogWarning("ofxiOSVideoPlayer::play()") << "video not loaded"; } - [(AVFoundationVideoPlayer *)videoPlayer play]; + [(__bridge AVFoundationVideoPlayer *)videoPlayer play]; } //---------------------------------------- @@ -165,8 +164,8 @@ return; } - [(AVFoundationVideoPlayer *)videoPlayer pause]; - [(AVFoundationVideoPlayer *)videoPlayer setPosition:0]; + [(__bridge AVFoundationVideoPlayer *)videoPlayer pause]; + [(__bridge AVFoundationVideoPlayer *)videoPlayer setPosition:0]; } //---------------------------------------- @@ -195,7 +194,7 @@ bResetPixels = false; } - CVImageBufferRef imageBuffer = [(AVFoundationVideoPlayer *)videoPlayer getCurrentFrame]; + CVImageBufferRef imageBuffer = [(__bridge AVFoundationVideoPlayer *)videoPlayer getCurrentFrame]; CVPixelBufferLockBaseAddress(imageBuffer, kCVPixelBufferLock_ReadOnly); @@ -288,10 +287,10 @@ int maxTextureSize = 0; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - if([(AVFoundationVideoPlayer *)videoPlayer getWidth] > maxTextureSize || - [(AVFoundationVideoPlayer *)videoPlayer getHeight] > maxTextureSize) { + if([(__bridge AVFoundationVideoPlayer *)videoPlayer getWidth] > maxTextureSize || + [(__bridge AVFoundationVideoPlayer *)videoPlayer getHeight] > maxTextureSize) { ofLogWarning("ofxiOSVideoPlayer::getTexturePtr()") - << [(AVFoundationVideoPlayer *)videoPlayer getWidth] << "x" << [(AVFoundationVideoPlayer *)videoPlayer getHeight] + << [(__bridge AVFoundationVideoPlayer *)videoPlayer getWidth] << "x" << [(__bridge AVFoundationVideoPlayer *)videoPlayer getHeight] << " video image is bigger then max supported texture size " << maxTextureSize; return NULL; } @@ -307,7 +306,7 @@ //---------------------------------------- texture cache void ofxiOSVideoPlayer::initTextureCache() { - CVImageBufferRef imageBuffer = [(AVFoundationVideoPlayer *)videoPlayer getCurrentFrame]; + CVImageBufferRef imageBuffer = [(__bridge AVFoundationVideoPlayer *)videoPlayer getCurrentFrame]; if(imageBuffer == nil) { return; } @@ -329,8 +328,8 @@ * so... we can use ofTexture::setUseExternalTextureID() to get around this. */ - int videoTextureW = [(AVFoundationVideoPlayer *)videoPlayer getWidth]; - int videoTextureH = [(AVFoundationVideoPlayer *)videoPlayer getHeight]; + int videoTextureW = [(__bridge AVFoundationVideoPlayer *)videoPlayer getWidth]; + int videoTextureH = [(__bridge AVFoundationVideoPlayer *)videoPlayer getHeight]; videoTexture.allocate(videoTextureW, videoTextureH, GL_RGBA); ofTextureData & texData = videoTexture.getTextureData(); @@ -397,7 +396,7 @@ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getWidth]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getWidth]; } //---------------------------------------- @@ -406,7 +405,7 @@ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getHeight]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getHeight]; } //---------------------------------------- @@ -415,7 +414,7 @@ return false; } - return ![((AVFoundationVideoPlayer *)videoPlayer) isPlaying]; + return ![((__bridge AVFoundationVideoPlayer *)videoPlayer) isPlaying]; } //---------------------------------------- @@ -424,7 +423,7 @@ return false; } - return [((AVFoundationVideoPlayer *)videoPlayer) isReady]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) isReady]; } //---------------------------------------- @@ -433,7 +432,7 @@ return false; } - return [((AVFoundationVideoPlayer *)videoPlayer) isPlaying]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) isPlaying]; } //---------------------------------------- @@ -442,7 +441,7 @@ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getPosition]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getPosition]; } //---------------------------------------- @@ -451,7 +450,7 @@ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getSpeed]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getSpeed]; } //---------------------------------------- @@ -460,7 +459,7 @@ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getDurationInSec]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getDurationInSec]; } //---------------------------------------- @@ -469,7 +468,7 @@ return false; } - return [((AVFoundationVideoPlayer *)videoPlayer) isFinished]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) isFinished]; } //---------------------------------------- @@ -479,9 +478,9 @@ } if(bPause) { - [((AVFoundationVideoPlayer *)videoPlayer) pause]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) pause]; } else { - [((AVFoundationVideoPlayer *)videoPlayer) play]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) play]; } } @@ -491,7 +490,7 @@ return; } - [((AVFoundationVideoPlayer *)videoPlayer) setPosition:pct]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setPosition:pct]; } //---------------------------------------- @@ -503,7 +502,7 @@ ofLogWarning("ofxiOSVideoPlayer::setVolume()") << "expected range is 0-1, limiting requested volume " << volume << " to 1.0"; volume = 1.0f; } - [((AVFoundationVideoPlayer *)videoPlayer) setVolume:volume]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setVolume:volume]; } //---------------------------------------- @@ -517,7 +516,7 @@ (state == OF_LOOP_PALINDROME)) { bLoop = true; } - [((AVFoundationVideoPlayer *)videoPlayer) setLoop:bLoop]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setLoop:bLoop]; } //---------------------------------------- @@ -526,7 +525,7 @@ return; } - [((AVFoundationVideoPlayer *)videoPlayer) setSpeed:speed]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setSpeed:speed]; } //---------------------------------------- @@ -535,7 +534,7 @@ return; } - [((AVFoundationVideoPlayer *)videoPlayer) setFrame:frame]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setFrame:frame]; } //---------------------------------------- @@ -543,7 +542,7 @@ if(videoPlayer == NULL){ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getCurrentFrameNum]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getCurrentFrameNum]; } //---------------------------------------- @@ -551,7 +550,7 @@ if(videoPlayer == NULL){ return 0; } - return [((AVFoundationVideoPlayer *)videoPlayer) getDurationInFrames]; + return [((__bridge AVFoundationVideoPlayer *)videoPlayer) getDurationInFrames]; } //---------------------------------------- @@ -560,7 +559,7 @@ return OF_LOOP_NONE; } - bool bLoop = [((AVFoundationVideoPlayer *)videoPlayer) getLoop]; + bool bLoop = [((__bridge AVFoundationVideoPlayer *)videoPlayer) getLoop]; if(bLoop) { return OF_LOOP_NORMAL; } @@ -573,7 +572,7 @@ return; } - [((AVFoundationVideoPlayer *)videoPlayer) setPosition:0]; + [((__bridge AVFoundationVideoPlayer *)videoPlayer) setPosition:0]; } //---------------------------------------- diff --git a/libs/openFrameworks/app/ofAppGLFWWindow.cpp b/libs/openFrameworks/app/ofAppGLFWWindow.cpp index 66d05e7fc42..c47a282280e 100644 --- a/libs/openFrameworks/app/ofAppGLFWWindow.cpp +++ b/libs/openFrameworks/app/ofAppGLFWWindow.cpp @@ -1732,11 +1732,11 @@ EGLSurface ofAppGLFWWindow::getEGLSurface(){ #if defined(TARGET_OSX) void * ofAppGLFWWindow::getNSGLContext(){ - return glfwGetNSGLContext(windowP); + return (__bridge void *)glfwGetNSGLContext(windowP); } void * ofAppGLFWWindow::getCocoaWindow(){ - return glfwGetCocoaWindow(windowP); + return (__bridge void *)glfwGetCocoaWindow(windowP); } #endif diff --git a/libs/openFrameworks/utils/ofConstants.h b/libs/openFrameworks/utils/ofConstants.h index 8afb8b778be..4a06d3952d0 100644 --- a/libs/openFrameworks/utils/ofConstants.h +++ b/libs/openFrameworks/utils/ofConstants.h @@ -196,6 +196,10 @@ enum ofTargetPlatform{ #if defined(__LITTLE_ENDIAN__) #define TARGET_LITTLE_ENDIAN // intel cpu #endif + + #if defined(__OBJC__) && !__has_feature(objc_arc) + #error "Please enable ARC (Automatic Reference Counting) at the project level" + #endif #endif #ifdef TARGET_LINUX @@ -246,6 +250,11 @@ enum ofTargetPlatform{ #define TARGET_LITTLE_ENDIAN // arm cpu + + #if defined(__OBJC__) && !__has_feature(objc_arc) + #error "Please enable ARC (Automatic Reference Counting) at the project level" + #endif + #endif #ifdef TARGET_ANDROID diff --git a/libs/openFrameworks/utils/ofSystemUtils.cpp b/libs/openFrameworks/utils/ofSystemUtils.cpp index 05190ebf850..478e9813f0e 100644 --- a/libs/openFrameworks/utils/ofSystemUtils.cpp +++ b/libs/openFrameworks/utils/ofSystemUtils.cpp @@ -68,7 +68,7 @@ std::wstring convertNarrowToWide( const std::string& as ){ #if defined( TARGET_OSX ) static void restoreAppWindowFocus(){ - NSWindow * appWindow = (NSWindow *)ofGetCocoaWindow(); + NSWindow * appWindow = (__bridge NSWindow *)ofGetCocoaWindow(); if(appWindow) { [appWindow makeKeyAndOrderFront:nil]; } @@ -292,7 +292,7 @@ void ofSystemAlertDialog(string errorMessage){ #ifdef TARGET_OSX @autoreleasepool { - NSAlert* alertDialog = [[[NSAlert alloc] init] autorelease]; + NSAlert* alertDialog = [[NSAlert alloc] init]; alertDialog.messageText = [NSString stringWithUTF8String:errorMessage.c_str()]; [alertDialog runModal]; restoreAppWindowFocus(); @@ -627,13 +627,13 @@ string ofSystemTextBoxDialog(string question, string text){ #ifdef TARGET_OSX @autoreleasepool { // create alert dialog - NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"OK"]; [alert addButtonWithTitle:@"Cancel"]; [alert setMessageText:[NSString stringWithCString:question.c_str() encoding:NSUTF8StringEncoding]]; // create text field - NSTextField* label = [[[NSTextField alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0,0,300,40))] autorelease]; + NSTextField* label = [[NSTextField alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0,0,300,40))]; [label setStringValue:[NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding]]; // add text field to alert dialog diff --git a/libs/openFrameworks/video/ofAVFoundationGrabber.mm b/libs/openFrameworks/video/ofAVFoundationGrabber.mm index 30f6881ccc9..5e697dfb52d 100644 --- a/libs/openFrameworks/video/ofAVFoundationGrabber.mm +++ b/libs/openFrameworks/video/ofAVFoundationGrabber.mm @@ -20,7 +20,7 @@ @implementation OSXVideoGrabber #pragma mark - #pragma mark Initialization -- (id)init { +- (instancetype)init { self = [super init]; if (self) { captureInput = nil; @@ -153,7 +153,6 @@ - (BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h{ dispatch_queue_t queue; queue = dispatch_queue_create("cameraQueue", NULL); [captureOutput setSampleBufferDelegate:self queue:queue]; - dispatch_release(queue); NSDictionary* videoSettings =[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithDouble:width], (id)kCVPixelBufferWidthKey, @@ -166,7 +165,7 @@ - (BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h{ if(self.captureSession) { self.captureSession = nil; } - self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; + self.captureSession = [[AVCaptureSession alloc] init]; [self.captureSession beginConfiguration]; @@ -342,7 +341,6 @@ - (void)dealloc { if(captureOutput.sampleBufferDelegate != nil) { [captureOutput setSampleBufferDelegate:nil queue:NULL]; } - [captureOutput release]; captureOutput = nil; } @@ -358,7 +356,6 @@ - (void)dealloc { CGImageRelease(currentFrame); currentFrame = nil; } - [super dealloc]; } - (void)eraseGrabberPtr { @@ -398,7 +395,6 @@ - (void)eraseGrabberPtr { // Stop and release the the OSXVideoGrabber [grabber stopCapture]; [grabber eraseGrabberPtr]; - [grabber release]; grabber = nil; } clear(); diff --git a/libs/openFrameworks/video/ofAVFoundationPlayer.mm b/libs/openFrameworks/video/ofAVFoundationPlayer.mm index 5f624964ced..9768f29caed 100644 --- a/libs/openFrameworks/video/ofAVFoundationPlayer.mm +++ b/libs/openFrameworks/video/ofAVFoundationPlayer.mm @@ -160,7 +160,6 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ @autoreleasepool { [currentPlayer unloadVideo]; // synchronious call to unload video - [currentPlayer autorelease]; // release } }); diff --git a/libs/openFrameworks/video/ofAVFoundationVideoPlayer.h b/libs/openFrameworks/video/ofAVFoundationVideoPlayer.h index 0862980fd0a..98c27e279b6 100644 --- a/libs/openFrameworks/video/ofAVFoundationVideoPlayer.h +++ b/libs/openFrameworks/video/ofAVFoundationVideoPlayer.h @@ -32,22 +32,10 @@ typedef enum _playerLoopType{ //---------------------------------------------------------- video player. @interface ofAVFoundationVideoPlayer : NSObject { - - AVPlayer * _player; - AVAsset * _asset; - AVPlayerItem * _playerItem; - - - AVAssetReader * _assetReader; - AVAssetReaderTrackOutput * _assetReaderVideoTrackOutput; - AVAssetReaderTrackOutput * _assetReaderAudioTrackOutput; - #if defined(USE_VIDEO_OUTPUT) CMVideoFormatDescriptionRef _videoInfo; - AVPlayerItemVideoOutput * _videoOutput; #endif - id timeObserver; CMSampleBufferRef videoSampleBuffer; @@ -89,17 +77,17 @@ typedef enum _playerLoopType{ NSCondition* deallocCond; } -@property (nonatomic, retain) AVPlayer * player; -@property (nonatomic, retain) AVAsset * asset; -@property (nonatomic, retain) AVPlayerItem * playerItem; +@property (nonatomic, strong) AVPlayer * player; +@property (nonatomic, strong) AVAsset * asset; +@property (nonatomic, strong) AVPlayerItem * playerItem; -@property (nonatomic, retain) AVAssetReader * assetReader; -@property (nonatomic, retain) AVAssetReaderTrackOutput * assetReaderVideoTrackOutput; -@property (nonatomic, retain) AVAssetReaderTrackOutput * assetReaderAudioTrackOutput; +@property (nonatomic, strong) AVAssetReader * assetReader; +@property (nonatomic, strong) AVAssetReaderTrackOutput * assetReaderVideoTrackOutput; +@property (nonatomic, strong) AVAssetReaderTrackOutput * assetReaderAudioTrackOutput; #if defined(USE_VIDEO_OUTPUT) -@property (nonatomic, retain) AVPlayerItemVideoOutput *videoOutput; +@property (nonatomic, strong) AVPlayerItemVideoOutput *videoOutput; #endif diff --git a/libs/openFrameworks/video/ofAVFoundationVideoPlayer.m b/libs/openFrameworks/video/ofAVFoundationVideoPlayer.m index ced9fb37748..c8b654ac09b 100644 --- a/libs/openFrameworks/video/ofAVFoundationVideoPlayer.m +++ b/libs/openFrameworks/video/ofAVFoundationVideoPlayer.m @@ -17,23 +17,11 @@ //---------------------------------------------------------- video player. @implementation ofAVFoundationVideoPlayer -@synthesize player = _player; -@synthesize asset = _asset; -@synthesize playerItem = _playerItem; - -@synthesize assetReader = _assetReader; -@synthesize assetReaderVideoTrackOutput = _assetReaderVideoTrackOutput; -@synthesize assetReaderAudioTrackOutput = _assetReaderAudioTrackOutput; -#if defined(USE_VIDEO_OUTPUT) -@synthesize videoOutput = _videoOutput; -#endif - - static const void *ItemStatusContext = &ItemStatusContext; static const void *PlayerRateContext = &ItemStatusContext; -- (id)init { +- (instancetype)init { self = [super init]; if(self) { @@ -101,7 +89,7 @@ - (void)createVideoOutput NSDictionary *pixBuffAttributes = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32ARGB)}; #endif - self.videoOutput = [[[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes] autorelease]; + self.videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes]; if (!self.videoOutput) { NSLog(@"error creating video output"); return; @@ -124,15 +112,9 @@ - (void)dealloc [asyncLock unlock]; // release locks - [asyncLock autorelease]; - if (deallocCond != nil) { - [deallocCond release]; - deallocCond = nil; + deallocCond = nil; } - - - [super dealloc]; } @@ -348,15 +330,14 @@ - (BOOL)loadWithURL:(NSURL*)url async:(BOOL)bAsync { //------------------------------------------------------------ recreate player. // destroy player if any - should never be the case!! - if(_player != nil) { + if(self.player != nil) { [self removeTimeObserverFromPlayer]; [self.player removeObserver:self forKeyPath:kRateKey context:&PlayerRateContext]; self.player = nil; - [_player release]; } // create new player - _player = [[AVPlayer playerWithPlayerItem:self.playerItem] retain]; + self.player = [AVPlayer playerWithPlayerItem:self.playerItem]; [self.player addObserver:self forKeyPath:kRateKey options:NSKeyValueObservingOptionNew @@ -381,10 +362,8 @@ - (BOOL)loadWithURL:(NSURL*)url async:(BOOL)bAsync { // Wait for the dispatch semaphore signal if(bAsync == NO){ dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); - dispatch_release(sema); return bLoaded; } else { - dispatch_release(sema); return YES; } } @@ -468,16 +447,13 @@ - (void)unloadVideoAsync { // relase assetreader if (currentReader != nil) { [currentReader cancelReading]; - [currentReader autorelease]; currentReader = nil; if (currentVideoTrack != nil) { - [currentVideoTrack autorelease]; currentVideoTrack = nil; } if (currentAudioTrack != nil) { - [currentAudioTrack autorelease]; currentAudioTrack = nil; } } @@ -485,7 +461,6 @@ - (void)unloadVideoAsync { // release asset if (currentAsset != nil) { [currentAsset cancelLoading]; - [currentAsset autorelease]; currentAsset = nil; } @@ -514,7 +489,6 @@ - (void)unloadVideoAsync { // release videouOutput if (currentVideoOutput != nil) { - [currentVideoOutput autorelease]; currentVideoOutput = nil; } @@ -525,7 +499,6 @@ - (void)unloadVideoAsync { } #endif - [currentItem autorelease]; currentItem = nil; } @@ -536,11 +509,9 @@ - (void)unloadVideoAsync { if (currentTimeObserver != nil) { [currentPlayer removeTimeObserver:currentTimeObserver]; - [currentTimeObserver autorelease]; currentTimeObserver = nil; } - [currentPlayer autorelease]; currentPlayer = nil; } @@ -580,7 +551,6 @@ - (void)unloadVideo [deallocCond wait]; [deallocCond unlock]; - [deallocCond release]; deallocCond = nil; } @@ -620,7 +590,7 @@ - (BOOL)createAssetReaderWithTimeRange:(CMTimeRange)timeRange { //------------------------------------------------------------ add video output. if (bSampleVideo) { - NSMutableDictionary * videoOutputSettings = [[[NSMutableDictionary alloc] init] autorelease]; + NSMutableDictionary * videoOutputSettings = [[NSMutableDictionary alloc] init]; #ifdef TARGET_IOS [videoOutputSettings setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]; @@ -1108,17 +1078,16 @@ - (void)addTimeObserverToPlayer { double interval = 1.0 / (double)frameRate; __block ofAVFoundationVideoPlayer* refToSelf = self; - timeObserver = [[_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(interval, NSEC_PER_SEC) - queue:dispatch_get_main_queue() usingBlock: - ^(CMTime time) { - [refToSelf update]; - }] retain]; + timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(interval, NSEC_PER_SEC) + queue:dispatch_get_main_queue() + usingBlock:^(CMTime time) { + [refToSelf update]; + }]; } - (void)removeTimeObserverFromPlayer { if(timeObserver != nil) { [_player removeTimeObserver:timeObserver]; - [timeObserver release]; timeObserver = nil; } } diff --git a/libs/openFrameworksCompiled/project/ios/CoreOF.xcconfig b/libs/openFrameworksCompiled/project/ios/CoreOF.xcconfig index 9eb221509a3..bb7e43171da 100644 --- a/libs/openFrameworksCompiled/project/ios/CoreOF.xcconfig +++ b/libs/openFrameworksCompiled/project/ios/CoreOF.xcconfig @@ -42,3 +42,4 @@ OF_CORE_FRAMEWORKS = -framework AudioToolbox -framework Accelerate -framework AV CLANG_CXX_LIBRARY = libc++ CLANG_CXX_LANGUAGE_STANDARD = c++17 IPHONEOS_DEPLOYMENT_TARGET = 13.0 +CLANG_ENABLE_OBJC_ARC = YES diff --git a/libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig b/libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig index f6076377bf0..76125ee4d42 100644 --- a/libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig +++ b/libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig @@ -2,6 +2,8 @@ CLANG_CXX_LIBRARY = libc++ CLANG_CXX_LANGUAGE_STANDARD = c++11 +CLANG_ENABLE_OBJC_ARC = YES + MACOSX_DEPLOYMENT_TARGET = 10.9 diff --git a/libs/openFrameworksCompiled/project/osx/config.osx.default.mk b/libs/openFrameworksCompiled/project/osx/config.osx.default.mk index 1e41fa4d777..083ea74476b 100644 --- a/libs/openFrameworksCompiled/project/osx/config.osx.default.mk +++ b/libs/openFrameworksCompiled/project/osx/config.osx.default.mk @@ -147,6 +147,10 @@ PLATFORM_CFLAGS += -mmacosx-version-min=$(MAC_OS_MIN_VERSION) PLATFORM_CXXFLAGS += -x objective-c++ PLATFORM_CXXFLAGS += $(MAC_OS_CPP_VER) +# Enable ARC +PLATFORM_CFLAGS += -fobjc-arc + + ifeq ($(USE_GST),1) PLATFORM_CFLAGS += -I/Library/Frameworks/Gstreamer.framework/Headers endif diff --git a/libs/openFrameworksCompiled/project/tvOS/CoreOF.xcconfig b/libs/openFrameworksCompiled/project/tvOS/CoreOF.xcconfig index d72cd2e2db5..6832fbe5feb 100644 --- a/libs/openFrameworksCompiled/project/tvOS/CoreOF.xcconfig +++ b/libs/openFrameworksCompiled/project/tvOS/CoreOF.xcconfig @@ -42,3 +42,5 @@ OF_CORE_FRAMEWORKS = -framework AudioToolbox -framework Accelerate -framework AV CLANG_CXX_LIBRARY = libc++ CLANG_CXX_LANGUAGE_STANDARD = c++17 TVOS_DEPLOYMENT_TARGET = 13.0 +CLANG_ENABLE_OBJC_ARC = YES + diff --git a/libs/openFrameworksCompiled/project/tvOS/tvOS+OFLib.xcodeproj/project.pbxproj b/libs/openFrameworksCompiled/project/tvOS/tvOS+OFLib.xcodeproj/project.pbxproj index 20129e9c040..c0d61f5e31a 100644 --- a/libs/openFrameworksCompiled/project/tvOS/tvOS+OFLib.xcodeproj/project.pbxproj +++ b/libs/openFrameworksCompiled/project/tvOS/tvOS+OFLib.xcodeproj/project.pbxproj @@ -457,8 +457,6 @@ libc++ CLANG_ENABLE_MODULES YES - CLANG_ENABLE_OBJC_ARC - NO CLANG_WARN_BOOL_CONVERSION YES CLANG_WARN_CONSTANT_CONVERSION @@ -546,8 +544,6 @@ libc++ CLANG_ENABLE_MODULES YES - CLANG_ENABLE_OBJC_ARC - NO CLANG_WARN_BOOL_CONVERSION YES CLANG_WARN_CONSTANT_CONVERSION