]> git.sesse.net Git - vlc/blob - modules/gui/macosx/extended.m
* added the opaqueness-slider to the extended panel (refs #318)
[vlc] / modules / gui / macosx / extended.m
1 /*****************************************************************************
2  * extended.m: MacOS X Extended interface panel
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Felix Kühne <fkuehne@users.sf.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Note: 
27  * the code used to bind with VLC's modules is heavily based upon 
28  * ../wxwidgets/extrapanel.cpp, written by Clément Stenac.
29  * the code used to insert/remove the views was inspired by intf.m, 
30  * written by Derk-Jan Hartman and Benjamin Pracht. 
31  * (all 3 are members of the VideoLAN team) 
32  *****************************************************************************/
33
34
35 /*****************************************************************************
36  * Preamble
37  *****************************************************************************/
38
39 #import "extended.h"
40 #import "intf.h"
41 #import "vout.h"
42 #import <vlc/aout.h>
43 #import <aout_internal.h>
44 #import <vlc/vout.h>
45 #import <vlc/intf.h>
46
47 /*****************************************************************************
48  * VLCExtended implementation
49  *****************************************************************************/
50
51 @implementation VLCExtended
52
53 static VLCExtended *_o_sharedInstance = nil;
54
55 + (VLCExtended *)sharedInstance
56 {
57     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
58 }
59
60 - (id)init
61 {
62     if (_o_sharedInstance) {
63         [self dealloc];
64     } else {
65         _o_sharedInstance = [super init];
66     }
67
68     return _o_sharedInstance;
69 }
70
71 /*****************************************************************************
72  * GUI methods
73  *****************************************************************************/
74
75 - (void)initStrings
76 {
77     /* localise GUI-strings */
78     /* method is called from intf.m (in method showExtended) */
79     [o_extended_window setTitle: _NS("Extended controls")];
80     [o_lbl_video setStringValue: _NS("Video")];
81     [o_lbl_audio setStringValue: _NS("Audio")];
82     [o_lbl_audioFlts setStringValue: _NS("Audio filters")];
83     [o_lbl_videoFlts setStringValue: _NS("Video filters")];
84     [o_lbl_adjustImage setStringValue: _NS("Adjust Image")];
85     [o_btn_vidFlts_mrInfo setTitle: _NS("More Info")];
86     [o_ckb_blur setTitle: _NS("Blurring")];
87     [o_ckb_blur setToolTip: _NS("Creates a motion blurring on the image")];
88     [o_ckb_distortion setTitle: _NS("Distortion")];
89     [o_ckb_distortion setToolTip: _NS("Adds distorsion effects")];
90     [o_ckb_imgClone setTitle: _NS("Image clone")];
91     [o_ckb_imgClone setToolTip: _NS("Creates several clones of the image")];
92     [o_ckb_imgCrop setTitle: _NS("Image cropping")];
93     [o_ckb_imgCrop setToolTip: _NS("Crops the image")];
94     [o_ckb_imgInvers setTitle: _NS("Image inversion")];
95     [o_ckb_imgInvers setToolTip: _NS("Inverts the image colors")];
96     [o_ckb_trnsform setTitle: _NS("Transformation")];
97     [o_ckb_trnsform setToolTip: _NS("Rotates or flips the image")];
98     [o_ckb_vlme_norm setTitle: _NS("Volume normalization")];
99     [o_ckb_vlme_norm setToolTip: _NS("This filters prevents the audio output " \
100         "power from going over a defined value.")];
101     [o_ckb_hdphnVirt setTitle: _NS("Headphone virtualization")];
102     [o_ckb_hdphnVirt setToolTip: _NS("This filter gives the feeling of a " \
103         "5.1 speaker set when using a headphone.")];
104     [o_lbl_maxLevel setStringValue: _NS("Maximum level")];
105     [o_btn_rstrDefaults setTitle: _NS("Restore Defaults")];
106     [o_ckb_enblAdjustImg setTitle: _NS("Enable")];
107     [o_lbl_brightness setStringValue: _NS("Brightness")];
108     [o_lbl_contrast setStringValue: _NS("Contrast")];
109     [o_lbl_gamma setStringValue: _NS("Gamma")];
110     [o_lbl_hue setStringValue: _NS("Hue")];
111     [o_lbl_saturation setStringValue: _NS("Saturation")];
112     [o_lbl_opaque setStringValue: _NS("Opaqueness")];
113     
114 }
115
116 - (void)awakeFromNib
117 {
118     /* set the adjust-filter-sliders to the values from the prefs and enable
119      * them, if wanted */
120     char * psz_vfilters;
121     intf_thread_t * p_intf = VLCIntf;
122     psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
123     if( psz_vfilters && strstr( psz_vfilters, "adjust" ) )
124     {
125         [o_ckb_enblAdjustImg setState: NSOnState];
126         [o_btn_rstrDefaults setEnabled: YES];
127         [o_sld_brightness setEnabled: YES];
128         [o_sld_contrast setEnabled: YES];
129         [o_sld_gamma setEnabled: YES];
130         [o_sld_hue setEnabled: YES];
131         [o_sld_saturation setEnabled: YES];
132     }
133     else
134     {
135         [o_ckb_enblAdjustImg setState: NSOffState];
136         [o_btn_rstrDefaults setEnabled: NO];
137         [o_sld_brightness setEnabled: NO];
138         [o_sld_contrast setEnabled: NO];
139         [o_sld_gamma setEnabled: NO];
140         [o_sld_hue setEnabled: NO];
141         [o_sld_saturation setEnabled: NO];
142     }
143     
144     /* set the other video-filter-checkboxes to the correct values */
145     if( psz_vfilters )
146     {
147         [o_ckb_blur setState: (int)strstr( psz_vfilters, "motionblur")];
148         [o_ckb_distortion setState: (int)strstr( psz_vfilters, "distort")];
149         [o_ckb_imgClone setState: (int)strstr( psz_vfilters, "clone")];
150         [o_ckb_imgCrop setState: (int)strstr( psz_vfilters, "crop")];
151         [o_ckb_imgInvers setState: (int)strstr( psz_vfilters, "invert")];
152         [o_ckb_trnsform setState: (int)strstr( psz_vfilters, "transform")];
153         
154         free( psz_vfilters );
155     }
156     
157     /* set the audio-filter-checkboxes to the values taken from the prefs */
158     char * psz_afilters;
159     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
160     if( psz_afilters )
161     {
162         [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
163         [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
164         
165         free( psz_afilters );
166     }
167 }
168
169 - (void)showPanel
170 {
171     /* get the correct slider values from the prefs, in case they were changed
172      * elsewhere */
173     intf_thread_t * p_intf = VLCIntf;
174
175     int i_value = config_GetInt( p_intf, "hue" );
176     if( i_value > 0 && i_value < 360 )
177     {
178         [o_sld_hue setIntValue: i_value];
179     }
180
181     float f_value;
182     
183     f_value = config_GetFloat( p_intf, "saturation" );
184     if( f_value > 0 && f_value < 5 )
185     {
186         [o_sld_saturation setIntValue: (int)(100 * f_value) ];
187     }
188
189     f_value = config_GetFloat( p_intf, "contrast" );
190     if( f_value > 0 && f_value < 4 )
191     {
192         [o_sld_contrast setIntValue: (int)(100 * f_value) ];
193     }
194
195     f_value = config_GetFloat( p_intf, "brightness" );
196     if( f_value > 0 && f_value < 2 )
197     {
198         [o_sld_brightness setIntValue: (int)(100 * f_value) ];
199     }
200
201     f_value = config_GetFloat( p_intf, "gamma" );
202     if( f_value > 0 && f_value < 10 )
203     {
204         [o_sld_gamma setIntValue: (int)(10 * f_value) ];
205     }
206
207     [o_sld_maxLevel setFloatValue: (config_GetFloat(p_intf, "norm-max-level") \
208         * 10)];
209
210     [o_sld_opaque setFloatValue: (config_GetFloat( p_intf, \
211         "macosx-opaqueness") * 100)];
212
213
214     /* show the window */
215     [o_extended_window displayIfNeeded];
216     [o_extended_window makeKeyAndOrderFront:nil];
217 }
218
219 - (IBAction)adjImg_Enbl:(id)sender
220 {
221     /* en-/disable the sliders */
222     if ([o_ckb_enblAdjustImg state] == NSOnState)
223     {
224         [o_btn_rstrDefaults setEnabled: YES];
225         [o_sld_brightness setEnabled: YES];
226         [o_sld_contrast setEnabled: YES];
227         [o_sld_gamma setEnabled: YES];
228         [o_sld_hue setEnabled: YES];
229         [o_sld_saturation setEnabled: YES];
230         [self changeVFiltersString: "adjust" onOrOff: VLC_TRUE];
231     }else{
232         [o_btn_rstrDefaults setEnabled: NO];
233         [o_sld_brightness setEnabled: NO];
234         [o_sld_contrast setEnabled: NO];
235         [o_sld_gamma setEnabled: NO];
236         [o_sld_hue setEnabled: NO];
237         [o_sld_saturation setEnabled: NO];
238         [self changeVFiltersString: "adjust" onOrOff: VLC_FALSE];
239     }
240 }
241
242 - (IBAction)adjImg_rstrDefaults:(id)sender
243 {
244     /* reset the sliders */
245     [o_sld_brightness setIntValue: 100];
246     [o_sld_contrast setIntValue: 100];
247     [o_sld_gamma setIntValue: 10];
248     [o_sld_hue setIntValue: 0];
249     [o_sld_saturation setIntValue: 100];
250     
251     /* transmit the values */
252     [self adjImg_sliders: o_sld_brightness];
253     [self adjImg_sliders: o_sld_contrast];
254     [self adjImg_sliders: o_sld_gamma];
255     [self adjImg_sliders: o_sld_hue];
256     [self adjImg_sliders: o_sld_saturation];
257 }
258
259 - (IBAction)adjImg_sliders:(id)sender
260 {
261     /* read-out the sliders' values and apply them */
262     intf_thread_t * p_intf = VLCIntf;
263     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
264                                  VLC_OBJECT_VOUT, FIND_ANYWHERE);
265     if( p_vout == NULL )
266     {
267         if (sender == o_sld_brightness)
268         {
269             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
270         } else if (sender == o_sld_contrast)
271         {
272             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
273         } else if (sender == o_sld_gamma)
274         {
275             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
276         } else if (sender == o_sld_hue)
277         {
278             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
279         } else if (sender == o_sld_saturation)
280         {
281             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
282         } else {
283             msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
284                 "moved slider");
285         }
286     } else {
287         vlc_value_t val;
288         if (sender == o_sld_brightness)
289         {
290             val.f_float = [o_sld_brightness floatValue] / 100;
291             var_Set( p_vout, "brightness", val );
292             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
293         } else if (sender == o_sld_contrast)
294         {
295             val.f_float = [o_sld_contrast floatValue] / 100;
296             var_Set( p_vout, "contrast", val );
297             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
298         } else if (sender == o_sld_gamma)
299         {
300             val.f_float = [o_sld_gamma floatValue] / 10;
301             var_Set( p_vout, "gamma", val );
302             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
303         } else if (sender == o_sld_hue)
304         {
305             val.i_int = [o_sld_hue intValue];
306             var_Set( p_vout, "hue", val );
307             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
308         } else if (sender == o_sld_saturation)
309         {
310             val.f_float = [o_sld_saturation floatValue] / 100;
311             var_Set( p_vout, "saturation", val );
312             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
313         } else {
314             msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
315                 "moved slider");
316         }
317         vlc_object_release( p_vout );
318     }
319 }
320
321 - (IBAction)adjImg_opaque:(id)sender
322 {
323     /* change the opaqueness of the vouts */
324     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
325         FIND_ANYWHERE );
326     vout_thread_t * p_vout = (vout_thread_t *)vlc_object_find( p_playlist, \
327         VLC_OBJECT_VOUT, FIND_ANYWHERE );
328     
329     vlc_value_t val;
330     val.f_float = [o_sld_opaque floatValue] / 100;
331
332     /* Try to set on the fly */
333     if( p_vout )
334     {
335         /* FIXME: insert the correct pointer here */
336         /* [p_vout->p_sys->o_window setAlpha: var_CreateGetFloat( p_vout, \
337             "macosx-opaqueness")]; */
338         msg_Dbg( p_playlist, "p_vout found");
339         var_Set( p_vout, "macosx-opaqueness", val );
340         vlc_object_release( p_vout );
341     }
342     
343     /* store to prefs */
344     config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
345     
346     vlc_object_release( p_playlist );
347 }
348
349 - (IBAction)audFtls_hdphnVirt:(id)sender
350 {
351     /* en-/disable headphone virtualisation */
352     if ([o_ckb_hdphnVirt state] == NSOnState)
353     {
354         [self changeAFiltersString: "headphone" onOrOff: VLC_TRUE ];
355     }else{
356         [self changeAFiltersString: "headphone" onOrOff: VLC_FALSE ];
357     }
358 }
359
360 - (IBAction)audFtls_maxLevelSld:(id)sender
361 {
362     /* read-out the slider's value and apply it */
363     intf_thread_t * p_intf = VLCIntf;
364     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
365                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
366     if( p_aout != NULL )
367     {
368         var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] / 10 );
369         vlc_object_release( p_aout );
370     }
371     else
372     {
373         config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] /10 );
374     }
375 }
376
377 - (IBAction)audFtls_vlmeNorm:(id)sender
378 {
379     /* en-/disable volume normalisation */
380     if ([o_ckb_vlme_norm state] == NSOnState)
381     {
382         [self changeAFiltersString: "normvol" onOrOff: YES ];
383     }else{
384         [self changeAFiltersString: "normvol" onOrOff: NO ];
385     }
386 }
387
388 - (IBAction)extWin_exp_adjImg:(id)sender
389 {
390     /* expand or collapse adjImg */
391     NSRect o_win_rect = [o_extended_window frame];
392     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
393     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
394     NSRect o_box_adjImg_rect = [o_box_adjImg frame];
395     
396     if (o_adjImg_expanded)
397     {
398         /* move the window contents upwards (partially done through settings
399          * inside the nib) and resize the window */
400         o_win_rect.size.height = o_win_rect.size.height - 171;
401         o_win_rect.origin.y = [o_extended_window frame].origin.y + 171;
402         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 171;
403         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 171;
404         
405         /* remove the inserted view */
406         [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
407     }else{
408     
409         /* move the window contents downwards and resize the window */
410         o_win_rect.size.height = o_win_rect.size.height + 171;
411         o_win_rect.origin.y = [o_extended_window frame].origin.y - 171;
412         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 171;
413         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 171;
414     }
415     
416     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
417     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
418     [o_extended_window displayIfNeeded];
419     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
420     
421     if (o_adjImg_expanded)
422     {
423         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 171;
424         msg_Dbg( VLCIntf, "collapsed adjust-image section");
425         o_adjImg_expanded = NO;
426     } else {
427         /* insert view */
428         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 171;
429         [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 181)];
430         [o_adjustImg_view setNeedsDisplay:YES];
431         [o_adjustImg_view setAutoresizesSubviews: YES];
432         [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
433         msg_Dbg( VLCIntf, "expanded adjust-image section");
434         o_adjImg_expanded = YES;
435     }
436     [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
437 }
438
439 - (IBAction)extWin_exp_audFlts:(id)sender
440 {
441     /* expand or collapse audFlts */
442     NSRect o_win_rect = [o_extended_window frame];
443     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
444     
445     if (o_audFlts_expanded)
446     {
447         /* move the window contents upwards (partially done through settings
448          * inside the nib) and resize the window */
449         o_win_rect.size.height = o_win_rect.size.height - 66;
450         o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
451         
452         /* remove the inserted view */
453         [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
454     }else{
455         /* move the window contents downwards and resize the window */
456         o_win_rect.size.height = o_win_rect.size.height + 66;
457         o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
458     }
459     [o_extended_window displayIfNeeded];
460     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
461     
462     
463     if (o_audFlts_expanded)
464     {
465         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
466         msg_Dbg( VLCIntf, "collapsed audio-filters section");
467         o_audFlts_expanded = NO;
468     } else {
469         /* insert view */
470         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
471         [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
472         [o_audioFlts_view setNeedsDisplay:YES];
473         [o_audioFlts_view setAutoresizesSubviews: YES];
474         [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
475         msg_Dbg( VLCIntf, "expanded audio-filters section");
476         o_audFlts_expanded = YES;
477     }
478     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
479 }
480
481 - (IBAction)extWin_exp_vidFlts:(id)sender
482 {
483     /* expand or collapse vidFlts */
484     NSRect o_win_rect = [o_extended_window frame];
485     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
486     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
487     
488     if (o_vidFlts_expanded)
489     {
490         /* move the window contents upwards (partially done through settings
491          * inside the nib) and resize the window */
492         o_win_rect.size.height = o_win_rect.size.height - 134;
493         o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
494         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
495         
496         /* remove the inserted view */
497         [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
498     }else{
499     
500         /* move the window contents downwards and resize the window */
501         o_win_rect.size.height = o_win_rect.size.height + 134;
502         o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
503         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
504     }
505     
506     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
507     [o_extended_window displayIfNeeded];
508     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
509     
510     if (o_vidFlts_expanded)
511     {
512         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
513         msg_Dbg( VLCIntf, "collapsed video-filters section");
514         o_vidFlts_expanded = NO;
515     } else {
516         /* insert view */
517         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
518         [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
519         [o_videoFilters_view setNeedsDisplay:YES];
520         [o_videoFilters_view setAutoresizesSubviews: YES];
521         [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
522         msg_Dbg( VLCIntf, "expanded video-filters section");
523         o_vidFlts_expanded = YES;
524     }
525     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
526 }
527
528 - (IBAction)vidFlts:(id)sender
529 {
530     /* en-/disable video filters */
531     if (sender == o_ckb_blur)
532     {
533         [self changeVFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
534     }
535     else if (sender == o_ckb_distortion)
536     {
537         [self changeVFiltersString: "distort" onOrOff: [o_ckb_distortion state]];
538     }
539     else if (sender == o_ckb_imgClone)
540     {
541         [self changeVFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
542     }
543     else if (sender == o_ckb_imgCrop)
544     {
545         [self changeVFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
546     }
547     else if (sender == o_ckb_imgInvers)
548     {
549         [self changeVFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
550     }
551     else if (sender == o_ckb_trnsform)
552     {
553         [self changeVFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
554     } else {
555         /* this shouldn't happen */
556         msg_Warn (VLCIntf, "cannot find selected video-filter");
557     }
558 }
559
560 - (IBAction)vidFlts_mrInfo:(id)sender
561 {
562     /* show info sheet */
563     NSBeginInformationalAlertSheet(_NS("More information"), _NS("OK"), @"", @"", \
564         o_extended_window, nil, nil, nil, nil, _NS("Select the video effects " \
565         "filters to apply. You must restart the stream for these settings to " \
566         "take effect.\nTo configure the filters, go to the Preferences, and " \
567         "go to Modules/Video Filters. You can then configure each filter.\n" \
568         "If you want fine control over the filters ( to choose the order in " \
569         "which they are applied ), you need to enter manually a filters " \
570         "string (Preferences / Video / Filters)."));
571 }
572
573
574 /*****************************************************************************
575  * methods to communicate changes to VLC's core
576  *****************************************************************************/
577
578 - (void)changeVFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add 
579 {
580     /* copied from ../wxwidgets/extrapanel.cpp
581      * renamed to conform with Cocoa's rules */
582      
583     vout_thread_t *p_vout;
584     intf_thread_t * p_intf = VLCIntf;
585     
586     char *psz_parser, *psz_string;
587     psz_string = config_GetPsz( p_intf, "vout-filter" );
588     
589     if( !psz_string ) psz_string = strdup("");
590
591     psz_parser = strstr( psz_string, psz_name );
592
593     if( b_add )
594     {
595         if( !psz_parser )
596         {
597             psz_parser = psz_string;
598             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
599                             psz_string, psz_name );
600             free( psz_parser );
601         }
602         else
603         {
604             return;
605         }
606     }
607     else
608     {
609         if( psz_parser )
610         {
611             memmove( psz_parser, psz_parser + strlen(psz_name) +
612                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
613                             strlen(psz_parser + strlen(psz_name)) + 1 );
614
615             /* Remove trailing : : */
616             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
617             {
618                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
619             }
620          }
621          else
622          {
623              free( psz_string );
624              return;
625          }
626     }
627     /* Vout is not kept, so put that in the config */
628     config_PutPsz( p_intf, "vout-filter", psz_string );
629
630     /* Try to set on the fly */
631     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
632                                               FIND_ANYWHERE );
633     if( p_vout )
634     {
635         var_SetString( p_vout, "vout-filter", psz_string );
636         vlc_object_release( p_vout );
637     }
638
639     free( psz_string );
640     
641     [self savePrefs];
642 }
643
644
645 - (void)changeAFiltersString: (char *)psz_name onOrOff: (vlc_bool_t )b_add;
646 {
647     char *psz_parser, *psz_string;
648     intf_thread_t * p_intf = VLCIntf;
649     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
650                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
651
652     if( p_aout )
653     {
654         psz_string = var_GetString( p_aout, "audio-filter" );
655     }
656     else
657     {
658         psz_string = config_GetPsz( p_intf, "audio-filter" );
659     }
660
661     if( !psz_string ) psz_string = strdup("");
662
663     psz_parser = strstr( psz_string, psz_name );
664
665     if( b_add )
666     {
667         if( !psz_parser )
668         {
669             psz_parser = psz_string;
670             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
671                             psz_string, psz_name );
672             free( psz_parser );
673         }
674         else
675         {
676             return;
677         }
678     }
679     else
680     {
681         if( psz_parser )
682         {
683             memmove( psz_parser, psz_parser + strlen(psz_name) +
684                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
685                             strlen(psz_parser + strlen(psz_name)) + 1 );
686
687             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
688             {
689                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
690             }
691          }
692          else
693          {
694              free( psz_string );
695              return;
696          }
697     }
698
699     if( p_aout == NULL )
700     {
701         config_PutPsz( p_intf, "audio-filter", psz_string );
702     }
703     else
704     {
705         var_SetString( p_aout, "audio-filter", psz_string );
706         int i = 0;
707         while( i < p_aout->i_nb_inputs )
708         {
709             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
710             i = (i + 1);
711         }
712         vlc_object_release( p_aout );
713     }
714     free( psz_string );
715     
716     [self savePrefs];
717 }
718
719 - (void)savePrefs
720 {    
721     /* save the preferences to make sure that our module-changes will up on
722      * next launch again */
723     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
724         FIND_ANYWHERE );
725     int returnedValue;
726     
727     returnedValue = config_SaveConfigFile( p_playlist, NULL);
728     if (returnedValue == 0)
729     {
730         msg_Dbg(p_playlist, "VLCExtended: saved preferences successfully");
731     } else {
732         msg_Dbg(p_playlist, "VLCExtended: error while saving the preferences " \
733             "(%i)" , returnedValue);
734     }
735     vlc_object_release( p_playlist );
736 }
737
738
739 /*****************************************************************************
740  * delegate method
741  *****************************************************************************/
742
743 - (BOOL)applicationShouldTerminate:(NSWindow *)sender
744 {
745     /* save the prefs before shutting down */
746     [self savePrefs];
747     
748     return YES;
749 }
750 @end