1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "Controller.h"
8 #include "a52dec/a52.h"
9 #import "HBOutputPanelController.h"
10 #import "HBPreferencesController.h"
12 #define _(a) NSLocalizedString(a,NULL)
14 static int FormatSettings[4][10] =
15 { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
16 HB_MUX_MP4 | HB_VCODEC_X264 | HB_ACODEC_FAAC,
19 { HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
20 HB_MUX_AVI | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
21 HB_MUX_AVI | HB_VCODEC_X264 | HB_ACODEC_LAME,
22 HB_MUX_AVI | HB_VCODEC_X264 | HB_ACODEC_AC3},
23 { HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
24 HB_MUX_OGM | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
27 { HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
28 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_AC3,
29 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_LAME,
30 HB_MUX_MKV | HB_VCODEC_FFMPEG | HB_ACODEC_VORBIS,
31 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_FAAC,
32 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_AC3,
33 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_LAME,
34 HB_MUX_MKV | HB_VCODEC_X264 | HB_ACODEC_VORBIS,
38 /* We setup the toolbar values here */
39 static NSString* MyDocToolbarIdentifier = @"My Document Toolbar Identifier";
40 static NSString* ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
41 //static NSString* ToggleDrawerIdentifier = @"Toggle Presets Item Identifier";
42 static NSString* StartEncodingIdentifier = @"Start Encoding Item Identifier";
43 static NSString* PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
44 static NSString* ShowQueueIdentifier = @"Show Queue Item Identifier";
45 static NSString* AddToQueueIdentifier = @"Add to Queue Item Identifier";
46 static NSString* DebugOutputIdentifier = @"Debug Output Item Identifier";
48 /*******************************
49 * HBController implementation *
50 *******************************/
51 @implementation HBController
56 [HBPreferencesController registerUserDefaults];
58 outputPanel = [[HBOutputPanelController alloc] init];
62 - (void) applicationDidFinishLaunching: (NSNotification *) notification
67 // Open debug output window now if it was visible when HB was closed
68 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
69 [self showDebugOutputPanel:nil];
72 int debugLevel = [[NSUserDefaults standardUserDefaults] boolForKey:@"ShowVerboseOutput"] ? HB_DEBUG_ALL : HB_DEBUG_NONE;
73 fHandle = hb_init(debugLevel, [[NSUserDefaults standardUserDefaults] boolForKey:@"CheckForUpdates"]);
75 // Set the Growl Delegate
76 HBController *hbGrowlDelegate = [[HBController alloc] init];
77 [GrowlApplicationBridge setGrowlDelegate: hbGrowlDelegate];
78 /* Init others controllers */
79 [fScanController SetHandle: fHandle];
80 [fPictureController SetHandle: fHandle];
81 [fQueueController SetHandle: fHandle];
83 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
84 [fChapterTable setDataSource:fChapterTitlesDelegate];
86 /* Call UpdateUI every 2/10 sec */
87 [[NSRunLoop currentRunLoop] addTimer: [NSTimer
88 scheduledTimerWithTimeInterval: 0.2 target: self
89 selector: @selector( UpdateUI: ) userInfo: NULL repeats: FALSE]
90 forMode: NSModalPanelRunLoopMode];
92 if( ( build = hb_check_update( fHandle, &version ) ) > -1 )
94 /* Update available - tell the user */
96 NSBeginInformationalAlertSheet( _( @"Update is available" ),
97 _( @"Go get it!" ), _( @"Discard" ), NULL, fWindow, self,
98 @selector( UpdateAlertDone:returnCode:contextInfo: ),
99 NULL, NULL, [NSString stringWithFormat:
100 _( @"HandBrake %s (build %d) is now available for download." ),
106 /* Show scan panel ASAP */
107 [self performSelectorOnMainThread: @selector(ShowScanPanel:)
108 withObject: NULL waitUntilDone: NO];
111 - (NSApplicationTerminateReply) applicationShouldTerminate:
112 (NSApplication *) app
114 if( [[fRipButton title] isEqualToString: _( @"Cancel" )] )
117 return NSTerminateCancel;
119 return NSTerminateNow;
122 - (void)applicationWillTerminate:(NSNotification *)aNotification
124 [outputPanel release];
129 - (void) awakeFromNib
133 [self TranslateStrings];
134 currentScanCount = 0;
136 //[self registrationDictionaryForGrowl];
137 /* Init User Presets .plist */
138 /* We declare the default NSFileManager into fileManager */
139 NSFileManager * fileManager = [NSFileManager defaultManager];
140 //presetPrefs = [[NSUserDefaults standardUserDefaults] retain];
141 /* we set the files and support paths here */
142 AppSupportDirectory = @"~/Library/Application Support/HandBrake";
143 AppSupportDirectory = [AppSupportDirectory stringByExpandingTildeInPath];
145 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
146 UserPresetsFile = [UserPresetsFile stringByExpandingTildeInPath];
148 x264ProfilesFile = @"~/Library/Application Support/HandBrake/x264Profiles.plist";
149 x264ProfilesFile = [x264ProfilesFile stringByExpandingTildeInPath];
150 /* We check for the app support directory for media fork */
151 if ([fileManager fileExistsAtPath:AppSupportDirectory] == 0)
153 // If it doesnt exist yet, we create it here
154 [fileManager createDirectoryAtPath:AppSupportDirectory attributes:nil];
156 // We check for the presets.plist here
158 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
161 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
164 // We check for the x264profiles.plist here
166 if ([fileManager fileExistsAtPath:x264ProfilesFile] == 0)
169 [fileManager createFileAtPath:x264ProfilesFile contents:nil attributes:nil];
173 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
174 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
176 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
177 if (nil == UserPresets)
179 UserPresets = [[NSMutableArray alloc] init];
180 [self AddFactoryPresets:NULL];
182 /* Show/Dont Show Presets drawer upon launch based
183 on user preference DefaultPresetsDrawerShow*/
184 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
186 [fPresetDrawer open];
192 [fDstFormatPopUp removeAllItems];
193 [fDstFormatPopUp addItemWithTitle: _( @"MP4 file" )];
194 [fDstFormatPopUp addItemWithTitle: _( @"AVI file" )];
195 [fDstFormatPopUp addItemWithTitle: _( @"OGM file" )];
196 [fDstFormatPopUp addItemWithTitle: _( @"MKV file" )];
197 [fDstFormatPopUp selectItemAtIndex: 0];
199 [self FormatPopUpChanged: NULL];
201 /* We enable the create chapters checkbox here since we are .mp4 */
202 [fCreateChapterMarkers setEnabled: YES];
203 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
205 [fCreateChapterMarkers setState: NSOnState];
211 [fDstFile2Field setStringValue: [NSString stringWithFormat:
212 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
215 [fVidEncoderPopUp removeAllItems];
216 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
217 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
222 [fVidTargetSizeField setIntValue: 700];
223 [fVidBitrateField setIntValue: 1000];
225 [fVidQualityMatrix selectCell: fVidBitrateCell];
226 [self VideoMatrixChanged: NULL];
228 /* Video framerate */
229 [fVidRatePopUp removeAllItems];
230 [fVidRatePopUp addItemWithTitle: _( @"Same as source" )];
231 for( int i = 0; i < hb_video_rates_count; i++ )
233 [fVidRatePopUp addItemWithTitle:
234 [NSString stringWithCString: hb_video_rates[i].string]];
236 [fVidRatePopUp selectItemAtIndex: 0];
238 /* Picture Settings */
239 [fPicLabelPAROutp setStringValue: @""];
240 [fPicLabelPAROutputX setStringValue: @""];
241 [fPicSettingPARWidth setStringValue: @""];
242 [fPicSettingPARHeight setStringValue: @""];
245 [fAudBitratePopUp removeAllItems];
246 for( int i = 0; i < hb_audio_bitrates_count; i++ )
248 [fAudBitratePopUp addItemWithTitle:
249 [NSString stringWithCString: hb_audio_bitrates[i].string]];
251 [fAudBitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
253 /* Audio samplerate */
254 [fAudRatePopUp removeAllItems];
255 for( int i = 0; i < hb_audio_rates_count; i++ )
257 [fAudRatePopUp addItemWithTitle:
258 [NSString stringWithCString: hb_audio_rates[i].string]];
260 [fAudRatePopUp selectItemAtIndex: hb_audio_rates_default];
263 [fStatusField setStringValue: @""];
266 //[fPauseButton setEnabled: NO];
267 //[fRipButton setEnabled: NO];
268 /* Use new Toolbar start and pause here */
270 pauseButtonEnabled = NO;
271 startButtonEnabled = NO;
273 /* In Ritsuka's patch, this goes below the Turbo stuff below
274 Lets try to keep it all together */
275 startButtonEnabled = NO;
277 AddToQueueButtonEnabled = NO;
278 pauseButtonEnabled = NO;
281 /* We disable the Turbo 1st pass checkbox since we are not x264 */
282 [fVidTurboPassCheck setEnabled: NO];
283 [fVidTurboPassCheck setState: NSOffState];
286 // ============================================================
287 // NSToolbar Related Methods
288 // ============================================================
290 - (void) setupToolbar {
291 // Create a new toolbar instance, and attach it to our document window
292 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: MyDocToolbarIdentifier] autorelease];
294 // Set up toolbar properties: Allow customization, give a default display mode, and remember state in user defaults
295 [toolbar setAllowsUserCustomization: YES];
296 [toolbar setAutosavesConfiguration: YES];
297 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
299 // We are the delegate
300 [toolbar setDelegate: self];
302 // Attach the toolbar to the document window
303 [fWindow setToolbar: toolbar];
306 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
307 // Required delegate method: Given an item identifier, this method returns an item
308 // The toolbar will use this method to obtain toolbar items that can be displayed in the customization sheet, or in the toolbar itself
309 NSToolbarItem *toolbarItem = nil;
311 if ([itemIdent isEqual: ToggleDrawerIdentifier]) {
312 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
314 // Set the text label to be displayed in the toolbar and customization palette
315 [toolbarItem setLabel: @"Toggle Presets"];
316 [toolbarItem setPaletteLabel: @"Toggler Presets"];
318 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
319 [toolbarItem setToolTip: @"Open/Close Preset Drawer"];
320 [toolbarItem setImage: [NSImage imageNamed: @"Drawer-List2"]];
322 // Tell the item what message to send when it is clicked
323 [toolbarItem setTarget: self];
324 [toolbarItem setAction: @selector(toggleDrawer)];
326 } else if ([itemIdent isEqual: StartEncodingIdentifier]) {
327 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
329 // Set the text label to be displayed in the toolbar and customization palette
330 [toolbarItem setLabel: @"Start"];
331 [toolbarItem setPaletteLabel: @"Start Encoding"];
333 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
334 [toolbarItem setToolTip: @"Start Encoding"];
335 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
337 // Tell the item what message to send when it is clicked
338 [toolbarItem setTarget: self];
339 [toolbarItem setAction: @selector(Rip:)];
343 } else if ([itemIdent isEqual: ShowQueueIdentifier]) {
344 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
346 // Set the text label to be displayed in the toolbar and customization palette
347 [toolbarItem setLabel: @"Show Queue"];
348 [toolbarItem setPaletteLabel: @"Show Queue"];
350 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
351 [toolbarItem setToolTip: @"Show Queue"];
352 [toolbarItem setImage: [NSImage imageNamed: @"Brushed Window"]];
354 // Tell the item what message to send when it is clicked
355 [toolbarItem setTarget: self];
356 [toolbarItem setAction: @selector(ShowQueuePanel:)];
358 } else if ([itemIdent isEqual: AddToQueueIdentifier]) {
359 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
361 // Set the text label to be displayed in the toolbar and customization palette
362 [toolbarItem setLabel: @"Add to Queue"];
363 [toolbarItem setPaletteLabel: @"Add to Queue"];
365 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
366 [toolbarItem setToolTip: @"Add to Queue"];
367 [toolbarItem setImage: [NSImage imageNamed: @"Add"]];
369 // Tell the item what message to send when it is clicked
370 [toolbarItem setTarget: self];
371 [toolbarItem setAction: @selector(AddToQueue:)];
374 } else if ([itemIdent isEqual: PauseEncodingIdentifier]) {
375 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
377 // Set the text label to be displayed in the toolbar and customization palette
378 [toolbarItem setLabel: @"Pause"];
379 [toolbarItem setPaletteLabel: @"Pause Encoding"];
381 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
382 [toolbarItem setToolTip: @"Pause Encoding"];
383 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
385 // Tell the item what message to send when it is clicked
386 [toolbarItem setTarget: self];
387 [toolbarItem setAction: @selector(Pause:)];
389 } else if ([itemIdent isEqual: DebugOutputIdentifier]) {
390 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
392 // Set the text label to be displayed in the toolbar and customization palette
393 [toolbarItem setLabel: @"Activity Window"];
394 [toolbarItem setPaletteLabel: @"Show Activity Window"];
396 // Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
397 [toolbarItem setToolTip: @"Show Activity Window"];
398 [toolbarItem setImage: [NSImage imageNamed: @"Terminal"]];
400 // Tell the item what message to send when it is clicked
401 [toolbarItem setTarget: self];
402 [toolbarItem setAction: @selector(showDebugOutputPanel:)];
405 //itemIdent refered to a toolbar item that is not provide or supported by us or cocoa
406 //Returning nil will inform the toolbar this kind of item is not supported
413 - (void) toggleDrawer {
414 [fPresetDrawer toggle:self];
417 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
418 // Required delegate method: Returns the ordered list of items to be shown in the toolbar by default
419 // If during the toolbar's initialization, no overriding values are found in the user defaults, or if the
420 // user chooses to revert to the default items this set will be used
421 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, NSToolbarSeparatorItemIdentifier,
422 AddToQueueIdentifier, ShowQueueIdentifier,
423 NSToolbarFlexibleSpaceItemIdentifier,
424 NSToolbarSpaceItemIdentifier, DebugOutputIdentifier, ToggleDrawerIdentifier, nil];
427 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
428 // Required delegate method: Returns the list of all allowed items by identifier. By default, the toolbar
429 // does not assume any items are allowed, even the separator. So, every allowed item must be explicitly listed
430 // The set of allowed items is used to construct the customization palette
431 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier,
432 DebugOutputIdentifier, NSToolbarCustomizeToolbarItemIdentifier,
433 NSToolbarFlexibleSpaceItemIdentifier, NSToolbarSpaceItemIdentifier,
434 NSToolbarSeparatorItemIdentifier,ToggleDrawerIdentifier, nil];
437 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem {
438 // Optional method: This message is sent to us since we are the target of some toolbar item actions
440 if ([[toolbarItem itemIdentifier] isEqual: ToggleDrawerIdentifier]) {
443 if ([[toolbarItem itemIdentifier] isEqual: StartEncodingIdentifier]) {
444 enable = startButtonEnabled;
446 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
447 [toolbarItem setLabel: @"Cancel"];
448 [toolbarItem setPaletteLabel: @"Cancel"];
449 [toolbarItem setToolTip: @"Cancel Encoding"];
452 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
453 [toolbarItem setLabel: @"Start"];
454 [toolbarItem setPaletteLabel: @"Start Encoding"];
455 [toolbarItem setToolTip: @"Start Encoding"];
459 if ([[toolbarItem itemIdentifier] isEqual: PauseEncodingIdentifier]) {
460 enable = pauseButtonEnabled;
462 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
463 [toolbarItem setLabel: @"Resume"];
464 [toolbarItem setPaletteLabel: @"Resume Encoding"];
465 [toolbarItem setToolTip: @"Resume Encoding"];
468 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
469 [toolbarItem setLabel: @"Pause"];
470 [toolbarItem setPaletteLabel: @"Pause Encoding"];
471 [toolbarItem setToolTip: @"Pause Encoding"];
474 if ([[toolbarItem itemIdentifier] isEqual: DebugOutputIdentifier]) {
477 if ([[toolbarItem itemIdentifier] isEqual: ShowQueueIdentifier]) {
480 if ([[toolbarItem itemIdentifier] isEqual: AddToQueueIdentifier]) {
481 enable = AddToQueueButtonEnabled;
486 // register a test notification and make
487 // it enabled by default
488 #define SERVICE_NAME @"Encode Done"
489 - (NSDictionary *)registrationDictionaryForGrowl
491 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
492 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
493 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
496 return registrationDictionary;
498 - (void) TranslateStrings
500 [fSrcDVD1Field setStringValue: _( @"DVD:" )];
501 [fSrcTitleField setStringValue: _( @"Title:" )];
502 [fSrcChapterField setStringValue: _( @"Chapters:" )];
503 [fSrcChapterToField setStringValue: _( @"to" )];
504 [fSrcDuration1Field setStringValue: _( @"Duration:" )];
506 [fDstFormatField setStringValue: _( @"File format:" )];
507 [fDstCodecsField setStringValue: _( @"Codecs:" )];
508 [fDstFile1Field setStringValue: _( @"File:" )];
509 [fDstBrowseButton setTitle: _( @"Browse" )];
511 [fVidRateField setStringValue: _( @"Framerate (fps):" )];
512 [fVidEncoderField setStringValue: _( @"Encoder:" )];
513 [fVidQualityField setStringValue: _( @"Quality:" )];
516 /***********************************************************************
518 ***********************************************************************
519 * Shows a progression bar on the dock icon, filled according to
520 * 'progress' (0.0 <= progress <= 1.0).
521 * Called with progress < 0.0 or progress > 1.0, restores the original
523 **********************************************************************/
524 - (void) UpdateDockIcon: (float) progress
528 NSBitmapImageRep * bmp;
530 uint32_t black = htonl( 0x000000FF );
531 uint32_t red = htonl( 0xFF0000FF );
532 uint32_t white = htonl( 0xFFFFFFFF );
533 int row_start, row_end;
536 /* Get application original icon */
537 icon = [NSImage imageNamed: @"NSApplicationIcon"];
539 if( progress < 0.0 || progress > 1.0 )
541 [NSApp setApplicationIconImage: icon];
545 /* Get it in a raw bitmap form */
546 tiff = [icon TIFFRepresentationUsingCompression:
547 NSTIFFCompressionNone factor: 1.0];
548 bmp = [NSBitmapImageRep imageRepWithData: tiff];
550 /* Draw the progression bar */
551 /* It's pretty simple (ugly?) now, but I'm no designer */
553 row_start = 3 * (int) [bmp size].height / 4;
554 row_end = 7 * (int) [bmp size].height / 8;
556 for( i = row_start; i < row_start + 2; i++ )
558 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
559 for( j = 0; j < (int) [bmp size].width; j++ )
564 for( i = row_start + 2; i < row_end - 2; i++ )
566 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
569 for( j = 2; j < (int) [bmp size].width - 2; j++ )
571 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
583 for( i = row_end - 2; i < row_end; i++ )
585 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
586 for( j = 0; j < (int) [bmp size].width; j++ )
592 /* Now update the dock icon */
593 tiff = [bmp TIFFRepresentationUsingCompression:
594 NSTIFFCompressionNone factor: 1.0];
595 icon = [[NSImage alloc] initWithData: tiff];
596 [NSApp setApplicationIconImage: icon];
600 - (void) UpdateUI: (NSTimer *) timer
604 list = hb_get_titles( fHandle );
605 /* check to see if there has been a new scan done
606 this bypasses the constraints of HB_STATE_WORKING
607 not allowing setting a newly scanned source */
608 int checkScanCount = hb_get_scancount( fHandle );
609 if (checkScanCount > currentScanCount)
612 currentScanCount = checkScanCount;
613 [fScanController Cancel: NULL];
614 [fScanIndicator setIndeterminate: NO];
615 [fScanIndicator setDoubleValue: 0.0];
616 [fScanIndicator setHidden: YES];
617 [fScanController Cancel: NULL];
618 if( !hb_list_count( list ) )
620 /* We display a message if a valid dvd source was not chosen */
621 [fSrcDVD2Field setStringValue: @"No Valid DVD Source Chosen"];
622 currentSource = [fSrcDVD2Field stringValue];
626 [self ShowNewScan: NULL];
634 hb_get_state( fHandle, &s );
641 #define p s.param.scanning
642 case HB_STATE_SCANNING:
644 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
645 _( @"Scanning title %d of %d..." ),
646 p.title_cur, p.title_count]];
647 [fScanIndicator setIndeterminate: NO];
648 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) /
654 #define p s.param.scandone
655 case HB_STATE_SCANDONE:
658 [fScanIndicator setIndeterminate: NO];
659 [fScanIndicator setDoubleValue: 0.0];
660 [fScanIndicator setHidden: YES];
661 [fScanController Cancel: NULL];
662 if( !hb_list_count( list ) )
664 /* We display a message if a valid dvd source was not chosen */
665 [fSrcDVD2Field setStringValue: @"No Valid DVD Source Chosen"];
666 currentSource = [fSrcDVD2Field stringValue];
670 [self ShowNewScan: NULL];
676 #define p s.param.working
677 case HB_STATE_WORKING:
679 float progress_total;
680 NSMutableString * string;
681 /* Currently, p.job_cur and p.job_count get screwed up when adding
682 jobs during encoding, if they cannot be fixed in libhb, will implement a
683 nasty but working cocoa solution */
684 /* Update text field */
685 string = [NSMutableString stringWithFormat: _( @"Encoding: task %d of %d, %.2f %%" ), p.job_cur, p.job_count, 100.0 * p.progress];
689 [string appendFormat:
690 _( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)" ),
691 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
693 [fStatusField setStringValue: string];
696 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
697 [fRipIndicator setIndeterminate: NO];
698 [fRipIndicator setDoubleValue: 100.0 * progress_total];
700 /* Update dock icon */
701 [self UpdateDockIcon: progress_total];
703 /* new toolbar controls */
704 pauseButtonEnabled = YES;
706 startButtonEnabled = YES;
713 #define p s.param.muxing
714 case HB_STATE_MUXING:
716 NSMutableString * string;
718 /* Update text field */
719 string = [NSMutableString stringWithFormat:
721 [fStatusField setStringValue: string];
724 [fRipIndicator setIndeterminate: YES];
725 [fRipIndicator startAnimation: nil];
727 /* Update dock icon */
728 [self UpdateDockIcon: 1.0];
730 //[fPauseButton setEnabled: YES];
731 //[fPauseButton setTitle: _( @"Pause" )];
732 //[fRipButton setEnabled: YES];
733 // [fRipButton setTitle: _( @"Cancel" )];
738 case HB_STATE_PAUSED:
739 //[fStatusField setStringValue: _( @"Paused" )];
740 //[fPauseButton setEnabled: YES];
741 //[fPauseButton setTitle: _( @"Resume" )];
742 //[fRipButton setEnabled: YES];
743 //[fRipButton setTitle: _( @"Cancel" )];
744 /* new toolbar controls */
745 pauseButtonEnabled = YES;
747 startButtonEnabled = YES;
751 case HB_STATE_WORKDONE:
753 [fStatusField setStringValue: _( @"Done." )];
754 [fRipIndicator setIndeterminate: NO];
755 [fRipIndicator setDoubleValue: 0.0];
756 //[fRipButton setTitle: _( @"Start" )];
758 /* Restore dock icon */
759 [self UpdateDockIcon: -1.0];
761 //[fPauseButton setEnabled: NO];
762 //[fPauseButton setTitle: _( @"Pause" )];
763 // [fRipButton setEnabled: YES];
764 // [fRipButton setTitle: _( @"Start" )];
765 /* new toolbar controls */
766 pauseButtonEnabled = NO;
768 startButtonEnabled = YES;
770 NSRect frame = [fWindow frame];
771 if (frame.size.width <= 591)
772 frame.size.width = 591;
773 frame.size.height += -44;
774 frame.origin.y -= -44;
775 [fWindow setFrame:frame display:YES animate:YES];
779 while( ( job = hb_job( fHandle, 0 ) ) )
781 hb_rem( fHandle, job );
783 /* Check to see if the encode state has not been cancelled
784 to determine if we should check for encode done notifications */
785 if (fEncodeState != 2) {
786 /* If Growl Notification or Window and Growl has been selected */
787 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
788 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
790 /*Growl Notification*/
791 [self showGrowlDoneNotification: NULL];
793 /* If Alert Window or Window and Growl has been selected */
794 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
795 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
797 /*On Screen Notification*/
800 status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
801 [NSApp requestUserAttention:NSCriticalRequest];
802 if ( status == NSAlertDefaultReturn )
804 [self EnableUI: YES];
809 [self EnableUI: YES];
814 [self EnableUI: YES];
820 /* Lets show the queue status
821 here in the main window*/
822 int queue_count = hb_count( fHandle );
825 [fQueueStatus setStringValue: [NSString stringWithFormat:
826 @"%d task%s in the queue",
827 queue_count, ( queue_count > 1 ) ? "s" : ""]];
831 [fQueueStatus setStringValue: @""];
834 [[NSRunLoop currentRunLoop] addTimer: [NSTimer
835 scheduledTimerWithTimeInterval: 0.2 target: self
836 selector: @selector( UpdateUI: ) userInfo: NULL repeats: FALSE]
837 forMode: NSModalPanelRunLoopMode];
839 - (IBAction) ShowNewScan:(id)sender
843 int indxpri=0; // Used to search the longuest title (default in combobox)
844 int longuestpri=0; // Used to search the longuest title (default in combobox)
846 //[fScanController UpdateUI: &s];
848 list = hb_get_titles( fHandle );
850 if( !hb_list_count( list ) )
852 /* We display a message if a valid dvd source was not chosen */
853 [fSrcDVD2Field setStringValue: @"No Valid DVD Source Chosen"];
854 currentSource = [fSrcDVD2Field stringValue];
858 [fSrcTitlePopUp removeAllItems];
859 for( int i = 0; i < hb_list_count( list ); i++ )
861 title = (hb_title_t *) hb_list_item( list, i );
862 /*Set DVD Name at top of window*/
863 [fSrcDVD2Field setStringValue:[NSString stringWithUTF8String: title->name]];
864 currentSource = [NSString stringWithUTF8String: title->dvd];
865 sourceDisplayName = [NSString stringWithUTF8String: title->name];
866 /* Use the dvd name in the default output field here
867 May want to add code to remove blank spaces for some dvd names*/
868 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
869 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
871 [fDstFile2Field setStringValue: [NSString stringWithFormat:
872 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[NSString
873 stringWithUTF8String: title->name]]];
877 [fDstFile2Field setStringValue: [NSString stringWithFormat:
878 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[NSString
879 stringWithUTF8String: title->name]]];
883 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
885 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
890 int format = [fDstFormatPopUp indexOfSelectedItem];
896 /*Get Default MP4 File Extension for mpeg4 (.mp4 or .m4v) from prefs*/
897 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
915 NSString * string = [fDstFile2Field stringValue];
916 /* Add/replace File Output name to the correct extension*/
917 if( [string characterAtIndex: [string length] - 4] == '.' )
919 [fDstFile2Field setStringValue: [NSString stringWithFormat:
920 @"%@.%s", [string substringToIndex: [string length] - 4],
925 [fDstFile2Field setStringValue: [NSString stringWithFormat:
926 @"%@.%s", string, ext]];
930 [fSrcTitlePopUp addItemWithTitle: [NSString
931 stringWithFormat: @"%d - %02dh%02dm%02ds",
932 title->index, title->hours, title->minutes,
936 // Select the longuest title
937 [fSrcTitlePopUp selectItemAtIndex: indxpri];
938 /* We set the Settings Display to "Default" here
939 until we get default presets implemented */
940 [fPresetSelectedDisplay setStringValue: @"Default"];
941 /* We set the auto crop in the main window to value "1" just as in PictureController,
942 as it does not seem to be taken from any job-> variable */
943 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
946 [self TitlePopUpChanged: NULL];
947 [self EnableUI: YES];
948 //[fPauseButton setEnabled: NO];
949 //[fRipButton setEnabled: YES];
950 startButtonEnabled = YES;
952 AddToQueueButtonEnabled = YES;
953 pauseButtonEnabled = NO;
958 -(IBAction)showGrowlDoneNotification:(id)sender
962 [GrowlApplicationBridge
963 notifyWithTitle:@"Put down that cocktail..."
964 description:@"your HandBrake encode is done!"
965 notificationName:SERVICE_NAME
971 - (void) EnableUI: (bool) b
973 NSControl * controls[] =
974 { fSrcDVD1Field, fSrcTitleField, fSrcTitlePopUp,
975 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
976 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
977 fDstFormatField, fDstFormatPopUp, fDstCodecsField,
978 fDstCodecsPopUp, fDstFile1Field, fDstFile2Field,
979 fDstBrowseButton, fVidRateField, fVidRatePopUp,
980 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
981 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
982 fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
983 fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
984 fAudRateField, fAudRatePopUp, fAudBitrateField,
985 fAudBitratePopUp, fPictureButton,fQueueStatus,
986 fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,
987 fPicSettingARkeep,fPicSettingDeinterlace,fPicSettingARkeepDsply,
988 fPicSettingDeinterlaceDsply,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
989 fPicLabelAr,fPicLabelDeinter,fPicLabelSrcX,fPicLabelOutputX,
990 fPicLabelPAROutp,fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
991 fPicSettingPARDsply,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
992 fCreateChapterMarkers,fX264optViewTitleLabel,fDisplayX264Options,fDisplayX264OptionsLabel,fX264optBframesLabel,
993 fX264optBframesPopUp,fX264optRefLabel,fX264optRefPopUp,fX264optNfpskipLabel,fX264optNfpskipSwitch,
994 fX264optNodctdcmtLabel,fX264optNodctdcmtSwitch,fX264optSubmeLabel,fX264optSubmePopUp,
995 fX264optTrellisLabel,fX264optTrellisPopUp,fX264optMixedRefsLabel,fX264optMixedRefsSwitch,
996 fX264optMotionEstLabel,fX264optMotionEstPopUp,fX264optMERangeLabel,fX264optMERangePopUp,
997 fX264optWeightBLabel,fX264optWeightBSwitch,fX264optBRDOLabel,fX264optBRDOSwitch,
998 fX264optBPyramidLabel,fX264optBPyramidSwitch,fX264optBiMELabel,fX264optBiMESwitch,
999 fX264optDirectPredLabel,fX264optDirectPredPopUp,fX264optDeblockLabel,fX264optAnalyseLabel,
1000 fX264optAnalysePopUp,fX264opt8x8dctLabel,fX264opt8x8dctSwitch,fX264optCabacLabel,fX264optCabacSwitch,
1001 fX264optAlphaDeblockPopUp,fX264optBetaDeblockPopUp,fVidTurboPassCheck,fDstMpgLargeFileCheck,fPicSettingAutoCropLabel,
1002 fPicSettingAutoCropDsply};
1004 for( unsigned i = 0;
1005 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
1007 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
1009 NSTextField * tf = (NSTextField *) controls[i];
1010 if( ![tf isBezeled] )
1012 [tf setTextColor: b ? [NSColor controlTextColor] :
1013 [NSColor disabledControlTextColor]];
1017 [controls[i] setEnabled: b];
1023 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
1024 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
1025 [self SetEnabledStateOfAudioMixdownControls: NULL];
1029 [tableView setEnabled: NO];
1033 [self VideoMatrixChanged: NULL];
1036 - (IBAction) ShowScanPanel: (id) sender
1038 [fScanController Show];
1041 - (IBAction) OpenMainWindow: (id) sender
1043 [fWindow makeKeyAndOrderFront:nil];
1044 [fWindow setReleasedWhenClosed: YES];
1046 - (BOOL) windowShouldClose: (id) sender
1049 /* See if we are currently running */
1051 hb_get_state( fHandle, &s );
1052 if ( s.state == HB_STATE_WORKING)
1054 /* If we are running, leave in memory when closing main window */
1055 [fWindow setReleasedWhenClosed: NO];
1061 /* Stop the application when the user closes the window */
1062 [NSApp terminate: self];
1068 - (IBAction) VideoMatrixChanged: (id) sender;
1070 bool target, bitrate, quality;
1072 target = bitrate = quality = false;
1073 if( [fVidQualityMatrix isEnabled] )
1075 switch( [fVidQualityMatrix selectedRow] )
1088 [fVidTargetSizeField setEnabled: target];
1089 [fVidBitrateField setEnabled: bitrate];
1090 [fVidQualitySlider setEnabled: quality];
1091 [fVidTwoPassCheck setEnabled: !quality &&
1092 [fVidQualityMatrix isEnabled]];
1095 [fVidTwoPassCheck setState: NSOffState];
1098 [self QualitySliderChanged: sender];
1099 [self CalculateBitrate: sender];
1100 [self CustomSettingUsed: sender];
1103 - (IBAction) QualitySliderChanged: (id) sender
1105 [fVidConstantCell setTitle: [NSString stringWithFormat:
1106 _( @"Constant quality: %.0f %%" ), 100.0 *
1107 [fVidQualitySlider floatValue]]];
1108 [self CustomSettingUsed: sender];
1111 - (IBAction) BrowseFile: (id) sender
1113 /* Open a panel to let the user choose and update the text field */
1114 NSSavePanel * panel = [NSSavePanel savePanel];
1115 /* We get the current file name and path from the destination field here */
1116 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1117 modalForWindow: fWindow modalDelegate: self
1118 didEndSelector: @selector( BrowseFileDone:returnCode:contextInfo: )
1122 - (void) BrowseFileDone: (NSSavePanel *) sheet
1123 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1125 if( returnCode == NSOKButton )
1127 [fDstFile2Field setStringValue: [sheet filename]];
1132 - (IBAction) ShowPicturePanel: (id) sender
1134 hb_list_t * list = hb_get_titles( fHandle );
1135 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1136 [fSrcTitlePopUp indexOfSelectedItem] );
1138 /* Resize the panel */
1140 newSize.width = 246 + title->width;
1141 newSize.height = 80 + title->height;
1142 [fPicturePanel setContentSize: newSize];
1144 [fPictureController SetTitle: title];
1146 [NSApp beginSheet: fPicturePanel modalForWindow: fWindow
1147 modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
1148 [NSApp runModalForWindow: fPicturePanel];
1149 [NSApp endSheet: fPicturePanel];
1150 [fPicturePanel orderOut: self];
1151 [self CalculatePictureSizing: sender];
1154 - (IBAction) ShowQueuePanel: (id) sender
1156 /* Update the OutlineView */
1157 [fQueueController Update: sender];
1159 /* Show the panel */
1160 [NSApp beginSheet: fQueuePanel modalForWindow: fWindow
1161 modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
1162 [NSApp runModalForWindow: fQueuePanel];
1163 [NSApp endSheet: fQueuePanel];
1164 [fQueuePanel orderOut: self];
1169 hb_list_t * list = hb_get_titles( fHandle );
1170 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1171 [fSrcTitlePopUp indexOfSelectedItem] );
1172 hb_job_t * job = title->job;
1175 /* Chapter selection */
1176 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
1177 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
1179 /* Format and codecs */
1180 int format = [fDstFormatPopUp indexOfSelectedItem];
1181 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1182 job->mux = FormatSettings[format][codecs] & HB_MUX_MASK;
1183 job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
1184 job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1185 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
1186 if ([fDstFormatPopUp indexOfSelectedItem] == 0)
1188 /* We set the chapter marker extraction here based on the format being
1189 mpeg4 and the checkbox being checked */
1190 if ([fCreateChapterMarkers state] == NSOnState)
1192 job->chapter_markers = 1;
1196 job->chapter_markers = 0;
1198 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
1199 mpeg4 and the checkbox being checked
1200 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
1201 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0 && [fDstMpgLargeFileCheck state] == NSOnState)
1203 job->largeFileSize = 1;
1207 job->largeFileSize = 0;
1212 if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
1213 [fVidEncoderPopUp indexOfSelectedItem] > 0 )
1215 job->vcodec = HB_VCODEC_XVID;
1217 if( job->vcodec & HB_VCODEC_X264 )
1219 if ([fVidEncoderPopUp indexOfSelectedItem] > 0 )
1221 /* Just use new Baseline Level 3.0
1222 Lets Deprecate Baseline Level 1.3h264_level*/
1223 job->h264_level = 30;
1224 job->mux = HB_MUX_IPOD;
1225 /* move sanity check for iPod Encoding here */
1226 job->pixel_ratio = 0 ;
1230 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
1231 Currently only used with Constant Quality setting*/
1232 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
1237 /* Below Sends x264 options to the core library if x264 is selected*/
1238 /* Lets use this as per Nyx, Thanks Nyx!*/
1239 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1240 /* Turbo first pass if two pass and Turbo First pass is selected */
1241 if( [fVidTwoPassCheck state] == NSOnState && [fVidTurboPassCheck state] == NSOnState )
1243 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
1244 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:weightb=0:trellis=0:no-fast-pskip=0:8x8dct=0";
1245 /* append the "Turbo" string variable to the existing opts string.
1246 Note: the "Turbo" string must be appended, not prepended to work properly*/
1247 NSString *firstPassOptStringCombined = [[fDisplayX264Options stringValue] stringByAppendingString:firstPassOptStringTurbo];
1248 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
1252 strcpy(job->x264opts, [[fDisplayX264Options stringValue] UTF8String]);
1255 job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
1258 /* Video settings */
1259 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
1261 job->vrate = 27000000;
1262 job->vrate_base = hb_video_rates[[fVidRatePopUp
1263 indexOfSelectedItem]-1].rate;
1267 job->vrate = title->rate;
1268 job->vrate_base = title->rate_base;
1271 switch( [fVidQualityMatrix selectedRow] )
1275 Bitrate should already have been calculated and displayed
1276 in fVidBitrateField, so let's just use it */
1278 job->vquality = -1.0;
1279 job->vbitrate = [fVidBitrateField intValue];
1282 job->vquality = [fVidQualitySlider floatValue];
1287 job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
1291 /* Subtitle settings */
1292 job->subtitle = [fSubPopUp indexOfSelectedItem] - 1;
1294 /* Audio tracks and mixdowns */
1295 /* check for the condition where track 2 has an audio selected, but track 1 does not */
1296 /* we will use track 2 as track 1 in this scenario */
1297 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1299 job->audios[0] = [fAudLang1PopUp indexOfSelectedItem] - 1;
1300 job->audios[1] = [fAudLang2PopUp indexOfSelectedItem] - 1; /* will be -1 if "none" is selected */
1301 job->audios[2] = -1;
1302 job->audio_mixdowns[0] = [[fAudTrack1MixPopUp selectedItem] tag];
1303 job->audio_mixdowns[1] = [[fAudTrack2MixPopUp selectedItem] tag];
1305 else if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1307 job->audios[0] = [fAudLang2PopUp indexOfSelectedItem] - 1;
1308 job->audio_mixdowns[0] = [[fAudTrack2MixPopUp selectedItem] tag];
1309 job->audios[1] = -1;
1313 job->audios[0] = -1;
1316 /* Audio settings */
1317 job->arate = hb_audio_rates[[fAudRatePopUp
1318 indexOfSelectedItem]].rate;
1319 job->abitrate = [[fAudBitratePopUp selectedItem] tag];
1325 - (IBAction) AddToQueue: (id) sender
1327 /* We get the destination directory from the destingation field here */
1328 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1329 /* We check for a valid destination here */
1330 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1332 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1337 hb_list_t * list = hb_get_titles( fHandle );
1338 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1339 [fSrcTitlePopUp indexOfSelectedItem] );
1340 hb_job_t * job = title->job;
1344 /* Destination file */
1345 job->file = [[fDstFile2Field stringValue] UTF8String];
1347 if( [fVidTwoPassCheck state] == NSOnState )
1350 hb_add( fHandle, job );
1353 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
1354 strcpy(job->x264opts, [[fDisplayX264Options stringValue] UTF8String]);
1356 hb_add( fHandle, job );
1361 hb_add( fHandle, job );
1364 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1365 /* Lets try to update stuff, taken from remove in the queue controller */
1366 [fQueueController performSelectorOnMainThread: @selector( Update: )
1367 withObject: sender waitUntilDone: NO];
1371 - (IBAction) Rip: (id) sender
1373 /* Rip or Cancel ? */
1374 // if( [[fRipButton title] isEqualToString: _( @"Cancel" )] )
1377 [self Cancel: sender];
1380 /* if there is no job in the queue, then add it to the queue and rip
1381 otherwise, there are already jobs in queue, so just rip the queue */
1382 int count = hb_count( fHandle );
1385 [self AddToQueue: sender];
1388 /* We check for duplicate name here */
1389 if( [[NSFileManager defaultManager] fileExistsAtPath:
1390 [fDstFile2Field stringValue]] )
1392 NSBeginCriticalAlertSheet( _( @"File already exists" ),
1393 _( @"Cancel" ), _( @"Overwrite" ), NULL, fWindow, self,
1394 @selector( OverwriteAlertDone:returnCode:contextInfo: ),
1395 NULL, NULL, [NSString stringWithFormat:
1396 _( @"Do you want to overwrite %@?" ),
1397 [fDstFile2Field stringValue]] );
1400 /* We get the destination directory from the destination field here */
1401 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1402 /* We check for a valid destination here */
1403 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
1405 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
1409 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1417 - (void) OverwriteAlertDone: (NSWindow *) sheet
1418 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1420 if( returnCode == NSAlertAlternateReturn )
1426 - (void) UpdateAlertDone: (NSWindow *) sheet
1427 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1429 if( returnCode == NSAlertAlternateReturn )
1431 /* Show scan panel */
1432 [self performSelectorOnMainThread: @selector(ShowScanPanel:)
1433 withObject: NULL waitUntilDone: NO];
1437 /* Go to HandBrake homepage and exit */
1438 [self OpenHomepage: NULL];
1439 [NSApp terminate: self];
1444 /* Let libhb do the job */
1445 hb_start( fHandle );
1446 /*set the fEncodeState State */
1449 /* Disable interface */
1450 //[self EnableUI: NO];
1451 // [fPauseButton setEnabled: NO];
1452 // [fRipButton setEnabled: NO];
1453 pauseButtonEnabled = NO;
1454 startButtonEnabled = NO;
1455 NSRect frame = [fWindow frame];
1456 if (frame.size.width <= 591)
1457 frame.size.width = 591;
1458 frame.size.height += 44;
1459 frame.origin.y -= 44;
1460 [fWindow setFrame:frame display:YES animate:YES];
1463 - (IBAction) Cancel: (id) sender
1465 NSBeginCriticalAlertSheet( _( @"Cancel - Are you sure?" ),
1466 _( @"Keep working" ), _( @"Cancel encoding" ), NULL, fWindow, self,
1467 @selector( _Cancel:returnCode:contextInfo: ), NULL, NULL,
1468 _( @"Encoding won't be recoverable." ) );
1471 - (void) _Cancel: (NSWindow *) sheet
1472 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1474 if( returnCode == NSAlertAlternateReturn )
1477 // [fPauseButton setEnabled: NO];
1478 // [fRipButton setEnabled: NO];
1479 pauseButtonEnabled = NO;
1480 startButtonEnabled = NO;
1481 /*set the fEncodeState State */
1486 - (IBAction) Pause: (id) sender
1488 // [fPauseButton setEnabled: NO];
1489 // [fRipButton setEnabled: NO];
1491 // if( [[fPauseButton title] isEqualToString: _( @"Resume" )] )
1492 pauseButtonEnabled = NO;
1493 startButtonEnabled = NO;
1497 hb_resume( fHandle );
1501 hb_pause( fHandle );
1505 - (IBAction) TitlePopUpChanged: (id) sender
1507 hb_list_t * list = hb_get_titles( fHandle );
1508 hb_title_t * title = (hb_title_t*)
1509 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1512 /* If Auto Naming is on. We create an output filename of dvd name - title number */
1513 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
1515 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1516 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
1517 [NSString stringWithUTF8String: title->name],
1518 [fSrcTitlePopUp indexOfSelectedItem] + 1,
1519 [[fDstFile2Field stringValue] pathExtension]]];
1522 /* Update chapter popups */
1523 [fSrcChapterStartPopUp removeAllItems];
1524 [fSrcChapterEndPopUp removeAllItems];
1525 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
1527 [fSrcChapterStartPopUp addItemWithTitle: [NSString
1528 stringWithFormat: @"%d", i + 1]];
1529 [fSrcChapterEndPopUp addItemWithTitle: [NSString
1530 stringWithFormat: @"%d", i + 1]];
1532 [fSrcChapterStartPopUp selectItemAtIndex: 0];
1533 [fSrcChapterEndPopUp selectItemAtIndex:
1534 hb_list_count( title->list_chapter ) - 1];
1535 [self ChapterPopUpChanged: NULL];
1537 /* Start Get and set the initial pic size for display */
1538 hb_job_t * job = title->job;
1540 /* Turn Deinterlace on/off depending on the preference */
1541 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
1543 job->deinterlace = 1;
1547 job->deinterlace = 0;
1550 /* Pixel Ratio Setting */
1551 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
1554 job->pixel_ratio = 1 ;
1558 job->pixel_ratio = 0 ;
1560 /*Set Source Size Fields Here */
1561 [fPicSrcWidth setStringValue: [NSString stringWithFormat:
1562 @"%d", fTitle->width]];
1563 [fPicSrcHeight setStringValue: [NSString stringWithFormat:
1564 @"%d", fTitle->height]];
1565 /* We get the originial output picture width and height and put them
1566 in variables for use with some presets later on */
1567 PicOrigOutputWidth = job->width;
1568 PicOrigOutputHeight = job->height;
1569 /* we test getting the max output value for pic sizing here to be used later*/
1570 [fPicSettingWidth setStringValue: [NSString stringWithFormat:
1571 @"%d", PicOrigOutputWidth]];
1572 [fPicSettingHeight setStringValue: [NSString stringWithFormat:
1573 @"%d", PicOrigOutputHeight]];
1574 /* we run the picture size values through
1575 CalculatePictureSizing to get all picture size
1577 [self CalculatePictureSizing: NULL];
1578 /* Run Through EncoderPopUpChanged to see if there
1579 needs to be any pic value modifications based on encoder settings */
1580 //[self EncoderPopUpChanged: NULL];
1581 /* END Get and set the initial pic size for display */
1583 /* Update subtitle popups */
1584 hb_subtitle_t * subtitle;
1585 [fSubPopUp removeAllItems];
1586 [fSubPopUp addItemWithTitle: @"None"];
1587 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
1589 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
1591 /* We cannot use NSPopUpButton's addItemWithTitle because
1592 it checks for duplicate entries */
1593 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
1594 subtitle->lang] action: NULL keyEquivalent: @""];
1596 [fSubPopUp selectItemAtIndex: 0];
1598 /* Update chapter table */
1599 [fChapterTitlesDelegate resetWithTitle:title];
1600 [fChapterTable reloadData];
1602 /* Update audio popups */
1603 [self AddAllAudioTracksToPopUp: fAudLang1PopUp];
1604 [self AddAllAudioTracksToPopUp: fAudLang2PopUp];
1605 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
1606 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
1607 [self SelectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
1608 [self SelectAudioTrackInPopUp: fAudLang2PopUp searchPrefixString: NULL selectIndexIfNotFound: 0];
1610 /* changing the title may have changed the audio channels on offer, */
1611 /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1612 [self AudioTrackPopUpChanged: fAudLang1PopUp];
1613 [self AudioTrackPopUpChanged: fAudLang2PopUp];
1617 - (IBAction) ChapterPopUpChanged: (id) sender
1620 /* If start chapter popup is greater than end chapter popup,
1621 we set the end chapter popup to the same as start chapter popup */
1622 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
1624 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
1629 hb_list_t * list = hb_get_titles( fHandle );
1630 hb_title_t * title = (hb_title_t *)
1631 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1633 hb_chapter_t * chapter;
1634 int64_t duration = 0;
1635 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
1636 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
1638 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
1639 duration += chapter->duration;
1642 duration /= 90000; /* pts -> seconds */
1643 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
1644 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
1647 [self CalculateBitrate: sender];
1650 - (IBAction) FormatPopUpChanged: (id) sender
1652 NSString * string = [fDstFile2Field stringValue];
1653 int format = [fDstFormatPopUp indexOfSelectedItem];
1655 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
1656 [fDstMpgLargeFileCheck setHidden: YES];
1657 /* Update the codecs popup */
1658 [fDstCodecsPopUp removeAllItems];
1662 /*Get Default MP4 File Extension*/
1663 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
1671 [fDstCodecsPopUp addItemWithTitle:
1672 _( @"MPEG-4 Video / AAC Audio" )];
1673 [fDstCodecsPopUp addItemWithTitle:
1674 _( @"AVC/H.264 Video / AAC Audio" )];
1675 /* We enable the create chapters checkbox here since we are .mp4*/
1676 [fCreateChapterMarkers setEnabled: YES];
1677 /* We show the Large File (64 bit formatting) checkbox since we are .mp4
1678 if we have enabled the option in the global preferences*/
1679 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AllowLargeFiles"] > 0)
1681 [fDstMpgLargeFileCheck setHidden: NO];
1685 /* if not enable in global preferences, we additionaly sanity check that the
1686 hidden checkbox is set to off. */
1687 [fDstMpgLargeFileCheck setState: NSOffState];
1692 [fDstCodecsPopUp addItemWithTitle:
1693 _( @"MPEG-4 Video / MP3 Audio" )];
1694 [fDstCodecsPopUp addItemWithTitle:
1695 _( @"MPEG-4 Video / AC-3 Audio" )];
1696 [fDstCodecsPopUp addItemWithTitle:
1697 _( @"AVC/H.264 Video / MP3 Audio" )];
1698 [fDstCodecsPopUp addItemWithTitle:
1699 _( @"AVC/H.264 Video / AC-3 Audio" )];
1700 /* We disable the create chapters checkbox here since we are NOT .mp4
1701 and make sure it is unchecked*/
1702 [fCreateChapterMarkers setEnabled: NO];
1703 [fCreateChapterMarkers setState: NSOffState];
1707 [fDstCodecsPopUp addItemWithTitle:
1708 _( @"MPEG-4 Video / Vorbis Audio" )];
1709 [fDstCodecsPopUp addItemWithTitle:
1710 _( @"MPEG-4 Video / MP3 Audio" )];
1711 /* We disable the create chapters checkbox here since we are NOT .mp4
1712 and make sure it is unchecked*/
1713 [fCreateChapterMarkers setEnabled: NO];
1714 [fCreateChapterMarkers setState: NSOffState];
1718 [fDstCodecsPopUp addItemWithTitle:
1719 _( @"MPEG-4 Video / AAC Audio" )];
1720 [fDstCodecsPopUp addItemWithTitle:
1721 _( @"MPEG-4 Video / AC-3 Audio" )];
1722 [fDstCodecsPopUp addItemWithTitle:
1723 _( @"MPEG-4 Video / MP3 Audio" )];
1724 [fDstCodecsPopUp addItemWithTitle:
1725 _( @"MPEG-4 Video / Vorbis Audio" )];
1727 [fDstCodecsPopUp addItemWithTitle:
1728 _( @"AVC/H.264 Video / AAC Audio" )];
1729 [fDstCodecsPopUp addItemWithTitle:
1730 _( @"AVC/H.264 Video / AC-3 Audio" )];
1731 [fDstCodecsPopUp addItemWithTitle:
1732 _( @"AVC/H.264 Video / MP3 Audio" )];
1733 [fDstCodecsPopUp addItemWithTitle:
1734 _( @"AVC/H.264 Video / Vorbis Audio" )];
1735 /* We disable the create chapters checkbox here since we are NOT .mp4
1736 and make sure it is unchecked*/
1737 [fCreateChapterMarkers setEnabled: YES];
1740 [self CodecsPopUpChanged: NULL];
1742 /* Add/replace to the correct extension */
1743 if( [string characterAtIndex: [string length] - 4] == '.' )
1745 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1746 @"%@.%s", [string substringToIndex: [string length] - 4],
1751 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1752 @"%@.%s", string, ext]];
1755 /* changing the format may mean that we can / can't offer mono or 6ch, */
1756 /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1757 [self AudioTrackPopUpChanged: fAudLang1PopUp];
1758 [self AudioTrackPopUpChanged: fAudLang2PopUp];
1759 /* We call the method to properly enable/disable turbo 2 pass */
1760 [self TwoPassCheckboxChanged: sender];
1761 /* We call method method to change UI to reflect whether a preset is used or not*/
1762 [self CustomSettingUsed: sender];
1766 - (IBAction) CodecsPopUpChanged: (id) sender
1768 int format = [fDstFormatPopUp indexOfSelectedItem];
1769 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1770 [fX264optView setHidden: YES];
1771 [fX264optViewTitleLabel setStringValue: @"Only Used With The x264 (H.264) Codec"];
1774 /* Update the encoder popup*/
1775 if( ( FormatSettings[format][codecs] & HB_VCODEC_X264 ) )
1777 /* MPEG-4 -> H.264 */
1778 [fVidEncoderPopUp removeAllItems];
1779 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 Main)"];
1780 [fVidEncoderPopUp addItemWithTitle: @"x264 (h.264 iPod)"];
1781 [fVidEncoderPopUp selectItemAtIndex: 0];
1782 [fX264optView setHidden: NO];
1783 [fX264optViewTitleLabel setStringValue: @""];
1788 else if( ( FormatSettings[format][codecs] & HB_VCODEC_FFMPEG ) )
1790 /* H.264 -> MPEG-4 */
1791 [fVidEncoderPopUp removeAllItems];
1792 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
1793 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
1794 [fVidEncoderPopUp selectItemAtIndex: 0];
1798 if( FormatSettings[format][codecs] & HB_ACODEC_AC3 )
1800 /* AC-3 pass-through: disable samplerate and bitrate */
1801 [fAudRatePopUp setEnabled: NO];
1802 [fAudBitratePopUp setEnabled: NO];
1806 [fAudRatePopUp setEnabled: YES];
1807 [fAudBitratePopUp setEnabled: YES];
1809 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
1810 /* so call AudioTrackPopUpChanged for both audio tracks to update the mixdown popups */
1811 [self AudioTrackPopUpChanged: fAudLang1PopUp];
1812 [self AudioTrackPopUpChanged: fAudLang2PopUp];
1814 [self CalculateBitrate: sender];
1815 [self TwoPassCheckboxChanged: sender];
1818 - (IBAction) EncoderPopUpChanged: (id) sender
1821 /* Check to see if we need to modify the job pic values based on x264 (iPod) encoder selection */
1822 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fDstCodecsPopUp indexOfSelectedItem] == 1 && [fVidEncoderPopUp indexOfSelectedItem] == 1)
1824 hb_job_t * job = fTitle->job;
1825 job->pixel_ratio = 0 ;
1827 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPicSizeAutoiPod"] > 0)
1830 if (job->width > 640)
1834 job->keep_ratio = 1;
1835 hb_fix_aspect( job, HB_KEEP_WIDTH );
1838 /* Make sure the 64bit formatting checkbox is off */
1839 [fDstMpgLargeFileCheck setState: NSOffState];
1842 [self CalculatePictureSizing: sender];
1843 [self TwoPassCheckboxChanged: sender];
1846 - (IBAction) TwoPassCheckboxChanged: (id) sender
1848 /* check to see if x264 is chosen */
1849 if([fDstFormatPopUp indexOfSelectedItem] == 0 && [fDstCodecsPopUp indexOfSelectedItem] == 1)
1851 if( [fVidTwoPassCheck state] == NSOnState)
1853 [fVidTurboPassCheck setHidden: NO];
1857 [fVidTurboPassCheck setHidden: YES];
1858 [fVidTurboPassCheck setState: NSOffState];
1860 /* Make sure Two Pass is checked if Turbo is checked */
1861 if( [fVidTurboPassCheck state] == NSOnState)
1863 [fVidTwoPassCheck setState: NSOnState];
1868 [fVidTurboPassCheck setHidden: YES];
1869 [fVidTurboPassCheck setState: NSOffState];
1872 /* We call method method to change UI to reflect whether a preset is used or not*/
1873 [self CustomSettingUsed: sender];
1876 - (IBAction) SetEnabledStateOfAudioMixdownControls: (id) sender
1879 /* enable/disable the mixdown text and popupbutton for audio track 1 */
1880 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
1881 [fAudTrack1MixLabel setTextColor: ([fAudLang1PopUp indexOfSelectedItem] == 0) ?
1882 [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
1884 /* enable/disable the mixdown text and popupbutton for audio track 2 */
1885 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
1886 [fAudTrack2MixLabel setTextColor: ([fAudLang2PopUp indexOfSelectedItem] == 0) ?
1887 [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
1891 - (IBAction) AddAllAudioTracksToPopUp: (id) sender
1894 hb_list_t * list = hb_get_titles( fHandle );
1895 hb_title_t * title = (hb_title_t*)
1896 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
1900 [sender removeAllItems];
1901 [sender addItemWithTitle: _( @"None" )];
1902 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
1904 audio = (hb_audio_t *) hb_list_item( title->list_audio, i );
1905 [[sender menu] addItemWithTitle:
1906 [NSString stringWithCString: audio->lang]
1907 action: NULL keyEquivalent: @""];
1909 [sender selectItemAtIndex: 0];
1913 - (IBAction) SelectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
1916 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
1917 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
1918 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
1919 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
1921 if (searchPrefixString != NULL)
1924 for( int i = 0; i < [sender numberOfItems]; i++ )
1926 /* Try to find the desired search string */
1927 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
1929 [sender selectItemAtIndex: i];
1933 /* couldn't find the string, so select the requested "search string not found" item */
1934 /* index of 0 means select the "none" item */
1935 /* index of 1 means select the first audio track */
1936 [sender selectItemAtIndex: selectIndexIfNotFound];
1940 /* if no search string is provided, then select the selectIndexIfNotFound item */
1941 [sender selectItemAtIndex: selectIndexIfNotFound];
1946 - (IBAction) AudioTrackPopUpChanged: (id) sender
1948 /* utility function to call AudioTrackPopUpChanged without passing in a mixdown-to-use */
1949 [self AudioTrackPopUpChanged: sender mixdownToUse: 0];
1952 - (IBAction) AudioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
1955 /* make sure we have a selected title before continuing */
1956 if (fTitle == NULL) return;
1958 /* find out if audio track 1 or 2 was changed - this is passed to us in the tag of the sender */
1959 /* the sender will have been either fAudLang1PopUp (tag = 0) or fAudLang2PopUp (tag = 1) */
1960 int thisAudio = [sender tag];
1962 /* get the index of the selected audio */
1963 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
1965 /* Handbrake can't currently cope with ripping the same source track twice */
1966 /* So, if this audio is also selected in the other audio track popup, set that popup's selection to "none" */
1967 /* get a reference to the two audio track popups */
1968 NSPopUpButton * thisAudioPopUp = (thisAudio == 1 ? fAudLang2PopUp : fAudLang1PopUp);
1969 NSPopUpButton * otherAudioPopUp = (thisAudio == 1 ? fAudLang1PopUp : fAudLang2PopUp);
1970 /* if the same track is selected in the other audio popup, then select "none" in that popup */
1971 /* unless, of course, both are selected as "none!" */
1972 if ([thisAudioPopUp indexOfSelectedItem] != 0 && [thisAudioPopUp indexOfSelectedItem] == [otherAudioPopUp indexOfSelectedItem]) {
1973 [otherAudioPopUp selectItemAtIndex: 0];
1974 [self AudioTrackPopUpChanged: otherAudioPopUp];
1977 /* pointer for the hb_audio_s struct we will use later on */
1980 /* find out what the currently-selected output audio codec is */
1981 int format = [fDstFormatPopUp indexOfSelectedItem];
1982 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
1983 int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
1985 /* pointer to this track's mixdown NSPopUpButton */
1986 NSTextField * mixdownTextField;
1987 NSPopUpButton * mixdownPopUp;
1989 /* find our mixdown NSTextField and NSPopUpButton */
1992 mixdownTextField = fAudTrack1MixLabel;
1993 mixdownPopUp = fAudTrack1MixPopUp;
1997 mixdownTextField = fAudTrack2MixLabel;
1998 mixdownPopUp = fAudTrack2MixPopUp;
2001 /* delete the previous audio mixdown options */
2002 [mixdownPopUp removeAllItems];
2004 /* check if the audio mixdown controls need their enabled state changing */
2005 [self SetEnabledStateOfAudioMixdownControls: NULL];
2007 if (thisAudioIndex != -1)
2011 audio = (hb_audio_t *) hb_list_item( fTitle->list_audio, thisAudioIndex );
2015 /* find out if our selected output audio codec supports mono and / or 6ch */
2016 /* we also check for an input codec of AC3 or DCA,
2017 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
2018 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
2019 but this may change in the future, so they are separated for flexibility */
2020 int audioCodecsSupportMono = ((audio->codec == HB_ACODEC_AC3 ||
2021 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2022 int audioCodecsSupport6Ch = ((audio->codec == HB_ACODEC_AC3 ||
2023 audio->codec == HB_ACODEC_DCA) && acodec == HB_ACODEC_FAAC);
2025 /* check for AC-3 passthru */
2026 if (audio->codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
2028 [[mixdownPopUp menu] addItemWithTitle:
2029 [NSString stringWithCString: "AC3 Passthru"]
2030 action: NULL keyEquivalent: @""];
2035 /* add the appropriate audio mixdown menuitems to the popupbutton */
2036 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
2037 so that we can reference the mixdown later */
2039 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
2040 int minMixdownUsed = 0;
2041 int maxMixdownUsed = 0;
2043 /* get the input channel layout without any lfe channels */
2044 int layout = audio->input_channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2046 /* do we want to add a mono option? */
2047 if (audioCodecsSupportMono == 1) {
2048 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2049 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
2050 action: NULL keyEquivalent: @""];
2051 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
2052 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
2053 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
2056 /* do we want to add a stereo option? */
2057 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
2058 /* also offer stereo if we have a stereo-or-better source */
2059 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO) {
2060 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2061 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
2062 action: NULL keyEquivalent: @""];
2063 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
2064 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
2065 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
2068 /* do we want to add a dolby surround (DPL1) option? */
2069 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY) {
2070 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2071 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
2072 action: NULL keyEquivalent: @""];
2073 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
2074 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
2075 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
2078 /* do we want to add a dolby pro logic 2 (DPL2) option? */
2079 if (layout == HB_INPUT_CH_LAYOUT_3F2R) {
2080 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2081 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
2082 action: NULL keyEquivalent: @""];
2083 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
2084 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
2085 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
2088 /* do we want to add a 6-channel discrete option? */
2089 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->input_channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE)) {
2090 id<NSMenuItem> menuItem = [[mixdownPopUp menu] addItemWithTitle:
2091 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
2092 action: NULL keyEquivalent: @""];
2093 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
2094 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
2095 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
2098 /* auto-select the best mixdown based on our saved mixdown preference */
2100 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
2101 /* ultimately this should be a prefs option */
2104 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
2105 if (mixdownToUse > 0)
2107 useMixdown = mixdownToUse;
2111 useMixdown = HB_AMIXDOWN_DOLBYPLII;
2114 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
2115 if (useMixdown > maxMixdownUsed) useMixdown = maxMixdownUsed;
2117 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
2118 if (useMixdown < minMixdownUsed) useMixdown = minMixdownUsed;
2120 /* select the (possibly-amended) preferred mixdown */
2121 [mixdownPopUp selectItemWithTag: useMixdown];
2123 /* lets call the AudioTrackMixdownChanged method here to determine appropriate bitrates, etc. */
2124 [self AudioTrackMixdownChanged: NULL];
2131 /* see if the new audio track choice will change the bitrate we need */
2132 [self CalculateBitrate: sender];
2135 - (IBAction) AudioTrackMixdownChanged: (id) sender
2138 /* find out what the currently-selected output audio codec is */
2139 int format = [fDstFormatPopUp indexOfSelectedItem];
2140 int codecs = [fDstCodecsPopUp indexOfSelectedItem];
2141 int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
2143 /* storage variable for the min and max bitrate allowed for this codec */
2149 case HB_ACODEC_FAAC:
2150 /* check if we have a 6ch discrete conversion in either audio track */
2151 if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2153 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
2155 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
2161 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
2163 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
2164 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
2169 case HB_ACODEC_LAME:
2170 /* Lame is happy using our min bitrate of 32 kbps */
2172 /* Lame won't encode if the bitrate is higher than 320 kbps */
2176 case HB_ACODEC_VORBIS:
2177 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
2179 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
2184 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
2190 [fAudBitratePopUp removeAllItems];
2192 for( int i = 0; i < hb_audio_bitrates_count; i++ )
2194 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
2196 /* add a new menuitem for this bitrate */
2197 id<NSMenuItem> menuItem = [[fAudBitratePopUp menu] addItemWithTitle:
2198 [NSString stringWithCString: hb_audio_bitrates[i].string]
2199 action: NULL keyEquivalent: @""];
2200 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
2201 [menuItem setTag: hb_audio_bitrates[i].rate];
2205 /* select the default bitrate (but use 384 for 6-ch AAC) */
2206 if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH || [[fAudTrack2MixPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
2208 [fAudBitratePopUp selectItemWithTag: 384];
2212 [fAudBitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
2216 /* lets set the picture size back to the max from right after title scan
2217 Lets use an IBAction here as down the road we could always use a checkbox
2218 in the gui to easily take the user back to max. Remember, the compiler
2219 resolves IBActions down to -(void) during compile anyway */
2220 - (IBAction) RevertPictureSizeToMax: (id) sender
2222 hb_job_t * job = fTitle->job;
2223 /* We use the output picture width and height
2224 as calculated from libhb right after title is set
2225 in TitlePopUpChanged */
2226 job->width = PicOrigOutputWidth;
2227 job->height = PicOrigOutputHeight;
2231 [self CalculatePictureSizing: sender];
2232 /* We call method method to change UI to reflect whether a preset is used or not*/
2233 [self CustomSettingUsed: sender];
2237 /* Get and Display Current Pic Settings in main window */
2238 - (IBAction) CalculatePictureSizing: (id) sender
2242 [fPicSettingWidth setStringValue: [NSString stringWithFormat:
2243 @"%d", fTitle->job->width]];
2244 [fPicSettingHeight setStringValue: [NSString stringWithFormat:
2245 @"%d", fTitle->job->height]];
2246 [fPicSettingARkeep setStringValue: [NSString stringWithFormat:
2247 @"%d", fTitle->job->keep_ratio]];
2248 [fPicSettingDeinterlace setStringValue: [NSString stringWithFormat:
2249 @"%d", fTitle->job->deinterlace]];
2250 [fPicSettingPAR setStringValue: [NSString stringWithFormat:
2251 @"%d", fTitle->job->pixel_ratio]];
2253 if (fTitle->job->pixel_ratio == 1)
2255 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
2256 int arpwidth = fTitle->job->pixel_aspect_width;
2257 int arpheight = fTitle->job->pixel_aspect_height;
2258 int displayparwidth = titlewidth * arpwidth / arpheight;
2259 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
2260 [fPicSettingWidth setStringValue: [NSString stringWithFormat:
2261 @"%d", titlewidth]];
2262 [fPicSettingHeight setStringValue: [NSString stringWithFormat:
2263 @"%d", displayparheight]];
2264 [fPicLabelPAROutp setStringValue: @"Anamorphic Output:"];
2265 [fPicLabelPAROutputX setStringValue: @"x"];
2266 [fPicSettingPARWidth setStringValue: [NSString stringWithFormat:
2267 @"%d", displayparwidth]];
2268 [fPicSettingPARHeight setStringValue: [NSString stringWithFormat:
2269 @"%d", displayparheight]];
2271 fTitle->job->keep_ratio = 0;
2275 [fPicLabelPAROutp setStringValue: @""];
2276 [fPicLabelPAROutputX setStringValue: @""];
2277 [fPicSettingPARWidth setStringValue: @""];
2278 [fPicSettingPARHeight setStringValue: @""];
2281 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
2282 if (fTitle->job->keep_ratio > 0)
2284 [fPicSettingARkeepDsply setStringValue: @"On"];
2288 [fPicSettingARkeepDsply setStringValue: @"Off"];
2290 if (fTitle->job->deinterlace > 0)
2292 [fPicSettingDeinterlaceDsply setStringValue: @"On"];
2296 [fPicSettingDeinterlaceDsply setStringValue: @"Off"];
2298 if (fTitle->job->pixel_ratio > 0)
2300 [fPicSettingPARDsply setStringValue: @"On"];
2304 [fPicSettingPARDsply setStringValue: @"Off"];
2306 /* Set the display field for crop as per boolean */
2307 if ([[fPicSettingAutoCrop stringValue] isEqualToString: @"0"])
2309 [fPicSettingAutoCropDsply setStringValue: @"Custom"];
2313 [fPicSettingAutoCropDsply setStringValue: @"Auto"];
2316 /* below will trigger the preset, if selected, to be
2317 changed to "Custom". Lets comment out for now until
2318 we figure out a way to determine if the picture values
2319 changed modify the preset values */
2320 //[self CustomSettingUsed: sender];
2323 - (IBAction) CalculateBitrate: (id) sender
2325 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 )
2330 hb_list_t * list = hb_get_titles( fHandle );
2331 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2332 [fSrcTitlePopUp indexOfSelectedItem] );
2333 hb_job_t * job = title->job;
2337 [fVidBitrateField setIntValue: hb_calc_bitrate( job,
2338 [fVidTargetSizeField intValue] )];
2343 /* Method to determine if we should change the UI
2344 To reflect whether or not a Preset is being used or if
2345 the user is using "Custom" settings by determining the sender*/
2346 - (IBAction) CustomSettingUsed: (id) sender
2348 if ([sender stringValue] != NULL)
2350 /* Deselect the currently selected Preset if there is one*/
2351 [tableView deselectRow:[tableView selectedRow]];
2352 /* Change UI to show "Custom" settings are being used */
2353 [fPresetSelectedDisplay setStringValue: @"Custom"];
2355 curUserPresetChosenNum = nil;
2362 - (IBAction) X264AdvancedOptionsSet: (id) sender
2364 /*Set opt widget values here*/
2366 /*B-Frames fX264optBframesPopUp*/
2368 [fX264optBframesPopUp removeAllItems];
2369 [fX264optBframesPopUp addItemWithTitle:@"Default (0)"];
2372 [fX264optBframesPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2375 /*Reference Frames fX264optRefPopUp*/
2376 [fX264optRefPopUp removeAllItems];
2377 [fX264optRefPopUp addItemWithTitle:@"Default (1)"];
2380 [fX264optRefPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2383 /*No Fast P-Skip fX264optNfpskipSwitch BOOLEAN*/
2384 [fX264optNfpskipSwitch setState:0];
2386 /*No Dict Decimate fX264optNodctdcmtSwitch BOOLEAN*/
2387 [fX264optNodctdcmtSwitch setState:0];
2389 /*Sub Me fX264optSubmePopUp*/
2390 [fX264optSubmePopUp removeAllItems];
2391 [fX264optSubmePopUp addItemWithTitle:@"Default (4)"];
2394 [fX264optSubmePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2397 /*Trellis fX264optTrellisPopUp*/
2398 [fX264optTrellisPopUp removeAllItems];
2399 [fX264optTrellisPopUp addItemWithTitle:@"Default (0)"];
2402 [fX264optTrellisPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2405 /*Mixed-references fX264optMixedRefsSwitch BOOLEAN*/
2406 [fX264optMixedRefsSwitch setState:0];
2408 /*Motion Estimation fX264optMotionEstPopUp*/
2409 [fX264optMotionEstPopUp removeAllItems];
2410 [fX264optMotionEstPopUp addItemWithTitle:@"Default (Hexagon)"];
2411 [fX264optMotionEstPopUp addItemWithTitle:@"Diamond"];
2412 [fX264optMotionEstPopUp addItemWithTitle:@"Hexagon"];
2413 [fX264optMotionEstPopUp addItemWithTitle:@"Uneven Multi-Hexagon"];
2414 [fX264optMotionEstPopUp addItemWithTitle:@"Exhaustive"];
2416 /*Motion Estimation range fX264optMERangePopUp*/
2417 [fX264optMERangePopUp removeAllItems];
2418 [fX264optMERangePopUp addItemWithTitle:@"Default (16)"];
2421 [fX264optMERangePopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2424 /*Weighted B-Frame Prediction fX264optWeightBSwitch BOOLEAN*/
2425 [fX264optWeightBSwitch setState:0];
2427 /*B-Frame Rate Distortion Optimization fX264optBRDOSwitch BOOLEAN*/
2428 [fX264optBRDOSwitch setState:0];
2430 /*B-frame Pyramids fX264optBPyramidSwitch BOOLEAN*/
2431 [fX264optBPyramidSwitch setState:0];
2433 /*Bidirectional Motion Estimation Refinement fX264optBiMESwitch BOOLEAN*/
2434 [fX264optBiMESwitch setState:0];
2436 /*Direct B-Frame Prediction Mode fX264optDirectPredPopUp*/
2437 [fX264optDirectPredPopUp removeAllItems];
2438 [fX264optDirectPredPopUp addItemWithTitle:@"Default (Spatial)"];
2439 [fX264optDirectPredPopUp addItemWithTitle:@"None"];
2440 [fX264optDirectPredPopUp addItemWithTitle:@"Spatial"];
2441 [fX264optDirectPredPopUp addItemWithTitle:@"Temporal"];
2442 [fX264optDirectPredPopUp addItemWithTitle:@"Automatic"];
2445 [fX264optAlphaDeblockPopUp removeAllItems];
2446 [fX264optAlphaDeblockPopUp addItemWithTitle:@"Default (0)"];
2449 [fX264optAlphaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2453 [fX264optBetaDeblockPopUp removeAllItems];
2454 [fX264optBetaDeblockPopUp addItemWithTitle:@"Default (0)"];
2457 [fX264optBetaDeblockPopUp addItemWithTitle:[NSString stringWithFormat:@"%d",i]];
2460 /* Analysis fX264optAnalysePopUp */
2461 [fX264optAnalysePopUp removeAllItems];
2462 [fX264optAnalysePopUp addItemWithTitle:@"Default (some)"]; /* 0=default */
2463 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"None"]]; /* 1=none */
2464 [fX264optAnalysePopUp addItemWithTitle:[NSString stringWithFormat:@"All"]]; /* 2=all */
2466 /* 8x8 DCT fX264op8x8dctSwitch */
2467 [fX264opt8x8dctSwitch setState:0];
2469 /* CABAC fX264opCabacSwitch */
2470 [fX264optCabacSwitch setState:1];
2472 /* Standardize the option string */
2473 [self X264AdvancedOptionsStandardizeOptString: NULL];
2474 /* Set Current GUI Settings based on newly standardized string */
2475 [self X264AdvancedOptionsSetCurrentSettings: NULL];
2478 - (IBAction) X264AdvancedOptionsStandardizeOptString: (id) sender
2480 /* Set widgets depending on the opt string in field */
2481 NSString * thisOpt; // The separated option such as "bframes=3"
2482 NSString * optName = @""; // The option name such as "bframes"
2483 NSString * optValue = @"";// The option value such as "3"
2484 NSString * changedOptString = @"";
2485 NSArray *currentOptsArray;
2487 /*First, we get an opt string to process */
2488 NSString *currentOptString = [fDisplayX264Options stringValue];
2490 /*verify there is an opt string to process */
2491 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
2492 if (currentOptRange.location != NSNotFound)
2494 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
2495 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
2497 /*iterate through the array and get <opts> and <values*/
2498 //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
2500 int currentOptsArrayCount = [currentOptsArray count];
2501 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
2503 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
2505 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
2506 if (splitOptRange.location != NSNotFound)
2508 optName = [thisOpt substringToIndex:splitOptRange.location];
2509 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
2511 /* Standardize the names here depending on whats in the string */
2512 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
2513 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,optValue];
2515 else // No value given so we use a default of "1"
2518 /* Standardize the names here depending on whats in the string */
2519 optName = [self X264AdvancedOptionsStandardizeOptNames:optName];
2520 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
2523 /* Construct New String for opts here */
2524 if ([thisOpt isEqualToString:@""])
2526 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
2530 if ([changedOptString isEqualToString:@""])
2532 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
2536 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
2542 /* Change the option string to reflect the new standardized option string */
2543 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
2546 - (NSString *) X264AdvancedOptionsStandardizeOptNames:(NSString *) cleanOptNameString
2548 if ([cleanOptNameString isEqualToString:@"ref"] || [cleanOptNameString isEqualToString:@"frameref"])
2550 cleanOptNameString = @"ref";
2553 /*No Fast PSkip nofast_pskip*/
2554 if ([cleanOptNameString isEqualToString:@"no-fast-pskip"] || [cleanOptNameString isEqualToString:@"no_fast_pskip"] || [cleanOptNameString isEqualToString:@"nofast_pskip"])
2556 cleanOptNameString = @"no-fast-pskip";
2559 /*No Dict Decimate*/
2560 if ([cleanOptNameString isEqualToString:@"no-dct-decimate"] || [cleanOptNameString isEqualToString:@"no_dct_decimate"] || [cleanOptNameString isEqualToString:@"nodct_decimate"])
2562 cleanOptNameString = @"no-dct-decimate";
2566 if ([cleanOptNameString isEqualToString:@"subme"])
2568 cleanOptNameString = @"subq";
2572 if ([cleanOptNameString isEqualToString:@"me-range"] || [cleanOptNameString isEqualToString:@"me_range"])
2573 cleanOptNameString = @"merange";
2576 if ([cleanOptNameString isEqualToString:@"weight-b"] || [cleanOptNameString isEqualToString:@"weight_b"])
2578 cleanOptNameString = @"weightb";
2582 if ([cleanOptNameString isEqualToString:@"b-rdo"] || [cleanOptNameString isEqualToString:@"b_rdo"])
2584 cleanOptNameString = @"brdo";
2588 if ([cleanOptNameString isEqualToString:@"b_pyramid"])
2590 cleanOptNameString = @"b-pyramid";
2593 /*Direct Prediction*/
2594 if ([cleanOptNameString isEqualToString:@"direct-pred"] || [cleanOptNameString isEqualToString:@"direct_pred"])
2596 cleanOptNameString = @"direct";
2600 if ([cleanOptNameString isEqualToString:@"filter"])
2602 cleanOptNameString = @"deblock";
2606 if ([cleanOptNameString isEqualToString:@"partitions"])
2608 cleanOptNameString = @"analyse";
2612 return cleanOptNameString;
2615 - (IBAction) X264AdvancedOptionsSetCurrentSettings: (id) sender
2617 /* Set widgets depending on the opt string in field */
2618 NSString * thisOpt; // The separated option such as "bframes=3"
2619 NSString * optName = @""; // The option name such as "bframes"
2620 NSString * optValue = @"";// The option value such as "3"
2621 NSArray *currentOptsArray;
2623 /*First, we get an opt string to process */
2624 //NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
2625 NSString *currentOptString = [fDisplayX264Options stringValue];
2627 /*verify there is an opt string to process */
2628 NSRange currentOptRange = [currentOptString rangeOfString:@"="];
2629 if (currentOptRange.location != NSNotFound)
2631 /* lets clean the opt string here to standardize any names*/
2632 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
2633 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
2635 /*iterate through the array and get <opts> and <values*/
2636 //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];
2638 int currentOptsArrayCount = [currentOptsArray count];
2640 /*iterate through the array and get <opts> and <values*/
2641 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
2643 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
2644 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
2646 if (splitOptRange.location != NSNotFound)
2648 optName = [thisOpt substringToIndex:splitOptRange.location];
2649 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
2651 /*Run through the available widgets for x264 opts and set them, as you add widgets,
2652 they need to be added here. This should be moved to its own method probably*/
2654 /*bframes NSPopUpButton*/
2655 if ([optName isEqualToString:@"bframes"])
2657 [fX264optBframesPopUp selectItemAtIndex:[optValue intValue]+1];
2659 /*ref NSPopUpButton*/
2660 if ([optName isEqualToString:@"ref"])
2662 [fX264optRefPopUp selectItemAtIndex:[optValue intValue]+1];
2664 /*No Fast PSkip NSPopUpButton*/
2665 if ([optName isEqualToString:@"no-fast-pskip"])
2667 [fX264optNfpskipSwitch setState:[optValue intValue]];
2669 /*No Dict Decimate NSPopUpButton*/
2670 if ([optName isEqualToString:@"no-dct-decimate"])
2672 [fX264optNodctdcmtSwitch setState:[optValue intValue]];
2674 /*Sub Me NSPopUpButton*/
2675 if ([optName isEqualToString:@"subq"])
2677 [fX264optSubmePopUp selectItemAtIndex:[optValue intValue]+1];
2679 /*Trellis NSPopUpButton*/
2680 if ([optName isEqualToString:@"trellis"])
2682 [fX264optTrellisPopUp selectItemAtIndex:[optValue intValue]+1];
2684 /*Mixed Refs NSButton*/
2685 if ([optName isEqualToString:@"mixed-refs"])
2687 [fX264optMixedRefsSwitch setState:[optValue intValue]];
2689 /*Motion Estimation NSPopUpButton*/
2690 if ([optName isEqualToString:@"me"])
2692 if ([optValue isEqualToString:@"dia"])
2693 [fX264optMotionEstPopUp selectItemAtIndex:1];
2694 else if ([optValue isEqualToString:@"hex"])
2695 [fX264optMotionEstPopUp selectItemAtIndex:2];
2696 else if ([optValue isEqualToString:@"umh"])
2697 [fX264optMotionEstPopUp selectItemAtIndex:3];
2698 else if ([optValue isEqualToString:@"esa"])
2699 [fX264optMotionEstPopUp selectItemAtIndex:4];
2701 /*ME Range NSPopUpButton*/
2702 if ([optName isEqualToString:@"merange"])
2704 [fX264optMERangePopUp selectItemAtIndex:[optValue intValue]-3];
2706 /*Weighted B-Frames NSPopUpButton*/
2707 if ([optName isEqualToString:@"weightb"])
2709 [fX264optWeightBSwitch setState:[optValue intValue]];
2711 /*BRDO NSPopUpButton*/
2712 if ([optName isEqualToString:@"brdo"])
2714 [fX264optBRDOSwitch setState:[optValue intValue]];
2716 /*B Pyramid NSPopUpButton*/
2717 if ([optName isEqualToString:@"b-pyramid"])
2719 [fX264optBPyramidSwitch setState:[optValue intValue]];
2721 /*Bidirectional Motion Estimation Refinement NSPopUpButton*/
2722 if ([optName isEqualToString:@"bime"])
2724 [fX264optBiMESwitch setState:[optValue intValue]];
2726 /*Direct B-frame Prediction NSPopUpButton*/
2727 if ([optName isEqualToString:@"direct"])
2729 if ([optValue isEqualToString:@"none"])
2730 [fX264optDirectPredPopUp selectItemAtIndex:1];
2731 else if ([optValue isEqualToString:@"spatial"])
2732 [fX264optDirectPredPopUp selectItemAtIndex:2];
2733 else if ([optValue isEqualToString:@"temporal"])
2734 [fX264optDirectPredPopUp selectItemAtIndex:3];
2735 else if ([optValue isEqualToString:@"auto"])
2736 [fX264optDirectPredPopUp selectItemAtIndex:4];
2738 /*Deblocking NSPopUpButtons*/
2739 if ([optName isEqualToString:@"deblock"])
2741 NSString * alphaDeblock = @"";
2742 NSString * betaDeblock = @"";
2744 NSRange splitDeblock = [optValue rangeOfString:@","];
2745 alphaDeblock = [optValue substringToIndex:splitDeblock.location];
2746 betaDeblock = [optValue substringFromIndex:splitDeblock.location + 1];
2748 if ([alphaDeblock isEqualToString:@"0"] && [betaDeblock isEqualToString:@"0"])
2750 [fX264optAlphaDeblockPopUp selectItemAtIndex:0];
2751 [fX264optBetaDeblockPopUp selectItemAtIndex:0];
2755 if (![alphaDeblock isEqualToString:@"0"])
2757 [fX264optAlphaDeblockPopUp selectItemAtIndex:[alphaDeblock intValue]+7];
2761 [fX264optAlphaDeblockPopUp selectItemAtIndex:7];
2764 if (![betaDeblock isEqualToString:@"0"])
2766 [fX264optBetaDeblockPopUp selectItemAtIndex:[betaDeblock intValue]+7];
2770 [fX264optBetaDeblockPopUp selectItemAtIndex:7];
2774 /* Analysis NSPopUpButton */
2775 if ([optName isEqualToString:@"analyse"])
2777 if ([optValue isEqualToString:@"p8x8,b8x8,i8x8,i4x4"])
2779 [fX264optAnalysePopUp selectItemAtIndex:0];
2781 if ([optValue isEqualToString:@"none"])
2783 [fX264optAnalysePopUp selectItemAtIndex:1];
2785 if ([optValue isEqualToString:@"all"])
2787 [fX264optAnalysePopUp selectItemAtIndex:2];
2790 /* 8x8 DCT NSButton */
2791 if ([optName isEqualToString:@"8x8dct"])
2793 [fX264opt8x8dctSwitch setState:[optValue intValue]];
2795 /* CABAC NSButton */
2796 if ([optName isEqualToString:@"cabac"])
2798 [fX264optCabacSwitch setState:[optValue intValue]];
2805 - (IBAction) X264AdvancedOptionsChanged: (id) sender
2807 /*Determine which outlet is being used and set optName to process accordingly */
2808 NSString * optNameToChange = @""; // The option name such as "bframes"
2810 if (sender == fX264optBframesPopUp)
2812 optNameToChange = @"bframes";
2814 if (sender == fX264optRefPopUp)
2816 optNameToChange = @"ref";
2818 if (sender == fX264optNfpskipSwitch)
2820 optNameToChange = @"no-fast-pskip";
2822 if (sender == fX264optNodctdcmtSwitch)
2824 optNameToChange = @"no-dct-decimate";
2826 if (sender == fX264optSubmePopUp)
2828 optNameToChange = @"subq";
2830 if (sender == fX264optTrellisPopUp)
2832 optNameToChange = @"trellis";
2834 if (sender == fX264optMixedRefsSwitch)
2836 optNameToChange = @"mixed-refs";
2838 if (sender == fX264optMotionEstPopUp)
2840 optNameToChange = @"me";
2842 if (sender == fX264optMERangePopUp)
2844 optNameToChange = @"merange";
2846 if (sender == fX264optWeightBSwitch)
2848 optNameToChange = @"weightb";
2850 if (sender == fX264optBRDOSwitch)
2852 optNameToChange = @"brdo";
2854 if (sender == fX264optBPyramidSwitch)
2856 optNameToChange = @"b-pyramid";
2858 if (sender == fX264optBiMESwitch)
2860 optNameToChange = @"bime";
2862 if (sender == fX264optDirectPredPopUp)
2864 optNameToChange = @"direct";
2866 if (sender == fX264optAlphaDeblockPopUp)
2868 optNameToChange = @"deblock";
2870 if (sender == fX264optBetaDeblockPopUp)
2872 optNameToChange = @"deblock";
2874 if (sender == fX264optAnalysePopUp)
2876 optNameToChange = @"analyse";
2878 if (sender == fX264opt8x8dctSwitch)
2880 optNameToChange = @"8x8dct";
2882 if (sender == fX264optCabacSwitch)
2884 optNameToChange = @"cabac";
2887 /* Set widgets depending on the opt string in field */
2888 NSString * thisOpt; // The separated option such as "bframes=3"
2889 NSString * optName = @""; // The option name such as "bframes"
2890 NSString * optValue = @"";// The option value such as "3"
2891 NSArray *currentOptsArray;
2893 /*First, we get an opt string to process */
2894 //EXAMPLE: NSString *currentOptString = @"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";
2895 NSString *currentOptString = [fDisplayX264Options stringValue];
2897 /*verify there is an occurrence of the opt specified by the sender to change */
2898 /*take care of any multi-value opt names here. This is extremely kludgy, but test for functionality
2899 and worry about pretty later */
2901 /*First, we create a pattern to check for ":"optNameToChange"=" to modify the option if the name falls after
2902 the first character of the opt string (hence the ":") */
2903 NSString *checkOptNameToChange = [NSString stringWithFormat:@":%@=",optNameToChange];
2904 NSRange currentOptRange = [currentOptString rangeOfString:checkOptNameToChange];
2905 /*Then we create a pattern to check for "<beginning of line>"optNameToChange"=" to modify the option to
2906 see if the name falls at the beginning of the line, where we would not have the ":" as a pattern to test against*/
2907 NSString *checkOptNameToChangeBeginning = [NSString stringWithFormat:@"%@=",optNameToChange];
2908 NSRange currentOptRangeBeginning = [currentOptString rangeOfString:checkOptNameToChangeBeginning];
2909 if (currentOptRange.location != NSNotFound || currentOptRangeBeginning.location == 0)
2911 /* Create new empty opt string*/
2912 NSString *changedOptString = @"";
2914 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/
2915 currentOptsArray = [currentOptString componentsSeparatedByString:@":"];
2917 /*iterate through the array and get <opts> and <values*/
2919 int currentOptsArrayCount = [currentOptsArray count];
2920 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
2922 thisOpt = [currentOptsArray objectAtIndex:loopcounter];
2923 NSRange splitOptRange = [thisOpt rangeOfString:@"="];
2925 if (splitOptRange.location != NSNotFound)
2927 optName = [thisOpt substringToIndex:splitOptRange.location];
2928 optValue = [thisOpt substringFromIndex:splitOptRange.location + 1];
2930 /*Run through the available widgets for x264 opts and set them, as you add widgets,
2931 they need to be added here. This should be moved to its own method probably*/
2933 /*If the optNameToChange is found, appropriately change the value or delete it if
2934 "Unspecified" is set.*/
2935 if ([optName isEqualToString:optNameToChange])
2937 if ([optNameToChange isEqualToString:@"deblock"])
2939 if ((([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optAlphaDeblockPopUp indexOfSelectedItem] == 7)) && (([fX264optBetaDeblockPopUp indexOfSelectedItem] == 0) || ([fX264optBetaDeblockPopUp indexOfSelectedItem] == 7)))
2945 thisOpt = [NSString stringWithFormat:@"%@=%d,%d",optName, ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0,([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0];
2948 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
2950 if ([sender state] == 0)
2956 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,1];
2959 else if ([optNameToChange isEqualToString:@"cabac"])
2961 if ([sender state] == 1)
2967 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,0];
2970 else if (([sender indexOfSelectedItem] == 0) && (sender != fX264optAlphaDeblockPopUp) && (sender != fX264optBetaDeblockPopUp) ) // means that "unspecified" is chosen, lets then remove it from the string
2974 else if ([optNameToChange isEqualToString:@"me"])
2976 switch ([sender indexOfSelectedItem])
2979 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"dia"];
2983 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"hex"];
2987 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"umh"];
2991 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"esa"];
2998 else if ([optNameToChange isEqualToString:@"direct"])
3000 switch ([sender indexOfSelectedItem])
3003 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
3007 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"spatial"];
3011 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"temporal"];
3015 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"auto"];
3022 else if ([optNameToChange isEqualToString:@"analyse"])
3024 switch ([sender indexOfSelectedItem])
3027 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"none"];
3031 thisOpt = [NSString stringWithFormat:@"%@=%@",optName,@"all"];
3038 else if ([optNameToChange isEqualToString:@"merange"])
3040 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]+3];
3042 else // we have a valid value to change, so change it
3044 thisOpt = [NSString stringWithFormat:@"%@=%d",optName,[sender indexOfSelectedItem]-1];
3049 /* Construct New String for opts here */
3050 if ([thisOpt isEqualToString:@""])
3052 changedOptString = [NSString stringWithFormat:@"%@%@",changedOptString,thisOpt];
3056 if ([changedOptString isEqualToString:@""])
3058 changedOptString = [NSString stringWithFormat:@"%@",thisOpt];
3062 changedOptString = [NSString stringWithFormat:@"%@:%@",changedOptString,thisOpt];
3067 /* Change the option string to reflect the new mod settings */
3068 [fDisplayX264Options setStringValue:[NSString stringWithFormat:changedOptString]];
3070 else // if none exists, add it to the string
3072 if ([[fDisplayX264Options stringValue] isEqualToString: @""])
3074 if ([optNameToChange isEqualToString:@"me"])
3076 switch ([sender indexOfSelectedItem])
3079 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3080 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
3084 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3085 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
3089 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3090 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
3094 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3095 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
3102 else if ([optNameToChange isEqualToString:@"direct"])
3104 switch ([sender indexOfSelectedItem])
3107 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3108 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3112 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3113 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
3117 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3118 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
3122 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3123 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
3130 else if ([optNameToChange isEqualToString:@"analyse"])
3132 switch ([sender indexOfSelectedItem])
3135 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3136 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3140 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3141 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
3149 else if ([optNameToChange isEqualToString:@"merange"])
3151 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3152 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
3154 else if ([optNameToChange isEqualToString:@"deblock"])
3156 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@", [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d,%d", ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0, ([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0]]];
3158 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] ) {
3159 if ([sender state] == 0)
3161 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
3165 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3166 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3169 else if ([optNameToChange isEqualToString:@"cabac"])
3171 if ([sender state] == 1)
3173 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@""]];
3177 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3178 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3183 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@=%@",
3184 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
3189 if ([optNameToChange isEqualToString:@"me"])
3191 switch ([sender indexOfSelectedItem])
3194 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3195 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3196 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"dia"]]];
3200 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3201 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3202 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"hex"]]];
3206 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3207 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3208 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"umh"]]];
3212 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3213 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3214 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"esa"]]];
3221 else if ([optNameToChange isEqualToString:@"direct"])
3223 switch ([sender indexOfSelectedItem])
3226 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3227 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3228 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3232 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3233 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3234 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"spatial"]]];
3238 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3239 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3240 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"temporal"]]];
3244 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3245 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3246 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"auto"]]];
3253 else if ([optNameToChange isEqualToString:@"analyse"])
3255 switch ([sender indexOfSelectedItem])
3258 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3259 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3260 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"none"]]];
3264 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",
3265 [NSString stringWithFormat:[fDisplayX264Options stringValue]],
3266 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"all"]]];
3274 else if ([optNameToChange isEqualToString:@"merange"])
3276 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
3277 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]+3]]];
3279 else if ([optNameToChange isEqualToString:@"deblock"])
3281 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@", [NSString stringWithFormat:[fDisplayX264Options stringValue]], [NSString stringWithFormat:optNameToChange], [NSString stringWithFormat:@"%d,%d", ([fX264optAlphaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optAlphaDeblockPopUp indexOfSelectedItem]-7 : 0, ([fX264optBetaDeblockPopUp indexOfSelectedItem] != 0) ? [fX264optBetaDeblockPopUp indexOfSelectedItem]-7 : 0]]];
3283 else if /*Boolean Switches*/ ([optNameToChange isEqualToString:@"mixed-refs"] || [optNameToChange isEqualToString:@"weightb"] || [optNameToChange isEqualToString:@"brdo"] || [optNameToChange isEqualToString:@"bime"] || [optNameToChange isEqualToString:@"b-pyramid"] || [optNameToChange isEqualToString:@"no-fast-pskip"] || [optNameToChange isEqualToString:@"no-dct-decimate"] || [optNameToChange isEqualToString:@"8x8dct"] )
3285 if ([sender state] == 0)
3287 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
3291 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
3292 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3295 else if ([optNameToChange isEqualToString:@"cabac"])
3297 if ([sender state] == 1)
3299 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]]]];
3303 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
3304 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender state]]]];
3309 [fDisplayX264Options setStringValue:[NSString stringWithFormat:@"%@:%@=%@",[NSString stringWithFormat:[fDisplayX264Options stringValue]],
3310 [NSString stringWithFormat:optNameToChange],[NSString stringWithFormat:@"%d",[sender indexOfSelectedItem]-1]]];
3315 /* We now need to reset the opt widgets since we changed some stuff */
3316 [self X264AdvancedOptionsSet:NULL];
3320 /* We use this method to recreate new, updated factory
3322 - (IBAction)AddFactoryPresets:(id)sender
3324 /* First, we delete any existing built in presets */
3325 [self DeleteFactoryPresets: sender];
3326 /* Then, we re-create new built in presets programmatically CreateIpodOnlyPreset*/
3327 [UserPresets addObject:[self CreateNormalPreset]];
3328 [UserPresets addObject:[self CreateClassicPreset]];
3329 [UserPresets addObject:[self CreateQuickTimePreset]];
3330 [UserPresets addObject:[self CreateIpodLowPreset]];
3331 [UserPresets addObject:[self CreateIpodHighPreset]];
3332 [UserPresets addObject:[self CreateAppleTVPreset]];
3333 [UserPresets addObject:[self CreateiPhonePreset]];
3334 [UserPresets addObject:[self CreatePSThreePreset]];
3335 [UserPresets addObject:[self CreatePSPPreset]];
3336 [UserPresets addObject:[self CreateFilmPreset]];
3337 [UserPresets addObject:[self CreateTelevisionPreset]];
3338 [UserPresets addObject:[self CreateAnimationPreset]];
3339 [UserPresets addObject:[self CreateBedlamPreset]];
3343 - (IBAction)DeleteFactoryPresets:(id)sender
3346 NSEnumerator *enumerator = [UserPresets objectEnumerator];
3350 NSMutableArray *tempArray;
3353 tempArray = [NSMutableArray array];
3354 /* we look here to see if the preset is we move on to the next one */
3355 while ( tempObject = [enumerator nextObject] )
3357 /* if the preset is "Factory" then we put it in the array of
3358 presets to delete */
3359 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
3361 [tempArray addObject:tempObject];
3365 [UserPresets removeObjectsInArray:tempArray];
3366 [tableView reloadData];
3371 - (IBAction) ShowAddPresetPanel: (id) sender
3373 /* Deselect the currently selected Preset if there is one*/
3374 [tableView deselectRow:[tableView selectedRow]];
3376 /* Populate the preset picture settings popup here */
3377 [fPresetNewPicSettingsPopUp removeAllItems];
3378 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
3379 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
3380 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
3381 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
3383 /* Erase info from the input fields fPresetNewDesc*/
3384 [fPresetNewName setStringValue: @""];
3385 [fPresetNewDesc setStringValue: @""];
3386 /* Show the panel */
3387 [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow
3388 modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
3389 [NSApp runModalForWindow: fAddPresetPanel];
3390 [NSApp endSheet: fAddPresetPanel];
3391 [fAddPresetPanel orderOut: self];
3395 - (IBAction) CloseAddPresetPanel: (id) sender
3401 - (IBAction)AddUserPreset:(id)sender
3404 /* Here we create a custom user preset */
3405 [UserPresets addObject:[self CreatePreset]];
3406 /* Erase info from the input fields */
3407 [fPresetNewName setStringValue: @""];
3408 [fPresetNewDesc setStringValue: @""];
3409 /* We stop the modal window for the new preset */
3419 /* We Sort the Presets By Factory or Custom */
3420 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
3421 ascending:YES] autorelease];
3422 /* We Sort the Presets Alphabetically by name */
3423 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
3424 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
3425 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
3426 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
3427 [UserPresets setArray:sortedArray];
3430 /* We Reload the New Table data for presets */
3431 [tableView reloadData];
3432 /* We save all of the preset data here */
3436 - (IBAction)InsertPreset:(id)sender
3438 int index = [tableView selectedRow];
3439 [UserPresets insertObject:[self CreatePreset] atIndex:index];
3440 [tableView reloadData];
3444 - (NSDictionary *)CreatePreset
3446 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3447 /* Get the New Preset Name from the field in the AddPresetPanel */
3448 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
3449 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3450 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
3451 /*Set whether or not this is default, at creation set to 0*/
3452 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3453 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3454 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
3455 /* Get New Preset Description from the field in the AddPresetPanel*/
3456 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
3458 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
3459 /* Chapter Markers fCreateChapterMarkers*/
3460 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
3461 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
3462 [preset setObject:[NSNumber numberWithInt:[fDstMpgLargeFileCheck state]] forKey:@"Mp4LargeFile"];
3464 [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
3466 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
3467 /* x264 Option String */
3468 [preset setObject:[fDisplayX264Options stringValue] forKey:@"x264Option"];
3470 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
3471 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3472 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
3473 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3475 /* Video framerate */
3476 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
3478 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
3479 /* 2 Pass Encoding */
3480 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
3481 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
3482 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
3483 /*Picture Settings*/
3484 hb_job_t * job = fTitle->job;
3485 /* Basic Picture Settings */
3486 /* Use Max Picture settings for whatever the dvd is.*/
3487 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3488 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
3489 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
3490 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
3491 [preset setObject:[NSNumber numberWithInt:fTitle->job->deinterlace] forKey:@"PictureDeinterlace"];
3492 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
3493 /* Set crop settings here */
3494 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3495 //[preset setObject:[NSNumber numberWithInt:[[fPictureController fCropMatrix] selectedRow]] forKey:@"PictureAutoCrop"];
3497 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
3498 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
3499 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
3500 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
3503 /* Audio Sample Rate*/
3504 [preset setObject:[fAudRatePopUp titleOfSelectedItem] forKey:@"AudioSampleRate"];
3505 /* Audio Bitrate Rate*/
3506 [preset setObject:[fAudBitratePopUp titleOfSelectedItem] forKey:@"AudioBitRate"];
3508 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
3511 [preset autorelease];
3516 - (NSDictionary *)CreateIpodLowPreset
3518 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3519 /* Get the New Preset Name from the field in the AddPresetPanel */
3520 [preset setObject:@"HB-iPod Low-Res" forKey:@"PresetName"];
3521 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3522 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3523 /*Set whether or not this is default, at creation set to 0*/
3524 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3525 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3526 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3527 /* Get the New Preset Description from the field in the AddPresetPanel */
3528 [preset setObject:@"HandBrake's low resolution settings for the iPod. Optimized for great playback on the iPod screen, with smaller file size." forKey:@"PresetDescription"];
3530 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3531 /* Chapter Markers*/
3532 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3534 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3536 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3537 /* x264 Option String */
3538 [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"];
3540 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3541 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3542 [preset setObject:@"700" forKey:@"VideoAvgBitrate"];
3543 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3545 /* Video framerate */
3546 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3548 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3549 /* 2 Pass Encoding */
3550 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3552 /*Picture Settings*/
3553 //hb_job_t * job = fTitle->job;
3554 /* Basic Picture Settings */
3555 /* Use Max Picture settings for whatever the dvd is.*/
3556 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3557 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3558 [preset setObject:[NSNumber numberWithInt:320] forKey:@"PictureWidth"];
3559 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3560 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3561 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3562 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3563 /* Set crop settings here */
3564 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3565 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3566 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3567 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3568 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3571 /* Audio Sample Rate*/
3572 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3573 /* Audio Bitrate Rate*/
3574 [preset setObject:@"160" forKey:@"AudioBitRate"];
3576 [preset setObject:@"None" forKey:@"Subtitles"];
3579 [preset autorelease];
3585 - (NSDictionary *)CreateIpodHighPreset
3587 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3588 /* Get the New Preset Name from the field in the AddPresetPanel */
3589 [preset setObject:@"HB-iPod High-Res" forKey:@"PresetName"];
3590 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3591 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3592 /*Set whether or not this is default, at creation set to 0*/
3593 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3594 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3595 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3596 /* Get the New Preset Description from the field in the AddPresetPanel */
3597 [preset setObject:@"HandBrake's high resolution settings for the iPod. Good video quality, great for viewing on a TV using your iPod" forKey:@"PresetDescription"];
3599 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3600 /* Chapter Markers*/
3601 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3603 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3605 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
3606 /* x264 Option String */
3607 [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"];
3609 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3610 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3611 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3612 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3614 /* Video framerate */
3615 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3617 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3618 /* 2 Pass Encoding */
3619 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3621 /*Picture Settings*/
3622 //hb_job_t * job = fTitle->job;
3623 /* Basic Picture Settings */
3624 /* Use Max Picture settings for whatever the dvd is.*/
3625 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3626 [preset setObject:[NSNumber numberWithInt:640] forKey:@"PictureWidth"];
3627 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3628 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3629 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3630 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3631 /* Set crop settings here */
3632 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3633 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3634 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3635 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3636 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3639 /* Audio Sample Rate*/
3640 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3641 /* Audio Bitrate Rate*/
3642 [preset setObject:@"160" forKey:@"AudioBitRate"];
3644 [preset setObject:@"None" forKey:@"Subtitles"];
3647 [preset autorelease];
3652 - (NSDictionary *)CreateAppleTVPreset
3654 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3655 /* Get the New Preset Name from the field in the AddPresetPanel */
3656 [preset setObject:@"HB-AppleTV" forKey:@"PresetName"];
3657 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3658 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3659 /*Set whether or not this is default, at creation set to 0*/
3660 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3661 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3662 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3663 /* Get the New Preset Description from the field in the AddPresetPanel */
3664 [preset setObject:@"HandBrake's settings for the AppleTV. Provides a good balance between quality and file size, and optimizes performance." forKey:@"PresetDescription"];
3666 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3667 /* Chapter Markers*/
3668 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3670 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3672 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3673 /* x264 Option String (We can use this to tweak the appleTV output)*/
3674 [preset setObject:@"bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2" forKey:@"x264Option"];
3676 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3677 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3678 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3679 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3681 /* Video framerate */
3682 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3684 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3685 /* 2 Pass Encoding */
3686 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3688 /*Picture Settings*/
3689 /* For AppleTV we only want to retain UsesMaxPictureSettings
3690 which depend on the source dvd picture settings, so we don't
3691 record the current dvd's picture info since it will vary from
3693 //hb_job_t * job = fTitle->job;
3694 //hb_job_t * job = title->job;
3695 /* Basic Picture Settings */
3696 /* Use Max Picture settings for whatever the dvd is.*/
3697 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3698 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3699 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3700 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3701 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3702 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3703 /* Set crop settings here */
3704 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3705 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3706 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3707 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3708 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3711 /* Audio Sample Rate*/
3712 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3713 /* Audio Bitrate Rate*/
3714 [preset setObject:@"160" forKey:@"AudioBitRate"];
3716 [preset setObject:@"None" forKey:@"Subtitles"];
3719 [preset autorelease];
3724 - (NSDictionary *)CreatePSThreePreset
3726 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3727 /* Get the New Preset Name from the field in the AddPresetPanel */
3728 [preset setObject:@"HB-PS3" forKey:@"PresetName"];
3729 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3730 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3731 /*Set whether or not this is default, at creation set to 0*/
3732 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3733 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3734 [preset setObject:[NSNumber numberWithInt:2] forKey:@"UsesPictureSettings"];
3735 /* Get the New Preset Description from the field in the AddPresetPanel */
3736 [preset setObject:@"HandBrake's settings for the Sony PlayStation 3." forKey:@"PresetDescription"];
3738 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3739 /* Chapter Markers*/
3740 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3742 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3744 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3745 /* x264 Option String (We can use this to tweak the appleTV output)*/
3746 [preset setObject:@"level=41:subme=5:me=umh" forKey:@"x264Option"];
3748 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3749 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3750 [preset setObject:@"2500" forKey:@"VideoAvgBitrate"];
3751 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3753 /* Video framerate */
3754 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3756 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3757 /* 2 Pass Encoding */
3758 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3760 /*Picture Settings*/
3761 /* For PS3 we only want to retain UsesMaxPictureSettings
3762 which depend on the source dvd picture settings, so we don't
3763 record the current dvd's picture info since it will vary from
3765 /* Use Max Picture settings for whatever the dvd is.*/
3766 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3767 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3768 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3769 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3770 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3771 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3772 /* Set crop settings here */
3773 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3774 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3775 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3776 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3777 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3780 /* Audio Sample Rate*/
3781 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3782 /* Audio Bitrate Rate*/
3783 [preset setObject:@"160" forKey:@"AudioBitRate"];
3785 [preset setObject:@"None" forKey:@"Subtitles"];
3788 [preset autorelease];
3792 - (NSDictionary *)CreatePSPPreset
3794 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3795 /* Get the New Preset Name from the field in the AddPresetPanel */
3796 [preset setObject:@"HB-PSP" forKey:@"PresetName"];
3797 /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
3798 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3799 /*Set whether or not this is default, at creation set to 0*/
3800 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3801 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3802 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3803 /* Get the New Preset Description from the field in the AddPresetPanel */
3804 [preset setObject:@"HandBrake's settings for the Sony PlayStation Portable." forKey:@"PresetDescription"];
3806 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3807 /* Chapter Markers*/
3808 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3810 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3812 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3813 /* x264 Option String (We can use this to tweak the appleTV output)*/
3814 [preset setObject:@"" forKey:@"x264Option"];
3816 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3817 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3818 [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
3819 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3821 /* Video framerate */
3822 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3824 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3825 /* 2 Pass Encoding */
3826 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3828 /*Picture Settings*/
3829 /* For PS3 we only want to retain UsesMaxPictureSettings
3830 which depend on the source dvd picture settings, so we don't
3831 record the current dvd's picture info since it will vary from
3833 /* Use Max Picture settings for whatever the dvd is.*/
3834 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
3835 [preset setObject:@"368" forKey:@"PictureWidth"];
3836 [preset setObject:@"208" forKey:@"PictureHeight"];
3837 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3838 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3839 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3840 /* Set crop settings here */
3841 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3842 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3843 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3844 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3845 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3848 /* Audio Sample Rate*/
3849 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3850 /* Audio Bitrate Rate*/
3851 [preset setObject:@"128" forKey:@"AudioBitRate"];
3853 [preset setObject:@"None" forKey:@"Subtitles"];
3856 [preset autorelease];
3861 - (NSDictionary *)CreateNormalPreset
3863 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3864 /* Get the New Preset Name from the field in the AddPresetPanel */
3865 [preset setObject:@"HB-Normal" forKey:@"PresetName"];
3866 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3867 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3868 /*Set whether or not this is default, at creation set to 0*/
3869 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3870 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3871 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3872 /* Get the New Preset Description from the field in the AddPresetPanel */
3873 [preset setObject:@"HandBrake's normal, default settings." forKey:@"PresetDescription"];
3875 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3876 /* Chapter Markers*/
3877 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
3879 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
3881 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
3882 /* x264 Option String */
3883 [preset setObject:@"ref=2:mixed-refs:bframes=3:weightb:bime:direct=auto:subme=5:me=umh:trellis=1" forKey:@"x264Option"];
3885 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3886 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3887 [preset setObject:@"1500" forKey:@"VideoAvgBitrate"];
3888 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3890 /* Video framerate */
3891 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3893 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3894 /* 2 Pass Encoding */
3895 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
3897 /*Picture Settings*/
3898 //hb_job_t * job = fTitle->job;
3899 /* Basic Picture Settings */
3900 /* Use Max Picture settings for whatever the dvd is.*/
3901 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3902 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3903 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3904 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3905 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
3906 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3907 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
3908 /* Set crop settings here */
3909 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3910 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3911 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3912 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3913 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3916 /* Audio Sample Rate*/
3917 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3918 /* Audio Bitrate Rate*/
3919 [preset setObject:@"160" forKey:@"AudioBitRate"];
3921 [preset setObject:@"None" forKey:@"Subtitles"];
3924 [preset autorelease];
3929 - (NSDictionary *)CreateClassicPreset
3931 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
3932 /* Get the New Preset Name from the field in the AddPresetPanel */
3933 [preset setObject:@"HB-Classic" forKey:@"PresetName"];
3934 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
3935 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
3936 /*Set whether or not this is default, at creation set to 0*/
3937 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
3938 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
3939 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
3940 /* Get the New Preset Description from the field in the AddPresetPanel */
3941 [preset setObject:@"HandBrake's traditional, faster, lower-quality settings." forKey:@"PresetDescription"];
3943 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
3944 /* Chapter Markers*/
3945 [preset setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
3947 [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
3949 [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
3950 /* x264 Option String */
3951 [preset setObject:@"" forKey:@"x264Option"];
3953 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
3954 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
3955 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
3956 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
3958 /* Video framerate */
3959 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
3961 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
3962 /* 2 Pass Encoding */
3963 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
3965 /*Picture Settings*/
3966 //hb_job_t * job = fTitle->job;
3967 /* Basic Picture Settings */
3968 /* Use Max Picture settings for whatever the dvd is.*/
3969 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
3970 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
3971 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
3972 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
3973 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
3974 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
3975 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
3976 /* Set crop settings here */
3977 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
3978 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
3979 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
3980 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
3981 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
3984 /* Audio Sample Rate*/
3985 [preset setObject:@"48" forKey:@"AudioSampleRate"];
3986 /* Audio Bitrate Rate*/
3987 [preset setObject:@"160" forKey:@"AudioBitRate"];
3989 [preset setObject:@"None" forKey:@"Subtitles"];
3992 [preset autorelease];
3997 - (NSDictionary *)CreateFilmPreset
3999 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4000 /* Get the New Preset Name from the field in the AddPresetPanel */
4001 [preset setObject:@"HB-Film" forKey:@"PresetName"];
4002 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4003 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4004 /*Set whether or not this is default, at creation set to 0*/
4005 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4006 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4007 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4008 /* Get the New Preset Description from the field in the AddPresetPanel */
4009 [preset setObject:@"HandBrake's preset for feature films." forKey:@"PresetDescription"];
4011 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4012 /* Chapter Markers*/
4013 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4015 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4017 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4018 /* x264 Option String */
4019 [preset setObject:@"ref=6:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=24:analyse=all:8x8dct:trellis=2:no-fast-pskip" forKey:@"x264Option"];
4021 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4022 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4023 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4024 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4026 /* Video framerate */
4027 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4029 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4030 /* 2 Pass Encoding */
4031 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4033 /*Picture Settings*/
4034 //hb_job_t * job = fTitle->job;
4035 /* Basic Picture Settings */
4036 /* Use Max Picture settings for whatever the dvd is.*/
4037 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4038 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4039 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4040 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4041 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4042 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4043 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4044 /* Set crop settings here */
4045 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4046 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4047 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4048 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4049 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4052 /* Audio Sample Rate*/
4053 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4054 /* Audio Bitrate Rate*/
4055 [preset setObject:@"160" forKey:@"AudioBitRate"];
4057 [preset setObject:@"None" forKey:@"Subtitles"];
4060 [preset autorelease];
4065 - (NSDictionary *)CreateTelevisionPreset
4067 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4068 /* Get the New Preset Name from the field in the AddPresetPanel */
4069 [preset setObject:@"HB-Television" forKey:@"PresetName"];
4070 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4071 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4072 /*Set whether or not this is default, at creation set to 0*/
4073 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4074 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4075 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4076 /* Get the New Preset Description from the field in the AddPresetPanel */
4077 [preset setObject:@"HandBrake's settings for video from television." forKey:@"PresetDescription"];
4079 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4080 /* Chapter Markers*/
4081 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4083 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4085 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4086 /* x264 Option String */
4087 [preset setObject:@"ref=3:mixed-refs:bframes=9:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:me-range=24:analyse=all:8x8dct:trellis=2:nr=150:no-fast-pskip" forKey:@"x264Option"];
4089 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4090 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4091 [preset setObject:@"1300" forKey:@"VideoAvgBitrate"];
4092 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4094 /* Video framerate */
4095 [preset setObject:@"29.97" forKey:@"VideoFramerate"];
4097 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4098 /* 2 Pass Encoding */
4099 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4101 /*Picture Settings*/
4102 //hb_job_t * job = fTitle->job;
4103 /* Basic Picture Settings */
4104 /* Use Max Picture settings for whatever the dvd is.*/
4105 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4106 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4107 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4108 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4109 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4110 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
4111 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4112 /* Set crop settings here */
4113 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4114 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4115 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4116 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4117 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4120 /* Audio Sample Rate*/
4121 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4122 /* Audio Bitrate Rate*/
4123 [preset setObject:@"160" forKey:@"AudioBitRate"];
4125 [preset setObject:@"None" forKey:@"Subtitles"];
4128 [preset autorelease];
4133 - (NSDictionary *)CreateAnimationPreset
4135 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4136 /* Get the New Preset Name from the field in the AddPresetPanel */
4137 [preset setObject:@"HB-Animation" forKey:@"PresetName"];
4138 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4139 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4140 /*Set whether or not this is default, at creation set to 0*/
4141 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4142 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4143 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4144 /* Get the New Preset Description from the field in the AddPresetPanel */
4145 [preset setObject:@"HandBrake's settings for cartoons, anime, and CGI." forKey:@"PresetDescription"];
4147 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4148 /* Chapter Markers*/
4149 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4151 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4153 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4154 /* x264 Option String */
4155 [preset setObject:@"ref=9:mixed-refs:bframes=13:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=24:analyse=all:8x8dct:trellis=2:nr=150:no-fast-pskip:filter=2,2" forKey:@"x264Option"];
4157 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4158 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4159 [preset setObject:@"1000" forKey:@"VideoAvgBitrate"];
4160 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4162 /* Video framerate */
4163 [preset setObject:@"29.97" forKey:@"VideoFramerate"];
4165 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4166 /* 2 Pass Encoding */
4167 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4169 /*Picture Settings*/
4170 //hb_job_t * job = fTitle->job;
4171 /* Basic Picture Settings */
4172 /* Use Max Picture settings for whatever the dvd is.*/
4173 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4174 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4175 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4176 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4177 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4178 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureDeinterlace"];
4179 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4180 /* Set crop settings here */
4181 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4182 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4183 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4184 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4185 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4188 /* Audio Sample Rate*/
4189 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4190 /* Audio Bitrate Rate*/
4191 [preset setObject:@"160" forKey:@"AudioBitRate"];
4193 [preset setObject:@"None" forKey:@"Subtitles"];
4196 [preset autorelease];
4201 - (NSDictionary *)CreateQuickTimePreset
4203 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4204 /* Get the New Preset Name from the field in the AddPresetPanel */
4205 [preset setObject:@"HB-QuickTime" forKey:@"PresetName"];
4206 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4207 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4208 /*Set whether or not this is default, at creation set to 0*/
4209 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4210 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4211 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4212 /* Get the New Preset Description from the field in the AddPresetPanel */
4213 [preset setObject:@"HandBrake's settings for use with QuickTime." forKey:@"PresetDescription"];
4215 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4216 /* Chapter Markers*/
4217 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4219 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4221 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4222 /* x264 Option String */
4223 [preset setObject:@"ref=6:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=7:me-range=24:analyse=all:8x8dct:trellis=2:no-fast-pskip" forKey:@"x264Option"];
4225 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4226 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4227 [preset setObject:@"2000" forKey:@"VideoAvgBitrate"];
4228 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4230 /* Video framerate */
4231 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4233 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4234 /* 2 Pass Encoding */
4235 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4237 /*Picture Settings*/
4238 //hb_job_t * job = fTitle->job;
4239 /* Basic Picture Settings */
4240 /* Use Max Picture settings for whatever the dvd is.*/
4241 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4242 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4243 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4244 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4245 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4246 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4247 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4248 /* Set crop settings here */
4249 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4250 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4251 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4252 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4253 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4256 /* Audio Sample Rate*/
4257 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4258 /* Audio Bitrate Rate*/
4259 [preset setObject:@"160" forKey:@"AudioBitRate"];
4261 [preset setObject:@"None" forKey:@"Subtitles"];
4264 [preset autorelease];
4269 - (NSDictionary *)CreateBedlamPreset
4271 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4272 /* Get the New Preset Name from the field in the AddPresetPanel */
4273 [preset setObject:@"HB-Bedlam" forKey:@"PresetName"];
4274 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4275 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4276 /*Set whether or not this is default, at creation set to 0*/
4277 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4278 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4279 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4280 /* Get the New Preset Description from the field in the AddPresetPanel */
4281 [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"];
4283 [preset setObject:@"MKV file" forKey:@"FileFormat"];
4284 /* Chapter Markers*/
4285 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4287 [preset setObject:@"AVC/H.264 Video / AC-3 Audio" forKey:@"FileCodecs"];
4289 [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
4290 /* x264 Option String */
4291 [preset setObject:@"ref=16:mixed-refs:bframes=13: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"];
4293 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4294 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4295 [preset setObject:@"1800" forKey:@"VideoAvgBitrate"];
4296 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4298 /* Video framerate */
4299 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4301 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4302 /* 2 Pass Encoding */
4303 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoTwoPass"];
4305 /*Picture Settings*/
4306 //hb_job_t * job = fTitle->job;
4307 /* Basic Picture Settings */
4308 /* Use Max Picture settings for whatever the dvd is.*/
4309 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
4310 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureAutoCrop"];
4311 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureWidth"];
4312 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4313 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
4314 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4315 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
4316 /* Set crop settings here */
4317 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4318 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4319 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4320 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4321 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4324 /* Audio Sample Rate*/
4325 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4326 /* Audio Bitrate Rate*/
4327 [preset setObject:@"160" forKey:@"AudioBitRate"];
4329 [preset setObject:@"None" forKey:@"Subtitles"];
4332 [preset autorelease];
4337 - (NSDictionary *)CreateiPhonePreset
4339 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
4340 /* Get the New Preset Name from the field in the AddPresetPanel */
4341 [preset setObject:@"HB-iPhone" forKey:@"PresetName"];
4342 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
4343 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
4344 /*Set whether or not this is default, at creation set to 0*/
4345 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
4346 /*Get the whether or not to apply pic settings in the AddPresetPanel*/
4347 [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
4348 /* Get the New Preset Description from the field in the AddPresetPanel */
4349 [preset setObject:@"HandBrake's settings for the iPhone." forKey:@"PresetDescription"];
4351 [preset setObject:@"MP4 file" forKey:@"FileFormat"];
4352 /* Chapter Markers*/
4353 [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
4355 [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
4357 [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
4358 /* x264 Option String */
4359 [preset setObject:@"cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=2" forKey:@"x264Option"];
4361 [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
4362 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
4363 [preset setObject:@"960" forKey:@"VideoAvgBitrate"];
4364 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
4366 /* Video framerate */
4367 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
4369 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
4370 /* 2 Pass Encoding */
4371 [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
4373 /*Picture Settings*/
4374 //hb_job_t * job = fTitle->job;
4375 /* Basic Picture Settings */
4376 /* Use Max Picture settings for whatever the dvd is.*/
4377 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
4378 [preset setObject:[NSNumber numberWithInt:480] forKey:@"PictureWidth"];
4379 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureHeight"];
4380 [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
4381 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
4382 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
4383 /* Set crop settings here */
4384 /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
4385 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureTopCrop"];
4386 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureBottomCrop"];
4387 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureLeftCrop"];
4388 [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureRightCrop"];
4391 /* Audio Sample Rate*/
4392 [preset setObject:@"48" forKey:@"AudioSampleRate"];
4393 /* Audio Bitrate Rate*/
4394 [preset setObject:@"160" forKey:@"AudioBitRate"];
4396 [preset setObject:@"None" forKey:@"Subtitles"];
4399 [preset autorelease];
4404 - (IBAction)DeletePreset:(id)sender
4407 NSEnumerator *enumerator;
4409 NSMutableArray *tempArray;
4412 if ( [tableView numberOfSelectedRows] == 0 )
4414 /* Alert user before deleting preset */
4415 /* Comment out for now, tie to user pref eventually */
4418 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
4420 if ( status == NSAlertDefaultReturn ) {
4421 enumerator = [tableView selectedRowEnumerator];
4422 tempArray = [NSMutableArray array];
4424 while ( (index = [enumerator nextObject]) ) {
4425 tempObject = [UserPresets objectAtIndex:[index intValue]];
4426 [tempArray addObject:tempObject];
4429 [UserPresets removeObjectsInArray:tempArray];
4430 [tableView reloadData];
4434 - (IBAction)tableViewSelected:(id)sender
4436 /* Since we cannot disable the presets tableView in terms of clickability
4437 we will use the enabled state of the add presets button to determine whether
4438 or not clicking on a preset will do anything */
4439 if ([fPresetsAdd isEnabled])
4442 /* we get the chosen preset from the UserPresets array */
4443 chosenPreset = [UserPresets objectAtIndex:[sender selectedRow]];
4444 curUserPresetChosenNum = [sender selectedRow];
4445 /* we set the preset display field in main window here */
4446 [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
4448 [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
4449 [self FormatPopUpChanged: NULL];
4451 /* Chapter Markers*/
4452 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4453 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4454 [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4456 [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
4457 [self CodecsPopUpChanged: NULL];
4459 [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
4461 /* We can show the preset options here in the gui if we want to
4462 so we check to see it the user has specified it in the prefs */
4463 [fDisplayX264Options setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
4465 [self X264AdvancedOptionsSet:NULL];
4467 /* Lets run through the following functions to get variables set there */
4468 [self EncoderPopUpChanged: NULL];
4470 [self CalculateBitrate: NULL];
4473 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4475 [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
4476 [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
4478 [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
4479 [self VideoMatrixChanged: NULL];
4481 /* Video framerate */
4482 [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
4485 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4487 /* 2 Pass Encoding */
4488 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4489 [self TwoPassCheckboxChanged: NULL];
4490 /* Turbo 1st pass for 2 Pass Encoding */
4491 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4495 /* Audio Sample Rate*/
4496 [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
4497 /* Audio Bitrate Rate*/
4498 [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
4500 [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
4502 /* Picture Settings */
4503 /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
4504 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
4506 hb_job_t * job = fTitle->job;
4507 /* Check to see if we should use the max picture setting for the current title*/
4508 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
4510 /* Use Max Picture settings for whatever the dvd is.*/
4511 [self RevertPictureSizeToMax: NULL];
4512 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4513 if (job->keep_ratio == 1)
4515 hb_fix_aspect( job, HB_KEEP_WIDTH );
4517 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4521 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
4522 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
4523 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
4524 if (job->keep_ratio == 1)
4526 hb_fix_aspect( job, HB_KEEP_WIDTH );
4528 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
4529 /* AutoCrop is in preset, then use the autocrop settings for each dvd */
4530 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 1)
4532 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
4534 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
4535 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
4536 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
4537 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
4539 else /* if custom crop has been saved in preset, use the saved custom cropping regardless of the source */
4541 [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
4543 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
4544 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
4545 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
4546 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
4549 [self CalculatePictureSizing: NULL];
4560 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
4562 return [UserPresets count];
4565 /* we use this to determine display characteristics for
4566 each table cell based on content currently only used to
4567 show the built in presets in a blue font. */
4568 - (void)tableView:(NSTableView *)aTableView
4569 willDisplayCell:(id)aCell
4570 forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
4572 NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
4574 NSColor *shadowColor;
4575 /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
4576 if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
4579 fontColor = [NSColor whiteColor];
4580 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4584 /* We set the properties of unselected rows */
4585 /* if built-in preset (defined by "type" == 0) we use a blue font */
4586 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4588 fontColor = [NSColor blueColor];
4590 else // User created preset, use a black font
4592 fontColor = [NSColor blackColor];
4596 [aCell setTextColor:fontColor];
4597 /* this shadow stuff (like mail app) for some reason looks crappy, commented out
4598 temporarily in case we want to resurrect it */
4600 NSShadow *shadow = [[NSShadow alloc] init];
4601 NSSize shadowOffset = { width: 1.0, height: -1.5};
4602 [shadow setShadowOffset:shadowOffset];
4603 [shadow setShadowColor:shadowColor];
4608 /* Method to display tooltip with the description for each preset, if available */
4609 - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell
4610 rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
4611 row:(int)rowIndex mouseLocation:(NSPoint)aPos
4613 /* initialize the tooltip contents variable */
4615 /* if there is a description for the preset, we show it in the tooltip */
4616 if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
4618 loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
4623 loc_tip = @"No description available";
4629 - (id)tableView:(NSTableView *)aTableView
4630 objectValueForTableColumn:(NSTableColumn *)aTableColumn
4633 id theRecord, theValue;
4635 theRecord = [UserPresets objectAtIndex:rowIndex];
4636 theValue = [theRecord objectForKey:[aTableColumn identifier]];
4640 // NSTableDataSource method that we implement to edit values directly in the table...
4641 - (void)tableView:(NSTableView *)aTableView
4642 setObjectValue:(id)anObject
4643 forTableColumn:(NSTableColumn *)aTableColumn
4648 theRecord = [UserPresets objectAtIndex:rowIndex];
4649 [theRecord setObject:anObject forKey:@"PresetName"];
4650 /* We Sort the Presets By Factory or Custom */
4651 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
4652 ascending:YES] autorelease];
4653 /* We Sort the Presets Alphabetically by name */
4654 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
4655 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
4656 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
4657 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
4658 [UserPresets setArray:sortedArray];
4659 /* We Reload the New Table data for presets */
4660 [tableView reloadData];
4661 /* We save all of the preset data here */
4668 [UserPresets writeToFile:UserPresetsFile atomically:YES];
4674 - (void) controlTextDidBeginEditing: (NSNotification *) notification
4676 [self CalculateBitrate: NULL];
4679 - (void) controlTextDidEndEditing: (NSNotification *) notification
4681 [self CalculateBitrate: NULL];
4684 - (void) controlTextDidChange: (NSNotification *) notification
4686 [self CalculateBitrate: NULL];
4689 - (IBAction) OpenHomepage: (id) sender
4691 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4692 URLWithString:@"http://handbrake.m0k.org/"]];
4695 - (IBAction) OpenForums: (id) sender
4697 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4698 URLWithString:@"http://handbrake.m0k.org/forum/"]];
4700 - (IBAction) OpenUserGuide: (id) sender
4702 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4703 URLWithString:@"http://handbrake.m0k.org/trac/wiki/HandBrakeGuide"]];
4707 * Shows debug output window.
4709 - (IBAction)showDebugOutputPanel:(id)sender
4711 [outputPanel showOutputPanel:sender];
4715 * Creates preferences controller, shows preferences window modally, and
4716 * releases the controller after user has closed the window.
4718 - (IBAction)showPreferencesWindow:(id)sender
4720 HBPreferencesController *controller = [[HBPreferencesController alloc] init];
4721 [controller runModal:nil];
4722 [controller release];