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 " \
278 vlc_object_release( p_vout );
282 - (IBAction)audFtls_hdphnVirt:(id)sender
284 /* en-/disable headphone virtualisation */
285 if ([o_ckb_hdphnVirt state] == NSOnState)
287 [self changeAFiltersString: "headphone" onOrOff: YES ];
289 [self changeAFiltersString: "headphone" onOrOff: NO ];
293 - (IBAction)audFtls_maxLevelSld:(id)sender
295 /* read-out the slider's value and apply it */
296 intf_thread_t * p_intf = VLCIntf;
297 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
298 VLC_OBJECT_AOUT, FIND_ANYWHERE);
301 var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] / 10 );
302 vlc_object_release( p_aout );
306 config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] /10 );
310 - (IBAction)audFtls_vlmeNorm:(id)sender
312 /* en-/disable volume normalisation */
313 if ([o_ckb_vlme_norm state] == NSOnState)
315 [self changeAFiltersString: "normvol" onOrOff: YES ];
317 [self changeAFiltersString: "normvol" onOrOff: NO ];
321 - (IBAction)extWin_exp_adjImg:(id)sender
323 /* expand or collapse adjImg */
324 NSRect o_win_rect = [o_extended_window frame];
325 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
326 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
327 NSRect o_box_adjImg_rect = [o_box_adjImg frame];
329 if (o_adjImg_expanded)
331 /* move the window contents upwards (partially done through settings
332 * inside the nib) and resize the window */
333 o_win_rect.size.height = o_win_rect.size.height - 151;
334 o_win_rect.origin.y = [o_extended_window frame].origin.y + 151;
335 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 151;
336 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 151;
338 /* remove the inserted view */
339 [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
342 /* move the window contents downwards and resize the window */
343 o_win_rect.size.height = o_win_rect.size.height + 151;
344 o_win_rect.origin.y = [o_extended_window frame].origin.y - 151;
345 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 151;
346 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 151;
349 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
350 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
351 [o_extended_window displayIfNeeded];
352 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
354 if (o_adjImg_expanded)
356 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 151;
357 msg_Dbg( VLCIntf, "collapsed adjust-image section");
358 o_adjImg_expanded = NO;
361 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 151;
362 [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 161)];
363 [o_adjustImg_view setNeedsDisplay:YES];
364 [o_adjustImg_view setAutoresizesSubviews: YES];
365 [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
366 msg_Dbg( VLCIntf, "expanded adjust-image section");
367 o_adjImg_expanded = YES;
369 [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
372 - (IBAction)extWin_exp_audFlts:(id)sender
374 /* expand or collapse audFlts */
375 NSRect o_win_rect = [o_extended_window frame];
376 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
378 if (o_audFlts_expanded)
380 /* move the window contents upwards (partially done through settings
381 * inside the nib) and resize the window */
382 o_win_rect.size.height = o_win_rect.size.height - 66;
383 o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
385 /* remove the inserted view */
386 [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
388 /* move the window contents downwards and resize the window */
389 o_win_rect.size.height = o_win_rect.size.height + 66;
390 o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
392 [o_extended_window displayIfNeeded];
393 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
396 if (o_audFlts_expanded)
398 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
399 msg_Dbg( VLCIntf, "collapsed audio-filters section");
400 o_audFlts_expanded = NO;
403 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
404 [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
405 [o_audioFlts_view setNeedsDisplay:YES];
406 [o_audioFlts_view setAutoresizesSubviews: YES];
407 [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
408 msg_Dbg( VLCIntf, "expanded audio-filters section");
409 o_audFlts_expanded = YES;
411 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
414 - (IBAction)extWin_exp_vidFlts:(id)sender
416 /* expand or collapse vidFlts */
417 NSRect o_win_rect = [o_extended_window frame];
418 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
419 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
421 if (o_vidFlts_expanded)
423 /* move the window contents upwards (partially done through settings
424 * inside the nib) and resize the window */
425 o_win_rect.size.height = o_win_rect.size.height - 134;
426 o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
427 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
429 /* remove the inserted view */
430 [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
433 /* move the window contents downwards and resize the window */
434 o_win_rect.size.height = o_win_rect.size.height + 134;
435 o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
436 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
439 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
440 [o_extended_window displayIfNeeded];
441 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
443 if (o_vidFlts_expanded)
445 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
446 msg_Dbg( VLCIntf, "collapsed video-filters section");
447 o_vidFlts_expanded = NO;
450 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
451 [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
452 [o_videoFilters_view setNeedsDisplay:YES];
453 [o_videoFilters_view setAutoresizesSubviews: YES];
454 [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
455 msg_Dbg( VLCIntf, "expanded video-filters section");
456 o_vidFlts_expanded = YES;
458 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
461 - (IBAction)vidFlts:(id)sender
463 /* en-/disable video filters */
464 if (sender == o_ckb_blur)
466 [self changeVFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
468 else if (sender == o_ckb_distortion)
470 [self changeVFiltersString: "distort" onOrOff: [o_ckb_distortion state]];
472 else if (sender == o_ckb_imgClone)
474 [self changeVFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
476 else if (sender == o_ckb_imgCrop)
478 [self changeVFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
480 else if (sender == o_ckb_imgInvers)
482 [self changeVFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
484 else if (sender == o_ckb_trnsform)
486 [self changeVFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
488 /* this shouldn't happen */
489 msg_Warn (VLCIntf, "cannot find selected video-filter");
493 - (IBAction)vidFlts_mrInfo:(id)sender
495 /* show info sheet */
496 NSBeginInformationalAlertSheet(_NS("More information"), _NS("OK"), @"", @"", \
497 o_extended_window, nil, nil, nil, nil, _NS("Select the video effects " \
498 "filters to apply. You must restart the stream for these settings to " \
499 "take effect.\nTo configure the filters, go to the Preferences, and " \
500 "go to Modules/Video Filters. You can then configure each filter.\n" \
501 "If you want fine control over the filters ( to choose the order in " \
502 "which they are applied ), you need to enter manually a filters " \
503 "string (Preferences / Video / Filters)."));
506 - (void)changeVFiltersString:(char *)psz_name onOrOff:(BOOL)o_onOrOff
508 /* copied from ../wxwidgets/extrapanel.cpp
509 * renamed to conform with Cocoa's rules */
511 vout_thread_t *p_vout;
512 intf_thread_t * p_intf = VLCIntf;
514 char *psz_parser, *psz_string;
515 psz_string = config_GetPsz( p_intf, "vout-filter" );
517 if( !psz_string ) psz_string = strdup("");
519 psz_parser = strstr( psz_string, psz_name );
525 psz_parser = psz_string;
526 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
527 psz_string, psz_name );
539 memmove( psz_parser, psz_parser + strlen(psz_name) +
540 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
541 strlen(psz_parser + strlen(psz_name)) + 1 );
543 /* Remove trailing : : */
544 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
546 *(psz_string+strlen(psz_string ) -1 ) = '\0';
555 /* Vout is not kept, so put that in the config */
556 config_PutPsz( p_intf, "vout-filter", psz_string );
558 /* Try to set on the fly */
559 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
563 var_SetString( p_vout, "vout-filter", psz_string );
564 vlc_object_release( p_vout );
571 - (void)changeAFiltersString: (char *)psz_name onOrOff: (BOOL)o_onOrOff;
573 char *psz_parser, *psz_string;
574 intf_thread_t * p_intf = VLCIntf;
575 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
576 VLC_OBJECT_AOUT, FIND_ANYWHERE);
580 psz_string = var_GetString( p_aout, "audio-filter" );
584 psz_string = config_GetPsz( p_intf, "audio-filter" );
587 if( !psz_string ) psz_string = strdup("");
589 psz_parser = strstr( psz_string, psz_name );
595 psz_parser = psz_string;
596 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
597 psz_string, psz_name );
609 memmove( psz_parser, psz_parser + strlen(psz_name) +
610 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
611 strlen(psz_parser + strlen(psz_name)) + 1 );
613 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
615 *(psz_string+strlen(psz_string ) -1 ) = '\0';
627 config_PutPsz( p_intf, "audio-filter", psz_string );
631 var_SetString( p_aout, "audio-filter", psz_string );
633 while( i < p_aout->i_nb_inputs )
635 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
638 vlc_object_release( p_aout );