]> git.sesse.net Git - vlc/blob - modules/gui/macosx/VideoEffects.m
macosx: don't use Carbon to retrieve icons from the OS
[vlc] / modules / gui / macosx / VideoEffects.m
1 /*****************************************************************************
2  * VideoEffects.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
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 #import "intf.h"
25 #import <vlc_common.h>
26 #import "VideoEffects.h"
27
28 #pragma mark -
29 #pragma mark Initialization & Generic code
30
31 @implementation VLCVideoEffects
32 static VLCVideoEffects *_o_sharedInstance = nil;
33
34 + (VLCVideoEffects *)sharedInstance
35 {
36     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
37 }
38
39 - (id)init
40 {
41     if (_o_sharedInstance) {
42         [self dealloc];
43     } else {
44         p_intf = VLCIntf;
45         _o_sharedInstance = [super init];
46     }
47     
48     return _o_sharedInstance;
49 }
50
51 - (IBAction)toggleWindow:(id)sender
52 {
53     if( [o_window isVisible] )
54         [o_window orderOut:sender];
55     else
56         [o_window makeKeyAndOrderFront:sender];
57 }
58
59 - (void)awakeFromNib
60 {
61     [o_window setTitle: _NS("Video Effects")];
62     [o_window setExcludedFromWindowsMenu:YES];
63     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"basic"]] setLabel:_NS("Basic")];
64     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"crop"]] setLabel:_NS("Crop")];
65     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"geometry"]] setLabel:_NS("Geometry")];
66     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"color"]] setLabel:_NS("Color")];
67     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"overlay"]] setLabel:_NS("Video output/Overlay")];
68     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"logo"]] setLabel:_NS("Logo")];
69
70     [o_adjust_ckb setTitle:_NS("Image Adjust")];
71     [o_adjust_hue_lbl setStringValue:_NS("Hue")];
72     [o_adjust_contrast_lbl setStringValue:_NS("Contrast")];
73     [o_adjust_brightness_lbl setStringValue:_NS("Brightness")];
74     [o_adjust_brightness_ckb setTitle:_NS("Brightness Threshold")];
75     [o_adjust_saturation_lbl setStringValue:_NS("Saturation")];
76     [o_adjust_gamma_lbl setStringValue:_NS("Gamma")];
77     [o_adjust_opaque_lbl setStringValue:_NS("Opaqueness")];
78     [o_sharpen_ckb setTitle:_NS("Sharpen")];
79     [o_sharpen_lbl setStringValue:_NS("Sigma")];
80     [o_banding_ckb setTitle:_NS("Banding removal")];
81     [o_banding_lbl setStringValue:_NS("Radius")];
82     [o_grain_ckb setTitle:_NS("Film Grain")];
83     [o_grain_lbl setStringValue:_NS("Variance")];
84     [o_crop_top_lbl setStringValue:_NS("Top")];
85     [o_crop_left_lbl setStringValue:_NS("Left")];
86     [o_crop_right_lbl setStringValue:_NS("Right")];
87     [o_crop_bottom_lbl setStringValue:_NS("Bottom")];
88     [o_crop_sync_top_bottom_ckb setTitle:_NS("Synchronize top and bottom")];
89     [o_crop_sync_left_right_ckb setTitle:_NS("Synchronize left and right")];
90
91     [o_transform_ckb setTitle:_NS("Transform")];
92     [o_transform_pop removeAllItems];
93     [o_transform_pop addItemWithTitle: _NS("Rotate by 90 degrees")];
94     [[o_transform_pop lastItem] setTag: 90];
95     [o_transform_pop addItemWithTitle: _NS("Rotate by 180 degrees")];
96     [[o_transform_pop lastItem] setTag: 180];
97     [o_transform_pop addItemWithTitle: _NS("Rotate by 270 degrees")];
98     [[o_transform_pop lastItem] setTag: 270];
99     [o_transform_pop addItemWithTitle: _NS("Flip horizontally")];
100     [[o_transform_pop lastItem] setTag: 1];
101     [o_transform_pop addItemWithTitle: _NS("Flip vertically")];
102     [[o_transform_pop lastItem] setTag: 2];
103     [o_zoom_ckb setTitle:_NS("Magnification/Zoom")];
104     [o_puzzle_ckb setTitle:_NS("Puzzle game")];
105     [o_puzzle_rows_lbl setStringValue:_NS("Rows")];
106     [o_puzzle_columns_lbl setStringValue:_NS("Columns")];
107     [o_puzzle_blackslot_ckb setTitle:_NS("Black Slot")];
108
109     [o_threshold_ckb setTitle:_NS("Color threshold")];
110     [o_threshold_color_lbl setStringValue:_NS("Color")];
111     [o_threshold_saturation_lbl setStringValue:_NS("Saturation")];
112     [o_threshold_similarity_lbl setStringValue:_NS("Similarity")];
113     [o_sepia_ckb setTitle:_NS("Sepia")];
114     [o_sepia_lbl setStringValue:_NS("Intensity")];
115     [o_noise_ckb setTitle:_NS("Noise")];
116     [o_gradient_ckb setTitle:_NS("Gradient")];
117     [o_gradient_mode_lbl setStringValue:_NS("Mode")];
118     [o_gradient_mode_pop removeAllItems];
119     [o_gradient_mode_pop addItemWithTitle: _NS("Gradient")];
120     [[o_gradient_mode_pop lastItem] setTag: 1];
121     [o_gradient_mode_pop addItemWithTitle: _NS("Edge")];
122     [[o_gradient_mode_pop lastItem] setTag: 2];
123     [o_gradient_mode_pop addItemWithTitle: _NS("Hough")];
124     [[o_gradient_mode_pop lastItem] setTag: 3];
125     [o_gradient_color_ckb setTitle:_NS("Color")];
126     [o_gradient_cartoon_ckb setTitle:_NS("Cartoon")];
127     [o_extract_ckb setTitle:_NS("Color extraction")];
128     [o_extract_lbl setStringValue:_NS("Color")];
129     [o_invert_ckb setTitle:_NS("Invert colors")];
130     [o_posterize_ckb setTitle:_NS("Posterize")];
131     [o_posterize_lbl setStringValue:_NS("Posterize level")];
132     [o_blur_ckb setTitle:_NS("Motion blue")];
133     [o_blur_lbl setStringValue:_NS("Factor")];
134     [o_motiondetect_ckb setTitle:_NS("Motion Detect")];
135     [o_watereffect_ckb setTitle:_NS("Water effect")];
136     [o_waves_ckb setTitle:_NS("Waves")];
137     [o_psychedelic_ckb setTitle:_NS("Psychedelic")];
138
139     [o_clone_ckb setTitle:_NS("Image clone")];
140     [o_clone_lbl setStringValue:_NS("Number of clones")];
141     [o_addtext_ckb setTitle:_NS("Add text")];
142     [o_addtext_text_lbl setStringValue:_NS("Text")];
143     [o_addtext_pos_lbl setStringValue:_NS("Position")];
144     [o_addtext_pos_pop removeAllItems];
145     [o_addtext_pos_pop addItemWithTitle: _NS("Center")];
146     [[o_addtext_pos_pop lastItem] setTag: 0];
147     [o_addtext_pos_pop addItemWithTitle: _NS("Left")];
148     [[o_addtext_pos_pop lastItem] setTag: 1];
149     [o_addtext_pos_pop addItemWithTitle: _NS("Right")];
150     [[o_addtext_pos_pop lastItem] setTag: 2];
151     [o_addtext_pos_pop addItemWithTitle: _NS("Top")];
152     [[o_addtext_pos_pop lastItem] setTag: 4];
153     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom")];
154     [[o_addtext_pos_pop lastItem] setTag: 8];
155     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Left")];
156     [[o_addtext_pos_pop lastItem] setTag: 5];
157     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Right")];
158     [[o_addtext_pos_pop lastItem] setTag: 6];
159     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Left")];
160     [[o_addtext_pos_pop lastItem] setTag: 9];
161     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Right")];
162     [[o_addtext_pos_pop lastItem] setTag: 10];
163
164     [o_addlogo_ckb setTitle:_NS("Add logo")];
165     [o_addlogo_logo_lbl setStringValue:_NS("Logo")];
166     [o_addlogo_top_lbl setStringValue:_NS("Top")];
167     [o_addlogo_left_lbl setStringValue:_NS("Left")];
168     [o_addlogo_transparency_lbl setStringValue:_NS("Transparency")];
169     [o_eraselogo_ckb setTitle:_NS("Logo erase")];
170     [o_eraselogo_mask_lbl setStringValue:_NS("Mask")];
171     [o_eraselogo_top_lbl setStringValue:_NS("Top")];
172     [o_eraselogo_left_lbl setStringValue:_NS("Left")];
173
174     [o_tableView selectFirstTabViewItem:self];
175
176     [self resetValues];
177 }
178
179 - (void)resetValues
180 {
181     NSString *tmpString;
182     char *tmpChar;
183     /* do we have any filter enabled? if yes, show it. */
184     char * psz_vfilters;
185     psz_vfilters = config_GetPsz( p_intf, "video-filter" );
186     if( psz_vfilters ) {
187         [o_adjust_ckb setState: (NSInteger)strstr( psz_vfilters, "adjust")];
188         [o_sharpen_ckb setState: (NSInteger)strstr( psz_vfilters, "sharpen")];
189         [o_banding_ckb setState: (NSInteger)strstr( psz_vfilters, "gradfun")];
190         [o_grain_ckb setState: (NSInteger)strstr( psz_vfilters, "grain")];
191         [o_transform_ckb setState: (NSInteger)strstr( psz_vfilters, "transform")];
192         [o_zoom_ckb setState: (NSInteger)strstr( psz_vfilters, "magnify")];
193         [o_puzzle_ckb setState: (NSInteger)strstr( psz_vfilters, "puzzle")];
194         [o_threshold_ckb setState: (NSInteger)strstr( psz_vfilters, "colorthres")];
195         [o_sepia_ckb setState: (NSInteger)strstr( psz_vfilters, "sepia")];
196         [o_noise_ckb setState: (NSInteger)strstr( psz_vfilters, "noise")];
197         [o_gradient_ckb setState: (NSInteger)strstr( psz_vfilters, "gradient")];
198         [o_extract_ckb setState: (NSInteger)strstr( psz_vfilters, "extract")];
199         [o_invert_ckb setState: (NSInteger)strstr( psz_vfilters, "invert")];
200         [o_posterize_ckb setState: (NSInteger)strstr( psz_vfilters, "posterize")];
201         [o_blur_ckb setState: (NSInteger)strstr( psz_vfilters, "motionblur")];
202         [o_motiondetect_ckb setState: (NSInteger)strstr( psz_vfilters, "motiondetect")];
203         [o_watereffect_ckb setState: (NSInteger)strstr( psz_vfilters, "ripple")];
204         [o_waves_ckb setState: (NSInteger)strstr( psz_vfilters, "wave")];
205         [o_psychedelic_ckb setState: (NSInteger)strstr( psz_vfilters, "psychedelic")];
206         [o_clone_ckb setState: (NSInteger)strstr( psz_vfilters, "clone")];
207         free( psz_vfilters );
208     }
209     // TODO: don't forget about o_addtext_ckb, o_addlogo_ckb, o_eraselogo_ckb
210
211     /* fetch and show the various values */
212     [o_adjust_hue_sld setIntValue: config_GetInt( p_intf, "hue" )];
213     [o_adjust_contrast_sld setFloatValue: config_GetFloat( p_intf, "contrast" )];
214     [o_adjust_brightness_sld setFloatValue: config_GetFloat( p_intf, "brightness" )];
215     [o_adjust_saturation_sld setFloatValue: config_GetFloat( p_intf, "saturation" )];
216     [o_adjust_gamma_sld setFloatValue: config_GetFloat( p_intf, "gamma" )];
217     [o_adjust_brightness_sld setEnabled: [o_adjust_ckb state]];
218     [o_adjust_brightness_ckb setEnabled: [o_adjust_ckb state]];
219     [o_adjust_contrast_sld setEnabled: [o_adjust_ckb state]];
220     [o_adjust_gamma_sld setEnabled: [o_adjust_ckb state]];
221     [o_adjust_hue_sld setEnabled: [o_adjust_ckb state]];
222     [o_adjust_saturation_sld setEnabled: [o_adjust_ckb state]];
223     [o_adjust_brightness_lbl setEnabled: [o_adjust_ckb state]];
224     [o_adjust_contrast_lbl setEnabled: [o_adjust_ckb state]];
225     [o_adjust_gamma_lbl setEnabled: [o_adjust_ckb state]];
226     [o_adjust_hue_lbl setEnabled: [o_adjust_ckb state]];
227     [o_adjust_saturation_lbl setEnabled: [o_adjust_ckb state]];
228     [o_adjust_opaque_sld setFloatValue: config_GetFloat( p_intf, "macosx-opaqueness" )];
229     [o_adjust_opaque_sld setEnabled: [o_adjust_ckb state]];
230     [o_adjust_opaque_lbl setEnabled: [o_adjust_ckb state]];
231     [o_sharpen_sld setFloatValue: config_GetFloat( p_intf, "sharpen-sigma" )];
232     [o_sharpen_sld setEnabled: [o_sharpen_ckb state]];
233     [o_sharpen_lbl setEnabled: [o_sharpen_ckb state]];
234     [o_banding_sld setIntValue: config_GetInt( p_intf, "gradfun-radius" )];
235     [o_banding_sld setEnabled: [o_banding_ckb state]];
236     [o_banding_lbl setEnabled: [o_banding_ckb state]];
237     [o_grain_sld setFloatValue: config_GetFloat( p_intf, "grain-variance" )];
238     [o_grain_sld setEnabled: [o_grain_ckb state]];
239     [o_grain_lbl setEnabled: [o_grain_ckb state]];
240
241     [o_crop_top_fld setIntValue: 0];
242     [o_crop_left_fld setIntValue: 0];
243     [o_crop_right_fld setIntValue: 0];
244     [o_crop_bottom_fld setIntValue: 0];
245     [o_crop_sync_top_bottom_ckb setState: NSOffState];
246     [o_crop_sync_left_right_ckb setState: NSOffState];
247
248     tmpChar = config_GetPsz( p_intf, "transform-type" );
249     tmpString = [NSString stringWithUTF8String: tmpChar];
250     if( [tmpString isEqualToString:@"hflip"] )
251         [o_transform_pop selectItemWithTag: 1];
252     else if( [tmpString isEqualToString:@"vflip"] )
253         [o_transform_pop selectItemWithTag: 2];
254     else
255         [o_transform_pop selectItemWithTag:[tmpString intValue]];
256     FREENULL( tmpChar );
257     [o_transform_pop setEnabled: [o_transform_ckb state]];
258     [o_puzzle_rows_fld setIntValue: config_GetInt( p_intf, "puzzle-rows" )];
259     [o_puzzle_columns_fld setIntValue: config_GetInt( p_intf, "puzzle-cols" )];
260     [o_puzzle_blackslot_ckb setState: config_GetInt( p_intf, "puzzle-black-slot" )];
261     [o_puzzle_rows_fld setEnabled: [o_puzzle_ckb state]];
262     [o_puzzle_rows_lbl setEnabled: [o_puzzle_ckb state]];
263     [o_puzzle_columns_fld setEnabled: [o_puzzle_ckb state]];
264     [o_puzzle_columns_lbl setEnabled: [o_puzzle_ckb state]];
265     [o_puzzle_blackslot_ckb setEnabled: [o_puzzle_ckb state]];
266
267     [o_threshold_color_fld setStringValue: [[NSString stringWithFormat:@"%x", config_GetInt( p_intf, "colorthres-color" )] uppercaseString]];
268     [o_threshold_saturation_sld setIntValue: config_GetInt( p_intf, "colorthres-saturationthres" )];
269     [o_threshold_similarity_sld setIntValue: config_GetInt( p_intf, "colorthres-similaritythres" )];
270     [o_threshold_color_fld setEnabled: [o_threshold_ckb state]];
271     [o_threshold_color_lbl setEnabled: [o_threshold_ckb state]];
272     [o_threshold_saturation_sld setEnabled: [o_threshold_ckb state]];
273     [o_threshold_saturation_lbl setEnabled: [o_threshold_ckb state]];
274     [o_threshold_similarity_sld setEnabled: [o_threshold_ckb state]];
275     [o_threshold_similarity_lbl setEnabled: [o_threshold_ckb state]];
276     [o_sepia_fld setIntValue: config_GetInt( p_intf, "sepia-intensity" )];
277     [o_sepia_fld setEnabled: [o_sepia_ckb state]];
278     [o_sepia_lbl setEnabled: [o_sepia_ckb state]];
279     tmpChar = config_GetPsz( p_intf, "gradient-mode" );
280     tmpString = [NSString stringWithUTF8String: tmpChar];
281     if( [tmpString isEqualToString:@"hough"] )
282         [o_gradient_mode_pop selectItemWithTag: 3];
283     else if( [tmpString isEqualToString:@"edge"] )
284         [o_gradient_mode_pop selectItemWithTag: 2];
285     else
286         [o_gradient_mode_pop selectItemWithTag: 1];
287     FREENULL( tmpChar );
288     [o_gradient_cartoon_ckb setState: config_GetInt( p_intf, "gradient-cartoon" )];
289     [o_gradient_color_ckb setState: config_GetInt( p_intf, "gradient-type" )];
290     [o_gradient_mode_pop setEnabled: [o_gradient_ckb state]];
291     [o_gradient_mode_lbl setEnabled: [o_gradient_ckb state]];
292     [o_gradient_cartoon_ckb setEnabled: [o_gradient_ckb state]];
293     [o_gradient_color_ckb setEnabled: [o_gradient_ckb state]];
294     [o_extract_fld setStringValue: [[NSString stringWithFormat:@"%x", config_GetInt( p_intf, "extract-component" )] uppercaseString]];
295     [o_extract_fld setEnabled: [o_extract_ckb state]];
296     [o_extract_lbl setEnabled: [o_extract_ckb state]];
297     [o_posterize_fld setIntValue: config_GetInt( p_intf, "posterize-level" )];
298     [o_posterize_fld setEnabled: [o_posterize_ckb state]];
299     [o_posterize_lbl setEnabled: [o_posterize_ckb state]];
300     [o_blur_sld setIntValue: config_GetInt( p_intf, "blur-factor" )];
301     [o_blur_sld setEnabled: [o_blur_ckb state]];
302     [o_blur_lbl setEnabled: [o_blur_ckb state]];
303
304     [o_clone_fld setIntValue: config_GetInt( p_intf, "clone-count" )];
305     [o_clone_fld setEnabled: [o_clone_ckb state]];
306     [o_clone_lbl setEnabled: [o_clone_ckb state]];
307     tmpChar = config_GetPsz( p_intf, "marq-marquee" );
308     if( tmpChar )
309     {
310         [o_addtext_text_fld setStringValue: [NSString stringWithUTF8String: tmpChar]];
311         FREENULL( tmpChar );
312     }
313     [o_addtext_pos_pop selectItemWithTag: config_GetInt( p_intf, "marq-position" )];
314     [o_addtext_pos_pop setEnabled: [o_addtext_ckb state]];
315     [o_addtext_pos_lbl setEnabled: [o_addtext_ckb state]];
316     [o_addtext_text_lbl setEnabled: [o_addtext_ckb state]];
317     [o_addtext_text_fld setEnabled: [o_addtext_ckb state]];
318
319     tmpChar = config_GetPsz( p_intf, "logo-file" );
320     if( tmpChar )
321     {
322        [o_addlogo_logo_fld setStringValue: [NSString stringWithUTF8String: tmpChar]];
323         FREENULL( tmpChar );
324     }
325     [o_addlogo_top_fld setIntValue: config_GetInt( p_intf, "logo-x" )];
326     [o_addlogo_left_fld setIntValue: config_GetInt( p_intf, "logo-y" )];
327     [o_addlogo_transparency_sld setIntValue: config_GetInt( p_intf, "logo-opacity" )];
328     [o_addlogo_logo_fld setEnabled: [o_addlogo_ckb state]];
329     [o_addlogo_logo_lbl setEnabled: [o_addlogo_ckb state]];
330     [o_addlogo_left_fld setEnabled: [o_addlogo_ckb state]];
331     [o_addlogo_left_lbl setEnabled: [o_addlogo_ckb state]];
332     [o_addlogo_top_fld setEnabled: [o_addlogo_ckb state]];
333     [o_addlogo_top_lbl setEnabled: [o_addlogo_ckb state]];
334     [o_addlogo_transparency_sld setEnabled: [o_addlogo_ckb state]];
335     [o_addlogo_transparency_lbl setEnabled: [o_addlogo_ckb state]];
336     tmpChar = config_GetPsz( p_intf, "erase-mask" );
337     if( tmpChar )
338     {
339         [o_eraselogo_mask_fld setStringValue: [NSString stringWithUTF8String: tmpChar]];
340         FREENULL( tmpChar );
341     }
342     [o_eraselogo_top_fld setIntValue: config_GetInt( p_intf, "erase-x" )];
343     [o_eraselogo_left_fld setIntValue: config_GetInt( p_intf, "erase-y" )];
344     [o_eraselogo_mask_fld setEnabled: [o_eraselogo_ckb state]];
345     [o_eraselogo_mask_lbl setEnabled: [o_eraselogo_ckb state]];
346     [o_eraselogo_left_fld setEnabled: [o_eraselogo_ckb state]];
347     [o_eraselogo_left_lbl setEnabled: [o_eraselogo_ckb state]];
348     [o_eraselogo_top_fld setEnabled: [o_eraselogo_ckb state]];
349     [o_eraselogo_top_lbl setEnabled: [o_eraselogo_ckb state]];
350 }
351
352 - (void)setVideoFilter: (char *)psz_name on:(BOOL)b_on
353 {
354     char *psz_tmp;
355     vout_thread_t * p_vout = getVout();
356     if( p_vout )
357         psz_tmp = var_GetNonEmptyString( p_vout, "video-filter" );
358     else
359         psz_tmp = config_GetPsz( p_intf, "video-filter" );
360
361     if( b_on )
362     {
363         if(! psz_tmp)
364             config_PutPsz( p_intf, "video-filter", psz_name );
365         else if( (NSInteger)strstr( psz_tmp, psz_name ) == NO )
366         {
367             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:%s", psz_tmp, psz_name] UTF8String];
368             config_PutPsz( p_intf, "video-filter", psz_tmp );
369         }
370     } else {
371         if( psz_tmp )
372         {
373             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@":%s",psz_name]]] UTF8String];
374             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%s:",psz_name]]] UTF8String];
375             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithUTF8String:psz_name]]] UTF8String];
376             config_PutPsz( p_intf, "video-filter", psz_tmp );
377         }
378     }
379
380     if( p_vout ) {
381         var_SetString( p_vout, "video-filter", psz_tmp );
382         vlc_object_release( p_vout );
383     }
384 }
385
386 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter integer: (int)i_value
387 {
388     vout_thread_t *p_vout = getVout();
389     vlc_object_t *p_filter;
390
391     if( p_vout == NULL ) {
392         config_PutInt( p_intf , psz_name , i_value );
393     } else {
394         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
395
396         if(! p_filter ) {
397             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
398             vlc_object_release( p_vout );
399             return;
400         }
401         var_SetFloat( p_filter, psz_name, i_value );
402         config_PutFloat( p_intf, psz_name, i_value );
403         vlc_object_release( p_vout );
404     }
405 }
406
407 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter float: (float)f_value
408 {
409     vout_thread_t *p_vout = getVout();
410     vlc_object_t *p_filter;
411
412     if( p_vout == NULL ) {
413         config_PutFloat( p_intf , psz_name , f_value );
414     } else {
415         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
416
417         if(! p_filter ) {
418             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
419             vlc_object_release( p_vout );
420             return;
421         }
422         var_SetFloat( p_filter, psz_name, f_value );
423         config_PutFloat( p_intf, psz_name, f_value );
424         vlc_object_release( p_vout );
425     }
426 }
427
428 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter string: (char *)psz_value
429 {
430     vout_thread_t *p_vout = getVout();
431     vlc_object_t *p_filter;
432
433     if( p_vout == NULL ) {
434         config_PutPsz( p_intf, psz_name, psz_value );
435     } else {
436         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
437
438         if(! p_filter ) {
439             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
440             vlc_object_release( p_vout );
441             return;
442         }
443         var_SetString( p_filter, psz_name, psz_value );
444         config_PutPsz( p_intf, psz_name, psz_value );
445         vlc_object_release( p_vout );
446     }
447 }
448
449 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter boolean: (BOOL)b_value
450 {
451     vout_thread_t *p_vout = getVout();
452     vlc_object_t *p_filter;
453
454     if( p_vout == NULL ) {
455         config_PutInt( p_intf, psz_name, b_value );
456     } else {
457         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
458
459         if(! p_filter ) {
460             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
461             vlc_object_release( p_vout );
462             return;
463         }
464         var_SetBool( p_filter, psz_name, b_value );
465         config_PutInt( p_intf, psz_name, b_value );
466         vlc_object_release( p_vout );
467     }
468 }
469
470 #pragma mark -
471 #pragma mark basic
472 - (IBAction)enableAdjust:(id)sender
473 {
474     BOOL state = [o_adjust_ckb state];
475     [self setVideoFilter: "adjust" on:[o_adjust_ckb state]];
476     [o_adjust_brightness_sld setEnabled: state];
477     [o_adjust_brightness_ckb setEnabled: state];
478     [o_adjust_brightness_lbl setEnabled: state];
479     [o_adjust_contrast_sld setEnabled: state];
480     [o_adjust_contrast_lbl setEnabled: state];
481     [o_adjust_gamma_sld setEnabled: state];
482     [o_adjust_gamma_lbl setEnabled: state];
483     [o_adjust_hue_sld setEnabled: state];
484     [o_adjust_hue_lbl setEnabled: state];
485     [o_adjust_saturation_sld setEnabled: state];
486     [o_adjust_saturation_lbl setEnabled: state];
487     [o_adjust_opaque_sld setEnabled: state];
488     [o_adjust_opaque_lbl setEnabled: state];
489 }
490
491 - (IBAction)adjustSliderChanged:(id)sender
492 {
493     if( sender == o_adjust_opaque_sld ){
494         vlc_value_t val;
495         id o_tmpWindow = [NSApp keyWindow];
496         NSArray *o_windows = [NSApp orderedWindows];
497         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
498         playlist_t * p_playlist = pl_Get( p_intf );
499         vout_thread_t *p_vout = getVout();
500         vout_thread_t *p_real_vout;
501
502         val.f_float = [o_adjust_opaque_sld floatValue];
503
504         if( p_vout != NULL )
505         {
506             //FIXME: update this implementation once the vout is fixed
507             #if 0
508                 p_real_vout = [VLCVoutView realVout: p_vout];
509                 var_Set( p_real_vout, "macosx-opaqueness", val );
510
511                 while ((o_tmpWindow = [o_enumerator nextObject]))
512                 {
513                     if( [[o_tmpWindow className] isEqualToString: @"VLCVoutWindow"] ||
514                        [[[VLCMain sharedInstance] embeddedList] windowContainsEmbedded: o_tmpWindow])
515                     {
516                         [o_tmpWindow setAlphaValue: val.f_float];
517                     }
518                     break;
519                 }
520             #endif
521             vlc_object_release( p_vout );
522         }
523
524         config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
525     } else {
526         if( sender == o_adjust_brightness_sld )
527             [self setVideoFilterProperty: "brightness" forFilter: "adjust" float: [o_adjust_brightness_sld floatValue]];
528         else if( sender == o_adjust_contrast_sld )
529             [self setVideoFilterProperty: "contrast" forFilter: "adjust" float: [o_adjust_contrast_sld floatValue]];
530         else if( sender == o_adjust_gamma_sld )
531             [self setVideoFilterProperty: "gamma" forFilter: "adjust" float: [o_adjust_gamma_sld floatValue]];
532         else if( sender == o_adjust_hue_sld )
533             [self setVideoFilterProperty: "hue" forFilter: "adjust" integer: [o_adjust_hue_sld intValue]];
534         else if( sender == o_adjust_saturation_sld )
535             [self setVideoFilterProperty: "saturation" forFilter: "adjust" float: [o_adjust_saturation_sld floatValue]];
536     }
537 }
538
539 - (IBAction)enableAdjustBrightnessThreshold:(id)sender
540 {
541     config_PutInt( p_intf, "brightness-threshold", [o_adjust_brightness_ckb state] );
542 }
543
544 - (IBAction)enableSharpen:(id)sender
545 {
546     [self setVideoFilter: "sharpen" on: [o_sharpen_ckb state]];
547     [o_sharpen_sld setEnabled: [o_sharpen_ckb state]];
548     [o_sharpen_lbl setEnabled: [o_sharpen_ckb state]];
549 }
550
551 - (IBAction)sharpenSliderChanged:(id)sender
552 {
553     [self setVideoFilterProperty: "sharpen-sigma" forFilter: "sharpen" float: [o_sharpen_sld floatValue]];
554 }
555
556 - (IBAction)enableBanding:(id)sender
557 {
558     [self setVideoFilter: "gradfun" on: [o_banding_ckb state]];
559     [o_banding_sld setEnabled: [o_banding_ckb state]];
560     [o_banding_lbl setEnabled: [o_banding_ckb state]];
561 }
562
563 - (IBAction)bandingSliderChanged:(id)sender
564 {
565     [self setVideoFilterProperty: "gradfun-radius" forFilter: "gradfun" integer: [o_banding_sld intValue]];
566 }
567
568 - (IBAction)enableGrain:(id)sender
569 {
570     [self setVideoFilter: "grain" on: [o_grain_ckb state]];
571     [o_grain_sld setEnabled: [o_grain_ckb state]];
572     [o_grain_lbl setEnabled: [o_grain_ckb state]];
573 }
574
575 - (IBAction)grainSliderChanged:(id)sender
576 {
577     [self setVideoFilterProperty: "grain-variance" forFilter: "grain" float: [o_grain_sld floatValue]];
578 }
579
580
581 #pragma mark -
582 #pragma mark crop
583 - (IBAction)cropObjectChanged:(id)sender
584 {
585     if( [o_crop_sync_top_bottom_ckb state] )
586         [o_crop_bottom_fld setIntValue: [o_crop_top_fld intValue]];
587     if( [o_crop_sync_left_right_ckb state] )
588         [o_crop_right_fld setIntValue: [o_crop_left_fld intValue]];
589
590     vout_thread_t *p_vout = getVout();
591     if( p_vout ) {
592         var_SetInteger( p_vout, "crop-top", [o_crop_top_fld intValue] );
593         var_SetInteger( p_vout, "crop-bottom", [o_crop_bottom_fld intValue] );
594         var_SetInteger( p_vout, "crop-left", [o_crop_left_fld intValue] );
595         var_SetInteger( p_vout, "crop-right", [o_crop_right_fld intValue] );
596         vlc_object_release( p_vout );
597     }
598 }
599
600 #pragma mark -
601 #pragma mark geometry
602 - (IBAction)enableTransform:(id)sender
603 {
604     [self setVideoFilter: "transform" on: [o_transform_ckb state]];
605     [o_transform_pop setEnabled: [o_transform_ckb state]];
606 }
607
608 - (IBAction)transformModifierChanged:(id)sender
609 {
610     if( [[o_transform_pop selectedItem] tag] == 1 )
611         config_PutPsz( p_intf, "transform-type", "hflip" );
612     else if( [[o_transform_pop selectedItem] tag] == 2 )
613         config_PutPsz( p_intf, "transform-type", "vflip" );
614     else
615         config_PutPsz( p_intf, "transform-type", (char *)[o_transform_pop tag] );
616 }
617
618 - (IBAction)enableZoom:(id)sender
619 {
620     [self setVideoFilter: "magnify" on: [o_zoom_ckb state]];
621 }
622
623 - (IBAction)enablePuzzle:(id)sender
624 {
625     BOOL state = [o_puzzle_ckb state];
626     [self setVideoFilter: "puzzle" on: state];
627     [o_puzzle_columns_fld setEnabled: state];
628     [o_puzzle_columns_lbl setEnabled: state];
629     [o_puzzle_rows_fld setEnabled: state];
630     [o_puzzle_rows_lbl setEnabled: state];
631     [o_puzzle_blackslot_ckb setEnabled: state];
632 }
633
634 - (IBAction)puzzleModifierChanged:(id)sender
635 {
636     if( sender == o_puzzle_blackslot_ckb )
637         [self setVideoFilterProperty: "puzzle-black-slot" forFilter: "puzzle" boolean: [o_puzzle_blackslot_ckb state]];
638     else if( sender == o_puzzle_columns_fld )
639         [self setVideoFilterProperty: "puzzle-cols" forFilter: "puzzle" integer: [o_puzzle_columns_fld intValue]];
640     else
641         [self setVideoFilterProperty: "puzzle-rows" forFilter: "puzzle" integer: [o_puzzle_rows_fld intValue]];
642 }
643
644
645 #pragma mark -
646 #pragma mark color
647 - (IBAction)enableThreshold:(id)sender
648 {
649     BOOL state = [o_threshold_ckb state];
650     [self setVideoFilter: "colorthres" on: state];
651     [o_threshold_color_fld setEnabled: state];
652     [o_threshold_color_lbl setEnabled: state];
653     [o_threshold_saturation_sld setEnabled: state];
654     [o_threshold_saturation_lbl setEnabled: state];
655     [o_threshold_similarity_sld setEnabled: state];
656     [o_threshold_similarity_lbl setEnabled: state];
657 }
658
659 - (IBAction)thresholdModifierChanged:(id)sender
660 {
661     if( sender == o_threshold_color_fld )
662         [self setVideoFilterProperty: "colorthres-color" forFilter: "colorthres" integer: [o_threshold_color_fld intValue]];
663     else if( sender == o_threshold_saturation_sld )
664         [self setVideoFilterProperty: "colorthres-saturationthres" forFilter: "colorthres" integer: [o_threshold_saturation_sld intValue]];
665     else
666         [self setVideoFilterProperty: "colorthres-similaritythres" forFilter: "colorthres" integer: [o_threshold_similarity_sld intValue]];
667 }
668
669 - (IBAction)enableSepia:(id)sender
670 {
671     [self setVideoFilter: "sepia" on: [o_sepia_ckb state]];
672     [o_sepia_fld setEnabled: [o_sepia_ckb state]];
673     [o_sepia_lbl setEnabled: [o_sepia_ckb state]];
674 }
675
676 - (IBAction)sepiaModifierChanged:(id)sender
677 {
678     [self setVideoFilterProperty: "sepia-intensity" forFilter: "sepia" integer: [o_sepia_fld intValue]];
679 }
680
681 - (IBAction)enableNoise:(id)sender
682 {
683     [self setVideoFilter: "noise" on: [o_noise_ckb state]];
684 }
685
686 - (IBAction)enableGradient:(id)sender
687 {
688     BOOL state = [o_gradient_ckb state];
689     [self setVideoFilter: "gradient" on: state];
690     [o_gradient_mode_pop setEnabled: state];
691     [o_gradient_mode_lbl setEnabled: state];
692     [o_gradient_color_ckb setEnabled: state];
693     [o_gradient_cartoon_ckb setEnabled: state];
694 }
695
696 - (IBAction)gradientModifierChanged:(id)sender
697 {
698     if( sender == o_gradient_mode_pop ) {
699         if( [[o_gradient_mode_pop selectedItem] tag] == 3 )
700             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "hough"];
701         else if( [[o_gradient_mode_pop selectedItem] tag] == 2 )
702             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "edge"];
703         else
704             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "gradient"];
705     }
706     else if( sender == o_gradient_color_ckb )
707         [self setVideoFilterProperty: "gradient-type" forFilter: "gradient" integer: [o_gradient_color_ckb state]];
708     else
709         [self setVideoFilterProperty: "gradient-cartoon" forFilter: "gradient" boolean: [o_gradient_cartoon_ckb state]];
710 }
711
712 - (IBAction)enableExtract:(id)sender
713 {
714     [self setVideoFilter: "extract" on: [o_extract_ckb state]];
715     [o_extract_fld setEnabled: [o_extract_ckb state]];
716     [o_extract_lbl setEnabled: [o_extract_ckb state]];
717 }
718
719 - (IBAction)extractModifierChanged:(id)sender
720 {
721     [self setVideoFilterProperty: "extract-component" forFilter: "extract" integer: [o_extract_fld intValue]];  
722 }
723
724 - (IBAction)enableInvert:(id)sender
725 {
726     [self setVideoFilter: "invert" on: [o_invert_ckb state]];
727 }
728
729 - (IBAction)enablePosterize:(id)sender
730 {
731     [self setVideoFilter: "posterize" on: [o_posterize_ckb state]];
732     [o_posterize_fld setEnabled: [o_posterize_ckb state]];
733     [o_posterize_lbl setEnabled: [o_posterize_ckb state]];
734 }
735
736 - (IBAction)posterizeModifierChanged:(id)sender
737 {
738     [self setVideoFilterProperty: "posterize-level" forFilter: "posterize" integer: [o_extract_fld intValue]];
739 }
740
741 - (IBAction)enableBlur:(id)sender
742 {
743     [self setVideoFilter: "motionblur" on: [o_blur_ckb state]];
744     [o_blur_sld setEnabled: [o_blur_ckb state]];
745     [o_blur_lbl setEnabled: [o_blur_ckb state]];
746 }
747
748 - (IBAction)blurModifierChanged:(id)sender
749 {
750     [self setVideoFilterProperty: "blur-factor" forFilter: "motionblur" integer: [o_blur_sld intValue]];
751 }
752
753 - (IBAction)enableMotionDetect:(id)sender
754 {
755     [self setVideoFilter: "motiondetect" on: [o_motiondetect_ckb state]];
756 }
757
758 - (IBAction)enableWaterEffect:(id)sender
759 {
760     [self setVideoFilter: "ripple" on: [o_watereffect_ckb state]];
761 }
762
763 - (IBAction)enableWaves:(id)sender
764 {
765     [self setVideoFilter: "wave" on: [o_waves_ckb state]];
766 }
767
768 - (IBAction)enablePsychedelic:(id)sender
769 {
770     [self setVideoFilter: "psychedelic" on: [o_psychedelic_ckb state]];
771 }
772
773
774 #pragma mark -
775 #pragma mark video output & overlay
776 - (IBAction)enableClone:(id)sender
777 {
778     msg_Dbg( p_intf, "not yet implemented" );
779 }
780
781 - (IBAction)cloneModifierChanged:(id)sender
782 {
783     msg_Dbg( p_intf, "not yet implemented" );
784 }
785
786 - (IBAction)enableAddText:(id)sender
787 {
788     msg_Dbg( p_intf, "not yet implemented" );
789 }
790
791 - (IBAction)addTextModifierChanged:(id)sender
792 {
793     msg_Dbg( p_intf, "not yet implemented" );
794 }
795
796
797 #pragma mark -
798 #pragma mark logo
799 - (IBAction)enableAddLogo:(id)sender
800 {
801     msg_Dbg( p_intf, "not yet implemented" );
802 }
803
804 - (IBAction)addLogoModifierChanged:(id)sender
805 {
806     msg_Dbg( p_intf, "not yet implemented" );
807 }
808
809 - (IBAction)enableEraseLogo:(id)sender
810 {
811     msg_Dbg( p_intf, "not yet implemented" );
812 }
813
814 - (IBAction)eraseLogoModifierChanged:(id)sender
815 {
816     msg_Dbg( p_intf, "not yet implemented" );
817 }
818
819
820 @end