extended.m 26.7 KB
Newer Older
1
2
3
4
5
6
/*****************************************************************************
 * extended.m: MacOS X Extended interface panel
 *****************************************************************************
 * Copyright (C) 2005 the VideoLAN team
 * $Id$
 *
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
7
 * Authors: Felix Kühne <fkuehne@users.sf.net>
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
dionoea's avatar
dionoea committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
23
24
25
26
27
 *****************************************************************************/


/*****************************************************************************
 * Note: 
 * the code used to bind with VLC's modules is heavily based upon 
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
28
 * ../wxwidgets/extrapanel.cpp, written by Clément Stenac.
29
30
31
 * the code used to insert/remove the views was inspired by intf.m, 
 * written by Derk-Jan Hartman and Benjamin Pracht. 
 * (all 3 are members of the VideoLAN team) 
32
33
34
35
36
37
38
39
40
 *****************************************************************************/


/*****************************************************************************
 * Preamble
 *****************************************************************************/

#import "extended.h"
#import "intf.h"
41
#import "vout.h"
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#import <vlc/aout.h>
#import <aout_internal.h>
#import <vlc/vout.h>
#import <vlc/intf.h>

/*****************************************************************************
 * VLCExtended implementation
 *****************************************************************************/

@implementation VLCExtended

static VLCExtended *_o_sharedInstance = nil;

+ (VLCExtended *)sharedInstance
{
    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
}

- (id)init
{
    if (_o_sharedInstance) {
        [self dealloc];
    } else {
        _o_sharedInstance = [super init];
    }

    return _o_sharedInstance;
}

71
72
73
74
/*****************************************************************************
 * GUI methods
 *****************************************************************************/

75
76
77
78
- (void)initStrings
{
    /* localise GUI-strings */
    /* method is called from intf.m (in method showExtended) */
79
80
81
82
83
    [o_extended_window setTitle: _NS("Extended controls")];
    [o_lbl_video setStringValue: _NS("Video")];
    [o_lbl_audio setStringValue: _NS("Audio")];
    [o_lbl_audioFlts setStringValue: _NS("Audio filters")];
    [o_lbl_videoFlts setStringValue: _NS("Video filters")];
84
    [o_lbl_adjustImage setStringValue: _NS("Image adjustment")];
85
86
    [o_btn_vidFlts_mrInfo setTitle: _NS("More Info")];
    [o_ckb_blur setTitle: _NS("Blurring")];
87
    [o_ckb_blur setToolTip: _NS("Adds motion blurring to the image")];
88
    [o_ckb_distortion setTitle: _NS("Distortion")];
89
    [o_ckb_distortion setToolTip: _NS("Adds distortion effects")];
90
    [o_ckb_imgClone setTitle: _NS("Image clone")];
91
92
    [o_ckb_imgClone setToolTip: _NS("Creates several copies of the Video " \
                                    "output window" )];
93
    [o_ckb_imgCrop setTitle: _NS("Image cropping")];
94
    [o_ckb_imgCrop setToolTip: _NS("Crops a defined part of the image")];
95
    [o_ckb_imgInvers setTitle: _NS("Image inversion")];
96
    [o_ckb_imgInvers setToolTip: _NS("Inverts the colors of the image")];
97
    [o_ckb_trnsform setTitle: _NS("Transformation")];
98
    [o_ckb_trnsform setToolTip: _NS("Rotates or flips the image")];
99
    [o_ckb_vlme_norm setTitle: _NS("Volume normalization")];
100
101
    [o_ckb_vlme_norm setToolTip: _NS("Prevents the audio output from going " \
        "over a predefined value.")];
102
    [o_ckb_hdphnVirt setTitle: _NS("Headphone virtualization")];
103
104
    [o_ckb_hdphnVirt setToolTip: _NS("Imitates the effect of surround sound " \
        "when using headphones.")];
105
106
107
108
109
110
111
112
    [o_lbl_maxLevel setStringValue: _NS("Maximum level")];
    [o_btn_rstrDefaults setTitle: _NS("Restore Defaults")];
    [o_ckb_enblAdjustImg setTitle: _NS("Enable")];
    [o_lbl_brightness setStringValue: _NS("Brightness")];
    [o_lbl_contrast setStringValue: _NS("Contrast")];
    [o_lbl_gamma setStringValue: _NS("Gamma")];
    [o_lbl_hue setStringValue: _NS("Hue")];
    [o_lbl_saturation setStringValue: _NS("Saturation")];
113
    [o_lbl_opaque setStringValue: _NS("Opaqueness")];
114
    
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
}

