Skip to content

Commit

Permalink
[Visualization]: Add Spectrum window
Browse files Browse the repository at this point in the history
Add a dedicated spectrum visualization window, and add the necessary
hooks to start its event timer if playback is already running when it is
first opened.

Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed May 23, 2022
1 parent e2d7ebd commit f4712ad
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -1385,6 +1385,11 @@
<action selector="showWindow:" target="dJ9-b3-BFu" id="l8q-wn-w0b"/>
</connections>
</menuItem>
<menuItem title="Show Spectrum Window" keyEquivalent="V" id="wl2-Vo-pul">
<connections>
<action selector="showWindow:" target="Ix4-7A-ejK" id="wS9-M9-Dhe"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="1854">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
Expand Down Expand Up @@ -2326,6 +2331,11 @@ Gw
</connections>
</customObject>
<customObject id="dJ9-b3-BFu" customClass="EqualizerWindowController"/>
<customObject id="Ix4-7A-ejK" customClass="SpectrumWindowController">
<connections>
<outlet property="playbackController" destination="705" id="jJw-Zl-5DT"/>
</connections>
</customObject>
</objects>
<resources>
<image name="deadItemsTemplate" width="20" height="20"/>
Expand Down
10 changes: 10 additions & 0 deletions Cog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
8314A46F27A28C29000EBE7E /* equalizerTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 8314A46527A28C28000EBE7E /* equalizerTemplate.pdf */; };
8316B3932839FFD5004CC392 /* Scenes.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = 8316B3922839FFD5004CC392 /* Scenes.scnassets */; };
831B99BF27C23E88005A969B /* Cog.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 831B99BE27C23E88005A969B /* Cog.sdef */; };
83229C9F283B0095004626A8 /* SpectrumWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 83229C9D283B0095004626A8 /* SpectrumWindowController.m */; };
83229CA0283B0095004626A8 /* SpectrumWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83229C9E283B0095004626A8 /* SpectrumWindow.xib */; };
832923AF279FAC400048201E /* Cog.q1.json in Resources */ = {isa = PBXBuildFile; fileRef = 832923AE279FAC400048201E /* Cog.q1.json */; };
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 */; };
Expand Down Expand Up @@ -908,6 +910,9 @@
8314D63B1A354DFE00EEE8E6 /* sidplay.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = sidplay.xcodeproj; path = Plugins/sidplay/sidplay.xcodeproj; sourceTree = "<group>"; };
8316B3922839FFD5004CC392 /* Scenes.scnassets */ = {isa = PBXFileReference; lastKnownFileType = wrapper.scnassets; path = Scenes.scnassets; sourceTree = "<group>"; };
831B99BE27C23E88005A969B /* Cog.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Cog.sdef; sourceTree = "<group>"; };
83229C9C283B0095004626A8 /* SpectrumWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpectrumWindowController.h; sourceTree = "<group>"; };
83229C9D283B0095004626A8 /* SpectrumWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SpectrumWindowController.m; sourceTree = "<group>"; };
83229C9E283B0095004626A8 /* SpectrumWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SpectrumWindow.xib; sourceTree = "<group>"; };
832923AE279FAC400048201E /* Cog.q1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Cog.q1.json; sourceTree = "<group>"; };
83293065277885790010C07E /* OpenMPTOld.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OpenMPTOld.xcodeproj; path = Plugins/OpenMPT.old/OpenMPTOld.xcodeproj; sourceTree = "<group>"; };
832C1252180BD1E2005507C1 /* Cog.help */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Cog.help; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1811,6 +1816,9 @@
8377C66127B8CF6300E8BC0F /* SpectrumView.m */,
8377C6B727B900F000E8BC0F /* SpectrumItem.h */,
8377C6B827B900F000E8BC0F /* SpectrumItem.m */,
83229C9C283B0095004626A8 /* SpectrumWindowController.h */,
83229C9D283B0095004626A8 /* SpectrumWindowController.m */,
83229C9E283B0095004626A8 /* SpectrumWindow.xib */,
);
name = Visualization;
sourceTree = "<group>";
Expand Down Expand Up @@ -2493,6 +2501,7 @@
17D1B2810CF8B2830028F5B5 /* song.icns in Resources */,
831B99BF27C23E88005A969B /* Cog.sdef in Resources */,
832923AF279FAC400048201E /* Cog.q1.json in Resources */,
83229CA0283B0095004626A8 /* SpectrumWindow.xib in Resources */,
836F462A28207FA4005B9B87 /* PauseColorful.png in Resources */,
17D1B2820CF8B2830028F5B5 /* vg.icns in Resources */,
17D1B2830CF8B2830028F5B5 /* xm.icns in Resources */,
Expand Down Expand Up @@ -2597,6 +2606,7 @@
171EFE8C0F59FEAE000ADC42 /* DockIconController.m in Sources */,
17F6C8070F603701000D9DA9 /* PlaybackEventController.m in Sources */,
83BC5AB220E4C87100631CD4 /* DualWindow.m in Sources */,
83229C9F283B0095004626A8 /* SpectrumWindowController.m in Sources */,
835F00BB279BD1CD00055FCF /* SecondsFormatter.m in Sources */,
1784560F0F631E24007E8021 /* FileTreeViewController.m in Sources */,
178456120F631E31007E8021 /* SideViewController.m in Sources */,
Expand Down
Binary file modified Scenes.scnassets/Spectrum.scn
Binary file not shown.
31 changes: 31 additions & 0 deletions SpectrumWindow.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SpectrumWindow">
<connections>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Spectrum" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" appearanceType="darkAqua" animationBehavior="default" titlebarAppearsTransparent="YES" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="139" y="110"/>
</window>
</objects>
</document>
20 changes: 20 additions & 0 deletions SpectrumWindowController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SpectrumWindowController.h
// Cog
//
// Created by Christopher Snowhill on 5/22/22.
//

