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