- (void)awakeFromNib
{
    /* set the adjust-filter-sliders to the values from the prefs and enable
     * them, if wanted */
    char * psz_vfilters;
    intf_thread_t * p_intf = VLCIntf;
    psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
    if( psz_vfilters && strstr( psz_vfilters, "adjust" ) )
    {
        [o_ckb_enblAdjustImg setState: NSOnState];
        [o_btn_rstrDefaults setEnabled: YES];
        [o_sld_brightness setEnabled: YES];
        [o_sld_contrast setEnabled: YES];
        [o_sld_gamma setEnabled: YES];
        [o_sld_hue setEnabled: YES];
        [o_sld_saturation setEnabled: YES];
    }
    else
    {
        [o_ckb_enblAdjustImg setState: NSOffState];
        [o_btn_rstrDefaults setEnabled: NO];
        [o_sld_brightness setEnabled: NO];
        [o_sld_contrast setEnabled: NO];
        [o_sld_gamma setEnabled: NO];
        [o_sld_hue setEnabled: NO];
        [o_sld_saturation setEnabled: NO];
    }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    
    /* set the other video-filter-checkboxes to the correct values */
    if( psz_vfilters )
    {
        [o_ckb_blur setState: (int)strstr( psz_vfilters, "motionblur")];
        [o_ckb_distortion setState: (int)strstr( psz_vfilters, "distort")];
        [o_ckb_imgClone setState: (int)strstr( psz_vfilters, "clone")];
        [o_ckb_imgCrop setState: (int)strstr( psz_vfilters, "crop")];
        [o_ckb_imgInvers setState: (int)strstr( psz_vfilters, "invert")];
        [o_ckb_trnsform setState: (int)strstr( psz_vfilters, "transform")];
        
        free( psz_vfilters );
    }
    
    /* set the audio-filter-checkboxes to the values taken from the prefs */
    char * psz_afilters;
    psz_afilters = config_GetPsz( p_intf, "audio-filter" );
    if( psz_afilters )
    {
        [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
        [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
        
        free( psz_afilters );
    }
}

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
- (void)collapsAll
{
    /* collaps all views so Cocoa saves the window position correctly */
    if( o_adjImg_expanded )
    {
        [self extWin_exp_adjImg: nil];
    }
    if( o_audFlts_expanded )
    {
        [self extWin_exp_audFlts: nil];
    }
    if( o_vidFlts_expanded )
    {
        [self extWin_exp_vidFlts: nil];
    }
}

- (BOOL)getConfigChanged
{
    return o_config_changed;
}

192
193
194
195
196
- (void)showPanel
{
    /* get the correct slider values from the prefs, in case they were changed
     * elsewhere */
    intf_thread_t * p_intf = VLCIntf;
197
198
199
200
201
202

    int i_value = config_GetInt( p_intf, "hue" );
    if( i_value > 0 && i_value < 360 )
    {
        [o_sld_hue setIntValue: i_value];
    }
203

204
205
206
207
208
209
210
    float f_value;
    
    f_value = config_GetFloat( p_intf, "saturation" );
    if( f_value > 0 && f_value < 5 )
    {
        [o_sld_saturation setIntValue: (int)(100 * f_value) ];
    }
211

212
213
214
215
216
    f_value = config_GetFloat( p_intf, "contrast" );
    if( f_value > 0 && f_value < 4 )
    {
        [o_sld_contrast setIntValue: (int)(100 * f_value) ];
    }
217

218
219
220
221
222
    f_value = config_GetFloat( p_intf, "brightness" );
    if( f_value > 0 && f_value < 2 )
    {
        [o_sld_brightness setIntValue: (int)(100 * f_value) ];
    }
223

224
225
226
227
228
    f_value = config_GetFloat( p_intf, "gamma" );
    if( f_value > 0 && f_value < 10 )
    {
        [o_sld_gamma setIntValue: (int)(10 * f_value) ];
    }
229

230
231
232
233
234
    f_value = config_GetFloat( p_intf, "norm-max-level" );
    if( f_value > 0 && f_value < 10 )
    {
        [o_sld_maxLevel setFloatValue: f_value ];
    }
235

236
237
238
239
    [o_sld_opaque setFloatValue: (config_GetFloat( p_intf, \
        "macosx-opaqueness") * 100)];


240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
    /* show the window */
    [o_extended_window displayIfNeeded];
    [o_extended_window makeKeyAndOrderFront:nil];
}

- (IBAction)adjImg_Enbl:(id)sender
{
    /* en-/disable the sliders */
    if ([o_ckb_enblAdjustImg state] == NSOnState)
    {
        [o_btn_rstrDefaults setEnabled: YES];
        [o_sld_brightness setEnabled: YES];
        [o_sld_contrast setEnabled: YES];
        [o_sld_gamma setEnabled: YES];
        [o_sld_hue setEnabled: YES];
        [o_sld_saturation setEnabled: YES];
256
        [self changeVFiltersString: "adjust" onOrOff: VLC_TRUE];
257
258
259
260
261
262
263
    }else{
        [o_btn_rstrDefaults setEnabled: NO];
        [o_sld_brightness setEnabled: NO];
        [o_sld_contrast setEnabled: NO];
        [o_sld_gamma setEnabled: NO];
        [o_sld_hue setEnabled: NO];
        [o_sld_saturation setEnabled: NO];
264
        [self changeVFiltersString: "adjust" onOrOff: VLC_FALSE];
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    }
}

- (IBAction)adjImg_rstrDefaults:(id)sender
{
    /* reset the sliders */
    [o_sld_brightness setIntValue: 100];
    [o_sld_contrast setIntValue: 100];
    [o_sld_gamma setIntValue: 10];
    [o_sld_hue setIntValue: 0];
    [o_sld_saturation setIntValue: 100];
    
    /* transmit the values */
    [self adjImg_sliders: o_sld_brightness];
    [self adjImg_sliders: o_sld_contrast];
    [self adjImg_sliders: o_sld_gamma];
    [self adjImg_sliders: o_sld_hue];
    [self adjImg_sliders: o_sld_saturation];
}

- (IBAction)adjImg_sliders:(id)sender
{
    /* read-out the sliders' values and apply them */
    intf_thread_t * p_intf = VLCIntf;
    vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf,
                                 VLC_OBJECT_VOUT, FIND_ANYWHERE);
    if( p_vout == NULL )
    {
        if (sender == o_sld_brightness)
        {
            config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
        } else if (sender == o_sld_contrast)
        {
            config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
        } else if (sender == o_sld_gamma)
        {
            config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
        } else if (sender == o_sld_hue)
        {
            config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
        } else if (sender == o_sld_saturation)
        {
            config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
308
        } else {
309
            msg_Warn( p_intf, "the corresponding subfilter coundn't be found" );
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
        }
    } else {
        vlc_value_t val;
        if (sender == o_sld_brightness)
        {
            val.f_float = [o_sld_brightness floatValue] / 100;
            var_Set( p_vout, "brightness", val );
            config_PutFloat( p_intf , "brightness" , [o_sld_brightness floatValue] / 100);
        } else if (sender == o_sld_contrast)
        {
            val.f_float = [o_sld_contrast floatValue] / 100;
            var_Set( p_vout, "contrast", val );
            config_PutFloat( p_intf , "contrast" , [o_sld_contrast floatValue] / 100);
        } else if (sender == o_sld_gamma)
        {
            val.f_float = [o_sld_gamma floatValue] / 10;
            var_Set( p_vout, "gamma", val );
            config_PutFloat( p_intf , "gamma" , [o_sld_gamma floatValue] / 10);
        } else if (sender == o_sld_hue)
        {
            val.i_int = [o_sld_hue intValue];
            var_Set( p_vout, "hue", val );
            config_PutInt( p_intf , "hue" , [o_sld_hue intValue]);
        } else if (sender == o_sld_saturation)
        {
            val.f_float = [o_sld_saturation floatValue] / 100;
            var_Set( p_vout, "saturation", val );
            config_PutFloat( p_intf , "saturation" , [o_sld_saturation floatValue] / 100);
338
        } else {
339
            msg_Warn( p_intf, "the corresponding subfilter coundn't be found" );
340
        }
341
        vlc_object_release( p_vout );
342
    }
343
344

    o_config_changed = YES;
345
346
}

hartman's avatar
hartman committed
347
/* change the opaqueness of the vouts */
348
349
- (IBAction)adjImg_opaque:(id)sender
{
hartman's avatar
hartman committed
350
351
352
353
    vlc_value_t val;
    id o_window = [NSApp keyWindow];
    NSArray *o_windows = [NSApp orderedWindows];
    NSEnumerator *o_enumerator = [o_windows objectEnumerator];
354
355
    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
        FIND_ANYWHERE );
hartman's avatar
hartman committed
356
357
    vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
    vout_thread_t *p_real_vout;
358

359
360
    val.f_float = [o_sld_opaque floatValue] / 100;

361

hartman's avatar
hartman committed
362
    if( p_vout != NULL )
363
    {
364
        p_real_vout = [VLCVoutView getRealVout: p_vout];
hartman's avatar
hartman committed
365
        var_Set( p_real_vout, "macosx-opaqueness", val );
366

hartman's avatar
hartman committed
367
368
        while ((o_window = [o_enumerator nextObject]))
        {
369
370
371
            if( [[o_window className] isEqualToString: @"VLCWindow"] ||
                [[[VLCMain sharedInstance] getEmbeddedList]
                                    windowContainsEmbedded: o_window])
hartman's avatar
hartman committed
372
373
374
            {
                [o_window setAlphaValue: val.f_float];
            }
375
            break;
hartman's avatar
hartman committed
376
        }
377
378
379
380
381
382
383
        vlc_object_release( p_vout );
    }
    
    /* store to prefs */
    config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
    
    vlc_object_release( p_playlist );
384
385

    o_config_changed = YES;
386
387
}

