From d225838c221d53489b3e3af69272484c89e58ea3 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 13 Dec 2018 20:51:42 -0500 Subject: [PATCH] Actually do shutdown and memory management properly too! So you can open and close Former-commit-id: b2be3b822618fb959fe99dfb74811572497bbcad --- src/au/aulayer.cpp | 5 +++ src/au/aulayer_cocoaui.mm | 65 ++++++++++++------------------- src/common/gui/SurgeGUIEditor.cpp | 4 ++ 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/au/aulayer.cpp b/src/au/aulayer.cpp index ce4f6baedd6..4b8fb39b848 100644 --- a/src/au/aulayer.cpp +++ b/src/au/aulayer.cpp @@ -26,6 +26,11 @@ aulayer::~aulayer() plugin_instance->~plugin(); _aligned_free(plugin_instance); } + + if( editor_instance ) + { + delete editor_instance; + } } //---------------------------------------------------------------------------------------------------- diff --git a/src/au/aulayer_cocoaui.mm b/src/au/aulayer_cocoaui.mm index 7a201d7e404..04d8674fec3 100644 --- a/src/au/aulayer_cocoaui.mm +++ b/src/au/aulayer_cocoaui.mm @@ -15,12 +15,12 @@ @interface SurgeNSView : NSView { SurgeGUIEditor *editController; - NSTimer *idleTimer; + CFRunLoopTimerRef idleTimer; } - (id) initWithSurge: (SurgeGUIEditor *) cont preferredSize: (NSSize) size; - (void) doIdle; -- (void) drawRect:(NSRect)dirtyRect; +- (void) dealloc; @end @@ -69,6 +69,7 @@ @implementation SurgeNSView - (id) initWithSurge: (SurgeGUIEditor *) cont preferredSize: (NSSize) size { self = [super initWithFrame: NSMakeRect (0, 0, size.width / 2, size.height / 2)]; + idleTimer = nil; editController = cont; if (self) { @@ -84,38 +85,18 @@ - (id) initWithSurge: (SurgeGUIEditor *) cont preferredSize: (NSSize) size AULOG::log( "Done resizing\n" ); - CFTimeInterval TIMER_INTERVAL = .05; // In SurgeGUISynthesizer.h it uses 50 ms + CFTimeInterval TIMER_INTERVAL = .05; // In SurgeGUISynthesizer.h it uses 50 ms CFRunLoopTimerContext TimerContext = {0, self, NULL, NULL, NULL}; - CFAbsoluteTime FireTime = CFAbsoluteTimeGetCurrent() + TIMER_INTERVAL; - auto mTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, - FireTime, - TIMER_INTERVAL, - 0, 0, - timerCallback, - &TimerContext); - if (mTimer) - CFRunLoopAddTimer (CFRunLoopGetMain (), mTimer, kCFRunLoopCommonModes); + CFAbsoluteTime FireTime = CFAbsoluteTimeGetCurrent() + TIMER_INTERVAL; + idleTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, + FireTime, + TIMER_INTERVAL, + 0, 0, + timerCallback, + &TimerContext); + if (idleTimer) + CFRunLoopAddTimer (CFRunLoopGetMain (), idleTimer, kCFRunLoopCommonModes); AULOG::log( "Added timer on %d\n", self ); - /*idleTimer = [NSTimer timerWithTimeInterval:1.0 - target:self - selector:@selector(doIdle:) - userInfo:nil - repeats:YES - ];*/ - - //[[NSRunLoop currentRunLoop] addTime:idleTimer forMode:NSDefaultRunLoopMode]; - - AULOG::log( "Timer made %d\n", [NSRunLoop currentRunLoop] ); - // Start the idle thread - //[NSThread detachNewThreadSelector:@selector(runIdle) toTarget:[self retain] withObject:nil]; - -/* - // What was this? - isAttached = YES; - UInt32 size = sizeof (FObject*); - if (AudioUnitGetProperty (audioUnit, 64001, kAudioUnitScope_Global, 0, &dynlib, &size) == noErr) - dynlib->addRef (); -*/ } return self; @@ -126,15 +107,19 @@ - (void) doIdle editController->idle(); } -// Just for now -- (void) drawRect:(NSRect)dirtyRect { - // This next line sets the the current fill color parameter of the Graphics Context - [[NSColor redColor] setFill]; - // This next function fills a rect the same as dirtyRect with the current fill color of the Graphics Context. - NSRectFill(dirtyRect); - // You might want to use _bounds or self.bounds if you want to be sure to fill the entire bounds rect of the view. - [super drawRect:dirtyRect]; +- (void) dealloc +{ + AULOG::log( "Shutting down SurgeNSView in dealloc\n" ); + editController->close(); + if( idleTimer ) + { + AULOG::log( "Invadliated Timer\n" ); + CFRunLoopTimerInvalidate( idleTimer ); + } + + [super dealloc]; } + @end diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index 3566bda70ca..f3d2d4d9362 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -1160,6 +1160,10 @@ bool PLUGIN_API SurgeGUIEditor::open(void* parent, const PlatformType& platformT void SurgeGUIEditor::close() { +#ifndef TARGET_VST3 + super::close(); +#endif + #ifdef TARGET_VST3 _idleTimer->stop(); #endif