diff --git a/Audio/Output/OutputCoreAudio.h b/Audio/Output/OutputCoreAudio.h index 75ea43935..4b6bd2c3f 100644 --- a/Audio/Output/OutputCoreAudio.h +++ b/Audio/Output/OutputCoreAudio.h @@ -56,6 +56,7 @@ BOOL observersapplied; float volume; + float eqPreamp; AVAudioFormat *_deviceFormat; diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index 3e9819d4c..21d34fc6f 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -152,6 +152,10 @@ static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioAct volumeScale = 0.5; } + if(_self->eqEnabled) { + volumeScale *= _self->eqPreamp; + } + scaleBuffersByVolume(ioData, _self->volume * volumeScale); if(amountRead < amountToRead) { @@ -216,6 +220,9 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const BOOL enabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]; [self setEqualizerEnabled:enabled]; + } else if([keyPath isEqualToString:@"values.eqPreamp"]) { + float preamp = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] floatForKey:@"eqPreamp"]; + eqPreamp = pow(10.0, preamp / 20.0); } } @@ -746,6 +753,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.outputDevice" options:0 context:NULL]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQenable" options:0 context:NULL]; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.eqPreamp" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:NULL]; observersapplied = YES; return (err == nil); @@ -777,6 +785,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const observersapplied = NO; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"]; [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.eqPreamp"]; } if(stopNext && started && !paused) { while(![[outputController buffer] isEmpty]) { diff --git a/Base.lproj/Equalizer.xib b/Base.lproj/Equalizer.xib index c7a96735e..a6ee70bb6 100644 --- a/Base.lproj/Equalizer.xib +++ b/Base.lproj/Equalizer.xib @@ -8,813 +8,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name @@ -824,5 +55,783 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Equalizer/EqualizerWindowController.m b/Equalizer/EqualizerWindowController.m index aa1d1d249..5f290fb14 100644 --- a/Equalizer/EqualizerWindowController.m +++ b/Equalizer/EqualizerWindowController.m @@ -339,6 +339,8 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) { [super windowDidLoad]; [self changePreset:presetSelector]; + + [self handleMouseEvents]; } - (void)setEQ:(AudioUnit)au { @@ -453,27 +455,25 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) { [eqPreamp setFloatValue:-maxValue]; [[NSUserDefaults standardUserDefaults] setFloat:-maxValue forKey:[cog_equalizer_band_settings objectAtIndex:0]]; - - if(au) - equalizerLoadPreset(au); } } - (IBAction)adjustSlider:(id)sender { NSInteger tag = [sender tag]; + NSInteger count = [equalizer_presets_processed count]; + if([presetSelector indexOfSelectedItem] != count) { + [presetSelector selectItemAtIndex:count]; + } + if(tag == 0) { float preamp = [eqPreamp floatValue]; [[NSUserDefaults standardUserDefaults] setFloat:preamp forKey:[cog_equalizer_band_settings objectAtIndex:0]]; - - equalizerLoadPreset(au); } else if(tag < [cog_equalizer_band_settings count]) { - float preamp = [eqPreamp floatValue]; - float value = [sender floatValue]; [[NSUserDefaults standardUserDefaults] setFloat:value forKey:[cog_equalizer_band_settings objectAtIndex:tag]]; if(au) - AudioUnitSetParameter(au, (int)(tag - 1), kAudioUnitScope_Global, 0, value + preamp, 0); + AudioUnitSetParameter(au, (int)(tag - 1), kAudioUnitScope_Global, 0, value, 0); } } @@ -481,6 +481,8 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) { NSInteger index = [sender indexOfSelectedItem]; if(index >= 0 && index < [equalizer_presets_processed count]) { + [[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"GraphicEQpreset"]; + NSDictionary *preset = [equalizer_presets_processed objectAtIndex:index]; equalizerApplyPreset(au, preset); @@ -502,4 +504,26 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) { } } +- (void)handleMouseEvents { + [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskRightMouseDown | NSEventMaskRightMouseDragged + handler:^NSEvent *_Nullable(NSEvent *_Nonnull theEvent) { + if([theEvent window] == [self window]) { + NSPoint event_location = [theEvent locationInWindow]; + NSPoint local_point = [self.window.contentView convertPoint:event_location fromView:nil]; + + for(NSInteger i = 0; i < [cog_equalizer_band_settings count]; ++i) { + NSSlider *slider = [self sliderForIndex:i]; + if(NSPointInRect(local_point, [slider frame])) { + float sliderPosition = (MAX(MIN(local_point.y, 344.0), 40.0) - 40.0) / 152.0 - 1.0; + [slider setFloatValue:sliderPosition * 20.0]; + [self adjustSlider:slider]; + break; + } + } + } + + return theEvent; + }]; +} + @end