]> git.sesse.net Git - vlc/blob - modules/gui/macosx/AudioEffects.m
1e47b851377dd5cec66ec8accd89c84a3cd39251
[vlc] / modules / gui / macosx / AudioEffects.m
1 /*****************************************************************************
2  * AudioEffects.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2004-2012 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *          Jérôme Decoodt <djc@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # import "config.h"
27 #endif
28
29 #import "intf.h"
30 #import "AudioEffects.h"
31 #import "../../audio_filter/equalizer_presets.h"
32 #import "CompatibilityFixes.h"
33 #import "SharedDialogs.h"
34
35 #import <vlc_common.h>
36 #import <vlc_aout_intf.h>
37 #import <vlc_strings.h>
38
39 #import <math.h>
40
41 #pragma mark -
42 #pragma mark Initialization
43
44 @implementation VLCAudioEffects
45 static VLCAudioEffects *_o_sharedInstance = nil;
46
47 + (VLCAudioEffects *)sharedInstance
48 {
49     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
50 }
51
52 + (void)initialize{
53     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
54
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];
60
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]]];
77     }
78
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];
81
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];
84
85     [workValues release];
86     [workPreamp release];
87     [workTitles release];
88     [workNames release];
89 }
90
91 - (id)init
92 {
93     if (_o_sharedInstance)
94         [self dealloc];
95     else {
96         p_intf = VLCIntf;
97         _o_sharedInstance = [super init];
98     }
99
100     return _o_sharedInstance;
101 }
102
103 - (void)awakeFromNib
104 {
105     /* setup the user's language */
106     /* Equalizer */
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")];
110
111     /* Compressor */
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")];
121
122     /* Spatializer */
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")];
130
131     /* Filter */
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")];
135
136     /* generic */
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];
145
146     [self setupEqualizer];
147     [self resetCompressor];
148     [self resetSpatializer];
149     [self resetAudioFilters];
150     [self resetProfileSelector];
151 }
152
153 #pragma mark -
154 #pragma mark internal functions
155
156 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
157 {
158     char *psz_tmp;
159     audio_output_t * p_aout = getAout();
160     if (p_aout)
161         psz_tmp = var_GetNonEmptyString(p_aout, "audio-filter");
162     else
163         psz_tmp = config_GetPsz(p_intf, "audio-filter");
164
165     if (b_on) {
166         if (!psz_tmp)
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);
171         }
172     } else {
173         if (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);
178         }
179     }
180
181     if (p_aout) {
182         aout_EnableFilter(pl_Get(p_intf), psz_name, b_on);
183         vlc_object_release(p_aout);
184     }
185 }
186
187 - (void)resetProfileSelector
188 {
189     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
190     [o_profile_pop removeAllItems];
191
192     NSArray * profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
193     [o_profile_pop addItemsWithTitles:profileNames];
194
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:)];
199
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:)];
204     }
205
206     [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
207     [self profileSelectorAction:self];
208 }
209
210 #pragma mark -
211 #pragma mark generic code
212 - (IBAction)toggleWindow:(id)sender
213 {
214     if ([o_window isVisible])
215         [o_window orderOut:sender];
216     else
217         [o_window makeKeyAndOrderFront:sender];
218 }
219
220 - (IBAction)profileSelectorAction:(id)sender
221 {
222     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
223     NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem];
224
225     audio_output_t * p_aout = getAout();
226     playlist_t * p_playlist = pl_Get(p_intf);
227
228     if (p_aout) {
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);
236     }
237
238     /* fetch preset */
239     NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
240
241     /* eq preset */
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]);
248     else
249         var_SetString(p_object,"equalizer-preset","flat");
250     vlc_object_release(p_object);
251
252     /* filter handling */
253     NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])];
254     NSArray *tempArray;
255     NSUInteger count;
256     /* enable the new filters, if we have an aout */
257     if (p_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);
263         }
264     }
265     config_PutPsz(p_intf,"audio-filter",[tempString UTF8String]);
266
267     /* values */
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]);
282
283     /* set values on-the-fly if we have an aout */
284     if (p_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]);
299     }
300
301     /* update UI */
302     if ([tempString rangeOfString:@"equalizer"].location == NSNotFound)
303         [o_eq_enable_ckb setState:NSOffState];
304     else
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];
311
312     /* store current profile selection */
313     [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"];
314     [defaults synchronize];
315
316     if (p_aout)
317         vlc_object_release(p_aout);
318 }
319
320 - (IBAction)addAudioEffectsProfile:(id)sender
321 {
322     /* show panel */
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;
330
331     [panel runModalForWindow:o_window];
332 }
333
334 - (IBAction)removeAudioEffectsProfile:(id)sender
335 {
336     /* show panel */
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;
345
346     [panel runModalForWindow:o_window];
347 }
348
349 #pragma mark -
350 #pragma mark Equalizer
351 static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
352                              char *psz_name)
353 {
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));
358
359     psz_string = config_GetPsz(p_custom_intf, "audio-filter");
360
361     if (!psz_string)
362         psz_string = var_GetNonEmptyString(p_object, "audio-filter");
363
364     vlc_object_release(p_object);
365
366     if (!psz_string)
367         return false;
368
369     psz_parser = strstr(psz_string, psz_name);
370
371     free(psz_string);
372
373     if (psz_parser)
374         return true;
375     else
376         return false;
377 }
378
379 - (void)setupEqualizer
380 {
381     vlc_object_t *p_object = VLC_OBJECT(getAout());
382     if (p_object == NULL)
383         p_object = vlc_object_hold(pl_Get(p_intf));
384
385     var_Create(p_object, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
386
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];
394         }];
395     }
396
397     char psz_bands[100];
398     snprintf(psz_bands, sizeof(psz_bands),
399              "%.1f %.1f %.1f %.1f %.1f %.1f %.1f "
400              "%.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]);
411
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);
417
418     [self updatePresetSelector];
419
420     [self equalizerUpdated];
421 }
422
423 - (void)updatePresetSelector
424 {
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:)];
434
435     vlc_object_t *p_object = VLC_OBJECT(getAout());
436     if (p_object == NULL)
437         p_object = vlc_object_hold(pl_Get(p_intf));
438
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];
446         }];
447     }
448
449     [o_eq_presets_popup selectItemAtIndex:currentPresetIndex];
450     [o_eq_preamp_sld setFloatValue:[[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:currentPresetIndex] floatValue]];
451     [self setBandSliderValuesForPreset:currentPresetIndex];
452
453     vlc_object_release(p_object);
454 }
455
456 - (void)equalizerUpdated
457 {
458     float f_preamp, f_band[10];
459     char *psz_bands, *psz_bands_init, *p_next;
460     bool b_2p;
461     bool b_enabled = GetEqualizerStatus(p_intf, (char *)"equalizer");
462     vlc_object_t *p_object = VLC_OBJECT(getAout());
463
464     if (p_object == NULL)
465         p_object = vlc_object_hold(pl_Get(p_intf));
466
467     var_Create(p_object, "equalizer-preamp", VLC_VAR_FLOAT |
468                VLC_VAR_DOINHERIT);
469     var_Create(p_object, "equalizer-bands", VLC_VAR_STRING |
470                VLC_VAR_DOINHERIT);
471
472     psz_bands = var_GetNonEmptyString(p_object, "equalizer-bands");
473
474     if (psz_bands == NULL)
475         psz_bands = strdup("0 0 0 0 0 0 0 0 0 0");
476
477     b_2p = (BOOL)config_GetInt(p_object, "equalizer-2pass");
478     f_preamp = config_GetFloat(p_object, "equalizer-preamp");
479
480     vlc_object_release(p_object);
481
482     /* Setup sliders */
483     [self updatePresetSelector];
484
485     /* Set the the checkboxes */
486     [o_eq_enable_ckb setState: b_enabled];
487     [o_eq_twopass_ckb setState: b_2p];
488 }
489
490 - (id)sliderByIndex:(int)index
491 {
492     switch(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;
504     }
505 }
506
507 - (void)setBandSlidersValues:(float *)values
508 {
509     for (int i = 0 ; i<= 9 ; i++)
510         [self setValue:values[i] forSlider:i];
511 }
512
513 - (void)setBandSliderValuesForPreset:(NSInteger)presetID
514 {
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];
520 }
521
522 - (void)initBandSliders
523 {
524     for (int i = 0 ; i< 9 ; i++)
525         [self setValue:0.0 forSlider:i];
526 }
527
528 - (NSString *)generatePresetString
529 {
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]];
541 }
542
543 - (void)setValue:(float)value forSlider:(int)index
544 {
545     id slider = [self sliderByIndex:index];
546
547     if (slider != nil)
548         [slider setFloatValue:value];
549 }
550
551 - (IBAction)eq_enable:(id)sender
552 {
553     [self setAudioFilter: "equalizer" on:[sender state]];
554 }
555
556 - (IBAction)eq_bandSliderUpdated:(id)sender
557 {
558     vlc_object_t *p_object = VLC_OBJECT(getAout());
559
560     if (p_object == NULL)
561         p_object = vlc_object_hold(pl_Get(p_intf));
562
563     var_SetString(p_object, "equalizer-bands", [[self generatePresetString] UTF8String]);
564
565     /* save changed to config */
566     config_PutPsz(p_intf, "equalizer-bands", [[self generatePresetString] UTF8String]);
567
568     vlc_object_release(p_object);
569 }
570
571 - (IBAction)eq_changePreset:(id)sender
572 {
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];
578
579     NSString *preset = [[defaults objectForKey:@"EQValues"] objectAtIndex:numberOfChosenPreset];
580     NSString *preamp = [[defaults objectForKey:@"EQPreampValues"] objectAtIndex:numberOfChosenPreset];
581
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]);
585
586     [o_eq_preamp_sld setFloatValue: [preamp floatValue]];
587     [self setBandSliderValuesForPreset:numberOfChosenPreset];
588
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]);
593
594     vlc_object_release(p_object);
595 }
596
597 - (IBAction)eq_preampSliderUpdated:(id)sender
598 {
599     float f_preamp = [sender floatValue] ;
600
601     vlc_object_t *p_object = VLC_OBJECT(getAout());
602     if (p_object == NULL)
603         p_object = vlc_object_hold(pl_Get(p_intf));
604
605     var_SetFloat(p_object, "equalizer-preamp", f_preamp);
606
607     /* save changed to config */
608     config_PutFloat(p_intf, "equalizer-preamp", f_preamp);
609
610     vlc_object_release(p_object);
611 }
612 - (IBAction)eq_twopass:(id)sender
613 {
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));
619
620     var_SetBool(p_object, "equalizer-2pass", b_2p);
621
622     /* save changed to config */
623     config_PutInt(p_intf, "equalizer-2pass", (int)b_2p);
624
625     vlc_object_release(p_object);
626 }
627
628 - (IBAction)addPresetAction:(id)sender
629 {
630     /* show panel */
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;
638
639     [panel runModalForWindow:o_window];
640 }
641
642 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
643 {
644     if (value == NSOKButton) {
645         if ([text length] > 0) {
646             NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
647
648             if (!b_genericAudioProfileInInteraction) {
649
650                 NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
651                 [workArray addObject:[self generatePresetString]];
652                 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
653                 [workArray release];
654                 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
655                 [workArray addObject:text];
656                 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
657                 [workArray release];
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"];
661                 [workArray release];
662                 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
663                 [workArray addObject:[text decomposedStringWithCanonicalMapping]];
664                 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
665                 [workArray release];
666                 [defaults synchronize];
667
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));
672
673                 var_SetString(p_object , "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
674                 config_PutPsz(p_object, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
675
676                 vlc_object_release(p_object);
677
678                 /* update UI */
679                 [self updatePresetSelector];
680             } else {
681                 vlc_object_t *p_object = VLC_OBJECT(getAout());
682                 if (p_object == NULL)
683                     p_object = vlc_object_hold(pl_Get(p_intf));
684
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];
691                     }];
692                 }
693                 NSString *newProfile = [NSString stringWithFormat:@"%li;%s;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%lli",
694                                         currentPresetIndex,
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")];
710
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"];
717                 [workArray release];
718                 workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
719                 [workArray addObject:text];
720                 [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
721                 [workArray release];
722
723                 /* save defaults */
724                 [defaults synchronize];
725                 vlc_object_release(p_object);
726             }
727         }
728     }
729
730     [self resetProfileSelector];
731 }
732
733 - (IBAction)deletePresetAction:(id)sender
734 {
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;
743
744     [panel runModalForWindow:o_window];
745 }
746
747 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
748 {
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"];
756             [workArray release];
757             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
758             [workArray removeObjectAtIndex:item];
759             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
760             [workArray release];
761             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
762             [workArray removeObjectAtIndex:item];
763             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
764             [workArray release];
765             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
766             [workArray removeObjectAtIndex:item];
767             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
768             [workArray release];
769             [defaults synchronize];
770
771             /* update UI */
772             [self updatePresetSelector];
773         } else {
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"];
779             [workArray release];
780             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
781             [workArray removeObjectAtIndex:item];
782             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
783             [workArray release];
784
785             /* save defaults */
786             [defaults synchronize];
787             [self resetProfileSelector];
788         }
789     }
790 }
791
792 #pragma mark -
793 #pragma mark Compressor
794 - (void)resetCompressor
795 {
796     char * psz_afilters;
797     psz_afilters = config_GetPsz(p_intf, "audio-filter");
798     if (psz_afilters) {
799         [o_comp_enable_ckb setState: (NSInteger)strstr(psz_afilters, "compressor") ];
800         free(psz_afilters);
801     }
802     else
803         [o_comp_enable_ckb setState: NSOffState];
804
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]]];
819 }
820
821 - (IBAction)resetCompressorValues:(id)sender
822 {
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);
830
831     audio_output_t * p_aout = getAout();
832     if (p_aout) {
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);
841     }
842     [self resetCompressor];
843 }
844
845 - (IBAction)comp_enable:(id)sender
846 {
847     [self setAudioFilter:"compressor" on:[sender state]];
848 }
849
850 - (IBAction)comp_sliderUpdated:(id)sender
851 {
852     audio_output_t * p_aout = getAout();
853     char * value;
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";
868
869     if (p_aout) {
870         var_SetFloat(p_aout, value, [sender floatValue]);
871         vlc_object_release(p_aout);
872     }
873     config_PutFloat(p_intf, value, [sender floatValue]);
874
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]]];
889 }
890
891 #pragma mark -
892 #pragma mark Spatializer
893 - (void)resetSpatializer
894 {
895     char * psz_afilters;
896     psz_afilters = config_GetPsz(p_intf, "audio-filter");
897     if (psz_afilters) {
898         [o_spat_enable_ckb setState: (NSInteger)strstr(psz_afilters, "spatializer") ];
899         free(psz_afilters);
900     }
901     else
902         [o_spat_enable_ckb setState: NSOffState];
903
904 #define setSlider(bandsld, bandfld, var) \
905     [bandsld setFloatValue: config_GetFloat(p_intf, var) * 10.]; \
906     [bandfld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [bandsld floatValue]]]
907
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");
913
914 #undef setSlider
915 }
916
917 - (IBAction)resetSpatializerValues:(id)sender
918 {
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);
924
925     audio_output_t * p_aout = getAout();
926     if (p_aout) {
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);
933     }
934     [self resetSpatializer];
935 }
936
937 - (IBAction)spat_enable:(id)sender
938 {
939     [self setAudioFilter:"spatializer" on:[sender state]];
940 }
941
942 - (IBAction)spat_sliderUpdated:(id)sender
943 {
944     audio_output_t * p_aout = getAout();
945     char * value;
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";
956
957     if (p_aout) {
958         var_SetFloat(p_aout, value, [sender floatValue] / 10.);
959         vlc_object_release(p_aout);
960     }
961     config_PutFloat(p_intf, value, [sender floatValue] / 10.);
962
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]]];
973 }
974
975 #pragma mark -
976 #pragma mark Filter
977 - (void)resetAudioFilters
978 {
979     char * psz_afilters;
980     psz_afilters = config_GetPsz(p_intf, "audio-filter");
981     if (psz_afilters) {
982         [o_filter_headPhone_ckb setState: (NSInteger)strstr(psz_afilters, "headphone") ];
983         [o_filter_normLevel_ckb setState: (NSInteger)strstr(psz_afilters, "normvol") ];
984         free(psz_afilters);
985     } else {
986         [o_filter_headPhone_ckb setState: NSOffState];
987         [o_filter_normLevel_ckb setState: NSOffState];
988     }
989     [o_filter_normLevel_sld setFloatValue: config_GetFloat(p_intf, "norm-max-level")];
990 }
991
992 - (IBAction)filter_enableHeadPhoneVirt:(id)sender
993 {
994     [self setAudioFilter: "headphone" on:[sender state]];
995 }
996
997 - (IBAction)filter_enableVolumeNorm:(id)sender
998 {
999     [self setAudioFilter: "normvol" on:[sender state]];
1000 }
1001
1002 - (IBAction)filter_volNormSliderUpdated:(id)sender
1003 {
1004     audio_output_t * p_aout= getAout();
1005
1006     if (p_aout) {
1007         var_SetFloat(p_aout, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1008         vlc_object_release(p_aout);
1009     }
1010
1011     config_PutFloat(p_intf, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1012 }
1013
1014 @end