OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[handbrake-jp/handbrake-jp-git.git] / macosx / HBAdvancedController.m
1 /* HBAdvancedController
2
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. */
6     
7 #import "HBAdvancedController.h"
8
9 @implementation HBAdvancedController
10
11 - (id)init
12 {
13     [super init];
14     [self loadMyNibFile];
15     
16     return self;
17 }
18
19 - (void) setView: (NSBox *) box {
20     fOptionsBox = box;
21     [fOptionsBox setContentView:fX264optView];
22 }
23
24 - (BOOL) loadMyNibFile
25 {
26     if(![NSBundle loadNibNamed:@"AdvancedView" owner:self])
27     {
28         NSLog(@"Warning! Could not load myNib file.\n");
29         return NO;
30     }
31     
32     return YES;
33 }
34
35 - (NSString *) optionsString {
36     return [fDisplayX264Options stringValue];
37 }
38
39 - (void) setOptions: (NSString *)string {
40     [fDisplayX264Options setStringValue:string];
41     [self X264AdvancedOptionsSet:NULL];
42 }
43
44 - (void) setHidden: (BOOL) hide {
45     if(hide)
46     {
47         [fOptionsBox setContentView:fEmptyView];
48         [fX264optViewTitleLabel setStringValue: @"Only Used With The x264 (H.264) Codec"];
49     }
50     else
51     {
52         [fOptionsBox setContentView:fX264optView];
53         [fX264optViewTitleLabel setStringValue: @""];
54     }
55     return;
56 }
57
58  - (void) enableUI: (bool) b
59 {
60     unsigned i;
61     NSControl * controls[] =
62       { fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
63                 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,fX264optNfpskipLabel,fX264optNfpskipSwitch,
64                 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
65                 fX264optTrellisLabel,fX264optTrellisPopUp,fX264optMixedRefsLabel,fX264optMixedRefsSwitch,
66                 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
67                 fX264optWeightBLabel,fX264optWeightBSwitch,fX264optBRDOLabel,fX264optBRDOSwitch,
68                 fX264optBPyramidLabel,fX264optBPyramidSwitch,fX264optBiMELabel,fX264optBiMESwitch,
69                 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
70                 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
71                 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp};
72
73     for( i = 0; i < sizeof( controls ) / sizeof( NSControl * ); i++ )
74     {
75         if( [[controls[i] className] isEqualToString: @"NSTextField"] )
76         {
77             NSTextField * tf = (NSTextField *) controls[i];
78             if( ![tf isBezeled] )
79             {
80                 [tf setTextColor: b ? [NSColor controlTextColor] :
81                     [NSColor disabledControlTextColor]];
82                 continue;
83             }
84         }
85         [controls[i] setEnabled: b];
86
87     }
88 }
89
90 - (void)dealloc
91 {
92     [super dealloc];
93 }
94
95 - (IBAction) X264AdvancedOptionsSet: (id) sender
96 {
97     /*Set opt widget values here*/
98     
99     /*B-Frames fX264optBframesPopUp*/
100     int i;
101     [fX264optBframesPopUp removeAllItems];
102     [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
103     for (i=0; i<17;i++)
104     {
105         [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
106     }
107     
108     /*Reference Frames fX264optRefPopUp*/
109     [fX264optRefPopUp removeAllItems];
110     [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
111     for (i=0; i<17;i++)
112     {
113         [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
114     }
115     
116     /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
117     [fX264optNfpskipSwitch setState:0];
118     
119     /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
120     [fX264optNodctdcmtSwitch setState:0];    
121     
122     /*Sub Me fX264optSubmePopUp*/
123     [fX264optSubmePopUp removeAllItems];
124     [fX264optSubmePopUp addItemWithTitle:@"Default (4)"];
125     for (i=0; i<8;i++)
126     {
127         [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
128     }
129     
130     /*Trellis fX264optTrellisPopUp*/
131     [fX264optTrellisPopUp removeAllItems];
132     [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
133     for (i=0; i<3;i++)
134     {
135         [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
136     }
137     
138     /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
139     [fX264optMixedRefsSwitch setState:0];
140     
141     /*Motion Estimation fX264optMotionEstPopUp*/
142     [fX264optMotionEstPopUp removeAllItems];
143     [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
144     [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
145     [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
146     [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
147     [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
148     
149     /*Motion Estimation range fX264optMERangePopUp*/
150     [fX264optMERangePopUp removeAllItems];
151     [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
152     for (i=4; i<65;i++)
153     {
154         [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
155     }
156     
157     /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
158     [fX264optWeightBSwitch setState:0];
159     
160     /*B-Frame Rate Distortion Optimization fX264optBRDOSwitch BOOLEAN*/
161     [fX264optBRDOSwitch setState:0];
162     
163     /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
164     [fX264optBPyramidSwitch setState:0];
165     
166     /*Bidirectional Motion Estimation Refinement fX264optBiMESwitch BOOLEAN*/
167     [fX264optBiMESwitch setState:0];
168     
169     /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
170     [fX264optDirectPredPopUp removeAllItems];
171     [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
172     [fX264optDirectPredPopUp addItemWithTitle:@"None"];
173     [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
174     [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
175     [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
176     
177     /*Alpha Deblock*/
178     [fX264optAlphaDeblockPopUp removeAllItems];
179     [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
180     for (i=-6; i<7;i++)
181     {
182         [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
183     }
184     
185     /*Beta Deblock*/
186     [fX264optBetaDeblockPopUp removeAllItems];
187     [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
188     for (i=-6; i<7;i++)
189     {
190         [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
191     }     
192     
193     /* Analysis fX264optAnalysePopUp */
194     [fX264optAnalysePopUp removeAllItems];
195     [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
196         [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
197             [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
198                 
199                 /* 8x8 DCT fX264op8x8dctSwitch */
200                 [fX264opt8x8dctSwitch setState:0];
201                 
202                 /* CABAC fX264opCabacSwitch */
203                 [fX264optCabacSwitch setState:1];
204                 
205                 /* Standardize the option string */
206                 [self X264AdvancedOptionsStandardizeOptString: NULL];
207                 /* Set Current GUI Settings based on newly standardized string */
208                 [self X264AdvancedOptionsSetCurrentSettings: NULL];
209 }
210
211 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
212 {
213     /* Set widgets depending on the opt string in field */
214     NSString * thisOpt; // The separated option such as "bframes=3"
215     NSString * optName = @""; // The option name such as "bframes"
216     NSString * optValue = @"";// The option value such as "3"
217         NSString * changedOptString = @"";
218         NSArray *currentOptsArray;
219         
220         /*First, we get an opt string to process */
221         NSString *currentOptString = [fDisplayX264Options stringValue];
222         
223         /*verify there is an opt string to process */
224         NSRange currentOptRange = [currentOptString rangeOfString:@"="];
225         if (currentOptRange.location != NSNotFound)
226         {
227             /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
228             currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
229             
230             /*iterate through the array and get <opts> and <values*/
231             //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
232             int loopcounter;
233             int currentOptsArrayCount = [currentOptsArray count];
234             for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
235             {
236                 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
237                 
238                 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
239                 if (splitOptRange.location != NSNotFound)
240                 {
241                     optName = [thisOpt substringToIndex:splitOptRange.location];
242                     optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
243                     
244                     /* Standardize the names here depending on whats in the string */
245                     optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
246                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];    
247                 }
248                 else // No value given so we use a default of "1"
249                 {
250                     optName = thisOpt;
251                     /* Standardize the names here depending on whats in the string */
252                     optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
253                     thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
254                 }
255                 
256                 /* Construct New String for opts here */
257                 if ([thisOpt isEqualToString:@""])
258                 {
259                     changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
260                 }
261                 else
262                 {
263                     if ([changedOptString isEqualToString:@""])
264                     {
265                         changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
266                     }
267                     else
268                     {
269                         changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
270                     }
271                 }
272             }
273         }
274         
275         /* Change the option string to reflect the new standardized option string */
276         [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
277 }
278
279 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
280 {
281     if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
282     {
283         cleanOptNameString = @"ref";
284     }
285     
286     /*No Fast PSkip nofast_pskip*/
287     if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
288     {
289         cleanOptNameString = @"no-fast-pskip";
290     }
291     
292     /*No Dict Decimate*/
293     if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
294     {
295         cleanOptNameString = @"no-dct-decimate";
296     }
297     
298     /*Subme*/
299     if ([cleanOptNameString isEqualToString:@"subme"])
300     {
301         cleanOptNameString = @"subq";
302     }
303     
304     /*ME Range*/
305     if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
306         cleanOptNameString = @"merange";
307     
308     /*WeightB*/
309     if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
310     {
311         cleanOptNameString = @"weightb";
312     }
313     
314     /*BRDO*/
315     if ([cleanOptNameString isEqualToString:@"b-rdo"] || [cleanOptNameString isEqualToString:@"b_rdo"])
316     {
317         cleanOptNameString = @"brdo";
318     }
319     
320     /*B Pyramid*/
321     if ([cleanOptNameString isEqualToString:@"b_pyramid"])
322     {
323         cleanOptNameString = @"b-pyramid";
324     }
325     
326     /*Direct Prediction*/
327     if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
328     {
329         cleanOptNameString = @"direct";
330     }
331     
332     /*Deblocking*/
333     if ([cleanOptNameString isEqualToString:@"filter"])
334     {
335         cleanOptNameString = @"deblock";
336     }
337     
338     /*Analysis*/
339     if ([cleanOptNameString isEqualToString:@"partitions"])
340     {
341         cleanOptNameString = @"analyse";
342     }
343     
344     
345     return cleanOptNameString;  
346 }
347
348 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
349 {
350     /* Set widgets depending on the opt string in field */
351     NSString * thisOpt; // The separated option such as "bframes=3"
352     NSString * optName = @""; // The option name such as "bframes"
353     NSString * optValue = @"";// The option value such as "3"
354         NSArray *currentOptsArray;
355         
356         /*First, we get an opt string to process */
357         //NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
358         NSString *currentOptString = [fDisplayX264Options stringValue];
359         
360         /*verify there is an opt string to process */
361         NSRange currentOptRange = [currentOptString rangeOfString:@"="];
362         if (currentOptRange.location != NSNotFound)
363         {
364             /* lets clean the opt string here to standardize any names*/
365             /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
366             currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
367             
368             /*iterate through the array and get <opts> and <values*/
369             //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
370             int loopcounter;
371             int currentOptsArrayCount = [currentOptsArray count];
372             
373             /*iterate through the array and get <opts> and <values*/
374             for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
375             {
376                 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
377                 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
378                 
379                 if (splitOptRange.location != NSNotFound)
380                 {
381                     optName = [thisOpt substringToIndex:splitOptRange.location];
382                     optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
383                     
384                     /*Run through the available widgets for x264 opts and set them, as you add widgets, 
385                         they need to be added here. This should be moved to its own method probably*/
386                     
387                     /*bframes NSPopUpButton*/
388                     if ([optName isEqualToString:@"bframes"])
389                     {
390                         [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
391                     }
392                     /*ref NSPopUpButton*/
393                     if ([optName isEqualToString:@"ref"])
394                     {
395                         [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
396                     }
397                     /*No Fast PSkip NSPopUpButton*/
398                     if ([optName isEqualToString:@"no-fast-pskip"])
399                     {
400                         [fX264optNfpskipSwitch setState:[optValue intValue]];
401                     }
402                     /*No Dict Decimate NSPopUpButton*/
403                     if ([optName isEqualToString:@"no-dct-decimate"])
404                     {
405                         [fX264optNodctdcmtSwitch setState:[optValue intValue]];
406                     }
407                     /*Sub Me NSPopUpButton*/
408                     if ([optName isEqualToString:@"subq"])
409                     {
410                         [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
411                     }
412                     /*Trellis NSPopUpButton*/
413                     if ([optName isEqualToString:@"trellis"])
414                     {
415                         [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
416                     }
417                     /*Mixed Refs NSButton*/
418                     if ([optName isEqualToString:@"mixed-refs"])
419                     {
420                         [fX264optMixedRefsSwitch setState:[optValue intValue]];
421                     }
422                     /*Motion Estimation NSPopUpButton*/
423                     if ([optName isEqualToString:@"me"])
424                     {
425                         if ([optValue isEqualToString:@"dia"])
426                             [fX264optMotionEstPopUp selectItemAtIndex:1];
427                         else if ([optValue isEqualToString:@"hex"])
428                             [fX264optMotionEstPopUp selectItemAtIndex:2];
429                         else if ([optValue isEqualToString:@"umh"])
430                             [fX264optMotionEstPopUp selectItemAtIndex:3];
431                         else if ([optValue isEqualToString:@"esa"])
432                             [fX264optMotionEstPopUp selectItemAtIndex:4];                        
433                     }
434                     /*ME Range NSPopUpButton*/
435                     if ([optName isEqualToString:@"merange"])
436                     {
437                         [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
438                     }
439                     /*Weighted B-Frames NSPopUpButton*/
440                     if ([optName isEqualToString:@"weightb"])
441                     {
442                         [fX264optWeightBSwitch setState:[optValue intValue]];
443                     }
444                     /*BRDO NSPopUpButton*/
445                     if ([optName isEqualToString:@"brdo"])
446                     {
447                         [fX264optBRDOSwitch setState:[optValue intValue]];
448                     }
449                     /*B Pyramid NSPopUpButton*/
450                     if ([optName isEqualToString:@"b-pyramid"])
451                     {
452                         [fX264optBPyramidSwitch setState:[optValue intValue]];
453                     }
454                     /*Bidirectional Motion Estimation Refinement NSPopUpButton*/
455                     if ([optName isEqualToString:@"bime"])
456                     {
457                         [fX264optBiMESwitch setState:[optValue intValue]];
458                     }
459                     /*Direct B-frame Prediction NSPopUpButton*/
460                     if ([optName isEqualToString:@"direct"])
461                     {
462                         if ([optValue isEqualToString:@"none"])
463                             [fX264optDirectPredPopUp selectItemAtIndex:1];
464                         else if ([optValue isEqualToString:@"spatial"])
465                             [fX264optDirectPredPopUp selectItemAtIndex:2];
466                         else if ([optValue isEqualToString:@"temporal"])
467                             [fX264optDirectPredPopUp selectItemAtIndex:3];
468                         else if ([optValue isEqualToString:@"auto"])
469                             [fX264optDirectPredPopUp selectItemAtIndex:4];                        
470                     }
471                     /*Deblocking NSPopUpButtons*/
472                     if ([optName isEqualToString:@"deblock"])
473                     {
474                         NSString * alphaDeblock = @"";
475                         NSString * betaDeblock = @"";
476                         
477                         NSRange splitDeblock = [optValue rangeOfString:@","];
478                         alphaDeblock = [optValue substringToIndex:splitDeblock.location];
479                         betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
480                         
481                         if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
482                         {
483                             [fX264optAlphaDeblockPopUp selectItemAtIndex:0];                        
484                             [fX264optBetaDeblockPopUp selectItemAtIndex:0];                               
485                         }
486                         else
487                         {
488                             if (![alphaDeblock isEqualToString:@"0"])
489                             {
490                                 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
491                             }
492                             else
493                             {
494                                 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];                        
495                             }
496                             
497                             if (![betaDeblock isEqualToString:@"0"])
498                             {
499                                 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
500                             }
501                             else
502                             {
503                                 [fX264optBetaDeblockPopUp selectItemAtIndex:7];                        
504                             }
505                         }
506                     }
507                     /* Analysis NSPopUpButton */
508                     if ([optName isEqualToString:@"analyse"])
509                     {
510                         if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
511                         {
512                             [fX264optAnalysePopUp selectItemAtIndex:0];
513                         }
514                         if ([optValue isEqualToString:@"none"])
515                         {
516                             [fX264optAnalysePopUp selectItemAtIndex:1];
517                         }
518                         if ([optValue isEqualToString:@"all"])
519                         {
520                             [fX264optAnalysePopUp selectItemAtIndex:2];
521                         }
522                     }
523                     /* 8x8 DCT NSButton */
524                     if ([optName isEqualToString:@"8x8dct"])
525                     {
526                         [fX264opt8x8dctSwitch setState:[optValue intValue]];
527                     }
528                     /* CABAC NSButton */
529                     if ([optName isEqualToString:@"cabac"])
530                     {
531                         [fX264optCabacSwitch setState:[optValue intValue]];
532                     }                                                                 
533                 }
534             }
535         }
536 }
537
538 - (IBAction) X264AdvancedOptionsChanged: (id) sender
539 {
540     /*Determine which outlet is being used and set optName to process accordingly */
541     NSString * optNameToChange = @""; // The option name such as "bframes"
542     
543     if (sender == fX264optBframesPopUp)
544     {
545         optNameToChange = @"bframes";
546     }
547     if (sender == fX264optRefPopUp)
548     {
549         optNameToChange = @"ref";
550     }
551     if (sender == fX264optNfpskipSwitch)
552     {
553         optNameToChange = @"no-fast-pskip";
554     }
555     if (sender == fX264optNodctdcmtSwitch)
556     {
557         optNameToChange = @"no-dct-decimate";
558     }
559     if (sender == fX264optSubmePopUp)
560     {
561         optNameToChange = @"subq";
562     }
563     if (sender == fX264optTrellisPopUp)
564     {
565         optNameToChange = @"trellis";
566     }
567     if (sender == fX264optMixedRefsSwitch)
568     {
569         optNameToChange = @"mixed-refs";
570     }
571     if (sender == fX264optMotionEstPopUp)
572     {
573         optNameToChange = @"me";
574     }
575     if (sender == fX264optMERangePopUp)
576     {
577         optNameToChange = @"merange";
578     }
579     if (sender == fX264optWeightBSwitch)
580     {
581         optNameToChange = @"weightb";
582     }
583     if (sender == fX264optBRDOSwitch)
584     {
585         optNameToChange = @"brdo";
586     }
587     if (sender == fX264optBPyramidSwitch)
588     {
589         optNameToChange = @"b-pyramid";
590     }
591     if (sender == fX264optBiMESwitch)
592     {
593         optNameToChange = @"bime";
594     }
595     if (sender == fX264optDirectPredPopUp)
596     {
597         optNameToChange = @"direct";
598     }
599     if (sender == fX264optAlphaDeblockPopUp)
600     {
601         optNameToChange = @"deblock";
602     }
603     if (sender == fX264optBetaDeblockPopUp)
604     {
605         optNameToChange = @"deblock";
606     }        
607     if (sender == fX264optAnalysePopUp)
608     {
609         optNameToChange = @"analyse";
610     }
611     if (sender == fX264opt8x8dctSwitch)
612     {
613         optNameToChange = @"8x8dct";
614     }
615     if (sender == fX264optCabacSwitch)
616     {
617         optNameToChange = @"cabac";
618     }
619     
620     /* Set widgets depending on the opt string in field */
621     NSString * thisOpt; // The separated option such as "bframes=3"
622     NSString * optName = @""; // The option name such as "bframes"
623     NSString * optValue = @"";// The option value such as "3"
624         NSArray *currentOptsArray;
625         
626         /*First, we get an opt string to process */
627         //EXAMPLE: NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
628         NSString *currentOptString = [fDisplayX264Options stringValue];
629         
630         /*verify there is an occurrence of the opt specified by the sender to change */
631         /*take care of any multi-value opt names here. This is extremely kludgy, but test for functionality
632             and worry about pretty later */
633         
634         /*First, we create a pattern to check for ":"optNameToChange"=" to modify the option if the name falls after
635             the first character of the opt string (hence the ":") */
636         NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
637         NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
638         /*Then we create a pattern to check for "<beginning of line>"optNameToChange"=" to modify the option to
639             see if the name falls at the beginning of the line, where we would not have the ":" as a pattern to test against*/
640         NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
641         NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
642         if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
643         {
644             /* Create new empty opt string*/
645             NSString *changedOptString = @"";
646             
647             /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
648             currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
649             
650             /*iterate through the array and get <opts> and <values*/
651             int loopcounter;
652             int currentOptsArrayCount = [currentOptsArray count];
653             for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
654             {
655                 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
656                 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
657                 
658                 if (splitOptRange.location != NSNotFound)
659                 {
660                     optName = [thisOpt substringToIndex:splitOptRange.location];
661                     optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
662                     
663                     /*Run through the available widgets for x264 opts and set them, as you add widgets, 
664                         they need to be added here. This should be moved to its own method probably*/
665                     
666                     /*If the optNameToChange is found, appropriately change the value or delete it if
667                         "Unspecified" is set.*/
668                     if ([optName isEqualToString:optNameToChange])
669                     {
670                         if ([optNameToChange isEqualToString:@"deblock"])
671                         {
672                             if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
673                             {
674                                 thisOpt = @"";                                
675                             }
676                             else
677                             {
678                                 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
679                             }
680                         }
681                         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"] )
682                         {
683                             if ([sender state] == 0)
684                             {
685                                 thisOpt = @"";
686                             }
687                             else
688                             {
689                                 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
690                             }
691                         }
692                         else if ([optNameToChange isEqualToString:@"cabac"])
693                         {
694                             if ([sender state] == 1)
695                             {
696                                 thisOpt = @"";
697                             }
698                             else
699                             {
700                                 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
701                             }
702                         }                                        
703                         else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
704                         {
705                             thisOpt = @"";
706                         }
707                         else if ([optNameToChange isEqualToString:@"me"])
708                         {
709                             switch ([sender indexOfSelectedItem])
710                             {   
711                                 case 1:
712                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
713                                     break;
714                                     
715                                 case 2:
716                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
717                                     break;
718                                     
719                                 case 3:
720                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
721                                     break;
722                                     
723                                 case 4:
724                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
725                                     break;
726                                     
727                                 default:
728                                     break;
729                             }
730                         }
731                         else if ([optNameToChange isEqualToString:@"direct"])
732                         {
733                             switch ([sender indexOfSelectedItem])
734                             {   
735                                 case 1:
736                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
737                                     break;
738                                     
739                                 case 2:
740                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
741                                     break;
742                                     
743                                 case 3:
744                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
745                                     break;
746                                     
747                                 case 4:
748                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
749                                     break;
750                                     
751                                 default:
752                                     break;
753                             }
754                         }
755                         else if ([optNameToChange isEqualToString:@"analyse"])
756                         {
757                             switch ([sender indexOfSelectedItem])
758                             {   
759                                 case 1:
760                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
761                                     break;
762                                     
763                                 case 2:
764                                     thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
765                                     break;
766                                     
767                                 default:
768                                     break;
769                             }
770                         }
771                         else if ([optNameToChange isEqualToString:@"merange"])
772                         {
773                             thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
774                         }
775                         else // we have a valid value to change, so change it
776                         {
777                             thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
778                         }
779                     }
780                 }
781                 
782                 /* Construct New String for opts here */
783                 if ([thisOpt isEqualToString:@""])
784                 {
785                     changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
786                 }
787                 else
788                 {
789                     if ([changedOptString isEqualToString:@""])
790                     {
791                         changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
792                     }
793                     else
794                     {
795                         changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
796                     }
797                 }
798             }
799             
800             /* Change the option string to reflect the new mod settings */
801             [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];  
802         }
803         else // if none exists, add it to the string
804         {
805             if ([[fDisplayX264Options stringValue] isEqualToString: @""])
806             {
807                 if ([optNameToChange isEqualToString:@"me"])
808                 {
809                     switch ([sender indexOfSelectedItem])
810                     {   
811                         case 1:
812                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
813                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
814                             break;
815                             
816                         case 2:
817                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
818                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
819                             break;
820                             
821                         case 3:
822                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
823                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
824                             break;
825                             
826                         case 4:
827                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
828                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
829                             break;
830                             
831                         default:
832                             break;
833                     }
834                 }
835                 else if ([optNameToChange isEqualToString:@"direct"])
836                 {
837                     switch ([sender indexOfSelectedItem])
838                     {   
839                         case 1:
840                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
841                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
842                             break;
843                             
844                         case 2:
845                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
846                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
847                             break;
848                             
849                         case 3:
850                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
851                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
852                             break;
853                             
854                         case 4:
855                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
856                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
857                             break;
858                             
859                         default:
860                             break;
861                     }
862                 }
863                 else if ([optNameToChange isEqualToString:@"analyse"])
864                 {
865                     switch ([sender indexOfSelectedItem])
866                     {   
867                         case 1:
868                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
869                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
870                             break;
871                             
872                         case 2:
873                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
874                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
875                             break;
876                             
877                         default:
878                             break;
879                     }
880                 }
881                 
882                 else if ([optNameToChange isEqualToString:@"merange"])
883                 {
884                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
885                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
886                 }
887                 else if ([optNameToChange isEqualToString:@"deblock"])
888                 {
889                     [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]]];                
890                 }
891                 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"] )            {
892                     if ([sender state] == 0)
893                     {
894                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];                    
895                     }
896                     else
897                     {
898                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
899                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
900                     }
901                 }
902                 else if ([optNameToChange isEqualToString:@"cabac"])
903                 {
904                     if ([sender state] == 1)
905                     {
906                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];                                        
907                     }
908                     else
909                     {
910                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
911                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];                    
912                     }
913                 }            
914                 else
915                 {
916                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
917                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
918                 }
919             }
920             else
921             {
922                 if ([optNameToChange isEqualToString:@"me"])
923                 {
924                     switch ([sender indexOfSelectedItem])
925                     {   
926                         case 1:
927                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
928                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
929                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
930                             break;
931                             
932                         case 2:
933                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
934                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
935                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
936                             break;
937                             
938                         case 3:
939                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
940                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
941                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
942                             break;
943                             
944                         case 4:
945                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
946                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
947                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
948                             break;
949                             
950                         default:
951                             break;
952                     }
953                 }
954                 else if ([optNameToChange isEqualToString:@"direct"])
955                 {
956                     switch ([sender indexOfSelectedItem])
957                     {   
958                         case 1:
959                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
960                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
961                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
962                             break;
963                             
964                         case 2:
965                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
966                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
967                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
968                             break;
969                             
970                         case 3:
971                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
972                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
973                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
974                             break;
975                             
976                         case 4:
977                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
978                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
979                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
980                             break;
981                             
982                         default:
983                             break;
984                     }
985                 }
986                 else if ([optNameToChange isEqualToString:@"analyse"])
987                 {
988                     switch ([sender indexOfSelectedItem])
989                     {   
990                         case 1:
991                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
992                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
993                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
994                             break;
995                             
996                         case 2:
997                             [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
998                                 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
999                                 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
1000                             break;
1001                             
1002                         default:
1003                             break;
1004                     }
1005                 }
1006                 
1007                 else if ([optNameToChange isEqualToString:@"merange"])
1008                 {
1009                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
1010                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
1011                 }
1012                 else if ([optNameToChange isEqualToString:@"deblock"])
1013                 {
1014                     [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]]];                
1015                 }
1016                 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"] )
1017                 {
1018                     if ([sender state] == 0)
1019                     {
1020                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];                    
1021                     }
1022                     else
1023                     {
1024                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
1025                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];                
1026                     }
1027                 }
1028                 else if ([optNameToChange isEqualToString:@"cabac"])
1029                 {
1030                     if ([sender state] == 1)
1031                     {
1032                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];                    
1033                     }
1034                     else
1035                     {
1036                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
1037                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
1038                     }
1039                 }
1040                 else
1041                 {
1042                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
1043                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
1044                 }
1045             }
1046         }
1047         
1048         /* We now need to reset the opt widgets since we changed some stuff */          
1049         [self X264AdvancedOptionsSet:NULL];             
1050 }
1051
1052 @end