]> git.sesse.net Git - vlc/blob - modules/gui/macosx/extended.m
a6cfe513d8dea194f3baf368e58cdf54396a4381
[vlc] / modules / gui / macosx / extended.m
1 /*****************************************************************************
2  * extended.m: MacOS X Extended interface panel
3  *****************************************************************************
4  * Copyright (C) 2005-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne@videolan.org>
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  * Preamble
27  *****************************************************************************/
28
29 #import "extended.h"
30 #import "vout.h"
31 #import <vlc_aout.h>
32 #import <vlc_vout.h>
33 #import <vlc_interface.h>
34
35 /*****************************************************************************
36  * VLCExtended implementation
37  *****************************************************************************/
38
39 @implementation VLCExtended
40
41 static VLCExtended *_o_sharedInstance = nil;
42
43 + (VLCExtended *)sharedInstance
44 {
45     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
46 }
47
48 - (id)init
49 {
50     if (_o_sharedInstance) {
51         [self dealloc];
52     } else {
53         _o_sharedInstance = [super init];
54     }
55
56     return _o_sharedInstance;
57 }
58
59 /*****************************************************************************
60  * GUI methods
61  *****************************************************************************/
62
63 - (void)initStrings
64 {
65     /* localise GUI-strings */
66     /* method is called from intf.m (in method showExtended) */
67     [o_extended_window setTitle: _NS("Extended controls")];
68     [o_btn_vidFlts_mrInfo setToolTip: _NS("Shows more information about the available video filters.")];
69     [o_ckb_wave setTitle: _NS("Wave")];
70     [o_ckb_ripple setTitle: _NS("Ripple")];
71     [o_ckb_psycho setTitle: _NS("Psychedelic")];
72     [o_ckb_gradient setTitle: _NS("Gradient")];
73     [o_lbl_general setStringValue: _NS("General editing filters")];
74     [o_lbl_distort setStringValue: _NS("Distortion filters")];
75     [o_ckb_blur setTitle: _NS("Blur")];
76     [o_ckb_blur setToolTip: _NS("Adds motion blurring to the image")];
77     [o_ckb_imgClone setTitle: _NS("Image clone")];
78     [o_ckb_imgClone setToolTip: _NS("Creates several copies of the Video "
79                                     "output window" )];
80     [o_ckb_imgCrop setTitle: _NS("Image cropping")];
81     [o_ckb_imgCrop setToolTip: _NS("Crops a defined part of the image")];
82     [o_ckb_imgInvers setTitle: _NS("Invert colors")];
83     [o_ckb_imgInvers setToolTip: _NS("Inverts the colors of the image")];
84     [o_ckb_trnsform setTitle: _NS("Transformation")];
85     [o_ckb_trnsform setToolTip: _NS("Rotates or flips the image")];
86     [o_ckb_intZoom setTitle: _NS("Interactive Zoom")];
87     [o_ckb_intZoom setToolTip: _NS("Enables an interactive Zoom feature")];
88     [o_ckb_vlme_norm setTitle: _NS("Volume normalization")];
89     [o_ckb_vlme_norm setToolTip: _NS("Prevents the audio output from going "
90                                      "over a predefined value.")];
91     [o_ckb_hdphnVirt setTitle: _NS("Headphone virtualization")];
92     [o_ckb_hdphnVirt setToolTip: _NS("Imitates the effect of surround sound "
93                                      "when using headphones.")];
94     [o_lbl_maxLevel setStringValue: _NS("Maximum level")];
95     [o_btn_rstrDefaults setTitle: _NS("Restore Defaults")];
96     [o_ckb_enblAdjustImg setTitle: _NS("Enable")];
97     [o_lbl_brightness setStringValue: _NS("Brightness")];
98     [o_lbl_contrast setStringValue: _NS("Contrast")];
99     [o_lbl_gamma setStringValue: _NS("Gamma")];
100     [o_lbl_hue setStringValue: _NS("Hue")];
101     [o_lbl_saturation setStringValue: _NS("Saturation")];
102     [o_lbl_opaque setStringValue: _NS("Opaqueness")];
103  
104 }
105
106 - (void)awakeFromNib
107 {
108     /* set the adjust-filter-sliders to the values from the prefs and enable
109      * them, if wanted */
110     char * psz_vfilters;
111     intf_thread_t * p_intf = VLCIntf;
112     psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
113     /* set the video-filter-checkboxes to the correct values */
114     if( psz_vfilters )
115     {
116         [o_ckb_blur setState: (int)strstr( psz_vfilters, "motionblur")];
117         [o_ckb_imgClone setState: (int)strstr( psz_vfilters, "clone")];
118         [o_ckb_imgCrop setState: (int)strstr( psz_vfilters, "crop")];
119         [o_ckb_trnsform setState: (int)strstr( psz_vfilters, "transform")];
120
121         free( psz_vfilters );
122     }
123  
124     /* set the video-filter checkboxes to the correct values */
125     char * psz_vifilters;
126     psz_vifilters = config_GetPsz( p_intf, "video-filter" );
127     if( psz_vifilters && strstr( psz_vifilters, "adjust" ) )
128     {
129         [o_ckb_enblAdjustImg setState: NSOnState];
130         [o_btn_rstrDefaults setEnabled: YES];
131         [o_sld_brightness setEnabled: YES];
132         [o_sld_contrast setEnabled: YES];
133         [o_sld_gamma setEnabled: YES];
134         [o_sld_hue setEnabled: YES];
135         [o_sld_saturation setEnabled: YES];
136     }
137     else
138     {
139         [o_ckb_enblAdjustImg setState: NSOffState];
140         [o_btn_rstrDefaults setEnabled: NO];
141         [o_sld_brightness setEnabled: NO];
142         [o_sld_contrast setEnabled: NO];
143         [o_sld_gamma setEnabled: NO];
144         [o_sld_hue setEnabled: NO];
145         [o_sld_saturation setEnabled: NO];
146     }
147     if( psz_vifilters )
148     {
149         [o_ckb_wave setState: (int)strstr( psz_vifilters, "wave")];
150         [o_ckb_psycho setState: (int)strstr( psz_vifilters, "psychedelic")];
151         [o_ckb_ripple setState: (int)strstr( psz_vifilters, "ripple")];
152         [o_ckb_gradient setState: (int)strstr( psz_vifilters, "gradient")];
153         [o_ckb_imgInvers setState: (int)strstr( psz_vifilters, "invert")];
154
155         free( psz_vifilters );
156     }
157  
158     /* set the audio-filter-checkboxes to the values taken from the prefs */
159     char * psz_afilters;
160     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
161     if( psz_afilters )
162     {
163         [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
164         [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
165  
166         free( psz_afilters );
167     }
168
169     /* fill the popup button according to our available views */
170     [o_selector_pop removeAllItems];
171     [o_selector_pop addItemWithTitle: _NS("Adjust Image")];
172     [o_selector_pop addItemWithTitle: _NS("Video Filter")];
173     [o_selector_pop addItemWithTitle: _NS("Audio Filter")];
174     [o_selector_pop selectItemAtIndex: 0];
175
176     /* make sure we draw a view on launch */
177     [self viewSelectorAction: self];
178
179     [self initStrings];
180 }
181
182 - (BOOL)getConfigChanged
183 {
184     return o_config_changed;
185 }
186
187 - (void)showPanel
188 {
189     /* get the correct slider values from the prefs, in case they were changed
190      * elsewhere */
191     intf_thread_t * p_intf = VLCIntf;
192
193     int i_value = config_GetInt( p_intf, "hue" );
194     if( i_value > 0 && i_value < 360 )
195     {
196         [o_sld_hue setIntValue: i_value];
197     }
198
199     float f_value;
200  
201     f_value = config_GetFloat( p_intf, "saturation" );
202     if( f_value > 0 && f_value < 5 )
203         [o_sld_saturation setIntValue: (int)(100 * f_value) ];
204
205     f_value = config_GetFloat( p_intf, "contrast" );
206     if( f_value > 0 && f_value < 4 )
207         [o_sld_contrast setIntValue: (int)(100 * f_value) ];
208
209     f_value = config_GetFloat( p_intf, "brightness" );
210     if( f_value > 0 && f_value < 2 )
211         [o_sld_brightness setIntValue: (int)(100 * f_value) ];
212
213     f_value = config_GetFloat( p_intf, "gamma" );
214     if( f_value > 0 && f_value < 10 )
215         [o_sld_gamma setIntValue: (int)(10 * f_value) ];
216
217     f_value = config_GetFloat( p_intf, "norm-max-level" );
218     if( f_value > 0 && f_value < 10 )
219         [o_sld_maxLevel setFloatValue: f_value ];
220
221     [o_sld_opaque setFloatValue: (config_GetFloat( p_intf,
222         "macosx-opaqueness") * 100)];
223
224     /* show the window */
225     [o_extended_window displayIfNeeded];
226     [o_extended_window makeKeyAndOrderFront:nil];
227 }
228
229 - (IBAction)viewSelectorAction:(id)sender
230 {
231     NSView *o_toBeShown_view;
232     /* check which view to show */
233     if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Adjust Image")] )
234         o_toBeShown_view = o_adjustImg_view;
235     else if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Audio Filter")] )
236         o_toBeShown_view = o_audioFlts_view;
237     else if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Video Filter")] )
238         o_toBeShown_view = o_videoFilters_view;
239     else
240         msg_Err( VLCIntf, "invalid ui view requested" );
241     
242     NSRect o_win_rect, o_view_rect, o_old_view_rect;
243     o_win_rect = [o_extended_window frame];
244     o_view_rect = [o_toBeShown_view frame];
245     
246     if( o_currentlyshown_view != nil )
247     {
248         /* restore our window's height, if we've shown another category previously */
249         o_old_view_rect = [o_currentlyshown_view frame];
250         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
251         o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
252         
253         /* remove our previous category view */
254         [o_currentlyshown_view removeFromSuperviewWithoutNeedingDisplay];
255     }
256     
257     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
258     
259     //[o_extended_window displayIfNeeded];
260     [o_extended_window setFrame: o_win_rect display:YES animate: YES];
261     
262     [o_toBeShown_view setFrame: NSMakeRect( 0, 
263                                               0, //[o_top_controls_box frame].size.height, 
264                                               o_view_rect.size.width, 
265                                               o_view_rect.size.height )];
266     [o_toBeShown_view setNeedsDisplay: YES];
267     [o_toBeShown_view setAutoresizesSubviews: YES];
268     [[o_extended_window contentView] addSubview: o_toBeShown_view];
269
270     /* keep our current category for further reference */
271     [o_currentlyshown_view release];
272     o_currentlyshown_view = o_toBeShown_view;
273     [o_currentlyshown_view retain];
274 }
275
276 - (IBAction)enableAdjustImage:(id)sender
277 {
278     /* en-/disable the sliders */
279     if ([o_ckb_enblAdjustImg state] == NSOnState)
280     {
281         [o_btn_rstrDefaults setEnabled: YES];
282         [o_sld_brightness setEnabled: YES];
283         [o_sld_contrast setEnabled: YES];
284         [o_sld_gamma setEnabled: YES];
285         [o_sld_hue setEnabled: YES];
286         [o_sld_saturation setEnabled: YES];
287         [self changeVideoFiltersString: "adjust" onOrOff: true];
288     }
289     else
290     {
291         [o_btn_rstrDefaults setEnabled: NO];
292         [o_sld_brightness setEnabled: NO];
293         [o_sld_contrast setEnabled: NO];
294         [o_sld_gamma setEnabled: NO];
295         [o_sld_hue setEnabled: NO];
296         [o_sld_saturation setEnabled: NO];
297         [self changeVideoFiltersString: "adjust" onOrOff: false];
298     }
299 }
300
301 - (IBAction)restoreDefaultsForAdjustImage:(id)sender
302 {
303     /* reset the sliders */
304     [o_sld_brightness setIntValue: 100];
305     [o_sld_contrast setIntValue: 100];
306     [o_sld_gamma setIntValue: 10];
307     [o_sld_hue setIntValue: 0];
308     [o_sld_saturation setIntValue: 100];
309     [o_sld_opaque setIntValue: 100];
310
311     /* transmit the values */
312     [self sliderActionAdjustImage: o_sld_brightness];
313     [self sliderActionAdjustImage: o_sld_contrast];
314     [self sliderActionAdjustImage: o_sld_gamma];
315     [self sliderActionAdjustImage: o_sld_hue];
316     [self sliderActionAdjustImage: o_sld_saturation];
317     [self opaqueSliderAction: o_sld_opaque];
318 }
319
320 - (IBAction)sliderActionAdjustImage:(id)sender
321 {
322     /* read-out the sliders' values and apply them */
323     intf_thread_t * p_intf = VLCIntf;
324     vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE);
325     vlc_object_t *p_filter;
326
327     if( p_vout == NULL )
328     {
329         msg_Dbg( p_intf, "no vout present, saving settings anyway" );
330         if (sender == o_sld_brightness)
331         {
332             config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
333         } 
334         else if (sender == o_sld_contrast)
335         {
336             config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
337         } 
338         else if (sender == o_sld_gamma)
339         {
340             config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
341         } 
342         else if (sender == o_sld_hue)
343         {
344             config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
345         } 
346         else if (sender == o_sld_saturation)
347         {
348             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
349         } 
350         else
351         {
352             msg_Warn( p_intf, "the corresponding subfilter coundn't be found" );
353         }
354     } 
355     else
356     {
357         msg_Dbg( p_intf, "we found a vout to adjust, let's look for the filter" );
358         p_filter = (vlc_object_t *)vlc_object_find_name( p_intf, "adjust", FIND_ANYWHERE );
359
360         if(! p_filter )
361         {
362             msg_Err( p_intf, "we're unable to find the adjust filter!" );
363             vlc_object_release( p_vout );
364             return;
365         }
366
367         if (sender == o_sld_brightness)
368         {
369             var_SetFloat( p_filter, "brightness", [o_sld_brightness floatValue] / 100 );
370             config_PutFloat( p_intf, "brightness", [o_sld_brightness floatValue] / 100 );
371         } 
372         else if (sender == o_sld_contrast)
373         {
374             var_SetFloat( p_filter, "contrast", [o_sld_contrast floatValue] / 100 );
375             config_PutFloat( p_intf, "contrast", [o_sld_contrast floatValue] / 100 );
376         } 
377         else if (sender == o_sld_gamma)
378         {
379             var_SetFloat( p_filter, "gamma", [o_sld_gamma floatValue] / 10 );
380             config_PutFloat( p_intf, "gamma", [o_sld_gamma floatValue] / 10 );
381         } 
382         else if (sender == o_sld_hue)
383         {
384             var_SetInteger( p_filter, "hue", [o_sld_hue intValue] );
385             config_PutInt( p_intf , "hue" , [o_sld_hue intValue] );
386         } 
387         else if (sender == o_sld_saturation)
388         {
389             var_SetFloat( p_filter, "saturation", [o_sld_saturation floatValue] / 100 );
390             config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100 );
391         } 
392         else
393         {
394             msg_Warn( p_intf, "couldn't find variable for slider!" );
395         }
396         vlc_object_release( p_filter );
397         vlc_object_release( p_vout );
398     }
399
400     o_config_changed = YES;
401 }
402
403 /* change the opaqueness of the vouts */
404 - (IBAction)opaqueSliderAction:(id)sender
405 {
406     vlc_value_t val;
407     id o_window = [NSApp keyWindow];
408     NSArray *o_windows = [NSApp orderedWindows];
409     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
410     playlist_t * p_playlist = pl_Yield( VLCIntf );
411     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
412     vout_thread_t *p_real_vout;
413
414     val.f_float = [o_sld_opaque floatValue] / 100;
415
416     if( p_vout != NULL )
417     {
418         p_real_vout = [VLCVoutView getRealVout: p_vout];
419         var_Set( p_real_vout, "macosx-opaqueness", val );
420
421         while ((o_window = [o_enumerator nextObject]))
422         {
423             if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
424                 [[[VLCMain sharedInstance] getEmbeddedList]
425                                     windowContainsEmbedded: o_window])
426             {
427                 [o_window setAlphaValue: val.f_float];
428             }
429             break;
430         }
431         vlc_object_release( p_vout );
432     }
433
434     /* store to prefs */
435     config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
436
437     vlc_object_release( p_playlist );
438
439     o_config_changed = YES;
440 }
441
442 - (IBAction)enableHeadphoneVirtualizer:(id)sender
443 {
444     /* en-/disable headphone virtualisation */
445     if ([o_ckb_hdphnVirt state] == NSOnState)
446         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: true ];
447     else
448         [self changeAFiltersString: "headphone_channel_mixer" onOrOff: false ];
449 }
450
451 - (IBAction)sliderActionMaximumAudioLevel:(id)sender
452 {
453     /* read-out the slider's value and apply it */
454     intf_thread_t * p_intf = VLCIntf;
455     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
456
457     if( p_aout != NULL )
458     {
459         var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] );
460         vlc_object_release( p_aout );
461     }
462
463     config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] );
464
465     o_config_changed = YES;
466 }
467
468 - (IBAction)enableVolumeNormalization:(id)sender
469 {
470     /* en-/disable volume normalisation */
471     if( [o_ckb_vlme_norm state] == NSOnState )
472         [self changeAFiltersString: "normvol" onOrOff: YES ];
473     else
474         [self changeAFiltersString: "normvol" onOrOff: NO ];
475 }
476
477 - (IBAction)videoFilterAction:(id)sender
478 {
479     /* en-/disable video filters */
480     if (sender == o_ckb_blur)
481         [self changeVoutFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
482
483     else if (sender == o_ckb_imgClone)
484         [self changeVoutFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
485
486     else if (sender == o_ckb_imgCrop)
487         [self changeVoutFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
488
489     else if (sender == o_ckb_imgInvers)
490         [self changeVideoFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
491
492     else if (sender == o_ckb_trnsform)
493         [self changeVoutFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
494
495     else if (sender == o_ckb_intZoom )
496         [self changeVoutFiltersString: "magnify" onOrOff: [o_ckb_intZoom state]];
497
498     else if (sender == o_ckb_wave )
499         [self changeVideoFiltersString: "wave" onOrOff: [o_ckb_wave state]];
500
501     else if (sender == o_ckb_gradient )
502         [self changeVideoFiltersString: "gradient" onOrOff: [o_ckb_gradient state]];
503
504     else if (sender == o_ckb_psycho )
505         [self changeVideoFiltersString: "psychedelic" onOrOff: [o_ckb_psycho state]];
506
507     else if (sender == o_ckb_ripple )
508         [self changeVideoFiltersString: "ripple" onOrOff: [o_ckb_ripple state]];
509
510     else
511         msg_Err( VLCIntf, "cannot find switched video-filter" ); /* this can't happen */
512 }
513
514 - (IBAction)moreInfoVideoFilters:(id)sender
515 {
516     /* show info sheet */
517     NSBeginInformationalAlertSheet(_NS("About the video filters"), 
518                                    _NS("OK"), 
519                                    @"", 
520                                    @"",
521                                    o_extended_window, 
522                                    nil, 
523                                    nil, 
524                                    nil, 
525                                    nil, 
526                                    _NS("This panel allows on-the-fly selection of various video effects.\n"
527                                        "These filters can be configured individually in the Preferences, in "
528                                        "the subsections of Video/Filters.\n"
529                                        "To choose the order in which the filter are applied, a filter "
530                                        "option string can be set in the Preferences, Video / Filters section."));
531 }
532
533
534 /*****************************************************************************
535  * methods to communicate changes to VLC's core
536  *****************************************************************************/
537
538 - (void)changeVoutFiltersString:(char *)psz_name onOrOff:(bool )b_add
539 {
540     /* copied from ../wxwidgets/extrapanel.cpp
541      * renamed to conform with Cocoa's rules */
542     /* this method only changes 1st generation video filters (the ones that
543      * can't be used for transcoding). Have a look at changeVideoFiltersString
544      * for the 2nd generation filters. */
545  
546     vout_thread_t *p_vout;
547     intf_thread_t * p_intf = VLCIntf;
548  
549     char *psz_parser, *psz_string;
550     psz_string = config_GetPsz( p_intf, "vout-filter" );
551  
552     if( !psz_string ) psz_string = strdup("");
553
554     psz_parser = strstr( psz_string, psz_name );
555
556     if( b_add )
557     {
558         if( !psz_parser )
559         {
560             psz_parser = psz_string;
561             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
562                             psz_string, psz_name );
563             free( psz_parser );
564         }
565         else
566         {
567             return;
568         }
569     }
570     else
571     {
572         if( psz_parser )
573         {
574             memmove( psz_parser, psz_parser + strlen(psz_name) +
575                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
576                             strlen(psz_parser + strlen(psz_name)) + 1 );
577
578             /* Remove trailing : : */
579             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
580             {
581                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
582             }
583          }
584          else
585          {
586              free( psz_string );
587              return;
588          }
589     }
590     /* Vout is not kept, so put that in the config */
591     config_PutPsz( p_intf, "vout-filter", psz_string );
592
593     /* Try to set on the fly */
594     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
595                                               FIND_ANYWHERE );
596     if( p_vout )
597     {
598         var_SetString( p_vout, "vout-filter", psz_string );
599         vlc_object_release( p_vout );
600     }
601
602     free( psz_string );
603
604     o_config_changed = YES;
605 }
606
607
608 - (void)changeVideoFiltersString:(char *)psz_name onOrOff:(bool )b_add
609 {
610     /* same as changeVoutFiltersString but addressing the "video-filter"
611      * variable which represents the video filter 2 modules */
612  
613     vout_thread_t *p_vout;
614     intf_thread_t * p_intf = VLCIntf;
615  
616     char *psz_parser, *psz_string;
617     psz_string = config_GetPsz( p_intf, "video-filter" );
618  
619     if( !psz_string ) psz_string = strdup("");
620
621     psz_parser = strstr( psz_string, psz_name );
622
623     if( b_add )
624     {
625         if( !psz_parser )
626         {
627             psz_parser = psz_string;
628             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
629                             psz_string, psz_name );
630             free( psz_parser );
631         }
632         else
633         {
634             return;
635         }
636     }
637     else
638     {
639         if( psz_parser )
640         {
641             memmove( psz_parser, psz_parser + strlen(psz_name) +
642                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
643                             strlen(psz_parser + strlen(psz_name)) + 1 );
644
645             /* Remove trailing : : */
646             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
647             {
648                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
649             }
650          }
651          else
652          {
653              free( psz_string );
654              return;
655          }
656     }
657     /* Vout is not kept, so put that in the config */
658     config_PutPsz( p_intf, "video-filter", psz_string );
659
660     /* Try to set on the fly */
661     p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
662                                               FIND_ANYWHERE );
663     if( p_vout )
664     {
665         var_SetString( p_vout, "video-filter", psz_string );
666         vlc_object_release( p_vout );
667     }
668
669     free( psz_string );
670
671     o_config_changed = YES;
672 }
673
674 - (void)changeAFiltersString: (char *)psz_name onOrOff: (bool )b_add;
675 {
676     /* copied from ../wxwidgets/extrapanel.cpp
677      * renamed to conform with Cocoa's rules */
678
679     char *psz_parser, *psz_string;
680     intf_thread_t * p_intf = VLCIntf;
681     aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
682                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
683
684     if( p_aout )
685     {
686         psz_string = var_GetNonEmptyString( p_aout, "audio-filter" );
687     }
688     else
689     {
690         psz_string = config_GetPsz( p_intf, "audio-filter" );
691     }
692
693     if( !psz_string ) psz_string = strdup("");
694
695     psz_parser = strstr( psz_string, psz_name );
696
697     if( b_add )
698     {
699         if( !psz_parser )
700         {
701             psz_parser = psz_string;
702             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
703                             psz_string, psz_name );
704             free( psz_parser );
705         }
706         else
707         {
708             return;
709         }
710     }
711     else
712     {
713         if( psz_parser )
714         {
715             memmove( psz_parser, psz_parser + strlen(psz_name) +
716                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
717                             strlen(psz_parser + strlen(psz_name)) + 1 );
718
719             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
720             {
721                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
722             }
723          }
724          else
725          {
726              free( psz_string );
727              return;
728          }
729     }
730
731     if( p_aout == NULL )
732     {
733         config_PutPsz( p_intf, "audio-filter", psz_string );
734     }
735     else
736     {
737         var_SetString( p_aout, "audio-filter", psz_string );
738         int i = 0;
739         while( i < p_aout->i_nb_inputs )
740         {
741             p_aout->pp_inputs[i]->b_restart = true;
742             i = (i + 1);
743         }
744         vlc_object_release( p_aout );
745     }
746     free( psz_string );
747
748     o_config_changed = YES;
749 }
750
751 - (void)savePrefs
752 {
753     /* save the preferences to make sure that our module-changes will up on
754      * next launch again */
755     playlist_t * p_playlist = pl_Yield( VLCIntf );
756     int returnedValue;
757     NSArray * theModules;
758     theModules = [[NSArray alloc] initWithObjects: @"main", 
759         @"headphone",
760         @"transform", 
761         @"adjust", 
762         @"invert", 
763         @"motionblur", 
764         @"distort",
765         @"clone", 
766         @"crop", 
767         @"normvol", 
768         @"headphone_channel_mixer", 
769         @"macosx",
770         nil];
771     unsigned int x = 0;
772  
773     while ( x != [theModules count] )
774     {
775         returnedValue = config_SaveConfigFile( p_playlist, [[theModules
776             objectAtIndex: x] UTF8String] );
777
778         if (returnedValue != 0)
779         {
780             msg_Err(p_playlist, "unable to save the preferences of the "
781             "extended control attribute '%s' (%i)",
782             [[theModules objectAtIndex: x] UTF8String] , returnedValue);
783             [theModules release];
784             vlc_object_release( p_playlist );
785  
786             return;
787         }
788
789         x = ( x + 1 );
790     }
791  
792     msg_Dbg( VLCIntf, "VLCExtended: saved certain preferences successfully" );
793  
794     [theModules release];
795     vlc_object_release( p_playlist );
796 }
797 @end