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,fX264optBRDOLabel,fX264optBRDOSwitch,
72 fX264optBPyramidLabel,fX264optBPyramidSwitch,fX264optBiMELabel,fX264optBiMESwitch,
73 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
74 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
75 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp};
77 for( i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ )
79 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
81 NSTextField * tf = (NSTextField *) controls[i];
84 [tf setTextColor: b ? [NSColor controlTextColor] :
85 [NSColor disabledControlTextColor]];
89 [controls[i] setEnabled: b];
93 [fX264optView setWantsLayer:YES];
102 * Populates the option widgets
104 - (IBAction) X264AdvancedOptionsSet: (id) sender
106 /*Set opt widget values here*/
108 /*B-Frames fX264optBframesPopUp*/
110 [fX264optBframesPopUp removeAllItems];
111 [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
114 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
117 /*Reference Frames fX264optRefPopUp*/
118 [fX264optRefPopUp removeAllItems];
119 [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
122 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
125 /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
126 [fX264optNfpskipSwitch setState:0];
128 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
129 [fX264optNodctdcmtSwitch setState:0];
131 /*Sub Me fX264optSubmePopUp*/
132 [fX264optSubmePopUp removeAllItems];
133 [fX264optSubmePopUp addItemWithTitle:@"Default (6)"];
136 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
139 /*Trellis fX264optTrellisPopUp*/
140 [fX264optTrellisPopUp removeAllItems];
141 [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
144 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
146 [fX264optTrellisPopUp setWantsLayer:YES];
148 /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
149 [fX264optMixedRefsSwitch setState:0];
150 [fX264optMixedRefsSwitch setWantsLayer:YES];
152 /*Motion Estimation fX264optMotionEstPopUp*/
153 [fX264optMotionEstPopUp removeAllItems];
154 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
155 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
156 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
157 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
158 [fX264optMotionEstPopUp addItemWithTitle:@"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 Rate Distortion Optimization fX264optBRDOSwitch BOOLEAN*/
173 [fX264optBRDOSwitch setState:0];
174 [fX264optBRDOSwitch setWantsLayer:YES];
176 /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
177 [fX264optBPyramidSwitch setState:0];
178 [fX264optBPyramidSwitch setWantsLayer:YES];
180 /*Bidirectional Motion Estimation Refinement fX264optBiMESwitch BOOLEAN*/
181 [fX264optBiMESwitch setState:0];
182 [fX264optBiMESwitch setWantsLayer:YES];
184 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
185 [fX264optDirectPredPopUp removeAllItems];
186 [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
187 [fX264optDirectPredPopUp addItemWithTitle:@"None"];
188 [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
189 [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
190 [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
191 [fX264optDirectPredPopUp 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 /* Standardize the option string */
223 [self X264AdvancedOptionsStandardizeOptString:nil];
225 /* Set Current GUI Settings based on newly standardized string */
226 [self X264AdvancedOptionsSetCurrentSettings:nil];
228 /* Fade out options that don't apply */
229 [self X264AdvancedOptionsAnimate: sender];
233 * Cleans the option string to use a standard format of option=value
235 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
237 /* Set widgets depending on the opt string in field */
238 NSString * thisOpt; // The separated option such as "bframes=3"
239 NSString * optName = @""; // The option name such as "bframes"
240 NSString * optValue = @"";// The option value such as "3"
241 NSString * changedOptString = @"";
242 NSArray *currentOptsArray;
244 /*First, we get an opt string to process */
245 NSString *currentOptString = [fDisplayX264Options stringValue];
247 /* Verify there is an opt string to process by making sure an
248 option is getting its value set. If so, start to process it. */
249 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
250 if (currentOptRange.location != NSNotFound)
252 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
253 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
255 /*iterate through the array and get <opts> and <values*/
257 int currentOptsArrayCount = [currentOptsArray count];
258 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
260 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
262 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
263 if (splitOptRange.location != NSNotFound)
265 optName = [thisOpt substringToIndex:splitOptRange.location];
266 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
268 /* Standardize the names here depending on whats in the string */
269 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
270 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
272 else // No value given so we use a default of "1"
276 /* Standardize the names here depending on whats in the string */
277 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
278 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
281 /* Construct New String for opts here.*/
282 if ([thisOpt isEqualToString:@""])
284 /* Blank option, just add it to the string. (Why?) */
285 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
289 if ([changedOptString isEqualToString:@""])
291 /* Blank string, output the current option. */
292 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
296 /* Option exists and string exists, so append the option
297 to the string with a semi-colon inbetween them. */
298 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
304 /* Change the option string to reflect the new standardized option string */
305 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
309 * Cleans the option string to use a standard set of option names, by conflating synonyms.
311 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
313 /* Reference Frames */
314 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
316 cleanOptNameString = @"ref";
319 /*No Fast PSkip nofast_pskip*/
320 if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
322 cleanOptNameString = @"no-fast-pskip";
326 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
328 cleanOptNameString = @"no-dct-decimate";
332 if ([cleanOptNameString isEqualToString:@"subme"])
334 cleanOptNameString = @"subq";
338 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
339 cleanOptNameString = @"merange";
342 if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
344 cleanOptNameString = @"weightb";
348 if ([cleanOptNameString isEqualToString:@"b-rdo"] || [cleanOptNameString isEqualToString:@"b_rdo"])
350 cleanOptNameString = @"brdo";
354 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
356 cleanOptNameString = @"b-pyramid";
359 /*Direct Prediction*/
360 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
362 cleanOptNameString = @"direct";
366 if ([cleanOptNameString isEqualToString:@"filter"])
368 cleanOptNameString = @"deblock";
372 if ([cleanOptNameString isEqualToString:@"partitions"])
374 cleanOptNameString = @"analyse";
377 return cleanOptNameString;
381 * Fades options in and out depending on whether they're available..
383 - (IBAction) X264AdvancedOptionsAnimate: (id) sender
385 /* Lots of situations to cover.
386 - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)
387 - CABAC (when 0 turn off trellis)
388 - subme (if under 6 turn off brdo)
389 - analysis (if none, turn off 8x8dct)
390 - refs (under 2, disable mixed-refs)
393 if ( [fX264optBframesPopUp indexOfSelectedItem ] < 2)
395 /* If the b-frame widget is at 0 or 1, the user has chosen
396 not to use b-frames at all. So disable the options
397 that can only be used when b-frames are enabled. */
398 [[fX264optWeightBSwitch animator] setHidden:YES];
399 [[fX264optWeightBLabel animator] setHidden:YES];
400 if ( [fX264optWeightBSwitch state] == 1 && sender != fX264optWeightBSwitch && sender != fX264optBRDOSwitch && sender != fX264optBPyramidSwitch && sender != fX264optBiMESwitch && sender != fX264optDirectPredPopUp)
401 [fX264optWeightBSwitch performClick:self];
403 [[fX264optBRDOSwitch animator] setHidden:YES];
404 [[fX264optBRDOLabel animator] setHidden:YES];
405 if ( [fX264optBRDOSwitch state] == 1 && sender != fX264optWeightBSwitch && sender != fX264optBRDOSwitch && sender != fX264optBPyramidSwitch && sender != fX264optBiMESwitch && sender != fX264optDirectPredPopUp)
406 [fX264optBRDOSwitch performClick:self];
408 [[fX264optBPyramidSwitch animator] setHidden:YES];
409 [[fX264optBPyramidLabel animator] setHidden:YES];
410 if ( [fX264optBPyramidSwitch state] == 1 && sender != fX264optWeightBSwitch && sender != fX264optBRDOSwitch && sender != fX264optBPyramidSwitch && sender != fX264optBiMESwitch && sender != fX264optDirectPredPopUp)
411 [fX264optBPyramidSwitch performClick:self];
413 [[fX264optBiMESwitch animator] setHidden:YES];
414 [[fX264optBiMELabel animator] setHidden:YES];
415 if ( [fX264optBiMESwitch state] == 1 && sender != fX264optWeightBSwitch && sender != fX264optBRDOSwitch && sender != fX264optBPyramidSwitch && sender != fX264optBiMESwitch && sender != fX264optDirectPredPopUp)
416 [fX264optBiMESwitch performClick:self];
418 [[fX264optDirectPredPopUp animator] setHidden:YES];
419 [[fX264optDirectPredLabel animator] setHidden:YES];
420 if ( [fX264optDirectPredPopUp indexOfSelectedItem] > 0 && sender != fX264optWeightBSwitch && sender != fX264optBRDOSwitch && sender != fX264optBPyramidSwitch && sender != fX264optBiMESwitch && sender != fX264optDirectPredPopUp)
422 [fX264optDirectPredPopUp selectItemAtIndex: 0];
423 [[fX264optDirectPredPopUp cell] performClick:self];
427 else if ( [fX264optBframesPopUp indexOfSelectedItem ] == 2)
429 /* Only 1 b-frame? Disable b-pyramid. */
430 [[fX264optBPyramidSwitch animator] setHidden:YES];
431 [[fX264optBPyramidLabel animator] setHidden:YES];
432 if ( [fX264optBPyramidSwitch state] == 1 && sender != fX264optBPyramidSwitch)
433 [fX264optBPyramidSwitch performClick:self];
435 [[fX264optWeightBSwitch animator] setHidden:NO];
436 [[fX264optWeightBLabel animator] setHidden:NO];
438 [[fX264optBiMESwitch animator] setHidden:NO];
439 [[fX264optBiMELabel animator] setHidden:NO];
441 if ( [fX264optSubmePopUp indexOfSelectedItem] >= 7 || [fX264optSubmePopUp indexOfSelectedItem] == 0 )
443 /* Only show B-RDO if both bframes and subme allow it. */
444 [[fX264optBRDOSwitch animator] setHidden:NO];
445 [[fX264optBRDOLabel animator] setHidden:NO];
448 [[fX264optDirectPredPopUp animator] setHidden:NO];
449 [[fX264optDirectPredLabel animator] setHidden:NO];
453 [[fX264optWeightBSwitch animator] setHidden:NO];
454 [[fX264optWeightBLabel animator] setHidden:NO];
456 [[fX264optBPyramidSwitch animator] setHidden:NO];
457 [[fX264optBPyramidLabel animator] setHidden:NO];
459 [[fX264optBiMESwitch animator] setHidden:NO];
460 [[fX264optBiMELabel animator] setHidden:NO];
462 if ( [fX264optSubmePopUp indexOfSelectedItem] >= 7 || [fX264optSubmePopUp indexOfSelectedItem] == 0 )
464 /* Only show B-RDO if both bframes and subme allow it. */
465 [[fX264optBRDOSwitch animator] setHidden:NO];
466 [[fX264optBRDOLabel animator] setHidden:NO];
469 [[fX264optDirectPredPopUp animator] setHidden:NO];
470 [[fX264optDirectPredLabel animator] setHidden:NO];
473 if ( [fX264optCabacSwitch state] == false)
475 /* Without CABAC entropy coding, trellis doesn't run. */
477 [[fX264optTrellisPopUp animator] setHidden:YES];
478 [[fX264optTrellisLabel animator] setHidden:YES];
479 [fX264optTrellisPopUp selectItemAtIndex:0];
480 if (sender != fX264optTrellisPopUp)
481 [[fX264optTrellisPopUp cell] performClick:self];
485 [[fX264optTrellisPopUp animator] setHidden:NO];
486 [[fX264optTrellisLabel animator] setHidden:NO];
489 if ( [fX264optSubmePopUp indexOfSelectedItem] < 7 && [fX264optSubmePopUp indexOfSelectedItem] != 0 )
491 /* When subme < 6, B-RDO doesn't work. */
492 [[fX264optBRDOSwitch animator] setHidden:YES];
493 [[fX264optBRDOLabel animator] setHidden:YES];
494 if ( [fX264optBRDOSwitch state] == 1 && sender != fX264optBRDOSwitch )
495 [fX264optBRDOSwitch performClick:self];
497 else if ( [fX264optBframesPopUp indexOfSelectedItem ] >= 2 )
499 /* Make sure to only display B-RDO if allowed by both
500 the subme and bframe option settings. */
501 [[fX264optBRDOSwitch animator] setHidden:NO];
502 [[fX264optBRDOLabel animator] setHidden:NO];
505 if ( [fX264optAnalysePopUp indexOfSelectedItem] == 1)
507 /* No analysis? Disable 8x8dct */
508 [[fX264opt8x8dctSwitch animator] setHidden:YES];
509 [[fX264opt8x8dctLabel animator] setHidden:YES];
510 if ( [fX264opt8x8dctSwitch state] == 1 && sender != fX264opt8x8dctSwitch )
511 [fX264opt8x8dctSwitch performClick:self];
515 [[fX264opt8x8dctSwitch animator] setHidden:NO];
516 [[fX264opt8x8dctLabel animator] setHidden:NO];
519 if ( [fX264optRefPopUp indexOfSelectedItem] < 3)
521 /* Only do mixed-refs when there are at least 2 refs to mix. */
522 [[fX264optMixedRefsSwitch animator] setHidden:YES];
523 [[fX264optMixedRefsLabel animator] setHidden:YES];
524 if ( [fX264optMixedRefsSwitch state] == 1 && sender != fX264optMixedRefsSwitch )
525 [fX264optMixedRefsSwitch performClick:self];
529 [[fX264optMixedRefsSwitch animator] setHidden:NO];
530 [[fX264optMixedRefsLabel animator] setHidden:NO];
535 * Resets the GUI widgets to the contents of the option string.
537 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
539 /* Set widgets depending on the opt string in field */
540 NSString * thisOpt; // The separated option such as "bframes=3"
541 NSString * optName = @""; // The option name such as "bframes"
542 NSString * optValue = @"";// The option value such as "3"
543 NSArray *currentOptsArray;
545 /*First, we get an opt string to process */
546 NSString *currentOptString = [fDisplayX264Options stringValue];
548 /* Verify there is an opt string to process by making sure an
549 option is getting its value set. If so, start to process it. */
550 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
551 if (currentOptRange.location != NSNotFound)
553 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
554 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
556 /*iterate through the array and get <opts> and <values*/
558 int currentOptsArrayCount = [currentOptsArray count];
559 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
561 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
563 /* Verify the option sets a value */
564 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
565 if (splitOptRange.location != NSNotFound)
567 /* Split thisOpt into an optName setting an optValue. */
568 optName = [thisOpt substringToIndex:splitOptRange.location];
569 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
571 /*Run through the available widgets for x264 opts and set them, as you add widgets,
572 they need to be added here. This should be moved to its own method probably*/
574 /*bframes NSPopUpButton*/
575 if ([optName isEqualToString:@"bframes"])
577 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
579 /*ref NSPopUpButton*/
580 if ([optName isEqualToString:@"ref"])
582 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
584 /*No Fast PSkip NSButton*/
585 if ([optName isEqualToString:@"no-fast-pskip"])
587 [fX264optNfpskipSwitch setState:[optValue intValue]];
589 /*No Dict Decimate NSButton*/
590 if ([optName isEqualToString:@"no-dct-decimate"])
592 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
594 /*Sub Me NSPopUpButton*/
595 if ([optName isEqualToString:@"subq"])
597 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
599 /*Trellis NSPopUpButton*/
600 if ([optName isEqualToString:@"trellis"])
602 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
604 /*Mixed Refs NSButton*/
605 if ([optName isEqualToString:@"mixed-refs"])
607 [fX264optMixedRefsSwitch setState:[optValue intValue]];
609 /*Motion Estimation NSPopUpButton*/
610 if ([optName isEqualToString:@"me"])
612 if ([optValue isEqualToString:@"dia"])
613 [fX264optMotionEstPopUp selectItemAtIndex:1];
614 else if ([optValue isEqualToString:@"hex"])
615 [fX264optMotionEstPopUp selectItemAtIndex:2];
616 else if ([optValue isEqualToString:@"umh"])
617 [fX264optMotionEstPopUp selectItemAtIndex:3];
618 else if ([optValue isEqualToString:@"esa"])
619 [fX264optMotionEstPopUp selectItemAtIndex:4];
621 /*ME Range NSPopUpButton*/
622 if ([optName isEqualToString:@"merange"])
624 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
626 /*Weighted B-Frames NSButton*/
627 if ([optName isEqualToString:@"weightb"])
629 [fX264optWeightBSwitch setState:[optValue intValue]];
632 if ([optName isEqualToString:@"brdo"])
634 [fX264optBRDOSwitch setState:[optValue intValue]];
636 /*B Pyramid NSPButton*/
637 if ([optName isEqualToString:@"b-pyramid"])
639 [fX264optBPyramidSwitch setState:[optValue intValue]];
641 /*Bidirectional Motion Estimation Refinement NSButton*/
642 if ([optName isEqualToString:@"bime"])
644 [fX264optBiMESwitch setState:[optValue intValue]];
646 /*Direct B-frame Prediction NSPopUpButton*/
647 if ([optName isEqualToString:@"direct"])
649 if ([optValue isEqualToString:@"none"])
650 [fX264optDirectPredPopUp selectItemAtIndex:1];
651 else if ([optValue isEqualToString:@"spatial"])
652 [fX264optDirectPredPopUp selectItemAtIndex:2];
653 else if ([optValue isEqualToString:@"temporal"])
654 [fX264optDirectPredPopUp selectItemAtIndex:3];
655 else if ([optValue isEqualToString:@"auto"])
656 [fX264optDirectPredPopUp selectItemAtIndex:4];
658 /*Deblocking NSPopUpButtons*/
659 if ([optName isEqualToString:@"deblock"])
661 NSString * alphaDeblock = @"";
662 NSString * betaDeblock = @"";
664 NSRange splitDeblock = [optValue rangeOfString:@","];
665 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
666 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
668 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
670 /* When both filters are at 0, default */
671 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
672 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
676 if (![alphaDeblock isEqualToString:@"0"])
678 /* Alpha isn't 0, so set it. The offset of 7 is
679 because filters start at -6 instead of at 0. */
680 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
684 /* Set alpha filter to 0, which is 7 up
685 because filters start at -6, not 0. */
686 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
689 if (![betaDeblock isEqualToString:@"0"])
691 /* Beta isn't 0, so set it. */
692 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
696 /* Set beta filter to 0. */
697 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
701 /* Analysis NSPopUpButton */
702 if ([optName isEqualToString:@"analyse"])
704 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
706 /* Default ("some") */
707 [fX264optAnalysePopUp selectItemAtIndex:0];
709 if ([optValue isEqualToString:@"none"])
711 [fX264optAnalysePopUp selectItemAtIndex:1];
713 if ([optValue isEqualToString:@"all"])
715 [fX264optAnalysePopUp selectItemAtIndex:2];
718 /* 8x8 DCT NSButton */
719 if ([optName isEqualToString:@"8x8dct"])
721 [fX264opt8x8dctSwitch setState:[optValue intValue]];
724 if ([optName isEqualToString:@"cabac"])
726 [fX264optCabacSwitch setState:[optValue intValue]];
734 * Resets the option string to mirror the GUI widgets.
736 - (IBAction) X264AdvancedOptionsChanged: (id) sender
738 /*Determine which outlet is being used and set optName to process accordingly */
739 NSString * optNameToChange = @""; // The option name such as "bframes"
741 if (sender == fX264optBframesPopUp)
743 optNameToChange = @"bframes";
745 if (sender == fX264optRefPopUp)
747 optNameToChange = @"ref";
749 if (sender == fX264optNfpskipSwitch)
751 optNameToChange = @"no-fast-pskip";
753 if (sender == fX264optNodctdcmtSwitch)
755 optNameToChange = @"no-dct-decimate";
757 if (sender == fX264optSubmePopUp)
759 optNameToChange = @"subq";
761 if (sender == fX264optTrellisPopUp)
763 optNameToChange = @"trellis";
765 if (sender == fX264optMixedRefsSwitch)
767 optNameToChange = @"mixed-refs";
769 if (sender == fX264optMotionEstPopUp)
771 optNameToChange = @"me";
773 if (sender == fX264optMERangePopUp)
775 optNameToChange = @"merange";
777 if (sender == fX264optWeightBSwitch)
779 optNameToChange = @"weightb";
781 if (sender == fX264optBRDOSwitch)
783 optNameToChange = @"brdo";
785 if (sender == fX264optBPyramidSwitch)
787 optNameToChange = @"b-pyramid";
789 if (sender == fX264optBiMESwitch)
791 optNameToChange = @"bime";
793 if (sender == fX264optDirectPredPopUp)
795 optNameToChange = @"direct";
797 if (sender == fX264optAlphaDeblockPopUp)
799 optNameToChange = @"deblock";
801 if (sender == fX264optBetaDeblockPopUp)
803 optNameToChange = @"deblock";
805 if (sender == fX264optAnalysePopUp)
807 optNameToChange = @"analyse";
809 if (sender == fX264opt8x8dctSwitch)
811 optNameToChange = @"8x8dct";
813 if (sender == fX264optCabacSwitch)
815 optNameToChange = @"cabac";
818 /* Set widgets depending on the opt string in field */
819 NSString * thisOpt; // The separated option such as "bframes=3"
820 NSString * optName = @""; // The option name such as "bframes"
821 NSString * optValue = @"";// The option value such as "3"
822 NSArray *currentOptsArray;
824 /*First, we get an opt string to process */
825 NSString *currentOptString = [fDisplayX264Options stringValue];
827 /* There are going to be a few possibilities.
828 - The option might start off the string.
829 - The option might be in the middle of the string.
830 - The option might not be in the string at all yet.
831 - The string itself might not yet exist.
833 Because each of these possibilities means constructing a different kind of string,
834 they're all handled separately in a sea of messy, somewhat redundant code. =( */
836 /* If the option is in the string but not the beginning of it, it will be in the form of ":optName=value"
837 so we really want to be looking for ":optNameToChange=" rather than "optNameToChange". */
838 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
840 /* Now we store the part of the string up through the option name in currentOptRange. */
841 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
843 /* We need to know if the option is at the beginning of the string.
844 If it is at the start, it won't be preceded by a colon.
845 To figure this out, we'll use the rangeOfString method. First,
846 store what the option name would be if if it was at the beginning,
847 in checkOptNameToChangeBeginning. Then, find its range in the string.
848 If the range is 0, it's the first option listed in the string. */
849 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
850 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
852 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
854 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
855 This means parsing the whole string into an array of options and values. From there,
856 iterate through the options, and when you reach the one that's been changed, edit it. */
858 /* Create new empty opt string*/
859 NSString *changedOptString = @"";
861 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
862 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
864 /*iterate through the array and get <opts> and <values*/
866 int currentOptsArrayCount = [currentOptsArray count];
867 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
869 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
870 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
872 if (splitOptRange.location != NSNotFound)
874 /* First off, it's time to handle option strings that
875 already have at least one option=value pair in them. */
877 optName = [thisOpt substringToIndex:splitOptRange.location];
878 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
880 /*Run through the available widgets for x264 opts and set them, as you add widgets,
881 they need to be added here. This should be moved to its own method probably*/
883 /*If the optNameToChange is found, appropriately change the value or delete it if
884 "Unspecified" is set.*/
885 if ([optName isEqualToString:optNameToChange])
887 if ([optNameToChange isEqualToString:@"deblock"])
889 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
891 /* When both deblock widgets are 0 or default or a mix of the two,
892 use a blank string, since deblocking defaults to 0,0. */
897 /* Otherwise the format is deblock=a,b, where a and b both have an array
898 offset of 7 because deblocking values start at -6 instead of at zero. */
899 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
902 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
904 /* Here is where we take care of the boolean options that work overtly:
905 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
906 require the inverse, but those will be handled a couple lines down. */
907 if ([sender state] == 0)
909 /* When these options are false, don't include them. They all default
910 to being set off, so they don't need to be mentioned at all. */
915 /* Otherwise, include them as optioname=1 */
916 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
919 else if ([optNameToChange isEqualToString:@"cabac"])
921 /* CABAC is odd, in that it defaults to being on. That means
922 it only needs to be included in the string when turned off. */
923 if ([sender state] == 1)
925 /* It's true so don't include it. */
930 /* Otherwise, include cabac=0 in the string to enable CAVLC. */
931 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
934 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
936 /* When a widget is at index 0, it's default. Default means don't add to the string.
937 The exception for deblocking is because for those, *both* need to at index 0
938 for it to default, so it's handled separately, above this section. */
941 else if ([optNameToChange isEqualToString:@"me"])
943 /* Motion estimation uses string values, so this switch
944 pairs the widget index with the right value string. */
945 switch ([sender indexOfSelectedItem])
948 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
952 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
956 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
960 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
967 else if ([optNameToChange isEqualToString:@"direct"])
969 /* Direct prediction uses string values, so this switch
970 pairs the right string value with the right widget index. */
971 switch ([sender indexOfSelectedItem])
974 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
978 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
982 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
986 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
993 else if ([optNameToChange isEqualToString:@"analyse"])
995 /* Analysis uses string values as well. */
996 switch ([sender indexOfSelectedItem])
999 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1003 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
1010 else if ([optNameToChange isEqualToString:@"merange"])
1012 /* Motion estimation range uses an odd array offset because in addition
1013 to starting with index 0 as default, index 1 starts at 4 instead of 1,
1014 because merange can't go below 4. So it has to be handled separately. */
1015 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
1017 else // we have a valid value to change, so change it
1019 if ( [sender indexOfSelectedItem] != 0 )
1020 /* Here's our general case, that catches things like ref frames and b-frames.
1021 Basically, any options that are PopUp menus with index 0 as default and
1022 index 1 as 1, with numerical values, are all handled right here. All of
1023 the above stuff is for the exceptions to the general case. */
1024 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
1029 /* Construct New String for opts here */
1030 if ([thisOpt isEqualToString:@""])
1032 /* Blank option, so just add it to the string. (Why?) */
1033 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
1037 if ([changedOptString isEqualToString:@""])
1039 /* No existing string, make the string this option. */
1040 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
1044 /* Existing string, existing option. Append the
1045 option to the string, preceding it with a colon. */
1046 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
1051 /* Change the dislayed option string to reflect the new modified settings */
1052 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
1054 else // if none exists, add it to the string
1056 /* This is where options that aren't already in the string are handled. */
1057 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
1059 /* The option might not be in the string because the
1060 string is empty. Handle this possibility first. */
1061 if ([optNameToChange isEqualToString:@"me"])
1063 /* Special case for motion estimation, which uses string values
1064 that need to be paired up with the equivalent widget index. */
1065 switch ([sender indexOfSelectedItem])
1068 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1069 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
1073 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1074 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
1078 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1079 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
1083 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1084 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
1091 else if ([optNameToChange isEqualToString:@"direct"])
1093 /* Special case for direct prediction, which uses string values
1094 that need to be paired up with the equivalent widget index. */
1095 switch ([sender indexOfSelectedItem])
1098 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1099 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1103 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1104 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
1108 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1109 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
1113 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1114 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
1121 else if ([optNameToChange isEqualToString:@"analyse"])
1123 /* Special case for partition analysis, which uses string values
1124 that need to be paired up with the equivalent widget index. */
1125 switch ([sender indexOfSelectedItem])
1128 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1129 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1133 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1134 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1142 else if ([optNameToChange isEqualToString:@"merange"])
1144 /* Special case for motion estimation range, which uses
1145 a widget index offset of 3. This is because the
1146 first valid value after default is four, not zero. */
1147 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1148 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1150 else if ([optNameToChange isEqualToString:@"deblock"])
1152 /* Very special case for deblock. Uses a weird widget index offset
1153 of 7, because the first value after default is -6, rather than 0.
1154 As well, deblock only goes to default when *both* alpha and beta
1155 are zero. If only one is zero, you can't mark it down as default.
1156 Instead, mark that one down as literally 0. This is because when
1157 widgets are at default values, they aren't included in the string.
1158 If only one filter is at 0, both need to be overtly specified. */
1159 [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]]];
1161 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
1163 /* This covers all the boolean options that need to be specified only when true. */
1164 if ([sender state] == 0)
1166 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1170 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1171 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1174 else if ([optNameToChange isEqualToString:@"cabac"])
1176 /* CABAC is weird in that you need the inverse. Only include in the string
1177 when cabac=0, because cabac=1 is the default. Turning it off means CAVLC. */
1178 if ([sender state] == 1)
1180 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1184 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1185 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1190 if ( [sender indexOfSelectedItem] != 0 )
1191 /* General case to cover all the normal PopUp widgets, like ref and b-frames. */
1192 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1193 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1198 /* The string isn't empty, and the option isn't already in it,
1199 so it will need to be appended to the string with a colon. */
1200 if ([optNameToChange isEqualToString:@"me"])
1202 /* Special case for motion estimation, which uses string values
1203 that need to be paired up with the equivalent widget index. */
1204 switch ([sender indexOfSelectedItem])
1207 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1208 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1209 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
1213 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1214 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1215 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
1219 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1220 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1221 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
1225 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1226 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1227 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
1234 else if ([optNameToChange isEqualToString:@"direct"])
1236 /* Special case for direct prediction, which uses string values
1237 that need to be paired up with the equivalent widget index. */
1238 switch ([sender indexOfSelectedItem])
1241 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1242 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1243 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1247 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1248 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1249 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
1253 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1254 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1255 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
1259 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1260 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1261 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
1268 else if ([optNameToChange isEqualToString:@"analyse"])
1270 /* Special case for partition analysis, which uses string values
1271 that need to be paired up with the equivalent widget index. */
1272 switch ([sender indexOfSelectedItem])
1275 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1276 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1277 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1281 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1282 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1283 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1291 else if ([optNameToChange isEqualToString:@"merange"])
1293 /* Motion estimation range uses a weird offset since its index goes
1294 0: default, 1: 4, because the first valid value is 4, not 1. */
1295 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1296 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1298 else if ([optNameToChange isEqualToString:@"deblock"])
1300 /* Deblock is really weird because it has two values, and if only one is default, both
1301 still need to be specified directly. with the default one at zero. To make deblock
1302 just a little more fun, values start at -6 instead of at zero. */
1303 [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]]];
1305 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
1307 /* Covers all the normal booleans, that only need to be included in the string when they're true. */
1308 if ([sender state] == 0)
1310 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1314 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1315 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1318 else if ([optNameToChange isEqualToString:@"cabac"])
1320 /* CABAC is weird, in that it's an inverse. Only include it in the string when it's false. */
1321 if ([sender state] == 1)
1323 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1327 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1328 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1333 /* General case to handle the normal PopUp widgets like ref and b-frames. */
1334 if ( [sender indexOfSelectedItem] != 0 )
1335 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1336 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1341 /* We now need to reset the opt widgets since we changed some stuff */
1342 [self X264AdvancedOptionsSet:sender];