Skip to content

Commit

Permalink
Actually do shutdown and memory management properly too! So you can o…
Browse files Browse the repository at this point in the history
…pen and close

Former-commit-id: b2be3b8
  • Loading branch information
baconpaul committed Dec 14, 2018
1 parent 876c317 commit d225838
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
5 changes: 5 additions & 0 deletions src/au/aulayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ aulayer::~aulayer()
plugin_instance->~plugin();
_aligned_free(plugin_instance);
}

if( editor_instance )
{
delete editor_instance;
}
}

//----------------------------------------------------------------------------------------------------
Expand Down
65 changes: 25 additions & 40 deletions src/au/aulayer_cocoaui.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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


Expand Down
4 changes: 4 additions & 0 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d225838

Please sign in to comment.