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_aout_intf.h>
37 #import <vlc_strings.h>
42 #pragma mark Initialization
44 @implementation VLCAudioEffects
45 static VLCAudioEffects *_o_sharedInstance = nil;
47 + (VLCAudioEffects *)sharedInstance
49 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
53 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
55 NSString * workString;
56 NSMutableArray * workValues = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
57 NSMutableArray * workPreamp = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
58 NSMutableArray * workTitles = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
59 NSMutableArray * workNames = [[NSMutableArray alloc] initWithCapacity:NB_PRESETS];
61 for (int i = 0 ; i < NB_PRESETS ; i++) {
62 workString = [NSString stringWithFormat:@"%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f",
63 eqz_preset_10b[i].f_amp[0],
64 eqz_preset_10b[i].f_amp[1],
65 eqz_preset_10b[i].f_amp[2],
66 eqz_preset_10b[i].f_amp[3],
67 eqz_preset_10b[i].f_amp[4],
68 eqz_preset_10b[i].f_amp[5],
69 eqz_preset_10b[i].f_amp[6],
70 eqz_preset_10b[i].f_amp[7],
71 eqz_preset_10b[i].f_amp[8],
72 eqz_preset_10b[i].f_amp[9]];
73 [workValues addObject:workString];
74 [workPreamp addObject:[NSString stringWithFormat:@"%1.f", eqz_preset_10b[i].f_preamp]];
75 [workTitles addObject:[NSString stringWithUTF8String:preset_list_text[i]]];
76 [workNames addObject:[NSString stringWithUTF8String:preset_list[i]]];
79 NSString *defaultProfile = [NSString stringWithFormat:@"%i;;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%i",
80 0,.0,25.,100.,-11.,8.,2.5,7.,.85,1.,.4,.5,.5,2.,0];
82 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];
83 [defaults registerDefaults:appDefaults];
93 if (_o_sharedInstance)
97 _o_sharedInstance = [super init];
100 return _o_sharedInstance;
105 /* setup the user's language */
107 [o_eq_enable_ckb setTitle:_NS("Enable")];
108 [o_eq_twopass_ckb setTitle:_NS("2 Pass")];
109 [o_eq_preamp_lbl setStringValue:_NS("Preamp")];
112 [o_comp_enable_ckb setTitle:_NS("Enable dynamic range compressor")];
113 [o_comp_reset_btn setTitle:_NS("Reset")];
114 [o_comp_band1_lbl setStringValue:_NS("RMS/peak")];;
115 [o_comp_band2_lbl setStringValue:_NS("Attack")];
116 [o_comp_band3_lbl setStringValue:_NS("Release")];
117 [o_comp_band4_lbl setStringValue:_NS("Threshold")];
118 [o_comp_band5_lbl setStringValue:_NS("Ratio")];
119 [o_comp_band6_lbl setStringValue:_NS("Knee radius")];
120 [o_comp_band7_lbl setStringValue:_NS("Makeup gain")];
123 [o_spat_enable_ckb setTitle:_NS("Enable Spatializer")];
124 [o_spat_reset_btn setTitle:_NS("Reset")];
125 [o_spat_band1_lbl setStringValue:_NS("Size")];
126 [o_spat_band2_lbl setStringValue:_NS("Width")];
127 [o_spat_band3_lbl setStringValue:_NS("Wet")];
128 [o_spat_band4_lbl setStringValue:_NS("Dry")];
129 [o_spat_band5_lbl setStringValue:_NS("Damp")];
132 [o_filter_headPhone_ckb setTitle:_NS("Headphone virtualization")];
133 [o_filter_normLevel_ckb setTitle:_NS("Volume normalization")];
134 [o_filter_normLevel_lbl setStringValue:_NS("Maximum level")];
137 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"equalizer"]] setLabel:_NS("Equalizer")];
138 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"compressor"]] setLabel:_NS("Compressor")];
139 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"spatializer"]] setLabel:_NS("Spatializer")];
140 [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"filter"]] setLabel:_NS("Filter")];
141 [o_window setTitle:_NS("Audio Effects")];
142 [o_window setExcludedFromWindowsMenu:YES];
143 if (!OSX_SNOW_LEOPARD)
144 [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
146 [self setupEqualizer];
147 [self resetCompressor];
148 [self resetSpatializer];
149 [self resetAudioFilters];
150 [self resetProfileSelector];
154 #pragma mark internal functions
156 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
159 audio_output_t * p_aout = getAout();
161 psz_tmp = var_GetNonEmptyString(p_aout, "audio-filter");
163 psz_tmp = config_GetPsz(p_intf, "audio-filter");
167 config_PutPsz(p_intf, "audio-filter", psz_name);
168 else if ((NSInteger)strstr(psz_tmp, psz_name) == NO) {
169 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:%s", psz_tmp, psz_name] UTF8String];
170 config_PutPsz(p_intf, "audio-filter", psz_tmp);
174 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@":%s",psz_name]]] UTF8String];
175 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%s:",psz_name]]] UTF8String];
176 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithUTF8String:psz_name]]] UTF8String];
177 config_PutPsz(p_intf, "audio-filter", psz_tmp);
182 aout_EnableFilter(pl_Get(p_intf), psz_name, b_on);
183 vlc_object_release(p_aout);
187 - (void)resetProfileSelector
189 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
190 [o_profile_pop removeAllItems];
192 NSArray * profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
193 [o_profile_pop addItemsWithTitles:profileNames];
195 [[o_profile_pop menu] addItem:[NSMenuItem separatorItem]];
196 [o_profile_pop addItemWithTitle:_NS("Save selection as new profile...")];
197 [[o_profile_pop lastItem] setTarget: self];
198 [[o_profile_pop lastItem] setAction: @selector(addAudioEffectsProfile:)];
200 if ([profileNames count] > 1) {
201 [o_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
202 [[o_profile_pop lastItem] setTarget: self];
203 [[o_profile_pop lastItem] setAction: @selector(removeAudioEffectsProfile:)];
206 [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
207 [self profileSelectorAction:self];
211 #pragma mark generic code
212 - (IBAction)toggleWindow:(id)sender
214 if ([o_window isVisible])
215 [o_window orderOut:sender];
217 [o_window makeKeyAndOrderFront:sender];
220 - (IBAction)profileSelectorAction:(id)sender
222 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
223 NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem];
225 audio_output_t * p_aout = getAout();
226 playlist_t * p_playlist = pl_Get(p_intf);
229 /* disable existing filters */
230 aout_EnableFilter(p_playlist, "equalizer", false);
231 aout_EnableFilter(p_playlist, "compressor", false);
232 aout_EnableFilter(p_playlist, "spatializer", false);
233 aout_EnableFilter(p_playlist, "compressor", false);
234 aout_EnableFilter(p_playlist, "headphone", false);
235 aout_EnableFilter(p_playlist, "normvol", false);
239 NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
242 vlc_object_t *p_object = VLC_OBJECT(getAout());
243 if (p_object == NULL)
244 p_object = vlc_object_hold(pl_Get(p_intf));
245 /* sanity check here, since the user may have removed the custom preset in the mean time */
246 if ([[items objectAtIndex:0] intValue] < [[defaults objectForKey:@"EQNames"] count])
247 var_SetString(p_object,"equalizer-preset",[[[defaults objectForKey:@"EQNames"] objectAtIndex:[[items objectAtIndex:0] intValue]]UTF8String]);
249 var_SetString(p_object,"equalizer-preset","flat");
250 vlc_object_release(p_object);
252 /* filter handling */
253 NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])];
256 /* enable the new filters, if we have an aout */
258 if ([tempString length] > 0) {
259 tempArray = [tempString componentsSeparatedByString:@":"];
260 count = [tempArray count];
261 for (NSUInteger x = 0; x < count; x++)
262 aout_EnableFilter(p_playlist, (char *)[[tempArray objectAtIndex:x] UTF8String], true);
265 config_PutPsz(p_intf,"audio-filter",[tempString UTF8String]);
268 config_PutFloat(p_intf, "compressor-rms-peak",[[items objectAtIndex:2] floatValue]);
269 config_PutFloat(p_intf, "compressor-attack",[[items objectAtIndex:3] floatValue]);
270 config_PutFloat(p_intf, "compressor-release",[[items objectAtIndex:4] floatValue]);
271 config_PutFloat(p_intf, "compressor-threshold",[[items objectAtIndex:5] floatValue]);
272 config_PutFloat(p_intf, "compressor-ratio",[[items objectAtIndex:6] floatValue]);
273 config_PutFloat(p_intf, "compressor-knee",[[items objectAtIndex:7] floatValue]);
274 config_PutFloat(p_intf, "compressor-makeup-gain",[[items objectAtIndex:8] floatValue]);
275 config_PutFloat(p_intf, "spatializer-roomsize",[[items objectAtIndex:9] floatValue]);
276 config_PutFloat(p_intf, "spatializer-width",[[items objectAtIndex:10] floatValue]);
277 config_PutFloat(p_intf, "spatializer-wet",[[items objectAtIndex:11] floatValue]);
278 config_PutFloat(p_intf, "spatializer-dry",[[items objectAtIndex:12] floatValue]);
279 config_PutFloat(p_intf, "spatializer-damp",[[items objectAtIndex:13] floatValue]);
280 config_PutFloat(p_intf, "norm-max-level",[[items objectAtIndex:14] floatValue]);
281 config_PutInt(p_intf, "equalizer-2pass",[[items objectAtIndex:15] intValue]);
283 /* set values on-the-fly if we have an aout */
285 var_SetFloat(p_aout, "compressor-rms-peak", [[items objectAtIndex:2] floatValue]);
286 var_SetFloat(p_aout, "compressor-attack", [[items objectAtIndex:3] floatValue]);
287 var_SetFloat(p_aout, "compressor-release", [[items objectAtIndex:4] floatValue]);
288 var_SetFloat(p_aout, "compressor-threshold", [[items objectAtIndex:5] floatValue]);
289 var_SetFloat(p_aout, "compressor-ratio", [[items objectAtIndex:6] floatValue]);
290 var_SetFloat(p_aout, "compressor-knee", [[items objectAtIndex:7] floatValue]);
291 var_SetFloat(p_aout, "compressor-makeup-gain", [[items objectAtIndex:8] floatValue]);
292 var_SetFloat(p_aout, "spatializer-roomsize", [[items objectAtIndex:9] floatValue]);
293 var_SetFloat(p_aout, "spatializer-width", [[items objectAtIndex:10] floatValue]);
294 var_SetFloat(p_aout, "spatializer-wet", [[items objectAtIndex:11] floatValue]);
295 var_SetFloat(p_aout, "spatializer-dry", [[items objectAtIndex:12] floatValue]);
296 var_SetFloat(p_aout, "spatializer-damp", [[items objectAtIndex:13] floatValue]);
297 var_SetFloat(p_aout, "norm-max-level", [[items objectAtIndex:14] floatValue]);
298 var_SetBool(p_aout, "equalizer-2pass", (BOOL)[[items objectAtIndex:15] intValue]);
302 if ([tempString rangeOfString:@"equalizer"].location == NSNotFound)
303 [o_eq_enable_ckb setState:NSOffState];
305 [o_eq_enable_ckb setState:NSOnState];
306 [o_eq_twopass_ckb setState:[[items objectAtIndex:15] intValue]];
307 [self resetCompressor];
308 [self resetSpatializer];
309 [self resetAudioFilters];
310 [self updatePresetSelector];
312 /* store current profile selection */
313 [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"];
314 [defaults synchronize];
317 vlc_object_release(p_aout);
320 - (IBAction)addAudioEffectsProfile:(id)sender
323 VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
324 [panel setTitle: _NS("Save current selection as new profile")];
325 [panel setSubTitle: _NS("Enter a name for the new profile:")];
326 [panel setCancelButtonLabel: _NS("Cancel")];
327 [panel setOKButtonLabel: _NS("Save")];
328 [panel setTarget:self];
329 b_genericAudioProfileInInteraction = YES;
331 [panel runModalForWindow:o_window];
334 - (IBAction)removeAudioEffectsProfile:(id)sender
337 VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
338 [panel setTitle:_NS("Remove a preset")];
339 [panel setSubTitle:_NS("Select the preset you would like to remove:")];
340 [panel setOKButtonLabel:_NS("Remove")];
341 [panel setCancelButtonLabel:_NS("Cancel")];
342 [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
343 [panel setTarget:self];
344 b_genericAudioProfileInInteraction = YES;
346 [panel runModalForWindow:o_window];
350 #pragma mark Equalizer
351 static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
354 char *psz_parser, *psz_string = NULL;
355 vlc_object_t *p_object = VLC_OBJECT(getAout());
356 if (p_object == NULL)
357 p_object = vlc_object_hold(pl_Get(p_custom_intf));
359 psz_string = config_GetPsz(p_custom_intf, "audio-filter");
362 psz_string = var_GetNonEmptyString(p_object, "audio-filter");
364 vlc_object_release(p_object);
369 psz_parser = strstr(psz_string, psz_name);
379 - (void)setupEqualizer
381 vlc_object_t *p_object = VLC_OBJECT(getAout());
382 if (p_object == NULL)
383 p_object = vlc_object_hold(pl_Get(p_intf));
385 var_Create(p_object, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
387 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
388 NSArray * presets = [defaults objectForKey:@"EQNames"];
389 NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")];
390 NSInteger currentPresetIndex = 0;
391 if ([currentPreset length] > 0) {
392 currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
393 return [obj isEqualToString:currentPreset];
398 snprintf(psz_bands, sizeof(psz_bands),
399 "%.1f %.1f %.1f %.1f %.1f %.1f %.1f "
401 eqz_preset_10b[currentPresetIndex].f_amp[0],
402 eqz_preset_10b[currentPresetIndex].f_amp[1],
403 eqz_preset_10b[currentPresetIndex].f_amp[2],
404 eqz_preset_10b[currentPresetIndex].f_amp[3],
405 eqz_preset_10b[currentPresetIndex].f_amp[4],
406 eqz_preset_10b[currentPresetIndex].f_amp[5],
407 eqz_preset_10b[currentPresetIndex].f_amp[6],
408 eqz_preset_10b[currentPresetIndex].f_amp[7],
409 eqz_preset_10b[currentPresetIndex].f_amp[8],
410 eqz_preset_10b[currentPresetIndex].f_amp[9]);
412 var_Create(p_object, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
413 var_Create(p_object, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
414 var_SetFloat(p_object, "equalizer-preamp", eqz_preset_10b[currentPresetIndex].f_preamp);
415 var_SetString(p_object, "equalizer-bands", psz_bands);
416 vlc_object_release(p_object);
418 [self updatePresetSelector];
420 [self equalizerUpdated];
423 - (void)updatePresetSelector
425 [o_eq_presets_popup removeAllItems];
426 [o_eq_presets_popup addItemsWithTitles:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
427 [[o_eq_presets_popup menu] addItem:[NSMenuItem separatorItem]];
428 [o_eq_presets_popup addItemWithTitle:_NS("Add new Preset...")];
429 [[o_eq_presets_popup lastItem] setTarget: self];
430 [[o_eq_presets_popup lastItem] setAction: @selector(addPresetAction:)];
431 [o_eq_presets_popup addItemWithTitle:_NS("Organize Presets...")];
432 [[o_eq_presets_popup lastItem] setTarget: self];
433 [[o_eq_presets_popup lastItem] setAction: @selector(deletePresetAction:)];
435 vlc_object_t *p_object = VLC_OBJECT(getAout());
436 if (p_object == NULL)
437 p_object = vlc_object_hold(pl_Get(p_intf));
439 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
440 NSArray * presets = [defaults objectForKey:@"EQNames"];
441 NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")];
442 NSInteger currentPresetIndex = 0;
443 if ([currentPreset length] > 0) {
444 currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
445 return [obj isEqualToString:currentPreset];
449 [o_eq_presets_popup selectItemAtIndex:currentPresetIndex];
450 [o_eq_preamp_sld setFloatValue:[[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:currentPresetIndex] floatValue]];
451 [self setBandSliderValuesForPreset:currentPresetIndex];
453 vlc_object_release(p_object);
456 - (void)equalizerUpdated
458 float f_preamp, f_band[10];
459 char *psz_bands, *psz_bands_init, *p_next;
461 bool b_enabled = GetEqualizerStatus(p_intf, (char *)"equalizer");
462 vlc_object_t *p_object = VLC_OBJECT(getAout());
464 if (p_object == NULL)
465 p_object = vlc_object_hold(pl_Get(p_intf));
467 var_Create(p_object, "equalizer-preamp", VLC_VAR_FLOAT |
469 var_Create(p_object, "equalizer-bands", VLC_VAR_STRING |
472 psz_bands = var_GetNonEmptyString(p_object, "equalizer-bands");
474 if (psz_bands == NULL)
475 psz_bands = strdup("0 0 0 0 0 0 0 0 0 0");
477 b_2p = (BOOL)config_GetInt(p_object, "equalizer-2pass");
478 f_preamp = config_GetFloat(p_object, "equalizer-preamp");
480 vlc_object_release(p_object);
483 [self updatePresetSelector];
485 /* Set the the checkboxes */
486 [o_eq_enable_ckb setState: b_enabled];
487 [o_eq_twopass_ckb setState: b_2p];
490 - (id)sliderByIndex:(int)index
493 case 0 : return o_eq_band1_sld;
494 case 1 : return o_eq_band2_sld;
495 case 2 : return o_eq_band3_sld;
496 case 3 : return o_eq_band4_sld;
497 case 4 : return o_eq_band5_sld;
498 case 5 : return o_eq_band6_sld;
499 case 6 : return o_eq_band7_sld;
500 case 7 : return o_eq_band8_sld;
501 case 8 : return o_eq_band9_sld;
502 case 9 : return o_eq_band10_sld;
503 default : return nil;
507 - (void)setBandSlidersValues:(float *)values
509 for (int i = 0 ; i<= 9 ; i++)
510 [self setValue:values[i] forSlider:i];
513 - (void)setBandSliderValuesForPreset:(NSInteger)presetID
515 NSString * preset = [[[NSUserDefaults standardUserDefaults] objectForKey:@"EQValues"] objectAtIndex:presetID];
516 NSArray * values = [preset componentsSeparatedByString:@" "];
517 NSUInteger count = [values count];
518 for (NSUInteger x = 0; x < count; x++)
519 [self setValue:[[values objectAtIndex:x] floatValue] forSlider:x];
522 - (void)initBandSliders
524 for (int i = 0 ; i< 9 ; i++)
525 [self setValue:0.0 forSlider:i];
528 - (NSString *)generatePresetString
530 return [NSString stringWithFormat:@"%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f",
531 [o_eq_band1_sld floatValue],
532 [o_eq_band2_sld floatValue],
533 [o_eq_band3_sld floatValue],
534 [o_eq_band4_sld floatValue],
535 [o_eq_band5_sld floatValue],
536 [o_eq_band6_sld floatValue],
537 [o_eq_band7_sld floatValue],
538 [o_eq_band8_sld floatValue],
539 [o_eq_band9_sld floatValue],
540 [o_eq_band10_sld floatValue]];
543 - (void)setValue:(float)value forSlider:(int)index
545 id slider = [self sliderByIndex:index];
548 [slider setFloatValue:value];
551 - (IBAction)eq_enable:(id)sender
553 [self setAudioFilter: "equalizer" on:[sender state]];
556 - (IBAction)eq_bandSliderUpdated:(id)sender
558 vlc_object_t *p_object = VLC_OBJECT(getAout());
560 if (p_object == NULL)
561 p_object = vlc_object_hold(pl_Get(p_intf));
563 var_SetString(p_object, "equalizer-bands", [[self generatePresetString] UTF8String]);
565 /* save changed to config */
566 config_PutPsz(p_intf, "equalizer-bands", [[self generatePresetString] UTF8String]);
568 vlc_object_release(p_object);
571 - (IBAction)eq_changePreset:(id)sender
573 vlc_object_t *p_object= VLC_OBJECT(getAout());
574 if (p_object == NULL)
575 p_object = vlc_object_hold(pl_Get(p_intf));
576 NSInteger numberOfChosenPreset = [sender indexOfSelectedItem];
577 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
579 NSString *preset = [[defaults objectForKey:@"EQValues"] objectAtIndex:numberOfChosenPreset];
580 NSString *preamp = [[defaults objectForKey:@"EQPreampValues"] objectAtIndex:numberOfChosenPreset];
582 var_SetString(p_object, "equalizer-bands", [preset UTF8String]);
583 var_SetFloat(p_object, "equalizer-preamp", [preamp floatValue]);
584 var_SetString(p_object , "equalizer-preset" , [[[defaults objectForKey:@"EQNames"] objectAtIndex:numberOfChosenPreset] UTF8String]);
586 [o_eq_preamp_sld setFloatValue: [preamp floatValue]];
587 [self setBandSliderValuesForPreset:numberOfChosenPreset];
589 /* save changed to config */
590 config_PutPsz(p_intf, "equalizer-bands", [preset UTF8String]);
591 config_PutFloat(p_intf, "equalizer-preamp", [preamp floatValue]);
592 config_PutPsz(p_intf, "equalizer-preset", [[[defaults objectForKey:@"EQNames"] objectAtIndex:numberOfChosenPreset] UTF8String]);
594 vlc_object_release(p_object);
597 - (IBAction)eq_preampSliderUpdated:(id)sender
599 float f_preamp = [sender floatValue] ;
601 vlc_object_t *p_object = VLC_OBJECT(getAout());
602 if (p_object == NULL)
603 p_object = vlc_object_hold(pl_Get(p_intf));
605 var_SetFloat(p_object, "equalizer-preamp", f_preamp);
607 /* save changed to config */
608 config_PutFloat(p_intf, "equalizer-preamp", f_preamp);
610 vlc_object_release(p_object);
612 - (IBAction)eq_twopass:(id)sender
614 bool b_2p = [sender state] ? true : false;
615 audio_output_t *p_aout = getAout();
616 vlc_object_t *p_object= VLC_OBJECT(p_aout);
617 if (p_object == NULL)
618 p_object = vlc_object_hold(pl_Get(p_intf));
620 var_SetBool(p_object, "equalizer-2pass", b_2p);
622 /* save changed to config */
623 config_PutInt(p_intf, "equalizer-2pass", (int)b_2p);
625 vlc_object_release(p_object);
628 - (IBAction)addPresetAction:(id)sender
631 VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
632 [panel setTitle: _NS("Save current selection as new preset")];
633 [panel setSubTitle: _NS("Enter a name for the new preset:")];
634 [panel setCancelButtonLabel: _NS("Cancel")];
635 [panel setOKButtonLabel: _NS("Save")];
636 [panel setTarget:self];
637 b_genericAudioProfileInInteraction = NO;
639 [panel runModalForWindow:o_window];
642 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
644 if (value == NSOKButton) {
645 if ([text length] > 0) {
646 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
648 if (!b_genericAudioProfileInInteraction) {
650 NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
651 [workArray addObject:[self generatePresetString]];
652 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
654 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
655 [workArray addObject:text];
656 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
658 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
659 [workArray addObject:[NSString stringWithFormat:@"%.1f", [o_eq_preamp_sld floatValue]]];
660 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
662 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
663 [workArray addObject:[text decomposedStringWithCanonicalMapping]];
664 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
666 [defaults synchronize];
668 /* update VLC internals */
669 vlc_object_t *p_object= VLC_OBJECT(getAout());
670 if (p_object == NULL)
671 p_object = vlc_object_hold(pl_Get(p_intf));
673 var_SetString(p_object , "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
674 config_PutPsz(p_object, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
676 vlc_object_release(p_object);
679 [self updatePresetSelector];
681 vlc_object_t *p_object = VLC_OBJECT(getAout());
682 if (p_object == NULL)
683 p_object = vlc_object_hold(pl_Get(p_intf));
685 NSArray * presets = [defaults objectForKey:@"EQNames"];
686 NSString * currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_object, "equalizer-preset")];
687 NSInteger currentPresetIndex = 0;
688 if ([currentPreset length] > 0) {
689 currentPresetIndex = [presets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
690 return [obj isEqualToString:currentPreset];
693 NSString *newProfile = [NSString stringWithFormat:@"%li;%s;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%lli",
695 vlc_b64_encode(config_GetPsz(p_intf, "audio-filter")),
696 config_GetFloat(p_intf, "compressor-rms-peak"),
697 config_GetFloat(p_intf, "compressor-attack"),
698 config_GetFloat(p_intf, "compressor-release"),
699 config_GetFloat(p_intf, "compressor-threshold"),
700 config_GetFloat(p_intf, "compressor-ratio"),
701 config_GetFloat(p_intf, "compressor-knee"),
702 config_GetFloat(p_intf, "compressor-makeup-gain"),
703 config_GetFloat(p_intf, "spatializer-roomsize"),
704 config_GetFloat(p_intf, "spatializer-width"),
705 config_GetFloat(p_intf, "spatializer-wet"),
706 config_GetFloat(p_intf, "spatializer-dry"),
707 config_GetFloat(p_intf, "spatializer-damp"),
708 config_GetFloat(p_intf, "norm-max-level"),
709 config_GetInt(p_intf,"equalizer-2pass")];
711 /* add string to user defaults as well as a label */
712 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
713 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
714 [workArray addObject:newProfile];
715 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
716 [defaults setInteger:[workArray count] - 1 forKey:@"AudioEffectSelectedProfile"];
718 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
719 [workArray addObject:text];
720 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
724 [defaults synchronize];
725 vlc_object_release(p_object);
730 [self resetProfileSelector];
733 - (IBAction)deletePresetAction:(id)sender
735 VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
736 [panel setTitle:_NS("Remove a preset")];
737 [panel setSubTitle:_NS("Select the preset you would like to remove:")];
738 [panel setOKButtonLabel:_NS("Remove")];
739 [panel setCancelButtonLabel:_NS("Cancel")];
740 [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
741 [panel setTarget:self];
742 b_genericAudioProfileInInteraction = NO;
744 [panel runModalForWindow:o_window];
747 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
749 if (value == NSOKButton) {
750 if (!b_genericAudioProfileInInteraction) {
751 /* remove requested profile from the arrays */
752 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
753 NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
754 [workArray removeObjectAtIndex:item];
755 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
757 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
758 [workArray removeObjectAtIndex:item];
759 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
761 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
762 [workArray removeObjectAtIndex:item];
763 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
765 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
766 [workArray removeObjectAtIndex:item];
767 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
769 [defaults synchronize];
772 [self updatePresetSelector];
774 /* remove selected profile from settings */
775 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
776 NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
777 [workArray removeObjectAtIndex:item];
778 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
780 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
781 [workArray removeObjectAtIndex:item];
782 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
786 [defaults synchronize];
787 [self resetProfileSelector];
793 #pragma mark Compressor
794 - (void)resetCompressor
797 psz_afilters = config_GetPsz(p_intf, "audio-filter");
799 [o_comp_enable_ckb setState: (NSInteger)strstr(psz_afilters, "compressor") ];
803 [o_comp_enable_ckb setState: NSOffState];
805 [o_comp_band1_sld setFloatValue: config_GetFloat(p_intf, "compressor-rms-peak")];
806 [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_comp_band1_sld floatValue]]];
807 [o_comp_band2_sld setFloatValue: config_GetFloat(p_intf, "compressor-attack")];
808 [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [o_comp_band2_sld floatValue]]];
809 [o_comp_band3_sld setFloatValue: config_GetFloat(p_intf, "compressor-release")];
810 [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [o_comp_band3_sld floatValue]]];
811 [o_comp_band4_sld setFloatValue: config_GetFloat(p_intf, "compressor-threshold")];
812 [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [o_comp_band4_sld floatValue]]];
813 [o_comp_band5_sld setFloatValue: config_GetFloat(p_intf, "compressor-ratio")];
814 [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [o_comp_band5_sld floatValue]]];
815 [o_comp_band6_sld setFloatValue: config_GetFloat(p_intf, "compressor-knee")];
816 [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band6_sld floatValue]]];
817 [o_comp_band7_sld setFloatValue: config_GetFloat(p_intf, "compressor-makeup-gain")];
818 [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band7_sld floatValue]]];
821 - (IBAction)resetCompressorValues:(id)sender
823 config_PutFloat(p_intf, "compressor-rms-peak", 0.000000);
824 config_PutFloat(p_intf, "compressor-attack", 25.000000);
825 config_PutFloat(p_intf, "compressor-release", 100.000000);
826 config_PutFloat(p_intf, "compressor-threshold", -11.000000);
827 config_PutFloat(p_intf, "compressor-ratio", 8.000000);
828 config_PutFloat(p_intf, "compressor-knee", 2.500000);
829 config_PutFloat(p_intf, "compressor-makeup-gain", 7.000000);
831 audio_output_t * p_aout = getAout();
833 var_SetFloat(p_aout, "compressor-rms-peak", 0.000000);
834 var_SetFloat(p_aout, "compressor-attack", 25.000000);
835 var_SetFloat(p_aout, "compressor-release", 100.000000);
836 var_SetFloat(p_aout, "compressor-threshold", -11.000000);
837 var_SetFloat(p_aout, "compressor-ratio", 8.000000);
838 var_SetFloat(p_aout, "compressor-knee", 2.500000);
839 var_SetFloat(p_aout, "compressor-makeup-gain", 7.000000);
840 vlc_object_release(p_aout);
842 [self resetCompressor];
845 - (IBAction)comp_enable:(id)sender
847 [self setAudioFilter:"compressor" on:[sender state]];
850 - (IBAction)comp_sliderUpdated:(id)sender
852 audio_output_t * p_aout = getAout();
854 if (sender == o_comp_band1_sld)
855 value = "compressor-rms-peak";
856 else if (sender == o_comp_band2_sld)
857 value = "compressor-attack";
858 else if (sender == o_comp_band3_sld)
859 value = "compressor-release";
860 else if (sender == o_comp_band4_sld)
861 value = "compressor-threshold";
862 else if (sender == o_comp_band5_sld)
863 value = "compressor-ratio";
864 else if (sender == o_comp_band6_sld)
865 value = "compressor-knee";
866 else if (sender == o_comp_band7_sld)
867 value = "compressor-makeup-gain";
870 var_SetFloat(p_aout, value, [sender floatValue]);
871 vlc_object_release(p_aout);
873 config_PutFloat(p_intf, value, [sender floatValue]);
875 if (sender == o_comp_band1_sld)
876 [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
877 else if (sender == o_comp_band2_sld)
878 [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [sender floatValue]]];
879 else if (sender == o_comp_band3_sld)
880 [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [sender floatValue]]];
881 else if (sender == o_comp_band4_sld)
882 [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [sender floatValue]]];
883 else if (sender == o_comp_band5_sld)
884 [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [sender floatValue]]];
885 else if (sender == o_comp_band6_sld)
886 [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
887 else if (sender == o_comp_band7_sld)
888 [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
892 #pragma mark Spatializer
893 - (void)resetSpatializer
896 psz_afilters = config_GetPsz(p_intf, "audio-filter");
898 [o_spat_enable_ckb setState: (NSInteger)strstr(psz_afilters, "spatializer") ];
902 [o_spat_enable_ckb setState: NSOffState];
904 #define setSlider(bandsld, bandfld, var) \
905 [bandsld setFloatValue: config_GetFloat(p_intf, var) * 10.]; \
906 [bandfld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [bandsld floatValue]]]
908 setSlider(o_spat_band1_sld, o_spat_band1_fld, "spatializer-roomsize");
909 setSlider(o_spat_band2_sld, o_spat_band2_fld, "spatializer-width");
910 setSlider(o_spat_band3_sld, o_spat_band3_fld, "spatializer-wet");
911 setSlider(o_spat_band4_sld, o_spat_band4_fld, "spatializer-dry");
912 setSlider(o_spat_band5_sld, o_spat_band5_fld, "spatializer-damp");
917 - (IBAction)resetSpatializerValues:(id)sender
919 config_PutFloat(p_intf, "spatializer-roomsize", .85);
920 config_PutFloat(p_intf, "spatializer-width", 1.);
921 config_PutFloat(p_intf, "spatializer-wet", .4);
922 config_PutFloat(p_intf, "spatializer-dry", .5);
923 config_PutFloat(p_intf, "spatializer-damp", .5);
925 audio_output_t * p_aout = getAout();
927 var_SetFloat(p_aout, "spatializer-roomsize", .85);
928 var_SetFloat(p_aout, "spatializer-width", 1.);
929 var_SetFloat(p_aout, "spatializer-wet", .4);
930 var_SetFloat(p_aout, "spatializer-dry", .5);
931 var_SetFloat(p_aout, "spatializer-damp", .5);
932 vlc_object_release(p_aout);
934 [self resetSpatializer];
937 - (IBAction)spat_enable:(id)sender
939 [self setAudioFilter:"spatializer" on:[sender state]];
942 - (IBAction)spat_sliderUpdated:(id)sender
944 audio_output_t * p_aout = getAout();
946 if (sender == o_spat_band1_sld)
947 value = "spatializer-roomsize";
948 else if (sender == o_spat_band2_sld)
949 value = "spatializer-width";
950 else if (sender == o_spat_band3_sld)
951 value = "spatializer-wet";
952 else if (sender == o_spat_band4_sld)
953 value = "spatializer-dry";
954 else if (sender == o_spat_band5_sld)
955 value = "spatializer-damp";
958 var_SetFloat(p_aout, value, [sender floatValue] / 10.);
959 vlc_object_release(p_aout);
961 config_PutFloat(p_intf, value, [sender floatValue] / 10.);
963 if (sender == o_spat_band1_sld)
964 [o_spat_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
965 else if (sender == o_spat_band2_sld)
966 [o_spat_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
967 else if (sender == o_spat_band3_sld)
968 [o_spat_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
969 else if (sender == o_spat_band4_sld)
970 [o_spat_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
971 else if (sender == o_spat_band5_sld)
972 [o_spat_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
977 - (void)resetAudioFilters
980 psz_afilters = config_GetPsz(p_intf, "audio-filter");
982 [o_filter_headPhone_ckb setState: (NSInteger)strstr(psz_afilters, "headphone") ];
983 [o_filter_normLevel_ckb setState: (NSInteger)strstr(psz_afilters, "normvol") ];
986 [o_filter_headPhone_ckb setState: NSOffState];
987 [o_filter_normLevel_ckb setState: NSOffState];
989 [o_filter_normLevel_sld setFloatValue: config_GetFloat(p_intf, "norm-max-level")];
992 - (IBAction)filter_enableHeadPhoneVirt:(id)sender
994 [self setAudioFilter: "headphone" on:[sender state]];
997 - (IBAction)filter_enableVolumeNorm:(id)sender
999 [self setAudioFilter: "normvol" on:[sender state]];
1002 - (IBAction)filter_volNormSliderUpdated:(id)sender
1004 audio_output_t * p_aout= getAout();
1007 var_SetFloat(p_aout, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1008 vlc_object_release(p_aout);
1011 config_PutFloat(p_intf, "norm-max-level", [o_filter_normLevel_sld floatValue]);