#import <Cocoa/Cocoa.h>

#import "PlaybackController.h"

NS_ASSUME_NONNULL_BEGIN

@interface SpectrumWindowController : NSWindowController {
IBOutlet PlaybackController *playbackController;
}

@end

NS_ASSUME_NONNULL_END
47 changes: 47 additions & 0 deletions SpectrumWindowController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SpectrumWindowController.m
// Cog
//
// Created by Christopher Snowhill on 5/22/22.
//

#import "SpectrumWindowController.h"

#import "SpectrumView.h"

@interface SpectrumWindowController ()
@property SpectrumView *spectrumView;
@end

@implementation SpectrumWindowController

- (id)init {
return [super initWithWindowNibName:@"SpectrumWindow"];
}

- (void)windowDidLoad {
[super windowDidLoad];

self.spectrumView = [[SpectrumView alloc] initWithFrame:[[self window] frame]];
[[self window] setContentView:self.spectrumView];

[self.spectrumView enableCameraControl];

if(playbackController.playbackStatus == CogStatusPlaying)
[self.spectrumView startPlayback];
}

- (IBAction)toggleWindow:(id)sender {
if([[self window] isVisible])
[[self window] orderOut:self];
else
[self showWindow:self];
}

- (IBAction)showWindow:(id)sender {
if(self.spectrumView && playbackController.playbackStatus == CogStatusPlaying)
[self.spectrumView startPlayback];
return [super showWindow:sender];
}

@end
3 changes: 3 additions & 0 deletions Visualization/SpectrumView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ NS_ASSUME_NONNULL_BEGIN

@interface SpectrumView : SCNView
@property(nonatomic) BOOL isListening;

- (void)enableCameraControl;
- (void)startPlayback;
@end

NS_ASSUME_NONNULL_END
13 changes: 13 additions & 0 deletions Visualization/SpectrumView.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @interface SpectrumView () {
BOOL stopped;
BOOL isListening;
BOOL bandsReset;
BOOL cameraControlEnabled;

NSColor *backgroundColor;
ddb_analyzer_t _analyzer;
Expand Down Expand Up @@ -114,12 +115,18 @@ - (void)updateControls {
}
}

- (void)enableCameraControl {
[self setAllowsCameraControl:YES];
cameraControlEnabled = YES;
}

- (void)setup {
visController = [NSClassFromString(@"VisualizationController") sharedController];
timer = nil;
stopped = YES;
paused = NO;
isListening = NO;
cameraControlEnabled = NO;

[self setBackgroundColor:[NSColor clearColor]];

Expand Down Expand Up @@ -238,6 +245,10 @@ - (void)timerRun:(NSTimer *)timer {
[self repaint];
}

- (void)startPlayback {
[self playbackDidBegin:nil];
}

- (void)playbackDidBegin:(NSNotification *)notification {
stopped = NO;
paused = NO;
Expand Down Expand Up @@ -331,6 +342,8 @@ - (void)drawAnalyzer {
}

- (void)mouseDown:(NSEvent *)event {
if(cameraControlEnabled) return;

BOOL freqMode = ![[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumFreqMode"];
[[NSUserDefaults standardUserDefaults] setBool:freqMode forKey:@"spectrumFreqMode"];

Expand Down

0 comments on commit f4712ad

Please sign in to comment.