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 view and resize/remove the other stuff
30 * was inspired by intf.m, written by Derk-Jan Hartman.
31 * (both 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) */
79 /* set the adjust-filter-sliders to the values from the prefs and enable
82 intf_thread_t * p_intf = VLCIntf;
83 psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
84 if( psz_vfilters && strstr( psz_vfilters, "adjust" ) )
86 [o_ckb_enblAdjustImg setState: NSOnState];
87 [o_btn_rstrDefaults setEnabled: YES];
88 [o_sld_brightness setEnabled: YES];
89 [o_sld_contrast setEnabled: YES];
90 [o_sld_gamma setEnabled: YES];
91 [o_sld_hue setEnabled: YES];
92 [o_sld_saturation setEnabled: YES];
96 [o_ckb_enblAdjustImg setState: NSOffState];
97 [o_btn_rstrDefaults setEnabled: NO];
98 [o_sld_brightness setEnabled: NO];
99 [o_sld_contrast setEnabled: NO];
100 [o_sld_gamma setEnabled: NO];
101 [o_sld_hue setEnabled: NO];
102 [o_sld_saturation setEnabled: NO];
104 if( psz_vfilters ) free( psz_vfilters );
106 int i_value = config_GetInt( p_intf, "hue" );
107 if( i_value > 0 && i_value < 360 )
109 [o_sld_hue setIntValue: i_value];
114 f_value = config_GetFloat( p_intf, "saturation" );
115 if( f_value > 0 && f_value < 5 )
117 [o_sld_saturation setIntValue: (int)(100 * f_value) ];
120 f_value = config_GetFloat( p_intf, "contrast" );
121 if( f_value > 0 && f_value < 4 )
123 [o_sld_contrast setIntValue: (int)(100 * f_value) ];
126 f_value = config_GetFloat( p_intf, "brightness" );
127 if( f_value > 0 && f_value < 2 )
129 [o_sld_brightness setIntValue: (int)(100 * f_value) ];
132 f_value = config_GetFloat( p_intf, "gamma" );
133 if( f_value > 0 && f_value < 10 )
135 [o_sld_gamma setIntValue: (int)(10 * f_value) ];
139 /* set the audio-filter-checkboxes to the values taken from the prefs */
141 psz_afilters = config_GetPsz( p_intf, "audio-filter" );
144 [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
145 [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
146 free( psz_afilters );
152 /* show the window */
153 [o_extended_window displayIfNeeded];
154 [o_extended_window makeKeyAndOrderFront:nil];
157 - (IBAction)adjImg_Enbl:(id)sender
159 /* en-/disable the sliders */
160 if ([o_ckb_enblAdjustImg state] == NSOnState)
162 [o_btn_rstrDefaults setEnabled: YES];
163 [o_sld_brightness setEnabled: YES];
164 [o_sld_contrast setEnabled: YES];
165 [o_sld_gamma setEnabled: YES];
166 [o_sld_hue setEnabled: YES];
167 [o_sld_saturation setEnabled: YES];
168 [self changeVFiltersString: "adjust" onOrOff: YES];
170 [o_btn_rstrDefaults setEnabled: NO];
171 [o_sld_brightness setEnabled: NO];
172 [o_sld_contrast setEnabled: NO];
173 [o_sld_gamma setEnabled: NO];
174 [o_sld_hue setEnabled: NO];
175 [o_sld_saturation setEnabled: NO];
176 [self changeVFiltersString: "adjust" onOrOff: NO];
180 - (IBAction)adjImg_rstrDefaults:(id)sender
182 /* reset the sliders */
183 [o_sld_brightness setIntValue: 100];
184 [o_sld_contrast setIntValue: 100];
185 [o_sld_gamma setIntValue: 10];
186 [o_sld_hue setIntValue: 0];
187 [o_sld_saturation setIntValue: 100];
189 /* transmit the values */
190 [self adjImg_sliders: o_sld_brightness];
191 [self adjImg_sliders: o_sld_contrast];
192 [self adjImg_sliders: o_sld_gamma];
193 [self adjImg_sliders: o_sld_hue];
194 [self adjImg_sliders: o_sld_saturation];
197 - (IBAction)adjImg_sliders:(id)sender
199 /* read-out the sliders' values and apply them */
200 intf_thread_t * p_intf = VLCIntf;
201 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
202 VLC_OBJECT_VOUT, FIND_ANYWHERE);
205 if (sender == o_sld_brightness)
207 config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
208 } else if (sender == o_sld_contrast)
210 config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
211 } else if (sender == o_sld_gamma)
213 config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
214 } else if (sender == o_sld_hue)
216 config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
217 } else if (sender == o_sld_saturation)
219 config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
223 if (sender == o_sld_brightness)
225 val.f_float = [o_sld_brightness floatValue] / 100;
226 var_Set( p_vout, "brightness", val );
227 config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
228 } else if (sender == o_sld_contrast)
230 val.f_float = [o_sld_contrast floatValue] / 100;
231 var_Set( p_vout, "contrast", val );
232 config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
233 } else if (sender == o_sld_gamma)
235 val.f_float = [o_sld_gamma floatValue] / 10;
236 var_Set( p_vout, "gamma", val );
237 config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
238 } else if (sender == o_sld_hue)
240 val.i_int = [o_sld_hue intValue];
241 var_Set( p_vout, "hue", val );
242 config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
243 } else if (sender == o_sld_saturation)
245 val.f_float = [o_sld_saturation floatValue] / 100;
246 var_Set( p_vout, "saturation", val );
247 config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
252 - (IBAction)audFtls_hdphnVirt:(id)sender
254 /* en-/disable headphone virtualisation */
255 if ([o_ckb_hdphnVirt state] == NSOnState)
257 [self changeAFiltersString: "headphone" onOrOff: YES ];
259 [self changeAFiltersString: "headphone" onOrOff: NO ];
263 - (IBAction)audFtls_maxLevelSld:(id)sender
265 /* read-out the slider's value and apply it */
266 intf_thread_t * p_intf = VLCIntf;
267 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
268 VLC_OBJECT_AOUT, FIND_ANYWHERE);
271 var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] / 10 );
272 vlc_object_release( p_aout );
276 config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] /10 );
280 - (IBAction)audFtls_vlmeNorm:(id)sender
282 /* en-/disable volume normalisation */
283 if ([o_ckb_vlme_norm state] == NSOnState)
285 [self changeAFiltersString: "normvol" onOrOff: YES ];
287 [self changeAFiltersString: "normvol" onOrOff: NO ];
291 - (IBAction)extWin_exp_adjImg:(id)sender
293 /* expand or collapse adjImg */
294 NSRect o_win_rect = [o_extended_window frame];
295 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
296 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
297 NSRect o_box_adjImg_rect = [o_box_adjImg frame];
299 if (o_adjImg_expanded)
301 /* move the window contents upwards (partially done through settings
302 * inside the nib) and resize the window */
303 o_win_rect.size.height = o_win_rect.size.height - 151;
304 o_win_rect.origin.y = [o_extended_window frame].origin.y + 151;
305 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 151;
306 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 151;
308 /* remove the inserted view */
309 [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
312 /* move the window contents downwards and resize the window */
313 o_win_rect.size.height = o_win_rect.size.height + 151;
314 o_win_rect.origin.y = [o_extended_window frame].origin.y - 151;
315 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 151;
316 o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 151;
319 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
320 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
321 [o_extended_window displayIfNeeded];
322 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
324 if (o_adjImg_expanded)
326 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 151;
327 o_adjImg_expanded = NO;
330 o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 151;
331 [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 161)];
332 [o_adjustImg_view setNeedsDisplay:YES];
333 [o_adjustImg_view setAutoresizesSubviews: YES];
334 [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
335 o_adjImg_expanded = YES;
337 [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
340 - (IBAction)extWin_exp_audFlts:(id)sender
342 /* expand or collapse audFlts */
343 NSRect o_win_rect = [o_extended_window frame];
344 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
346 if (o_audFlts_expanded)
348 /* move the window contents upwards (partially done through settings
349 * inside the nib) and resize the window */
350 o_win_rect.size.height = o_win_rect.size.height - 66;
351 o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
353 /* remove the inserted view */
354 [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
356 /* move the window contents downwards and resize the window */
357 o_win_rect.size.height = o_win_rect.size.height + 66;
358 o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
360 [o_extended_window displayIfNeeded];
361 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
364 if (o_audFlts_expanded)
366 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
367 o_audFlts_expanded = NO;
370 o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
371 [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
372 [o_audioFlts_view setNeedsDisplay:YES];
373 [o_audioFlts_view setAutoresizesSubviews: YES];
374 [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
375 o_audFlts_expanded = YES;
377 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
380 - (IBAction)extWin_exp_vidFlts:(id)sender
382 /* expand or collapse vidFlts */
383 NSRect o_win_rect = [o_extended_window frame];
384 NSRect o_box_audFlts_rect = [o_box_audFlts frame];
385 NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
387 if (o_vidFlts_expanded)
389 /* move the window contents upwards (partially done through settings
390 * inside the nib) and resize the window */
391 o_win_rect.size.height = o_win_rect.size.height - 134;
392 o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
393 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
395 /* remove the inserted view */
396 [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
399 /* move the window contents downwards and resize the window */
400 o_win_rect.size.height = o_win_rect.size.height + 134;
401 o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
402 o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
405 [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
406 [o_extended_window displayIfNeeded];
407 [o_extended_window setFrame: o_win_rect display:YES animate: YES];
409 if (o_vidFlts_expanded)
411 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
412 o_vidFlts_expanded = NO;
415 o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
416 [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
417 [o_videoFilters_view setNeedsDisplay:YES];
418 [o_videoFilters_view setAutoresizesSubviews: YES];
419 [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
420 o_vidFlts_expanded = YES;
422 [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
425 - (IBAction)vidFlts:(id)sender
427 /* en-/disable video filters */
430 - (IBAction)vidFlts_mrInfo:(id)sender
432 /* show info sheet */
433 NSBeginInformationalAlertSheet(_NS("More information"), _NS("OK"), @"", @"", \
434 o_extended_window, nil, nil, nil, nil, _NS("Select the video effects " \
435 "filters to apply. You must restart the stream for these settings to " \
436 "take effect.\nTo configure the filters, go to the Preferences, and " \
437 "go to Modules/Video Filters. You can then configure each filter.\n" \
438 "If you want fine control over the filters ( to choose the order in " \
439 "which they are applied ), you need to enter manually a filters " \
440 "string (Preferences / Video / Filters)."));
443 - (void)changeVFiltersString:(char *)psz_name onOrOff:(BOOL)o_onOrOff
445 /* copied from ../wxwidgets/extrapanel.cpp
446 * renamed to conform with Cocoa's rules */
448 vout_thread_t *p_vout;
449 intf_thread_t * p_intf = VLCIntf;
451 char *psz_parser, *psz_string;
452 psz_string = config_GetPsz( p_intf, "vout-filter" );
454 if( !psz_string ) psz_string = strdup("");
456 psz_parser = strstr( psz_string, psz_name );
462 psz_parser = psz_string;
463 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
464 psz_string, psz_name );
476 memmove( psz_parser, psz_parser + strlen(psz_name) +
477 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
478 strlen(psz_parser + strlen(psz_name)) + 1 );
480 /* Remove trailing : : */
481 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
483 *(psz_string+strlen(psz_string ) -1 ) = '\0';
492 /* Vout is not kept, so put that in the config */
493 config_PutPsz( p_intf, "vout-filter", psz_string );
495 /* Try to set on the fly */
496 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
500 var_SetString( p_vout, "vout-filter", psz_string );
501 vlc_object_release( p_vout );
508 - (void)changeAFiltersString: (char *)psz_name onOrOff: (BOOL)o_onOrOff;
510 char *psz_parser, *psz_string;
511 intf_thread_t * p_intf = VLCIntf;
512 aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
513 VLC_OBJECT_AOUT, FIND_ANYWHERE);
517 psz_string = var_GetString( p_aout, "audio-filter" );
521 psz_string = config_GetPsz( p_intf, "audio-filter" );
524 if( !psz_string ) psz_string = strdup("");
526 psz_parser = strstr( psz_string, psz_name );
532 psz_parser = psz_string;
533 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
534 psz_string, psz_name );
546 memmove( psz_parser, psz_parser + strlen(psz_name) +
547 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
548 strlen(psz_parser + strlen(psz_name)) + 1 );
550 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
552 *(psz_string+strlen(psz_string ) -1 ) = '\0';
564 config_PutPsz( p_intf, "audio-filter", psz_string );
568 var_SetString( p_aout, "audio-filter", psz_string );
570 while( i < p_aout->i_nb_inputs )
572 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
575 vlc_object_release( p_aout );