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 [HBPreferencesController registerUserDefaults];
43 fQueueEncodeLibhb = NULL;
44 /* Check for check for the app support directory here as
45 * outputPanel needs it right away, as may other future methods
47 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
49 YES ) objectAtIndex:0];
50 AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
51 stringByAppendingPathComponent:@"HandBrake"];
52 if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
54 [[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
57 /* Check for and create the App Support Preview directory if necessary */
58 NSString *PreviewDirectory = [AppSupportDirectory stringByAppendingPathComponent:@"Previews"];
59 if( ![[NSFileManager defaultManager] fileExistsAtPath:PreviewDirectory] )
61 [[NSFileManager defaultManager] createDirectoryAtPath:PreviewDirectory
64 outputPanel = [[HBOutputPanelController alloc] init];
65 fPictureController = [[PictureController alloc] init];
66 fQueueController = [[HBQueueController alloc] init];
67 fAdvancedOptions = [[HBAdvancedController alloc] init];
68 /* we init the HBPresets class which currently is only used
69 * for updating built in presets, may move more functionality
72 fPresetsBuiltin = [[HBPresets alloc] init];
73 fPreferencesController = [[HBPreferencesController alloc] init];
74 /* Lets report the HandBrake version number here to the activity log and text log file */
75 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
76 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
82 - (void) applicationDidFinishLaunching: (NSNotification *) notification
84 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
85 int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
86 fHandle = hb_init(loggingLevel, 0);
87 /* Optional dvd nav UseDvdNav*/
88 hb_dvd_set_dvdnav([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]);
89 /* Init a separate instance of libhb for user scanning and setting up jobs */
90 fQueueEncodeLibhb = hb_init(loggingLevel, 0);
92 // Set the Growl Delegate
93 [GrowlApplicationBridge setGrowlDelegate: self];
94 /* Init others controllers */
95 [fPictureController SetHandle: fHandle];
96 [fPictureController setHBController: self];
98 [fQueueController setHandle: fQueueEncodeLibhb];
99 [fQueueController setHBController: self];
101 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
102 [fChapterTable setDataSource:fChapterTitlesDelegate];
103 [fChapterTable setDelegate:fChapterTitlesDelegate];
105 /* setup the subtitles delegate and connections to table */
106 fSubtitlesDelegate = [[HBSubtitles alloc] init];
107 [fSubtitlesTable setDataSource:fSubtitlesDelegate];
108 [fSubtitlesTable setDelegate:fSubtitlesDelegate];
109 [fSubtitlesTable setRowHeight:25.0];
111 [fPresetsOutlineView setAutosaveName:@"Presets View"];
112 [fPresetsOutlineView setAutosaveExpandedItems:YES];
114 dockIconProgress = 0;
116 /* Call UpdateUI every 1/2 sec */
117 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
118 scheduledTimerWithTimeInterval:0.5 target:self
119 selector:@selector(updateUI:) userInfo:nil repeats:YES]
120 forMode:NSDefaultRunLoopMode];
122 // Open debug output window now if it was visible when HB was closed
123 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
124 [self showDebugOutputPanel:nil];
126 // Open queue window now if it was visible when HB was closed
127 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
128 [self showQueueWindow:nil];
130 [self openMainWindow:nil];
132 /* We have to set the bool to tell hb what to do after a scan
133 * Initially we set it to NO until we start processing the queue
135 applyQueueToScan = NO;
137 /* Now we re-check the queue array to see if there are
138 * any remaining encodes to be done in it and ask the
139 * user if they want to reload the queue */
140 if ([QueueFileArray count] > 0)
142 /* run getQueueStats to see whats in the queue file */
143 [self getQueueStats];
144 /* this results in these values
145 * fEncodingQueueItem = 0;
147 * fCompletedCount = 0;
148 * fCanceledCount = 0;
152 /*On Screen Notification*/
153 NSString * alertTitle;
155 /* We check to see if there is already another instance of hb running.
156 * Note: hbInstances == 1 means we are the only instance of HandBrake.app
158 if ([self hbInstances] > 1)
160 alertTitle = [NSString stringWithFormat:
161 NSLocalizedString(@"There is already an instance of HandBrake running.", @"")];
162 NSBeginCriticalAlertSheet(
164 NSLocalizedString(@"Reload Queue", nil),
168 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
169 NSLocalizedString(@" HandBrake will now load up the existing queue.", nil));
173 if (fWorkingCount > 0)
175 alertTitle = [NSString stringWithFormat:
176 NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
177 fWorkingCount,fPendingCount];
181 alertTitle = [NSString stringWithFormat:
182 NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
186 NSBeginCriticalAlertSheet(
188 NSLocalizedString(@"Reload Queue", nil),
190 NSLocalizedString(@"Empty Queue", nil),
192 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
193 NSLocalizedString(@" Do you want to reload them ?", nil));
196 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
197 // right below to either clear the old queue or keep it loaded up.
201 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
202 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
204 [self browseSources:nil];
207 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
209 [self browseSources:(id)fOpenSourceTitleMMenu];
216 /* check to see if another instance of HandBrake.app is running */
217 NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications];
218 NSDictionary *aDictionary;
220 for (aDictionary in runningAppDictionaries)
222 // NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]);
224 if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
232 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
234 if (returnCode == NSAlertOtherReturn)
236 [self clearQueueAllItems];
237 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
238 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
240 [self browseSources:nil];
243 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
245 [self browseSources:(id)fOpenSourceTitleMMenu];
250 if ([self hbInstances] == 1)
252 [self setQueueEncodingItemsAsPending];
254 [self showQueueWindow:NULL];
258 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
260 /* if we are in preview full screen mode, we need to go to
261 * windowed mode and release the display before we terminate.
262 * We do it here (instead of applicationWillTerminate) so we
263 * release the displays and can then see the alerts below.
265 if ([fPictureController previewFullScreenMode] == YES)
267 [fPictureController previewGoWindowed:nil];
271 hb_get_state( fQueueEncodeLibhb, &s );
273 if ( s.state != HB_STATE_IDLE )
275 int result = NSRunCriticalAlertPanel(
276 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
277 NSLocalizedString(@"If you quit HandBrake your current encode will be reloaded into your queue at next launch. Do you want to quit anyway?", nil),
278 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
280 if (result == NSAlertDefaultReturn)
282 return NSTerminateNow;
285 return NSTerminateCancel;
288 // Warn if items still in the queue
289 else if ( fPendingCount > 0 )
291 int result = NSRunCriticalAlertPanel(
292 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
293 NSLocalizedString(@"There are pending encodes in your queue. Do you want to quit anyway?",nil),
294 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
296 if ( result == NSAlertDefaultReturn )
297 return NSTerminateNow;
299 return NSTerminateCancel;
302 return NSTerminateNow;
305 - (void)applicationWillTerminate:(NSNotification *)aNotification
308 [browsedSourceDisplayName release];
309 [outputPanel release];
310 [fQueueController release];
311 [fPreviewController release];
312 [fPictureController release];
315 hb_close(&fQueueEncodeLibhb);
319 - (void) awakeFromNib
322 [fWindow setExcludedFromWindowsMenu:YES];
323 [fAdvancedOptions setView:fAdvancedView];
325 /* lets setup our presets drawer for drag and drop here */
326 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
327 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
328 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
330 /* Initialize currentScanCount so HB can use it to
331 evaluate successive scans */
332 currentScanCount = 0;
335 /* Init UserPresets .plist */
338 /* Init QueueFile .plist */
339 [self loadQueueFile];
341 fRipIndicatorShown = NO; // initially out of view in the nib
343 /* For 64 bit builds, the threaded animation in the progress
344 * indicators conflicts with the animation in the advanced tab
345 * for reasons not completely clear. jbrjake found a note in the
346 * 10.5 dev notes regarding this possiblility. It was also noted
347 * that unless specified, setUsesThreadedAnimation defaults to true.
348 * So, at least for now we set the indicator animation to NO for
349 * both the scan and regular progress indicators for both 32 and 64 bit
350 * as it test out fine on both and there is no reason our progress indicators
351 * should require their own thread.
354 [fScanIndicator setUsesThreadedAnimation:NO];
355 [fRipIndicator setUsesThreadedAnimation:NO];
359 /* Show/Dont Show Presets drawer upon launch based
360 on user preference DefaultPresetsDrawerShow*/
361 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0 )
363 [fPresetDrawer setDelegate:self];
364 NSSize drawerSize = NSSizeFromString( [[NSUserDefaults standardUserDefaults]
365 stringForKey:@"Drawer Size"] );
366 if( drawerSize.width )
367 [fPresetDrawer setContentSize: drawerSize];
368 [fPresetDrawer open];
371 /* Initially set the dvd angle widgets to hidden (dvdnav only) */
372 [fSrcAngleLabel setHidden:YES];
373 [fSrcAnglePopUp setHidden:YES];
376 NSMenuItem *menuItem;
377 [fDstFormatPopUp removeAllItems];
379 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
380 [menuItem setTag: HB_MUX_MP4];
382 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
383 [menuItem setTag: HB_MUX_MKV];
385 [fDstFormatPopUp selectItemAtIndex: 0];
387 [self formatPopUpChanged:nil];
389 /* We enable the create chapters checkbox here since we are .mp4 */
390 [fCreateChapterMarkers setEnabled: YES];
391 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
393 [fCreateChapterMarkers setState: NSOnState];
399 [fDstFile2Field setStringValue: [NSString stringWithFormat:
400 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
403 [fVidEncoderPopUp removeAllItems];
404 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
409 [fVidTargetSizeField setIntValue: 700];
410 [fVidBitrateField setIntValue: 1000];
412 [fVidQualityMatrix selectCell: fVidBitrateCell];
413 [self videoMatrixChanged:nil];
415 /* Video framerate */
416 [fVidRatePopUp removeAllItems];
417 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
418 for( int i = 0; i < hb_video_rates_count; i++ )
420 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
422 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
423 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
425 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
427 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
428 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
430 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
432 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
433 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
437 [fVidRatePopUp addItemWithTitle:
438 [NSString stringWithCString: hb_video_rates[i].string]];
441 [fVidRatePopUp selectItemAtIndex: 0];
443 /* Set Auto Crop to On at launch */
444 [fPictureController setAutoCrop:YES];
447 [fAudTrack1BitratePopUp removeAllItems];
448 for( int i = 0; i < hb_audio_bitrates_count; i++ )
450 [fAudTrack1BitratePopUp addItemWithTitle:
451 [NSString stringWithCString: hb_audio_bitrates[i].string]];
454 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
456 /* Audio samplerate */
457 [fAudTrack1RatePopUp removeAllItems];
458 for( int i = 0; i < hb_audio_rates_count; i++ )
460 [fAudTrack1RatePopUp addItemWithTitle:
461 [NSString stringWithCString: hb_audio_rates[i].string]];
463 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
466 [fStatusField setStringValue: @""];
471 /* We disable the Turbo 1st pass checkbox since we are not x264 */
472 [fVidTurboPassCheck setEnabled: NO];
473 [fVidTurboPassCheck setState: NSOffState];
476 /* lets get our default prefs here */
477 [self getDefaultPresets:nil];
478 /* lets initialize the current successful scancount here to 0 */
479 currentSuccessfulScanCount = 0;
484 - (void) enableUI: (bool) b
486 NSControl * controls[] =
487 { fSrcTitleField, fSrcTitlePopUp,
488 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
489 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
490 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
491 fDstBrowseButton, fVidRateField, fVidRatePopUp,fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
492 fPictureSizeField,fPictureCroppingField, fVideoFiltersField,fVidQualityMatrix, fSubField, fSubPopUp,
493 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
494 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
495 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
496 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
497 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
498 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
499 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
500 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
501 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
502 fQueueStatus,fPresetsAdd,fPresetsDelete,fSrcAngleLabel,fSrcAnglePopUp,
503 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView,
504 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel};
507 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
509 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
511 NSTextField * tf = (NSTextField *) controls[i];
512 if( ![tf isBezeled] )
514 [tf setTextColor: b ? [NSColor controlTextColor] :
515 [NSColor disabledControlTextColor]];
519 [controls[i] setEnabled: b];
525 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
526 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
527 [self setEnabledStateOfAudioMixdownControls:nil];
528 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
529 [self calculatePictureSizing:nil];
533 [fPresetsOutlineView setEnabled: NO];
537 [self videoMatrixChanged:nil];
538 [fAdvancedOptions enableUI:b];
542 /***********************************************************************
544 ***********************************************************************
545 * Shows a progression bar on the dock icon, filled according to
546 * 'progress' (0.0 <= progress <= 1.0).
547 * Called with progress < 0.0 or progress > 1.0, restores the original
549 **********************************************************************/
550 - (void) UpdateDockIcon: (float) progress
554 NSBitmapImageRep * bmp;
556 uint32_t black = htonl( 0x000000FF );
557 uint32_t red = htonl( 0xFF0000FF );
558 uint32_t white = htonl( 0xFFFFFFFF );
559 int row_start, row_end;
562 /* Get application original icon */
563 icon = [NSImage imageNamed: @"NSApplicationIcon"];
565 if( progress < 0.0 || progress > 1.0 )
567 [NSApp setApplicationIconImage: icon];
571 /* Get it in a raw bitmap form */
572 tiff = [icon TIFFRepresentationUsingCompression:
573 NSTIFFCompressionNone factor: 1.0];
574 bmp = [NSBitmapImageRep imageRepWithData: tiff];
576 /* Draw the progression bar */
577 /* It's pretty simple (ugly?) now, but I'm no designer */
579 row_start = 3 * (int) [bmp size].height / 4;
580 row_end = 7 * (int) [bmp size].height / 8;
582 for( i = row_start; i < row_start + 2; i++ )
584 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
585 for( j = 0; j < (int) [bmp size].width; j++ )
590 for( i = row_start + 2; i < row_end - 2; i++ )
592 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
595 for( j = 2; j < (int) [bmp size].width - 2; j++ )
597 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
609 for( i = row_end - 2; i < row_end; i++ )
611 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
612 for( j = 0; j < (int) [bmp size].width; j++ )
618 /* Now update the dock icon */
619 tiff = [bmp TIFFRepresentationUsingCompression:
620 NSTIFFCompressionNone factor: 1.0];
621 icon = [[NSImage alloc] initWithData: tiff];
622 [NSApp setApplicationIconImage: icon];
626 - (void) updateUI: (NSTimer *) timer
629 /* Update UI for fHandle (user scanning instance of libhb ) */
632 list = hb_get_titles( fHandle );
633 /* check to see if there has been a new scan done
634 this bypasses the constraints of HB_STATE_WORKING
635 not allowing setting a newly scanned source */
636 int checkScanCount = hb_get_scancount( fHandle );
637 if( checkScanCount > currentScanCount )
639 currentScanCount = checkScanCount;
640 [fScanIndicator setIndeterminate: NO];
641 [fScanIndicator setDoubleValue: 0.0];
642 [fScanIndicator setHidden: YES];
643 [self showNewScan:nil];
647 hb_get_state( fHandle, &s );
653 #define p s.param.scanning
654 case HB_STATE_SCANNING:
656 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
657 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
658 p.title_cur, p.title_count]];
659 [fScanIndicator setHidden: NO];
660 [fScanIndicator setDoubleValue: 100.0 * ((double)( p.title_cur - 1 ) / p.title_count)];
665 #define p s.param.scandone
666 case HB_STATE_SCANDONE:
668 [fScanIndicator setIndeterminate: NO];
669 [fScanIndicator setDoubleValue: 0.0];
670 [fScanIndicator setHidden: YES];
671 [self writeToActivityLog:"ScanDone state received from fHandle"];
672 [self showNewScan:nil];
673 [[fWindow toolbar] validateVisibleItems];
679 #define p s.param.working
680 case HB_STATE_WORKING:
687 #define p s.param.muxing
688 case HB_STATE_MUXING:
695 case HB_STATE_PAUSED:
698 case HB_STATE_WORKDONE:
705 /* Update UI for fQueueEncodeLibhb */
707 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
708 /* check to see if there has been a new scan done
709 this bypasses the constraints of HB_STATE_WORKING
710 not allowing setting a newly scanned source */
712 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
713 if( checkScanCount > currentScanCount )
715 currentScanCount = checkScanCount;
716 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
720 hb_get_state( fQueueEncodeLibhb, &s );
726 #define p s.param.scanning
727 case HB_STATE_SCANNING:
729 [fStatusField setStringValue: [NSString stringWithFormat:
730 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
731 p.title_cur, p.title_count]];
733 /* Set the status string in fQueueController as well */
734 [fQueueController setQueueStatusString: [NSString stringWithFormat:
735 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
736 p.title_cur, p.title_count]];
741 #define p s.param.scandone
742 case HB_STATE_SCANDONE:
744 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
745 [self processNewQueueEncode];
746 [[fWindow toolbar] validateVisibleItems];
752 #define p s.param.working
753 case HB_STATE_WORKING:
755 NSMutableString * string;
756 /* Update text field */
757 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
761 [string appendFormat:
762 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
763 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
766 [fStatusField setStringValue: string];
767 /* Set the status string in fQueueController as well */
768 [fQueueController setQueueStatusString: string];
770 CGFloat progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
771 [fRipIndicator setIndeterminate: NO];
772 [fRipIndicator setDoubleValue:100.0 * progress_total];
774 // If progress bar hasn't been revealed at the bottom of the window, do
775 // that now. This code used to be in doRip. I moved it to here to handle
776 // the case where hb_start is called by HBQueueController and not from
778 if( !fRipIndicatorShown )
780 NSRect frame = [fWindow frame];
781 if( frame.size.width <= 591 )
782 frame.size.width = 591;
783 frame.size.height += 36;
784 frame.origin.y -= 36;
785 [fWindow setFrame:frame display:YES animate:YES];
786 fRipIndicatorShown = YES;
790 /* Update dock icon */
791 if( dockIconProgress < 100.0 * progress_total )
793 [self UpdateDockIcon: progress_total];
794 dockIconProgress += 5;
801 #define p s.param.muxing
802 case HB_STATE_MUXING:
804 /* Update text field */
805 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
806 /* Set the status string in fQueueController as well */
807 [fQueueController setQueueStatusString: NSLocalizedString( @"Muxing...", @"" )];
809 [fRipIndicator setIndeterminate: YES];
810 [fRipIndicator startAnimation: nil];
812 /* Update dock icon */
813 [self UpdateDockIcon: 1.0];
819 case HB_STATE_PAUSED:
820 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
821 [fQueueController setQueueStatusString: NSLocalizedString( @"Paused", @"" )];
825 case HB_STATE_WORKDONE:
827 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
828 // or someone calling hb_stop. In the latter case, hb_stop does not clear
829 // out the remaining passes/jobs in the queue. We'll do that here.
831 // Delete all remaining jobs of this encode.
832 [fStatusField setStringValue: NSLocalizedString( @"Encode Finished.", @"" )];
833 /* Set the status string in fQueueController as well */
834 [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
835 [fRipIndicator setIndeterminate: NO];
836 [fRipIndicator stopAnimation: nil];
837 [fRipIndicator setDoubleValue: 0.0];
838 [[fWindow toolbar] validateVisibleItems];
840 /* Restore dock icon */
841 [self UpdateDockIcon: -1.0];
842 dockIconProgress = 0;
844 if( fRipIndicatorShown )
846 NSRect frame = [fWindow frame];
847 if( frame.size.width <= 591 )
848 frame.size.width = 591;
849 frame.size.height += -36;
850 frame.origin.y -= -36;
851 [fWindow setFrame:frame display:YES animate:YES];
852 fRipIndicatorShown = NO;
854 /* Since we are done with this encode, tell output to stop writing to the
855 * individual encode log
857 [outputPanel endEncodeLog];
858 /* Check to see if the encode state has not been cancelled
859 to determine if we should check for encode done notifications */
860 if( fEncodeState != 2 )
862 NSString *pathOfFinishedEncode;
863 /* Get the output file name for the finished encode */
864 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
866 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
868 [self showGrowlDoneNotification:pathOfFinishedEncode];
870 [self sendToMetaX:pathOfFinishedEncode];
872 /* since we have successfully completed an encode, we increment the queue counter */
873 [self incrementQueueItemDone:nil];
875 /* all end of queue actions below need to be done after all queue encodes have finished
876 * and there are no pending jobs left to process
878 if (fPendingCount == 0)
880 /* If Alert Window or Window and Growl has been selected */
881 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
882 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
884 /*On Screen Notification*/
887 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
888 [NSApp requestUserAttention:NSCriticalRequest];
891 /* If sleep has been selected */
892 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
895 NSDictionary* errorDict;
896 NSAppleEventDescriptor* returnDescriptor = nil;
897 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
898 @"tell application \"Finder\" to sleep"];
899 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
900 [scriptObject release];
902 /* If Shutdown has been selected */
903 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
906 NSDictionary* errorDict;
907 NSAppleEventDescriptor* returnDescriptor = nil;
908 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
909 @"tell application \"Finder\" to shut down"];
910 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
911 [scriptObject release];
925 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
926 - (void) writeToActivityLog:(const char *) format, ...
929 va_start(args, format);
933 vsnprintf( str, 1024, format, args );
935 time_t _now = time( NULL );
936 struct tm * now = localtime( &_now );
937 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
944 // ============================================================
945 // NSToolbar Related Methods
946 // ============================================================
948 - (void) setupToolbar {
949 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
951 [toolbar setAllowsUserCustomization: YES];
952 [toolbar setAutosavesConfiguration: YES];
953 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
955 [toolbar setDelegate: self];
957 [fWindow setToolbar: toolbar];
960 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
961 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
962 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
964 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
966 [item setLabel: @"Toggle Presets"];
967 [item setPaletteLabel: @"Toggler Presets"];
968 [item setToolTip: @"Open/Close Preset Drawer"];
969 [item setImage: [NSImage imageNamed: @"Drawer"]];
970 [item setTarget: self];
971 [item setAction: @selector(toggleDrawer:)];
972 [item setAutovalidates: NO];
974 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
976 [item setLabel: @"Start"];
977 [item setPaletteLabel: @"Start Encoding"];
978 [item setToolTip: @"Start Encoding"];
979 [item setImage: [NSImage imageNamed: @"Play"]];
980 [item setTarget: self];
981 [item setAction: @selector(Rip:)];
983 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
985 [item setLabel: @"Show Queue"];
986 [item setPaletteLabel: @"Show Queue"];
987 [item setToolTip: @"Show Queue"];
988 [item setImage: [NSImage imageNamed: @"Queue"]];
989 [item setTarget: self];
990 [item setAction: @selector(showQueueWindow:)];
991 [item setAutovalidates: NO];
993 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
995 [item setLabel: @"Add to Queue"];
996 [item setPaletteLabel: @"Add to Queue"];
997 [item setToolTip: @"Add to Queue"];
998 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
999 [item setTarget: self];
1000 [item setAction: @selector(addToQueue:)];
1002 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
1004 [item setLabel: @"Pause"];
1005 [item setPaletteLabel: @"Pause Encoding"];
1006 [item setToolTip: @"Pause Encoding"];
1007 [item setImage: [NSImage imageNamed: @"Pause"]];
1008 [item setTarget: self];
1009 [item setAction: @selector(Pause:)];
1011 else if ([itemIdent isEqualToString: ShowPictureIdentifier])
1013 [item setLabel: @"Picture Settings"];
1014 [item setPaletteLabel: @"Show Picture Settings"];
1015 [item setToolTip: @"Show Picture Settings"];
1016 [item setImage: [NSImage imageNamed: @"pref-picture"]];
1017 [item setTarget: self];
1018 [item setAction: @selector(showPicturePanel:)];
1020 else if ([itemIdent isEqualToString: ShowPreviewIdentifier])
1022 [item setLabel: @"Preview Window"];
1023 [item setPaletteLabel: @"Show Preview"];
1024 [item setToolTip: @"Show Preview"];
1025 //[item setImage: [NSImage imageNamed: @"pref-picture"]];
1026 [item setImage: [NSImage imageNamed: @"Brushed_Window"]];
1027 [item setTarget: self];
1028 [item setAction: @selector(showPreviewWindow:)];
1030 else if ([itemIdent isEqualToString: ShowActivityIdentifier])
1032 [item setLabel: @"Activity Window"];
1033 [item setPaletteLabel: @"Show Activity Window"];
1034 [item setToolTip: @"Show Activity Window"];
1035 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
1036 [item setTarget: self];
1037 [item setAction: @selector(showDebugOutputPanel:)];
1038 [item setAutovalidates: NO];
1040 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
1042 [item setLabel: @"Source"];
1043 [item setPaletteLabel: @"Source"];
1044 [item setToolTip: @"Choose Video Source"];
1045 [item setImage: [NSImage imageNamed: @"Source"]];
1046 [item setTarget: self];
1047 [item setAction: @selector(browseSources:)];
1057 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
1059 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
1060 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1061 NSToolbarSpaceItemIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
1064 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
1066 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
1067 ChooseSourceIdentifier, ShowQueueIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
1068 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1069 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
1072 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
1074 NSString * ident = [toolbarItem itemIdentifier];
1079 hb_get_state2( fQueueEncodeLibhb, &s );
1081 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
1083 if ([ident isEqualToString: StartEncodingIdentifier])
1085 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
1086 [toolbarItem setLabel: @"Stop"];
1087 [toolbarItem setPaletteLabel: @"Stop"];
1088 [toolbarItem setToolTip: @"Stop Encoding"];
1091 if ([ident isEqualToString: PauseEncodingIdentifier])
1093 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
1094 [toolbarItem setLabel: @"Pause"];
1095 [toolbarItem setPaletteLabel: @"Pause Encoding"];
1096 [toolbarItem setToolTip: @"Pause Encoding"];
1101 if ([ident isEqualToString: AddToQueueIdentifier])
1103 if ([ident isEqualToString: ShowPictureIdentifier])
1105 if ([ident isEqualToString: ShowPreviewIdentifier])
1109 else if (s.state == HB_STATE_PAUSED)
1111 if ([ident isEqualToString: PauseEncodingIdentifier])
1113 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1114 [toolbarItem setLabel: @"Resume"];
1115 [toolbarItem setPaletteLabel: @"Resume Encoding"];
1116 [toolbarItem setToolTip: @"Resume Encoding"];
1119 if ([ident isEqualToString: StartEncodingIdentifier])
1121 if ([ident isEqualToString: AddToQueueIdentifier])
1123 if ([ident isEqualToString: ShowPictureIdentifier])
1125 if ([ident isEqualToString: ShowPreviewIdentifier])
1128 else if (s.state == HB_STATE_SCANNING)
1130 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
1132 if ([ident isEqualToString: StartEncodingIdentifier])
1134 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1135 if (hb_count(fHandle) > 0)
1136 [toolbarItem setLabel: @"Start Queue"];
1138 [toolbarItem setLabel: @"Start"];
1139 [toolbarItem setPaletteLabel: @"Start Encoding"];
1140 [toolbarItem setToolTip: @"Start Encoding"];
1143 if ([ident isEqualToString: AddToQueueIdentifier])
1145 if ([ident isEqualToString: ShowPictureIdentifier])
1147 if ([ident isEqualToString: ShowPreviewIdentifier])
1152 /* If there are any pending queue items, make sure the start/stop button is active */
1153 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1155 if ([ident isEqualToString: ShowQueueIdentifier])
1157 if ([ident isEqualToString: ToggleDrawerIdentifier])
1159 if ([ident isEqualToString: ChooseSourceIdentifier])
1161 if ([ident isEqualToString: ShowActivityIdentifier])
1167 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1169 SEL action = [menuItem action];
1172 hb_get_state2( fHandle, &s );
1176 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1177 return SuccessfulScan && [fWindow attachedSheet] == nil;
1179 if (action == @selector(browseSources:))
1181 if (s.state == HB_STATE_SCANNING)
1184 return [fWindow attachedSheet] == nil;
1186 if (action == @selector(selectDefaultPreset:))
1187 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1188 if (action == @selector(Pause:))
1190 if (s.state == HB_STATE_WORKING)
1192 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1193 [menuItem setTitle:@"Pause Encoding"];
1196 else if (s.state == HB_STATE_PAUSED)
1198 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1199 [menuItem setTitle:@"Resume Encoding"];
1205 if (action == @selector(Rip:))
1207 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1209 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1210 [menuItem setTitle:@"Stop Encoding"];
1213 else if (SuccessfulScan)
1215 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1216 [menuItem setTitle:@"Start Encoding"];
1217 return [fWindow attachedSheet] == nil;
1223 if( action == @selector(setDefaultPreset:) )
1225 return [fPresetsOutlineView selectedRow] != -1;
1232 #pragma mark Encode Done Actions
1233 // register a test notification and make
1234 // it enabled by default
1235 #define SERVICE_NAME @"Encode Done"
1236 - (NSDictionary *)registrationDictionaryForGrowl
1238 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1239 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1240 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1243 return registrationDictionary;
1246 -(void)showGrowlDoneNotification:(NSString *) filePath
1248 /* This end of encode action is called as each encode rolls off of the queue */
1249 NSString * finishedEncode = filePath;
1250 /* strip off the path to just show the file name */
1251 finishedEncode = [finishedEncode lastPathComponent];
1252 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1253 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1255 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1256 [GrowlApplicationBridge
1257 notifyWithTitle:@"Put down that cocktail..."
1258 description:growlMssg
1259 notificationName:SERVICE_NAME
1267 -(void)sendToMetaX:(NSString *) filePath
1269 /* This end of encode action is called as each encode rolls off of the queue */
1270 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1272 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1273 [myScript executeAndReturnError: nil];
1278 #pragma mark Get New Source
1280 /*Opens the source browse window, called from Open Source widgets */
1281 - (IBAction) browseSources: (id) sender
1283 NSOpenPanel * panel;
1285 panel = [NSOpenPanel openPanel];
1286 [panel setAllowsMultipleSelection: NO];
1287 [panel setCanChooseFiles: YES];
1288 [panel setCanChooseDirectories: YES ];
1289 NSString * sourceDirectory;
1290 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1292 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1296 sourceDirectory = @"~/Desktop";
1297 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1299 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1300 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1302 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1303 modalForWindow: fWindow modalDelegate: self
1304 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1305 contextInfo: sender];
1308 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1309 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1311 /* we convert the sender content of contextInfo back into a variable called sender
1312 * mostly just for consistency for evaluation later
1314 id sender = (id)contextInfo;
1315 /* User selected a file to open */
1316 if( returnCode == NSOKButton )
1318 /* Free display name allocated previously by this code */
1319 [browsedSourceDisplayName release];
1321 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1322 /* we set the last searched source directory in the prefs here */
1323 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1324 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1325 /* we order out sheet, which is the browse window as we need to open
1326 * the title selection sheet right away
1328 [sheet orderOut: self];
1330 if (sender == fOpenSourceTitleMMenu)
1332 /* We put the chosen source path in the source display text field for the
1333 * source title selection sheet in which the user specifies the specific title to be
1334 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1335 * purposes in the title panel
1338 [fScanSrcTitlePathField setStringValue:scanPath];
1339 NSString *displayTitlescanSourceName;
1341 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1343 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1344 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1345 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1349 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1350 displayTitlescanSourceName = [scanPath lastPathComponent];
1352 /* we set the source display name in the title selection dialogue */
1353 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1354 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1355 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1356 /* We show the actual sheet where the user specifies the title to be scanned
1357 * as we are going to do a title specific scan
1359 [self showSourceTitleScanPanel:nil];
1363 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1364 NSString *path = [[sheet filenames] objectAtIndex: 0];
1366 /* We check to see if the chosen file at path is a package */
1367 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1369 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1370 /* We check to see if this is an .eyetv package */
1371 if ([[path pathExtension] isEqualToString: @"eyetv"])
1373 [self writeToActivityLog:"trying to open eyetv package"];
1374 /* We're looking at an EyeTV package - try to open its enclosed
1376 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1378 int n = [[path stringByAppendingString: @"/"]
1379 completePathIntoString: &mpgname caseSensitive: NO
1380 matchesIntoArray: nil
1381 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1384 /* Found an mpeg inside the eyetv package, make it our scan path
1385 and call performScan on the enclosed mpeg */
1387 [self writeToActivityLog:"found mpeg in eyetv package"];
1388 [self performScan:path scanTitleNum:0];
1392 /* We did not find an mpeg file in our package, so we do not call performScan */
1393 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1396 /* We check to see if this is a .dvdmedia package */
1397 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1399 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1400 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1401 [self writeToActivityLog:"trying to open dvdmedia package"];
1402 [self performScan:path scanTitleNum:0];
1406 /* The package is not an eyetv package, so we do not call performScan */
1407 [self writeToActivityLog:"unable to open package"];
1410 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1412 /* path is not a package, so we call perform scan directly on our file */
1413 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1415 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1416 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1417 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1421 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1422 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1423 /* make sure we remove any path extension as this can also be an '.mpg' file */
1424 browsedSourceDisplayName = [[path lastPathComponent] retain];
1426 [self performScan:path scanTitleNum:0];
1434 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1435 - (IBAction) showSourceTitleScanPanel: (id) sender
1437 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1440 [fScanSrcTitleNumField setStringValue: @"0"];
1441 /* Show the panel */
1442 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1445 - (IBAction) closeSourceTitleScanPanel: (id) sender
1447 [NSApp endSheet: fScanSrcTitlePanel];
1448 [fScanSrcTitlePanel orderOut: self];
1450 if(sender == fScanSrcTitleOpenButton)
1452 /* We setup the scan status in the main window to indicate a source title scan */
1453 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1454 [fScanIndicator setHidden: NO];
1455 [fScanIndicator setIndeterminate: YES];
1456 [fScanIndicator startAnimation: nil];
1458 /* We use the performScan method to actually perform the specified scan passing the path and the title
1461 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1465 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1466 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1468 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1469 applyQueueToScan = NO;
1470 /* use a bool to determine whether or not we can decrypt using vlc */
1471 BOOL cancelScanDecrypt = 0;
1472 NSString *path = scanPath;
1473 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1475 // Notify ChapterTitles that there's no title
1476 [fChapterTitlesDelegate resetWithTitle:nil];
1477 [fChapterTable reloadData];
1479 // Notify Subtitles that there's no title
1480 [fSubtitlesDelegate resetWithTitle:nil];
1481 [fSubtitlesTable reloadData];
1483 [self enableUI: NO];
1485 if( [detector isVideoDVD] )
1487 // The chosen path was actually on a DVD, so use the raw block
1488 // device path instead.
1489 path = [detector devicePath];
1490 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1493 /* If we are 64 bit, we cannot read encrypted dvd's as vlc is 32 bit only */
1494 cancelScanDecrypt = 1;
1495 [self writeToActivityLog: "64 bit mode cannot read dvd's, scan cancelled"];
1496 /*On Screen Notification*/
1499 status = NSRunAlertPanel(@"64-bit HandBrake cannot read encrypted dvds!",@"", @"Cancel Scan", @"Attempt Scan Anyway", nil);
1500 [NSApp requestUserAttention:NSCriticalRequest];
1502 if (status == NSAlertDefaultReturn)
1504 /* User chose to cancel the scan */
1505 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1506 cancelScanDecrypt = 1;
1510 [self writeToActivityLog: "user overrode 64-bit warning trying to open physical dvd without decryption"];
1511 cancelScanDecrypt = 0;
1515 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1516 NSString *vlcPath = @"/Applications/VLC.app/Contents/MacOS/lib/libdvdcss.2.dylib";
1517 NSFileManager * fileManager = [NSFileManager defaultManager];
1518 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1520 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1521 cancelScanDecrypt = 1;
1522 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1524 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");
1525 [NSApp requestUserAttention:NSCriticalRequest];
1527 if (status == NSAlertDefaultReturn)
1529 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1530 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1532 else if (status == NSAlertAlternateReturn)
1534 /* User chose to cancel the scan */
1535 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1539 /* 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 */
1540 cancelScanDecrypt = 0;
1541 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1547 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1548 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1553 if (cancelScanDecrypt == 0)
1555 /* we actually pass the scan off to libhb here */
1556 /* If there is no title number passed to scan, we use "0"
1557 * which causes the default behavior of a full source scan
1563 if (scanTitleNum > 0)
1565 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1567 /* We use our advance pref to determine how many previews to scan */
1568 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
1569 /* set title to NULL */
1571 hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
1572 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1576 - (IBAction) showNewScan:(id)sender
1580 int indxpri=0; // Used to search the longuest title (default in combobox)
1581 int longuestpri=0; // Used to search the longuest title (default in combobox)
1584 list = hb_get_titles( fHandle );
1586 if( !hb_list_count( list ) )
1588 /* We display a message if a valid dvd source was not chosen */
1589 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1590 SuccessfulScan = NO;
1592 // Notify ChapterTitles that there's no title
1593 [fSubtitlesDelegate resetWithTitle:nil];
1594 [fSubtitlesTable reloadData];
1596 // Notify Subtitles that there's no title
1597 [fChapterTitlesDelegate resetWithTitle:nil];
1598 [fChapterTable reloadData];
1602 /* We increment the successful scancount here by one,
1603 which we use at the end of this function to tell the gui
1604 if this is the first successful scan since launch and whether
1605 or not we should set all settings to the defaults */
1607 currentSuccessfulScanCount++;
1609 [[fWindow toolbar] validateVisibleItems];
1611 [fSrcTitlePopUp removeAllItems];
1612 for( int i = 0; i < hb_list_count( list ); i++ )
1614 title = (hb_title_t *) hb_list_item( list, i );
1616 currentSource = [NSString stringWithUTF8String: title->name];
1617 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1618 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1620 /* Use the dvd name in the default output field here
1621 May want to add code to remove blank spaces for some dvd names*/
1622 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1623 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1625 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1626 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1630 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1631 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1635 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1637 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1641 [fSrcTitlePopUp addItemWithTitle: [NSString
1642 stringWithFormat: @"%d - %02dh%02dm%02ds",
1643 title->index, title->hours, title->minutes,
1647 // Select the longuest title
1648 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1649 [self titlePopUpChanged:nil];
1651 SuccessfulScan = YES;
1652 [self enableUI: YES];
1654 /* if its the initial successful scan after awakeFromNib */
1655 if (currentSuccessfulScanCount == 1)
1657 [self selectDefaultPreset:nil];
1659 // Open preview window now if it was visible when HB was closed
1660 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PreviewWindowIsOpen"])
1661 [self showPreviewWindow:nil];
1663 // Open picture sizing window now if it was visible when HB was closed
1664 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PictureSizeWindowIsOpen"])
1665 [self showPicturePanel:nil];
1676 #pragma mark New Output Destination
1678 - (IBAction) browseFile: (id) sender
1680 /* Open a panel to let the user choose and update the text field */
1681 NSSavePanel * panel = [NSSavePanel savePanel];
1682 /* We get the current file name and path from the destination field here */
1683 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1684 modalForWindow: fWindow modalDelegate: self
1685 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1689 - (void) browseFileDone: (NSSavePanel *) sheet
1690 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1692 if( returnCode == NSOKButton )
1694 [fDstFile2Field setStringValue: [sheet filename]];
1695 /* Save this path to the prefs so that on next browse destination window it opens there */
1696 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1697 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1703 #pragma mark Main Window Control
1705 - (IBAction) openMainWindow: (id) sender
1707 [fWindow makeKeyAndOrderFront:nil];
1710 - (BOOL) windowShouldClose: (id) sender
1715 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1718 [fWindow makeKeyAndOrderFront:nil];
1726 - (NSSize) drawerWillResizeContents:(NSDrawer *) drawer toSize:(NSSize) contentSize {
1727 [[NSUserDefaults standardUserDefaults] setObject:NSStringFromSize( contentSize ) forKey:@"Drawer Size"];
1732 #pragma mark Queue File
1734 - (void) loadQueueFile {
1735 /* We declare the default NSFileManager into fileManager */
1736 NSFileManager * fileManager = [NSFileManager defaultManager];
1737 /*We define the location of the user presets file */
1738 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1739 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1740 /* We check for the presets.plist */
1741 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1743 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1746 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1747 /* lets check to see if there is anything in the queue file .plist */
1748 if (nil == QueueFileArray)
1750 /* if not, then lets initialize an empty array */
1751 QueueFileArray = [[NSMutableArray alloc] init];
1753 /* Initialize our curQueueEncodeIndex to 0
1754 * so we can use it to track which queue
1755 * item is to be used to track our encodes */
1756 /* NOTE: this should be changed if and when we
1757 * are able to get the last unfinished encode
1758 * in the case of a crash or shutdown */
1763 [self clearQueueEncodedItems];
1765 currentQueueEncodeIndex = 0;
1768 - (void)addQueueFileItem
1770 [QueueFileArray addObject:[self createQueueFileItem]];
1771 [self saveQueueFileItem];
1775 - (void) removeQueueFileItem:(int) queueItemToRemove
1778 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1779 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1781 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1782 * by one to keep in sync with the queue array
1784 currentQueueEncodeIndex--;
1785 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1787 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1788 [self saveQueueFileItem];
1792 - (void)saveQueueFileItem
1794 [QueueFileArray writeToFile:QueueFile atomically:YES];
1795 [fQueueController setQueueArray: QueueFileArray];
1796 [self getQueueStats];
1799 - (void)getQueueStats
1801 /* lets get the stats on the status of the queue array */
1803 fEncodingQueueItem = 0;
1805 fCompletedCount = 0;
1809 /* We use a number system to set the encode status of the queue item
1811 * 0 == already encoded
1812 * 1 == is being encoded
1813 * 2 == is yet to be encoded
1818 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1820 while (tempObject = [enumerator nextObject])
1822 NSDictionary *thisQueueDict = tempObject;
1823 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1827 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1830 fEncodingQueueItem = i;
1832 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1836 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1843 /* Set the queue status field in the main window */
1844 NSMutableString * string;
1845 if (fPendingCount == 1)
1847 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1851 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1853 [fQueueStatus setStringValue:string];
1856 /* This method will set any item marked as encoding back to pending
1857 * currently used right after a queue reload
1859 - (void) setQueueEncodingItemsAsPending
1861 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1863 NSMutableArray *tempArray;
1864 tempArray = [NSMutableArray array];
1865 /* we look here to see if the preset is we move on to the next one */
1866 while ( tempObject = [enumerator nextObject] )
1868 /* If the queue item is marked as "encoding" (1)
1869 * then change its status back to pending (2) which effectively
1870 * puts it back into the queue to be encoded
1872 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
1874 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
1876 [tempArray addObject:tempObject];
1879 [QueueFileArray setArray:tempArray];
1880 [self saveQueueFileItem];
1884 /* This method will clear the queue of any encodes that are not still pending
1885 * this includes both successfully completed encodes as well as cancelled encodes */
1886 - (void) clearQueueEncodedItems
1888 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1890 NSMutableArray *tempArray;
1891 tempArray = [NSMutableArray array];
1892 /* we look here to see if the preset is we move on to the next one */
1893 while ( tempObject = [enumerator nextObject] )
1895 /* If the queue item is either completed (0) or cancelled (3) from the
1896 * last session, then we put it in tempArray to be deleted from QueueFileArray.
1897 * NOTE: this means we retain pending (2) and also an item that is marked as
1898 * still encoding (1). If the queue has an item that is still marked as encoding
1899 * from a previous session, we can conlude that HB was either shutdown, or crashed
1900 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
1902 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
1904 [tempArray addObject:tempObject];
1908 [QueueFileArray removeObjectsInArray:tempArray];
1909 [self saveQueueFileItem];
1912 /* This method will clear the queue of all encodes. effectively creating an empty queue */
1913 - (void) clearQueueAllItems
1915 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1917 NSMutableArray *tempArray;
1918 tempArray = [NSMutableArray array];
1919 /* we look here to see if the preset is we move on to the next one */
1920 while ( tempObject = [enumerator nextObject] )
1922 [tempArray addObject:tempObject];
1925 [QueueFileArray removeObjectsInArray:tempArray];
1926 [self saveQueueFileItem];
1929 /* This method will duplicate prepareJob however into the
1930 * queue .plist instead of into the job structure so it can
1931 * be recalled later */
1932 - (NSDictionary *)createQueueFileItem
1934 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1936 hb_list_t * list = hb_get_titles( fHandle );
1937 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1938 [fSrcTitlePopUp indexOfSelectedItem] );
1939 hb_job_t * job = title->job;
1943 /* We use a number system to set the encode status of the queue item
1944 * 0 == already encoded
1945 * 1 == is being encoded
1946 * 2 == is yet to be encoded
1949 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1950 /* Source and Destination Information */
1952 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1953 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1954 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1955 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcAnglePopUp indexOfSelectedItem] + 1] forKey:@"TitleAngle"];
1956 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1958 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1960 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1962 /* Lets get the preset info if there is any */
1963 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1964 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1966 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1967 /* Chapter Markers*/
1968 /* If we have only one chapter or a title without chapters, set chapter markers to off */
1969 if ([fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem])
1971 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
1975 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1978 /* We need to get the list of chapter names to put into an array and store
1979 * in our queue, so they can be reapplied in prepareJob when this queue
1980 * item comes up if Chapter Markers is set to on.
1983 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
1984 int chaptercount = hb_list_count( fTitle->list_chapter );
1985 for( i = 0; i < chaptercount; i++ )
1987 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
1988 if( chapter != NULL )
1990 [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
1993 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
1994 [ChapterNamesArray autorelease];
1996 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1997 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1998 /* Mux mp4 with http optimization */
1999 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
2000 /* Add iPod uuid atom */
2001 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
2005 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2006 /* x264 Option String */
2007 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2009 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2010 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2011 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2012 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
2014 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2016 /* 2 Pass Encoding */
2017 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2018 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2019 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2021 /* Picture Sizing */
2022 /* Use Max Picture settings for whatever the dvd is.*/
2023 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2024 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2025 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2026 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2027 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2028 /* if we are custom anamorphic, store the exact storage, par and display dims */
2029 if (fTitle->job->anamorphic.mode == 3)
2031 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
2032 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
2034 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_width] forKey:@"PicturePARPixelWidth"];
2035 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_height] forKey:@"PicturePARPixelHeight"];
2037 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_width] forKey:@"PicturePARDisplayWidth"];
2038 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_height] forKey:@"PicturePARDisplayHeight"];
2041 NSString * pictureSummary;
2042 pictureSummary = [fPictureSizeField stringValue];
2043 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
2044 /* Set crop settings here */
2045 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2046 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2047 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2048 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2049 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2051 /* Picture Filters */
2052 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2053 [queueFileJob setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
2055 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
2056 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
2057 [queueFileJob setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
2059 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2060 [queueFileJob setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
2062 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2063 [queueFileJob setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
2065 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
2067 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
2070 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2072 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
2073 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
2074 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
2075 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
2076 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
2077 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
2078 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
2080 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2082 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
2083 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
2084 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
2085 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
2086 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
2087 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
2088 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
2090 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2092 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
2093 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
2094 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
2095 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
2096 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
2097 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
2098 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
2100 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2102 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
2103 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
2104 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
2105 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
2106 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
2107 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
2108 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
2112 NSMutableArray *subtitlesArray = [[NSMutableArray alloc] init];
2113 [queueFileJob setObject:[NSArray arrayWithArray: [fSubtitlesDelegate getSubtitleArray: subtitlesArray]] forKey:@"SubtitleList"];
2114 [subtitlesArray autorelease];
2116 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
2118 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
2120 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
2123 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
2127 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
2130 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
2131 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
2132 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
2134 /* Picture Sizing */
2135 /* Use Max Picture settings for whatever the dvd is.*/
2136 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2137 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2138 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2139 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2140 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2142 /* Set crop settings here */
2143 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2144 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2145 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2146 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2147 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2151 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2153 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
2154 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
2155 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
2156 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
2157 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
2159 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2161 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
2162 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
2163 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
2164 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
2165 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
2167 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2169 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
2170 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
2171 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
2172 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
2173 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
2175 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2177 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
2178 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
2179 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
2180 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
2181 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
2185 /* we need to auto relase the queueFileJob and return it */
2186 [queueFileJob autorelease];
2187 return queueFileJob;
2191 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
2192 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
2194 NSUInteger index = [indexSet lastIndex];
2195 NSUInteger aboveInsertIndexCount = 0;
2198 NSUInteger removeIndex;
2200 if (index >= insertIndex)
2202 removeIndex = index + aboveInsertIndexCount;
2203 aboveInsertIndexCount++;
2207 removeIndex = index;
2211 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2212 [QueueFileArray removeObjectAtIndex:removeIndex];
2213 [QueueFileArray insertObject:object atIndex:insertIndex];
2216 index = [indexSet indexLessThanIndex:index];
2218 /* We save all of the Queue data here
2219 * and it also gets sent back to the queue controller*/
2220 [self saveQueueFileItem];
2226 #pragma mark Queue Job Processing
2228 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2230 int i = currentQueueEncodeIndex;
2231 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2233 /* We save all of the Queue data here */
2234 [self saveQueueFileItem];
2235 /* We Reload the New Table data for presets */
2236 //[fPresetsOutlineView reloadData];
2238 /* Since we have now marked a queue item as done
2239 * we can go ahead and increment currentQueueEncodeIndex
2240 * so that if there is anything left in the queue we can
2241 * go ahead and move to the next item if we want to */
2242 currentQueueEncodeIndex++ ;
2243 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2244 int queueItems = [QueueFileArray count];
2245 /* If we still have more items in our queue, lets go to the next one */
2246 if (currentQueueEncodeIndex < queueItems)
2248 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2249 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2253 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2257 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2258 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2260 /* Tell HB to output a new activity log file for this encode */
2261 [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
2264 /* use a bool to determine whether or not we can decrypt using vlc */
2265 BOOL cancelScanDecrypt = 0;
2266 /* set the bool so that showNewScan knows to apply the appropriate queue
2267 * settings as this is a queue rescan
2269 applyQueueToScan = YES;
2270 NSString *path = scanPath;
2271 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2273 /*On Screen Notification*/
2275 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2276 //[NSApp requestUserAttention:NSCriticalRequest];
2278 if( [detector isVideoDVD] )
2280 // The chosen path was actually on a DVD, so use the raw block
2281 // device path instead.
2282 path = [detector devicePath];
2283 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2285 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2286 NSString *vlcPath = @"/Applications/VLC.app";
2287 NSFileManager * fileManager = [NSFileManager defaultManager];
2288 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2290 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2291 cancelScanDecrypt = 1;
2292 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2294 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");
2295 [NSApp requestUserAttention:NSCriticalRequest];
2297 if (status == NSAlertDefaultReturn)
2299 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2300 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2302 else if (status == NSAlertAlternateReturn)
2304 /* User chose to cancel the scan */
2305 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2309 /* 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 */
2310 cancelScanDecrypt = 0;
2311 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2317 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2318 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2322 if (cancelScanDecrypt == 0)
2324 /* we actually pass the scan off to libhb here */
2325 /* If there is no title number passed to scan, we use "0"
2326 * which causes the default behavior of a full source scan
2332 if (scanTitleNum > 0)
2334 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2337 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2338 /* We use our advance pref to determine how many previews to scan */
2339 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
2340 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
2344 /* This method was originally used to load up a new queue item in the gui and
2345 * then start processing it. However we now have modified -prepareJob and use a second
2346 * instance of libhb to do our actual encoding, therefor right now it is not required.
2347 * Nonetheless I want to leave this in here
2348 * because basically its everything we need to be able to actually modify a pending queue
2349 * item in the gui and resave it. At least for now - dynaflash
2352 - (IBAction)applyQueueSettings:(id)sender
2354 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2355 hb_job_t * job = fTitle->job;
2357 /* Set title number and chapters */
2358 /* since the queue only scans a single title, we really don't need to pick a title */
2359 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2361 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2362 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2365 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2366 [self formatPopUpChanged:nil];
2368 /* Chapter Markers*/
2369 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2370 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2371 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2372 /* Mux mp4 with http optimization */
2373 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2376 /* We set the advanced opt string here if applicable*/
2377 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2378 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2380 /* Lets run through the following functions to get variables set there */
2381 [self videoEncoderPopUpChanged:nil];
2382 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2383 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2384 [self calculateBitrate:nil];
2387 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2389 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2390 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2391 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2393 [self videoMatrixChanged:nil];
2395 /* Video framerate */
2396 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2397 detected framerate in the fVidRatePopUp so we use index 0*/
2398 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2400 [fVidRatePopUp selectItemAtIndex: 0];
2404 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2407 /* 2 Pass Encoding */
2408 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2409 [self twoPassCheckboxChanged:nil];
2410 /* Turbo 1st pass for 2 Pass Encoding */
2411 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2414 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2416 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2418 [fAudLang1PopUp selectItemAtIndex: 1];
2420 [self audioTrackPopUpChanged: fAudLang1PopUp];
2421 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2422 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2423 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2424 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2426 if ([fAudTrack1MixPopUp selectedItem] == nil)
2428 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2430 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2431 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2432 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2434 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2436 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2437 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2439 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2441 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2443 [fAudLang2PopUp selectItemAtIndex: 1];
2445 [self audioTrackPopUpChanged: fAudLang2PopUp];
2446 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2447 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2448 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2449 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2451 if ([fAudTrack2MixPopUp selectedItem] == nil)
2453 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2455 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2456 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2457 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2459 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2461 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2462 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2464 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2466 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2468 [fAudLang3PopUp selectItemAtIndex: 1];
2470 [self audioTrackPopUpChanged: fAudLang3PopUp];
2471 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2472 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2473 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2474 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2476 if ([fAudTrack3MixPopUp selectedItem] == nil)
2478 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2480 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2481 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2482 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2484 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2486 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2487 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2489 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2491 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2493 [fAudLang4PopUp selectItemAtIndex: 1];
2495 [self audioTrackPopUpChanged: fAudLang4PopUp];
2496 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2497 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2498 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2499 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2501 if ([fAudTrack4MixPopUp selectedItem] == nil)
2503 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2505 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2506 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2507 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2509 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2511 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2512 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2517 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2518 /* Forced Subtitles */
2519 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2521 /* Picture Settings */
2522 /* we check to make sure the presets width/height does not exceed the sources width/height */
2523 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2525 /* if so, then we use the sources height and width to avoid scaling up */
2526 job->width = fTitle->width;
2527 job->height = fTitle->height;
2529 else // source width/height is >= the preset height/width
2531 /* we can go ahead and use the presets values for height and width */
2532 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2533 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2535 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2536 if (job->keep_ratio == 1)
2538 hb_fix_aspect( job, HB_KEEP_WIDTH );
2539 if( job->height > fTitle->height )
2541 job->height = fTitle->height;
2542 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2545 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2548 /* If Cropping is set to custom, then recall all four crop values from
2549 when the preset was created and apply them */
2550 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2552 [fPictureController setAutoCrop:NO];
2554 /* Here we use the custom crop values saved at the time the preset was saved */
2555 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2556 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2557 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2558 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2561 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2563 [fPictureController setAutoCrop:YES];
2564 /* Here we use the auto crop values determined right after scan */
2565 job->crop[0] = AutoCropTop;
2566 job->crop[1] = AutoCropBottom;
2567 job->crop[2] = AutoCropLeft;
2568 job->crop[3] = AutoCropRight;
2574 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2577 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2579 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2581 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2583 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2585 [fPictureController setGrayscale:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2587 [self calculatePictureSizing:nil];
2590 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2591 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2592 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2593 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2595 /* Deselect the currently selected Preset if there is one*/
2596 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2597 //[self selectPreset:nil];
2599 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2600 /* Change UI to show "Custom" settings are being used */
2601 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2603 curUserPresetChosenNum = nil;
2607 /* Deselect the currently selected Preset if there is one*/
2608 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2609 /* Change UI to show "Custom" settings are being used */
2610 [fPresetSelectedDisplay setStringValue: @"Custom"];
2612 //curUserPresetChosenNum = nil;
2615 /* We need to set this bool back to NO, in case the user wants to do a scan */
2616 //applyQueueToScan = NO;
2618 /* so now we go ahead and process the new settings */
2619 [self processNewQueueEncode];
2624 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2625 - (void) processNewQueueEncode
2627 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2628 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2629 hb_job_t * job = title->job;
2631 if( !hb_list_count( list ) )
2633 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2636 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2637 [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
2638 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2639 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2640 //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2644 * If scanning we need to do some extra setup of the job.
2646 if( job->indepth_scan == 1 )
2651 * When subtitle scan is enabled do a fast pre-scan job
2652 * which will determine which subtitles to enable, if any.
2655 x264opts_tmp = job->x264opts;
2657 job->x264opts = NULL;
2659 job->indepth_scan = 1;
2663 * Add the pre-scan job
2665 hb_add( fQueueEncodeLibhb, job );
2666 job->x264opts = x264opts_tmp;
2670 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2672 job->indepth_scan = 0;
2678 hb_add( fQueueEncodeLibhb, job );
2682 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2683 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2685 hb_add( fQueueEncodeLibhb, job );
2690 job->indepth_scan = 0;
2693 hb_add( fQueueEncodeLibhb, job );
2696 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2697 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2698 /* Lets mark our new encode as 1 or "Encoding" */
2699 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2700 [self saveQueueFileItem];
2702 /* we need to clean up the subtitle tracks after the job(s) have been set */
2703 int num_subtitle_tracks = hb_list_count(job->list_subtitle);
2705 for(ii = 0; ii < num_subtitle_tracks; ii++)
2707 hb_subtitle_t * subtitle;
2708 subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
2711 hb_list_rem(job->list_subtitle, subtitle);
2716 /* We should be all setup so let 'er rip */
2721 #pragma mark Live Preview
2722 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
2723 * can encode to its temp preview directory and playback. This is *not* used for any actual user
2726 - (void) prepareJobForPreview
2728 hb_list_t * list = hb_get_titles( fHandle );
2729 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2730 [fSrcTitlePopUp indexOfSelectedItem] );
2731 hb_job_t * job = title->job;
2732 hb_audio_config_t * audio;
2733 /* set job->angle for libdvdnav */
2734 job->angle = [fSrcAnglePopUp indexOfSelectedItem] + 1;
2735 /* Chapter selection */
2736 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
2737 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
2739 /* Format (Muxer) and Video Encoder */
2740 job->mux = [[fDstFormatPopUp selectedItem] tag];
2741 job->vcodec = [[fVidEncoderPopUp selectedItem] tag];
2743 job->chapter_markers = 0;
2745 if( job->vcodec & HB_VCODEC_X264 )
2747 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2748 Currently only used with Constant Quality setting*/
2749 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
2754 /* Below Sends x264 options to the core library if x264 is selected*/
2755 /* Lets use this as per Nyx, Thanks Nyx!*/
2756 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2757 /* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
2758 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
2763 /* Video settings */
2764 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2765 * and detelecine is on, so we handle that in the logic below
2768 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
2770 /* a specific framerate has been chosen */
2771 job->vrate = 27000000;
2772 job->vrate_base = hb_video_rates[[fVidRatePopUp indexOfSelectedItem]-1].rate;
2773 /* We are not same as source so we set job->cfr to 1
2774 * to enable constant frame rate since user has specified
2775 * a specific framerate*/
2780 /* We are same as source (variable) */
2781 job->vrate = title->rate;
2782 job->vrate_base = title->rate_base;
2783 /* We are same as source so we set job->cfr to 0
2784 * to enable true same as source framerate */
2786 /* If we are same as source and we have detelecine on, we need to turn on
2789 if ([fPictureController detelecine] == 1)
2795 switch( [fVidQualityMatrix selectedRow] )
2799 Bitrate should already have been calculated and displayed
2800 in fVidBitrateField, so let's just use it */
2802 job->vquality = -1.0;
2803 job->vbitrate = [fVidBitrateField intValue];
2806 job->vquality = [fVidQualityRFField floatValue];
2811 /* Subtitle settings */
2812 NSMutableArray *subtitlesArray = nil;
2813 subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray: subtitlesArray]];
2821 bool one_burned = FALSE;
2824 NSEnumerator *enumerator = [subtitlesArray objectEnumerator];
2826 while (tempObject = [enumerator nextObject])
2829 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
2830 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
2831 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
2832 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
2834 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
2835 * we want to ignore it for display as well as encoding.
2839 /* if i is 0, then we are in the first item of the subtitles which we need to
2840 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
2841 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
2844 /* if we are on the first track and using "Foreign Audio Search" */
2845 if (i == 0 && subtitle == 1)
2847 /* NOTE: Currently foreign language search is borked for preview.
2848 * Commented out but left in for initial commit. */
2851 [self writeToActivityLog: "Foreign Language Search: %d", 1];
2853 job->indepth_scan = 1;
2854 if (burned == 1 || job->mux != HB_MUX_MP4)
2856 if (burned != 1 && job->mux == HB_MUX_MKV)
2858 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2861 job->select_subtitle_config.force = force;
2862 job->select_subtitle_config.default_track = def;
2871 /* for the actual source tracks, we must subtract the non source entries so
2872 * that the menu index matches the source subtitle_list index for convenience */
2875 /* for the first track, the source tracks start at menu index 2 ( None is 0,
2876 * Foreign Language Search is 1) so subtract 2 */
2877 subtitle = subtitle - 2;
2881 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
2884 subtitle = subtitle - 1;
2887 /* We are setting a source subtitle so access the source subtitle info */
2888 hb_subtitle_t * subt;
2890 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
2894 [self writeToActivityLog: "Setting Subtitle: %s", subt];
2896 hb_subtitle_config_t sub_config = subt->config;
2898 if (!burned && job->mux == HB_MUX_MKV &&
2899 subt->format == hb_subtitle_s::PICTURESUB)
2901 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2903 else if (!burned && job->mux == HB_MUX_MP4 &&
2904 subt->format == hb_subtitle_s::PICTURESUB)
2906 // Skip any non-burned vobsubs when output is mp4
2909 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
2911 // Only allow one subtitle to be burned into the video
2916 sub_config.force = force;
2917 sub_config.default_track = def;
2918 hb_subtitle_add( job, &sub_config, subtitle );
2928 [subtitlesArray autorelease];
2931 /* Audio tracks and mixdowns */
2932 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2933 int audiotrack_count = hb_list_count(job->list_audio);
2934 for( int i = 0; i < audiotrack_count;i++)
2936 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2937 hb_list_rem(job->list_audio, temp_audio);
2939 /* Now lets add our new tracks to the audio list here */
2940 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2942 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2943 hb_audio_config_init(audio);
2944 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2945 /* We go ahead and assign values to our audio->out.<properties> */
2946 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2947 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
2948 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
2949 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
2950 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
2951 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
2953 hb_audio_add( job, audio );
2956 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2958 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2959 hb_audio_config_init(audio);
2960 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2961 /* We go ahead and assign values to our audio->out.<properties> */
2962 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2963 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
2964 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
2965 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
2966 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
2967 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
2969 hb_audio_add( job, audio );
2974 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2976 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2977 hb_audio_config_init(audio);
2978 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2979 /* We go ahead and assign values to our audio->out.<properties> */
2980 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2981 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
2982 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
2983 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
2984 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
2985 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
2987 hb_audio_add( job, audio );
2992 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2994 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2995 hb_audio_config_init(audio);
2996 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
2997 /* We go ahead and assign values to our audio->out.<properties> */
2998 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
2999 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
3000 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
3001 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
3002 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
3003 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
3005 hb_audio_add( job, audio );
3014 /* Though Grayscale is not really a filter, per se
3015 * we put it here since its in the filters panel
3018 if ([fPictureController grayscale])
3027 /* Initialize the filters list */
3028 job->filters = hb_list_init();
3030 /* Now lets call the filters if applicable.
3031 * The order of the filters is critical
3035 if ([fPictureController detelecine] == 1)
3037 hb_list_add( job->filters, &hb_filter_detelecine );
3039 if ([fPictureController detelecine] == 2)
3041 /* use a custom detelecine string */
3042 hb_filter_detelecine.settings = (char *) [[fPictureController detelecineCustomString] UTF8String];
3043 hb_list_add( job->filters, &hb_filter_detelecine );
3045 if ([fPictureController useDecomb] == 1)
3048 if ([fPictureController decomb] == 1)
3050 /* Run old deinterlacer fd by default */
3051 //hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
3052 hb_list_add( job->filters, &hb_filter_decomb );
3054 /* we add the custom string if present */
3055 if ([fPictureController decomb] == 2)
3057 /* use a custom decomb string */
3058 hb_filter_decomb.settings = (char *) [[fPictureController decombCustomString] UTF8String];
3059 hb_list_add( job->filters, &hb_filter_decomb );
3066 if ([fPictureController deinterlace] == 1)
3068 /* Run old deinterlacer fd by default */
3069 hb_filter_deinterlace.settings = "-1";
3070 hb_list_add( job->filters, &hb_filter_deinterlace );
3072 else if ([fPictureController deinterlace] == 2)
3074 /* Yadif mode 0 (without spatial deinterlacing.) */
3075 hb_filter_deinterlace.settings = "2";
3076 hb_list_add( job->filters, &hb_filter_deinterlace );
3078 else if ([fPictureController deinterlace] == 3)
3080 /* Yadif (with spatial deinterlacing) */
3081 hb_filter_deinterlace.settings = "0";
3082 hb_list_add( job->filters, &hb_filter_deinterlace );
3084 else if ([fPictureController deinterlace] == 4)
3086 /* we add the custom string if present */
3087 hb_filter_deinterlace.settings = (char *) [[fPictureController deinterlaceCustomString] UTF8String];
3088 hb_list_add( job->filters, &hb_filter_deinterlace );
3093 if ([fPictureController denoise] == 1) // Weak in popup
3095 hb_filter_denoise.settings = "2:1:2:3";
3096 hb_list_add( job->filters, &hb_filter_denoise );
3098 else if ([fPictureController denoise] == 2) // Medium in popup
3100 hb_filter_denoise.settings = "3:2:2:3";
3101 hb_list_add( job->filters, &hb_filter_denoise );
3103 else if ([fPictureController denoise] == 3) // Strong in popup
3105 hb_filter_denoise.settings = "7:7:5:5";
3106 hb_list_add( job->filters, &hb_filter_denoise );
3108 else if ([fPictureController denoise] == 4) // custom in popup
3110 /* we add the custom string if present */
3111 hb_filter_denoise.settings = (char *) [[fPictureController denoiseCustomString] UTF8String];
3112 hb_list_add( job->filters, &hb_filter_denoise );
3115 /* Deblock (uses pp7 default) */
3116 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3117 * the macgui's purposes a value of 0 actually means to not even use the filter
3118 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3120 if ([fPictureController deblock] != 0)
3122 NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
3123 hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
3124 hb_list_add( job->filters, &hb_filter_deblock );
3131 #pragma mark Job Handling
3137 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
3138 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
3139 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
3140 hb_job_t * job = title->job;
3141 hb_audio_config_t * audio;
3142 /* Title Angle for dvdnav */
3143 job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
3144 /* Chapter selection */
3145 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
3146 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
3148 /* Format (Muxer) and Video Encoder */
3149 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
3150 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
3153 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
3154 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
3156 job->largeFileSize = 1;
3160 job->largeFileSize = 0;
3162 /* We set http optimized mp4 here */
3163 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
3165 job->mp4_optimize = 1;
3169 job->mp4_optimize = 0;
3173 /* We set the chapter marker extraction here based on the format being
3174 mpeg4 or mkv and the checkbox being checked */
3175 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
3177 job->chapter_markers = 1;
3179 /* now lets get our saved chapter names out the array in the queue file
3180 * and insert them back into the title chapter list. We have it here,
3181 * because unless we are inserting chapter markers there is no need to
3182 * spend the overhead of iterating through the chapter names array imo
3183 * Also, note that if for some reason we don't apply chapter names, the
3184 * chapters just come out 001, 002, etc. etc.
3187 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
3189 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
3191 while (tempObject = [enumerator nextObject])
3193 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3194 if( chapter != NULL )
3196 strncpy( chapter->title, [tempObject UTF8String], 1023);
3197 chapter->title[1023] = '\0';
3204 job->chapter_markers = 0;
3207 if( job->vcodec & HB_VCODEC_X264 )
3209 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
3218 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
3219 Currently only used with Constant Quality setting*/
3220 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
3224 /* Below Sends x264 options to the core library if x264 is selected*/
3225 /* Lets use this as per Nyx, Thanks Nyx!*/
3226 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
3227 /* Turbo first pass if two pass and Turbo First pass is selected */
3228 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
3230 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
3231 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
3232 /* append the "Turbo" string variable to the existing opts string.
3233 Note: the "Turbo" string must be appended, not prepended to work properly*/
3234 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
3235 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
3239 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
3245 /* Picture Size Settings */
3246 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
3247 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
3249 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
3250 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
3251 if ([[queueToApply objectForKey:@"PicturePAR"] intValue] == 3)
3253 /* insert our custom values here for capuj */
3254 job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"] intValue];
3255 job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"] intValue];
3257 job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"] intValue];
3258 job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"] intValue];
3260 job->anamorphic.dar_width = [[queueToApply objectForKey:@"PicturePARDisplayWidth"] floatValue];
3261 job->anamorphic.dar_height = [[queueToApply objectForKey:@"PicturePARDisplayHeight"] floatValue];
3264 /* Here we use the crop values saved at the time the preset was saved */
3265 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
3266 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
3267 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
3268 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
3270 /* Video settings */
3273 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
3274 * and detelecine is on, so we handle that in the logic below
3277 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
3279 /* a specific framerate has been chosen */
3280 job->vrate = 27000000;
3281 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
3282 /* We are not same as source so we set job->cfr to 1
3283 * to enable constant frame rate since user has specified
3284 * a specific framerate*/
3289 /* We are same as source (variable) */
3290 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
3291 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
3292 /* We are same as source so we set job->cfr to 0
3293 * to enable true same as source framerate */
3295 /* If we are same as source and we have detelecine on, we need to turn on
3298 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3304 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
3307 Bitrate should already have been calculated and displayed
3308 in fVidBitrateField, so let's just use it same as abr*/
3309 job->vquality = -1.0;
3310 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
3312 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
3314 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
3319 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
3324 #pragma mark Process Subtitles to libhb
3326 /* Map the settings in the dictionaries for the SubtitleList array to match title->list_subtitle
3327 * which means that we need to account for the offset of non source language settings in from
3328 * the NSPopUpCell menu. For all of the objects in the SubtitleList array this means 0 is "None"
3329 * from the popup menu, additionally the first track has "Foreign Audio Search" at 1. So we use
3330 * an int to offset the index number for the objectForKey:@"subtitleSourceTrackNum" to map that
3331 * to the source tracks position in title->list_subtitle.
3338 bool one_burned = FALSE;
3341 NSEnumerator *enumerator = [[queueToApply objectForKey:@"SubtitleList"] objectEnumerator];
3343 while (tempObject = [enumerator nextObject])
3346 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
3347 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
3348 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
3349 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
3351 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
3352 * we want to ignore it for display as well as encoding.
3356 /* if i is 0, then we are in the first item of the subtitles which we need to
3357 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
3358 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
3361 /* if we are on the first track and using "Foreign Audio Search" */
3362 if (i == 0 && subtitle == 1)
3364 [self writeToActivityLog: "Foreign Language Search: %d", 1];
3366 job->indepth_scan = 1;
3367 if (burned == 1 || job->mux != HB_MUX_MP4)
3369 if (burned != 1 && job->mux == HB_MUX_MKV)
3371 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3375 job->select_subtitle_config.dest = hb_subtitle_config_s::RENDERSUB;
3378 job->select_subtitle_config.force = force;
3379 job->select_subtitle_config.default_track = def;
3387 /* for the actual source tracks, we must subtract the non source entries so
3388 * that the menu index matches the source subtitle_list index for convenience */
3391 /* for the first track, the source tracks start at menu index 2 ( None is 0,
3392 * Foreign Language Search is 1) so subtract 2 */
3393 subtitle = subtitle - 2;
3397 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
3400 subtitle = subtitle - 1;
3403 /* We are setting a source subtitle so access the source subtitle info */
3404 hb_subtitle_t * subt;
3406 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3410 [self writeToActivityLog: "Setting Subtitle: %s", subt];
3412 hb_subtitle_config_t sub_config = subt->config;
3414 if (!burned && job->mux == HB_MUX_MKV &&
3415 subt->format == hb_subtitle_s::PICTURESUB)
3417 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3419 else if (!burned && job->mux == HB_MUX_MP4 &&
3420 subt->format == hb_subtitle_s::PICTURESUB)
3422 // Skip any non-burned vobsubs when output is mp4
3425 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
3427 // Only allow one subtitle to be burned into the video
3432 sub_config.force = force;
3433 sub_config.default_track = def;
3434 hb_subtitle_add( job, &sub_config, subtitle );
3445 /* Audio tracks and mixdowns */
3446 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3447 int audiotrack_count = hb_list_count(job->list_audio);
3448 for( int i = 0; i < audiotrack_count;i++)
3450 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3451 hb_list_rem(job->list_audio, temp_audio);
3453 /* Now lets add our new tracks to the audio list here */
3454 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
3456 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3457 hb_audio_config_init(audio);
3458 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3459 /* We go ahead and assign values to our audio->out.<properties> */
3460 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3461 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
3462 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
3463 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
3464 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
3465 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
3467 hb_audio_add( job, audio );
3470 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
3473 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3474 hb_audio_config_init(audio);
3475 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3476 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
3477 /* We go ahead and assign values to our audio->out.<properties> */
3478 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3479 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
3480 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
3481 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
3482 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
3483 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
3485 hb_audio_add( job, audio );
3489 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
3491 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3492 hb_audio_config_init(audio);
3493 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3494 /* We go ahead and assign values to our audio->out.<properties> */
3495 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3496 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
3497 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
3498 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
3499 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
3500 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
3502 hb_audio_add( job, audio );
3506 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
3508 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3509 hb_audio_config_init(audio);
3510 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3511 /* We go ahead and assign values to our audio->out.<properties> */
3512 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3513 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
3514 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
3515 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
3516 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
3517 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue];
3519 hb_audio_add( job, audio );
3525 job->filters = hb_list_init();
3527 /* Now lets call the filters if applicable.
3528 * The order of the filters is critical
3531 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3533 //if ([queueToApply objectForKey:@"PictureDetelecineCustom"])
3534 hb_list_add( job->filters, &hb_filter_detelecine );
3536 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 2)
3538 /* use a custom detelecine string */
3539 hb_filter_detelecine.settings = (char *) [[queueToApply objectForKey:@"PictureDetelecineCustom"] UTF8String];
3540 hb_list_add( job->filters, &hb_filter_detelecine );
3543 if ([[queueToApply objectForKey:@"PictureDecombDeinterlace"] intValue] == 1)
3546 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
3548 /* Run old deinterlacer fd by default */
3549 hb_list_add( job->filters, &hb_filter_decomb );
3551 /* we add the custom string if present */
3552 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 2)
3554 /* use a custom decomb string */
3555 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"PictureDecombCustom"] UTF8String];
3556 hb_list_add( job->filters, &hb_filter_decomb );
3564 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
3566 /* Run old deinterlacer fd by default */
3567 hb_filter_deinterlace.settings = "-1";
3568 hb_list_add( job->filters, &hb_filter_deinterlace );
3570 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
3572 /* Yadif mode 0 (without spatial deinterlacing.) */
3573 hb_filter_deinterlace.settings = "2";
3574 hb_list_add( job->filters, &hb_filter_deinterlace );
3576 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
3578 /* Yadif (with spatial deinterlacing) */
3579 hb_filter_deinterlace.settings = "0";
3580 hb_list_add( job->filters, &hb_filter_deinterlace );
3582 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 4)
3584 /* we add the custom string if present */
3585 hb_filter_deinterlace.settings = (char *) [[queueToApply objectForKey:@"PictureDeinterlaceCustom"] UTF8String];
3586 hb_list_add( job->filters, &hb_filter_deinterlace );
3592 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
3594 hb_filter_denoise.settings = "2:1:2:3";
3595 hb_list_add( job->filters, &hb_filter_denoise );
3597 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
3599 hb_filter_denoise.settings = "3:2:2:3";
3600 hb_list_add( job->filters, &hb_filter_denoise );
3602 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
3604 hb_filter_denoise.settings = "7:7:5:5";
3605 hb_list_add( job->filters, &hb_filter_denoise );
3607 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 4) // Custom in popup
3609 /* we add the custom string if present */
3610 hb_filter_denoise.settings = (char *) [[queueToApply objectForKey:@"PictureDenoiseCustom"] UTF8String];
3611 hb_list_add( job->filters, &hb_filter_denoise );
3614 /* Deblock (uses pp7 default) */
3615 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3616 * the macgui's purposes a value of 0 actually means to not even use the filter
3617 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3619 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
3621 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
3622 hb_list_add( job->filters, &hb_filter_deblock );
3624 [self writeToActivityLog: "prepareJob exiting"];
3629 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
3631 - (IBAction) addToQueue: (id) sender
3633 /* We get the destination directory from the destination field here */
3634 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3635 /* We check for a valid destination here */
3636 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3638 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3645 BOOL fileExistsInQueue;
3646 fileExistsInQueue = NO;
3648 /* We check for and existing file here */
3649 if([[NSFileManager defaultManager] fileExistsAtPath: [fDstFile2Field stringValue]])
3654 /* We now run through the queue and make sure we are not overwriting an exisiting queue item */
3656 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
3658 while (tempObject = [enumerator nextObject])
3660 NSDictionary *thisQueueDict = tempObject;
3661 if ([[thisQueueDict objectForKey:@"DestinationPath"] isEqualToString: [fDstFile2Field stringValue]])
3663 fileExistsInQueue = YES;
3669 if(fileExists == YES)
3671 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists.", @"" ),
3672 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3673 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3674 NULL, NULL, [NSString stringWithFormat:
3675 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3676 [fDstFile2Field stringValue]] );
3678 else if (fileExistsInQueue == YES)
3680 NSBeginCriticalAlertSheet( NSLocalizedString( @"There is already a queue item for this destination.", @"" ),
3681 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3682 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3683 NULL, NULL, [NSString stringWithFormat:
3684 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3685 [fDstFile2Field stringValue]] );
3689 [self doAddToQueue];
3693 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
3694 the user if they want to overwrite an exiting movie file.
3696 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
3697 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3699 if( returnCode == NSAlertAlternateReturn )
3700 [self doAddToQueue];
3703 - (void) doAddToQueue
3705 [self addQueueFileItem ];
3710 /* Rip: puts up an alert before ultimately calling doRip
3712 - (IBAction) Rip: (id) sender
3714 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
3715 /* Rip or Cancel ? */
3717 hb_get_state2( fQueueEncodeLibhb, &s );
3719 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
3721 [self Cancel: sender];
3725 /* We check to see if we need to warn the user that the computer will go to sleep
3726 or shut down when encoding is finished */
3727 [self remindUserOfSleepOrShutdown];
3729 // If there are pending jobs in the queue, then this is a rip the queue
3730 if (fPendingCount > 0)
3732 /* here lets start the queue with the first pending item */
3733 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3738 // Before adding jobs to the queue, check for a valid destination.
3740 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3741 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3743 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3747 /* We check for duplicate name here */
3748 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
3750 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3751 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3752 @selector( overWriteAlertDone:returnCode:contextInfo: ),
3753 NULL, NULL, [NSString stringWithFormat:
3754 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3755 [fDstFile2Field stringValue]] );
3757 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
3761 /* if there are no pending jobs in the queue, then add this one to the queue and rip
3762 otherwise, just rip the queue */
3763 if(fPendingCount == 0)
3765 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
3766 [self doAddToQueue];
3769 /* go right to processing the new queue encode */
3770 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
3771 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3776 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3777 want to overwrite an exiting movie file.
3779 - (void) overWriteAlertDone: (NSWindow *) sheet
3780 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3782 if( returnCode == NSAlertAlternateReturn )
3784 /* if there are no jobs in the queue, then add this one to the queue and rip
3785 otherwise, just rip the queue */
3786 if( fPendingCount == 0 )
3788 [self doAddToQueue];
3791 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3792 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3793 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3798 - (void) remindUserOfSleepOrShutdown
3800 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
3802 /*Warn that computer will sleep after encoding*/
3805 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);
3806 [NSApp requestUserAttention:NSCriticalRequest];
3807 if ( reminduser == NSAlertAlternateReturn )
3809 [self showPreferencesWindow:nil];
3812 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
3814 /*Warn that computer will shut down after encoding*/
3817 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);
3818 [NSApp requestUserAttention:NSCriticalRequest];
3819 if ( reminduser == NSAlertAlternateReturn )
3821 [self showPreferencesWindow:nil];
3830 /* Let libhb do the job */
3831 hb_start( fQueueEncodeLibhb );
3832 /*set the fEncodeState State */
3837 //------------------------------------------------------------------------------------
3838 // Displays an alert asking user if the want to cancel encoding of current job.
3839 // Cancel: returns immediately after posting the alert. Later, when the user
3840 // acknowledges the alert, doCancelCurrentJob is called.
3841 //------------------------------------------------------------------------------------
3842 - (IBAction)Cancel: (id)sender
3844 if (!fQueueController) return;
3846 hb_pause( fQueueEncodeLibhb );
3847 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3849 // Which window to attach the sheet to?
3850 NSWindow * docWindow;
3851 if ([sender respondsToSelector: @selector(window)])
3852 docWindow = [sender window];
3854 docWindow = fWindow;
3856 NSBeginCriticalAlertSheet(
3858 NSLocalizedString(@"Continue Encoding", nil),
3859 NSLocalizedString(@"Cancel Current and Stop", nil),
3860 NSLocalizedString(@"Cancel Current and Continue", nil),
3862 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3863 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3865 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3868 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3870 hb_resume( fQueueEncodeLibhb );
3871 if (returnCode == NSAlertOtherReturn)
3873 [self doCancelCurrentJob]; // <- this also stops libhb
3875 if (returnCode == NSAlertAlternateReturn)
3877 [self doCancelCurrentJobAndStop];
3881 //------------------------------------------------------------------------------------
3882 // Cancels and deletes the current job and stops libhb from processing the remaining
3884 //------------------------------------------------------------------------------------
3885 - (void) doCancelCurrentJob
3887 // Stop the current job. hb_stop will only cancel the current pass and then set
3888 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3889 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3890 // remaining passes of the job and then start the queue back up if there are any
3894 hb_stop( fQueueEncodeLibhb );
3896 // Delete all remaining jobs since libhb doesn't do this on its own.
3898 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3899 hb_rem( fQueueEncodeLibhb, job );
3901 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3903 // now that we've stopped the currently encoding job, lets mark it as cancelled
3904 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3905 // and as always, save it in the queue .plist...
3906 /* We save all of the Queue data here */
3907 [self saveQueueFileItem];
3908 // so now lets move to
3909 currentQueueEncodeIndex++ ;
3910 // ... and see if there are more items left in our queue
3911 int queueItems = [QueueFileArray count];
3912 /* If we still have more items in our queue, lets go to the next one */
3913 if (currentQueueEncodeIndex < queueItems)
3915 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3916 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3918 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3922 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3927 - (void) doCancelCurrentJobAndStop
3929 hb_stop( fQueueEncodeLibhb );
3931 // Delete all remaining jobs since libhb doesn't do this on its own.
3933 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3934 hb_rem( fQueueEncodeLibhb, job );
3937 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3939 // now that we've stopped the currently encoding job, lets mark it as cancelled
3940 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3941 // and as always, save it in the queue .plist...
3942 /* We save all of the Queue data here */
3943 [self saveQueueFileItem];
3944 // so now lets move to
3945 currentQueueEncodeIndex++ ;
3946 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3948 - (IBAction) Pause: (id) sender
3951 hb_get_state2( fQueueEncodeLibhb, &s );
3953 if( s.state == HB_STATE_PAUSED )
3955 hb_resume( fQueueEncodeLibhb );
3959 hb_pause( fQueueEncodeLibhb );
3964 #pragma mark GUI Controls Changed Methods
3966 - (IBAction) titlePopUpChanged: (id) sender
3968 hb_list_t * list = hb_get_titles( fHandle );
3969 hb_title_t * title = (hb_title_t*)
3970 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3972 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3973 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3975 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3976 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3977 [browsedSourceDisplayName stringByDeletingPathExtension],
3979 [[fDstFile2Field stringValue] pathExtension]]];
3982 /* Update chapter popups */
3983 [fSrcChapterStartPopUp removeAllItems];
3984 [fSrcChapterEndPopUp removeAllItems];
3985 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
3987 [fSrcChapterStartPopUp addItemWithTitle: [NSString
3988 stringWithFormat: @"%d", i + 1]];
3989 [fSrcChapterEndPopUp addItemWithTitle: [NSString
3990 stringWithFormat: @"%d", i + 1]];
3993 [fSrcChapterStartPopUp selectItemAtIndex: 0];
3994 [fSrcChapterEndPopUp selectItemAtIndex:
3995 hb_list_count( title->list_chapter ) - 1];
3996 [self chapterPopUpChanged:nil];
3998 /* if using dvd nav, show the angle widget */
3999 if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue])
4001 [fSrcAngleLabel setHidden:NO];
4002 [fSrcAnglePopUp setHidden:NO];
4004 [fSrcAnglePopUp removeAllItems];
4005 for( int i = 0; i < title->angle_count; i++ )
4007 [fSrcAnglePopUp addItemWithTitle: [NSString stringWithFormat: @"%d", i + 1]];
4009 [fSrcAnglePopUp selectItemAtIndex: 0];
4013 [fSrcAngleLabel setHidden:YES];
4014 [fSrcAnglePopUp setHidden:YES];
4017 /* Start Get and set the initial pic size for display */
4018 hb_job_t * job = title->job;
4021 /* Set Auto Crop to on upon selecting a new title */
4022 [fPictureController setAutoCrop:YES];
4024 /* We get the originial output picture width and height and put them
4025 in variables for use with some presets later on */
4026 PicOrigOutputWidth = job->width;
4027 PicOrigOutputHeight = job->height;
4028 AutoCropTop = job->crop[0];
4029 AutoCropBottom = job->crop[1];
4030 AutoCropLeft = job->crop[2];
4031 AutoCropRight = job->crop[3];
4033 /* Reset the new title in fPictureController && fPreviewController*/
4034 [fPictureController SetTitle:title];
4037 /* Update Subtitle Table */
4038 [fSubtitlesDelegate resetWithTitle:title];
4039 [fSubtitlesTable reloadData];
4042 /* Update chapter table */
4043 [fChapterTitlesDelegate resetWithTitle:title];
4044 [fChapterTable reloadData];
4046 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
4047 int audiotrack_count = hb_list_count(job->list_audio);
4048 for( int i = 0; i < audiotrack_count;i++)
4050 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4051 hb_list_rem(job->list_audio, temp_audio);
4054 /* Update audio popups */
4055 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
4056 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
4057 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
4058 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
4059 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
4060 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
4061 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
4062 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4063 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4064 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4066 /* changing the title may have changed the audio channels on offer, */
4067 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4068 [self audioTrackPopUpChanged: fAudLang1PopUp];
4069 [self audioTrackPopUpChanged: fAudLang2PopUp];
4070 [self audioTrackPopUpChanged: fAudLang3PopUp];
4071 [self audioTrackPopUpChanged: fAudLang4PopUp];
4073 [fVidRatePopUp selectItemAtIndex: 0];
4075 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
4076 [self calculatePictureSizing:nil];
4078 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
4079 [self selectPreset:nil];
4082 - (IBAction) chapterPopUpChanged: (id) sender
4085 /* If start chapter popup is greater than end chapter popup,
4086 we set the end chapter popup to the same as start chapter popup */
4087 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
4089 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
4093 hb_list_t * list = hb_get_titles( fHandle );
4094 hb_title_t * title = (hb_title_t *)
4095 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4097 hb_chapter_t * chapter;
4098 int64_t duration = 0;
4099 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
4100 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
4102 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
4103 duration += chapter->duration;
4106 duration /= 90000; /* pts -> seconds */
4107 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
4108 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
4111 [self calculateBitrate: sender];
4113 if ( [fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem] )
4115 /* Disable chapter markers for any source with less than two chapters as it makes no sense. */
4116 [fCreateChapterMarkers setEnabled: NO];
4117 [fCreateChapterMarkers setState: NSOffState];
4121 [fCreateChapterMarkers setEnabled: YES];
4125 - (IBAction) formatPopUpChanged: (id) sender
4127 NSString * string = [fDstFile2Field stringValue];
4128 int format = [fDstFormatPopUp indexOfSelectedItem];
4130 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
4131 [fDstMp4LargeFileCheck setHidden: YES];
4132 [fDstMp4HttpOptFileCheck setHidden: YES];
4133 [fDstMp4iPodFileCheck setHidden: YES];
4135 /* Update the Video Codec PopUp */
4136 /* lets get the tag of the currently selected item first so we might reset it later */
4137 int selectedVidEncoderTag;
4138 selectedVidEncoderTag = [[fVidEncoderPopUp selectedItem] tag];
4140 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
4141 [fVidEncoderPopUp removeAllItems];
4142 NSMenuItem *menuItem;
4143 /* These video encoders are available to all of our current muxers, so lets list them once here */
4144 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
4145 [menuItem setTag: HB_VCODEC_FFMPEG];
4150 /*Get Default MP4 File Extension*/
4151 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
4159 /* Add additional video encoders here */
4160 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4161 [menuItem setTag: HB_VCODEC_X264];
4162 /* We show the mp4 option checkboxes here since we are mp4 */
4163 [fCreateChapterMarkers setEnabled: YES];
4164 [fDstMp4LargeFileCheck setHidden: NO];
4165 [fDstMp4HttpOptFileCheck setHidden: NO];
4166 [fDstMp4iPodFileCheck setHidden: NO];
4171 /* Add additional video encoders here */
4172 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4173 [menuItem setTag: HB_VCODEC_X264];
4174 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
4175 [menuItem setTag: HB_VCODEC_THEORA];
4176 /* We enable the create chapters checkbox here */
4177 [fCreateChapterMarkers setEnabled: YES];
4182 /* tell fSubtitlesDelegate we have a new video container */
4184 [fSubtitlesDelegate containerChanged:[[fDstFormatPopUp selectedItem] tag]];
4185 [fSubtitlesTable reloadData];
4186 /* if we have a previously selected vid encoder tag, then try to select it */
4187 if (selectedVidEncoderTag)
4189 [fVidEncoderPopUp selectItemWithTag: selectedVidEncoderTag];
4193 [fVidEncoderPopUp selectItemAtIndex: 0];
4196 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4197 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4198 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4199 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4202 [self autoSetM4vExtension: sender];
4204 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
4206 if( SuccessfulScan )
4208 /* Add/replace to the correct extension */
4209 [self audioTrackPopUpChanged: fAudLang1PopUp];
4210 [self audioTrackPopUpChanged: fAudLang2PopUp];
4211 [self audioTrackPopUpChanged: fAudLang3PopUp];
4212 [self audioTrackPopUpChanged: fAudLang4PopUp];
4214 if( [fVidEncoderPopUp selectedItem] == nil )
4217 [fVidEncoderPopUp selectItemAtIndex:0];
4218 [self videoEncoderPopUpChanged:nil];
4220 /* changing the format may mean that we can / can't offer mono or 6ch, */
4221 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4223 /* We call the method to properly enable/disable turbo 2 pass */
4224 [self twoPassCheckboxChanged: sender];
4225 /* We call method method to change UI to reflect whether a preset is used or not*/
4228 [self customSettingUsed: sender];
4231 - (IBAction) autoSetM4vExtension: (id) sender
4233 if ( [fDstFormatPopUp indexOfSelectedItem] )
4236 NSString * extension = @"mp4";
4238 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4239 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4240 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4241 [fCreateChapterMarkers state] == NSOnState ||
4242 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
4247 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
4250 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
4251 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
4254 /* Method to determine if we should change the UI
4255 To reflect whether or not a Preset is being used or if
4256 the user is using "Custom" settings by determining the sender*/
4257 - (IBAction) customSettingUsed: (id) sender
4259 if ([sender stringValue])
4261 /* Deselect the currently selected Preset if there is one*/
4262 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
4263 /* Change UI to show "Custom" settings are being used */
4264 [fPresetSelectedDisplay setStringValue: @"Custom"];
4266 curUserPresetChosenNum = nil;
4268 [self calculateBitrate:nil];
4273 #pragma mark - Video
4275 - (IBAction) videoEncoderPopUpChanged: (id) sender
4277 hb_job_t * job = fTitle->job;
4278 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
4280 [fAdvancedOptions setHidden:YES];
4281 /* If we are using x264 then show the x264 advanced panel*/
4282 if (videoEncoder == HB_VCODEC_X264)
4284 [fAdvancedOptions setHidden:NO];
4285 [self autoSetM4vExtension: sender];
4288 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
4289 is being used as it borks up loose anamorphic .
4290 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
4291 to use the index itself but this is easier */
4292 if (videoEncoder == HB_VCODEC_FFMPEG)
4294 if (job->anamorphic.mode == 2)
4296 job->anamorphic.mode = 0;
4298 [fPictureController setAllowLooseAnamorphic:NO];
4299 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
4300 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
4301 anything other than MP4.
4303 [fDstMp4iPodFileCheck setEnabled: NO];
4304 [fDstMp4iPodFileCheck setState: NSOffState];
4308 [fPictureController setAllowLooseAnamorphic:YES];
4309 [fDstMp4iPodFileCheck setEnabled: YES];
4311 [self setupQualitySlider];
4312 [self calculatePictureSizing: sender];
4313 [self twoPassCheckboxChanged: sender];
4317 - (IBAction) twoPassCheckboxChanged: (id) sender
4319 /* check to see if x264 is chosen */
4320 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4322 if( [fVidTwoPassCheck state] == NSOnState)
4324 [fVidTurboPassCheck setHidden: NO];
4328 [fVidTurboPassCheck setHidden: YES];
4329 [fVidTurboPassCheck setState: NSOffState];
4331 /* Make sure Two Pass is checked if Turbo is checked */
4332 if( [fVidTurboPassCheck state] == NSOnState)
4334 [fVidTwoPassCheck setState: NSOnState];
4339 [fVidTurboPassCheck setHidden: YES];
4340 [fVidTurboPassCheck setState: NSOffState];
4343 /* We call method method to change UI to reflect whether a preset is used or not*/
4344 [self customSettingUsed: sender];
4347 - (IBAction ) videoFrameRateChanged: (id) sender
4349 /* We call method method to calculatePictureSizing to error check detelecine*/
4350 [self calculatePictureSizing: sender];
4352 /* We call method method to change UI to reflect whether a preset is used or not*/
4353 [self customSettingUsed: sender];
4355 - (IBAction) videoMatrixChanged: (id) sender;
4357 bool target, bitrate, quality;
4359 target = bitrate = quality = false;
4360 if( [fVidQualityMatrix isEnabled] )
4362 switch( [fVidQualityMatrix selectedRow] )
4375 [fVidTargetSizeField setEnabled: target];
4376 [fVidBitrateField setEnabled: bitrate];
4377 [fVidQualitySlider setEnabled: quality];
4378 [fVidQualityRFField setEnabled: quality];
4379 [fVidQualityRFLabel setEnabled: quality];
4380 [fVidTwoPassCheck setEnabled: !quality &&
4381 [fVidQualityMatrix isEnabled]];
4384 [fVidTwoPassCheck setState: NSOffState];
4385 [fVidTurboPassCheck setHidden: YES];
4386 [fVidTurboPassCheck setState: NSOffState];
4389 [self qualitySliderChanged: sender];
4390 [self calculateBitrate: sender];
4391 [self customSettingUsed: sender];
4394 /* Use this method to setup the quality slider for cq/rf values depending on
4395 * the video encoder selected.
4397 - (void) setupQualitySlider
4399 /* Get the current slider maxValue to check for a change in slider scale later
4400 * so that we can choose a new similar value on the new slider scale */
4401 float previousMaxValue = [fVidQualitySlider maxValue];
4402 float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1);
4403 NSString * qpRFLabelString = @"QP:";
4405 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4407 [fVidQualitySlider setMinValue:0.0];
4408 [fVidQualitySlider setMaxValue:51.0];
4409 /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
4410 int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
4411 [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
4412 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0)
4414 qpRFLabelString = @"RF:";
4418 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
4420 [fVidQualitySlider setMinValue:1.0];
4421 [fVidQualitySlider setMaxValue:31.0];
4422 [fVidQualitySlider setNumberOfTickMarks:31];
4425 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4427 [fVidQualitySlider setMinValue:0.0];
4428 [fVidQualitySlider setMaxValue:63.0];
4429 [fVidQualitySlider setNumberOfTickMarks:64];
4431 [fVidQualityRFLabel setStringValue:qpRFLabelString];
4433 /* check to see if we have changed slider scales */
4434 if (previousMaxValue != [fVidQualitySlider maxValue])
4436 /* if so, convert the old setting to the new scale as close as possible based on percentages */
4437 float rf = ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1) * previousPercentOfSliderScale;
4438 [fVidQualitySlider setFloatValue:rf];
4441 [self qualitySliderChanged:nil];
4444 - (IBAction) qualitySliderChanged: (id) sender
4446 /* Our constant quality slider is in a range based
4447 * on each encoders qp/rf values. The range depends
4448 * on the encoder. Also, the range is inverse of quality
4449 * for all of the encoders *except* for theora
4450 * (ie. as the "quality" goes up, the cq or rf value
4451 * actually goes down). Since the IB sliders always set
4452 * their max value at the right end of the slider, we
4453 * will calculate the inverse, so as the slider floatValue
4454 * goes up, we will show the inverse in the rf field
4455 * so, the floatValue at the right for x264 would be 51
4456 * and our rf field needs to show 0 and vice versa.
4459 float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue];
4460 /* If the encoder is theora, use the float, otherwise use the inverse float*/
4461 float sliderRfToPercent;
4462 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4464 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];
4465 sliderRfToPercent = [fVidQualityRFField floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4469 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]];
4470 sliderRfToPercent = ( ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - ([fVidQualityRFField floatValue] - [fVidQualitySlider minValue])) / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4472 [fVidConstantCell setTitle: [NSString stringWithFormat:
4473 NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]];
4475 [self customSettingUsed: sender];
4478 - (void) controlTextDidChange: (NSNotification *) notification
4480 [self calculateBitrate:nil];
4483 - (IBAction) calculateBitrate: (id) sender
4485 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
4490 hb_list_t * list = hb_get_titles( fHandle );
4491 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4492 [fSrcTitlePopUp indexOfSelectedItem] );
4493 hb_job_t * job = title->job;
4494 hb_audio_config_t * audio;
4495 /* For hb_calc_bitrate in addition to the Target Size in MB out of the
4496 * Target Size Field, we also need the job info for the Muxer, the Chapters
4497 * as well as all of the audio track info.
4498 * This used to be accomplished by simply calling prepareJob here, however
4499 * since the resilient queue sets the queue array values instead of the job
4500 * values directly, we duplicate the old prepareJob code here for the variables
4503 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
4504 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
4505 job->mux = [[fDstFormatPopUp selectedItem] tag];
4507 /* Audio goes here */
4508 int audiotrack_count = hb_list_count(job->list_audio);
4509 for( int i = 0; i < audiotrack_count;i++)
4511 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4512 hb_list_rem(job->list_audio, temp_audio);
4514 /* Now we need our audio info here for each track if applicable */
4515 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4517 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4518 hb_audio_config_init(audio);
4519 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4520 /* We go ahead and assign values to our audio->out.<properties> */
4521 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4522 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
4523 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
4524 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
4525 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
4526 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
4528 hb_audio_add( job, audio );
4531 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4533 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4534 hb_audio_config_init(audio);
4535 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4536 /* We go ahead and assign values to our audio->out.<properties> */
4537 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4538 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
4539 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
4540 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
4541 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
4542 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
4544 hb_audio_add( job, audio );
4549 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4551 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4552 hb_audio_config_init(audio);
4553 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4554 /* We go ahead and assign values to our audio->out.<properties> */
4555 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4556 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
4557 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
4558 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
4559 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
4560 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
4562 hb_audio_add( job, audio );
4567 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4569 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4570 hb_audio_config_init(audio);
4571 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4572 /* We go ahead and assign values to our audio->out.<properties> */
4573 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4574 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
4575 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
4576 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
4577 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
4578 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
4580 hb_audio_add( job, audio );
4585 [fVidBitrateField setIntValue: hb_calc_bitrate( job, [fVidTargetSizeField intValue] )];
4589 #pragma mark - Picture
4591 /* lets set the picture size back to the max from right after title scan
4592 Lets use an IBAction here as down the road we could always use a checkbox
4593 in the gui to easily take the user back to max. Remember, the compiler
4594 resolves IBActions down to -(void) during compile anyway */
4595 - (IBAction) revertPictureSizeToMax: (id) sender
4597 hb_job_t * job = fTitle->job;
4598 /* Here we apply the title source and height */
4599 job->width = fTitle->width;
4600 job->height = fTitle->height;
4602 [self calculatePictureSizing: sender];
4603 /* We call method to change UI to reflect whether a preset is used or not*/
4604 [self customSettingUsed: sender];
4608 * Registers changes made in the Picture Settings Window.
4611 - (void)pictureSettingsDidChange
4613 [self calculatePictureSizing:nil];
4616 /* Get and Display Current Pic Settings in main window */
4617 - (IBAction) calculatePictureSizing: (id) sender
4619 if (fTitle->job->anamorphic.mode > 0)
4621 fTitle->job->keep_ratio = 0;
4624 [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
4626 NSString *picCropping;
4627 /* Set the display field for crop as per boolean */
4628 if (![fPictureController autoCrop])
4630 picCropping = @"Custom";
4634 picCropping = @"Auto";
4636 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]]];
4638 [fPictureCroppingField setStringValue: [NSString stringWithFormat:@"Picture Cropping: %@",picCropping]];
4640 NSString *videoFilters;
4643 if ([fPictureController detelecine] == 1)
4645 videoFilters = [videoFilters stringByAppendingString:@" - Detelecine (Default)"];
4647 else if ([fPictureController detelecine] == 2)
4649 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Detelecine (%@)",[fPictureController detelecineCustomString]]];
4653 if ([fPictureController useDecomb] == 1)
4656 if ([fPictureController decomb] == 1)
4658 videoFilters = [videoFilters stringByAppendingString:@" - Decomb (Default)"];
4660 else if ([fPictureController decomb] == 2)
4662 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Decomb (%@)",[fPictureController decombCustomString]]];
4668 if ([fPictureController deinterlace] > 0)
4670 fTitle->job->deinterlace = 1;
4674 fTitle->job->deinterlace = 0;
4677 if ([fPictureController deinterlace] == 1)
4679 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Fast)"];
4681 else if ([fPictureController deinterlace] == 2)
4683 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slow)"];
4685 else if ([fPictureController deinterlace] == 3)
4687 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slower)"];
4689 else if ([fPictureController deinterlace] == 4)
4691 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deinterlace (%@)",[fPictureController deinterlaceCustomString]]];
4697 if ([fPictureController denoise] == 1)
4699 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Weak)"];
4701 else if ([fPictureController denoise] == 2)
4703 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Medium)"];
4705 else if ([fPictureController denoise] == 3)
4707 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Strong)"];
4709 else if ([fPictureController denoise] == 4)
4711 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Denoise (%@)",[fPictureController denoiseCustomString]]];
4715 if ([fPictureController deblock] > 0)
4717 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deblock (%d)",[fPictureController deblock]]];
4721 if ([fPictureController grayscale])
4723 videoFilters = [videoFilters stringByAppendingString:@" - Grayscale"];
4725 [fVideoFiltersField setStringValue: [NSString stringWithFormat:@"Video Filters: %@", videoFilters]];
4727 //[fPictureController reloadStillPreview];
4732 #pragma mark - Audio and Subtitles
4733 - (IBAction) audioCodecsPopUpChanged: (id) sender
4736 NSPopUpButton * audiotrackPopUp;
4737 NSPopUpButton * sampleratePopUp;
4738 NSPopUpButton * bitratePopUp;
4739 NSPopUpButton * audiocodecPopUp;
4740 if (sender == fAudTrack1CodecPopUp)
4742 audiotrackPopUp = fAudLang1PopUp;
4743 audiocodecPopUp = fAudTrack1CodecPopUp;
4744 sampleratePopUp = fAudTrack1RatePopUp;
4745 bitratePopUp = fAudTrack1BitratePopUp;
4747 else if (sender == fAudTrack2CodecPopUp)
4749 audiotrackPopUp = fAudLang2PopUp;
4750 audiocodecPopUp = fAudTrack2CodecPopUp;
4751 sampleratePopUp = fAudTrack2RatePopUp;
4752 bitratePopUp = fAudTrack2BitratePopUp;
4754 else if (sender == fAudTrack3CodecPopUp)
4756 audiotrackPopUp = fAudLang3PopUp;
4757 audiocodecPopUp = fAudTrack3CodecPopUp;
4758 sampleratePopUp = fAudTrack3RatePopUp;
4759 bitratePopUp = fAudTrack3BitratePopUp;
4763 audiotrackPopUp = fAudLang4PopUp;
4764 audiocodecPopUp = fAudTrack4CodecPopUp;
4765 sampleratePopUp = fAudTrack4RatePopUp;
4766 bitratePopUp = fAudTrack4BitratePopUp;
4769 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
4770 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4771 [self audioTrackPopUpChanged: audiotrackPopUp];
4775 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
4777 /* We will be setting the enabled/disabled state of each tracks audio controls based on
4778 * the settings of the source audio for that track. We leave the samplerate and bitrate
4779 * to audiotrackMixdownChanged
4782 /* We will first verify that a lower track number has been selected before enabling each track
4783 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
4785 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4787 [fAudLang2PopUp setEnabled: NO];
4788 [fAudLang2PopUp selectItemAtIndex: 0];
4792 [fAudLang2PopUp setEnabled: YES];
4795 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4797 [fAudLang3PopUp setEnabled: NO];
4798 [fAudLang3PopUp selectItemAtIndex: 0];
4802 [fAudLang3PopUp setEnabled: YES];
4804 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4806 [fAudLang4PopUp setEnabled: NO];
4807 [fAudLang4PopUp selectItemAtIndex: 0];
4811 [fAudLang4PopUp setEnabled: YES];
4813 /* enable/disable the mixdown text and popupbutton for audio track 1 */
4814 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4815 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4816 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4817 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4818 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4819 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4820 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4822 [fAudTrack1CodecPopUp removeAllItems];
4823 [fAudTrack1MixPopUp removeAllItems];
4824 [fAudTrack1RatePopUp removeAllItems];
4825 [fAudTrack1BitratePopUp removeAllItems];
4826 [fAudTrack1DrcSlider setFloatValue: 1.00];
4827 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
4829 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4831 [fAudTrack1RatePopUp setEnabled: NO];
4832 [fAudTrack1BitratePopUp setEnabled: NO];
4833 [fAudTrack1DrcSlider setEnabled: NO];
4834 [fAudTrack1DrcField setEnabled: NO];
4837 /* enable/disable the mixdown text and popupbutton for audio track 2 */
4838 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4839 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4840 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4841 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4842 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4843 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4844 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4846 [fAudTrack2CodecPopUp removeAllItems];
4847 [fAudTrack2MixPopUp removeAllItems];
4848 [fAudTrack2RatePopUp removeAllItems];
4849 [fAudTrack2BitratePopUp removeAllItems];
4850 [fAudTrack2DrcSlider setFloatValue: 1.00];
4851 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
4853 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4855 [fAudTrack2RatePopUp setEnabled: NO];
4856 [fAudTrack2BitratePopUp setEnabled: NO];
4857 [fAudTrack2DrcSlider setEnabled: NO];
4858 [fAudTrack2DrcField setEnabled: NO];
4861 /* enable/disable the mixdown text and popupbutton for audio track 3 */
4862 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4863 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4864 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4865 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4866 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4867 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4868 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4870 [fAudTrack3CodecPopUp removeAllItems];
4871 [fAudTrack3MixPopUp removeAllItems];
4872 [fAudTrack3RatePopUp removeAllItems];
4873 [fAudTrack3BitratePopUp removeAllItems];
4874 [fAudTrack3DrcSlider setFloatValue: 1.00];
4875 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
4877 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4879 [fAudTrack3RatePopUp setEnabled: NO];
4880 [fAudTrack3BitratePopUp setEnabled: NO];
4881 [fAudTrack3DrcSlider setEnabled: NO];
4882 [fAudTrack3DrcField setEnabled: NO];
4885 /* enable/disable the mixdown text and popupbutton for audio track 4 */
4886 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4887 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4888 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4889 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4890 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4891 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4892 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
4894 [fAudTrack4CodecPopUp removeAllItems];
4895 [fAudTrack4MixPopUp removeAllItems];
4896 [fAudTrack4RatePopUp removeAllItems];
4897 [fAudTrack4BitratePopUp removeAllItems];
4898 [fAudTrack4DrcSlider setFloatValue: 1.00];
4899 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
4901 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4903 [fAudTrack4RatePopUp setEnabled: NO];
4904 [fAudTrack4BitratePopUp setEnabled: NO];
4905 [fAudTrack4DrcSlider setEnabled: NO];
4906 [fAudTrack4DrcField setEnabled: NO];
4911 - (IBAction) addAllAudioTracksToPopUp: (id) sender
4914 hb_list_t * list = hb_get_titles( fHandle );
4915 hb_title_t * title = (hb_title_t*)
4916 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4918 hb_audio_config_t * audio;
4920 [sender removeAllItems];
4921 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
4922 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
4924 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
4925 [[sender menu] addItemWithTitle:
4926 [NSString stringWithCString: audio->lang.description]
4927 action: NULL keyEquivalent: @""];
4929 [sender selectItemAtIndex: 0];
4933 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
4936 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
4937 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
4938 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
4939 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
4941 if (searchPrefixString)
4944 for( int i = 0; i < [sender numberOfItems]; i++ )
4946 /* Try to find the desired search string */
4947 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
4949 [sender selectItemAtIndex: i];
4953 /* couldn't find the string, so select the requested "search string not found" item */
4954 /* index of 0 means select the "none" item */
4955 /* index of 1 means select the first audio track */
4956 [sender selectItemAtIndex: selectIndexIfNotFound];
4960 /* if no search string is provided, then select the selectIndexIfNotFound item */
4961 [sender selectItemAtIndex: selectIndexIfNotFound];
4965 - (IBAction) audioAddAudioTrackCodecs: (id)sender
4967 int format = [fDstFormatPopUp indexOfSelectedItem];
4969 /* setup pointers to the appropriate popups for the correct track */
4970 NSPopUpButton * audiocodecPopUp;
4971 NSPopUpButton * audiotrackPopUp;
4972 if (sender == fAudTrack1CodecPopUp)
4974 audiotrackPopUp = fAudLang1PopUp;
4975 audiocodecPopUp = fAudTrack1CodecPopUp;
4977 else if (sender == fAudTrack2CodecPopUp)
4979 audiotrackPopUp = fAudLang2PopUp;
4980 audiocodecPopUp = fAudTrack2CodecPopUp;
4982 else if (sender == fAudTrack3CodecPopUp)
4984 audiotrackPopUp = fAudLang3PopUp;
4985 audiocodecPopUp = fAudTrack3CodecPopUp;
4989 audiotrackPopUp = fAudLang4PopUp;
4990 audiocodecPopUp = fAudTrack4CodecPopUp;
4993 [audiocodecPopUp removeAllItems];
4994 /* Make sure "None" isnt selected in the source track */
4995 if ([audiotrackPopUp indexOfSelectedItem] > 0)
4997 [audiocodecPopUp setEnabled:YES];
4998 NSMenuItem *menuItem;
4999 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
5005 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5006 [menuItem setTag: HB_ACODEC_FAAC];
5009 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5010 [menuItem setTag: HB_ACODEC_CA_AAC];
5013 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5014 [menuItem setTag: HB_ACODEC_AC3];
5020 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5021 [menuItem setTag: HB_ACODEC_FAAC];
5023 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5024 [menuItem setTag: HB_ACODEC_CA_AAC];
5026 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5027 [menuItem setTag: HB_ACODEC_AC3];
5029 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"DTS Passthru" action: NULL keyEquivalent: @""];
5030 [menuItem setTag: HB_ACODEC_DCA];
5032 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5033 [menuItem setTag: HB_ACODEC_LAME];
5035 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5036 [menuItem setTag: HB_ACODEC_VORBIS];
5042 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5043 [menuItem setTag: HB_ACODEC_LAME];
5045 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5046 [menuItem setTag: HB_ACODEC_AC3];
5052 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5053 [menuItem setTag: HB_ACODEC_VORBIS];
5055 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5056 [menuItem setTag: HB_ACODEC_LAME];
5059 [audiocodecPopUp selectItemAtIndex:0];
5063 [audiocodecPopUp setEnabled:NO];
5067 - (IBAction) audioTrackPopUpChanged: (id) sender
5069 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
5070 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
5073 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
5076 /* make sure we have a selected title before continuing */
5077 if (fTitle == NULL) return;
5078 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
5079 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
5081 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
5083 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
5085 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
5087 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
5089 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
5091 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
5093 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
5095 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
5098 /* Now lets make the sender the appropriate Audio Track popup from this point on */
5099 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
5101 sender = fAudLang1PopUp;
5103 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
5105 sender = fAudLang2PopUp;
5107 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
5109 sender = fAudLang3PopUp;
5111 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
5113 sender = fAudLang4PopUp;
5116 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
5117 NSPopUpButton * mixdownPopUp;
5118 NSPopUpButton * audiocodecPopUp;
5119 NSPopUpButton * sampleratePopUp;
5120 NSPopUpButton * bitratePopUp;
5121 if (sender == fAudLang1PopUp)
5123 mixdownPopUp = fAudTrack1MixPopUp;
5124 audiocodecPopUp = fAudTrack1CodecPopUp;
5125 sampleratePopUp = fAudTrack1RatePopUp;
5126 bitratePopUp = fAudTrack1BitratePopUp;
5128 else if (sender == fAudLang2PopUp)
5130 mixdownPopUp = fAudTrack2MixPopUp;
5131 audiocodecPopUp = fAudTrack2CodecPopUp;
5132 sampleratePopUp = fAudTrack2RatePopUp;
5133 bitratePopUp = fAudTrack2BitratePopUp;
5135 else if (sender == fAudLang3PopUp)
5137 mixdownPopUp = fAudTrack3MixPopUp;
5138 audiocodecPopUp = fAudTrack3CodecPopUp;
5139 sampleratePopUp = fAudTrack3RatePopUp;
5140 bitratePopUp = fAudTrack3BitratePopUp;
5144 mixdownPopUp = fAudTrack4MixPopUp;
5145 audiocodecPopUp = fAudTrack4CodecPopUp;
5146 sampleratePopUp = fAudTrack4RatePopUp;
5147 bitratePopUp = fAudTrack4BitratePopUp;
5150 /* get the index of the selected audio Track*/
5151 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
5153 /* pointer for the hb_audio_s struct we will use later on */
5154 hb_audio_config_t * audio;
5157 /* check if the audio mixdown controls need their enabled state changing */
5158 [self setEnabledStateOfAudioMixdownControls:nil];
5160 if (thisAudioIndex != -1)
5164 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
5166 /* actually manipulate the proper mixdowns here */
5167 /* delete the previous audio mixdown options */
5168 [mixdownPopUp removeAllItems];
5170 acodec = [[audiocodecPopUp selectedItem] tag];
5175 /* find out if our selected output audio codec supports mono and / or 6ch */
5176 /* we also check for an input codec of AC3 or DCA,
5177 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
5178 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
5179 but this may change in the future, so they are separated for flexibility */
5180 int audioCodecsSupportMono =
5181 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5182 (acodec != HB_ACODEC_LAME);
5183 int audioCodecsSupport6Ch =
5184 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5185 (acodec != HB_ACODEC_LAME);
5187 /* check for AC-3 passthru */
5188 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5191 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5192 [NSString stringWithCString: "AC3 Passthru"]
5193 action: NULL keyEquivalent: @""];
5194 [menuItem setTag: HB_ACODEC_AC3];
5196 else if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5198 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5199 [NSString stringWithCString: "DTS Passthru"]
5200 action: NULL keyEquivalent: @""];
5201 [menuItem setTag: HB_ACODEC_DCA];
5206 /* add the appropriate audio mixdown menuitems to the popupbutton */
5207 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
5208 so that we can reference the mixdown later */
5210 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
5211 int minMixdownUsed = 0;
5212 int maxMixdownUsed = 0;
5214 /* get the input channel layout without any lfe channels */
5215 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
5217 /* do we want to add a mono option? */
5218 if (audioCodecsSupportMono == 1)
5220 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5221 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
5222 action: NULL keyEquivalent: @""];
5223 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
5224 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
5225 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
5228 /* do we want to add a stereo option? */
5229 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
5230 /* also offer stereo if we have a stereo-or-better source */
5231 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
5233 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5234 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
5235 action: NULL keyEquivalent: @""];
5236 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
5237 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
5238 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
5241 /* do we want to add a dolby surround (DPL1) option? */
5242 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
5244 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5245 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
5246 action: NULL keyEquivalent: @""];
5247 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
5248 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
5249 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
5252 /* do we want to add a dolby pro logic 2 (DPL2) option? */
5253 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
5255 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5256 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
5257 action: NULL keyEquivalent: @""];
5258 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
5259 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
5260 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
5263 /* do we want to add a 6-channel discrete option? */
5264 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
5266 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5267 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
5268 action: NULL keyEquivalent: @""];
5269 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
5270 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
5271 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
5274 /* do we want to add an AC-3 passthrough option? */
5275 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5277 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5278 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5279 action: NULL keyEquivalent: @""];
5280 [menuItem setTag: HB_ACODEC_AC3];
5281 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5282 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5285 /* do we want to add a DTS Passthru option ? HB_ACODEC_DCA*/
5286 if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5288 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5289 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5290 action: NULL keyEquivalent: @""];
5291 [menuItem setTag: HB_ACODEC_DCA];
5292 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5293 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5296 /* auto-select the best mixdown based on our saved mixdown preference */
5298 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
5299 /* ultimately this should be a prefs option */
5302 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
5303 if (mixdownToUse > 0)
5305 useMixdown = mixdownToUse;
5309 useMixdown = HB_AMIXDOWN_DOLBYPLII;
5312 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
5313 if (useMixdown > maxMixdownUsed)
5315 useMixdown = maxMixdownUsed;
5318 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
5319 if (useMixdown < minMixdownUsed)
5321 useMixdown = minMixdownUsed;
5324 /* select the (possibly-amended) preferred mixdown */
5325 [mixdownPopUp selectItemWithTag: useMixdown];
5328 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
5329 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5332 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
5334 /* If we are using the avi container, we select MP3 as there is no aac available*/
5335 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5337 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5341 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5345 /* In the case of a source track that is not DTS and the user tries to use DTS Passthru (which does not work)
5346 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5349 if (audio->in.codec != HB_ACODEC_DCA && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_DCA)
5351 /* If we are using the avi container, we select MP3 as there is no aac available*/
5352 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5354 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5358 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5362 /* Setup our samplerate and bitrate popups we will need based on mixdown */
5363 [self audioTrackMixdownChanged: mixdownPopUp];
5367 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
5369 [self autoSetM4vExtension: sender];
5373 - (IBAction) audioTrackMixdownChanged: (id) sender
5377 /* setup pointers to all of the other audio track controls
5378 * we will need later
5380 NSPopUpButton * mixdownPopUp;
5381 NSPopUpButton * sampleratePopUp;
5382 NSPopUpButton * bitratePopUp;
5383 NSPopUpButton * audiocodecPopUp;
5384 NSPopUpButton * audiotrackPopUp;
5385 NSSlider * drcSlider;
5386 NSTextField * drcField;
5387 if (sender == fAudTrack1MixPopUp)
5389 audiotrackPopUp = fAudLang1PopUp;
5390 audiocodecPopUp = fAudTrack1CodecPopUp;
5391 mixdownPopUp = fAudTrack1MixPopUp;
5392 sampleratePopUp = fAudTrack1RatePopUp;
5393 bitratePopUp = fAudTrack1BitratePopUp;
5394 drcSlider = fAudTrack1DrcSlider;
5395 drcField = fAudTrack1DrcField;
5397 else if (sender == fAudTrack2MixPopUp)
5399 audiotrackPopUp = fAudLang2PopUp;
5400 audiocodecPopUp = fAudTrack2CodecPopUp;
5401 mixdownPopUp = fAudTrack2MixPopUp;
5402 sampleratePopUp = fAudTrack2RatePopUp;
5403 bitratePopUp = fAudTrack2BitratePopUp;
5404 drcSlider = fAudTrack2DrcSlider;
5405 drcField = fAudTrack2DrcField;
5407 else if (sender == fAudTrack3MixPopUp)
5409 audiotrackPopUp = fAudLang3PopUp;
5410 audiocodecPopUp = fAudTrack3CodecPopUp;
5411 mixdownPopUp = fAudTrack3MixPopUp;
5412 sampleratePopUp = fAudTrack3RatePopUp;
5413 bitratePopUp = fAudTrack3BitratePopUp;
5414 drcSlider = fAudTrack3DrcSlider;
5415 drcField = fAudTrack3DrcField;
5419 audiotrackPopUp = fAudLang4PopUp;
5420 audiocodecPopUp = fAudTrack4CodecPopUp;
5421 mixdownPopUp = fAudTrack4MixPopUp;
5422 sampleratePopUp = fAudTrack4RatePopUp;
5423 bitratePopUp = fAudTrack4BitratePopUp;
5424 drcSlider = fAudTrack4DrcSlider;
5425 drcField = fAudTrack4DrcField;
5427 acodec = [[audiocodecPopUp selectedItem] tag];
5428 /* storage variable for the min and max bitrate allowed for this codec */
5434 case HB_ACODEC_FAAC:
5435 /* check if we have a 6ch discrete conversion in either audio track */
5436 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5438 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
5440 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5446 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
5448 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
5449 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
5454 case HB_ACODEC_CA_AAC:
5455 /* check if we have a 6ch discrete conversion in either audio track */
5456 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5469 case HB_ACODEC_LAME:
5470 /* Lame is happy using our min bitrate of 32 kbps */
5472 /* Lame won't encode if the bitrate is higher than 320 kbps */
5476 case HB_ACODEC_VORBIS:
5477 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5479 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
5481 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5487 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
5489 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
5495 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
5501 /* make sure we have a selected title before continuing */
5502 if (fTitle == NULL) return;
5503 /* get the audio so we can find out what input rates are*/
5504 hb_audio_config_t * audio;
5505 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
5506 int inputbitrate = audio->in.bitrate / 1000;
5507 int inputsamplerate = audio->in.samplerate;
5509 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3 && [[mixdownPopUp selectedItem] tag] != HB_ACODEC_DCA)
5511 [bitratePopUp removeAllItems];
5513 for( int i = 0; i < hb_audio_bitrates_count; i++ )
5515 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
5517 /* add a new menuitem for this bitrate */
5518 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5519 [NSString stringWithCString: hb_audio_bitrates[i].string]
5520 action: NULL keyEquivalent: @""];
5521 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
5522 [menuItem setTag: hb_audio_bitrates[i].rate];
5526 /* select the default bitrate (but use 384 for 6-ch AAC) */
5527 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5529 [bitratePopUp selectItemWithTag: 384];
5533 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
5536 /* populate and set the sample rate popup */
5537 /* Audio samplerate */
5538 [sampleratePopUp removeAllItems];
5539 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
5540 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
5541 [menuItem setTag: inputsamplerate];
5543 for( int i = 0; i < hb_audio_rates_count; i++ )
5545 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
5546 [NSString stringWithCString: hb_audio_rates[i].string]
5547 action: NULL keyEquivalent: @""];
5548 [menuItem setTag: hb_audio_rates[i].rate];
5550 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
5551 * and there is no compelling reason to use anything else as default, though the users default
5552 * preset will likely override any setting chosen here.
5554 [sampleratePopUp selectItemWithTag: inputsamplerate];
5557 /* Since AC3 Pass Thru and DTS Pass Thru uses the input bitrate and sample rate, we get the input tracks
5558 * bitrate and display it in the bitrate popup even though libhb happily ignores any bitrate input from
5559 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
5561 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[mixdownPopUp selectedItem] tag] == HB_ACODEC_DCA)
5564 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
5565 [bitratePopUp removeAllItems];
5566 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5567 [NSString stringWithFormat:@"%d", inputbitrate]
5568 action: NULL keyEquivalent: @""];
5569 [menuItem setTag: inputbitrate];
5570 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
5571 [bitratePopUp setEnabled: NO];
5572 [sampleratePopUp setEnabled: NO];
5574 [drcSlider setFloatValue: 1.00];
5575 [self audioDRCSliderChanged: drcSlider];
5576 [drcSlider setEnabled: NO];
5577 [drcField setEnabled: NO];
5581 [sampleratePopUp setEnabled: YES];
5582 [bitratePopUp setEnabled: YES];
5583 [drcSlider setEnabled: YES];
5584 [drcField setEnabled: YES];
5586 [self calculateBitrate:nil];
5589 - (IBAction) audioDRCSliderChanged: (id) sender
5591 NSSlider * drcSlider;
5592 NSTextField * drcField;
5593 if (sender == fAudTrack1DrcSlider)
5595 drcSlider = fAudTrack1DrcSlider;
5596 drcField = fAudTrack1DrcField;
5598 else if (sender == fAudTrack2DrcSlider)
5600 drcSlider = fAudTrack2DrcSlider;
5601 drcField = fAudTrack2DrcField;
5603 else if (sender == fAudTrack3DrcSlider)
5605 drcSlider = fAudTrack3DrcSlider;
5606 drcField = fAudTrack3DrcField;
5610 drcSlider = fAudTrack4DrcSlider;
5611 drcField = fAudTrack4DrcField;
5614 /* If we are between 0.0 and 1.0 on the slider, snap it to 1.0 */
5615 if ([drcSlider floatValue] > 0.0 && [drcSlider floatValue] < 1.0)
5617 [drcSlider setFloatValue:1.0];
5621 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
5622 /* For now, do not call this until we have an intelligent way to determine audio track selections
5623 * compared to presets
5625 //[self customSettingUsed: sender];
5630 #pragma mark Open New Windows
5632 - (IBAction) openHomepage: (id) sender
5634 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5635 URLWithString:@"http://handbrake.fr/"]];
5638 - (IBAction) openForums: (id) sender
5640 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5641 URLWithString:@"http://handbrake.fr/forum/"]];
5643 - (IBAction) openUserGuide: (id) sender
5645 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5646 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
5650 * Shows debug output window.
5652 - (IBAction)showDebugOutputPanel:(id)sender
5654 [outputPanel showOutputPanel:sender];
5658 * Shows preferences window.
5660 - (IBAction) showPreferencesWindow: (id) sender
5662 NSWindow * window = [fPreferencesController window];
5663 if (![window isVisible])
5666 [window makeKeyAndOrderFront: nil];
5670 * Shows queue window.
5672 - (IBAction) showQueueWindow:(id)sender
5674 [fQueueController showQueueWindow:sender];
5678 - (IBAction) toggleDrawer:(id)sender {
5679 [fPresetDrawer toggle:self];
5683 * Shows Picture Settings Window.
5686 - (IBAction) showPicturePanel: (id) sender
5688 [fPictureController showPictureWindow:sender];
5691 - (void) picturePanelFullScreen
5693 [fPictureController setToFullScreenMode];
5696 - (void) picturePanelWindowed
5698 [fPictureController setToWindowedMode];
5701 - (IBAction) showPreviewWindow: (id) sender
5703 [fPictureController showPreviewWindow:sender];
5707 #pragma mark Preset Outline View Methods
5708 #pragma mark - Required
5709 /* These are required by the NSOutlineView Datasource Delegate */
5712 /* used to specify the number of levels to show for each item */
5713 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
5715 /* currently use no levels to test outline view viability */
5716 if (item == nil) // for an outline view the root level of the hierarchy is always nil
5718 return [UserPresets count];
5722 /* we need to return the count of the array in ChildrenArray for this folder */
5723 NSArray *children = nil;
5724 children = [item objectForKey:@"ChildrenArray"];
5725 if ([children count] > 0)
5727 return [children count];
5736 /* We use this to deterimine children of an item */
5737 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
5740 /* we need to return the count of the array in ChildrenArray for this folder */
5741 NSArray *children = nil;
5744 children = UserPresets;
5748 if ([item objectForKey:@"ChildrenArray"])
5750 children = [item objectForKey:@"ChildrenArray"];
5753 if ((children == nil) || ( [children count] <= (NSUInteger) index))
5759 return [children objectAtIndex:index];
5763 // We are only one level deep, so we can't be asked about children
5764 //NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
5768 /* We use this to determine if an item should be expandable */
5769 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
5772 /* we need to return the count of the array in ChildrenArray for this folder */
5773 NSArray *children= nil;
5776 children = UserPresets;
5780 if ([item objectForKey:@"ChildrenArray"])
5782 children = [item objectForKey:@"ChildrenArray"];
5786 /* To deterimine if an item should show a disclosure triangle
5787 * we could do it by the children count as so:
5788 * if ([children count] < 1)
5789 * However, lets leave the triangle show even if there are no
5790 * children to help indicate a folder, just like folder in the
5791 * finder can show a disclosure triangle even when empty
5794 /* We need to determine if the item is a folder */
5795 if ([[item objectForKey:@"Folder"] intValue] == 1)
5806 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
5808 // Our outline view has no levels, but we can still expand every item. Doing so
5809 // just makes the row taller. See heightOfRowByItem below.
5810 //return ![(HBQueueOutlineView*)outlineView isDragging];
5816 /* Used to tell the outline view which information is to be displayed per item */
5817 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5819 /* We have two columns right now, icon and PresetName */
5821 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5823 return [item objectForKey:@"PresetName"];
5832 - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object
5834 return [NSKeyedUnarchiver unarchiveObjectWithData:object];
5836 - (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item
5838 return [NSKeyedArchiver archivedDataWithRootObject:item];
5841 #pragma mark - Added Functionality (optional)
5842 /* Use to customize the font and display characteristics of the title cell */
5843 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
5845 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5849 NSColor *shadowColor;
5850 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
5851 /*check to see if its a selected row */
5852 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
5855 fontColor = [NSColor blackColor];
5856 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
5860 if ([[item objectForKey:@"Type"] intValue] == 0)
5862 fontColor = [NSColor blueColor];
5864 else // User created preset, use a black font
5866 fontColor = [NSColor blackColor];
5868 /* check to see if its a folder */
5869 //if ([[item objectForKey:@"Folder"] intValue] == 1)
5871 //fontColor = [NSColor greenColor];
5876 /* We use Bold Text for the HB Default */
5877 if ([[item objectForKey:@"Default"] intValue] == 1)// 1 is HB default
5879 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5881 /* We use Bold Text for the User Specified Default */
5882 if ([[item objectForKey:@"Default"] intValue] == 2)// 2 is User default
5884 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5888 [cell setTextColor:fontColor];
5889 [cell setFont:txtFont];
5894 /* We use this to edit the name field in the outline view */
5895 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5897 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5902 [theRecord setObject:object forKey:@"PresetName"];
5906 [fPresetsOutlineView reloadData];
5907 /* We save all of the preset data here */
5911 /* We use this to provide tooltips for the items in the presets outline view */
5912 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
5914 //if ([[tc identifier] isEqualToString:@"PresetName"])
5916 /* initialize the tooltip contents variable */
5918 /* if there is a description for the preset, we show it in the tooltip */
5919 if ([item objectForKey:@"PresetDescription"])
5921 loc_tip = [item objectForKey:@"PresetDescription"];
5926 loc_tip = @"No description available";
5933 #pragma mark Preset Outline View Methods (dragging related)
5936 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
5938 // Dragging is only allowed for custom presets.
5939 //[[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1
5940 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
5944 // Don't retain since this is just holding temporaral drag information, and it is
5945 //only used during a drag! We could put this in the pboard actually.
5946 fDraggedNodes = items;
5947 // Provide data for our custom type, and simple NSStrings.
5948 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
5950 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
5951 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
5956 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
5959 // Don't allow dropping ONTO an item since they can't really contain any children.
5961 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
5962 if (isOnDropTypeProposal)
5963 return NSDragOperationNone;
5965 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
5968 index = [fPresetsOutlineView rowForItem: item] + 1;
5972 // Don't allow dropping into the Built In Presets.
5973 if (index < presetCurrentBuiltInCount)
5975 return NSDragOperationNone;
5976 index = MAX (index, presetCurrentBuiltInCount);
5979 [outlineView setDropItem:item dropChildIndex:index];
5980 return NSDragOperationGeneric;
5985 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
5987 /* first, lets see if we are dropping into a folder */
5988 if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
5990 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
5991 childrenArray = [[fPresetsOutlineView itemAtRow:index] objectForKey:@"ChildrenArray"];
5992 [childrenArray addObject:item];
5993 [[fPresetsOutlineView itemAtRow:index] setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
5994 [childrenArray autorelease];
5996 else // We are not, so we just move the preset into the existing array
5998 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
6000 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
6001 while (obj = [enumerator nextObject])
6003 [moveItems addIndex:[UserPresets indexOfObject:obj]];
6005 // Successful drop, lets rearrange the view and save it all
6006 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
6008 [fPresetsOutlineView reloadData];
6013 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
6015 NSUInteger index = [indexSet lastIndex];
6016 NSUInteger aboveInsertIndexCount = 0;
6018 NSUInteger removeIndex;
6020 if (index >= insertIndex)
6022 removeIndex = index + aboveInsertIndexCount;
6023 aboveInsertIndexCount++;
6027 removeIndex = index;
6031 id object = [[array objectAtIndex:removeIndex] retain];
6032 [array removeObjectAtIndex:removeIndex];
6033 [array insertObject:object atIndex:insertIndex];
6036 index = [indexSet indexLessThanIndex:index];
6041 #pragma mark - Functional Preset NSOutlineView Methods
6043 - (IBAction)selectPreset:(id)sender
6046 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
6048 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6049 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6051 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
6053 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
6057 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6061 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
6062 [self formatPopUpChanged:nil];
6064 /* Chapter Markers*/
6065 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
6066 /* check to see if we have only one chapter */
6067 [self chapterPopUpChanged:nil];
6069 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6070 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
6071 /* Mux mp4 with http optimization */
6072 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
6075 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
6076 /* We set the advanced opt string here if applicable*/
6077 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
6079 /* Lets run through the following functions to get variables set there */
6080 [self videoEncoderPopUpChanged:nil];
6081 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
6082 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
6083 [self calculateBitrate:nil];
6086 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
6088 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
6089 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
6091 /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float.
6092 * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type
6093 * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret
6094 * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet,
6095 * though it should be a corner case since it would pretty much be a preset for lossless encoding. */
6096 if ([[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue] < 1.0)
6098 /* For the quality slider we need to convert the old percent's to the new rf scales */
6099 float rf = (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]);
6100 [fVidQualitySlider setFloatValue:rf];
6105 [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6108 [self videoMatrixChanged:nil];
6110 /* Video framerate */
6111 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
6112 detected framerate in the fVidRatePopUp so we use index 0*/
6113 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
6115 [fVidRatePopUp selectItemAtIndex: 0];
6119 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
6123 /* 2 Pass Encoding */
6124 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
6125 [self twoPassCheckboxChanged:nil];
6127 /* Turbo 1st pass for 2 Pass Encoding */
6128 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
6131 /* First we check to see if we are using the current audio track layout based on AudioList array */
6132 if ([chosenPreset objectForKey:@"AudioList"])
6134 /* Populate the audio widgets based on the contents of the AudioList array */
6136 NSEnumerator *enumerator = [[chosenPreset objectForKey:@"AudioList"] objectEnumerator];
6138 while (tempObject = [enumerator nextObject])
6143 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6145 [fAudLang1PopUp selectItemAtIndex: 1];
6147 [self audioTrackPopUpChanged: fAudLang1PopUp];
6148 [fAudTrack1CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6149 /* check our pref for core audio and use it in place of faac if applicable */
6150 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6151 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6153 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6156 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6157 [fAudTrack1MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6158 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6160 if ([fAudTrack1MixPopUp selectedItem] == nil)
6162 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6164 [fAudTrack1RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6165 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6166 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6168 [fAudTrack1BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6170 [fAudTrack1DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6171 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6177 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6179 [fAudLang2PopUp selectItemAtIndex: 1];
6181 [self audioTrackPopUpChanged: fAudLang2PopUp];
6182 [fAudTrack2CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6183 /* check our pref for core audio and use it in place of faac if applicable */
6184 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6185 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6187 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6189 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6190 [fAudTrack2MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6191 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6193 if ([fAudTrack2MixPopUp selectedItem] == nil)
6195 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6197 [fAudTrack2RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6198 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6199 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6201 [fAudTrack2BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6203 [fAudTrack2DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6204 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6210 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6214 [fAudLang4PopUp selectItemAtIndex: 0];
6215 [self audioTrackPopUpChanged: fAudLang4PopUp];
6219 [fAudLang3PopUp selectItemAtIndex: 0];
6220 [self audioTrackPopUpChanged: fAudLang3PopUp];
6224 [fAudLang2PopUp selectItemAtIndex: 0];
6225 [self audioTrackPopUpChanged: fAudLang2PopUp];
6233 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
6235 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6237 [fAudLang1PopUp selectItemAtIndex: 1];
6239 [self audioTrackPopUpChanged: fAudLang1PopUp];
6240 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
6241 /* check our pref for core audio and use it in place of faac if applicable */
6242 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6243 [[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString: @"AAC (faac)"])
6245 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6247 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6248 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
6249 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6251 if ([fAudTrack1MixPopUp selectedItem] == nil)
6253 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6255 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
6256 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6257 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
6259 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
6261 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
6262 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6264 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
6266 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6268 [fAudLang2PopUp selectItemAtIndex: 1];
6270 [self audioTrackPopUpChanged: fAudLang2PopUp];
6271 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
6272 /* check our pref for core audio and use it in place of faac if applicable */
6273 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6274 [[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString: @"AAC (faac)"])
6276 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6278 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6279 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
6280 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6282 if ([fAudTrack2MixPopUp selectedItem] == nil)
6284 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6286 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
6287 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6288 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
6290 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
6292 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
6293 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6295 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
6297 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
6299 [fAudLang3PopUp selectItemAtIndex: 1];
6301 [self audioTrackPopUpChanged: fAudLang3PopUp];
6302 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
6303 /* check our pref for core audio and use it in place of faac if applicable */
6304 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6305 [[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AAC (faac)"])
6307 [fAudTrack3CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6309 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6310 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
6311 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6313 if ([fAudTrack3MixPopUp selectedItem] == nil)
6315 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6317 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
6318 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6319 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
6321 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
6323 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
6324 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
6326 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
6328 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
6330 [fAudLang4PopUp selectItemAtIndex: 1];
6332 [self audioTrackPopUpChanged: fAudLang4PopUp];
6333 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
6334 /* check our pref for core audio and use it in place of faac if applicable */
6335 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6336 [[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString: @"AAC (faac)"])
6338 [fAudTrack4CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6340 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6341 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
6342 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6344 if ([fAudTrack4MixPopUp selectedItem] == nil)
6346 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6348 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
6349 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6350 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
6352 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
6354 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
6355 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
6358 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6360 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
6362 [fAudLang2PopUp selectItemAtIndex: 0];
6363 [self audioTrackPopUpChanged: fAudLang2PopUp];
6365 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
6367 [fAudLang3PopUp selectItemAtIndex: 0];
6368 [self audioTrackPopUpChanged: fAudLang3PopUp];
6370 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
6372 [fAudLang4PopUp selectItemAtIndex: 0];
6373 [self audioTrackPopUpChanged: fAudLang4PopUp];
6378 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
6379 /* Forced Subtitles */
6380 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
6382 /* Picture Settings */
6383 /* Note: objectForKey:@"UsesPictureSettings" refers to picture size, which encompasses:
6384 * height, width, keep ar, anamorphic and crop settings.
6385 * picture filters are handled separately below.
6387 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
6388 * ( 2 is use max for source and 1 is use exact size when the preset was created ) and the
6389 * preset completely ignores any picture sizing values in the preset.
6391 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
6393 hb_job_t * job = fTitle->job;
6395 /* If Cropping is set to custom, then recall all four crop values from
6396 when the preset was created and apply them */
6397 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
6399 [fPictureController setAutoCrop:NO];
6401 /* Here we use the custom crop values saved at the time the preset was saved */
6402 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
6403 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
6404 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
6405 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
6408 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
6410 [fPictureController setAutoCrop:YES];
6411 /* Here we use the auto crop values determined right after scan */
6412 job->crop[0] = AutoCropTop;
6413 job->crop[1] = AutoCropBottom;
6414 job->crop[2] = AutoCropLeft;
6415 job->crop[3] = AutoCropRight;
6420 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
6421 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
6423 /* Use Max Picture settings for whatever the dvd is.*/
6424 [self revertPictureSizeToMax:nil];
6425 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6426 if (job->keep_ratio == 1)
6428 hb_fix_aspect( job, HB_KEEP_WIDTH );
6429 if( job->height > fTitle->height )
6431 job->height = fTitle->height;
6432 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6435 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6437 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
6439 /* we check to make sure the presets width/height does not exceed the sources width/height */
6440 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
6442 /* if so, then we use the sources height and width to avoid scaling up */
6443 //job->width = fTitle->width;
6444 //job->height = fTitle->height;
6445 [self revertPictureSizeToMax:nil];
6447 else // source width/height is >= the preset height/width
6449 /* we can go ahead and use the presets values for height and width */
6450 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
6451 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
6453 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6454 if (job->keep_ratio == 1)
6456 hb_fix_aspect( job, HB_KEEP_WIDTH );
6457 if( job->height > fTitle->height )
6459 job->height = fTitle->height;
6460 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6463 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6469 /* If the preset has an objectForKey:@"UsesPictureFilters", and handle the filters here */
6470 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
6474 /* We only allow *either* Decomb or Deinterlace. So check for the PictureDecombDeinterlace key.
6475 * also, older presets may not have this key, in which case we also check to see if that preset had PictureDecomb
6476 * specified, in which case we use decomb and ignore any possible Deinterlace settings as using both was less than
6479 [fPictureController setUseDecomb:1];
6480 [fPictureController setDecomb:0];
6481 [fPictureController setDeinterlace:0];
6482 if ([[chosenPreset objectForKey:@"PictureDecombDeinterlace"] intValue] == 1 || [[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6484 /* we are using decomb */
6486 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6488 [fPictureController setDecomb:[[chosenPreset objectForKey:@"PictureDecomb"] intValue]];
6490 /* if we are using "Custom" in the decomb setting, also set the custom string*/
6491 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] == 2)
6493 [fPictureController setDecombCustomString:[chosenPreset objectForKey:@"PictureDecombCustom"]];
6499 /* We are using Deinterlace */
6501 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] > 0)
6503 [fPictureController setUseDecomb:0];
6504 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
6505 /* if we are using "Custom" in the deinterlace setting, also set the custom string*/
6506 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
6508 [fPictureController setDeinterlaceCustomString:[chosenPreset objectForKey:@"PictureDeinterlaceCustom"]];
6515 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] > 0)
6517 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
6518 /* if we are using "Custom" in the detelecine setting, also set the custom string*/
6519 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 2)
6521 [fPictureController setDetelecineCustomString:[chosenPreset objectForKey:@"PictureDetelecineCustom"]];
6526 [fPictureController setDetelecine:0];
6530 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] > 0)
6532 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
6533 /* if we are using "Custom" in the denoise setting, also set the custom string*/
6534 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] == 4)
6536 [fPictureController setDenoiseCustomString:[chosenPreset objectForKey:@"PictureDenoiseCustom"]];
6541 [fPictureController setDenoise:0];
6545 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
6547 /* if its a one, then its the old on/off deblock, set on to 5*/
6548 [fPictureController setDeblock:5];
6552 /* use the settings intValue */
6553 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
6556 if ([[chosenPreset objectForKey:@"VideoGrayScale"] intValue] == 1)
6558 [fPictureController setGrayscale:1];
6562 [fPictureController setGrayscale:0];
6565 /* we call SetTitle: in fPictureController so we get an instant update in the Picture Settings window */
6566 [fPictureController SetTitle:fTitle];
6567 [fPictureController SetTitle:fTitle];
6568 [self calculatePictureSizing:nil];
6574 #pragma mark Manage Presets
6576 - (void) loadPresets {
6577 /* We declare the default NSFileManager into fileManager */
6578 NSFileManager * fileManager = [NSFileManager defaultManager];
6579 /*We define the location of the user presets file */
6580 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
6581 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
6582 /* We check for the presets.plist */
6583 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
6585 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
6588 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
6589 if (nil == UserPresets)
6591 UserPresets = [[NSMutableArray alloc] init];
6592 [self addFactoryPresets:nil];
6594 [fPresetsOutlineView reloadData];
6596 [self checkBuiltInsForUpdates];
6599 - (void) checkBuiltInsForUpdates {
6601 BOOL updateBuiltInPresets = NO;
6603 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6605 while (tempObject = [enumerator nextObject])
6607 /* iterate through the built in presets to see if any have an old build number */
6608 NSMutableDictionary *thisPresetDict = tempObject;
6609 /*Key Type == 0 is built in, and key PresetBuildNumber is the build number it was created with */
6610 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0)
6612 if (![thisPresetDict objectForKey:@"PresetBuildNumber"] || [[thisPresetDict objectForKey:@"PresetBuildNumber"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue])
6614 updateBuiltInPresets = YES;
6619 /* if we have built in presets to update, then do so AlertBuiltInPresetUpdate*/
6620 if ( updateBuiltInPresets == YES)
6622 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"AlertBuiltInPresetUpdate"] == YES)
6624 /* Show an alert window that built in presets will be updated */
6625 /*On Screen Notification*/
6628 status = NSRunAlertPanel(@"HandBrake has determined your built in presets are out of date...",@"HandBrake will now update your built-in presets.", @"OK", nil, nil);
6629 [NSApp requestUserAttention:NSCriticalRequest];
6631 /* when alert is dismissed, go ahead and update the built in presets */
6632 [self addFactoryPresets:nil];
6638 - (IBAction) showAddPresetPanel: (id) sender
6640 /* Deselect the currently selected Preset if there is one*/
6641 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
6643 /* Populate the preset picture settings popup here */
6644 [fPresetNewPicSettingsPopUp removeAllItems];
6645 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
6646 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
6647 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
6648 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
6649 /* Uncheck the preset use filters checkbox */
6650 [fPresetNewPicFiltersCheck setState:NSOffState];
6651 // fPresetNewFolderCheck
6652 [fPresetNewFolderCheck setState:NSOffState];
6653 /* Erase info from the input fields*/
6654 [fPresetNewName setStringValue: @""];
6655 [fPresetNewDesc setStringValue: @""];
6656 /* Show the panel */
6657 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
6660 - (IBAction) closeAddPresetPanel: (id) sender
6662 [NSApp endSheet: fAddPresetPanel];
6663 [fAddPresetPanel orderOut: self];
6666 - (IBAction)addUserPreset:(id)sender
6668 if (![[fPresetNewName stringValue] length])
6669 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
6672 /* Here we create a custom user preset */
6673 [UserPresets addObject:[self createPreset]];
6676 [self closeAddPresetPanel:nil];
6683 /* We Reload the New Table data for presets */
6684 [fPresetsOutlineView reloadData];
6685 /* We save all of the preset data here */
6693 /* We Sort the Presets By Factory or Custom */
6694 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
6695 ascending:YES] autorelease];
6696 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
6698 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
6699 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
6700 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
6703 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
6704 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
6705 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
6706 [UserPresets setArray:sortedArray];
6711 - (IBAction)insertPreset:(id)sender
6713 int index = [fPresetsOutlineView selectedRow];
6714 [UserPresets insertObject:[self createPreset] atIndex:index];
6715 [fPresetsOutlineView reloadData];
6719 - (NSDictionary *)createPreset
6721 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
6722 /* Preset build number */
6723 [preset setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
6724 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6725 /* Get the New Preset Name from the field in the AddPresetPanel */
6726 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6727 /* Set whether or not this is to be a folder fPresetNewFolderCheck*/
6728 [preset setObject:[NSNumber numberWithBool:[fPresetNewFolderCheck state]] forKey:@"Folder"];
6729 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
6730 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
6731 /*Set whether or not this is default, at creation set to 0*/
6732 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6733 if ([fPresetNewFolderCheck state] == YES)
6735 /* initialize and set an empty array for children here since we are a new folder */
6736 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6737 [preset setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6738 [childrenArray autorelease];
6740 else // we are not creating a preset folder, so we go ahead with the rest of the preset info
6742 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
6743 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
6744 /* Get whether or not to use the current Picture Filter settings for the preset */
6745 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
6747 /* Get New Preset Description from the field in the AddPresetPanel*/
6748 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
6750 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
6751 /* Chapter Markers fCreateChapterMarkers*/
6752 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
6753 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6754 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
6755 /* Mux mp4 with http optimization */
6756 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
6757 /* Add iPod uuid atom */
6758 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
6762 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
6763 /* x264 Option String */
6764 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
6766 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
6767 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
6768 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
6769 [preset setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
6771 /* Video framerate */
6772 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
6774 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
6776 else // we can record the actual titleOfSelectedItem
6778 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
6781 /* 2 Pass Encoding */
6782 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
6783 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
6784 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
6785 /*Picture Settings*/
6786 hb_job_t * job = fTitle->job;
6787 /* Picture Sizing */
6788 /* Use Max Picture settings for whatever the dvd is.*/
6789 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
6790 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
6791 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
6792 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
6793 [preset setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
6795 /* Set crop settings here */
6796 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
6797 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
6798 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
6799 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
6800 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
6802 /* Picture Filters */
6803 [preset setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
6804 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
6805 [preset setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
6806 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
6807 [preset setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
6808 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
6809 [preset setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
6810 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
6811 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
6812 [preset setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
6813 [preset setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
6816 NSMutableArray *audioListArray = [[NSMutableArray alloc] init];
6817 /* we actually call the methods for the nests here */
6818 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
6820 NSMutableDictionary *audioTrack1Array = [[NSMutableDictionary alloc] init];
6821 [audioTrack1Array setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6822 [audioTrack1Array setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6823 [audioTrack1Array setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6824 [audioTrack1Array setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6825 [audioTrack1Array setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6826 [audioTrack1Array setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6827 [audioTrack1Array setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6828 [audioTrack1Array autorelease];
6829 [audioListArray addObject:audioTrack1Array];
6832 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
6834 NSMutableDictionary *audioTrack2Array = [[NSMutableDictionary alloc] init];
6835 [audioTrack2Array setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6836 [audioTrack2Array setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6837 [audioTrack2Array setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6838 [audioTrack2Array setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6839 [audioTrack2Array setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6840 [audioTrack2Array setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6841 [audioTrack2Array setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6842 [audioTrack2Array autorelease];
6843 [audioListArray addObject:audioTrack2Array];
6846 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
6848 NSMutableDictionary *audioTrack3Array = [[NSMutableDictionary alloc] init];
6849 [audioTrack3Array setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6850 [audioTrack3Array setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6851 [audioTrack3Array setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6852 [audioTrack3Array setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6853 [audioTrack3Array setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6854 [audioTrack3Array setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6855 [audioTrack3Array setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6856 [audioTrack3Array autorelease];
6857 [audioListArray addObject:audioTrack3Array];
6860 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
6862 NSMutableDictionary *audioTrack4Array = [[NSMutableDictionary alloc] init];
6863 [audioTrack4Array setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6864 [audioTrack4Array setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6865 [audioTrack4Array setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6866 [audioTrack4Array setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6867 [audioTrack4Array setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6868 [audioTrack4Array setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6869 [audioTrack4Array setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6870 [audioTrack4Array autorelease];
6871 [audioListArray addObject:audioTrack4Array];
6875 [preset setObject:[NSMutableArray arrayWithArray: audioListArray] forKey:@"AudioList"];
6880 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
6881 /* Forced Subtitles */
6882 [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
6884 [preset autorelease];
6891 [UserPresets writeToFile:UserPresetsFile atomically:YES];
6892 /* We get the default preset in case it changed */
6893 [self getDefaultPresets:nil];
6897 - (IBAction)deletePreset:(id)sender
6901 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
6905 /* Alert user before deleting preset */
6907 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
6909 if ( status == NSAlertDefaultReturn )
6911 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6912 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6913 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
6915 NSEnumerator *enumerator;
6916 NSMutableArray *presetsArrayToMod;
6917 NSMutableArray *tempArray;
6919 /* If we are a root level preset, we are modding the UserPresets array */
6920 if (presetToModLevel == 0)
6922 presetsArrayToMod = UserPresets;
6924 else // We have a parent preset, so we modify the chidren array object for key
6926 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
6929 enumerator = [presetsArrayToMod objectEnumerator];
6930 tempArray = [NSMutableArray array];
6932 while (tempObject = [enumerator nextObject])
6934 NSDictionary *thisPresetDict = tempObject;
6935 if (thisPresetDict == presetToMod)
6937 [tempArray addObject:tempObject];
6941 [presetsArrayToMod removeObjectsInArray:tempArray];
6942 [fPresetsOutlineView reloadData];
6949 #pragma mark Import Export Preset(s)
6951 - (IBAction) browseExportPresetFile: (id) sender
6953 /* Open a panel to let the user choose where and how to save the export file */
6954 NSSavePanel * panel = [NSSavePanel savePanel];
6955 /* We get the current file name and path from the destination field here */
6956 NSString *defaultExportDirectory = [NSString stringWithFormat: @"%@/Desktop/", NSHomeDirectory()];
6958 [panel beginSheetForDirectory: defaultExportDirectory file: @"HB_Export.plist"
6959 modalForWindow: fWindow modalDelegate: self
6960 didEndSelector: @selector( browseExportPresetFileDone:returnCode:contextInfo: )
6964 - (void) browseExportPresetFileDone: (NSSavePanel *) sheet
6965 returnCode: (int) returnCode contextInfo: (void *) contextInfo
6967 if( returnCode == NSOKButton )
6969 NSString *presetExportDirectory = [[sheet filename] stringByDeletingLastPathComponent];
6970 NSString *exportPresetsFile = [sheet filename];
6971 [[NSUserDefaults standardUserDefaults] setObject:presetExportDirectory forKey:@"LastPresetExportDirectory"];
6972 /* We check for the presets.plist */
6973 if ([[NSFileManager defaultManager] fileExistsAtPath:exportPresetsFile] == 0)
6975 [[NSFileManager defaultManager] createFileAtPath:exportPresetsFile contents:nil attributes:nil];
6977 NSMutableArray * presetsToExport = [[NSMutableArray alloc] initWithContentsOfFile:exportPresetsFile];
6978 if (nil == presetsToExport)
6980 presetsToExport = [[NSMutableArray alloc] init];
6982 /* now get and add selected presets to export */
6985 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
6987 [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6988 [presetsToExport writeToFile:exportPresetsFile atomically:YES];
6996 - (IBAction) browseImportPresetFile: (id) sender
6999 NSOpenPanel * panel;
7001 panel = [NSOpenPanel openPanel];
7002 [panel setAllowsMultipleSelection: NO];
7003 [panel setCanChooseFiles: YES];
7004 [panel setCanChooseDirectories: NO ];
7005 NSString * sourceDirectory;
7006 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"])
7008 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"];
7012 sourceDirectory = @"~/Desktop";
7013 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
7015 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
7016 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
7018 /* set this for allowed file types, not sure if we should allow xml or not */
7019 NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"xml", nil];
7020 [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes
7021 modalForWindow: fWindow modalDelegate: self
7022 didEndSelector: @selector( browseImportPresetDone:returnCode:contextInfo: )
7023 contextInfo: sender];
7026 - (void) browseImportPresetDone: (NSSavePanel *) sheet
7027 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7029 if( returnCode == NSOKButton )
7031 NSString *importPresetsDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7032 NSString *importPresetsFile = [sheet filename];
7033 [[NSUserDefaults standardUserDefaults] setObject:importPresetsDirectory forKey:@"LastPresetImportDirectory"];
7034 /* NOTE: here we need to do some sanity checking to verify we do not hose up our presets file */
7035 NSMutableArray * presetsToImport = [[NSMutableArray alloc] initWithContentsOfFile:importPresetsFile];
7036 /* iterate though the new array of presets to import and add them to our presets array */
7038 NSEnumerator *enumerator = [presetsToImport objectEnumerator];
7040 while (tempObject = [enumerator nextObject])
7042 /* make any changes to the incoming preset we see fit */
7043 /* make sure the incoming preset is not tagged as default */
7044 [tempObject setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7045 /* prepend "(imported) to the name of the incoming preset for clarification since it can be changed */
7046 NSString * prependedName = [@"(import) " stringByAppendingString:[tempObject objectForKey:@"PresetName"]] ;
7047 [tempObject setObject:prependedName forKey:@"PresetName"];
7049 /* actually add the new preset to our presets array */
7050 [UserPresets addObject:tempObject];
7053 [presetsToImport autorelease];
7061 #pragma mark Manage Default Preset
7063 - (IBAction)getDefaultPresets:(id)sender
7065 presetHbDefault = nil;
7066 presetUserDefault = nil;
7067 presetUserDefaultParent = nil;
7068 presetUserDefaultParentParent = nil;
7069 NSMutableDictionary *presetHbDefaultParent = nil;
7070 NSMutableDictionary *presetHbDefaultParentParent = nil;
7073 BOOL userDefaultFound = NO;
7074 presetCurrentBuiltInCount = 0;
7075 /* First we iterate through the root UserPresets array to check for defaults */
7076 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7078 while (tempObject = [enumerator nextObject])
7080 NSMutableDictionary *thisPresetDict = tempObject;
7081 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7083 presetHbDefault = thisPresetDict;
7085 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7087 presetUserDefault = thisPresetDict;
7088 userDefaultFound = YES;
7090 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7092 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
7096 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7097 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7099 NSMutableDictionary *thisPresetDictParent = thisPresetDict;
7100 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7102 while (tempObject = [enumerator nextObject])
7104 NSMutableDictionary *thisPresetDict = tempObject;
7105 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7107 presetHbDefault = thisPresetDict;
7108 presetHbDefaultParent = thisPresetDictParent;
7110 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7112 presetUserDefault = thisPresetDict;
7113 presetUserDefaultParent = thisPresetDictParent;
7114 userDefaultFound = YES;
7117 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7118 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7120 NSMutableDictionary *thisPresetDictParentParent = thisPresetDict;
7121 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7123 while (tempObject = [enumerator nextObject])
7125 NSMutableDictionary *thisPresetDict = tempObject;
7126 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7128 presetHbDefault = thisPresetDict;
7129 presetHbDefaultParent = thisPresetDictParent;
7130 presetHbDefaultParentParent = thisPresetDictParentParent;
7132 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7134 presetUserDefault = thisPresetDict;
7135 presetUserDefaultParent = thisPresetDictParent;
7136 presetUserDefaultParentParent = thisPresetDictParentParent;
7137 userDefaultFound = YES;
7146 /* check to see if a user specified preset was found, if not then assign the parents for
7147 * the presetHbDefault so that we can open the parents for the nested presets
7149 if (userDefaultFound == NO)
7151 presetUserDefaultParent = presetHbDefaultParent;
7152 presetUserDefaultParentParent = presetHbDefaultParentParent;
7156 - (IBAction)setDefaultPreset:(id)sender
7158 /* We need to determine if the item is a folder */
7159 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] == 1)
7165 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7167 /* First make sure the old user specified default preset is removed */
7168 while (tempObject = [enumerator nextObject])
7170 NSMutableDictionary *thisPresetDict = tempObject;
7171 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7173 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7176 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7177 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7179 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7182 while (tempObject = [enumerator nextObject])
7184 NSMutableDictionary *thisPresetDict1 = tempObject;
7185 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7187 [[[thisPresetDict objectForKey:@"ChildrenArray"] objectAtIndex:ii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7189 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7190 if ([thisPresetDict1 objectForKey:@"ChildrenArray"])
7192 NSEnumerator *enumerator = [[thisPresetDict1 objectForKey:@"ChildrenArray"] objectEnumerator];
7195 while (tempObject = [enumerator nextObject])
7197 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7199 [[[thisPresetDict1 objectForKey:@"ChildrenArray"] objectAtIndex:iii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7212 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7213 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
7214 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
7217 NSMutableArray *presetsArrayToMod;
7218 NSMutableArray *tempArray;
7220 /* If we are a root level preset, we are modding the UserPresets array */
7221 if (presetToModLevel == 0)
7223 presetsArrayToMod = UserPresets;
7225 else // We have a parent preset, so we modify the chidren array object for key
7227 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
7230 enumerator = [presetsArrayToMod objectEnumerator];
7231 tempArray = [NSMutableArray array];
7233 while (tempObject = [enumerator nextObject])
7235 NSDictionary *thisPresetDict = tempObject;
7236 if (thisPresetDict == presetToMod)
7238 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 2
7240 [[presetsArrayToMod objectAtIndex:iiii] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
7247 /* We save all of the preset data here */
7249 /* We Reload the New Table data for presets */
7250 [fPresetsOutlineView reloadData];
7253 - (IBAction)selectDefaultPreset:(id)sender
7255 NSMutableDictionary *presetToMod;
7256 /* if there is a user specified default, we use it */
7257 if (presetUserDefault)
7259 presetToMod = presetUserDefault;
7261 else if (presetHbDefault) //else we use the built in default presetHbDefault
7263 presetToMod = presetHbDefault;
7270 if (presetUserDefaultParent != nil)
7272 [fPresetsOutlineView expandItem:presetUserDefaultParent];
7275 if (presetUserDefaultParentParent != nil)
7277 [fPresetsOutlineView expandItem:presetUserDefaultParentParent];
7281 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[fPresetsOutlineView rowForItem: presetToMod]] byExtendingSelection:NO];
7282 [self selectPreset:nil];
7287 #pragma mark Manage Built In Presets
7290 - (IBAction)deleteFactoryPresets:(id)sender
7293 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7297 NSMutableArray *tempArray;
7300 tempArray = [NSMutableArray array];
7301 /* we look here to see if the preset is we move on to the next one */
7302 while ( tempObject = [enumerator nextObject] )
7304 /* if the preset is "Factory" then we put it in the array of
7305 presets to delete */
7306 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
7308 [tempArray addObject:tempObject];
7312 [UserPresets removeObjectsInArray:tempArray];
7313 [fPresetsOutlineView reloadData];
7318 /* We use this method to recreate new, updated factory presets */
7319 - (IBAction)addFactoryPresets:(id)sender
7322 /* First, we delete any existing built in presets */
7323 [self deleteFactoryPresets: sender];
7324 /* Then we generate new built in presets programmatically with fPresetsBuiltin
7325 * which is all setup in HBPresets.h and HBPresets.m*/
7326 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
7327 /* update build number for built in presets */
7328 /* iterate though the new array of presets to import and add them to our presets array */
7330 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7332 while (tempObject = [enumerator nextObject])
7334 /* Record the apps current build number in the PresetBuildNumber key */
7335 if ([[tempObject objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7337 /* Preset build number */
7338 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
7342 /* report the built in preset updating to the activity log */
7343 [self writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]];
7353 /*******************************
7354 * Subclass of the HBPresetsOutlineView *
7355 *******************************/
7357 @implementation HBPresetsOutlineView
7358 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
7362 // By default, NSTableView only drags an image of the first column. Change this to
7363 // drag an image of the queue's icon and PresetName columns.
7364 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"PresetName"], nil];
7365 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
7370 - (void) mouseDown:(NSEvent *)theEvent
7372 [super mouseDown:theEvent];
7378 - (BOOL) isDragging;