diff --git a/SpectrumWindowController.h b/SpectrumWindowController.h index 621fce94c..218a0a09c 100644 --- a/SpectrumWindowController.h +++ b/SpectrumWindowController.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface SpectrumWindowController : NSWindowController { +@interface SpectrumWindowController : NSWindowController { IBOutlet PlaybackController *playbackController; } diff --git a/SpectrumWindowController.m b/SpectrumWindowController.m index fb180fbf6..6fd4e5beb 100644 --- a/SpectrumWindowController.m +++ b/SpectrumWindowController.m @@ -22,15 +22,33 @@ - (void)windowDidLoad { [super windowDidLoad]; - self.spectrumView = [[SpectrumView alloc] initWithFrame:[[self window] frame]]; - [[self window] setContentView:self.spectrumView]; + [self startRunning]; +} - [self.spectrumView enableCameraControl]; +- (void)startRunning { + if(!self.spectrumView) { + self.spectrumView = [[SpectrumView alloc] initWithFrame:[[self window] frame]]; + [[self window] setContentView:self.spectrumView]; + + [self.spectrumView enableCameraControl]; + } if(playbackController.playbackStatus == CogStatusPlaying) [self.spectrumView startPlayback]; } +- (void)stopRunning { + [[self window] setContentView:nil]; + self.spectrumView = nil; +} + +- (void)windowWillClose:(NSNotification *)notification { + NSWindow *currentWindow = notification.object; + if([currentWindow isEqualTo:self.window]) { + [self stopRunning]; + } +} + - (IBAction)toggleWindow:(id)sender { if([[self window] isVisible]) [[self window] orderOut:self]; @@ -39,8 +57,7 @@ } - (IBAction)showWindow:(id)sender { - if(self.spectrumView && playbackController.playbackStatus == CogStatusPlaying) - [self.spectrumView startPlayback]; + [self startRunning]; return [super showWindow:sender]; }