Revert "macosx: clean code of objectAtIndex"
[vlc/vlc-acra.git] / modules / gui / macosx / VideoEffects.m
blob28f89a025680c3d8106b6450748113b441fb350a
1 /*****************************************************************************
2  * VideoEffects.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2012 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  *****************************************************************************/
24 #import "CompatibilityFixes.h"
25 #import "intf.h"
26 #import <vlc_common.h>
27 #import <vlc_modules.h>
28 #import <vlc_charset.h>
29 #import <vlc_strings.h>
30 #import "VideoEffects.h"
31 #import "SharedDialogs.h"
33 @interface VLCVideoEffects (Internal)
34 - (void)resetProfileSelector;
35 @end
37 #pragma mark -
38 #pragma mark Initialization
40 @implementation VLCVideoEffects
41 static VLCVideoEffects *_o_sharedInstance = nil;
43 @synthesize cropLeftValue, cropTopValue, cropRightValue, cropBottomValue;
44 @synthesize puzzleRowsValue, puzzleColumnsValue;
45 @synthesize wallRowsValue, wallColumnsValue;
46 @synthesize cloneValue;
47 @synthesize sepiaValue;
48 @synthesize posterizeValue;
50 + (VLCVideoEffects *)sharedInstance
52     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
55 + (void)initialize
57     NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:@[@";;;0;1.000000;1.000000;1.000000;1.000000;0.050000;16;2.000000;OTA=;4;4;16711680;20;15;120;Z3JhZGllbnQ=;1;0;16711680;6;80;VkxD;-1;;-1;255;2;3;3"], @"VideoEffectProfiles",
58                                  @[_NS("Default")], @"VideoEffectProfileNames", nil];
59     [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
62 - (id)init
64     if (_o_sharedInstance)
65         [self dealloc];
66     else {
67         p_intf = VLCIntf;
68         i_old_profile_index = -1;
69         _o_sharedInstance = [super init];
70     }
72     return _o_sharedInstance;
75 - (void)awakeFromNib
77     [o_window setTitle: _NS("Video Effects")];
78     [o_window setExcludedFromWindowsMenu:YES];
79     if (!OSX_SNOW_LEOPARD)
80         [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
82     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"basic"]] setLabel:_NS("Basic")];
83     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"crop"]] setLabel:_NS("Crop")];
84     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"geometry"]] setLabel:_NS("Geometry")];
85     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"color"]] setLabel:_NS("Color")];
86     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"misc"]] setLabel:_NS("Miscellaneous")];
88     [self resetProfileSelector];
90     [o_adjust_ckb setTitle:_NS("Image Adjust")];
91     [o_adjust_hue_lbl setStringValue:_NS("Hue")];
92     [o_adjust_contrast_lbl setStringValue:_NS("Contrast")];
93     [o_adjust_brightness_lbl setStringValue:_NS("Brightness")];
94     [o_adjust_brightness_ckb setTitle:_NS("Brightness Threshold")];
95     [o_adjust_saturation_lbl setStringValue:_NS("Saturation")];
96     [o_adjust_gamma_lbl setStringValue:_NS("Gamma")];
97     [o_adjust_reset_btn setTitle: _NS("Reset")];
98     [o_sharpen_ckb setTitle:_NS("Sharpen")];
99     [o_sharpen_lbl setStringValue:_NS("Sigma")];
100     [o_banding_ckb setTitle:_NS("Banding removal")];
101     [o_banding_lbl setStringValue:_NS("Radius")];
102     [o_grain_ckb setTitle:_NS("Film Grain")];
103     [o_grain_lbl setStringValue:_NS("Variance")];
104     [o_crop_top_lbl setStringValue:_NS("Top")];
105     [o_crop_left_lbl setStringValue:_NS("Left")];
106     [o_crop_right_lbl setStringValue:_NS("Right")];
107     [o_crop_bottom_lbl setStringValue:_NS("Bottom")];
108     [o_crop_sync_top_bottom_ckb setTitle:_NS("Synchronize top and bottom")];
109     [o_crop_sync_left_right_ckb setTitle:_NS("Synchronize left and right")];
111     [o_transform_ckb setTitle:_NS("Transform")];
112     [o_transform_pop removeAllItems];
113     [o_transform_pop addItemWithTitle: _NS("Rotate by 90 degrees")];
114     [[o_transform_pop lastItem] setTag: 90];
115     [o_transform_pop addItemWithTitle: _NS("Rotate by 180 degrees")];
116     [[o_transform_pop lastItem] setTag: 180];
117     [o_transform_pop addItemWithTitle: _NS("Rotate by 270 degrees")];
118     [[o_transform_pop lastItem] setTag: 270];
119     [o_transform_pop addItemWithTitle: _NS("Flip horizontally")];
120     [[o_transform_pop lastItem] setTag: 1];
121     [o_transform_pop addItemWithTitle: _NS("Flip vertically")];
122     [[o_transform_pop lastItem] setTag: 2];
123     [o_zoom_ckb setTitle:_NS("Magnification/Zoom")];
124     [o_puzzle_ckb setTitle:_NS("Puzzle game")];
125     [o_puzzle_rows_lbl setStringValue:_NS("Rows")];
126     [o_puzzle_columns_lbl setStringValue:_NS("Columns")];
127     [o_clone_ckb setTitle:_NS("Clone")];
128     [o_clone_number_lbl setStringValue:_NS("Number of clones")];
129     [o_wall_ckb setTitle:_NS("Wall")];
130     [o_wall_numofrows_lbl setStringValue:_NS("Rows")];
131     [o_wall_numofcols_lbl setStringValue:_NS("Columns")];
133     [o_threshold_ckb setTitle:_NS("Color threshold")];
134     [o_threshold_color_lbl setStringValue:_NS("Color")];
135     [o_threshold_saturation_lbl setStringValue:_NS("Saturation")];
136     [o_threshold_similarity_lbl setStringValue:_NS("Similarity")];
137     [o_sepia_ckb setTitle:_NS("Sepia")];
138     [o_sepia_lbl setStringValue:_NS("Intensity")];
139     [o_noise_ckb setTitle:_NS("Noise")];
140     [o_gradient_ckb setTitle:_NS("Gradient")];
141     [o_gradient_mode_lbl setStringValue:_NS("Mode")];
142     [o_gradient_mode_pop removeAllItems];
143     [o_gradient_mode_pop addItemWithTitle: _NS("Gradient")];
144     [[o_gradient_mode_pop lastItem] setTag: 1];
145     [o_gradient_mode_pop addItemWithTitle: _NS("Edge")];
146     [[o_gradient_mode_pop lastItem] setTag: 2];
147     [o_gradient_mode_pop addItemWithTitle: _NS("Hough")];
148     [[o_gradient_mode_pop lastItem] setTag: 3];
149     [o_gradient_color_ckb setTitle:_NS("Color")];
150     [o_gradient_cartoon_ckb setTitle:_NS("Cartoon")];
151     [o_extract_ckb setTitle:_NS("Color extraction")];
152     [o_extract_lbl setStringValue:_NS("Color")];
153     [o_invert_ckb setTitle:_NS("Invert colors")];
154     [o_posterize_ckb setTitle:_NS("Posterize")];
155     [o_posterize_lbl setStringValue:_NS("Posterize level")];
156     [o_blur_ckb setTitle:_NS("Motion blur")];
157     [o_blur_lbl setStringValue:_NS("Factor")];
158     [o_motiondetect_ckb setTitle:_NS("Motion Detect")];
159     [o_watereffect_ckb setTitle:_NS("Water effect")];
160     [o_waves_ckb setTitle:_NS("Waves")];
161     [o_psychedelic_ckb setTitle:_NS("Psychedelic")];
162     [o_anaglyph_ckb setTitle:_NS("Anaglyph")];
164     [o_addtext_ckb setTitle:_NS("Add text")];
165     [o_addtext_text_lbl setStringValue:_NS("Text")];
166     [o_addtext_pos_lbl setStringValue:_NS("Position")];
167     [o_addtext_pos_pop removeAllItems];
168     [o_addtext_pos_pop addItemWithTitle: _NS("Center")];
169     [[o_addtext_pos_pop lastItem] setTag: 0];
170     [o_addtext_pos_pop addItemWithTitle: _NS("Left")];
171     [[o_addtext_pos_pop lastItem] setTag: 1];
172     [o_addtext_pos_pop addItemWithTitle: _NS("Right")];
173     [[o_addtext_pos_pop lastItem] setTag: 2];
174     [o_addtext_pos_pop addItemWithTitle: _NS("Top")];
175     [[o_addtext_pos_pop lastItem] setTag: 4];
176     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom")];
177     [[o_addtext_pos_pop lastItem] setTag: 8];
178     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Left")];
179     [[o_addtext_pos_pop lastItem] setTag: 5];
180     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Right")];
181     [[o_addtext_pos_pop lastItem] setTag: 6];
182     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Left")];
183     [[o_addtext_pos_pop lastItem] setTag: 9];
184     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Right")];
185     [[o_addtext_pos_pop lastItem] setTag: 10];
186     [o_addlogo_ckb setTitle:_NS("Add logo")];
187     [o_addlogo_logo_lbl setStringValue:_NS("Logo")];
188     [o_addlogo_pos_lbl setStringValue:_NS("Position")];
189     [o_addlogo_pos_pop removeAllItems];
190     [o_addlogo_pos_pop addItemWithTitle: _NS("Center")];
191     [[o_addlogo_pos_pop lastItem] setTag: 0];
192     [o_addlogo_pos_pop addItemWithTitle: _NS("Left")];
193     [[o_addlogo_pos_pop lastItem] setTag: 1];
194     [o_addlogo_pos_pop addItemWithTitle: _NS("Right")];
195     [[o_addlogo_pos_pop lastItem] setTag: 2];
196     [o_addlogo_pos_pop addItemWithTitle: _NS("Top")];
197     [[o_addlogo_pos_pop lastItem] setTag: 4];
198     [o_addlogo_pos_pop addItemWithTitle: _NS("Bottom")];
199     [[o_addlogo_pos_pop lastItem] setTag: 8];
200     [o_addlogo_pos_pop addItemWithTitle: _NS("Top-Left")];
201     [[o_addlogo_pos_pop lastItem] setTag: 5];
202     [o_addlogo_pos_pop addItemWithTitle: _NS("Top-Right")];
203     [[o_addlogo_pos_pop lastItem] setTag: 6];
204     [o_addlogo_pos_pop addItemWithTitle: _NS("Bottom-Left")];
205     [[o_addlogo_pos_pop lastItem] setTag: 9];
206     [o_addlogo_pos_pop addItemWithTitle: _NS("Bottom-Right")];
207     [[o_addlogo_pos_pop lastItem] setTag: 10];
208     [o_addlogo_transparency_lbl setStringValue:_NS("Transparency")];
210     [o_tableView selectFirstTabViewItem:self];
212     [self resetValues];
215 - (void)updateCocoaWindowLevel:(NSInteger)i_level
217     if (o_window && [o_window isVisible] && [o_window level] != i_level)
218         [o_window setLevel: i_level];
221 #pragma mark -
222 #pragma mark internal functions
223 - (void)resetProfileSelector
225     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
226     [o_profile_pop removeAllItems];
228     NSArray * profileNames = [defaults objectForKey:@"VideoEffectProfileNames"];
229     [o_profile_pop addItemsWithTitles:profileNames];
231     [[o_profile_pop menu] addItem:[NSMenuItem separatorItem]];
232     [o_profile_pop addItemWithTitle:_NS("Duplicate current profile...")];
233     [[o_profile_pop lastItem] setTarget: self];
234     [[o_profile_pop lastItem] setAction: @selector(addProfile:)];
236     if ([profileNames count] > 1) {
237         [o_profile_pop addItemWithTitle:_NS("Organize profiles...")];
238         [[o_profile_pop lastItem] setTarget: self];
239         [[o_profile_pop lastItem] setAction: @selector(removeProfile:)];
240     }
242     [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
243     [self profileSelectorAction:self];
246 - (void)resetValues
248     NSString *tmpString;
249     char *tmpChar;
250     BOOL b_state;
252     /* do we have any filter enabled? if yes, show it. */
253     char * psz_vfilters;
254     psz_vfilters = config_GetPsz(p_intf, "video-filter");
255     if (psz_vfilters) {
256         [o_adjust_ckb setState: (NSInteger)strstr(psz_vfilters, "adjust")];
257         [o_sharpen_ckb setState: (NSInteger)strstr(psz_vfilters, "sharpen")];
258         [o_banding_ckb setState: (NSInteger)strstr(psz_vfilters, "gradfun")];
259         [o_grain_ckb setState: (NSInteger)strstr(psz_vfilters, "grain")];
260         [o_transform_ckb setState: (NSInteger)strstr(psz_vfilters, "transform")];
261         [o_zoom_ckb setState: (NSInteger)strstr(psz_vfilters, "magnify")];
262         [o_puzzle_ckb setState: (NSInteger)strstr(psz_vfilters, "puzzle")];
263         [o_threshold_ckb setState: (NSInteger)strstr(psz_vfilters, "colorthres")];
264         [o_sepia_ckb setState: (NSInteger)strstr(psz_vfilters, "sepia")];
265         [o_noise_ckb setState: (NSInteger)strstr(psz_vfilters, "noise")];
266         [o_gradient_ckb setState: (NSInteger)strstr(psz_vfilters, "gradient")];
267         [o_extract_ckb setState: (NSInteger)strstr(psz_vfilters, "extract")];
268         [o_invert_ckb setState: (NSInteger)strstr(psz_vfilters, "invert")];
269         [o_posterize_ckb setState: (NSInteger)strstr(psz_vfilters, "posterize")];
270         [o_blur_ckb setState: (NSInteger)strstr(psz_vfilters, "motionblur")];
271         [o_motiondetect_ckb setState: (NSInteger)strstr(psz_vfilters, "motiondetect")];
272         [o_watereffect_ckb setState: (NSInteger)strstr(psz_vfilters, "ripple")];
273         [o_waves_ckb setState: (NSInteger)strstr(psz_vfilters, "wave")];
274         [o_psychedelic_ckb setState: (NSInteger)strstr(psz_vfilters, "psychedelic")];
275         [o_anaglyph_ckb setState: (NSInteger)strstr(psz_vfilters, "anaglyph")];
276         free(psz_vfilters);
277     } else {
278         [o_adjust_ckb setState: NSOffState];
279         [o_sharpen_ckb setState: NSOffState];
280         [o_banding_ckb setState: NSOffState];
281         [o_grain_ckb setState: NSOffState];
282         [o_transform_ckb setState: NSOffState];
283         [o_zoom_ckb setState: NSOffState];
284         [o_puzzle_ckb setState: NSOffState];
285         [o_threshold_ckb setState: NSOffState];
286         [o_sepia_ckb setState: NSOffState];
287         [o_noise_ckb setState: NSOffState];
288         [o_gradient_ckb setState: NSOffState];
289         [o_extract_ckb setState: NSOffState];
290         [o_invert_ckb setState: NSOffState];
291         [o_posterize_ckb setState: NSOffState];
292         [o_blur_ckb setState: NSOffState];
293         [o_motiondetect_ckb setState: NSOffState];
294         [o_watereffect_ckb setState: NSOffState];
295         [o_waves_ckb setState: NSOffState];
296         [o_psychedelic_ckb setState: NSOffState];
297         [o_anaglyph_ckb setState: NSOffState];
298     }
300     psz_vfilters = config_GetPsz(p_intf, "sub-source");
301     if (psz_vfilters) {
302         [o_addtext_ckb setState: (NSInteger)strstr(psz_vfilters, "marq")];
303         [o_addlogo_ckb setState: (NSInteger)strstr(psz_vfilters, "logo")];
304         free(psz_vfilters);
305     } else {
306         [o_addtext_ckb setState: NSOffState];
307         [o_addlogo_ckb setState: NSOffState];
308     }
310     psz_vfilters = config_GetPsz(p_intf, "video-splitter");
311     if (psz_vfilters) {
312         [o_clone_ckb setState: (NSInteger)strstr(psz_vfilters, "clone")];
313         [o_wall_ckb setState: (NSInteger)strstr(psz_vfilters, "wall")];
314         free(psz_vfilters);
315     } else {
316         [o_clone_ckb setState: NSOffState];
317         [o_wall_ckb setState: NSOffState];
318     }
320     /* fetch and show the various values */
321     [o_adjust_hue_sld setIntValue: config_GetInt(p_intf, "hue")];
322     [o_adjust_contrast_sld setFloatValue: config_GetFloat(p_intf, "contrast")];
323     [o_adjust_brightness_sld setFloatValue: config_GetFloat(p_intf, "brightness")];
324     [o_adjust_saturation_sld setFloatValue: config_GetFloat(p_intf, "saturation")];
325     [o_adjust_gamma_sld setFloatValue: config_GetFloat(p_intf, "gamma")];
326     [o_adjust_brightness_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "brightness")]];
327     [o_adjust_contrast_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "contrast")]];
328     [o_adjust_gamma_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "gamma")]];
329     [o_adjust_hue_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "hue")]];
330     [o_adjust_saturation_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "saturation")]];
331     b_state = [o_adjust_ckb state];
332     [o_adjust_brightness_sld setEnabled: b_state];
333     [o_adjust_brightness_ckb setEnabled: b_state];
334     [o_adjust_contrast_sld setEnabled: b_state];
335     [o_adjust_gamma_sld setEnabled: b_state];
336     [o_adjust_hue_sld setEnabled: b_state];
337     [o_adjust_saturation_sld setEnabled: b_state];
338     [o_adjust_brightness_lbl setEnabled: b_state];
339     [o_adjust_contrast_lbl setEnabled: b_state];
340     [o_adjust_gamma_lbl setEnabled: b_state];
341     [o_adjust_hue_lbl setEnabled: b_state];
342     [o_adjust_saturation_lbl setEnabled: b_state];
343     [o_adjust_reset_btn setEnabled: b_state];
345     [o_sharpen_sld setFloatValue: config_GetFloat(p_intf, "sharpen-sigma")];
346     [o_sharpen_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "sharpen-sigma")]];
347     [o_sharpen_sld setEnabled: [o_sharpen_ckb state]];
348     [o_sharpen_lbl setEnabled: [o_sharpen_ckb state]];
350     [o_banding_sld setIntValue: config_GetInt(p_intf, "gradfun-radius")];
351     [o_banding_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "gradfun-radius")]];
352     [o_banding_sld setEnabled: [o_banding_ckb state]];
353     [o_banding_lbl setEnabled: [o_banding_ckb state]];
355     [o_grain_sld setFloatValue: config_GetFloat(p_intf, "grain-variance")];
356     [o_grain_sld setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "grain-variance")]];
357     [o_grain_sld setEnabled: [o_grain_ckb state]];
358     [o_grain_lbl setEnabled: [o_grain_ckb state]];
360     [self setCropLeftValue: 0];
361     [self setCropTopValue: 0];
362     [self setCropRightValue: 0];
363     [self setCropBottomValue: 0];
364     [o_crop_sync_top_bottom_ckb setState: NSOffState];
365     [o_crop_sync_left_right_ckb setState: NSOffState];
367     tmpChar = config_GetPsz(p_intf, "transform-type");
368     tmpString = @(tmpChar);
369     if ([tmpString isEqualToString:@"hflip"])
370         [o_transform_pop selectItemWithTag: 1];
371     else if ([tmpString isEqualToString:@"vflip"])
372         [o_transform_pop selectItemWithTag: 2];
373     else
374         [o_transform_pop selectItemWithTag:[tmpString intValue]];
375     FREENULL(tmpChar);
376     [o_transform_pop setEnabled: [o_transform_ckb state]];
378     [self setPuzzleColumnsValue: config_GetInt(p_intf, "puzzle-cols")];
379     [self setPuzzleRowsValue: config_GetInt(p_intf, "puzzle-rows")];
380     b_state = [o_puzzle_ckb state];
381     [o_puzzle_rows_fld setEnabled: b_state];
382     [o_puzzle_rows_stp setEnabled: b_state];
383     [o_puzzle_rows_lbl setEnabled: b_state];
384     [o_puzzle_columns_fld setEnabled: b_state];
385     [o_puzzle_columns_stp setEnabled: b_state];
386     [o_puzzle_columns_lbl setEnabled: b_state];
388     [self setCloneValue: config_GetInt(p_intf, "clone-count")];
389     b_state = [o_clone_ckb state];
390     [o_clone_number_lbl setEnabled: b_state];
391     [o_clone_number_fld setEnabled: b_state];
392     [o_clone_number_stp setEnabled: b_state];
394     b_state = [o_wall_ckb state];
395     [self setWallRowsValue: config_GetInt(p_intf, "wall-rows")];
396     [o_wall_numofrows_lbl setEnabled: b_state];
397     [o_wall_numofrows_fld setEnabled: b_state];
398     [o_wall_numofrows_stp setEnabled: b_state];
399     [self setWallColumnsValue: config_GetInt(p_intf, "wall-cols")];
400     [o_wall_numofcols_lbl setEnabled: b_state];
401     [o_wall_numofcols_fld setEnabled: b_state];
402     [o_wall_numofcols_stp setEnabled: b_state];
404     [o_threshold_color_fld setStringValue: [[NSString stringWithFormat:@"%llx", config_GetInt(p_intf, "colorthres-color")] uppercaseString]];
405     [o_threshold_saturation_sld setIntValue: config_GetInt(p_intf, "colorthres-saturationthres")];
406     [o_threshold_saturation_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "colorthres-saturationthres")]];
407     [o_threshold_similarity_sld setIntValue: config_GetInt(p_intf, "colorthres-similaritythres")];
408     [o_threshold_similarity_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "colorthres-similaritythres")]];
409     
410     b_state = [o_threshold_ckb state];
411     [o_threshold_color_fld setEnabled: b_state];
412     [o_threshold_color_lbl setEnabled: b_state];
413     [o_threshold_saturation_sld setEnabled: b_state];
414     [o_threshold_saturation_lbl setEnabled: b_state];
415     [o_threshold_similarity_sld setEnabled: b_state];
416     [o_threshold_similarity_lbl setEnabled: b_state];
417     
418     [self setSepiaValue: config_GetInt(p_intf, "sepia-intensity")];
419     b_state = [o_sepia_ckb state];
420     [o_sepia_fld setEnabled: b_state];
421     [o_sepia_stp setEnabled: b_state];
422     [o_sepia_lbl setEnabled: b_state];
424     tmpChar = config_GetPsz(p_intf, "gradient-mode");
425     tmpString = @(tmpChar);
426     if ([tmpString isEqualToString:@"hough"])
427         [o_gradient_mode_pop selectItemWithTag: 3];
428     else if ([tmpString isEqualToString:@"edge"])
429         [o_gradient_mode_pop selectItemWithTag: 2];
430     else
431         [o_gradient_mode_pop selectItemWithTag: 1];
432     FREENULL(tmpChar);
433     [o_gradient_cartoon_ckb setState: config_GetInt(p_intf, "gradient-cartoon")];
434     [o_gradient_color_ckb setState: config_GetInt(p_intf, "gradient-type")];
435     b_state = [o_gradient_ckb state];
436     [o_gradient_mode_pop setEnabled: b_state];
437     [o_gradient_mode_lbl setEnabled: b_state];
438     [o_gradient_cartoon_ckb setEnabled: b_state];
439     [o_gradient_color_ckb setEnabled: b_state];
441     [o_extract_fld setStringValue: [[NSString stringWithFormat:@"%llx", config_GetInt(p_intf, "extract-component")] uppercaseString]];
442     [o_extract_fld setEnabled: [o_extract_ckb state]];
443     [o_extract_lbl setEnabled: [o_extract_ckb state]];
445     [self setPosterizeValue: config_GetInt(p_intf, "posterize-level")];
446     b_state = [o_posterize_ckb state];
447     [o_posterize_fld setEnabled: b_state];
448     [o_posterize_stp setEnabled: b_state];
449     [o_posterize_lbl setEnabled: b_state];
450     
451     [o_blur_sld setIntValue: config_GetInt(p_intf, "blur-factor")];
452     [o_blur_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "blur-factor")]];
453     [o_blur_sld setEnabled: [o_blur_ckb state]];
454     [o_blur_lbl setEnabled: [o_blur_ckb state]];
456     tmpChar = config_GetPsz(p_intf, "marq-marquee");
457     if (tmpChar) {
458         [o_addtext_text_fld setStringValue: @(tmpChar)];
459         FREENULL(tmpChar);
460     } else
461         [o_addtext_text_fld setStringValue: @""];
462     [o_addtext_pos_pop selectItemWithTag: config_GetInt(p_intf, "marq-position")];
463     b_state = [o_addtext_ckb state];
464     [o_addtext_pos_pop setEnabled: b_state];
465     [o_addtext_pos_lbl setEnabled: b_state];
466     [o_addtext_text_lbl setEnabled: b_state];
467     [o_addtext_text_fld setEnabled: b_state];
469     tmpChar = config_GetPsz(p_intf, "logo-file");
470     if (tmpChar) {
471         [o_addlogo_logo_fld setStringValue: @(tmpChar)];
472         FREENULL(tmpChar);
473     } else
474         [o_addlogo_logo_fld setStringValue: @""];
475     [o_addlogo_pos_pop selectItemWithTag: config_GetInt(p_intf, "logo-position")];
476     [o_addlogo_transparency_sld setIntValue: config_GetInt(p_intf, "logo-opacity")];
477     [o_addlogo_transparency_sld setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "logo-opacity")]];
478     b_state = [o_addlogo_ckb state];
479     [o_addlogo_pos_pop setEnabled: b_state];
480     [o_addlogo_pos_lbl setEnabled: b_state];
481     [o_addlogo_logo_fld setEnabled: b_state];
482     [o_addlogo_logo_lbl setEnabled: b_state];
483     [o_addlogo_transparency_sld setEnabled: b_state];
484     [o_addlogo_transparency_lbl setEnabled: b_state];
487 - (void)setVideoFilter: (char *)psz_name on:(BOOL)b_on
489     char *psz_string, *psz_parser;
490     const char *psz_filter_type;
492     module_t *p_obj = module_find(psz_name);
493     if (!p_obj) {
494         msg_Err(p_intf, "Unable to find filter module \"%s\".", psz_name);
495         return;
496     }
497     msg_Dbg(p_intf, "will set filter '%s'", psz_name);
499     if (module_provides(p_obj, "video splitter")) {
500         psz_filter_type = "video-splitter";
501     } else if (module_provides(p_obj, "video filter2")) {
502         psz_filter_type = "video-filter";
503     } else if (module_provides(p_obj, "sub source")) {
504         psz_filter_type = "sub-source";
505     } else if (module_provides(p_obj, "sub filter")) {
506         psz_filter_type = "sub-filter";
507     } else {
508         msg_Err(p_intf, "Unknown video filter type.");
509         return;
510     }
512     psz_string = config_GetPsz(p_intf, psz_filter_type);
514     if (b_on) {
515         if (!psz_string)
516             psz_string = psz_name;
517         else if (strstr(psz_string, psz_name) == NULL)
518             psz_string = (char *)[[NSString stringWithFormat: @"%s:%s", psz_string, psz_name] UTF8String];
519     } else {
520         if (!psz_string)
521             return;
523         psz_parser = strstr(psz_string, psz_name);
524         if (psz_parser) {
525             if (*(psz_parser + strlen(psz_name)) == ':') {
526                 memmove(psz_parser, psz_parser + strlen(psz_name) + 1,
527                         strlen(psz_parser + strlen(psz_name) + 1) + 1);
528             } else {
529                 *psz_parser = '\0';
530             }
532             /* Remove trailing : : */
533             if (strlen(psz_string) > 0 && *(psz_string + strlen(psz_string) -1) == ':')
534                 *(psz_string + strlen(psz_string) -1) = '\0';
535         } else {
536             free(psz_string);
537             return;
538         }
539     }
540     config_PutPsz(p_intf, psz_filter_type, psz_string);
542     /* Try to set on the fly */
543     if (!strcmp(psz_filter_type, "video-splitter")) {
544         playlist_t *p_playlist = pl_Get(p_intf);
545         var_SetString(p_playlist, psz_filter_type, psz_string);
546     } else {
547         vout_thread_t *p_vout = getVout();
548         if (p_vout) {
549             var_SetString(p_vout, psz_filter_type, psz_string);
550             vlc_object_release(p_vout);
551         }
552     }
555 - (void)restartFilterIfNeeded: (char *)psz_filter option: (char *)psz_name
557     vout_thread_t *p_vout = getVout();
559     if (p_vout == NULL)
560         return;
561     else
562         vlc_object_release(p_vout);
564     vlc_object_t *p_filter = vlc_object_find_name(pl_Get(p_intf), psz_filter);
565     if (p_filter) {
566         int i_type;
567         i_type = var_Type(p_filter, psz_name);
568         if (i_type == 0)
569             i_type = config_GetType(p_intf, psz_name);
571         if (!(i_type & VLC_VAR_ISCOMMAND)) {
572             msg_Warn(p_intf, "Brute-restarting filter '%s', because the last changed option isn't a command", psz_name);
573             [self setVideoFilter: psz_filter on: NO];
574             [self setVideoFilter: psz_filter on: YES];
575         } else
576             msg_Dbg(p_intf, "restart not needed");
578         vlc_object_release(p_filter);
579     }
582 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter integer: (int)i_value
584     vout_thread_t *p_vout = getVout();
585     vlc_object_t *p_filter;
587     config_PutInt(p_intf, psz_name, i_value);
589     if (p_vout) {
590         p_filter = vlc_object_find_name(pl_Get(p_intf), psz_filter);
592         if (!p_filter) {
593             msg_Warn(p_intf, "filter '%s' isn't enabled", psz_filter);
594             vlc_object_release(p_vout);
595             return;
596         }
597         var_SetInteger(p_filter, psz_name, i_value);
598         vlc_object_release(p_vout);
599         vlc_object_release(p_filter);
601         [self restartFilterIfNeeded: psz_filter option: psz_name];
602     }
605 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter float: (float)f_value
607     vout_thread_t *p_vout = getVout();
608     vlc_object_t *p_filter;
610     config_PutFloat(p_intf, psz_name, f_value);
612     if (p_vout) {
613         p_filter = vlc_object_find_name(pl_Get(p_intf), psz_filter);
615         if (!p_filter) {
616             msg_Warn(p_intf, "filter '%s' isn't enabled", psz_filter);
617             vlc_object_release(p_vout);
618             return;
619         }
620         var_SetFloat(p_filter, psz_name, f_value);
621         vlc_object_release(p_vout);
622         vlc_object_release(p_filter);
624         [self restartFilterIfNeeded: psz_filter option: psz_name];
625     }
628 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter string: (char *)psz_value
630     vout_thread_t *p_vout = getVout();
631     vlc_object_t *p_filter;
633     config_PutPsz(p_intf, psz_name, EnsureUTF8(psz_value));
635     if (p_vout) {
636         p_filter = vlc_object_find_name(pl_Get(p_intf), psz_filter);
638         if (!p_filter) {
639             msg_Warn(p_intf, "filter '%s' isn't enabled", psz_filter);
640             vlc_object_release(p_vout);
641             return;
642         }
643         var_SetString(p_filter, psz_name, EnsureUTF8(psz_value));
644         vlc_object_release(p_vout);
645         vlc_object_release(p_filter);
647         [self restartFilterIfNeeded: psz_filter option: psz_name];
648     }
651 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter boolean: (BOOL)b_value
653     vout_thread_t *p_vout = getVout();
654     vlc_object_t *p_filter;
656     config_PutInt(p_intf, psz_name, b_value);
658     if (p_vout) {
659         p_filter = vlc_object_find_name(pl_Get(p_intf), psz_filter);
661         if (!p_filter) {
662             msg_Warn(p_intf, "filter '%s' isn't enabled", psz_filter);
663             vlc_object_release(p_vout);
664             return;
665         }
666         var_SetBool(p_filter, psz_name, b_value);
667         vlc_object_release(p_vout);
668         vlc_object_release(p_filter);
669     }
672 - (NSString *)generateProfileString
674     return [NSString stringWithFormat:@"%s;%s;%s;%lli;%f;%f;%f;%f;%f;%lli;%f;%s;%lli;%lli;%lli;%lli;%lli;%lli;%s;%lli;%lli;%lli;%lli;%lli;%s;%lli;%s;%lli;%lli;%lli;%lli;%lli",
675             vlc_b64_encode(config_GetPsz(p_intf, "video-filter")),
676             vlc_b64_encode(config_GetPsz(p_intf, "sub-source")),
677             vlc_b64_encode(config_GetPsz(p_intf, "video-splitter")),
678             config_GetInt(p_intf, "hue"),
679             config_GetFloat(p_intf, "contrast"),
680             config_GetFloat(p_intf, "brightness"),
681             config_GetFloat(p_intf, "saturation"),
682             config_GetFloat(p_intf, "gamma"),
683             config_GetFloat(p_intf, "sharpen-sigma"),
684             config_GetInt(p_intf, "gradfun-radius"),
685             config_GetFloat(p_intf, "grain-variance"),
686             vlc_b64_encode(config_GetPsz(p_intf, "transform-type")),
687             config_GetInt(p_intf, "puzzle-rows"),
688             config_GetInt(p_intf, "puzzle-cols"),
689             config_GetInt(p_intf, "colorthres-color"),
690             config_GetInt(p_intf, "colorthres-saturationthres"),
691             config_GetInt(p_intf, "colorthres-similaritythres"),
692             config_GetInt(p_intf, "sepia-intensity"),
693             vlc_b64_encode(config_GetPsz(p_intf, "gradient-mode")),
694             config_GetInt(p_intf, "gradient-cartoon"),
695             config_GetInt(p_intf, "gradient-type"),
696             config_GetInt(p_intf, "extract-component"),
697             config_GetInt(p_intf, "posterize-level"),
698             config_GetInt(p_intf, "blur-factor"),
699             vlc_b64_encode(config_GetPsz(p_intf, "marq-marquee")),
700             config_GetInt(p_intf, "marq-position"),
701             vlc_b64_encode(config_GetPsz(p_intf, "logo-file")),
702             config_GetInt(p_intf, "logo-position"),
703             config_GetInt(p_intf, "logo-opacity"),
704             config_GetInt(p_intf, "clone-count"),
705             config_GetInt(p_intf, "wall-rows"),
706             config_GetInt(p_intf, "wall-cols")
707             ];
710 #pragma mark -
711 #pragma mark generic UI code
713 - (void)saveCurrentProfile
715     if (i_old_profile_index == -1)
716         return;
718     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
719     /* fetch all the current settings in a uniform string */
720     NSString *newProfile = [self generateProfileString];
722     NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
723     if (i_old_profile_index >= [workArray count])
724         return;
726     [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile];
727     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
728     [workArray release];
729     [defaults synchronize];
732 - (IBAction)toggleWindow:(id)sender
734     if ([o_window isVisible])
735         [o_window orderOut:sender];
736     else {
737         [o_window setLevel: [[[VLCMain sharedInstance] voutController] currentWindowLevel]];
738         [o_window makeKeyAndOrderFront:sender];
739     }
742 - (IBAction)profileSelectorAction:(id)sender
744     [self saveCurrentProfile];
745     i_old_profile_index = [o_profile_pop indexOfSelectedItem];
747     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
748     NSUInteger selectedProfile = [o_profile_pop indexOfSelectedItem];
750     /* disable all current video filters, if a vout is available */
751     vout_thread_t *p_vout = getVout();
752     if (p_vout) {
753         var_SetString(p_vout, "video-filter", "");
754         var_SetString(p_vout, "sub-source", "");
755         var_SetString(p_vout, "video-splitter", "");
756         vlc_object_release(p_vout);
757     }
759     /* fetch preset */
760     NSArray *items = [[[defaults objectForKey:@"VideoEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
762     /* filter handling */
763     NSString *tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:0] UTF8String])];
764     NSArray *tempArray;
765     NSUInteger count;
766     /* enable the new filters */
767     if ([tempString length] > 0) {
768         tempArray = [tempString componentsSeparatedByString:@":"];
769         count = [tempArray count];
770         for (NSUInteger x = 0; x < count; x++)
771             [self setVideoFilter:(char *)[[tempArray objectAtIndex:x] UTF8String] on:YES];
772     }
773     config_PutPsz(p_intf, "video-filter", [tempString UTF8String]);
775     tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:1] UTF8String])];
776     /* enable another round of new filters */
777     if ([tempString length] > 0) {
778         tempArray = [tempString componentsSeparatedByString:@":"];
779         count = [tempArray count];
780         for (NSUInteger x = 0; x < count; x++)
781             [self setVideoFilter:(char *)[[tempArray objectAtIndex:x] UTF8String] on:YES];
782     }
783     config_PutPsz(p_intf,"sub-source", [tempString UTF8String]);
785     tempString = [NSString stringWithFormat:@"%s", vlc_b64_decode([[items objectAtIndex:2] UTF8String])];
786     /* enable another round of new filters */
787     if ([tempString length] > 0) {
788         tempArray = [tempString componentsSeparatedByString:@":"];
789         count = [tempArray count];
790         for (NSUInteger x = 0; x < count; x++)
791             [self setVideoFilter:(char *)[[tempArray objectAtIndex:x] UTF8String] on:YES];
792     }
793     config_PutPsz(p_intf,"video-splitter", [tempString UTF8String]);
795     /* try to set filter values on-the-fly and store them appropriately */
796     [self setVideoFilterProperty:"hue" forFilter:"adjust" integer:[[items objectAtIndex:3] intValue]];
797     [self setVideoFilterProperty:"contrast" forFilter:"adjust" float:[[items objectAtIndex:4] floatValue]];
798     [self setVideoFilterProperty:"brightness" forFilter:"adjust" float:[[items objectAtIndex:5] floatValue]];
799     [self setVideoFilterProperty:"saturation" forFilter:"adjust" float:[[items objectAtIndex:6] floatValue]];
800     [self setVideoFilterProperty:"gamma" forFilter:"adjust" float:[[items objectAtIndex:7] floatValue]];
801     [self setVideoFilterProperty:"sharpen-sigma" forFilter:"sharpen" float:[[items objectAtIndex:8] floatValue]];
802     [self setVideoFilterProperty:"gradfun-radius" forFilter:"gradfun" integer:[[items objectAtIndex:9] intValue]];
803     [self setVideoFilterProperty:"grain-variance" forFilter:"grain" float:[[items objectAtIndex:10] floatValue]];
804     [self setVideoFilterProperty:"transform-type" forFilter:"transform" string:vlc_b64_decode([[items objectAtIndex:11] UTF8String])];
805     [self setVideoFilterProperty:"puzzle-rows" forFilter:"puzzle" integer:[[items objectAtIndex:12] intValue]];
806     [self setVideoFilterProperty:"puzzle-cols" forFilter:"puzzle" integer:[[items objectAtIndex:13] intValue]];
807     [self setVideoFilterProperty:"colorthres-color" forFilter:"colorthres" integer:[[items objectAtIndex:14] intValue]];
808     [self setVideoFilterProperty:"colorthres-saturationthres" forFilter:"colorthres" integer:[[items objectAtIndex:15] intValue]];
809     [self setVideoFilterProperty:"colorthres-similaritythres" forFilter:"colorthres" integer:[[items objectAtIndex:16] intValue]];
810     [self setVideoFilterProperty:"sepia-intensity" forFilter:"sepia" integer:[[items objectAtIndex:17] intValue]];
811     [self setVideoFilterProperty:"gradient-mode" forFilter:"gradient" string:vlc_b64_decode([[items objectAtIndex:18] UTF8String])];
812     [self setVideoFilterProperty:"gradient-cartoon" forFilter:"gradient" integer:[[items objectAtIndex:19] intValue]];
813     [self setVideoFilterProperty:"gradient-type" forFilter:"gradient" integer:[[items objectAtIndex:20] intValue]];
814     [self setVideoFilterProperty:"extract-component" forFilter:"extract" integer:[[items objectAtIndex:21] intValue]];
815     [self setVideoFilterProperty:"posterize-level" forFilter:"posterize" integer:[[items objectAtIndex:22] intValue]];
816     [self setVideoFilterProperty:"blur-factor" forFilter:"motionblur" integer:[[items objectAtIndex:23] intValue]];
817     [self setVideoFilterProperty:"marq-marquee" forFilter:"marq" string:vlc_b64_decode([[items objectAtIndex:24] UTF8String])];
818     [self setVideoFilterProperty:"marq-position" forFilter:"marq" integer:[[items objectAtIndex:25] intValue]];
819     [self setVideoFilterProperty:"logo-file" forFilter:"logo" string:vlc_b64_decode([[items objectAtIndex:26] UTF8String])];
820     [self setVideoFilterProperty:"logo-position" forFilter:"logo" integer:[[items objectAtIndex:27] intValue]];
821     [self setVideoFilterProperty:"logo-opacity" forFilter:"logo" integer:[[items objectAtIndex:28] intValue]];
822     [self setVideoFilterProperty:"clone-count" forFilter:"clone" integer:[[items objectAtIndex:29] intValue]];
823     [self setVideoFilterProperty:"wall-rows" forFilter:"wall" integer:[[items objectAtIndex:30] intValue]];
824     [self setVideoFilterProperty:"wall-cols" forFilter:"wall" integer:[[items objectAtIndex:31] intValue]];
826     [defaults setInteger:selectedProfile forKey:@"VideoEffectSelectedProfile"];
827     [defaults synchronize];
829     [self resetValues];
832 - (IBAction)addProfile:(id)sender
834     /* show panel */
835     VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
836     [panel setTitle: _NS("Duplicate current profile for a new profile")];
837     [panel setSubTitle: _NS("Enter a name for the new profile:")];
838     [panel setCancelButtonLabel: _NS("Cancel")];
839     [panel setOKButtonLabel: _NS("Save")];
840     [panel setTarget:self];
842     [panel runModalForWindow:o_window];
845 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
847     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
849     if (value != NSOKButton) {
850         [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
851         return;
852     }
854     NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"];
856     // duplicate names are not allowed in the popup control
857     if ([text length] == 0 || [profileNames containsObject:text]) {
858         [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
860         NSAlert *alert = [[[NSAlert alloc] init] autorelease];
861         [alert setAlertStyle:NSCriticalAlertStyle];
862         [alert setMessageText:_NS("Please enter a unique name for the new profile.")];
863         [alert setInformativeText:_NS("Multiple profiles with the same name are not allowed.")];
865         [alert beginSheetModalForWindow:o_window
866                           modalDelegate:nil
867                          didEndSelector:nil
868                             contextInfo:nil];
869         return;
870     }
872     /* fetch all the current settings in a uniform string */
873     NSString *newProfile = [self generateProfileString];
875     /* add string to user defaults as well as a label */
877     NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
878     [workArray addObject:newProfile];
879     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
880     [defaults setInteger:[workArray count] - 1 forKey:@"VideoEffectSelectedProfile"];
881     [workArray release];
882     
883     workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfileNames"]];
884     [workArray addObject:text];
885     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
886     [workArray release];
888     /* save defaults */
889     [defaults synchronize];
891     /* refresh UI */
892     [self resetProfileSelector];
895 - (IBAction)removeProfile:(id)sender
897     /* show panel */
898     VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
899     [panel setTitle:_NS("Remove a preset")];
900     [panel setSubTitle:_NS("Select the preset you would like to remove:")];
901     [panel setOKButtonLabel:_NS("Remove")];
902     [panel setCancelButtonLabel:_NS("Cancel")];
903     [panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]];
904     [panel setTarget:self];
906     [panel runModalForWindow:o_window];
909 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
911     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
913     if (value != NSOKButton) {
914         [o_profile_pop selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
915         return;
916     }
918     /* remove selected profile from settings */
919     NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]];
920     [workArray removeObjectAtIndex:item];
921     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
922     [workArray release];
924     workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfileNames"]];
925     [workArray removeObjectAtIndex:item];
926     [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
927     [workArray release];
929     if (i_old_profile_index >= item)
930         [defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"];
932     /* save defaults */
933     [defaults synchronize];
935     /* do not save deleted profile */
936     i_old_profile_index = -1;
937     /* refresh UI */
938     [self resetProfileSelector];
941 #pragma mark -
942 #pragma mark basic
943 - (IBAction)enableAdjust:(id)sender
945     BOOL b_state = [o_adjust_ckb state];
947     [self setVideoFilter: "adjust" on: b_state];
948     [o_adjust_brightness_sld setEnabled: b_state];
949     [o_adjust_brightness_ckb setEnabled: b_state];
950     [o_adjust_brightness_lbl setEnabled: b_state];
951     [o_adjust_contrast_sld setEnabled: b_state];
952     [o_adjust_contrast_lbl setEnabled: b_state];
953     [o_adjust_gamma_sld setEnabled: b_state];
954     [o_adjust_gamma_lbl setEnabled: b_state];
955     [o_adjust_hue_sld setEnabled: b_state];
956     [o_adjust_hue_lbl setEnabled: b_state];
957     [o_adjust_saturation_sld setEnabled: b_state];
958     [o_adjust_saturation_lbl setEnabled: b_state];
959     [o_adjust_reset_btn setEnabled: b_state];
962 - (IBAction)adjustSliderChanged:(id)sender
964     if (sender == o_adjust_brightness_sld)
965         [self setVideoFilterProperty: "brightness" forFilter: "adjust" float: [o_adjust_brightness_sld floatValue]];
966     else if (sender == o_adjust_contrast_sld)
967         [self setVideoFilterProperty: "contrast" forFilter: "adjust" float: [o_adjust_contrast_sld floatValue]];
968     else if (sender == o_adjust_gamma_sld)
969         [self setVideoFilterProperty: "gamma" forFilter: "adjust" float: [o_adjust_gamma_sld floatValue]];
970     else if (sender == o_adjust_hue_sld)
971         [self setVideoFilterProperty: "hue" forFilter: "adjust" integer: [o_adjust_hue_sld intValue]];
972     else if (sender == o_adjust_saturation_sld)
973         [self setVideoFilterProperty: "saturation" forFilter: "adjust" float: [o_adjust_saturation_sld floatValue]];
975     if (sender == o_adjust_hue_sld)
976         [o_adjust_hue_sld setToolTip: [NSString stringWithFormat:@"%i", [o_adjust_hue_sld intValue]]];
977     else
978         [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
981 - (IBAction)enableAdjustBrightnessThreshold:(id)sender
983     if (sender == o_adjust_reset_btn) {
984         [o_adjust_brightness_sld setFloatValue: 1.0];
985         [o_adjust_contrast_sld setFloatValue: 1.0];
986         [o_adjust_gamma_sld setFloatValue: 1.0];
987         [o_adjust_hue_sld setIntValue: 0];
988         [o_adjust_saturation_sld setFloatValue: 1.0];
989         [o_adjust_brightness_sld setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
990         [o_adjust_contrast_sld setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
991         [o_adjust_gamma_sld setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
992         [o_adjust_hue_sld setToolTip: [NSString stringWithFormat:@"%i", 0]];
993         [o_adjust_saturation_sld setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
994         [self setVideoFilterProperty: "brightness" forFilter: "adjust" float: 1.0];
995         [self setVideoFilterProperty: "contrast" forFilter: "adjust" float: 1.0];
996         [self setVideoFilterProperty: "gamma" forFilter: "adjust" float: 1.0];
997         [self setVideoFilterProperty: "hue" forFilter: "adjust" integer: 0.0];
998         [self setVideoFilterProperty: "saturation" forFilter: "adjust" float: 1.0];
999     } else
1000         config_PutInt(p_intf, "brightness-threshold", [o_adjust_brightness_ckb state]);
1003 - (IBAction)enableSharpen:(id)sender
1005     BOOL b_state = [o_sharpen_ckb state];
1007     [self setVideoFilter: "sharpen" on: b_state];
1008     [o_sharpen_sld setEnabled: b_state];
1009     [o_sharpen_lbl setEnabled: b_state];
1012 - (IBAction)sharpenSliderChanged:(id)sender
1014     [self setVideoFilterProperty: "sharpen-sigma" forFilter: "sharpen" float: [sender floatValue]];
1015     [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
1018 - (IBAction)enableBanding:(id)sender
1020     BOOL b_state = [o_banding_ckb state];
1022     [self setVideoFilter: "gradfun" on: b_state];
1023     [o_banding_sld setEnabled: b_state];
1024     [o_banding_lbl setEnabled: b_state];
1027 - (IBAction)bandingSliderChanged:(id)sender
1029     [self setVideoFilterProperty: "gradfun-radius" forFilter: "gradfun" integer: [sender intValue]];
1030     [sender setToolTip: [NSString stringWithFormat:@"%i", [sender intValue]]];
1033 - (IBAction)enableGrain:(id)sender
1035     BOOL b_state = [o_grain_ckb state];
1037     [self setVideoFilter: "grain" on: b_state];
1038     [o_grain_sld setEnabled: b_state];
1039     [o_grain_lbl setEnabled: b_state];
1042 - (IBAction)grainSliderChanged:(id)sender
1044     [self setVideoFilterProperty: "grain-variance" forFilter: "grain" float: [sender floatValue]];
1045     [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
1049 #pragma mark -
1050 #pragma mark crop
1052 - (IBAction)cropObjectChanged:(id)sender
1054     if ([o_crop_sync_top_bottom_ckb state]) {
1055         if (sender == o_crop_bottom_fld || sender == o_crop_bottom_stp)
1056             [self setCropTopValue: [self cropBottomValue]];
1057         else
1058             [self setCropBottomValue: [self cropTopValue]];
1059     }
1060     if ([o_crop_sync_left_right_ckb state]) {
1061         if (sender == o_crop_right_fld || sender == o_crop_right_stp)
1062             [self setCropLeftValue: [self cropRightValue]];
1063         else
1064             [self setCropRightValue: [self cropLeftValue]];
1065     }
1067     vout_thread_t *p_vout = getVout();
1068     if (p_vout) {
1069         var_SetInteger(p_vout, "crop-top", [o_crop_top_fld intValue]);
1070         var_SetInteger(p_vout, "crop-bottom", [o_crop_bottom_fld intValue]);
1071         var_SetInteger(p_vout, "crop-left", [o_crop_left_fld intValue]);
1072         var_SetInteger(p_vout, "crop-right", [o_crop_right_fld intValue]);
1073         vlc_object_release(p_vout);
1074     }
1077 #pragma mark -
1078 #pragma mark geometry
1079 - (IBAction)enableTransform:(id)sender
1081     [self setVideoFilter: "transform" on: [o_transform_ckb state]];
1082     [o_transform_pop setEnabled: [o_transform_ckb state]];
1085 - (IBAction)transformModifierChanged:(id)sender
1087     NSInteger tag = [[o_transform_pop selectedItem] tag];
1088     char *psz_string = (char *)[[NSString stringWithFormat:@"%li", tag] UTF8String];
1089     if (tag == 1)
1090         psz_string = (char *)"hflip";
1091     else if (tag == 2)
1092         psz_string = (char *)"vflip";
1094     [self setVideoFilterProperty: "transform-type" forFilter: "transform" string: psz_string];
1097 - (IBAction)enableZoom:(id)sender
1099     [self setVideoFilter: "magnify" on: [o_zoom_ckb state]];
1102 - (IBAction)enablePuzzle:(id)sender
1104     BOOL b_state = [o_puzzle_ckb state];
1106     [self setVideoFilter: "puzzle" on: b_state];
1107     [o_puzzle_columns_fld setEnabled: b_state];
1108     [o_puzzle_columns_stp setEnabled: b_state];
1109     [o_puzzle_columns_lbl setEnabled: b_state];
1110     [o_puzzle_rows_fld setEnabled: b_state];
1111     [o_puzzle_rows_stp setEnabled: b_state];
1112     [o_puzzle_rows_lbl setEnabled: b_state];
1115 - (IBAction)puzzleModifierChanged:(id)sender
1117     if (sender == o_puzzle_columns_fld || sender == o_puzzle_columns_stp)
1118         [self setVideoFilterProperty: "puzzle-cols" forFilter: "puzzle" integer: [sender intValue]];
1119     else
1120         [self setVideoFilterProperty: "puzzle-rows" forFilter: "puzzle" integer: [sender intValue]];
1123 - (IBAction)enableClone:(id)sender
1125     BOOL b_state = [o_clone_ckb state];
1127     if (b_state && [o_wall_ckb state]) {
1128         [o_wall_ckb setState: NSOffState];
1129         [self enableWall: o_wall_ckb];
1130     }
1132     [self setVideoFilter: "clone" on: b_state];
1133     [o_clone_number_lbl setEnabled: b_state];
1134     [o_clone_number_fld setEnabled: b_state];
1135     [o_clone_number_stp setEnabled: b_state];
1138 - (IBAction)cloneModifierChanged:(id)sender
1140     [self setVideoFilterProperty: "clone-count" forFilter: "clone" integer: [o_clone_number_fld intValue]];
1143 - (IBAction)enableWall:(id)sender
1145     BOOL b_state = [o_wall_ckb state];
1147     if (b_state && [o_clone_ckb state]) {
1148         [o_clone_ckb setState: NSOffState];
1149         [self enableClone: o_clone_ckb];
1150     }
1152     [self setVideoFilter: "wall" on: b_state];
1153     [o_wall_numofcols_fld setEnabled: b_state];
1154     [o_wall_numofcols_stp setEnabled: b_state];
1155     [o_wall_numofcols_lbl setEnabled: b_state];
1156     
1157     [o_wall_numofrows_fld setEnabled: b_state];
1158     [o_wall_numofrows_stp setEnabled: b_state];
1159     [o_wall_numofrows_lbl setEnabled: b_state];
1162 - (IBAction)wallModifierChanged:(id)sender
1164     if (sender == o_wall_numofcols_fld || sender == o_wall_numofcols_stp)
1165         [self setVideoFilterProperty: "wall-cols" forFilter: "wall" integer: [sender intValue]];
1166     else
1167         [self setVideoFilterProperty: "wall-rows" forFilter: "wall" integer: [sender intValue]];
1170 #pragma mark -
1171 #pragma mark color
1172 - (IBAction)enableThreshold:(id)sender
1174     BOOL b_state = [o_threshold_ckb state];
1176     [self setVideoFilter: "colorthres" on: b_state];
1177     [o_threshold_color_fld setEnabled: b_state];
1178     [o_threshold_color_lbl setEnabled: b_state];
1179     [o_threshold_saturation_sld setEnabled: b_state];
1180     [o_threshold_saturation_lbl setEnabled: b_state];
1181     [o_threshold_similarity_sld setEnabled: b_state];
1182     [o_threshold_similarity_lbl setEnabled: b_state];
1185 - (IBAction)thresholdModifierChanged:(id)sender
1187     if (sender == o_threshold_color_fld)
1188         [self setVideoFilterProperty: "colorthres-color" forFilter: "colorthres" integer: [o_threshold_color_fld intValue]];
1189     else if (sender == o_threshold_saturation_sld) {
1190         [self setVideoFilterProperty: "colorthres-saturationthres" forFilter: "colorthres" integer: [o_threshold_saturation_sld intValue]];
1191         [o_threshold_saturation_sld setToolTip: [NSString stringWithFormat:@"%i", [o_threshold_saturation_sld intValue]]];
1192     } else {
1193         [self setVideoFilterProperty: "colorthres-similaritythres" forFilter: "colorthres" integer: [o_threshold_similarity_sld intValue]];
1194         [o_threshold_similarity_sld setToolTip: [NSString stringWithFormat:@"%i", [o_threshold_similarity_sld intValue]]];
1195     }
1198 - (IBAction)enableSepia:(id)sender
1200     BOOL b_state = [o_sepia_ckb state];
1202     [self setVideoFilter: "sepia" on: b_state];
1203     [o_sepia_fld setEnabled: b_state];
1204     [o_sepia_stp setEnabled: b_state];
1205     [o_sepia_lbl setEnabled: b_state];
1208 - (IBAction)sepiaModifierChanged:(id)sender
1210     [self setVideoFilterProperty: "sepia-intensity" forFilter: "sepia" integer: [o_sepia_fld intValue]];
1213 - (IBAction)enableNoise:(id)sender
1215     [self setVideoFilter: "noise" on: [o_noise_ckb state]];
1218 - (IBAction)enableGradient:(id)sender
1220     BOOL b_state = [o_gradient_ckb state];
1222     [self setVideoFilter: "gradient" on: b_state];
1223     [o_gradient_mode_pop setEnabled: b_state];
1224     [o_gradient_mode_lbl setEnabled: b_state];
1225     [o_gradient_color_ckb setEnabled: b_state];
1226     [o_gradient_cartoon_ckb setEnabled: b_state];
1229 - (IBAction)gradientModifierChanged:(id)sender
1231     if (sender == o_gradient_mode_pop) {
1232         if ([[o_gradient_mode_pop selectedItem] tag] == 3)
1233             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "hough"];
1234         else if ([[o_gradient_mode_pop selectedItem] tag] == 2)
1235             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "edge"];
1236         else
1237             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "gradient"];
1238     } else if (sender == o_gradient_color_ckb)
1239         [self setVideoFilterProperty: "gradient-type" forFilter: "gradient" integer: [o_gradient_color_ckb state]];
1240     else
1241         [self setVideoFilterProperty: "gradient-cartoon" forFilter: "gradient" boolean: [o_gradient_cartoon_ckb state]];
1244 - (IBAction)enableExtract:(id)sender
1246     BOOL b_state = [o_extract_ckb state];
1247     [self setVideoFilter: "extract" on: b_state];
1248     [o_extract_fld setEnabled: b_state];
1249     [o_extract_lbl setEnabled: b_state];
1252 - (IBAction)extractModifierChanged:(id)sender
1254     [self setVideoFilterProperty: "extract-component" forFilter: "extract" integer: [o_extract_fld intValue]];
1257 - (IBAction)enableInvert:(id)sender
1259     [self setVideoFilter: "invert" on: [o_invert_ckb state]];
1262 - (IBAction)enablePosterize:(id)sender
1264     BOOL b_state = [o_posterize_ckb state];
1266     [self setVideoFilter: "posterize" on: b_state];
1267     [o_posterize_fld setEnabled: b_state];
1268     [o_posterize_stp setEnabled: b_state];
1269     [o_posterize_lbl setEnabled: b_state];
1272 - (IBAction)posterizeModifierChanged:(id)sender
1274     [self setVideoFilterProperty: "posterize-level" forFilter: "posterize" integer: [o_posterize_fld intValue]];
1277 - (IBAction)enableBlur:(id)sender
1279     BOOL b_state = [o_blur_ckb state];
1281     [self setVideoFilter: "motionblur" on: b_state];
1282     [o_blur_sld setEnabled: b_state];
1283     [o_blur_lbl setEnabled: b_state];
1286 - (IBAction)blurModifierChanged:(id)sender
1288     [self setVideoFilterProperty: "blur-factor" forFilter: "motionblur" integer: [sender intValue]];
1289     [sender setToolTip: [NSString stringWithFormat:@"%i", [sender intValue]]];
1292 - (IBAction)enableMotionDetect:(id)sender
1294     [self setVideoFilter: "motiondetect" on: [o_motiondetect_ckb state]];
1297 - (IBAction)enableWaterEffect:(id)sender
1299     [self setVideoFilter: "ripple" on: [o_watereffect_ckb state]];
1302 - (IBAction)enableWaves:(id)sender
1304     [self setVideoFilter: "wave" on: [o_waves_ckb state]];
1307 - (IBAction)enablePsychedelic:(id)sender
1309     [self setVideoFilter: "psychedelic" on: [o_psychedelic_ckb state]];
1312 #pragma mark -
1313 #pragma mark Miscellaneous
1314 - (IBAction)enableAddText:(id)sender
1316     BOOL b_state = [o_addtext_ckb state];
1318     [o_addtext_pos_pop setEnabled: b_state];
1319     [o_addtext_pos_lbl setEnabled: b_state];
1320     [o_addtext_text_lbl setEnabled: b_state];
1321     [o_addtext_text_fld setEnabled: b_state];
1322     [self setVideoFilter: "marq" on: b_state];
1323     [self setVideoFilterProperty: "marq-marquee" forFilter: "marq" string: (char *)[[o_addtext_text_fld stringValue] UTF8String]];
1324     [self setVideoFilterProperty: "marq-position" forFilter: "marq" integer: [[o_addtext_pos_pop selectedItem] tag]];
1327 - (IBAction)addTextModifierChanged:(id)sender
1329     if (sender == o_addtext_text_fld)
1330         [self setVideoFilterProperty: "marq-marquee" forFilter: "marq" string: (char *)[[o_addtext_text_fld stringValue] UTF8String]];
1331     else
1332         [self setVideoFilterProperty: "marq-position" forFilter: "marq" integer: [[o_addtext_pos_pop selectedItem] tag]];
1335 - (IBAction)enableAddLogo:(id)sender
1337     BOOL b_state = [o_addlogo_ckb state];
1339     [o_addlogo_pos_pop setEnabled: b_state];
1340     [o_addlogo_pos_lbl setEnabled: b_state];
1341     [o_addlogo_logo_fld setEnabled: b_state];
1342     [o_addlogo_logo_lbl setEnabled: b_state];
1343     [o_addlogo_transparency_sld setEnabled: b_state];
1344     [o_addlogo_transparency_lbl setEnabled: b_state];
1345     [self setVideoFilter: "logo" on: b_state];
1348 - (IBAction)addLogoModifierChanged:(id)sender
1350     if (sender == o_addlogo_logo_fld)
1351         [self setVideoFilterProperty: "logo-file" forFilter: "logo" string: (char *)[[o_addlogo_logo_fld stringValue] UTF8String]];
1352     else if (sender == o_addlogo_pos_pop)
1353         [self setVideoFilterProperty: "logo-position" forFilter: "logo" integer: [[o_addlogo_pos_pop selectedItem] tag]];
1354     else {
1355         [self setVideoFilterProperty: "logo-opacity" forFilter: "logo" integer: [o_addlogo_transparency_sld intValue]];
1356         [o_addlogo_transparency_sld setToolTip: [NSString stringWithFormat:@"%i", [o_addlogo_transparency_sld intValue]]];
1357     }
1360 - (IBAction)enableAnaglyph:(id)sender
1362     [self setVideoFilter: "anaglyph" on: [o_anaglyph_ckb state]];
1365 @end