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.fr/>.
5 It may be used under the terms of the GNU General Public License. */
8 #import "HBOutputPanelController.h"
9 #import "HBPreferencesController.h"
10 #import "HBDVDDetector.h"
12 #import "HBPreviewController.h"
14 #define DragDropSimplePboardType @"MyCustomOutlineViewPboardType"
16 /* We setup the toolbar values here ShowPreviewIdentifier */
17 static NSString * ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
18 static NSString * StartEncodingIdentifier = @"Start Encoding Item Identifier";
19 static NSString * PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
20 static NSString * ShowQueueIdentifier = @"Show Queue Item Identifier";
21 static NSString * AddToQueueIdentifier = @"Add to Queue Item Identifier";
22 static NSString * ShowPictureIdentifier = @"Show Picture Window Item Identifier";
23 static NSString * ShowPreviewIdentifier = @"Show Preview Window Item Identifier";
24 static NSString * ShowActivityIdentifier = @"Debug Output Item Identifier";
25 static NSString * ChooseSourceIdentifier = @"Choose Source Item Identifier";
28 /*******************************
29 * HBController implementation *
30 *******************************/
31 @implementation HBController
41 /* replace bundled app icon with one which is 32/64-bit savvy */
42 #if defined( __LP64__ )
43 fApplicationIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"HandBrake-64.icns"]];
45 fApplicationIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"HandBrake.icns"]];
47 if( fApplicationIcon != nil )
48 [NSApp setApplicationIconImage:fApplicationIcon];
50 [HBPreferencesController registerUserDefaults];
52 fQueueEncodeLibhb = NULL;
53 /* Check for check for the app support directory here as
54 * outputPanel needs it right away, as may other future methods
56 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
58 YES ) objectAtIndex:0];
59 AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
60 stringByAppendingPathComponent:@"HandBrake"];
61 if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
63 [[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
66 /* Check for and create the App Support Preview directory if necessary */
67 NSString *PreviewDirectory = [AppSupportDirectory stringByAppendingPathComponent:@"Previews"];
68 if( ![[NSFileManager defaultManager] fileExistsAtPath:PreviewDirectory] )
70 [[NSFileManager defaultManager] createDirectoryAtPath:PreviewDirectory
73 outputPanel = [[HBOutputPanelController alloc] init];
74 fPictureController = [[PictureController alloc] init];
75 fQueueController = [[HBQueueController alloc] init];
76 fAdvancedOptions = [[HBAdvancedController alloc] init];
77 /* we init the HBPresets class which currently is only used
78 * for updating built in presets, may move more functionality
81 fPresetsBuiltin = [[HBPresets alloc] init];
82 fPreferencesController = [[HBPreferencesController alloc] init];
83 /* Lets report the HandBrake version number here to the activity log and text log file */
84 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
85 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
91 - (void) applicationDidFinishLaunching: (NSNotification *) notification
93 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
94 int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
95 fHandle = hb_init(loggingLevel, 0);
96 /* Optional dvd nav UseDvdNav*/
97 hb_dvd_set_dvdnav([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]);
98 /* Init a separate instance of libhb for user scanning and setting up jobs */
99 fQueueEncodeLibhb = hb_init(loggingLevel, 0);
101 // Set the Growl Delegate
102 [GrowlApplicationBridge setGrowlDelegate: self];
103 /* Init others controllers */
104 [fPictureController SetHandle: fHandle];
105 [fPictureController setHBController: self];
107 [fQueueController setHandle: fQueueEncodeLibhb];
108 [fQueueController setHBController: self];
110 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
111 [fChapterTable setDataSource:fChapterTitlesDelegate];
112 [fChapterTable setDelegate:fChapterTitlesDelegate];
114 /* setup the subtitles delegate and connections to table */
115 fSubtitlesDelegate = [[HBSubtitles alloc] init];
116 [fSubtitlesTable setDataSource:fSubtitlesDelegate];
117 [fSubtitlesTable setDelegate:fSubtitlesDelegate];
118 [fSubtitlesTable setRowHeight:25.0];
120 [fPresetsOutlineView setAutosaveName:@"Presets View"];
121 [fPresetsOutlineView setAutosaveExpandedItems:YES];
123 dockIconProgress = 0;
125 /* Call UpdateUI every 1/2 sec */
126 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
127 scheduledTimerWithTimeInterval:0.5 target:self
128 selector:@selector(updateUI:) userInfo:nil repeats:YES]
129 forMode:NSDefaultRunLoopMode];
131 // Open debug output window now if it was visible when HB was closed
132 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
133 [self showDebugOutputPanel:nil];
135 // Open queue window now if it was visible when HB was closed
136 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
137 [self showQueueWindow:nil];
139 [self openMainWindow:nil];
141 /* We have to set the bool to tell hb what to do after a scan
142 * Initially we set it to NO until we start processing the queue
144 applyQueueToScan = NO;
146 /* Now we re-check the queue array to see if there are
147 * any remaining encodes to be done in it and ask the
148 * user if they want to reload the queue */
149 if ([QueueFileArray count] > 0)
151 /* run getQueueStats to see whats in the queue file */
152 [self getQueueStats];
153 /* this results in these values
154 * fEncodingQueueItem = 0;
156 * fCompletedCount = 0;
157 * fCanceledCount = 0;
161 /*On Screen Notification*/
162 NSString * alertTitle;
164 /* We check to see if there is already another instance of hb running.
165 * Note: hbInstances == 1 means we are the only instance of HandBrake.app
167 if ([self hbInstances] > 1)
169 alertTitle = [NSString stringWithFormat:
170 NSLocalizedString(@"There is already an instance of HandBrake running.", @"")];
171 NSBeginCriticalAlertSheet(
173 NSLocalizedString(@"Reload Queue", nil),
177 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
178 NSLocalizedString(@" HandBrake will now load up the existing queue.", nil));
182 if (fWorkingCount > 0)
184 alertTitle = [NSString stringWithFormat:
185 NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
186 fWorkingCount,fPendingCount];
190 alertTitle = [NSString stringWithFormat:
191 NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
195 NSBeginCriticalAlertSheet(
197 NSLocalizedString(@"Reload Queue", nil),
199 NSLocalizedString(@"Empty Queue", nil),
201 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
202 NSLocalizedString(@" Do you want to reload them ?", nil));
205 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
206 // right below to either clear the old queue or keep it loaded up.
210 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
211 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
213 [self browseSources:nil];
216 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
218 [self browseSources:(id)fOpenSourceTitleMMenu];
225 /* check to see if another instance of HandBrake.app is running */
226 NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications];
227 NSDictionary *aDictionary;
229 for (aDictionary in runningAppDictionaries)
231 // NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]);
233 if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
241 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
243 if (returnCode == NSAlertOtherReturn)
245 [self clearQueueAllItems];
246 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
247 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
249 [self browseSources:nil];
252 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
254 [self browseSources:(id)fOpenSourceTitleMMenu];
259 if ([self hbInstances] == 1)
261 [self setQueueEncodingItemsAsPending];
263 [self showQueueWindow:NULL];
267 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
269 /* if we are in preview full screen mode, we need to go to
270 * windowed mode and release the display before we terminate.
271 * We do it here (instead of applicationWillTerminate) so we
272 * release the displays and can then see the alerts below.
274 if ([fPictureController previewFullScreenMode] == YES)
276 [fPictureController previewGoWindowed:nil];
280 hb_get_state( fQueueEncodeLibhb, &s );
282 if ( s.state != HB_STATE_IDLE )
284 int result = NSRunCriticalAlertPanel(
285 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
286 NSLocalizedString(@"If you quit HandBrake your current encode will be reloaded into your queue at next launch. Do you want to quit anyway?", nil),
287 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
289 if (result == NSAlertDefaultReturn)
291 return NSTerminateNow;
294 return NSTerminateCancel;
297 // Warn if items still in the queue
298 else if ( fPendingCount > 0 )
300 int result = NSRunCriticalAlertPanel(
301 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
302 NSLocalizedString(@"There are pending encodes in your queue. Do you want to quit anyway?",nil),
303 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
305 if ( result == NSAlertDefaultReturn )
306 return NSTerminateNow;
308 return NSTerminateCancel;
311 return NSTerminateNow;
314 - (void)applicationWillTerminate:(NSNotification *)aNotification
317 [browsedSourceDisplayName release];
318 [outputPanel release];
319 [fQueueController release];
320 [fPreviewController release];
321 [fPictureController release];
322 [fApplicationIcon release];
325 hb_close(&fQueueEncodeLibhb);
329 - (void) awakeFromNib
332 [fWindow setExcludedFromWindowsMenu:YES];
333 [fAdvancedOptions setView:fAdvancedView];
335 /* lets setup our presets drawer for drag and drop here */
336 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
337 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
338 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
340 /* Initialize currentScanCount so HB can use it to
341 evaluate successive scans */
342 currentScanCount = 0;
345 /* Init UserPresets .plist */
348 /* Init QueueFile .plist */
349 [self loadQueueFile];
351 fRipIndicatorShown = NO; // initially out of view in the nib
353 /* For 64 bit builds, the threaded animation in the progress
354 * indicators conflicts with the animation in the advanced tab
355 * for reasons not completely clear. jbrjake found a note in the
356 * 10.5 dev notes regarding this possiblility. It was also noted
357 * that unless specified, setUsesThreadedAnimation defaults to true.
358 * So, at least for now we set the indicator animation to NO for
359 * both the scan and regular progress indicators for both 32 and 64 bit
360 * as it test out fine on both and there is no reason our progress indicators
361 * should require their own thread.
364 [fScanIndicator setUsesThreadedAnimation:NO];
365 [fRipIndicator setUsesThreadedAnimation:NO];
369 /* Show/Dont Show Presets drawer upon launch based
370 on user preference DefaultPresetsDrawerShow*/
371 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0 )
373 [fPresetDrawer setDelegate:self];
374 NSSize drawerSize = NSSizeFromString( [[NSUserDefaults standardUserDefaults]
375 stringForKey:@"Drawer Size"] );
376 if( drawerSize.width )
377 [fPresetDrawer setContentSize: drawerSize];
378 [fPresetDrawer open];
381 /* Initially set the dvd angle widgets to hidden (dvdnav only) */
382 [fSrcAngleLabel setHidden:YES];
383 [fSrcAnglePopUp setHidden:YES];
386 NSMenuItem *menuItem;
387 [fDstFormatPopUp removeAllItems];
389 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
390 [menuItem setTag: HB_MUX_MP4];
392 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
393 [menuItem setTag: HB_MUX_MKV];
395 [fDstFormatPopUp selectItemAtIndex: 0];
397 [self formatPopUpChanged:nil];
399 /* We enable the create chapters checkbox here since we are .mp4 */
400 [fCreateChapterMarkers setEnabled: YES];
401 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
403 [fCreateChapterMarkers setState: NSOnState];
409 [fDstFile2Field setStringValue: [NSString stringWithFormat:
410 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
413 [fVidEncoderPopUp removeAllItems];
414 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
419 [fVidTargetSizeField setIntValue: 700];
420 [fVidBitrateField setIntValue: 1000];
422 [fVidQualityMatrix selectCell: fVidBitrateCell];
423 [self videoMatrixChanged:nil];
425 /* Video framerate */
426 [fVidRatePopUp removeAllItems];
427 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
428 for( int i = 0; i < hb_video_rates_count; i++ )
430 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
432 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
433 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
435 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
437 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
438 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
440 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
442 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
443 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
447 [fVidRatePopUp addItemWithTitle:
448 [NSString stringWithCString: hb_video_rates[i].string]];
451 [fVidRatePopUp selectItemAtIndex: 0];
453 /* Set Auto Crop to On at launch */
454 [fPictureController setAutoCrop:YES];
457 [fAudTrack1BitratePopUp removeAllItems];
458 for( int i = 0; i < hb_audio_bitrates_count; i++ )
460 [fAudTrack1BitratePopUp addItemWithTitle:
461 [NSString stringWithCString: hb_audio_bitrates[i].string]];
464 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
466 /* Audio samplerate */
467 [fAudTrack1RatePopUp removeAllItems];
468 for( int i = 0; i < hb_audio_rates_count; i++ )
470 [fAudTrack1RatePopUp addItemWithTitle:
471 [NSString stringWithCString: hb_audio_rates[i].string]];
473 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
476 [fStatusField setStringValue: @""];
481 /* We disable the Turbo 1st pass checkbox since we are not x264 */
482 [fVidTurboPassCheck setEnabled: NO];
483 [fVidTurboPassCheck setState: NSOffState];
486 /* lets get our default prefs here */
487 [self getDefaultPresets:nil];
488 /* lets initialize the current successful scancount here to 0 */
489 currentSuccessfulScanCount = 0;
494 - (void) enableUI: (bool) b
496 NSControl * controls[] =
497 { fSrcTitleField, fSrcTitlePopUp,
498 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
499 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
500 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
501 fDstBrowseButton, fVidRateField, fVidRatePopUp,fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
502 fPictureSizeField,fPictureCroppingField, fVideoFiltersField,fVidQualityMatrix, fSubField, fSubPopUp,
503 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
504 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
505 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
506 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
507 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
508 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
509 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
510 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
511 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
512 fQueueStatus,fPresetsAdd,fPresetsDelete,fSrcAngleLabel,fSrcAnglePopUp,
513 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView,
514 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel};
517 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
519 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
521 NSTextField * tf = (NSTextField *) controls[i];
522 if( ![tf isBezeled] )
524 [tf setTextColor: b ? [NSColor controlTextColor] :
525 [NSColor disabledControlTextColor]];
529 [controls[i] setEnabled: b];
535 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
536 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
537 [self setEnabledStateOfAudioMixdownControls:nil];
538 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
539 [self calculatePictureSizing:nil];
543 [fPresetsOutlineView setEnabled: NO];
547 [self videoMatrixChanged:nil];
548 [fAdvancedOptions enableUI:b];
552 /***********************************************************************
554 ***********************************************************************
555 * Shows a progression bar on the dock icon, filled according to
556 * 'progress' (0.0 <= progress <= 1.0).
557 * Called with progress < 0.0 or progress > 1.0, restores the original
559 **********************************************************************/
560 - (void) UpdateDockIcon: (float) progress
563 NSBitmapImageRep * bmp;
565 uint32_t black = htonl( 0x000000FF );
566 uint32_t red = htonl( 0xFF0000FF );
567 uint32_t white = htonl( 0xFFFFFFFF );
568 int row_start, row_end;
571 if( progress < 0.0 || progress > 1.0 )
573 [NSApp setApplicationIconImage: fApplicationIcon];
577 /* Get it in a raw bitmap form */
578 tiff = [fApplicationIcon TIFFRepresentationUsingCompression:
579 NSTIFFCompressionNone factor: 1.0];
580 bmp = [NSBitmapImageRep imageRepWithData: tiff];
582 /* Draw the progression bar */
583 /* It's pretty simple (ugly?) now, but I'm no designer */
585 row_start = 3 * (int) [bmp size].height / 4;
586 row_end = 7 * (int) [bmp size].height / 8;
588 for( i = row_start; i < row_start + 2; i++ )
590 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
591 for( j = 0; j < (int) [bmp size].width; j++ )
596 for( i = row_start + 2; i < row_end - 2; i++ )
598 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
601 for( j = 2; j < (int) [bmp size].width - 2; j++ )
603 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
615 for( i = row_end - 2; i < row_end; i++ )
617 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
618 for( j = 0; j < (int) [bmp size].width; j++ )
624 /* Now update the dock icon */
625 tiff = [bmp TIFFRepresentationUsingCompression:
626 NSTIFFCompressionNone factor: 1.0];
627 NSImage* icon = [[NSImage alloc] initWithData: tiff];
628 [NSApp setApplicationIconImage: icon];
632 - (void) updateUI: (NSTimer *) timer
635 /* Update UI for fHandle (user scanning instance of libhb ) */
638 list = hb_get_titles( fHandle );
639 /* check to see if there has been a new scan done
640 this bypasses the constraints of HB_STATE_WORKING
641 not allowing setting a newly scanned source */
642 int checkScanCount = hb_get_scancount( fHandle );
643 if( checkScanCount > currentScanCount )
645 currentScanCount = checkScanCount;
646 [fScanIndicator setIndeterminate: NO];
647 [fScanIndicator setDoubleValue: 0.0];
648 [fScanIndicator setHidden: YES];
649 [self showNewScan:nil];
653 hb_get_state( fHandle, &s );
659 #define p s.param.scanning
660 case HB_STATE_SCANNING:
662 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
663 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
664 p.title_cur, p.title_count]];
665 [fScanIndicator setHidden: NO];
666 [fScanIndicator setDoubleValue: 100.0 * ((double)( p.title_cur - 1 ) / p.title_count)];
671 #define p s.param.scandone
672 case HB_STATE_SCANDONE:
674 [fScanIndicator setIndeterminate: NO];
675 [fScanIndicator setDoubleValue: 0.0];
676 [fScanIndicator setHidden: YES];
677 [self writeToActivityLog:"ScanDone state received from fHandle"];
678 [self showNewScan:nil];
679 [[fWindow toolbar] validateVisibleItems];
685 #define p s.param.working
686 case HB_STATE_WORKING:
693 #define p s.param.muxing
694 case HB_STATE_MUXING:
701 case HB_STATE_PAUSED:
704 case HB_STATE_WORKDONE:
711 /* Update UI for fQueueEncodeLibhb */
713 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
714 /* check to see if there has been a new scan done
715 this bypasses the constraints of HB_STATE_WORKING
716 not allowing setting a newly scanned source */
718 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
719 if( checkScanCount > currentScanCount )
721 currentScanCount = checkScanCount;
722 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
726 hb_get_state( fQueueEncodeLibhb, &s );
732 #define p s.param.scanning
733 case HB_STATE_SCANNING:
735 [fStatusField setStringValue: [NSString stringWithFormat:
736 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
737 p.title_cur, p.title_count]];
739 /* Set the status string in fQueueController as well */
740 [fQueueController setQueueStatusString: [NSString stringWithFormat:
741 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
742 p.title_cur, p.title_count]];
747 #define p s.param.scandone
748 case HB_STATE_SCANDONE:
750 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
751 [self processNewQueueEncode];
752 [[fWindow toolbar] validateVisibleItems];
758 #define p s.param.working
759 case HB_STATE_WORKING:
761 NSMutableString * string;
762 /* Update text field */
763 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
767 [string appendFormat:
768 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
769 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
772 [fStatusField setStringValue: string];
773 /* Set the status string in fQueueController as well */
774 [fQueueController setQueueStatusString: string];
776 CGFloat progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
777 [fRipIndicator setIndeterminate: NO];
778 [fRipIndicator setDoubleValue:100.0 * progress_total];
780 // If progress bar hasn't been revealed at the bottom of the window, do
781 // that now. This code used to be in doRip. I moved it to here to handle
782 // the case where hb_start is called by HBQueueController and not from
784 if( !fRipIndicatorShown )
786 NSRect frame = [fWindow frame];
787 if( frame.size.width <= 591 )
788 frame.size.width = 591;
789 frame.size.height += 36;
790 frame.origin.y -= 36;
791 [fWindow setFrame:frame display:YES animate:YES];
792 fRipIndicatorShown = YES;
796 /* Update dock icon */
797 if( dockIconProgress < 100.0 * progress_total )
799 [self UpdateDockIcon: progress_total];
800 dockIconProgress += 5;
807 #define p s.param.muxing
808 case HB_STATE_MUXING:
810 /* Update text field */
811 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
812 /* Set the status string in fQueueController as well */
813 [fQueueController setQueueStatusString: NSLocalizedString( @"Muxing...", @"" )];
815 [fRipIndicator setIndeterminate: YES];
816 [fRipIndicator startAnimation: nil];
818 /* Update dock icon */
819 [self UpdateDockIcon: 1.0];
825 case HB_STATE_PAUSED:
826 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
827 [fQueueController setQueueStatusString: NSLocalizedString( @"Paused", @"" )];
831 case HB_STATE_WORKDONE:
833 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
834 // or someone calling hb_stop. In the latter case, hb_stop does not clear
835 // out the remaining passes/jobs in the queue. We'll do that here.
837 // Delete all remaining jobs of this encode.
838 [fStatusField setStringValue: NSLocalizedString( @"Encode Finished.", @"" )];
839 /* Set the status string in fQueueController as well */
840 [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
841 [fRipIndicator setIndeterminate: NO];
842 [fRipIndicator stopAnimation: nil];
843 [fRipIndicator setDoubleValue: 0.0];
844 [[fWindow toolbar] validateVisibleItems];
846 /* Restore dock icon */
847 [self UpdateDockIcon: -1.0];
848 dockIconProgress = 0;
850 if( fRipIndicatorShown )
852 NSRect frame = [fWindow frame];
853 if( frame.size.width <= 591 )
854 frame.size.width = 591;
855 frame.size.height += -36;
856 frame.origin.y -= -36;
857 [fWindow setFrame:frame display:YES animate:YES];
858 fRipIndicatorShown = NO;
860 /* Since we are done with this encode, tell output to stop writing to the
861 * individual encode log
863 [outputPanel endEncodeLog];
864 /* Check to see if the encode state has not been cancelled
865 to determine if we should check for encode done notifications */
866 if( fEncodeState != 2 )
868 NSString *pathOfFinishedEncode;
869 /* Get the output file name for the finished encode */
870 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
872 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
874 [self showGrowlDoneNotification:pathOfFinishedEncode];
876 [self sendToMetaX:pathOfFinishedEncode];
878 /* since we have successfully completed an encode, we increment the queue counter */
879 [self incrementQueueItemDone:nil];
881 /* all end of queue actions below need to be done after all queue encodes have finished
882 * and there are no pending jobs left to process
884 if (fPendingCount == 0)
886 /* If Alert Window or Window and Growl has been selected */
887 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
888 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
890 /*On Screen Notification*/
893 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
894 [NSApp requestUserAttention:NSCriticalRequest];
897 /* If sleep has been selected */
898 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
901 NSDictionary* errorDict;
902 NSAppleEventDescriptor* returnDescriptor = nil;
903 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
904 @"tell application \"Finder\" to sleep"];
905 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
906 [scriptObject release];
908 /* If Shutdown has been selected */
909 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
912 NSDictionary* errorDict;
913 NSAppleEventDescriptor* returnDescriptor = nil;
914 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
915 @"tell application \"Finder\" to shut down"];
916 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
917 [scriptObject release];
931 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
932 - (void) writeToActivityLog:(const char *) format, ...
935 va_start(args, format);
939 vsnprintf( str, 1024, format, args );
941 time_t _now = time( NULL );
942 struct tm * now = localtime( &_now );
943 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
950 // ============================================================
951 // NSToolbar Related Methods
952 // ============================================================
954 - (void) setupToolbar {
955 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
957 [toolbar setAllowsUserCustomization: YES];
958 [toolbar setAutosavesConfiguration: YES];
959 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
961 [toolbar setDelegate: self];
963 [fWindow setToolbar: toolbar];
966 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
967 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
968 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
970 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
972 [item setLabel: @"Toggle Presets"];
973 [item setPaletteLabel: @"Toggler Presets"];
974 [item setToolTip: @"Open/Close Preset Drawer"];
975 [item setImage: [NSImage imageNamed: @"Drawer"]];
976 [item setTarget: self];
977 [item setAction: @selector(toggleDrawer:)];
978 [item setAutovalidates: NO];
980 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
982 [item setLabel: @"Start"];
983 [item setPaletteLabel: @"Start Encoding"];
984 [item setToolTip: @"Start Encoding"];
985 [item setImage: [NSImage imageNamed: @"Play"]];
986 [item setTarget: self];
987 [item setAction: @selector(Rip:)];
989 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
991 [item setLabel: @"Show Queue"];
992 [item setPaletteLabel: @"Show Queue"];
993 [item setToolTip: @"Show Queue"];
994 [item setImage: [NSImage imageNamed: @"Queue"]];
995 [item setTarget: self];
996 [item setAction: @selector(showQueueWindow:)];
997 [item setAutovalidates: NO];
999 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
1001 [item setLabel: @"Add to Queue"];
1002 [item setPaletteLabel: @"Add to Queue"];
1003 [item setToolTip: @"Add to Queue"];
1004 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
1005 [item setTarget: self];
1006 [item setAction: @selector(addToQueue:)];
1008 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
1010 [item setLabel: @"Pause"];
1011 [item setPaletteLabel: @"Pause Encoding"];
1012 [item setToolTip: @"Pause Encoding"];
1013 [item setImage: [NSImage imageNamed: @"Pause"]];
1014 [item setTarget: self];
1015 [item setAction: @selector(Pause:)];
1017 else if ([itemIdent isEqualToString: ShowPictureIdentifier])
1019 [item setLabel: @"Picture Settings"];
1020 [item setPaletteLabel: @"Show Picture Settings"];
1021 [item setToolTip: @"Show Picture Settings"];
1022 [item setImage: [NSImage imageNamed: @"pref-picture"]];
1023 [item setTarget: self];
1024 [item setAction: @selector(showPicturePanel:)];
1026 else if ([itemIdent isEqualToString: ShowPreviewIdentifier])
1028 [item setLabel: @"Preview Window"];
1029 [item setPaletteLabel: @"Show Preview"];
1030 [item setToolTip: @"Show Preview"];
1031 //[item setImage: [NSImage imageNamed: @"pref-picture"]];
1032 [item setImage: [NSImage imageNamed: @"Brushed_Window"]];
1033 [item setTarget: self];
1034 [item setAction: @selector(showPreviewWindow:)];
1036 else if ([itemIdent isEqualToString: ShowActivityIdentifier])
1038 [item setLabel: @"Activity Window"];
1039 [item setPaletteLabel: @"Show Activity Window"];
1040 [item setToolTip: @"Show Activity Window"];
1041 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
1042 [item setTarget: self];
1043 [item setAction: @selector(showDebugOutputPanel:)];
1044 [item setAutovalidates: NO];
1046 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
1048 [item setLabel: @"Source"];
1049 [item setPaletteLabel: @"Source"];
1050 [item setToolTip: @"Choose Video Source"];
1051 [item setImage: [NSImage imageNamed: @"Source"]];
1052 [item setTarget: self];
1053 [item setAction: @selector(browseSources:)];
1063 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
1065 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
1066 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1067 NSToolbarSpaceItemIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
1070 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
1072 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
1073 ChooseSourceIdentifier, ShowQueueIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
1074 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1075 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
1078 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
1080 NSString * ident = [toolbarItem itemIdentifier];
1085 hb_get_state2( fQueueEncodeLibhb, &s );
1087 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
1089 if ([ident isEqualToString: StartEncodingIdentifier])
1091 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
1092 [toolbarItem setLabel: @"Stop"];
1093 [toolbarItem setPaletteLabel: @"Stop"];
1094 [toolbarItem setToolTip: @"Stop Encoding"];
1097 if ([ident isEqualToString: PauseEncodingIdentifier])
1099 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
1100 [toolbarItem setLabel: @"Pause"];
1101 [toolbarItem setPaletteLabel: @"Pause Encoding"];
1102 [toolbarItem setToolTip: @"Pause Encoding"];
1107 if ([ident isEqualToString: AddToQueueIdentifier])
1109 if ([ident isEqualToString: ShowPictureIdentifier])
1111 if ([ident isEqualToString: ShowPreviewIdentifier])
1115 else if (s.state == HB_STATE_PAUSED)
1117 if ([ident isEqualToString: PauseEncodingIdentifier])
1119 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1120 [toolbarItem setLabel: @"Resume"];
1121 [toolbarItem setPaletteLabel: @"Resume Encoding"];
1122 [toolbarItem setToolTip: @"Resume Encoding"];
1125 if ([ident isEqualToString: StartEncodingIdentifier])
1127 if ([ident isEqualToString: AddToQueueIdentifier])
1129 if ([ident isEqualToString: ShowPictureIdentifier])
1131 if ([ident isEqualToString: ShowPreviewIdentifier])
1134 else if (s.state == HB_STATE_SCANNING)
1136 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
1138 if ([ident isEqualToString: StartEncodingIdentifier])
1140 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1141 if (hb_count(fHandle) > 0)
1142 [toolbarItem setLabel: @"Start Queue"];
1144 [toolbarItem setLabel: @"Start"];
1145 [toolbarItem setPaletteLabel: @"Start Encoding"];
1146 [toolbarItem setToolTip: @"Start Encoding"];
1149 if ([ident isEqualToString: AddToQueueIdentifier])
1151 if ([ident isEqualToString: ShowPictureIdentifier])
1153 if ([ident isEqualToString: ShowPreviewIdentifier])
1158 /* If there are any pending queue items, make sure the start/stop button is active */
1159 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1161 if ([ident isEqualToString: ShowQueueIdentifier])
1163 if ([ident isEqualToString: ToggleDrawerIdentifier])
1165 if ([ident isEqualToString: ChooseSourceIdentifier])
1167 if ([ident isEqualToString: ShowActivityIdentifier])
1173 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1175 SEL action = [menuItem action];
1178 hb_get_state2( fHandle, &s );
1182 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1183 return SuccessfulScan && [fWindow attachedSheet] == nil;
1185 if (action == @selector(browseSources:))
1187 if (s.state == HB_STATE_SCANNING)
1190 return [fWindow attachedSheet] == nil;
1192 if (action == @selector(selectDefaultPreset:))
1193 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1194 if (action == @selector(Pause:))
1196 if (s.state == HB_STATE_WORKING)
1198 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1199 [menuItem setTitle:@"Pause Encoding"];
1202 else if (s.state == HB_STATE_PAUSED)
1204 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1205 [menuItem setTitle:@"Resume Encoding"];
1211 if (action == @selector(Rip:))
1213 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1215 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1216 [menuItem setTitle:@"Stop Encoding"];
1219 else if (SuccessfulScan)
1221 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1222 [menuItem setTitle:@"Start Encoding"];
1223 return [fWindow attachedSheet] == nil;
1229 if( action == @selector(setDefaultPreset:) )
1231 return [fPresetsOutlineView selectedRow] != -1;
1238 #pragma mark Encode Done Actions
1239 // register a test notification and make
1240 // it enabled by default
1241 #define SERVICE_NAME @"Encode Done"
1242 - (NSDictionary *)registrationDictionaryForGrowl
1244 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1245 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1246 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1249 return registrationDictionary;
1252 -(void)showGrowlDoneNotification:(NSString *) filePath
1254 /* This end of encode action is called as each encode rolls off of the queue */
1255 NSString * finishedEncode = filePath;
1256 /* strip off the path to just show the file name */
1257 finishedEncode = [finishedEncode lastPathComponent];
1258 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1259 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1261 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1262 [GrowlApplicationBridge
1263 notifyWithTitle:@"Put down that cocktail..."
1264 description:growlMssg
1265 notificationName:SERVICE_NAME
1273 -(void)sendToMetaX:(NSString *) filePath
1275 /* This end of encode action is called as each encode rolls off of the queue */
1276 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1278 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1279 [myScript executeAndReturnError: nil];
1284 #pragma mark Get New Source
1286 /*Opens the source browse window, called from Open Source widgets */
1287 - (IBAction) browseSources: (id) sender
1289 NSOpenPanel * panel;
1291 panel = [NSOpenPanel openPanel];
1292 [panel setAllowsMultipleSelection: NO];
1293 [panel setCanChooseFiles: YES];
1294 [panel setCanChooseDirectories: YES ];
1295 NSString * sourceDirectory;
1296 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1298 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1302 sourceDirectory = @"~/Desktop";
1303 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1305 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1306 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1308 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1309 modalForWindow: fWindow modalDelegate: self
1310 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1311 contextInfo: sender];
1314 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1315 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1317 /* we convert the sender content of contextInfo back into a variable called sender
1318 * mostly just for consistency for evaluation later
1320 id sender = (id)contextInfo;
1321 /* User selected a file to open */
1322 if( returnCode == NSOKButton )
1324 /* Free display name allocated previously by this code */
1325 [browsedSourceDisplayName release];
1327 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1328 /* we set the last searched source directory in the prefs here */
1329 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1330 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1331 /* we order out sheet, which is the browse window as we need to open
1332 * the title selection sheet right away
1334 [sheet orderOut: self];
1336 if (sender == fOpenSourceTitleMMenu)
1338 /* We put the chosen source path in the source display text field for the
1339 * source title selection sheet in which the user specifies the specific title to be
1340 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1341 * purposes in the title panel
1344 [fScanSrcTitlePathField setStringValue:scanPath];
1345 NSString *displayTitlescanSourceName;
1347 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1349 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1350 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1351 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1355 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1356 displayTitlescanSourceName = [scanPath lastPathComponent];
1358 /* we set the source display name in the title selection dialogue */
1359 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1360 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1361 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1362 /* We show the actual sheet where the user specifies the title to be scanned
1363 * as we are going to do a title specific scan
1365 [self showSourceTitleScanPanel:nil];
1369 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1370 NSString *path = [[sheet filenames] objectAtIndex: 0];
1372 /* We check to see if the chosen file at path is a package */
1373 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1375 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1376 /* We check to see if this is an .eyetv package */
1377 if ([[path pathExtension] isEqualToString: @"eyetv"])
1379 [self writeToActivityLog:"trying to open eyetv package"];
1380 /* We're looking at an EyeTV package - try to open its enclosed
1382 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1384 int n = [[path stringByAppendingString: @"/"]
1385 completePathIntoString: &mpgname caseSensitive: NO
1386 matchesIntoArray: nil
1387 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1390 /* Found an mpeg inside the eyetv package, make it our scan path
1391 and call performScan on the enclosed mpeg */
1393 [self writeToActivityLog:"found mpeg in eyetv package"];
1394 [self performScan:path scanTitleNum:0];
1398 /* We did not find an mpeg file in our package, so we do not call performScan */
1399 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1402 /* We check to see if this is a .dvdmedia package */
1403 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1405 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1406 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1407 [self writeToActivityLog:"trying to open dvdmedia package"];
1408 [self performScan:path scanTitleNum:0];
1412 /* The package is not an eyetv package, so we do not call performScan */
1413 [self writeToActivityLog:"unable to open package"];
1416 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1418 /* path is not a package, so we call perform scan directly on our file */
1419 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1421 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1422 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1423 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1427 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1428 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1429 /* make sure we remove any path extension as this can also be an '.mpg' file */
1430 browsedSourceDisplayName = [[path lastPathComponent] retain];
1432 [self performScan:path scanTitleNum:0];
1440 - (IBAction)showAboutPanel:(id)sender
1442 NSMutableDictionary* d = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
1443 fApplicationIcon, @"ApplicationIcon",
1445 [NSApp orderFrontStandardAboutPanelWithOptions:d];
1449 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1450 - (IBAction) showSourceTitleScanPanel: (id) sender
1452 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1455 [fScanSrcTitleNumField setStringValue: @"0"];
1456 /* Show the panel */
1457 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1460 - (IBAction) closeSourceTitleScanPanel: (id) sender
1462 [NSApp endSheet: fScanSrcTitlePanel];
1463 [fScanSrcTitlePanel orderOut: self];
1465 if(sender == fScanSrcTitleOpenButton)
1467 /* We setup the scan status in the main window to indicate a source title scan */
1468 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1469 [fScanIndicator setHidden: NO];
1470 [fScanIndicator setIndeterminate: YES];
1471 [fScanIndicator startAnimation: nil];
1473 /* We use the performScan method to actually perform the specified scan passing the path and the title
1476 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1480 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1481 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1483 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1484 applyQueueToScan = NO;
1485 /* use a bool to determine whether or not we can decrypt using vlc */
1486 BOOL cancelScanDecrypt = 0;
1487 NSString *path = scanPath;
1488 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1490 // Notify ChapterTitles that there's no title
1491 [fChapterTitlesDelegate resetWithTitle:nil];
1492 [fChapterTable reloadData];
1494 // Notify Subtitles that there's no title
1495 [fSubtitlesDelegate resetWithTitle:nil];
1496 [fSubtitlesTable reloadData];
1498 [self enableUI: NO];
1500 if( [detector isVideoDVD] )
1502 // The chosen path was actually on a DVD, so use the raw block
1503 // device path instead.
1504 path = [detector devicePath];
1505 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1507 #if defined( __LP64__ )
1508 /* If we are 64 bit, we cannot read encrypted dvd's as vlc is 32 bit only */
1509 cancelScanDecrypt = 1;
1510 [self writeToActivityLog: "64 bit mode cannot read dvd's, scan cancelled"];
1511 /*On Screen Notification*/
1514 status = NSRunAlertPanel(@"64-bit HandBrake cannot read encrypted dvds!",@"", @"Cancel Scan", @"Attempt Scan Anyway", nil);
1515 [NSApp requestUserAttention:NSCriticalRequest];
1517 if (status == NSAlertDefaultReturn)
1519 /* User chose to cancel the scan */
1520 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1521 cancelScanDecrypt = 1;
1525 [self writeToActivityLog: "user overrode 64-bit warning trying to open physical dvd without decryption"];
1526 cancelScanDecrypt = 0;
1530 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1531 NSString *vlcPath = @"/Applications/VLC.app/Contents/MacOS/lib/libdvdcss.2.dylib";
1532 NSFileManager * fileManager = [NSFileManager defaultManager];
1533 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1535 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1536 cancelScanDecrypt = 1;
1537 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1539 status = NSRunAlertPanel(@"HandBrake could not find VLC or your VLC is out of date.",@"Please download and install VLC media player in your /Applications folder if you wish to read encrypted DVDs.", @"Get VLC", @"Cancel Scan", @"Attempt Scan Anyway");
1540 [NSApp requestUserAttention:NSCriticalRequest];
1542 if (status == NSAlertDefaultReturn)
1544 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1545 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1547 else if (status == NSAlertAlternateReturn)
1549 /* User chose to cancel the scan */
1550 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1554 /* User chose to override our warning and scan the physical dvd anyway, at their own peril. on an encrypted dvd this produces massive log files and fails */
1555 cancelScanDecrypt = 0;
1556 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1562 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1563 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1568 if (cancelScanDecrypt == 0)
1570 /* we actually pass the scan off to libhb here */
1571 /* If there is no title number passed to scan, we use "0"
1572 * which causes the default behavior of a full source scan
1578 if (scanTitleNum > 0)
1580 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1582 /* We use our advance pref to determine how many previews to scan */
1583 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
1584 /* set title to NULL */
1586 hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
1587 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1591 - (IBAction) showNewScan:(id)sender
1595 int indxpri=0; // Used to search the longuest title (default in combobox)
1596 int longuestpri=0; // Used to search the longuest title (default in combobox)
1599 list = hb_get_titles( fHandle );
1601 if( !hb_list_count( list ) )
1603 /* We display a message if a valid dvd source was not chosen */
1604 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1605 SuccessfulScan = NO;
1607 // Notify ChapterTitles that there's no title
1608 [fSubtitlesDelegate resetWithTitle:nil];
1609 [fSubtitlesTable reloadData];
1611 // Notify Subtitles that there's no title
1612 [fChapterTitlesDelegate resetWithTitle:nil];
1613 [fChapterTable reloadData];
1617 /* We increment the successful scancount here by one,
1618 which we use at the end of this function to tell the gui
1619 if this is the first successful scan since launch and whether
1620 or not we should set all settings to the defaults */
1622 currentSuccessfulScanCount++;
1624 [[fWindow toolbar] validateVisibleItems];
1626 [fSrcTitlePopUp removeAllItems];
1627 for( int i = 0; i < hb_list_count( list ); i++ )
1629 title = (hb_title_t *) hb_list_item( list, i );
1631 currentSource = [NSString stringWithUTF8String: title->name];
1632 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1633 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1635 /* Use the dvd name in the default output field here
1636 May want to add code to remove blank spaces for some dvd names*/
1637 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1638 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1640 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1641 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1645 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1646 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1650 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1652 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1656 [fSrcTitlePopUp addItemWithTitle: [NSString
1657 stringWithFormat: @"%d - %02dh%02dm%02ds",
1658 title->index, title->hours, title->minutes,
1662 // Select the longuest title
1663 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1664 [self titlePopUpChanged:nil];
1666 SuccessfulScan = YES;
1667 [self enableUI: YES];
1669 /* if its the initial successful scan after awakeFromNib */
1670 if (currentSuccessfulScanCount == 1)
1672 [self selectDefaultPreset:nil];
1674 // Open preview window now if it was visible when HB was closed
1675 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PreviewWindowIsOpen"])
1676 [self showPreviewWindow:nil];
1678 // Open picture sizing window now if it was visible when HB was closed
1679 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PictureSizeWindowIsOpen"])
1680 [self showPicturePanel:nil];
1691 #pragma mark New Output Destination
1693 - (IBAction) browseFile: (id) sender
1695 /* Open a panel to let the user choose and update the text field */
1696 NSSavePanel * panel = [NSSavePanel savePanel];
1697 /* We get the current file name and path from the destination field here */
1698 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1699 modalForWindow: fWindow modalDelegate: self
1700 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1704 - (void) browseFileDone: (NSSavePanel *) sheet
1705 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1707 if( returnCode == NSOKButton )
1709 [fDstFile2Field setStringValue: [sheet filename]];
1710 /* Save this path to the prefs so that on next browse destination window it opens there */
1711 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1712 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1718 #pragma mark Main Window Control
1720 - (IBAction) openMainWindow: (id) sender
1722 [fWindow makeKeyAndOrderFront:nil];
1725 - (BOOL) windowShouldClose: (id) sender
1730 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1733 [fWindow makeKeyAndOrderFront:nil];
1741 - (NSSize) drawerWillResizeContents:(NSDrawer *) drawer toSize:(NSSize) contentSize {
1742 [[NSUserDefaults standardUserDefaults] setObject:NSStringFromSize( contentSize ) forKey:@"Drawer Size"];
1747 #pragma mark Queue File
1749 - (void) loadQueueFile {
1750 /* We declare the default NSFileManager into fileManager */
1751 NSFileManager * fileManager = [NSFileManager defaultManager];
1752 /*We define the location of the user presets file */
1753 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1754 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1755 /* We check for the presets.plist */
1756 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1758 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1761 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1762 /* lets check to see if there is anything in the queue file .plist */
1763 if (nil == QueueFileArray)
1765 /* if not, then lets initialize an empty array */
1766 QueueFileArray = [[NSMutableArray alloc] init];
1768 /* Initialize our curQueueEncodeIndex to 0
1769 * so we can use it to track which queue
1770 * item is to be used to track our encodes */
1771 /* NOTE: this should be changed if and when we
1772 * are able to get the last unfinished encode
1773 * in the case of a crash or shutdown */
1778 [self clearQueueEncodedItems];
1780 currentQueueEncodeIndex = 0;
1783 - (void)addQueueFileItem
1785 [QueueFileArray addObject:[self createQueueFileItem]];
1786 [self saveQueueFileItem];
1790 - (void) removeQueueFileItem:(int) queueItemToRemove
1793 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1794 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1796 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1797 * by one to keep in sync with the queue array
1799 currentQueueEncodeIndex--;
1800 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1802 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1803 [self saveQueueFileItem];
1807 - (void)saveQueueFileItem
1809 [QueueFileArray writeToFile:QueueFile atomically:YES];
1810 [fQueueController setQueueArray: QueueFileArray];
1811 [self getQueueStats];
1814 - (void)getQueueStats
1816 /* lets get the stats on the status of the queue array */
1818 fEncodingQueueItem = 0;
1820 fCompletedCount = 0;
1824 /* We use a number system to set the encode status of the queue item
1826 * 0 == already encoded
1827 * 1 == is being encoded
1828 * 2 == is yet to be encoded
1833 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1835 while (tempObject = [enumerator nextObject])
1837 NSDictionary *thisQueueDict = tempObject;
1838 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1842 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1845 fEncodingQueueItem = i;
1847 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1851 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1858 /* Set the queue status field in the main window */
1859 NSMutableString * string;
1860 if (fPendingCount == 1)
1862 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1866 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1868 [fQueueStatus setStringValue:string];
1871 /* This method will set any item marked as encoding back to pending
1872 * currently used right after a queue reload
1874 - (void) setQueueEncodingItemsAsPending
1876 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1878 NSMutableArray *tempArray;
1879 tempArray = [NSMutableArray array];
1880 /* we look here to see if the preset is we move on to the next one */
1881 while ( tempObject = [enumerator nextObject] )
1883 /* If the queue item is marked as "encoding" (1)
1884 * then change its status back to pending (2) which effectively
1885 * puts it back into the queue to be encoded
1887 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
1889 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
1891 [tempArray addObject:tempObject];
1894 [QueueFileArray setArray:tempArray];
1895 [self saveQueueFileItem];
1899 /* This method will clear the queue of any encodes that are not still pending
1900 * this includes both successfully completed encodes as well as cancelled encodes */
1901 - (void) clearQueueEncodedItems
1903 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1905 NSMutableArray *tempArray;
1906 tempArray = [NSMutableArray array];
1907 /* we look here to see if the preset is we move on to the next one */
1908 while ( tempObject = [enumerator nextObject] )
1910 /* If the queue item is either completed (0) or cancelled (3) from the
1911 * last session, then we put it in tempArray to be deleted from QueueFileArray.
1912 * NOTE: this means we retain pending (2) and also an item that is marked as
1913 * still encoding (1). If the queue has an item that is still marked as encoding
1914 * from a previous session, we can conlude that HB was either shutdown, or crashed
1915 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
1917 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
1919 [tempArray addObject:tempObject];
1923 [QueueFileArray removeObjectsInArray:tempArray];
1924 [self saveQueueFileItem];
1927 /* This method will clear the queue of all encodes. effectively creating an empty queue */
1928 - (void) clearQueueAllItems
1930 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1932 NSMutableArray *tempArray;
1933 tempArray = [NSMutableArray array];
1934 /* we look here to see if the preset is we move on to the next one */
1935 while ( tempObject = [enumerator nextObject] )
1937 [tempArray addObject:tempObject];
1940 [QueueFileArray removeObjectsInArray:tempArray];
1941 [self saveQueueFileItem];
1944 /* This method will duplicate prepareJob however into the
1945 * queue .plist instead of into the job structure so it can
1946 * be recalled later */
1947 - (NSDictionary *)createQueueFileItem
1949 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1951 hb_list_t * list = hb_get_titles( fHandle );
1952 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1953 [fSrcTitlePopUp indexOfSelectedItem] );
1954 hb_job_t * job = title->job;
1958 /* We use a number system to set the encode status of the queue item
1959 * 0 == already encoded
1960 * 1 == is being encoded
1961 * 2 == is yet to be encoded
1964 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1965 /* Source and Destination Information */
1967 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1968 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1969 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1970 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcAnglePopUp indexOfSelectedItem] + 1] forKey:@"TitleAngle"];
1971 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1973 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1975 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1977 /* Lets get the preset info if there is any */
1978 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1979 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1981 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1982 /* Chapter Markers*/
1983 /* If we have only one chapter or a title without chapters, set chapter markers to off */
1984 if ([fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem])
1986 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
1990 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1993 /* We need to get the list of chapter names to put into an array and store
1994 * in our queue, so they can be reapplied in prepareJob when this queue
1995 * item comes up if Chapter Markers is set to on.
1998 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
1999 int chaptercount = hb_list_count( fTitle->list_chapter );
2000 for( i = 0; i < chaptercount; i++ )
2002 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
2003 if( chapter != NULL )
2005 [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
2008 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
2009 [ChapterNamesArray autorelease];
2011 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2012 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
2013 /* Mux mp4 with http optimization */
2014 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
2015 /* Add iPod uuid atom */
2016 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
2020 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2021 /* x264 Option String */
2022 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2024 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2025 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2026 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2027 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
2029 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2031 /* 2 Pass Encoding */
2032 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2033 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2034 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2036 /* Picture Sizing */
2037 /* Use Max Picture settings for whatever the dvd is.*/
2038 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2039 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2040 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2041 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2042 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2043 /* if we are custom anamorphic, store the exact storage, par and display dims */
2044 if (fTitle->job->anamorphic.mode == 3)
2046 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
2047 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
2049 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_width] forKey:@"PicturePARPixelWidth"];
2050 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_height] forKey:@"PicturePARPixelHeight"];
2052 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_width] forKey:@"PicturePARDisplayWidth"];
2053 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_height] forKey:@"PicturePARDisplayHeight"];
2056 NSString * pictureSummary;
2057 pictureSummary = [fPictureSizeField stringValue];
2058 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
2059 /* Set crop settings here */
2060 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2061 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2062 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2063 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2064 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2066 /* Picture Filters */
2067 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2068 [queueFileJob setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
2070 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
2071 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
2072 [queueFileJob setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
2074 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2075 [queueFileJob setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
2077 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2078 [queueFileJob setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
2080 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
2082 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
2085 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2087 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
2088 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
2089 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
2090 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
2091 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
2092 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
2093 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
2095 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2097 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
2098 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
2099 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
2100 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
2101 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
2102 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
2103 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
2105 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2107 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
2108 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
2109 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
2110 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
2111 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
2112 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
2113 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
2115 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2117 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
2118 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
2119 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
2120 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
2121 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
2122 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
2123 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
2127 NSMutableArray *subtitlesArray = [[NSMutableArray alloc] init];
2128 [queueFileJob setObject:[NSArray arrayWithArray: [fSubtitlesDelegate getSubtitleArray: subtitlesArray]] forKey:@"SubtitleList"];
2129 [subtitlesArray autorelease];
2131 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
2133 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
2135 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
2138 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
2142 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
2145 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
2146 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
2147 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
2149 /* Picture Sizing */
2150 /* Use Max Picture settings for whatever the dvd is.*/
2151 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2152 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2153 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2154 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2155 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2157 /* Set crop settings here */
2158 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2159 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2160 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2161 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2162 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2166 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2168 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
2169 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
2170 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
2171 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
2172 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
2174 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2176 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
2177 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
2178 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
2179 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
2180 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
2182 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2184 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
2185 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
2186 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
2187 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
2188 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
2190 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2192 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
2193 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
2194 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
2195 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
2196 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
2200 /* we need to auto relase the queueFileJob and return it */
2201 [queueFileJob autorelease];
2202 return queueFileJob;
2206 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
2207 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
2209 NSUInteger index = [indexSet lastIndex];
2210 NSUInteger aboveInsertIndexCount = 0;
2213 NSUInteger removeIndex;
2215 if (index >= insertIndex)
2217 removeIndex = index + aboveInsertIndexCount;
2218 aboveInsertIndexCount++;
2222 removeIndex = index;
2226 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2227 [QueueFileArray removeObjectAtIndex:removeIndex];
2228 [QueueFileArray insertObject:object atIndex:insertIndex];
2231 index = [indexSet indexLessThanIndex:index];
2233 /* We save all of the Queue data here
2234 * and it also gets sent back to the queue controller*/
2235 [self saveQueueFileItem];
2241 #pragma mark Queue Job Processing
2243 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2245 int i = currentQueueEncodeIndex;
2246 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2248 /* We save all of the Queue data here */
2249 [self saveQueueFileItem];
2250 /* We Reload the New Table data for presets */
2251 //[fPresetsOutlineView reloadData];
2253 /* Since we have now marked a queue item as done
2254 * we can go ahead and increment currentQueueEncodeIndex
2255 * so that if there is anything left in the queue we can
2256 * go ahead and move to the next item if we want to */
2257 currentQueueEncodeIndex++ ;
2258 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2259 int queueItems = [QueueFileArray count];
2260 /* If we still have more items in our queue, lets go to the next one */
2261 if (currentQueueEncodeIndex < queueItems)
2263 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2264 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2268 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2272 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2273 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2275 /* Tell HB to output a new activity log file for this encode */
2276 [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
2279 /* use a bool to determine whether or not we can decrypt using vlc */
2280 BOOL cancelScanDecrypt = 0;
2281 /* set the bool so that showNewScan knows to apply the appropriate queue
2282 * settings as this is a queue rescan
2284 applyQueueToScan = YES;
2285 NSString *path = scanPath;
2286 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2288 /*On Screen Notification*/
2290 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2291 //[NSApp requestUserAttention:NSCriticalRequest];
2293 if( [detector isVideoDVD] )
2295 // The chosen path was actually on a DVD, so use the raw block
2296 // device path instead.
2297 path = [detector devicePath];
2298 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2300 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2301 NSString *vlcPath = @"/Applications/VLC.app";
2302 NSFileManager * fileManager = [NSFileManager defaultManager];
2303 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2305 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2306 cancelScanDecrypt = 1;
2307 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2309 status = NSRunAlertPanel(@"HandBrake could not find VLC.",@"Please download and install VLC media player in your /Applications folder if you wish to read encrypted DVDs.", @"Get VLC", @"Cancel Scan", @"Attempt Scan Anyway");
2310 [NSApp requestUserAttention:NSCriticalRequest];
2312 if (status == NSAlertDefaultReturn)
2314 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2315 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2317 else if (status == NSAlertAlternateReturn)
2319 /* User chose to cancel the scan */
2320 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2324 /* User chose to override our warning and scan the physical dvd anyway, at their own peril. on an encrypted dvd this produces massive log files and fails */
2325 cancelScanDecrypt = 0;
2326 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2332 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2333 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2337 if (cancelScanDecrypt == 0)
2339 /* we actually pass the scan off to libhb here */
2340 /* If there is no title number passed to scan, we use "0"
2341 * which causes the default behavior of a full source scan
2347 if (scanTitleNum > 0)
2349 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2352 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2353 /* We use our advance pref to determine how many previews to scan */
2354 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
2355 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
2359 /* This method was originally used to load up a new queue item in the gui and
2360 * then start processing it. However we now have modified -prepareJob and use a second
2361 * instance of libhb to do our actual encoding, therefor right now it is not required.
2362 * Nonetheless I want to leave this in here
2363 * because basically its everything we need to be able to actually modify a pending queue
2364 * item in the gui and resave it. At least for now - dynaflash
2367 - (IBAction)applyQueueSettings:(id)sender
2369 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2370 hb_job_t * job = fTitle->job;
2372 /* Set title number and chapters */
2373 /* since the queue only scans a single title, we really don't need to pick a title */
2374 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2376 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2377 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2380 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2381 [self formatPopUpChanged:nil];
2383 /* Chapter Markers*/
2384 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2385 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2386 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2387 /* Mux mp4 with http optimization */
2388 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2391 /* We set the advanced opt string here if applicable*/
2392 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2393 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2395 /* Lets run through the following functions to get variables set there */
2396 [self videoEncoderPopUpChanged:nil];
2397 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2398 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2399 [self calculateBitrate:nil];
2402 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2404 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2405 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2406 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2408 [self videoMatrixChanged:nil];
2410 /* Video framerate */
2411 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2412 detected framerate in the fVidRatePopUp so we use index 0*/
2413 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2415 [fVidRatePopUp selectItemAtIndex: 0];
2419 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2422 /* 2 Pass Encoding */
2423 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2424 [self twoPassCheckboxChanged:nil];
2425 /* Turbo 1st pass for 2 Pass Encoding */
2426 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2429 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2431 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2433 [fAudLang1PopUp selectItemAtIndex: 1];
2435 [self audioTrackPopUpChanged: fAudLang1PopUp];
2436 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2437 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2438 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2439 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2441 if ([fAudTrack1MixPopUp selectedItem] == nil)
2443 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2445 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2446 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2447 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2449 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2451 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2452 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2454 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2456 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2458 [fAudLang2PopUp selectItemAtIndex: 1];
2460 [self audioTrackPopUpChanged: fAudLang2PopUp];
2461 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2462 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2463 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2464 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2466 if ([fAudTrack2MixPopUp selectedItem] == nil)
2468 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2470 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2471 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2472 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2474 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2476 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2477 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2479 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2481 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2483 [fAudLang3PopUp selectItemAtIndex: 1];
2485 [self audioTrackPopUpChanged: fAudLang3PopUp];
2486 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2487 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2488 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2489 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2491 if ([fAudTrack3MixPopUp selectedItem] == nil)
2493 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2495 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2496 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2497 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2499 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2501 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2502 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2504 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2506 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2508 [fAudLang4PopUp selectItemAtIndex: 1];
2510 [self audioTrackPopUpChanged: fAudLang4PopUp];
2511 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2512 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2513 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2514 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2516 if ([fAudTrack4MixPopUp selectedItem] == nil)
2518 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2520 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2521 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2522 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2524 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2526 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2527 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2532 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2533 /* Forced Subtitles */
2534 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2536 /* Picture Settings */
2537 /* we check to make sure the presets width/height does not exceed the sources width/height */
2538 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2540 /* if so, then we use the sources height and width to avoid scaling up */
2541 job->width = fTitle->width;
2542 job->height = fTitle->height;
2544 else // source width/height is >= the preset height/width
2546 /* we can go ahead and use the presets values for height and width */
2547 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2548 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2550 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2551 if (job->keep_ratio == 1)
2553 hb_fix_aspect( job, HB_KEEP_WIDTH );
2554 if( job->height > fTitle->height )
2556 job->height = fTitle->height;
2557 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2560 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2563 /* If Cropping is set to custom, then recall all four crop values from
2564 when the preset was created and apply them */
2565 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2567 [fPictureController setAutoCrop:NO];
2569 /* Here we use the custom crop values saved at the time the preset was saved */
2570 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2571 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2572 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2573 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2576 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2578 [fPictureController setAutoCrop:YES];
2579 /* Here we use the auto crop values determined right after scan */
2580 job->crop[0] = AutoCropTop;
2581 job->crop[1] = AutoCropBottom;
2582 job->crop[2] = AutoCropLeft;
2583 job->crop[3] = AutoCropRight;
2589 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2592 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2594 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2596 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2598 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2600 [fPictureController setGrayscale:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2602 [self calculatePictureSizing:nil];
2605 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2606 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2607 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2608 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2610 /* Deselect the currently selected Preset if there is one*/
2611 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2612 //[self selectPreset:nil];
2614 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2615 /* Change UI to show "Custom" settings are being used */
2616 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2618 curUserPresetChosenNum = nil;
2622 /* Deselect the currently selected Preset if there is one*/
2623 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2624 /* Change UI to show "Custom" settings are being used */
2625 [fPresetSelectedDisplay setStringValue: @"Custom"];
2627 //curUserPresetChosenNum = nil;
2630 /* We need to set this bool back to NO, in case the user wants to do a scan */
2631 //applyQueueToScan = NO;
2633 /* so now we go ahead and process the new settings */
2634 [self processNewQueueEncode];
2639 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2640 - (void) processNewQueueEncode
2642 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2643 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2644 hb_job_t * job = title->job;
2646 if( !hb_list_count( list ) )
2648 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2651 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2652 [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
2653 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2654 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2655 //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2659 * If scanning we need to do some extra setup of the job.
2661 if( job->indepth_scan == 1 )
2666 * When subtitle scan is enabled do a fast pre-scan job
2667 * which will determine which subtitles to enable, if any.
2670 x264opts_tmp = job->x264opts;
2672 job->x264opts = NULL;
2674 job->indepth_scan = 1;
2678 * Add the pre-scan job
2680 hb_add( fQueueEncodeLibhb, job );
2681 job->x264opts = x264opts_tmp;
2685 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2687 job->indepth_scan = 0;
2693 hb_add( fQueueEncodeLibhb, job );
2697 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2698 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2700 hb_add( fQueueEncodeLibhb, job );
2705 job->indepth_scan = 0;
2708 hb_add( fQueueEncodeLibhb, job );
2711 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2712 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2713 /* Lets mark our new encode as 1 or "Encoding" */
2714 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2715 [self saveQueueFileItem];
2717 /* we need to clean up the subtitle tracks after the job(s) have been set */
2718 int num_subtitle_tracks = hb_list_count(job->list_subtitle);
2720 for(ii = 0; ii < num_subtitle_tracks; ii++)
2722 hb_subtitle_t * subtitle;
2723 subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
2726 hb_list_rem(job->list_subtitle, subtitle);
2731 /* We should be all setup so let 'er rip */
2736 #pragma mark Live Preview
2737 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
2738 * can encode to its temp preview directory and playback. This is *not* used for any actual user
2741 - (void) prepareJobForPreview
2743 hb_list_t * list = hb_get_titles( fHandle );
2744 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2745 [fSrcTitlePopUp indexOfSelectedItem] );
2746 hb_job_t * job = title->job;
2747 hb_audio_config_t * audio;
2748 /* set job->angle for libdvdnav */
2749 job->angle = [fSrcAnglePopUp indexOfSelectedItem] + 1;
2750 /* Chapter selection */
2751 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
2752 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
2754 /* Format (Muxer) and Video Encoder */
2755 job->mux = [[fDstFormatPopUp selectedItem] tag];
2756 job->vcodec = [[fVidEncoderPopUp selectedItem] tag];
2758 job->chapter_markers = 0;
2760 if( job->vcodec & HB_VCODEC_X264 )
2762 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2763 Currently only used with Constant Quality setting*/
2764 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
2769 /* Below Sends x264 options to the core library if x264 is selected*/
2770 /* Lets use this as per Nyx, Thanks Nyx!*/
2771 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2772 /* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
2773 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
2778 /* Video settings */
2779 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2780 * and detelecine is on, so we handle that in the logic below
2783 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
2785 /* a specific framerate has been chosen */
2786 job->vrate = 27000000;
2787 job->vrate_base = hb_video_rates[[fVidRatePopUp indexOfSelectedItem]-1].rate;
2788 /* We are not same as source so we set job->cfr to 1
2789 * to enable constant frame rate since user has specified
2790 * a specific framerate*/
2795 /* We are same as source (variable) */
2796 job->vrate = title->rate;
2797 job->vrate_base = title->rate_base;
2798 /* We are same as source so we set job->cfr to 0
2799 * to enable true same as source framerate */
2801 /* If we are same as source and we have detelecine on, we need to turn on
2804 if ([fPictureController detelecine] == 1)
2810 switch( [fVidQualityMatrix selectedRow] )
2814 Bitrate should already have been calculated and displayed
2815 in fVidBitrateField, so let's just use it */
2817 job->vquality = -1.0;
2818 job->vbitrate = [fVidBitrateField intValue];
2821 job->vquality = [fVidQualityRFField floatValue];
2826 /* Subtitle settings */
2827 NSMutableArray *subtitlesArray = nil;
2828 subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray: subtitlesArray]];
2836 bool one_burned = FALSE;
2839 NSEnumerator *enumerator = [subtitlesArray objectEnumerator];
2841 while (tempObject = [enumerator nextObject])
2844 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
2845 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
2846 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
2847 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
2849 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
2850 * we want to ignore it for display as well as encoding.
2854 /* if i is 0, then we are in the first item of the subtitles which we need to
2855 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
2856 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
2859 /* if we are on the first track and using "Foreign Audio Search" */
2860 if (i == 0 && subtitle == 1)
2862 /* NOTE: Currently foreign language search is borked for preview.
2863 * Commented out but left in for initial commit. */
2866 [self writeToActivityLog: "Foreign Language Search: %d", 1];
2868 job->indepth_scan = 1;
2869 if (burned == 1 || job->mux != HB_MUX_MP4)
2871 if (burned != 1 && job->mux == HB_MUX_MKV)
2873 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2876 job->select_subtitle_config.force = force;
2877 job->select_subtitle_config.default_track = def;
2886 /* for the actual source tracks, we must subtract the non source entries so
2887 * that the menu index matches the source subtitle_list index for convenience */
2890 /* for the first track, the source tracks start at menu index 2 ( None is 0,
2891 * Foreign Language Search is 1) so subtract 2 */
2892 subtitle = subtitle - 2;
2896 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
2899 subtitle = subtitle - 1;
2902 /* We are setting a source subtitle so access the source subtitle info */
2903 hb_subtitle_t * subt;
2905 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
2909 [self writeToActivityLog: "Setting Subtitle: %s", subt];
2911 hb_subtitle_config_t sub_config = subt->config;
2913 if (!burned && job->mux == HB_MUX_MKV &&
2914 subt->format == hb_subtitle_s::PICTURESUB)
2916 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2918 else if (!burned && job->mux == HB_MUX_MP4 &&
2919 subt->format == hb_subtitle_s::PICTURESUB)
2921 // Skip any non-burned vobsubs when output is mp4
2924 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
2926 // Only allow one subtitle to be burned into the video
2931 sub_config.force = force;
2932 sub_config.default_track = def;
2933 hb_subtitle_add( job, &sub_config, subtitle );
2943 [subtitlesArray autorelease];
2946 /* Audio tracks and mixdowns */
2947 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2948 int audiotrack_count = hb_list_count(job->list_audio);
2949 for( int i = 0; i < audiotrack_count;i++)
2951 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2952 hb_list_rem(job->list_audio, temp_audio);
2954 /* Now lets add our new tracks to the audio list here */
2955 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2957 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2958 hb_audio_config_init(audio);
2959 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2960 /* We go ahead and assign values to our audio->out.<properties> */
2961 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2962 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
2963 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
2964 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
2965 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
2966 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
2968 hb_audio_add( job, audio );
2971 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2973 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2974 hb_audio_config_init(audio);
2975 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2976 /* We go ahead and assign values to our audio->out.<properties> */
2977 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2978 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
2979 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
2980 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
2981 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
2982 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
2984 hb_audio_add( job, audio );
2989 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2991 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2992 hb_audio_config_init(audio);
2993 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2994 /* We go ahead and assign values to our audio->out.<properties> */
2995 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2996 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
2997 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
2998 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
2999 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
3000 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
3002 hb_audio_add( job, audio );
3007 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
3009 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3010 hb_audio_config_init(audio);
3011 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3012 /* We go ahead and assign values to our audio->out.<properties> */
3013 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3014 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
3015 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
3016 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
3017 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
3018 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
3020 hb_audio_add( job, audio );
3029 /* Though Grayscale is not really a filter, per se
3030 * we put it here since its in the filters panel
3033 if ([fPictureController grayscale])
3042 /* Initialize the filters list */
3043 job->filters = hb_list_init();
3045 /* Now lets call the filters if applicable.
3046 * The order of the filters is critical
3050 if ([fPictureController detelecine] == 1)
3052 hb_list_add( job->filters, &hb_filter_detelecine );
3054 if ([fPictureController detelecine] == 2)
3056 /* use a custom detelecine string */
3057 hb_filter_detelecine.settings = (char *) [[fPictureController detelecineCustomString] UTF8String];
3058 hb_list_add( job->filters, &hb_filter_detelecine );
3060 if ([fPictureController useDecomb] == 1)
3063 if ([fPictureController decomb] == 1)
3065 /* Run old deinterlacer fd by default */
3066 //hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
3067 hb_list_add( job->filters, &hb_filter_decomb );
3069 /* we add the custom string if present */
3070 if ([fPictureController decomb] == 2)
3072 /* use a custom decomb string */
3073 hb_filter_decomb.settings = (char *) [[fPictureController decombCustomString] UTF8String];
3074 hb_list_add( job->filters, &hb_filter_decomb );
3081 if ([fPictureController deinterlace] == 1)
3083 /* Run old deinterlacer fd by default */
3084 hb_filter_deinterlace.settings = "-1";
3085 hb_list_add( job->filters, &hb_filter_deinterlace );
3087 else if ([fPictureController deinterlace] == 2)
3089 /* Yadif mode 0 (without spatial deinterlacing.) */
3090 hb_filter_deinterlace.settings = "2";
3091 hb_list_add( job->filters, &hb_filter_deinterlace );
3093 else if ([fPictureController deinterlace] == 3)
3095 /* Yadif (with spatial deinterlacing) */
3096 hb_filter_deinterlace.settings = "0";
3097 hb_list_add( job->filters, &hb_filter_deinterlace );
3099 else if ([fPictureController deinterlace] == 4)
3101 /* we add the custom string if present */
3102 hb_filter_deinterlace.settings = (char *) [[fPictureController deinterlaceCustomString] UTF8String];
3103 hb_list_add( job->filters, &hb_filter_deinterlace );
3108 if ([fPictureController denoise] == 1) // Weak in popup
3110 hb_filter_denoise.settings = "2:1:2:3";
3111 hb_list_add( job->filters, &hb_filter_denoise );
3113 else if ([fPictureController denoise] == 2) // Medium in popup
3115 hb_filter_denoise.settings = "3:2:2:3";
3116 hb_list_add( job->filters, &hb_filter_denoise );
3118 else if ([fPictureController denoise] == 3) // Strong in popup
3120 hb_filter_denoise.settings = "7:7:5:5";
3121 hb_list_add( job->filters, &hb_filter_denoise );
3123 else if ([fPictureController denoise] == 4) // custom in popup
3125 /* we add the custom string if present */
3126 hb_filter_denoise.settings = (char *) [[fPictureController denoiseCustomString] UTF8String];
3127 hb_list_add( job->filters, &hb_filter_denoise );
3130 /* Deblock (uses pp7 default) */
3131 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3132 * the macgui's purposes a value of 0 actually means to not even use the filter
3133 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3135 if ([fPictureController deblock] != 0)
3137 NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
3138 hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
3139 hb_list_add( job->filters, &hb_filter_deblock );
3146 #pragma mark Job Handling
3152 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
3153 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
3154 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
3155 hb_job_t * job = title->job;
3156 hb_audio_config_t * audio;
3157 /* Title Angle for dvdnav */
3158 job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
3159 /* Chapter selection */
3160 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
3161 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
3163 /* Format (Muxer) and Video Encoder */
3164 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
3165 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
3168 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
3169 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
3171 job->largeFileSize = 1;
3175 job->largeFileSize = 0;
3177 /* We set http optimized mp4 here */
3178 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
3180 job->mp4_optimize = 1;
3184 job->mp4_optimize = 0;
3188 /* We set the chapter marker extraction here based on the format being
3189 mpeg4 or mkv and the checkbox being checked */
3190 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
3192 job->chapter_markers = 1;
3194 /* now lets get our saved chapter names out the array in the queue file
3195 * and insert them back into the title chapter list. We have it here,
3196 * because unless we are inserting chapter markers there is no need to
3197 * spend the overhead of iterating through the chapter names array imo
3198 * Also, note that if for some reason we don't apply chapter names, the
3199 * chapters just come out 001, 002, etc. etc.
3202 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
3204 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
3206 while (tempObject = [enumerator nextObject])
3208 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3209 if( chapter != NULL )
3211 strncpy( chapter->title, [tempObject UTF8String], 1023);
3212 chapter->title[1023] = '\0';
3219 job->chapter_markers = 0;
3222 if( job->vcodec & HB_VCODEC_X264 )
3224 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
3233 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
3234 Currently only used with Constant Quality setting*/
3235 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
3239 /* Below Sends x264 options to the core library if x264 is selected*/
3240 /* Lets use this as per Nyx, Thanks Nyx!*/
3241 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
3242 /* Turbo first pass if two pass and Turbo First pass is selected */
3243 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
3245 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
3246 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
3247 /* append the "Turbo" string variable to the existing opts string.
3248 Note: the "Turbo" string must be appended, not prepended to work properly*/
3249 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
3250 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
3254 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
3260 /* Picture Size Settings */
3261 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
3262 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
3264 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
3265 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
3266 if ([[queueToApply objectForKey:@"PicturePAR"] intValue] == 3)
3268 /* insert our custom values here for capuj */
3269 job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"] intValue];
3270 job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"] intValue];
3272 job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"] intValue];
3273 job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"] intValue];
3275 job->anamorphic.dar_width = [[queueToApply objectForKey:@"PicturePARDisplayWidth"] floatValue];
3276 job->anamorphic.dar_height = [[queueToApply objectForKey:@"PicturePARDisplayHeight"] floatValue];
3279 /* Here we use the crop values saved at the time the preset was saved */
3280 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
3281 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
3282 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
3283 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
3285 /* Video settings */
3288 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
3289 * and detelecine is on, so we handle that in the logic below
3292 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
3294 /* a specific framerate has been chosen */
3295 job->vrate = 27000000;
3296 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
3297 /* We are not same as source so we set job->cfr to 1
3298 * to enable constant frame rate since user has specified
3299 * a specific framerate*/
3304 /* We are same as source (variable) */
3305 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
3306 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
3307 /* We are same as source so we set job->cfr to 0
3308 * to enable true same as source framerate */
3310 /* If we are same as source and we have detelecine on, we need to turn on
3313 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3319 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
3322 Bitrate should already have been calculated and displayed
3323 in fVidBitrateField, so let's just use it same as abr*/
3324 job->vquality = -1.0;
3325 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
3327 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
3329 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
3334 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
3339 #pragma mark Process Subtitles to libhb
3341 /* Map the settings in the dictionaries for the SubtitleList array to match title->list_subtitle
3342 * which means that we need to account for the offset of non source language settings in from
3343 * the NSPopUpCell menu. For all of the objects in the SubtitleList array this means 0 is "None"
3344 * from the popup menu, additionally the first track has "Foreign Audio Search" at 1. So we use
3345 * an int to offset the index number for the objectForKey:@"subtitleSourceTrackNum" to map that
3346 * to the source tracks position in title->list_subtitle.
3353 bool one_burned = FALSE;
3356 NSEnumerator *enumerator = [[queueToApply objectForKey:@"SubtitleList"] objectEnumerator];
3358 while (tempObject = [enumerator nextObject])
3361 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
3362 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
3363 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
3364 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
3366 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
3367 * we want to ignore it for display as well as encoding.
3371 /* if i is 0, then we are in the first item of the subtitles which we need to
3372 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
3373 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
3376 /* if we are on the first track and using "Foreign Audio Search" */
3377 if (i == 0 && subtitle == 1)
3379 [self writeToActivityLog: "Foreign Language Search: %d", 1];
3381 job->indepth_scan = 1;
3382 if (burned == 1 || job->mux != HB_MUX_MP4)
3384 if (burned != 1 && job->mux == HB_MUX_MKV)
3386 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3390 job->select_subtitle_config.dest = hb_subtitle_config_s::RENDERSUB;
3393 job->select_subtitle_config.force = force;
3394 job->select_subtitle_config.default_track = def;
3402 /* for the actual source tracks, we must subtract the non source entries so
3403 * that the menu index matches the source subtitle_list index for convenience */
3406 /* for the first track, the source tracks start at menu index 2 ( None is 0,
3407 * Foreign Language Search is 1) so subtract 2 */
3408 subtitle = subtitle - 2;
3412 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
3415 subtitle = subtitle - 1;
3418 /* We are setting a source subtitle so access the source subtitle info */
3419 hb_subtitle_t * subt;
3421 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3425 [self writeToActivityLog: "Setting Subtitle: %s", subt];
3427 hb_subtitle_config_t sub_config = subt->config;
3429 if (!burned && job->mux == HB_MUX_MKV &&
3430 subt->format == hb_subtitle_s::PICTURESUB)
3432 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3434 else if (!burned && job->mux == HB_MUX_MP4 &&
3435 subt->format == hb_subtitle_s::PICTURESUB)
3437 // Skip any non-burned vobsubs when output is mp4
3440 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
3442 // Only allow one subtitle to be burned into the video
3447 sub_config.force = force;
3448 sub_config.default_track = def;
3449 hb_subtitle_add( job, &sub_config, subtitle );
3460 /* Audio tracks and mixdowns */
3461 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3462 int audiotrack_count = hb_list_count(job->list_audio);
3463 for( int i = 0; i < audiotrack_count;i++)
3465 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3466 hb_list_rem(job->list_audio, temp_audio);
3468 /* Now lets add our new tracks to the audio list here */
3469 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
3471 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3472 hb_audio_config_init(audio);
3473 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3474 /* We go ahead and assign values to our audio->out.<properties> */
3475 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3476 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
3477 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
3478 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
3479 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
3480 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
3482 hb_audio_add( job, audio );
3485 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
3488 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3489 hb_audio_config_init(audio);
3490 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3491 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
3492 /* We go ahead and assign values to our audio->out.<properties> */
3493 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3494 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
3495 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
3496 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
3497 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
3498 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
3500 hb_audio_add( job, audio );
3504 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
3506 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3507 hb_audio_config_init(audio);
3508 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3509 /* We go ahead and assign values to our audio->out.<properties> */
3510 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3511 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
3512 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
3513 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
3514 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
3515 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
3517 hb_audio_add( job, audio );
3521 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
3523 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3524 hb_audio_config_init(audio);
3525 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3526 /* We go ahead and assign values to our audio->out.<properties> */
3527 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3528 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
3529 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
3530 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
3531 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
3532 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue];
3534 hb_audio_add( job, audio );
3540 job->filters = hb_list_init();
3542 /* Now lets call the filters if applicable.
3543 * The order of the filters is critical
3546 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3548 //if ([queueToApply objectForKey:@"PictureDetelecineCustom"])
3549 hb_list_add( job->filters, &hb_filter_detelecine );
3551 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 2)
3553 /* use a custom detelecine string */
3554 hb_filter_detelecine.settings = (char *) [[queueToApply objectForKey:@"PictureDetelecineCustom"] UTF8String];
3555 hb_list_add( job->filters, &hb_filter_detelecine );
3558 if ([[queueToApply objectForKey:@"PictureDecombDeinterlace"] intValue] == 1)
3561 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
3563 /* Run old deinterlacer fd by default */
3564 hb_list_add( job->filters, &hb_filter_decomb );
3566 /* we add the custom string if present */
3567 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 2)
3569 /* use a custom decomb string */
3570 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"PictureDecombCustom"] UTF8String];
3571 hb_list_add( job->filters, &hb_filter_decomb );
3579 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
3581 /* Run old deinterlacer fd by default */
3582 hb_filter_deinterlace.settings = "-1";
3583 hb_list_add( job->filters, &hb_filter_deinterlace );
3585 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
3587 /* Yadif mode 0 (without spatial deinterlacing.) */
3588 hb_filter_deinterlace.settings = "2";
3589 hb_list_add( job->filters, &hb_filter_deinterlace );
3591 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
3593 /* Yadif (with spatial deinterlacing) */
3594 hb_filter_deinterlace.settings = "0";
3595 hb_list_add( job->filters, &hb_filter_deinterlace );
3597 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 4)
3599 /* we add the custom string if present */
3600 hb_filter_deinterlace.settings = (char *) [[queueToApply objectForKey:@"PictureDeinterlaceCustom"] UTF8String];
3601 hb_list_add( job->filters, &hb_filter_deinterlace );
3607 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
3609 hb_filter_denoise.settings = "2:1:2:3";
3610 hb_list_add( job->filters, &hb_filter_denoise );
3612 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
3614 hb_filter_denoise.settings = "3:2:2:3";
3615 hb_list_add( job->filters, &hb_filter_denoise );
3617 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
3619 hb_filter_denoise.settings = "7:7:5:5";
3620 hb_list_add( job->filters, &hb_filter_denoise );
3622 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 4) // Custom in popup
3624 /* we add the custom string if present */
3625 hb_filter_denoise.settings = (char *) [[queueToApply objectForKey:@"PictureDenoiseCustom"] UTF8String];
3626 hb_list_add( job->filters, &hb_filter_denoise );
3629 /* Deblock (uses pp7 default) */
3630 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3631 * the macgui's purposes a value of 0 actually means to not even use the filter
3632 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3634 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
3636 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
3637 hb_list_add( job->filters, &hb_filter_deblock );
3639 [self writeToActivityLog: "prepareJob exiting"];
3644 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
3646 - (IBAction) addToQueue: (id) sender
3648 /* We get the destination directory from the destination field here */
3649 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3650 /* We check for a valid destination here */
3651 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3653 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3660 BOOL fileExistsInQueue;
3661 fileExistsInQueue = NO;
3663 /* We check for and existing file here */
3664 if([[NSFileManager defaultManager] fileExistsAtPath: [fDstFile2Field stringValue]])
3669 /* We now run through the queue and make sure we are not overwriting an exisiting queue item */
3671 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
3673 while (tempObject = [enumerator nextObject])
3675 NSDictionary *thisQueueDict = tempObject;
3676 if ([[thisQueueDict objectForKey:@"DestinationPath"] isEqualToString: [fDstFile2Field stringValue]])
3678 fileExistsInQueue = YES;
3684 if(fileExists == YES)
3686 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists.", @"" ),
3687 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3688 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3689 NULL, NULL, [NSString stringWithFormat:
3690 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3691 [fDstFile2Field stringValue]] );
3693 else if (fileExistsInQueue == YES)
3695 NSBeginCriticalAlertSheet( NSLocalizedString( @"There is already a queue item for this destination.", @"" ),
3696 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3697 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3698 NULL, NULL, [NSString stringWithFormat:
3699 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3700 [fDstFile2Field stringValue]] );
3704 [self doAddToQueue];
3708 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
3709 the user if they want to overwrite an exiting movie file.
3711 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
3712 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3714 if( returnCode == NSAlertAlternateReturn )
3715 [self doAddToQueue];
3718 - (void) doAddToQueue
3720 [self addQueueFileItem ];
3725 /* Rip: puts up an alert before ultimately calling doRip
3727 - (IBAction) Rip: (id) sender
3729 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
3730 /* Rip or Cancel ? */
3732 hb_get_state2( fQueueEncodeLibhb, &s );
3734 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
3736 [self Cancel: sender];
3740 /* We check to see if we need to warn the user that the computer will go to sleep
3741 or shut down when encoding is finished */
3742 [self remindUserOfSleepOrShutdown];
3744 // If there are pending jobs in the queue, then this is a rip the queue
3745 if (fPendingCount > 0)
3747 /* here lets start the queue with the first pending item */
3748 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3753 // Before adding jobs to the queue, check for a valid destination.
3755 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3756 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3758 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3762 /* We check for duplicate name here */
3763 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
3765 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3766 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3767 @selector( overWriteAlertDone:returnCode:contextInfo: ),
3768 NULL, NULL, [NSString stringWithFormat:
3769 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3770 [fDstFile2Field stringValue]] );
3772 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
3776 /* if there are no pending jobs in the queue, then add this one to the queue and rip
3777 otherwise, just rip the queue */
3778 if(fPendingCount == 0)
3780 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
3781 [self doAddToQueue];
3784 /* go right to processing the new queue encode */
3785 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
3786 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3791 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3792 want to overwrite an exiting movie file.
3794 - (void) overWriteAlertDone: (NSWindow *) sheet
3795 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3797 if( returnCode == NSAlertAlternateReturn )
3799 /* if there are no jobs in the queue, then add this one to the queue and rip
3800 otherwise, just rip the queue */
3801 if( fPendingCount == 0 )
3803 [self doAddToQueue];
3806 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3807 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3808 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3813 - (void) remindUserOfSleepOrShutdown
3815 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
3817 /*Warn that computer will sleep after encoding*/
3820 reminduser = NSRunAlertPanel(@"The computer will sleep after encoding is done.",@"You have selected to sleep the computer after encoding. To turn off sleeping, go to the HandBrake preferences.", @"OK", @"Preferences...", nil);
3821 [NSApp requestUserAttention:NSCriticalRequest];
3822 if ( reminduser == NSAlertAlternateReturn )
3824 [self showPreferencesWindow:nil];
3827 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
3829 /*Warn that computer will shut down after encoding*/
3832 reminduser = NSRunAlertPanel(@"The computer will shut down after encoding is done.",@"You have selected to shut down the computer after encoding. To turn off shut down, go to the HandBrake preferences.", @"OK", @"Preferences...", nil);
3833 [NSApp requestUserAttention:NSCriticalRequest];
3834 if ( reminduser == NSAlertAlternateReturn )
3836 [self showPreferencesWindow:nil];
3845 /* Let libhb do the job */
3846 hb_start( fQueueEncodeLibhb );
3847 /*set the fEncodeState State */
3852 //------------------------------------------------------------------------------------
3853 // Displays an alert asking user if the want to cancel encoding of current job.
3854 // Cancel: returns immediately after posting the alert. Later, when the user
3855 // acknowledges the alert, doCancelCurrentJob is called.
3856 //------------------------------------------------------------------------------------
3857 - (IBAction)Cancel: (id)sender
3859 if (!fQueueController) return;
3861 hb_pause( fQueueEncodeLibhb );
3862 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3864 // Which window to attach the sheet to?
3865 NSWindow * docWindow;
3866 if ([sender respondsToSelector: @selector(window)])
3867 docWindow = [sender window];
3869 docWindow = fWindow;
3871 NSBeginCriticalAlertSheet(
3873 NSLocalizedString(@"Continue Encoding", nil),
3874 NSLocalizedString(@"Cancel Current and Stop", nil),
3875 NSLocalizedString(@"Cancel Current and Continue", nil),
3877 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3878 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3880 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3883 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3885 hb_resume( fQueueEncodeLibhb );
3886 if (returnCode == NSAlertOtherReturn)
3888 [self doCancelCurrentJob]; // <- this also stops libhb
3890 if (returnCode == NSAlertAlternateReturn)
3892 [self doCancelCurrentJobAndStop];
3896 //------------------------------------------------------------------------------------
3897 // Cancels and deletes the current job and stops libhb from processing the remaining
3899 //------------------------------------------------------------------------------------
3900 - (void) doCancelCurrentJob
3902 // Stop the current job. hb_stop will only cancel the current pass and then set
3903 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3904 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3905 // remaining passes of the job and then start the queue back up if there are any
3909 hb_stop( fQueueEncodeLibhb );
3911 // Delete all remaining jobs since libhb doesn't do this on its own.
3913 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3914 hb_rem( fQueueEncodeLibhb, job );
3916 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3918 // now that we've stopped the currently encoding job, lets mark it as cancelled
3919 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3920 // and as always, save it in the queue .plist...
3921 /* We save all of the Queue data here */
3922 [self saveQueueFileItem];
3923 // so now lets move to
3924 currentQueueEncodeIndex++ ;
3925 // ... and see if there are more items left in our queue
3926 int queueItems = [QueueFileArray count];
3927 /* If we still have more items in our queue, lets go to the next one */
3928 if (currentQueueEncodeIndex < queueItems)
3930 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3931 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3933 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3937 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3942 - (void) doCancelCurrentJobAndStop
3944 hb_stop( fQueueEncodeLibhb );
3946 // Delete all remaining jobs since libhb doesn't do this on its own.
3948 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3949 hb_rem( fQueueEncodeLibhb, job );
3952 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3954 // now that we've stopped the currently encoding job, lets mark it as cancelled
3955 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3956 // and as always, save it in the queue .plist...
3957 /* We save all of the Queue data here */
3958 [self saveQueueFileItem];
3959 // so now lets move to
3960 currentQueueEncodeIndex++ ;
3961 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3963 - (IBAction) Pause: (id) sender
3966 hb_get_state2( fQueueEncodeLibhb, &s );
3968 if( s.state == HB_STATE_PAUSED )
3970 hb_resume( fQueueEncodeLibhb );
3974 hb_pause( fQueueEncodeLibhb );
3979 #pragma mark GUI Controls Changed Methods
3981 - (IBAction) titlePopUpChanged: (id) sender
3983 hb_list_t * list = hb_get_titles( fHandle );
3984 hb_title_t * title = (hb_title_t*)
3985 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3987 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3988 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3990 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3991 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3992 [browsedSourceDisplayName stringByDeletingPathExtension],
3994 [[fDstFile2Field stringValue] pathExtension]]];
3997 /* Update chapter popups */
3998 [fSrcChapterStartPopUp removeAllItems];
3999 [fSrcChapterEndPopUp removeAllItems];
4000 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
4002 [fSrcChapterStartPopUp addItemWithTitle: [NSString
4003 stringWithFormat: @"%d", i + 1]];
4004 [fSrcChapterEndPopUp addItemWithTitle: [NSString
4005 stringWithFormat: @"%d", i + 1]];
4008 [fSrcChapterStartPopUp selectItemAtIndex: 0];
4009 [fSrcChapterEndPopUp selectItemAtIndex:
4010 hb_list_count( title->list_chapter ) - 1];
4011 [self chapterPopUpChanged:nil];
4013 /* if using dvd nav, show the angle widget */
4014 if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue])
4016 [fSrcAngleLabel setHidden:NO];
4017 [fSrcAnglePopUp setHidden:NO];
4019 [fSrcAnglePopUp removeAllItems];
4020 for( int i = 0; i < title->angle_count; i++ )
4022 [fSrcAnglePopUp addItemWithTitle: [NSString stringWithFormat: @"%d", i + 1]];
4024 [fSrcAnglePopUp selectItemAtIndex: 0];
4028 [fSrcAngleLabel setHidden:YES];
4029 [fSrcAnglePopUp setHidden:YES];
4032 /* Start Get and set the initial pic size for display */
4033 hb_job_t * job = title->job;
4036 /* Set Auto Crop to on upon selecting a new title */
4037 [fPictureController setAutoCrop:YES];
4039 /* We get the originial output picture width and height and put them
4040 in variables for use with some presets later on */
4041 PicOrigOutputWidth = job->width;
4042 PicOrigOutputHeight = job->height;
4043 AutoCropTop = job->crop[0];
4044 AutoCropBottom = job->crop[1];
4045 AutoCropLeft = job->crop[2];
4046 AutoCropRight = job->crop[3];
4048 /* Reset the new title in fPictureController && fPreviewController*/
4049 [fPictureController SetTitle:title];
4052 /* Update Subtitle Table */
4053 [fSubtitlesDelegate resetWithTitle:title];
4054 [fSubtitlesTable reloadData];
4057 /* Update chapter table */
4058 [fChapterTitlesDelegate resetWithTitle:title];
4059 [fChapterTable reloadData];
4061 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
4062 int audiotrack_count = hb_list_count(job->list_audio);
4063 for( int i = 0; i < audiotrack_count;i++)
4065 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4066 hb_list_rem(job->list_audio, temp_audio);
4069 /* Update audio popups */
4070 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
4071 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
4072 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
4073 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
4074 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
4075 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
4076 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
4077 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4078 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4079 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4081 /* changing the title may have changed the audio channels on offer, */
4082 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4083 [self audioTrackPopUpChanged: fAudLang1PopUp];
4084 [self audioTrackPopUpChanged: fAudLang2PopUp];
4085 [self audioTrackPopUpChanged: fAudLang3PopUp];
4086 [self audioTrackPopUpChanged: fAudLang4PopUp];
4088 [fVidRatePopUp selectItemAtIndex: 0];
4090 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
4091 [self calculatePictureSizing:nil];
4093 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
4094 [self selectPreset:nil];
4097 - (IBAction) chapterPopUpChanged: (id) sender
4100 /* If start chapter popup is greater than end chapter popup,
4101 we set the end chapter popup to the same as start chapter popup */
4102 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
4104 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
4108 hb_list_t * list = hb_get_titles( fHandle );
4109 hb_title_t * title = (hb_title_t *)
4110 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4112 hb_chapter_t * chapter;
4113 int64_t duration = 0;
4114 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
4115 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
4117 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
4118 duration += chapter->duration;
4121 duration /= 90000; /* pts -> seconds */
4122 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
4123 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
4126 [self calculateBitrate: sender];
4128 if ( [fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem] )
4130 /* Disable chapter markers for any source with less than two chapters as it makes no sense. */
4131 [fCreateChapterMarkers setEnabled: NO];
4132 [fCreateChapterMarkers setState: NSOffState];
4136 [fCreateChapterMarkers setEnabled: YES];
4140 - (IBAction) formatPopUpChanged: (id) sender
4142 NSString * string = [fDstFile2Field stringValue];
4143 int format = [fDstFormatPopUp indexOfSelectedItem];
4145 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
4146 [fDstMp4LargeFileCheck setHidden: YES];
4147 [fDstMp4HttpOptFileCheck setHidden: YES];
4148 [fDstMp4iPodFileCheck setHidden: YES];
4150 /* Update the Video Codec PopUp */
4151 /* lets get the tag of the currently selected item first so we might reset it later */
4152 int selectedVidEncoderTag;
4153 selectedVidEncoderTag = [[fVidEncoderPopUp selectedItem] tag];
4155 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
4156 [fVidEncoderPopUp removeAllItems];
4157 NSMenuItem *menuItem;
4158 /* These video encoders are available to all of our current muxers, so lets list them once here */
4159 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
4160 [menuItem setTag: HB_VCODEC_FFMPEG];
4165 /*Get Default MP4 File Extension*/
4166 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
4174 /* Add additional video encoders here */
4175 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4176 [menuItem setTag: HB_VCODEC_X264];
4177 /* We show the mp4 option checkboxes here since we are mp4 */
4178 [fCreateChapterMarkers setEnabled: YES];
4179 [fDstMp4LargeFileCheck setHidden: NO];
4180 [fDstMp4HttpOptFileCheck setHidden: NO];
4181 [fDstMp4iPodFileCheck setHidden: NO];
4186 /* Add additional video encoders here */
4187 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4188 [menuItem setTag: HB_VCODEC_X264];
4189 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
4190 [menuItem setTag: HB_VCODEC_THEORA];
4191 /* We enable the create chapters checkbox here */
4192 [fCreateChapterMarkers setEnabled: YES];
4197 /* tell fSubtitlesDelegate we have a new video container */
4199 [fSubtitlesDelegate containerChanged:[[fDstFormatPopUp selectedItem] tag]];
4200 [fSubtitlesTable reloadData];
4201 /* if we have a previously selected vid encoder tag, then try to select it */
4202 if (selectedVidEncoderTag)
4204 [fVidEncoderPopUp selectItemWithTag: selectedVidEncoderTag];
4208 [fVidEncoderPopUp selectItemAtIndex: 0];
4211 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4212 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4213 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4214 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4217 [self autoSetM4vExtension: sender];
4219 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
4221 if( SuccessfulScan )
4223 /* Add/replace to the correct extension */
4224 [self audioTrackPopUpChanged: fAudLang1PopUp];
4225 [self audioTrackPopUpChanged: fAudLang2PopUp];
4226 [self audioTrackPopUpChanged: fAudLang3PopUp];
4227 [self audioTrackPopUpChanged: fAudLang4PopUp];
4229 if( [fVidEncoderPopUp selectedItem] == nil )
4232 [fVidEncoderPopUp selectItemAtIndex:0];
4233 [self videoEncoderPopUpChanged:nil];
4235 /* changing the format may mean that we can / can't offer mono or 6ch, */
4236 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4238 /* We call the method to properly enable/disable turbo 2 pass */
4239 [self twoPassCheckboxChanged: sender];
4240 /* We call method method to change UI to reflect whether a preset is used or not*/
4243 [self customSettingUsed: sender];
4246 - (IBAction) autoSetM4vExtension: (id) sender
4248 if ( [fDstFormatPopUp indexOfSelectedItem] )
4251 NSString * extension = @"mp4";
4253 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4254 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4255 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4256 [fCreateChapterMarkers state] == NSOnState ||
4257 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
4262 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
4265 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
4266 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
4269 /* Method to determine if we should change the UI
4270 To reflect whether or not a Preset is being used or if
4271 the user is using "Custom" settings by determining the sender*/
4272 - (IBAction) customSettingUsed: (id) sender
4274 if ([sender stringValue])
4276 /* Deselect the currently selected Preset if there is one*/
4277 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
4278 /* Change UI to show "Custom" settings are being used */
4279 [fPresetSelectedDisplay setStringValue: @"Custom"];
4281 curUserPresetChosenNum = nil;
4283 [self calculateBitrate:nil];
4288 #pragma mark - Video
4290 - (IBAction) videoEncoderPopUpChanged: (id) sender
4292 hb_job_t * job = fTitle->job;
4293 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
4295 [fAdvancedOptions setHidden:YES];
4296 /* If we are using x264 then show the x264 advanced panel*/
4297 if (videoEncoder == HB_VCODEC_X264)
4299 [fAdvancedOptions setHidden:NO];
4300 [self autoSetM4vExtension: sender];
4303 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
4304 is being used as it borks up loose anamorphic .
4305 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
4306 to use the index itself but this is easier */
4307 if (videoEncoder == HB_VCODEC_FFMPEG)
4309 if (job->anamorphic.mode == 2)
4311 job->anamorphic.mode = 0;
4313 [fPictureController setAllowLooseAnamorphic:NO];
4314 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
4315 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
4316 anything other than MP4.
4318 [fDstMp4iPodFileCheck setEnabled: NO];
4319 [fDstMp4iPodFileCheck setState: NSOffState];
4323 [fPictureController setAllowLooseAnamorphic:YES];
4324 [fDstMp4iPodFileCheck setEnabled: YES];
4326 [self setupQualitySlider];
4327 [self calculatePictureSizing: sender];
4328 [self twoPassCheckboxChanged: sender];
4332 - (IBAction) twoPassCheckboxChanged: (id) sender
4334 /* check to see if x264 is chosen */
4335 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4337 if( [fVidTwoPassCheck state] == NSOnState)
4339 [fVidTurboPassCheck setHidden: NO];
4343 [fVidTurboPassCheck setHidden: YES];
4344 [fVidTurboPassCheck setState: NSOffState];
4346 /* Make sure Two Pass is checked if Turbo is checked */
4347 if( [fVidTurboPassCheck state] == NSOnState)
4349 [fVidTwoPassCheck setState: NSOnState];
4354 [fVidTurboPassCheck setHidden: YES];
4355 [fVidTurboPassCheck setState: NSOffState];
4358 /* We call method method to change UI to reflect whether a preset is used or not*/
4359 [self customSettingUsed: sender];
4362 - (IBAction ) videoFrameRateChanged: (id) sender
4364 /* We call method method to calculatePictureSizing to error check detelecine*/
4365 [self calculatePictureSizing: sender];
4367 /* We call method method to change UI to reflect whether a preset is used or not*/
4368 [self customSettingUsed: sender];
4370 - (IBAction) videoMatrixChanged: (id) sender;
4372 bool target, bitrate, quality;
4374 target = bitrate = quality = false;
4375 if( [fVidQualityMatrix isEnabled] )
4377 switch( [fVidQualityMatrix selectedRow] )
4390 [fVidTargetSizeField setEnabled: target];
4391 [fVidBitrateField setEnabled: bitrate];
4392 [fVidQualitySlider setEnabled: quality];
4393 [fVidQualityRFField setEnabled: quality];
4394 [fVidQualityRFLabel setEnabled: quality];
4395 [fVidTwoPassCheck setEnabled: !quality &&
4396 [fVidQualityMatrix isEnabled]];
4399 [fVidTwoPassCheck setState: NSOffState];
4400 [fVidTurboPassCheck setHidden: YES];
4401 [fVidTurboPassCheck setState: NSOffState];
4404 [self qualitySliderChanged: sender];
4405 [self calculateBitrate: sender];
4406 [self customSettingUsed: sender];
4409 /* Use this method to setup the quality slider for cq/rf values depending on
4410 * the video encoder selected.
4412 - (void) setupQualitySlider
4414 /* Get the current slider maxValue to check for a change in slider scale later
4415 * so that we can choose a new similar value on the new slider scale */
4416 float previousMaxValue = [fVidQualitySlider maxValue];
4417 float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1);
4418 NSString * qpRFLabelString = @"QP:";
4420 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4422 [fVidQualitySlider setMinValue:0.0];
4423 [fVidQualitySlider setMaxValue:51.0];
4424 /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
4425 int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
4426 [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
4427 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0)
4429 qpRFLabelString = @"RF:";
4433 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
4435 [fVidQualitySlider setMinValue:1.0];
4436 [fVidQualitySlider setMaxValue:31.0];
4437 [fVidQualitySlider setNumberOfTickMarks:31];
4440 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4442 [fVidQualitySlider setMinValue:0.0];
4443 [fVidQualitySlider setMaxValue:63.0];
4444 [fVidQualitySlider setNumberOfTickMarks:64];
4446 [fVidQualityRFLabel setStringValue:qpRFLabelString];
4448 /* check to see if we have changed slider scales */
4449 if (previousMaxValue != [fVidQualitySlider maxValue])
4451 /* if so, convert the old setting to the new scale as close as possible based on percentages */
4452 float rf = ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1) * previousPercentOfSliderScale;
4453 [fVidQualitySlider setFloatValue:rf];
4456 [self qualitySliderChanged:nil];
4459 - (IBAction) qualitySliderChanged: (id) sender
4461 /* Our constant quality slider is in a range based
4462 * on each encoders qp/rf values. The range depends
4463 * on the encoder. Also, the range is inverse of quality
4464 * for all of the encoders *except* for theora
4465 * (ie. as the "quality" goes up, the cq or rf value
4466 * actually goes down). Since the IB sliders always set
4467 * their max value at the right end of the slider, we
4468 * will calculate the inverse, so as the slider floatValue
4469 * goes up, we will show the inverse in the rf field
4470 * so, the floatValue at the right for x264 would be 51
4471 * and our rf field needs to show 0 and vice versa.
4474 float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue];
4475 /* If the encoder is theora, use the float, otherwise use the inverse float*/
4476 float sliderRfToPercent;
4477 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4479 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];
4480 sliderRfToPercent = [fVidQualityRFField floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4484 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]];
4485 sliderRfToPercent = ( ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - ([fVidQualityRFField floatValue] - [fVidQualitySlider minValue])) / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4487 [fVidConstantCell setTitle: [NSString stringWithFormat:
4488 NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]];
4490 [self customSettingUsed: sender];
4493 - (void) controlTextDidChange: (NSNotification *) notification
4495 [self calculateBitrate:nil];
4498 - (IBAction) calculateBitrate: (id) sender
4500 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
4505 hb_list_t * list = hb_get_titles( fHandle );
4506 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4507 [fSrcTitlePopUp indexOfSelectedItem] );
4508 hb_job_t * job = title->job;
4509 hb_audio_config_t * audio;
4510 /* For hb_calc_bitrate in addition to the Target Size in MB out of the
4511 * Target Size Field, we also need the job info for the Muxer, the Chapters
4512 * as well as all of the audio track info.
4513 * This used to be accomplished by simply calling prepareJob here, however
4514 * since the resilient queue sets the queue array values instead of the job
4515 * values directly, we duplicate the old prepareJob code here for the variables
4518 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
4519 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
4520 job->mux = [[fDstFormatPopUp selectedItem] tag];
4522 /* Audio goes here */
4523 int audiotrack_count = hb_list_count(job->list_audio);
4524 for( int i = 0; i < audiotrack_count;i++)
4526 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4527 hb_list_rem(job->list_audio, temp_audio);
4529 /* Now we need our audio info here for each track if applicable */
4530 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4532 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4533 hb_audio_config_init(audio);
4534 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4535 /* We go ahead and assign values to our audio->out.<properties> */
4536 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4537 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
4538 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
4539 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
4540 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
4541 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
4543 hb_audio_add( job, audio );
4546 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4548 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4549 hb_audio_config_init(audio);
4550 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4551 /* We go ahead and assign values to our audio->out.<properties> */
4552 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4553 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
4554 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
4555 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
4556 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
4557 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
4559 hb_audio_add( job, audio );
4564 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4566 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4567 hb_audio_config_init(audio);
4568 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4569 /* We go ahead and assign values to our audio->out.<properties> */
4570 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4571 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
4572 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
4573 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
4574 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
4575 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
4577 hb_audio_add( job, audio );
4582 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4584 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4585 hb_audio_config_init(audio);
4586 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4587 /* We go ahead and assign values to our audio->out.<properties> */
4588 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4589 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
4590 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
4591 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
4592 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
4593 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
4595 hb_audio_add( job, audio );
4600 [fVidBitrateField setIntValue: hb_calc_bitrate( job, [fVidTargetSizeField intValue] )];
4604 #pragma mark - Picture
4606 /* lets set the picture size back to the max from right after title scan
4607 Lets use an IBAction here as down the road we could always use a checkbox
4608 in the gui to easily take the user back to max. Remember, the compiler
4609 resolves IBActions down to -(void) during compile anyway */
4610 - (IBAction) revertPictureSizeToMax: (id) sender
4612 hb_job_t * job = fTitle->job;
4613 /* Here we apply the title source and height */
4614 job->width = fTitle->width;
4615 job->height = fTitle->height;
4617 [self calculatePictureSizing: sender];
4618 /* We call method to change UI to reflect whether a preset is used or not*/
4619 [self customSettingUsed: sender];
4623 * Registers changes made in the Picture Settings Window.
4626 - (void)pictureSettingsDidChange
4628 [self calculatePictureSizing:nil];
4631 /* Get and Display Current Pic Settings in main window */
4632 - (IBAction) calculatePictureSizing: (id) sender
4634 if (fTitle->job->anamorphic.mode > 0)
4636 fTitle->job->keep_ratio = 0;
4639 [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
4641 NSString *picCropping;
4642 /* Set the display field for crop as per boolean */
4643 if (![fPictureController autoCrop])
4645 picCropping = @"Custom";
4649 picCropping = @"Auto";
4651 picCropping = [picCropping stringByAppendingString:[NSString stringWithFormat:@" %d/%d/%d/%d",fTitle->job->crop[0],fTitle->job->crop[1],fTitle->job->crop[2],fTitle->job->crop[3]]];
4653 [fPictureCroppingField setStringValue: [NSString stringWithFormat:@"Picture Cropping: %@",picCropping]];
4655 NSString *videoFilters;
4658 if ([fPictureController detelecine] == 1)
4660 videoFilters = [videoFilters stringByAppendingString:@" - Detelecine (Default)"];
4662 else if ([fPictureController detelecine] == 2)
4664 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Detelecine (%@)",[fPictureController detelecineCustomString]]];
4668 if ([fPictureController useDecomb] == 1)
4671 if ([fPictureController decomb] == 1)
4673 videoFilters = [videoFilters stringByAppendingString:@" - Decomb (Default)"];
4675 else if ([fPictureController decomb] == 2)
4677 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Decomb (%@)",[fPictureController decombCustomString]]];
4683 if ([fPictureController deinterlace] > 0)
4685 fTitle->job->deinterlace = 1;
4689 fTitle->job->deinterlace = 0;
4692 if ([fPictureController deinterlace] == 1)
4694 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Fast)"];
4696 else if ([fPictureController deinterlace] == 2)
4698 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slow)"];
4700 else if ([fPictureController deinterlace] == 3)
4702 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slower)"];
4704 else if ([fPictureController deinterlace] == 4)
4706 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deinterlace (%@)",[fPictureController deinterlaceCustomString]]];
4712 if ([fPictureController denoise] == 1)
4714 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Weak)"];
4716 else if ([fPictureController denoise] == 2)
4718 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Medium)"];
4720 else if ([fPictureController denoise] == 3)
4722 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Strong)"];
4724 else if ([fPictureController denoise] == 4)
4726 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Denoise (%@)",[fPictureController denoiseCustomString]]];
4730 if ([fPictureController deblock] > 0)
4732 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deblock (%d)",[fPictureController deblock]]];
4736 if ([fPictureController grayscale])
4738 videoFilters = [videoFilters stringByAppendingString:@" - Grayscale"];
4740 [fVideoFiltersField setStringValue: [NSString stringWithFormat:@"Video Filters: %@", videoFilters]];
4742 //[fPictureController reloadStillPreview];
4747 #pragma mark - Audio and Subtitles
4748 - (IBAction) audioCodecsPopUpChanged: (id) sender
4751 NSPopUpButton * audiotrackPopUp;
4752 NSPopUpButton * sampleratePopUp;
4753 NSPopUpButton * bitratePopUp;
4754 NSPopUpButton * audiocodecPopUp;
4755 if (sender == fAudTrack1CodecPopUp)
4757 audiotrackPopUp = fAudLang1PopUp;
4758 audiocodecPopUp = fAudTrack1CodecPopUp;
4759 sampleratePopUp = fAudTrack1RatePopUp;
4760 bitratePopUp = fAudTrack1BitratePopUp;
4762 else if (sender == fAudTrack2CodecPopUp)
4764 audiotrackPopUp = fAudLang2PopUp;
4765 audiocodecPopUp = fAudTrack2CodecPopUp;
4766 sampleratePopUp = fAudTrack2RatePopUp;
4767 bitratePopUp = fAudTrack2BitratePopUp;
4769 else if (sender == fAudTrack3CodecPopUp)
4771 audiotrackPopUp = fAudLang3PopUp;
4772 audiocodecPopUp = fAudTrack3CodecPopUp;
4773 sampleratePopUp = fAudTrack3RatePopUp;
4774 bitratePopUp = fAudTrack3BitratePopUp;
4778 audiotrackPopUp = fAudLang4PopUp;
4779 audiocodecPopUp = fAudTrack4CodecPopUp;
4780 sampleratePopUp = fAudTrack4RatePopUp;
4781 bitratePopUp = fAudTrack4BitratePopUp;
4784 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
4785 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4786 [self audioTrackPopUpChanged: audiotrackPopUp];
4790 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
4792 /* We will be setting the enabled/disabled state of each tracks audio controls based on
4793 * the settings of the source audio for that track. We leave the samplerate and bitrate
4794 * to audiotrackMixdownChanged
4797 /* We will first verify that a lower track number has been selected before enabling each track
4798 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
4800 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4802 [fAudLang2PopUp setEnabled: NO];
4803 [fAudLang2PopUp selectItemAtIndex: 0];
4807 [fAudLang2PopUp setEnabled: YES];
4810 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4812 [fAudLang3PopUp setEnabled: NO];
4813 [fAudLang3PopUp selectItemAtIndex: 0];
4817 [fAudLang3PopUp setEnabled: YES];
4819 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4821 [fAudLang4PopUp setEnabled: NO];
4822 [fAudLang4PopUp selectItemAtIndex: 0];
4826 [fAudLang4PopUp setEnabled: YES];
4828 /* enable/disable the mixdown text and popupbutton for audio track 1 */
4829 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4830 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4831 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4832 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4833 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4834 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4835 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4837 [fAudTrack1CodecPopUp removeAllItems];
4838 [fAudTrack1MixPopUp removeAllItems];
4839 [fAudTrack1RatePopUp removeAllItems];
4840 [fAudTrack1BitratePopUp removeAllItems];
4841 [fAudTrack1DrcSlider setFloatValue: 1.00];
4842 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
4844 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4846 [fAudTrack1RatePopUp setEnabled: NO];
4847 [fAudTrack1BitratePopUp setEnabled: NO];
4848 [fAudTrack1DrcSlider setEnabled: NO];
4849 [fAudTrack1DrcField setEnabled: NO];
4852 /* enable/disable the mixdown text and popupbutton for audio track 2 */
4853 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4854 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4855 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4856 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4857 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4858 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4859 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4861 [fAudTrack2CodecPopUp removeAllItems];
4862 [fAudTrack2MixPopUp removeAllItems];
4863 [fAudTrack2RatePopUp removeAllItems];
4864 [fAudTrack2BitratePopUp removeAllItems];
4865 [fAudTrack2DrcSlider setFloatValue: 1.00];
4866 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
4868 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4870 [fAudTrack2RatePopUp setEnabled: NO];
4871 [fAudTrack2BitratePopUp setEnabled: NO];
4872 [fAudTrack2DrcSlider setEnabled: NO];
4873 [fAudTrack2DrcField setEnabled: NO];
4876 /* enable/disable the mixdown text and popupbutton for audio track 3 */
4877 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4878 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4879 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4880 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4881 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4882 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4883 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4885 [fAudTrack3CodecPopUp removeAllItems];
4886 [fAudTrack3MixPopUp removeAllItems];
4887 [fAudTrack3RatePopUp removeAllItems];
4888 [fAudTrack3BitratePopUp removeAllItems];
4889 [fAudTrack3DrcSlider setFloatValue: 1.00];
4890 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
4892 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4894 [fAudTrack3RatePopUp setEnabled: NO];
4895 [fAudTrack3BitratePopUp setEnabled: NO];
4896 [fAudTrack3DrcSlider setEnabled: NO];
4897 [fAudTrack3DrcField setEnabled: NO];
4900 /* enable/disable the mixdown text and popupbutton for audio track 4 */
4901 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4902 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4903 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4904 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4905 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4906 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4907 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
4909 [fAudTrack4CodecPopUp removeAllItems];
4910 [fAudTrack4MixPopUp removeAllItems];
4911 [fAudTrack4RatePopUp removeAllItems];
4912 [fAudTrack4BitratePopUp removeAllItems];
4913 [fAudTrack4DrcSlider setFloatValue: 1.00];
4914 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
4916 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4918 [fAudTrack4RatePopUp setEnabled: NO];
4919 [fAudTrack4BitratePopUp setEnabled: NO];
4920 [fAudTrack4DrcSlider setEnabled: NO];
4921 [fAudTrack4DrcField setEnabled: NO];
4926 - (IBAction) addAllAudioTracksToPopUp: (id) sender
4929 hb_list_t * list = hb_get_titles( fHandle );
4930 hb_title_t * title = (hb_title_t*)
4931 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4933 hb_audio_config_t * audio;
4935 [sender removeAllItems];
4936 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
4937 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
4939 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
4940 [[sender menu] addItemWithTitle:
4941 [NSString stringWithCString: audio->lang.description]
4942 action: NULL keyEquivalent: @""];
4944 [sender selectItemAtIndex: 0];
4948 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
4951 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
4952 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
4953 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
4954 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
4956 if (searchPrefixString)
4959 for( int i = 0; i < [sender numberOfItems]; i++ )
4961 /* Try to find the desired search string */
4962 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
4964 [sender selectItemAtIndex: i];
4968 /* couldn't find the string, so select the requested "search string not found" item */
4969 /* index of 0 means select the "none" item */
4970 /* index of 1 means select the first audio track */
4971 [sender selectItemAtIndex: selectIndexIfNotFound];
4975 /* if no search string is provided, then select the selectIndexIfNotFound item */
4976 [sender selectItemAtIndex: selectIndexIfNotFound];
4980 - (IBAction) audioAddAudioTrackCodecs: (id)sender
4982 int format = [fDstFormatPopUp indexOfSelectedItem];
4984 /* setup pointers to the appropriate popups for the correct track */
4985 NSPopUpButton * audiocodecPopUp;
4986 NSPopUpButton * audiotrackPopUp;
4987 if (sender == fAudTrack1CodecPopUp)
4989 audiotrackPopUp = fAudLang1PopUp;
4990 audiocodecPopUp = fAudTrack1CodecPopUp;
4992 else if (sender == fAudTrack2CodecPopUp)
4994 audiotrackPopUp = fAudLang2PopUp;
4995 audiocodecPopUp = fAudTrack2CodecPopUp;
4997 else if (sender == fAudTrack3CodecPopUp)
4999 audiotrackPopUp = fAudLang3PopUp;
5000 audiocodecPopUp = fAudTrack3CodecPopUp;
5004 audiotrackPopUp = fAudLang4PopUp;
5005 audiocodecPopUp = fAudTrack4CodecPopUp;
5008 [audiocodecPopUp removeAllItems];
5009 /* Make sure "None" isnt selected in the source track */
5010 if ([audiotrackPopUp indexOfSelectedItem] > 0)
5012 [audiocodecPopUp setEnabled:YES];
5013 NSMenuItem *menuItem;
5014 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
5020 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5021 [menuItem setTag: HB_ACODEC_FAAC];
5024 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5025 [menuItem setTag: HB_ACODEC_CA_AAC];
5028 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5029 [menuItem setTag: HB_ACODEC_AC3];
5035 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5036 [menuItem setTag: HB_ACODEC_FAAC];
5038 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5039 [menuItem setTag: HB_ACODEC_CA_AAC];
5041 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5042 [menuItem setTag: HB_ACODEC_AC3];
5044 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"DTS Passthru" action: NULL keyEquivalent: @""];
5045 [menuItem setTag: HB_ACODEC_DCA];
5047 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5048 [menuItem setTag: HB_ACODEC_LAME];
5050 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5051 [menuItem setTag: HB_ACODEC_VORBIS];
5057 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5058 [menuItem setTag: HB_ACODEC_LAME];
5060 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5061 [menuItem setTag: HB_ACODEC_AC3];
5067 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5068 [menuItem setTag: HB_ACODEC_VORBIS];
5070 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5071 [menuItem setTag: HB_ACODEC_LAME];
5074 [audiocodecPopUp selectItemAtIndex:0];
5078 [audiocodecPopUp setEnabled:NO];
5082 - (IBAction) audioTrackPopUpChanged: (id) sender
5084 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
5085 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
5088 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
5091 /* make sure we have a selected title before continuing */
5092 if (fTitle == NULL) return;
5093 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
5094 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
5096 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
5098 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
5100 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
5102 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
5104 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
5106 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
5108 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
5110 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
5113 /* Now lets make the sender the appropriate Audio Track popup from this point on */
5114 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
5116 sender = fAudLang1PopUp;
5118 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
5120 sender = fAudLang2PopUp;
5122 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
5124 sender = fAudLang3PopUp;
5126 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
5128 sender = fAudLang4PopUp;
5131 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
5132 NSPopUpButton * mixdownPopUp;
5133 NSPopUpButton * audiocodecPopUp;
5134 NSPopUpButton * sampleratePopUp;
5135 NSPopUpButton * bitratePopUp;
5136 if (sender == fAudLang1PopUp)
5138 mixdownPopUp = fAudTrack1MixPopUp;
5139 audiocodecPopUp = fAudTrack1CodecPopUp;
5140 sampleratePopUp = fAudTrack1RatePopUp;
5141 bitratePopUp = fAudTrack1BitratePopUp;
5143 else if (sender == fAudLang2PopUp)
5145 mixdownPopUp = fAudTrack2MixPopUp;
5146 audiocodecPopUp = fAudTrack2CodecPopUp;
5147 sampleratePopUp = fAudTrack2RatePopUp;
5148 bitratePopUp = fAudTrack2BitratePopUp;
5150 else if (sender == fAudLang3PopUp)
5152 mixdownPopUp = fAudTrack3MixPopUp;
5153 audiocodecPopUp = fAudTrack3CodecPopUp;
5154 sampleratePopUp = fAudTrack3RatePopUp;
5155 bitratePopUp = fAudTrack3BitratePopUp;
5159 mixdownPopUp = fAudTrack4MixPopUp;
5160 audiocodecPopUp = fAudTrack4CodecPopUp;
5161 sampleratePopUp = fAudTrack4RatePopUp;
5162 bitratePopUp = fAudTrack4BitratePopUp;
5165 /* get the index of the selected audio Track*/
5166 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
5168 /* pointer for the hb_audio_s struct we will use later on */
5169 hb_audio_config_t * audio;
5172 /* check if the audio mixdown controls need their enabled state changing */
5173 [self setEnabledStateOfAudioMixdownControls:nil];
5175 if (thisAudioIndex != -1)
5179 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
5181 /* actually manipulate the proper mixdowns here */
5182 /* delete the previous audio mixdown options */
5183 [mixdownPopUp removeAllItems];
5185 acodec = [[audiocodecPopUp selectedItem] tag];
5190 /* find out if our selected output audio codec supports mono and / or 6ch */
5191 /* we also check for an input codec of AC3 or DCA,
5192 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
5193 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
5194 but this may change in the future, so they are separated for flexibility */
5195 int audioCodecsSupportMono =
5196 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5197 (acodec != HB_ACODEC_LAME);
5198 int audioCodecsSupport6Ch =
5199 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5200 (acodec != HB_ACODEC_LAME);
5202 /* check for AC-3 passthru */
5203 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5206 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5207 [NSString stringWithCString: "AC3 Passthru"]
5208 action: NULL keyEquivalent: @""];
5209 [menuItem setTag: HB_ACODEC_AC3];
5211 else if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5213 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5214 [NSString stringWithCString: "DTS Passthru"]
5215 action: NULL keyEquivalent: @""];
5216 [menuItem setTag: HB_ACODEC_DCA];
5221 /* add the appropriate audio mixdown menuitems to the popupbutton */
5222 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
5223 so that we can reference the mixdown later */
5225 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
5226 int minMixdownUsed = 0;
5227 int maxMixdownUsed = 0;
5229 /* get the input channel layout without any lfe channels */
5230 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
5232 /* do we want to add a mono option? */
5233 if (audioCodecsSupportMono == 1)
5235 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5236 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
5237 action: NULL keyEquivalent: @""];
5238 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
5239 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
5240 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
5243 /* do we want to add a stereo option? */
5244 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
5245 /* also offer stereo if we have a stereo-or-better source */
5246 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
5248 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5249 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
5250 action: NULL keyEquivalent: @""];
5251 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
5252 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
5253 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
5256 /* do we want to add a dolby surround (DPL1) option? */
5257 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
5259 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5260 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
5261 action: NULL keyEquivalent: @""];
5262 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
5263 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
5264 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
5267 /* do we want to add a dolby pro logic 2 (DPL2) option? */
5268 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
5270 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5271 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
5272 action: NULL keyEquivalent: @""];
5273 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
5274 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
5275 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
5278 /* do we want to add a 6-channel discrete option? */
5279 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
5281 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5282 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
5283 action: NULL keyEquivalent: @""];
5284 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
5285 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
5286 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
5289 /* do we want to add an AC-3 passthrough option? */
5290 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5292 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5293 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5294 action: NULL keyEquivalent: @""];
5295 [menuItem setTag: HB_ACODEC_AC3];
5296 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5297 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5300 /* do we want to add a DTS Passthru option ? HB_ACODEC_DCA*/
5301 if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5303 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5304 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5305 action: NULL keyEquivalent: @""];
5306 [menuItem setTag: HB_ACODEC_DCA];
5307 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5308 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5311 /* auto-select the best mixdown based on our saved mixdown preference */
5313 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
5314 /* ultimately this should be a prefs option */
5317 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
5318 if (mixdownToUse > 0)
5320 useMixdown = mixdownToUse;
5324 useMixdown = HB_AMIXDOWN_DOLBYPLII;
5327 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
5328 if (useMixdown > maxMixdownUsed)
5330 useMixdown = maxMixdownUsed;
5333 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
5334 if (useMixdown < minMixdownUsed)
5336 useMixdown = minMixdownUsed;
5339 /* select the (possibly-amended) preferred mixdown */
5340 [mixdownPopUp selectItemWithTag: useMixdown];
5343 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
5344 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5347 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
5349 /* If we are using the avi container, we select MP3 as there is no aac available*/
5350 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5352 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5356 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5360 /* In the case of a source track that is not DTS and the user tries to use DTS Passthru (which does not work)
5361 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5364 if (audio->in.codec != HB_ACODEC_DCA && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_DCA)
5366 /* If we are using the avi container, we select MP3 as there is no aac available*/
5367 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5369 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5373 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5377 /* Setup our samplerate and bitrate popups we will need based on mixdown */
5378 [self audioTrackMixdownChanged: mixdownPopUp];
5382 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
5384 [self autoSetM4vExtension: sender];
5388 - (IBAction) audioTrackMixdownChanged: (id) sender
5392 /* setup pointers to all of the other audio track controls
5393 * we will need later
5395 NSPopUpButton * mixdownPopUp;
5396 NSPopUpButton * sampleratePopUp;
5397 NSPopUpButton * bitratePopUp;
5398 NSPopUpButton * audiocodecPopUp;
5399 NSPopUpButton * audiotrackPopUp;
5400 NSSlider * drcSlider;
5401 NSTextField * drcField;
5402 if (sender == fAudTrack1MixPopUp)
5404 audiotrackPopUp = fAudLang1PopUp;
5405 audiocodecPopUp = fAudTrack1CodecPopUp;
5406 mixdownPopUp = fAudTrack1MixPopUp;
5407 sampleratePopUp = fAudTrack1RatePopUp;
5408 bitratePopUp = fAudTrack1BitratePopUp;
5409 drcSlider = fAudTrack1DrcSlider;
5410 drcField = fAudTrack1DrcField;
5412 else if (sender == fAudTrack2MixPopUp)
5414 audiotrackPopUp = fAudLang2PopUp;
5415 audiocodecPopUp = fAudTrack2CodecPopUp;
5416 mixdownPopUp = fAudTrack2MixPopUp;
5417 sampleratePopUp = fAudTrack2RatePopUp;
5418 bitratePopUp = fAudTrack2BitratePopUp;
5419 drcSlider = fAudTrack2DrcSlider;
5420 drcField = fAudTrack2DrcField;
5422 else if (sender == fAudTrack3MixPopUp)
5424 audiotrackPopUp = fAudLang3PopUp;
5425 audiocodecPopUp = fAudTrack3CodecPopUp;
5426 mixdownPopUp = fAudTrack3MixPopUp;
5427 sampleratePopUp = fAudTrack3RatePopUp;
5428 bitratePopUp = fAudTrack3BitratePopUp;
5429 drcSlider = fAudTrack3DrcSlider;
5430 drcField = fAudTrack3DrcField;
5434 audiotrackPopUp = fAudLang4PopUp;
5435 audiocodecPopUp = fAudTrack4CodecPopUp;
5436 mixdownPopUp = fAudTrack4MixPopUp;
5437 sampleratePopUp = fAudTrack4RatePopUp;
5438 bitratePopUp = fAudTrack4BitratePopUp;
5439 drcSlider = fAudTrack4DrcSlider;
5440 drcField = fAudTrack4DrcField;
5442 acodec = [[audiocodecPopUp selectedItem] tag];
5443 /* storage variable for the min and max bitrate allowed for this codec */
5449 case HB_ACODEC_FAAC:
5450 /* check if we have a 6ch discrete conversion in either audio track */
5451 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5453 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
5455 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5461 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
5463 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
5464 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
5469 case HB_ACODEC_CA_AAC:
5470 /* check if we have a 6ch discrete conversion in either audio track */
5471 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5484 case HB_ACODEC_LAME:
5485 /* Lame is happy using our min bitrate of 32 kbps */
5487 /* Lame won't encode if the bitrate is higher than 320 kbps */
5491 case HB_ACODEC_VORBIS:
5492 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5494 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
5496 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5502 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
5504 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
5510 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
5516 /* make sure we have a selected title before continuing */
5517 if (fTitle == NULL) return;
5518 /* get the audio so we can find out what input rates are*/
5519 hb_audio_config_t * audio;
5520 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
5521 int inputbitrate = audio->in.bitrate / 1000;
5522 int inputsamplerate = audio->in.samplerate;
5524 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3 && [[mixdownPopUp selectedItem] tag] != HB_ACODEC_DCA)
5526 [bitratePopUp removeAllItems];
5528 for( int i = 0; i < hb_audio_bitrates_count; i++ )
5530 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
5532 /* add a new menuitem for this bitrate */
5533 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5534 [NSString stringWithCString: hb_audio_bitrates[i].string]
5535 action: NULL keyEquivalent: @""];
5536 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
5537 [menuItem setTag: hb_audio_bitrates[i].rate];
5541 /* select the default bitrate (but use 384 for 6-ch AAC) */
5542 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5544 [bitratePopUp selectItemWithTag: 384];
5548 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
5551 /* populate and set the sample rate popup */
5552 /* Audio samplerate */
5553 [sampleratePopUp removeAllItems];
5554 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
5555 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
5556 [menuItem setTag: inputsamplerate];
5558 for( int i = 0; i < hb_audio_rates_count; i++ )
5560 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
5561 [NSString stringWithCString: hb_audio_rates[i].string]
5562 action: NULL keyEquivalent: @""];
5563 [menuItem setTag: hb_audio_rates[i].rate];
5565 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
5566 * and there is no compelling reason to use anything else as default, though the users default
5567 * preset will likely override any setting chosen here.
5569 [sampleratePopUp selectItemWithTag: inputsamplerate];
5572 /* Since AC3 Pass Thru and DTS Pass Thru uses the input bitrate and sample rate, we get the input tracks
5573 * bitrate and display it in the bitrate popup even though libhb happily ignores any bitrate input from
5574 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
5576 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[mixdownPopUp selectedItem] tag] == HB_ACODEC_DCA)
5579 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
5580 [bitratePopUp removeAllItems];
5581 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5582 [NSString stringWithFormat:@"%d", inputbitrate]
5583 action: NULL keyEquivalent: @""];
5584 [menuItem setTag: inputbitrate];
5585 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
5586 [bitratePopUp setEnabled: NO];
5587 [sampleratePopUp setEnabled: NO];
5589 [drcSlider setFloatValue: 1.00];
5590 [self audioDRCSliderChanged: drcSlider];
5591 [drcSlider setEnabled: NO];
5592 [drcField setEnabled: NO];
5596 [sampleratePopUp setEnabled: YES];
5597 [bitratePopUp setEnabled: YES];
5598 [drcSlider setEnabled: YES];
5599 [drcField setEnabled: YES];
5601 [self calculateBitrate:nil];
5604 - (IBAction) audioDRCSliderChanged: (id) sender
5606 NSSlider * drcSlider;
5607 NSTextField * drcField;
5608 if (sender == fAudTrack1DrcSlider)
5610 drcSlider = fAudTrack1DrcSlider;
5611 drcField = fAudTrack1DrcField;
5613 else if (sender == fAudTrack2DrcSlider)
5615 drcSlider = fAudTrack2DrcSlider;
5616 drcField = fAudTrack2DrcField;
5618 else if (sender == fAudTrack3DrcSlider)
5620 drcSlider = fAudTrack3DrcSlider;
5621 drcField = fAudTrack3DrcField;
5625 drcSlider = fAudTrack4DrcSlider;
5626 drcField = fAudTrack4DrcField;
5629 /* If we are between 0.0 and 1.0 on the slider, snap it to 1.0 */
5630 if ([drcSlider floatValue] > 0.0 && [drcSlider floatValue] < 1.0)
5632 [drcSlider setFloatValue:1.0];
5636 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
5637 /* For now, do not call this until we have an intelligent way to determine audio track selections
5638 * compared to presets
5640 //[self customSettingUsed: sender];
5645 #pragma mark Open New Windows
5647 - (IBAction) openHomepage: (id) sender
5649 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5650 URLWithString:@"http://handbrake.fr/"]];
5653 - (IBAction) openForums: (id) sender
5655 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5656 URLWithString:@"http://handbrake.fr/forum/"]];
5658 - (IBAction) openUserGuide: (id) sender
5660 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5661 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
5665 * Shows debug output window.
5667 - (IBAction)showDebugOutputPanel:(id)sender
5669 [outputPanel showOutputPanel:sender];
5673 * Shows preferences window.
5675 - (IBAction) showPreferencesWindow: (id) sender
5677 NSWindow * window = [fPreferencesController window];
5678 if (![window isVisible])
5681 [window makeKeyAndOrderFront: nil];
5685 * Shows queue window.
5687 - (IBAction) showQueueWindow:(id)sender
5689 [fQueueController showQueueWindow:sender];
5693 - (IBAction) toggleDrawer:(id)sender {
5694 [fPresetDrawer toggle:self];
5698 * Shows Picture Settings Window.
5701 - (IBAction) showPicturePanel: (id) sender
5703 [fPictureController showPictureWindow:sender];
5706 - (void) picturePanelFullScreen
5708 [fPictureController setToFullScreenMode];
5711 - (void) picturePanelWindowed
5713 [fPictureController setToWindowedMode];
5716 - (IBAction) showPreviewWindow: (id) sender
5718 [fPictureController showPreviewWindow:sender];
5722 #pragma mark Preset Outline View Methods
5723 #pragma mark - Required
5724 /* These are required by the NSOutlineView Datasource Delegate */
5727 /* used to specify the number of levels to show for each item */
5728 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
5730 /* currently use no levels to test outline view viability */
5731 if (item == nil) // for an outline view the root level of the hierarchy is always nil
5733 return [UserPresets count];
5737 /* we need to return the count of the array in ChildrenArray for this folder */
5738 NSArray *children = nil;
5739 children = [item objectForKey:@"ChildrenArray"];
5740 if ([children count] > 0)
5742 return [children count];
5751 /* We use this to deterimine children of an item */
5752 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
5755 /* we need to return the count of the array in ChildrenArray for this folder */
5756 NSArray *children = nil;
5759 children = UserPresets;
5763 if ([item objectForKey:@"ChildrenArray"])
5765 children = [item objectForKey:@"ChildrenArray"];
5768 if ((children == nil) || ( [children count] <= (NSUInteger) index))
5774 return [children objectAtIndex:index];
5778 // We are only one level deep, so we can't be asked about children
5779 //NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
5783 /* We use this to determine if an item should be expandable */
5784 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
5787 /* we need to return the count of the array in ChildrenArray for this folder */
5788 NSArray *children= nil;
5791 children = UserPresets;
5795 if ([item objectForKey:@"ChildrenArray"])
5797 children = [item objectForKey:@"ChildrenArray"];
5801 /* To deterimine if an item should show a disclosure triangle
5802 * we could do it by the children count as so:
5803 * if ([children count] < 1)
5804 * However, lets leave the triangle show even if there are no
5805 * children to help indicate a folder, just like folder in the
5806 * finder can show a disclosure triangle even when empty
5809 /* We need to determine if the item is a folder */
5810 if ([[item objectForKey:@"Folder"] intValue] == 1)
5821 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
5823 // Our outline view has no levels, but we can still expand every item. Doing so
5824 // just makes the row taller. See heightOfRowByItem below.
5825 //return ![(HBQueueOutlineView*)outlineView isDragging];
5831 /* Used to tell the outline view which information is to be displayed per item */
5832 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5834 /* We have two columns right now, icon and PresetName */
5836 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5838 return [item objectForKey:@"PresetName"];
5847 - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object
5849 return [NSKeyedUnarchiver unarchiveObjectWithData:object];
5851 - (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item
5853 return [NSKeyedArchiver archivedDataWithRootObject:item];
5856 #pragma mark - Added Functionality (optional)
5857 /* Use to customize the font and display characteristics of the title cell */
5858 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
5860 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5864 NSColor *shadowColor;
5865 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
5866 /*check to see if its a selected row */
5867 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
5870 fontColor = [NSColor blackColor];
5871 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
5875 if ([[item objectForKey:@"Type"] intValue] == 0)
5877 fontColor = [NSColor blueColor];
5879 else // User created preset, use a black font
5881 fontColor = [NSColor blackColor];
5883 /* check to see if its a folder */
5884 //if ([[item objectForKey:@"Folder"] intValue] == 1)
5886 //fontColor = [NSColor greenColor];
5891 /* We use Bold Text for the HB Default */
5892 if ([[item objectForKey:@"Default"] intValue] == 1)// 1 is HB default
5894 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5896 /* We use Bold Text for the User Specified Default */
5897 if ([[item objectForKey:@"Default"] intValue] == 2)// 2 is User default
5899 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5903 [cell setTextColor:fontColor];
5904 [cell setFont:txtFont];
5909 /* We use this to edit the name field in the outline view */
5910 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5912 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5917 [theRecord setObject:object forKey:@"PresetName"];
5921 [fPresetsOutlineView reloadData];
5922 /* We save all of the preset data here */
5926 /* We use this to provide tooltips for the items in the presets outline view */
5927 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
5929 //if ([[tc identifier] isEqualToString:@"PresetName"])
5931 /* initialize the tooltip contents variable */
5933 /* if there is a description for the preset, we show it in the tooltip */
5934 if ([item objectForKey:@"PresetDescription"])
5936 loc_tip = [item objectForKey:@"PresetDescription"];
5941 loc_tip = @"No description available";
5948 #pragma mark Preset Outline View Methods (dragging related)
5951 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
5953 // Dragging is only allowed for custom presets.
5954 //[[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1
5955 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
5959 // Don't retain since this is just holding temporaral drag information, and it is
5960 //only used during a drag! We could put this in the pboard actually.
5961 fDraggedNodes = items;
5962 // Provide data for our custom type, and simple NSStrings.
5963 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
5965 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
5966 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
5971 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
5974 // Don't allow dropping ONTO an item since they can't really contain any children.
5976 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
5977 if (isOnDropTypeProposal)
5978 return NSDragOperationNone;
5980 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
5983 index = [fPresetsOutlineView rowForItem: item] + 1;
5987 // Don't allow dropping into the Built In Presets.
5988 if (index < presetCurrentBuiltInCount)
5990 return NSDragOperationNone;
5991 index = MAX (index, presetCurrentBuiltInCount);
5994 [outlineView setDropItem:item dropChildIndex:index];
5995 return NSDragOperationGeneric;
6000 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
6002 /* first, lets see if we are dropping into a folder */
6003 if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
6005 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6006 childrenArray = [[fPresetsOutlineView itemAtRow:index] objectForKey:@"ChildrenArray"];
6007 [childrenArray addObject:item];
6008 [[fPresetsOutlineView itemAtRow:index] setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6009 [childrenArray autorelease];
6011 else // We are not, so we just move the preset into the existing array
6013 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
6015 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
6016 while (obj = [enumerator nextObject])
6018 [moveItems addIndex:[UserPresets indexOfObject:obj]];
6020 // Successful drop, lets rearrange the view and save it all
6021 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
6023 [fPresetsOutlineView reloadData];
6028 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
6030 NSUInteger index = [indexSet lastIndex];
6031 NSUInteger aboveInsertIndexCount = 0;
6033 NSUInteger removeIndex;
6035 if (index >= insertIndex)
6037 removeIndex = index + aboveInsertIndexCount;
6038 aboveInsertIndexCount++;
6042 removeIndex = index;
6046 id object = [[array objectAtIndex:removeIndex] retain];
6047 [array removeObjectAtIndex:removeIndex];
6048 [array insertObject:object atIndex:insertIndex];
6051 index = [indexSet indexLessThanIndex:index];
6056 #pragma mark - Functional Preset NSOutlineView Methods
6058 - (IBAction)selectPreset:(id)sender
6061 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
6063 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6064 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6066 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
6068 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
6072 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6076 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
6077 [self formatPopUpChanged:nil];
6079 /* Chapter Markers*/
6080 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
6081 /* check to see if we have only one chapter */
6082 [self chapterPopUpChanged:nil];
6084 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6085 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
6086 /* Mux mp4 with http optimization */
6087 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
6090 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
6091 /* We set the advanced opt string here if applicable*/
6092 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
6094 /* Lets run through the following functions to get variables set there */
6095 [self videoEncoderPopUpChanged:nil];
6096 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
6097 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
6098 [self calculateBitrate:nil];
6101 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
6103 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
6104 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
6106 /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float.
6107 * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type
6108 * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret
6109 * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet,
6110 * though it should be a corner case since it would pretty much be a preset for lossless encoding. */
6111 if ([[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue] < 1.0)
6113 /* For the quality slider we need to convert the old percent's to the new rf scales */
6114 float rf = (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]);
6115 [fVidQualitySlider setFloatValue:rf];
6120 [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6123 [self videoMatrixChanged:nil];
6125 /* Video framerate */
6126 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
6127 detected framerate in the fVidRatePopUp so we use index 0*/
6128 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
6130 [fVidRatePopUp selectItemAtIndex: 0];
6134 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
6138 /* 2 Pass Encoding */
6139 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
6140 [self twoPassCheckboxChanged:nil];
6142 /* Turbo 1st pass for 2 Pass Encoding */
6143 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
6146 /* First we check to see if we are using the current audio track layout based on AudioList array */
6147 if ([chosenPreset objectForKey:@"AudioList"])
6149 /* Populate the audio widgets based on the contents of the AudioList array */
6151 NSEnumerator *enumerator = [[chosenPreset objectForKey:@"AudioList"] objectEnumerator];
6153 while (tempObject = [enumerator nextObject])
6158 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6160 [fAudLang1PopUp selectItemAtIndex: 1];
6162 [self audioTrackPopUpChanged: fAudLang1PopUp];
6163 [fAudTrack1CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6164 /* check our pref for core audio and use it in place of faac if applicable */
6165 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6166 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6168 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6171 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6172 [fAudTrack1MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6173 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6175 if ([fAudTrack1MixPopUp selectedItem] == nil)
6177 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6179 [fAudTrack1RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6180 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6181 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6183 [fAudTrack1BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6185 [fAudTrack1DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6186 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6192 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6194 [fAudLang2PopUp selectItemAtIndex: 1];
6196 [self audioTrackPopUpChanged: fAudLang2PopUp];
6197 [fAudTrack2CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6198 /* check our pref for core audio and use it in place of faac if applicable */
6199 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6200 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6202 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6204 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6205 [fAudTrack2MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6206 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6208 if ([fAudTrack2MixPopUp selectedItem] == nil)
6210 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6212 [fAudTrack2RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6213 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6214 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6216 [fAudTrack2BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6218 [fAudTrack2DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6219 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6225 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6229 [fAudLang4PopUp selectItemAtIndex: 0];
6230 [self audioTrackPopUpChanged: fAudLang4PopUp];
6234 [fAudLang3PopUp selectItemAtIndex: 0];
6235 [self audioTrackPopUpChanged: fAudLang3PopUp];
6239 [fAudLang2PopUp selectItemAtIndex: 0];
6240 [self audioTrackPopUpChanged: fAudLang2PopUp];
6248 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
6250 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6252 [fAudLang1PopUp selectItemAtIndex: 1];
6254 [self audioTrackPopUpChanged: fAudLang1PopUp];
6255 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
6256 /* check our pref for core audio and use it in place of faac if applicable */
6257 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6258 [[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString: @"AAC (faac)"])
6260 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6262 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6263 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
6264 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6266 if ([fAudTrack1MixPopUp selectedItem] == nil)
6268 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6270 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
6271 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6272 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
6274 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
6276 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
6277 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6279 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
6281 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6283 [fAudLang2PopUp selectItemAtIndex: 1];
6285 [self audioTrackPopUpChanged: fAudLang2PopUp];
6286 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
6287 /* check our pref for core audio and use it in place of faac if applicable */
6288 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6289 [[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString: @"AAC (faac)"])
6291 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6293 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6294 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
6295 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6297 if ([fAudTrack2MixPopUp selectedItem] == nil)
6299 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6301 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
6302 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6303 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
6305 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
6307 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
6308 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6310 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
6312 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
6314 [fAudLang3PopUp selectItemAtIndex: 1];
6316 [self audioTrackPopUpChanged: fAudLang3PopUp];
6317 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
6318 /* check our pref for core audio and use it in place of faac if applicable */
6319 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6320 [[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AAC (faac)"])
6322 [fAudTrack3CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6324 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6325 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
6326 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6328 if ([fAudTrack3MixPopUp selectedItem] == nil)
6330 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6332 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
6333 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6334 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
6336 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
6338 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
6339 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
6341 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
6343 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
6345 [fAudLang4PopUp selectItemAtIndex: 1];
6347 [self audioTrackPopUpChanged: fAudLang4PopUp];
6348 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
6349 /* check our pref for core audio and use it in place of faac if applicable */
6350 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6351 [[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString: @"AAC (faac)"])
6353 [fAudTrack4CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6355 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6356 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
6357 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6359 if ([fAudTrack4MixPopUp selectedItem] == nil)
6361 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6363 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
6364 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6365 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
6367 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
6369 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
6370 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
6373 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6375 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
6377 [fAudLang2PopUp selectItemAtIndex: 0];
6378 [self audioTrackPopUpChanged: fAudLang2PopUp];
6380 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
6382 [fAudLang3PopUp selectItemAtIndex: 0];
6383 [self audioTrackPopUpChanged: fAudLang3PopUp];
6385 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
6387 [fAudLang4PopUp selectItemAtIndex: 0];
6388 [self audioTrackPopUpChanged: fAudLang4PopUp];
6393 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
6394 /* Forced Subtitles */
6395 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
6397 /* Picture Settings */
6398 /* Note: objectForKey:@"UsesPictureSettings" refers to picture size, which encompasses:
6399 * height, width, keep ar, anamorphic and crop settings.
6400 * picture filters are handled separately below.
6402 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
6403 * ( 2 is use max for source and 1 is use exact size when the preset was created ) and the
6404 * preset completely ignores any picture sizing values in the preset.
6406 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
6408 hb_job_t * job = fTitle->job;
6410 /* If Cropping is set to custom, then recall all four crop values from
6411 when the preset was created and apply them */
6412 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
6414 [fPictureController setAutoCrop:NO];
6416 /* Here we use the custom crop values saved at the time the preset was saved */
6417 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
6418 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
6419 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
6420 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
6423 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
6425 [fPictureController setAutoCrop:YES];
6426 /* Here we use the auto crop values determined right after scan */
6427 job->crop[0] = AutoCropTop;
6428 job->crop[1] = AutoCropBottom;
6429 job->crop[2] = AutoCropLeft;
6430 job->crop[3] = AutoCropRight;
6435 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
6436 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
6438 /* Use Max Picture settings for whatever the dvd is.*/
6439 [self revertPictureSizeToMax:nil];
6440 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6441 if (job->keep_ratio == 1)
6443 hb_fix_aspect( job, HB_KEEP_WIDTH );
6444 if( job->height > fTitle->height )
6446 job->height = fTitle->height;
6447 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6450 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6452 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
6454 /* we check to make sure the presets width/height does not exceed the sources width/height */
6455 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
6457 /* if so, then we use the sources height and width to avoid scaling up */
6458 //job->width = fTitle->width;
6459 //job->height = fTitle->height;
6460 [self revertPictureSizeToMax:nil];
6462 else // source width/height is >= the preset height/width
6464 /* we can go ahead and use the presets values for height and width */
6465 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
6466 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
6468 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6469 if (job->keep_ratio == 1)
6471 hb_fix_aspect( job, HB_KEEP_WIDTH );
6472 if( job->height > fTitle->height )
6474 job->height = fTitle->height;
6475 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6478 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6484 /* If the preset has an objectForKey:@"UsesPictureFilters", and handle the filters here */
6485 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
6489 /* We only allow *either* Decomb or Deinterlace. So check for the PictureDecombDeinterlace key.
6490 * also, older presets may not have this key, in which case we also check to see if that preset had PictureDecomb
6491 * specified, in which case we use decomb and ignore any possible Deinterlace settings as using both was less than
6494 [fPictureController setUseDecomb:1];
6495 [fPictureController setDecomb:0];
6496 [fPictureController setDeinterlace:0];
6497 if ([[chosenPreset objectForKey:@"PictureDecombDeinterlace"] intValue] == 1 || [[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6499 /* we are using decomb */
6501 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6503 [fPictureController setDecomb:[[chosenPreset objectForKey:@"PictureDecomb"] intValue]];
6505 /* if we are using "Custom" in the decomb setting, also set the custom string*/
6506 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] == 2)
6508 [fPictureController setDecombCustomString:[chosenPreset objectForKey:@"PictureDecombCustom"]];
6514 /* We are using Deinterlace */
6516 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] > 0)
6518 [fPictureController setUseDecomb:0];
6519 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
6520 /* if we are using "Custom" in the deinterlace setting, also set the custom string*/
6521 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
6523 [fPictureController setDeinterlaceCustomString:[chosenPreset objectForKey:@"PictureDeinterlaceCustom"]];
6530 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] > 0)
6532 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
6533 /* if we are using "Custom" in the detelecine setting, also set the custom string*/
6534 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 2)
6536 [fPictureController setDetelecineCustomString:[chosenPreset objectForKey:@"PictureDetelecineCustom"]];
6541 [fPictureController setDetelecine:0];
6545 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] > 0)
6547 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
6548 /* if we are using "Custom" in the denoise setting, also set the custom string*/
6549 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] == 4)
6551 [fPictureController setDenoiseCustomString:[chosenPreset objectForKey:@"PictureDenoiseCustom"]];
6556 [fPictureController setDenoise:0];
6560 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
6562 /* if its a one, then its the old on/off deblock, set on to 5*/
6563 [fPictureController setDeblock:5];
6567 /* use the settings intValue */
6568 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
6571 if ([[chosenPreset objectForKey:@"VideoGrayScale"] intValue] == 1)
6573 [fPictureController setGrayscale:1];
6577 [fPictureController setGrayscale:0];
6580 /* we call SetTitle: in fPictureController so we get an instant update in the Picture Settings window */
6581 [fPictureController SetTitle:fTitle];
6582 [fPictureController SetTitle:fTitle];
6583 [self calculatePictureSizing:nil];
6589 #pragma mark Manage Presets
6591 - (void) loadPresets {
6592 /* We declare the default NSFileManager into fileManager */
6593 NSFileManager * fileManager = [NSFileManager defaultManager];
6594 /*We define the location of the user presets file */
6595 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
6596 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
6597 /* We check for the presets.plist */
6598 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
6600 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
6603 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
6604 if (nil == UserPresets)
6606 UserPresets = [[NSMutableArray alloc] init];
6607 [self addFactoryPresets:nil];
6609 [fPresetsOutlineView reloadData];
6611 [self checkBuiltInsForUpdates];
6614 - (void) checkBuiltInsForUpdates {
6616 BOOL updateBuiltInPresets = NO;
6618 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6620 while (tempObject = [enumerator nextObject])
6622 /* iterate through the built in presets to see if any have an old build number */
6623 NSMutableDictionary *thisPresetDict = tempObject;
6624 /*Key Type == 0 is built in, and key PresetBuildNumber is the build number it was created with */
6625 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0)
6627 if (![thisPresetDict objectForKey:@"PresetBuildNumber"] || [[thisPresetDict objectForKey:@"PresetBuildNumber"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue])
6629 updateBuiltInPresets = YES;
6634 /* if we have built in presets to update, then do so AlertBuiltInPresetUpdate*/
6635 if ( updateBuiltInPresets == YES)
6637 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"AlertBuiltInPresetUpdate"] == YES)
6639 /* Show an alert window that built in presets will be updated */
6640 /*On Screen Notification*/
6643 status = NSRunAlertPanel(@"HandBrake has determined your built in presets are out of date...",@"HandBrake will now update your built-in presets.", @"OK", nil, nil);
6644 [NSApp requestUserAttention:NSCriticalRequest];
6646 /* when alert is dismissed, go ahead and update the built in presets */
6647 [self addFactoryPresets:nil];
6653 - (IBAction) showAddPresetPanel: (id) sender
6655 /* Deselect the currently selected Preset if there is one*/
6656 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
6658 /* Populate the preset picture settings popup here */
6659 [fPresetNewPicSettingsPopUp removeAllItems];
6660 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
6661 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
6662 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
6663 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
6664 /* Uncheck the preset use filters checkbox */
6665 [fPresetNewPicFiltersCheck setState:NSOffState];
6666 // fPresetNewFolderCheck
6667 [fPresetNewFolderCheck setState:NSOffState];
6668 /* Erase info from the input fields*/
6669 [fPresetNewName setStringValue: @""];
6670 [fPresetNewDesc setStringValue: @""];
6671 /* Show the panel */
6672 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
6675 - (IBAction) closeAddPresetPanel: (id) sender
6677 [NSApp endSheet: fAddPresetPanel];
6678 [fAddPresetPanel orderOut: self];
6681 - (IBAction)addUserPreset:(id)sender
6683 if (![[fPresetNewName stringValue] length])
6684 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
6687 /* Here we create a custom user preset */
6688 [UserPresets addObject:[self createPreset]];
6691 [self closeAddPresetPanel:nil];
6698 /* We Reload the New Table data for presets */
6699 [fPresetsOutlineView reloadData];
6700 /* We save all of the preset data here */
6708 /* We Sort the Presets By Factory or Custom */
6709 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
6710 ascending:YES] autorelease];
6711 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
6713 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
6714 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
6715 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
6718 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
6719 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
6720 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
6721 [UserPresets setArray:sortedArray];
6726 - (IBAction)insertPreset:(id)sender
6728 int index = [fPresetsOutlineView selectedRow];
6729 [UserPresets insertObject:[self createPreset] atIndex:index];
6730 [fPresetsOutlineView reloadData];
6734 - (NSDictionary *)createPreset
6736 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
6737 /* Preset build number */
6738 [preset setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
6739 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6740 /* Get the New Preset Name from the field in the AddPresetPanel */
6741 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6742 /* Set whether or not this is to be a folder fPresetNewFolderCheck*/
6743 [preset setObject:[NSNumber numberWithBool:[fPresetNewFolderCheck state]] forKey:@"Folder"];
6744 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
6745 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
6746 /*Set whether or not this is default, at creation set to 0*/
6747 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6748 if ([fPresetNewFolderCheck state] == YES)
6750 /* initialize and set an empty array for children here since we are a new folder */
6751 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6752 [preset setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6753 [childrenArray autorelease];
6755 else // we are not creating a preset folder, so we go ahead with the rest of the preset info
6757 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
6758 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
6759 /* Get whether or not to use the current Picture Filter settings for the preset */
6760 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
6762 /* Get New Preset Description from the field in the AddPresetPanel*/
6763 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
6765 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
6766 /* Chapter Markers fCreateChapterMarkers*/
6767 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
6768 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6769 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
6770 /* Mux mp4 with http optimization */
6771 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
6772 /* Add iPod uuid atom */
6773 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
6777 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
6778 /* x264 Option String */
6779 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
6781 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
6782 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
6783 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
6784 [preset setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
6786 /* Video framerate */
6787 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
6789 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
6791 else // we can record the actual titleOfSelectedItem
6793 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
6796 /* 2 Pass Encoding */
6797 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
6798 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
6799 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
6800 /*Picture Settings*/
6801 hb_job_t * job = fTitle->job;
6802 /* Picture Sizing */
6803 /* Use Max Picture settings for whatever the dvd is.*/
6804 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
6805 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
6806 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
6807 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
6808 [preset setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
6810 /* Set crop settings here */
6811 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
6812 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
6813 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
6814 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
6815 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
6817 /* Picture Filters */
6818 [preset setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
6819 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
6820 [preset setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
6821 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
6822 [preset setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
6823 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
6824 [preset setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
6825 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
6826 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
6827 [preset setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
6828 [preset setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
6831 NSMutableArray *audioListArray = [[NSMutableArray alloc] init];
6832 /* we actually call the methods for the nests here */
6833 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
6835 NSMutableDictionary *audioTrack1Array = [[NSMutableDictionary alloc] init];
6836 [audioTrack1Array setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6837 [audioTrack1Array setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6838 [audioTrack1Array setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6839 [audioTrack1Array setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6840 [audioTrack1Array setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6841 [audioTrack1Array setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6842 [audioTrack1Array setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6843 [audioTrack1Array autorelease];
6844 [audioListArray addObject:audioTrack1Array];
6847 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
6849 NSMutableDictionary *audioTrack2Array = [[NSMutableDictionary alloc] init];
6850 [audioTrack2Array setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6851 [audioTrack2Array setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6852 [audioTrack2Array setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6853 [audioTrack2Array setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6854 [audioTrack2Array setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6855 [audioTrack2Array setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6856 [audioTrack2Array setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6857 [audioTrack2Array autorelease];
6858 [audioListArray addObject:audioTrack2Array];
6861 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
6863 NSMutableDictionary *audioTrack3Array = [[NSMutableDictionary alloc] init];
6864 [audioTrack3Array setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6865 [audioTrack3Array setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6866 [audioTrack3Array setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6867 [audioTrack3Array setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6868 [audioTrack3Array setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6869 [audioTrack3Array setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6870 [audioTrack3Array setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6871 [audioTrack3Array autorelease];
6872 [audioListArray addObject:audioTrack3Array];
6875 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
6877 NSMutableDictionary *audioTrack4Array = [[NSMutableDictionary alloc] init];
6878 [audioTrack4Array setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6879 [audioTrack4Array setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6880 [audioTrack4Array setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6881 [audioTrack4Array setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6882 [audioTrack4Array setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6883 [audioTrack4Array setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6884 [audioTrack4Array setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6885 [audioTrack4Array autorelease];
6886 [audioListArray addObject:audioTrack4Array];
6890 [preset setObject:[NSMutableArray arrayWithArray: audioListArray] forKey:@"AudioList"];
6893 /* Temporarily remove subtitles from creating a new preset as it has to be converted over to use the new
6894 * subititle array code. */
6896 //[preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
6897 /* Forced Subtitles */
6898 //[preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
6900 [preset autorelease];
6907 [UserPresets writeToFile:UserPresetsFile atomically:YES];
6908 /* We get the default preset in case it changed */
6909 [self getDefaultPresets:nil];
6913 - (IBAction)deletePreset:(id)sender
6917 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
6921 /* Alert user before deleting preset */
6923 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
6925 if ( status == NSAlertDefaultReturn )
6927 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6928 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6929 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
6931 NSEnumerator *enumerator;
6932 NSMutableArray *presetsArrayToMod;
6933 NSMutableArray *tempArray;
6935 /* If we are a root level preset, we are modding the UserPresets array */
6936 if (presetToModLevel == 0)
6938 presetsArrayToMod = UserPresets;
6940 else // We have a parent preset, so we modify the chidren array object for key
6942 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
6945 enumerator = [presetsArrayToMod objectEnumerator];
6946 tempArray = [NSMutableArray array];
6948 while (tempObject = [enumerator nextObject])
6950 NSDictionary *thisPresetDict = tempObject;
6951 if (thisPresetDict == presetToMod)
6953 [tempArray addObject:tempObject];
6957 [presetsArrayToMod removeObjectsInArray:tempArray];
6958 [fPresetsOutlineView reloadData];
6965 #pragma mark Import Export Preset(s)
6967 - (IBAction) browseExportPresetFile: (id) sender
6969 /* Open a panel to let the user choose where and how to save the export file */
6970 NSSavePanel * panel = [NSSavePanel savePanel];
6971 /* We get the current file name and path from the destination field here */
6972 NSString *defaultExportDirectory = [NSString stringWithFormat: @"%@/Desktop/", NSHomeDirectory()];
6974 [panel beginSheetForDirectory: defaultExportDirectory file: @"HB_Export.plist"
6975 modalForWindow: fWindow modalDelegate: self
6976 didEndSelector: @selector( browseExportPresetFileDone:returnCode:contextInfo: )
6980 - (void) browseExportPresetFileDone: (NSSavePanel *) sheet
6981 returnCode: (int) returnCode contextInfo: (void *) contextInfo
6983 if( returnCode == NSOKButton )
6985 NSString *presetExportDirectory = [[sheet filename] stringByDeletingLastPathComponent];
6986 NSString *exportPresetsFile = [sheet filename];
6987 [[NSUserDefaults standardUserDefaults] setObject:presetExportDirectory forKey:@"LastPresetExportDirectory"];
6988 /* We check for the presets.plist */
6989 if ([[NSFileManager defaultManager] fileExistsAtPath:exportPresetsFile] == 0)
6991 [[NSFileManager defaultManager] createFileAtPath:exportPresetsFile contents:nil attributes:nil];
6993 NSMutableArray * presetsToExport = [[NSMutableArray alloc] initWithContentsOfFile:exportPresetsFile];
6994 if (nil == presetsToExport)
6996 presetsToExport = [[NSMutableArray alloc] init];
6998 /* now get and add selected presets to export */
7001 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
7003 [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7004 [presetsToExport writeToFile:exportPresetsFile atomically:YES];
7012 - (IBAction) browseImportPresetFile: (id) sender
7015 NSOpenPanel * panel;
7017 panel = [NSOpenPanel openPanel];
7018 [panel setAllowsMultipleSelection: NO];
7019 [panel setCanChooseFiles: YES];
7020 [panel setCanChooseDirectories: NO ];
7021 NSString * sourceDirectory;
7022 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"])
7024 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"];
7028 sourceDirectory = @"~/Desktop";
7029 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
7031 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
7032 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
7034 /* set this for allowed file types, not sure if we should allow xml or not */
7035 NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"xml", nil];
7036 [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes
7037 modalForWindow: fWindow modalDelegate: self
7038 didEndSelector: @selector( browseImportPresetDone:returnCode:contextInfo: )
7039 contextInfo: sender];
7042 - (void) browseImportPresetDone: (NSSavePanel *) sheet
7043 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7045 if( returnCode == NSOKButton )
7047 NSString *importPresetsDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7048 NSString *importPresetsFile = [sheet filename];
7049 [[NSUserDefaults standardUserDefaults] setObject:importPresetsDirectory forKey:@"LastPresetImportDirectory"];
7050 /* NOTE: here we need to do some sanity checking to verify we do not hose up our presets file */
7051 NSMutableArray * presetsToImport = [[NSMutableArray alloc] initWithContentsOfFile:importPresetsFile];
7052 /* iterate though the new array of presets to import and add them to our presets array */
7054 NSEnumerator *enumerator = [presetsToImport objectEnumerator];
7056 while (tempObject = [enumerator nextObject])
7058 /* make any changes to the incoming preset we see fit */
7059 /* make sure the incoming preset is not tagged as default */
7060 [tempObject setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7061 /* prepend "(imported) to the name of the incoming preset for clarification since it can be changed */
7062 NSString * prependedName = [@"(import) " stringByAppendingString:[tempObject objectForKey:@"PresetName"]] ;
7063 [tempObject setObject:prependedName forKey:@"PresetName"];
7065 /* actually add the new preset to our presets array */
7066 [UserPresets addObject:tempObject];
7069 [presetsToImport autorelease];
7077 #pragma mark Manage Default Preset
7079 - (IBAction)getDefaultPresets:(id)sender
7081 presetHbDefault = nil;
7082 presetUserDefault = nil;
7083 presetUserDefaultParent = nil;
7084 presetUserDefaultParentParent = nil;
7085 NSMutableDictionary *presetHbDefaultParent = nil;
7086 NSMutableDictionary *presetHbDefaultParentParent = nil;
7089 BOOL userDefaultFound = NO;
7090 presetCurrentBuiltInCount = 0;
7091 /* First we iterate through the root UserPresets array to check for defaults */
7092 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7094 while (tempObject = [enumerator nextObject])
7096 NSMutableDictionary *thisPresetDict = tempObject;
7097 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7099 presetHbDefault = thisPresetDict;
7101 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7103 presetUserDefault = thisPresetDict;
7104 userDefaultFound = YES;
7106 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7108 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
7112 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7113 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7115 NSMutableDictionary *thisPresetDictParent = thisPresetDict;
7116 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7118 while (tempObject = [enumerator nextObject])
7120 NSMutableDictionary *thisPresetDict = tempObject;
7121 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7123 presetHbDefault = thisPresetDict;
7124 presetHbDefaultParent = thisPresetDictParent;
7126 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7128 presetUserDefault = thisPresetDict;
7129 presetUserDefaultParent = thisPresetDictParent;
7130 userDefaultFound = YES;
7133 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7134 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7136 NSMutableDictionary *thisPresetDictParentParent = thisPresetDict;
7137 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7139 while (tempObject = [enumerator nextObject])
7141 NSMutableDictionary *thisPresetDict = tempObject;
7142 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7144 presetHbDefault = thisPresetDict;
7145 presetHbDefaultParent = thisPresetDictParent;
7146 presetHbDefaultParentParent = thisPresetDictParentParent;
7148 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7150 presetUserDefault = thisPresetDict;
7151 presetUserDefaultParent = thisPresetDictParent;
7152 presetUserDefaultParentParent = thisPresetDictParentParent;
7153 userDefaultFound = YES;
7162 /* check to see if a user specified preset was found, if not then assign the parents for
7163 * the presetHbDefault so that we can open the parents for the nested presets
7165 if (userDefaultFound == NO)
7167 presetUserDefaultParent = presetHbDefaultParent;
7168 presetUserDefaultParentParent = presetHbDefaultParentParent;
7172 - (IBAction)setDefaultPreset:(id)sender
7174 /* We need to determine if the item is a folder */
7175 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] == 1)
7181 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7183 /* First make sure the old user specified default preset is removed */
7184 while (tempObject = [enumerator nextObject])
7186 NSMutableDictionary *thisPresetDict = tempObject;
7187 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7189 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7192 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7193 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7195 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7198 while (tempObject = [enumerator nextObject])
7200 NSMutableDictionary *thisPresetDict1 = tempObject;
7201 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7203 [[[thisPresetDict objectForKey:@"ChildrenArray"] objectAtIndex:ii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7205 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7206 if ([thisPresetDict1 objectForKey:@"ChildrenArray"])
7208 NSEnumerator *enumerator = [[thisPresetDict1 objectForKey:@"ChildrenArray"] objectEnumerator];
7211 while (tempObject = [enumerator nextObject])
7213 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7215 [[[thisPresetDict1 objectForKey:@"ChildrenArray"] objectAtIndex:iii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7228 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7229 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
7230 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
7233 NSMutableArray *presetsArrayToMod;
7234 NSMutableArray *tempArray;
7236 /* If we are a root level preset, we are modding the UserPresets array */
7237 if (presetToModLevel == 0)
7239 presetsArrayToMod = UserPresets;
7241 else // We have a parent preset, so we modify the chidren array object for key
7243 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
7246 enumerator = [presetsArrayToMod objectEnumerator];
7247 tempArray = [NSMutableArray array];
7249 while (tempObject = [enumerator nextObject])
7251 NSDictionary *thisPresetDict = tempObject;
7252 if (thisPresetDict == presetToMod)
7254 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 2
7256 [[presetsArrayToMod objectAtIndex:iiii] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
7263 /* We save all of the preset data here */
7265 /* We Reload the New Table data for presets */
7266 [fPresetsOutlineView reloadData];
7269 - (IBAction)selectDefaultPreset:(id)sender
7271 NSMutableDictionary *presetToMod;
7272 /* if there is a user specified default, we use it */
7273 if (presetUserDefault)
7275 presetToMod = presetUserDefault;
7277 else if (presetHbDefault) //else we use the built in default presetHbDefault
7279 presetToMod = presetHbDefault;
7286 if (presetUserDefaultParent != nil)
7288 [fPresetsOutlineView expandItem:presetUserDefaultParent];
7291 if (presetUserDefaultParentParent != nil)
7293 [fPresetsOutlineView expandItem:presetUserDefaultParentParent];
7297 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[fPresetsOutlineView rowForItem: presetToMod]] byExtendingSelection:NO];
7298 [self selectPreset:nil];
7303 #pragma mark Manage Built In Presets
7306 - (IBAction)deleteFactoryPresets:(id)sender
7309 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7313 NSMutableArray *tempArray;
7316 tempArray = [NSMutableArray array];
7317 /* we look here to see if the preset is we move on to the next one */
7318 while ( tempObject = [enumerator nextObject] )
7320 /* if the preset is "Factory" then we put it in the array of
7321 presets to delete */
7322 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
7324 [tempArray addObject:tempObject];
7328 [UserPresets removeObjectsInArray:tempArray];
7329 [fPresetsOutlineView reloadData];
7334 /* We use this method to recreate new, updated factory presets */
7335 - (IBAction)addFactoryPresets:(id)sender
7338 /* First, we delete any existing built in presets */
7339 [self deleteFactoryPresets: sender];
7340 /* Then we generate new built in presets programmatically with fPresetsBuiltin
7341 * which is all setup in HBPresets.h and HBPresets.m*/
7342 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
7343 /* update build number for built in presets */
7344 /* iterate though the new array of presets to import and add them to our presets array */
7346 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7348 while (tempObject = [enumerator nextObject])
7350 /* Record the apps current build number in the PresetBuildNumber key */
7351 if ([[tempObject objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7353 /* Preset build number */
7354 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
7358 /* report the built in preset updating to the activity log */
7359 [self writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]];
7369 /*******************************
7370 * Subclass of the HBPresetsOutlineView *
7371 *******************************/
7373 @implementation HBPresetsOutlineView
7374 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
7378 // By default, NSTableView only drags an image of the first column. Change this to
7379 // drag an image of the queue's icon and PresetName columns.
7380 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"PresetName"], nil];
7381 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
7386 - (void) mouseDown:(NSEvent *)theEvent
7388 [super mouseDown:theEvent];
7394 - (BOOL) isDragging;