1 /*****************************************************************************
2 * extended.m: MacOS X Extended interface panel
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Felix Kühne <fkuehne@users.sf.net>
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.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 /*****************************************************************************
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 *****************************************************************************/
35 /*****************************************************************************
37 *****************************************************************************/
43 #import <aout_internal.h>
47 /*****************************************************************************
48 * VLCExtended implementation
49 *****************************************************************************/
51 @implementation VLCExtended
53 static VLCExtended *_o_sharedInstance = nil;
55 + (VLCExtended *)sharedInstance
57 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
62 if (_o_sharedInstance) {
65 _o_sharedInstance = [super init];
68 return _o_sharedInstance;
73 /* localise GUI-strings */
74 /* method is called from intf.m (in method showExtended) */
75 [o_extended_window setTitle: _NS("Extended controls")];
76 [o_lbl_video setStringValue: _NS("Video")];
77 [o_lbl_audio setStringValue: _NS("Audio")];
78 [o_lbl_audioFlts setStringValue: _NS("Audio filters")];
79 [o_lbl_videoFlts setStringValue: _NS("Video filters")];
80 [o_lbl_adjustImage setStringValue: _NS("Adjust Image")];
81 [o_btn_vidFlts_mrInfo setTitle: _NS("More Info")];
82 [o_ckb_blur setTitle: _NS("Blurring")];
83 [o_ckb_distortion setTitle: _NS("Distortion")];
84 [o_ckb_imgClone setTitle: _NS("Image clone")];
85 [o_ckb_imgCrop setTitle: _NS("Image cropping")];
86 [o_ckb_imgInvers setTitle: _NS("Image inversion")];
87 [o_ckb_trnsform setTitle: _NS("Transformation")];
88 [o_ckb_vlme_norm setTitle: _NS("Volume normalization")];
89 [o_ckb_hdphnVirt setTitle: _NS("Headphone virtualization")];
90 [o_lbl_maxLevel setStringValue: _NS("Maximum level")];
91 [o_btn_rstrDefaults setTitle: _NS("Restore Defaults")];
92 [o_ckb_enblAdjustImg setTitle: _NS("Enable")];
93 [o_lbl_brightness setStringValue: _NS("Brightness")];
94 [o_lbl_contrast setStringValue: _NS("Contrast")];
95 [o_lbl_gamma setStringValue: _NS("Gamma")];
96 [o_lbl_hue setStringValue: _NS("Hue")];
97 [o_lbl_saturation setStringValue: _NS("Saturation")];
102 /* set the adjust-filter-sliders to the values from the prefs and enable
105 intf_thread_t * p_intf = VLCIntf;
106 psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
107 if( psz_vfilters && strstr( psz_vfilters, "adjust" ) )
109 [o_ckb_enblAdjustImg setState: NSOnState];
110 [o_btn_rstrDefaults setEnabled: YES];
111 [o_sld_brightness setEnabled: YES];
112 [o_sld_contrast setEnabled: YES];
113 [o_sld_gamma setEnabled: YES];
114 [o_sld_hue setEnabled: YES];
115 [o_sld_saturation setEnabled: YES];
119 [o_ckb_enblAdjustImg setState: NSOffState];
120 [o_btn_rstrDefaults setEnabled: NO];
121 [o_sld_brightness setEnabled: NO];
122 [o_sld_contrast setEnabled: NO];
123 [o_sld_gamma setEnabled: NO];
124 [o_sld_hue setEnabled: NO];
125 [o_sld_saturation setEnabled: NO];
127 if( psz_vfilters ) free( psz_vfilters );
129 int i_value = config_GetInt( p_intf, "hue" );
130 if( i_value > 0 && i_value < 360 )
132 [o_sld_hue setIntValue: i_value];
137 f_value = config_GetFloat( p_intf, "saturation" );
138 if( f_value > 0 && f_value < 5 )
140 [o_sld_saturation setIntValue: (int)(100 * f_value) ];
143 f_value = config_GetFloat( p_intf, "contrast" );
144 if( f_value > 0 && f_value < 4 )
146 [o_sld_contrast setIntValue: (int)(100 * f_value) ];
149 f_value = config_GetFloat( p_intf, "brightness" );
150 if( f_value > 0 && f_value < 2 )
152 [o_sld_brightness setIntValue: (int)(100 * f_value) ];
155 f_value = config_GetFloat( p_intf, "gamma" );
156 if( f_value > 0 && f_value < 10 )
158 [o_sld_gamma setIntValue: (int)(10 * f_value) ];
162 /* set the audio-filter-checkboxes to the values taken from the prefs */
164 psz_afilters = config_GetPsz( p_intf, "audio-filter" );
167 [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
168 [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
169 free( psz_afilters );
175 /* show the window */
176 [o_extended_window displayIfNeeded];
177 [o_extended_window makeKeyAndOrderFront:nil];
180 - (IBAction)adjImg_Enbl:(id)sender
182 /* en-/disable the sliders */
183 if ([o_ckb_enblAdjustImg state] == NSOnState)
185 [o_btn_rstrDefaults setEnabled: YES];
186 [o_sld_brightness setEnabled: YES];
187 [o_sld_contrast setEnabled: YES];
188 [o_sld_gamma setEnabled: YES];
189 [o_sld_hue setEnabled: YES];
190 [o_sld_saturation setEnabled: YES];
191 [self changeVFiltersString: "adjust" onOrOff: YES];
193 [o_btn_rstrDefaults setEnabled: NO];
194 [o_sld_brightness setEnabled: NO];
195 [o_sld_contrast setEnabled: NO];
196 [o_sld_gamma setEnabled: NO];
197 [o_sld_hue setEnabled: NO];
198 [o_sld_saturation setEnabled: NO];
199 [self changeVFiltersString: "adjust" onOrOff: NO];
203 - (IBAction)adjImg_rstrDefaults:(id)sender
205 /* reset the sliders */
206 [o_sld_brightness setIntValue: 100];
207 [o_sld_contrast setIntValue: 100];
208 [o_sld_gamma setIntValue: 10];
209 [o_sld_hue setIntValue: 0];
210 [o_sld_saturation setIntValue: 100];
212 /* transmit the values */
213 [self adjImg_sliders: o_sld_brightness];
214 [self adjImg_sliders: o_sld_contrast];
215 [self adjImg_sliders: o_sld_gamma];
216 [self adjImg_sliders: o_sld_hue];
217 [self adjImg_sliders: o_sld_saturation];
220 - (IBAction)adjImg_sliders:(id)sender
222 /* read-out the sliders' values and apply them */
223 intf_thread_t * p_intf = VLCIntf;
224 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
225 VLC_OBJECT_VOUT, FIND_ANYWHERE);
228 if (sender == o_sld_brightness)
230 config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
231 } else if (sender == o_sld_contrast)
233 config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
234 } else if (sender == o_sld_gamma)
236 config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
237 } else if (sender == o_sld_hue)
239 config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
240 } else if (sender == o_sld_saturation)
242 config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
244 msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
249 if (sender == o_sld_brightness)
251 val.f_float = [o_sld_brightness floatValue] / 100;
252 var_Set( p_vout, "brightness", val );
253 config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
254 } else if (sender == o_sld_contrast)
256 val.f_float = [o_sld_contrast floatValue] / 100;
257 var_Set( p_vout, "contrast", val );
258 config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
259 } else if (sender == o_sld_gamma)
261 val.f_float = [o_sld_gamma floatValue] / 10;
262 var_Set( p_vout, "gamma", val );
263 config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
264 } else if (sender == o_sld_hue)
266 val.i_int = [o_sld_hue intValue];
267 var_Set( p_vout, "hue", val );
268 config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
269 } else if (sender == o_sld_saturation)
271 val.f_float = [o_sld_saturation floatValue] / 100;
272 var_Set( p_vout, "saturation", val );
273 config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
275 msg_Warn( p_intf, "cannot find adjust-image-subfilter related to " \
281 - (IBAction)audFtls_hdphnVirt:(id)sender
283 /* en-/disable headphone virtualisation */
284 if ([o_ckb_hdphnVirt state] == NSOnState)
286 [self changeAFiltersString: "headphone" onOrOff: YES ];
288 [self changeAFiltersString: "headphone" onOrOff: NO ];
292 - (IBAction)audFtls_maxLevelSld:(id)sender
294 /* read-out the slider's value and apply it */
295 intf_thread_t * p_intf = VLCIntf;
296 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
297 VLC_OBJECT_AOUT, FIND_ANYWHERE);
300 var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] / 10 );
301 vlc_object_release( p_aout );
305 config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] /10 );
309 - (IBAction)audFtls_vlmeNorm:(id)sender
311 /* en-/disable volume normalisation */
312 if ([o_ckb_vlme_norm state] == NSOnState)
314 [self changeAFiltersString: "normvol" onOrOff: YES ];
316 [self changeAFiltersString: "normvol" onOrOff: NO ];
320 - (IBAction)extWin_exp_adjImg:(id)sender
322 /* expand or collapse adjImg */
323 NSRect o_win_rect = [o_extended_window frame];
324 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
325 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
326 NSRect o_box_adjImg_rect = [o_box_adjImg frame];
328 if (o_adjImg_expanded)
330 /* move the window contents upwards (partially done through settings
331 * inside the nib) and resize the window */
332 o_win_rect.size.height = o_win_rect.size.height - 151;
333 o_win_rect.origin.y = [o_extended_window frame].origin.y + 151;
334 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 151;
335 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 151;
337 /* remove the inserted view */
338 [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
341 /* move the window contents downwards and resize the window */
342 o_win_rect.size.height = o_win_rect.size.height + 151;
343 o_win_rect.origin.y = [o_extended_window frame].origin.y - 151;
344 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 151;
345 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 151;
348 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
349 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
350 [o_extended_window displayIfNeeded];
351 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
353 if (o_adjImg_expanded)
355 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 151;
356 msg_Dbg( VLCIntf, "collapsed adjust-image section");
357 o_adjImg_expanded = NO;
360 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 151;
361 [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 161)];
362 [o_adjustImg_view setNeedsDisplay:YES];
363 [o_adjustImg_view setAutoresizesSubviews: YES];
364 [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
365 msg_Dbg( VLCIntf, "expanded adjust-image section");
366 o_adjImg_expanded = YES;
368 [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
371 - (IBAction)extWin_exp_audFlts:(id)sender
373 /* expand or collapse audFlts */
374 NSRect o_win_rect = [o_extended_window frame];
375 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
377 if (o_audFlts_expanded)
379 /* move the window contents upwards (partially done through settings
380 * inside the nib) and resize the window */
381 o_win_rect.size.height = o_win_rect.size.height - 66;
382 o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
384 /* remove the inserted view */
385 [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
387 /* move the window contents downwards and resize the window */
388 o_win_rect.size.height = o_win_rect.size.height + 66;
389 o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
391 [o_extended_window displayIfNeeded];
392 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
395 if (o_audFlts_expanded)
397 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
398 msg_Dbg( VLCIntf, "collapsed audio-filters section");
399 o_audFlts_expanded = NO;
402 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
403 [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
404 [o_audioFlts_view setNeedsDisplay:YES];
405 [o_audioFlts_view setAutoresizesSubviews: YES];
406 [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
407 msg_Dbg( VLCIntf, "expanded audio-filters section");
408 o_audFlts_expanded = YES;
410 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
413 - (IBAction)extWin_exp_vidFlts:(id)sender
415 /* expand or collapse vidFlts */
416 NSRect o_win_rect = [o_extended_window frame];
417 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
418 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
420 if (o_vidFlts_expanded)
422 /* move the window contents upwards (partially done through settings
423 * inside the nib) and resize the window */
424 o_win_rect.size.height = o_win_rect.size.height - 134;
425 o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
426 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
428 /* remove the inserted view */
429 [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
432 /* move the window contents downwards and resize the window */
433 o_win_rect.size.height = o_win_rect.size.height + 134;
434 o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
435 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
438 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
439 [o_extended_window displayIfNeeded];
440 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
442 if (o_vidFlts_expanded)
444 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
445 msg_Dbg( VLCIntf, "collapsed video-filters section");
446 o_vidFlts_expanded = NO;
449 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
450 [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
451 [o_videoFilters_view setNeedsDisplay:YES];
452 [o_videoFilters_view setAutoresizesSubviews: YES];
453 [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
454 msg_Dbg( VLCIntf, "expanded video-filters section");
455 o_vidFlts_expanded = YES;
457 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
460 - (IBAction)vidFlts:(id)sender
462 /* en-/disable video filters */
463 if (sender == o_ckb_blur)
465 [self changeVFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
467 else if (sender == o_ckb_distortion)
469 [self changeVFiltersString: "distort" onOrOff: [o_ckb_distortion state]];
471 else if (sender == o_ckb_imgClone)
473 [self changeVFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
475 else if (sender == o_ckb_imgCrop)
477 [self changeVFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
479 else if (sender == o_ckb_imgInvers)
481 [self changeVFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
483 else if (sender == o_ckb_trnsform)
485 [self changeVFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
487 /* this shouldn't happen */
488 msg_Warn (VLCIntf, "cannot find selected video-filter");
492 - (IBAction)vidFlts_mrInfo:(id)sender
494 /* show info sheet */
495 NSBeginInformationalAlertSheet(_NS("More information"), _NS("OK"), @"", @"", \
496 o_extended_window, nil, nil, nil, nil, _NS("Select the video effects " \
497 "filters to apply. You must restart the stream for these settings to " \
498 "take effect.\nTo configure the filters, go to the Preferences, and " \
499 "go to Modules/Video Filters. You can then configure each filter.\n" \
500 "If you want fine control over the filters ( to choose the order in " \
501 "which they are applied ), you need to enter manually a filters " \
502 "string (Preferences / Video / Filters)."));
505 - (void)changeVFiltersString:(char *)psz_name onOrOff:(BOOL)o_onOrOff
507 /* copied from ../wxwidgets/extrapanel.cpp
508 * renamed to conform with Cocoa's rules */
510 vout_thread_t *p_vout;
511 intf_thread_t * p_intf = VLCIntf;
513 char *psz_parser, *psz_string;
514 psz_string = config_GetPsz( p_intf, "vout-filter" );
516 if( !psz_string ) psz_string = strdup("");
518 psz_parser = strstr( psz_string, psz_name );
524 psz_parser = psz_string;
525 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
526 psz_string, psz_name );
538 memmove( psz_parser, psz_parser + strlen(psz_name) +
539 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
540 strlen(psz_parser + strlen(psz_name)) + 1 );
542 /* Remove trailing : : */
543 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
545 *(psz_string+strlen(psz_string ) -1 ) = '\0';
554 /* Vout is not kept, so put that in the config */
555 config_PutPsz( p_intf, "vout-filter", psz_string );
557 /* Try to set on the fly */
558 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
562 var_SetString( p_vout, "vout-filter", psz_string );
563 vlc_object_release( p_vout );
570 - (void)changeAFiltersString: (char *)psz_name onOrOff: (BOOL)o_onOrOff;
572 char *psz_parser, *psz_string;
573 intf_thread_t * p_intf = VLCIntf;
574 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
575 VLC_OBJECT_AOUT, FIND_ANYWHERE);
579 psz_string = var_GetString( p_aout, "audio-filter" );
583 psz_string = config_GetPsz( p_intf, "audio-filter" );
586 if( !psz_string ) psz_string = strdup("");
588 psz_parser = strstr( psz_string, psz_name );
594 psz_parser = psz_string;
595 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
596 psz_string, psz_name );
608 memmove( psz_parser, psz_parser + strlen(psz_name) +
609 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
610 strlen(psz_parser + strlen(psz_name)) + 1 );
612 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
614 *(psz_string+strlen(psz_string ) -1 ) = '\0';
626 config_PutPsz( p_intf, "audio-filter", psz_string );
630 var_SetString( p_aout, "audio-filter", psz_string );
632 while( i < p_aout->i_nb_inputs )
634 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
637 vlc_object_release( p_aout );