]> git.sesse.net Git - vlc/blob - modules/gui/macosx/extended.m
* Add an controls to the vout (using the embedded vout framework)
[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)collapsAll
170 {
171     /* collaps all views so Cocoa saves the window position correctly */
172     if( o_adjImg_expanded )
173     {
174         [self extWin_exp_adjImg: nil];
175     }
176     if( o_audFlts_expanded )
177     {
178         [self extWin_exp_audFlts: nil];
179     }
180     if( o_vidFlts_expanded )
181     {
182         [self extWin_exp_vidFlts: nil];
183     }
184 }
185
186 - (BOOL)getConfigChanged
187 {
188     return o_config_changed;
189 }
190
191 - (void)showPanel
192 {
193     /* get the correct slider values from the prefs, in case they were changed
194      * elsewhere */
195     intf_thread_t * p_intf = VLCIntf;
196
197     int i_value = config_GetInt( p_intf, "hue" );
198     if( i_value > 0 && i_value < 360 )
199     {
200         [o_sld_hue setIntValue: i_value];
201     }
202
203     float f_value;
204     
205     f_value = config_GetFloat( p_intf, "saturation" );
206     if( f_value > 0 && f_value < 5 )
207     {
208         [o_sld_saturation setIntValue: (int)(100 * f_value) ];
209     }
210
211     f_value = config_GetFloat( p_intf, "contrast" );
212     if( f_value > 0 && f_value < 4 )
213     {
214         [o_sld_contrast setIntValue: (int)(100 * f_value) ];
215     }
216
217     f_value = config_GetFloat( p_intf, "brightness" );
218     if( f_value > 0 && f_value < 2 )
219     {
220         [o_sld_brightness setIntValue: (int)(100 * f_value) ];
221     }
222
223     f_value = config_GetFloat( p_intf, "gamma" );
224     if( f_value > 0 && f_value < 10 )
225     {
226         [o_sld_gamma setIntValue: (int)(10 * f_value) ];
227     }
228
229     f_value = config_GetFloat( p_intf, "norm-max-level" );
230     if( f_value > 0 && f_value < 10 )
231     {
232         [o_sld_maxLevel setFloatValue: f_value ];
233     }
234
235     [o_sld_opaque setFloatValue: (config_GetFloat( p_intf, \
236         "macosx-opaqueness") * 100)];
237
238
239     /* show the window */
240     [o_extended_window displayIfNeeded];
241     [o_extended_window makeKeyAndOrderFront:nil];
242 }
243
244 - (IBAction)adjImg_Enbl:(id)sender
245 {
246     /* en-/disable the sliders */
247     if ([o_ckb_enblAdjustImg state] == NSOnState)
248     {
249         [o_btn_rstrDefaults setEnabled: YES];
250         [o_sld_brightness setEnabled: YES];
251         [o_sld_contrast setEnabled: YES];
252         [o_sld_gamma setEnabled: YES];
253         [o_sld_hue setEnabled: YES];
254         [o_sld_saturation setEnabled: YES];
255         [self changeVFiltersString: "adjust" onOrOff: VLC_TRUE];
256     }else{
257         [o_btn_rstrDefaults setEnabled: NO];
258         [o_sld_brightness setEnabled: NO];
259         [o_sld_contrast setEnabled: NO];
260         [o_sld_gamma setEnabled: NO];
261         [o_sld_hue setEnabled: NO];
262         [o_sld_saturation setEnabled: NO];
263         [self changeVFiltersString: "adjust" onOrOff: VLC_FALSE];
264     }
265 }
266
267 - (IBAction)adjImg_rstrDefaults:(id)sender
268 {
269     /* reset the sliders */
270     [o_sld_brightness setIntValue: 100];
271     [o_sld_contrast setIntValue: 100];
272     [o_sld_gamma setIntValue: 10];
273     [o_sld_hue setIntValue: 0];
274     [o_sld_saturation setIntValue: 100];
275     
276     /* transmit the values */
277     [self adjImg_sliders: o_sld_brightness];
278     [self adjImg_sliders: o_sld_contrast];
279     [self adjImg_sliders: o_sld_gamma];
280     [self adjImg_sliders: o_sld_hue];
281     [self adjImg_sliders: o_sld_saturation];
282 }
283
284 - (IBAction)adjImg_sliders:(id)sender
285 {
286     /* read-out the sliders' values and apply them */
287     intf_thread_t * p_intf = VLCIntf;
288     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
289                                  VLC_OBJECT_VOUT, FIND_ANYWHERE);
290     if( p_vout == NULL )
291     {
292         if (sender == o_sld_brightness)
293         {
294             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
295         } else if (sender == o_sld_contrast)
296         {
297             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
298         } else if (sender == o_sld_gamma)
299         {
300             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
301         } else if (sender == o_sld_hue)
302         {
303             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
304         } else if (sender == o_sld_saturation)
305         {
306             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
307         } else {
308             msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
309                 "moved slider");
310         }
311     } else {
312         vlc_value_t val;
313         if (sender == o_sld_brightness)
314         {
315             val.f_float = [o_sld_brightness floatValue] / 100;
316             var_Set( p_vout, "brightness", val );
317             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
318         } else if (sender == o_sld_contrast)
319         {
320             val.f_float = [o_sld_contrast floatValue] / 100;
321             var_Set( p_vout, "contrast", val );
322             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
323         } else if (sender == o_sld_gamma)
324         {
325             val.f_float = [o_sld_gamma floatValue] / 10;
326             var_Set( p_vout, "gamma", val );
327             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
328         } else if (sender == o_sld_hue)
329         {
330             val.i_int = [o_sld_hue intValue];
331             var_Set( p_vout, "hue", val );
332             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
333         } else if (sender == o_sld_saturation)
334         {
335             val.f_float = [o_sld_saturation floatValue] / 100;
336             var_Set( p_vout, "saturation", val );
337             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
338         } else {
339             msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
340                 "moved slider");
341         }
342         vlc_object_release( p_vout );
343     }
344
345     o_config_changed = YES;
346 }
347
348 /* change the opaqueness of the vouts */
349 - (IBAction)adjImg_opaque:(id)sender
350 {
351     vlc_value_t val;
352     id o_window = [NSApp keyWindow];
353     NSArray *o_windows = [NSApp orderedWindows];
354     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
355     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
356         FIND_ANYWHERE );
357     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
358     vout_thread_t *p_real_vout;
359
360     val.f_float = [o_sld_opaque floatValue] / 100;
361
362
363     if( p_vout != NULL )
364     {
365         p_real_vout = [VLCVoutView getRealVout: p_vout];
366         var_Set( p_real_vout, "macosx-opaqueness", val );
367
368         while ((o_window = [o_enumerator nextObject]))
369         {
370             if( [[o_window className] isEqualToString: @"VLCWindow"] ||
371                 [[[VLCMain sharedInstance] getEmbeddedList]
372                                     windowContainsEmbedded: o_window])
373             {
374                 [o_window setAlphaValue: val.f_float];
375             }
376             break;
377         }
378         vlc_object_release( p_vout );
379     }
380     
381     /* store to prefs */
382     config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
383     
384     vlc_object_release( p_playlist );
385
386     o_config_changed = YES;
387 }
388
389 - (IBAction)audFtls_hdphnVirt:(id)sender
390 {
391     /* en-/disable headphone virtualisation */
392     if ([o_ckb_hdphnVirt state] == NSOnState)
393     {
394         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_TRUE ];
395     }else{
396         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_FALSE ];
397     }
398 }
399
400 - (IBAction)audFtls_maxLevelSld:(id)sender
401 {
402     /* read-out the slider's value and apply it */
403     intf_thread_t * p_intf = VLCIntf;
404     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
405                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
406     if( p_aout != NULL )
407     {
408         var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] );
409         vlc_object_release( p_aout );
410     }
411     config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] );
412
413     o_config_changed = YES;
414 }
415
416 - (IBAction)audFtls_vlmeNorm:(id)sender
417 {
418     /* en-/disable volume normalisation */
419     if ([o_ckb_vlme_norm state] == NSOnState)
420     {
421         [self changeAFiltersString: "normvol" onOrOff: YES ];
422     }else{
423         [self changeAFiltersString: "normvol" onOrOff: NO ];
424     }
425 }
426
427 - (IBAction)extWin_exp_adjImg:(id)sender
428 {
429     /* expand or collapse adjImg */
430     NSRect o_win_rect = [o_extended_window frame];
431     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
432     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
433     NSRect o_box_adjImg_rect = [o_box_adjImg frame];
434     
435     if (o_adjImg_expanded)
436     {
437         /* move the window contents upwards (partially done through settings
438          * inside the nib) and resize the window */
439         o_win_rect.size.height = o_win_rect.size.height - 171;
440         o_win_rect.origin.y = [o_extended_window frame].origin.y + 171;
441         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 171;
442         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 171;
443         
444         /* remove the inserted view */
445         [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
446     }else{
447     
448         /* move the window contents downwards and resize the window */
449         o_win_rect.size.height = o_win_rect.size.height + 171;
450         o_win_rect.origin.y = [o_extended_window frame].origin.y - 171;
451         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 171;
452         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 171;
453     }
454     
455     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
456     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
457     [o_extended_window displayIfNeeded];
458     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
459     
460     if (o_adjImg_expanded)
461     {
462         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 171;
463         msg_Dbg( VLCIntf, "collapsed adjust-image section");
464         o_adjImg_expanded = NO;
465     } else {
466         /* insert view */
467         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 171;
468         [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 181)];
469         [o_adjustImg_view setNeedsDisplay:YES];
470         [o_adjustImg_view setAutoresizesSubviews: YES];
471         [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
472         msg_Dbg( VLCIntf, "expanded adjust-image section");
473         o_adjImg_expanded = YES;
474     }
475     [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
476 }
477
478 - (IBAction)extWin_exp_audFlts:(id)sender
479 {
480     /* expand or collapse audFlts */
481     NSRect o_win_rect = [o_extended_window frame];
482     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
483     
484     if (o_audFlts_expanded)
485     {
486         /* move the window contents upwards (partially done through settings
487          * inside the nib) and resize the window */
488         o_win_rect.size.height = o_win_rect.size.height - 66;
489         o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
490         
491         /* remove the inserted view */
492         [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
493     }else{
494         /* move the window contents downwards and resize the window */
495         o_win_rect.size.height = o_win_rect.size.height + 66;
496         o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
497     }
498     [o_extended_window displayIfNeeded];
499     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
500     
501     
502     if (o_audFlts_expanded)
503     {
504         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
505         msg_Dbg( VLCIntf, "collapsed audio-filters section");
506         o_audFlts_expanded = NO;
507     } else {
508         /* insert view */
509         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
510         [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
511         [o_audioFlts_view setNeedsDisplay:YES];
512         [o_audioFlts_view setAutoresizesSubviews: YES];
513         [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
514         msg_Dbg( VLCIntf, "expanded audio-filters section");
515         o_audFlts_expanded = YES;
516     }
517     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
518 }
519
520 - (IBAction)extWin_exp_vidFlts:(id)sender
521 {
522     /* expand or collapse vidFlts */
523     NSRect o_win_rect = [o_extended_window frame];
524     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
525     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
526     
527     if (o_vidFlts_expanded)
528     {
529         /* move the window contents upwards (partially done through settings
530          * inside the nib) and resize the window */
531         o_win_rect.size.height = o_win_rect.size.height - 134;
532         o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
533         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
534         
535         /* remove the inserted view */
536         [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
537     }else{
538     
539         /* move the window contents downwards and resize the window */
540         o_win_rect.size.height = o_win_rect.size.height + 134;
541         o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
542         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
543     }
544     
545     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
546     [o_extended_window displayIfNeeded];
547     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
548     
549     if (o_vidFlts_expanded)
550     {
551         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
552         msg_Dbg( VLCIntf, "collapsed video-filters section");
553         o_vidFlts_expanded = NO;
554     } else {
555         /* insert view */
556         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
557         [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
558         [o_videoFilters_view setNeedsDisplay:YES];
559         [o_videoFilters_view setAutoresizesSubviews: YES];
560         [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
561         msg_Dbg( VLCIntf, "expanded video-filters section");
562         o_vidFlts_expanded = YES;
563     }
564     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
565 }
566
567 - (IBAction)vidFlts:(id)sender
568 {
569     /* en-/disable video filters */
570     if (sender == o_ckb_blur)
571     {
572         [self changeVFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
573     }
574     else if (sender == o_ckb_distortion)
575     {
576         [self changeVFiltersString: "distort" onOrOff: [o_ckb_distortion state]];
577     }
578     else if (sender == o_ckb_imgClone)
579     {
580         [self changeVFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
581     }
582     else if (sender == o_ckb_imgCrop)
583     {
584         [self changeVFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
585     }
586     else if (sender == o_ckb_imgInvers)
587     {
588         [self changeVFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
589     }
590     else if (sender == o_ckb_trnsform)
591     {
592         [self changeVFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
593     } else {
594         /* this shouldn't happen */
595         msg_Warn (VLCIntf, "cannot find selected video-filter");
596     }
597 }
598
599 - (IBAction)vidFlts_mrInfo:(id)sender
600 {
601     /* show info sheet */
602     NSBeginInformationalAlertSheet(_NS("More information"), _NS("OK"), @"", @"", \
603         o_extended_window, nil, nil, nil, nil, _NS("Select the video effects " \
604         "filters to apply. You must restart the stream for these settings to " \
605         "take effect.\nTo configure the filters, go to the Preferences, and " \
606         "go to Modules/Video Filters. You can then configure each filter.\n" \
607         "If you want fine control over the filters ( to choose the order in " \
608         "which they are applied ), you need to enter manually a filters " \
609         "string (Preferences / Video / Filters)."));
610 }
611
612
613 /*****************************************************************************
614  * methods to communicate changes to VLC's core
615  *****************************************************************************/
616
617 - (void)changeVFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add 
618 {
619     /* copied from ../wxwidgets/extrapanel.cpp
620      * renamed to conform with Cocoa's rules */
621      
622     vout_thread_t *p_vout;
623     intf_thread_t * p_intf = VLCIntf;
624     
625     char *psz_parser, *psz_string;
626     psz_string = config_GetPsz( p_intf, "vout-filter" );
627     
628     if( !psz_string ) psz_string = strdup("");
629
630     psz_parser = strstr( psz_string, psz_name );
631
632     if( b_add )
633     {
634         if( !psz_parser )
635         {
636             psz_parser = psz_string;
637             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
638                             psz_string, psz_name );
639             free( psz_parser );
640         }
641         else
642         {
643             return;
644         }
645     }
646     else
647     {
648         if( psz_parser )
649         {
650             memmove( psz_parser, psz_parser + strlen(psz_name) +
651                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
652                             strlen(psz_parser + strlen(psz_name)) + 1 );
653
654             /* Remove trailing : : */
655             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
656             {
657                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
658             }
659          }
660          else
661          {
662              free( psz_string );
663              return;
664          }
665     }
666     /* Vout is not kept, so put that in the config */
667     config_PutPsz( p_intf, "vout-filter", psz_string );
668
669     /* Try to set on the fly */
670     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
671                                               FIND_ANYWHERE );
672     if( p_vout )
673     {
674         var_SetString( p_vout, "vout-filter", psz_string );
675         vlc_object_release( p_vout );
676     }
677
678     free( psz_string );
679
680     o_config_changed = YES;
681 }
682
683
684 - (void)changeAFiltersString: (char *)psz_name onOrOff: (vlc_bool_t )b_add;
685 {
686     /* copied from ../wxwidgets/extrapanel.cpp
687      * renamed to conform with Cocoa's rules */
688
689     char *psz_parser, *psz_string;
690     intf_thread_t * p_intf = VLCIntf;
691     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
692                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
693
694     if( p_aout )
695     {
696         psz_string = var_GetString( p_aout, "audio-filter" );
697     }
698     else
699     {
700         psz_string = config_GetPsz( p_intf, "audio-filter" );
701     }
702
703     if( !psz_string ) psz_string = strdup("");
704
705     psz_parser = strstr( psz_string, psz_name );
706
707     if( b_add )
708     {
709         if( !psz_parser )
710         {
711             psz_parser = psz_string;
712             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
713                             psz_string, psz_name );
714             free( psz_parser );
715         }
716         else
717         {
718             return;
719         }
720     }
721     else
722     {
723         if( psz_parser )
724         {
725             memmove( psz_parser, psz_parser + strlen(psz_name) +
726                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
727                             strlen(psz_parser + strlen(psz_name)) + 1 );
728
729             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
730             {
731                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
732             }
733          }
734          else
735          {
736              free( psz_string );
737              return;
738          }
739     }
740
741     if( p_aout == NULL )
742     {
743         config_PutPsz( p_intf, "audio-filter", psz_string );
744     }
745     else
746     {
747         var_SetString( p_aout, "audio-filter", psz_string );
748         int i = 0;
749         while( i < p_aout->i_nb_inputs )
750         {
751             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
752             i = (i + 1);
753         }
754         vlc_object_release( p_aout );
755     }
756     free( psz_string );
757
758     o_config_changed = YES;
759 }
760
761 - (void)savePrefs
762 {    
763     /* save the preferences to make sure that our module-changes will up on
764      * next launch again */
765     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
766         FIND_ANYWHERE );
767     int returnedValue;
768     NSArray * theModules;
769     theModules = [[NSArray alloc] initWithObjects: @"main", @"headphone", \
770         @"transform", @"adjust", @"invert", @"motionblur", @"distort", \
771         @"clone", @"crop", @"normvol", @"headphone_channel_mixer", @"macosx", \
772         nil];
773     unsigned int x = 0;
774     
775     while ( x != [theModules count] )
776     {
777         returnedValue = config_SaveConfigFile( p_playlist, [[theModules \
778             objectAtIndex: x] UTF8String] );
779
780         if (returnedValue != 0)
781         {
782             msg_Err(p_playlist, "VLCExtended: error while saving the " \
783             "preferences of '%s' (%i)", [[theModules objectAtIndex: x] \
784             UTF8String] , returnedValue);
785             
786             [theModules release];
787             vlc_object_release( p_playlist );
788             
789             return;
790         }
791
792         x = ( x + 1 );
793     }
794     
795     msg_Dbg( p_playlist, "VLCExtended: saved certain preferences successfully" );
796     
797     [theModules release];
798     vlc_object_release( p_playlist );
799 }
800 @end