[Spectrum] Enable switching style at runtime

It is now possible to switch the display style at runtime, while the
views are open.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
lastfm
Christopher Snowhill 2022-07-05 13:43:21 -07:00
parent f4926cf569
commit d4b434a68f
7 changed files with 107 additions and 19 deletions

View File

@ -990,6 +990,9 @@
<rect key="frame" x="0.0" y="14" width="64" height="26"/> <rect key="frame" x="0.0" y="14" width="64" height="26"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</customView> </customView>
<connections>
<outlet property="playbackController" destination="705" id="FPc-ek-NRd"/>
</connections>
</toolbarItem> </toolbarItem>
</allowedToolbarItems> </allowedToolbarItems>
<defaultToolbarItems> <defaultToolbarItems>
@ -1246,6 +1249,9 @@
<rect key="frame" x="0.0" y="14" width="64" height="26"/> <rect key="frame" x="0.0" y="14" width="64" height="26"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</customView> </customView>
<connections>
<outlet property="playbackController" destination="705" id="GWc-77-WHY"/>
</connections>
</toolbarItem> </toolbarItem>
</allowedToolbarItems> </allowedToolbarItems>
<defaultToolbarItems> <defaultToolbarItems>

View File

@ -363,7 +363,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="gUE-Yu-LLA"> <clipView key="contentView" id="gUE-Yu-LLA">
<rect key="frame" x="1" y="1" width="488" height="113"/> <rect key="frame" x="1" y="1" width="488" height="113"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" headerView="9rQ-Rq-K6J" viewBased="YES" id="gHG-xw-OyR"> <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" headerView="9rQ-Rq-K6J" viewBased="YES" id="gHG-xw-OyR">
<rect key="frame" x="0.0" y="0.0" width="488" height="85"/> <rect key="frame" x="0.0" y="0.0" width="488" height="85"/>
@ -385,7 +385,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView id="EEt-uJ-j6o"> <tableCellView id="EEt-uJ-j6o">
<rect key="frame" x="18" y="0.0" width="386" height="24"/> <rect key="frame" x="8" y="0.0" width="386" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7l9-R2-FVF"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7l9-R2-FVF">
@ -420,7 +420,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/> <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews> <prototypeCellViews>
<tableCellView id="EDi-gi-Vg9"> <tableCellView id="EDi-gi-Vg9">
<rect key="frame" x="421" y="0.0" width="38" height="24"/> <rect key="frame" x="411" y="0.0" width="38" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0TJ-dK-Rfk"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0TJ-dK-Rfk">
@ -538,19 +538,19 @@
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4xb-C2-wmz"> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4xb-C2-wmz">
<rect key="frame" x="40" y="78" width="470" height="18"/> <rect key="frame" x="40" y="78" width="470" height="18"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Spectrum 2D view" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="gXL-j6-df0"> <buttonCell key="cell" type="check" title="Use flat perspective in toolbar" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="gXL-j6-df0">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
<connections> <connections>
<binding destination="52" name="enabled" keyPath="values.spectrumSceneKit" id="frQ-l7-tCE"/>
<binding destination="52" name="value" keyPath="values.spectrumProjectionMode" id="UGh-1j-iFC"/> <binding destination="52" name="value" keyPath="values.spectrumProjectionMode" id="UGh-1j-iFC"/>
<binding destination="52" name="enabled" keyPath="values.spectrumSceneKit" id="frQ-l7-tCE"/>
</connections> </connections>
</button> </button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="t6C-Va-hmO" userLabel="Use SceneKit"> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="t6C-Va-hmO" userLabel="Use SceneKit">
<rect key="frame" x="18" y="104" width="108" height="18"/> <rect key="frame" x="18" y="104" width="492" height="18"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Use SceneKit" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="NMg-TO-amV"> <buttonCell key="cell" type="check" title="Use 3D rendered spectrum" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="NMg-TO-amV">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>

View File

@ -198,7 +198,7 @@
"ds2-aw-ebU.title" = "Limit volume control to 100%"; "ds2-aw-ebU.title" = "Limit volume control to 100%";
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */ /* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
"gXL-j6-df0.title" = "Spectrum 2D view"; "gXL-j6-df0.title" = "Use flat perspective in toolbar";
/* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "klv-Wh-0ur"; */ /* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "klv-Wh-0ur"; */
"klv-Wh-0ur.title" = "hh:mm:ss.ms"; "klv-Wh-0ur.title" = "hh:mm:ss.ms";
@ -226,3 +226,7 @@
/* Class = "NSButtonCell"; title = "Send crash reports and usage data"; ObjectID = "zQ2-6O-3Og"; */ /* Class = "NSButtonCell"; title = "Send crash reports and usage data"; ObjectID = "zQ2-6O-3Og"; */
"zQ2-6O-3Og.title" = "Send crash reports and usage data"; "zQ2-6O-3Og.title" = "Send crash reports and usage data";
/* Class = "NSButtonCell"; title = "Use 3D rendered spectrum"; ObjectID = "NMg-TO-amV"; */
"NMg-TO-amV.title" = "Use 3D rendered spectrum";

View File

