1 /* HBAdvancedController
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
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:NULL];
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];
100 * Populates the option widgets
102 - (IBAction) X264AdvancedOptionsSet: (id) sender
104 /*Set opt widget values here*/
106 /*B-Frames fX264optBframesPopUp*/
108 [fX264optBframesPopUp removeAllItems];
109 [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
112 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
115 /*Reference Frames fX264optRefPopUp*/
116 [fX264optRefPopUp removeAllItems];
117 [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
120 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
123 /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
124 [fX264optNfpskipSwitch setState:0];
126 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
127 [fX264optNodctdcmtSwitch setState:0];
129 /*Sub Me fX264optSubmePopUp*/
130 [fX264optSubmePopUp removeAllItems];
131 [fX264optSubmePopUp addItemWithTitle:@"Default (4)"];
134 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
137 /*Trellis fX264optTrellisPopUp*/
138 [fX264optTrellisPopUp removeAllItems];
139 [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
142 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
145 /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
146 [fX264optMixedRefsSwitch setState:0];
148 /*Motion Estimation fX264optMotionEstPopUp*/
149 [fX264optMotionEstPopUp removeAllItems];
150 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
151 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
152 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
153 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
154 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
156 /*Motion Estimation range fX264optMERangePopUp*/
157 [fX264optMERangePopUp removeAllItems];
158 [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
161 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
164 /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
165 [fX264optWeightBSwitch setState:0];
167 /*B-Frame Rate Distortion Optimization fX264optBRDOSwitch BOOLEAN*/
168 [fX264optBRDOSwitch setState:0];
170 /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
171 [fX264optBPyramidSwitch setState:0];
173 /*Bidirectional Motion Estimation Refinement fX264optBiMESwitch BOOLEAN*/
174 [fX264optBiMESwitch setState:0];
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"];
185 [fX264optAlphaDeblockPopUp removeAllItems];
186 [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
189 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
193 [fX264optBetaDeblockPopUp removeAllItems];
194 [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
197 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
200 /* Analysis fX264optAnalysePopUp */
201 [fX264optAnalysePopUp removeAllItems];
202 [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
203 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
204 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
206 /* 8x8 DCT fX264op8x8dctSwitch */
207 [fX264opt8x8dctSwitch setState:0];
209 /* CABAC fX264opCabacSwitch */
210 [fX264optCabacSwitch setState:1];
212 /* Standardize the option string */
213 [self X264AdvancedOptionsStandardizeOptString: NULL];
215 /* Set Current GUI Settings based on newly standardized string */
216 [self X264AdvancedOptionsSetCurrentSettings: NULL];
220 * Cleans the option string to use a standard format of option=value
222 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
224 /* Set widgets depending on the opt string in field */
225 NSString * thisOpt; // The separated option such as "bframes=3"
226 NSString * optName = @""; // The option name such as "bframes"
227 NSString * optValue = @"";// The option value such as "3"
228 NSString * changedOptString = @"";
229 NSArray *currentOptsArray;
231 /*First, we get an opt string to process */
232 NSString *currentOptString = [fDisplayX264Options stringValue];
234 /* Verify there is an opt string to process by making sure an
235 option is getting its value set. If so, start to process it. */
236 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
237 if (currentOptRange.location != NSNotFound)
239 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
240 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
242 /*iterate through the array and get <opts> and <values*/
244 int currentOptsArrayCount = [currentOptsArray count];
245 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
247 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
249 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
250 if (splitOptRange.location != NSNotFound)
252 optName = [thisOpt substringToIndex:splitOptRange.location];
253 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
255 /* Standardize the names here depending on whats in the string */
256 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
257 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
259 else // No value given so we use a default of "1"
263 /* Standardize the names here depending on whats in the string */
264 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
265 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
268 /* Construct New String for opts here.*/
269 if ([thisOpt isEqualToString:@""])
271 /* Blank option, just add it to the string. (Why?) */
272 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
276 if ([changedOptString isEqualToString:@""])
278 /* Blank string, output the current option. */
279 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
283 /* Option exists and string exists, so append the option
284 to the string with a semi-colon inbetween them. */
285 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
291 /* Change the option string to reflect the new standardized option string */
292 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
296 * Cleans the option string to use a standard set of option names, by conflating synonyms.
298 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
300 /* Reference Frames */
301 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
303 cleanOptNameString = @"ref";
306 /*No Fast PSkip nofast_pskip*/
307 if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
309 cleanOptNameString = @"no-fast-pskip";
313 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
315 cleanOptNameString = @"no-dct-decimate";
319 if ([cleanOptNameString isEqualToString:@"subme"])
321 cleanOptNameString = @"subq";
325 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
326 cleanOptNameString = @"merange";
329 if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
331 cleanOptNameString = @"weightb";
335 if ([cleanOptNameString isEqualToString:@"b-rdo"] || [cleanOptNameString isEqualToString:@"b_rdo"])
337 cleanOptNameString = @"brdo";
341 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
343 cleanOptNameString = @"b-pyramid";
346 /*Direct Prediction*/
347 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
349 cleanOptNameString = @"direct";
353 if ([cleanOptNameString isEqualToString:@"filter"])
355 cleanOptNameString = @"deblock";
359 if ([cleanOptNameString isEqualToString:@"partitions"])
361 cleanOptNameString = @"analyse";
364 return cleanOptNameString;
368 * Resets the GUI widgets to the contents of the option string.
370 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
372 /* Set widgets depending on the opt string in field */
373 NSString * thisOpt; // The separated option such as "bframes=3"
374 NSString * optName = @""; // The option name such as "bframes"
375 NSString * optValue = @"";// The option value such as "3"
376 NSArray *currentOptsArray;
378 /*First, we get an opt string to process */
379 NSString *currentOptString = [fDisplayX264Options stringValue];
381 /* Verify there is an opt string to process by making sure an
382 option is getting its value set. If so, start to process it. */
383 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
384 if (currentOptRange.location != NSNotFound)
386 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
387 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
389 /*iterate through the array and get <opts> and <values*/
391 int currentOptsArrayCount = [currentOptsArray count];
392 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
394 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
396 /* Verify the option sets a value */
397 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
398 if (splitOptRange.location != NSNotFound)
400 /* Split thisOpt into an optName setting an optValue. */
401 optName = [thisOpt substringToIndex:splitOptRange.location];
402 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
404 /*Run through the available widgets for x264 opts and set them, as you add widgets,
405 they need to be added here. This should be moved to its own method probably*/
407 /*bframes NSPopUpButton*/
408 if ([optName isEqualToString:@"bframes"])
410 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
412 /*ref NSPopUpButton*/
413 if ([optName isEqualToString:@"ref"])
415 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
417 /*No Fast PSkip NSButton*/
418 if ([optName isEqualToString:@"no-fast-pskip"])
420 [fX264optNfpskipSwitch setState:[optValue intValue]];
422 /*No Dict Decimate NSButton*/
423 if ([optName isEqualToString:@"no-dct-decimate"])
425 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
427 /*Sub Me NSPopUpButton*/
428 if ([optName isEqualToString:@"subq"])
430 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
432 /*Trellis NSPopUpButton*/
433 if ([optName isEqualToString:@"trellis"])
435 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
437 /*Mixed Refs NSButton*/
438 if ([optName isEqualToString:@"mixed-refs"])
440 [fX264optMixedRefsSwitch setState:[optValue intValue]];
442 /*Motion Estimation NSPopUpButton*/
443 if ([optName isEqualToString:@"me"])
445 if ([optValue isEqualToString:@"dia"])
446 [fX264optMotionEstPopUp selectItemAtIndex:1];
447 else if ([optValue isEqualToString:@"hex"])
448 [fX264optMotionEstPopUp selectItemAtIndex:2];
449 else if ([optValue isEqualToString:@"umh"])
450 [fX264optMotionEstPopUp selectItemAtIndex:3];
451 else if ([optValue isEqualToString:@"esa"])
452 [fX264optMotionEstPopUp selectItemAtIndex:4];
454 /*ME Range NSPopUpButton*/
455 if ([optName isEqualToString:@"merange"])
457 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
459 /*Weighted B-Frames NSButton*/
460 if ([optName isEqualToString:@"weightb"])
462 [fX264optWeightBSwitch setState:[optValue intValue]];
465 if ([optName isEqualToString:@"brdo"])
467 [fX264optBRDOSwitch setState:[optValue intValue]];
469 /*B Pyramid NSPButton*/
470 if ([optName isEqualToString:@"b-pyramid"])
472 [fX264optBPyramidSwitch setState:[optValue intValue]];
474 /*Bidirectional Motion Estimation Refinement NSButton*/
475 if ([optName isEqualToString:@"bime"])
477 [fX264optBiMESwitch setState:[optValue intValue]];
479 /*Direct B-frame Prediction NSPopUpButton*/
480 if ([optName isEqualToString:@"direct"])
482 if ([optValue isEqualToString:@"none"])
483 [fX264optDirectPredPopUp selectItemAtIndex:1];
484 else if ([optValue isEqualToString:@"spatial"])
485 [fX264optDirectPredPopUp selectItemAtIndex:2];
486 else if ([optValue isEqualToString:@"temporal"])
487 [fX264optDirectPredPopUp selectItemAtIndex:3];
488 else if ([optValue isEqualToString:@"auto"])
489 [fX264optDirectPredPopUp selectItemAtIndex:4];
491 /*Deblocking NSPopUpButtons*/
492 if ([optName isEqualToString:@"deblock"])
494 NSString * alphaDeblock = @"";
495 NSString * betaDeblock = @"";
497 NSRange splitDeblock = [optValue rangeOfString:@","];
498 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
499 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
501 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
503 /* When both filters are at 0, default */
504 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
505 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
509 if (![alphaDeblock isEqualToString:@"0"])
511 /* Alpha isn't 0, so set it. The offset of 7 is
512 because filters start at -6 instead of at 0. */
513 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
517 /* Set alpha filter to 0, which is 7 up
518 because filters start at -6, not 0. */
519 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
522 if (![betaDeblock isEqualToString:@"0"])
524 /* Beta isn't 0, so set it. */
525 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
529 /* Set beta filter to 0. */
530 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
534 /* Analysis NSPopUpButton */
535 if ([optName isEqualToString:@"analyse"])
537 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
539 /* Default ("some") */
540 [fX264optAnalysePopUp selectItemAtIndex:0];
542 if ([optValue isEqualToString:@"none"])
544 [fX264optAnalysePopUp selectItemAtIndex:1];
546 if ([optValue isEqualToString:@"all"])
548 [fX264optAnalysePopUp selectItemAtIndex:2];
551 /* 8x8 DCT NSButton */
552 if ([optName isEqualToString:@"8x8dct"])
554 [fX264opt8x8dctSwitch setState:[optValue intValue]];
557 if ([optName isEqualToString:@"cabac"])
559 [fX264optCabacSwitch setState:[optValue intValue]];
567 * Resets the option string to mirror the GUI widgets.
569 - (IBAction) X264AdvancedOptionsChanged: (id) sender
571 /*Determine which outlet is being used and set optName to process accordingly */
572 NSString * optNameToChange = @""; // The option name such as "bframes"
574 if (sender == fX264optBframesPopUp)
576 optNameToChange = @"bframes";
578 if (sender == fX264optRefPopUp)
580 optNameToChange = @"ref";
582 if (sender == fX264optNfpskipSwitch)
584 optNameToChange = @"no-fast-pskip";
586 if (sender == fX264optNodctdcmtSwitch)
588 optNameToChange = @"no-dct-decimate";
590 if (sender == fX264optSubmePopUp)
592 optNameToChange = @"subq";
594 if (sender == fX264optTrellisPopUp)
596 optNameToChange = @"trellis";
598 if (sender == fX264optMixedRefsSwitch)
600 optNameToChange = @"mixed-refs";
602 if (sender == fX264optMotionEstPopUp)
604 optNameToChange = @"me";
606 if (sender == fX264optMERangePopUp)
608 optNameToChange = @"merange";
610 if (sender == fX264optWeightBSwitch)
612 optNameToChange = @"weightb";
614 if (sender == fX264optBRDOSwitch)
616 optNameToChange = @"brdo";
618 if (sender == fX264optBPyramidSwitch)
620 optNameToChange = @"b-pyramid";
622 if (sender == fX264optBiMESwitch)
624 optNameToChange = @"bime";
626 if (sender == fX264optDirectPredPopUp)
628 optNameToChange = @"direct";
630 if (sender == fX264optAlphaDeblockPopUp)
632 optNameToChange = @"deblock";
634 if (sender == fX264optBetaDeblockPopUp)
636 optNameToChange = @"deblock";
638 if (sender == fX264optAnalysePopUp)
640 optNameToChange = @"analyse";
642 if (sender == fX264opt8x8dctSwitch)
644 optNameToChange = @"8x8dct";
646 if (sender == fX264optCabacSwitch)
648 optNameToChange = @"cabac";
651 /* Set widgets depending on the opt string in field */
652 NSString * thisOpt; // The separated option such as "bframes=3"
653 NSString * optName = @""; // The option name such as "bframes"
654 NSString * optValue = @"";// The option value such as "3"
655 NSArray *currentOptsArray;
657 /*First, we get an opt string to process */
658 NSString *currentOptString = [fDisplayX264Options stringValue];
660 /* There are going to be a few possibilities.
661 - The option might start off the string.
662 - The option might be in the middle of the string.
663 - The option might not be in the string at all yet.
664 - The string itself might not yet exist.
666 Because each of these possibilities means constructing a different kind of string,
667 they're all handled separately in a sea of messy, somewhat redundant code. =( */
669 /* If the option is in the string but not the beginning of it, it will be in the form of ":optName=value"
670 so we really want to be looking for ":optNameToChange=" rather than "optNameToChange". */
671 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
673 /* Now we store the part of the string up through the option name in currentOptRange. */
674 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
676 /* We need to know if the option is at the beginning of the string.
677 If it is at the start, it won't be preceded by a colon.
678 To figure this out, we'll use the rangeOfString method. First,
679 store what the option name would be if if it was at the beginning,
680 in checkOptNameToChangeBeginning. Then, find its range in the string.
681 If the range is 0, it's the first option listed in the string. */
682 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
683 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
685 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
687 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
688 This means parsing the whole string into an array of options and values. From there,
689 iterate through the options, and when you reach the one that's been changed, edit it. */
691 /* Create new empty opt string*/
692 NSString *changedOptString = @"";
694 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
695 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
697 /*iterate through the array and get <opts> and <values*/
699 int currentOptsArrayCount = [currentOptsArray count];
700 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
702 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
703 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
705 if (splitOptRange.location != NSNotFound)
707 /* First off, it's time to handle option strings that
708 already have at least one option=value pair in them. */
710 optName = [thisOpt substringToIndex:splitOptRange.location];
711 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
713 /*Run through the available widgets for x264 opts and set them, as you add widgets,
714 they need to be added here. This should be moved to its own method probably*/
716 /*If the optNameToChange is found, appropriately change the value or delete it if
717 "Unspecified" is set.*/
718 if ([optName isEqualToString:optNameToChange])
720 if ([optNameToChange isEqualToString:@"deblock"])
722 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
724 /* When both deblock widgets are 0 or default or a mix of the two,
725 use a blank string, since deblocking defaults to 0,0. */
730 /* Otherwise the format is deblock=a,b, where a and b both have an array
731 offset of 7 because deblocking values start at -6 instead of at zero. */
732 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
735 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"] )
737 /* Here is where we take care of the boolean options that work overtly:
738 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
739 require the inverse, but those will be handled a couple lines down. */
740 if ([sender state] == 0)
742 /* When these options are false, don't include them. They all default
743 to being set off, so they don't need to be mentioned at all. */
748 /* Otherwise, include them as optioname=1 */
749 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
752 else if ([optNameToChange isEqualToString:@"cabac"])
754 /* CABAC is odd, in that it defaults to being on. That means
755 it only needs to be included in the string when turned off. */
756 if ([sender state] == 1)
758 /* It's true so don't include it. */
763 /* Otherwise, include cabac=0 in the string to enable CAVLC. */
764 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
767 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
769 /* When a widget is at index 0, it's default. Default means don't add to the string.
770 The exception for deblocking is because for those, *both* need to at index 0
771 for it to default, so it's handled separately, above this section. */
774 else if ([optNameToChange isEqualToString:@"me"])
776 /* Motion estimation uses string values, so this switch
777 pairs the widget index with the right value string. */
778 switch ([sender indexOfSelectedItem])
781 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
785 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
789 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
793 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
800 else if ([optNameToChange isEqualToString:@"direct"])
802 /* Direct prediction uses string values, so this switch
803 pairs the right string value with the right widget index. */
804 switch ([sender indexOfSelectedItem])
807 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
811 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
815 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
819 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
826 else if ([optNameToChange isEqualToString:@"analyse"])
828 /* Analysis uses string values as well. */
829 switch ([sender indexOfSelectedItem])
832 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
836 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
843 else if ([optNameToChange isEqualToString:@"merange"])
845 /* Motion estimation range uses an odd array offset because in addition
846 to starting with index 0 as default, index 1 starts at 4 instead of 1,
847 because merange can't go below 4. So it has to be handled separately. */
848 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
850 else // we have a valid value to change, so change it
852 if ( [sender indexOfSelectedItem] != 0 )
853 /* Here's our general case, that catches things like ref frames and b-frames.
854 Basically, any options that are PopUp menus with index 0 as default and
855 index 1 as 1, with numerical values, are all handled right here. All of
856 the above stuff is for the exceptions to the general case. */
857 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
862 /* Construct New String for opts here */
863 if ([thisOpt isEqualToString:@""])
865 /* Blank option, so just add it to the string. (Why?) */
866 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
870 if ([changedOptString isEqualToString:@""])
872 /* No existing string, make the string this option. */
873 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
877 /* Existing string, existing option. Append the
878 option to the string, preceding it with a colon. */
879 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
884 /* Change the dislayed option string to reflect the new modified settings */
885 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
887 else // if none exists, add it to the string
889 /* This is where options that aren't already in the string are handled. */
890 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
892 /* The option might not be in the string because the
893 string is empty. Handle this possibility first. */
894 if ([optNameToChange isEqualToString:@"me"])
896 /* Special case for motion estimation, which uses string values
897 that need to be paired up with the equivalent widget index. */
898 switch ([sender indexOfSelectedItem])
901 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
902 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
906 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
907 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
911 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
912 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
916 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
917 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
924 else if ([optNameToChange isEqualToString:@"direct"])
926 /* Special case for direct prediction, which uses string values
927 that need to be paired up with the equivalent widget index. */
928 switch ([sender indexOfSelectedItem])
931 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
932 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
936 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
937 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
941 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
942 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
946 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
947 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
954 else if ([optNameToChange isEqualToString:@"analyse"])
956 /* Special case for partition analysis, which uses string values
957 that need to be paired up with the equivalent widget index. */
958 switch ([sender indexOfSelectedItem])
961 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
962 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
966 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
967 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
975 else if ([optNameToChange isEqualToString:@"merange"])
977 /* Special case for motion estimation range, which uses
978 a widget index offset of 3. This is because the
979 first valid value after default is four, not zero. */
980 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
981 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
983 else if ([optNameToChange isEqualToString:@"deblock"])
985 /* Very special case for deblock. Uses a weird widget index offset
986 of 7, because the first value after default is -6, rather than 0.
987 As well, deblock only goes to default when *both* alpha and beta
988 are zero. If only one is zero, you can't mark it down as default.
989 Instead, mark that one down as literally 0. This is because when
990 widgets are at default values, they aren't included in the string.
991 If only one filter is at 0, both need to be overtly specified. */
992 [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]]];
994 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"] )
996 /* This covers all the boolean options that need to be specified only when true. */
997 if ([sender state] == 0)
999 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1003 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1004 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1007 else if ([optNameToChange isEqualToString:@"cabac"])
1009 /* CABAC is weird in that you need the inverse. Only include in the string
1010 when cabac=0, because cabac=1 is the default. Turning it off means CAVLC. */
1011 if ([sender state] == 1)
1013 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
1017 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1018 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1023 if ( [sender indexOfSelectedItem] != 0 )
1024 /* General case to cover all the normal PopUp widgets, like ref and b-frames. */
1025 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
1026 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1031 /* The string isn't empty, and the option isn't already in it,
1032 so it will need to be appended to the string with a colon. */
1033 if ([optNameToChange isEqualToString:@"me"])
1035 /* Special case for motion estimation, which uses string values
1036 that need to be paired up with the equivalent widget index. */
1037 switch ([sender indexOfSelectedItem])
1040 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1041 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1042 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
1046 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1047 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1048 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
1052 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1053 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1054 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
1058 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1059 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1060 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
1067 else if ([optNameToChange isEqualToString:@"direct"])
1069 /* Special case for direct prediction, which uses string values
1070 that need to be paired up with the equivalent widget index. */
1071 switch ([sender indexOfSelectedItem])
1074 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1075 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1076 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1080 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1081 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1082 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
1086 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1087 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1088 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
1092 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1093 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1094 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
1101 else if ([optNameToChange isEqualToString:@"analyse"])
1103 /* Special case for partition analysis, which uses string values
1104 that need to be paired up with the equivalent widget index. */
1105 switch ([sender indexOfSelectedItem])
1108 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1109 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1110 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
1114 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
1115 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
1116 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1124 else if ([optNameToChange isEqualToString:@"merange"])
1126 /* Motion estimation range uses a weird offset since its index goes
1127 0: default, 1: 4, because the first valid value is 4, not 1. */
1128 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1129 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1131 else if ([optNameToChange isEqualToString:@"deblock"])
1133 /* Deblock is really weird because it has two values, and if only one is default, both
1134 still need to be specified directly. with the default one at zero. To make deblock
1135 just a little more fun, values start at -6 instead of at zero. */
1136 [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]]];
1138 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"] )
1140 /* Covers all the normal booleans, that only need to be included in the string when they're true. */
1141 if ([sender state] == 0)
1143 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1147 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1148 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1151 else if ([optNameToChange isEqualToString:@"cabac"])
1153 /* CABAC is weird, in that it's an inverse. Only include it in the string when it's false. */
1154 if ([sender state] == 1)
1156 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
1160 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1161 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1166 /* General case to handle the normal PopUp widgets like ref and b-frames. */
1167 if ( [sender indexOfSelectedItem] != 0 )
1168 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
1169 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1174 /* We now need to reset the opt widgets since we changed some stuff */
1175 [self X264AdvancedOptionsSet:NULL];