388
389
390
391
392
- (IBAction)audFtls_hdphnVirt:(id)sender
{
    /* en-/disable headphone virtualisation */
    if ([o_ckb_hdphnVirt state] == NSOnState)
    {
393
        [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_TRUE ];
394
    }else{
395
        [self changeAFiltersString: "headphone_channel_mixer" onOrOff: VLC_FALSE ];
396
397
398
399
400
401
402
403
404
405
406
    }
}

- (IBAction)audFtls_maxLevelSld:(id)sender
{
    /* read-out the slider's value and apply it */
    intf_thread_t * p_intf = VLCIntf;
    aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
    if( p_aout != NULL )
    {
407
        var_SetFloat( p_aout, "norm-max-level", [o_sld_maxLevel floatValue] );
408
409
        vlc_object_release( p_aout );
    }
410
411
412
    config_PutFloat( p_intf, "norm-max-level", [o_sld_maxLevel floatValue] );

    o_config_changed = YES;
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
}

- (IBAction)audFtls_vlmeNorm:(id)sender
{
    /* en-/disable volume normalisation */
    if ([o_ckb_vlme_norm state] == NSOnState)
    {
        [self changeAFiltersString: "normvol" onOrOff: YES ];
    }else{
        [self changeAFiltersString: "normvol" onOrOff: NO ];
    }
}

