Moves the filters' logging info to work.c, adds parameter info. I also changed the...
[HandBrake.git] / macosx / Controller.mm
blobfc1ce3737108f211faedd375b7031ba6f402bee7
1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.m0k.org/>.
5    It may be used under the terms of the GNU General Public License. */
7 #include "Controller.h"
8 #include "a52dec/a52.h"
9 #import "HBOutputPanelController.h"
10 #import "HBPreferencesController.h"
12 #define _(a) NSLocalizedString(a,NULL)
14 static int FormatSettings[4][10] =
15   { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
16           HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
17           0,
18           0},
19     { HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
20           HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
21           HB_MUX_AVI | HB_VCODEC_X264   | HB_ACODEC_LAME,
22           HB_MUX_AVI | HB_VCODEC_X264   | HB_ACODEC_AC3},
23     { HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
24           HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
25           0,
26           0 },
27     { HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
28           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
29           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
30           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
31           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_FAAC,
32           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_AC3,
33           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_LAME,
34           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_VORBIS,
35           0,
36           0 } };
38 /* We setup the toolbar values here */
39 static NSString*       MyDocToolbarIdentifier          = @"My Document Toolbar Identifier";
40 static NSString*       ToggleDrawerIdentifier  = @"Toggle Drawer Item Identifier";
41 static NSString*       StartEncodingIdentifier         = @"Start Encoding Item Identifier";
42 static NSString*       PauseEncodingIdentifier         = @"Pause Encoding Item Identifier";
43 static NSString*       ShowQueueIdentifier     = @"Show Queue Item Identifier";
44 static NSString*       AddToQueueIdentifier    = @"Add to Queue Item Identifier";
45 static NSString*       DebugOutputIdentifier   = @"Debug Output Item Identifier";
46 static NSString*       ChooseSourceIdentifier   = @"Choose Source Item Identifier";
48 /*******************************
49  * HBController implementation *
50  *******************************/
51 @implementation HBController
53 - init
55     self = [super init];
56     [HBPreferencesController registerUserDefaults];
57     fHandle = NULL;
58     outputPanel = [[HBOutputPanelController alloc] init];
59     return self;
62 - (void) applicationDidFinishLaunching: (NSNotification *) notification
64     int    build;
65     char * version;
67     // Open debug output window now if it was visible when HB was closed
68     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
69         [self showDebugOutputPanel:nil];
71     // Init libhb
72         int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
73     fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
75         // Set the Growl Delegate
76         HBController *hbGrowlDelegate = [[HBController alloc] init];
77         [GrowlApplicationBridge setGrowlDelegate: hbGrowlDelegate];    
78     /* Init others controllers */
79     [fScanController    SetHandle: fHandle];
80     [fPictureController SetHandle: fHandle];
81     [fQueueController   SetHandle: fHandle];
82         
83     fChapterTitlesDelegate = [[ChapterTitles alloc] init];
84     [fChapterTable setDataSource:fChapterTitlesDelegate];
86      /* Call UpdateUI every 2/10 sec */
87     [[NSRunLoop currentRunLoop] addTimer: [NSTimer
88         scheduledTimerWithTimeInterval: 0.2 target: self
89         selector: @selector( UpdateUI: ) userInfo: NULL repeats: FALSE]
90         forMode: NSModalPanelRunLoopMode];
92     if( ( build = hb_check_update( fHandle, &version ) ) > -1 )
93     {
94         /* Update available - tell the user */
95         
96         NSBeginInformationalAlertSheet( _( @"Update is available" ),
97             _( @"Go get it!" ), _( @"Discard" ), NULL, fWindow, self,
98             @selector( UpdateAlertDone:returnCode:contextInfo: ),
99             NULL, NULL, [NSString stringWithFormat:
100             _( @"HandBrake %s (build %d) is now available for download." ),
101             version, build] );
102         return;
104     }
106     /* Show scan panel ASAP */
107     [self performSelectorOnMainThread: @selector(ShowScanPanel:)
108         withObject: NULL waitUntilDone: NO];
111 - (NSApplicationTerminateReply) applicationShouldTerminate:
112     (NSApplication *) app
114     if( [[fRipButton title] isEqualToString: _( @"Cancel" )] )
115     {
116         [self Cancel: NULL];
117         return NSTerminateCancel;
118     }    
119     return NSTerminateNow;
122 - (void)applicationWillTerminate:(NSNotification *)aNotification
124         [outputPanel release];
125         hb_close(&fHandle);
129 - (void) awakeFromNib
131     [fWindow center];
132         
133     [self TranslateStrings];
134     /* Initialize currentScanCount so HB can use it to
135                 evaluate successive scans */
136         currentScanCount = 0;
137         
138     /* Init User Presets .plist */
139         /* We declare the default NSFileManager into fileManager */
140         NSFileManager * fileManager = [NSFileManager defaultManager];
141         //presetPrefs = [[NSUserDefaults standardUserDefaults] retain];
142         /* we set the files and support paths here */
143         AppSupportDirectory = @"~/Library/Application Support/HandBrake";
144     AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath];
145     
146         UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
147     UserPresetsFile = [UserPresetsFile stringByExpandingTildeInPath];
148         
149         x264ProfilesFile = @"~/Library/Application Support/HandBrake/x264Profiles.plist";
150     x264ProfilesFile = [x264ProfilesFile stringByExpandingTildeInPath];
151         /* We check for the app support directory for media fork */
152         if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0) 
153         {
154                 // If it doesnt exist yet, we create it here 
155                 [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil];
156         }
157         // We check for the presets.plist here
158         
159         if ([fileManager fileExistsAtPath:UserPresetsFile] == 0) 
160         {
161                 
162                 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
163                 
164         }
165         // We check for the x264profiles.plist here
166         
167         if ([fileManager fileExistsAtPath:x264ProfilesFile] == 0) 
168         {
169         
170                 [fileManager createFileAtPath:x264ProfilesFile contents:nil attributes:nil];
171         }
172     
173         
174         UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
175         UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
176         
177         UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
178         if (nil == UserPresets) 
179         {
180                 UserPresets = [[NSMutableArray alloc] init];
181                 [self AddFactoryPresets:NULL];
182         }
183         
184         
185         
186         /* Show/Dont Show Presets drawer upon launch based
187                 on user preference DefaultPresetsDrawerShow*/
188         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
189         {
190                 [fPresetDrawer open];
191         }
192         
193         
194         
195     /* Destination box*/
196     [fDstFormatPopUp removeAllItems];
197     [fDstFormatPopUp addItemWithTitle: _( @"MP4 file" )];
198     [fDstFormatPopUp addItemWithTitle: _( @"AVI file" )];
199     [fDstFormatPopUp addItemWithTitle: _( @"OGM file" )];
200         [fDstFormatPopUp addItemWithTitle: _( @"MKV file" )];
201     [fDstFormatPopUp selectItemAtIndex: 0];
202         
203     [self FormatPopUpChanged: NULL];
204     
205         /* We enable the create chapters checkbox here since we are .mp4 */     
206         [fCreateChapterMarkers setEnabled: YES];
207         if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
208         {
209                 [fCreateChapterMarkers setState: NSOnState];
210         }
211         
212         
213         
214         
215     [fDstFile2Field setStringValue: [NSString stringWithFormat:
216         @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
217         
218     /* Video encoder */
219     [fVidEncoderPopUp removeAllItems];
220     [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
221     [fVidEncoderPopUp addItemWithTitle: @"XviD"];
222         
223     
224         
225     /* Video quality */
226     [fVidTargetSizeField setIntValue: 700];
227         [fVidBitrateField    setIntValue: 1000];
228         
229     [fVidQualityMatrix   selectCell: fVidBitrateCell];
230     [self VideoMatrixChanged: NULL];
231         
232     /* Video framerate */
233     [fVidRatePopUp removeAllItems];
234         [fVidRatePopUp addItemWithTitle: _( @"Same as source" )];
235     for( int i = 0; i < hb_video_rates_count; i++ )
236     {
237         if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
238                 {
239                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
240                                 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
241                 }
242                 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
243                 {
244                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
245                                 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
246                 }
247                 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
248                 {
249                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
250                                 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
251                 }
252                 else
253                 {
254                         [fVidRatePopUp addItemWithTitle:
255                                 [NSString stringWithCString: hb_video_rates[i].string]];
256                 }
257     }
258     [fVidRatePopUp selectItemAtIndex: 0];
259         
260         /* Picture Settings */
261         [fPicLabelPAROutp setStringValue: @""];
262         [fPicLabelPAROutputX setStringValue: @""];
263         [fPicSettingPARWidth setStringValue: @""];
264         [fPicSettingPARHeight setStringValue:  @""];
265         
266         /*Set detelecine to Off upon launch */
267         [fPicSettingDetelecine setStringValue: @"No"];
268         [fPicSettingDenoise setStringValue: @"0"];
269         
270         /* Audio bitrate */
271     [fAudBitratePopUp removeAllItems];
272     for( int i = 0; i < hb_audio_bitrates_count; i++ )
273     {
274         [fAudBitratePopUp addItemWithTitle:
275                                 [NSString stringWithCString: hb_audio_bitrates[i].string]];
277     }
278     [fAudBitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
279         
280     /* Audio samplerate */
281     [fAudRatePopUp removeAllItems];
282     for( int i = 0; i < hb_audio_rates_count; i++ )
283     {
284         [fAudRatePopUp addItemWithTitle:
285             [NSString stringWithCString: hb_audio_rates[i].string]];
286     }
287     [fAudRatePopUp selectItemAtIndex: hb_audio_rates_default];
288         
289     /* Bottom */
290     [fStatusField setStringValue: @""];
291         
292     [self EnableUI: NO];
293     /* Use new Toolbar start and pause here */
294         startButtonEnabled = NO;
295         stopOrStart = NO;
296         AddToQueueButtonEnabled = NO;
297         pauseButtonEnabled = NO;
298         resumeOrPause = NO;
299         [self setupToolbar];
300         
301         [fPresetsActionButton setMenu:fPresetsActionMenu];
302         
303         /* We disable the Turbo 1st pass checkbox since we are not x264 */
304         [fVidTurboPassCheck setEnabled: NO];
305         [fVidTurboPassCheck setState: NSOffState];
306         
307         
308         /* lets get our default prefs here */
309         [self GetDefaultPresets: NULL];
310         /* lets initialize the current successful scancount here to 0 */
311         currentSuccessfulScanCount = 0;
312         
316 // ============================================================
317 // NSToolbar Related Methods
318 // ============================================================
320 - (void) setupToolbar {
321     // Create a new toolbar instance, and attach it to our document window 
322     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: MyDocToolbarIdentifier] autorelease];
323     
324     // Set up toolbar properties: Allow customization, give a default display mode, and remember state in user defaults 
325     [toolbar setAllowsUserCustomization: YES];
326     [toolbar setAutosavesConfiguration: YES];
327     [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
328     
329     // We are the delegate
330     [toolbar setDelegate: self];
331     
332     // Attach the toolbar to the document window 
333     [fWindow setToolbar: toolbar];
336 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
337     // Required delegate method:  Given an item identifier, this method returns an item 
338     // The toolbar will use this method to obtain toolbar items that can be displayed in the customization sheet, or in the toolbar itself 
339     NSToolbarItem *toolbarItem = nil;
340     
341     if ([itemIdent isEqual: ToggleDrawerIdentifier]) {
342         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
343                 
344         // Set the text label to be displayed in the toolbar and customization palette 
345                 [toolbarItem setLabel: @"Toggle Presets"];
346                 [toolbarItem setPaletteLabel: @"Toggler Presets"];
347                 
348                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
349                 [toolbarItem setToolTip: @"Open/Close Preset Drawer"];
350                 [toolbarItem setImage: [NSImage imageNamed: @"Drawer-List2"]];
351                 
352                 // Tell the item what message to send when it is clicked 
353                 [toolbarItem setTarget: self];
354                 [toolbarItem setAction: @selector(toggleDrawer)];
355                 
356         } else if ([itemIdent isEqual: StartEncodingIdentifier]) {
357         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
358                 
359         // Set the text label to be displayed in the toolbar and customization palette 
360                 [toolbarItem setLabel: @"Start"];
361                 [toolbarItem setPaletteLabel: @"Start Encoding"];
362                 
363                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
364                 [toolbarItem setToolTip: @"Start Encoding"];
365                 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
366                 
367                 // Tell the item what message to send when it is clicked 
368                 [toolbarItem setTarget: self];
369                 [toolbarItem setAction: @selector(Rip:)];
370                 
371                 
372                 
373         } else if ([itemIdent isEqual: ShowQueueIdentifier]) {
374         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
375                 
376         // Set the text label to be displayed in the toolbar and customization palette 
377                 [toolbarItem setLabel: @"Show Queue"];
378                 [toolbarItem setPaletteLabel: @"Show Queue"];
379                 
380                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
381                 [toolbarItem setToolTip: @"Show Queue"];
382                 [toolbarItem setImage: [NSImage imageNamed: @"Brushed Window"]];
383                 
384                 // Tell the item what message to send when it is clicked 
385                 [toolbarItem setTarget: self];
386                 [toolbarItem setAction: @selector(ShowQueuePanel:)];
387                 
388         } else if ([itemIdent isEqual: AddToQueueIdentifier]) {
389         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
390                 
391         // Set the text label to be displayed in the toolbar and customization palette 
392                 [toolbarItem setLabel: @"Add to Queue"];
393                 [toolbarItem setPaletteLabel: @"Add to Queue"];
394                 
395                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
396                 [toolbarItem setToolTip: @"Add to Queue"];
397                 [toolbarItem setImage: [NSImage imageNamed: @"Add"]];
398                 
399                 // Tell the item what message to send when it is clicked 
400                 [toolbarItem setTarget: self];
401                 [toolbarItem setAction: @selector(AddToQueue:)];
402                 
403                 
404         } else if ([itemIdent isEqual: PauseEncodingIdentifier]) {
405         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
406                 
407         // Set the text label to be displayed in the toolbar and customization palette 
408                 [toolbarItem setLabel: @"Pause"];
409                 [toolbarItem setPaletteLabel: @"Pause Encoding"];
410                 
411                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
412                 [toolbarItem setToolTip: @"Pause Encoding"];
413                 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
414                 
415                 // Tell the item what message to send when it is clicked 
416                 [toolbarItem setTarget: self];
417                 [toolbarItem setAction: @selector(Pause:)];
418                 
419         } else if ([itemIdent isEqual: DebugOutputIdentifier]) {
420         toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
421                 
422         // Set the text label to be displayed in the toolbar and customization palette 
423                 [toolbarItem setLabel: @"Activity Window"];
424                 [toolbarItem setPaletteLabel: @"Show Activity Window"];
425                 
426                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
427                 [toolbarItem setToolTip: @"Show Activity Window"];
428                 [toolbarItem setImage: [NSImage imageNamed: @"Terminal"]];
429                 
430                 // Tell the item what message to send when it is clicked 
431                 [toolbarItem setTarget: self];
432                 [toolbarItem setAction: @selector(showDebugOutputPanel:)];
433         
434                 } else if ([itemIdent isEqual: ChooseSourceIdentifier]) {
435          toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
437          // Set the text label to be displayed in the toolbar and customization palette 
438                 [toolbarItem setLabel: @"Source"];
439                 [toolbarItem setPaletteLabel: @"Source"];
441                 // Set up a reasonable tooltip, and image   Note, these aren't localized, but you will likely want to localize many of the item's properties 
442                 [toolbarItem setToolTip: @"Choose Video Source"];
443                 [toolbarItem setImage: [NSImage imageNamed: @"Disc"]];
445                 // Tell the item what message to send when it is clicked 
446                 [toolbarItem setTarget: self];
447                 [toolbarItem setAction: @selector(ShowScanPanel:)];
448         
449     } else {
450         //itemIdent refered to a toolbar item that is not provide or supported by us or cocoa 
451         //Returning nil will inform the toolbar this kind of item is not supported 
452                 toolbarItem = nil;
453     }
454         
455     return toolbarItem;
458 - (void) toggleDrawer {
459     [fPresetDrawer toggle:self];
462 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
463     // Required delegate method:  Returns the ordered list of items to be shown in the toolbar by default    
464     // If during the toolbar's initialization, no overriding values are found in the user defaults, or if the
465     // user chooses to revert to the default items this set will be used 
466     return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier, PauseEncodingIdentifier,
467                 AddToQueueIdentifier, ShowQueueIdentifier,
468                 NSToolbarFlexibleSpaceItemIdentifier, 
469                 NSToolbarSpaceItemIdentifier, DebugOutputIdentifier, ToggleDrawerIdentifier, nil];
472 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
473     // Required delegate method:  Returns the list of all allowed items by identifier.  By default, the toolbar 
474     // does not assume any items are allowed, even the separator.  So, every allowed item must be explicitly listed   
475     // The set of allowed items is used to construct the customization palette 
476     return [NSArray arrayWithObjects:  StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier,
477                 DebugOutputIdentifier, NSToolbarCustomizeToolbarItemIdentifier,
478                 NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier, NSToolbarSpaceItemIdentifier, ChooseSourceIdentifier,
479                 NSToolbarSeparatorItemIdentifier,ToggleDrawerIdentifier, nil];
482 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem {
483     // Optional method:  This message is sent to us since we are the target of some toolbar item actions 
484     BOOL enable = NO;
485     if ([[toolbarItem itemIdentifier] isEqual: ToggleDrawerIdentifier]) {
486                 enable = YES;
487         }
488         if ([[toolbarItem itemIdentifier] isEqual: StartEncodingIdentifier]) {
489                 enable = startButtonEnabled;
490                 if(stopOrStart) {
491                         [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
492                         [toolbarItem setLabel: @"Cancel"];
493                         [toolbarItem setPaletteLabel: @"Cancel"];
494                         [toolbarItem setToolTip: @"Cancel Encoding"];
495                 }
496                 else {
497                         [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
498                         [toolbarItem setLabel: @"Start"];
499                         [toolbarItem setPaletteLabel: @"Start Encoding"];
500                         [toolbarItem setToolTip: @"Start Encoding"];
501                 }
502                 
503         }
504         if ([[toolbarItem itemIdentifier] isEqual: PauseEncodingIdentifier]) {
505                 enable = pauseButtonEnabled;
506                 if(resumeOrPause) {
507                         [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
508                         [toolbarItem setLabel: @"Resume"];
509                         [toolbarItem setPaletteLabel: @"Resume Encoding"];
510                         [toolbarItem setToolTip: @"Resume Encoding"];
511                 }
512                 else {
513                         [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
514                         [toolbarItem setLabel: @"Pause"];
515                         [toolbarItem setPaletteLabel: @"Pause Encoding"];
516                         [toolbarItem setToolTip: @"Pause Encoding"];
517                 }
518         }
519         if ([[toolbarItem itemIdentifier] isEqual: DebugOutputIdentifier]) {
520                 enable = YES;
521         }
522         if ([[toolbarItem itemIdentifier] isEqual: ShowQueueIdentifier]) {
523                 enable = YES;
524         }
525         if ([[toolbarItem itemIdentifier] isEqual: AddToQueueIdentifier]) {
526                 enable = AddToQueueButtonEnabled;
527         }
528         if ([[toolbarItem itemIdentifier] isEqual: ChooseSourceIdentifier]) {
529         enable = YES;
530     }    
531         return enable;
534 // register a test notification and make
535 // it enabled by default
536 #define SERVICE_NAME @"Encode Done"
537 - (NSDictionary *)registrationDictionaryForGrowl 
539 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys: 
540 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL, 
541 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT, 
542 nil]; 
544 return registrationDictionary; 
546 - (void) TranslateStrings
548     [fSrcDVD1Field      setStringValue: _( @"DVD:" )];
549     [fSrcTitleField     setStringValue: _( @"Title:" )];
550     [fSrcChapterField   setStringValue: _( @"Chapters:" )];
551     [fSrcChapterToField setStringValue: _( @"to" )];
552     [fSrcDuration1Field setStringValue: _( @"Duration:" )];
554     [fDstFormatField    setStringValue: _( @"File format:" )];
555     [fDstCodecsField    setStringValue: _( @"Codecs:" )];
556     [fDstFile1Field     setStringValue: _( @"File:" )];
557     [fDstBrowseButton   setTitle:       _( @"Browse" )];
559     [fVidRateField      setStringValue: _( @"Framerate (fps):" )];
560     [fVidEncoderField   setStringValue: _( @"Encoder:" )];
561     [fVidQualityField   setStringValue: _( @"Quality:" )];
564 /***********************************************************************
565  * UpdateDockIcon
566  ***********************************************************************
567  * Shows a progression bar on the dock icon, filled according to
568  * 'progress' (0.0 <= progress <= 1.0).
569  * Called with progress < 0.0 or progress > 1.0, restores the original
570  * icon.
571  **********************************************************************/
572 - (void) UpdateDockIcon: (float) progress
574     NSImage * icon;
575     NSData * tiff;
576     NSBitmapImageRep * bmp;
577     uint32_t * pen;
578     uint32_t black = htonl( 0x000000FF );
579     uint32_t red   = htonl( 0xFF0000FF );
580     uint32_t white = htonl( 0xFFFFFFFF );
581     int row_start, row_end;
582     int i, j;
584     /* Get application original icon */
585     icon = [NSImage imageNamed: @"NSApplicationIcon"];
587     if( progress < 0.0 || progress > 1.0 )
588     {
589         [NSApp setApplicationIconImage: icon];
590         return;
591     }
593     /* Get it in a raw bitmap form */
594     tiff = [icon TIFFRepresentationUsingCompression:
595             NSTIFFCompressionNone factor: 1.0];
596     bmp = [NSBitmapImageRep imageRepWithData: tiff];
597     
598     /* Draw the progression bar */
599     /* It's pretty simple (ugly?) now, but I'm no designer */
601     row_start = 3 * (int) [bmp size].height / 4;
602     row_end   = 7 * (int) [bmp size].height / 8;
604     for( i = row_start; i < row_start + 2; i++ )
605     {
606         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
607         for( j = 0; j < (int) [bmp size].width; j++ )
608         {
609             pen[j] = black;
610         }
611     }
612     for( i = row_start + 2; i < row_end - 2; i++ )
613     {
614         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
615         pen[0] = black;
616         pen[1] = black;
617         for( j = 2; j < (int) [bmp size].width - 2; j++ )
618         {
619             if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
620             {
621                 pen[j] = red;
622             }
623             else
624             {
625                 pen[j] = white;
626             }
627         }
628         pen[j]   = black;
629         pen[j+1] = black;
630     }
631     for( i = row_end - 2; i < row_end; i++ )
632     {
633         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
634         for( j = 0; j < (int) [bmp size].width; j++ )
635         {
636             pen[j] = black;
637         }
638     }
640     /* Now update the dock icon */
641     tiff = [bmp TIFFRepresentationUsingCompression:
642             NSTIFFCompressionNone factor: 1.0];
643     icon = [[NSImage alloc] initWithData: tiff];
644     [NSApp setApplicationIconImage: icon];
645     [icon release];
648 - (void) UpdateUI: (NSTimer *) timer
651 hb_list_t  * list;
652 list = hb_get_titles( fHandle );        
653     /* check to see if there has been a new scan done
654         this bypasses the constraints of HB_STATE_WORKING
655         not allowing setting a newly scanned source */
656         int checkScanCount = hb_get_scancount( fHandle );
657         if (checkScanCount > currentScanCount)
658         {
660                 currentScanCount = checkScanCount;
661                         [fScanController Cancel: NULL];
662                     [fScanIndicator setIndeterminate: NO];
663             [fScanIndicator setDoubleValue: 0.0];
664                         [fScanIndicator setHidden: YES];
665                         [fScanController Cancel: NULL];
666                         [self ShowNewScan: NULL];
668         }
669         
670         
671         
672         
673     hb_state_t s;
674     hb_get_state( fHandle, &s );
675         
676         
677     switch( s.state )
678     {
679         case HB_STATE_IDLE:
680                 break;
681 #define p s.param.scanning                      
682         case HB_STATE_SCANNING:
683                 {
684             [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
685                 _( @"Scanning title %d of %d..." ),
686                 p.title_cur, p.title_count]];
687             [fScanIndicator setIndeterminate: NO];
688                         [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) /
689                 p.title_count];
690             break;
691                 }
692 #undef p
693         
694 #define p s.param.scandone
695         case HB_STATE_SCANDONE:
696         {
697                         
698                         [fScanIndicator setIndeterminate: NO];
699             [fScanIndicator setDoubleValue: 0.0];
700                         [fScanIndicator setHidden: YES];
701                         [fScanController Cancel: NULL];
702                         [self ShowNewScan: NULL];
703                         break;
704         }
705 #undef p
706                         
707 #define p s.param.working
708         case HB_STATE_WORKING:
709         {
710             float progress_total;
711             NSMutableString * string;
712                         /* Currently, p.job_cur and p.job_count get screwed up when adding
713                                 jobs during encoding, if they cannot be fixed in libhb, will implement a
714                                 nasty but working cocoa solution */
715                         /* Update text field */
716                         string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress];
717             
718                         if( p.seconds > -1 )
719             {
720                 [string appendFormat:
721                     _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ),
722                     p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
723             }
724             [fStatusField setStringValue: string];
725                         
726             /* Update slider */
727                         progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
728             [fRipIndicator setIndeterminate: NO];
729             [fRipIndicator setDoubleValue: 100.0 * progress_total];
730                         
731             /* Update dock icon */
732             [self UpdateDockIcon: progress_total];
733                         
734             /* new toolbar controls */
735             pauseButtonEnabled = YES;
736             resumeOrPause = NO;
737             startButtonEnabled = YES;
738             stopOrStart = YES;                  
739                         
740             break;
741         }
742 #undef p
743                         
744 #define p s.param.muxing
745         case HB_STATE_MUXING:
746         {
747             NSMutableString * string;
748                         
749             /* Update text field */
750             string = [NSMutableString stringWithFormat:
751                 _( @"Muxing..." )];
752             [fStatusField setStringValue: string];
753                         
754             /* Update slider */
755             [fRipIndicator setIndeterminate: YES];
756             [fRipIndicator startAnimation: nil];
757                         
758             /* Update dock icon */
759             [self UpdateDockIcon: 1.0];
760                         
761             //[fPauseButton setEnabled: YES];
762             //[fPauseButton setTitle: _( @"Pause" )];
763             //[fRipButton setEnabled: YES];
764                         // [fRipButton setTitle: _( @"Cancel" )];
765             break;
766         }
767 #undef p
768                         
769         case HB_STATE_PAUSED:
770                     //[fStatusField setStringValue: _( @"Paused" )];
771             //[fPauseButton setEnabled: YES];
772             //[fPauseButton setTitle: _( @"Resume" )];
773             //[fRipButton setEnabled: YES];
774             //[fRipButton setTitle: _( @"Cancel" )];
775                         /* new toolbar controls */
776             pauseButtonEnabled = YES;
777             resumeOrPause = YES;
778             startButtonEnabled = YES;
779             stopOrStart = YES;
780             break;
781                         
782         case HB_STATE_WORKDONE:
783         {
784             [fStatusField setStringValue: _( @"Done." )];
785             [fRipIndicator setIndeterminate: NO];
786             [fRipIndicator setDoubleValue: 0.0];
787             //[fRipButton setTitle: _( @"Start" )];
788                         
789             /* Restore dock icon */
790             [self UpdateDockIcon: -1.0];
791                         
792             //[fPauseButton setEnabled: NO];
793             //[fPauseButton setTitle: _( @"Pause" )];
794                         // [fRipButton setEnabled: YES];
795                         // [fRipButton setTitle: _( @"Start" )];
796                         /* new toolbar controls */
797             pauseButtonEnabled = NO;
798             resumeOrPause = NO;
799             startButtonEnabled = YES;
800             stopOrStart = NO;
801                         NSRect frame = [fWindow frame];
802                         if (frame.size.width <= 591)
803                                 frame.size.width = 591;
804                         frame.size.height += -44;
805                         frame.origin.y -= -44;
806                         [fWindow setFrame:frame display:YES animate:YES];
807                         
808             /* FIXME */
809             hb_job_t * job;
810             while( ( job = hb_job( fHandle, 0 ) ) )
811             {
812                 hb_rem( fHandle, job );
813             }
814             /* Check to see if the encode state has not been cancelled
815                                 to determine if we should check for encode done notifications */
816                         if (fEncodeState != 2)                  {
817                                 /* If Growl Notification or Window and Growl has been selected */
818                                 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] || 
819                                         [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
820                 {
821                                         /*Growl Notification*/
822                                         [self showGrowlDoneNotification: NULL];
823                 }
824                 /* If Alert Window or Window and Growl has been selected */
825                                 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] || 
826                                         [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
827                 {
828                                         /*On Screen Notification*/
829                                         int status;
830                                         NSBeep();
831                                         status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
832                                         [NSApp requestUserAttention:NSCriticalRequest];
833                                         if ( status == NSAlertDefaultReturn ) 
834                                         {
835                                                 [self EnableUI: YES];
836                                         }
837                 }
838                                 else
839                                 {
840                                         [self EnableUI: YES];
841                                 }
842                                    /* If sleep has been selected */ 
843             if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"]) 
844                 { 
845                /* Sleep */ 
846                NSDictionary* errorDict; 
847                NSAppleEventDescriptor* returnDescriptor = NULL; 
848                NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: 
849                         @"tell application \"Finder\" to sleep"]; 
850                returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 
851                [scriptObject release]; 
852                [self EnableUI: YES]; 
853                 } 
854             /* If Shutdown has been selected */ 
855             if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"]) 
856                 { 
857                /* Shut Down */ 
858                NSDictionary* errorDict; 
859                NSAppleEventDescriptor* returnDescriptor = NULL; 
860                NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: 
861                         @"tell application \"Finder\" to shut down"]; 
862                returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 
863                [scriptObject release]; 
864                [self EnableUI: YES]; 
865                 }
866                         
867                                                 // MetaX insertion via AppleScript
868                         if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
869                         {
870                         NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", [fDstFile2Field stringValue], @"\")"]];
871                         [myScript executeAndReturnError: nil];
872                         [myScript release];
873                         }
874                         
875                         
876                         }
877                         else
878                         {
879                                 [self EnableUI: YES];
880                         }
881             break;
882         }
883     }
884         
885     /* Lets show the queue status
886                 here in the main window*/
887         int queue_count = hb_count( fHandle );
888         if( queue_count )
889         {
890                 [fQueueStatus setStringValue: [NSString stringWithFormat:
891                         @"%d task%s in the queue",
892                                                  queue_count, ( queue_count > 1 ) ? "s" : ""]];
893         }
894         else
895         {
896                 [fQueueStatus setStringValue: @""];
897         }
898         
899     [[NSRunLoop currentRunLoop] addTimer: [NSTimer
900         scheduledTimerWithTimeInterval: 0.5 target: self
901                                                           selector: @selector( UpdateUI: ) userInfo: NULL repeats: FALSE]
902                                                                  forMode: NSModalPanelRunLoopMode];
904 - (IBAction) ShowNewScan:(id)sender
906         hb_list_t  * list;
907         hb_title_t * title;
908         int indxpri=0;    // Used to search the longuest title (default in combobox)
909         int longuestpri=0; // Used to search the longuest title (default in combobox)
910         
911         list = hb_get_titles( fHandle );
912         
913         if( !hb_list_count( list ) )
914         {
915                 /* We display a message if a valid dvd source was not chosen */
916                 if (sourceDisplayName)
917                 {
918                 /* Temporary string if til restoring old source is fixed */
919                 [fSrcDVD2Field setStringValue: @"Not A Valid Source"];
920                 //[fSrcDVD2Field setStringValue: [NSString stringWithFormat: @"%s", sourceDisplayName]];
921                 }
922                 else
923                 {
924             [fSrcDVD2Field setStringValue: @"No Valid Title Found"];
925                 }       
926         }
927         else
928         {
929                 /* We increment the successful scancount here by one,
930                    which we use at the end of this function to tell the gui
931                    if this is the first successful scan since launch and whether
932                    or not we should set all settings to the defaults */
933                 currentSuccessfulScanCount++;
934                 
935                 [fSrcTitlePopUp removeAllItems];
936                 for( int i = 0; i < hb_list_count( list ); i++ )
937                 {
938                         title = (hb_title_t *) hb_list_item( list, i );
939                         /*Set DVD Name at top of window*/
940                         [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]];
941                         
942                         currentSource = [NSString stringWithUTF8String: title->dvd];
943                         
944                         
945                         /* Use the dvd name in the default output field here 
946                                 May want to add code to remove blank spaces for some dvd names*/
947                         /* Check to see if the last destination has been set,use if so, if not, use Desktop */
948                         if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
949                         {
950                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
951                                         @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString
952                   stringWithUTF8String: title->name]]];
953                         }
954                         else
955                         {
956                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
957                                         @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString
958                   stringWithUTF8String: title->name]]];
959                         }
960                         
961                         
962                         if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
963                         {
964                                 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
965                                 indxpri=i;
966                         }
967                         
968                         
969                         int format = [fDstFormatPopUp indexOfSelectedItem];
970                         char * ext = NULL;
971                         switch( format )
972                         {
973                                 case 0:
974                                         
975                                         /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/
976                                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
977                                         {
978                                                 ext = "m4v";
979                                         }
980                                         else
981                                         {
982                                                 ext = "mp4";
983                                         }
984                                         break;
985                                 case 1: 
986                                         ext = "avi";
987                                         break;
988                                 case 2:
989                                         ext = "ogm";
990                                         break;
991                         }
992                         
993                         
994                         NSString * string = [fDstFile2Field stringValue];
995                         /* Add/replace File Output name to the correct extension*/
996                         if( [string characterAtIndex: [string length] - 4] == '.' )
997                         {
998                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
999                                         @"%@.%s", [string substringToIndex: [string length] - 4],
1000                                         ext]];
1001                         }
1002                         else
1003                         {
1004                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1005                                         @"%@.%s", string, ext]];
1006                         }
1007                         
1008                         
1009                         [fSrcTitlePopUp addItemWithTitle: [NSString
1010                     stringWithFormat: @"%d - %02dh%02dm%02ds",
1011                                 title->index, title->hours, title->minutes,
1012                                 title->seconds]];
1013                         
1014                 }
1015                 // Select the longuest title
1016                 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1017                 [self TitlePopUpChanged: NULL];
1018                 /* We set the auto crop in the main window to value "1" just as in PictureController,
1019                         as it does not seem to be taken from any job-> variable */
1020                 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
1021                         @"%d", 0]];
1022                 
1023                 
1024                 [self EnableUI: YES];
1025                 
1026                 startButtonEnabled = YES;
1027                 stopOrStart = NO;
1028                 AddToQueueButtonEnabled = YES;
1029                 pauseButtonEnabled = NO;
1030                 resumeOrPause = NO;
1031                 /* we record the current source name here in case the next scan is unsuccessful,
1032                                 then we can replace the scan progress with the old name if necessary */
1033        sourceDisplayName = [NSString stringWithFormat:[fSrcDVD2Field stringValue]];
1034         
1035         /* if its the initial successful scan after awakeFromNib */
1036            if (currentSuccessfulScanCount == 1)
1037            {
1038        [self SelectDefaultPreset: NULL];
1039            }  
1040            
1041         }
1045 -(IBAction)showGrowlDoneNotification:(id)sender
1048   
1049   [GrowlApplicationBridge 
1050           notifyWithTitle:@"Put down that cocktail..." 
1051               description:@"your HandBrake encode is done!" 
1052          notificationName:SERVICE_NAME
1053                  iconData:nil 
1054                  priority:0 
1055                  isSticky:1 
1056              clickContext:nil];
1058 - (void) EnableUI: (bool) b
1060     NSControl * controls[] =
1061       { fSrcDVD1Field, fSrcTitleField, fSrcTitlePopUp,
1062         fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
1063         fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
1064         fDstFormatField, fDstFormatPopUp, fDstCodecsField,
1065         fDstCodecsPopUp, fDstFile1Field, fDstFile2Field,
1066         fDstBrowseButton, fVidRateField, fVidRatePopUp,
1067         fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
1068         fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
1069         fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
1070         fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
1071         fAudRateField, fAudRatePopUp, fAudBitrateField,
1072         fAudBitratePopUp, fPictureButton,fQueueStatus, 
1073                 fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,
1074                 fPicSettingARkeep,fPicSettingDeinterlace,fPicSettingARkeepDsply,
1075                 fPicSettingDeinterlaceDsply,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
1076                 fPicLabelAr,fPicLabelDeinter,fPicLabelSrcX,fPicLabelOutputX,
1077                 fPicLabelPAROutp,fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
1078                 fPicSettingPARDsply,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
1079                 fCreateChapterMarkers,fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
1080                 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,fX264optNfpskipLabel,fX264optNfpskipSwitch,
1081                 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
1082                 fX264optTrellisLabel,fX264optTrellisPopUp,fX264optMixedRefsLabel,fX264optMixedRefsSwitch,
1083                 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
1084                 fX264optWeightBLabel,fX264optWeightBSwitch,fX264optBRDOLabel,fX264optBRDOSwitch,
1085                 fX264optBPyramidLabel,fX264optBPyramidSwitch,fX264optBiMELabel,fX264optBiMESwitch,
1086                 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
1087                 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
1088                 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp,fVidTurboPassCheck,fDstMpgLargeFileCheck,fPicSettingAutoCropLabel,
1089                 fPicSettingAutoCropDsply,fPicSettingDetelecine,fPicSettingDetelecineLabel,fPicSettingDenoiseLabel};
1091     for( unsigned i = 0;
1092          i < sizeof( controls ) / sizeof( NSControl * ); i++ )
1093     {
1094         if( [[controls[i] className] isEqualToString: @"NSTextField"] )
1095         {
1096             NSTextField * tf = (NSTextField *) controls[i];
1097             if( ![tf isBezeled] )
1098             {
1099                 [tf setTextColor: b ? [NSColor controlTextColor] :
1100                     [NSColor disabledControlTextColor]];
1101                 continue;
1102             }
1103         }
1104         [controls[i] setEnabled: b];
1106     }
1107         
1108         if (b) {
1110         /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
1111         /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
1112         [self SetEnabledStateOfAudioMixdownControls: NULL];
1113         
1114         } else {
1116                 [tableView setEnabled: NO];
1117         
1118         }
1120     [self VideoMatrixChanged: NULL];
1123 - (IBAction) ShowScanPanel: (id) sender
1125     [fScanController Show];
1128 - (IBAction) OpenMainWindow: (id) sender
1130 [fWindow  makeKeyAndOrderFront:nil];
1131 [fWindow setReleasedWhenClosed: YES];
1133 - (BOOL) windowShouldClose: (id) sender
1136         /* See if we are currently running */
1137         hb_state_t s;
1138         hb_get_state( fHandle, &s );
1139         if ( s.state ==  HB_STATE_WORKING)
1140         {
1141            /* If we are running, leave in memory when closing main window */
1142            [fWindow setReleasedWhenClosed: NO];
1143            return YES;
1145         }
1146         else
1147         {
1148                 /* Stop the application when the user closes the window */
1149                 [NSApp terminate: self];
1150                 return YES;
1151         }
1152         
1155 - (IBAction) VideoMatrixChanged: (id) sender;
1157     bool target, bitrate, quality;
1159     target = bitrate = quality = false;
1160     if( [fVidQualityMatrix isEnabled] )
1161     {
1162         switch( [fVidQualityMatrix selectedRow] )
1163         {
1164             case 0:
1165                 target = true;
1166                 break;
1167             case 1:
1168                 bitrate = true;
1169                 break;
1170             case 2:
1171                 quality = true;
1172                 break;
1173         }
1174     }
1175     [fVidTargetSizeField  setEnabled: target];
1176     [fVidBitrateField     setEnabled: bitrate];
1177     [fVidQualitySlider    setEnabled: quality];
1178     [fVidTwoPassCheck     setEnabled: !quality &&
1179         [fVidQualityMatrix isEnabled]];
1180     if( quality )
1181     {
1182         [fVidTwoPassCheck setState: NSOffState];
1183                 [fVidTurboPassCheck setHidden: YES];
1184                 [fVidTurboPassCheck setState: NSOffState];
1185     }
1187     [self QualitySliderChanged: sender];
1188     [self CalculateBitrate:     sender];
1189         [self CustomSettingUsed: sender];
1192 - (IBAction) QualitySliderChanged: (id) sender
1194     [fVidConstantCell setTitle: [NSString stringWithFormat:
1195         _( @"Constant quality: %.0f %%" ), 100.0 *
1196         [fVidQualitySlider floatValue]]];
1197                 [self CustomSettingUsed: sender];
1200 - (IBAction) BrowseFile: (id) sender
1202     /* Open a panel to let the user choose and update the text field */
1203     NSSavePanel * panel = [NSSavePanel savePanel];
1204         /* We get the current file name and path from the destination field here */
1205         [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1206                                    modalForWindow: fWindow modalDelegate: self
1207                                    didEndSelector: @selector( BrowseFileDone:returnCode:contextInfo: )
1208                                           contextInfo: NULL];
1211 - (void) BrowseFileDone: (NSSavePanel *) sheet
1212     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1214     if( returnCode == NSOKButton )
1215     {
1216         [fDstFile2Field setStringValue: [sheet filename]];
1217                 
1218     }
1221 - (IBAction) ShowPicturePanel: (id) sender
1223     hb_list_t  * list  = hb_get_titles( fHandle );
1224     hb_title_t * title = (hb_title_t *) hb_list_item( list,
1225             [fSrcTitlePopUp indexOfSelectedItem] );
1227     /* Resize the panel */
1228     NSSize newSize;
1229     newSize.width  = 246 + title->width;
1230     newSize.height = 80 + title->height;
1231     [fPicturePanel setContentSize: newSize];
1233     [fPictureController SetTitle: title];
1235     [NSApp beginSheet: fPicturePanel modalForWindow: fWindow
1236         modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
1237     [NSApp runModalForWindow: fPicturePanel];
1238     [NSApp endSheet: fPicturePanel];
1239     [fPicturePanel orderOut: self];
1240         [self CalculatePictureSizing: sender];
1243 - (IBAction) ShowQueuePanel: (id) sender
1245     /* Update the OutlineView */
1246     [fQueueController Update: sender];
1248     /* Show the panel */
1249     [NSApp beginSheet: fQueuePanel modalForWindow: fWindow
1250         modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
1251     [NSApp runModalForWindow: fQueuePanel];
1252     [NSApp endSheet: fQueuePanel];
1253     [fQueuePanel orderOut: self];
1256 - (void) PrepareJob
1258     hb_list_t  * list  = hb_get_titles( fHandle );
1259     hb_title_t * title = (hb_title_t *) hb_list_item( list,
1260             [fSrcTitlePopUp indexOfSelectedItem] );
1261     hb_job_t * job = title->job;
1262     //int i;
1264     /* Chapter selection */
1265     job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
1266     job->chapter_end   = [fSrcChapterEndPopUp   indexOfSelectedItem] + 1;
1267         
1268     /* Format and codecs */
1269     int format = [fDstFormatPopUp indexOfSelectedItem];
1270     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1271     job->mux    = FormatSettings[format][codecs] & HB_MUX_MASK;
1272     job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
1273     job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1274     /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
1275         if ([fDstFormatPopUp indexOfSelectedItem] == 0)
1276         {
1277         /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
1278                 mpeg4 and the checkbox being checked 
1279                 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
1280                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0 && [fDstMpgLargeFileCheck state] == NSOnState)
1281                 {
1282                         job->largeFileSize = 1;
1283                 }
1284                 else
1285                 {
1286                         job->largeFileSize = 0;
1287                 }
1288         }
1289         if ([fDstFormatPopUp indexOfSelectedItem] == 0 || [fDstFormatPopUp indexOfSelectedItem] == 3)
1290         {
1291           /* We set the chapter marker extraction here based on the format being
1292                 mpeg4 or mkv and the checkbox being checked */
1293                 if ([fCreateChapterMarkers state] == NSOnState)
1294                 {
1295                         job->chapter_markers = 1;
1296                 }
1297                 else
1298                 {
1299                         job->chapter_markers = 0;
1300                 }
1301         }
1302         if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
1303         [fVidEncoderPopUp indexOfSelectedItem] > 0 )
1304     {
1305         job->vcodec = HB_VCODEC_XVID;
1306     }
1307     if( job->vcodec & HB_VCODEC_X264 )
1308     {
1309                 if ([fVidEncoderPopUp indexOfSelectedItem] > 0 )
1310             {
1311                         /* Just use new Baseline Level 3.0 
1312                         Lets Deprecate Baseline Level 1.3h264_level*/
1313                         job->h264_level = 30;
1314                         job->mux = HB_MUX_IPOD;
1315                         /* move sanity check for iPod Encoding here */
1316                         job->pixel_ratio = 0 ;
1317                         
1318                 }
1319                 
1320                 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
1321                 Currently only used with Constant Quality setting*/
1322                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
1323                 {
1324                 job->crf = 1;
1325                 }
1326                 
1327                 /* Below Sends x264 options to the core library if x264 is selected*/
1328                 /* Lets use this as per Nyx, Thanks Nyx!*/
1329                 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1330                 /* Turbo first pass if two pass and Turbo First pass is selected */
1331                 if( [fVidTwoPassCheck state] == NSOnState && [fVidTurboPassCheck state] == NSOnState )
1332                 {
1333                         /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
1334                         NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:weightb=0:trellis=0:no-fast-pskip=0:8x8dct=0";
1335                         /* append the "Turbo" string variable to the existing opts string.
1336                         Note: the "Turbo" string must be appended, not prepended to work properly*/
1337                         NSString *firstPassOptStringCombined = [[fDisplayX264Options stringValue] stringByAppendingString:firstPassOptStringTurbo];
1338                         strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
1339                 }
1340                 else
1341                 {
1342                         strcpy(job->x264opts, [[fDisplayX264Options stringValue] UTF8String]);
1343                 }
1344                 
1345         job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
1346     }
1348     /* Video settings */
1349     if( [fVidRatePopUp indexOfSelectedItem] > 0 )
1350     {
1351         job->vrate      = 27000000;
1352         job->vrate_base = hb_video_rates[[fVidRatePopUp
1353             indexOfSelectedItem]-1].rate;
1354     }
1355     else
1356     {
1357         job->vrate      = title->rate;
1358         job->vrate_base = title->rate_base;
1359     }
1361     switch( [fVidQualityMatrix selectedRow] )
1362     {
1363         case 0:
1364             /* Target size.
1365                Bitrate should already have been calculated and displayed
1366                in fVidBitrateField, so let's just use it */
1367         case 1:
1368             job->vquality = -1.0;
1369             job->vbitrate = [fVidBitrateField intValue];
1370             break;
1371         case 2:
1372             job->vquality = [fVidQualitySlider floatValue];
1373             job->vbitrate = 0;
1374             break;
1375     }
1377     job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
1378     
1381     /* Subtitle settings */
1382     job->subtitle = [fSubPopUp indexOfSelectedItem] - 1;
1384     /* Audio tracks and mixdowns */
1385     /* check for the condition where track 2 has an audio selected, but track 1 does not */
1386     /* we will use track 2 as track 1 in this scenario */
1387     if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1388     {
1389         job->audios[0] = [fAudLang1PopUp indexOfSelectedItem] - 1;
1390         job->audios[1] = [fAudLang2PopUp indexOfSelectedItem] - 1; /* will be -1 if "none" is selected */
1391         job->audios[2] = -1;
1392         job->audio_mixdowns[0] = [[fAudTrack1MixPopUp selectedItem] tag];
1393         job->audio_mixdowns[1] = [[fAudTrack2MixPopUp selectedItem] tag];
1394     }
1395     else if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1396     {
1397         job->audios[0] = [fAudLang2PopUp indexOfSelectedItem] - 1;
1398         job->audio_mixdowns[0] = [[fAudTrack2MixPopUp selectedItem] tag];
1399         job->audios[1] = -1;
1400     }
1401     else
1402     {
1403         job->audios[0] = -1;
1404     }
1406     /* Audio settings */
1407     job->arate = hb_audio_rates[[fAudRatePopUp
1408                      indexOfSelectedItem]].rate;
1409     job->abitrate = [[fAudBitratePopUp selectedItem] tag];
1410     
1411     /* TODO: Filter settings */
1412     if( job->filters )
1413     {
1414         hb_list_close( &job->filters );
1415     }
1416     job->filters = hb_list_init();
1417    
1418         /* Detelecine */
1419    if ([[fPicSettingDetelecine stringValue] isEqualToString: @"Yes"])
1420    {
1421    hb_list_add( job->filters, &hb_filter_detelecine );
1422    }
1423    
1424    /* Deinterlace */
1425    if( job->deinterlace == 1)
1426     {        
1427         if ([fPicSettingDeinterlace intValue] == 1)
1428         {
1429             /* Run old deinterlacer by default */
1430             hb_filter_deinterlace.settings = "-1"; 
1431             hb_list_add( job->filters, &hb_filter_deinterlace );
1432         }
1433         if ([fPicSettingDeinterlace intValue] == 2)
1434         {
1435             /* Yadif mode 0 (1-pass with spatial deinterlacing.) */
1436             hb_filter_deinterlace.settings = "0"; 
1437             hb_list_add( job->filters, &hb_filter_deinterlace );            
1438         }
1439         if ([fPicSettingDeinterlace intValue] == 3)
1440         {
1441             /* Yadif (1-pass w/o spatial deinterlacing) and Mcdeint */
1442             hb_filter_deinterlace.settings = "2:-1:1"; 
1443             hb_list_add( job->filters, &hb_filter_deinterlace );            
1444         }
1445         if ([fPicSettingDeinterlace intValue] == 4)
1446         {
1447             /* Yadif (2-pass w/ spatial deinterlacing) and Mcdeint*/
1448             hb_filter_deinterlace.settings = "1:-1:1"; 
1449             hb_list_add( job->filters, &hb_filter_deinterlace );            
1450         }
1451     }
1452         
1453         /* Denoise */
1454         
1455         if ([fPicSettingDenoise intValue] == 1) // Weak in popup
1456         {
1457                 hb_filter_denoise.settings = "2:1:2:3"; 
1458         hb_list_add( job->filters, &hb_filter_denoise );        
1459         }
1460         else if ([fPicSettingDenoise intValue] == 2) // Medium in popup
1461         {
1462                 hb_filter_denoise.settings = "3:2:2:3"; 
1463         hb_list_add( job->filters, &hb_filter_denoise );        
1464         }
1465         else if ([fPicSettingDenoise intValue] == 3) // Strong in popup
1466         {
1467                 hb_filter_denoise.settings = "7:7:5:5"; 
1468         hb_list_add( job->filters, &hb_filter_denoise );        
1469         }
1475 - (IBAction) AddToQueue: (id) sender
1477 /* We get the destination directory from the destingation field here */
1478         NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1479         /* We check for a valid destination here */
1480         if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0) 
1481         {
1482                 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1483         }
1484         else
1485         {
1486                 
1487                 hb_list_t  * list  = hb_get_titles( fHandle );
1488                 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1489                                                                                                                   [fSrcTitlePopUp indexOfSelectedItem] );
1490                 hb_job_t * job = title->job;
1491                 
1492                 [self PrepareJob];
1493                 
1494                 /* Destination file */
1495                 job->file = [[fDstFile2Field stringValue] UTF8String];
1496                 
1497                 if( [fVidTwoPassCheck state] == NSOnState )
1498                 {
1499                         job->pass = 1;
1500                         hb_add( fHandle, job );
1501                         job->pass = 2;
1502                         
1503                         job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */  
1504                         strcpy(job->x264opts, [[fDisplayX264Options stringValue] UTF8String]);
1505                         
1506                         hb_add( fHandle, job );
1507                 }
1508                 else
1509                 {
1510                         job->pass = 0;
1511                         hb_add( fHandle, job );
1512                 }
1513         
1514         [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1515         /* Lets try to update stuff, taken from remove in the queue controller */
1516         [fQueueController performSelectorOnMainThread: @selector( Update: )
1517         withObject: sender waitUntilDone: NO];
1518         }
1521 - (IBAction) Rip: (id) sender
1523     /* Rip or Cancel ? */
1524  //   if( [[fRipButton title] isEqualToString: _( @"Cancel" )] )
1525     if(stopOrStart)
1526         {
1527         [self Cancel: sender];
1528         return;
1529     }
1530         /* if there is no job in the queue, then add it to the queue and rip 
1531         otherwise, there are already jobs in queue, so just rip the queue */
1532         int count = hb_count( fHandle );
1533         if( count < 1 )
1534         {
1535                 [self AddToQueue: sender];
1536                 }
1537     
1538             /* We check for duplicate name here */
1539         if( [[NSFileManager defaultManager] fileExistsAtPath:
1540             [fDstFile2Field stringValue]] )
1541     {
1542         NSBeginCriticalAlertSheet( _( @"File already exists" ),
1543             _( @"Cancel" ), _( @"Overwrite" ), NULL, fWindow, self,
1544             @selector( OverwriteAlertDone:returnCode:contextInfo: ),
1545             NULL, NULL, [NSString stringWithFormat:
1546             _( @"Do you want to overwrite %@?" ),
1547             [fDstFile2Field stringValue]] );
1548         return;
1549     }
1550         /* We get the destination directory from the destination field here */
1551         NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1552         /* We check for a valid destination here */
1553         if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0) 
1554         {
1555                 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1556         }
1557         else
1558         {
1559         [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1560                 [self _Rip];
1561         }
1562         
1567 - (void) OverwriteAlertDone: (NSWindow *) sheet
1568     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1570     if( returnCode == NSAlertAlternateReturn )
1571     {
1572         [self _Rip];
1573     }
1576 - (void) UpdateAlertDone: (NSWindow *) sheet
1577     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1579     if( returnCode == NSAlertAlternateReturn )
1580     {
1581         /* Show scan panel */
1582         [self performSelectorOnMainThread: @selector(ShowScanPanel:)
1583             withObject: NULL waitUntilDone: NO];
1584         return;
1585     }
1587     /* Go to HandBrake homepage and exit */
1588     [self OpenHomepage: NULL];
1589     [NSApp terminate: self];
1592 - (void) _Rip
1594     /* Let libhb do the job */
1595     hb_start( fHandle );
1596         /*set the fEncodeState State */
1597         fEncodeState = 1;
1598         
1599     /* Disable interface */
1600         //[self EnableUI: NO];
1601         // [fPauseButton setEnabled: NO];
1602         // [fRipButton   setEnabled: NO];
1603         pauseButtonEnabled = NO;
1604         startButtonEnabled = NO;
1605         NSRect frame = [fWindow frame];
1606     if (frame.size.width <= 591)
1607         frame.size.width = 591;
1608     frame.size.height += 44;
1609     frame.origin.y -= 44;
1610     [fWindow setFrame:frame display:YES animate:YES];
1613 - (IBAction) Cancel: (id) sender
1615     NSBeginCriticalAlertSheet( _( @"Cancel - Are you sure?" ),
1616         _( @"Keep working" ), _( @"Cancel encoding" ), NULL, fWindow, self,
1617         @selector( _Cancel:returnCode:contextInfo: ), NULL, NULL,
1618         _( @"Encoding won't be recoverable." ) );
1621 - (void) _Cancel: (NSWindow *) sheet
1622     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1624     if( returnCode == NSAlertAlternateReturn )
1625     {
1626         hb_stop( fHandle );
1627        // [fPauseButton setEnabled: NO];
1628        // [fRipButton   setEnabled: NO];
1629            pauseButtonEnabled = NO;
1630        startButtonEnabled = NO;
1631                 /*set the fEncodeState State */
1632              fEncodeState = 2;
1633     }
1636 - (IBAction) Pause: (id) sender
1638    // [fPauseButton setEnabled: NO];
1639    // [fRipButton   setEnabled: NO];
1641    // if( [[fPauseButton title] isEqualToString: _( @"Resume" )] )
1642           pauseButtonEnabled = NO;
1643        startButtonEnabled = NO;
1645     if(resumeOrPause)
1646     {
1647         hb_resume( fHandle );
1648     }
1649     else
1650     {
1651         hb_pause( fHandle );
1652     }
1655 - (IBAction) TitlePopUpChanged: (id) sender
1657     hb_list_t  * list  = hb_get_titles( fHandle );
1658     hb_title_t * title = (hb_title_t*)
1659         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1660                 
1661                 
1662     /* If Auto Naming is on. We create an output filename of dvd name - title number */
1663     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
1664         {
1665                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1666                         @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
1667                         [NSString stringWithUTF8String: title->name],
1668                         [fSrcTitlePopUp indexOfSelectedItem] + 1,
1669                         [[fDstFile2Field stringValue] pathExtension]]]; 
1670         }
1672     /* Update chapter popups */
1673     [fSrcChapterStartPopUp removeAllItems];
1674     [fSrcChapterEndPopUp   removeAllItems];
1675     for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
1676     {
1677         [fSrcChapterStartPopUp addItemWithTitle: [NSString
1678             stringWithFormat: @"%d", i + 1]];
1679         [fSrcChapterEndPopUp addItemWithTitle: [NSString
1680             stringWithFormat: @"%d", i + 1]];
1681     }
1682     [fSrcChapterStartPopUp selectItemAtIndex: 0];
1683     [fSrcChapterEndPopUp   selectItemAtIndex:
1684         hb_list_count( title->list_chapter ) - 1];
1685     [self ChapterPopUpChanged: NULL];
1687 /* Start Get and set the initial pic size for display */
1688         hb_job_t * job = title->job;
1689         fTitle = title; 
1690         /* Turn Deinterlace on/off depending on the preference */
1691         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1692         {
1693                 job->deinterlace = 1;
1694         }
1695         else
1696         {
1697                 job->deinterlace = 0;
1698         }
1699         
1700         /* Pixel Ratio Setting */
1701         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
1702     {
1704                 job->pixel_ratio = 1 ;
1705         }
1706         else
1707         {
1708                 job->pixel_ratio = 0 ;
1709         }
1710         /*Set Source Size Fields Here */
1711         [fPicSrcWidth setStringValue: [NSString stringWithFormat:
1712                                                          @"%d", fTitle->width]];
1713         [fPicSrcHeight setStringValue: [NSString stringWithFormat:
1714                                                          @"%d", fTitle->height]];
1715                                                          
1716         /* We get the originial output picture width and height and put them
1717         in variables for use with some presets later on */
1718         PicOrigOutputWidth = job->width;
1719         PicOrigOutputHeight = job->height;
1720         AutoCropTop = job->crop[0];
1721         AutoCropBottom = job->crop[1];
1722         AutoCropLeft = job->crop[2];
1723         AutoCropRight = job->crop[3];
1724         /* we test getting the max output value for pic sizing here to be used later*/
1725         [fPicSettingWidth setStringValue: [NSString stringWithFormat:
1726                 @"%d", PicOrigOutputWidth]];
1727         [fPicSettingHeight setStringValue: [NSString stringWithFormat:
1728                 @"%d", PicOrigOutputHeight]];
1729         /* we run the picture size values through
1730         CalculatePictureSizing to get all picture size
1731         information*/
1732         [self CalculatePictureSizing: NULL];
1733         /* Run Through EncoderPopUpChanged to see if there
1734                 needs to be any pic value modifications based on encoder settings */
1735         //[self EncoderPopUpChanged: NULL];
1736         /* END Get and set the initial pic size for display */ 
1738     /* Update subtitle popups */
1739     hb_subtitle_t * subtitle;
1740     [fSubPopUp removeAllItems];
1741     [fSubPopUp addItemWithTitle: @"None"];
1742     for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
1743     {
1744         subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
1746         /* We cannot use NSPopUpButton's addItemWithTitle because
1747            it checks for duplicate entries */
1748         [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
1749             subtitle->lang] action: NULL keyEquivalent: @""];
1750     }
1751     [fSubPopUp selectItemAtIndex: 0];
1752     
1753     /* Update chapter table */
1754     [fChapterTitlesDelegate resetWithTitle:title];
1755     [fChapterTable reloadData];
1757     /* Update audio popups */
1758     [self AddAllAudioTracksToPopUp: fAudLang1PopUp];
1759     [self AddAllAudioTracksToPopUp: fAudLang2PopUp];
1760     /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
1761         NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
1762     [self SelectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
1763     [self SelectAudioTrackInPopUp: fAudLang2PopUp searchPrefixString: NULL selectIndexIfNotFound: 0];
1764         
1765         /* changing the title may have changed the audio channels on offer, */
1766         /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1767         [self AudioTrackPopUpChanged: fAudLang1PopUp];
1768         [self AudioTrackPopUpChanged: fAudLang2PopUp];
1769         /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
1770         [self tableViewSelected:NULL];
1773 - (IBAction) ChapterPopUpChanged: (id) sender
1775     
1776         /* If start chapter popup is greater than end chapter popup,
1777         we set the end chapter popup to the same as start chapter popup */
1778         if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
1779         {
1780                 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
1781     }
1783                 
1784         
1785         hb_list_t  * list  = hb_get_titles( fHandle );
1786     hb_title_t * title = (hb_title_t *)
1787         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1789     hb_chapter_t * chapter;
1790     int64_t        duration = 0;
1791     for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
1792          i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
1793     {
1794         chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
1795         duration += chapter->duration;
1796     }
1797     
1798     duration /= 90000; /* pts -> seconds */
1799     [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
1800         @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
1801         duration % 60]];
1803     [self CalculateBitrate: sender];
1806 - (IBAction) FormatPopUpChanged: (id) sender
1808     NSString * string = [fDstFile2Field stringValue];
1809     int format = [fDstFormatPopUp indexOfSelectedItem];
1810     char * ext = NULL;
1811         /* Initially set the large file (64 bit formatting) output checkbox to hidden */
1812     [fDstMpgLargeFileCheck setHidden: YES];
1813     /* Update the codecs popup */
1814     [fDstCodecsPopUp removeAllItems];
1815     switch( format )
1816     {
1817         case 0:
1818                         /*Get Default MP4 File Extension*/
1819                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1820                         {
1821                                 ext = "m4v";
1822                         }
1823                         else
1824                         {
1825                                 ext = "mp4";
1826                         }
1827             [fDstCodecsPopUp addItemWithTitle:
1828                 _( @"MPEG-4 Video / AAC Audio" )];
1829             [fDstCodecsPopUp addItemWithTitle:
1830                 _( @"AVC/H.264 Video / AAC Audio" )];
1831                         /* We enable the create chapters checkbox here since we are .mp4*/
1832                         [fCreateChapterMarkers setEnabled: YES];
1833                         /* We show the Large File (64 bit formatting) checkbox since we are .mp4 
1834                         if we have enabled the option in the global preferences*/
1835                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0)
1836                         {
1837                                 [fDstMpgLargeFileCheck setHidden: NO];
1838                         }
1839                                 else
1840                                 {
1841                                         /* if not enable in global preferences, we additionaly sanity check that the
1842                                         hidden checkbox is set to off. */
1843                                         [fDstMpgLargeFileCheck setState: NSOffState];
1844                                 }
1845                                 break;
1846         case 1: 
1847             ext = "avi";
1848             [fDstCodecsPopUp addItemWithTitle:
1849                 _( @"MPEG-4 Video / MP3 Audio" )];
1850             [fDstCodecsPopUp addItemWithTitle:
1851                 _( @"MPEG-4 Video / AC-3 Audio" )];
1852             [fDstCodecsPopUp addItemWithTitle:
1853                 _( @"AVC/H.264 Video / MP3 Audio" )];
1854             [fDstCodecsPopUp addItemWithTitle:
1855                 _( @"AVC/H.264 Video / AC-3 Audio" )];
1856                         /* We disable the create chapters checkbox here since we are NOT .mp4 
1857                         and make sure it is unchecked*/
1858                         [fCreateChapterMarkers setEnabled: NO];
1859                         [fCreateChapterMarkers setState: NSOffState];
1860                         break;
1861         case 2:
1862             ext = "ogm";
1863             [fDstCodecsPopUp addItemWithTitle:
1864                 _( @"MPEG-4 Video / Vorbis Audio" )];
1865             [fDstCodecsPopUp addItemWithTitle:
1866                 _( @"MPEG-4 Video / MP3 Audio" )];
1867             /* We disable the create chapters checkbox here since we are NOT .mp4 
1868                         and make sure it is unchecked*/
1869                         [fCreateChapterMarkers setEnabled: NO];
1870                         [fCreateChapterMarkers setState: NSOffState];
1871                         break;
1872                 case 3:
1873             ext = "mkv";
1874             [fDstCodecsPopUp addItemWithTitle:
1875                 _( @"MPEG-4 Video / AAC Audio" )];
1876                                 [fDstCodecsPopUp addItemWithTitle:
1877                 _( @"MPEG-4 Video / AC-3 Audio" )];
1878                         [fDstCodecsPopUp addItemWithTitle:
1879                 _( @"MPEG-4 Video / MP3 Audio" )];
1880                         [fDstCodecsPopUp addItemWithTitle:
1881                 _( @"MPEG-4 Video / Vorbis Audio" )];
1882             
1883                         [fDstCodecsPopUp addItemWithTitle:
1884                 _( @"AVC/H.264 Video / AAC Audio" )];
1885                         [fDstCodecsPopUp addItemWithTitle:
1886                 _( @"AVC/H.264 Video / AC-3 Audio" )];
1887                         [fDstCodecsPopUp addItemWithTitle:
1888                 _( @"AVC/H.264 Video / MP3 Audio" )];
1889                         [fDstCodecsPopUp addItemWithTitle:
1890                 _( @"AVC/H.264 Video / Vorbis Audio" )];
1891             /* We disable the create chapters checkbox here since we are NOT .mp4 
1892                         and make sure it is unchecked*/
1893                         [fCreateChapterMarkers setEnabled: YES];
1894                         break;
1895     }
1896     [self CodecsPopUpChanged: NULL];
1898     /* Add/replace to the correct extension */
1899     if( [string characterAtIndex: [string length] - 4] == '.' )
1900     {
1901         [fDstFile2Field setStringValue: [NSString stringWithFormat:
1902             @"%@.%s", [string substringToIndex: [string length] - 4],
1903             ext]];
1904     }
1905     else
1906     {
1907         [fDstFile2Field setStringValue: [NSString stringWithFormat:
1908             @"%@.%s", string, ext]];
1909     }
1911         /* changing the format may mean that we can / can't offer mono or 6ch, */
1912         /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1913         [self AudioTrackPopUpChanged: fAudLang1PopUp];
1914         [self AudioTrackPopUpChanged: fAudLang2PopUp];
1915         /* We call the method to properly enable/disable turbo 2 pass */
1916         [self TwoPassCheckboxChanged: sender];
1917         /* We call method method to change UI to reflect whether a preset is used or not*/
1918         [self CustomSettingUsed: sender];       
1919         
1922 - (IBAction) CodecsPopUpChanged: (id) sender
1924     int format = [fDstFormatPopUp indexOfSelectedItem];
1925     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1926         [fX264optView setHidden: YES];
1927         [fX264optViewTitleLabel setStringValue: @"Only Used With The x264 (H.264) Codec"];
1930     /* Update the encoder popup*/
1931     if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
1932     {
1933         /* MPEG-4 -> H.264 */
1934         [fVidEncoderPopUp removeAllItems];
1935                 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 Main)"];
1936                 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 iPod)"];
1937                 [fVidEncoderPopUp selectItemAtIndex: 0];
1938         [fX264optView setHidden: NO];
1939                 [fX264optViewTitleLabel setStringValue: @""];
1942                 
1943     }
1944     else if( ( FormatSettings[format][codecs] & HB_VCODEC_FFMPEG ) )
1945     {
1946         /* H.264 -> MPEG-4 */
1947         [fVidEncoderPopUp removeAllItems];
1948         [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
1949         [fVidEncoderPopUp addItemWithTitle: @"XviD"];
1950         [fVidEncoderPopUp selectItemAtIndex: 0];
1951                                 
1952     }
1954     if( FormatSettings[format][codecs] & HB_ACODEC_AC3 )
1955     {
1956         /* AC-3 pass-through: disable samplerate and bitrate */
1957         [fAudRatePopUp    setEnabled: NO];
1958         [fAudBitratePopUp setEnabled: NO];
1959     }
1960     else
1961     {
1962         [fAudRatePopUp    setEnabled: YES];
1963         [fAudBitratePopUp setEnabled: YES];
1964     }
1965     /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
1966         /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1967         [self AudioTrackPopUpChanged: fAudLang1PopUp];
1968         [self AudioTrackPopUpChanged: fAudLang2PopUp];
1970     [self CalculateBitrate: sender];
1971     [self TwoPassCheckboxChanged: sender];
1974 - (IBAction) EncoderPopUpChanged: (id) sender
1976     
1977         /* Check to see if we need to modify the job pic values based on x264 (iPod) encoder selection */
1978     if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fDstCodecsPopUp indexOfSelectedItem] == 1 && [fVidEncoderPopUp indexOfSelectedItem] == 1)
1979     {
1980                 hb_job_t * job = fTitle->job;
1981                 job->pixel_ratio = 0 ;
1982                 
1983                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPicSizeAutoiPod"] > 0)
1984                 {
1985                         
1986                         if (job->width > 640)
1987                         {
1988                                 job->width = 640;
1989                         }
1990                         job->keep_ratio = 1;
1991                         hb_fix_aspect( job, HB_KEEP_WIDTH );
1992                         
1993                 }
1994                 /* Make sure the 64bit formatting checkbox is off */
1995                 [fDstMpgLargeFileCheck setState: NSOffState];
1996         }
1997     
1998         [self CalculatePictureSizing: sender];
1999         [self TwoPassCheckboxChanged: sender];
2002 - (IBAction) TwoPassCheckboxChanged: (id) sender
2004         /* check to see if x264 is chosen */
2005         int format = [fDstFormatPopUp indexOfSelectedItem];
2006     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2007         if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
2008     {
2009                 if( [fVidTwoPassCheck state] == NSOnState)
2010                 {
2011                         [fVidTurboPassCheck setHidden: NO];
2012                 }
2013                 else
2014                 {
2015                         [fVidTurboPassCheck setHidden: YES];
2016                         [fVidTurboPassCheck setState: NSOffState];
2017                 }
2018                 /* Make sure Two Pass is checked if Turbo is checked */
2019                 if( [fVidTurboPassCheck state] == NSOnState)
2020                 {
2021                         [fVidTwoPassCheck setState: NSOnState];
2022                 }
2023         }
2024         else
2025         {
2026                 [fVidTurboPassCheck setHidden: YES];
2027                 [fVidTurboPassCheck setState: NSOffState];
2028         }
2029         
2030         /* We call method method to change UI to reflect whether a preset is used or not*/
2031         [self CustomSettingUsed: sender];
2034 - (IBAction ) VideoFrameRateChanged: (id) sender
2036 /* We call method method to CalculatePictureSizing to error check detelecine*/
2037 [self CalculatePictureSizing: sender];
2039 /* We call method method to change UI to reflect whether a preset is used or not*/
2040         [self CustomSettingUsed: sender];
2043 - (IBAction) SetEnabledStateOfAudioMixdownControls: (id) sender
2046     /* enable/disable the mixdown text and popupbutton for audio track 1 */
2047     [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
2048     [fAudTrack1MixLabel setTextColor: ([fAudLang1PopUp indexOfSelectedItem] == 0) ?
2049         [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2051     /* enable/disable the mixdown text and popupbutton for audio track 2 */
2052     [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
2053     [fAudTrack2MixLabel setTextColor: ([fAudLang2PopUp indexOfSelectedItem] == 0) ?
2054         [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2058 - (IBAction) AddAllAudioTracksToPopUp: (id) sender
2061     hb_list_t  * list  = hb_get_titles( fHandle );
2062     hb_title_t * title = (hb_title_t*)
2063         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
2065         hb_audio_t * audio;
2067     [sender removeAllItems];
2068     [sender addItemWithTitle: _( @"None" )];
2069     for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
2070     {
2071         audio = (hb_audio_t *) hb_list_item( title->list_audio, i );
2072         [[sender menu] addItemWithTitle:
2073             [NSString stringWithCString: audio->lang]
2074             action: NULL keyEquivalent: @""];
2075     }
2076     [sender selectItemAtIndex: 0];
2080 - (IBAction) SelectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
2083     /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
2084     /* e.g. to find the first French track, pass in an NSString * of "Francais" */
2085     /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
2086     /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
2087     
2088         if (searchPrefixString != NULL) 
2089         {
2091         for( int i = 0; i < [sender numberOfItems]; i++ )
2092         {
2093             /* Try to find the desired search string */
2094             if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
2095             {
2096                 [sender selectItemAtIndex: i];
2097                 return;
2098             }
2099         }
2100         /* couldn't find the string, so select the requested "search string not found" item */
2101         /* index of 0 means select the "none" item */
2102         /* index of 1 means select the first audio track */
2103         [sender selectItemAtIndex: selectIndexIfNotFound];
2104         }
2105     else
2106     {
2107         /* if no search string is provided, then select the selectIndexIfNotFound item */
2108         [sender selectItemAtIndex: selectIndexIfNotFound];
2109     }
2113 - (IBAction) AudioTrackPopUpChanged: (id) sender
2115     /* utility function to call AudioTrackPopUpChanged without passing in a mixdown-to-use */
2116     [self AudioTrackPopUpChanged: sender mixdownToUse: 0];
2119 - (IBAction) AudioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
2122     /* make sure we have a selected title before continuing */
2123     if (fTitle == NULL) return;
2125     /* find out if audio track 1 or 2 was changed - this is passed to us in the tag of the sender */
2126     /* the sender will have been either fAudLang1PopUp (tag = 0) or fAudLang2PopUp (tag = 1) */
2127     int thisAudio = [sender tag];
2129     /* get the index of the selected audio */
2130     int thisAudioIndex = [sender indexOfSelectedItem] - 1;
2132     /* Handbrake can't currently cope with ripping the same source track twice */
2133     /* So, if this audio is also selected in the other audio track popup, set that popup's selection to "none" */
2134     /* get a reference to the two audio track popups */
2135     NSPopUpButton * thisAudioPopUp  = (thisAudio == 1 ? fAudLang2PopUp : fAudLang1PopUp);
2136     NSPopUpButton * otherAudioPopUp = (thisAudio == 1 ? fAudLang1PopUp : fAudLang2PopUp);
2137     /* if the same track is selected in the other audio popup, then select "none" in that popup */
2138     /* unless, of course, both are selected as "none!" */
2139     if ([thisAudioPopUp indexOfSelectedItem] != 0 && [thisAudioPopUp indexOfSelectedItem] == [otherAudioPopUp indexOfSelectedItem]) {
2140         [otherAudioPopUp selectItemAtIndex: 0];
2141         [self AudioTrackPopUpChanged: otherAudioPopUp];
2142     }
2144     /* pointer for the hb_audio_s struct we will use later on */
2145     hb_audio_t * audio;
2147     /* find out what the currently-selected output audio codec is */
2148     int format = [fDstFormatPopUp indexOfSelectedItem];
2149     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2150     int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2152     /* pointer to this track's mixdown NSPopUpButton */
2153     NSTextField   * mixdownTextField;
2154     NSPopUpButton * mixdownPopUp;
2156     /* find our mixdown NSTextField and NSPopUpButton */
2157     if (thisAudio == 0)
2158     {
2159         mixdownTextField = fAudTrack1MixLabel;
2160         mixdownPopUp = fAudTrack1MixPopUp;
2161     }
2162     else
2163     {
2164         mixdownTextField = fAudTrack2MixLabel;
2165         mixdownPopUp = fAudTrack2MixPopUp;
2166     }
2168     /* delete the previous audio mixdown options */
2169     [mixdownPopUp removeAllItems];
2171     /* check if the audio mixdown controls need their enabled state changing */
2172     [self SetEnabledStateOfAudioMixdownControls: NULL];
2174     if (thisAudioIndex != -1)
2175     {
2177         /* get the audio */
2178         audio = (hb_audio_t *) hb_list_item( fTitle->list_audio, thisAudioIndex );
2179         if (audio != NULL)
2180         {
2182             /* find out if our selected output audio codec supports mono and / or 6ch */
2183             /* we also check for an input codec of AC3 or DCA,
2184                as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
2185             /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
2186                but this may change in the future, so they are separated for flexibility */
2187             int audioCodecsSupportMono = ((audio->codec == HB_ACODEC_AC3 ||
2188                 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2189             int audioCodecsSupport6Ch =  ((audio->codec == HB_ACODEC_AC3 ||
2190                 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2192             /* check for AC-3 passthru */
2193             if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
2194             {
2195                     [[mixdownPopUp menu] addItemWithTitle:
2196                         [NSString stringWithCString: "AC3 Passthru"]
2197                         action: NULL keyEquivalent: @""];
2198             }
2199             else
2200             {
2202                 /* add the appropriate audio mixdown menuitems to the popupbutton */
2203                 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
2204                    so that we can reference the mixdown later */
2206                 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
2207                 int minMixdownUsed = 0;
2208                 int maxMixdownUsed = 0;
2209                 
2210                 /* get the input channel layout without any lfe channels */
2211                 int layout = audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2213                 /* do we want to add a mono option? */
2214                 if (audioCodecsSupportMono == 1) {
2215                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2216                         [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
2217                         action: NULL keyEquivalent: @""];
2218                     [menuItem setTag: hb_audio_mixdowns[0].amixdown];
2219                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
2220                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
2221                 }
2223                 /* do we want to add a stereo option? */
2224                 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
2225                 /* also offer stereo if we have a stereo-or-better source */
2226                 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO) {
2227                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2228                         [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
2229                         action: NULL keyEquivalent: @""];
2230                     [menuItem setTag: hb_audio_mixdowns[1].amixdown];
2231                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
2232                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
2233                 }
2235                 /* do we want to add a dolby surround (DPL1) option? */
2236                 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY) {
2237                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2238                         [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
2239                         action: NULL keyEquivalent: @""];
2240                     [menuItem setTag: hb_audio_mixdowns[2].amixdown];
2241                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
2242                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
2243                 }
2245                 /* do we want to add a dolby pro logic 2 (DPL2) option? */
2246                 if (layout == HB_INPUT_CH_LAYOUT_3F2R) {
2247                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2248                         [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
2249                         action: NULL keyEquivalent: @""];
2250                     [menuItem setTag: hb_audio_mixdowns[3].amixdown];
2251                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
2252                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
2253                 }
2255                 /* do we want to add a 6-channel discrete option? */
2256                 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE)) {
2257                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2258                         [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
2259                         action: NULL keyEquivalent: @""];
2260                     [menuItem setTag: hb_audio_mixdowns[4].amixdown];
2261                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
2262                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
2263                 }
2265                 /* auto-select the best mixdown based on our saved mixdown preference */
2266                 
2267                 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
2268                 /* ultimately this should be a prefs option */
2269                 int useMixdown;
2270                 
2271                 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
2272                 if (mixdownToUse > 0)
2273                 {
2274                     useMixdown = mixdownToUse;
2275                 }
2276                 else
2277                 {
2278                     useMixdown = HB_AMIXDOWN_DOLBYPLII;
2279                 }
2280                 
2281                 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
2282                 if (useMixdown > maxMixdownUsed) useMixdown = maxMixdownUsed;
2284                 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
2285                 if (useMixdown < minMixdownUsed) useMixdown = minMixdownUsed;
2287                 /* select the (possibly-amended) preferred mixdown */
2288                 [mixdownPopUp selectItemWithTag: useMixdown];
2289                                 
2290                                 /* lets call the AudioTrackMixdownChanged method here to determine appropriate bitrates, etc. */
2291                 [self AudioTrackMixdownChanged: NULL];
2292             }
2294         }
2295         
2296     }
2298         /* see if the new audio track choice will change the bitrate we need */
2299     [self CalculateBitrate: sender];    
2302 - (IBAction) AudioTrackMixdownChanged: (id) sender
2305     /* find out what the currently-selected output audio codec is */
2306     int format = [fDstFormatPopUp indexOfSelectedItem];
2307     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2308     int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2309     
2310     /* storage variable for the min and max bitrate allowed for this codec */
2311     int minbitrate;
2312     int maxbitrate;
2313     
2314     switch( acodec )
2315     {
2316         case HB_ACODEC_FAAC:
2317             /* check if we have a 6ch discrete conversion in either audio track */
2318             if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2319             {
2320                 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
2321                 minbitrate = 32;
2322                 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
2323                 maxbitrate = 384;
2324                 break;
2325             }
2326             else
2327             {
2328                 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
2329                 minbitrate = 32;
2330                 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
2331                 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
2332                 maxbitrate = 160;
2333                 break;
2334             }
2336         case HB_ACODEC_LAME:
2337             /* Lame is happy using our min bitrate of 32 kbps */
2338             minbitrate = 32;
2339             /* Lame won't encode if the bitrate is higher than 320 kbps */
2340             maxbitrate = 320;
2341             break;
2343         case HB_ACODEC_VORBIS:
2344             /* Vorbis causes a crash if we use a bitrate below 48 kbps */
2345             minbitrate = 48;
2346             /* Vorbis can cope with 384 kbps quite happily, even for stereo */
2347             maxbitrate = 384;
2348             break;
2350         default:
2351             /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
2352             minbitrate = 32;
2353             maxbitrate = 384;
2354         
2355     }
2357     [fAudBitratePopUp removeAllItems];
2359     for( int i = 0; i < hb_audio_bitrates_count; i++ )
2360     {
2361         if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
2362         {
2363             /* add a new menuitem for this bitrate */
2364             id<NSMenuItem> menuItem = [[fAudBitratePopUp menu] addItemWithTitle:
2365                 [NSString stringWithCString: hb_audio_bitrates[i].string]
2366                 action: NULL keyEquivalent: @""];
2367             /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
2368             [menuItem setTag: hb_audio_bitrates[i].rate];
2369         }
2370     }
2372     /* select the default bitrate (but use 384 for 6-ch AAC) */
2373     if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2374     {
2375         [fAudBitratePopUp selectItemWithTag: 384];
2376     }
2377     else
2378     {
2379         [fAudBitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
2380     }
2383 /* lets set the picture size back to the max from right after title scan
2384    Lets use an IBAction here as down the road we could always use a checkbox
2385    in the gui to easily take the user back to max. Remember, the compiler
2386    resolves IBActions down to -(void) during compile anyway */
2387 - (IBAction) RevertPictureSizeToMax: (id) sender
2389         hb_job_t * job = fTitle->job;
2390         /* We use the output picture width and height
2391         as calculated from libhb right after title is set
2392         in TitlePopUpChanged */
2393         job->width = PicOrigOutputWidth;
2394         job->height = PicOrigOutputHeight;
2395     [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
2396                 @"%d", 1]];
2397         /* Here we use the auto crop values determined right after scan */
2398         job->crop[0] = AutoCropTop;
2399         job->crop[1] = AutoCropBottom;
2400         job->crop[2] = AutoCropLeft;
2401         job->crop[3] = AutoCropRight;
2402                                 
2403                                 
2404                                 [self CalculatePictureSizing: sender];
2405                                 /* We call method method to change UI to reflect whether a preset is used or not*/    
2406                                 [self CustomSettingUsed: sender];
2410 /* Get and Display Current Pic Settings in main window */
2411 - (IBAction) CalculatePictureSizing: (id) sender
2413         
2415         [fPicSettingWidth setStringValue: [NSString stringWithFormat:
2416                 @"%d", fTitle->job->width]];
2417         [fPicSettingHeight setStringValue: [NSString stringWithFormat:
2418                 @"%d", fTitle->job->height]];
2419         [fPicSettingARkeep setStringValue: [NSString stringWithFormat:
2420                 @"%d", fTitle->job->keep_ratio]];                
2421         //[fPicSettingDeinterlace setStringValue: [NSString stringWithFormat:
2422         //      @"%d", fTitle->job->deinterlace]];
2423         [fPicSettingPAR setStringValue: [NSString stringWithFormat:
2424                 @"%d", fTitle->job->pixel_ratio]];
2425                 
2426         if (fTitle->job->pixel_ratio == 1)
2427         {
2428         int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
2429         int arpwidth = fTitle->job->pixel_aspect_width;
2430         int arpheight = fTitle->job->pixel_aspect_height;
2431         int displayparwidth = titlewidth * arpwidth / arpheight;
2432         int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
2433         [fPicSettingWidth setStringValue: [NSString stringWithFormat:
2434                 @"%d", titlewidth]];
2435         [fPicSettingHeight setStringValue: [NSString stringWithFormat:
2436                 @"%d", displayparheight]];
2437         [fPicLabelPAROutp setStringValue: @"Anamorphic Output:"];
2438         [fPicLabelPAROutputX setStringValue: @"x"];
2439     [fPicSettingPARWidth setStringValue: [NSString stringWithFormat:
2440         @"%d", displayparwidth]];
2441         [fPicSettingPARHeight setStringValue: [NSString stringWithFormat:
2442         @"%d", displayparheight]];
2444         fTitle->job->keep_ratio = 0;
2445         }
2446         else
2447         {
2448         [fPicLabelPAROutp setStringValue: @""];
2449         [fPicLabelPAROutputX setStringValue: @""];
2450         [fPicSettingPARWidth setStringValue: @""];
2451         [fPicSettingPARHeight setStringValue:  @""];
2452         }
2453         if ([fPicSettingDeinterlace intValue] == 0)
2454         {
2455         fTitle->job->deinterlace = 0;
2456         }
2457         else
2458         {
2459         fTitle->job->deinterlace = 1;
2460         }
2461                 
2462                                 
2463         /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */      
2464         if (fTitle->job->keep_ratio > 0)
2465         {
2466                 [fPicSettingARkeepDsply setStringValue: @"On"];
2467         }
2468         else
2469         {
2470                 [fPicSettingARkeepDsply setStringValue: @"Off"];
2471         }       
2472         /* Deinterlace */
2473         if ([fPicSettingDeinterlace intValue] == 0)
2474         {
2475                 [fPicSettingDeinterlaceDsply setStringValue: @"Off"];
2476         }
2477         else if ([fPicSettingDeinterlace intValue] == 1)
2478         {
2479                 [fPicSettingDeinterlaceDsply setStringValue: @"Fast"];
2480         }
2481         else if ([fPicSettingDeinterlace intValue] == 2)
2482         {
2483                 [fPicSettingDeinterlaceDsply setStringValue: @"Slow"];
2484         }
2485         else if ([fPicSettingDeinterlace intValue] == 3)
2486         {
2487                 [fPicSettingDeinterlaceDsply setStringValue: @"Slower"];
2488         }
2489         else if ([fPicSettingDeinterlace intValue] == 4)
2490         {
2491                 [fPicSettingDeinterlaceDsply setStringValue: @"Slowest"];
2492         }
2493         /* Denoise */
2494         if ([fPicSettingDenoise intValue] == 0)
2495         {
2496                 [fPicSettingDenoiseDsply setStringValue: @"Off"];
2497         }
2498         else if ([fPicSettingDenoise intValue] == 1)
2499         {
2500                 [fPicSettingDenoiseDsply setStringValue: @"Weak"];
2501         }
2502         else if ([fPicSettingDenoise intValue] == 2)
2503         {
2504                 [fPicSettingDenoiseDsply setStringValue: @"Medium"];
2505         }
2506         else if ([fPicSettingDenoise intValue] == 3)
2507         {
2508                 [fPicSettingDenoiseDsply setStringValue: @"Strong"];
2509         }
2510         
2511         if (fTitle->job->pixel_ratio > 0)
2512         {
2513                 [fPicSettingPARDsply setStringValue: @"On"];
2514         }
2515         else
2516         {
2517                 [fPicSettingPARDsply setStringValue: @"Off"];
2518         }
2519         /* Set the display field for crop as per boolean */
2520         if ([[fPicSettingAutoCrop stringValue] isEqualToString: @"0"])
2521         {
2522             [fPicSettingAutoCropDsply setStringValue: @"Custom"];
2523         }
2524         else
2525         {
2526                 [fPicSettingAutoCropDsply setStringValue: @"Auto"];
2527         }       
2528         /* check video framerate and turn off detelecine if necessary */
2529         if (fTitle->rate_base == 1126125 || [[fVidRatePopUp titleOfSelectedItem] isEqualToString: @"23.976 (NTSC Film)"])
2530         {
2531                 [fPicSettingDetelecine setStringValue: @"No"];
2532         }
2533         
2534         
2535         
2536         /* below will trigger the preset, if selected, to be
2537         changed to "Custom". Lets comment out for now until
2538         we figure out a way to determine if the picture values
2539         changed modify the preset values */     
2540         //[self CustomSettingUsed: sender];
2543 - (IBAction) CalculateBitrate: (id) sender
2545     if( !fHandle || [fVidQualityMatrix selectedRow] != 0 )
2546     {
2547         return;
2548     }
2550     hb_list_t  * list  = hb_get_titles( fHandle );
2551     hb_title_t * title = (hb_title_t *) hb_list_item( list,
2552             [fSrcTitlePopUp indexOfSelectedItem] );
2553     hb_job_t * job = title->job;
2555     [self PrepareJob];
2557     [fVidBitrateField setIntValue: hb_calc_bitrate( job,
2558             [fVidTargetSizeField intValue] )];
2559                         
2560                         
2563 /* Method to determine if we should change the UI
2564 To reflect whether or not a Preset is being used or if
2565 the user is using "Custom" settings by determining the sender*/
2566 - (IBAction) CustomSettingUsed: (id) sender
2568         if ([sender stringValue] != NULL)
2569         {
2570                 /* Deselect the currently selected Preset if there is one*/
2571                 [tableView deselectRow:[tableView selectedRow]];
2572                 [[fPresetsActionMenu itemAtIndex:0] setEnabled: NO];
2573                 /* Change UI to show "Custom" settings are being used */
2574                 [fPresetSelectedDisplay setStringValue: @"Custom"];
2575                 
2576                 curUserPresetChosenNum = nil;
2578                 
2579         }
2583 - (IBAction) X264AdvancedOptionsSet: (id) sender
2585     /*Set opt widget values here*/
2586     
2587     /*B-Frames fX264optBframesPopUp*/
2588     int i;
2589     [fX264optBframesPopUp removeAllItems];
2590     [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
2591     for (i=0; i<17;i++)
2592     {
2593         [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2594     }
2595     
2596     /*Reference Frames fX264optRefPopUp*/
2597     [fX264optRefPopUp removeAllItems];
2598     [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
2599     for (i=0; i<17;i++)
2600     {
2601         [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2602     }
2603     
2604     /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
2605     [fX264optNfpskipSwitch setState:0];
2606     
2607     /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
2608     [fX264optNodctdcmtSwitch setState:0];    
2610     /*Sub Me fX264optSubmePopUp*/
2611     [fX264optSubmePopUp removeAllItems];
2612     [fX264optSubmePopUp addItemWithTitle:@"Default (4)"];
2613     for (i=0; i<8;i++)
2614     {
2615         [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2616     }
2617     
2618     /*Trellis fX264optTrellisPopUp*/
2619     [fX264optTrellisPopUp removeAllItems];
2620     [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
2621     for (i=0; i<3;i++)
2622     {
2623         [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2624     }
2625     
2626     /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
2627     [fX264optMixedRefsSwitch setState:0];
2628     
2629     /*Motion Estimation fX264optMotionEstPopUp*/
2630     [fX264optMotionEstPopUp removeAllItems];
2631     [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
2632     [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
2633     [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
2634     [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
2635     [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
2636     
2637     /*Motion Estimation range fX264optMERangePopUp*/
2638     [fX264optMERangePopUp removeAllItems];
2639     [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
2640     for (i=4; i<65;i++)
2641     {
2642         [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2643     }
2644     
2645     /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
2646     [fX264optWeightBSwitch setState:0];
2647     
2648     /*B-Frame Rate Distortion Optimization fX264optBRDOSwitch BOOLEAN*/
2649     [fX264optBRDOSwitch setState:0];
2650     
2651     /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
2652     [fX264optBPyramidSwitch setState:0];
2653     
2654     /*Bidirectional Motion Estimation Refinement fX264optBiMESwitch BOOLEAN*/
2655     [fX264optBiMESwitch setState:0];
2656     
2657     /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
2658     [fX264optDirectPredPopUp removeAllItems];
2659     [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
2660     [fX264optDirectPredPopUp addItemWithTitle:@"None"];
2661     [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
2662     [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
2663     [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
2664     
2665     /*Alpha Deblock*/
2666     [fX264optAlphaDeblockPopUp removeAllItems];
2667     [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
2668     for (i=-6; i<7;i++)
2669     {
2670         [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2671     }
2672     
2673     /*Beta Deblock*/
2674     [fX264optBetaDeblockPopUp removeAllItems];
2675     [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
2676     for (i=-6; i<7;i++)
2677     {
2678         [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2679     }     
2680     
2681     /* Analysis fX264optAnalysePopUp */
2682     [fX264optAnalysePopUp removeAllItems];
2683     [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
2684     [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
2685     [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
2686     
2687     /* 8x8 DCT fX264op8x8dctSwitch */
2688     [fX264opt8x8dctSwitch setState:0];
2689     
2690     /* CABAC fX264opCabacSwitch */
2691     [fX264optCabacSwitch setState:1];
2693     /* Standardize the option string */
2694     [self X264AdvancedOptionsStandardizeOptString: NULL];
2695     /* Set Current GUI Settings based on newly standardized string */
2696     [self X264AdvancedOptionsSetCurrentSettings: NULL];
2699 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
2701     /* Set widgets depending on the opt string in field */
2702     NSString * thisOpt; // The separated option such as "bframes=3"
2703     NSString * optName = @""; // The option name such as "bframes"
2704     NSString * optValue = @"";// The option value such as "3"
2705     NSString * changedOptString = @"";
2706     NSArray *currentOptsArray;
2708     /*First, we get an opt string to process */
2709     NSString *currentOptString = [fDisplayX264Options stringValue];
2711     /*verify there is an opt string to process */
2712     NSRange currentOptRange = [currentOptString rangeOfString:@"="];
2713     if (currentOptRange.location != NSNotFound)
2714     {
2715         /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
2716         currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
2718         /*iterate through the array and get <opts> and <values*/
2719         //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
2720         int loopcounter;
2721         int currentOptsArrayCount = [currentOptsArray count];
2722         for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
2723         {
2724             thisOpt = [currentOptsArray objectAtIndex:loopcounter];
2725             
2726             NSRange splitOptRange = [thisOpt rangeOfString:@"="];
2727             if (splitOptRange.location != NSNotFound)
2728             {
2729                 optName = [thisOpt substringToIndex:splitOptRange.location];
2730                 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
2731                 
2732                 /* Standardize the names here depending on whats in the string */
2733                 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
2734                 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];        
2735             }
2736             else // No value given so we use a default of "1"
2737             {
2738                 optName = thisOpt;
2739                 /* Standardize the names here depending on whats in the string */
2740                 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
2741                 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
2742             }
2743             
2744             /* Construct New String for opts here */
2745             if ([thisOpt isEqualToString:@""])
2746             {
2747                 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
2748             }
2749             else
2750             {
2751                 if ([changedOptString isEqualToString:@""])
2752                 {
2753                     changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
2754                 }
2755                 else
2756                 {
2757                     changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
2758                 }
2759             }
2760         }
2761     }
2762     
2763     /* Change the option string to reflect the new standardized option string */
2764     [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
2767 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
2769     if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
2770     {
2771         cleanOptNameString = @"ref";
2772     }
2773     
2774     /*No Fast PSkip nofast_pskip*/
2775     if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
2776     {
2777         cleanOptNameString = @"no-fast-pskip";
2778     }
2779     
2780     /*No Dict Decimate*/
2781     if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
2782     {
2783         cleanOptNameString = @"no-dct-decimate";
2784     }
2785     
2786     /*Subme*/
2787     if ([cleanOptNameString isEqualToString:@"subme"])
2788     {
2789         cleanOptNameString = @"subq";
2790     }
2791     
2792     /*ME Range*/
2793     if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
2794         cleanOptNameString = @"merange";
2795     
2796     /*WeightB*/
2797     if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
2798     {
2799         cleanOptNameString = @"weightb";
2800     }
2801     
2802     /*BRDO*/
2803     if ([cleanOptNameString isEqualToString:@"b-rdo"] || [cleanOptNameString isEqualToString:@"b_rdo"])
2804     {
2805         cleanOptNameString = @"brdo";
2806     }
2807     
2808     /*B Pyramid*/
2809     if ([cleanOptNameString isEqualToString:@"b_pyramid"])
2810     {
2811         cleanOptNameString = @"b-pyramid";
2812     }
2813     
2814     /*Direct Prediction*/
2815     if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
2816     {
2817         cleanOptNameString = @"direct";
2818     }
2819     
2820     /*Deblocking*/
2821     if ([cleanOptNameString isEqualToString:@"filter"])
2822     {
2823         cleanOptNameString = @"deblock";
2824     }
2826     /*Analysis*/
2827     if ([cleanOptNameString isEqualToString:@"partitions"])
2828     {
2829         cleanOptNameString = @"analyse";
2830     }
2832         
2833     return cleanOptNameString;  
2836 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
2838     /* Set widgets depending on the opt string in field */
2839     NSString * thisOpt; // The separated option such as "bframes=3"
2840     NSString * optName = @""; // The option name such as "bframes"
2841     NSString * optValue = @"";// The option value such as "3"
2842     NSArray *currentOptsArray;
2843     
2844     /*First, we get an opt string to process */
2845     //NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
2846     NSString *currentOptString = [fDisplayX264Options stringValue];
2847     
2848     /*verify there is an opt string to process */
2849     NSRange currentOptRange = [currentOptString rangeOfString:@"="];
2850     if (currentOptRange.location != NSNotFound)
2851     {
2852         /* lets clean the opt string here to standardize any names*/
2853         /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
2854         currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
2855         
2856         /*iterate through the array and get <opts> and <values*/
2857         //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
2858         int loopcounter;
2859         int currentOptsArrayCount = [currentOptsArray count];
2860         
2861         /*iterate through the array and get <opts> and <values*/
2862         for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
2863         {
2864             thisOpt = [currentOptsArray objectAtIndex:loopcounter];
2865             NSRange splitOptRange = [thisOpt rangeOfString:@"="];
2866             
2867             if (splitOptRange.location != NSNotFound)
2868             {
2869                 optName = [thisOpt substringToIndex:splitOptRange.location];
2870                 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
2871            
2872                 /*Run through the available widgets for x264 opts and set them, as you add widgets, 
2873                 they need to be added here. This should be moved to its own method probably*/
2874            
2875                 /*bframes NSPopUpButton*/
2876                 if ([optName isEqualToString:@"bframes"])
2877                 {
2878                     [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
2879                 }
2880                 /*ref NSPopUpButton*/
2881                 if ([optName isEqualToString:@"ref"])
2882                 {
2883                    [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
2884                 }
2885                 /*No Fast PSkip NSPopUpButton*/
2886                 if ([optName isEqualToString:@"no-fast-pskip"])
2887                 {
2888                     [fX264optNfpskipSwitch setState:[optValue intValue]];
2889                 }
2890                 /*No Dict Decimate NSPopUpButton*/
2891                 if ([optName isEqualToString:@"no-dct-decimate"])
2892                 {
2893                     [fX264optNodctdcmtSwitch setState:[optValue intValue]];
2894                 }
2895                 /*Sub Me NSPopUpButton*/
2896                 if ([optName isEqualToString:@"subq"])
2897                 {
2898                     [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
2899                 }
2900                 /*Trellis NSPopUpButton*/
2901                 if ([optName isEqualToString:@"trellis"])
2902                 {
2903                     [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
2904                 }
2905                 /*Mixed Refs NSButton*/
2906                 if ([optName isEqualToString:@"mixed-refs"])
2907                 {
2908                     [fX264optMixedRefsSwitch setState:[optValue intValue]];
2909                 }
2910                 /*Motion Estimation NSPopUpButton*/
2911                 if ([optName isEqualToString:@"me"])
2912                 {
2913                     if ([optValue isEqualToString:@"dia"])
2914                         [fX264optMotionEstPopUp selectItemAtIndex:1];
2915                     else if ([optValue isEqualToString:@"hex"])
2916                         [fX264optMotionEstPopUp selectItemAtIndex:2];
2917                     else if ([optValue isEqualToString:@"umh"])
2918                         [fX264optMotionEstPopUp selectItemAtIndex:3];
2919                     else if ([optValue isEqualToString:@"esa"])
2920                         [fX264optMotionEstPopUp selectItemAtIndex:4];                        
2921                 }
2922                 /*ME Range NSPopUpButton*/
2923                 if ([optName isEqualToString:@"merange"])
2924                 {
2925                     [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
2926                 }
2927                 /*Weighted B-Frames NSPopUpButton*/
2928                 if ([optName isEqualToString:@"weightb"])
2929                 {
2930                     [fX264optWeightBSwitch setState:[optValue intValue]];
2931                 }
2932                 /*BRDO NSPopUpButton*/
2933                 if ([optName isEqualToString:@"brdo"])
2934                 {
2935                     [fX264optBRDOSwitch setState:[optValue intValue]];
2936                 }
2937                 /*B Pyramid NSPopUpButton*/
2938                 if ([optName isEqualToString:@"b-pyramid"])
2939                 {
2940                     [fX264optBPyramidSwitch setState:[optValue intValue]];
2941                 }
2942                 /*Bidirectional Motion Estimation Refinement NSPopUpButton*/
2943                 if ([optName isEqualToString:@"bime"])
2944                 {
2945                     [fX264optBiMESwitch setState:[optValue intValue]];
2946                 }
2947                 /*Direct B-frame Prediction NSPopUpButton*/
2948                 if ([optName isEqualToString:@"direct"])
2949                 {
2950                     if ([optValue isEqualToString:@"none"])
2951                         [fX264optDirectPredPopUp selectItemAtIndex:1];
2952                     else if ([optValue isEqualToString:@"spatial"])
2953                         [fX264optDirectPredPopUp selectItemAtIndex:2];
2954                     else if ([optValue isEqualToString:@"temporal"])
2955                         [fX264optDirectPredPopUp selectItemAtIndex:3];
2956                     else if ([optValue isEqualToString:@"auto"])
2957                         [fX264optDirectPredPopUp selectItemAtIndex:4];                        
2958                 }
2959                 /*Deblocking NSPopUpButtons*/
2960                 if ([optName isEqualToString:@"deblock"])
2961                 {
2962                     NSString * alphaDeblock = @"";
2963                     NSString * betaDeblock = @"";
2964                 
2965                     NSRange splitDeblock = [optValue rangeOfString:@","];
2966                     alphaDeblock = [optValue substringToIndex:splitDeblock.location];
2967                     betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
2968                     
2969                     if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
2970                     {
2971                         [fX264optAlphaDeblockPopUp selectItemAtIndex:0];                        
2972                         [fX264optBetaDeblockPopUp selectItemAtIndex:0];                               
2973                     }
2974                     else
2975                     {
2976                         if (![alphaDeblock isEqualToString:@"0"])
2977                         {
2978                             [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
2979                         }
2980                         else
2981                         {
2982                             [fX264optAlphaDeblockPopUp selectItemAtIndex:7];                        
2983                         }
2984                         
2985                         if (![betaDeblock isEqualToString:@"0"])
2986                         {
2987                             [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
2988                         }
2989                         else
2990                         {
2991                             [fX264optBetaDeblockPopUp selectItemAtIndex:7];                        
2992                         }
2993                     }
2994                 }
2995                 /* Analysis NSPopUpButton */
2996                 if ([optName isEqualToString:@"analyse"])
2997                 {
2998                     if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
2999                     {
3000                         [fX264optAnalysePopUp selectItemAtIndex:0];
3001                     }
3002                     if ([optValue isEqualToString:@"none"])
3003                     {
3004                         [fX264optAnalysePopUp selectItemAtIndex:1];
3005                     }
3006                     if ([optValue isEqualToString:@"all"])
3007                     {
3008                         [fX264optAnalysePopUp selectItemAtIndex:2];
3009                     }
3010                 }
3011                 /* 8x8 DCT NSButton */
3012                 if ([optName isEqualToString:@"8x8dct"])
3013                 {
3014                     [fX264opt8x8dctSwitch setState:[optValue intValue]];
3015                 }
3016                 /* CABAC NSButton */
3017                 if ([optName isEqualToString:@"cabac"])
3018                 {
3019                     [fX264optCabacSwitch setState:[optValue intValue]];
3020                 }                                                                 
3021             }
3022         }
3023     }
3026 - (IBAction) X264AdvancedOptionsChanged: (id) sender
3028     /*Determine which outlet is being used and set optName to process accordingly */
3029     NSString * optNameToChange = @""; // The option name such as "bframes"
3031     if (sender == fX264optBframesPopUp)
3032     {
3033         optNameToChange = @"bframes";
3034     }
3035     if (sender == fX264optRefPopUp)
3036     {
3037         optNameToChange = @"ref";
3038     }
3039     if (sender == fX264optNfpskipSwitch)
3040     {
3041         optNameToChange = @"no-fast-pskip";
3042     }
3043     if (sender == fX264optNodctdcmtSwitch)
3044     {
3045         optNameToChange = @"no-dct-decimate";
3046     }
3047     if (sender == fX264optSubmePopUp)
3048     {
3049         optNameToChange = @"subq";
3050     }
3051     if (sender == fX264optTrellisPopUp)
3052     {
3053         optNameToChange = @"trellis";
3054     }
3055     if (sender == fX264optMixedRefsSwitch)
3056     {
3057         optNameToChange = @"mixed-refs";
3058     }
3059     if (sender == fX264optMotionEstPopUp)
3060     {
3061         optNameToChange = @"me";
3062     }
3063     if (sender == fX264optMERangePopUp)
3064     {
3065         optNameToChange = @"merange";
3066     }
3067     if (sender == fX264optWeightBSwitch)
3068     {
3069         optNameToChange = @"weightb";
3070     }
3071     if (sender == fX264optBRDOSwitch)
3072     {
3073         optNameToChange = @"brdo";
3074     }
3075     if (sender == fX264optBPyramidSwitch)
3076     {
3077         optNameToChange = @"b-pyramid";
3078     }
3079     if (sender == fX264optBiMESwitch)
3080     {
3081         optNameToChange = @"bime";
3082     }
3083     if (sender == fX264optDirectPredPopUp)
3084     {
3085         optNameToChange = @"direct";
3086     }
3087     if (sender == fX264optAlphaDeblockPopUp)
3088     {
3089         optNameToChange = @"deblock";
3090     }
3091     if (sender == fX264optBetaDeblockPopUp)
3092     {
3093         optNameToChange = @"deblock";
3094     }        
3095     if (sender == fX264optAnalysePopUp)
3096     {
3097         optNameToChange = @"analyse";
3098     }
3099     if (sender == fX264opt8x8dctSwitch)
3100     {
3101         optNameToChange = @"8x8dct";
3102     }
3103     if (sender == fX264optCabacSwitch)
3104     {
3105         optNameToChange = @"cabac";
3106     }
3107     
3108     /* Set widgets depending on the opt string in field */
3109     NSString * thisOpt; // The separated option such as "bframes=3"
3110     NSString * optName = @""; // The option name such as "bframes"
3111     NSString * optValue = @"";// The option value such as "3"
3112     NSArray *currentOptsArray;
3114     /*First, we get an opt string to process */
3115     //EXAMPLE: NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
3116     NSString *currentOptString = [fDisplayX264Options stringValue];
3118     /*verify there is an occurrence of the opt specified by the sender to change */
3119     /*take care of any multi-value opt names here. This is extremely kludgy, but test for functionality
3120     and worry about pretty later */
3121         
3122         /*First, we create a pattern to check for ":"optNameToChange"=" to modify the option if the name falls after
3123         the first character of the opt string (hence the ":") */
3124         NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
3125     NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
3126         /*Then we create a pattern to check for "<beginning of line>"optNameToChange"=" to modify the option to
3127         see if the name falls at the beginning of the line, where we would not have the ":" as a pattern to test against*/
3128         NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
3129     NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
3130     if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
3131     {
3132         /* Create new empty opt string*/
3133         NSString *changedOptString = @"";
3135         /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
3136         currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
3138         /*iterate through the array and get <opts> and <values*/
3139         int loopcounter;
3140         int currentOptsArrayCount = [currentOptsArray count];
3141         for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
3142         {
3143             thisOpt = [currentOptsArray objectAtIndex:loopcounter];
3144             NSRange splitOptRange = [thisOpt rangeOfString:@"="];
3146             if (splitOptRange.location != NSNotFound)
3147             {
3148                 optName = [thisOpt substringToIndex:splitOptRange.location];
3149                 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
3150                 
3151                 /*Run through the available widgets for x264 opts and set them, as you add widgets, 
3152                 they need to be added here. This should be moved to its own method probably*/
3153                 
3154                 /*If the optNameToChange is found, appropriately change the value or delete it if
3155                 "Unspecified" is set.*/
3156                 if ([optName isEqualToString:optNameToChange])
3157                 {
3158                     if ([optNameToChange isEqualToString:@"deblock"])
3159                     {
3160                         if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
3161                         {
3162                             thisOpt = @"";                                
3163                         }
3164                         else
3165                         {
3166                             thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
3167                         }
3168                     }
3169                     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"] )
3170                     {
3171                         if ([sender state] == 0)
3172                         {
3173                             thisOpt = @"";
3174                         }
3175                         else
3176                         {
3177                             thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
3178                         }
3179                     }
3180                     else if ([optNameToChange isEqualToString:@"cabac"])
3181                     {
3182                         if ([sender state] == 1)
3183                         {
3184                             thisOpt = @"";
3185                         }
3186                         else
3187                         {
3188                             thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
3189                         }
3190                     }                                        
3191                     else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
3192                     {
3193                         thisOpt = @"";
3194                     }
3195                     else if ([optNameToChange isEqualToString:@"me"])
3196                     {
3197                         switch ([sender indexOfSelectedItem])
3198                         {   
3199                             case 1:
3200                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
3201                                break;
3203                             case 2:
3204                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
3205                                break;
3207                             case 3:
3208                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
3209                                break;
3211                             case 4:
3212                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
3213                                break;
3214                             
3215                             default:
3216                                 break;
3217                         }
3218                     }
3219                     else if ([optNameToChange isEqualToString:@"direct"])
3220                     {
3221                         switch ([sender indexOfSelectedItem])
3222                         {   
3223                             case 1:
3224                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
3225                                break;
3227                             case 2:
3228                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
3229                                break;
3231                             case 3:
3232                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
3233                                break;
3235                             case 4:
3236                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
3237                                break;
3238                             
3239                             default:
3240                                 break;
3241                         }
3242                     }
3243                     else if ([optNameToChange isEqualToString:@"analyse"])
3244                     {
3245                         switch ([sender indexOfSelectedItem])
3246                         {   
3247                             case 1:
3248                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
3249                                break;
3251                             case 2:
3252                                thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
3253                                break;
3254                             
3255                             default:
3256                                 break;
3257                         }
3258                     }
3259                     else if ([optNameToChange isEqualToString:@"merange"])
3260                     {
3261                         thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
3262                     }
3263                     else // we have a valid value to change, so change it
3264                     {
3265                         thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
3266                     }
3267                 }
3268             }
3270             /* Construct New String for opts here */
3271             if ([thisOpt isEqualToString:@""])
3272             {
3273                 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
3274             }
3275             else
3276             {
3277                 if ([changedOptString isEqualToString:@""])
3278                 {
3279                     changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
3280                 }
3281                 else
3282                 {
3283                     changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
3284                 }
3285             }
3286         }
3288         /* Change the option string to reflect the new mod settings */
3289         [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];      
3290     }
3291     else // if none exists, add it to the string
3292     {
3293         if ([[fDisplayX264Options stringValue] isEqualToString: @""])
3294         {
3295             if ([optNameToChange isEqualToString:@"me"])
3296             {
3297                 switch ([sender indexOfSelectedItem])
3298                 {   
3299                     case 1:
3300                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3301                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
3302                         break;
3303                
3304                     case 2:
3305                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3306                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
3307                         break;
3308                
3309                    case 3:
3310                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3311                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
3312                         break;
3313                
3314                    case 4:
3315                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3316                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
3317                         break;
3318                    
3319                    default:
3320                         break;
3321                 }
3322             }
3323             else if ([optNameToChange isEqualToString:@"direct"])
3324             {
3325                 switch ([sender indexOfSelectedItem])
3326                 {   
3327                     case 1:
3328                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3329                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3330                         break;
3331                
3332                     case 2:
3333                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3334                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
3335                         break;
3336                
3337                    case 3:
3338                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3339                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
3340                         break;
3341                
3342                    case 4:
3343                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3344                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
3345                         break;
3346                    
3347                    default:
3348                         break;
3349                 }
3350             }
3351             else if ([optNameToChange isEqualToString:@"analyse"])
3352             {
3353                 switch ([sender indexOfSelectedItem])
3354                 {   
3355                     case 1:
3356                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3357                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3358                         break;
3359                
3360                     case 2:
3361                         [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3362                             [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
3363                         break;
3364                    
3365                    default:
3366                         break;
3367                 }
3368             }
3370             else if ([optNameToChange isEqualToString:@"merange"])
3371             {
3372                 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3373                     [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
3374             }
3375             else if ([optNameToChange isEqualToString:@"deblock"])
3376             {
3377                 [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]]];                
3378             }
3379             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"] )            {
3380                 if ([sender state] == 0)
3381                 {
3382                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];                    
3383                 }
3384                 else
3385                 {
3386                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3387                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3388                 }
3389             }
3390             else if ([optNameToChange isEqualToString:@"cabac"])
3391             {
3392                 if ([sender state] == 1)
3393                 {
3394                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];                                        
3395                 }
3396                 else
3397                 {
3398                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3399                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];                    
3400                 }
3401             }            
3402             else
3403             {
3404                 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", 
3405                     [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
3406             }
3407         }
3408         else
3409         {
3410             if ([optNameToChange isEqualToString:@"me"])
3411             {
3412                 switch ([sender indexOfSelectedItem])
3413                 {   
3414                     case 1:
3415                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3416                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3417                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
3418                          break;
3420                     case 2:
3421                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3422                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3423                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
3424                          break;
3426                     case 3:
3427                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3428                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3429                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
3430                          break;
3432                     case 4:
3433                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3434                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3435                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
3436                          break;
3438                     default:
3439                          break;
3440                 }
3441             }
3442             else if ([optNameToChange isEqualToString:@"direct"])
3443             {
3444                 switch ([sender indexOfSelectedItem])
3445                 {   
3446                     case 1:
3447                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3448                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3449                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3450                          break;
3452                     case 2:
3453                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3454                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3455                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
3456                          break;
3458                     case 3:
3459                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3460                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3461                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
3462                          break;
3464                     case 4:
3465                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3466                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3467                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
3468                          break;
3470                     default:
3471                          break;
3472                 }
3473             }
3474             else if ([optNameToChange isEqualToString:@"analyse"])
3475             {
3476                 switch ([sender indexOfSelectedItem])
3477                 {   
3478                     case 1:
3479                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3480                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3481                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3482                          break;
3484                     case 2:
3485                          [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", 
3486                              [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3487                              [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
3488                          break;
3490                     default:
3491                          break;
3492                 }
3493             }
3495             else if ([optNameToChange isEqualToString:@"merange"])
3496             {
3497                 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
3498                     [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
3499             }
3500             else if ([optNameToChange isEqualToString:@"deblock"])
3501             {
3502                 [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]]];                
3503             }
3504             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"] )
3505             {
3506                 if ([sender state] == 0)
3507                 {
3508                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];                    
3509                 }
3510                 else
3511                 {
3512                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
3513                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];                
3514                 }
3515             }
3516             else if ([optNameToChange isEqualToString:@"cabac"])
3517             {
3518                 if ([sender state] == 1)
3519                 {
3520                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];                    
3521                 }
3522                 else
3523                 {
3524                     [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
3525                         [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3526                 }
3527             }
3528             else
3529             {
3530                 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]], 
3531                     [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
3532             }
3533         }
3534     }
3536     /* We now need to reset the opt widgets since we changed some stuff */              
3537     [self X264AdvancedOptionsSet:NULL];         
3541    /* We use this method to recreate new, updated factory
3542    presets */
3543 - (IBAction)AddFactoryPresets:(id)sender
3545     /* First, we delete any existing built in presets */
3546     [self DeleteFactoryPresets: sender];
3547     /* Then, we re-create new built in presets programmatically CreateIpodOnlyPreset*/
3548     [UserPresets addObject:[self CreateNormalPreset]];
3549     [UserPresets addObject:[self CreateClassicPreset]];
3550     [UserPresets addObject:[self CreateQuickTimePreset]];
3551         [UserPresets addObject:[self CreateIpodLowPreset]];
3552         [UserPresets addObject:[self CreateIpodHighPreset]];
3553         [UserPresets addObject:[self CreateAppleTVPreset]];
3554     [UserPresets addObject:[self CreateiPhonePreset]];
3555         [UserPresets addObject:[self CreatePSThreePreset]];
3556         [UserPresets addObject:[self CreatePSPPreset]];
3557         [UserPresets addObject:[self CreateFilmPreset]];
3558     [UserPresets addObject:[self CreateTelevisionPreset]];
3559     [UserPresets addObject:[self CreateAnimationPreset]];
3560     [UserPresets addObject:[self CreateBedlamPreset]];
3561     [UserPresets addObject:[self CreateDeuxSixQuatrePreset]];
3562     [UserPresets addObject:[self CreateBrokePreset]];
3563     [UserPresets addObject:[self CreateBlindPreset]];
3564     [UserPresets addObject:[self CreateCRFPreset]];
3565     
3566     [self AddPreset];
3568 - (IBAction)DeleteFactoryPresets:(id)sender
3570     //int status;
3571     NSEnumerator *enumerator = [UserPresets objectEnumerator];
3572         id tempObject;
3573     
3574         //NSNumber *index;
3575     NSMutableArray *tempArray;
3578         tempArray = [NSMutableArray array];
3579         /* we look here to see if the preset is we move on to the next one */
3580         while ( tempObject = [enumerator nextObject] )  
3581                 {
3582                         /* if the preset is "Factory" then we put it in the array of
3583                         presets to delete */
3584                         if ([[tempObject objectForKey:@"Type"] intValue] == 0)
3585                         {
3586                                 [tempArray addObject:tempObject];
3587                         }
3588         }
3589         
3590         [UserPresets removeObjectsInArray:tempArray];
3591         [tableView reloadData];
3592         [self savePreset];   
3596 - (IBAction) ShowAddPresetPanel: (id) sender
3598     /* Deselect the currently selected Preset if there is one*/
3599                 [tableView deselectRow:[tableView selectedRow]];
3601         /* Populate the preset picture settings popup here */
3602         [fPresetNewPicSettingsPopUp removeAllItems];
3603         [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
3604         [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
3605         [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
3606         [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];      
3607         
3608                 /* Erase info from the input fields fPresetNewDesc*/
3609         [fPresetNewName setStringValue: @""];
3610         [fPresetNewDesc setStringValue: @""];
3611         /* Show the panel */
3612         [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow
3613         modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
3614     [NSApp runModalForWindow: fAddPresetPanel];
3615     [NSApp endSheet: fAddPresetPanel];
3616     [fAddPresetPanel orderOut: self];
3617         
3618         
3620 - (IBAction) CloseAddPresetPanel: (id) sender
3622         [NSApp stopModal];
3626 - (IBAction)AddUserPreset:(id)sender
3629     /* Here we create a custom user preset */
3630         [UserPresets addObject:[self CreatePreset]];
3631         /* Erase info from the input fields */
3632         [fPresetNewName setStringValue: @""];
3633         [fPresetNewDesc setStringValue: @""];
3634         /* We stop the modal window for the new preset */
3635         [NSApp stopModal];
3636     [self AddPreset];
3637         
3640 - (void)AddPreset
3643         
3644         /* We Sort the Presets By Factory or Custom */
3645         NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type" 
3646                                                     ascending:YES] autorelease];
3647         /* We Sort the Presets Alphabetically by name */
3648         NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
3649                                                     ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
3650         NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
3651         NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
3652         [UserPresets setArray:sortedArray];
3653         
3654         
3655         /* We Reload the New Table data for presets */
3656     [tableView reloadData];
3657    /* We save all of the preset data here */
3658     [self savePreset];
3661 - (IBAction)InsertPreset:(id)sender
3663     int index = [tableView selectedRow];
3664     [UserPresets insertObject:[self CreatePreset] atIndex:index];
3665     [tableView reloadData];
3666     [self savePreset];
3669 - (NSDictionary *)CreatePreset
3671     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3672         /* Get the New Preset Name from the field in the AddPresetPanel */
3673     [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
3674         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3675         [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
3676         /*Set whether or not this is default, at creation set to 0*/
3677         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3678         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3679         [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
3680         /* Get New Preset Description from the field in the AddPresetPanel*/
3681         [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
3682         /* File Format */
3683     [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
3684         /* Chapter Markers fCreateChapterMarkers*/
3685         [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
3686         /* Allow Mpeg4 64 bit formatting +4GB file sizes */
3687         [preset setObject:[NSNumber numberWithInt:[fDstMpgLargeFileCheck state]] forKey:@"Mp4LargeFile"];
3688         /* Codecs */
3689         [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
3690         /* Video encoder */
3691         [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
3692         /* x264 Option String */
3693         [preset setObject:[fDisplayX264Options stringValue] forKey:@"x264Option"];
3694         
3695         [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
3696         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3697         [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
3698         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3699         
3700         /* Video framerate */
3701         [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
3702         /* GrayScale */
3703         [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
3704         /* 2 Pass Encoding */
3705         [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
3706         /* Turbo 2 pass Encoding fVidTurboPassCheck*/
3707         [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
3708         /*Picture Settings*/
3709         hb_job_t * job = fTitle->job;
3710         /* Basic Picture Settings */
3711         /* Use Max Picture settings for whatever the dvd is.*/
3712         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3713         [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
3714         [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
3715         [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
3716         [preset setObject:[NSNumber numberWithInt:[fPicSettingDeinterlace intValue]] forKey:@"PictureDeinterlace"];
3717         [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
3718         [preset setObject:[fPicSettingDetelecine stringValue] forKey:@"PictureDetelecine"];
3719         [preset setObject:[NSNumber numberWithInt:[fPicSettingDenoise intValue]] forKey:@"PictureDenoise"]; 
3720         /* Set crop settings here */
3721         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3722         [preset setObject:[NSNumber numberWithInt:[fPicSettingAutoCrop intValue]] forKey:@"PictureAutoCrop"];
3724         [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
3725     [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
3726         [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
3727         [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
3728         
3729         /*Audio*/
3730         /* Audio Sample Rate*/
3731         [preset setObject:[fAudRatePopUp titleOfSelectedItem] forKey:@"AudioSampleRate"];
3732         /* Audio Bitrate Rate*/
3733         [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
3734         /* Subtitles*/
3735         [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
3736         
3738     [preset autorelease];
3739     return preset;
3743 - (NSDictionary *)CreateIpodLowPreset
3745     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3746         /* Get the New Preset Name from the field in the AddPresetPanel */
3747     [preset setObject:@"iPod Low-Rez" forKey:@"PresetName"];
3748         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3749         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3750         /*Set whether or not this is default, at creation set to 0*/
3751         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3752         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3753         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3754         /* Get the New Preset Description from the field in the AddPresetPanel */
3755     [preset setObject:@"HandBrake's low resolution settings for the iPod. Optimized for great playback on the iPod screen, with smaller file size." forKey:@"PresetDescription"];
3756         /* File Format */
3757     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3758         /* Chapter Markers*/
3759          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3760     /* Codecs */
3761         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3762         /* Video encoder */
3763         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3764         /* x264 Option String */
3765         [preset setObject:@"keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1" forKey:@"x264Option"];
3766         /* Video quality */
3767         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3768         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3769         [preset setObject:@"700" forKey:@"VideoAvgBitrate"];
3770         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3771         
3772         /* Video framerate */
3773         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3774         /* GrayScale */
3775         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3776         /* 2 Pass Encoding */
3777         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3778         
3779         /*Picture Settings*/
3780         //hb_job_t * job = fTitle->job;
3781         /* Basic Picture Settings */
3782         /* Use Max Picture settings for whatever the dvd is.*/
3783         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3784         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3785         [preset setObject:[NSNumber numberWithInt:320] forKey:@"PictureWidth"];
3786         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3787         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3788         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3789         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3790         /* Set crop settings here */
3791         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3792         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3793     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3794         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3795         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3796         
3797         /*Audio*/
3798         /* Audio Sample Rate*/
3799         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3800         /* Audio Bitrate Rate*/
3801         [preset setObject:@"160" forKey:@"AudioBitRate"];
3802         /* Subtitles*/
3803         [preset setObject:@"None" forKey:@"Subtitles"];
3804         
3806     [preset autorelease];
3807     return preset;
3812 - (NSDictionary *)CreateIpodHighPreset
3814     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3815         /* Get the New Preset Name from the field in the AddPresetPanel */
3816     [preset setObject:@"iPod High-Rez" forKey:@"PresetName"];
3817         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3818         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3819         /*Set whether or not this is default, at creation set to 0*/
3820         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3821         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3822         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3823         /* Get the New Preset Description from the field in the AddPresetPanel */
3824     [preset setObject:@"HandBrake's high resolution settings for the iPod. Good video quality, great for viewing on a TV using your iPod" forKey:@"PresetDescription"];
3825         /* File Format */
3826     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3827         /* Chapter Markers*/
3828          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3829     /* Codecs */
3830         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3831         /* Video encoder */
3832         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3833         /* x264 Option String */
3834         [preset setObject:@"keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1" forKey:@"x264Option"];
3835         /* Video quality */
3836         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3837         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3838         [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3839         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3840         
3841         /* Video framerate */
3842         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3843         /* GrayScale */
3844         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3845         /* 2 Pass Encoding */
3846         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3847         
3848         /*Picture Settings*/
3849         //hb_job_t * job = fTitle->job;
3850         /* Basic Picture Settings */
3851         /* Use Max Picture settings for whatever the dvd is.*/
3852         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3853         [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
3854         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3855         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3856         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3857         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3858         /* Set crop settings here */
3859         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3860         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3861         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3862     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3863         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3864         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3865         
3866         /*Audio*/
3867         /* Audio Sample Rate*/
3868         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3869         /* Audio Bitrate Rate*/
3870         [preset setObject:@"160" forKey:@"AudioBitRate"];
3871         /* Subtitles*/
3872         [preset setObject:@"None" forKey:@"Subtitles"];
3873         
3875     [preset autorelease];
3876     return preset;
3880 - (NSDictionary *)CreateAppleTVPreset
3882     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3883         /* Get the New Preset Name from the field in the AddPresetPanel */
3884     [preset setObject:@"AppleTV" forKey:@"PresetName"];
3885         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3886         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3887         /*Set whether or not this is default, at creation set to 0*/
3888         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3889         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3890         [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3891         /* Get the New Preset Description from the field in the AddPresetPanel */
3892     [preset setObject:@"HandBrake's settings for the AppleTV. Provides a good balance between quality and file size, and optimizes performance." forKey:@"PresetDescription"];
3893         /* File Format */
3894     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3895         /* Chapter Markers*/
3896          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3897         /* Codecs */
3898         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3899         /* Video encoder */
3900         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3901         /* x264 Option String (We can use this to tweak the appleTV output)*/
3902         [preset setObject:@"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2" forKey:@"x264Option"];
3903         /* Video quality */
3904         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3905         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3906         [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3907         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3908         
3909         /* Video framerate */
3910         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3911         /* GrayScale */
3912         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3913         /* 2 Pass Encoding */
3914         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3915         
3916         /*Picture Settings*/
3917         /* For AppleTV we only want to retain UsesMaxPictureSettings
3918         which depend on the source dvd picture settings, so we don't
3919         record the current dvd's picture info since it will vary from
3920         source to source*/
3921         //hb_job_t * job = fTitle->job;
3922         //hb_job_t * job = title->job;
3923         /* Basic Picture Settings */
3924         /* Use Max Picture settings for whatever the dvd is.*/
3925         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3926         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3927         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3928         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3929         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3930         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3931         /* Set crop settings here */
3932         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3933         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3934     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3935         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3936         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3937         
3938         /*Audio*/
3939         /* Audio Sample Rate*/
3940         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3941         /* Audio Bitrate Rate*/
3942         [preset setObject:@"160" forKey:@"AudioBitRate"];
3943         /* Subtitles*/
3944         [preset setObject:@"None" forKey:@"Subtitles"];
3945         
3947     [preset autorelease];
3948     return preset;
3952 - (NSDictionary *)CreatePSThreePreset
3954     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3955         /* Get the New Preset Name from the field in the AddPresetPanel */
3956     [preset setObject:@"PS3" forKey:@"PresetName"];
3957         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3958         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3959         /*Set whether or not this is default, at creation set to 0*/
3960         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3961         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3962         [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3963         /* Get the New Preset Description from the field in the AddPresetPanel */
3964     [preset setObject:@"HandBrake's settings for the Sony PlayStation 3." forKey:@"PresetDescription"];
3965         /* File Format */
3966     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3967         /* Chapter Markers*/
3968          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3969         /* Codecs */
3970         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3971         /* Video encoder */
3972         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3973         /* x264 Option String (We can use this to tweak the appleTV output)*/
3974         [preset setObject:@"level=41:subme=5:me=umh" forKey:@"x264Option"];
3975         /* Video quality */
3976         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3977         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3978         [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3979         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3980         
3981         /* Video framerate */
3982         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3983         /* GrayScale */
3984         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3985         /* 2 Pass Encoding */
3986         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3987         
3988         /*Picture Settings*/
3989         /* For PS3 we only want to retain UsesMaxPictureSettings
3990         which depend on the source dvd picture settings, so we don't
3991         record the current dvd's picture info since it will vary from
3992         source to source*/
3993         /* Use Max Picture settings for whatever the dvd is.*/
3994         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3995         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3996         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3997         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3998         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3999         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4000         /* Set crop settings here */
4001         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4002         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4003     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4004         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4005         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4006         
4007         /*Audio*/
4008         /* Audio Sample Rate*/
4009         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4010         /* Audio Bitrate Rate*/
4011         [preset setObject:@"160" forKey:@"AudioBitRate"];
4012         /* Subtitles*/
4013         [preset setObject:@"None" forKey:@"Subtitles"];
4014         
4016     [preset autorelease];
4017     return preset;
4020 - (NSDictionary *)CreatePSPPreset
4022     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4023         /* Get the New Preset Name from the field in the AddPresetPanel */
4024     [preset setObject:@"PSP" forKey:@"PresetName"];
4025         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
4026         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4027         /*Set whether or not this is default, at creation set to 0*/
4028         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4029         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4030         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4031         /* Get the New Preset Description from the field in the AddPresetPanel */
4032     [preset setObject:@"HandBrake's settings for the Sony PlayStation Portable." forKey:@"PresetDescription"];
4033         /* File Format */
4034     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4035         /* Chapter Markers*/
4036          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4037         /* Codecs */
4038         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
4039         /* Video encoder */
4040         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
4041         /* x264 Option String (We can use this to tweak the appleTV output)*/
4042         [preset setObject:@"" forKey:@"x264Option"];
4043         /* Video quality */
4044         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4045         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4046         [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
4047         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4048         
4049         /* Video framerate */
4050         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4051         /* GrayScale */
4052         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4053         /* 2 Pass Encoding */
4054         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4055         
4056         /*Picture Settings*/
4057         /* For PS3 we only want to retain UsesMaxPictureSettings
4058         which depend on the source dvd picture settings, so we don't
4059         record the current dvd's picture info since it will vary from
4060         source to source*/
4061         /* Use Max Picture settings for whatever the dvd is.*/
4062         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
4063         [preset setObject:@"368" forKey:@"PictureWidth"];
4064         [preset setObject:@"208" forKey:@"PictureHeight"];
4065         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4066         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4067         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4068         /* Set crop settings here */
4069         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4070         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4071         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4072     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4073         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4074         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4075         
4076         /*Audio*/
4077         /* Audio Sample Rate*/
4078         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4079         /* Audio Bitrate Rate*/
4080         [preset setObject:@"128" forKey:@"AudioBitRate"];
4081         /* Subtitles*/
4082         [preset setObject:@"None" forKey:@"Subtitles"];
4083         
4085     [preset autorelease];
4086     return preset;
4090 - (NSDictionary *)CreateNormalPreset
4092     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4093         /* Get the New Preset Name from the field in the AddPresetPanel */
4094     [preset setObject:@"Normal" forKey:@"PresetName"];
4095         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4096         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4097         /*Set whether or not this is default, at creation set to 0*/
4098         [preset setObject:[NSNumber numberWithInt:1] forKey:@"Default"];
4099         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4100         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4101         /* Get the New Preset Description from the field in the AddPresetPanel */
4102     [preset setObject:@"HandBrake's normal, default settings." forKey:@"PresetDescription"];
4103         /* File Format */
4104     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4105         /* Chapter Markers*/
4106          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4107     /* Codecs */
4108         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4109         /* Video encoder */
4110         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4111         /* x264 Option String */
4112         [preset setObject:@"ref=2:bframes=2:subme=5:me=umh" forKey:@"x264Option"];
4113         /* Video quality */
4114         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4115         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4116         [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
4117         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4118         
4119         /* Video framerate */
4120         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4121         /* GrayScale */
4122         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4123         /* 2 Pass Encoding */
4124         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4125         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4126         
4127         /*Picture Settings*/
4128         //hb_job_t * job = fTitle->job;
4129         /* Basic Picture Settings */
4130         /* Use Max Picture settings for whatever the dvd is.*/
4131         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4132         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4133         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4134         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4135         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4136         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4137         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4138         /* Set crop settings here */
4139         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4140         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4141     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4142         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4143         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4144         
4145         /*Audio*/
4146         /* Audio Sample Rate*/
4147         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4148         /* Audio Bitrate Rate*/
4149         [preset setObject:@"160" forKey:@"AudioBitRate"];
4150         /* Subtitles*/
4151         [preset setObject:@"None" forKey:@"Subtitles"];
4152         
4154     [preset autorelease];
4155     return preset;
4159 - (NSDictionary *)CreateClassicPreset
4161     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4162         /* Get the New Preset Name from the field in the AddPresetPanel */
4163     [preset setObject:@"Classic" forKey:@"PresetName"];
4164         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4165         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4166         /*Set whether or not this is default, at creation set to 0*/
4167         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4168         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4169         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4170         /* Get the New Preset Description from the field in the AddPresetPanel */
4171     [preset setObject:@"HandBrake's traditional, faster, lower-quality settings." forKey:@"PresetDescription"];
4172         /* File Format */
4173     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4174         /* Chapter Markers*/
4175          [preset setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
4176     /* Codecs */
4177         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
4178         /* Video encoder */
4179         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
4180         /* x264 Option String */
4181         [preset setObject:@"" forKey:@"x264Option"];
4182         /* Video quality */
4183         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4184         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4185         [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
4186         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4187         
4188         /* Video framerate */
4189         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4190         /* GrayScale */
4191         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4192         /* 2 Pass Encoding */
4193         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4194         
4195         /*Picture Settings*/
4196         //hb_job_t * job = fTitle->job;
4197         /* Basic Picture Settings */
4198         /* Use Max Picture settings for whatever the dvd is.*/
4199         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4200         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4201         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4202         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4203         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4204         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4205         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4206         /* Set crop settings here */
4207         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4208         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4209     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4210         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4211         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4212         
4213         /*Audio*/
4214         /* Audio Sample Rate*/
4215         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4216         /* Audio Bitrate Rate*/
4217         [preset setObject:@"160" forKey:@"AudioBitRate"];
4218         /* Subtitles*/
4219         [preset setObject:@"None" forKey:@"Subtitles"];
4220         
4222     [preset autorelease];
4223     return preset;
4227 - (NSDictionary *)CreateFilmPreset
4229     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4230         /* Get the New Preset Name from the field in the AddPresetPanel */
4231     [preset setObject:@"Film" forKey:@"PresetName"];
4232         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4233         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4234         /*Set whether or not this is default, at creation set to 0*/
4235         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4236         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4237         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4238         /* Get the New Preset Description from the field in the AddPresetPanel */
4239     [preset setObject:@"HandBrake's preset for feature films." forKey:@"PresetDescription"];
4240         /* File Format */
4241     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4242         /* Chapter Markers*/
4243          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4244     /* Codecs */
4245         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4246         /* Video encoder */
4247         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4248         /* x264 Option String */
4249         [preset setObject:@"ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:no-fast-pskip" forKey:@"x264Option"];
4250         /* Video quality */
4251         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4252         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4253         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4254         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4255         
4256         /* Video framerate */
4257         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4258         /* GrayScale */
4259         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4260         /* 2 Pass Encoding */
4261         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4262         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4263         
4264         /*Picture Settings*/
4265         //hb_job_t * job = fTitle->job;
4266         /* Basic Picture Settings */
4267         /* Use Max Picture settings for whatever the dvd is.*/
4268         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4269         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4270         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4271         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4272         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4273         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4274         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4275         /* Set crop settings here */
4276         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4277         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4278     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4279         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4280         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4281         
4282         /*Audio*/
4283         /* Audio Sample Rate*/
4284         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4285         /* Audio Bitrate Rate*/
4286         [preset setObject:@"160" forKey:@"AudioBitRate"];
4287         /* Subtitles*/
4288         [preset setObject:@"None" forKey:@"Subtitles"];
4289         
4291     [preset autorelease];
4292     return preset;
4296 - (NSDictionary *)CreateTelevisionPreset
4298     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4299         /* Get the New Preset Name from the field in the AddPresetPanel */
4300     [preset setObject:@"Television" forKey:@"PresetName"];
4301         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4302         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4303         /*Set whether or not this is default, at creation set to 0*/
4304         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4305         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4306         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4307         /* Get the New Preset Description from the field in the AddPresetPanel */
4308     [preset setObject:@"HandBrake's settings for video from television." forKey:@"PresetDescription"];
4309         /* File Format */
4310     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4311         /* Chapter Markers*/
4312          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4313     /* Codecs */
4314         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4315         /* Video encoder */
4316         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4317         /* x264 Option String */
4318         [preset setObject:@"ref=3:mixed-refs:bframes=6:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip" forKey:@"x264Option"];
4319         /* Video quality */
4320         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4321         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4322         [preset setObject:@"1300" forKey:@"VideoAvgBitrate"];
4323         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4324         
4325         /* Video framerate */
4326         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4327         /* GrayScale */
4328         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4329         /* 2 Pass Encoding */
4330         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4331         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4332         
4333         /*Picture Settings*/
4334         //hb_job_t * job = fTitle->job;
4335         /* Basic Picture Settings */
4336         /* Use Max Picture settings for whatever the dvd is.*/
4337         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4338         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4339         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4340         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4341         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4342         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
4343         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4344         /* Set crop settings here */
4345         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4346         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4347     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4348         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4349         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4350         
4351         /*Audio*/
4352         /* Audio Sample Rate*/
4353         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4354         /* Audio Bitrate Rate*/
4355         [preset setObject:@"160" forKey:@"AudioBitRate"];
4356         /* Subtitles*/
4357         [preset setObject:@"None" forKey:@"Subtitles"];
4358         
4360     [preset autorelease];
4361     return preset;
4365 - (NSDictionary *)CreateAnimationPreset
4367     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4368         /* Get the New Preset Name from the field in the AddPresetPanel */
4369     [preset setObject:@"Animation" forKey:@"PresetName"];
4370         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4371         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4372         /*Set whether or not this is default, at creation set to 0*/
4373         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4374         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4375         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4376         /* Get the New Preset Description from the field in the AddPresetPanel */
4377     [preset setObject:@"HandBrake's settings for cartoons, anime, and CGI." forKey:@"PresetDescription"];
4378         /* File Format */
4379     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4380         /* Chapter Markers*/
4381          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4382     /* Codecs */
4383         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4384         /* Video encoder */
4385         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4386         /* x264 Option String */
4387         [preset setObject:@"ref=5:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=5:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2" forKey:@"x264Option"];
4388         /* Video quality */
4389         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4390         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4391         [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
4392         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4393         
4394         /* Video framerate */
4395         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4396         /* GrayScale */
4397         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4398         /* 2 Pass Encoding */
4399         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4400         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4401         
4402         /*Picture Settings*/
4403         //hb_job_t * job = fTitle->job;
4404         /* Basic Picture Settings */
4405         /* Use Max Picture settings for whatever the dvd is.*/
4406         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4407         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4408         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4409         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4410         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4411         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
4412         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4413         /* Set crop settings here */
4414         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4415         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4416     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4417         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4418         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4419         
4420         /*Audio*/
4421         /* Audio Sample Rate*/
4422         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4423         /* Audio Bitrate Rate*/
4424         [preset setObject:@"160" forKey:@"AudioBitRate"];
4425         /* Subtitles*/
4426         [preset setObject:@"None" forKey:@"Subtitles"];
4427         
4429     [preset autorelease];
4430     return preset;
4434 - (NSDictionary *)CreateQuickTimePreset
4436     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4437         /* Get the New Preset Name from the field in the AddPresetPanel */
4438     [preset setObject:@"QuickTime" forKey:@"PresetName"];
4439         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4440         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4441         /*Set whether or not this is default, at creation set to 0*/
4442         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4443         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4444         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4445         /* Get the New Preset Description from the field in the AddPresetPanel */
4446     [preset setObject:@"HandBrake's high quality settings for use with QuickTime. It can be slow, so use it when the Normal preset doesn't look good enough." forKey:@"PresetDescription"];
4447         /* File Format */
4448     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4449         /* Chapter Markers*/
4450          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4451     /* Codecs */
4452         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4453         /* Video encoder */
4454         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4455         /* x264 Option String */
4456         [preset setObject:@"ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip" forKey:@"x264Option"];
4457         /* Video quality */
4458         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4459         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4460         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4461         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4462         
4463         /* Video framerate */
4464         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4465         /* GrayScale */
4466         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4467         /* 2 Pass Encoding */
4468         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4469         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4470         
4471         /*Picture Settings*/
4472         //hb_job_t * job = fTitle->job;
4473         /* Basic Picture Settings */
4474         /* Use Max Picture settings for whatever the dvd is.*/
4475         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4476         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4477         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4478         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4479         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4480         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4481         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4482         /* Set crop settings here */
4483         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4484         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4485     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4486         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4487         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4488         
4489         /*Audio*/
4490         /* Audio Sample Rate*/
4491         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4492         /* Audio Bitrate Rate*/
4493         [preset setObject:@"160" forKey:@"AudioBitRate"];
4494         /* Subtitles*/
4495         [preset setObject:@"None" forKey:@"Subtitles"];
4496         
4498     [preset autorelease];
4499     return preset;
4503 - (NSDictionary *)CreateBedlamPreset
4505     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4506         /* Get the New Preset Name from the field in the AddPresetPanel */
4507     [preset setObject:@"Bedlam" forKey:@"PresetName"];
4508         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4509         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4510         /*Set whether or not this is default, at creation set to 0*/
4511         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4512         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4513         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4514         /* Get the New Preset Description from the field in the AddPresetPanel */
4515     [preset setObject:@"HandBrake's settings maxed out for slowest encoding and highest quality. Use at your own risk. So slow it's not just insane...it's a trip to the looney bin." forKey:@"PresetDescription"];
4516         /* File Format */
4517     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4518         /* Chapter Markers*/
4519          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4520     /* Codecs */
4521         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4522         /* Video encoder */
4523         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4524         /* x264 Option String */
4525         [preset setObject:@"ref=16:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=64:analyse=all:8x8dct:trellis=2:no-fast-pskip:no-dct-decimate:filter=-2,-1" forKey:@"x264Option"];
4526         /* Video quality */
4527         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4528         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4529         [preset setObject:@"1800" forKey:@"VideoAvgBitrate"];
4530         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4531         
4532         /* Video framerate */
4533         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4534         /* GrayScale */
4535         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4536         /* 2 Pass Encoding */
4537         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4538         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4539         
4540         /*Picture Settings*/
4541         //hb_job_t * job = fTitle->job;
4542         /* Basic Picture Settings */
4543         /* Use Max Picture settings for whatever the dvd is.*/
4544         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4545         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4546         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4547         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4548         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4549         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4550         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4551         /* Set crop settings here */
4552         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4553         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4554     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4555         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4556         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4557         
4558         /*Audio*/
4559         /* Audio Sample Rate*/
4560         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4561         /* Audio Bitrate Rate*/
4562         [preset setObject:@"160" forKey:@"AudioBitRate"];
4563         /* Subtitles*/
4564         [preset setObject:@"None" forKey:@"Subtitles"];
4565         
4567     [preset autorelease];
4568     return preset;
4572 - (NSDictionary *)CreateiPhonePreset
4574     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4575         /* Get the New Preset Name from the field in the AddPresetPanel */
4576     [preset setObject:@"iPhone" forKey:@"PresetName"];
4577         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4578         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4579         /*Set whether or not this is default, at creation set to 0*/
4580         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4581         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4582         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4583         /* Get the New Preset Description from the field in the AddPresetPanel */
4584     [preset setObject:@"HandBrake's settings for the iPhone." forKey:@"PresetDescription"];
4585         /* File Format */
4586     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4587         /* Chapter Markers*/
4588          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4589     /* Codecs */
4590         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4591         /* Video encoder */
4592         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
4593         /* x264 Option String */
4594         [preset setObject:@"cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1" forKey:@"x264Option"];
4595         /* Video quality */
4596         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4597         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4598         [preset setObject:@"960" forKey:@"VideoAvgBitrate"];
4599         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4600         
4601         /* Video framerate */
4602         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4603         /* GrayScale */
4604         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4605         /* 2 Pass Encoding */
4606         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4607         
4608         /*Picture Settings*/
4609         //hb_job_t * job = fTitle->job;
4610         /* Basic Picture Settings */
4611         /* Use Max Picture settings for whatever the dvd is.*/
4612         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
4613         [preset setObject:[NSNumber numberWithInt:480] forKey:@"PictureWidth"];
4614         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4615         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4616         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4617         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4618         /* Set crop settings here */
4619         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4620         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4621         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4622     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4623         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4624         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4625         
4626         /*Audio*/
4627         /* Audio Sample Rate*/
4628         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4629         /* Audio Bitrate Rate*/
4630         [preset setObject:@"128" forKey:@"AudioBitRate"];
4631         /* Subtitles*/
4632         [preset setObject:@"None" forKey:@"Subtitles"];
4633         
4635     [preset autorelease];
4636     return preset;
4640 - (NSDictionary *)CreateDeuxSixQuatrePreset
4642     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4643         /* Get the New Preset Name from the field in the AddPresetPanel */
4644     [preset setObject:@"Deux Six Quatre" forKey:@"PresetName"];
4645         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4646         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4647         /*Set whether or not this is default, at creation set to 0*/
4648         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4649         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4650         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4651         /* Get the New Preset Description from the field in the AddPresetPanel */
4652     [preset setObject:@"HandBrake's preset for true high profile x264 quality. A good balance of quality and speed, based on community standards found in the wild. This preset will give you a much better sense of x264's capabilities than vanilla main profile." forKey:@"PresetDescription"];
4653         /* File Format */
4654     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4655         /* Chapter Markers*/
4656          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4657     /* Codecs */
4658         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4659         /* Video encoder */
4660         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4661         /* x264 Option String */
4662         [preset setObject:@"ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip" forKey:@"x264Option"];
4663         /* Video quality */
4664         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4665         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4666         [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
4667         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4668         
4669         /* Video framerate */
4670         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4671         /* GrayScale */
4672         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4673         /* 2 Pass Encoding */
4674         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4675         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4676         
4677         /*Picture Settings*/
4678         //hb_job_t * job = fTitle->job;
4679         /* Basic Picture Settings */
4680         /* Use Max Picture settings for whatever the dvd is.*/
4681         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4682         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4683         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4684         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4685         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4686         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4687         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4688         /* Set crop settings here */
4689         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4690         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4691     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4692         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4693         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4694         
4695         /*Audio*/
4696         /* Audio Sample Rate*/
4697         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4698         /* Audio Bitrate Rate*/
4699         [preset setObject:@"160" forKey:@"AudioBitRate"];
4700         /* Subtitles*/
4701         [preset setObject:@"None" forKey:@"Subtitles"];
4702         
4704     [preset autorelease];
4705     return preset;
4709 - (NSDictionary *)CreateBrokePreset
4711     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4712         /* Get the New Preset Name from the field in the AddPresetPanel */
4713     [preset setObject:@"Broke" forKey:@"PresetName"];
4714         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4715         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4716         /*Set whether or not this is default, at creation set to 0*/
4717         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4718         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4719         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4720         /* Get the New Preset Description from the field in the AddPresetPanel */
4721     [preset setObject:@"HandBrake's preset for people without a lot of money to waste on hard drives. Tries to maximize quality for burning to CDs, so you can party like it's 1999." forKey:@"PresetDescription"];
4722         /* File Format */
4723     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4724         /* Chapter Markers*/
4725          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4726     /* Codecs */
4727         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4728         /* Video encoder */
4729         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4730         /* x264 Option String */
4731         [preset setObject:@"ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:b-pyramid::direct=auto:me=umh:subme=6:trellis=1:analyse=all:8x8dct:no-fast-pskip" forKey:@"x264Option"];
4732         /* Video quality */
4733         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoQualityType"];
4734         [preset setObject:@"695" forKey:@"VideoTargetSize"];
4735         [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
4736         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4737         
4738         /* Video framerate */
4739         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4740         /* GrayScale */
4741         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4742         /* 2 Pass Encoding */
4743         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4744         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
4745         
4746         /*Picture Settings*/
4747         //hb_job_t * job = fTitle->job;
4748         /* Basic Picture Settings */
4749         /* Use Max Picture settings for whatever the dvd is.*/
4750         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
4751         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4752         [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
4753         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4754         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4755         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4756         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4757         /* Set crop settings here */
4758         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4759         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4760     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4761         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4762         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4763         
4764         /*Audio*/
4765         /* Audio Sample Rate*/
4766         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4767         /* Audio Bitrate Rate*/
4768         [preset setObject:@"128" forKey:@"AudioBitRate"];
4769         /* Subtitles*/
4770         [preset setObject:@"None" forKey:@"Subtitles"];
4771         
4773     [preset autorelease];
4774     return preset;
4778 - (NSDictionary *)CreateBlindPreset
4780     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4781         /* Get the New Preset Name from the field in the AddPresetPanel */
4782     [preset setObject:@"Blind" forKey:@"PresetName"];
4783         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4784         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4785         /*Set whether or not this is default, at creation set to 0*/
4786         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4787         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4788         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4789         /* Get the New Preset Description from the field in the AddPresetPanel */
4790     [preset setObject:@"HandBrake's preset for impatient people who don't care about picture quality." forKey:@"PresetDescription"];
4791         /* File Format */
4792     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4793         /* Chapter Markers*/
4794          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4795     /* Codecs */
4796         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
4797         /* Video encoder */
4798         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
4799         /* x264 Option String */
4800         [preset setObject:@"" forKey:@"x264Option"];
4801         /* Video quality */
4802         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4803         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4804         [preset setObject:@"512" forKey:@"VideoAvgBitrate"];
4805         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4806         
4807         /* Video framerate */
4808         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4809         /* GrayScale */
4810         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4811         /* 2 Pass Encoding */
4812         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4813         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
4814         
4815         /*Picture Settings*/
4816         //hb_job_t * job = fTitle->job;
4817         /* Basic Picture Settings */
4818         /* Use Max Picture settings for whatever the dvd is.*/
4819         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
4820         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4821         [preset setObject:[NSNumber numberWithInt:512] forKey:@"PictureWidth"];
4822         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4823         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4824         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4825         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4826         /* Set crop settings here */
4827         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4828         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4829     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4830         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4831         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4832         
4833         /*Audio*/
4834         /* Audio Sample Rate*/
4835         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4836         /* Audio Bitrate Rate*/
4837         [preset setObject:@"128" forKey:@"AudioBitRate"];
4838         /* Subtitles*/
4839         [preset setObject:@"None" forKey:@"Subtitles"];
4840         
4842     [preset autorelease];
4843     return preset;
4847 - (NSDictionary *)CreateCRFPreset
4849     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4850         /* Get the New Preset Name from the field in the AddPresetPanel */
4851     [preset setObject:@"Constant Quality Rate" forKey:@"PresetName"];
4852         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4853         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4854         /*Set whether or not this is default, at creation set to 0*/
4855         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4856         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4857         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4858         /* Get the New Preset Description from the field in the AddPresetPanel */
4859     [preset setObject:@"HandBrake's preset for consistently excellent quality in one pass, with the downside of entirely unpredictable file sizes and bitrates." forKey:@"PresetDescription"];
4860         /* File Format */
4861     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4862         /* Chapter Markers*/
4863          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4864     /* Codecs */
4865         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4866         /* Video encoder */
4867         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4868         /* x264 Option String */
4869         [preset setObject:@"ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh" forKey:@"x264Option"];
4870         /* Video quality */
4871         [preset setObject:[NSNumber numberWithInt:2] forKey:@"VideoQualityType"];
4872         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4873         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4874         [preset setObject:[NSNumber numberWithFloat:0.6471] forKey:@"VideoQualitySlider"];
4875         
4876         /* Video framerate */
4877         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4878         /* GrayScale */
4879         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4880         /* 2 Pass Encoding */
4881         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4882         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
4883         
4884         /*Picture Settings*/
4885         //hb_job_t * job = fTitle->job;
4886         /* Basic Picture Settings */
4887         /* Use Max Picture settings for whatever the dvd is.*/
4888         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4889         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4890         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4891         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4892         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4893         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4894         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4895         /* Set crop settings here */
4896         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4897         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4898     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4899         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4900         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4901         
4902         /*Audio*/
4903         /* Audio Sample Rate*/
4904         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4905         /* Audio Bitrate Rate*/
4906         [preset setObject:@"160" forKey:@"AudioBitRate"];
4907         /* Subtitles*/
4908         [preset setObject:@"None" forKey:@"Subtitles"];
4909         
4911     [preset autorelease];
4912     return preset;
4917 - (IBAction)DeletePreset:(id)sender
4919     int status;
4920     NSEnumerator *enumerator;
4921     NSNumber *index;
4922     NSMutableArray *tempArray;
4923     id tempObject;
4924     
4925     if ( [tableView numberOfSelectedRows] == 0 )
4926         return;
4927     /* Alert user before deleting preset */
4928         /* Comment out for now, tie to user pref eventually */
4930     //NSBeep();
4931     status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
4932     
4933     if ( status == NSAlertDefaultReturn ) {
4934         enumerator = [tableView selectedRowEnumerator];
4935         tempArray = [NSMutableArray array];
4936         
4937         while ( (index = [enumerator nextObject]) ) {
4938             tempObject = [UserPresets objectAtIndex:[index intValue]];
4939             [tempArray addObject:tempObject];
4940         }
4941         
4942         [UserPresets removeObjectsInArray:tempArray];
4943         [tableView reloadData];
4944         [self savePreset];   
4945     }
4948 - (IBAction)GetDefaultPresets:(id)sender
4950         int i = 0;
4951     NSEnumerator *enumerator = [UserPresets objectEnumerator];
4952         id tempObject;
4953         while (tempObject = [enumerator nextObject])
4954         {
4955                 NSDictionary *thisPresetDict = tempObject;
4956                 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
4957                 {
4958                         presetHbDefault = i;    
4959                 }
4960                 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
4961                 {
4962                         presetUserDefault = i;  
4963                 }
4964                 i++;
4965         }
4968 - (IBAction)SetDefaultPreset:(id)sender
4970     int i = 0;
4971     NSEnumerator *enumerator = [UserPresets objectEnumerator];
4972         id tempObject;
4973         /* First make sure the old user specified default preset is removed */
4974         while (tempObject = [enumerator nextObject])
4975         {
4976                 /* make sure we are not removing the default HB preset */
4977                 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4978                 {
4979                         [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4980                 }
4981                 i++;
4982         }
4983         /* Second, go ahead and set the appropriate user specfied preset */
4984         /* we get the chosen preset from the UserPresets array */
4985         if ([[[UserPresets objectAtIndex:[tableView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4986         {
4987                 [[UserPresets objectAtIndex:[tableView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
4988         }
4989         presetUserDefault = [tableView selectedRow];
4990         
4991         /* We save all of the preset data here */
4992     [self savePreset];
4993         /* We Reload the New Table data for presets */
4994     [tableView reloadData];
4997 - (IBAction)SelectDefaultPreset:(id)sender
4999         /* if there is a user specified default, we use it */
5000         if (presetUserDefault)
5001         {
5002         [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
5003         [self tableViewSelected:NULL];
5004         }
5005         else if (presetHbDefault) //else we use the built in default presetHbDefault
5006         {
5007         [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
5008         [self tableViewSelected:NULL];
5009         }
5012 - (IBAction)tableViewSelected:(id)sender
5014     /* Since we cannot disable the presets tableView in terms of clickability
5015            we will use the enabled state of the add presets button to determine whether
5016            or not clicking on a preset will do anything */
5017         if ([fPresetsAdd isEnabled])
5018         {
5019                 if ([tableView selectedRow] >= 0)
5020                 {       
5021                         /* we get the chosen preset from the UserPresets array */
5022                         chosenPreset = [UserPresets objectAtIndex:[tableView selectedRow]];
5023                         curUserPresetChosenNum = [sender selectedRow];
5024                         /* we set the preset display field in main window here */
5025                         [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
5026                         if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
5027                         {
5028                                 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@ (Default)",[chosenPreset valueForKey:@"PresetName"]]];
5029                         }
5030                         else
5031                         {
5032                                 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
5033                         }
5034                         /* File Format */
5035                         [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
5036                         [self FormatPopUpChanged: NULL];
5037                         
5038                         /* Chapter Markers*/
5039                         [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
5040                         /* Allow Mpeg4 64 bit formatting +4GB file sizes */
5041                         [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
5042                         /* Codecs */
5043                         [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
5044                         [self CodecsPopUpChanged: NULL];
5045                         /* Video encoder */
5046                         [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
5047                         
5048                         /* We can show the preset options here in the gui if we want to
5049                                 so we check to see it the user has specified it in the prefs */
5050                         [fDisplayX264Options setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
5051                         
5052                         [self X264AdvancedOptionsSet:NULL];
5053                         
5054                         /* Lets run through the following functions to get variables set there */
5055                         [self EncoderPopUpChanged: NULL];
5056                         
5057                         [self CalculateBitrate: NULL];
5058                         
5059                         /* Video quality */
5060                         [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
5061                         
5062                         [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
5063                         [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
5064                         
5065                         [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
5066                         [self VideoMatrixChanged: NULL];
5067                         
5068                         /* Video framerate */
5069                         [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
5070                         
5071                         /* GrayScale */
5072                         [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
5073                         
5074                         /* 2 Pass Encoding */
5075                         [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
5076                         [self TwoPassCheckboxChanged: NULL];
5077                         /* Turbo 1st pass for 2 Pass Encoding */
5078                         [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
5079                         
5080                         /*Audio*/
5081                         
5082                         /* Audio Sample Rate*/
5083                         [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
5084                         /* Audio Bitrate Rate*/
5085                         [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
5086                         /*Subtitles*/
5087                         [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
5088                         
5089                         /* Picture Settings */
5090                         /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
5091                         if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] > 0)
5092                         {
5093                                 hb_job_t * job = fTitle->job;
5094                                 /* Check to see if we should use the max picture setting for the current title*/
5095                                 if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"]  intValue] == 1)
5096                                 {
5097                                         /* Use Max Picture settings for whatever the dvd is.*/
5098                                         [self RevertPictureSizeToMax: NULL];
5099                                         job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
5100                                         if (job->keep_ratio == 1)
5101                                         {
5102                                                 hb_fix_aspect( job, HB_KEEP_WIDTH );
5103                                                 if( job->height > fTitle->height )
5104                                                 {
5105                                                         job->height = fTitle->height;
5106                                                         hb_fix_aspect( job, HB_KEEP_HEIGHT );
5107                                                 }
5108                                         }
5109                                         job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
5110                                 }
5111                                 else // Apply picture settings that were in effect at the time the preset was saved
5112                                 {
5113                                         job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
5114                                         job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
5115                                         job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
5116                                         if (job->keep_ratio == 1)
5117                                         {
5118                                                 hb_fix_aspect( job, HB_KEEP_WIDTH );
5119                                                 if( job->height > fTitle->height )
5120                                                 {
5121                                                         job->height = fTitle->height;
5122                                                         hb_fix_aspect( job, HB_KEEP_HEIGHT );
5123                                                 }
5124                                         }
5125                                         job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
5126                                         [fPicSettingDeinterlace setStringValue: [NSString stringWithFormat: @"%d",[[chosenPreset objectForKey:@"PictureDeinterlace"]  intValue]]];
5127                                         
5128                                         if ([chosenPreset objectForKey:@"PictureDetelecine"])
5129                                         {
5130                                         [fPicSettingDetelecine setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PictureDetelecine"]]];
5131                                         }
5132                                         if ([chosenPreset objectForKey:@"PictureDenoise"])
5133                                         {
5134                                         [fPicSettingDenoise setStringValue: [NSString stringWithFormat: @"%d",[[chosenPreset objectForKey:@"PictureDenoise"]  intValue]]];
5135                                         }
5136                                         /* If Cropping is set to custom, then recall all four crop values from
5137                                                 when the preset was created and apply them */
5138                                         if ([[chosenPreset objectForKey:@"PictureAutoCrop"]  intValue] == 0)
5139                                         {
5140                                                 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
5141                                                         @"%d", 0]];
5142                                                 
5143                                                 /* Here we use the custom crop values saved at the time the preset was saved */
5144                                                 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"]  intValue];
5145                                                 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"]  intValue];
5146                                                 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"]  intValue];
5147                                                 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"]  intValue];
5148                                                 
5149                                         }
5150                                         else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
5151                                         {
5152                                                 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
5153                                                         @"%d", 1]];
5154                                                 /* Here we use the auto crop values determined right after scan */
5155                                                 job->crop[0] = AutoCropTop;
5156                                                 job->crop[1] = AutoCropBottom;
5157                                                 job->crop[2] = AutoCropLeft;
5158                                                 job->crop[3] = AutoCropRight;
5159                                                 
5160                                         }
5161                                 }
5162                                 [self CalculatePictureSizing: NULL]; 
5163                         }
5164                         
5165                         
5166                         [[fPresetsActionMenu itemAtIndex:0] setEnabled: YES];
5167                         }
5173 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
5175     return [UserPresets count];
5178 /* we use this to determine display characteristics for
5179 each table cell based on content currently only used to
5180 show the built in presets in a blue font. */
5181 - (void)tableView:(NSTableView *)aTableView
5182  willDisplayCell:(id)aCell 
5183  forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
5185     NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
5186         NSFont *txtFont;
5187         NSColor *fontColor;
5188         NSColor *shadowColor;
5189         txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
5190         /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
5191         if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
5192         {
5193                 
5194                 fontColor = [NSColor whiteColor];
5195                 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
5196         }
5197         else
5198         {
5199                 /* We set the properties of unselected rows */
5200                 /* if built-in preset (defined by "type" == 0) we use a blue font */
5201                 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
5202                 {
5203                         fontColor = [NSColor blueColor];
5204                 }
5205                 else // User created preset, use a black font
5206                 {
5207                         fontColor = [NSColor blackColor];
5208                 }
5209                 shadowColor = nil;
5210         }
5211         /* We check to see if this is the HB default, if so, color it appropriately */
5212         if (!presetUserDefault && presetHbDefault && rowIndex == presetHbDefault)
5213         {
5214         txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5215         }
5216         /* We check to see if this is the User Specified default, if so, color it appropriately */
5217         if (presetUserDefault && rowIndex == presetUserDefault)
5218         {
5219         txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5220         }
5221         
5222         [aCell setTextColor:fontColor];
5223         [aCell setFont:txtFont];
5224         /* this shadow stuff (like mail app) for some reason looks crappy, commented out
5225         temporarily in case we want to resurrect it */
5226         /*
5227         NSShadow *shadow = [[NSShadow alloc] init];
5228         NSSize shadowOffset = { width: 1.0, height: -1.5};
5229         [shadow setShadowOffset:shadowOffset];
5230         [shadow setShadowColor:shadowColor];
5231         [shadow set];
5232         */
5233         
5235 /* Method to display tooltip with the description for each preset, if available */
5236 - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell 
5237                    rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
5238                     row:(int)rowIndex mouseLocation:(NSPoint)aPos
5240      /* initialize the tooltip contents variable */
5241          NSString *loc_tip;
5242      /* if there is a description for the preset, we show it in the tooltip */
5243          if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
5244          {
5245          loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
5246          return (loc_tip);
5247          }
5248          else
5249          {
5250          loc_tip = @"No description available";
5251          }
5252          return (loc_tip);
5256 - (id)tableView:(NSTableView *)aTableView
5257       objectValueForTableColumn:(NSTableColumn *)aTableColumn
5258       row:(int)rowIndex
5260 id theRecord, theValue;
5261     
5262     theRecord = [UserPresets objectAtIndex:rowIndex];
5263     theValue = [theRecord objectForKey:[aTableColumn identifier]];
5264     return theValue;
5267 // NSTableDataSource method that we implement to edit values directly in the table...
5268 - (void)tableView:(NSTableView *)aTableView
5269         setObjectValue:(id)anObject
5270         forTableColumn:(NSTableColumn *)aTableColumn
5271         row:(int)rowIndex
5273     id theRecord;
5274     
5275     theRecord = [UserPresets objectAtIndex:rowIndex];
5276     [theRecord setObject:anObject forKey:@"PresetName"];
5277     /* We Sort the Presets By Factory or Custom */
5278         NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type" 
5279                                                     ascending:YES] autorelease];
5280                 /* We Sort the Presets Alphabetically by name */
5281         NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
5282                                                     ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
5283         NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
5284     NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
5285         [UserPresets setArray:sortedArray];
5286         /* We Reload the New Table data for presets */
5287     [tableView reloadData];
5288    /* We save all of the preset data here */
5289     [self savePreset];
5293 - (void)savePreset
5295     [UserPresets writeToFile:UserPresetsFile atomically:YES];
5296         /* We get the default preset in case it changed */
5297         [self GetDefaultPresets: NULL];
5303 - (void) controlTextDidBeginEditing: (NSNotification *) notification
5305     [self CalculateBitrate: NULL];
5308 - (void) controlTextDidEndEditing: (NSNotification *) notification
5310     [self CalculateBitrate: NULL];
5313 - (void) controlTextDidChange: (NSNotification *) notification
5315     [self CalculateBitrate: NULL];
5318 - (IBAction) OpenHomepage: (id) sender
5320     [[NSWorkspace sharedWorkspace] openURL: [NSURL
5321         URLWithString:@"http://handbrake.m0k.org/"]];
5324 - (IBAction) OpenForums: (id) sender
5326     [[NSWorkspace sharedWorkspace] openURL: [NSURL
5327         URLWithString:@"http://handbrake.m0k.org/forum/"]];
5329 - (IBAction) OpenUserGuide: (id) sender
5331     [[NSWorkspace sharedWorkspace] openURL: [NSURL
5332         URLWithString:@"http://handbrake.m0k.org/trac/wiki/HandBrakeGuide"]];
5336  * Shows debug output window.
5337  */
5338 - (IBAction)showDebugOutputPanel:(id)sender
5340     [outputPanel showOutputPanel:sender];
5344  * Creates preferences controller, shows preferences window modally, and
5345  * releases the controller after user has closed the window.
5346  */
5347 - (IBAction)showPreferencesWindow:(id)sender
5349     HBPreferencesController *controller = [[HBPreferencesController alloc] init];
5350     [controller runModal:nil];
5351     [controller release];
5354 @end