@ -109,9 +109,6 @@
/* Class = "NSButtonCell"; title = "Colorful dock icons"; ObjectID = "GdX-5e-NeU"; */ /* Class = "NSButtonCell"; title = "Colorful dock icons"; ObjectID = "GdX-5e-NeU"; */
"GdX-5e-NeU.title" = "Colorear icono del dock"; "GdX-5e-NeU.title" = "Colorear icono del dock";
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
"gXL-j6-df0.title" = "Analizador en 2D";
/* Class = "NSMenu"; title = "OtherViews"; ObjectID = "HKM-FW-dhH"; */ /* Class = "NSMenu"; title = "OtherViews"; ObjectID = "HKM-FW-dhH"; */
"HKM-FW-dhH.title" = "Otras vistas"; "HKM-FW-dhH.title" = "Otras vistas";
@ -240,3 +237,10 @@
/* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "zaI-0m-tQf"; */ /* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "zaI-0m-tQf"; */
"zaI-0m-tQf.title" = "hh:mm:ss.ms"; "zaI-0m-tQf.title" = "hh:mm:ss.ms";
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
"gXL-j6-df0.title" = "Use flat perspective in toolbar";
/* Class = "NSButtonCell"; title = "Use 3D rendered spectrum"; ObjectID = "NMg-TO-amV"; */
"NMg-TO-amV.title" = "Use 3D rendered spectrum";

View File

@ -10,6 +10,8 @@
#import "SpectrumViewSK.h" #import "SpectrumViewSK.h"
#import "SpectrumViewCG.h" #import "SpectrumViewCG.h"
static void *kSpectrumWindowContext = &kSpectrumWindowContext;
@interface SpectrumWindowController () @interface SpectrumWindowController ()
@property SpectrumViewSK *spectrumViewSK; @property SpectrumViewSK *spectrumViewSK;
@property SpectrumViewCG *spectrumViewCG; @property SpectrumViewCG *spectrumViewCG;
@ -18,7 +20,11 @@
@implementation SpectrumWindowController @implementation SpectrumWindowController
- (id)init { - (id)init {
return [super initWithWindowNibName:@"SpectrumWindow"]; self = [super initWithWindowNibName:@"SpectrumWindow"];
if(self) {
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumSceneKit" options:0 context:kSpectrumWindowContext];
}
return self;
} }
- (void)windowDidLoad { - (void)windowDidLoad {
@ -27,6 +33,25 @@
[self startRunning]; [self startRunning];
} }
- (void)dealloc {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumSceneKit" context:kSpectrumWindowContext];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context {
if(context == kSpectrumWindowContext) {
if([keyPath isEqualToString:@"values.spectrumSceneKit"]) {
self.spectrumViewSK = nil;
self.spectrumViewCG = nil;
[self startRunning];
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)startRunning { - (void)startRunning {
if(!self.spectrumViewSK && !self.spectrumViewCG) { if(!self.spectrumViewSK && !self.spectrumViewCG) {
NSRect frame = [[self window] frame]; NSRect frame = [[self window] frame];

View File

@ -7,10 +7,13 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "PlaybackController.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface SpectrumItem : NSToolbarItem @interface SpectrumItem : NSToolbarItem {
IBOutlet PlaybackController *playbackController;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -12,14 +12,60 @@
#import "Logging.h" #import "Logging.h"
static void *kSpectrumItemContext = &kSpectrumItemContext;
@interface SpectrumItem ()
@property SpectrumViewSK *spectrumViewSK;
@property SpectrumViewCG *spectrumViewCG;
@end
@implementation SpectrumItem @implementation SpectrumItem
- (void)awakeFromNib { - (void)awakeFromNib {
NSRect frame = NSMakeRect(0, 0, 64, 26); [self startRunning];
NSView *view = nil;
if(self.toolbar) view = [SpectrumViewSK createGuardWithFrame:frame]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumSceneKit" options:0 context:kSpectrumItemContext];
if(!view) view = [[SpectrumViewCG alloc] initWithFrame:frame]; }
[self setView:view];
- (void)startRunning {
if(!self.spectrumViewSK && !self.spectrumViewCG) {
NSRect frame = NSMakeRect(0, 0, 64, 26);
self.spectrumViewSK = [SpectrumViewSK createGuardWithFrame:frame];
if(self.spectrumViewSK) {
[self setView:self.spectrumViewSK];
} else {
self.spectrumViewCG = [[SpectrumViewCG alloc] initWithFrame:frame];
if(self.spectrumViewCG) {
[self setView:self.spectrumViewCG];
}
}
}
if(playbackController.playbackStatus == CogStatusPlaying) {
if(self.spectrumViewSK)
[self.spectrumViewSK startPlayback];
else if(self.spectrumViewCG)
[self.spectrumViewCG startPlayback];
}
}
- (void)dealloc {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumSceneKit" context:kSpectrumItemContext];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
context:(void *)context {
if(context == kSpectrumItemContext) {
if([keyPath isEqualToString:@"values.spectrumSceneKit"]) {
self.spectrumViewSK = nil;
self.spectrumViewCG = nil;
[self startRunning];
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
} }
@end @end