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,
68 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
69 fX264optTrellisLabel,fX264optTrellisPopUp, fX264optWeightPLabel, fX264optWeightPSwitch,
70 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
71 fX264optBPyramidLabel,fX264optBPyramidPopUp, fX264optAqLabel, fX264optAqSlider,
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 NSString * toolTip = @"";
109 /*B-Frames fX264optBframesPopUp*/
111 [fX264optBframesPopUp removeAllItems];
112 [fX264optBframesPopUp addItemWithTitle:@"Default (3)"];
115 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
118 @"Sane values are ~2-5. This specifies the maximum number of sequential B-frames that the encoder can use. Large numbers generally won't help significantly unless Adaptive B-frames is set to Optimal. Cel-animated source material and B-pyramid also significantly increase the usefulness of larger values. Baseline profile, as required for iPods and similar devices, requires B-frames to be set to 0 (off).";
119 [fX264optBframesPopUp setToolTip: toolTip];
120 [fX264optBframesLabel setToolTip: toolTip];
122 /*Reference Frames fX264optRefPopUp*/
123 [fX264optRefPopUp removeAllItems];
124 [fX264optRefPopUp addItemWithTitle:@"Default (3)"];
127 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
130 @"Sane values are ~1-6. The more you add, the better the compression, but the slower the encode. Cel animation tends to benefit from more reference frames a lot more than film content. Note that many hardware devices have limitations on the number of supported reference frames, so if you're encoding for a handheld or standalone player, don't touch this unless you're absolutely sure you know what you're doing!";
131 [fX264optRefPopUp setToolTip: toolTip];
132 [fX264optRefLabel setToolTip: toolTip];
134 /*Weight-P fX264optWeightPSwitch BOOLEAN*/
135 [fX264optWeightPSwitch setState:1];
137 @"Performs extra analysis to decide upon weighting parameters for each frame. This improves overall compression slightly and improves the quality of fades greatly. Baseline profile, as required for iPods and similar devices, requires weighted P-frame prediction to be disabled. Note that some devices and players, even those that support Main Profile, may have problems with Weighted P-frame prediction: the Apple TV is completely incompatible with it, for example.";
138 [fX264optWeightPSwitch setToolTip: toolTip];
139 [fX264optWeightPLabel setToolTip: toolTip];
141 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
142 [fX264optNodctdcmtSwitch setState:0];
144 @"x264 normally zeroes out nearly-empty data blocks to save bits to be better used for some other purpose in the video. However, this can sometimes have slight negative effects on retention of subtle grain and dither. Don't touch this unless you're having banding issues or other such cases where you are having trouble keeping fine noise.";
145 [fX264optNodctdcmtSwitch setToolTip: toolTip];
146 [fX264optNodctdcmtLabel setToolTip: toolTip];
148 /*Sub Me fX264optSubmePopUp*/
149 [fX264optSubmePopUp removeAllItems];
150 [fX264optSubmePopUp addItemWithTitle:@"Default (7)"];
151 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"0: SAD, no subpel (super fast!)"]];
152 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"1: SAD, qpel"]];
153 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"2: SATD, qpel"]];
154 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"3: SATD, multi-qpel"]];
155 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"4: SATD, qpel on all"]];
156 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"5: SATD, multi-qpel on all"]];
157 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"6: RD in I/P-frames"]];
158 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"7: RD in all frames"]];
159 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"8: RD refine in I/P-frames"]];
160 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"9: RD refine in all frames"]];
161 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"10: QPRD in all frames"]];
163 @"This setting controls both subpixel-precision motion estimation and mode decision methods.\n\nSubpixel motion estimation is used for refining motion estimates beyond mere pixel accuracy, improving compression.\n\nMode decision is the method used to choose how to encode each block of the frame: a very important decision.\n\nSAD is the fastest method, followed by SATD, RD, RD refinement, and the slowest, QPRD.\n\n6 or higher is strongly recommended: Psy-RD, a very powerful psy optimization that helps retain detail, requires RD.\n\n10, the most powerful and slowest option, requires trellis=2.";
164 [fX264optSubmePopUp setToolTip: toolTip];
165 [fX264optSubmeLabel setToolTip: toolTip];
167 /*Trellis fX264optTrellisPopUp*/
168 [fX264optTrellisPopUp removeAllItems];
169 [fX264optTrellisPopUp addItemWithTitle:@"Default (Encode only)"];
170 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Off"]];
171 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Encode only"]];
172 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"Always"]];
173 [fX264optTrellisPopUp setWantsLayer:YES];
175 @"Trellis fine-tunes the rounding of transform coefficients to squeeze out 3-5% more compression at the cost of some speed. \"Always\" uses trellis not only during the main encoding process, but also during analysis, which improves compression even more, albeit at great speed cost. Trellis costs more speed at higher bitrates.";
176 [fX264optTrellisPopUp setToolTip: toolTip];
177 [fX264optTrellisLabel setToolTip: toolTip];
179 /*Motion Estimation fX264optMotionEstPopUp*/
180 [fX264optMotionEstPopUp removeAllItems];
181 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
182 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
183 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
184 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
185 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
186 [fX264optMotionEstPopUp addItemWithTitle:@"Transformed Exhaustive"];
188 @"Controls the motion estimation method. Motion estimation is how the encoder estimates how each block of pixels in a frame has moved. A better motion search method improves compression at the cost of speed.\n\nDiamond: performs an extremely fast and simple search using a diamond pattern.\n\nHexagon: performs a somewhat more effective but slightly slower search using a hexagon pattern.\n\nUneven Multi-Hex: performs a very wide search using a variety of patterns, more accurately capturing complex motion.\n\nExhaustive: performs a \"dumb\" search of every pixel in a wide area. Significantly slower for only a small compression gain.\n\nTransformed Exhaustive: Like exhaustive, but makes even more accurate decisions. Accordingly, somewhat slower, also for only a small improvement.";
189 [fX264optMotionEstPopUp setToolTip: toolTip];
190 [fX264optMotionEstLabel setToolTip: toolTip];
192 /*Motion Estimation range fX264optMERangePopUp*/
193 [fX264optMERangePopUp removeAllItems];
194 [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
197 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
200 @"This is the distance x264 searches from its best guess at the motion of a block in order to try to find its actual motion. Doesn't apply to Diamond or Hexagon search options. The default is fine for most content, but extremely high motion video, especially at HD resolutions, may benefit from higher ranges, albeit at a high speed cost.";
201 [fX264optMERangePopUp setToolTip: toolTip];
202 [fX264optMERangeLabel setToolTip: toolTip];
204 /*B-frame Pyramids fX264optBPyramidPopUp*/
205 [fX264optBPyramidPopUp removeAllItems];
206 [fX264optBPyramidPopUp addItemWithTitle:@"Default (Normal)"];
207 [fX264optBPyramidPopUp addItemWithTitle:@"Off"];
208 [fX264optBPyramidPopUp addItemWithTitle:@"Strict"];
209 [fX264optBPyramidPopUp setWantsLayer:YES];
211 @"B-pyramid improves compression by creating a pyramidal structure (hence the name) of B-frames, allowing B-frames to reference each other to improve compression. Requires Max B-frames greater than 1; optimal adaptive B-frames is strongly recommended for full compression benefit.";
212 [fX264optBPyramidPopUp setToolTip: toolTip];
213 [fX264optBPyramidLabel setToolTip: toolTip];
215 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
216 [fX264optDirectPredPopUp removeAllItems];
217 [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
218 [fX264optDirectPredPopUp addItemWithTitle:@"None"];
219 [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
220 [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
221 [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
222 [fX264optDirectPredPopUp setWantsLayer:YES];
224 @"H.264 allows for two different prediction modes, spatial and temporal, in B-frames.\n\nSpatial, the default, is almost always better, but temporal is sometimes useful too.\n\nx264 can, at the cost of a small amount of speed (and accordingly for a small compression gain), adaptively select which is better for each particular frame.";
225 [fX264optDirectPredPopUp setToolTip: toolTip];
226 [fX264optDirectPredLabel setToolTip: toolTip];
228 /* Adaptive B-Frames Mode fX264optBAdaptPopUp */
229 [fX264optBAdaptPopUp removeAllItems];
230 [fX264optBAdaptPopUp addItemWithTitle:@"Default (Fast)"];
231 [fX264optBAdaptPopUp addItemWithTitle:@"Off"];
232 [fX264optBAdaptPopUp addItemWithTitle:@"Fast"];
233 [fX264optBAdaptPopUp addItemWithTitle:@"Optimal"];
234 [fX264optBAdaptPopUp setWantsLayer:YES];
236 @"x264 has a variety of algorithms to decide when to use B-frames and how many to use.\n\nFast mode takes roughly the same amount of time no matter how many B-frames you specify. However, while fast, its decisions are often suboptimal.\n\nOptimal mode gets slower as the maximum number of B-Frames increases, but makes much more accurate decisions, especially when used with B-pyramid.";
237 [fX264optBAdaptPopUp setToolTip: toolTip];
238 [fX264optBAdaptLabel setToolTip: toolTip];
241 [fX264optAlphaDeblockPopUp removeAllItems];
242 [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
245 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
248 @"H.264 has a built-in deblocking filter that smooths out blocking artifacts after decoding each frame. This not only improves visual quality, but also helps compression significantly. The deblocking filter takes a lot of CPU power, so if you're looking to minimize CPU requirements for video playback, disable it.\n\nThe deblocking filter has two adjustable parameters, \"strength\" and \"threshold\". The former controls how strong (or weak) the deblocker is, while the latter controls how many (or few) edges it applies to. Lower values mean less deblocking, higher values mean more deblocking. The default is 0 (normal strength) for both parameters.";
249 [fX264optAlphaDeblockPopUp setToolTip: toolTip];
250 [fX264optDeblockLabel setToolTip: toolTip];
253 [fX264optBetaDeblockPopUp removeAllItems];
254 [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
257 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
259 [fX264optBetaDeblockPopUp setToolTip: toolTip];
260 [fX264optDeblockLabel setToolTip: toolTip];
262 /* Analysis fX264optAnalysePopUp */
263 [fX264optAnalysePopUp removeAllItems];
264 [fX264optAnalysePopUp addItemWithTitle:@"Default (Most)"]; /* 0=default */
265 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
266 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"Some"]]; /* 2=some */
267 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 3=all */
269 @"Mode decision picks from a variety of options to make its decision: this option chooses what options those are. Fewer partitions to check means faster encoding, at the cost of worse decisions, since the best option might have been one that was turned off.";
270 [fX264optAnalysePopUp setToolTip: toolTip];
271 [fX264optAnalyseLabel setToolTip: toolTip];
273 /* 8x8 DCT fX264op8x8dctSwitch */
274 [fX264opt8x8dctSwitch setState:1];
275 [fX264opt8x8dctSwitch setWantsLayer:YES];
277 @"The 8x8 transform is the single most useful feature of x264 in terms of compression-per-speed. It improves compression by at least 5% at a very small speed cost and may provide an unusually high visual quality benefit compared to its compression gain. However, it requires High Profile, which many devices may not support.";
278 [fX264opt8x8dctSwitch setToolTip: toolTip];
279 [fX264opt8x8dctLabel setToolTip: toolTip];
281 /* CABAC fX264opCabacSwitch */
282 [fX264optCabacSwitch setState:1];
284 @"After the encoder has done its work, it has a bunch of data that needs to be compressed losslessly, similar to ZIP or RAR. H.264 provides two options for this: CAVLC and CABAC. CABAC decodes a lot slower but compresses significantly better (10-30%), especially at lower bitrates. If you're looking to minimize CPU requirements for video playback, disable this option. Baseline profile, as required for iPods and similar devices, requires CABAC to be disabled.";
285 [fX264optCabacSwitch setToolTip: toolTip];
286 [fX264optCabacLabel setToolTip: toolTip];
288 /* Adaptive Quantization Strength fX264opAqSlider */
289 [fX264optAqSlider setMinValue:0.0];
290 [fX264optAqSlider setMaxValue:2.0];
291 [fX264optAqSlider setTickMarkPosition:NSTickMarkBelow];
292 [fX264optAqSlider setNumberOfTickMarks:21];
293 [fX264optAqSlider setAllowsTickMarkValuesOnly:YES];
294 [fX264optAqSlider setFloatValue:1.0];
296 @"Adaptive quantization controls how the encoder distributes bits across the frame. Higher values take more bits away from edges and complex areas to improve areas with finer detail.";
297 [fX264optAqSlider setToolTip: toolTip];
298 [fX264optAqLabel setToolTip: toolTip];
300 /* PsyRDO fX264optPsyRDSlider */
301 [fX264optPsyRDSlider setMinValue:0.0];
302 [fX264optPsyRDSlider setMaxValue:2.0];
303 [fX264optPsyRDSlider setTickMarkPosition:NSTickMarkBelow];
304 [fX264optPsyRDSlider setNumberOfTickMarks:21];
305 [fX264optPsyRDSlider setAllowsTickMarkValuesOnly:YES];
306 [fX264optPsyRDSlider setFloatValue:1.0];
308 @"Psychovisual rate-distortion optimization takes advantage of the characteristics of human vision to dramatically improve apparent detail and sharpness. The effect can be made weaker or stronger by adjusting the strength. Being an RD algorithm, it requires mode decision to be at least \"6\".";
309 [fX264optPsyRDSlider setToolTip: toolTip];
310 [fX264optPsyRDLabel setToolTip: toolTip];
312 /* PsyTrellis fX264optPsyRDSlider */
313 [fX264optPsyTrellisSlider setMinValue:0.0];
314 [fX264optPsyTrellisSlider setMaxValue:1.0];
315 [fX264optPsyTrellisSlider setTickMarkPosition:NSTickMarkBelow];
316 [fX264optPsyTrellisSlider setNumberOfTickMarks:21];
317 [fX264optPsyTrellisSlider setAllowsTickMarkValuesOnly:YES];
318 [fX264optPsyTrellisSlider setFloatValue:0.0];
320 @"Psychovisual trellis is an experimental algorithm to further improve sharpness and detail retention beyond what Psychovisual RD does. Recommended values are around 0.2, though higher values may help for very grainy video or lower bitrate encodes. Not recommended for cel animation and other sharp-edged graphics.";
321 [fX264optPsyTrellisSlider setToolTip: toolTip];
322 [fX264optPsyTrellisLabel setToolTip: toolTip];
324 /* Standardize the option string */
325 [self X264AdvancedOptionsStandardizeOptString:nil];
327 /* Set Current GUI Settings based on newly standardized string */
328 [self X264AdvancedOptionsSetCurrentSettings:sender];
330 /* Fade out options that don't apply */
331 [self X264AdvancedOptionsAnimate: sender];
335 * Cleans the option string to use a standard format of option=value
337 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
339 /* Set widgets depending on the opt string in field */
340 NSString * thisOpt; // The separated option such as "bframes=3"
341 NSString * optName = @""; // The option name such as "bframes"
342 NSString * optValue = @"";// The option value such as "3"
343 NSString * changedOptString = @"";
344 NSArray *currentOptsArray;
346 /*First, we get an opt string to process */
347 NSString *currentOptString = [fDisplayX264Options stringValue];
349 /* Verify there is an opt string to process by making sure an
350 option is getting its value set. If so, start to process it. */
351 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
352 if (currentOptRange.location != NSNotFound)
354 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
355 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
357 /*iterate through the array and get <opts> and <values*/
359 int currentOptsArrayCount = [currentOptsArray count];
360 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
362 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
364 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
365 if (splitOptRange.location != NSNotFound)
367 optName = [thisOpt substringToIndex:splitOptRange.location];
368 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
370 /* Standardize the names here depending on whats in the string */
371 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
372 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
374 else // No value given so we use a default of "1"
378 /* Standardize the names here depending on whats in the string */
379 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
380 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
383 /* Construct New String for opts here.*/
384 if ([thisOpt isEqualToString:@""])
386 /* Blank option, just add it to the string. (Why?) */
387 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
391 if ([changedOptString isEqualToString:@""])
393 /* Blank string, output the current option. */
394 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
398 /* Option exists and string exists, so append the option
399 to the string with a semi-colon inbetween them. */
400 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
406 /* Change the option string to reflect the new standardized option string */
407 [fDisplayX264Options setStringValue:changedOptString];
411 * Cleans the option string to use a standard set of option names, by conflating synonyms.
413 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
415 /* Reference Frames */
416 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
418 cleanOptNameString = @"ref";
422 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
424 cleanOptNameString = @"no-dct-decimate";
428 if ([cleanOptNameString isEqualToString:@"subme"])
430 cleanOptNameString = @"subq";
434 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
435 cleanOptNameString = @"merange";
438 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
440 cleanOptNameString = @"b-pyramid";
443 /*Direct Prediction*/
444 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
446 cleanOptNameString = @"direct";
450 if ([cleanOptNameString isEqualToString:@"filter"])
452 cleanOptNameString = @"deblock";
456 if ([cleanOptNameString isEqualToString:@"partitions"])
458 cleanOptNameString = @"analyse";
461 return cleanOptNameString;
465 * Fades options in and out depending on whether they're available..
467 - (IBAction) X264AdvancedOptionsAnimate: (id) sender
469 /* Lots of situations to cover.
470 - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)
471 - CABAC (when 0 turn off trellis and psy-trel)
472 - subme (if under 6, turn off psy-rd and psy-trel)
473 - trellis (if 0, turn off psy-trel)
476 if( sender == fX264optBframesPopUp || sender == nil || sender == fDisplayX264Options )
478 if ( [fX264optBframesPopUp indexOfSelectedItem ] == 1 )
480 /* If the b-frame widget is at 1, the user has chosen
481 not to use b-frames at all. So disable the options
482 that can only be used when b-frames are enabled. */
484 if( [fX264optBPyramidPopUp isHidden] == false )
486 [[fX264optBPyramidPopUp animator] setHidden:YES];
487 [[fX264optBPyramidLabel animator] setHidden:YES];
488 if ( [fX264optBPyramidPopUp indexOfSelectedItem] > 0 )
490 [fX264optBPyramidPopUp selectItemAtIndex: 0];
491 [[fX264optBPyramidPopUp cell] performClick:self];
495 if( [fX264optDirectPredPopUp isHidden] == false )
497 [[fX264optDirectPredPopUp animator] setHidden:YES];
498 [[fX264optDirectPredLabel animator] setHidden:YES];
499 if ( [fX264optDirectPredPopUp indexOfSelectedItem] > 0 )
501 [fX264optDirectPredPopUp selectItemAtIndex: 0];
502 [[fX264optDirectPredPopUp cell] performClick:self];
506 if( [fX264optBAdaptPopUp isHidden] == false )
508 [[fX264optBAdaptPopUp animator] setHidden:YES];
509 [[fX264optBAdaptLabel animator] setHidden:YES];
510 if ( [fX264optBAdaptPopUp indexOfSelectedItem] > 0 )
512 [fX264optBAdaptPopUp selectItemAtIndex: 0];
513 [[fX264optBAdaptPopUp cell] performClick:self];
517 else if ( [fX264optBframesPopUp indexOfSelectedItem ] == 2)
519 /* Only 1 b-frame? Disable b-pyramid. */
520 if( [fX264optBPyramidPopUp isHidden] == false )
522 [[fX264optBPyramidPopUp animator] setHidden:YES];
523 [[fX264optBPyramidLabel animator] setHidden:YES];
524 if ( [fX264optBPyramidPopUp indexOfSelectedItem] > 0 )
526 [fX264optBPyramidPopUp selectItemAtIndex: 0];
527 [[fX264optBPyramidPopUp cell] performClick:self];
531 if( [fX264optDirectPredPopUp isHidden] == true )
533 [[fX264optDirectPredPopUp animator] setHidden:NO];
534 [[fX264optDirectPredLabel animator] setHidden:NO];
537 if( [fX264optBAdaptPopUp isHidden] == true )
539 [[fX264optBAdaptPopUp animator] setHidden:NO];
540 [[fX264optBAdaptLabel animator] setHidden:NO];
545 if( [fX264optBPyramidPopUp isHidden] == true )
547 [[fX264optBPyramidPopUp animator] setHidden:NO];
548 [[fX264optBPyramidLabel animator] setHidden:NO];
551 if( [fX264optDirectPredPopUp isHidden] == true )
553 [[fX264optDirectPredPopUp animator] setHidden:NO];
554 [[fX264optDirectPredLabel animator] setHidden:NO];
557 if( [fX264optBAdaptPopUp isHidden] == true )
559 [[fX264optBAdaptPopUp animator] setHidden:NO];
560 [[fX264optBAdaptLabel animator] setHidden:NO];
565 if( sender == fX264optMotionEstPopUp || sender == nil || sender == fDisplayX264Options )
567 if ( [fX264optMotionEstPopUp indexOfSelectedItem] < 3 )
569 /* ME-range can only be above 16 if me >= umh
570 and changing it to < 16 is idiotic so hide it . */
571 if( [fX264optMERangePopUp isHidden] == false )
573 [[fX264optMERangePopUp animator] setHidden:YES];
574 [[fX264optMERangeLabel animator] setHidden:YES];
575 if ( [fX264optMERangePopUp indexOfSelectedItem] > 0 )
577 [fX264optMERangePopUp selectItemAtIndex:0];
578 [[fX264optMERangePopUp cell] performClick:self];
584 if( [fX264optMERangePopUp isHidden] == true )
586 [[fX264optMERangePopUp animator] setHidden:NO];
587 [[fX264optMERangeLabel animator] setHidden:NO];
592 if( sender == fX264optSubmePopUp || sender == nil || sender == fDisplayX264Options )
594 if( [fX264optSubmePopUp indexOfSelectedItem] != 0 && [fX264optSubmePopUp indexOfSelectedItem] < 7 )
596 /* No Psy-RDO or Psy=trel if subme < 6. */
597 if( [fX264optPsyRDSlider isHidden] == false )
599 [[fX264optPsyRDSlider animator] setHidden:YES];
600 [[fX264optPsyRDLabel animator] setHidden:YES];
601 if ( [fX264optPsyRDSlider floatValue] < 1.0 )
603 [fX264optPsyRDSlider setFloatValue:1.0];
604 [[fX264optPsyRDSlider cell] performClick:self];
608 if( [fX264optPsyTrellisSlider isHidden] == false)
610 [[fX264optPsyTrellisSlider animator] setHidden:YES];
611 [[fX264optPsyTrellisLabel animator] setHidden:YES];
612 if ( [fX264optPsyTrellisSlider floatValue] > 0.0 )
614 [fX264optPsyTrellisSlider setFloatValue:0.0];
615 [[fX264optPsyTrellisSlider cell] performClick:self];
621 if( [fX264optPsyRDSlider isHidden] == true )
623 [[fX264optPsyRDSlider animator] setHidden:NO];
624 [[fX264optPsyRDLabel animator] setHidden:NO];
627 if( ( [fX264optTrellisPopUp indexOfSelectedItem] == 0 || [fX264optTrellisPopUp indexOfSelectedItem] >= 2 ) && [fX264optPsyTrellisSlider isHidden] == true )
629 [[fX264optPsyTrellisSlider animator] setHidden:NO];
630 [[fX264optPsyTrellisLabel animator] setHidden:NO];
635 if( sender == fX264optTrellisPopUp || sender == nil || sender == fDisplayX264Options )
637 if( [fX264optTrellisPopUp indexOfSelectedItem] > 0 && [fX264optTrellisPopUp indexOfSelectedItem] < 2 )
639 if( [fX264optPsyTrellisSlider isHidden] == false )
641 /* No Psy-trellis without trellis. */
642 [[fX264optPsyTrellisSlider animator] setHidden:YES];
643 [[fX264optPsyTrellisLabel animator] setHidden:YES];
644 [[fX264optPsyTrellisSlider animator] setFloatValue:0.0];
645 [[fX264optPsyTrellisSlider cell] performClick:self];
650 if( ( [fX264optSubmePopUp indexOfSelectedItem] == 0 || [fX264optSubmePopUp indexOfSelectedItem] >= 7 ) && [fX264optPsyTrellisSlider isHidden] == true )
652 [[fX264optPsyTrellisSlider animator] setHidden:NO];
653 [[fX264optPsyTrellisLabel animator] setHidden:NO];
660 * Resets the GUI widgets to the contents of the option string.
662 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
664 /* Set widgets depending on the opt string in field */
665 NSString * thisOpt; // The separated option such as "bframes=3"
666 NSString * optName = @""; // The option name such as "bframes"
667 NSString * optValue = @"";// The option value such as "3"
668 NSArray *currentOptsArray;
670 /*First, we get an opt string to process */
671 NSString *currentOptString = [fDisplayX264Options stringValue];
673 /* Verify there is an opt string to process by making sure an
674 option is getting its value set. If so, start to process it. */
675 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
676 if (currentOptRange.location != NSNotFound)
678 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
679 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
681 /*iterate through the array and get <opts> and <values*/
683 int currentOptsArrayCount = [currentOptsArray count];
684 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
686 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
688 /* Verify the option sets a value */
689 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
690 if (splitOptRange.location != NSNotFound)
692 /* Split thisOpt into an optName setting an optValue. */
693 optName = [thisOpt substringToIndex:splitOptRange.location];
694 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
696 /*Run through the available widgets for x264 opts and set them, as you add widgets,
697 they need to be added here. This should be moved to its own method probably*/
699 /*bframes NSPopUpButton*/
700 if ([optName isEqualToString:@"bframes"])
702 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
704 /*ref NSPopUpButton*/
705 if ([optName isEqualToString:@"ref"])
707 // Clamp values to a minimum of 1 and a maximum of 16
708 if ( [optValue intValue] < 1 )
710 [fX264optRefPopUp selectItemAtIndex:1];
711 [ self X264AdvancedOptionsChanged: fX264optRefPopUp];
713 else if ( [optValue intValue] > 16 )
715 [fX264optRefPopUp selectItemAtIndex:16];
716 [ self X264AdvancedOptionsChanged: fX264optRefPopUp];
720 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]];
724 if ([optName isEqualToString:@"weightp"])
726 if ([optValue intValue] < 1)
727 [fX264optWeightPSwitch setState:0];
729 [fX264optWeightPSwitch setState:1];
731 /*No Dict Decimate NSButton*/
732 if ([optName isEqualToString:@"no-dct-decimate"])
734 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
736 /*Sub Me NSPopUpButton*/
737 if ([optName isEqualToString:@"subq"])
739 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
741 /*Trellis NSPopUpButton*/
742 if ([optName isEqualToString:@"trellis"])
744 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
746 /*Motion Estimation NSPopUpButton*/
747 if ([optName isEqualToString:@"me"])
749 if ([optValue isEqualToString:@"dia"])
750 [fX264optMotionEstPopUp selectItemAtIndex:1];
751 else if ([optValue isEqualToString:@"hex"])
752 [fX264optMotionEstPopUp selectItemAtIndex:2];
753 else if ([optValue isEqualToString:@"umh"])
754 [fX264optMotionEstPopUp selectItemAtIndex:3];
755 else if ([optValue isEqualToString:@"esa"])
756 [fX264optMotionEstPopUp selectItemAtIndex:4];
757 else if ([optValue isEqualToString:@"tesa"])
758 [fX264optMotionEstPopUp selectItemAtIndex:5];
760 /*ME Range NSPopUpButton*/
761 if ([optName isEqualToString:@"merange"])
763 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
765 /* Adaptive B-Frames NSPopUpButton*/
766 if ([optName isEqualToString:@"b-adapt"])
768 [fX264optBAdaptPopUp selectItemAtIndex:[optValue intValue]+1];
770 /*B Pyramid NSPButton*/
771 if ([optName isEqualToString:@"b-pyramid"])
774 if( [optValue isEqualToString:@"normal"] )
776 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
777 [fX264optBPyramidPopUp selectItemAtIndex:0];
779 else if( [optValue isEqualToString:@"2"] )
781 [fX264optBPyramidPopUp selectItemAtIndex:0];
782 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
784 if( [optValue isEqualToString:@"strict"] )
786 [fX264optBPyramidPopUp selectItemAtIndex:2];
788 else if( [optValue isEqualToString:@"1"] )
790 [fX264optBPyramidPopUp selectItemAtIndex:2];
791 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
793 if( [optValue isEqualToString:@"none"] )
795 [fX264optBPyramidPopUp selectItemAtIndex:1];
797 else if( [optValue isEqualToString:@"0"] )
799 [fX264optBPyramidPopUp selectItemAtIndex:1];
800 [self X264AdvancedOptionsChanged: fX264optBPyramidPopUp];
803 /*Direct B-frame Prediction NSPopUpButton*/
804 if ([optName isEqualToString:@"direct"])
806 if ([optValue isEqualToString:@"none"])
807 [fX264optDirectPredPopUp selectItemAtIndex:1];
808 else if ([optValue isEqualToString:@"spatial"])
809 [fX264optDirectPredPopUp selectItemAtIndex:2];
810 else if ([optValue isEqualToString:@"temporal"])
811 [fX264optDirectPredPopUp selectItemAtIndex:3];
812 else if ([optValue isEqualToString:@"auto"])
813 [fX264optDirectPredPopUp selectItemAtIndex:4];
815 /*Deblocking NSPopUpButtons*/
816 if ([optName isEqualToString:@"deblock"])
818 NSString * alphaDeblock = @"";
819 NSString * betaDeblock = @"";
821 NSRange splitDeblock = [optValue rangeOfString:@","];
822 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
823 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
825 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
827 /* When both filters are at 0, default */
828 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
829 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
833 if (![alphaDeblock isEqualToString:@"0"])
835 /* Alpha isn't 0, so set it. The offset of 7 is
836 because filters start at -6 instead of at 0. */
837 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
841 /* Set alpha filter to 0, which is 7 up
842 because filters start at -6, not 0. */
843 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
846 if (![betaDeblock isEqualToString:@"0"])
848 /* Beta isn't 0, so set it. */
849 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
853 /* Set beta filter to 0. */
854 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
858 /* Analysis NSPopUpButton */
859 if ([optName isEqualToString:@"analyse"])
861 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
863 /* Default ("most") */
864 [fX264optAnalysePopUp selectItemAtIndex:0];
866 else if ([optValue isEqualToString:@"i4x4,i8x8"] ||
867 [optValue isEqualToString:@"i8x8,i4x4"] )
870 [fX264optAnalysePopUp selectItemAtIndex:2];
872 else if ([optValue isEqualToString:@"none"])
874 [fX264optAnalysePopUp selectItemAtIndex:1];
876 else if ([optValue isEqualToString:@"all"])
878 [fX264optAnalysePopUp selectItemAtIndex:3];
882 /* 8x8 DCT NSButton */
883 if ([optName isEqualToString:@"8x8dct"])
885 [fX264opt8x8dctSwitch setState:[optValue intValue]];
888 if ([optName isEqualToString:@"cabac"])
890 [fX264optCabacSwitch setState:[optValue intValue]];
892 /* Adaptive Quantization Strength NSSlider */
893 if ([optName isEqualToString:@"aq-strength"])
895 [fX264optAqSlider setFloatValue:[optValue floatValue]];
897 /* Psy-RD and Psy-Trellis NSSliders */
898 if ([optName isEqualToString:@"psy-rd"])
900 NSString * rdOpt = @"";
901 NSString * trellisOpt = @"";
903 NSRange splitRD = [optValue rangeOfString:@","];
904 rdOpt = [optValue substringToIndex:splitRD.location];
905 trellisOpt = [optValue substringFromIndex:splitRD.location + 1];
907 [fX264optPsyRDSlider setFloatValue:[rdOpt floatValue]];
908 [fX264optPsyTrellisSlider setFloatValue:[trellisOpt floatValue]];
915 - (NSString *) X264AdvancedOptionsOptIDToString: (id) widget
917 /*Determine which outlet is being used and set optName to process accordingly */
918 NSString * optNameToChange = @""; // The option name such as "bframes"
920 if (widget == fX264optBframesPopUp)
922 optNameToChange = @"bframes";
924 if (widget == fX264optRefPopUp)
926 optNameToChange = @"ref";
928 if (widget == fX264optWeightPSwitch)
930 optNameToChange = @"weightp";
932 if (widget == fX264optNodctdcmtSwitch)
934 optNameToChange = @"no-dct-decimate";
936 if (widget == fX264optSubmePopUp)
938 optNameToChange = @"subq";
940 if (widget == fX264optTrellisPopUp)
942 optNameToChange = @"trellis";
944 if (widget == fX264optMotionEstPopUp)
946 optNameToChange = @"me";
948 if (widget == fX264optMERangePopUp)
950 optNameToChange = @"merange";
952 if (widget == fX264optBAdaptPopUp)
954 optNameToChange = @"b-adapt";
956 if (widget == fX264optBPyramidPopUp)
958 optNameToChange = @"b-pyramid";
960 if (widget == fX264optDirectPredPopUp)
962 optNameToChange = @"direct";
964 if (widget == fX264optAlphaDeblockPopUp)
966 optNameToChange = @"deblock";
968 if (widget == fX264optBetaDeblockPopUp)
970 optNameToChange = @"deblock";
972 if (widget == fX264optAnalysePopUp)
974 optNameToChange = @"analyse";
976 if (widget == fX264opt8x8dctSwitch)
978 optNameToChange = @"8x8dct";
980 if (widget == fX264optCabacSwitch)
982 optNameToChange = @"cabac";
984 if( widget == fX264optAqSlider)
986 optNameToChange = @"aq-strength";
988 if( widget == fX264optPsyRDSlider)
990 optNameToChange = @"psy-rd";
992 if( widget == fX264optPsyTrellisSlider)
994 optNameToChange = @"psy-rd";
997 return optNameToChange;
1000 - (NSString *) X264AdvancedOptionsWidgetToString: (NSString *) optName withID: (id) sender
1002 NSString * thisOpt = @""; // The option=value string the method will return
1004 if ([optName isEqualToString:@"deblock"])
1006 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
1008 /* When both deblock widgets are 0 or default or a mix of the two,
1009 use a blank string, since deblocking defaults to 0,0. */
1014 /* Otherwise the format is deblock=a,b, where a and b both have an array
1015 offset of 7 because deblocking values start at -6 instead of at zero. */
1016 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
1020 else if ([optName isEqualToString:@"aq-strength"])
1022 if( [fX264optAqSlider floatValue] == 1.0 )
1024 /* When Aq is 1 it's the default value and can be ignored. */
1029 thisOpt = [NSString stringWithFormat:@"%@=%0.1f", optName, [fX264optAqSlider floatValue] ];
1033 else if ([optName isEqualToString:@"psy-rd"])
1035 if( [fX264optPsyRDSlider floatValue] == 1.0 && [fX264optPsyTrellisSlider floatValue] == 0.0 )
1037 /* When PsyRD is 1 and PsyTrel is 0 they're default values and can be ignored. */
1042 /* Otherwise the format is deblock=a,b, where a and b both have an array
1043 offset of 7 because deblocking values start at -6 instead of at zero. */
1044 thisOpt = [NSString stringWithFormat:@"%@=%0.1f,%0.2f", optName, [fX264optPsyRDSlider floatValue], [fX264optPsyTrellisSlider floatValue] ];
1048 else if /*Boolean Switches*/ ( [optName isEqualToString:@"no-dct-decimate"] )
1050 /* Here is where we take care of the boolean options that work overtly:
1051 no-dct-decimate being on means no-dct-decimate=1, etc. Some options
1052 require the inverse, but those will be handled a couple lines down. */
1053 if ([sender state] == 0)
1055 /* When these options are false, don't include them. They all default
1056 to being set off, so they don't need to be mentioned at all. */
1061 /* Otherwise, include them as optioname=1 */
1062 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
1066 else if ( [optName isEqualToString:@"8x8dct"] || [optName isEqualToString:@"cabac"] || [optName isEqualToString:@"weightp"] )
1068 /* These options default to being on. That means they
1069 only need to be included in the string when turned off. */
1070 if ([sender state] == 1)
1072 /* It's true so don't include it. */
1077 /* Otherwise, include cabac=0, etc, in the string. */
1078 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
1082 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
1084 /* When a widget is at index 0, it's default. Default means don't add to the string.
1085 The exception for deblocking is because for those, *both* need to at index 0
1086 for it to default, so it's handled separately, above this section. */
1090 else if ([optName isEqualToString:@"me"])
1092 /* Motion estimation uses string values, so this switch
1093 pairs the widget index with the right value string. */
1094 switch ([sender indexOfSelectedItem])
1097 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
1101 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
1105 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
1109 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
1113 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"tesa"];
1120 else if ([optName isEqualToString:@"direct"])
1122 /* Direct prediction uses string values, so this switch
1123 pairs the right string value with the right widget index. */
1124 switch ([sender indexOfSelectedItem])
1127 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1131 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
1135 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
1139 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
1147 else if ([optName isEqualToString:@"analyse"])
1149 /* Analysis uses string values as well. */
1150 switch ([sender indexOfSelectedItem])
1153 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1156 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"i4x4,i8x8"];
1159 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
1167 else if ([optName isEqualToString:@"b-pyramid"])
1169 /* B-pyramid uses string values too. */
1170 switch ([sender indexOfSelectedItem])
1173 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
1176 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"strict"];
1187 else if ([optName isEqualToString:@"merange"])
1189 /* Motion estimation range uses an odd array offset because in addition
1190 to starting with index 0 as default, index 1 starts at 4 instead of 1,
1191 because merange can't go below 4. So it has to be handled separately. */
1192 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
1195 else if ([optName isEqualToString:@"b-adapt"])
1197 /* B-adapt starts at index 0 with default then goes 0, 1, 2)*/
1198 thisOpt = [NSString stringWithFormat:@"%@=%d", optName, [sender indexOfSelectedItem]-1];
1201 else if ([optName isEqualToString:@"ref"])
1203 /* Refs use actual index numbers */
1204 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]];
1207 else // we have a valid value to change, so change it
1209 if ( [sender indexOfSelectedItem] != 0 )
1210 /* Here's our general case, that catches things like b-frames.
1211 Basically, any options that are PopUp menus with index 0 as default and
1212 index 1 as 0, with numerical values, are all handled right here. All of
1213 the above stuff is for the exceptions to the general case. */
1214 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
1220 - (BOOL) X264AdvancedOptionsIsOpt: (NSString *) optNameToChange inString: (NSString *) currentOptString
1222 /* If the option is in the string but not the beginning of it,
1223 it will be in the form of ":optName=value" so we really want
1224 to be looking for ":optNameToChange=" rather than "optNameToChange". */
1225 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
1227 /* Now we store the part of the string up through the option name in currentOptRange. */
1228 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
1230 /* We need to know if the option is at the beginning of the string.
1231 If it is at the start, it won't be preceded by a colon.
1232 To figure this out, we'll use the rangeOfString method. First,
1233 store what the option name would be if if it was at the beginning,
1234 in checkOptNameToChangeBeginning. Then, find its range in the string.
1235 If the range is 0, it's the first option listed in the string. */
1236 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
1237 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
1239 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
1246 * Resets the option string to mirror the GUI widgets.
1248 - (IBAction) X264AdvancedOptionsChanged: (id) sender
1250 /* Look up the equivalent string option name of the calling widget. */
1251 NSString * optNameToChange = [self X264AdvancedOptionsOptIDToString: sender];
1253 NSString * thisOpt = @""; // The separated option such as "bframes=3"
1254 NSString * optName = @""; // The option name such as "bframes"
1255 NSString * optValue = @""; // The option value such as "3"
1256 NSArray *currentOptsArray;
1258 /* Get the current opt string being displayed. */
1259 NSString *currentOptString = [fDisplayX264Options stringValue];
1261 /* There are going to be a few possibilities.
1262 - The option might start off the string.
1263 - The option might be in the middle of the string.
1264 - The option might not be in the string at all yet.
1265 - The string itself might not yet exist. */
1267 if( [self X264AdvancedOptionsIsOpt: optNameToChange inString: currentOptString] )
1269 /* If the option is in the string wth a semicolon, or starts the string, it's time to edit.
1270 This means parsing the whole string into an array of options and values. From there,
1271 iterate through the options, and when you reach the one that's been changed, edit it. */
1273 /* Create new empty opt string*/
1274 NSString *changedOptString = @"";
1276 /* Put individual options into an array based on the ":"
1277 separator for processing, result is "<opt>=<value>" */
1278 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
1280 /* Iterate through the array and get <opts> and <values*/
1282 int currentOptsArrayCount = [currentOptsArray count];
1283 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
1285 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
1286 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
1288 if (splitOptRange.location != NSNotFound)
1290 /* First off, it's time to handle option strings that
1291 already have at least one option=value pair in them. */
1293 optName = [thisOpt substringToIndex:splitOptRange.location];
1294 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
1296 /*If the optNameToChange is found, appropriately change the value or delete it if
1297 "Unspecified" is set.*/
1298 if ([optName isEqualToString:optNameToChange])
1300 thisOpt = [self X264AdvancedOptionsWidgetToString: optName withID: sender];
1304 /* Construct New String for opts here */
1305 if ([thisOpt isEqualToString:@""])
1307 /* Blank option, so just add it to the string. (Why?) */
1308 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
1312 if ([changedOptString isEqualToString:@""])
1314 /* No existing string, make the string this option. */
1315 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
1319 /* Existing string, existing option. Append the
1320 option to the string, preceding it with a colon. */
1321 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
1326 /* Change the dislayed option string to reflect the new modified settings */
1327 [fDisplayX264Options setStringValue:changedOptString];
1329 else // if none exists, add it to the string
1331 /* This is where options that aren't already in the string are handled. */
1332 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
1335 [fDisplayX264Options setStringValue:
1336 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender]];
1340 /* The string isn't empty, and the option isn't already in it, so
1341 it will need to be appended to the current string with a colon,
1342 as long as the string to be appended isn't just blank (default). */
1343 if( [[self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] isEqualToString: @""] == false )
1345 [fDisplayX264Options setStringValue:
1346 [NSString stringWithFormat:@"%@:%@",
1348 [self X264AdvancedOptionsWidgetToString: optNameToChange withID: sender] ]];
1353 /* We now need to reset the opt widgets since we changed some stuff */
1354 [self X264AdvancedOptionsSet:sender];