[Spectrum Visualizer] Add crash check for SceneKit

The SceneKit visualizer now has a crash check, which will trigger if an
exception is thrown by the app.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-17 22:14:32 -07:00
parent fda16cc401
commit cbcbdf893d
8 changed files with 91 additions and 65 deletions

View File

@ -20,6 +20,11 @@
AppController *_appController; AppController *_appController;
} }
- (void)reportException:(NSException *)exception {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"sceneKitCrashed"];
[super reportException:exception];
}
- (void)finishLaunching { - (void)finishLaunching {
[super finishLaunching]; [super finishLaunching];
_appController = (AppController *)[self delegate]; _appController = (AppController *)[self delegate];

View File

@ -105,7 +105,7 @@
83293070277886250010C07E /* OpenMPTOld.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8329306D277885790010C07E /* OpenMPTOld.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 83293070277886250010C07E /* OpenMPTOld.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8329306D277885790010C07E /* OpenMPTOld.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
832C1253180BD1E2005507C1 /* Cog.help in Resources */ = {isa = PBXBuildFile; fileRef = 832C1252180BD1E2005507C1 /* Cog.help */; }; 832C1253180BD1E2005507C1 /* Cog.help in Resources */ = {isa = PBXBuildFile; fileRef = 832C1252180BD1E2005507C1 /* Cog.help */; };
832CFC4F2851AA1A002AC26F /* NSView+Visibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 832CFC4E2851AA1A002AC26F /* NSView+Visibility.m */; }; 832CFC4F2851AA1A002AC26F /* NSView+Visibility.m in Sources */ = {isa = PBXBuildFile; fileRef = 832CFC4E2851AA1A002AC26F /* NSView+Visibility.m */; };
832CFC562851AA8B002AC26F /* SpectrumViewLegacy.m in Sources */ = {isa = PBXBuildFile; fileRef = 832CFC552851AA8B002AC26F /* SpectrumViewLegacy.m */; }; 832CFC562851AA8B002AC26F /* SpectrumViewCG.m in Sources */ = {isa = PBXBuildFile; fileRef = 832CFC552851AA8B002AC26F /* SpectrumViewCG.m */; };
833D0C2527C4ABB80060E16A /* ScriptAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 833D0C2427C4ABB80060E16A /* ScriptAdditions.m */; }; 833D0C2527C4ABB80060E16A /* ScriptAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 833D0C2427C4ABB80060E16A /* ScriptAdditions.m */; };
83489C6B2782F78700BDCEA2 /* libvgmPlayer.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83489C542782F2DF00BDCEA2 /* libvgmPlayer.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 83489C6B2782F78700BDCEA2 /* libvgmPlayer.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 83489C542782F2DF00BDCEA2 /* libvgmPlayer.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
8349270C27B4EFFC0009AB2B /* duplicateItemsTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 8349270127B4EFFC0009AB2B /* duplicateItemsTemplate.pdf */; }; 8349270C27B4EFFC0009AB2B /* duplicateItemsTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 8349270127B4EFFC0009AB2B /* duplicateItemsTemplate.pdf */; };
@ -149,7 +149,7 @@
8370D73F2775AE1300245CE0 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8370D73E2775AE1300245CE0 /* libsqlite3.tbd */; }; 8370D73F2775AE1300245CE0 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8370D73E2775AE1300245CE0 /* libsqlite3.tbd */; };
83717825285D685800DE781D /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 83717824285D685800DE781D /* FirebaseAppCheck */; }; 83717825285D685800DE781D /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 83717824285D685800DE781D /* FirebaseAppCheck */; };
8372C93D27C7895300E250C9 /* MAD.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8372C93027C785BE00E250C9 /* MAD.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8372C93D27C7895300E250C9 /* MAD.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8372C93027C785BE00E250C9 /* MAD.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
8377C66327B8CF6300E8BC0F /* SpectrumView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8377C66127B8CF6300E8BC0F /* SpectrumView.m */; }; 8377C66327B8CF6300E8BC0F /* SpectrumViewSK.m in Sources */ = {isa = PBXBuildFile; fileRef = 8377C66127B8CF6300E8BC0F /* SpectrumViewSK.m */; };
8377C6B927B900F000E8BC0F /* SpectrumItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 8377C6B827B900F000E8BC0F /* SpectrumItem.m */; }; 8377C6B927B900F000E8BC0F /* SpectrumItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 8377C6B827B900F000E8BC0F /* SpectrumItem.m */; };
837DC92B285B05710005C58A /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 837DC92A285B05710005C58A /* CoreData.framework */; }; 837DC92B285B05710005C58A /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 837DC92A285B05710005C58A /* CoreData.framework */; };
837DC931285B3F790005C58A /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 837DC92F285B3F790005C58A /* DataModel.xcdatamodeld */; }; 837DC931285B3F790005C58A /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 837DC92F285B3F790005C58A /* DataModel.xcdatamodeld */; };
@ -927,8 +927,8 @@
832C1252180BD1E2005507C1 /* Cog.help */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Cog.help; sourceTree = "<group>"; }; 832C1252180BD1E2005507C1 /* Cog.help */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Cog.help; sourceTree = "<group>"; };
832CFC4E2851AA1A002AC26F /* NSView+Visibility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSView+Visibility.m"; sourceTree = "<group>"; }; 832CFC4E2851AA1A002AC26F /* NSView+Visibility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSView+Visibility.m"; sourceTree = "<group>"; };
832CFC532851AA37002AC26F /* NSView+Visibility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSView+Visibility.h"; sourceTree = "<group>"; }; 832CFC532851AA37002AC26F /* NSView+Visibility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSView+Visibility.h"; sourceTree = "<group>"; };
832CFC542851AA8B002AC26F /* SpectrumViewLegacy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpectrumViewLegacy.h; sourceTree = SOURCE_ROOT; }; 832CFC542851AA8B002AC26F /* SpectrumViewCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpectrumViewCG.h; sourceTree = SOURCE_ROOT; };
832CFC552851AA8B002AC26F /* SpectrumViewLegacy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpectrumViewLegacy.m; sourceTree = SOURCE_ROOT; }; 832CFC552851AA8B002AC26F /* SpectrumViewCG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpectrumViewCG.m; sourceTree = SOURCE_ROOT; };
833D0C2027C4ABA00060E16A /* ScriptAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScriptAdditions.h; sourceTree = "<group>"; }; 833D0C2027C4ABA00060E16A /* ScriptAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScriptAdditions.h; sourceTree = "<group>"; };
833D0C2427C4ABB80060E16A /* ScriptAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScriptAdditions.m; sourceTree = "<group>"; }; 833D0C2427C4ABB80060E16A /* ScriptAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScriptAdditions.m; sourceTree = "<group>"; };
833F681E1CDBCAA700AFB9F0 /* es */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 833F681E1CDBCAA700AFB9F0 /* es */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -989,8 +989,8 @@
8370D73E2775AE1300245CE0 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; }; 8370D73E2775AE1300245CE0 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
8372C92A27C785BD00E250C9 /* MAD.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MAD.xcodeproj; path = Plugins/MAD/MAD.xcodeproj; sourceTree = "<group>"; }; 8372C92A27C785BD00E250C9 /* MAD.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MAD.xcodeproj; path = Plugins/MAD/MAD.xcodeproj; sourceTree = "<group>"; };
8375B05117FFEA400092A79F /* OpusPlugin.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OpusPlugin.xcodeproj; path = Plugins/Opus/OpusPlugin.xcodeproj; sourceTree = "<group>"; }; 8375B05117FFEA400092A79F /* OpusPlugin.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OpusPlugin.xcodeproj; path = Plugins/Opus/OpusPlugin.xcodeproj; sourceTree = "<group>"; };
8377C66127B8CF6300E8BC0F /* SpectrumView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpectrumView.m; path = Visualization/SpectrumView.m; sourceTree = "<group>"; }; 8377C66127B8CF6300E8BC0F /* SpectrumViewSK.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpectrumViewSK.m; path = Visualization/SpectrumViewSK.m; sourceTree = "<group>"; };
8377C66227B8CF6300E8BC0F /* SpectrumView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpectrumView.h; path = Visualization/SpectrumView.h; sourceTree = "<group>"; }; 8377C66227B8CF6300E8BC0F /* SpectrumViewSK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpectrumViewSK.h; path = Visualization/SpectrumViewSK.h; sourceTree = "<group>"; };
8377C66427B8CF7A00E8BC0F /* VisualizationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VisualizationController.h; path = Audio/Visualization/VisualizationController.h; sourceTree = "<group>"; }; 8377C66427B8CF7A00E8BC0F /* VisualizationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VisualizationController.h; path = Audio/Visualization/VisualizationController.h; sourceTree = "<group>"; };
8377C6B727B900F000E8BC0F /* SpectrumItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SpectrumItem.h; path = Visualization/SpectrumItem.h; sourceTree = "<group>"; }; 8377C6B727B900F000E8BC0F /* SpectrumItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SpectrumItem.h; path = Visualization/SpectrumItem.h; sourceTree = "<group>"; };
8377C6B827B900F000E8BC0F /* SpectrumItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SpectrumItem.m; path = Visualization/SpectrumItem.m; sourceTree = "<group>"; }; 8377C6B827B900F000E8BC0F /* SpectrumItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SpectrumItem.m; path = Visualization/SpectrumItem.m; sourceTree = "<group>"; };
@ -1841,10 +1841,10 @@
children = ( children = (
830C37EF27B9956C00E02BB0 /* ThirdParty */, 830C37EF27B9956C00E02BB0 /* ThirdParty */,
8377C66427B8CF7A00E8BC0F /* VisualizationController.h */, 8377C66427B8CF7A00E8BC0F /* VisualizationController.h */,
8377C66227B8CF6300E8BC0F /* SpectrumView.h */, 8377C66227B8CF6300E8BC0F /* SpectrumViewSK.h */,
8377C66127B8CF6300E8BC0F /* SpectrumView.m */, 8377C66127B8CF6300E8BC0F /* SpectrumViewSK.m */,
832CFC542851AA8B002AC26F /* SpectrumViewLegacy.h */, 832CFC542851AA8B002AC26F /* SpectrumViewCG.h */,
832CFC552851AA8B002AC26F /* SpectrumViewLegacy.m */, 832CFC552851AA8B002AC26F /* SpectrumViewCG.m */,
8377C6B727B900F000E8BC0F /* SpectrumItem.h */, 8377C6B727B900F000E8BC0F /* SpectrumItem.h */,
8377C6B827B900F000E8BC0F /* SpectrumItem.m */, 8377C6B827B900F000E8BC0F /* SpectrumItem.m */,
83229C9C283B0095004626A8 /* SpectrumWindowController.h */, 83229C9C283B0095004626A8 /* SpectrumWindowController.h */,
@ -2615,7 +2615,7 @@
1770429E0B8BC53600B86321 /* PlaybackController.m in Sources */, 1770429E0B8BC53600B86321 /* PlaybackController.m in Sources */,
1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */, 1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */,
8355D6B6180612F300D05687 /* NSData+MD5.m in Sources */, 8355D6B6180612F300D05687 /* NSData+MD5.m in Sources */,
8377C66327B8CF6300E8BC0F /* SpectrumView.m in Sources */, 8377C66327B8CF6300E8BC0F /* SpectrumViewSK.m in Sources */,
1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */, 1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */,
1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */, 1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */,
8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */, 8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */,
@ -2628,7 +2628,7 @@
5604D4F60D60726E004F5C5D /* SpotlightPlaylistEntry.m in Sources */, 5604D4F60D60726E004F5C5D /* SpotlightPlaylistEntry.m in Sources */,
56462EAF0D6341F6000AB68C /* SpotlightTransformers.m in Sources */, 56462EAF0D6341F6000AB68C /* SpotlightTransformers.m in Sources */,
830C37A527B95EB300E02BB0 /* EqualizerWindowController.m in Sources */, 830C37A527B95EB300E02BB0 /* EqualizerWindowController.m in Sources */,
832CFC562851AA8B002AC26F /* SpectrumViewLegacy.m in Sources */, 832CFC562851AA8B002AC26F /* SpectrumViewCG.m in Sources */,
56462EB20D634206000AB68C /* SpotlightPlaylistController.m in Sources */, 56462EB20D634206000AB68C /* SpotlightPlaylistController.m in Sources */,
07E18DF30D62B38400BB0E11 /* NSArray+ShuffleUtils.m in Sources */, 07E18DF30D62B38400BB0E11 /* NSArray+ShuffleUtils.m in Sources */,
56C63D910D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.m in Sources */, 56C63D910D647DF300EAE25A /* NSComparisonPredicate+CogPredicate.m in Sources */,

