]> git.sesse.net Git - vlc/blob - modules/gui/macosx/AudioEffects.m
macosx: simplify and fix some minor bugs in equalizer code
[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_strings.h>
37
38 #import <math.h>
39
40 @interface VLCAudioEffects (Internal)
41 - (void)resetProfileSelector;
42 - (void)updatePresetSelector;
43 - (void)setBandSliderValuesForPreset:(NSInteger)presetID;
44 @end
45
46 #pragma mark -
47 #pragma mark Initialization
48
49 @implementation VLCAudioEffects
50 static VLCAudioEffects *_o_sharedInstance = nil;
51
52 + (VLCAudioEffects *)sharedInstance
53 {
54     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
55 }
56
57 + (void)initialize{
58     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
59
60     NSString *workString;
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];
65
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]]];
82     }
83
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];
86
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];
89
90     [workValues release];
91     [workPreamp release];
92     [workTitles release];
93     [workNames release];
94 }
95
96 - (id)init
97 {
98     if (_o_sharedInstance)
99         [self dealloc];
100     else {
101         p_intf = VLCIntf;
102         i_old_profile_index = -1;
103         _o_sharedInstance = [super init];
104     }
105
106     return _o_sharedInstance;
107 }
108
109 - (void)awakeFromNib
110 {
111     /* setup the user's language */
112     /* Equalizer */
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")];
116
117     /* Compressor */
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")];
127
128     /* Spatializer */
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")];
136
137     /* Filter */
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")];
142
143     /* generic */
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];
152
153     [self setupEqualizer];
154     [self resetCompressor];
155     [self resetSpatializer];
156     [self resetAudioFilters];
157     [self resetProfileSelector];
158 }
159
160 #pragma mark -
161 #pragma mark internal functions
162
163 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
164 {
165     char *psz_tmp;
166     audio_output_t *p_aout = getAout();
167     if (p_aout)
168         psz_tmp = var_GetNonEmptyString(p_aout, "audio-filter");
169     else
170         psz_tmp = config_GetPsz(p_intf, "audio-filter");
171
172     if (b_on) {
173         if (!psz_tmp)
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);
178         }
179     } else {
180         if (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);
185         }
186     }
187
188     if (p_aout) {
189         playlist_EnableAudioFilter(pl_Get(p_intf), psz_name, b_on);
190         vlc_object_release(p_aout);
191     }
192 }
193
194 - (void)resetProfileSelector
195 {
196     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
197     [o_profile_pop removeAllItems];
198
199     NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
200     [o_profile_pop addItemsWithTitles:profileNames];
201
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:)];
206
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:)];
211     }
212
213     [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
214     [self profileSelectorAction:self];
215 }
216
217 #pragma mark -
218 #pragma mark generic code
219 - (void)updateCocoaWindowLevel:(NSInteger)i_level
220 {
221     if (o_window && [o_window isVisible] && [o_window level] != i_level)
222         [o_window setLevel: i_level];
223 }
224
225 - (IBAction)toggleWindow:(id)sender
226 {
227     if ([o_window isVisible])
228         [o_window orderOut:sender];
229     else {
230         [o_window setLevel: [[[VLCMain sharedInstance] voutController] currentWindowLevel]];
231         [o_window makeKeyAndOrderFront:sender];
232     }
233 }
234
235 - (NSString *)generateProfileString
236 {
237     vlc_object_t *p_object = VLC_OBJECT(getAout());
238     if (p_object == NULL)
239         p_object = vlc_object_hold(pl_Get(p_intf));
240
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")];
258
259     vlc_object_release(p_object);
260     return o_str;
261 }
262
263 - (void)saveCurrentProfile
264 {
265     if (i_old_profile_index == -1)
266         return;
267
268     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
269     /* fetch all the current settings in a uniform string */
270     NSString *newProfile = [self generateProfileString];
271
272     NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
273     if (i_old_profile_index >= [workArray count])
274         return;
275
276     [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile];
277     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
278     [workArray release];
279     [defaults synchronize];
280 }
281
282 - (IBAction)profileSelectorAction:(id)sender
283 {
284     [self saveCurrentProfile];
285     i_old_profile_index = [o_profile_pop indexOfSelectedItem];
286
287     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
288     NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem];
289
290     audio_output_t *p_aout = getAout();
291     playlist_t *p_playlist = pl_Get(p_intf);
292
293     if (p_aout) {
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);
302     }
303
304     /* fetch preset */
305     NSArray *items = [[[defaults objectForKey:@"AudioEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
306
307     /* eq preset */
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);
313
314     /* filter handling */
315     NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])];
316     NSArray *tempArray;
317     NSUInteger count;
318     /* enable the new filters, if we have an aout */
319     if (p_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);
325         }
326     }
327     config_PutPsz(p_intf,"audio-filter",[tempString UTF8String]);
328
329     /* values */
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]);
344
345     /* set values on-the-fly if we have an aout */
346     if (p_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]);
361     }
362
363     /* update UI */
364     if ([tempString rangeOfString:@"equalizer"].location == NSNotFound)
365         [o_eq_enable_ckb setState:NSOffState];
366     else
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];
373
374     /* store current profile selection */
375     [defaults setInteger:selectedProfile forKey:@"AudioEffectSelectedProfile"];
376     [defaults synchronize];
377
378     if (p_aout)
379         vlc_object_release(p_aout);
380 }
381
382 - (IBAction)addAudioEffectsProfile:(id)sender
383 {
384     /* show panel */
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;
392
393     [panel runModalForWindow:o_window];
394 }
395
396 - (IBAction)removeAudioEffectsProfile:(id)sender
397 {
398     /* show panel */
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;
407
408     [panel runModalForWindow:o_window];
409 }
410
411 #pragma mark -
412 #pragma mark Equalizer
413 static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
414                                char *psz_name)
415 {
416     char *psz_parser, *psz_string = NULL;
417     audio_output_t *p_aout = getAout();
418     if (!p_aout)
419         return false;
420
421     psz_string = config_GetPsz(p_custom_intf, "audio-filter");
422
423     if (!psz_string)
424         psz_string = var_GetNonEmptyString(p_aout, "audio-filter");
425
426     vlc_object_release(p_aout);
427
428     if (!psz_string)
429         return false;
430
431     psz_parser = strstr(psz_string, psz_name);
432
433     free(psz_string);
434
435     if (psz_parser)
436         return true;
437     else
438         return false;
439 }
440
441 - (void)setupEqualizer
442 {
443     audio_output_t *p_aout = getAout();
444     if (p_aout) {
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);
449     }
450
451     [self equalizerUpdated];
452 }
453
454 - (void)updatePresetSelector
455 {
456     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
457     NSArray *presets = [defaults objectForKey:@"EQNames"];
458
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:)];
465
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:)];
470     }
471
472     audio_output_t *p_aout = getAout();
473
474     NSString *currentPreset = nil;
475     if (p_aout) {
476         currentPreset = [NSString stringWithFormat:@"%s",var_GetNonEmptyString(p_aout, "equalizer-preset")];
477         vlc_object_release(p_aout);
478     }
479
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];
484         }];
485
486         if (currentPresetIndex == NSNotFound)
487             currentPresetIndex = [presets count] - 1;
488     }    
489
490     [o_eq_presets_popup selectItemAtIndex:currentPresetIndex];
491     [self eq_changePreset: o_eq_presets_popup];
492
493     
494     [o_eq_preamp_sld setFloatValue:[[[defaults objectForKey:@"EQPreampValues"] objectAtIndex:currentPresetIndex] floatValue]];
495     [self setBandSliderValuesForPreset:currentPresetIndex];
496 }
497
498 - (void)equalizerUpdated
499 {
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");
503
504     /* Setup sliders */
505     [self updatePresetSelector];
506
507     /* Set the the checkboxes */
508     [o_eq_enable_ckb setState: b_enabled];
509     [o_eq_twopass_ckb setState: b_2p];
510 }
511
512 - (id)sliderByIndex:(int)index
513 {
514     switch(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;
526     }
527 }
528
529 - (void)setBandSliderValuesForPreset:(NSInteger)presetID
530 {
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];
536 }
537
538 - (NSString *)generatePresetString
539 {
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]];
551 }
552
553 - (void)setValue:(float)value forSlider:(int)index
554 {
555     id slider = [self sliderByIndex:index];
556
557     if (slider != nil)
558         [slider setFloatValue:value];
559 }
560
561 - (IBAction)eq_enable:(id)sender
562 {
563     [self setAudioFilter: "equalizer" on:[sender state]];
564 }
565
566 - (IBAction)eq_bandSliderUpdated:(id)sender
567 {
568     audio_output_t *p_aout = getAout();
569     if (p_aout) {
570         var_SetString(p_aout, "equalizer-bands", [[self generatePresetString] UTF8String]);
571         vlc_object_release(p_aout);
572     }
573
574     /* save changed to config */
575     config_PutPsz(p_intf, "equalizer-bands", [[self generatePresetString] UTF8String]);
576
577 }
578
579 - (IBAction)eq_changePreset:(id)sender
580 {
581     NSInteger numberOfChosenPreset = [sender indexOfSelectedItem];
582     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
583
584     NSString *preset = [[defaults objectForKey:@"EQValues"] objectAtIndex:numberOfChosenPreset];
585     NSString *preamp = [[defaults objectForKey:@"EQPreampValues"] objectAtIndex:numberOfChosenPreset];
586
587     audio_output_t *p_aout = getAout();
588     if (p_aout) {
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);
593     }
594
595     [o_eq_preamp_sld setFloatValue: [preamp floatValue]];
596     [self setBandSliderValuesForPreset:numberOfChosenPreset];
597
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]);
602
603 }
604
605 - (IBAction)eq_preampSliderUpdated:(id)sender
606 {
607     float f_preamp = [sender floatValue] ;
608
609     audio_output_t *p_aout = getAout();
610     if (p_aout) {
611         var_SetFloat(p_aout, "equalizer-preamp", f_preamp);
612         vlc_object_release(p_aout);
613     }
614     
615     /* save changed to config */
616     config_PutFloat(p_intf, "equalizer-preamp", f_preamp);
617
618 }
619 - (IBAction)eq_twopass:(id)sender
620 {
621     bool b_2p = [sender state] ? true : false;
622
623     audio_output_t *p_aout = getAout();
624     if (p_aout) {
625         var_SetBool(p_aout, "equalizer-2pass", b_2p);
626         vlc_object_release(p_aout);
627     }
628
629     /* save changed to config */
630     config_PutInt(p_intf, "equalizer-2pass", (int)b_2p);
631
632 }
633
634 - (IBAction)addPresetAction:(id)sender
635 {
636     /* show panel */
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;
644
645     [panel runModalForWindow:o_window];
646 }
647
648 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
649 {
650
651     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
652
653     // EQ settings
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"];
659             [workArray release];
660             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
661             [workArray addObject:text];
662             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
663             [workArray release];
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"];
667             [workArray release];
668             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
669             [workArray addObject:[text decomposedStringWithCanonicalMapping]];
670             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
671             [workArray release];
672             [defaults synchronize];
673
674             /* update VLC internals */
675             audio_output_t *p_aout = getAout();
676             if (p_aout) {
677                 var_SetString(p_aout, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
678                 vlc_object_release(p_aout);
679             }
680
681             config_PutPsz(p_intf, "equalizer-preset", [[text decomposedStringWithCanonicalMapping] UTF8String]);
682
683
684             /* update UI */
685             [self updatePresetSelector];
686         }
687
688     // profile settings
689     } else {
690
691         if (value != NSOKButton) {
692             [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
693             return;
694         }
695
696         NSArray *profileNames = [defaults objectForKey:@"AudioEffectProfileNames"];
697
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"]];
701
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.")];
706
707             [alert beginSheetModalForWindow:o_window
708                               modalDelegate:nil
709                              didEndSelector:nil
710                                 contextInfo:nil];
711             return;
712         }
713         
714         NSString *newProfile = [self generateProfileString];
715
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"];
722         [workArray release];
723         workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
724         [workArray addObject:text];
725         [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
726         [workArray release];
727
728         /* save defaults */
729         [defaults synchronize];
730         [self resetProfileSelector];
731     }
732 }
733
734 - (IBAction)deletePresetAction:(id)sender
735 {
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;
744
745     [panel runModalForWindow:o_window];
746 }
747
748 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
749 {
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"];
757             [workArray release];
758             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
759             [workArray removeObjectAtIndex:item];
760             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
761             [workArray release];
762             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
763             [workArray removeObjectAtIndex:item];
764             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
765             [workArray release];
766             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
767             [workArray removeObjectAtIndex:item];
768             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
769             [workArray release];
770             [defaults synchronize];
771
772             /* update UI */
773             [self updatePresetSelector];
774         } else {
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"];
780             [workArray release];
781             workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
782             [workArray removeObjectAtIndex:item];
783             [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
784             [workArray release];
785
786             if (i_old_profile_index >= item)
787                 [defaults setInteger:i_old_profile_index - 1 forKey:@"AudioEffectSelectedProfile"];
788
789             /* save defaults */
790             [defaults synchronize];
791             [self resetProfileSelector];
792         }
793     }
794 }
795
796 #pragma mark -
797 #pragma mark Compressor
798 - (void)resetCompressor
799 {
800     char *psz_afilters;
801     psz_afilters = config_GetPsz(p_intf, "audio-filter");
802     if (psz_afilters) {
803         [o_comp_enable_ckb setState: (NSInteger)strstr(psz_afilters, "compressor") ];
804         free(psz_afilters);
805     }
806     else
807         [o_comp_enable_ckb setState: NSOffState];
808
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]]];
823 }
824
825 - (IBAction)resetCompressorValues:(id)sender
826 {
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);
834
835     audio_output_t *p_aout = getAout();
836     if (p_aout) {
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);
845     }
846     [self resetCompressor];
847 }
848
849 - (IBAction)comp_enable:(id)sender
850 {
851     [self setAudioFilter:"compressor" on:[sender state]];
852 }
853
854 - (IBAction)comp_sliderUpdated:(id)sender
855 {
856     audio_output_t *p_aout = getAout();
857     char *value;
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";
872
873     if (p_aout) {
874         var_SetFloat(p_aout, value, [sender floatValue]);
875         vlc_object_release(p_aout);
876     }
877     config_PutFloat(p_intf, value, [sender floatValue]);
878
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]]];
893 }
894
895 #pragma mark -
896 #pragma mark Spatializer
897 - (void)resetSpatializer
898 {
899     char *psz_afilters;
900     psz_afilters = config_GetPsz(p_intf, "audio-filter");
901     if (psz_afilters) {
902         [o_spat_enable_ckb setState: (NSInteger)strstr(psz_afilters, "spatializer") ];
903         free(psz_afilters);
904     }
905     else
906         [o_spat_enable_ckb setState: NSOffState];
907
908 #define setSlider(bandsld, bandfld, var) \
909 [bandsld setFloatValue: config_GetFloat(p_intf, var) * 10.]; \
910 [bandfld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [bandsld floatValue]]]
911
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");
917
918 #undef setSlider
919 }
920
921 - (IBAction)resetSpatializerValues:(id)sender
922 {
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);
928
929     audio_output_t *p_aout = getAout();
930     if (p_aout) {
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);
937     }
938     [self resetSpatializer];
939 }
940
941 - (IBAction)spat_enable:(id)sender
942 {
943     [self setAudioFilter:"spatializer" on:[sender state]];
944 }
945
946 - (IBAction)spat_sliderUpdated:(id)sender
947 {
948     audio_output_t *p_aout = getAout();
949     char *value;
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";
960
961     if (p_aout) {
962         var_SetFloat(p_aout, value, [sender floatValue] / 10.);
963         vlc_object_release(p_aout);
964     }
965     config_PutFloat(p_intf, value, [sender floatValue] / 10.);
966
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]]];
977 }
978
979 #pragma mark -
980 #pragma mark Filter
981 - (void)resetAudioFilters
982 {
983     char *psz_afilters;
984     psz_afilters = config_GetPsz(p_intf, "audio-filter");
985     if (psz_afilters) {
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") ];
989         free(psz_afilters);
990     } else {
991         [o_filter_headPhone_ckb setState: NSOffState];
992         [o_filter_normLevel_ckb setState: NSOffState];
993         [o_filter_karaoke_ckb setState: NSOffState];
994     }
995     [o_filter_normLevel_sld setFloatValue: config_GetFloat(p_intf, "norm-max-level")];
996 }
997
998 - (IBAction)filter_enableHeadPhoneVirt:(id)sender
999 {
1000     [self setAudioFilter: "headphone" on:[sender state]];
1001 }
1002
1003 - (IBAction)filter_enableVolumeNorm:(id)sender
1004 {
1005     [self setAudioFilter: "normvol" on:[sender state]];
1006 }
1007
1008 - (IBAction)filter_volNormSliderUpdated:(id)sender
1009 {
1010     audio_output_t *p_aout = getAout();
1011
1012     if (p_aout) {
1013         var_SetFloat(p_aout, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1014         vlc_object_release(p_aout);
1015     }
1016
1017     config_PutFloat(p_intf, "norm-max-level", [o_filter_normLevel_sld floatValue]);
1018 }
1019
1020 - (IBAction)filter_enableKaraoke:(id)sender
1021 {
1022     [self setAudioFilter: "karaoke" on:[sender state]];
1023 }
1024
1025 @end