1 /* HBAdvancedController
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #import "HBAdvancedController.h"
9 @implementation HBAdvancedController
19 - (void) setView: (NSBox *) box
22 [fOptionsBox setContentView:fX264optView];
25 - (BOOL) loadMyNibFile
27 if(![NSBundle loadNibNamed:@"AdvancedView" owner:self])
29 NSLog(@"Warning! Could not load myNib file.\n");
36 - (NSString *) optionsString
38 return [fDisplayX264Options stringValue];
41 - (void) setOptions: (NSString *)string
43 [fDisplayX264Options setStringValue:string];
44 [self X264AdvancedOptionsSet:nil];
47 - (void) setHidden: (BOOL) hide
51 [fOptionsBox setContentView:fEmptyView];
52 [fX264optViewTitleLabel setStringValue: @"Only Used With The x264 (H.264) Codec"];
56 [fOptionsBox setContentView:fX264optView];
57 [fX264optViewTitleLabel setStringValue: @""];
62 - (void) enableUI: (bool) b
65 NSControl * controls[] =
66 { fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
67 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,fX264optNfpskipLabel,fX264optNfpskipSwitch,
68 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
69 fX264optTrellisLabel,fX264optTrellisPopUp,fX264optMixedRefsLabel,fX264optMixedRefsSwitch,
70 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
71 fX264optWeightBLabel,fX264optWeightBSwitch, fX264optBPyramidLabel,fX264optBPyramidSwitch,
72 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
73 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
74 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp, fX264optPsyRDSlider, fX264optPsyRDLabel, fX264optPsyTrellisSlider, fX264optPsyTrellisLabel, fX264optBAdaptPopUp, fX264optBAdaptLabel };
76 for( i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ )
78 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
80 NSTextField * tf = (NSTextField *) controls[i];
83 [tf setTextColor: b ? [NSColor controlTextColor] :
84 [NSColor disabledControlTextColor]];
88 [controls[i] setEnabled: b];
92 [fX264optView setWantsLayer:YES];
101 * Populates the option widgets
103 - (IBAction) X264AdvancedOptionsSet: (id) sender
105 /*Set opt widget values here*/
107 /*B-Frames fX264optBframesPopUp*/
109 [fX264optBframesPopUp removeAllItems];
110 [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
113 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
116 /*Reference Frames fX264optRefPopUp*/
117 [fX264optRefPopUp removeAllItems];
118 [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
121 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
124 /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
125 [fX264optNfpskipSwitch setState:0];
127 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
128 [fX264optNodctdcmtSwitch setState:0];
130 /*Sub Me fX264optSubmePopUp*/
131 [fX264optSubmePopUp removeAllItems];
132 [fX264optSubmePopUp addItemWithTitle:@"Default (6)"];
135 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
138 /*Trellis fX264optTrellisPopUp*/
139 [fX264optTrellisPopUp removeAllItems];
140 [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
143 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
145 [fX264optTrellisPopUp setWantsLayer:YES];
147 /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
148 [fX264optMixedRefsSwitch setState:0];
149 [fX264optMixedRefsSwitch setWantsLayer:YES];
151 /*Motion Estimation fX264optMotionEstPopUp*/
152 [fX264optMotionEstPopUp removeAllItems];
153 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
154 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
155 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
156 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
157 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
158 [fX264optMotionEstPopUp addItemWithTitle:@"Transformed Exhaustive"];
160 /*Motion Estimation range fX264optMERangePopUp*/
161 [fX264optMERangePopUp removeAllItems];
162 [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
165 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
168 /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
169 [fX264optWeightBSwitch setState:0];
170 [fX264optWeightBSwitch setWantsLayer:YES];
172 /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
173 [fX264optBPyramidSwitch setState:0];
174 [fX264optBPyramidSwitch setWantsLayer:YES];
176 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
177 [fX264optDirectPredPopUp removeAllItems];
178 [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
179 [fX264optDirectPredPopUp addItemWithTitle:@"None"];
180 [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
181 [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
182 [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
183 [fX264optDirectPredPopUp setWantsLayer:YES];
185 /* Adaptive B-Frames Mode fX264optBAdaptPopUp */
186 [fX264optBAdaptPopUp removeAllItems];
187 [fX264optBAdaptPopUp addItemWithTitle:@"Default (1)"];
188 [fX264optBAdaptPopUp addItemWithTitle:@"0"];
189 [fX264optBAdaptPopUp addItemWithTitle:@"1"];
190 [fX264optBAdaptPopUp addItemWithTitle:@"2"];
191 [fX264optBAdaptPopUp setWantsLayer:YES];
194 [fX264optAlphaDeblockPopUp removeAllItems];
195 [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
198 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
202 [fX264optBetaDeblockPopUp removeAllItems];
203 [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
206 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
209 /* Analysis fX264optAnalysePopUp */
210 [fX264optAnalysePopUp removeAllItems];
211 [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
212 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
213 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
215 /* 8x8 DCT fX264op8x8dctSwitch */
216 [fX264opt8x8dctSwitch setState:0];
217 [fX264opt8x8dctSwitch setWantsLayer:YES];
219 /* CABAC fX264opCabacSwitch */
220 [fX264optCabacSwitch setState:1];
222 /* PsyRDO fX264optPsyRDSlider */
223 [fX264optPsyRDSlider setMinValue:0.0];
224 [fX264optPsyRDSlider setMaxValue:1.0];
225 [fX264optPsyRDSlider setTickMarkPosition:NSTickMarkBelow];
226 [fX264optPsyRDSlider setNumberOfTickMarks:10];
227 [fX264optPsyRDSlider setAllowsTickMarkValuesOnly:YES];
228 [fX264optPsyRDSlider setFloatValue:1.0];
230 /* PsyTrellis fX264optPsyRDSlider */
231 [fX264optPsyTrellisSlider setMinValue:0.0];
232 [fX264optPsyTrellisSlider setMaxValue:1.0];
233 [fX264optPsyTrellisSlider setTickMarkPosition:NSTickMarkBelow];
234 [fX264optPsyTrellisSlider setNumberOfTickMarks:10];
235 [fX264optPsyTrellisSlider setAllowsTickMarkValuesOnly:YES];
236 [fX264optPsyTrellisSlider setFloatValue:0.0];
238 /* Standardize the option string */
239 [self X264AdvancedOptionsStandardizeOptString:nil];
241 /* Set Current GUI Settings based on newly standardized string */
242 [self X264AdvancedOptionsSetCurrentSettings:sender];
244 /* Fade out options that don't apply */
245 [self X264AdvancedOptionsAnimate: sender];
249 * Cleans the option string to use a standard format of option=value
251 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
253 /* Set widgets depending on the opt string in field */
254 NSString * thisOpt; // The separated option such as "bframes=3"
255 NSString * optName = @""; // The option name such as "bframes"
256 NSString * optValue = @"";// The option value such as "3"
257 NSString * changedOptString = @"";
258 NSArray *currentOptsArray;
260 /*First, we get an opt string to process */
261 NSString *currentOptString = [fDisplayX264Options stringValue];
263 /* Verify there is an opt string to process by making sure an
264 option is getting its value set. If so, start to process it. */
265 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
266 if (currentOptRange.location != NSNotFound)
268 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
269 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
271 /*iterate through the array and get <opts> and <values*/
273 int currentOptsArrayCount = [currentOptsArray count];
274 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
276 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
278 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
279 if (splitOptRange.location != NSNotFound)
281 optName = [thisOpt substringToIndex:splitOptRange.location];
282 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
284 /* Standardize the names here depending on whats in the string */
285 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
286 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
288 else // No value given so we use a default of "1"
292 /* Standardize the names here depending on whats in the string */
293 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
294 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
297 /* Construct New String for opts here.*/
298 if ([thisOpt isEqualToString:@""])
300 /* Blank option, just add it to the string. (Why?) */
301 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
305 if ([changedOptString isEqualToString:@""])
307 /* Blank string, output the current option. */
308 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
312 /* Option exists and string exists, so append the option
313 to the string with a semi-colon inbetween them. */
314 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
320 /* Change the option string to reflect the new standardized option string */
321 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
325 * Cleans the option string to use a standard set of option names, by conflating synonyms.
327 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
329 /* Reference Frames */
330 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
332 cleanOptNameString = @"ref";
335 /*No Fast PSkip nofast_pskip*/
336 if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
338 cleanOptNameString = @"no-fast-pskip";
342 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
344 cleanOptNameString = @"no-dct-decimate";
348 if ([cleanOptNameString isEqualToString:@"subme"])
350 cleanOptNameString = @"subq";
354 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
355 cleanOptNameString = @"merange";
358 if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
360 cleanOptNameString = @"weightb";
364 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
366 cleanOptNameString = @"b-pyramid";
369 /*Direct Prediction*/
370 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
372 cleanOptNameString = @"direct";
376 if ([cleanOptNameString isEqualToString:@"filter"])
378 cleanOptNameString = @"deblock";
382 if ([cleanOptNameString isEqualToString:@"partitions"])
384 cleanOptNameString = @"analyse";
387 return cleanOptNameString;
391 * Fades options in and out depending on whether they're available..
393 - (IBAction) X264AdvancedOptionsAnimate: (id) sender
395 /* Lots of situations to cover.
396 - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)
397 - CABAC (when 0 turn off trellis)
398 - analysis (if none, turn off 8x8dct)
399 - refs (under 2, disable mixed-refs)
400 - subme (if under 6, turn off psy-rd and psy-trel)
401 - trellis (if 0, turn off psy-trel)
404 if( sender == fX264optBframesPopUp || sender == nil || sender == fDisplayX264Options )
407 fprintf(stderr, "Bframes sender is nil!\n");
408 else if( sender == fDisplayX264Options )
409 fprintf(stderr, "Bframes sender is text box!\n");
411 if ( [fX264optBframesPopUp indexOfSelectedItem ] < 2)
413 /* If the b-frame widget is at 0 or 1, the user has chosen
414 not to use b-frames at all. So disable the options
415 that can only be used when b-frames are enabled. */
417 if( [fX264optWeightBSwitch isHidden] == false)
419 [[fX264optWeightBSwitch animator] setHidden:YES];
420 [[fX264optWeightBLabel animator] setHidden:YES];
421 if ( [fX264optWeightBSwitch state] == 1 )
422 [fX264optWeightBSwitch performClick:self];
425 if( [fX264optBPyramidSwitch isHidden] == false )
427 [[fX264optBPyramidSwitch animator] setHidden:YES];
428 [[fX264optBPyramidLabel animator] setHidden:YES];
429 if ( [fX264optBPyramidSwitch state] == 1 )
430 [fX264optBPyramidSwitch performClick:self];
433 if( [fX264optDirectPredPopUp isHidden] == false )
435 [[fX264optDirectPredPopUp animator] setHidden:YES];
436 [[fX264optDirectPredLabel animator] setHidden:YES];
437 if ( [fX264optDirectPredPopUp indexOfSelectedItem] > 0 )
439 [fX264optDirectPredPopUp selectItemAtIndex: 0];
440 [[fX264optDirectPredPopUp cell] performClick:self];
444 if( [fX264optBAdaptPopUp isHidden] == false )
446 [[fX264optBAdaptPopUp animator] setHidden:YES];
447 [[fX264optBAdaptLabel animator] setHidden:YES];
448 if ( [fX264optBAdaptPopUp indexOfSelectedItem] > 0 )
450 [fX264optBAdaptPopUp selectItemAtIndex: 0];
451 [[fX264optBAdaptPopUp cell] performClick:self];
455 else if ( [fX264optBframesPopUp indexOfSelectedItem ] == 2)
457 /* Only 1 b-frame? Disable b-pyramid. */
458 if( [fX264optBPyramidSwitch isHidden] == false )
460 [[fX264optBPyramidSwitch animator] setHidden:YES];
461 [[fX264optBPyramidLabel animator] setHidden:YES];
462 if ( [fX264optBPyramidSwitch state] == 1 )
463 [fX264optBPyramidSwitch performClick:self];
466 if( [fX264optWeightBSwitch isHidden] == true )
468 [[fX264optWeightBSwitch animator] setHidden:NO];
469 [[fX264optWeightBLabel animator] setHidden:NO];
472 if( [fX264optDirectPredPopUp isHidden] == true )
474 [[fX264optDirectPredPopUp animator] setHidden:NO];
475 [[fX264optDirectPredLabel animator] setHidden:NO];
478 if( [fX264optBAdaptPopUp isHidden] == true )
480 [[fX264optBAdaptPopUp animator] setHidden:NO];
481 [[fX264optBAdaptLabel animator] setHidden:NO];
486 if( [fX264optBPyramidSwitch isHidden] == true )
488 [[fX264optBPyramidSwitch animator] setHidden:NO];
489 [[fX264optBPyramidLabel animator] setHidden:NO];
492 if( [fX264optWeightBSwitch isHidden] == true )
494 [[fX264optWeightBSwitch animator] setHidden:NO];
495 [[fX264optWeightBLabel animator] setHidden:NO];
498 if( [fX264optDirectPredPopUp isHidden] == true )
500 [[fX264optDirectPredPopUp animator] setHidden:NO];
501 [[fX264optDirectPredLabel animator] setHidden:NO];
504 if( [fX264optBAdaptPopUp isHidden] == true )
506 [[fX264optBAdaptPopUp animator] setHidden:NO];
507 [[fX264optBAdaptLabel animator] setHidden:NO];
512 if( sender == fX264optCabacSwitch || sender == nil || sender == fDisplayX264Options )
514 if ( [fX264optCabacSwitch state] == false)
516 if( [fX264optTrellisPopUp isHidden] == false )
518 /* Without CABAC entropy coding, trellis doesn't run. */
519 [[fX264optTrellisPopUp animator] setHidden:YES];
520 [[fX264optTrellisLabel animator] setHidden:YES];
521 [fX264optTrellisPopUp selectItemAtIndex:0];
522 [[fX264optTrellisPopUp cell] performClick:self];
525 else if( [fX264optTrellisPopUp isHidden] == true)
527 [[fX264optTrellisPopUp animator] setHidden:NO];
528 [[fX264optTrellisLabel animator] setHidden:NO];
532 if( sender == fX264optAnalysePopUp || sender == nil || sender == fDisplayX264Options )
534 if ( [fX264optAnalysePopUp indexOfSelectedItem] == 1)
536 /* No analysis? Disable 8x8dct */
537 if( [fX264opt8x8dctSwitch isHidden] == false )
539 [[fX264opt8x8dctSwitch animator] setHidden:YES];
540 [[fX264opt8x8dctLabel animator] setHidden:YES];
541 if ( [fX264opt8x8dctSwitch state] == 1 )
542 [fX264opt8x8dctSwitch performClick:self];
547 if( [fX264opt8x8dctSwitch isHidden] == true )
549 [[fX264opt8x8dctSwitch animator] setHidden:NO];
550 [[fX264opt8x8dctLabel animator] setHidden:NO];
555 if( sender == fX264optRefPopUp || sender == nil || sender == fDisplayX264Options )
557 if ( [fX264optRefPopUp indexOfSelectedItem] < 3)
559 if( [fX264optMixedRefsSwitch isHidden] == false )
561 /* Only do mixed-refs when there are at least 2 refs to mix. */
562 [[fX264optMixedRefsSwitch animator] setHidden:YES];
563 [[fX264optMixedRefsLabel animator] setHidden:YES];
564 if( [fX264optMixedRefsSwitch state] == 1 )
565 [fX264optMixedRefsSwitch performClick:self];
570 if( [fX264optMixedRefsSwitch isHidden] == true )
572 [[fX264optMixedRefsSwitch animator] setHidden:NO];
573 [[fX264optMixedRefsLabel animator] setHidden:NO];
578 if( sender == fX264optMotionEstPopUp || sender == nil || sender == fDisplayX264Options )
580 if ( [fX264optMotionEstPopUp indexOfSelectedItem] < 3 )
582 /* ME-range can only be above 16 if me >= umh
583 and changing it to < 16 is idiotic so hide it . */
584 if( [fX264optMERangePopUp isHidden] == false )
586 [[fX264optMERangePopUp animator] setHidden:YES];
587 [[fX264optMERangeLabel animator] setHidden:YES];
588 if ( [fX264optMERangePopUp indexOfSelectedItem] > 0 )
590 [fX264optMERangePopUp selectItemAtIndex:0];
591 [[fX264optMERangePopUp cell] performClick:self];
597 if( [fX264optMERangePopUp isHidden] == true )
599 [[fX264optMERangePopUp animator] setHidden:NO];
600 [[fX264optMERangeLabel animator] setHidden:NO];
605 if( sender == fX264optSubmePopUp || sender == nil || sender == fDisplayX264Options )
607 if( [fX264optSubmePopUp indexOfSelectedItem] != 0 && [fX264optSubmePopUp indexOfSelectedItem] < 7 )
609 /* No Psy-RDO or Psy=trel if subme < 6. */
610 if( [fX264optPsyRDSlider isHidden] == false )
612 [[fX264optPsyRDSlider animator] setHidden:YES];
613 [[fX264optPsyRDLabel animator] setHidden:YES];
614 [[fX264optPsyRDSlider animator] setFloatValue:1];
615 if ( [fX264optPsyRDSlider floatValue] < 1.0 )
617 [fX264optPsyRDSlider setFloatValue:1.0];
618 [[fX264optPsyRDSlider cell] performClick:self];
622 if( [fX264optPsyTrellisSlider isHidden] == false)
624 [[fX264optPsyTrellisSlider animator] setHidden:YES];
625 [[fX264optPsyTrellisLabel animator] setHidden:YES];
626 [[fX264optPsyTrellisSlider animator] setFloatValue:0];
627 if ( [fX264optPsyTrellisSlider floatValue] > 0.0 )
629 [fX264optPsyTrellisSlider setFloatValue:0.0];
630 [[fX264optPsyTrellisSlider cell] performClick:self];
636 if( [fX264optPsyRDSlider isHidden] == true )
638 [[fX264optPsyRDSlider animator] setHidden:NO];
639 [[fX264optPsyRDLabel animator] setHidden:NO];
642 if( [fX264optTrellisPopUp indexOfSelectedItem] >= 2 && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
644 [[fX264optPsyTrellisSlider animator] setHidden:NO];
645 [[fX264optPsyTrellisLabel animator] setHidden:NO];
650 if( sender == fX264optTrellisPopUp || sender == nil || sender == fDisplayX264Options )
652 if( [fX264optTrellisPopUp indexOfSelectedItem] < 2 )
654 if( [fX264optPsyTrellisSlider isHidden] == false )
656 /* No Psy-trellis without trellis. */
657 [[fX264optPsyTrellisSlider animator] setHidden:YES];
658 [[fX264optPsyTrellisLabel animator] setHidden:YES];
659 [[fX264optPsyTrellisSlider animator] setFloatValue:0.0];
660 [[fX264optPsyTrellisSlider cell] performClick:self];
665 if( ( [fX264optSubmePopUp indexOfSelectedItem] == 0 || [fX264optSubmePopUp indexOfSelectedItem] >= 7 ) && [fX264optCabacSwitch state] == true && [fX264optPsyTrellisSlider isHidden] == true )
667 [[fX264optPsyTrellisSlider animator] setHidden:NO];
668 [[fX264optPsyTrellisLabel animator] setHidden:NO];
675 * Resets the GUI widgets to the contents of the option string.
677 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
679 /* Set widgets depending on the opt string in field */
680 NSString * thisOpt; // The separated option such as "bframes=3"
681 NSString * optName = @""; // The option name such as "bframes"
682 NSString * optValue = @"";// The option value such as "3"
683 NSArray *currentOptsArray;
685 /*First, we get an opt string to process */
686 NSString *currentOptString = [fDisplayX264Options stringValue];
688 /* Verify there is an opt string to process by making sure an
689 option is getting its value set. If so, start to process it. */
690 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
691 if (currentOptRange.location != NSNotFound)
693 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
694 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
696 /*iterate through the array and get <opts> and <values*/
698 int currentOptsArrayCount = [currentOptsArray count];
699 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
701 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
703 /* Verify the option sets a value */
704 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
705 if (splitOptRange.location != NSNotFound)
707 /* Split thisOpt into an optName setting an optValue. */
708 optName = [thisOpt substringToIndex:splitOptRange.location];
709 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
711 /*Run through the available widgets for x264 opts and set them, as you add widgets,
712 they need to be added here. This should be moved to its own method probably*/
714 /*bframes NSPopUpButton*/
715 if ([optName isEqualToString:@"bframes"])
717 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
719 /*ref NSPopUpButton*/
720 if ([optName isEqualToString:@"ref"])
722 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
724 /*No Fast PSkip NSButton*/
725 if ([optName isEqualToString:@"no-fast-pskip"])
727 [fX264optNfpskipSwitch setState:[optValue intValue]];
729 /*No Dict Decimate NSButton*/
730 if ([optName isEqualToString:@"no-dct-decimate"])
732 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
734 /*Sub Me NSPopUpButton*/
735 if ([optName isEqualToString:@"subq"])
737 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
739 /*Trellis NSPopUpButton*/
740 if ([optName isEqualToString:@"trellis"])
742 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
744 /*Mixed Refs NSButton*/
745 if ([optName isEqualToString:@"mixed-refs"])
747 [fX264optMixedRefsSwitch setState:[optValue intValue]];
749 /*Motion Estimation NSPopUpButton*/
750 if ([optName isEqualToString:@"me"])
752 if ([optValue isEqualToString:@"dia"])
753 [fX264optMotionEstPopUp selectItemAtIndex:1];
754 else if ([optValue isEqualToString:@"hex"])
755 [fX264optMotionEstPopUp selectItemAtIndex:2];
756 else if ([optValue isEqualToString:@"umh"])
757 [fX264optMotionEstPopUp selectItemAtIndex:3];
758 else if ([optValue isEqualToString:@"esa"])
759 [fX264optMotionEstPopUp selectItemAtIndex:4];
760 else if ([optValue isEqualToString:@"tesa"])
761 [fX264optMotionEstPopUp selectItemAtIndex:5];
763 /*ME Range NSPopUpButton*/
764 if ([optName isEqualToString:@"merange"])
766 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
768 /* Adaptive B-Frames NSPopUpButton*/
769 if ([optName isEqualToString:@"b-adapt"])
771 [fX264optBAdaptPopUp selectItemAtIndex:[optValue intValue]+1];
773 /*Weighted B-Frames NSButton*/
774 if ([optName isEqualToString:@"weightb"])
776 [fX264optWeightBSwitch setState:[optValue intValue]];
778 /*B Pyramid NSPButton*/
779 if ([optName isEqualToString:@"b-pyramid"])
781 [fX264optBPyramidSwitch setState:[optValue intValue]];
783 /*Direct B-frame Prediction NSPopUpButton*/
784 if ([optName isEqualToString:@"direct"])
786 if ([optValue isEqualToString:@"none"])
787 [fX264optDirectPredPopUp selectItemAtIndex:1];
788 else if ([optValue isEqualToString:@"spatial"])
789 [fX264optDirectPredPopUp selectItemAtIndex:2];
790 else if ([optValue isEqualToString:@"temporal"])
791 [fX264optDirectPredPopUp selectItemAtIndex:3];
792 else if ([optValue isEqualToString:@"auto"])
793 [fX264optDirectPredPopUp selectItemAtIndex:4];
795 /*Deblocking NSPopUpButtons*/
796 if ([optName isEqualToString:@"deblock"])
798 NSString * alphaDeblock = @"";
799 NSString * betaDeblock = @"";
801 NSRange splitDeblock = [optValue rangeOfString:@","];
802 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
803 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
805 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
807 /* When both filters are at 0, default */
808 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
809 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
813 if (![alphaDeblock isEqualToString:@"0"])
815 /* Alpha isn't 0, so set it. The offset of 7 is
816 because filters start at -6 instead of at 0. */
817 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
821 /* Set alpha filter to 0, which is 7 up
822 because filters start at -6, not 0. */
823 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
826 if (![betaDeblock isEqualToString:@"0"])
828 /* Beta isn't 0, so set it. */
829 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
833 /* Set beta filter to 0. */
834 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
838 /* Analysis NSPopUpButton */
839 if ([optName isEqualToString:@"analyse"])
841 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
843 /* Default ("some") */
844 [fX264optAnalysePopUp selectItemAtIndex:0];
846 if ([optValue isEqualToString:@"none"])
848 [fX264optAnalysePopUp selectItemAtIndex:1];
850 if ([optValue isEqualToString:@"all"])
852 [fX264optAnalysePopUp selectItemAtIndex:2];
855 /* 8x8 DCT NSButton */
856 if ([optName isEqualToString:@"8x8dct"])
858 [fX264opt8x8dctSwitch setState:[optValue intValue]];
861 if ([optName isEqualToString:@"cabac"])
863 [fX264optCabacSwitch setState:[optValue intValue]];
865 /* Psy-RD and Psy-Trellis NSSliders */
866 if ([optName isEqualToString:@"psy-rd"])
868 NSString * rdOpt = @"";
869 NSString * trellisOpt = @"";
871 NSRange splitRD = [optValue rangeOfString:@","];
872 rdOpt = [optValue substringToIndex:splitRD.location];
873 trellisOpt = [optValue substringFromIndex:splitRD.location + 1];
875 [fX264optPsyRDSlider setFloatValue:[rdOpt floatValue]];
876 [fX264optPsyTrellisSlider setFloatValue:[trellisOpt floatValue]];
884 * Resets the option string to mirror the GUI widgets.
886 - (IBAction) X264AdvancedOptionsChanged: (id) sender
888 /*Determine which outlet is being used and set optName to process accordingly */
889 NSString * optNameToChange = @""; // The option name such as "bframes"
891 if (sender == fX264optBframesPopUp)
893 optNameToChange = @"bframes";
895 if (sender == fX264optRefPopUp)
897 optNameToChange = @"ref";
899 if (sender == fX264optNfpskipSwitch)
901 optNameToChange = @"no-fast-pskip";
903 if (sender == fX264optNodctdcmtSwitch)
905 optNameToChange = @"no-dct-decimate";
907 if (sender == fX264optSubmePopUp)
909 optNameToChange = @"subq";
911 if (sender == fX264optTrellisPopUp)
913 optNameToChange = @"trellis";
915 if (sender == fX264optMixedRefsSwitch)
917 optNameToChange = @"mixed-refs";
919 if (sender == fX264optMotionEstPopUp)
921 optNameToChange = @"me";
923 if (sender == fX264optMERangePopUp)
925 optNameToChange = @"merange";
927 if (sender == fX264optBAdaptPopUp)
929 optNameToChange = @"b-adapt";
931 if (sender == fX264optWeightBSwitch)
933 optNameToChange = @"weightb";
935 if (sender == fX264optBPyramidSwitch)
937 optNameToChange = @"b-pyramid";
939 if (sender == fX264optDirectPredPopUp)
941 optNameToChange = @"direct";
943 if (sender == fX264optAlphaDeblockPopUp)
945 optNameToChange = @"deblock";
947 if (sender == fX264optBetaDeblockPopUp)
949 optNameToChange = @"deblock";
951 if (sender == fX264optAnalysePopUp)
953 optNameToChange = @"analyse";
955 if (sender == fX264opt8x8dctSwitch)
957 optNameToChange = @"8x8dct";
959 if (sender == fX264optCabacSwitch)
961 optNameToChange = @"cabac";
963 if( sender == fX264optPsyRDSlider)
965 optNameToChange = @"psy-rd";
967 if( sender == fX264optPsyTrellisSlider)
969 optNameToChange = @"psy-rd";
973 /* Set widgets depending on the opt string in field */
974 NSString * thisOpt; // The separated option such as "bframes=3"
975 NSString * optName = @""; // The option name such as "bframes"
976 NSString * optValue = @"";// The option value such as "3"
977 NSArray *currentOptsArray;
979 /*First, we get an opt string to process */
980 NSString *currentOptString = [fDisplayX264Options stringValue];
982 /* There are going to be a few possibilities.
983 - The option might start off the string.
984 - The option might be in the middle of the string.
985 - The option might not be in the string at all yet.
986 - The string itself might not yet exist.
988 Because each of these possibilities means constructing a different kind of string,
989 they're all handled separately in a sea of messy, somewhat redundant code. =( */
991 /* If the option is in the string but not the beginning of it, it will be in the form of ":optName=value"
992 so we really want to be looking for ":optNameToChange=" rather than "optNameToChange". */
993 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
995 /* Now we store the part of the string up through the option name in currentOptRange. */
996 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
998 /* We need to know if the option is at the beginning of the string.
999 If it is at the start, it won't be preceded by a colon.
1000 To figure this out, we'll use the rangeOfString method. First,
1001 store what the option name would be if if it was at the beginning,
1002 in checkOptNameToChangeBeginning. Then, find its range in the string.
1003 If the range is 0, it's the first option listed in the string. */
1004 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
1005 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
1007 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
1009 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
1010 This means parsing the whole string into an array of options and values. From there,
1011 iterate through the options, and when you reach the one that's been changed, edit it. */
1013 /* Create new empty opt string*/
1014 NSString *changedOptString = @"";
1016 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
1017 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
1019 /*iterate through the array and get <opts> and <values*/
1021 int currentOptsArrayCount = [currentOptsArray count];
1022 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
1024 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
1025 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
1027 if (splitOptRange.location != NSNotFound)
1029 /* First off, it's time to handle option strings that
1030 already have at least one option=value pair in them. */
1032 optName = [thisOpt substringToIndex:splitOptRange.location];
1033 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
1035 /*Run through the available widgets for x264 opts and set them, as you add widgets,
1036 they need to be added here. This should be moved to its own method probably*/
1038 /*If the optNameToChange is found, appropriately change the value or delete it if
1039 "Unspecified" is set.*/
1040 if ([optName isEqualToString:optNameToChange])
1042 if ([optNameToChange isEqualToString:@"deblock"])
1044 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
1046 /* When both deblock widgets are 0 or default or a mix of the two,
1047 use a blank string, since deblocking defaults to 0,0. */
1052 /* Otherwise the format is deblock=a,b, where a and b both have an array
1053 offset of 7 because deblocking values start at -6 instead of at zero. */
1054 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
1057 if ([optNameToChange isEqualToString:@"psy-rd"])
1059 if( [fX264optPsyRDSlider floatValue] == 1.0 && [fX264optPsyTrellisSlider floatValue] == 0.0 )
1061 /* When PsyRD is 1 and PsyTrel is 0 they're default values and can be ignored. */
1066 /* Otherwise the format is deblock=a,b, where a and b both have an array
1067 offset of 7 because deblocking values start at -6 instead of at zero. */
1068 thisOpt = [NSString stringWithFormat:@"%@=%0.1f,%0.1f", optName, [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue] ];
1071 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
1073 /* Here is where we take care of the boolean options that work overtly:
1074 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
1075 require the inverse, but those will be handled a couple lines down. */
1076 if ([sender state] == 0)
1078 /* When these options are false, don't include them. They all default
1079 to being set off, so they don't need to be mentioned at all. */
1084 /* Otherwise, include them as optioname=1 */
1085 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
1088 else if ([optNameToChange isEqualToString:@"cabac"])
1090 /* CABAC is odd, in that it defaults to being on. That means
1091 it only needs to be included in the string when turned off. */
1092 if ([sender state] == 1)
1094 /* It's true so don't include it. */
1099 /* Otherwise, include cabac=0 in the string to enable CAVLC. */
1100 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
1103 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
1105 /* When a widget is at index 0, it's default. Default means don't add to the string.
1106 The exception for deblocking is because for those, *both* need to at index 0
1107 for it to default, so it's handled separately, above this section. */
1110 else if ([optNameToChange isEqualToString:@"me"])
1112 /* Motion estimation uses string values, so this switch
1113 pairs the widget index with the right value string. */
1114 switch ([sender indexOfSelectedItem])
1117 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
1121 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
1125 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
1129 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
1133 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"tesa"];
1139 else if ([optNameToChange isEqualToString:@"direct"])
1141 /* Direct prediction uses string values, so this switch
1142 pairs the right string value with the right widget index. */
1143 switch ([sender indexOfSelectedItem])
1146 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1150 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
1154 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
1158 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
1165 else if ([optNameToChange isEqualToString:@"analyse"])
1167 /* Analysis uses string values as well. */
1168 switch ([sender indexOfSelectedItem])
1171 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1175 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
1182 else if ([optNameToChange isEqualToString:@"merange"])
1184 /* Motion estimation range uses an odd array offset because in addition
1185 to starting with index 0 as default, index 1 starts at 4 instead of 1,
1186 because merange can't go below 4. So it has to be handled separately. */
1187 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
1189 else if ([optNameToChange isEqualToString:@"b-adapt"])
1191 /* B-adapt starts at index 0 with default then goes 0, 1, 2)*/
1192 thisOpt = [NSString stringWithFormat:@"%@=%d", optName, [sender indexOfSelectedItem]-1];
1194 else // we have a valid value to change, so change it
1196 if ( [sender indexOfSelectedItem] != 0 )
1197 /* Here's our general case, that catches things like ref frames and b-frames.
1198 Basically, any options that are PopUp menus with index 0 as default and
1199 index 1 as 1, with numerical values, are all handled right here. All of
1200 the above stuff is for the exceptions to the general case. */
1201 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
1206 /* Construct New String for opts here */
1207 if ([thisOpt isEqualToString:@""])
1209 /* Blank option, so just add it to the string. (Why?) */
1210 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
1214 if ([changedOptString isEqualToString:@""])
1216 /* No existing string, make the string this option. */
1217 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
1221 /* Existing string, existing option. Append the
1222 option to the string, preceding it with a colon. */
1223 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
1228 /* Change the dislayed option string to reflect the new modified settings */
1229 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
1231 else // if none exists, add it to the string
1233 /* This is where options that aren't already in the string are handled. */
1234 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
1236 /* The option might not be in the string because the
1237 string is empty. Handle this possibility first. */
1238 if ([optNameToChange isEqualToString:@"me"])
1240 /* Special case for motion estimation, which uses string values
1241 that need to be paired up with the equivalent widget index. */
1242 switch ([sender indexOfSelectedItem])
1245 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1246 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
1250 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1251 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
1255 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1256 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
1260 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1261 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
1265 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1266 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"tesa"]]];
1273 else if ([optNameToChange isEqualToString:@"direct"])
1275 /* Special case for direct prediction, which uses string values
1276 that need to be paired up with the equivalent widget index. */
1277 switch ([sender indexOfSelectedItem])
1280 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1281 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1285 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1286 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
1290 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1291 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
1295 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1296 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
1303 else if ([optNameToChange isEqualToString:@"analyse"])
1305 /* Special case for partition analysis, which uses string values
1306 that need to be paired up with the equivalent widget index. */
1307 switch ([sender indexOfSelectedItem])
1310 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1311 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1315 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1316 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1323 else if ([optNameToChange isEqualToString:@"merange"])
1325 /* Special case for motion estimation range, which uses
1326 a widget index offset of 3. This is because the
1327 first valid value after default is four, not zero. */
1328 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1329 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1331 else if ([optNameToChange isEqualToString:@"b-adapt"])
1333 /* 0 is default, index 1 is 0*/
1334 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1335 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1337 else if ([optNameToChange isEqualToString:@"deblock"])
1339 /* Very special case for deblock. Uses a weird widget index offset
1340 of 7, because the first value after default is -6, rather than 0.
1341 As well, deblock only goes to default when *both* alpha and beta
1342 are zero. If only one is zero, you can't mark it down as default.
1343 Instead, mark that one down as literally 0. This is because when
1344 widgets are at default values, they aren't included in the string.
1345 If only one filter is at 0, both need to be overtly specified. */
1346 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d,%d", ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0, ([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0]]];
1348 else if ([optNameToChange isEqualToString:@"psy-rd"])
1350 /* Special case for psy-rd and psy-trellis. */
1351 if( [fX264optPsyRDSlider floatValue] == 1 && [fX264optPsyTrellisSlider floatValue] == 0 )
1353 /* Defaults, use null string. */
1354 [fDisplayX264Options setStringValue:@""];
1358 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%0.1f,%0.1f", [NSString stringWithFormat:optNameToChange], [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue]]];
1361 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
1363 /* This covers all the boolean options that need to be specified only when true. */
1364 if ([sender state] == 0)
1366 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1370 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1371 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1374 else if ([optNameToChange isEqualToString:@"cabac"])
1376 /* CABAC is weird in that you need the inverse. Only include in the string
1377 when cabac=0, because cabac=1 is the default. Turning it off means CAVLC. */
1378 if ([sender state] == 1)
1380 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1384 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1385 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1390 if ( [sender indexOfSelectedItem] != 0 )
1391 /* General case to cover all the normal PopUp widgets, like ref and b-frames. */
1392 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1393 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1398 /* The string isn't empty, and the option isn't already in it,
1399 so it will need to be appended to the string with a colon. */
1400 if ([optNameToChange isEqualToString:@"me"])
1402 /* Special case for motion estimation, which uses string values
1403 that need to be paired up with the equivalent widget index. */
1404 switch ([sender indexOfSelectedItem])
1407 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1408 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1409 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
1413 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1414 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1415 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
1419 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1420 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1421 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
1425 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1426 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1427 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
1431 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1432 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1433 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"tesa"]]];
1440 else if ([optNameToChange isEqualToString:@"direct"])
1442 /* Special case for direct prediction, which uses string values
1443 that need to be paired up with the equivalent widget index. */
1444 switch ([sender indexOfSelectedItem])
1447 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1448 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1449 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1453 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1454 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1455 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
1459 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1460 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1461 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
1465 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1466 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1467 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
1474 else if ([optNameToChange isEqualToString:@"analyse"])
1476 /* Special case for partition analysis, which uses string values
1477 that need to be paired up with the equivalent widget index. */
1478 switch ([sender indexOfSelectedItem])
1481 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1482 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1483 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1487 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1488 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1489 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1497 else if ([optNameToChange isEqualToString:@"merange"])
1499 /* Motion estimation range uses a weird offset since its index goes
1500 0: default, 1: 4, because the first valid value is 4, not 1. */
1501 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1502 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1504 else if ([optNameToChange isEqualToString:@"b-adapt"])
1506 /* 0 is default, index 1 is 0*/
1507 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1508 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1510 else if ([optNameToChange isEqualToString:@"deblock"])
1512 /* Deblock is really weird because it has two values, and if only one is default, both
1513 still need to be specified directly. with the default one at zero. To make deblock
1514 just a little more fun, values start at -6 instead of at zero. */
1515 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", [NSString stringWithFormat:[fDisplayX264Options stringValue]], [NSString stringWithFormat:optNameToChange], [NSString stringWithFormat:@"%d,%d", ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0, ([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0]]];
1517 else if ([optNameToChange isEqualToString:@"psy-rd"])
1519 /* Special case for psy-rd and psy-trel */
1520 if( [fX264optPsyRDSlider floatValue] == 1 && [fX264optPsyTrellisSlider floatValue] == 0 )
1522 /* Defaults, don't change string. */
1523 [fDisplayX264Options setStringValue:[NSString stringWithFormat:[fDisplayX264Options stringValue]]];
1527 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%0.1f,%0.1f", [NSString stringWithFormat:[fDisplayX264Options stringValue]], [NSString stringWithFormat:optNameToChange], [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue]]];
1531 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
1533 /* Covers all the normal booleans, that only need to be included in the string when they're true. */
1534 if ([sender state] == 0)
1536 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1540 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1541 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1544 else if ([optNameToChange isEqualToString:@"cabac"])
1546 /* CABAC is weird, in that it's an inverse. Only include it in the string when it's false. */
1547 if ([sender state] == 1)
1549 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1553 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1554 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1559 /* General case to handle the normal PopUp widgets like ref and b-frames. */
1560 if ( [sender indexOfSelectedItem] != 0 )
1561 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1562 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1567 /* We now need to reset the opt widgets since we changed some stuff */
1568 [self X264AdvancedOptionsSet:sender];