View File

@ -1,5 +1,5 @@
// //
// SpectrumViewLegacy.h // SpectrumViewCG.h
// Cog // Cog
// //
// Created by Christopher Snowhill on 2/12/22. // Created by Christopher Snowhill on 2/12/22.
@ -11,7 +11,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface SpectrumViewLegacy : NSView @interface SpectrumViewCG : NSView
@property(nonatomic) BOOL isListening; @property(nonatomic) BOOL isListening;
- (void)startPlayback; - (void)startPlayback;

View File

@ -1,11 +1,11 @@
// //
// SpectrumViewLegacy.m // SpectrumViewCG.m
// Cog // Cog
// //
// Created by Christopher Snowhill on 2/12/22. // Created by Christopher Snowhill on 2/12/22.
// //
#import "SpectrumViewLegacy.h" #import "SpectrumViewCG.h"
#import "NSView+Visibility.h" #import "NSView+Visibility.h"
@ -13,14 +13,14 @@
#define LOWER_BOUND -80 #define LOWER_BOUND -80
static void *kSpectrumViewLegacyContext = &kSpectrumViewLegacyContext; static void *kSpectrumViewCGContext = &kSpectrumViewCGContext;
extern NSString *CogPlaybackDidBeginNotficiation; extern NSString *CogPlaybackDidBeginNotficiation;
extern NSString *CogPlaybackDidPauseNotficiation; extern NSString *CogPlaybackDidPauseNotficiation;
extern NSString *CogPlaybackDidResumeNotficiation; extern NSString *CogPlaybackDidResumeNotficiation;
extern NSString *CogPlaybackDidStopNotficiation; extern NSString *CogPlaybackDidStopNotficiation;
@interface SpectrumViewLegacy () { @interface SpectrumViewCG () {
VisualizationController *visController; VisualizationController *visController;
NSTimer *timer; NSTimer *timer;
float saLowerBound; float saLowerBound;
@ -42,7 +42,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
} }
@end @end
@implementation SpectrumViewLegacy @implementation SpectrumViewCG
@synthesize isListening; @synthesize isListening;
@ -103,7 +103,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
ofObject:(id)object ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context { context:(void *)context {
if(context == kSpectrumViewLegacyContext) { if(context == kSpectrumViewCGContext) {
if([keyPath isEqualToString:@"self.window.visible"]) { if([keyPath isEqualToString:@"self.window.visible"]) {
[self updateVisListening]; [self updateVisListening];
} else { } else {
@ -116,10 +116,10 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)addObservers { - (void)addObservers {
if(!observersAdded) { if(!observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewLegacyContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewCGContext];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewLegacyContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewCGContext];
[self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewLegacyContext]; [self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewCGContext];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(colorsDidChange:) selector:@selector(colorsDidChange:)
@ -154,10 +154,10 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)removeObservers { - (void)removeObservers {
if(observersAdded) { if(observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewLegacyContext]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewCGContext];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewLegacyContext]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewCGContext];
[self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewLegacyContext]; [self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewCGContext];
[[NSNotificationCenter defaultCenter] removeObserver:self [[NSNotificationCenter defaultCenter] removeObserver:self
name:NSSystemColorsDidChangeNotification name:NSSystemColorsDidChangeNotification

View File

@ -7,12 +7,12 @@
#import "SpectrumWindowController.h" #import "SpectrumWindowController.h"
#import "SpectrumView.h" #import "SpectrumViewSK.h"
#import "SpectrumViewLegacy.h" #import "SpectrumViewCG.h"
@interface SpectrumWindowController () @interface SpectrumWindowController ()
@property SpectrumView *spectrumView; @property SpectrumViewSK *spectrumViewSK;
@property SpectrumViewLegacy *spectrumViewLegacy; @property SpectrumViewCG *spectrumViewCG;
@end @end
@implementation SpectrumWindowController @implementation SpectrumWindowController
@ -28,35 +28,35 @@
} }
- (void)startRunning { - (void)startRunning {
if(!self.spectrumView && !self.spectrumViewLegacy) { if(!self.spectrumViewSK && !self.spectrumViewCG) {
NSRect frame = [[self window] frame]; NSRect frame = [[self window] frame];
self.spectrumView = [[SpectrumView alloc] initWithFrame:frame]; self.spectrumViewSK = [SpectrumViewSK createGuardWithFrame:frame];
if(self.spectrumView) { if(self.spectrumViewSK) {
[[self window] setContentView:self.spectrumView]; [[self window] setContentView:self.spectrumViewSK];
[self.spectrumView enableCameraControl]; [self.spectrumViewSK enableCameraControl];
} else { } else {
self.spectrumViewLegacy = [[SpectrumViewLegacy alloc] initWithFrame:frame]; self.spectrumViewCG = [[SpectrumViewCG alloc] initWithFrame:frame];
if(self.spectrumViewLegacy) { if(self.spectrumViewCG) {
[[self window] setContentView:self.spectrumViewLegacy]; [[self window] setContentView:self.spectrumViewCG];
[self.spectrumViewLegacy enableFullView]; [self.spectrumViewCG enableFullView];
} }
} }
} }
if(playbackController.playbackStatus == CogStatusPlaying) { if(playbackController.playbackStatus == CogStatusPlaying) {
if(self.spectrumView) if(self.spectrumViewSK)
[self.spectrumView startPlayback]; [self.spectrumViewSK startPlayback];
else if(self.spectrumViewLegacy) else if(self.spectrumViewCG)
[self.spectrumViewLegacy startPlayback]; [self.spectrumViewCG startPlayback];
} }
} }
- (void)stopRunning { - (void)stopRunning {
[[self window] setContentView:nil]; [[self window] setContentView:nil];
self.spectrumView = nil; self.spectrumViewSK = nil;
self.spectrumViewLegacy = nil; self.spectrumViewCG = nil;
} }
- (void)windowWillClose:(NSNotification *)notification { - (void)windowWillClose:(NSNotification *)notification {

View File

@ -7,15 +7,18 @@
#import "SpectrumItem.h" #import "SpectrumItem.h"
#import "SpectrumView.h" #import "SpectrumViewSK.h"
#import "SpectrumViewLegacy.h" #import "SpectrumViewCG.h"
#import "Logging.h"
@implementation SpectrumItem @implementation SpectrumItem
- (void)awakeFromNib { - (void)awakeFromNib {
NSRect frame = NSMakeRect(0, 0, 64, 26); NSRect frame = NSMakeRect(0, 0, 64, 26);
NSView *view = [[SpectrumView alloc] initWithFrame:frame]; NSView *view = nil;
if(!view) view = [[SpectrumViewLegacy alloc] initWithFrame:frame]; if(self.toolbar) view = [SpectrumViewSK createGuardWithFrame:frame];
if(!view) view = [[SpectrumViewCG alloc] initWithFrame:frame];
[self setView:view]; [self setView:view];
} }

View File

@ -1,5 +1,5 @@
// //
// SpectrumView.h // SpectrumViewSK.h
// Cog // Cog
// //
// Created by Christopher Snowhill on 2/12/22. // Created by Christopher Snowhill on 2/12/22.
@ -13,8 +13,11 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface SpectrumView : SCNView @interface SpectrumViewSK : SCNView
@property(nonatomic) BOOL isListening; @property(nonatomic) BOOL isListening;
@property(nonatomic) BOOL isWorking;
+ (SpectrumViewSK *)createGuardWithFrame:(NSRect)frame;
- (void)enableCameraControl; - (void)enableCameraControl;
- (void)startPlayback; - (void)startPlayback;

View File

@ -1,11 +1,11 @@
// //
// SpectrumView.m // SpectrumViewSK.m
// Cog // Cog
// //
// Created by Christopher Snowhill on 2/12/22. // Created by Christopher Snowhill on 2/12/22.
// //
#import "SpectrumView.h" #import "SpectrumViewSK.h"
#import "NSView+Visibility.h" #import "NSView+Visibility.h"
@ -15,19 +15,20 @@
#define LOWER_BOUND -80 #define LOWER_BOUND -80
static void *kSpectrumViewContext = &kSpectrumViewContext; static void *kSpectrumViewSKContext = &kSpectrumViewSKContext;
extern NSString *CogPlaybackDidBeginNotficiation; extern NSString *CogPlaybackDidBeginNotficiation;
extern NSString *CogPlaybackDidPauseNotficiation; extern NSString *CogPlaybackDidPauseNotficiation;
extern NSString *CogPlaybackDidResumeNotficiation; extern NSString *CogPlaybackDidResumeNotficiation;
extern NSString *CogPlaybackDidStopNotficiation; extern NSString *CogPlaybackDidStopNotficiation;
@interface SpectrumView () { @interface SpectrumViewSK () {
VisualizationController *visController; VisualizationController *visController;
NSTimer *timer; NSTimer *timer;
BOOL paused; BOOL paused;
BOOL stopped; BOOL stopped;
BOOL isListening; BOOL isListening;
BOOL isWorking;
BOOL bandsReset; BOOL bandsReset;
BOOL cameraControlEnabled; BOOL cameraControlEnabled;
BOOL observersAdded; BOOL observersAdded;
@ -43,9 +44,17 @@ extern NSString *CogPlaybackDidStopNotficiation;
} }
@end @end
@implementation SpectrumView @implementation SpectrumViewSK
+ (SpectrumViewSK *)createGuardWithFrame:(NSRect)frame {
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"sceneKitCrashed"]) {
return [[SpectrumViewSK alloc] initWithFrame:frame];
}
return nil;
}
@synthesize isListening; @synthesize isListening;
@synthesize isWorking;
- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
id<MTLDevice> device = MTLCreateSystemDefaultDevice(); id<MTLDevice> device = MTLCreateSystemDefaultDevice();
@ -79,7 +88,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
ofObject:(id)object ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context { context:(void *)context {
if(context == kSpectrumViewContext) { if(context == kSpectrumViewSKContext) {
if([keyPath isEqualToString:@"self.window.visible"]) { if([keyPath isEqualToString:@"self.window.visible"]) {
[self updateVisListening]; [self updateVisListening];
} else { } else {
@ -144,6 +153,7 @@ extern NSString *CogPlaybackDidStopNotficiation;
paused = NO; paused = NO;
isListening = NO; isListening = NO;
cameraControlEnabled = NO; cameraControlEnabled = NO;
isWorking = NO;
[self setBackgroundColor:[NSColor clearColor]]; [self setBackgroundColor:[NSColor clearColor]];
@ -185,11 +195,11 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)addObservers { - (void)addObservers {
if(!observersAdded) { if(!observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumProjectionMode" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumProjectionMode" options:0 context:kSpectrumViewSKContext];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewSKContext];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewSKContext];
[self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewContext]; [self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewSKContext];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidBegin:) selector:@selector(playbackDidBegin:)
@ -221,11 +231,11 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)removeObservers { - (void)removeObservers {
if(observersAdded) { if(observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode" context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode" context:kSpectrumViewSKContext];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewSKContext];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewSKContext];
[self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewContext]; [self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewSKContext];
[[NSNotificationCenter defaultCenter] removeObserver:self [[NSNotificationCenter defaultCenter] removeObserver:self
name:CogPlaybackDidBeginNotficiation name:CogPlaybackDidBeginNotficiation
@ -246,6 +256,11 @@ extern NSString *CogPlaybackDidStopNotficiation;
- (void)repaint { - (void)repaint {
[self updateVisListening]; [self updateVisListening];
if(!isWorking) {
isWorking = YES;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"sceneKitCrashed"];
}
if(stopped) { if(stopped) {
[self drawBaseBands]; [self drawBaseBands];