]> git.sesse.net Git - vlc/blob - modules/gui/macosx/extended.m
* updated all files to yield the playlist instead of finding it
[vlc] / modules / gui / macosx / extended.m
1 /*****************************************************************************
2  * extended.m: MacOS X Extended interface panel
3  *****************************************************************************
4  * Copyright (C) 2005-2006 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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("Image adjustment")];
85     [o_btn_vidFlts_mrInfo setTitle: _NS("More Info")];
86     [o_ckb_wave setTitle: _NS("Wave")];
87     [o_ckb_ripple setTitle: _NS("Ripple")];
88     [o_ckb_psycho setTitle: _NS("Psychedelic")];
89     [o_ckb_gradient setTitle: _NS("Gradient")];
90     [o_lbl_general setStringValue: _NS("General editing filters")];
91     [o_lbl_distort setStringValue: _NS("Distortion filters")];
92     [o_ckb_blur setTitle: _NS("Blur")];
93     [o_ckb_blur setToolTip: _NS("Adds motion blurring to the image")];
94     [o_ckb_imgClone setTitle: _NS("Image clone")];
95     [o_ckb_imgClone setToolTip: _NS("Creates several copies of the Video "
96                                     "output window" )];
97     [o_ckb_imgCrop setTitle: _NS("Image cropping")];
98     [o_ckb_imgCrop setToolTip: _NS("Crops a defined part of the image")];
99     [o_ckb_imgInvers setTitle: _NS("Invert colors")];
100     [o_ckb_imgInvers setToolTip: _NS("Inverts the colors of the image")];
101     [o_ckb_trnsform setTitle: _NS("Transformation")];
102     [o_ckb_trnsform setToolTip: _NS("Rotates or flips the image")];
103     [o_ckb_intZoom setTitle: _NS("Interactive Zoom")];
104     [o_ckb_intZoom setToolTip: _NS("Enables an interactive Zoom feature")];
105     [o_ckb_vlme_norm setTitle: _NS("Volume normalization")];
106     [o_ckb_vlme_norm setToolTip: _NS("Prevents the audio output from going "
107         "over a predefined value.")];
108     [o_ckb_hdphnVirt setTitle: _NS("Headphone virtualization")];
109     [o_ckb_hdphnVirt setToolTip: _NS("Imitates the effect of surround sound "
110         "when using headphones.")];
111     [o_lbl_maxLevel setStringValue: _NS("Maximum level")];
112     [o_btn_rstrDefaults setTitle: _NS("Restore Defaults")];
113     [o_ckb_enblAdjustImg setTitle: _NS("Enable")];
114     [o_lbl_brightness setStringValue: _NS("Brightness")];
115     [o_lbl_contrast setStringValue: _NS("Contrast")];
116     [o_lbl_gamma setStringValue: _NS("Gamma")];
117     [o_lbl_hue setStringValue: _NS("Hue")];
118     [o_lbl_saturation setStringValue: _NS("Saturation")];
119     [o_lbl_opaque setStringValue: _NS("Opaqueness")];
120     
121 }
122
123 - (void)awakeFromNib
124 {
125     /* set the adjust-filter-sliders to the values from the prefs and enable
126      * them, if wanted */
127     char * psz_vfilters;
128     intf_thread_t * p_intf = VLCIntf;
129     psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
130     if( psz_vfilters && strstr( psz_vfilters, "adjust" ) )
131     {
132         [o_ckb_enblAdjustImg setState: NSOnState];
133         [o_btn_rstrDefaults setEnabled: YES];
134         [o_sld_brightness setEnabled: YES];
135         [o_sld_contrast setEnabled: YES];
136         [o_sld_gamma setEnabled: YES];
137         [o_sld_hue setEnabled: YES];
138         [o_sld_saturation setEnabled: YES];
139     }
140     else
141     {
142         [o_ckb_enblAdjustImg setState: NSOffState];
143         [o_btn_rstrDefaults setEnabled: NO];
144         [o_sld_brightness setEnabled: NO];
145         [o_sld_contrast setEnabled: NO];
146         [o_sld_gamma setEnabled: NO];
147         [o_sld_hue setEnabled: NO];
148         [o_sld_saturation setEnabled: NO];
149     }
150     
151     /* set the other video-filter-checkboxes to the correct values */
152     if( psz_vfilters )
153     {
154         [o_ckb_blur setState: (int)strstr( psz_vfilters, "motionblur")];
155         [o_ckb_imgClone setState: (int)strstr( psz_vfilters, "clone")];
156         [o_ckb_imgCrop setState: (int)strstr( psz_vfilters, "crop")];
157         [o_ckb_trnsform setState: (int)strstr( psz_vfilters, "transform")];
158
159         free( psz_vfilters );
160     }
161     
162     /* set the video-filter checkboxes to the correct values */
163     char * psz_vifilters;
164     psz_vifilters = config_GetPsz( p_intf, "video-filter" );
165     if( psz_vifilters )
166     {
167         [o_ckb_wave setState: (int)strstr( psz_vifilters, "wave")];
168         [o_ckb_psycho setState: (int)strstr( psz_vifilters, "psychedelic")];
169         [o_ckb_ripple setState: (int)strstr( psz_vifilters, "ripple")];
170         [o_ckb_gradient setState: (int)strstr( psz_vifilters, "gradient")];
171         [o_ckb_imgInvers setState: (int)strstr( psz_vifilters, "invert")];
172
173         free( psz_vifilters );
174     }
175     
176     /* set the audio-filter-checkboxes to the values taken from the prefs */
177     char * psz_afilters;
178     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
179     if( psz_afilters )
180     {
181         [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
182         [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
183         
184         free( psz_afilters );
185     }
186 }
187
188 - (void)collapsAll
189 {
190     /* collaps all views so Cocoa saves the window position correctly */
191     if( o_adjImg_expanded )
192     {
193         [self extWin_exp_adjImg: nil];
194     }
195     if( o_audFlts_expanded )
196     {
197         [self extWin_exp_audFlts: nil];
198     }
199     if( o_vidFlts_expanded )
200     {
201         [self extWin_exp_vidFlts: nil];
202     }
203 }
204
205 - (BOOL)getConfigChanged
206 {
207     return o_config_changed;
208 }
209
210 - (void)showPanel
211 {
212     /* get the correct slider values from the prefs, in case they were changed
213      * elsewhere */
214     intf_thread_t * p_intf = VLCIntf;
215
216     int i_value = config_GetInt( p_intf, "hue" );
217     if( i_value > 0 && i_value < 360 )
218     {
219         [o_sld_hue setIntValue: i_value];
220     }
221
222     float f_value;
223     
224     f_value = config_GetFloat( p_intf, "saturation" );
225     if( f_value > 0 && f_value < 5 )
226     {
227         [o_sld_saturation setIntValue: (int)(100 * f_value) ];
228     }
229
230     f_value = config_GetFloat( p_intf, "contrast" );
231     if( f_value > 0 && f_value < 4 )
232     {
233         [o_sld_contrast setIntValue: (int)(100 * f_value) ];
234     }
235
236     f_value = config_GetFloat( p_intf, "brightness" );
237     if( f_value > 0 && f_value < 2 )
238     {
239         [o_sld_brightness setIntValue: (int)(100 * f_value) ];
240     }
241
242     f_value = config_GetFloat( p_intf, "gamma" );
243     if( f_value > 0 && f_value < 10 )
244     {
245         [o_sld_gamma setIntValue: (int)(10 * f_value) ];
246     }
247
248     f_value = config_GetFloat( p_intf, "norm-max-level" );
249     if( f_value > 0 && f_value < 10 )
250     {
251         [o_sld_maxLevel setFloatValue: f_value ];
252     }
253
254     [o_sld_opaque setFloatValue: (config_GetFloat( p_intf,
255         "macosx-opaqueness") * 100)];
256
257
258     /* show the window */
259     [o_extended_window displayIfNeeded];
260     [o_extended_window makeKeyAndOrderFront:nil];
261 }
262
263 - (IBAction)adjImg_Enbl:(id)sender
264 {
265     /* en-/disable the sliders */
266     if ([o_ckb_enblAdjustImg state] == NSOnState)
267     {
268         [o_btn_rstrDefaults setEnabled: YES];
269         [o_sld_brightness setEnabled: YES];
270         [o_sld_contrast setEnabled: YES];
271         [o_sld_gamma setEnabled: YES];
272         [o_sld_hue setEnabled: YES];
273         [o_sld_saturation setEnabled: YES];
274         [self changeVoutFiltersString: "adjust" onOrOff: VLC_TRUE];
275     }else{
276         [o_btn_rstrDefaults setEnabled: NO];
277         [o_sld_brightness setEnabled: NO];
278         [o_sld_contrast setEnabled: NO];
279         [o_sld_gamma setEnabled: NO];
280         [o_sld_hue setEnabled: NO];
281         [o_sld_saturation setEnabled: NO];
282         [self changeVoutFiltersString: "adjust" onOrOff: VLC_FALSE];
283     }
284 }
285
286 - (IBAction)adjImg_rstrDefaults:(id)sender
287 {
288     /* reset the sliders */
289     [o_sld_brightness setIntValue: 100];
290     [o_sld_contrast setIntValue: 100];
291     [o_sld_gamma setIntValue: 10];
292     [o_sld_hue setIntValue: 0];
293     [o_sld_saturation setIntValue: 100];
294     
295     /* transmit the values */
296     [self adjImg_sliders: o_sld_brightness];
297     [self adjImg_sliders: o_sld_contrast];
298     [self adjImg_sliders: o_sld_gamma];
299     [self adjImg_sliders: o_sld_hue];
300     [self adjImg_sliders: o_sld_saturation];
301 }
302
303 - (IBAction)adjImg_sliders:(id)sender
304 {
305     /* read-out the sliders' values and apply them */
306     intf_thread_t * p_intf = VLCIntf;
307     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
308                                  VLC_OBJECT_VOUT, FIND_ANYWHERE);
309     if( p_vout == NULL )
310     {
311         if (sender == o_sld_brightness)
312         {
313             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
314         } else if (sender == o_sld_contrast)
315         {
316             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
317         } else if (sender == o_sld_gamma)
318         {
319             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
320         } else if (sender == o_sld_hue)
321         {
322             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
323         } else if (sender == o_sld_saturation)
324         {
325             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
326         } else {
327             msg_Warn( p_intf, "the corresponding subfilter coundn't be found" );
328         }
329     } else {
330         vlc_value_t val;
331         if (sender == o_sld_brightness)
332         {
333             val.f_float = [o_sld_brightness floatValue] / 100;
334             var_Set( p_vout, "brightness", val );
335             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
336         } else if (sender == o_sld_contrast)
337         {
338             val.f_float = [o_sld_contrast floatValue] / 100;
339             var_Set( p_vout, "contrast", val );
340             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
341         } else if (sender == o_sld_gamma)
342         {
343             val.f_float = [o_sld_gamma floatValue] / 10;
344             var_Set( p_vout, "gamma", val );
345             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
346         } else if (sender == o_sld_hue)
347         {
348             val.i_int = [o_sld_hue intValue];
349             var_Set( p_vout, "hue", val );
350             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
351         } else if (sender == o_sld_saturation)
352         {
353             val.f_float = [o_sld_saturation floatValue] / 100;
354             var_Set( p_vout, "saturation", val );
355             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
356         } else {
357             msg_Warn( p_intf, "the corresponding subfilter coundn't be found" );
358         }
359         vlc_object_release( p_vout );
360     }
361
362     o_config_changed = YES;
363 }
364
365 /* change the opaqueness of the vouts */
366 - (IBAction)adjImg_opaque:(id)sender
367 {
368     vlc_value_t val;
369     id o_window = [NSApp keyWindow];
370     NSArray *o_windows = [NSApp orderedWindows];
371     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
372     playlist_t * p_playlist = pl_Yield( VLCIntf );
373     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
374     vout_thread_t *p_real_vout;
375
376     val.f_float = [o_sld_opaque floatValue] / 100;
377
378
379     if( p_vout != NULL )
380     {
381         p_real_vout = [VLCVoutView getRealVout: p_vout];
382         var_Set( p_real_vout, "macosx-opaqueness", val );
383
384         while ((o_window = [o_enumerator nextObject]))
385         {
386             if( [[o_window className] isEqualToString: @"VLCWindow"] ||
387                 [[[VLCMain sharedInstance] getEmbeddedList]
388                                     windowContainsEmbedded: o_window])
389             {
390                 [o_window setAlphaValue: val.f_float];
391             }
392             break;
393         }
394         vlc_object_release( p_vout );
395     }
396     
397     /* store to prefs */
398     config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
399     
400     vlc_object_release( p_playlist );
401
402     o_config_changed = YES;
403 }
404
405 - (IBAction)audFtls_hdphnVirt:(id)sender
406 {
407     /* en-/disable headphone virtualisation */
408     if ([o_ckb_hdphnVirt state] == NSOnState)
409     {
410         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_TRUE ];
411     }else{
412         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_FALSE ];
413     }
414 }
415
416 - (IBAction)audFtls_maxLevelSld:(id)sender
417 {
418     /* read-out the slider's value and apply it */
419     intf_thread_t * p_intf = VLCIntf;
420     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
421                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
422     if( p_aout != NULL )
423     {
424         var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] );
425         vlc_object_release( p_aout );
426     }
427     config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] );
428
429     o_config_changed = YES;
430 }
431
432 - (IBAction)audFtls_vlmeNorm:(id)sender
433 {
434     /* en-/disable volume normalisation */
435     if ([o_ckb_vlme_norm state] == NSOnState)
436     {
437         [self changeAFiltersString: "normvol" onOrOff: YES ];
438     }else{
439         [self changeAFiltersString: "normvol" onOrOff: NO ];
440     }
441 }
442
443 - (IBAction)extWin_exp_adjImg:(id)sender
444 {
445     /* expand or collapse adjImg */
446     NSRect o_win_rect = [o_extended_window frame];
447     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
448     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
449     NSRect o_box_adjImg_rect = [o_box_adjImg frame];
450     
451     if (o_adjImg_expanded)
452     {
453         /* move the window contents upwards (partially done through settings
454          * inside the nib) and resize the window */
455         o_win_rect.size.height = o_win_rect.size.height - 193;
456         o_win_rect.origin.y = [o_extended_window frame].origin.y + 193;
457         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 193;
458         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 193;
459         
460         /* remove the inserted view */
461         [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
462     }else{
463     
464         /* move the window contents downwards and resize the window */
465         o_win_rect.size.height = o_win_rect.size.height + 193;
466         o_win_rect.origin.y = [o_extended_window frame].origin.y - 193;
467         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 193;
468         o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 193;
469     }
470     
471     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
472     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
473     [o_extended_window displayIfNeeded];
474     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
475     
476     if (o_adjImg_expanded)
477     {
478         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 193;
479         o_adjImg_expanded = NO;
480     } else {
481         /* insert view */
482         o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 193;
483         [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 203)];
484         [o_adjustImg_view setNeedsDisplay:YES];
485         [o_adjustImg_view setAutoresizesSubviews: YES];
486         [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
487         o_adjImg_expanded = YES;
488     }
489     [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
490 }
491
492 - (IBAction)extWin_exp_audFlts:(id)sender
493 {
494     /* expand or collapse audFlts */
495     NSRect o_win_rect = [o_extended_window frame];
496     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
497     
498     if (o_audFlts_expanded)
499     {
500         /* move the window contents upwards (partially done through settings
501          * inside the nib) and resize the window */
502         o_win_rect.size.height = o_win_rect.size.height - 66;
503         o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
504         
505         /* remove the inserted view */
506         [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
507     }else{
508         /* move the window contents downwards and resize the window */
509         o_win_rect.size.height = o_win_rect.size.height + 66;
510         o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
511     }
512     [o_extended_window displayIfNeeded];
513     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
514     
515     
516     if (o_audFlts_expanded)
517     {
518         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
519         o_audFlts_expanded = NO;
520     } else {
521         /* insert view */
522         o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
523         [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
524         [o_audioFlts_view setNeedsDisplay:YES];
525         [o_audioFlts_view setAutoresizesSubviews: YES];
526         [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
527         o_audFlts_expanded = YES;
528     }
529     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
530 }
531
532 - (IBAction)extWin_exp_vidFlts:(id)sender
533 {
534     /* expand or collapse vidFlts */
535     NSRect o_win_rect = [o_extended_window frame];
536     NSRect o_box_audFlts_rect = [o_box_audFlts frame];
537     NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
538     
539     if (o_vidFlts_expanded)
540     {
541         /* move the window contents upwards (partially done through settings
542          * inside the nib) and resize the window */
543         o_win_rect.size.height = o_win_rect.size.height - 188;
544         o_win_rect.origin.y = [o_extended_window frame].origin.y + 188;
545         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 188;
546         
547         /* remove the inserted view */
548         [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
549     }else{
550     
551         /* move the window contents downwards and resize the window */
552         o_win_rect.size.height = o_win_rect.size.height + 188;
553         o_win_rect.origin.y = [o_extended_window frame].origin.y - 188;
554         o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 188;
555     }
556     
557     [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
558     [o_extended_window displayIfNeeded];
559     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
560     
561     if (o_vidFlts_expanded)
562     {
563         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 188;
564         o_vidFlts_expanded = NO;
565     } else {
566         /* insert view */
567         o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 188;
568         [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 188)];
569         [o_videoFilters_view setNeedsDisplay:YES];
570         [o_videoFilters_view setAutoresizesSubviews: YES];
571         [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
572         o_vidFlts_expanded = YES;
573     }
574     [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
575 }
576
577 - (IBAction)vidFlts:(id)sender
578 {
579     /* en-/disable video filters */
580     if (sender == o_ckb_blur)
581         [self changeVoutFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
582
583     else if (sender == o_ckb_imgClone)
584         [self changeVoutFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
585
586     else if (sender == o_ckb_imgCrop)
587         [self changeVoutFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
588
589     else if (sender == o_ckb_imgInvers)
590         [self changeVideoFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
591
592     else if (sender == o_ckb_trnsform)
593         [self changeVoutFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
594
595     else if (sender == o_ckb_intZoom )
596         [self changeVoutFiltersString: "magnify" onOrOff: [o_ckb_intZoom state]];
597
598     else if (sender == o_ckb_wave )
599         [self changeVideoFiltersString: "wave" onOrOff: [o_ckb_wave state]];
600
601     else if (sender == o_ckb_gradient )
602         [self changeVideoFiltersString: "gradient" onOrOff: [o_ckb_gradient state]];
603
604     else if (sender == o_ckb_psycho )
605         [self changeVideoFiltersString: "psychedelic" onOrOff: [o_ckb_psycho state]];
606
607     else if (sender == o_ckb_ripple )
608         [self changeVideoFiltersString: "ripple" onOrOff: [o_ckb_ripple state]];
609
610     else {
611         /* this shouldn't happen */
612         msg_Warn (VLCIntf, "cannot find switched video-filter");
613     }
614 }
615
616 - (IBAction)vidFlts_mrInfo:(id)sender
617 {
618     /* show info sheet */
619     NSBeginInformationalAlertSheet(_NS("More Information"), _NS("OK"), @"", @"",
620         o_extended_window, nil, nil, nil, nil, _NS("This panel allows to "
621         "select video effects filters to apply.\n"
622         "The filters can be configured individually in the Preferences, in "
623         "the subsections of Video/Filters.\n"
624         "To choose the order in which the filter are applied, a filter "
625         "option string can be set in the Preferences, Video / Filters section."));
626 }
627
628
629 /*****************************************************************************
630  * methods to communicate changes to VLC's core
631  *****************************************************************************/
632
633 - (void)changeVoutFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add 
634 {
635     /* copied from ../wxwidgets/extrapanel.cpp
636      * renamed to conform with Cocoa's rules */
637     /* this method only changes 1st generation video filters (the ones which 
638      * can't be used for transcoding). Have a look at changeVideoFiltersString
639      * for the 2nd generation filters. */
640      
641     vout_thread_t *p_vout;
642     intf_thread_t * p_intf = VLCIntf;
643     
644     char *psz_parser, *psz_string;
645     psz_string = config_GetPsz( p_intf, "vout-filter" );
646     
647     if( !psz_string ) psz_string = strdup("");
648
649     psz_parser = strstr( psz_string, psz_name );
650
651     if( b_add )
652     {
653         if( !psz_parser )
654         {
655             psz_parser = psz_string;
656             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
657                             psz_string, psz_name );
658             free( psz_parser );
659         }
660         else
661         {
662             return;
663         }
664     }
665     else
666     {
667         if( psz_parser )
668         {
669             memmove( psz_parser, psz_parser + strlen(psz_name) +
670                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
671                             strlen(psz_parser + strlen(psz_name)) + 1 );
672
673             /* Remove trailing : : */
674             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
675             {
676                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
677             }
678          }
679          else
680          {
681              free( psz_string );
682              return;
683          }
684     }
685     /* Vout is not kept, so put that in the config */
686     config_PutPsz( p_intf, "vout-filter", psz_string );
687
688     /* Try to set on the fly */
689     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
690                                               FIND_ANYWHERE );
691     if( p_vout )
692     {
693         var_SetString( p_vout, "vout-filter", psz_string );
694         vlc_object_release( p_vout );
695     }
696
697     free( psz_string );
698
699     o_config_changed = YES;
700 }
701
702
703 - (void)changeVideoFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add 
704 {
705     /* same as changeVoutFiltersString but addressing the "video-filter"
706      * variable which represents the video filter 2 modules */
707      
708     vout_thread_t *p_vout;
709     intf_thread_t * p_intf = VLCIntf;
710     
711     char *psz_parser, *psz_string;
712     psz_string = config_GetPsz( p_intf, "video-filter" );
713     
714     if( !psz_string ) psz_string = strdup("");
715
716     psz_parser = strstr( psz_string, psz_name );
717
718     if( b_add )
719     {
720         if( !psz_parser )
721         {
722             psz_parser = psz_string;
723             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
724                             psz_string, psz_name );
725             free( psz_parser );
726         }
727         else
728         {
729             return;
730         }
731     }
732     else
733     {
734         if( psz_parser )
735         {
736             memmove( psz_parser, psz_parser + strlen(psz_name) +
737                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
738                             strlen(psz_parser + strlen(psz_name)) + 1 );
739
740             /* Remove trailing : : */
741             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
742             {
743                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
744             }
745          }
746          else
747          {
748              free( psz_string );
749              return;
750          }
751     }
752     /* Vout is not kept, so put that in the config */
753     config_PutPsz( p_intf, "video-filter", psz_string );
754
755     /* Try to set on the fly */
756     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
757                                               FIND_ANYWHERE );
758     if( p_vout )
759     {
760         var_SetString( p_vout, "video-filter", psz_string );
761         vlc_object_release( p_vout );
762     }
763
764     free( psz_string );
765
766     o_config_changed = YES;
767 }
768
769 - (void)changeAFiltersString: (char *)psz_name onOrOff: (vlc_bool_t )b_add;
770 {
771     /* copied from ../wxwidgets/extrapanel.cpp
772      * renamed to conform with Cocoa's rules */
773
774     char *psz_parser, *psz_string;
775     intf_thread_t * p_intf = VLCIntf;
776     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
777                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
778
779     if( p_aout )
780     {
781         psz_string = var_GetString( p_aout, "audio-filter" );
782     }
783     else
784     {
785         psz_string = config_GetPsz( p_intf, "audio-filter" );
786     }
787
788     if( !psz_string ) psz_string = strdup("");
789
790     psz_parser = strstr( psz_string, psz_name );
791
792     if( b_add )
793     {
794         if( !psz_parser )
795         {
796             psz_parser = psz_string;
797             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
798                             psz_string, psz_name );
799             free( psz_parser );
800         }
801         else
802         {
803             return;
804         }
805     }
806     else
807     {
808         if( psz_parser )
809         {
810             memmove( psz_parser, psz_parser + strlen(psz_name) +
811                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
812                             strlen(psz_parser + strlen(psz_name)) + 1 );
813
814             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
815             {
816                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
817             }
818          }
819          else
820          {
821              free( psz_string );
822              return;
823          }
824     }
825
826     if( p_aout == NULL )
827     {
828         config_PutPsz( p_intf, "audio-filter", psz_string );
829     }
830     else
831     {
832         var_SetString( p_aout, "audio-filter", psz_string );
833         int i = 0;
834         while( i < p_aout->i_nb_inputs )
835         {
836             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
837             i = (i + 1);
838         }
839         vlc_object_release( p_aout );
840     }
841     free( psz_string );
842
843     o_config_changed = YES;
844 }
845
846 - (void)savePrefs
847 {    
848     /* save the preferences to make sure that our module-changes will up on
849      * next launch again */
850     playlist_t * p_playlist = pl_Yield( VLCIntf );
851     int returnedValue;
852     NSArray * theModules;
853     theModules = [[NSArray alloc] initWithObjects: @"main", @"headphone",
854         @"transform", @"adjust", @"invert", @"motionblur", @"distort",
855         @"clone", @"crop", @"normvol", @"headphone_channel_mixer", @"macosx",
856         nil];
857     unsigned int x = 0;
858     
859     while ( x != [theModules count] )
860     {
861         returnedValue = config_SaveConfigFile( p_playlist, [[theModules
862             objectAtIndex: x] UTF8String] );
863
864         if (returnedValue != 0)
865         {
866             msg_Err(p_playlist, "unable to save the preferences of the "
867             "extended control attribute '%s' (%i)", 
868             [[theModules objectAtIndex: x] UTF8String] , returnedValue);
869             [theModules release];
870             vlc_object_release( p_playlist );
871             
872             return;
873         }
874
875         x = ( x + 1 );
876     }
877     
878     msg_Dbg( p_playlist, "VLCExtended: saved certain preferences successfully" );
879     
880     [theModules release];
881     vlc_object_release( p_playlist );
882 }
883 @end