1 /*****************************************************************************
2 * AudioEffects.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2004-2012 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * Jérôme Decoodt <djc@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #import "AudioEffects.h"
31 #import "../../audio_filter/equalizer_presets.h"
32 #import "CompatibilityFixes.h"
33 #import "SharedDialogs.h"
35 #import <vlc_common.h>
36 #import <vlc_strings.h>
40 @interface VLCAudioEffects (Internal)
41 - (void)resetProfileSelector;
42 - (void)updatePresetSelector;
43 - (void)setBandSliderValuesForPreset:(NSInteger)presetID;
47 #pragma mark Initialization
49 @implementation VLCAudioEffects
50 static VLCAudioEffects *_o_sharedInstance = nil;
52 + (VLCAudioEffects *)sharedInstance
54 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
58 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
61 NSMutableArray *workValues = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
62 NSMutableArray *workPreamp = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
63 NSMutableArray *workTitles = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
64 NSMutableArray *workNames = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
66 for (int i = 0 ; i < NB_PRESETS ; i++) {
67 workString = [NSString stringWithFormat:@"%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f",
68 eqz_preset_10b[i].f_amp[0],
69 eqz_preset_10b[i].f_amp[1],
70 eqz_preset_10b[i].f_amp[2],
71 eqz_preset_10b[i].f_amp[3],
72 eqz_preset_10b[i].f_amp[4],
73 eqz_preset_10b[i].f_amp[5],
74 eqz_preset_10b[i].f_amp[6],
75 eqz_preset_10b[i].f_amp[7],
76 eqz_preset_10b[i].f_amp[8],
77 eqz_preset_10b[i].f_amp[9]];
78 [workValues addObject:workString];
79 [workPreamp addObject:[NSString stringWithFormat:@"%1.f", eqz_preset_10b[i].f_preamp]];
80 [workTitles addObject:[NSString stringWithUTF8String:preset_list_text[i]]];
81 [workNames addObject:[NSString stringWithUTF8String:preset_list[i]]];
84 NSString *defaultProfile = [NSString stringWithFormat:@"ZmxhdA==;;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i",
85 .0,25.,100.,-11.,8.,2.5,7.,.85,1.,.4,.5,.5,2.,0];
87 NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithArray:workValues], @"EQValues", [NSArray arrayWithArray:workPreamp], @"EQPreampValues", [NSArray arrayWithArray:workTitles], @"EQTitles", [NSArray arrayWithArray:workNames], @"EQNames", [NSArray arrayWithObject:defaultProfile], @"AudioEffectProfiles", [NSArray arrayWithObject:_NS("Default")], @"AudioEffectProfileNames", nil];
88 [defaults registerDefaults:appDefaults];
98 if (_o_sharedInstance)
102 i_old_profile_index = -1;
103 _o_sharedInstance = [super init];
106 return _o_sharedInstance;
111 /* setup the user's language */
113 [o_eq_enable_ckb setTitle:_NS("Enable")];
114 [o_eq_twopass_ckb setTitle:_NS("2 Pass")];
115 [o_eq_preamp_lbl setStringValue:_NS("Preamp")];
118 [o_comp_enable_ckb setTitle:_NS("Enable dynamic range compressor")];
119 [o_comp_reset_btn setTitle:_NS("Reset")];
120 [o_comp_band1_lbl setStringValue:_NS("RMS/peak")];;
121 [o_comp_band2_lbl setStringValue:_NS("Attack")];
122 [o_comp_band3_lbl setStringValue:_NS("Release")];
123 [o_comp_band4_lbl setStringValue:_NS("Threshold")];
124 [o_comp_band5_lbl setStringValue:_NS("Ratio")];
125 [o_comp_band6_lbl setStringValue:_NS("Knee radius")];
126 [o_comp_band7_lbl setStringValue:_NS("Makeup gain")];
129 [o_spat_enable_ckb setTitle:_NS("Enable Spatializer")];
130 [o_spat_reset_btn setTitle:_NS("Reset")];
131 [o_spat_band1_lbl setStringValue:_NS("Size")];
132 [o_spat_band2_lbl setStringValue:_NS("Width")];
133 [o_spat_band3_lbl setStringValue:_NS("Wet")];
134 [o_spat_band4_lbl setStringValue:_NS("Dry")];
135 [o_spat_band5_lbl setStringValue:_NS("Damp")];
138 [o_filter_headPhone_ckb setTitle:_NS("Headphone virtualization")];
139 [o_filter_normLevel_ckb setTitle:_NS("Volume normalization")];
140 [o_filter_normLevel_lbl setStringValue:_NS("Maximum level")];
141 [o_filter_karaoke_ckb setTitle:_NS("Karaoke")];
144 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"equalizer"]] setLabel:_NS("Equalizer")];
145 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"compressor"]] setLabel:_NS("Compressor")];
146 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"spatializer"]] setLabel:_NS("Spatializer")];
147 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"filter"]] setLabel:_NS("Filter")];
148 [o_window setTitle:_NS("Audio Effects")];
149 [o_window setExcludedFromWindowsMenu:YES];
150 if (!OSX_SNOW_LEOPARD)
151 [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
153 [self setupEqualizer];
154 [self resetCompressor];
155 [self resetSpatializer];
156 [self resetAudioFilters];
157 [self resetProfileSelector];
161 #pragma mark internal functions
163 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
166 audio_output_t *p_aout = getAout();
168 psz_tmp = var_GetNonEmptyString(p_aout, "audio-filter");
170 psz_tmp = config_GetPsz(p_intf, "audio-filter");
174 config_PutPsz(p_intf, "audio-filter", psz_name);
175 else if (strstr(psz_tmp, psz_name) == NULL) {
176 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:%s", psz_tmp, psz_name] UTF8String];
177 config_PutPsz(p_intf, "audio-filter", psz_tmp);
181 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@":%s",psz_name]]] UTF8String];
182 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%s:",psz_name]]] UTF8String];
183 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithUTF8String:psz_name]]] UTF8String];
184 config_PutPsz(p_intf, "audio-filter", psz_tmp);
189 playlist_EnableAudioFilter(pl_Get(p_intf), psz_name, b_on);
190 vlc_object_release(p_aout);
194 - (void)resetProfileSelector
196 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
197 [o_profile_pop removeAllItems];
199 NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
200 [o_profile_pop addItemsWithTitles:profileNames];
202 [[o_profile_pop menu] addItem:[NSMenuItem separatorItem]];
203 [o_profile_pop addItemWithTitle:_NS("Duplicate current profile...")];
204 [[o_profile_pop lastItem] setTarget: self];
205 [[o_profile_pop lastItem] setAction: @selector(addAudioEffectsProfile:)];
207 if ([profileNames count] > 1) {
208 [o_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
209 [[o_profile_pop lastItem] setTarget: self];
210 [[o_profile_pop lastItem] setAction: @selector(removeAudioEffectsProfile:)];
213 [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
214 [self profileSelectorAction:self];
218 #pragma mark generic code
219 - (void)updateCocoaWindowLevel:(NSInteger)i_level
221 if (o_window && [o_window isVisible] && [o_window level] != i_level)
222 [o_window setLevel: i_level];
225 - (IBAction)toggleWindow:(id)sender
227 if ([o_window isVisible])
228 [o_window orderOut:sender];
230 [o_window setLevel: [[[VLCMain sharedInstance] voutController] currentWindowLevel]];
231 [o_window makeKeyAndOrderFront:sender];
235 - (NSString *)generateProfileString
237 vlc_object_t *p_object = VLC_OBJECT(getAout());
238 if (p_object == NULL)
239 p_object = vlc_object_hold(pl_Get(p_intf));
241 NSString *o_str = [NSString stringWithFormat:@"%s;%s;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%lli",
242 vlc_b64_encode(var_GetNonEmptyString(p_object, "equalizer-preset")),
243 vlc_b64_encode(config_GetPsz(p_intf, "audio-filter")),
244 config_GetFloat(p_intf, "compressor-rms-peak"),
245 config_GetFloat(p_intf, "compressor-attack"),
246 config_GetFloat(p_intf, "compressor-release"),
247 config_GetFloat(p_intf, "compressor-threshold"),
248 config_GetFloat(p_intf, "compressor-ratio"),
249 config_GetFloat(p_intf, "compressor-knee"),
250 config_GetFloat(p_intf, "compressor-makeup-gain"),
251 config_GetFloat(p_intf, "spatializer-roomsize"),
252 config_GetFloat(p_intf, "spatializer-width"),
253 config_GetFloat(p_intf, "spatializer-wet"),
254 config_GetFloat(p_intf, "spatializer-dry"),
255 config_GetFloat(p_intf, "spatializer-damp"),
256 config_GetFloat(p_intf, "norm-max-level"),
257 config_GetInt(p_intf,"equalizer-2pass")];
259 vlc_object_release(p_object);
263 - (void)saveCurrentProfile
265 if (i_old_profile_index == -1)
268 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
269 /* fetch all the current settings in a uniform string */
270 NSString *newProfile = [self generateProfileString];
272 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
273 if (i_old_profile_index >= [workArray count])
276 [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile];
277 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
279 [defaults synchronize];
282 - (IBAction)profileSelectorAction:(id)sender
284 [self saveCurrentProfile];
285 i_old_profile_index = [o_profile_pop indexOfSelectedItem];
287 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
288 NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem];
290 audio_output_t *p_aout = getAout();
291 playlist_t *p_playlist = pl_Get(p_intf);
294 /* disable existing filters */
295 playlist_EnableAudioFilter(p_playlist, "equalizer", false);
296 playlist_EnableAudioFilter(p_playlist, "compressor", false);
297 playlist_EnableAudioFilter(p_playlist, "spatializer", false);
298 playlist_EnableAudioFilter(p_playlist, "compressor", false);
299 playlist_EnableAudioFilter(p_playlist, "headphone", false);
300 playlist_EnableAudioFilter(p_playlist, "normvol", false);
301 playlist_EnableAudioFilter(p_playlist, "karaoke", false);
305 NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
308 vlc_object_t *p_object = VLC_OBJECT(getAout());
309 if (p_object == NULL)
310 p_object = vlc_object_hold(pl_Get(p_intf));
311 var_SetString(p_object,"equalizer-preset",vlc_b64_decode([[items objectAtIndex:0] UTF8String]));
312 vlc_object_release(p_object);
314 /* filter handling */
315 NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])];
318 /* enable the new filters, if we have an aout */
320 if ([tempString length] > 0) {
321 tempArray = [tempString componentsSeparatedByString:@":"];
322 count = [tempArray count];
323 for (NSUInteger x = 0; x < count; x++)
324 playlist_EnableAudioFilter(p_playlist, (char *)[[tempArray objectAtIndex:x] UTF8String], true);
327 config_PutPsz(p_intf,"audio-filter",[tempString UTF8String]);
330 config_PutFloat(p_intf, "compressor-rms-peak",[[items objectAtIndex:2] floatValue]);
331 config_PutFloat(p_intf, "compressor-attack",[[items objectAtIndex:3] floatValue]);
332 config_PutFloat(p_intf, "compressor-release",[[items objectAtIndex:4] floatValue]);
333 config_PutFloat(p_intf, "compressor-threshold",[[items objectAtIndex:5] floatValue]);
334 config_PutFloat(p_intf, "compressor-ratio",[[items objectAtIndex:6] floatValue]);
335 config_PutFloat(p_intf, "compressor-knee",[[items objectAtIndex:7] floatValue]);
336 config_PutFloat(p_intf, "compressor-makeup-gain",[[items objectAtIndex:8] floatValue]);
337 config_PutFloat(p_intf, "spatializer-roomsize",[[items objectAtIndex:9] floatValue]);
338 config_PutFloat(p_intf, "spatializer-width",[[items objectAtIndex:10] floatValue]);
339 config_PutFloat(p_intf, "spatializer-wet",[[items objectAtIndex:11] floatValue]);
340 config_PutFloat(p_intf, "spatializer-dry",[[items objectAtIndex:12] floatValue]);
341 config_PutFloat(p_intf, "spatializer-damp",[[items objectAtIndex:13] floatValue]);
342 config_PutFloat(p_intf, "norm-max-level",[[items objectAtIndex:14] floatValue]);
343 config_PutInt(p_intf, "equalizer-2pass",[[items objectAtIndex:15] intValue]);
345 /* set values on-the-fly if we have an aout */
347 var_SetFloat(p_aout, "compressor-rms-peak", [[items objectAtIndex:2] floatValue]);
348 var_SetFloat(p_aout, "compressor-attack", [[items objectAtIndex:3] floatValue]);
349 var_SetFloat(p_aout, "compressor-release", [[items objectAtIndex:4] floatValue]);
350 var_SetFloat(p_aout, "compressor-threshold", [[items objectAtIndex:5] floatValue]);
351 var_SetFloat(p_aout, "compressor-ratio", [[items objectAtIndex:6] floatValue]);
352 var_SetFloat(p_aout, "compressor-knee", [[items objectAtIndex:7] floatValue]);
353 var_SetFloat(p_aout, "compressor-makeup-gain", [[items objectAtIndex:8] floatValue]);
354 var_SetFloat(p_aout, "spatializer-roomsize", [[items objectAtIndex:9] floatValue]);
355 var_SetFloat(p_aout, "spatializer-width", [[items objectAtIndex:10] floatValue]);
356 var_SetFloat(p_aout, "spatializer-wet", [[items objectAtIndex:11] floatValue]);
357 var_SetFloat(p_aout, "spatializer-dry", [[items objectAtIndex:12] floatValue]);
358 var_SetFloat(p_aout, "spatializer-damp", [[items objectAtIndex:13] floatValue]);
359 var_SetFloat(p_aout, "norm-max-level", [[items objectAtIndex:14] floatValue]);
360 var_SetBool(p_aout, "equalizer-2pass", (BOOL)[[items objectAtIndex:15] intValue]);
364 if ([tempString rangeOfString:@"equalizer"].location == NSNotFound)
365 [o_eq_enable_ckb setState:NSOffState];
367 [o_eq_enable_ckb setState:NSOnState];
368 [o_eq_twopass_ckb setState:[[items objectAtIndex:15] intValue]];
369 [self resetCompressor];
370 [self resetSpatializer];
371 [self resetAudioFilters];
372 [self updatePresetSelector];
374 /* store current profile selection */
375 [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"];
376 [defaults synchronize];
379 vlc_object_release(p_aout);
382 - (IBAction)addAudioEffectsProfile:(id)sender
385 VLCEnterTextPanel *panel = [VLCEnterTextPanel sharedInstance];
386 [panel setTitle: _NS("Duplicate current profile for a new profile")];
387 [panel setSubTitle: _NS("Enter a name for the new profile:")];
388 [panel setCancelButtonLabel: _NS("Cancel")];
389 [panel setOKButtonLabel: _NS("Save")];
390 [panel setTarget:self];
391 b_genericAudioProfileInInteraction = YES;
393 [panel runModalForWindow:o_window];
396 - (IBAction)removeAudioEffectsProfile:(id)sender
399 VLCSelectItemInPopupPanel *panel = [VLCSelectItemInPopupPanel sharedInstance];
400 [panel setTitle:_NS("Remove a preset")];
401 [panel setSubTitle:_NS("Select the preset you would like to remove:")];
402 [panel setOKButtonLabel:_NS("Remove")];
403 [panel setCancelButtonLabel:_NS("Cancel")];
404 [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
405 [panel setTarget:self];
406 b_genericAudioProfileInInteraction = YES;
408 [panel runModalForWindow:o_window];
412 #pragma mark Equalizer
413 static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
416 char *psz_parser, *psz_string = NULL;
417 audio_output_t *p_aout = getAout();
421 psz_string = config_GetPsz(p_custom_intf, "audio-filter");
424 psz_string = var_GetNonEmptyString(p_aout, "audio-filter");
426 vlc_object_release(p_aout);
431 psz_parser = strstr(psz_string, psz_name);
441 - (void)setupEqualizer
443 audio_output_t *p_aout = getAout();
445 var_Create(p_aout, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
446 var_Create(p_aout, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
447 var_Create(p_aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
448 vlc_object_release(p_aout);
451 [self equalizerUpdated];
454 - (void)updatePresetSelector
456 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
457 NSArray *presets = [defaults objectForKey:@"EQNames"];
459 [o_eq_presets_popup removeAllItems];
460 [o_eq_presets_popup addItemsWithTitles:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
461 [[o_eq_presets_popup menu] addItem:[NSMenuItem separatorItem]];
462 [o_eq_presets_popup addItemWithTitle:_NS("Add new Preset...")];
463 [[o_eq_presets_popup lastItem] setTarget: self];
464 [[o_eq_presets_popup lastItem] setAction: @selector(addPresetAction:)];
466 if ([presets count] > 1) {
467 [o_eq_presets_popup addItemWithTitle:_NS("Organize Presets...")];
468 [[o_eq_presets_popup lastItem] setTarget: self];
469 [[o_eq_presets_popup lastItem] setAction: @selector(deletePresetAction:)];
472 audio_output_t *p_aout = getAout();
474 NSString *currentPreset = nil;
476 currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_aout, "equalizer-preset")];
477 vlc_object_release(p_aout);
480 NSUInteger currentPresetIndex = 0;
481 if (currentPreset && [currentPreset length] > 0) {
482 currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
483 return [obj isEqualToString:currentPreset];
486 if (currentPresetIndex == NSNotFound)
487 currentPresetIndex = [presets count] - 1;
490 [o_eq_presets_popup selectItemAtIndex:currentPresetIndex];
491 [self eq_changePreset: o_eq_presets_popup];
494 [o_eq_preamp_sld setFloatValue:[[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:currentPresetIndex] floatValue]];
495 [self setBandSliderValuesForPreset:currentPresetIndex];
498 - (void)equalizerUpdated
500 float f_preamp = config_GetFloat(p_intf, "equalizer-preamp");
501 bool b_2p = (BOOL)config_GetInt(p_intf, "equalizer-2pass");
502 bool b_enabled = GetEqualizerStatus(p_intf, (char *)"equalizer");
505 [self updatePresetSelector];
507 /* Set the the checkboxes */
508 [o_eq_enable_ckb setState: b_enabled];
509 [o_eq_twopass_ckb setState: b_2p];
512 - (id)sliderByIndex:(int)index
515 case 0 : return o_eq_band1_sld;
516 case 1 : return o_eq_band2_sld;
517 case 2 : return o_eq_band3_sld;
518 case 3 : return o_eq_band4_sld;
519 case 4 : return o_eq_band5_sld;
520 case 5 : return o_eq_band6_sld;
521 case 6 : return o_eq_band7_sld;
522 case 7 : return o_eq_band8_sld;
523 case 8 : return o_eq_band9_sld;
524 case 9 : return o_eq_band10_sld;
525 default : return nil;
529 - (void)setBandSliderValuesForPreset:(NSInteger)presetID
531 NSString *preset = [[[NSUserDefaults standardUserDefaults] objectForKey:@"EQValues"] objectAtIndex:presetID];
532 NSArray *values = [preset componentsSeparatedByString:@" "];
533 NSUInteger count = [values count];
534 for (NSUInteger x = 0; x < count; x++)
535 [self setValue:[[values objectAtIndex:x] floatValue] forSlider:x];
538 - (NSString *)generatePresetString
540 return [NSString stringWithFormat:@"%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f",
541 [o_eq_band1_sld floatValue],
542 [o_eq_band2_sld floatValue],
543 [o_eq_band3_sld floatValue],
544 [o_eq_band4_sld floatValue],
545 [o_eq_band5_sld floatValue],
546 [o_eq_band6_sld floatValue],
547 [o_eq_band7_sld floatValue],
548 [o_eq_band8_sld floatValue],
549 [o_eq_band9_sld floatValue],
550 [o_eq_band10_sld floatValue]];
553 - (void)setValue:(float)value forSlider:(int)index
555 id slider = [self sliderByIndex:index];
558 [slider setFloatValue:value];
561 - (IBAction)eq_enable:(id)sender
563 [self setAudioFilter: "equalizer" on:[sender state]];
566 - (IBAction)eq_bandSliderUpdated:(id)sender
568 audio_output_t *p_aout = getAout();
570 var_SetString(p_aout, "equalizer-bands", [[self generatePresetString] UTF8String]);
571 vlc_object_release(p_aout);
574 /* save changed to config */
575 config_PutPsz(p_intf, "equalizer-bands", [[self generatePresetString] UTF8String]);
579 - (IBAction)eq_changePreset:(id)sender
581 NSInteger numberOfChosenPreset = [sender indexOfSelectedItem];
582 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
584 NSString *preset = [[defaults objectForKey:@"EQValues"] objectAtIndex:numberOfChosenPreset];
585 NSString *preamp = [[defaults objectForKey:@"EQPreampValues"] objectAtIndex:numberOfChosenPreset];
587 audio_output_t *p_aout = getAout();
589 var_SetString(p_aout, "equalizer-bands", [preset UTF8String]);
590 var_SetFloat(p_aout, "equalizer-preamp", [preamp floatValue]);
591 var_SetString(p_aout, "equalizer-preset" , [[[defaults objectForKey:@"EQNames"] objectAtIndex:numberOfChosenPreset] UTF8String]);
592 vlc_object_release(p_aout);
595 [o_eq_preamp_sld setFloatValue: [preamp floatValue]];
596 [self setBandSliderValuesForPreset:numberOfChosenPreset];
598 /* save changed to config */
599 config_PutPsz(p_intf, "equalizer-bands", [preset UTF8String]);
600 config_PutFloat(p_intf, "equalizer-preamp", [preamp floatValue]);
601 config_PutPsz(p_intf, "equalizer-preset", [[[defaults objectForKey:@"EQNames"] objectAtIndex:numberOfChosenPreset] UTF8String]);
605 - (IBAction)eq_preampSliderUpdated:(id)sender
607 float f_preamp = [sender floatValue] ;
609 audio_output_t *p_aout = getAout();
611 var_SetFloat(p_aout, "equalizer-preamp", f_preamp);
612 vlc_object_release(p_aout);
615 /* save changed to config */
616 config_PutFloat(p_intf, "equalizer-preamp", f_preamp);
619 - (IBAction)eq_twopass:(id)sender
621 bool b_2p = [sender state] ? true : false;
623 audio_output_t *p_aout = getAout();
625 var_SetBool(p_aout, "equalizer-2pass", b_2p);
626 vlc_object_release(p_aout);
629 /* save changed to config */
630 config_PutInt(p_intf, "equalizer-2pass", (int)b_2p);
634 - (IBAction)addPresetAction:(id)sender
637 VLCEnterTextPanel *panel = [VLCEnterTextPanel sharedInstance];
638 [panel setTitle: _NS("Save current selection as new preset")];
639 [panel setSubTitle: _NS("Enter a name for the new preset:")];
640 [panel setCancelButtonLabel: _NS("Cancel")];
641 [panel setOKButtonLabel: _NS("Save")];
642 [panel setTarget:self];
643 b_genericAudioProfileInInteraction = NO;
645 [panel runModalForWindow:o_window];
648 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
651 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
654 if (!b_genericAudioProfileInInteraction) {
655 if (value == NSOKButton && [text length] > 0) {
656 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
657 [workArray addObject:[self generatePresetString]];
658 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
660 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
661 [workArray addObject:text];
662 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
664 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
665 [workArray addObject:[NSString stringWithFormat:@"%.1f", [o_eq_preamp_sld floatValue]]];
666 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
668 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
669 [workArray addObject:[text decomposedStringWithCanonicalMapping]];
670 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
672 [defaults synchronize];
674 /* update VLC internals */
675 audio_output_t *p_aout = getAout();
677 var_SetString(p_aout, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
678 vlc_object_release(p_aout);
681 config_PutPsz(p_intf, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
685 [self updatePresetSelector];
691 if (value != NSOKButton) {
692 [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
696 NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
698 // duplicate names are not allowed in the popup control
699 if ([text length] == 0 || [profileNames containsObject:text]) {
700 [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
702 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
703 [alert setAlertStyle:NSCriticalAlertStyle];
704 [alert setMessageText:_NS("Please enter a unique name for the new profile.")];
705 [alert setInformativeText:_NS("Multiple profiles with the same name are not allowed.")];
707 [alert beginSheetModalForWindow:o_window
714 NSString *newProfile = [self generateProfileString];
716 /* add string to user defaults as well as a label */
717 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
718 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
719 [workArray addObject:newProfile];
720 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
721 [defaults setInteger:[workArray count] - 1 forKey:@"AudioEffectSelectedProfile"];
723 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
724 [workArray addObject:text];
725 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
729 [defaults synchronize];
730 [self resetProfileSelector];
734 - (IBAction)deletePresetAction:(id)sender
736 VLCSelectItemInPopupPanel *panel = [VLCSelectItemInPopupPanel sharedInstance];
737 [panel setTitle:_NS("Remove a preset")];
738 [panel setSubTitle:_NS("Select the preset you would like to remove:")];
739 [panel setOKButtonLabel:_NS("Remove")];
740 [panel setCancelButtonLabel:_NS("Cancel")];
741 [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
742 [panel setTarget:self];
743 b_genericAudioProfileInInteraction = NO;
745 [panel runModalForWindow:o_window];
748 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
750 if (value == NSOKButton) {
751 if (!b_genericAudioProfileInInteraction) {
752 /* remove requested profile from the arrays */
753 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
754 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
755 [workArray removeObjectAtIndex:item];
756 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
758 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
759 [workArray removeObjectAtIndex:item];
760 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
762 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
763 [workArray removeObjectAtIndex:item];
764 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
766 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
767 [workArray removeObjectAtIndex:item];
768 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
770 [defaults synchronize];
773 [self updatePresetSelector];
775 /* remove selected profile from settings */
776 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
777 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
778 [workArray removeObjectAtIndex:item];
779 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
781 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
782 [workArray removeObjectAtIndex:item];
783 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
786 if (i_old_profile_index >= item)
787 [defaults setInteger:i_old_profile_index - 1 forKey:@"AudioEffectSelectedProfile"];
790 [defaults synchronize];
791 [self resetProfileSelector];
797 #pragma mark Compressor
798 - (void)resetCompressor
801 psz_afilters = config_GetPsz(p_intf, "audio-filter");
803 [o_comp_enable_ckb setState: (NSInteger)strstr(psz_afilters, "compressor") ];
807 [o_comp_enable_ckb setState: NSOffState];
809 [o_comp_band1_sld setFloatValue: config_GetFloat(p_intf, "compressor-rms-peak")];
810 [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_comp_band1_sld floatValue]]];
811 [o_comp_band2_sld setFloatValue: config_GetFloat(p_intf, "compressor-attack")];
812 [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [o_comp_band2_sld floatValue]]];
813 [o_comp_band3_sld setFloatValue: config_GetFloat(p_intf, "compressor-release")];
814 [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [o_comp_band3_sld floatValue]]];
815 [o_comp_band4_sld setFloatValue: config_GetFloat(p_intf, "compressor-threshold")];
816 [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [o_comp_band4_sld floatValue]]];
817 [o_comp_band5_sld setFloatValue: config_GetFloat(p_intf, "compressor-ratio")];
818 [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [o_comp_band5_sld floatValue]]];
819 [o_comp_band6_sld setFloatValue: config_GetFloat(p_intf, "compressor-knee")];
820 [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band6_sld floatValue]]];
821 [o_comp_band7_sld setFloatValue: config_GetFloat(p_intf, "compressor-makeup-gain")];
822 [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band7_sld floatValue]]];
825 - (IBAction)resetCompressorValues:(id)sender
827 config_PutFloat(p_intf, "compressor-rms-peak", 0.000000);
828 config_PutFloat(p_intf, "compressor-attack", 25.000000);
829 config_PutFloat(p_intf, "compressor-release", 100.000000);
830 config_PutFloat(p_intf, "compressor-threshold", -11.000000);
831 config_PutFloat(p_intf, "compressor-ratio", 8.000000);
832 config_PutFloat(p_intf, "compressor-knee", 2.500000);
833 config_PutFloat(p_intf, "compressor-makeup-gain", 7.000000);
835 audio_output_t *p_aout = getAout();
837 var_SetFloat(p_aout, "compressor-rms-peak", 0.000000);
838 var_SetFloat(p_aout, "compressor-attack", 25.000000);
839 var_SetFloat(p_aout, "compressor-release", 100.000000);
840 var_SetFloat(p_aout, "compressor-threshold", -11.000000);
841 var_SetFloat(p_aout, "compressor-ratio", 8.000000);
842 var_SetFloat(p_aout, "compressor-knee", 2.500000);
843 var_SetFloat(p_aout, "compressor-makeup-gain", 7.000000);
844 vlc_object_release(p_aout);
846 [self resetCompressor];
849 - (IBAction)comp_enable:(id)sender
851 [self setAudioFilter:"compressor" on:[sender state]];
854 - (IBAction)comp_sliderUpdated:(id)sender
856 audio_output_t *p_aout = getAout();
858 if (sender == o_comp_band1_sld)
859 value = "compressor-rms-peak";
860 else if (sender == o_comp_band2_sld)
861 value = "compressor-attack";
862 else if (sender == o_comp_band3_sld)
863 value = "compressor-release";
864 else if (sender == o_comp_band4_sld)
865 value = "compressor-threshold";
866 else if (sender == o_comp_band5_sld)
867 value = "compressor-ratio";
868 else if (sender == o_comp_band6_sld)
869 value = "compressor-knee";
870 else if (sender == o_comp_band7_sld)
871 value = "compressor-makeup-gain";
874 var_SetFloat(p_aout, value, [sender floatValue]);
875 vlc_object_release(p_aout);
877 config_PutFloat(p_intf, value, [sender floatValue]);
879 if (sender == o_comp_band1_sld)
880 [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
881 else if (sender == o_comp_band2_sld)
882 [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [sender floatValue]]];
883 else if (sender == o_comp_band3_sld)
884 [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [sender floatValue]]];
885 else if (sender == o_comp_band4_sld)
886 [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [sender floatValue]]];
887 else if (sender == o_comp_band5_sld)
888 [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [sender floatValue]]];
889 else if (sender == o_comp_band6_sld)
890 [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
891 else if (sender == o_comp_band7_sld)
892 [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
896 #pragma mark Spatializer
897 - (void)resetSpatializer
900 psz_afilters = config_GetPsz(p_intf, "audio-filter");
902 [o_spat_enable_ckb setState: (NSInteger)strstr(psz_afilters, "spatializer") ];
906 [o_spat_enable_ckb setState: NSOffState];
908 #define setSlider(bandsld, bandfld, var) \
909 [bandsld setFloatValue: config_GetFloat(p_intf, var) * 10.]; \
910 [bandfld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [bandsld floatValue]]]
912 setSlider(o_spat_band1_sld, o_spat_band1_fld, "spatializer-roomsize");
913 setSlider(o_spat_band2_sld, o_spat_band2_fld, "spatializer-width");
914 setSlider(o_spat_band3_sld, o_spat_band3_fld, "spatializer-wet");
915 setSlider(o_spat_band4_sld, o_spat_band4_fld, "spatializer-dry");
916 setSlider(o_spat_band5_sld, o_spat_band5_fld, "spatializer-damp");
921 - (IBAction)resetSpatializerValues:(id)sender
923 config_PutFloat(p_intf, "spatializer-roomsize", .85);
924 config_PutFloat(p_intf, "spatializer-width", 1.);
925 config_PutFloat(p_intf, "spatializer-wet", .4);
926 config_PutFloat(p_intf, "spatializer-dry", .5);
927 config_PutFloat(p_intf, "spatializer-damp", .5);
929 audio_output_t *p_aout = getAout();
931 var_SetFloat(p_aout, "spatializer-roomsize", .85);
932 var_SetFloat(p_aout, "spatializer-width", 1.);
933 var_SetFloat(p_aout, "spatializer-wet", .4);
934 var_SetFloat(p_aout, "spatializer-dry", .5);
935 var_SetFloat(p_aout, "spatializer-damp", .5);
936 vlc_object_release(p_aout);
938 [self resetSpatializer];
941 - (IBAction)spat_enable:(id)sender
943 [self setAudioFilter:"spatializer" on:[sender state]];
946 - (IBAction)spat_sliderUpdated:(id)sender
948 audio_output_t *p_aout = getAout();
950 if (sender == o_spat_band1_sld)
951 value = "spatializer-roomsize";
952 else if (sender == o_spat_band2_sld)
953 value = "spatializer-width";
954 else if (sender == o_spat_band3_sld)
955 value = "spatializer-wet";
956 else if (sender == o_spat_band4_sld)
957 value = "spatializer-dry";
958 else if (sender == o_spat_band5_sld)
959 value = "spatializer-damp";
962 var_SetFloat(p_aout, value, [sender floatValue] / 10.);
963 vlc_object_release(p_aout);
965 config_PutFloat(p_intf, value, [sender floatValue] / 10.);
967 if (sender == o_spat_band1_sld)
968 [o_spat_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
969 else if (sender == o_spat_band2_sld)
970 [o_spat_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
971 else if (sender == o_spat_band3_sld)
972 [o_spat_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
973 else if (sender == o_spat_band4_sld)
974 [o_spat_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
975 else if (sender == o_spat_band5_sld)
976 [o_spat_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
981 - (void)resetAudioFilters
984 psz_afilters = config_GetPsz(p_intf, "audio-filter");
986 [o_filter_headPhone_ckb setState: (NSInteger)strstr(psz_afilters, "headphone") ];
987 [o_filter_normLevel_ckb setState: (NSInteger)strstr(psz_afilters, "normvol") ];
988 [o_filter_karaoke_ckb setState: (NSInteger)strstr(psz_afilters, "karaoke") ];
991 [o_filter_headPhone_ckb setState: NSOffState];
992 [o_filter_normLevel_ckb setState: NSOffState];
993 [o_filter_karaoke_ckb setState: NSOffState];
995 [o_filter_normLevel_sld setFloatValue: config_GetFloat(p_intf, "norm-max-level")];
998 - (IBAction)filter_enableHeadPhoneVirt:(id)sender
1000 [self setAudioFilter: "headphone" on:[sender state]];
1003 - (IBAction)filter_enableVolumeNorm:(id)sender
1005 [self setAudioFilter: "normvol" on:[sender state]];
1008 - (IBAction)filter_volNormSliderUpdated:(id)sender
1010 audio_output_t *p_aout = getAout();
1013 var_SetFloat(p_aout, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1014 vlc_object_release(p_aout);
1017 config_PutFloat(p_intf, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1020 - (IBAction)filter_enableKaraoke:(id)sender
1022 [self setAudioFilter: "karaoke" on:[sender state]];