OSDN Git Service

MacGui: Fixed bitrate calculation for target size.
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.mm
1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.m0k.org/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #include "Controller.h"
8 #include "a52dec/a52.h"
9 #import "HBOutputPanelController.h"
10 #import "HBPreferencesController.h"
11 /* Added to integrate scanning into HBController */
12 #include <IOKit/IOKitLib.h>
13 #include <IOKit/storage/IOMedia.h>
14 #include <IOKit/storage/IODVDMedia.h>
15 #include "HBDVDDetector.h"
16 #include "dvdread/dvd_reader.h"
17
18 #define _(a) NSLocalizedString(a,NULL)
19
20 static int FormatSettings[4][10] =
21   { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
22           HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
23           0,
24           0},
25     { HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
26           HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
27           HB_MUX_AVI | HB_VCODEC_X264   | HB_ACODEC_LAME,
28           HB_MUX_AVI | HB_VCODEC_X264   | HB_ACODEC_AC3},
29     { HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
30           HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
31           0,
32           0 },
33     { HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
34           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
35           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
36           HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
37           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_FAAC,
38           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_AC3,
39           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_LAME,
40           HB_MUX_MKV | HB_VCODEC_X264   | HB_ACODEC_VORBIS,
41           0,
42           0 } };
43
44
45 /* We setup the toolbar values here */
46 static NSString *        ToggleDrawerIdentifier             = @"Toggle Drawer Item Identifier";
47 static NSString *        StartEncodingIdentifier            = @"Start Encoding Item Identifier";
48 static NSString *        PauseEncodingIdentifier            = @"Pause Encoding Item Identifier";
49 static NSString *        ShowQueueIdentifier                = @"Show Queue Item Identifier";
50 static NSString *        AddToQueueIdentifier               = @"Add to Queue Item Identifier";
51 static NSString *        ShowActivityIdentifier             = @"Debug Output Item Identifier";
52 static NSString *        ChooseSourceIdentifier             = @"Choose Source Item Identifier";
53
54 /**
55  * Returns the number of jobs groups in the queue.
56  * @param h Handle to hb_handle_t.
57  * @return Number of job groups.
58  */
59 static int hb_group_count(hb_handle_t * h)    
60 {
61         hb_job_t * job;
62         int count = 0;
63         int index = 0;
64         while( ( job = hb_job( h, index++ ) ) )
65         {
66                 if (job->sequence_id == 0)
67                         count++;
68         }
69         return count;
70 }
71
72 /*******************************
73  * HBController implementation *
74  *******************************/
75 @implementation HBController
76
77 - init
78 {
79     self = [super init];
80     [HBPreferencesController registerUserDefaults];
81     fHandle = NULL;
82     outputPanel = [[HBOutputPanelController alloc] init];
83     fPictureController = [[PictureController alloc] initWithDelegate:self];
84     fQueueController = [[HBQueueController alloc] init];
85     fAdvancedOptions = [[HBAdvancedController alloc] init];
86     return self;
87 }
88
89 - (void) applicationDidFinishLaunching: (NSNotification *) notification
90 {
91     int    build;
92     char * version;
93
94     // Init libhb
95         int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
96     fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
97
98         // Set the Growl Delegate
99     [GrowlApplicationBridge setGrowlDelegate: self];    
100     /* Init others controllers */
101     [fPictureController SetHandle: fHandle];
102     [fQueueController   setHandle: fHandle];
103         
104     fChapterTitlesDelegate = [[ChapterTitles alloc] init];
105     [fChapterTable setDataSource:fChapterTitlesDelegate];
106
107      /* Call UpdateUI every 1/2 sec */
108     [[NSRunLoop currentRunLoop] addTimer: [NSTimer
109         scheduledTimerWithTimeInterval: 0.5 target: self
110         selector: @selector( updateUI: ) userInfo: NULL repeats: YES]
111         forMode: NSEventTrackingRunLoopMode];
112
113     if( ( build = hb_check_update( fHandle, &version ) ) > -1 )
114     {
115         /* Update available - tell the user */
116         
117         NSBeginInformationalAlertSheet( _( @"Update is available" ),
118             _( @"Go get it!" ), _( @"Discard" ), NULL, fWindow, self,
119             @selector( updateAlertDone:returnCode:contextInfo: ),
120             NULL, NULL, [NSString stringWithFormat:
121             _( @"HandBrake %s (build %d) is now available for download." ),
122             version, build] );
123         return;
124
125     }
126
127     // Open debug output window now if it was visible when HB was closed
128     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
129         [self showDebugOutputPanel:nil];
130
131     // Open queue window now if it was visible when HB was closed
132     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
133         [self showQueueWindow:nil];
134
135         [self openMainWindow:nil];
136         
137     /* Show scan panel ASAP */
138     [self performSelectorOnMainThread: @selector(showScanPanel:)
139         withObject: NULL waitUntilDone: NO];
140 }
141
142 - (NSApplicationTerminateReply) applicationShouldTerminate:
143     (NSApplication *) app
144 {
145     hb_state_t s;
146     hb_get_state2( fHandle, &s );
147     if ( s.state ==  HB_STATE_WORKING )    
148     {
149         [self Cancel: NULL];
150         return NSTerminateCancel;
151     }    
152     return NSTerminateNow;
153 }
154
155 - (void)applicationWillTerminate:(NSNotification *)aNotification
156 {
157         [outputPanel release];
158         [fQueueController release];
159         hb_close(&fHandle);
160 }
161
162
163 - (void) awakeFromNib
164 {
165     [fWindow center];
166     [fWindow setExcludedFromWindowsMenu:YES];
167     [fAdvancedOptions setView:fAdvancedView];
168
169     /* Initialize currentScanCount so HB can use it to
170                 evaluate successive scans */
171         currentScanCount = 0;
172         
173     /* Init UserPresets .plist */
174         [self loadPresets];
175                 
176         fRipIndicatorShown = NO;  // initially out of view in the nib
177         
178         /* Show/Dont Show Presets drawer upon launch based
179                 on user preference DefaultPresetsDrawerShow*/
180         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
181         {
182                 [fPresetDrawer open];
183         }
184         
185         
186     /* Destination box*/
187     [fDstFormatPopUp removeAllItems];
188     [fDstFormatPopUp addItemWithTitle: _( @"MP4 file" )];
189     [fDstFormatPopUp addItemWithTitle: _( @"AVI file" )];
190     [fDstFormatPopUp addItemWithTitle: _( @"OGM file" )];
191         [fDstFormatPopUp addItemWithTitle: _( @"MKV file" )];
192     [fDstFormatPopUp selectItemAtIndex: 0];
193         
194     [self formatPopUpChanged: NULL];
195     
196         /* We enable the create chapters checkbox here since we are .mp4 */     
197         [fCreateChapterMarkers setEnabled: YES];
198         if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
199         {
200                 [fCreateChapterMarkers setState: NSOnState];
201         }
202         
203         
204         
205         
206     [fDstFile2Field setStringValue: [NSString stringWithFormat:
207         @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
208         
209     /* Video encoder */
210     [fVidEncoderPopUp removeAllItems];
211     [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
212     [fVidEncoderPopUp addItemWithTitle: @"XviD"];
213         
214     
215         
216     /* Video quality */
217     [fVidTargetSizeField setIntValue: 700];
218         [fVidBitrateField    setIntValue: 1000];
219         
220     [fVidQualityMatrix   selectCell: fVidBitrateCell];
221     [self videoMatrixChanged: NULL];
222         
223     /* Video framerate */
224     [fVidRatePopUp removeAllItems];
225         [fVidRatePopUp addItemWithTitle: _( @"Same as source" )];
226     for( int i = 0; i < hb_video_rates_count; i++ )
227     {
228         if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
229                 {
230                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
231                                 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
232                 }
233                 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
234                 {
235                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
236                                 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
237                 }
238                 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
239                 {
240                         [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
241                                 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
242                 }
243                 else
244                 {
245                         [fVidRatePopUp addItemWithTitle:
246                                 [NSString stringWithCString: hb_video_rates[i].string]];
247                 }
248     }
249     [fVidRatePopUp selectItemAtIndex: 0];
250         
251         /* Picture Settings */
252         [fPicLabelPAROutputX setStringValue: @""];
253         [fPicSettingPARWidth setStringValue: @""];
254         [fPicSettingPARHeight setStringValue:  @""];
255         
256         /* Set Auto Crop to On at launch */
257     [fPictureController setAutoCrop:YES];
258         
259         /* Audio bitrate */
260     [fAudBitratePopUp removeAllItems];
261     for( int i = 0; i < hb_audio_bitrates_count; i++ )
262     {
263         [fAudBitratePopUp addItemWithTitle:
264                                 [NSString stringWithCString: hb_audio_bitrates[i].string]];
265
266     }
267     [fAudBitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
268         
269     /* Audio samplerate */
270     [fAudRatePopUp removeAllItems];
271     for( int i = 0; i < hb_audio_rates_count; i++ )
272     {
273         [fAudRatePopUp addItemWithTitle:
274             [NSString stringWithCString: hb_audio_rates[i].string]];
275     }
276     [fAudRatePopUp selectItemAtIndex: hb_audio_rates_default];
277         
278     /* Bottom */
279     [fStatusField setStringValue: @""];
280         
281     [self enableUI: NO];
282         [self setupToolbar];
283         
284         [fPresetsActionButton setMenu:fPresetsActionMenu];
285         
286         /* We disable the Turbo 1st pass checkbox since we are not x264 */
287         [fVidTurboPassCheck setEnabled: NO];
288         [fVidTurboPassCheck setState: NSOffState];
289         
290         
291         /* lets get our default prefs here */
292         [self getDefaultPresets: NULL];
293         /* lets initialize the current successful scancount here to 0 */
294         currentSuccessfulScanCount = 0;
295     
296 }
297
298 - (void) loadPresets {
299         /* We declare the default NSFileManager into fileManager */
300         NSFileManager * fileManager = [NSFileManager defaultManager];
301         /* we set the files and support paths here */
302         AppSupportDirectory = @"~/Library/Application Support/HandBrake";
303     AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath];
304     //UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
305     //UserPresetsFile = [UserPresetsFile stringByExpandingTildeInPath];
306         /* We check for the app support directory for handbrake */
307         if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0) 
308         {
309                 // If it doesnt exist yet, we create it here 
310                 [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil];
311         }
312         /* We check for the presets.plist here */
313         if ([fileManager fileExistsAtPath:UserPresetsFile] == 0) 
314         {
315                 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
316         }
317         UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
318         UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
319         
320         UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
321         if (nil == UserPresets) 
322         {
323                 UserPresets = [[NSMutableArray alloc] init];
324                 [self addFactoryPresets:NULL];
325         }
326         
327 }
328
329 // ============================================================
330 // NSToolbar Related Methods
331 // ============================================================
332
333 - (void) setupToolbar {
334     toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
335     
336     [toolbar setAllowsUserCustomization: YES];
337     [toolbar setAutosavesConfiguration: YES];
338     [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
339     
340     [toolbar setDelegate: self];
341     
342     [fWindow setToolbar: toolbar];
343 }
344
345 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
346     (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
347     NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
348     
349     if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
350     {
351         [item setLabel: @"Toggle Presets"];
352         [item setPaletteLabel: @"Toggler Presets"];
353         [item setToolTip: @"Open/Close Preset Drawer"];
354         [item setImage: [NSImage imageNamed: @"Drawer-List2"]];
355         [item setTarget: self];
356         [item setAction: @selector(toggleDrawer:)];
357         [item setAutovalidates: NO];
358     }
359     else if ([itemIdent isEqualToString: StartEncodingIdentifier])
360     {
361         [item setLabel: @"Start"];
362         [item setPaletteLabel: @"Start Encoding"];
363         [item setToolTip: @"Start Encoding"];
364         [item setImage: [NSImage imageNamed: @"Play"]];
365         [item setTarget: self];
366         [item setAction: @selector(Rip:)];
367     }
368     else if ([itemIdent isEqualToString: ShowQueueIdentifier])
369     {
370         [item setLabel: @"Show Queue"];
371         [item setPaletteLabel: @"Show Queue"];
372         [item setToolTip: @"Show Queue"];
373         [item setImage: [NSImage imageNamed: @"Brushed Window"]];
374         [item setTarget: self];
375         [item setAction: @selector(showQueueWindow:)];
376         [item setAutovalidates: NO];
377     }
378     else if ([itemIdent isEqualToString: AddToQueueIdentifier])
379     {
380         [item setLabel: @"Add to Queue"];
381         [item setPaletteLabel: @"Add to Queue"];
382         [item setToolTip: @"Add to Queue"];
383         [item setImage: [NSImage imageNamed: @"Add"]];
384         [item setTarget: self];
385         [item setAction: @selector(addToQueue:)];
386     }
387     else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
388     {
389         [item setLabel: @"Pause"];
390         [item setPaletteLabel: @"Pause Encoding"];
391         [item setToolTip: @"Pause Encoding"];
392         [item setImage: [NSImage imageNamed: @"Pause"]];
393         [item setTarget: self];
394         [item setAction: @selector(Pause:)];
395     }
396     else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
397         [item setLabel: @"Activity Window"];
398         [item setPaletteLabel: @"Show Activity Window"];
399         [item setToolTip: @"Show Activity Window"];
400         [item setImage: [NSImage imageNamed: @"Terminal"]];
401         [item setTarget: self];
402         [item setAction: @selector(showDebugOutputPanel:)];
403         [item setAutovalidates: NO];
404     }
405     else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
406     {
407         [item setLabel: @"Source"];
408         [item setPaletteLabel: @"Source"];
409         [item setToolTip: @"Choose Video Source"];
410         [item setImage: [NSImage imageNamed: @"Disc"]];
411         [item setTarget: self];
412         [item setAction: @selector(showScanPanel:)];
413         [item setAutovalidates: NO];
414     }
415     else
416     {
417         [item release];
418         return nil;
419     }
420
421     return item;
422 }
423
424 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
425 {
426     return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
427         PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier, 
428                 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
429 }
430
431 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
432 {
433     return [NSArray arrayWithObjects:  StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
434         ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
435         NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier,
436         NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
437 }
438
439 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
440 {
441     NSString * ident = [toolbarItem itemIdentifier];
442         
443     if (fHandle)
444     {
445         hb_state_t s;
446         hb_get_state2( fHandle, &s );
447         
448         if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
449         {
450             if ([ident isEqualToString: StartEncodingIdentifier])
451             {
452                 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
453                 [toolbarItem setLabel: @"Cancel"];
454                 [toolbarItem setPaletteLabel: @"Cancel"];
455                 [toolbarItem setToolTip: @"Cancel Encoding"];
456                 return YES;
457             }
458             if ([ident isEqualToString: PauseEncodingIdentifier])
459             {
460                 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
461                 [toolbarItem setLabel: @"Pause"];
462                 [toolbarItem setPaletteLabel: @"Pause Encoding"];
463                 [toolbarItem setToolTip: @"Pause Encoding"];
464                 return YES;
465             }
466             if (SuccessfulScan)
467                 if ([ident isEqualToString: AddToQueueIdentifier])
468                     return YES;
469         }
470         else if (s.state == HB_STATE_PAUSED)
471         {
472             if ([ident isEqualToString: PauseEncodingIdentifier])
473             {
474                 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
475                 [toolbarItem setLabel: @"Resume"];
476                 [toolbarItem setPaletteLabel: @"Resume Encoding"];
477                 [toolbarItem setToolTip: @"Resume Encoding"];
478                 return YES;
479             }
480             if ([ident isEqualToString: StartEncodingIdentifier])
481                 return YES;
482             if ([ident isEqualToString: AddToQueueIdentifier])
483                 return YES;
484         }
485         else if (s.state == HB_STATE_SCANNING)
486             return NO;
487         else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
488         {
489             if ([ident isEqualToString: StartEncodingIdentifier])
490             {
491                 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
492                 [toolbarItem setLabel: @"Start"];
493                 [toolbarItem setPaletteLabel: @"Start Encoding"];
494                 [toolbarItem setToolTip: @"Start Encoding"];
495                 return YES;
496             }
497             if ([ident isEqualToString: AddToQueueIdentifier])
498                 return YES;
499         }
500
501     }
502     
503     if ([ident isEqualToString: ShowQueueIdentifier])
504         return YES;
505     if ([ident isEqualToString: ToggleDrawerIdentifier])
506         return YES;
507     if ([ident isEqualToString: ChooseSourceIdentifier])
508         return YES;
509     if ([ident isEqualToString: ShowActivityIdentifier])
510         return YES;
511     
512     return NO;
513 }
514
515 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
516 {
517     SEL action = [menuItem action];
518     
519     hb_state_t s;
520     hb_get_state2( fHandle, &s );
521     
522     if (fHandle)
523     {
524         if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
525             return SuccessfulScan && [fWindow attachedSheet] == nil;
526         
527         if (action == @selector(showScanPanel:))
528         {
529             if (s.state == HB_STATE_SCANNING)
530                 return NO;
531             else
532                 return [fWindow attachedSheet] == nil;
533         }
534         if (action == @selector(selectDefaultPreset:))
535             return [tableView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
536         if (action == @selector(Pause:))
537         {
538             if (s.state == HB_STATE_WORKING)
539             {
540                 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
541                     [menuItem setTitle:@"Pause Encoding"];
542                 return YES;
543             }
544             else if (s.state == HB_STATE_PAUSED)
545             {
546                 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
547                     [menuItem setTitle:@"Resume Encoding"];
548                 return YES;
549             }
550             else
551                 return NO;
552         }
553         if (action == @selector(Rip:))
554             if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
555             {
556                 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
557                     [menuItem setTitle:@"Stop Encoding"];
558                 return YES;
559             }
560             else if (SuccessfulScan)
561             {
562                 if(![[menuItem title] isEqualToString:@"Start Encoding"])
563                     [menuItem setTitle:@"Start Encoding"];
564                 return [fWindow attachedSheet] == nil;
565             }
566             else
567                 return NO;
568         }
569     
570     return YES;
571 }
572
573
574 // register a test notification and make
575 // it enabled by default
576 #define SERVICE_NAME @"Encode Done"
577 - (NSDictionary *)registrationDictionaryForGrowl 
578
579     NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys: 
580     [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL, 
581     [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT, 
582     nil]; 
583
584     return registrationDictionary; 
585
586
587 - (void) TranslateStrings
588 {
589     [fSrcTitleField     setStringValue: _( @"Title:" )];
590     [fSrcChapterField   setStringValue: _( @"Chapters:" )];
591     [fSrcChapterToField setStringValue: _( @"to" )];
592     [fSrcDuration1Field setStringValue: _( @"Duration:" )];
593
594     [fDstFormatField    setStringValue: _( @"Format:" )];
595     [fDstCodecsField    setStringValue: _( @"Codecs:" )];
596     [fDstFile1Field     setStringValue: _( @"File:" )];
597     [fDstBrowseButton   setTitle:       _( @"Browse" )];
598
599     [fVidRateField      setStringValue: _( @"Framerate (fps):" )];
600     [fVidEncoderField   setStringValue: _( @"Encoder:" )];
601     [fVidQualityField   setStringValue: _( @"Quality:" )];
602 }
603
604 /***********************************************************************
605  * UpdateDockIcon
606  ***********************************************************************
607  * Shows a progression bar on the dock icon, filled according to
608  * 'progress' (0.0 <= progress <= 1.0).
609  * Called with progress < 0.0 or progress > 1.0, restores the original
610  * icon.
611  **********************************************************************/
612 - (void) UpdateDockIcon: (float) progress
613 {
614     NSImage * icon;
615     NSData * tiff;
616     NSBitmapImageRep * bmp;
617     uint32_t * pen;
618     uint32_t black = htonl( 0x000000FF );
619     uint32_t red   = htonl( 0xFF0000FF );
620     uint32_t white = htonl( 0xFFFFFFFF );
621     int row_start, row_end;
622     int i, j;
623
624     /* Get application original icon */
625     icon = [NSImage imageNamed: @"NSApplicationIcon"];
626
627     if( progress < 0.0 || progress > 1.0 )
628     {
629         [NSApp setApplicationIconImage: icon];
630         return;
631     }
632
633     /* Get it in a raw bitmap form */
634     tiff = [icon TIFFRepresentationUsingCompression:
635             NSTIFFCompressionNone factor: 1.0];
636     bmp = [NSBitmapImageRep imageRepWithData: tiff];
637     
638     /* Draw the progression bar */
639     /* It's pretty simple (ugly?) now, but I'm no designer */
640
641     row_start = 3 * (int) [bmp size].height / 4;
642     row_end   = 7 * (int) [bmp size].height / 8;
643
644     for( i = row_start; i < row_start + 2; i++ )
645     {
646         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
647         for( j = 0; j < (int) [bmp size].width; j++ )
648         {
649             pen[j] = black;
650         }
651     }
652     for( i = row_start + 2; i < row_end - 2; i++ )
653     {
654         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
655         pen[0] = black;
656         pen[1] = black;
657         for( j = 2; j < (int) [bmp size].width - 2; j++ )
658         {
659             if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
660             {
661                 pen[j] = red;
662             }
663             else
664             {
665                 pen[j] = white;
666             }
667         }
668         pen[j]   = black;
669         pen[j+1] = black;
670     }
671     for( i = row_end - 2; i < row_end; i++ )
672     {
673         pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
674         for( j = 0; j < (int) [bmp size].width; j++ )
675         {
676             pen[j] = black;
677         }
678     }
679
680     /* Now update the dock icon */
681     tiff = [bmp TIFFRepresentationUsingCompression:
682             NSTIFFCompressionNone factor: 1.0];
683     icon = [[NSImage alloc] initWithData: tiff];
684     [NSApp setApplicationIconImage: icon];
685     [icon release];
686 }
687
688 - (void) updateUI: (NSTimer *) timer
689 {
690
691     hb_list_t  * list;
692     list = hb_get_titles( fHandle );    
693     /* check to see if there has been a new scan done
694         this bypasses the constraints of HB_STATE_WORKING
695         not allowing setting a newly scanned source */
696         int checkScanCount = hb_get_scancount( fHandle );
697         if (checkScanCount > currentScanCount)
698         {
699                 
700                 currentScanCount = checkScanCount;
701                 //[fScanController Cancel: NULL];
702                 [fScanIndicator setIndeterminate: NO];
703                 [fScanIndicator setDoubleValue: 0.0];
704                 [fScanIndicator setHidden: YES];
705
706                 [self showNewScan: NULL];
707         }
708         
709     BOOL jobGroups = [[NSUserDefaults standardUserDefaults] boolForKey:@"QueueShowsJobsAsGroups"];
710         
711     hb_state_t s;
712     hb_get_state( fHandle, &s );
713         
714         
715     switch( s.state )
716     {
717         case HB_STATE_IDLE:
718                 break;
719 #define p s.param.scanning                      
720         case HB_STATE_SCANNING:
721                 {
722             [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
723                 _( @"Scanning title %d of %d..." ),
724                 p.title_cur, p.title_count]];
725             [fScanIndicator setIndeterminate: NO];
726                         [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) /
727                 p.title_count];
728             break;
729                 }
730 #undef p
731         
732 #define p s.param.scandone
733         case HB_STATE_SCANDONE:
734         {
735                         
736                         [fScanIndicator setIndeterminate: NO];
737             [fScanIndicator setDoubleValue: 0.0];
738                         [fScanIndicator setHidden: YES];
739                         [self showNewScan: NULL];
740             [toolbar validateVisibleItems];
741                         break;
742         }
743 #undef p
744                         
745 #define p s.param.working
746         case HB_STATE_WORKING:
747         {
748             float progress_total;
749             NSMutableString * string;
750                         /* Currently, p.job_cur and p.job_count get screwed up when adding
751                                 jobs during encoding, if they cannot be fixed in libhb, will implement a
752                                 nasty but working cocoa solution */
753                         /* Update text field */
754                         string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress];
755             
756                         if( p.seconds > -1 )
757             {
758                 [string appendFormat:
759                     _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ),
760                     p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
761             }
762             [fStatusField setStringValue: string];
763                         
764             /* Update slider */
765                         progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
766             [fRipIndicator setIndeterminate: NO];
767             [fRipIndicator setDoubleValue: 100.0 * progress_total];
768                         
769             // If progress bar hasn't been revealed at the bottom of the window, do
770             // that now. This code used to be in _Rip. I moved it to here to handle
771             // the case where hb_start is called by HBQueueController and not from
772             // HBController.
773             if (!fRipIndicatorShown)
774             {
775                 NSRect frame = [fWindow frame];
776                 if (frame.size.width <= 591)
777                     frame.size.width = 591;
778                 frame.size.height += 36;
779                 frame.origin.y -= 36;
780                 [fWindow setFrame:frame display:YES animate:YES];
781                 fRipIndicatorShown = YES;
782             }
783
784             /* Update dock icon */
785             [self UpdateDockIcon: progress_total];
786                         
787             // Has current job changed? That means the queue has probably changed as
788                         // well so update it
789             if (fLastKnownCurrentJob != hb_current_job(fHandle))
790             {
791                 fLastKnownCurrentJob = hb_current_job(fHandle);
792                 [fQueueController updateQueueUI];
793             }
794             [fQueueController updateCurrentJobUI];
795             
796             break;
797         }
798 #undef p
799                         
800 #define p s.param.muxing
801         case HB_STATE_MUXING:
802         {
803             NSMutableString * string;
804                         
805             /* Update text field */
806             string = [NSMutableString stringWithFormat:
807                 _( @"Muxing..." )];
808             [fStatusField setStringValue: string];
809                         
810             /* Update slider */
811             [fRipIndicator setIndeterminate: YES];
812             [fRipIndicator startAnimation: nil];
813                         
814             /* Update dock icon */
815             [self UpdateDockIcon: 1.0];
816                         
817                         // Pass along the info to HBQueueController
818             [fQueueController updateCurrentJobUI];
819                         
820             break;
821         }
822 #undef p
823                         
824         case HB_STATE_PAUSED:
825                     [fStatusField setStringValue: _( @"Paused" )];
826             
827                         // Pass along the info to HBQueueController
828             [fQueueController updateCurrentJobUI];
829
830             break;
831                         
832         case HB_STATE_WORKDONE:
833         {
834             [fStatusField setStringValue: _( @"Done." )];
835             [fRipIndicator setIndeterminate: NO];
836             [fRipIndicator setDoubleValue: 0.0];
837             [toolbar validateVisibleItems];
838
839             /* Restore dock icon */
840             [self UpdateDockIcon: -1.0];
841
842             if (jobGroups)
843             {
844                 // Delete all remaining scans of this job
845                 hb_job_t * job;
846                 while( ( job = hb_job( fHandle, 0 ) ) && (job->sequence_id != 0) )
847                     hb_rem( fHandle, job );
848             }
849
850             // Start processing back up if jobs still left in queue
851             if (hb_count(fHandle) > 0)
852             {
853                 hb_start(fHandle);
854                 break;
855             }
856                         
857             if (fRipIndicatorShown)
858             {
859                 NSRect frame = [fWindow frame];
860                 if (frame.size.width <= 591)
861                                     frame.size.width = 591;
862                 frame.size.height += -36;
863                 frame.origin.y -= -36;
864                 [fWindow setFrame:frame display:YES animate:YES];
865                                 fRipIndicatorShown = NO;
866                         }
867                         
868             // Queue has been modified so update the UI
869                         fLastKnownCurrentJob = nil;
870             [fQueueController updateQueueUI];
871             [fQueueController updateCurrentJobUI];
872                         
873             /* Check to see if the encode state has not been cancelled
874                                 to determine if we should check for encode done notifications */
875                         if (fEncodeState != 2)                  {
876                                 /* If Growl Notification or Window and Growl has been selected */
877                                 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] || 
878                                         [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
879                 {
880                                         /*Growl Notification*/
881                                         [self showGrowlDoneNotification: NULL];
882                 }
883                 /* If Alert Window or Window and Growl has been selected */
884                                 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] || 
885                                         [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
886                 {
887                                         /*On Screen Notification*/
888                                         int status;
889                                         NSBeep();
890                                         status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
891                                         [NSApp requestUserAttention:NSCriticalRequest];
892                                         if ( status == NSAlertDefaultReturn ) 
893                                         {
894                                                 [self enableUI: YES];
895                                         }
896                 }
897                                 else
898                                 {
899                                         [self enableUI: YES];
900                                 }
901                                    /* If sleep has been selected */ 
902             if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"]) 
903                 { 
904                /* Sleep */ 
905                NSDictionary* errorDict; 
906                NSAppleEventDescriptor* returnDescriptor = NULL; 
907                NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: 
908                         @"tell application \"Finder\" to sleep"]; 
909                returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 
910                [scriptObject release]; 
911                [self enableUI: YES]; 
912                 } 
913             /* If Shutdown has been selected */ 
914             if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"]) 
915                 { 
916                /* Shut Down */ 
917                NSDictionary* errorDict; 
918                NSAppleEventDescriptor* returnDescriptor = NULL; 
919                NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: 
920                         @"tell application \"Finder\" to shut down"]; 
921                returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 
922                [scriptObject release]; 
923                [self enableUI: YES]; 
924                 }
925                         
926                                                 // MetaX insertion via AppleScript
927                         if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
928                         {
929                         NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", [fDstFile2Field stringValue], @"\")"]];
930                         [myScript executeAndReturnError: nil];
931                         [myScript release];
932                         }
933                         
934                         
935                         }
936                         else
937                         {
938                                 [self enableUI: YES];
939                         }
940             break;
941         }
942     }
943         
944     /* Lets show the queue status here in the main window */
945         int queue_count = jobGroups ? hb_group_count( fHandle ) : hb_count( fHandle );
946         if( queue_count )
947         {
948                 [fQueueStatus setStringValue: [NSString stringWithFormat:
949                         @"%d task%s in the queue",
950                                                  queue_count, ( queue_count > 1 ) ? "s" : ""]];
951         }
952         else
953         {
954                 [fQueueStatus setStringValue: @""];
955         }
956 }
957
958 - (IBAction) showNewScan:(id)sender
959 {
960         hb_list_t  * list;
961         hb_title_t * title;
962         int indxpri=0;    // Used to search the longuest title (default in combobox)
963         int longuestpri=0; // Used to search the longuest title (default in combobox)
964         
965         list = hb_get_titles( fHandle );
966         
967         if( !hb_list_count( list ) )
968         {
969                 /* We display a message if a valid dvd source was not chosen */
970                 [fSrcDVD2Field setStringValue: @"No Valid Title Found"];
971         SuccessfulScan = 0;
972         }
973         else
974         {
975      /* We increment the successful scancount here by one,
976                    which we use at the end of this function to tell the gui
977                    if this is the first successful scan since launch and whether
978                    or not we should set all settings to the defaults */
979                 
980         SuccessfulScan = 1;
981         currentSuccessfulScanCount++;
982
983                 [self enableUI: YES];
984
985         [toolbar validateVisibleItems];
986                 
987                 [fSrcTitlePopUp removeAllItems];
988                 for( int i = 0; i < hb_list_count( list ); i++ )
989                 {
990                         title = (hb_title_t *) hb_list_item( list, i );
991                         /*Set DVD Name at top of window*/
992                         [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]];
993                         
994                         currentSource = [NSString stringWithUTF8String: title->dvd];
995                         
996                         
997                         /* Use the dvd name in the default output field here 
998                                 May want to add code to remove blank spaces for some dvd names*/
999                         /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1000                         if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1001                         {
1002                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1003                                         @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString
1004                   stringWithUTF8String: title->name]]];
1005                         }
1006                         else
1007                         {
1008                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1009                                         @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString
1010                   stringWithUTF8String: title->name]]];
1011                         }
1012                         
1013                         
1014                         if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1015                         {
1016                                 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1017                                 indxpri=i;
1018                         }
1019                         
1020                         
1021                         int format = [fDstFormatPopUp indexOfSelectedItem];
1022                         char * ext = NULL;
1023                         switch( format )
1024                         {
1025                                 case 0:
1026                                         
1027                                         /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/
1028                                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1029                                         {
1030                                                 ext = "m4v";
1031                                         }
1032                                         else
1033                                         {
1034                                                 ext = "mp4";
1035                                         }
1036                                         break;
1037                                 case 1: 
1038                                         ext = "avi";
1039                                         break;
1040                                 case 2:
1041                                         ext = "ogm";
1042                                         break;
1043                                 case 3:
1044                                         ext = "mkv";
1045                                         break;
1046                         }
1047                         
1048                         
1049                         NSString * string = [fDstFile2Field stringValue];
1050                         /* Add/replace File Output name to the correct extension*/
1051                         if( [string characterAtIndex: [string length] - 4] == '.' )
1052                         {
1053                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1054                                         @"%@.%s", [string substringToIndex: [string length] - 4],
1055                                         ext]];
1056                         }
1057                         else
1058                         {
1059                                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1060                                         @"%@.%s", string, ext]];
1061                         }
1062                         
1063                         
1064                         [fSrcTitlePopUp addItemWithTitle: [NSString
1065                     stringWithFormat: @"%d - %02dh%02dm%02ds",
1066                                 title->index, title->hours, title->minutes,
1067                                 title->seconds]];
1068                         
1069                 }
1070                 // Select the longuest title
1071                 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1072                 [self titlePopUpChanged: NULL];
1073                 
1074                 
1075                 
1076                 [self enableUI: YES];
1077                 
1078                 /* we record the current source name here in case the next scan is unsuccessful,
1079                                 then we can replace the scan progress with the old name if necessary */
1080        sourceDisplayName = [NSString stringWithFormat:[fSrcDVD2Field stringValue]];
1081        
1082        /* if its the initial successful scan after awakeFromNib */
1083            if (currentSuccessfulScanCount == 1)
1084            {
1085            [self selectDefaultPreset: NULL];
1086            /* if Deinterlace upon launch is specified in the prefs, then set to 1 for "Fast",
1087            if not, then set to 0 for none */
1088            if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1089                [fPictureController setDeinterlace:1];
1090            else
1091                [fPictureController setDeinterlace:0];
1092            }
1093        
1094         }
1095 }
1096
1097 -(IBAction)showGrowlDoneNotification:(id)sender
1098 {
1099   [GrowlApplicationBridge 
1100           notifyWithTitle:@"Put down that cocktail..." 
1101               description:@"your HandBrake encode is done!" 
1102          notificationName:SERVICE_NAME
1103                  iconData:nil 
1104                  priority:0 
1105                  isSticky:1 
1106              clickContext:nil];
1107 }
1108
1109 - (void) enableUI: (bool) b
1110 {
1111     NSControl * controls[] =
1112       { fSrcTitleField, fSrcTitlePopUp,
1113         fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
1114         fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
1115         fDstFormatField, fDstFormatPopUp, fDstCodecsField,
1116         fDstCodecsPopUp, fDstFile1Field, fDstFile2Field,
1117         fDstBrowseButton, fVidRateField, fVidRatePopUp,
1118         fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
1119         fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
1120         fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
1121         fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
1122         fAudRateField, fAudRatePopUp, fAudBitrateField,
1123         fAudBitratePopUp, fPictureButton,fQueueStatus, 
1124                 fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,fPicSettingARkeep,
1125                 fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
1126                 fPicLabelAr,fPicLabelDeinterlace,fPicLabelSrcX,fPicLabelOutputX,
1127                 fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
1128                 fPicSettingPAR,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
1129                 fCreateChapterMarkers,fVidTurboPassCheck,fDstMpgLargeFileCheck,fPicLabelAutoCrop,
1130                 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,fSubForcedCheck,};
1131
1132     for( unsigned i = 0;
1133          i < sizeof( controls ) / sizeof( NSControl * ); i++ )
1134     {
1135         if( [[controls[i] className] isEqualToString: @"NSTextField"] )
1136         {
1137             NSTextField * tf = (NSTextField *) controls[i];
1138             if( ![tf isBezeled] )
1139             {
1140                 [tf setTextColor: b ? [NSColor controlTextColor] :
1141                     [NSColor disabledControlTextColor]];
1142                 continue;
1143             }
1144         }
1145         [controls[i] setEnabled: b];
1146
1147     }
1148         
1149         if (b) {
1150
1151         /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
1152         /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
1153         [self setEnabledStateOfAudioMixdownControls: NULL];
1154         
1155         } else {
1156
1157                 [tableView setEnabled: NO];
1158         
1159         }
1160
1161     [self videoMatrixChanged: NULL];
1162     [fAdvancedOptions enableUI:b];
1163 }
1164
1165 - (IBAction) showScanPanel: (id) sender
1166 {
1167     [self enableUI: NO];
1168         
1169         [self browseSources:NULL];
1170 }
1171
1172 - (void) browseSources: (id) sender
1173 {
1174     NSOpenPanel * panel;
1175         
1176     panel = [NSOpenPanel openPanel];
1177     [panel setAllowsMultipleSelection: NO];
1178     [panel setCanChooseFiles: YES];
1179     [panel setCanChooseDirectories: YES ];
1180     NSString * sourceDirectory;
1181         if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1182         {
1183                 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1184         }
1185         else
1186         {
1187                 sourceDirectory = @"~/Desktop";
1188                 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1189         }
1190    [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1191                                    modalForWindow: fWindow modalDelegate: self
1192                                    didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1193                                           contextInfo: nil];
1194 }
1195
1196 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1197                  returnCode: (int) returnCode contextInfo: (void *) contextInfo
1198 {
1199     /* User selected a file to open */
1200         if( returnCode == NSOKButton )
1201     {
1202         [fSrcDVD2Field setStringValue: _( @"Opening a new source ..." )];
1203                 [fScanIndicator setHidden: NO];
1204             [fScanIndicator setIndeterminate: YES];
1205         [fScanIndicator startAnimation: nil];
1206                 
1207                 /* we set the last source directory in the prefs here */
1208                 NSString *sourceDirectory = [[[sheet filenames] objectAtIndex: 0] stringByDeletingLastPathComponent];
1209                 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1210                 
1211         NSString *path = [[sheet filenames] objectAtIndex: 0];
1212         HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1213         if( [detector isVideoDVD] )
1214         {
1215             // The chosen path was actually on a DVD, so use the raw block
1216             // device path instead.
1217             path = [detector devicePath];
1218         }
1219                 
1220                 hb_scan( fHandle, [path UTF8String], 0 );
1221         }
1222         else // User clicked Cancel in browse window
1223         {
1224                 /* if we have a title loaded up */
1225                 if ([[fSrcDVD2Field stringValue] length] > 0)
1226                 {
1227             [self enableUI: YES];
1228         }
1229         }
1230 }
1231
1232 - (IBAction) openMainWindow: (id) sender
1233 {
1234     [fWindow  makeKeyAndOrderFront:nil];
1235     [fWindow setReleasedWhenClosed: YES];
1236 }
1237
1238 - (BOOL) windowShouldClose: (id) sender
1239 {
1240     [fWindow setReleasedWhenClosed: NO];
1241     return YES;
1242 }
1243
1244 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1245 {
1246     if( !flag ) {
1247         [fWindow  makeKeyAndOrderFront:nil];
1248         [fWindow setReleasedWhenClosed: YES];
1249         
1250         return YES;
1251     }
1252     
1253     return NO;
1254 }
1255
1256 - (IBAction) videoMatrixChanged: (id) sender;
1257 {
1258     bool target, bitrate, quality;
1259
1260     target = bitrate = quality = false;
1261     if( [fVidQualityMatrix isEnabled] )
1262     {
1263         switch( [fVidQualityMatrix selectedRow] )
1264         {
1265             case 0:
1266                 target = true;
1267                 break;
1268             case 1:
1269                 bitrate = true;
1270                 break;
1271             case 2:
1272                 quality = true;
1273                 break;
1274         }
1275     }
1276     [fVidTargetSizeField  setEnabled: target];
1277     [fVidBitrateField     setEnabled: bitrate];
1278     [fVidQualitySlider    setEnabled: quality];
1279     [fVidTwoPassCheck     setEnabled: !quality &&
1280         [fVidQualityMatrix isEnabled]];
1281     if( quality )
1282     {
1283         [fVidTwoPassCheck setState: NSOffState];
1284                 [fVidTurboPassCheck setHidden: YES];
1285                 [fVidTurboPassCheck setState: NSOffState];
1286     }
1287
1288     [self qualitySliderChanged: sender];
1289     [self calculateBitrate:     sender];
1290         [self customSettingUsed: sender];
1291 }
1292
1293 - (IBAction) qualitySliderChanged: (id) sender
1294 {
1295     [fVidConstantCell setTitle: [NSString stringWithFormat:
1296         _( @"Constant quality: %.0f %%" ), 100.0 *
1297         [fVidQualitySlider floatValue]]];
1298                 [self customSettingUsed: sender];
1299 }
1300
1301 - (IBAction) browseFile: (id) sender
1302 {
1303     /* Open a panel to let the user choose and update the text field */
1304     NSSavePanel * panel = [NSSavePanel savePanel];
1305         /* We get the current file name and path from the destination field here */
1306         [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1307                                    modalForWindow: fWindow modalDelegate: self
1308                                    didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1309                                           contextInfo: NULL];
1310 }
1311
1312 - (void) browseFileDone: (NSSavePanel *) sheet
1313     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1314 {
1315     if( returnCode == NSOKButton )
1316     {
1317         [fDstFile2Field setStringValue: [sheet filename]];
1318     }
1319 }
1320
1321 - (IBAction) showPicturePanel: (id) sender
1322 {
1323         hb_list_t  * list  = hb_get_titles( fHandle );
1324     hb_title_t * title = (hb_title_t *) hb_list_item( list,
1325             [fSrcTitlePopUp indexOfSelectedItem] );
1326     [fPictureController showPanelInWindow:fWindow forTitle:title];
1327 }
1328
1329 - (void)pictureSettingsDidChange {
1330         [self calculatePictureSizing: NULL];
1331 }
1332
1333 - (void) PrepareJob
1334 {
1335     hb_list_t  * list  = hb_get_titles( fHandle );
1336     hb_title_t * title = (hb_title_t *) hb_list_item( list,
1337             [fSrcTitlePopUp indexOfSelectedItem] );
1338     hb_job_t * job = title->job;
1339     //int i;
1340
1341     /* Chapter selection */
1342     job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
1343     job->chapter_end   = [fSrcChapterEndPopUp   indexOfSelectedItem] + 1;
1344         
1345     /* Format and codecs */
1346     int format = [fDstFormatPopUp indexOfSelectedItem];
1347     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1348     job->mux    = FormatSettings[format][codecs] & HB_MUX_MASK;
1349     job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
1350     job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1351     /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
1352         if ([fDstFormatPopUp indexOfSelectedItem] == 0)
1353         {
1354         /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
1355                 mpeg4 and the checkbox being checked 
1356                 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
1357                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0 && [fDstMpgLargeFileCheck state] == NSOnState)
1358                 {
1359                         job->largeFileSize = 1;
1360                 }
1361                 else
1362                 {
1363                         job->largeFileSize = 0;
1364                 }
1365         }
1366         if ([fDstFormatPopUp indexOfSelectedItem] == 0 || [fDstFormatPopUp indexOfSelectedItem] == 3)
1367         {
1368           /* We set the chapter marker extraction here based on the format being
1369                 mpeg4 or mkv and the checkbox being checked */
1370                 if ([fCreateChapterMarkers state] == NSOnState)
1371                 {
1372                         job->chapter_markers = 1;
1373                 }
1374                 else
1375                 {
1376                         job->chapter_markers = 0;
1377                 }
1378         }
1379         if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
1380         [fVidEncoderPopUp indexOfSelectedItem] > 0 )
1381     {
1382         job->vcodec = HB_VCODEC_XVID;
1383     }
1384     if( job->vcodec & HB_VCODEC_X264 )
1385     {
1386                 if ([fVidEncoderPopUp indexOfSelectedItem] > 0 )
1387             {
1388                         /* Just use new Baseline Level 3.0 
1389                         Lets Deprecate Baseline Level 1.3h264_level*/
1390                         job->h264_level = 30;
1391                         job->mux = HB_MUX_IPOD;
1392                         /* move sanity check for iPod Encoding here */
1393                         job->pixel_ratio = 0 ;
1394                         
1395                 }
1396                 
1397                 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
1398                 Currently only used with Constant Quality setting*/
1399                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
1400                 {
1401                 job->crf = 1;
1402                 }
1403                 
1404                 /* Below Sends x264 options to the core library if x264 is selected*/
1405                 /* Lets use this as per Nyx, Thanks Nyx!*/
1406                 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1407                 /* Turbo first pass if two pass and Turbo First pass is selected */
1408                 if( [fVidTwoPassCheck state] == NSOnState && [fVidTurboPassCheck state] == NSOnState )
1409                 {
1410                         /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
1411                         NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0";
1412                         /* append the "Turbo" string variable to the existing opts string.
1413                         Note: the "Turbo" string must be appended, not prepended to work properly*/
1414                         NSString *firstPassOptStringCombined = [[fAdvancedOptions optionsString] stringByAppendingString:firstPassOptStringTurbo];
1415                         strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
1416                 }
1417                 else
1418                 {
1419                         strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1420                 }
1421                 
1422         job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
1423     }
1424
1425     /* Video settings */
1426     if( [fVidRatePopUp indexOfSelectedItem] > 0 )
1427     {
1428         job->vrate      = 27000000;
1429         job->vrate_base = hb_video_rates[[fVidRatePopUp
1430             indexOfSelectedItem]-1].rate;
1431     }
1432     else
1433     {
1434         job->vrate      = title->rate;
1435         job->vrate_base = title->rate_base;
1436     }
1437
1438     switch( [fVidQualityMatrix selectedRow] )
1439     {
1440         case 0:
1441             /* Target size.
1442                Bitrate should already have been calculated and displayed
1443                in fVidBitrateField, so let's just use it */
1444         case 1:
1445             job->vquality = -1.0;
1446             job->vbitrate = [fVidBitrateField intValue];
1447             break;
1448         case 2:
1449             job->vquality = [fVidQualitySlider floatValue];
1450             job->vbitrate = 0;
1451             break;
1452     }
1453
1454     job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
1455
1456     /* Subtitle settings */
1457     job->subtitle = [fSubPopUp indexOfSelectedItem] - 2;
1458
1459     /* Audio tracks and mixdowns */
1460     /* check for the condition where track 2 has an audio selected, but track 1 does not */
1461     /* we will use track 2 as track 1 in this scenario */
1462     if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1463     {
1464         job->audios[0] = [fAudLang1PopUp indexOfSelectedItem] - 1;
1465         job->audios[1] = [fAudLang2PopUp indexOfSelectedItem] - 1; /* will be -1 if "none" is selected */
1466         job->audios[2] = -1;
1467         job->audio_mixdowns[0] = [[fAudTrack1MixPopUp selectedItem] tag];
1468         job->audio_mixdowns[1] = [[fAudTrack2MixPopUp selectedItem] tag];
1469     }
1470     else if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1471     {
1472         job->audios[0] = [fAudLang2PopUp indexOfSelectedItem] - 1;
1473         job->audio_mixdowns[0] = [[fAudTrack2MixPopUp selectedItem] tag];
1474         job->audios[1] = -1;
1475     }
1476     else
1477     {
1478         job->audios[0] = -1;
1479     }
1480
1481     /* Audio settings */
1482     job->arate = hb_audio_rates[[fAudRatePopUp
1483                      indexOfSelectedItem]].rate;
1484     job->abitrate = [[fAudBitratePopUp selectedItem] tag];
1485     
1486     job->filters = hb_list_init();
1487    
1488         /* Detelecine */
1489     if ([fPictureController detelecine])
1490     {
1491         hb_list_add( job->filters, &hb_filter_detelecine );
1492     }
1493    
1494     /* Deinterlace */
1495     if ([fPictureController deinterlace] == 1)
1496     {
1497         /* Run old deinterlacer by default */
1498         hb_filter_deinterlace.settings = "-1"; 
1499         hb_list_add( job->filters, &hb_filter_deinterlace );
1500     }
1501     else if ([fPictureController deinterlace] == 2)
1502     {
1503         /* Yadif mode 0 (1-pass with spatial deinterlacing.) */
1504         hb_filter_deinterlace.settings = "0"; 
1505         hb_list_add( job->filters, &hb_filter_deinterlace );            
1506     }
1507     else if ([fPictureController deinterlace] == 3)
1508     {
1509         /* Yadif (1-pass w/o spatial deinterlacing) and Mcdeint */
1510         hb_filter_deinterlace.settings = "2:-1:1"; 
1511         hb_list_add( job->filters, &hb_filter_deinterlace );            
1512     }
1513     else if ([fPictureController deinterlace] == 4)
1514     {
1515         /* Yadif (2-pass w/ spatial deinterlacing) and Mcdeint*/
1516         hb_filter_deinterlace.settings = "1:-1:1"; 
1517         hb_list_add( job->filters, &hb_filter_deinterlace );            
1518     }
1519         
1520         /* Denoise */
1521         
1522         if ([fPictureController denoise] == 1) // Weak in popup
1523         {
1524                 hb_filter_denoise.settings = "2:1:2:3"; 
1525         hb_list_add( job->filters, &hb_filter_denoise );        
1526         }
1527         else if ([fPictureController denoise] == 2) // Medium in popup
1528         {
1529                 hb_filter_denoise.settings = "3:2:2:3"; 
1530         hb_list_add( job->filters, &hb_filter_denoise );        
1531         }
1532         else if ([fPictureController denoise] == 3) // Strong in popup
1533         {
1534                 hb_filter_denoise.settings = "7:7:5:5"; 
1535         hb_list_add( job->filters, &hb_filter_denoise );        
1536         }
1537
1538 }
1539
1540
1541
1542 - (IBAction) addToQueue: (id) sender
1543 {
1544 /* We get the destination directory from the destingation field here */
1545         NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1546         /* We check for a valid destination here */
1547         if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0) 
1548         {
1549                 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1550         }
1551         else
1552         {
1553                 
1554                 hb_list_t  * list  = hb_get_titles( fHandle );
1555                 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1556                                                                                                                   [fSrcTitlePopUp indexOfSelectedItem] );
1557                 hb_job_t * job = title->job;
1558                 
1559         // Assign a sequence number, starting at zero, to each job added so they can
1560         // be lumped together in the UI.
1561         job->sequence_id = -1;
1562                 
1563                 [self PrepareJob];
1564                 
1565                 /* Destination file */
1566                 job->file = [[fDstFile2Field stringValue] UTF8String];
1567
1568                 if( [fSubForcedCheck state] == NSOnState )
1569                 {
1570                     job->subtitle_force = 1;
1571                 } else {
1572                     job->subtitle_force = 0;
1573                 }
1574
1575                 /*
1576                  * subtitle of -1 is a scan
1577                  */
1578                 if( job->subtitle == -1 )
1579                 {
1580                     char *x264opts_tmp;
1581
1582                     /*
1583                      * When subtitle scan is enabled do a fast pre-scan job
1584                      * which will determine which subtitles to enable, if any.
1585                      */
1586                     job->pass = -1;
1587                     x264opts_tmp = job->x264opts;
1588                     job->subtitle = -1;
1589
1590                     job->x264opts = NULL;
1591                     
1592                     job->subtitle_scan = 1;  
1593
1594                     job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
1595                     *(job->select_subtitle) = NULL;
1596                     
1597                     /*
1598                      * Add the pre-scan job
1599                      */
1600                                         job->sequence_id++; // for job grouping
1601                     hb_add( fHandle, job );
1602
1603                     job->x264opts = x264opts_tmp;
1604                 } else {
1605                     job->select_subtitle = NULL;
1606                 }
1607
1608                 /* No subtitle were selected, so reset the subtitle to -1 (which before
1609                  * this point meant we were scanning
1610                  */
1611                 if( job->subtitle == -2 )
1612                 {
1613                     job->subtitle = -1;
1614                 }
1615
1616                 if( [fVidTwoPassCheck state] == NSOnState )
1617                 {
1618             hb_subtitle_t **subtitle_tmp = job->select_subtitle;
1619             job->select_subtitle = NULL;
1620             job->subtitle_scan = 0;
1621
1622                         job->pass = 1;
1623                         job->sequence_id++; // for job grouping
1624                         hb_add( fHandle, job );
1625             
1626                         job->pass = 2;
1627                         job->sequence_id++; // for job grouping
1628                         
1629                         job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */  
1630                         strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
1631
1632             job->select_subtitle = subtitle_tmp;
1633
1634                         hb_add( fHandle, job );
1635                 }
1636                 else
1637                 {
1638                         job->subtitle_scan = 0;
1639                         job->pass = 0;
1640                         job->sequence_id++; // for job grouping
1641                         hb_add( fHandle, job );
1642                 }
1643         
1644         [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1645         /* Lets try to update stuff, taken from remove in the queue controller */
1646         [fQueueController performSelectorOnMainThread: @selector( updateQueueUI )
1647         withObject: NULL waitUntilDone: NO];
1648         }
1649 }
1650
1651 - (IBAction) Rip: (id) sender
1652 {
1653     /* Rip or Cancel ? */
1654     hb_state_t s;
1655     hb_get_state2( fHandle, &s );
1656
1657     if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
1658         {
1659         [self Cancel: sender];
1660         return;
1661     }
1662         /* if there is no job in the queue, then add it to the queue and rip 
1663         otherwise, there are already jobs in queue, so just rip the queue */
1664         int count = hb_count( fHandle );
1665         if( count < 1 )
1666         {
1667                 [self addToQueue: sender];
1668                 }
1669     
1670             /* We check for duplicate name here */
1671         if( [[NSFileManager defaultManager] fileExistsAtPath:
1672             [fDstFile2Field stringValue]] )
1673     {
1674         NSBeginCriticalAlertSheet( _( @"File already exists" ),
1675             _( @"Cancel" ), _( @"Overwrite" ), NULL, fWindow, self,
1676             @selector( overWriteAlertDone:returnCode:contextInfo: ),
1677             NULL, NULL, [NSString stringWithFormat:
1678             _( @"Do you want to overwrite %@?" ),
1679             [fDstFile2Field stringValue]] );
1680         return;
1681     }
1682         /* We get the destination directory from the destination field here */
1683         NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1684         /* We check for a valid destination here */
1685         if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0) 
1686         {
1687                 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1688         }
1689         else
1690         {
1691         [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1692                 [self _Rip];
1693         }
1694         
1695
1696
1697 }
1698
1699 - (void) overWriteAlertDone: (NSWindow *) sheet
1700     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1701 {
1702     if( returnCode == NSAlertAlternateReturn )
1703     {
1704         [self _Rip];
1705     }
1706 }
1707
1708 - (void) updateAlertDone: (NSWindow *) sheet
1709     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1710 {
1711     if( returnCode == NSAlertAlternateReturn )
1712     {
1713         /* Show scan panel */
1714         [self performSelectorOnMainThread: @selector(showScanPanel:)
1715             withObject: NULL waitUntilDone: NO];
1716         return;
1717     }
1718
1719     /* Go to HandBrake homepage and exit */
1720     [self openHomepage: NULL];
1721     [NSApp terminate: self];
1722 }
1723
1724 - (void) _Rip
1725 {
1726     /* Let libhb do the job */
1727     hb_start( fHandle );
1728         /*set the fEncodeState State */
1729         fEncodeState = 1;
1730 }
1731
1732 - (IBAction) Cancel: (id) sender
1733 {
1734     NSBeginCriticalAlertSheet( _( @"Cancel - Are you sure?" ),
1735         _( @"Keep working" ), _( @"Cancel encoding" ), NULL, fWindow, self,
1736         @selector( _Cancel:returnCode:contextInfo: ), NULL, NULL,
1737         _( @"Encoding won't be recoverable." ) );
1738 }
1739
1740 - (void) _Cancel: (NSWindow *) sheet
1741     returnCode: (int) returnCode contextInfo: (void *) contextInfo
1742 {
1743     if( returnCode == NSAlertAlternateReturn )
1744     {
1745         hb_stop( fHandle );
1746                 /*set the fEncodeState State */
1747              fEncodeState = 2;
1748     }
1749 }
1750
1751 - (IBAction) Pause: (id) sender
1752 {
1753     hb_state_t s;
1754     hb_get_state2( fHandle, &s );
1755
1756     if( s.state == HB_STATE_PAUSED )
1757     {
1758         hb_resume( fHandle );
1759     }
1760     else
1761     {
1762         hb_pause( fHandle );
1763     }
1764 }
1765
1766 - (IBAction) titlePopUpChanged: (id) sender
1767 {
1768     hb_list_t  * list  = hb_get_titles( fHandle );
1769     hb_title_t * title = (hb_title_t*)
1770     hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1771                 
1772                 
1773     /* If Auto Naming is on. We create an output filename of dvd name - title number */
1774     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
1775         {
1776                 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1777                         @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
1778                         [NSString stringWithUTF8String: title->name],
1779                           title->index,
1780                         [[fDstFile2Field stringValue] pathExtension]]]; 
1781         }
1782
1783     /* Update chapter popups */
1784     [fSrcChapterStartPopUp removeAllItems];
1785     [fSrcChapterEndPopUp   removeAllItems];
1786     for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
1787     {
1788         [fSrcChapterStartPopUp addItemWithTitle: [NSString
1789             stringWithFormat: @"%d", i + 1]];
1790         [fSrcChapterEndPopUp addItemWithTitle: [NSString
1791             stringWithFormat: @"%d", i + 1]];
1792     }
1793     [fSrcChapterStartPopUp selectItemAtIndex: 0];
1794     [fSrcChapterEndPopUp   selectItemAtIndex:
1795         hb_list_count( title->list_chapter ) - 1];
1796     [self chapterPopUpChanged: NULL];
1797
1798 /* Start Get and set the initial pic size for display */
1799         hb_job_t * job = title->job;
1800         fTitle = title; 
1801         /* Turn Deinterlace on/off depending on the preference */
1802         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1803         {
1804                 [fPictureController setDeinterlace:1];
1805         }
1806         else
1807         {
1808                 [fPictureController setDeinterlace:0];
1809         }
1810         
1811         /* Pixel Ratio Setting */
1812         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
1813     {
1814                 job->pixel_ratio = 1 ;
1815         }
1816         else
1817         {
1818                 job->pixel_ratio = 0 ;
1819         }
1820         /*Set Source Size Fields Here */
1821         [fPicSrcWidth setStringValue: [NSString stringWithFormat:
1822                                                          @"%d", fTitle->width]];
1823         [fPicSrcHeight setStringValue: [NSString stringWithFormat:
1824                                                          @"%d", fTitle->height]];
1825                                                          
1826         /* Set Auto Crop to on upon selecting a new title */
1827     [fPictureController setAutoCrop:YES];
1828     
1829         /* We get the originial output picture width and height and put them
1830         in variables for use with some presets later on */
1831         PicOrigOutputWidth = job->width;
1832         PicOrigOutputHeight = job->height;
1833         AutoCropTop = job->crop[0];
1834         AutoCropBottom = job->crop[1];
1835         AutoCropLeft = job->crop[2];
1836         AutoCropRight = job->crop[3];
1837         /* we test getting the max output value for pic sizing here to be used later*/
1838         [fPicSettingWidth setStringValue: [NSString stringWithFormat:
1839                 @"%d", PicOrigOutputWidth]];
1840         [fPicSettingHeight setStringValue: [NSString stringWithFormat:
1841                 @"%d", PicOrigOutputHeight]];
1842         /* we run the picture size values through
1843         calculatePictureSizing to get all picture size
1844         information*/
1845         [self calculatePictureSizing: NULL];
1846         /* Run Through encoderPopUpChanged to see if there
1847                 needs to be any pic value modifications based on encoder settings */
1848         //[self encoderPopUpChanged: NULL];
1849         /* END Get and set the initial pic size for display */ 
1850
1851     /* Update subtitle popups */
1852     hb_subtitle_t * subtitle;
1853     [fSubPopUp removeAllItems];
1854     [fSubPopUp addItemWithTitle: @"None"];
1855     [fSubPopUp addItemWithTitle: @"Autoselect"];
1856     for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
1857     {
1858         subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
1859
1860         /* We cannot use NSPopUpButton's addItemWithTitle because
1861            it checks for duplicate entries */
1862         [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
1863             subtitle->lang] action: NULL keyEquivalent: @""];
1864     }
1865     [fSubPopUp selectItemAtIndex: 0];
1866         
1867         [self subtitleSelectionChanged: NULL];
1868     
1869     /* Update chapter table */
1870     [fChapterTitlesDelegate resetWithTitle:title];
1871     [fChapterTable reloadData];
1872
1873     /* Update audio popups */
1874     [self addAllAudioTracksToPopUp: fAudLang1PopUp];
1875     [self addAllAudioTracksToPopUp: fAudLang2PopUp];
1876     /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
1877         NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
1878         [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
1879     [self selectAudioTrackInPopUp: fAudLang2PopUp searchPrefixString: NULL selectIndexIfNotFound: 0];
1880         
1881         /* changing the title may have changed the audio channels on offer, */
1882         /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1883         [self audioTrackPopUpChanged: fAudLang1PopUp];
1884         [self audioTrackPopUpChanged: fAudLang2PopUp];
1885         /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
1886         [self tableViewSelected:NULL];
1887 }
1888
1889 - (IBAction) chapterPopUpChanged: (id) sender
1890 {
1891     
1892         /* If start chapter popup is greater than end chapter popup,
1893         we set the end chapter popup to the same as start chapter popup */
1894         if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
1895         {
1896                 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
1897     }
1898
1899                 
1900         hb_list_t  * list  = hb_get_titles( fHandle );
1901     hb_title_t * title = (hb_title_t *)
1902         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1903
1904     hb_chapter_t * chapter;
1905     int64_t        duration = 0;
1906     for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
1907          i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
1908     {
1909         chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
1910         duration += chapter->duration;
1911     }
1912     
1913     duration /= 90000; /* pts -> seconds */
1914     [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
1915         @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
1916         duration % 60]];
1917
1918     [self calculateBitrate: sender];
1919 }
1920
1921 - (IBAction) formatPopUpChanged: (id) sender
1922 {
1923     NSString * string = [fDstFile2Field stringValue];
1924     int format = [fDstFormatPopUp indexOfSelectedItem];
1925     char * ext = NULL;
1926         /* Initially set the large file (64 bit formatting) output checkbox to hidden */
1927     [fDstMpgLargeFileCheck setHidden: YES];
1928     /* Update the codecs popup */
1929     [fDstCodecsPopUp removeAllItems];
1930     switch( format )
1931     {
1932         case 0:
1933                         /*Get Default MP4 File Extension*/
1934                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1935                         {
1936                                 ext = "m4v";
1937                         }
1938                         else
1939                         {
1940                                 ext = "mp4";
1941                         }
1942             [fDstCodecsPopUp addItemWithTitle:
1943                 _( @"MPEG-4 Video / AAC Audio" )];
1944             [fDstCodecsPopUp addItemWithTitle:
1945                 _( @"AVC/H.264 Video / AAC Audio" )];
1946                         /* We enable the create chapters checkbox here since we are .mp4*/
1947                         [fCreateChapterMarkers setEnabled: YES];
1948                         /* We show the Large File (64 bit formatting) checkbox since we are .mp4 
1949                         if we have enabled the option in the global preferences*/
1950                         if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0)
1951                         {
1952                                 [fDstMpgLargeFileCheck setHidden: NO];
1953                         }
1954                                 else
1955                                 {
1956                                         /* if not enable in global preferences, we additionaly sanity check that the
1957                                         hidden checkbox is set to off. */
1958                                         [fDstMpgLargeFileCheck setState: NSOffState];
1959                                 }
1960                                 break;
1961         case 1: 
1962             ext = "avi";
1963             [fDstCodecsPopUp addItemWithTitle:
1964                 _( @"MPEG-4 Video / MP3 Audio" )];
1965             [fDstCodecsPopUp addItemWithTitle:
1966                 _( @"MPEG-4 Video / AC-3 Audio" )];
1967             [fDstCodecsPopUp addItemWithTitle:
1968                 _( @"AVC/H.264 Video / MP3 Audio" )];
1969             [fDstCodecsPopUp addItemWithTitle:
1970                 _( @"AVC/H.264 Video / AC-3 Audio" )];
1971                         /* We disable the create chapters checkbox here since we are NOT .mp4 
1972                         and make sure it is unchecked*/
1973                         [fCreateChapterMarkers setEnabled: NO];
1974                         [fCreateChapterMarkers setState: NSOffState];
1975                         break;
1976         case 2:
1977             ext = "ogm";
1978             [fDstCodecsPopUp addItemWithTitle:
1979                 _( @"MPEG-4 Video / Vorbis Audio" )];
1980             [fDstCodecsPopUp addItemWithTitle:
1981                 _( @"MPEG-4 Video / MP3 Audio" )];
1982             /* We disable the create chapters checkbox here since we are NOT .mp4 
1983                         and make sure it is unchecked*/
1984                         [fCreateChapterMarkers setEnabled: NO];
1985                         [fCreateChapterMarkers setState: NSOffState];
1986                         break;
1987                 case 3:
1988             ext = "mkv";
1989             [fDstCodecsPopUp addItemWithTitle:
1990                 _( @"MPEG-4 Video / AAC Audio" )];
1991                                 [fDstCodecsPopUp addItemWithTitle:
1992                 _( @"MPEG-4 Video / AC-3 Audio" )];
1993                         [fDstCodecsPopUp addItemWithTitle:
1994                 _( @"MPEG-4 Video / MP3 Audio" )];
1995                         [fDstCodecsPopUp addItemWithTitle:
1996                 _( @"MPEG-4 Video / Vorbis Audio" )];
1997             
1998                         [fDstCodecsPopUp addItemWithTitle:
1999                 _( @"AVC/H.264 Video / AAC Audio" )];
2000                         [fDstCodecsPopUp addItemWithTitle:
2001                 _( @"AVC/H.264 Video / AC-3 Audio" )];
2002                         [fDstCodecsPopUp addItemWithTitle:
2003                 _( @"AVC/H.264 Video / MP3 Audio" )];
2004                         [fDstCodecsPopUp addItemWithTitle:
2005                 _( @"AVC/H.264 Video / Vorbis Audio" )];
2006             /* We disable the create chapters checkbox here since we are NOT .mp4 
2007                         and make sure it is unchecked*/
2008                         [fCreateChapterMarkers setEnabled: YES];
2009                         break;
2010     }
2011     [self codecsPopUpChanged: NULL];
2012
2013     /* Add/replace to the correct extension */
2014     if( [string characterAtIndex: [string length] - 4] == '.' )
2015     {
2016         [fDstFile2Field setStringValue: [NSString stringWithFormat:
2017             @"%@.%s", [string substringToIndex: [string length] - 4],
2018             ext]];
2019     }
2020     else
2021     {
2022         [fDstFile2Field setStringValue: [NSString stringWithFormat:
2023             @"%@.%s", string, ext]];
2024     }
2025
2026         /* changing the format may mean that we can / can't offer mono or 6ch, */
2027         /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
2028         [self audioTrackPopUpChanged: fAudLang1PopUp];
2029         [self audioTrackPopUpChanged: fAudLang2PopUp];
2030         /* We call the method to properly enable/disable turbo 2 pass */
2031         [self twoPassCheckboxChanged: sender];
2032         /* We call method method to change UI to reflect whether a preset is used or not*/
2033         [self customSettingUsed: sender];       
2034         
2035 }
2036
2037 - (IBAction) codecsPopUpChanged: (id) sender
2038 {
2039     int format = [fDstFormatPopUp indexOfSelectedItem];
2040     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2041         
2042     [fAdvancedOptions setHidden:YES];
2043
2044     /* Update the encoder popup*/
2045     if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
2046     {
2047         /* MPEG-4 -> H.264 */
2048         [fVidEncoderPopUp removeAllItems];
2049                 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 Main)"];
2050                 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 iPod)"];
2051                 [fVidEncoderPopUp selectItemAtIndex: 0];
2052         [fAdvancedOptions setHidden:NO];
2053     }
2054     
2055     else if( ( FormatSettings[format][codecs] & HB_VCODEC_FFMPEG ) )
2056     {
2057         /* H.264 -> MPEG-4 */
2058         [fVidEncoderPopUp removeAllItems];
2059         [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
2060         [fVidEncoderPopUp addItemWithTitle: @"XviD"];
2061         [fVidEncoderPopUp selectItemAtIndex: 0];
2062                                 
2063     }
2064
2065     if( FormatSettings[format][codecs] & HB_ACODEC_AC3 )
2066     {
2067         /* AC-3 pass-through: disable samplerate and bitrate */
2068         [fAudRatePopUp    setEnabled: NO];
2069         [fAudBitratePopUp setEnabled: NO];
2070     }
2071     else
2072     {
2073         [fAudRatePopUp    setEnabled: YES];
2074         [fAudBitratePopUp setEnabled: YES];
2075     }
2076     /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
2077         /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
2078         [self audioTrackPopUpChanged: fAudLang1PopUp];
2079         [self audioTrackPopUpChanged: fAudLang2PopUp];
2080
2081     [self calculateBitrate: sender];
2082     [self twoPassCheckboxChanged: sender];
2083 }
2084
2085 - (IBAction) encoderPopUpChanged: (id) sender
2086 {
2087     
2088         /* Check to see if we need to modify the job pic values based on x264 (iPod) encoder selection */
2089     if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fDstCodecsPopUp indexOfSelectedItem] == 1 && [fVidEncoderPopUp indexOfSelectedItem] == 1)
2090     {
2091                 hb_job_t * job = fTitle->job;
2092                 job->pixel_ratio = 0 ;
2093                 
2094                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPicSizeAutoiPod"] > 0)
2095                 {
2096                         
2097                         if (job->width > 640)
2098                         {
2099                                 job->width = 640;
2100                         }
2101                         job->keep_ratio = 1;
2102                         hb_fix_aspect( job, HB_KEEP_WIDTH );
2103                         
2104                 }
2105                 /* Make sure the 64bit formatting checkbox is off */
2106                 [fDstMpgLargeFileCheck setState: NSOffState];
2107         }
2108     
2109         [self calculatePictureSizing: sender];
2110         [self twoPassCheckboxChanged: sender];
2111 }
2112
2113 - (IBAction) twoPassCheckboxChanged: (id) sender
2114 {
2115         /* check to see if x264 is chosen */
2116         int format = [fDstFormatPopUp indexOfSelectedItem];
2117     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2118         if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
2119     {
2120                 if( [fVidTwoPassCheck state] == NSOnState)
2121                 {
2122                         [fVidTurboPassCheck setHidden: NO];
2123                 }
2124                 else
2125                 {
2126                         [fVidTurboPassCheck setHidden: YES];
2127                         [fVidTurboPassCheck setState: NSOffState];
2128                 }
2129                 /* Make sure Two Pass is checked if Turbo is checked */
2130                 if( [fVidTurboPassCheck state] == NSOnState)
2131                 {
2132                         [fVidTwoPassCheck setState: NSOnState];
2133                 }
2134         }
2135         else
2136         {
2137                 [fVidTurboPassCheck setHidden: YES];
2138                 [fVidTurboPassCheck setState: NSOffState];
2139         }
2140         
2141         /* We call method method to change UI to reflect whether a preset is used or not*/
2142         [self customSettingUsed: sender];
2143 }
2144
2145 - (IBAction ) videoFrameRateChanged: (id) sender
2146 {
2147     /* We call method method to calculatePictureSizing to error check detelecine*/
2148     [self calculatePictureSizing: sender];
2149
2150     /* We call method method to change UI to reflect whether a preset is used or not*/
2151         [self customSettingUsed: sender];
2152 }
2153
2154 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
2155 {
2156
2157     /* enable/disable the mixdown text and popupbutton for audio track 1 */
2158     [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
2159     [fAudTrack1MixLabel setTextColor: ([fAudLang1PopUp indexOfSelectedItem] == 0) ?
2160         [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2161
2162     /* enable/disable the mixdown text and popupbutton for audio track 2 */
2163     [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
2164     [fAudTrack2MixLabel setTextColor: ([fAudLang2PopUp indexOfSelectedItem] == 0) ?
2165         [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
2166
2167 }
2168
2169 - (IBAction) addAllAudioTracksToPopUp: (id) sender
2170 {
2171
2172     hb_list_t  * list  = hb_get_titles( fHandle );
2173     hb_title_t * title = (hb_title_t*)
2174         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
2175
2176         hb_audio_t * audio;
2177
2178     [sender removeAllItems];
2179     [sender addItemWithTitle: _( @"None" )];
2180     for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
2181     {
2182         audio = (hb_audio_t *) hb_list_item( title->list_audio, i );
2183         [[sender menu] addItemWithTitle:
2184             [NSString stringWithCString: audio->lang]
2185             action: NULL keyEquivalent: @""];
2186     }
2187     [sender selectItemAtIndex: 0];
2188
2189 }
2190
2191 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
2192 {
2193
2194     /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
2195     /* e.g. to find the first French track, pass in an NSString * of "Francais" */
2196     /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
2197     /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
2198     
2199         if (searchPrefixString != NULL) 
2200         {
2201
2202         for( int i = 0; i < [sender numberOfItems]; i++ )
2203         {
2204             /* Try to find the desired search string */
2205             if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
2206             {
2207                 [sender selectItemAtIndex: i];
2208                 return;
2209             }
2210         }
2211         /* couldn't find the string, so select the requested "search string not found" item */
2212         /* index of 0 means select the "none" item */
2213         /* index of 1 means select the first audio track */
2214         [sender selectItemAtIndex: selectIndexIfNotFound];
2215         }
2216     else
2217     {
2218         /* if no search string is provided, then select the selectIndexIfNotFound item */
2219         [sender selectItemAtIndex: selectIndexIfNotFound];
2220     }
2221
2222 }
2223
2224 - (IBAction) audioTrackPopUpChanged: (id) sender
2225 {
2226     /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
2227     [self audioTrackPopUpChanged: sender mixdownToUse: 0];
2228 }
2229
2230 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
2231 {
2232
2233     /* make sure we have a selected title before continuing */
2234     if (fTitle == NULL) return;
2235
2236     /* find out if audio track 1 or 2 was changed - this is passed to us in the tag of the sender */
2237     /* the sender will have been either fAudLang1PopUp (tag = 0) or fAudLang2PopUp (tag = 1) */
2238     int thisAudio = [sender tag];
2239
2240     /* get the index of the selected audio */
2241     int thisAudioIndex = [sender indexOfSelectedItem] - 1;
2242
2243     /* Handbrake can't currently cope with ripping the same source track twice */
2244     /* So, if this audio is also selected in the other audio track popup, set that popup's selection to "none" */
2245     /* get a reference to the two audio track popups */
2246     NSPopUpButton * thisAudioPopUp  = (thisAudio == 1 ? fAudLang2PopUp : fAudLang1PopUp);
2247     NSPopUpButton * otherAudioPopUp = (thisAudio == 1 ? fAudLang1PopUp : fAudLang2PopUp);
2248     /* if the same track is selected in the other audio popup, then select "none" in that popup */
2249     /* unless, of course, both are selected as "none!" */
2250     if ([thisAudioPopUp indexOfSelectedItem] != 0 && [thisAudioPopUp indexOfSelectedItem] == [otherAudioPopUp indexOfSelectedItem]) {
2251         [otherAudioPopUp selectItemAtIndex: 0];
2252         [self audioTrackPopUpChanged: otherAudioPopUp];
2253     }
2254
2255     /* pointer for the hb_audio_s struct we will use later on */
2256     hb_audio_t * audio;
2257
2258     /* find out what the currently-selected output audio codec is */
2259     int format = [fDstFormatPopUp indexOfSelectedItem];
2260     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2261     int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2262
2263     /* pointer to this track's mixdown NSPopUpButton */
2264     NSTextField   * mixdownTextField;
2265     NSPopUpButton * mixdownPopUp;
2266
2267     /* find our mixdown NSTextField and NSPopUpButton */
2268     if (thisAudio == 0)
2269     {
2270         mixdownTextField = fAudTrack1MixLabel;
2271         mixdownPopUp = fAudTrack1MixPopUp;
2272     }
2273     else
2274     {
2275         mixdownTextField = fAudTrack2MixLabel;
2276         mixdownPopUp = fAudTrack2MixPopUp;
2277     }
2278
2279     /* delete the previous audio mixdown options */
2280     [mixdownPopUp removeAllItems];
2281
2282     /* check if the audio mixdown controls need their enabled state changing */
2283     [self setEnabledStateOfAudioMixdownControls: NULL];
2284
2285     if (thisAudioIndex != -1)
2286     {
2287
2288         /* get the audio */
2289         audio = (hb_audio_t *) hb_list_item( fTitle->list_audio, thisAudioIndex );
2290         if (audio != NULL)
2291         {
2292
2293             /* find out if our selected output audio codec supports mono and / or 6ch */
2294             /* we also check for an input codec of AC3 or DCA,
2295                as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
2296             /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
2297                but this may change in the future, so they are separated for flexibility */
2298             int audioCodecsSupportMono = ((audio->codec == HB_ACODEC_AC3 ||
2299                 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2300             int audioCodecsSupport6Ch =  ((audio->codec == HB_ACODEC_AC3 ||
2301                 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2302
2303             /* check for AC-3 passthru */
2304             if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
2305             {
2306                     [[mixdownPopUp menu] addItemWithTitle:
2307                         [NSString stringWithCString: "AC3 Passthru"]
2308                         action: NULL keyEquivalent: @""];
2309             }
2310             else
2311             {
2312
2313                 /* add the appropriate audio mixdown menuitems to the popupbutton */
2314                 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
2315                    so that we can reference the mixdown later */
2316
2317                 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
2318                 int minMixdownUsed = 0;
2319                 int maxMixdownUsed = 0;
2320                 
2321                 /* get the input channel layout without any lfe channels */
2322                 int layout = audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2323
2324                 /* do we want to add a mono option? */
2325                 if (audioCodecsSupportMono == 1) {
2326                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2327                         [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
2328                         action: NULL keyEquivalent: @""];
2329                     [menuItem setTag: hb_audio_mixdowns[0].amixdown];
2330                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
2331                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
2332                 }
2333
2334                 /* do we want to add a stereo option? */
2335                 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
2336                 /* also offer stereo if we have a stereo-or-better source */
2337                 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO) {
2338                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2339                         [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
2340                         action: NULL keyEquivalent: @""];
2341                     [menuItem setTag: hb_audio_mixdowns[1].amixdown];
2342                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
2343                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
2344                 }
2345
2346                 /* do we want to add a dolby surround (DPL1) option? */
2347                 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY) {
2348                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2349                         [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
2350                         action: NULL keyEquivalent: @""];
2351                     [menuItem setTag: hb_audio_mixdowns[2].amixdown];
2352                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
2353                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
2354                 }
2355
2356                 /* do we want to add a dolby pro logic 2 (DPL2) option? */
2357                 if (layout == HB_INPUT_CH_LAYOUT_3F2R) {
2358                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2359                         [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
2360                         action: NULL keyEquivalent: @""];
2361                     [menuItem setTag: hb_audio_mixdowns[3].amixdown];
2362                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
2363                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
2364                 }
2365
2366                 /* do we want to add a 6-channel discrete option? */
2367                 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE)) {
2368                     id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2369                         [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
2370                         action: NULL keyEquivalent: @""];
2371                     [menuItem setTag: hb_audio_mixdowns[4].amixdown];
2372                     if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
2373                     maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
2374                 }
2375
2376                 /* auto-select the best mixdown based on our saved mixdown preference */
2377                 
2378                 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
2379                 /* ultimately this should be a prefs option */
2380                 int useMixdown;
2381                 
2382                 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
2383                 if (mixdownToUse > 0)
2384                 {
2385                     useMixdown = mixdownToUse;
2386                 }
2387                 else
2388                 {
2389                     useMixdown = HB_AMIXDOWN_DOLBYPLII;
2390                 }
2391                 
2392                 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
2393                 if (useMixdown > maxMixdownUsed) useMixdown = maxMixdownUsed;
2394
2395                 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
2396                 if (useMixdown < minMixdownUsed) useMixdown = minMixdownUsed;
2397
2398                 /* select the (possibly-amended) preferred mixdown */
2399                 [mixdownPopUp selectItemWithTag: useMixdown];
2400                                 
2401                                 /* lets call the audioTrackMixdownChanged method here to determine appropriate bitrates, etc. */
2402                 [self audioTrackMixdownChanged: NULL];
2403             }
2404
2405         }
2406         
2407     }
2408
2409         /* see if the new audio track choice will change the bitrate we need */
2410     [self calculateBitrate: sender];    
2411
2412 }
2413 - (IBAction) audioTrackMixdownChanged: (id) sender
2414 {
2415
2416     /* find out what the currently-selected output audio codec is */
2417     int format = [fDstFormatPopUp indexOfSelectedItem];
2418     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2419     int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2420     
2421     /* storage variable for the min and max bitrate allowed for this codec */
2422     int minbitrate;
2423     int maxbitrate;
2424     
2425     switch( acodec )
2426     {
2427         case HB_ACODEC_FAAC:
2428             /* check if we have a 6ch discrete conversion in either audio track */
2429             if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2430             {
2431                 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
2432                 minbitrate = 32;
2433                 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
2434                 maxbitrate = 384;
2435                 break;
2436             }
2437             else
2438             {
2439                 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
2440                 minbitrate = 32;
2441                 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
2442                 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
2443                 maxbitrate = 160;
2444                 break;
2445             }
2446
2447         case HB_ACODEC_LAME:
2448             /* Lame is happy using our min bitrate of 32 kbps */
2449             minbitrate = 32;
2450             /* Lame won't encode if the bitrate is higher than 320 kbps */
2451             maxbitrate = 320;
2452             break;
2453
2454         case HB_ACODEC_VORBIS:
2455             /* Vorbis causes a crash if we use a bitrate below 48 kbps */
2456             minbitrate = 48;
2457             /* Vorbis can cope with 384 kbps quite happily, even for stereo */
2458             maxbitrate = 384;
2459             break;
2460
2461         default:
2462             /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
2463             minbitrate = 32;
2464             maxbitrate = 384;
2465         
2466     }
2467
2468     [fAudBitratePopUp removeAllItems];
2469
2470     for( int i = 0; i < hb_audio_bitrates_count; i++ )
2471     {
2472         if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
2473         {
2474             /* add a new menuitem for this bitrate */
2475             id<NSMenuItem> menuItem = [[fAudBitratePopUp menu] addItemWithTitle:
2476                 [NSString stringWithCString: hb_audio_bitrates[i].string]
2477                 action: NULL keyEquivalent: @""];
2478             /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
2479             [menuItem setTag: hb_audio_bitrates[i].rate];
2480         }
2481     }
2482
2483     /* select the default bitrate (but use 384 for 6-ch AAC) */
2484     if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2485     {
2486         [fAudBitratePopUp selectItemWithTag: 384];
2487     }
2488     else
2489     {
2490         [fAudBitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
2491     }
2492
2493 }
2494
2495 - (IBAction) subtitleSelectionChanged: (id) sender
2496 {
2497         if ([fSubPopUp indexOfSelectedItem] == 0)
2498         {
2499         [fSubForcedCheck setState: NSOffState];
2500         [fSubForcedCheck setEnabled: NO];       
2501         }
2502         else
2503         {
2504         [fSubForcedCheck setEnabled: YES];      
2505         }
2506         
2507 }
2508
2509 /* lets set the picture size back to the max from right after title scan
2510    Lets use an IBAction here as down the road we could always use a checkbox
2511    in the gui to easily take the user back to max. Remember, the compiler
2512    resolves IBActions down to -(void) during compile anyway */
2513 - (IBAction) revertPictureSizeToMax: (id) sender
2514 {
2515         hb_job_t * job = fTitle->job;
2516         /* We use the output picture width and height
2517         as calculated from libhb right after title is set
2518         in TitlePopUpChanged */
2519         job->width = PicOrigOutputWidth;
2520         job->height = PicOrigOutputHeight;
2521     [fPictureController setAutoCrop:YES];
2522         /* Here we use the auto crop values determined right after scan */
2523         job->crop[0] = AutoCropTop;
2524         job->crop[1] = AutoCropBottom;
2525         job->crop[2] = AutoCropLeft;
2526         job->crop[3] = AutoCropRight;
2527                                 
2528                                 
2529                                 [self calculatePictureSizing: sender];
2530                                 /* We call method method to change UI to reflect whether a preset is used or not*/    
2531                                 [self customSettingUsed: sender];
2532 }
2533
2534
2535 /* Get and Display Current Pic Settings in main window */
2536 - (IBAction) calculatePictureSizing: (id) sender
2537 {
2538         [fPicSettingWidth setStringValue: [NSString stringWithFormat:@"%d", fTitle->job->width]];
2539         [fPicSettingHeight setStringValue: [NSString stringWithFormat:@"%d", fTitle->job->height]];
2540                 
2541         if (fTitle->job->pixel_ratio == 1)
2542         {
2543         int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
2544         int arpwidth = fTitle->job->pixel_aspect_width;
2545         int arpheight = fTitle->job->pixel_aspect_height;
2546         int displayparwidth = titlewidth * arpwidth / arpheight;
2547         int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
2548         
2549         [fPicSettingWidth setStringValue: [NSString stringWithFormat:@"%d", titlewidth]];
2550         [fPicSettingHeight setStringValue: [NSString stringWithFormat:@"%d", displayparheight]];
2551         [fPicLabelPAROutputX setStringValue: @"x"];
2552         [fPicSettingPARWidth setStringValue: [NSString stringWithFormat:@"%d", displayparwidth]];
2553         [fPicSettingPARHeight setStringValue: [NSString stringWithFormat:@"%d", displayparheight]];
2554         
2555         fTitle->job->keep_ratio = 0;
2556         }
2557         else
2558         {
2559         [fPicLabelPAROutputX setStringValue: @""];
2560         [fPicSettingPARWidth setStringValue: @""];
2561         [fPicSettingPARHeight setStringValue:  @""];
2562         }
2563                                 
2564         /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */      
2565         if (fTitle->job->keep_ratio > 0)
2566         {
2567                 [fPicSettingARkeep setStringValue: @"On"];
2568         }
2569         else
2570         {
2571                 [fPicSettingARkeep setStringValue: @"Off"];
2572         }       
2573     /* Detelecine */
2574     if ([fPictureController detelecine]) {
2575         [fPicSettingDetelecine setStringValue: @"Yes"];
2576     }
2577     else {
2578         [fPicSettingDetelecine setStringValue: @"No"];
2579     }
2580
2581         /* Deinterlace */
2582         if ([fPictureController deinterlace] == 0)
2583         {
2584                 [fPicSettingDeinterlace setStringValue: @"Off"];
2585         }
2586         else if ([fPictureController deinterlace] == 1)
2587         {
2588                 [fPicSettingDeinterlace setStringValue: @"Fast"];
2589         }
2590         else if ([fPictureController deinterlace] == 2)
2591         {
2592                 [fPicSettingDeinterlace setStringValue: @"Slow"];
2593         }
2594         else if ([fPictureController deinterlace] == 3)
2595         {
2596                 [fPicSettingDeinterlace setStringValue: @"Slower"];
2597         }
2598         else if ([fPictureController deinterlace] ==4)
2599         {
2600                 [fPicSettingDeinterlace setStringValue: @"Slowest"];
2601         }
2602         /* Denoise */
2603         if ([fPictureController denoise] == 0)
2604         {
2605                 [fPicSettingDenoise setStringValue: @"Off"];
2606         }
2607         else if ([fPictureController denoise] == 1)
2608         {
2609                 [fPicSettingDenoise setStringValue: @"Weak"];
2610         }
2611         else if ([fPictureController denoise] == 2)
2612         {
2613                 [fPicSettingDenoise setStringValue: @"Medium"];
2614         }
2615         else if ([fPictureController denoise] == 3)
2616         {
2617                 [fPicSettingDenoise setStringValue: @"Strong"];
2618         }
2619         
2620         if (fTitle->job->pixel_ratio > 0)
2621         {
2622                 [fPicSettingPAR setStringValue: @""];
2623         }
2624         else
2625         {
2626                 [fPicSettingPAR setStringValue: @"Off"];
2627         }
2628         /* Set the display field for crop as per boolean */
2629         if (![fPictureController autoCrop])
2630         {
2631             [fPicSettingAutoCrop setStringValue: @"Custom"];
2632         }
2633         else
2634         {
2635                 [fPicSettingAutoCrop setStringValue: @"Auto"];
2636         }       
2637         /* check video framerate and turn off detelecine if necessary */
2638         if (fTitle->rate_base == 1126125 || [[fVidRatePopUp titleOfSelectedItem] isEqualToString: @"23.976 (NTSC Film)"])
2639         {
2640                 [fPictureController setDetelecine:0];
2641         }
2642         
2643         
2644         
2645         /* below will trigger the preset, if selected, to be
2646         changed to "Custom". Lets comment out for now until
2647         we figure out a way to determine if the picture values
2648         changed modify the preset values */     
2649         //[self customSettingUsed: sender];
2650 }
2651
2652 - (IBAction) calculateBitrate: (id) sender
2653 {
2654     if( !fHandle || [fVidQualityMatrix selectedRow] != 0 )
2655     {
2656         return;
2657     }
2658
2659     hb_list_t  * list  = hb_get_titles( fHandle );
2660     hb_title_t * title = (hb_title_t *) hb_list_item( list,
2661             [fSrcTitlePopUp indexOfSelectedItem] );
2662     hb_job_t * job = title->job;
2663
2664     [self PrepareJob];
2665
2666     [fVidBitrateField setIntValue: hb_calc_bitrate( job,
2667             [fVidTargetSizeField intValue] )];
2668                         
2669     [self customSettingUsed:sender];
2670 }
2671
2672 /* Method to determine if we should change the UI
2673 To reflect whether or not a Preset is being used or if
2674 the user is using "Custom" settings by determining the sender*/
2675 - (IBAction) customSettingUsed: (id) sender
2676 {
2677         if ([sender stringValue] != NULL)
2678         {
2679                 /* Deselect the currently selected Preset if there is one*/
2680                 [tableView deselectRow:[tableView selectedRow]];
2681                 [[fPresetsActionMenu itemAtIndex:0] setEnabled: NO];
2682                 /* Change UI to show "Custom" settings are being used */
2683                 [fPresetSelectedDisplay setStringValue: @"Custom"];
2684                 
2685                 curUserPresetChosenNum = nil;
2686         }
2687
2688 }
2689
2690    /* We use this method to recreate new, updated factory
2691    presets */
2692 - (IBAction)addFactoryPresets:(id)sender
2693 {
2694     /* First, we delete any existing built in presets */
2695     [self deleteFactoryPresets: sender];
2696     /* Then, we re-create new built in presets programmatically CreateIpodOnlyPreset*/
2697     [UserPresets addObject:[self createNormalPreset]];
2698     [UserPresets addObject:[self createClassicPreset]];
2699     [UserPresets addObject:[self createQuickTimePreset]];
2700         [UserPresets addObject:[self createIpodLowPreset]];
2701         [UserPresets addObject:[self createIpodHighPreset]];
2702         [UserPresets addObject:[self createAppleTVPreset]];
2703     [UserPresets addObject:[self createiPhonePreset]];
2704         [UserPresets addObject:[self createPSThreePreset]];
2705         [UserPresets addObject:[self createPSPPreset]];
2706         [UserPresets addObject:[self createFilmPreset]];
2707     [UserPresets addObject:[self createTelevisionPreset]];
2708     [UserPresets addObject:[self createAnimationPreset]];
2709     [UserPresets addObject:[self createBedlamPreset]];
2710     [UserPresets addObject:[self createDeuxSixQuatrePreset]];
2711     [UserPresets addObject:[self createBrokePreset]];
2712     [UserPresets addObject:[self createBlindPreset]];
2713     [UserPresets addObject:[self createCRFPreset]];
2714     
2715     [self addPreset];
2716 }
2717 - (IBAction)deleteFactoryPresets:(id)sender
2718 {
2719     //int status;
2720     NSEnumerator *enumerator = [UserPresets objectEnumerator];
2721         id tempObject;
2722     
2723         //NSNumber *index;
2724     NSMutableArray *tempArray;
2725
2726
2727         tempArray = [NSMutableArray array];
2728         /* we look here to see if the preset is we move on to the next one */
2729         while ( tempObject = [enumerator nextObject] )  
2730                 {
2731                         /* if the preset is "Factory" then we put it in the array of
2732                         presets to delete */
2733                         if ([[tempObject objectForKey:@"Type"] intValue] == 0)
2734                         {
2735                                 [tempArray addObject:tempObject];
2736                         }
2737         }
2738         
2739         [UserPresets removeObjectsInArray:tempArray];
2740         [tableView reloadData];
2741         [self savePreset];   
2742
2743 }
2744
2745 - (IBAction) showAddPresetPanel: (id) sender
2746 {
2747     /* Deselect the currently selected Preset if there is one*/
2748     [tableView deselectRow:[tableView selectedRow]];
2749
2750     /* Populate the preset picture settings popup here */
2751     [fPresetNewPicSettingsPopUp removeAllItems];
2752     [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
2753     [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
2754     [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
2755     [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];  
2756         
2757     /* Erase info from the input fields fPresetNewDesc*/
2758         [fPresetNewName setStringValue: @""];
2759         [fPresetNewDesc setStringValue: @""];
2760         /* Show the panel */
2761         [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
2762 }
2763
2764 - (IBAction) closeAddPresetPanel: (id) sender
2765 {
2766     [NSApp endSheet: fAddPresetPanel];
2767     [fAddPresetPanel orderOut: self];
2768 }
2769
2770 - (IBAction)addUserPreset:(id)sender
2771 {
2772     if (![[fPresetNewName stringValue] length])
2773             NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
2774     else
2775     {
2776         /* Here we create a custom user preset */
2777         [UserPresets addObject:[self createPreset]];
2778         [self addPreset];
2779         
2780         [self closeAddPresetPanel:NULL];
2781     }
2782 }
2783 - (void)addPreset
2784 {
2785
2786         
2787         /* We Sort the Presets By Factory or Custom */
2788         NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type" 
2789                                                     ascending:YES] autorelease];
2790         /* We Sort the Presets Alphabetically by name */
2791         NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
2792                                                     ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
2793         NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
2794         NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
2795         [UserPresets setArray:sortedArray];
2796         
2797         
2798         /* We Reload the New Table data for presets */
2799     [tableView reloadData];
2800    /* We save all of the preset data here */
2801     [self savePreset];
2802 }
2803
2804 - (IBAction)insertPreset:(id)sender
2805 {
2806     int index = [tableView selectedRow];
2807     [UserPresets insertObject:[self createPreset] atIndex:index];
2808     [tableView reloadData];
2809     [self savePreset];
2810 }
2811
2812 - (NSDictionary *)createPreset
2813 {
2814     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2815         /* Get the New Preset Name from the field in the AddPresetPanel */
2816     [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
2817         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2818         [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
2819         /*Set whether or not this is default, at creation set to 0*/
2820         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2821         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2822         [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
2823         /* Get New Preset Description from the field in the AddPresetPanel*/
2824         [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
2825         /* File Format */
2826     [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
2827         /* Chapter Markers fCreateChapterMarkers*/
2828         [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
2829         /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2830         [preset setObject:[NSNumber numberWithInt:[fDstMpgLargeFileCheck state]] forKey:@"Mp4LargeFile"];
2831         /* Codecs */
2832         [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
2833         /* Video encoder */
2834         [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2835         /* x264 Option String */
2836         [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2837         
2838         [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2839         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2840         [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2841         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2842         
2843         /* Video framerate */
2844         [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2845         /* GrayScale */
2846         [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
2847         /* 2 Pass Encoding */
2848         [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2849         /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2850         [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2851         /*Picture Settings*/
2852         hb_job_t * job = fTitle->job;
2853         /* Basic Picture Settings */
2854         /* Use Max Picture settings for whatever the dvd is.*/
2855         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2856         [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2857         [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2858         [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2859         [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2860         [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
2861         [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2862         [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"]; 
2863         /* Set crop settings here */
2864         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2865         [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2866
2867         [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2868     [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2869         [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2870         [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2871         
2872         /*Audio*/
2873         /* Audio Sample Rate*/
2874         [preset setObject:[fAudRatePopUp titleOfSelectedItem] forKey:@"AudioSampleRate"];
2875         /* Audio Bitrate Rate*/
2876         [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
2877         /* Subtitles*/
2878         [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
2879         
2880
2881     [preset autorelease];
2882     return preset;
2883
2884 }
2885
2886 - (NSDictionary *)createIpodLowPreset
2887 {
2888     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2889         /* Get the New Preset Name from the field in the AddPresetPanel */
2890     [preset setObject:@"iPod Low-Rez" forKey:@"PresetName"];
2891         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2892         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2893         /*Set whether or not this is default, at creation set to 0*/
2894         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2895         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2896         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2897         /* Get the New Preset Description from the field in the AddPresetPanel */
2898     [preset setObject:@"HandBrake's low resolution settings for the iPod. Optimized for great playback on the iPod screen, with smaller file size." forKey:@"PresetDescription"];
2899         /* File Format */
2900     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2901         /* Chapter Markers*/
2902          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2903     /* Codecs */
2904         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2905         /* Video encoder */
2906         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2907         /* x264 Option String */
2908         [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"];
2909         /* Video quality */
2910         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2911         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2912         [preset setObject:@"700" forKey:@"VideoAvgBitrate"];
2913         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2914         
2915         /* Video framerate */
2916         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2917         /* GrayScale */
2918         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2919         /* 2 Pass Encoding */
2920         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2921         
2922         /*Picture Settings*/
2923         //hb_job_t * job = fTitle->job;
2924         /* Basic Picture Settings */
2925         /* Use Max Picture settings for whatever the dvd is.*/
2926         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2927         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
2928         [preset setObject:[NSNumber numberWithInt:320] forKey:@"PictureWidth"];
2929         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2930         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2931         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
2932         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
2933         /* Set crop settings here */
2934         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
2935         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
2936     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
2937         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
2938         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
2939         
2940         /*Audio*/
2941         /* Audio Sample Rate*/
2942         [preset setObject:@"48" forKey:@"AudioSampleRate"];
2943         /* Audio Bitrate Rate*/
2944         [preset setObject:@"160" forKey:@"AudioBitRate"];
2945         /* Subtitles*/
2946         [preset setObject:@"None" forKey:@"Subtitles"];
2947         
2948
2949     [preset autorelease];
2950     return preset;
2951
2952 }
2953
2954
2955 - (NSDictionary *)createIpodHighPreset
2956 {
2957     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
2958         /* Get the New Preset Name from the field in the AddPresetPanel */
2959     [preset setObject:@"iPod High-Rez" forKey:@"PresetName"];
2960         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
2961         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
2962         /*Set whether or not this is default, at creation set to 0*/
2963         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
2964         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
2965         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
2966         /* Get the New Preset Description from the field in the AddPresetPanel */
2967     [preset setObject:@"HandBrake's high resolution settings for the iPod. Good video quality, great for viewing on a TV using your iPod" forKey:@"PresetDescription"];
2968         /* File Format */
2969     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
2970         /* Chapter Markers*/
2971          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
2972     /* Codecs */
2973         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
2974         /* Video encoder */
2975         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
2976         /* x264 Option String */
2977         [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"];
2978         /* Video quality */
2979         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
2980         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2981         [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
2982         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
2983         
2984         /* Video framerate */
2985         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
2986         /* GrayScale */
2987         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
2988         /* 2 Pass Encoding */
2989         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
2990         
2991         /*Picture Settings*/
2992         //hb_job_t * job = fTitle->job;
2993         /* Basic Picture Settings */
2994         /* Use Max Picture settings for whatever the dvd is.*/
2995         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2996         [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
2997         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
2998         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
2999         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3000         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3001         /* Set crop settings here */
3002         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3003         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3004         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3005     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3006         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3007         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3008         
3009         /*Audio*/
3010         /* Audio Sample Rate*/
3011         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3012         /* Audio Bitrate Rate*/
3013         [preset setObject:@"160" forKey:@"AudioBitRate"];
3014         /* Subtitles*/
3015         [preset setObject:@"None" forKey:@"Subtitles"];
3016         
3017
3018     [preset autorelease];
3019     return preset;
3020
3021 }
3022
3023 - (NSDictionary *)createAppleTVPreset
3024 {
3025     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3026         /* Get the New Preset Name from the field in the AddPresetPanel */
3027     [preset setObject:@"AppleTV" forKey:@"PresetName"];
3028         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3029         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3030         /*Set whether or not this is default, at creation set to 0*/
3031         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3032         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3033         [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3034         /* Get the New Preset Description from the field in the AddPresetPanel */
3035     [preset setObject:@"HandBrake's settings for the AppleTV. Provides a good balance between quality and file size, and optimizes performance." forKey:@"PresetDescription"];
3036         /* File Format */
3037     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3038         /* Chapter Markers*/
3039          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3040         /* Codecs */
3041         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3042         /* Video encoder */
3043         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3044         /* x264 Option String (We can use this to tweak the appleTV output)*/
3045         [preset setObject:@"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2:cabac=0" forKey:@"x264Option"];
3046         /* Video quality */
3047         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3048         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3049         [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3050         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3051         
3052         /* Video framerate */
3053         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3054         /* GrayScale */
3055         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3056         /* 2 Pass Encoding */
3057         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3058         
3059         /*Picture Settings*/
3060         /* For AppleTV we only want to retain UsesMaxPictureSettings
3061         which depend on the source dvd picture settings, so we don't
3062         record the current dvd's picture info since it will vary from
3063         source to source*/
3064         //hb_job_t * job = fTitle->job;
3065         //hb_job_t * job = title->job;
3066         /* Basic Picture Settings */
3067         /* Use Max Picture settings for whatever the dvd is.*/
3068         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3069         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3070         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3071         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3072         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3073         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3074         /* Set crop settings here */
3075         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3076         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3077     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3078         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3079         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3080         
3081         /*Audio*/
3082         /* Audio Sample Rate*/
3083         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3084         /* Audio Bitrate Rate*/
3085         [preset setObject:@"160" forKey:@"AudioBitRate"];
3086         /* Subtitles*/
3087         [preset setObject:@"None" forKey:@"Subtitles"];
3088         
3089
3090     [preset autorelease];
3091     return preset;
3092
3093 }
3094
3095 - (NSDictionary *)createPSThreePreset
3096 {
3097     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3098         /* Get the New Preset Name from the field in the AddPresetPanel */
3099     [preset setObject:@"PS3" forKey:@"PresetName"];
3100         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3101         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3102         /*Set whether or not this is default, at creation set to 0*/
3103         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3104         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3105         [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3106         /* Get the New Preset Description from the field in the AddPresetPanel */
3107     [preset setObject:@"HandBrake's settings for the Sony PlayStation 3." forKey:@"PresetDescription"];
3108         /* File Format */
3109     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3110         /* Chapter Markers*/
3111          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3112         /* Codecs */
3113         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3114         /* Video encoder */
3115         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3116         /* x264 Option String (We can use this to tweak the appleTV output)*/
3117         [preset setObject:@"level=41:subme=5:me=umh" forKey:@"x264Option"];
3118         /* Video quality */
3119         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3120         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3121         [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3122         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3123         
3124         /* Video framerate */
3125         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3126         /* GrayScale */
3127         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3128         /* 2 Pass Encoding */
3129         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3130         
3131         /*Picture Settings*/
3132         /* For PS3 we only want to retain UsesMaxPictureSettings
3133         which depend on the source dvd picture settings, so we don't
3134         record the current dvd's picture info since it will vary from
3135         source to source*/
3136         /* Use Max Picture settings for whatever the dvd is.*/
3137         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3138         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3139         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3140         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3141         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3142         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3143         /* Set crop settings here */
3144         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3145         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3146     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3147         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3148         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3149         
3150         /*Audio*/
3151         /* Audio Sample Rate*/
3152         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3153         /* Audio Bitrate Rate*/
3154         [preset setObject:@"160" forKey:@"AudioBitRate"];
3155         /* Subtitles*/
3156         [preset setObject:@"None" forKey:@"Subtitles"];
3157         
3158
3159     [preset autorelease];
3160     return preset;
3161
3162 }
3163 - (NSDictionary *)createPSPPreset
3164 {
3165     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3166         /* Get the New Preset Name from the field in the AddPresetPanel */
3167     [preset setObject:@"PSP" forKey:@"PresetName"];
3168         /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3169         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3170         /*Set whether or not this is default, at creation set to 0*/
3171         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3172         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3173         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3174         /* Get the New Preset Description from the field in the AddPresetPanel */
3175     [preset setObject:@"HandBrake's settings for the Sony PlayStation Portable." forKey:@"PresetDescription"];
3176         /* File Format */
3177     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3178         /* Chapter Markers*/
3179          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3180         /* Codecs */
3181         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3182         /* Video encoder */
3183         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3184         /* x264 Option String (We can use this to tweak the appleTV output)*/
3185         [preset setObject:@"" forKey:@"x264Option"];
3186         /* Video quality */
3187         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3188         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3189         [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
3190         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3191         
3192         /* Video framerate */
3193         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3194         /* GrayScale */
3195         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3196         /* 2 Pass Encoding */
3197         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3198         
3199         /*Picture Settings*/
3200         /* For PS3 we only want to retain UsesMaxPictureSettings
3201         which depend on the source dvd picture settings, so we don't
3202         record the current dvd's picture info since it will vary from
3203         source to source*/
3204         /* Use Max Picture settings for whatever the dvd is.*/
3205         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3206         [preset setObject:@"368" forKey:@"PictureWidth"];
3207         [preset setObject:@"208" forKey:@"PictureHeight"];
3208         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3209         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3210         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3211         /* Set crop settings here */
3212         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3213         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3214         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3215     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3216         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3217         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3218         
3219         /*Audio*/
3220         /* Audio Sample Rate*/
3221         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3222         /* Audio Bitrate Rate*/
3223         [preset setObject:@"128" forKey:@"AudioBitRate"];
3224         /* Subtitles*/
3225         [preset setObject:@"None" forKey:@"Subtitles"];
3226         
3227
3228     [preset autorelease];
3229     return preset;
3230
3231 }
3232
3233 - (NSDictionary *)createNormalPreset
3234 {
3235     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3236         /* Get the New Preset Name from the field in the AddPresetPanel */
3237     [preset setObject:@"Normal" forKey:@"PresetName"];
3238         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3239         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3240         /*Set whether or not this is default, at creation set to 0*/
3241         [preset setObject:[NSNumber numberWithInt:1] forKey:@"Default"];
3242         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3243         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3244         /* Get the New Preset Description from the field in the AddPresetPanel */
3245     [preset setObject:@"HandBrake's normal, default settings." forKey:@"PresetDescription"];
3246         /* File Format */
3247     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3248         /* Chapter Markers*/
3249          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3250     /* Codecs */
3251         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3252         /* Video encoder */
3253         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3254         /* x264 Option String */
3255         [preset setObject:@"ref=2:bframes=2:subme=5:me=umh" forKey:@"x264Option"];
3256         /* Video quality */
3257         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3258         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3259         [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3260         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3261         
3262         /* Video framerate */
3263         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3264         /* GrayScale */
3265         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3266         /* 2 Pass Encoding */
3267         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3268         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3269         
3270         /*Picture Settings*/
3271         //hb_job_t * job = fTitle->job;
3272         /* Basic Picture Settings */
3273         /* Use Max Picture settings for whatever the dvd is.*/
3274         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3275         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3276         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3277         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3278         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3279         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3280         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3281         /* Set crop settings here */
3282         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3283         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3284     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3285         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3286         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3287         
3288         /*Audio*/
3289         /* Audio Sample Rate*/
3290         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3291         /* Audio Bitrate Rate*/
3292         [preset setObject:@"160" forKey:@"AudioBitRate"];
3293         /* Subtitles*/
3294         [preset setObject:@"None" forKey:@"Subtitles"];
3295         
3296
3297     [preset autorelease];
3298     return preset;
3299
3300 }
3301
3302 - (NSDictionary *)createClassicPreset
3303 {
3304     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3305         /* Get the New Preset Name from the field in the AddPresetPanel */
3306     [preset setObject:@"Classic" forKey:@"PresetName"];
3307         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3308         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3309         /*Set whether or not this is default, at creation set to 0*/
3310         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3311         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3312         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3313         /* Get the New Preset Description from the field in the AddPresetPanel */
3314     [preset setObject:@"HandBrake's traditional, faster, lower-quality settings." forKey:@"PresetDescription"];
3315         /* File Format */
3316     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3317         /* Chapter Markers*/
3318          [preset setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
3319     /* Codecs */
3320         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3321         /* Video encoder */
3322         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3323         /* x264 Option String */
3324         [preset setObject:@"" forKey:@"x264Option"];
3325         /* Video quality */
3326         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3327         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3328         [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3329         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3330         
3331         /* Video framerate */
3332         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3333         /* GrayScale */
3334         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3335         /* 2 Pass Encoding */
3336         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3337         
3338         /*Picture Settings*/
3339         //hb_job_t * job = fTitle->job;
3340         /* Basic Picture Settings */
3341         /* Use Max Picture settings for whatever the dvd is.*/
3342         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3343         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3344         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3345         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3346         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3347         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3348         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3349         /* Set crop settings here */
3350         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3351         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3352     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3353         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3354         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3355         
3356         /*Audio*/
3357         /* Audio Sample Rate*/
3358         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3359         /* Audio Bitrate Rate*/
3360         [preset setObject:@"160" forKey:@"AudioBitRate"];
3361         /* Subtitles*/
3362         [preset setObject:@"None" forKey:@"Subtitles"];
3363         
3364
3365     [preset autorelease];
3366     return preset;
3367
3368 }
3369
3370 - (NSDictionary *)createFilmPreset
3371 {
3372     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3373         /* Get the New Preset Name from the field in the AddPresetPanel */
3374     [preset setObject:@"Film" forKey:@"PresetName"];
3375         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3376         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3377         /*Set whether or not this is default, at creation set to 0*/
3378         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3379         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3380         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3381         /* Get the New Preset Description from the field in the AddPresetPanel */
3382     [preset setObject:@"HandBrake's preset for feature films." forKey:@"PresetDescription"];
3383         /* File Format */
3384     [preset setObject:@"MKV file" forKey:@"FileFormat"];
3385         /* Chapter Markers*/
3386          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3387     /* Codecs */
3388         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3389         /* Video encoder */
3390         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3391         /* x264 Option String */
3392         [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"];
3393         /* Video quality */
3394         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3395         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3396         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3397         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3398         
3399         /* Video framerate */
3400         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3401         /* GrayScale */
3402         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3403         /* 2 Pass Encoding */
3404         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3405         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3406         
3407         /*Picture Settings*/
3408         //hb_job_t * job = fTitle->job;
3409         /* Basic Picture Settings */
3410         /* Use Max Picture settings for whatever the dvd is.*/
3411         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3412         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3413         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3414         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3415         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3416         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3417         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3418         /* Set crop settings here */
3419         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3420         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3421     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3422         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3423         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3424         
3425         /*Audio*/
3426         /* Audio Sample Rate*/
3427         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3428         /* Audio Bitrate Rate*/
3429         [preset setObject:@"160" forKey:@"AudioBitRate"];
3430         /* Subtitles*/
3431         [preset setObject:@"None" forKey:@"Subtitles"];
3432         
3433
3434     [preset autorelease];
3435     return preset;
3436
3437 }
3438
3439 - (NSDictionary *)createTelevisionPreset
3440 {
3441     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3442         /* Get the New Preset Name from the field in the AddPresetPanel */
3443     [preset setObject:@"Television" forKey:@"PresetName"];
3444         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3445         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3446         /*Set whether or not this is default, at creation set to 0*/
3447         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3448         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3449         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3450         /* Get the New Preset Description from the field in the AddPresetPanel */
3451     [preset setObject:@"HandBrake's settings for video from television." forKey:@"PresetDescription"];
3452         /* File Format */
3453     [preset setObject:@"MKV file" forKey:@"FileFormat"];
3454         /* Chapter Markers*/
3455          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3456     /* Codecs */
3457         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3458         /* Video encoder */
3459         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3460         /* x264 Option String */
3461         [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"];
3462         /* Video quality */
3463         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3464         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3465         [preset setObject:@"1300" forKey:@"VideoAvgBitrate"];
3466         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3467         
3468         /* Video framerate */
3469         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3470         /* GrayScale */
3471         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3472         /* 2 Pass Encoding */
3473         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3474         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3475         
3476         /*Picture Settings*/
3477         //hb_job_t * job = fTitle->job;
3478         /* Basic Picture Settings */
3479         /* Use Max Picture settings for whatever the dvd is.*/
3480         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3481         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3482         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3483         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3484         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3485         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3486         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3487         /* Set crop settings here */
3488         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3489         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3490     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3491         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3492         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3493         
3494         /*Audio*/
3495         /* Audio Sample Rate*/
3496         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3497         /* Audio Bitrate Rate*/
3498         [preset setObject:@"160" forKey:@"AudioBitRate"];
3499         /* Subtitles*/
3500         [preset setObject:@"None" forKey:@"Subtitles"];
3501         
3502
3503     [preset autorelease];
3504     return preset;
3505
3506 }
3507
3508 - (NSDictionary *)createAnimationPreset
3509 {
3510     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3511         /* Get the New Preset Name from the field in the AddPresetPanel */
3512     [preset setObject:@"Animation" forKey:@"PresetName"];
3513         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3514         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3515         /*Set whether or not this is default, at creation set to 0*/
3516         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3517         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3518         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3519         /* Get the New Preset Description from the field in the AddPresetPanel */
3520     [preset setObject:@"HandBrake's settings for cartoons, anime, and CGI." forKey:@"PresetDescription"];
3521         /* File Format */
3522     [preset setObject:@"MKV file" forKey:@"FileFormat"];
3523         /* Chapter Markers*/
3524          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3525     /* Codecs */
3526         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3527         /* Video encoder */
3528         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3529         /* x264 Option String */
3530         [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"];
3531         /* Video quality */
3532         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3533         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3534         [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3535         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3536         
3537         /* Video framerate */
3538         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3539         /* GrayScale */
3540         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3541         /* 2 Pass Encoding */
3542         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3543         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3544         
3545         /*Picture Settings*/
3546         //hb_job_t * job = fTitle->job;
3547         /* Basic Picture Settings */
3548         /* Use Max Picture settings for whatever the dvd is.*/
3549         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3550         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3551         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3552         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3553         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3554         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
3555         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3556         /* Set crop settings here */
3557         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3558         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3559     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3560         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3561         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3562         
3563         /*Audio*/
3564         /* Audio Sample Rate*/
3565         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3566         /* Audio Bitrate Rate*/
3567         [preset setObject:@"160" forKey:@"AudioBitRate"];
3568         /* Subtitles*/
3569         [preset setObject:@"None" forKey:@"Subtitles"];
3570         
3571
3572     [preset autorelease];
3573     return preset;
3574
3575 }
3576
3577 - (NSDictionary *)createQuickTimePreset
3578 {
3579     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3580         /* Get the New Preset Name from the field in the AddPresetPanel */
3581     [preset setObject:@"QuickTime" forKey:@"PresetName"];
3582         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3583         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3584         /*Set whether or not this is default, at creation set to 0*/
3585         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3586         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3587         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3588         /* Get the New Preset Description from the field in the AddPresetPanel */
3589     [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"];
3590         /* File Format */
3591     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3592         /* Chapter Markers*/
3593          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3594     /* Codecs */
3595         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3596         /* Video encoder */
3597         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3598         /* x264 Option String */
3599         [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"];
3600         /* Video quality */
3601         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3602         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3603         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
3604         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3605         
3606         /* Video framerate */
3607         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3608         /* GrayScale */
3609         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3610         /* 2 Pass Encoding */
3611         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3612         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3613         
3614         /*Picture Settings*/
3615         //hb_job_t * job = fTitle->job;
3616         /* Basic Picture Settings */
3617         /* Use Max Picture settings for whatever the dvd is.*/
3618         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3619         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3620         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3621         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3622         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3623         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3624         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3625         /* Set crop settings here */
3626         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3627         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3628     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3629         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3630         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3631         
3632         /*Audio*/
3633         /* Audio Sample Rate*/
3634         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3635         /* Audio Bitrate Rate*/
3636         [preset setObject:@"160" forKey:@"AudioBitRate"];
3637         /* Subtitles*/
3638         [preset setObject:@"None" forKey:@"Subtitles"];
3639         
3640
3641     [preset autorelease];
3642     return preset;
3643
3644 }
3645
3646 - (NSDictionary *)createBedlamPreset
3647 {
3648     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3649         /* Get the New Preset Name from the field in the AddPresetPanel */
3650     [preset setObject:@"Bedlam" forKey:@"PresetName"];
3651         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3652         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3653         /*Set whether or not this is default, at creation set to 0*/
3654         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3655         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3656         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3657         /* Get the New Preset Description from the field in the AddPresetPanel */
3658     [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"];
3659         /* File Format */
3660     [preset setObject:@"MKV file" forKey:@"FileFormat"];
3661         /* Chapter Markers*/
3662          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3663     /* Codecs */
3664         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3665         /* Video encoder */
3666         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3667         /* x264 Option String */
3668         [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"];
3669         /* Video quality */
3670         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3671         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3672         [preset setObject:@"1800" forKey:@"VideoAvgBitrate"];
3673         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3674         
3675         /* Video framerate */
3676         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3677         /* GrayScale */
3678         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3679         /* 2 Pass Encoding */
3680         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3681         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3682         
3683         /*Picture Settings*/
3684         //hb_job_t * job = fTitle->job;
3685         /* Basic Picture Settings */
3686         /* Use Max Picture settings for whatever the dvd is.*/
3687         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3688         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3689         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3690         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3691         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3692         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3693         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3694         /* Set crop settings here */
3695         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3696         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3697     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3698         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3699         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3700         
3701         /*Audio*/
3702         /* Audio Sample Rate*/
3703         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3704         /* Audio Bitrate Rate*/
3705         [preset setObject:@"160" forKey:@"AudioBitRate"];
3706         /* Subtitles*/
3707         [preset setObject:@"None" forKey:@"Subtitles"];
3708         
3709
3710     [preset autorelease];
3711     return preset;
3712
3713 }
3714
3715 - (NSDictionary *)createiPhonePreset
3716 {
3717     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3718         /* Get the New Preset Name from the field in the AddPresetPanel */
3719     [preset setObject:@"iPhone" forKey:@"PresetName"];
3720         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3721         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3722         /*Set whether or not this is default, at creation set to 0*/
3723         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3724         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3725         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3726         /* Get the New Preset Description from the field in the AddPresetPanel */
3727     [preset setObject:@"HandBrake's settings for the iPhone." forKey:@"PresetDescription"];
3728         /* File Format */
3729     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3730         /* Chapter Markers*/
3731          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3732     /* Codecs */
3733         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3734         /* Video encoder */
3735         [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3736         /* x264 Option String */
3737         [preset setObject:@"cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1" forKey:@"x264Option"];
3738         /* Video quality */
3739         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3740         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3741         [preset setObject:@"960" forKey:@"VideoAvgBitrate"];
3742         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3743         
3744         /* Video framerate */
3745         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3746         /* GrayScale */
3747         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3748         /* 2 Pass Encoding */
3749         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3750         
3751         /*Picture Settings*/
3752         //hb_job_t * job = fTitle->job;
3753         /* Basic Picture Settings */
3754         /* Use Max Picture settings for whatever the dvd is.*/
3755         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3756         [preset setObject:[NSNumber numberWithInt:480] forKey:@"PictureWidth"];
3757         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3758         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3759         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3760         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3761         /* Set crop settings here */
3762         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3763         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3764         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3765     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3766         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3767         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3768         
3769         /*Audio*/
3770         /* Audio Sample Rate*/
3771         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3772         /* Audio Bitrate Rate*/
3773         [preset setObject:@"128" forKey:@"AudioBitRate"];
3774         /* Subtitles*/
3775         [preset setObject:@"None" forKey:@"Subtitles"];
3776         
3777
3778     [preset autorelease];
3779     return preset;
3780
3781 }
3782
3783 - (NSDictionary *)createDeuxSixQuatrePreset
3784 {
3785     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3786         /* Get the New Preset Name from the field in the AddPresetPanel */
3787     [preset setObject:@"Deux Six Quatre" forKey:@"PresetName"];
3788         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3789         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3790         /*Set whether or not this is default, at creation set to 0*/
3791         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3792         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3793         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3794         /* Get the New Preset Description from the field in the AddPresetPanel */
3795     [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"];
3796         /* File Format */
3797     [preset setObject:@"MKV file" forKey:@"FileFormat"];
3798         /* Chapter Markers*/
3799          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3800     /* Codecs */
3801         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
3802         /* Video encoder */
3803         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3804         /* x264 Option String */
3805         [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"];
3806         /* Video quality */
3807         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3808         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3809         [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3810         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3811         
3812         /* Video framerate */
3813         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3814         /* GrayScale */
3815         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3816         /* 2 Pass Encoding */
3817         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3818         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3819         
3820         /*Picture Settings*/
3821         //hb_job_t * job = fTitle->job;
3822         /* Basic Picture Settings */
3823         /* Use Max Picture settings for whatever the dvd is.*/
3824         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3825         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3826         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3827         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3828         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3829         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3830         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3831         /* Set crop settings here */
3832         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3833         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3834     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3835         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3836         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3837         
3838         /*Audio*/
3839         /* Audio Sample Rate*/
3840         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3841         /* Audio Bitrate Rate*/
3842         [preset setObject:@"160" forKey:@"AudioBitRate"];
3843         /* Subtitles*/
3844         [preset setObject:@"None" forKey:@"Subtitles"];
3845         
3846
3847     [preset autorelease];
3848     return preset;
3849
3850 }
3851
3852 - (NSDictionary *)createBrokePreset
3853 {
3854     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3855         /* Get the New Preset Name from the field in the AddPresetPanel */
3856     [preset setObject:@"Broke" forKey:@"PresetName"];
3857         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3858         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3859         /*Set whether or not this is default, at creation set to 0*/
3860         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3861         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3862         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3863         /* Get the New Preset Description from the field in the AddPresetPanel */
3864     [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"];
3865         /* File Format */
3866     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3867         /* Chapter Markers*/
3868          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3869     /* Codecs */
3870         [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3871         /* Video encoder */
3872         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3873         /* x264 Option String */
3874         [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"];
3875         /* Video quality */
3876         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoQualityType"];
3877         [preset setObject:@"695" forKey:@"VideoTargetSize"];
3878         [preset setObject:@"1600" forKey:@"VideoAvgBitrate"];
3879         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3880         
3881         /* Video framerate */
3882         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3883         /* GrayScale */
3884         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3885         /* 2 Pass Encoding */
3886         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3887         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTurboTwoPass"];
3888         
3889         /*Picture Settings*/
3890         //hb_job_t * job = fTitle->job;
3891         /* Basic Picture Settings */
3892         /* Use Max Picture settings for whatever the dvd is.*/
3893         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3894         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3895         [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
3896         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3897         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3898         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3899         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3900         /* Set crop settings here */
3901         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3902         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3903     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3904         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3905         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3906         
3907         /*Audio*/
3908         /* Audio Sample Rate*/
3909         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3910         /* Audio Bitrate Rate*/
3911         [preset setObject:@"128" forKey:@"AudioBitRate"];
3912         /* Subtitles*/
3913         [preset setObject:@"None" forKey:@"Subtitles"];
3914         
3915
3916     [preset autorelease];
3917     return preset;
3918
3919 }
3920
3921 - (NSDictionary *)createBlindPreset
3922 {
3923     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3924         /* Get the New Preset Name from the field in the AddPresetPanel */
3925     [preset setObject:@"Blind" forKey:@"PresetName"];
3926         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3927         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3928         /*Set whether or not this is default, at creation set to 0*/
3929         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3930         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3931         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3932         /* Get the New Preset Description from the field in the AddPresetPanel */
3933     [preset setObject:@"HandBrake's preset for impatient people who don't care about picture quality." forKey:@"PresetDescription"];
3934         /* File Format */
3935     [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3936         /* Chapter Markers*/
3937          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3938     /* Codecs */
3939         [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3940         /* Video encoder */
3941         [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3942         /* x264 Option String */
3943         [preset setObject:@"" forKey:@"x264Option"];
3944         /* Video quality */
3945         [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3946         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3947         [preset setObject:@"512" forKey:@"VideoAvgBitrate"];
3948         [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3949         
3950         /* Video framerate */
3951         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3952         /* GrayScale */
3953         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3954         /* 2 Pass Encoding */
3955         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3956         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
3957         
3958         /*Picture Settings*/
3959         //hb_job_t * job = fTitle->job;
3960         /* Basic Picture Settings */
3961         /* Use Max Picture settings for whatever the dvd is.*/
3962         [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3963         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3964         [preset setObject:[NSNumber numberWithInt:512] forKey:@"PictureWidth"];
3965         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3966         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3967         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3968         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3969         /* Set crop settings here */
3970         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3971         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3972     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3973         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3974         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3975         
3976         /*Audio*/
3977         /* Audio Sample Rate*/
3978         [preset setObject:@"48" forKey:@"AudioSampleRate"];
3979         /* Audio Bitrate Rate*/
3980         [preset setObject:@"128" forKey:@"AudioBitRate"];
3981         /* Subtitles*/
3982         [preset setObject:@"None" forKey:@"Subtitles"];
3983         
3984
3985     [preset autorelease];
3986     return preset;
3987
3988 }
3989
3990 - (NSDictionary *)createCRFPreset
3991 {
3992     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3993         /* Get the New Preset Name from the field in the AddPresetPanel */
3994     [preset setObject:@"Constant Quality Rate" forKey:@"PresetName"];
3995         /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3996         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3997         /*Set whether or not this is default, at creation set to 0*/
3998         [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3999         /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4000         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4001         /* Get the New Preset Description from the field in the AddPresetPanel */
4002     [preset setObject:@"HandBrake's preset for consistently excellent quality in one pass, with the downside of entirely unpredictable file sizes and bitrates." forKey:@"PresetDescription"];
4003         /* File Format */
4004     [preset setObject:@"MKV file" forKey:@"FileFormat"];
4005         /* Chapter Markers*/
4006          [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4007     /* Codecs */
4008         [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4009         /* Video encoder */
4010         [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4011         /* x264 Option String */
4012         [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"];
4013         /* Video quality */
4014         [preset setObject:[NSNumber numberWithInt:2] forKey:@"VideoQualityType"];
4015         [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4016         [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4017         [preset setObject:[NSNumber numberWithFloat:0.6471] forKey:@"VideoQualitySlider"];
4018         
4019         /* Video framerate */
4020         [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4021         /* GrayScale */
4022         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4023         /* 2 Pass Encoding */
4024         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4025         [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTurboTwoPass"];
4026         
4027         /*Picture Settings*/
4028         //hb_job_t * job = fTitle->job;
4029         /* Basic Picture Settings */
4030         /* Use Max Picture settings for whatever the dvd is.*/
4031         [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4032         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4033         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4034         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4035         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4036         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4037         [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4038         /* Set crop settings here */
4039         /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4040         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4041     [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4042         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4043         [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4044         
4045         /*Audio*/
4046         /* Audio Sample Rate*/
4047         [preset setObject:@"48" forKey:@"AudioSampleRate"];
4048         /* Audio Bitrate Rate*/
4049         [preset setObject:@"160" forKey:@"AudioBitRate"];
4050         /* Subtitles*/
4051         [preset setObject:@"None" forKey:@"Subtitles"];
4052         
4053
4054     [preset autorelease];
4055     return preset;
4056
4057 }
4058
4059
4060 - (IBAction)deletePreset:(id)sender
4061 {
4062     int status;
4063     NSEnumerator *enumerator;
4064     NSNumber *index;
4065     NSMutableArray *tempArray;
4066     id tempObject;
4067     
4068     if ( [tableView numberOfSelectedRows] == 0 )
4069         return;
4070     /* Alert user before deleting preset */
4071         /* Comment out for now, tie to user pref eventually */
4072
4073     //NSBeep();
4074     status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
4075     
4076     if ( status == NSAlertDefaultReturn ) {
4077         enumerator = [tableView selectedRowEnumerator];
4078         tempArray = [NSMutableArray array];
4079         
4080         while ( (index = [enumerator nextObject]) ) {
4081             tempObject = [UserPresets objectAtIndex:[index intValue]];
4082             [tempArray addObject:tempObject];
4083         }
4084         
4085         [UserPresets removeObjectsInArray:tempArray];
4086         [tableView reloadData];
4087         [self savePreset];   
4088     }
4089 }
4090
4091 - (IBAction)getDefaultPresets:(id)sender
4092 {
4093         int i = 0;
4094     NSEnumerator *enumerator = [UserPresets objectEnumerator];
4095         id tempObject;
4096         while (tempObject = [enumerator nextObject])
4097         {
4098                 NSDictionary *thisPresetDict = tempObject;
4099                 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
4100                 {
4101                         presetHbDefault = i;    
4102                 }
4103                 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
4104                 {
4105                         presetUserDefault = i;  
4106                 }
4107                 i++;
4108         }
4109 }
4110
4111 - (IBAction)setDefaultPreset:(id)sender
4112 {
4113     int i = 0;
4114     NSEnumerator *enumerator = [UserPresets objectEnumerator];
4115         id tempObject;
4116         /* First make sure the old user specified default preset is removed */
4117         while (tempObject = [enumerator nextObject])
4118         {
4119                 /* make sure we are not removing the default HB preset */
4120                 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4121                 {
4122                         [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4123                 }
4124                 i++;
4125         }
4126         /* Second, go ahead and set the appropriate user specfied preset */
4127         /* we get the chosen preset from the UserPresets array */
4128         if ([[[UserPresets objectAtIndex:[tableView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
4129         {
4130                 [[UserPresets objectAtIndex:[tableView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
4131         }
4132         presetUserDefault = [tableView selectedRow];
4133         
4134         /* We save all of the preset data here */
4135     [self savePreset];
4136         /* We Reload the New Table data for presets */
4137     [tableView reloadData];
4138 }
4139
4140 - (IBAction)selectDefaultPreset:(id)sender
4141 {
4142         /* if there is a user specified default, we use it */
4143         if (presetUserDefault)
4144         {
4145         [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
4146         [self tableViewSelected:NULL];
4147         }
4148         else if (presetHbDefault) //else we use the built in default presetHbDefault
4149         {
4150         [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
4151         [self tableViewSelected:NULL];
4152         }
4153 }
4154
4155 - (IBAction)tableViewSelected:(id)sender
4156 {
4157     /* Since we cannot disable the presets tableView in terms of clickability
4158            we will use the enabled state of the add presets button to determine whether
4159            or not clicking on a preset will do anything */
4160         if ([fPresetsAdd isEnabled])
4161         {
4162                 if ([tableView selectedRow] >= 0)
4163                 {       
4164                         /* we get the chosen preset from the UserPresets array */
4165                         chosenPreset = [UserPresets objectAtIndex:[tableView selectedRow]];
4166                         curUserPresetChosenNum = [sender selectedRow];
4167                         /* we set the preset display field in main window here */
4168                         [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4169                         if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4170                         {
4171                                 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@ (Default)",[chosenPreset valueForKey:@"PresetName"]]];
4172                         }
4173                         else
4174                         {
4175                                 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4176                         }
4177                         /* File Format */
4178                         [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
4179                         [self formatPopUpChanged: NULL];
4180                         
4181                         /* Chapter Markers*/
4182                         [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4183                         /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4184                         [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4185                         /* Codecs */
4186                         [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
4187                         [self codecsPopUpChanged: NULL];
4188                         /* Video encoder */
4189                         [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
4190                         
4191                         /* We can show the preset options here in the gui if we want to
4192                                 so we check to see it the user has specified it in the prefs */
4193                         [fAdvancedOptions setOptions: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
4194                         
4195                         /* Lets run through the following functions to get variables set there */
4196                         [self encoderPopUpChanged: NULL];
4197                         
4198                         [self calculateBitrate: NULL];
4199                         
4200                         /* Video quality */
4201                         [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4202                         
4203                         [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
4204                         [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
4205                         
4206                         [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
4207                         [self videoMatrixChanged: NULL];
4208                         
4209                         /* Video framerate */
4210                         [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
4211                         
4212                         /* GrayScale */
4213                         [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4214                         
4215                         /* 2 Pass Encoding */
4216                         [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4217                         [self twoPassCheckboxChanged: NULL];
4218                         /* Turbo 1st pass for 2 Pass Encoding */
4219                         [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4220                         
4221                         /*Audio*/
4222                         
4223                         /* Audio Sample Rate*/
4224                         [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
4225                         /* Audio Bitrate Rate*/
4226                         [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
4227                         /*Subtitles*/
4228                         [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
4229                         
4230                         /* Picture Settings */
4231                         /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
4232                         if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] > 0)
4233                         {
4234                                 hb_job_t * job = fTitle->job;
4235                                 /* Check to see if we should use the max picture setting for the current title*/
4236                                 if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"]  intValue] == 1)
4237                                 {
4238                                         /* Use Max Picture settings for whatever the dvd is.*/
4239                                         [self revertPictureSizeToMax: NULL];
4240                                         job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
4241                                         if (job->keep_ratio == 1)
4242                                         {
4243                                                 hb_fix_aspect( job, HB_KEEP_WIDTH );
4244                                                 if( job->height > fTitle->height )
4245                                                 {
4246                                                         job->height = fTitle->height;
4247                                                         hb_fix_aspect( job, HB_KEEP_HEIGHT );
4248                                                 }
4249                                         }
4250                                         job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
4251                                 }
4252                                 else // Apply picture settings that were in effect at the time the preset was saved
4253                                 {
4254                                         job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
4255                                         job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
4256                                         job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
4257                                         if (job->keep_ratio == 1)
4258                                         {
4259                                                 hb_fix_aspect( job, HB_KEEP_WIDTH );
4260                                                 if( job->height > fTitle->height )
4261                                                 {
4262                                                         job->height = fTitle->height;
4263                                                         hb_fix_aspect( job, HB_KEEP_HEIGHT );
4264                                                 }
4265                                         }
4266                                         job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
4267                     [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
4268                                         
4269                                         if ([chosenPreset objectForKey:@"PictureDetelecine"])
4270                                         {
4271                         [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
4272                                         }
4273                                         if ([chosenPreset objectForKey:@"PictureDenoise"])
4274                                         {
4275                         [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
4276                                         }
4277                                         /* If Cropping is set to custom, then recall all four crop values from
4278                                                 when the preset was created and apply them */
4279                                         if ([[chosenPreset objectForKey:@"PictureAutoCrop"]  intValue] == 0)
4280                                         {
4281                         [fPictureController setAutoCrop:NO];
4282                                                 
4283                                                 /* Here we use the custom crop values saved at the time the preset was saved */
4284                                                 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"]  intValue];
4285                                                 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"]  intValue];
4286                                                 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"]  intValue];
4287                                                 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"]  intValue];
4288                                                 
4289                                         }
4290                                         else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
4291                                         {
4292                         [fPictureController setAutoCrop:YES];
4293                         /* Here we use the auto crop values determined right after scan */
4294                                                 job->crop[0] = AutoCropTop;
4295                                                 job->crop[1] = AutoCropBottom;
4296                                                 job->crop[2] = AutoCropLeft;
4297                                                 job->crop[3] = AutoCropRight;
4298                                                 
4299                                         }
4300                                 }
4301                                 [self calculatePictureSizing: NULL]; 
4302                         }
4303                         
4304                         
4305                         [[fPresetsActionMenu itemAtIndex:0] setEnabled: YES];
4306                         }
4307 }
4308 }
4309
4310
4311
4312 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
4313 {
4314     return [UserPresets count];
4315 }
4316
4317 /* we use this to determine display characteristics for
4318 each table cell based on content currently only used to
4319 show the built in presets in a blue font. */
4320 - (void)tableView:(NSTableView *)aTableView
4321  willDisplayCell:(id)aCell 
4322  forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
4323 {
4324     NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
4325         NSFont *txtFont;
4326         NSColor *fontColor;
4327         NSColor *shadowColor;
4328         txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4329         /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
4330         if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
4331         {
4332                 
4333                 fontColor = [NSColor whiteColor];
4334                 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4335         }
4336         else
4337         {
4338                 /* We set the properties of unselected rows */
4339                 /* if built-in preset (defined by "type" == 0) we use a blue font */
4340                 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4341                 {
4342                         fontColor = [NSColor blueColor];
4343                 }
4344                 else // User created preset, use a black font
4345                 {
4346                         fontColor = [NSColor blackColor];
4347                 }
4348                 shadowColor = nil;
4349         }
4350         /* We check to see if this is the HB default, if so, color it appropriately */
4351         if (!presetUserDefault && presetHbDefault && rowIndex == presetHbDefault)
4352         {
4353         txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4354         }
4355         /* We check to see if this is the User Specified default, if so, color it appropriately */
4356         if (presetUserDefault && rowIndex == presetUserDefault)
4357         {
4358         txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4359         }
4360         
4361         [aCell setTextColor:fontColor];
4362         [aCell setFont:txtFont];
4363         /* this shadow stuff (like mail app) for some reason looks crappy, commented out
4364         temporarily in case we want to resurrect it */
4365         /*
4366         NSShadow *shadow = [[NSShadow alloc] init];
4367         NSSize shadowOffset = { width: 1.0, height: -1.5};
4368         [shadow setShadowOffset:shadowOffset];
4369         [shadow setShadowColor:shadowColor];
4370         [shadow set];
4371         */
4372         
4373 }
4374 /* Method to display tooltip with the description for each preset, if available */
4375 - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell 
4376                    rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
4377                     row:(int)rowIndex mouseLocation:(NSPoint)aPos
4378 {
4379      /* initialize the tooltip contents variable */
4380          NSString *loc_tip;
4381      /* if there is a description for the preset, we show it in the tooltip */
4382          if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
4383          {
4384         loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
4385         return (loc_tip);
4386          }
4387          else
4388          {
4389         loc_tip = @"No description available";
4390          }
4391          return (loc_tip);
4392
4393 }
4394
4395 - (id)tableView:(NSTableView *)aTableView
4396       objectValueForTableColumn:(NSTableColumn *)aTableColumn
4397       row:(int)rowIndex
4398 {
4399 id theRecord, theValue;
4400     
4401     theRecord = [UserPresets objectAtIndex:rowIndex];
4402     theValue = [theRecord objectForKey:[aTableColumn identifier]];
4403     return theValue;
4404 }
4405
4406 // NSTableDataSource method that we implement to edit values directly in the table...
4407 - (void)tableView:(NSTableView *)aTableView
4408         setObjectValue:(id)anObject
4409         forTableColumn:(NSTableColumn *)aTableColumn
4410         row:(int)rowIndex
4411 {
4412     id theRecord;
4413     
4414     theRecord = [UserPresets objectAtIndex:rowIndex];
4415     [theRecord setObject:anObject forKey:@"PresetName"];
4416     /* We Sort the Presets By Factory or Custom */
4417         NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type" 
4418                                                     ascending:YES] autorelease];
4419                 /* We Sort the Presets Alphabetically by name */
4420         NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
4421                                                     ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
4422         NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
4423     NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
4424         [UserPresets setArray:sortedArray];
4425         /* We Reload the New Table data for presets */
4426     [tableView reloadData];
4427    /* We save all of the preset data here */
4428     [self savePreset];
4429 }
4430
4431 - (void)savePreset
4432 {
4433     [UserPresets writeToFile:UserPresetsFile atomically:YES];
4434         /* We get the default preset in case it changed */
4435         [self getDefaultPresets: NULL];
4436
4437 }
4438
4439 - (void) controlTextDidBeginEditing: (NSNotification *) notification
4440 {
4441     [self calculateBitrate: NULL];
4442 }
4443
4444 - (void) controlTextDidEndEditing: (NSNotification *) notification
4445 {
4446     [self calculateBitrate: NULL];
4447 }
4448
4449 - (void) controlTextDidChange: (NSNotification *) notification
4450 {
4451     [self calculateBitrate: NULL];
4452 }
4453
4454 - (IBAction) openHomepage: (id) sender
4455 {
4456     [[NSWorkspace sharedWorkspace] openURL: [NSURL
4457         URLWithString:@"http://handbrake.m0k.org/"]];
4458 }
4459
4460 - (IBAction) openForums: (id) sender
4461 {
4462     [[NSWorkspace sharedWorkspace] openURL: [NSURL
4463         URLWithString:@"http://handbrake.m0k.org/forum/"]];
4464 }
4465 - (IBAction) openUserGuide: (id) sender
4466 {
4467     [[NSWorkspace sharedWorkspace] openURL: [NSURL
4468         URLWithString:@"http://handbrake.m0k.org/trac/wiki/HandBrakeGuide"]];
4469 }
4470
4471 /**
4472  * Shows debug output window.
4473  */
4474 - (IBAction)showDebugOutputPanel:(id)sender
4475 {
4476     [outputPanel showOutputPanel:sender];
4477 }
4478
4479 /**
4480  * Creates preferences controller, shows preferences window modally, and
4481  * releases the controller after user has closed the window.
4482  */
4483 - (IBAction)showPreferencesWindow:(id)sender
4484 {
4485     HBPreferencesController *controller = [[HBPreferencesController alloc] init];
4486     [controller runModal:nil];
4487     [controller release];
4488 }
4489
4490 /**
4491  * Shows queue window.
4492  */
4493 - (IBAction) showQueueWindow:(id)sender
4494 {
4495     [fQueueController showQueueWindow:sender];
4496 }
4497
4498
4499 - (IBAction) toggleDrawer:(id)sender {
4500     [fPresetDrawer toggle:self];
4501 }
4502
4503 @end