- (IBAction)extWin_exp_adjImg:(id)sender
{
    /* expand or collapse adjImg */
    NSRect o_win_rect = [o_extended_window frame];
    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
    NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
    NSRect o_box_adjImg_rect = [o_box_adjImg frame];
    
    if (o_adjImg_expanded)
    {
        /* move the window contents upwards (partially done through settings
         * inside the nib) and resize the window */
438
439
440
441
        o_win_rect.size.height = o_win_rect.size.height - 171;
        o_win_rect.origin.y = [o_extended_window frame].origin.y + 171;
        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 171;
        o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 171;
442
443
444
445
446
447
        
        /* remove the inserted view */
        [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
    }else{
    
        /* move the window contents downwards and resize the window */
448
449
450
451
        o_win_rect.size.height = o_win_rect.size.height + 171;
        o_win_rect.origin.y = [o_extended_window frame].origin.y - 171;
        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 171;
        o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 171;
452
453
454
455
456
457
458
459
460
    }
    
    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
    [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
    [o_extended_window displayIfNeeded];
    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
    
    if (o_adjImg_expanded)
    {
461
        o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 171;
462
        msg_Dbg( VLCIntf, "collapsed adjust-image section");
463
464
465
        o_adjImg_expanded = NO;
    } else {
        /* insert view */
466
467
        o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 171;
        [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 181)];
468
469
470
        [o_adjustImg_view setNeedsDisplay:YES];
        [o_adjustImg_view setAutoresizesSubviews: YES];
        [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
471
        msg_Dbg( VLCIntf, "expanded adjust-image section");
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
        o_adjImg_expanded = YES;
    }
    [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
}

- (IBAction)extWin_exp_audFlts:(id)sender
{
    /* expand or collapse audFlts */
    NSRect o_win_rect = [o_extended_window frame];
    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
    
    if (o_audFlts_expanded)
    {
        /* move the window contents upwards (partially done through settings
         * inside the nib) and resize the window */
        o_win_rect.size.height = o_win_rect.size.height - 66;
        o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
        
        /* remove the inserted view */
        [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
    }else{
        /* move the window contents downwards and resize the window */
        o_win_rect.size.height = o_win_rect.size.height + 66;
        o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
    }
    [o_extended_window displayIfNeeded];
    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
    
    
    if (o_audFlts_expanded)
    {
        o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
504
        msg_Dbg( VLCIntf, "collapsed audio-filters section");
505
506
507
508
509
510
511
512
        o_audFlts_expanded = NO;
    } else {
        /* insert view */
        o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
        [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
        [o_audioFlts_view setNeedsDisplay:YES];
        [o_audioFlts_view setAutoresizesSubviews: YES];
        [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
513
        msg_Dbg( VLCIntf, "expanded audio-filters section");
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
        o_audFlts_expanded = YES;
    }
    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
}

- (IBAction)extWin_exp_vidFlts:(id)sender
{
    /* expand or collapse vidFlts */
    NSRect o_win_rect = [o_extended_window frame];
    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
    NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
    
    if (o_vidFlts_expanded)
    {
        /* move the window contents upwards (partially done through settings
         * inside the nib) and resize the window */
        o_win_rect.size.height = o_win_rect.size.height - 134;
        o_win_rect.origin.y = [o_extended_window frame].origin.y + 134;
        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 134;
        
        /* remove the inserted view */
        [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
    }else{
    
        /* move the window contents downwards and resize the window */
        o_win_rect.size.height = o_win_rect.size.height + 134;
        o_win_rect.origin.y = [o_extended_window frame].origin.y - 134;
        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 134;
    }
    
    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
    [o_extended_window displayIfNeeded];
    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
    
    if (o_vidFlts_expanded)
    {
        o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 134;
551
        msg_Dbg( VLCIntf, "collapsed video-filters section");
552
553
554
555
556
557
558
559
        o_vidFlts_expanded = NO;
    } else {
        /* insert view */
        o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 134;
        [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 144)];
        [o_videoFilters_view setNeedsDisplay:YES];
        [o_videoFilters_view setAutoresizesSubviews: YES];
        [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
560
        msg_Dbg( VLCIntf, "expanded video-filters section");
561
562
563
564
565
566
567
568
        o_vidFlts_expanded = YES;
    }
    [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
}

- (IBAction)vidFlts:(id)sender
{
    /* en-/disable video filters */
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
    if (sender == o_ckb_blur)
    {
        [self changeVFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
    }
    else if (sender == o_ckb_distortion)
    {
        [self changeVFiltersString: "distort" onOrOff: [o_ckb_distortion state]];
    }
    else if (sender == o_ckb_imgClone)
    {
        [self changeVFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
    }
    else if (sender == o_ckb_imgCrop)
    {
        [self changeVFiltersString: "crop" onOrOff: [o_ckb_imgCrop state]];
    }
    else if (sender == o_ckb_imgInvers)
    {
        [self changeVFiltersString: "invert" onOrOff: [o_ckb_imgInvers state]];
    }
    else if (sender == o_ckb_trnsform)
    {
        [self changeVFiltersString: "transform" onOrOff: [o_ckb_trnsform state]];
    } else {
        /* this shouldn't happen */
        msg_Warn (VLCIntf, "cannot find selected video-filter");
    }
596
597
598
599
600
}

- (IBAction)vidFlts_mrInfo:(id)sender
{
    /* show info sheet */
601
    NSBeginInformationalAlertSheet(_NS("More Information"), _NS("OK"), @"", @"", \
602
603
604
605
606
607
        o_extended_window, nil, nil, nil, nil, _NS("This panel allows to " \
        "select video effects filters to apply.\n" \
        "The filters can be configured indivudually in the Preferences, in " \
        "the subsections of Video/Filters\n." \
        "To choose the order in which the filter are applied, a filter " \
        "option string can be set in the Preferences, Video / Filters section."));
608
609
}

610
611
612
613
614

/*****************************************************************************
 * methods to communicate changes to VLC's core
 *****************************************************************************/

615
- (void)changeVFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add 
616
617
618
619
620
621
622
623
624
625
626
627
628
629
{
    /* copied from ../wxwidgets/extrapanel.cpp
     * renamed to conform with Cocoa's rules */
     
    vout_thread_t *p_vout;
    intf_thread_t * p_intf = VLCIntf;
    
    char *psz_parser, *psz_string;
    psz_string = config_GetPsz( p_intf, "vout-filter" );
    
    if( !psz_string ) psz_string = strdup("");

    psz_parser = strstr( psz_string, psz_name );

630
    if( b_add )
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
    {
        if( !psz_parser )
        {
            psz_parser = psz_string;
            asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
                            psz_string, psz_name );
            free( psz_parser );
        }
        else
        {
            return;
        }
    }
    else
    {
        if( psz_parser )
        {
            memmove( psz_parser, psz_parser + strlen(psz_name) +
                            (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
                            strlen(psz_parser + strlen(psz_name)) + 1 );

            /* Remove trailing : : */
            if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
            {
                *(psz_string+strlen(psz_string ) -1 ) = '\0';
            }
         }
         else
         {
             free( psz_string );
             return;
         }
    }
    /* Vout is not kept, so put that in the config */
    config_PutPsz( p_intf, "vout-filter", psz_string );

    /* Try to set on the fly */
    p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                              FIND_ANYWHERE );
    if( p_vout )
    {
        var_SetString( p_vout, "vout-filter", psz_string );
        vlc_object_release( p_vout );
    }

    free( psz_string );
677
678

    o_config_changed = YES;
679
680
681
}


682
- (void)changeAFiltersString: (char *)psz_name onOrOff: (vlc_bool_t )b_add;
683
{
684
685
686
    /* copied from ../wxwidgets/extrapanel.cpp
     * renamed to conform with Cocoa's rules */

687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
    char *psz_parser, *psz_string;
    intf_thread_t * p_intf = VLCIntf;
    aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);

    if( p_aout )
    {
        psz_string = var_GetString( p_aout, "audio-filter" );
    }
    else
    {
        psz_string = config_GetPsz( p_intf, "audio-filter" );
    }

    if( !psz_string ) psz_string = strdup("");

    psz_parser = strstr( psz_string, psz_name );

705
    if( b_add )
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
    {
        if( !psz_parser )
        {
            psz_parser = psz_string;
            asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
                            psz_string, psz_name );
            free( psz_parser );
        }
        else
        {
            return;
        }
    }
    else
    {
        if( psz_parser )
        {
            memmove( psz_parser, psz_parser + strlen(psz_name) +
                            (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
                            strlen(psz_parser + strlen(psz_name)) + 1 );

            if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
            {
                *(psz_string+strlen(psz_string ) -1 ) = '\0';
            }
         }
         else
         {
             free( psz_string );
             return;
         }
    }

    if( p_aout == NULL )
    {
        config_PutPsz( p_intf, "audio-filter", psz_string );
    }
    else
    {
        var_SetString( p_aout, "audio-filter", psz_string );
        int i = 0;
        while( i < p_aout->i_nb_inputs )
        {
            p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
            i = (i + 1);
        }
        vlc_object_release( p_aout );
    }
    free( psz_string );
755
756

    o_config_changed = YES;
757
758
759
760
761
762
}

- (void)savePrefs
{    
    /* save the preferences to make sure that our module-changes will up on
     * next launch again */
763
764
    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST, \
        FIND_ANYWHERE );
765
    int returnedValue;
766
767
768
769
770
771
    NSArray * theModules;
    theModules = [[NSArray alloc] initWithObjects: @"main", @"headphone", \
        @"transform", @"adjust", @"invert", @"motionblur", @"distort", \
        @"clone", @"crop", @"normvol", @"headphone_channel_mixer", @"macosx", \
        nil];
    unsigned int x = 0;
772
    
773
    while ( x != [theModules count] )
774
    {
775
776
777
778
779
        returnedValue = config_SaveConfigFile( p_playlist, [[theModules \
            objectAtIndex: x] UTF8String] );

        if (returnedValue != 0)
        {
780
            msg_Err(p_playlist, "unable to save the preferences of the " \
781
782
            "extended control attribute '%s' (%i)", 
            [[theModules objectAtIndex: x] UTF8String] , returnedValue);
783
784
785
786
787
788
789
            [theModules release];
            vlc_object_release( p_playlist );
            
            return;
        }

        x = ( x + 1 );
790
    }
791
792
793
794
    
    msg_Dbg( p_playlist, "VLCExtended: saved certain preferences successfully" );
    
    [theModules release];
795
796
    vlc_object_release( p_playlist );
}
797
@end