diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index 8ca3640b6..63d02cc96 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -59,7 +59,8 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation"; - (void)initDefaults { NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble:100.0], @"volume", + [NSNumber numberWithDouble:100.0], @"volume", + [NSNumber numberWithBool:NO], @"GraphicEQenable", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary]; diff --git a/Audio/Output/OutputCoreAudio.h b/Audio/Output/OutputCoreAudio.h index 20ddcd5c7..165c45d8d 100644 --- a/Audio/Output/OutputCoreAudio.h +++ b/Audio/Output/OutputCoreAudio.h @@ -33,6 +33,8 @@ BOOL started; BOOL paused; + BOOL eqEnabled; + atomic_long bytesRendered; BOOL listenerapplied; @@ -62,4 +64,6 @@ - (void)setVolume:(double) v; +- (void)setEqualizerEnabled:(BOOL)enabled; + @end diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index d6b575a4e..7c1b76e3c 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -153,6 +153,7 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc readSemaphore = [[Semaphore alloc] init]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.outputDevice" options:0 context:NULL]; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQenable" options:0 context:NULL]; } return self; @@ -173,6 +174,11 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const [self setOutputDeviceWithDeviceDict:device]; } + else if ([keyPath isEqualToString:@"values.GraphicEQenable"]) { + BOOL enabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]; + + [self setEqualizerEnabled:enabled]; + } } - (void)signalEndOfStream @@ -442,7 +448,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const { NSError *err; AVAudioFormat *renderFormat; - + + [outputController incrementAmountPlayed:[[outputController buffer] bufferedLength]]; + [[outputController buffer] empty]; + _deviceFormat = format; deviceFormat = *(format.streamDescription); @@ -506,6 +515,8 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioUnitReset (_eq, kAudioUnitScope_Output, 0); AudioUnitReset (_eq, kAudioUnitScope_Global, 0); + + eqEnabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]; } return YES; @@ -569,6 +580,8 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const __block AudioUnit eq = _eq; __block AudioStreamBasicDescription *format = &deviceFormat; + __block BOOL *eqEnabled = &self->eqEnabled; + __block void *refCon = (__bridge void *)self; _au.outputProvider = ^AUAudioUnitStatus(AudioUnitRenderActionFlags * _Nonnull actionFlags, const AudioTimeStamp * _Nonnull timestamp, AUAudioFrameCount frameCount, NSInteger inputBusNumber, AudioBufferList * _Nonnull inputData) { @@ -590,7 +603,12 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const ioData->mBuffers[i].mDataByteSize = frameCount * sizeof(float); } - OSStatus ret = AudioUnitRender(eq, actionFlags, timestamp, (UInt32) inputBusNumber, frameCount, ioData); + OSStatus ret; + + if (*eqEnabled) + ret = AudioUnitRender(eq, actionFlags, timestamp, (UInt32) inputBusNumber, frameCount, ioData); + else + ret = renderCallback(refCon, actionFlags, timestamp, (UInt32) inputBusNumber, frameCount, ioData); if (ret) return ret; @@ -649,6 +667,19 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const volume = v * 0.01f; } +- (void)setEqualizerEnabled:(BOOL)enabled +{ + if (enabled && !eqEnabled) { + if (_eq) { + AudioUnitReset (_eq, kAudioUnitScope_Input, 0); + AudioUnitReset (_eq, kAudioUnitScope_Output, 0); + AudioUnitReset (_eq, kAudioUnitScope_Global, 0); + } + } + + eqEnabled = enabled; +} + - (void)start { [self threadEntry:nil]; @@ -694,6 +725,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const [self stop]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"]; } - (void)pause diff --git a/Base.lproj/InfoInspector.xib b/Base.lproj/InfoInspector.xib index 8568a237c..ab8226091 100644 --- a/Base.lproj/InfoInspector.xib +++ b/Base.lproj/InfoInspector.xib @@ -1,8 +1,8 @@ - + - + @@ -24,99 +24,99 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -260,9 +260,9 @@ - + - + @@ -281,9 +281,9 @@ - + - + @@ -316,16 +316,16 @@ - + - + - + diff --git a/Base.lproj/OpenURLPanel.xib b/Base.lproj/OpenURLPanel.xib index 5d108ecb5..069c0141e 100644 --- a/Base.lproj/OpenURLPanel.xib +++ b/Base.lproj/OpenURLPanel.xib @@ -1,8 +1,8 @@ - + - + @@ -18,7 +18,7 @@ - + diff --git a/Window/AUPlayerView.h b/Window/AUPlayerView.h index 054decabd..078e2c50f 100644 --- a/Window/AUPlayerView.h +++ b/Window/AUPlayerView.h @@ -16,19 +16,9 @@ @interface AUPluginUI : NSObject { AudioUnit au; - int prefheight; - int prefwidth; BOOL windowOpen; - BOOL resizable; - int min_width; - int min_height; - int req_width; - int req_height; - int alo_width; - int alo_height; - /* Cocoa */ NSWindow* cocoa_window; @@ -40,12 +30,18 @@ - (void) dealloc; - (BOOL) isOpen; -- (BOOL) isForeground; - (void) bringToFront; -- (NSInteger) windowNumber; +@end +@interface AUPluginWindow : NSWindow { + NSView *topView; + NSView *auView; + NSSplitView *splitView; +} + +- (id) initWithAuView:(NSView *)_auView bringToFront:(BOOL)front relativeToWindow:(NSInteger)window; @end #endif diff --git a/Window/AUPlayerView.m b/Window/AUPlayerView.m index 66a46a055..ec0714484 100644 --- a/Window/AUPlayerView.m +++ b/Window/AUPlayerView.m @@ -19,20 +19,12 @@ @end @implementation AUPluginUI - - (id) initWithSampler:(AudioUnit)_au bringToFront:(BOOL)front orWindowNumber:(NSInteger)window { self = [super init]; if (self) { au = _au; - resizable = NO; - min_width = 0; - min_height = 0; - req_width = 0; - req_height = 0; - alo_width = 0; - alo_height = 0; windowOpen = NO; @@ -46,31 +38,13 @@ if (au_view) { - cocoa_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, req_width, req_height) - styleMask:(NSWindowStyleMaskTitled | - NSWindowStyleMaskClosable) - backing:NSBackingStoreBuffered - defer:NO]; - - [cocoa_window setAutodisplay:YES]; - [cocoa_window setOneShot:YES]; - - [cocoa_window setContentView:au_view]; - - if (front) - { - [cocoa_window orderFront:cocoa_window]; + cocoa_window = [[AUPluginWindow alloc] initWithAuView:au_view bringToFront:front relativeToWindow:window]; + + if (cocoa_window) { + windowOpen = YES; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowClosed:) name:NSWindowWillCloseNotification object:cocoa_window]; } - else - [cocoa_window orderWindow:NSWindowBelow relativeTo:window]; - - [cocoa_window setReleasedWhenClosed:NO]; - - [cocoa_window setFrameUsingName:@"EqualizerWindowPosition"]; - - windowOpen = YES; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowClosed:) name:NSWindowWillCloseNotification object:cocoa_window]; } } @@ -99,14 +73,9 @@ [cocoa_window orderFront:cocoa_window]; } -- (NSInteger) windowNumber -{ - return cocoa_window.windowNumber; -} - - (void)windowClosed:(NSNotification*)notification { - [cocoa_window saveFrameUsingName:@"EqualizerWindowPosition"]; + [cocoa_window saveFrameUsingName:@"GraphicEQ.position"]; [[NSNotificationCenter defaultCenter] removeObserver:self]; windowOpen = NO; } @@ -221,13 +190,89 @@ [(AUGenericView *)au_view setShowsExpertParameters:1]; } - // Get the initial size of the new AU View's frame - NSRect frame = [au_view frame]; - min_width = req_width = CGRectGetWidth(NSRectToCGRect(frame)); - min_height = req_height = CGRectGetHeight(NSRectToCGRect(frame)); - resizable = [au_view autoresizingMask]; - return 0; } @end + +@implementation AUPluginWindow +- (id) initWithAuView:(NSView *)_auView bringToFront:(BOOL)front relativeToWindow:(NSInteger)window +{ + NSRect frame = [_auView frame]; + CGFloat req_width = frame.size.width; + CGFloat req_height = frame.size.height; + //BOOL resizable = [_auView autoresizingMask]; + + self = [super initWithContentRect:NSMakeRect(0, 0, req_width, req_height + 32) + styleMask:(NSWindowStyleMaskTitled | + NSWindowStyleMaskClosable) + backing:NSBackingStoreBuffered + defer:NO]; + if (self) + { + auView = _auView; + + [self setAutodisplay:YES]; + [self setOneShot:YES]; + + if (front) + { + [self orderFront:self]; + } + else + [self orderWindow:NSWindowBelow relativeTo:window]; + + [self setReleasedWhenClosed:NO]; + + NSRect topRect = NSMakeRect(0, 0, req_width, 32); + + topView = [[NSView alloc] initWithFrame:topRect]; + + NSRect topFrame = NSMakeRect(0, req_height, req_width, req_height); + NSRect newFrame = NSMakeRect(0, 0, req_width, topRect.size.height); + + topRect = NSMakeRect(0, 0, req_width, req_height + topRect.size.height); + + splitView = [[NSSplitView alloc] initWithFrame:topRect]; + + [splitView setSubviews:[NSArray arrayWithObjects:topView, auView, nil]]; + + [self setContentView:splitView]; + + [topView setFrame:topFrame]; + [auView setFrame:newFrame]; + + BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"GraphicEQenable"]; + + NSButton *button = [NSButton checkboxWithTitle:@"Enabled" target:self action:@selector(toggleEnable:)]; + [button setState:enabled ? NSControlStateValueOn : NSControlStateValueOff]; + + NSRect buttonFrame = [button frame]; + buttonFrame.origin = NSMakePoint( 18, 4 ); + [button setFrame:buttonFrame]; + + [topView addSubview:button]; + + [splitView adjustSubviews]; + + [splitView setDelegate:self]; + + [self setFrameUsingName:@"GraphicEQ.position"]; + } + + return self; +} + +- (NSRect)splitView:(NSSplitView *)splitView effectiveRect:(NSRect)proposedEffectiveRect forDrawnRect:(NSRect)drawnRect ofDividerAtIndex:(NSInteger)dividerIndex +{ + return NSZeroRect; +} + +- (void) toggleEnable:(id)sender +{ + BOOL enabled = [sender state] == NSControlStateValueOn; + + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"GraphicEQenable"]; +} +@end +