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