2022-02-13 07:04:03 +00:00
|
|
|
//
|
2022-06-18 05:14:32 +00:00
|
|
|
// SpectrumViewSK.m
|
2022-02-13 07:04:03 +00:00
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 2/12/22.
|
|
|
|
//
|
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
#import "SpectrumViewSK.h"
|
2022-02-13 07:04:03 +00:00
|
|
|
|
2022-06-09 04:32:52 +00:00
|
|
|
#import "NSView+Visibility.h"
|
|
|
|
|
2022-05-24 00:21:13 +00:00
|
|
|
#import <Metal/Metal.h>
|
|
|
|
|
2022-02-13 20:15:27 +00:00
|
|
|
#import "analyzer.h"
|
|
|
|
|
2022-06-19 01:14:25 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2022-02-13 20:15:27 +00:00
|
|
|
#define LOWER_BOUND -80
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
static void *kSpectrumViewSKContext = &kSpectrumViewSKContext;
|
2022-05-22 22:26:27 +00:00
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
extern NSString *CogPlaybackDidBeginNotficiation;
|
|
|
|
extern NSString *CogPlaybackDidPauseNotficiation;
|
|
|
|
extern NSString *CogPlaybackDidResumeNotficiation;
|
|
|
|
extern NSString *CogPlaybackDidStopNotficiation;
|
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
@interface SpectrumViewSK () {
|
2022-02-13 20:15:27 +00:00
|
|
|
VisualizationController *visController;
|
|
|
|
NSTimer *timer;
|
|
|
|
BOOL paused;
|
|
|
|
BOOL stopped;
|
|
|
|
BOOL isListening;
|
2022-05-22 07:03:52 +00:00
|
|
|
BOOL bandsReset;
|
2022-05-23 00:24:35 +00:00
|
|
|
BOOL cameraControlEnabled;
|
2022-06-09 04:32:52 +00:00
|
|
|
BOOL observersAdded;
|
2022-02-13 20:15:27 +00:00
|
|
|
|
|
|
|
NSColor *backgroundColor;
|
|
|
|
ddb_analyzer_t _analyzer;
|
|
|
|
ddb_analyzer_draw_data_t _draw_data;
|
2022-05-22 22:50:09 +00:00
|
|
|
|
|
|
|
SCNVector3 cameraPosition2d;
|
|
|
|
SCNVector3 cameraEulerAngles2d;
|
|
|
|
SCNVector3 cameraPosition3d;
|
|
|
|
SCNVector3 cameraEulerAngles3d;
|
2022-02-13 20:15:27 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
@implementation SpectrumViewSK
|
|
|
|
|
|
|
|
+ (SpectrumViewSK *)createGuardWithFrame:(NSRect)frame {
|
2022-07-05 19:52:53 +00:00
|
|
|
if (![NSUserDefaults.standardUserDefaults boolForKey:@"spectrumSceneKit"])
|
|
|
|
return nil;
|
2022-07-05 10:12:34 +00:00
|
|
|
|
2022-06-20 04:42:39 +00:00
|
|
|
do {
|
2022-06-23 05:54:32 +00:00
|
|
|
if(@available(macOS 11.0, *)) {
|
2022-06-20 04:42:39 +00:00
|
|
|
// macOS 11 and newer seems to be safe
|
|
|
|
break;
|
|
|
|
} else if(@available(macOS 10.15, *)) {
|
|
|
|
// macOS 10.15.7 has a SceneKit bug with PBR noise
|
|
|
|
return nil;
|
|
|
|
} else {
|
|
|
|
// macOS 10.12 through 10.14.x seem to be safe too
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
return [[SpectrumViewSK alloc] initWithFrame:frame];
|
2022-06-18 05:14:32 +00:00
|
|
|
}
|
2022-02-13 07:04:03 +00:00
|
|
|
|
2022-02-13 09:32:26 +00:00
|
|
|
@synthesize isListening;
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frame {
|
2022-05-30 07:15:49 +00:00
|
|
|
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
|
|
|
|
|
2022-06-09 04:56:47 +00:00
|
|
|
if(!device) return nil;
|
2022-05-30 07:15:49 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
NSDictionary *sceneOptions = @{
|
2022-05-29 01:23:15 +00:00
|
|
|
SCNPreferredRenderingAPIKey: @(SCNRenderingAPIMetal),
|
2022-05-30 07:15:49 +00:00
|
|
|
SCNPreferredDeviceKey: device,
|
2022-05-29 01:23:15 +00:00
|
|
|
SCNPreferLowPowerDeviceKey: @(NO)
|
2022-05-22 07:03:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self = [super initWithFrame:frame options:sceneOptions];
|
2022-02-13 09:32:26 +00:00
|
|
|
if(self) {
|
|
|
|
[self setup];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateVisListening {
|
2022-06-08 02:01:47 +00:00
|
|
|
if(self.isListening && (![self visibleInWindow] || paused || stopped)) {
|
2022-02-13 09:32:26 +00:00
|
|
|
[self stopTimer];
|
|
|
|
self.isListening = NO;
|
2022-06-08 02:01:47 +00:00
|
|
|
} else if(!self.isListening && ([self visibleInWindow] && !stopped && !paused)) {
|
2022-02-13 09:32:26 +00:00
|
|
|
[self startTimer];
|
|
|
|
self.isListening = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 22:26:27 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
|
|
ofObject:(id)object
|
|
|
|
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
|
|
|
context:(void *)context {
|
2022-06-18 05:14:32 +00:00
|
|
|
if(context == kSpectrumViewSKContext) {
|
2022-06-11 05:35:51 +00:00
|
|
|
if([keyPath isEqualToString:@"self.window.visible"]) {
|
|
|
|
[self updateVisListening];
|
|
|
|
} else {
|
|
|
|
[self updateControls];
|
|
|
|
}
|
2022-06-15 23:47:43 +00:00
|
|
|
} else {
|
|
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
2022-05-22 22:26:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateControls {
|
2022-05-23 00:45:51 +00:00
|
|
|
BOOL projectionMode = cameraControlEnabled ? NO : [[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumProjectionMode"];
|
2022-05-22 22:26:27 +00:00
|
|
|
SCNNode *rootNode = [[self scene] rootNode];
|
|
|
|
SCNNode *cameraNode = [rootNode childNodeWithName:@"camera" recursively:NO];
|
|
|
|
SCNCamera *camera = [cameraNode camera];
|
2022-05-22 22:50:09 +00:00
|
|
|
if (projectionMode) {
|
|
|
|
cameraNode.eulerAngles = cameraEulerAngles2d;
|
|
|
|
cameraNode.position = cameraPosition2d;
|
|
|
|
camera.usesOrthographicProjection = YES;
|
|
|
|
camera.orthographicScale = 0.6;
|
|
|
|
} else {
|
|
|
|
cameraNode.eulerAngles = cameraEulerAngles3d;
|
|
|
|
cameraNode.position = cameraPosition3d;
|
|
|
|
camera.usesOrthographicProjection = NO;
|
|
|
|
camera.orthographicScale = 1.0;
|
|
|
|
}
|
2022-05-22 22:26:27 +00:00
|
|
|
|
|
|
|
NSValueTransformer *colorToValueTransformer = [NSValueTransformer valueTransformerForName:@"ColorToValueTransformer"];
|
|
|
|
|
|
|
|
NSColor *barColor = [colorToValueTransformer transformedValue:[[NSUserDefaults standardUserDefaults] dataForKey:@"spectrumBarColor"]];
|
|
|
|
NSColor *dotColor = [colorToValueTransformer transformedValue:[[NSUserDefaults standardUserDefaults] dataForKey:@"spectrumDotColor"]];
|
|
|
|
|
|
|
|
{
|
|
|
|
SCNNode *barNode = [rootNode childNodeWithName:@"cylinder0" recursively:NO];
|
|
|
|
SCNGeometry *geometry = [barNode geometry];
|
|
|
|
NSArray<SCNMaterial *> *materials = [geometry materials];
|
|
|
|
SCNMaterial *material = materials[0];
|
|
|
|
material.diffuse.contents = barColor;
|
|
|
|
material.emission.contents = barColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCNNode *dotNode = [rootNode childNodeWithName:@"sphere0" recursively:NO];
|
|
|
|
SCNGeometry *geometry = [dotNode geometry];
|
|
|
|
NSArray<SCNMaterial *> *materials = [geometry materials];
|
|
|
|
SCNMaterial *material = materials[0];
|
|
|
|
material.diffuse.contents = dotColor;
|
|
|
|
material.emission.contents = dotColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 00:24:35 +00:00
|
|
|
- (void)enableCameraControl {
|
|
|
|
[self setAllowsCameraControl:YES];
|
|
|
|
cameraControlEnabled = YES;
|
2022-05-23 00:45:51 +00:00
|
|
|
[self updateControls];
|
2022-05-23 00:24:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 09:32:26 +00:00
|
|
|
- (void)setup {
|
2022-02-13 07:04:03 +00:00
|
|
|
visController = [NSClassFromString(@"VisualizationController") sharedController];
|
|
|
|
timer = nil;
|
|
|
|
stopped = YES;
|
2022-02-13 09:32:26 +00:00
|
|
|
paused = NO;
|
|
|
|
isListening = NO;
|
2022-05-23 00:24:35 +00:00
|
|
|
cameraControlEnabled = NO;
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
[self setBackgroundColor:[NSColor clearColor]];
|
|
|
|
|
|
|
|
SCNScene *theScene = [SCNScene sceneNamed:@"Scenes.scnassets/Spectrum.scn"];
|
|
|
|
[self setScene:theScene];
|
|
|
|
|
2022-05-22 23:32:57 +00:00
|
|
|
[self setAntialiasingMode:SCNAntialiasingModeMultisampling8X];
|
|
|
|
|
2022-05-22 22:50:09 +00:00
|
|
|
SCNNode *rootNode = [[self scene] rootNode];
|
|
|
|
SCNNode *cameraNode = [rootNode childNodeWithName:@"camera" recursively:NO];
|
|
|
|
cameraPosition2d = SCNVector3Make(0.0, 0.5, 1.0);
|
|
|
|
cameraEulerAngles2d = SCNVector3Zero;
|
|
|
|
// Save initial camera position from SceneKit file.
|
|
|
|
cameraPosition3d = cameraNode.position;
|
|
|
|
cameraEulerAngles3d = cameraNode.eulerAngles;
|
2022-05-22 22:26:27 +00:00
|
|
|
[self updateControls];
|
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
bandsReset = NO;
|
|
|
|
[self drawBaseBands];
|
|
|
|
|
|
|
|
//[self colorsDidChange:nil];
|
2022-02-13 07:04:03 +00:00
|
|
|
|
2022-02-16 07:24:58 +00:00
|
|
|
BOOL freqMode = [[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumFreqMode"];
|
|
|
|
|
2022-02-13 20:15:27 +00:00
|
|
|
ddb_analyzer_init(&_analyzer);
|
|
|
|
_analyzer.db_lower_bound = LOWER_BOUND;
|
2022-02-16 07:24:58 +00:00
|
|
|
_analyzer.min_freq = 10;
|
|
|
|
_analyzer.max_freq = 22000;
|
2022-02-13 20:15:27 +00:00
|
|
|
_analyzer.peak_hold = 10;
|
2022-05-29 01:31:09 +00:00
|
|
|
_analyzer.view_width = 1000;
|
2022-02-13 20:15:27 +00:00
|
|
|
_analyzer.fractional_bars = 1;
|
|
|
|
_analyzer.octave_bars_step = 2;
|
|
|
|
_analyzer.max_of_stereo_data = 1;
|
2022-02-16 07:24:58 +00:00
|
|
|
_analyzer.freq_is_log = 0;
|
|
|
|
_analyzer.mode = freqMode ? DDB_ANALYZER_MODE_FREQUENCIES : DDB_ANALYZER_MODE_OCTAVE_NOTE_BANDS;
|
2022-02-13 07:04:03 +00:00
|
|
|
|
2022-06-09 04:32:52 +00:00
|
|
|
[self addObservers];
|
2022-05-31 04:38:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 04:32:52 +00:00
|
|
|
- (void)addObservers {
|
|
|
|
if(!observersAdded) {
|
2022-06-18 05:14:32 +00:00
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumProjectionMode" options:0 context:kSpectrumViewSKContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewSKContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewSKContext];
|
2022-05-31 04:38:29 +00:00
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
[self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewSKContext];
|
2022-06-06 15:19:42 +00:00
|
|
|
|
2022-05-31 04:38:29 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(playbackDidBegin:)
|
|
|
|
name:CogPlaybackDidBeginNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(playbackDidPause:)
|
|
|
|
name:CogPlaybackDidPauseNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(playbackDidResume:)
|
|
|
|
name:CogPlaybackDidResumeNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(playbackDidStop:)
|
|
|
|
name:CogPlaybackDidStopNotficiation
|
|
|
|
object:nil];
|
|
|
|
|
2022-06-09 04:32:52 +00:00
|
|
|
observersAdded = YES;
|
2022-05-31 04:38:29 +00:00
|
|
|
}
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 09:32:26 +00:00
|
|
|
- (void)dealloc {
|
2022-02-13 20:15:27 +00:00
|
|
|
ddb_analyzer_dealloc(&_analyzer);
|
|
|
|
ddb_analyzer_draw_data_dealloc(&_draw_data);
|
|
|
|
|
2022-05-31 04:38:29 +00:00
|
|
|
[self removeObservers];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeObservers {
|
2022-06-09 04:32:52 +00:00
|
|
|
if(observersAdded) {
|
2022-06-18 05:14:32 +00:00
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode" context:kSpectrumViewSKContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewSKContext];
|
|
|
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewSKContext];
|
2022-05-31 04:38:29 +00:00
|
|
|
|
2022-06-18 05:14:32 +00:00
|
|
|
[self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewSKContext];
|
2022-06-06 15:19:42 +00:00
|
|
|
|
2022-05-31 04:38:29 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
|
|
name:CogPlaybackDidBeginNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
|
|
name:CogPlaybackDidPauseNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
|
|
name:CogPlaybackDidResumeNotficiation
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
|
|
name:CogPlaybackDidStopNotficiation
|
|
|
|
object:nil];
|
|
|
|
|
2022-06-09 04:32:52 +00:00
|
|
|
observersAdded = NO;
|
2022-05-31 04:38:29 +00:00
|
|
|
}
|
2022-02-13 09:32:26 +00:00
|
|
|
}
|
2022-02-13 07:04:03 +00:00
|
|
|
|
2022-02-13 09:32:26 +00:00
|
|
|
- (void)repaint {
|
2022-05-22 07:03:52 +00:00
|
|
|
[self updateVisListening];
|
|
|
|
|
|
|
|
if(stopped) {
|
|
|
|
[self drawBaseBands];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float visAudio[4096], visFFT[2048];
|
|
|
|
|
2022-06-26 12:36:20 +00:00
|
|
|
[self->visController copyVisPCM:&visAudio[0] visFFT:&visFFT[0] latencyOffset:0];
|
2022-05-22 07:03:52 +00:00
|
|
|
|
|
|
|
ddb_analyzer_process(&_analyzer, [self->visController readSampleRate] / 2.0, 1, visFFT, 2048);
|
|
|
|
ddb_analyzer_tick(&_analyzer);
|
|
|
|
ddb_analyzer_get_draw_data(&_analyzer, 11.0, 1.0, &_draw_data);
|
|
|
|
|
|
|
|
[self drawAnalyzer];
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startTimer {
|
|
|
|
[self stopTimer];
|
2022-02-13 09:32:26 +00:00
|
|
|
timer = [NSTimer timerWithTimeInterval:1.0 / 60.0
|
2022-02-13 07:04:03 +00:00
|
|
|
target:self
|
|
|
|
selector:@selector(timerRun:)
|
|
|
|
userInfo:nil
|
|
|
|
repeats:YES];
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopTimer {
|
|
|
|
[timer invalidate];
|
|
|
|
timer = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)timerRun:(NSTimer *)timer {
|
|
|
|
[self repaint];
|
|
|
|
}
|
|
|
|
|
2022-05-23 00:24:35 +00:00
|
|
|
- (void)startPlayback {
|
|
|
|
[self playbackDidBegin:nil];
|
|
|
|
}
|
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
- (void)playbackDidBegin:(NSNotification *)notification {
|
|
|
|
stopped = NO;
|
2022-02-13 09:32:26 +00:00
|
|
|
paused = NO;
|
|
|
|
[self updateVisListening];
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)playbackDidPause:(NSNotification *)notification {
|
|
|
|
stopped = NO;
|
2022-02-13 09:32:26 +00:00
|
|
|
paused = YES;
|
|
|
|
[self updateVisListening];
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)playbackDidResume:(NSNotification *)notification {
|
|
|
|
stopped = NO;
|
2022-02-13 09:32:26 +00:00
|
|
|
paused = NO;
|
|
|
|
[self updateVisListening];
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)playbackDidStop:(NSNotification *)notification {
|
|
|
|
stopped = YES;
|
2022-02-13 09:32:26 +00:00
|
|
|
paused = NO;
|
2022-06-24 06:17:31 +00:00
|
|
|
bandsReset = NO;
|
2022-02-13 09:32:26 +00:00
|
|
|
[self updateVisListening];
|
2022-02-13 07:04:03 +00:00
|
|
|
[self repaint];
|
|
|
|
}
|
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
- (void)drawBaseBands {
|
|
|
|
if(bandsReset) return;
|
2022-02-13 20:15:27 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
SCNScene *scene = [self scene];
|
|
|
|
SCNNode *rootNode = [scene rootNode];
|
|
|
|
NSArray<SCNNode *> *nodes = [rootNode childNodes];
|
2022-02-13 20:15:27 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
for(int i = 0; i < 11; ++i) {
|
|
|
|
SCNNode *node = nodes[i + 1];
|
|
|
|
SCNNode *dotNode = nodes[i + 1 + 11];
|
|
|
|
SCNVector3 position = node.position;
|
|
|
|
position.y = 0.0;
|
|
|
|
node.scale = SCNVector3Make(1.0, 0.0, 1.0);
|
|
|
|
node.position = position;
|
2022-02-13 20:15:27 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
position = dotNode.position;
|
2022-05-23 00:25:21 +00:00
|
|
|
position.y = 0.072;
|
2022-05-22 07:03:52 +00:00
|
|
|
dotNode.position = position;
|
2022-02-13 20:15:27 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
bandsReset = YES;
|
2022-02-13 20:15:27 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
- (void)drawAnalyzerOctaveBands {
|
|
|
|
const int maxBars = (int)(ceilf((float)(_draw_data.bar_count) / 11.0));
|
|
|
|
const int barStep = (int)(floorf((float)(_draw_data.bar_count) / 11.0));
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
ddb_analyzer_draw_bar_t *bar = _draw_data.bars;
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
SCNScene *scene = [self scene];
|
|
|
|
SCNNode *rootNode = [scene rootNode];
|
|
|
|
NSArray<SCNNode *> *nodes = [rootNode childNodes];
|
|
|
|
|
|
|
|
for(int i = 0; i < 11; ++i) {
|
|
|
|
float maxValue = 0.0;
|
|
|
|
float maxMax = 0.0;
|
|
|
|
for(int j = 0; j < maxBars; ++j) {
|
|
|
|
const int barBase = i * barStep;
|
|
|
|
const int barIndex = barBase + j;
|
|
|
|
if(barIndex < _draw_data.bar_count) {
|
|
|
|
if(bar[barIndex].bar_height > maxValue) {
|
|
|
|
maxValue = bar[barIndex].bar_height;
|
|
|
|
}
|
|
|
|
if(bar[barIndex].peak_ypos > maxMax) {
|
|
|
|
maxMax = bar[barIndex].peak_ypos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCNNode *node = nodes[i + 1];
|
|
|
|
SCNNode *dotNode = nodes[i + 1 + 11];
|
|
|
|
SCNVector3 position = node.position;
|
|
|
|
position.y = maxValue * 0.5;
|
2022-05-29 01:23:15 +00:00
|
|
|
node.scale = SCNVector3Make(1.0, maxValue, 1.0);
|
2022-05-22 07:03:52 +00:00
|
|
|
node.position = position;
|
|
|
|
|
|
|
|
position = dotNode.position;
|
2022-05-23 00:25:21 +00:00
|
|
|
position.y = maxMax + 0.072;
|
2022-05-22 07:03:52 +00:00
|
|
|
dotNode.position = position;
|
|
|
|
}
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
bandsReset = NO;
|
|
|
|
}
|
2022-02-13 09:32:26 +00:00
|
|
|
|
2022-05-22 07:03:52 +00:00
|
|
|
- (void)drawAnalyzer {
|
|
|
|
[self drawAnalyzerOctaveBands];
|
2022-02-13 07:04:03 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 07:24:58 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)event {
|
2022-05-23 00:24:35 +00:00
|
|
|
if(cameraControlEnabled) return;
|
|
|
|
|
2022-02-16 07:24:58 +00:00
|
|
|
BOOL freqMode = ![[NSUserDefaults standardUserDefaults] boolForKey:@"spectrumFreqMode"];
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:freqMode forKey:@"spectrumFreqMode"];
|
|
|
|
|
|
|
|
_analyzer.mode = freqMode ? DDB_ANALYZER_MODE_FREQUENCIES : DDB_ANALYZER_MODE_OCTAVE_NOTE_BANDS;
|
|
|
|
_analyzer.mode_did_change = 1;
|
|
|
|
|
|
|
|
[self repaint];
|
|
|
|
}
|
|
|
|
|
2022-02-13 07:04:03 +00:00
|
|
|
@end
|