[Visualizer] Constrain SceneKit visualizer events

Constrain observer events to the exact context requested, and remove
them with the same context specified.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-10 22:35:51 -07:00
parent 10f0644407
commit b821896560
1 changed files with 11 additions and 9 deletions

View File

@ -15,7 +15,7 @@
#define LOWER_BOUND -80 #define LOWER_BOUND -80
void *kSpectrumViewContext = &kSpectrumViewContext; static void *kSpectrumViewContext = &kSpectrumViewContext;
extern NSString *CogPlaybackDidBeginNotficiation; extern NSString *CogPlaybackDidBeginNotficiation;
extern NSString *CogPlaybackDidPauseNotficiation; extern NSString *CogPlaybackDidPauseNotficiation;
@ -80,9 +80,11 @@ extern NSString *CogPlaybackDidStopNotficiation;
change:(NSDictionary<NSKeyValueChangeKey, id> *)change change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context { context:(void *)context {
if(context == kSpectrumViewContext) { if(context == kSpectrumViewContext) {
[self updateControls]; if([keyPath isEqualToString:@"self.window.visible"]) {
} else if([keyPath isEqualToString:@"self.window.visible"]) { [self updateVisListening];
[self updateVisListening]; } else {
[self updateControls];
}
} }
} }
@ -185,7 +187,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewContext];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewContext];
[self addObserver:self forKeyPath:@"self.window.visible" options:0 context:nil]; [self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewContext];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidBegin:) selector:@selector(playbackDidBegin:)
@ -217,11 +219,11 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)removeObservers { - (void)removeObservers {
if(observersAdded) { if(observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode" context:kSpectrumViewContext];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewContext];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewContext];
[self removeObserver:self forKeyPath:@"self.window.visible" context:nil]; [self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewContext];
[[NSNotificationCenter defaultCenter] removeObserver:self [[NSNotificationCenter defaultCenter] removeObserver:self
name:CogPlaybackDidBeginNotficiation name:CogPlaybackDidBeginNotficiation