1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
8 #import "HBOutputPanelController.h"
9 #import "HBPreferencesController.h"
10 #import "HBDVDDetector.h"
12 #import "HBPreviewController.h"
14 #define DragDropSimplePboardType @"MyCustomOutlineViewPboardType"
16 /* We setup the toolbar values here ShowPreviewIdentifier */
17 static NSString * ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
18 static NSString * StartEncodingIdentifier = @"Start Encoding Item Identifier";
19 static NSString * PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
20 static NSString * ShowQueueIdentifier = @"Show Queue Item Identifier";
21 static NSString * AddToQueueIdentifier = @"Add to Queue Item Identifier";
22 static NSString * ShowPictureIdentifier = @"Show Picture Window Item Identifier";
23 static NSString * ShowPreviewIdentifier = @"Show Preview Window Item Identifier";
24 static NSString * ShowActivityIdentifier = @"Debug Output Item Identifier";
25 static NSString * ChooseSourceIdentifier = @"Choose Source Item Identifier";
28 /*******************************
29 * HBController implementation *
30 *******************************/
31 @implementation HBController
41 /* replace bundled app icon with one which is 32/64-bit savvy */
42 #if defined( __LP64__ )
43 fApplicationIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"HandBrake-64.icns"]];
45 fApplicationIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"HandBrake.icns"]];
47 if( fApplicationIcon != nil )
48 [NSApp setApplicationIconImage:fApplicationIcon];
50 [HBPreferencesController registerUserDefaults];
52 fQueueEncodeLibhb = NULL;
53 /* Check for check for the app support directory here as
54 * outputPanel needs it right away, as may other future methods
56 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
58 YES ) objectAtIndex:0];
59 AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
60 stringByAppendingPathComponent:@"HandBrake"];
61 if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
63 [[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
66 /* Check for and create the App Support Preview directory if necessary */
67 NSString *PreviewDirectory = [AppSupportDirectory stringByAppendingPathComponent:@"Previews"];
68 if( ![[NSFileManager defaultManager] fileExistsAtPath:PreviewDirectory] )
70 [[NSFileManager defaultManager] createDirectoryAtPath:PreviewDirectory
73 outputPanel = [[HBOutputPanelController alloc] init];
74 fPictureController = [[PictureController alloc] init];
75 fQueueController = [[HBQueueController alloc] init];
76 fAdvancedOptions = [[HBAdvancedController alloc] init];
77 /* we init the HBPresets class which currently is only used
78 * for updating built in presets, may move more functionality
81 fPresetsBuiltin = [[HBPresets alloc] init];
82 fPreferencesController = [[HBPreferencesController alloc] init];
83 /* Lets report the HandBrake version number here to the activity log and text log file */
84 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
85 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
91 - (void) applicationDidFinishLaunching: (NSNotification *) notification
93 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
94 int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
95 fHandle = hb_init(loggingLevel, 0);
96 /* Optional dvd nav UseDvdNav*/
97 hb_dvd_set_dvdnav([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]);
98 /* Init a separate instance of libhb for user scanning and setting up jobs */
99 fQueueEncodeLibhb = hb_init(loggingLevel, 0);
101 // Set the Growl Delegate
102 [GrowlApplicationBridge setGrowlDelegate: self];
103 /* Init others controllers */
104 [fPictureController SetHandle: fHandle];
105 [fPictureController setHBController: self];
107 [fQueueController setHandle: fQueueEncodeLibhb];
108 [fQueueController setHBController: self];
110 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
111 [fChapterTable setDataSource:fChapterTitlesDelegate];
112 [fChapterTable setDelegate:fChapterTitlesDelegate];
114 /* setup the subtitles delegate and connections to table */
115 fSubtitlesDelegate = [[HBSubtitles alloc] init];
116 [fSubtitlesTable setDataSource:fSubtitlesDelegate];
117 [fSubtitlesTable setDelegate:fSubtitlesDelegate];
118 [fSubtitlesTable setRowHeight:25.0];
120 [fPresetsOutlineView setAutosaveName:@"Presets View"];
121 [fPresetsOutlineView setAutosaveExpandedItems:YES];
123 dockIconProgress = 0;
125 /* Call UpdateUI every 1/2 sec */
126 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
127 scheduledTimerWithTimeInterval:0.5 target:self
128 selector:@selector(updateUI:) userInfo:nil repeats:YES]
129 forMode:NSDefaultRunLoopMode];
131 // Open debug output window now if it was visible when HB was closed
132 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
133 [self showDebugOutputPanel:nil];
135 // Open queue window now if it was visible when HB was closed
136 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
137 [self showQueueWindow:nil];
139 [self openMainWindow:nil];
141 /* We have to set the bool to tell hb what to do after a scan
142 * Initially we set it to NO until we start processing the queue
144 applyQueueToScan = NO;
146 /* Now we re-check the queue array to see if there are
147 * any remaining encodes to be done in it and ask the
148 * user if they want to reload the queue */
149 if ([QueueFileArray count] > 0)
151 /* run getQueueStats to see whats in the queue file */
152 [self getQueueStats];
153 /* this results in these values
154 * fEncodingQueueItem = 0;
156 * fCompletedCount = 0;
157 * fCanceledCount = 0;
161 /*On Screen Notification*/
162 NSString * alertTitle;
164 /* We check to see if there is already another instance of hb running.
165 * Note: hbInstances == 1 means we are the only instance of HandBrake.app
167 if ([self hbInstances] > 1)
169 alertTitle = [NSString stringWithFormat:
170 NSLocalizedString(@"There is already an instance of HandBrake running.", @"")];
171 NSBeginCriticalAlertSheet(
173 NSLocalizedString(@"Reload Queue", nil),
177 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
178 NSLocalizedString(@" HandBrake will now load up the existing queue.", nil));
182 if (fWorkingCount > 0)
184 alertTitle = [NSString stringWithFormat:
185 NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
186 fWorkingCount,fPendingCount];
190 alertTitle = [NSString stringWithFormat:
191 NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
195 NSBeginCriticalAlertSheet(
197 NSLocalizedString(@"Reload Queue", nil),
199 NSLocalizedString(@"Empty Queue", nil),
201 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
202 NSLocalizedString(@" Do you want to reload them ?", nil));
205 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
206 // right below to either clear the old queue or keep it loaded up.
210 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
211 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
213 [self browseSources:nil];
216 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
218 [self browseSources:(id)fOpenSourceTitleMMenu];
225 /* check to see if another instance of HandBrake.app is running */
226 NSArray *runningAppDictionaries = [[NSWorkspace sharedWorkspace] launchedApplications];
227 NSDictionary *aDictionary;
229 for (aDictionary in runningAppDictionaries)
231 // NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]);
233 if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
241 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
243 if (returnCode == NSAlertOtherReturn)
245 [self clearQueueAllItems];
246 /* We show whichever open source window specified in LaunchSourceBehavior preference key */
247 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source"])
249 [self browseSources:nil];
252 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchSourceBehavior"] isEqualToString: @"Open Source (Title Specific)"])
254 [self browseSources:(id)fOpenSourceTitleMMenu];
259 if ([self hbInstances] == 1)
261 [self setQueueEncodingItemsAsPending];
263 [self showQueueWindow:NULL];
267 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
269 /* if we are in preview full screen mode, we need to go to
270 * windowed mode and release the display before we terminate.
271 * We do it here (instead of applicationWillTerminate) so we
272 * release the displays and can then see the alerts below.
274 if ([fPictureController previewFullScreenMode] == YES)
276 [fPictureController previewGoWindowed:nil];
280 hb_get_state( fQueueEncodeLibhb, &s );
282 if ( s.state != HB_STATE_IDLE )
284 int result = NSRunCriticalAlertPanel(
285 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
286 NSLocalizedString(@"If you quit HandBrake your current encode will be reloaded into your queue at next launch. Do you want to quit anyway?", nil),
287 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
289 if (result == NSAlertDefaultReturn)
291 return NSTerminateNow;
294 return NSTerminateCancel;
297 // Warn if items still in the queue
298 else if ( fPendingCount > 0 )
300 int result = NSRunCriticalAlertPanel(
301 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
302 NSLocalizedString(@"There are pending encodes in your queue. Do you want to quit anyway?",nil),
303 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
305 if ( result == NSAlertDefaultReturn )
306 return NSTerminateNow;
308 return NSTerminateCancel;
311 return NSTerminateNow;
314 - (void)applicationWillTerminate:(NSNotification *)aNotification
317 [browsedSourceDisplayName release];
318 [outputPanel release];
319 [fQueueController release];
320 [fPreviewController release];
321 [fPictureController release];
322 [fApplicationIcon release];
325 hb_close(&fQueueEncodeLibhb);
329 - (void) awakeFromNib
332 [fWindow setExcludedFromWindowsMenu:YES];
333 [fAdvancedOptions setView:fAdvancedView];
335 /* lets setup our presets drawer for drag and drop here */
336 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
337 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
338 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
340 /* Initialize currentScanCount so HB can use it to
341 evaluate successive scans */
342 currentScanCount = 0;
345 /* Init UserPresets .plist */
348 /* Init QueueFile .plist */
349 [self loadQueueFile];
351 fRipIndicatorShown = NO; // initially out of view in the nib
353 /* For 64 bit builds, the threaded animation in the progress
354 * indicators conflicts with the animation in the advanced tab
355 * for reasons not completely clear. jbrjake found a note in the
356 * 10.5 dev notes regarding this possiblility. It was also noted
357 * that unless specified, setUsesThreadedAnimation defaults to true.
358 * So, at least for now we set the indicator animation to NO for
359 * both the scan and regular progress indicators for both 32 and 64 bit
360 * as it test out fine on both and there is no reason our progress indicators
361 * should require their own thread.
364 [fScanIndicator setUsesThreadedAnimation:NO];
365 [fRipIndicator setUsesThreadedAnimation:NO];
369 /* Show/Dont Show Presets drawer upon launch based
370 on user preference DefaultPresetsDrawerShow*/
371 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0 )
373 [fPresetDrawer setDelegate:self];
374 NSSize drawerSize = NSSizeFromString( [[NSUserDefaults standardUserDefaults]
375 stringForKey:@"Drawer Size"] );
376 if( drawerSize.width )
377 [fPresetDrawer setContentSize: drawerSize];
378 [fPresetDrawer open];
381 /* Initially set the dvd angle widgets to hidden (dvdnav only) */
382 [fSrcAngleLabel setHidden:YES];
383 [fSrcAnglePopUp setHidden:YES];
386 NSMenuItem *menuItem;
387 [fDstFormatPopUp removeAllItems];
389 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
390 [menuItem setTag: HB_MUX_MP4];
392 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
393 [menuItem setTag: HB_MUX_MKV];
395 [fDstFormatPopUp selectItemAtIndex: 0];
397 [self formatPopUpChanged:nil];
399 /* We enable the create chapters checkbox here since we are .mp4 */
400 [fCreateChapterMarkers setEnabled: YES];
401 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
403 [fCreateChapterMarkers setState: NSOnState];
409 [fDstFile2Field setStringValue: [NSString stringWithFormat:
410 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
413 [fVidEncoderPopUp removeAllItems];
414 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
419 [fVidTargetSizeField setIntValue: 700];
420 [fVidBitrateField setIntValue: 1000];
422 [fVidQualityMatrix selectCell: fVidBitrateCell];
423 [self videoMatrixChanged:nil];
425 /* Video framerate */
426 [fVidRatePopUp removeAllItems];
427 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
428 for( int i = 0; i < hb_video_rates_count; i++ )
430 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
432 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
433 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
435 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
437 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
438 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
440 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
442 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
443 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
447 [fVidRatePopUp addItemWithTitle:
448 [NSString stringWithCString: hb_video_rates[i].string]];
451 [fVidRatePopUp selectItemAtIndex: 0];
453 /* Set Auto Crop to On at launch */
454 [fPictureController setAutoCrop:YES];
457 [fAudTrack1BitratePopUp removeAllItems];
458 for( int i = 0; i < hb_audio_bitrates_count; i++ )
460 [fAudTrack1BitratePopUp addItemWithTitle:
461 [NSString stringWithCString: hb_audio_bitrates[i].string]];
464 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
466 /* Audio samplerate */
467 [fAudTrack1RatePopUp removeAllItems];
468 for( int i = 0; i < hb_audio_rates_count; i++ )
470 [fAudTrack1RatePopUp addItemWithTitle:
471 [NSString stringWithCString: hb_audio_rates[i].string]];
473 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
476 [fStatusField setStringValue: @""];
481 /* We disable the Turbo 1st pass checkbox since we are not x264 */
482 [fVidTurboPassCheck setEnabled: NO];
483 [fVidTurboPassCheck setState: NSOffState];
486 /* lets get our default prefs here */
487 [self getDefaultPresets:nil];
488 /* lets initialize the current successful scancount here to 0 */
489 currentSuccessfulScanCount = 0;
494 - (void) enableUI: (bool) b
496 NSControl * controls[] =
497 { fSrcTitleField, fSrcTitlePopUp,
498 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
499 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
500 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
501 fDstBrowseButton, fVidRateField, fVidRatePopUp,fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
502 fPictureSizeField,fPictureCroppingField, fVideoFiltersField,fVidQualityMatrix, fSubField, fSubPopUp,
503 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
504 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
505 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
506 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
507 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
508 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
509 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
510 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
511 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
512 fQueueStatus,fPresetsAdd,fPresetsDelete,fSrcAngleLabel,fSrcAnglePopUp,
513 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView,
514 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel};
517 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
519 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
521 NSTextField * tf = (NSTextField *) controls[i];
522 if( ![tf isBezeled] )
524 [tf setTextColor: b ? [NSColor controlTextColor] :
525 [NSColor disabledControlTextColor]];
529 [controls[i] setEnabled: b];
535 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
536 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
537 [self setEnabledStateOfAudioMixdownControls:nil];
538 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
539 [self calculatePictureSizing:nil];
543 [fPresetsOutlineView setEnabled: NO];
547 [self videoMatrixChanged:nil];
548 [fAdvancedOptions enableUI:b];
552 /***********************************************************************
554 ***********************************************************************
555 * Shows a progression bar on the dock icon, filled according to
556 * 'progress' (0.0 <= progress <= 1.0).
557 * Called with progress < 0.0 or progress > 1.0, restores the original
559 **********************************************************************/
560 - (void) UpdateDockIcon: (float) progress
563 NSBitmapImageRep * bmp;
565 uint32_t black = htonl( 0x000000FF );
566 uint32_t red = htonl( 0xFF0000FF );
567 uint32_t white = htonl( 0xFFFFFFFF );
568 int row_start, row_end;
571 if( progress < 0.0 || progress > 1.0 )
573 [NSApp setApplicationIconImage: fApplicationIcon];
577 /* Get it in a raw bitmap form */
578 tiff = [fApplicationIcon TIFFRepresentationUsingCompression:
579 NSTIFFCompressionNone factor: 1.0];
580 bmp = [NSBitmapImageRep imageRepWithData: tiff];
582 /* Draw the progression bar */
583 /* It's pretty simple (ugly?) now, but I'm no designer */
585 row_start = 3 * (int) [bmp size].height / 4;
586 row_end = 7 * (int) [bmp size].height / 8;
588 for( i = row_start; i < row_start + 2; i++ )
590 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
591 for( j = 0; j < (int) [bmp size].width; j++ )
596 for( i = row_start + 2; i < row_end - 2; i++ )
598 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
601 for( j = 2; j < (int) [bmp size].width - 2; j++ )
603 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
615 for( i = row_end - 2; i < row_end; i++ )
617 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
618 for( j = 0; j < (int) [bmp size].width; j++ )
624 /* Now update the dock icon */
625 tiff = [bmp TIFFRepresentationUsingCompression:
626 NSTIFFCompressionNone factor: 1.0];
627 NSImage* icon = [[NSImage alloc] initWithData: tiff];
628 [NSApp setApplicationIconImage: icon];
632 - (void) updateUI: (NSTimer *) timer
635 /* Update UI for fHandle (user scanning instance of libhb ) */
638 list = hb_get_titles( fHandle );
639 /* check to see if there has been a new scan done
640 this bypasses the constraints of HB_STATE_WORKING
641 not allowing setting a newly scanned source */
642 int checkScanCount = hb_get_scancount( fHandle );
643 if( checkScanCount > currentScanCount )
645 currentScanCount = checkScanCount;
646 [fScanIndicator setIndeterminate: NO];
647 [fScanIndicator setDoubleValue: 0.0];
648 [fScanIndicator setHidden: YES];
649 [self showNewScan:nil];
653 hb_get_state( fHandle, &s );
659 #define p s.param.scanning
660 case HB_STATE_SCANNING:
662 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
663 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
664 p.title_cur, p.title_count]];
665 [fScanIndicator setHidden: NO];
666 [fScanIndicator setDoubleValue: 100.0 * ((double)( p.title_cur - 1 ) / p.title_count)];
671 #define p s.param.scandone
672 case HB_STATE_SCANDONE:
674 [fScanIndicator setIndeterminate: NO];
675 [fScanIndicator setDoubleValue: 0.0];
676 [fScanIndicator setHidden: YES];
677 [self writeToActivityLog:"ScanDone state received from fHandle"];
678 [self showNewScan:nil];
679 [[fWindow toolbar] validateVisibleItems];
685 #define p s.param.working
686 case HB_STATE_WORKING:
693 #define p s.param.muxing
694 case HB_STATE_MUXING:
701 case HB_STATE_PAUSED:
704 case HB_STATE_WORKDONE:
711 /* Update UI for fQueueEncodeLibhb */
713 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
714 /* check to see if there has been a new scan done
715 this bypasses the constraints of HB_STATE_WORKING
716 not allowing setting a newly scanned source */
718 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
719 if( checkScanCount > currentScanCount )
721 currentScanCount = checkScanCount;
725 hb_get_state( fQueueEncodeLibhb, &s );
731 #define p s.param.scanning
732 case HB_STATE_SCANNING:
734 [fStatusField setStringValue: [NSString stringWithFormat:
735 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
736 p.title_cur, p.title_count]];
738 /* Set the status string in fQueueController as well */
739 [fQueueController setQueueStatusString: [NSString stringWithFormat:
740 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
741 p.title_cur, p.title_count]];
746 #define p s.param.scandone
747 case HB_STATE_SCANDONE:
749 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
750 [self processNewQueueEncode];
751 [[fWindow toolbar] validateVisibleItems];
757 #define p s.param.working
758 case HB_STATE_WORKING:
760 NSMutableString * string;
761 NSString * pass_desc;
762 /* Update text field */
763 if (p.job_cur == 1 && p.job_count > 1)
765 if ([[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SubtitleList"] && [[[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex]objectForKey:@"SubtitleList"] objectAtIndex:0] objectForKey:@"subtitleSourceTrackNum"] intValue] == 1)
767 pass_desc = @"(subtitle scan)";
779 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d %@ of %d, %.2f %%", @"" ), p.job_cur, pass_desc, p.job_count, 100.0 * p.progress];
783 [string appendFormat:
784 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
785 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
788 [fStatusField setStringValue: string];
789 /* Set the status string in fQueueController as well */
790 [fQueueController setQueueStatusString: string];
792 CGFloat progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
793 [fRipIndicator setIndeterminate: NO];
794 [fRipIndicator setDoubleValue:100.0 * progress_total];
796 // If progress bar hasn't been revealed at the bottom of the window, do
797 // that now. This code used to be in doRip. I moved it to here to handle
798 // the case where hb_start is called by HBQueueController and not from
800 if( !fRipIndicatorShown )
802 NSRect frame = [fWindow frame];
803 if( frame.size.width <= 591 )
804 frame.size.width = 591;
805 frame.size.height += 36;
806 frame.origin.y -= 36;
807 [fWindow setFrame:frame display:YES animate:YES];
808 fRipIndicatorShown = YES;
812 /* Update dock icon */
813 if( dockIconProgress < 100.0 * progress_total )
815 [self UpdateDockIcon: progress_total];
816 dockIconProgress += 5;
823 #define p s.param.muxing
824 case HB_STATE_MUXING:
826 /* Update text field */
827 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
828 /* Set the status string in fQueueController as well */
829 [fQueueController setQueueStatusString: NSLocalizedString( @"Muxing...", @"" )];
831 [fRipIndicator setIndeterminate: YES];
832 [fRipIndicator startAnimation: nil];
834 /* Update dock icon */
835 [self UpdateDockIcon: 1.0];
841 case HB_STATE_PAUSED:
842 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
843 [fQueueController setQueueStatusString: NSLocalizedString( @"Paused", @"" )];
847 case HB_STATE_WORKDONE:
849 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
850 // or someone calling hb_stop. In the latter case, hb_stop does not clear
851 // out the remaining passes/jobs in the queue. We'll do that here.
853 // Delete all remaining jobs of this encode.
854 [fStatusField setStringValue: NSLocalizedString( @"Encode Finished.", @"" )];
855 /* Set the status string in fQueueController as well */
856 [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
857 [fRipIndicator setIndeterminate: NO];
858 [fRipIndicator stopAnimation: nil];
859 [fRipIndicator setDoubleValue: 0.0];
860 [[fWindow toolbar] validateVisibleItems];
862 /* Restore dock icon */
863 [self UpdateDockIcon: -1.0];
864 dockIconProgress = 0;
866 if( fRipIndicatorShown )
868 NSRect frame = [fWindow frame];
869 if( frame.size.width <= 591 )
870 frame.size.width = 591;
871 frame.size.height += -36;
872 frame.origin.y -= -36;
873 [fWindow setFrame:frame display:YES animate:YES];
874 fRipIndicatorShown = NO;
876 /* Since we are done with this encode, tell output to stop writing to the
877 * individual encode log
879 [outputPanel endEncodeLog];
880 /* Check to see if the encode state has not been cancelled
881 to determine if we should check for encode done notifications */
882 if( fEncodeState != 2 )
884 NSString *pathOfFinishedEncode;
885 /* Get the output file name for the finished encode */
886 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
888 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
890 [self showGrowlDoneNotification:pathOfFinishedEncode];
892 [self sendToMetaX:pathOfFinishedEncode];
894 /* since we have successfully completed an encode, we increment the queue counter */
895 [self incrementQueueItemDone:nil];
897 /* all end of queue actions below need to be done after all queue encodes have finished
898 * and there are no pending jobs left to process
900 if (fPendingCount == 0)
902 /* If Alert Window or Window and Growl has been selected */
903 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
904 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
906 /*On Screen Notification*/
909 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
910 [NSApp requestUserAttention:NSCriticalRequest];
913 /* If sleep has been selected */
914 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
917 NSDictionary* errorDict;
918 NSAppleEventDescriptor* returnDescriptor = nil;
919 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
920 @"tell application \"Finder\" to sleep"];
921 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
922 [scriptObject release];
924 /* If Shutdown has been selected */
925 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
928 NSDictionary* errorDict;
929 NSAppleEventDescriptor* returnDescriptor = nil;
930 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
931 @"tell application \"Finder\" to shut down"];
932 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
933 [scriptObject release];
947 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
948 - (void) writeToActivityLog:(const char *) format, ...
951 va_start(args, format);
955 vsnprintf( str, 1024, format, args );
957 time_t _now = time( NULL );
958 struct tm * now = localtime( &_now );
959 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
966 // ============================================================
967 // NSToolbar Related Methods
968 // ============================================================
970 - (void) setupToolbar {
971 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
973 [toolbar setAllowsUserCustomization: YES];
974 [toolbar setAutosavesConfiguration: YES];
975 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
977 [toolbar setDelegate: self];
979 [fWindow setToolbar: toolbar];
982 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
983 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
984 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
986 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
988 [item setLabel: @"Toggle Presets"];
989 [item setPaletteLabel: @"Toggler Presets"];
990 [item setToolTip: @"Open/Close Preset Drawer"];
991 [item setImage: [NSImage imageNamed: @"Drawer"]];
992 [item setTarget: self];
993 [item setAction: @selector(toggleDrawer:)];
994 [item setAutovalidates: NO];
996 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
998 [item setLabel: @"Start"];
999 [item setPaletteLabel: @"Start Encoding"];
1000 [item setToolTip: @"Start Encoding"];
1001 [item setImage: [NSImage imageNamed: @"Play"]];
1002 [item setTarget: self];
1003 [item setAction: @selector(Rip:)];
1005 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
1007 [item setLabel: @"Show Queue"];
1008 [item setPaletteLabel: @"Show Queue"];
1009 [item setToolTip: @"Show Queue"];
1010 [item setImage: [NSImage imageNamed: @"Queue"]];
1011 [item setTarget: self];
1012 [item setAction: @selector(showQueueWindow:)];
1013 [item setAutovalidates: NO];
1015 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
1017 [item setLabel: @"Add to Queue"];
1018 [item setPaletteLabel: @"Add to Queue"];
1019 [item setToolTip: @"Add to Queue"];
1020 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
1021 [item setTarget: self];
1022 [item setAction: @selector(addToQueue:)];
1024 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
1026 [item setLabel: @"Pause"];
1027 [item setPaletteLabel: @"Pause Encoding"];
1028 [item setToolTip: @"Pause Encoding"];
1029 [item setImage: [NSImage imageNamed: @"Pause"]];
1030 [item setTarget: self];
1031 [item setAction: @selector(Pause:)];
1033 else if ([itemIdent isEqualToString: ShowPictureIdentifier])
1035 [item setLabel: @"Picture Settings"];
1036 [item setPaletteLabel: @"Show Picture Settings"];
1037 [item setToolTip: @"Show Picture Settings"];
1038 [item setImage: [NSImage imageNamed: @"pref-picture"]];
1039 [item setTarget: self];
1040 [item setAction: @selector(showPicturePanel:)];
1042 else if ([itemIdent isEqualToString: ShowPreviewIdentifier])
1044 [item setLabel: @"Preview Window"];
1045 [item setPaletteLabel: @"Show Preview"];
1046 [item setToolTip: @"Show Preview"];
1047 //[item setImage: [NSImage imageNamed: @"pref-picture"]];
1048 [item setImage: [NSImage imageNamed: @"Brushed_Window"]];
1049 [item setTarget: self];
1050 [item setAction: @selector(showPreviewWindow:)];
1052 else if ([itemIdent isEqualToString: ShowActivityIdentifier])
1054 [item setLabel: @"Activity Window"];
1055 [item setPaletteLabel: @"Show Activity Window"];
1056 [item setToolTip: @"Show Activity Window"];
1057 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
1058 [item setTarget: self];
1059 [item setAction: @selector(showDebugOutputPanel:)];
1060 [item setAutovalidates: NO];
1062 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
1064 [item setLabel: @"Source"];
1065 [item setPaletteLabel: @"Source"];
1066 [item setToolTip: @"Choose Video Source"];
1067 [item setImage: [NSImage imageNamed: @"Source"]];
1068 [item setTarget: self];
1069 [item setAction: @selector(browseSources:)];
1079 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
1081 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
1082 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1083 NSToolbarSpaceItemIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
1086 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
1088 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
1089 ChooseSourceIdentifier, ShowQueueIdentifier, ShowPictureIdentifier, ShowPreviewIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
1090 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
1091 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
1094 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
1096 NSString * ident = [toolbarItem itemIdentifier];
1101 hb_get_state2( fQueueEncodeLibhb, &s );
1103 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
1105 if ([ident isEqualToString: StartEncodingIdentifier])
1107 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
1108 [toolbarItem setLabel: @"Stop"];
1109 [toolbarItem setPaletteLabel: @"Stop"];
1110 [toolbarItem setToolTip: @"Stop Encoding"];
1113 if ([ident isEqualToString: PauseEncodingIdentifier])
1115 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
1116 [toolbarItem setLabel: @"Pause"];
1117 [toolbarItem setPaletteLabel: @"Pause Encoding"];
1118 [toolbarItem setToolTip: @"Pause Encoding"];
1123 if ([ident isEqualToString: AddToQueueIdentifier])
1125 if ([ident isEqualToString: ShowPictureIdentifier])
1127 if ([ident isEqualToString: ShowPreviewIdentifier])
1131 else if (s.state == HB_STATE_PAUSED)
1133 if ([ident isEqualToString: PauseEncodingIdentifier])
1135 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1136 [toolbarItem setLabel: @"Resume"];
1137 [toolbarItem setPaletteLabel: @"Resume Encoding"];
1138 [toolbarItem setToolTip: @"Resume Encoding"];
1141 if ([ident isEqualToString: StartEncodingIdentifier])
1143 if ([ident isEqualToString: AddToQueueIdentifier])
1145 if ([ident isEqualToString: ShowPictureIdentifier])
1147 if ([ident isEqualToString: ShowPreviewIdentifier])
1150 else if (s.state == HB_STATE_SCANNING)
1152 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
1154 if ([ident isEqualToString: StartEncodingIdentifier])
1156 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1157 if (hb_count(fHandle) > 0)
1158 [toolbarItem setLabel: @"Start Queue"];
1160 [toolbarItem setLabel: @"Start"];
1161 [toolbarItem setPaletteLabel: @"Start Encoding"];
1162 [toolbarItem setToolTip: @"Start Encoding"];
1165 if ([ident isEqualToString: AddToQueueIdentifier])
1167 if ([ident isEqualToString: ShowPictureIdentifier])
1169 if ([ident isEqualToString: ShowPreviewIdentifier])
1174 /* If there are any pending queue items, make sure the start/stop button is active */
1175 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1177 if ([ident isEqualToString: ShowQueueIdentifier])
1179 if ([ident isEqualToString: ToggleDrawerIdentifier])
1181 if ([ident isEqualToString: ChooseSourceIdentifier])
1183 if ([ident isEqualToString: ShowActivityIdentifier])
1189 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1191 SEL action = [menuItem action];
1194 hb_get_state2( fHandle, &s );
1198 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1199 return SuccessfulScan && [fWindow attachedSheet] == nil;
1201 if (action == @selector(browseSources:))
1203 if (s.state == HB_STATE_SCANNING)
1206 return [fWindow attachedSheet] == nil;
1208 if (action == @selector(selectDefaultPreset:))
1209 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1210 if (action == @selector(Pause:))
1212 if (s.state == HB_STATE_WORKING)
1214 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1215 [menuItem setTitle:@"Pause Encoding"];
1218 else if (s.state == HB_STATE_PAUSED)
1220 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1221 [menuItem setTitle:@"Resume Encoding"];
1227 if (action == @selector(Rip:))
1229 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1231 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1232 [menuItem setTitle:@"Stop Encoding"];
1235 else if (SuccessfulScan)
1237 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1238 [menuItem setTitle:@"Start Encoding"];
1239 return [fWindow attachedSheet] == nil;
1245 if( action == @selector(setDefaultPreset:) )
1247 return [fPresetsOutlineView selectedRow] != -1;
1254 #pragma mark Encode Done Actions
1255 // register a test notification and make
1256 // it enabled by default
1257 #define SERVICE_NAME @"Encode Done"
1258 - (NSDictionary *)registrationDictionaryForGrowl
1260 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1261 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1262 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1265 return registrationDictionary;
1268 -(void)showGrowlDoneNotification:(NSString *) filePath
1270 /* This end of encode action is called as each encode rolls off of the queue */
1271 NSString * finishedEncode = filePath;
1272 /* strip off the path to just show the file name */
1273 finishedEncode = [finishedEncode lastPathComponent];
1274 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1275 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1277 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1278 [GrowlApplicationBridge
1279 notifyWithTitle:@"Put down that cocktail..."
1280 description:growlMssg
1281 notificationName:SERVICE_NAME
1289 -(void)sendToMetaX:(NSString *) filePath
1291 /* This end of encode action is called as each encode rolls off of the queue */
1292 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1294 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1295 [myScript executeAndReturnError: nil];
1300 #pragma mark Get New Source
1302 /*Opens the source browse window, called from Open Source widgets */
1303 - (IBAction) browseSources: (id) sender
1305 NSOpenPanel * panel;
1307 panel = [NSOpenPanel openPanel];
1308 [panel setAllowsMultipleSelection: NO];
1309 [panel setCanChooseFiles: YES];
1310 [panel setCanChooseDirectories: YES ];
1311 NSString * sourceDirectory;
1312 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1314 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1318 sourceDirectory = @"~/Desktop";
1319 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1321 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1322 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1324 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1325 modalForWindow: fWindow modalDelegate: self
1326 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1327 contextInfo: sender];
1330 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1331 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1333 /* we convert the sender content of contextInfo back into a variable called sender
1334 * mostly just for consistency for evaluation later
1336 id sender = (id)contextInfo;
1337 /* User selected a file to open */
1338 if( returnCode == NSOKButton )
1340 /* Free display name allocated previously by this code */
1341 [browsedSourceDisplayName release];
1343 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1344 /* we set the last searched source directory in the prefs here */
1345 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1346 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1347 /* we order out sheet, which is the browse window as we need to open
1348 * the title selection sheet right away
1350 [sheet orderOut: self];
1352 if (sender == fOpenSourceTitleMMenu)
1354 /* We put the chosen source path in the source display text field for the
1355 * source title selection sheet in which the user specifies the specific title to be
1356 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1357 * purposes in the title panel
1360 [fScanSrcTitlePathField setStringValue:scanPath];
1361 NSString *displayTitlescanSourceName;
1363 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1365 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1366 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1367 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1371 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1372 displayTitlescanSourceName = [scanPath lastPathComponent];
1374 /* we set the source display name in the title selection dialogue */
1375 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1376 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1377 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1378 /* We show the actual sheet where the user specifies the title to be scanned
1379 * as we are going to do a title specific scan
1381 [self showSourceTitleScanPanel:nil];
1385 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1386 NSString *path = [[sheet filenames] objectAtIndex: 0];
1388 /* We check to see if the chosen file at path is a package */
1389 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1391 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1392 /* We check to see if this is an .eyetv package */
1393 if ([[path pathExtension] isEqualToString: @"eyetv"])
1395 [self writeToActivityLog:"trying to open eyetv package"];
1396 /* We're looking at an EyeTV package - try to open its enclosed
1398 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1400 int n = [[path stringByAppendingString: @"/"]
1401 completePathIntoString: &mpgname caseSensitive: NO
1402 matchesIntoArray: nil
1403 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1406 /* Found an mpeg inside the eyetv package, make it our scan path
1407 and call performScan on the enclosed mpeg */
1409 [self writeToActivityLog:"found mpeg in eyetv package"];
1410 [self performScan:path scanTitleNum:0];
1414 /* We did not find an mpeg file in our package, so we do not call performScan */
1415 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1418 /* We check to see if this is a .dvdmedia package */
1419 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1421 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1422 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1423 [self writeToActivityLog:"trying to open dvdmedia package"];
1424 [self performScan:path scanTitleNum:0];
1428 /* The package is not an eyetv package, so we do not call performScan */
1429 [self writeToActivityLog:"unable to open package"];
1432 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1434 /* path is not a package, so we call perform scan directly on our file */
1435 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1437 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1438 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1439 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1443 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1444 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1445 /* make sure we remove any path extension as this can also be an '.mpg' file */
1446 browsedSourceDisplayName = [[path lastPathComponent] retain];
1448 [self performScan:path scanTitleNum:0];
1456 - (IBAction)showAboutPanel:(id)sender
1458 NSMutableDictionary* d = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
1459 fApplicationIcon, @"ApplicationIcon",
1461 [NSApp orderFrontStandardAboutPanelWithOptions:d];
1465 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1466 - (IBAction) showSourceTitleScanPanel: (id) sender
1468 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1471 [fScanSrcTitleNumField setStringValue: @"0"];
1472 /* Show the panel */
1473 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1476 - (IBAction) closeSourceTitleScanPanel: (id) sender
1478 [NSApp endSheet: fScanSrcTitlePanel];
1479 [fScanSrcTitlePanel orderOut: self];
1481 if(sender == fScanSrcTitleOpenButton)
1483 /* We setup the scan status in the main window to indicate a source title scan */
1484 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1485 [fScanIndicator setHidden: NO];
1486 [fScanIndicator setIndeterminate: YES];
1487 [fScanIndicator startAnimation: nil];
1489 /* We use the performScan method to actually perform the specified scan passing the path and the title
1492 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1496 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1497 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1499 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1500 applyQueueToScan = NO;
1501 /* use a bool to determine whether or not we can decrypt using vlc */
1502 BOOL cancelScanDecrypt = 0;
1503 NSString *path = scanPath;
1504 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1506 // Notify ChapterTitles that there's no title
1507 [fChapterTitlesDelegate resetWithTitle:nil];
1508 [fChapterTable reloadData];
1510 // Notify Subtitles that there's no title
1511 [fSubtitlesDelegate resetWithTitle:nil];
1512 [fSubtitlesTable reloadData];
1514 [self enableUI: NO];
1516 if( [detector isVideoDVD] )
1518 // The chosen path was actually on a DVD, so use the raw block
1519 // device path instead.
1520 path = [detector devicePath];
1521 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1523 #if defined( __LP64__ )
1524 /* If we are 64 bit, we cannot read encrypted dvd's as vlc is 32 bit only */
1525 cancelScanDecrypt = 1;
1526 [self writeToActivityLog: "64 bit mode cannot read dvd's, scan cancelled"];
1527 /*On Screen Notification*/
1530 status = NSRunAlertPanel(@"64-bit HandBrake cannot read encrypted dvds!",@"", @"Cancel Scan", @"Attempt Scan Anyway", nil);
1531 [NSApp requestUserAttention:NSCriticalRequest];
1533 if (status == NSAlertDefaultReturn)
1535 /* User chose to cancel the scan */
1536 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1537 cancelScanDecrypt = 1;
1541 [self writeToActivityLog: "user overrode 64-bit warning trying to open physical dvd without decryption"];
1542 cancelScanDecrypt = 0;
1546 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1547 NSString *vlcPath = @"/Applications/VLC.app/Contents/MacOS/lib/libdvdcss.2.dylib";
1548 NSFileManager * fileManager = [NSFileManager defaultManager];
1549 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1551 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1552 cancelScanDecrypt = 1;
1553 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1555 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");
1556 [NSApp requestUserAttention:NSCriticalRequest];
1558 if (status == NSAlertDefaultReturn)
1560 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1561 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1563 else if (status == NSAlertAlternateReturn)
1565 /* User chose to cancel the scan */
1566 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1570 /* 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 */
1571 cancelScanDecrypt = 0;
1572 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1578 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1579 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1584 if (cancelScanDecrypt == 0)
1586 /* we actually pass the scan off to libhb here */
1587 /* If there is no title number passed to scan, we use "0"
1588 * which causes the default behavior of a full source scan
1594 if (scanTitleNum > 0)
1596 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1598 /* We use our advance pref to determine how many previews to scan */
1599 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
1600 /* set title to NULL */
1602 hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
1603 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1607 - (IBAction) showNewScan:(id)sender
1611 int indxpri=0; // Used to search the longuest title (default in combobox)
1612 int longuestpri=0; // Used to search the longuest title (default in combobox)
1615 list = hb_get_titles( fHandle );
1617 if( !hb_list_count( list ) )
1619 /* We display a message if a valid dvd source was not chosen */
1620 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1621 SuccessfulScan = NO;
1623 // Notify ChapterTitles that there's no title
1624 [fSubtitlesDelegate resetWithTitle:nil];
1625 [fSubtitlesTable reloadData];
1627 // Notify Subtitles that there's no title
1628 [fChapterTitlesDelegate resetWithTitle:nil];
1629 [fChapterTable reloadData];
1633 /* We increment the successful scancount here by one,
1634 which we use at the end of this function to tell the gui
1635 if this is the first successful scan since launch and whether
1636 or not we should set all settings to the defaults */
1638 currentSuccessfulScanCount++;
1640 [[fWindow toolbar] validateVisibleItems];
1642 [fSrcTitlePopUp removeAllItems];
1643 for( int i = 0; i < hb_list_count( list ); i++ )
1645 title = (hb_title_t *) hb_list_item( list, i );
1647 currentSource = [NSString stringWithUTF8String: title->name];
1648 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1649 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1651 /* Use the dvd name in the default output field here
1652 May want to add code to remove blank spaces for some dvd names*/
1653 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1654 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1656 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1657 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1661 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1662 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1666 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1668 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1672 [fSrcTitlePopUp addItemWithTitle: [NSString
1673 stringWithFormat: @"%d - %02dh%02dm%02ds",
1674 title->index, title->hours, title->minutes,
1678 // Select the longuest title
1679 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1680 [self titlePopUpChanged:nil];
1682 SuccessfulScan = YES;
1683 [self enableUI: YES];
1685 /* if its the initial successful scan after awakeFromNib */
1686 if (currentSuccessfulScanCount == 1)
1688 [self selectDefaultPreset:nil];
1690 // Open preview window now if it was visible when HB was closed
1691 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PreviewWindowIsOpen"])
1692 [self showPreviewWindow:nil];
1694 // Open picture sizing window now if it was visible when HB was closed
1695 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PictureSizeWindowIsOpen"])
1696 [self showPicturePanel:nil];
1707 #pragma mark New Output Destination
1709 - (IBAction) browseFile: (id) sender
1711 /* Open a panel to let the user choose and update the text field */
1712 NSSavePanel * panel = [NSSavePanel savePanel];
1713 /* We get the current file name and path from the destination field here */
1714 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1715 modalForWindow: fWindow modalDelegate: self
1716 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1720 - (void) browseFileDone: (NSSavePanel *) sheet
1721 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1723 if( returnCode == NSOKButton )
1725 [fDstFile2Field setStringValue: [sheet filename]];
1726 /* Save this path to the prefs so that on next browse destination window it opens there */
1727 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1728 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1734 #pragma mark Main Window Control
1736 - (IBAction) openMainWindow: (id) sender
1738 [fWindow makeKeyAndOrderFront:nil];
1741 - (BOOL) windowShouldClose: (id) sender
1746 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1749 [fWindow makeKeyAndOrderFront:nil];
1757 - (NSSize) drawerWillResizeContents:(NSDrawer *) drawer toSize:(NSSize) contentSize {
1758 [[NSUserDefaults standardUserDefaults] setObject:NSStringFromSize( contentSize ) forKey:@"Drawer Size"];
1763 #pragma mark Queue File
1765 - (void) loadQueueFile {
1766 /* We declare the default NSFileManager into fileManager */
1767 NSFileManager * fileManager = [NSFileManager defaultManager];
1768 /*We define the location of the user presets file */
1769 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1770 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1771 /* We check for the presets.plist */
1772 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1774 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1777 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1778 /* lets check to see if there is anything in the queue file .plist */
1779 if (nil == QueueFileArray)
1781 /* if not, then lets initialize an empty array */
1782 QueueFileArray = [[NSMutableArray alloc] init];
1784 /* Initialize our curQueueEncodeIndex to 0
1785 * so we can use it to track which queue
1786 * item is to be used to track our encodes */
1787 /* NOTE: this should be changed if and when we
1788 * are able to get the last unfinished encode
1789 * in the case of a crash or shutdown */
1794 [self clearQueueEncodedItems];
1796 currentQueueEncodeIndex = 0;
1799 - (void)addQueueFileItem
1801 [QueueFileArray addObject:[self createQueueFileItem]];
1802 [self saveQueueFileItem];
1806 - (void) removeQueueFileItem:(int) queueItemToRemove
1809 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1810 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1812 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1813 * by one to keep in sync with the queue array
1815 currentQueueEncodeIndex--;
1816 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1818 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1819 [self saveQueueFileItem];
1823 - (void)saveQueueFileItem
1825 [QueueFileArray writeToFile:QueueFile atomically:YES];
1826 [fQueueController setQueueArray: QueueFileArray];
1827 [self getQueueStats];
1830 - (void)getQueueStats
1832 /* lets get the stats on the status of the queue array */
1834 fEncodingQueueItem = 0;
1836 fCompletedCount = 0;
1840 /* We use a number system to set the encode status of the queue item
1842 * 0 == already encoded
1843 * 1 == is being encoded
1844 * 2 == is yet to be encoded
1849 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1851 while (tempObject = [enumerator nextObject])
1853 NSDictionary *thisQueueDict = tempObject;
1854 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1858 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1861 fEncodingQueueItem = i;
1863 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1867 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1874 /* Set the queue status field in the main window */
1875 NSMutableString * string;
1876 if (fPendingCount == 1)
1878 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1882 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1884 [fQueueStatus setStringValue:string];
1887 /* This method will set any item marked as encoding back to pending
1888 * currently used right after a queue reload
1890 - (void) setQueueEncodingItemsAsPending
1892 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1894 NSMutableArray *tempArray;
1895 tempArray = [NSMutableArray array];
1896 /* we look here to see if the preset is we move on to the next one */
1897 while ( tempObject = [enumerator nextObject] )
1899 /* If the queue item is marked as "encoding" (1)
1900 * then change its status back to pending (2) which effectively
1901 * puts it back into the queue to be encoded
1903 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
1905 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
1907 [tempArray addObject:tempObject];
1910 [QueueFileArray setArray:tempArray];
1911 [self saveQueueFileItem];
1915 /* This method will clear the queue of any encodes that are not still pending
1916 * this includes both successfully completed encodes as well as cancelled encodes */
1917 - (void) clearQueueEncodedItems
1919 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1921 NSMutableArray *tempArray;
1922 tempArray = [NSMutableArray array];
1923 /* we look here to see if the preset is we move on to the next one */
1924 while ( tempObject = [enumerator nextObject] )
1926 /* If the queue item is either completed (0) or cancelled (3) from the
1927 * last session, then we put it in tempArray to be deleted from QueueFileArray.
1928 * NOTE: this means we retain pending (2) and also an item that is marked as
1929 * still encoding (1). If the queue has an item that is still marked as encoding
1930 * from a previous session, we can conlude that HB was either shutdown, or crashed
1931 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
1933 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
1935 [tempArray addObject:tempObject];
1939 [QueueFileArray removeObjectsInArray:tempArray];
1940 [self saveQueueFileItem];
1943 /* This method will clear the queue of all encodes. effectively creating an empty queue */
1944 - (void) clearQueueAllItems
1946 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1948 NSMutableArray *tempArray;
1949 tempArray = [NSMutableArray array];
1950 /* we look here to see if the preset is we move on to the next one */
1951 while ( tempObject = [enumerator nextObject] )
1953 [tempArray addObject:tempObject];
1956 [QueueFileArray removeObjectsInArray:tempArray];
1957 [self saveQueueFileItem];
1960 /* This method will duplicate prepareJob however into the
1961 * queue .plist instead of into the job structure so it can
1962 * be recalled later */
1963 - (NSDictionary *)createQueueFileItem
1965 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1967 hb_list_t * list = hb_get_titles( fHandle );
1968 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1969 [fSrcTitlePopUp indexOfSelectedItem] );
1970 hb_job_t * job = title->job;
1974 /* We use a number system to set the encode status of the queue item
1975 * 0 == already encoded
1976 * 1 == is being encoded
1977 * 2 == is yet to be encoded
1980 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1981 /* Source and Destination Information */
1983 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1984 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1985 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1986 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcAnglePopUp indexOfSelectedItem] + 1] forKey:@"TitleAngle"];
1987 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1989 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1991 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1993 /* Lets get the preset info if there is any */
1994 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1995 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1997 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1998 /* Chapter Markers*/
1999 /* If we have only one chapter or a title without chapters, set chapter markers to off */
2000 if ([fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem])
2002 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
2006 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
2009 /* We need to get the list of chapter names to put into an array and store
2010 * in our queue, so they can be reapplied in prepareJob when this queue
2011 * item comes up if Chapter Markers is set to on.
2014 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
2015 int chaptercount = hb_list_count( fTitle->list_chapter );
2016 for( i = 0; i < chaptercount; i++ )
2018 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
2019 if( chapter != NULL )
2021 [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
2024 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
2025 [ChapterNamesArray autorelease];
2027 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2028 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
2029 /* Mux mp4 with http optimization */
2030 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
2031 /* Add iPod uuid atom */
2032 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
2036 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2037 /* x264 Option String */
2038 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2040 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2041 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2042 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2043 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
2045 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2047 /* 2 Pass Encoding */
2048 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2049 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2050 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2052 /* Picture Sizing */
2053 /* Use Max Picture settings for whatever the dvd is.*/
2054 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2055 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2056 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2057 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2058 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2059 /* if we are custom anamorphic, store the exact storage, par and display dims */
2060 if (fTitle->job->anamorphic.mode == 3)
2062 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
2063 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
2065 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_width] forKey:@"PicturePARPixelWidth"];
2066 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_height] forKey:@"PicturePARPixelHeight"];
2068 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_width] forKey:@"PicturePARDisplayWidth"];
2069 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_height] forKey:@"PicturePARDisplayHeight"];
2072 NSString * pictureSummary;
2073 pictureSummary = [fPictureSizeField stringValue];
2074 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
2075 /* Set crop settings here */
2076 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2077 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2078 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2079 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2080 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2082 /* Picture Filters */
2083 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2084 [queueFileJob setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
2086 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
2087 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
2088 [queueFileJob setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
2090 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2091 [queueFileJob setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
2093 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2094 [queueFileJob setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
2096 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
2098 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
2101 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2103 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
2104 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
2105 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
2106 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
2107 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
2108 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
2109 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
2111 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2113 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
2114 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
2115 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
2116 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
2117 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
2118 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
2119 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
2121 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2123 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
2124 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
2125 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
2126 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
2127 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
2128 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
2129 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
2131 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2133 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
2134 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
2135 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
2136 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
2137 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
2138 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
2139 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
2143 NSMutableArray *subtitlesArray = [[NSMutableArray alloc] init];
2144 [queueFileJob setObject:[NSArray arrayWithArray: [fSubtitlesDelegate getSubtitleArray: subtitlesArray]] forKey:@"SubtitleList"];
2145 [subtitlesArray autorelease];
2147 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
2149 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
2151 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
2154 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
2158 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
2161 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
2162 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
2163 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
2165 /* Picture Sizing */
2166 /* Use Max Picture settings for whatever the dvd is.*/
2167 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2168 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2169 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2170 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2171 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2173 /* Set crop settings here */
2174 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2175 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2176 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2177 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2178 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2182 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2184 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
2185 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
2186 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
2187 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
2188 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
2190 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2192 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
2193 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
2194 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
2195 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
2196 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
2198 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2200 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
2201 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
2202 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
2203 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
2204 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
2206 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2208 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
2209 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
2210 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
2211 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
2212 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
2216 /* we need to auto relase the queueFileJob and return it */
2217 [queueFileJob autorelease];
2218 return queueFileJob;
2222 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
2223 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
2225 NSUInteger index = [indexSet lastIndex];
2226 NSUInteger aboveInsertIndexCount = 0;
2229 NSUInteger removeIndex;
2231 if (index >= insertIndex)
2233 removeIndex = index + aboveInsertIndexCount;
2234 aboveInsertIndexCount++;
2238 removeIndex = index;
2242 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2243 [QueueFileArray removeObjectAtIndex:removeIndex];
2244 [QueueFileArray insertObject:object atIndex:insertIndex];
2247 index = [indexSet indexLessThanIndex:index];
2249 /* We save all of the Queue data here
2250 * and it also gets sent back to the queue controller*/
2251 [self saveQueueFileItem];
2257 #pragma mark Queue Job Processing
2259 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2261 int i = currentQueueEncodeIndex;
2262 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2264 /* We save all of the Queue data here */
2265 [self saveQueueFileItem];
2266 /* We Reload the New Table data for presets */
2267 //[fPresetsOutlineView reloadData];
2269 /* Since we have now marked a queue item as done
2270 * we can go ahead and increment currentQueueEncodeIndex
2271 * so that if there is anything left in the queue we can
2272 * go ahead and move to the next item if we want to */
2273 currentQueueEncodeIndex++ ;
2274 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2275 int queueItems = [QueueFileArray count];
2276 /* If we still have more items in our queue, lets go to the next one */
2277 if (currentQueueEncodeIndex < queueItems)
2279 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2280 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2284 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2288 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2289 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2291 /* Tell HB to output a new activity log file for this encode */
2292 [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
2295 /* use a bool to determine whether or not we can decrypt using vlc */
2296 BOOL cancelScanDecrypt = 0;
2297 /* set the bool so that showNewScan knows to apply the appropriate queue
2298 * settings as this is a queue rescan
2300 applyQueueToScan = YES;
2301 NSString *path = scanPath;
2302 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2304 /*On Screen Notification*/
2306 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2307 //[NSApp requestUserAttention:NSCriticalRequest];
2309 if( [detector isVideoDVD] )
2311 // The chosen path was actually on a DVD, so use the raw block
2312 // device path instead.
2313 path = [detector devicePath];
2314 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2316 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2317 NSString *vlcPath = @"/Applications/VLC.app";
2318 NSFileManager * fileManager = [NSFileManager defaultManager];
2319 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2321 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2322 cancelScanDecrypt = 1;
2323 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2325 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");
2326 [NSApp requestUserAttention:NSCriticalRequest];
2328 if (status == NSAlertDefaultReturn)
2330 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2331 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2333 else if (status == NSAlertAlternateReturn)
2335 /* User chose to cancel the scan */
2336 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2340 /* 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 */
2341 cancelScanDecrypt = 0;
2342 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2348 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2349 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2353 if (cancelScanDecrypt == 0)
2355 /* we actually pass the scan off to libhb here */
2356 /* If there is no title number passed to scan, we use "0"
2357 * which causes the default behavior of a full source scan
2363 if (scanTitleNum > 0)
2365 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2368 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2369 /* We use our advance pref to determine how many previews to scan */
2370 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
2371 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
2375 /* This method was originally used to load up a new queue item in the gui and
2376 * then start processing it. However we now have modified -prepareJob and use a second
2377 * instance of libhb to do our actual encoding, therefor right now it is not required.
2378 * Nonetheless I want to leave this in here
2379 * because basically its everything we need to be able to actually modify a pending queue
2380 * item in the gui and resave it. At least for now - dynaflash
2383 - (IBAction)applyQueueSettings:(id)sender
2385 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2386 hb_job_t * job = fTitle->job;
2388 /* Set title number and chapters */
2389 /* since the queue only scans a single title, we really don't need to pick a title */
2390 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2392 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2393 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2396 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2397 [self formatPopUpChanged:nil];
2399 /* Chapter Markers*/
2400 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2401 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2402 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2403 /* Mux mp4 with http optimization */
2404 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2407 /* We set the advanced opt string here if applicable*/
2408 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2409 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2411 /* Lets run through the following functions to get variables set there */
2412 [self videoEncoderPopUpChanged:nil];
2413 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2414 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2415 [self calculateBitrate:nil];
2418 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2420 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2421 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2422 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2424 [self videoMatrixChanged:nil];
2426 /* Video framerate */
2427 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2428 detected framerate in the fVidRatePopUp so we use index 0*/
2429 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2431 [fVidRatePopUp selectItemAtIndex: 0];
2435 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2438 /* 2 Pass Encoding */
2439 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2440 [self twoPassCheckboxChanged:nil];
2441 /* Turbo 1st pass for 2 Pass Encoding */
2442 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2445 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2447 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2449 [fAudLang1PopUp selectItemAtIndex: 1];
2451 [self audioTrackPopUpChanged: fAudLang1PopUp];
2452 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2453 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2454 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2455 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2457 if ([fAudTrack1MixPopUp selectedItem] == nil)
2459 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2461 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2462 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2463 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2465 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2467 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2468 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2470 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2472 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2474 [fAudLang2PopUp selectItemAtIndex: 1];
2476 [self audioTrackPopUpChanged: fAudLang2PopUp];
2477 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2478 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2479 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2480 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2482 if ([fAudTrack2MixPopUp selectedItem] == nil)
2484 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2486 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2487 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2488 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2490 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2492 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2493 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2495 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2497 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2499 [fAudLang3PopUp selectItemAtIndex: 1];
2501 [self audioTrackPopUpChanged: fAudLang3PopUp];
2502 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2503 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2504 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2505 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2507 if ([fAudTrack3MixPopUp selectedItem] == nil)
2509 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2511 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2512 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2513 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2515 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2517 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2518 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2520 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2522 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2524 [fAudLang4PopUp selectItemAtIndex: 1];
2526 [self audioTrackPopUpChanged: fAudLang4PopUp];
2527 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2528 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2529 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2530 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2532 if ([fAudTrack4MixPopUp selectedItem] == nil)
2534 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2536 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2537 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2538 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2540 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2542 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2543 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2548 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2549 /* Forced Subtitles */
2550 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2552 /* Picture Settings */
2553 /* we check to make sure the presets width/height does not exceed the sources width/height */
2554 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2556 /* if so, then we use the sources height and width to avoid scaling up */
2557 job->width = fTitle->width;
2558 job->height = fTitle->height;
2560 else // source width/height is >= the preset height/width
2562 /* we can go ahead and use the presets values for height and width */
2563 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2564 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2566 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2567 if (job->keep_ratio == 1)
2569 hb_fix_aspect( job, HB_KEEP_WIDTH );
2570 if( job->height > fTitle->height )
2572 job->height = fTitle->height;
2573 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2576 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2579 /* If Cropping is set to custom, then recall all four crop values from
2580 when the preset was created and apply them */
2581 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2583 [fPictureController setAutoCrop:NO];
2585 /* Here we use the custom crop values saved at the time the preset was saved */
2586 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2587 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2588 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2589 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2592 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2594 [fPictureController setAutoCrop:YES];
2595 /* Here we use the auto crop values determined right after scan */
2596 job->crop[0] = AutoCropTop;
2597 job->crop[1] = AutoCropBottom;
2598 job->crop[2] = AutoCropLeft;
2599 job->crop[3] = AutoCropRight;
2605 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2608 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2610 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2612 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2614 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2616 [fPictureController setGrayscale:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2618 [self calculatePictureSizing:nil];
2621 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2622 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2623 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2624 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2626 /* Deselect the currently selected Preset if there is one*/
2627 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2628 //[self selectPreset:nil];
2630 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2631 /* Change UI to show "Custom" settings are being used */
2632 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2634 curUserPresetChosenNum = nil;
2638 /* Deselect the currently selected Preset if there is one*/
2639 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2640 /* Change UI to show "Custom" settings are being used */
2641 [fPresetSelectedDisplay setStringValue: @"Custom"];
2643 //curUserPresetChosenNum = nil;
2646 /* We need to set this bool back to NO, in case the user wants to do a scan */
2647 //applyQueueToScan = NO;
2649 /* so now we go ahead and process the new settings */
2650 [self processNewQueueEncode];
2655 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2656 - (void) processNewQueueEncode
2658 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2659 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2660 hb_job_t * job = title->job;
2662 if( !hb_list_count( list ) )
2664 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2667 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2668 [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
2669 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2670 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2671 //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2675 * If scanning we need to do some extra setup of the job.
2677 if( job->indepth_scan == 1 )
2682 * When subtitle scan is enabled do a fast pre-scan job
2683 * which will determine which subtitles to enable, if any.
2686 x264opts_tmp = job->x264opts;
2688 job->x264opts = NULL;
2690 job->indepth_scan = 1;
2694 * Add the pre-scan job
2696 hb_add( fQueueEncodeLibhb, job );
2697 job->x264opts = x264opts_tmp;
2701 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2703 job->indepth_scan = 0;
2709 hb_add( fQueueEncodeLibhb, job );
2713 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2714 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2716 hb_add( fQueueEncodeLibhb, job );
2721 job->indepth_scan = 0;
2724 hb_add( fQueueEncodeLibhb, job );
2727 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2728 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2729 /* Lets mark our new encode as 1 or "Encoding" */
2730 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2731 [self saveQueueFileItem];
2733 /* we need to clean up the subtitle tracks after the job(s) have been set */
2734 int num_subtitle_tracks = hb_list_count(job->list_subtitle);
2736 for(ii = 0; ii < num_subtitle_tracks; ii++)
2738 hb_subtitle_t * subtitle;
2739 subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
2742 hb_list_rem(job->list_subtitle, subtitle);
2747 /* We should be all setup so let 'er rip */
2752 #pragma mark Live Preview
2753 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
2754 * can encode to its temp preview directory and playback. This is *not* used for any actual user
2757 - (void) prepareJobForPreview
2759 hb_list_t * list = hb_get_titles( fHandle );
2760 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2761 [fSrcTitlePopUp indexOfSelectedItem] );
2762 hb_job_t * job = title->job;
2763 hb_audio_config_t * audio;
2764 /* set job->angle for libdvdnav */
2765 job->angle = [fSrcAnglePopUp indexOfSelectedItem] + 1;
2766 /* Chapter selection */
2767 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
2768 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
2770 /* Format (Muxer) and Video Encoder */
2771 job->mux = [[fDstFormatPopUp selectedItem] tag];
2772 job->vcodec = [[fVidEncoderPopUp selectedItem] tag];
2774 job->chapter_markers = 0;
2776 if( job->vcodec & HB_VCODEC_X264 )
2778 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2779 Currently only used with Constant Quality setting*/
2780 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
2785 /* Below Sends x264 options to the core library if x264 is selected*/
2786 /* Lets use this as per Nyx, Thanks Nyx!*/
2787 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2788 /* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
2789 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
2794 /* Video settings */
2795 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2796 * and detelecine is on, so we handle that in the logic below
2799 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
2801 /* a specific framerate has been chosen */
2802 job->vrate = 27000000;
2803 job->vrate_base = hb_video_rates[[fVidRatePopUp indexOfSelectedItem]-1].rate;
2804 /* We are not same as source so we set job->cfr to 1
2805 * to enable constant frame rate since user has specified
2806 * a specific framerate*/
2811 /* We are same as source (variable) */
2812 job->vrate = title->rate;
2813 job->vrate_base = title->rate_base;
2814 /* We are same as source so we set job->cfr to 0
2815 * to enable true same as source framerate */
2817 /* If we are same as source and we have detelecine on, we need to turn on
2820 if ([fPictureController detelecine] == 1)
2826 switch( [fVidQualityMatrix selectedRow] )
2830 Bitrate should already have been calculated and displayed
2831 in fVidBitrateField, so let's just use it */
2833 job->vquality = -1.0;
2834 job->vbitrate = [fVidBitrateField intValue];
2837 job->vquality = [fVidQualityRFField floatValue];
2842 /* Subtitle settings */
2843 NSMutableArray *subtitlesArray = nil;
2844 subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray: subtitlesArray]];
2852 bool one_burned = FALSE;
2855 NSEnumerator *enumerator = [subtitlesArray objectEnumerator];
2857 while (tempObject = [enumerator nextObject])
2860 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
2861 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
2862 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
2863 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
2865 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
2866 * we want to ignore it for display as well as encoding.
2870 /* if i is 0, then we are in the first item of the subtitles which we need to
2871 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
2872 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
2875 /* if we are on the first track and using "Foreign Audio Search" */
2876 if (i == 0 && subtitle == 1)
2878 /* NOTE: Currently foreign language search is borked for preview.
2879 * Commented out but left in for initial commit. */
2882 [self writeToActivityLog: "Foreign Language Search: %d", 1];
2884 job->indepth_scan = 1;
2885 if (burned == 1 || job->mux != HB_MUX_MP4)
2887 if (burned != 1 && job->mux == HB_MUX_MKV)
2889 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2893 job->select_subtitle_config.dest = hb_subtitle_config_s::RENDERSUB;
2896 job->select_subtitle_config.force = force;
2897 job->select_subtitle_config.default_track = def;
2906 /* for the actual source tracks, we must subtract the non source entries so
2907 * that the menu index matches the source subtitle_list index for convenience */
2910 /* for the first track, the source tracks start at menu index 2 ( None is 0,
2911 * Foreign Language Search is 1) so subtract 2 */
2912 subtitle = subtitle - 2;
2916 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
2919 subtitle = subtitle - 1;
2922 /* We are setting a source subtitle so access the source subtitle info */
2923 hb_subtitle_t * subt;
2925 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
2929 [self writeToActivityLog: "Setting Subtitle: %s", subt];
2931 hb_subtitle_config_t sub_config = subt->config;
2933 if (!burned && job->mux == HB_MUX_MKV &&
2934 subt->format == hb_subtitle_s::PICTURESUB)
2936 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
2938 else if (!burned && job->mux == HB_MUX_MP4 &&
2939 subt->format == hb_subtitle_s::PICTURESUB)
2941 // Skip any non-burned vobsubs when output is mp4
2944 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
2946 // Only allow one subtitle to be burned into the video
2951 sub_config.force = force;
2952 sub_config.default_track = def;
2953 hb_subtitle_add( job, &sub_config, subtitle );
2963 [subtitlesArray autorelease];
2966 /* Audio tracks and mixdowns */
2967 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2968 int audiotrack_count = hb_list_count(job->list_audio);
2969 for( int i = 0; i < audiotrack_count;i++)
2971 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2972 hb_list_rem(job->list_audio, temp_audio);
2974 /* Now lets add our new tracks to the audio list here */
2975 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2977 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2978 hb_audio_config_init(audio);
2979 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2980 /* We go ahead and assign values to our audio->out.<properties> */
2981 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2982 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
2983 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
2984 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
2985 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
2986 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
2988 hb_audio_add( job, audio );
2991 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2993 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2994 hb_audio_config_init(audio);
2995 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2996 /* We go ahead and assign values to our audio->out.<properties> */
2997 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2998 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
2999 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
3000 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
3001 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
3002 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
3004 hb_audio_add( job, audio );
3009 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
3011 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3012 hb_audio_config_init(audio);
3013 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3014 /* We go ahead and assign values to our audio->out.<properties> */
3015 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3016 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
3017 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
3018 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
3019 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
3020 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
3022 hb_audio_add( job, audio );
3027 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
3029 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3030 hb_audio_config_init(audio);
3031 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3032 /* We go ahead and assign values to our audio->out.<properties> */
3033 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3034 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
3035 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
3036 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
3037 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
3038 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
3040 hb_audio_add( job, audio );
3049 /* Though Grayscale is not really a filter, per se
3050 * we put it here since its in the filters panel
3053 if ([fPictureController grayscale])
3062 /* Initialize the filters list */
3063 job->filters = hb_list_init();
3065 /* Now lets call the filters if applicable.
3066 * The order of the filters is critical
3070 if ([fPictureController detelecine] == 1)
3072 hb_list_add( job->filters, &hb_filter_detelecine );
3074 if ([fPictureController detelecine] == 2)
3076 /* use a custom detelecine string */
3077 hb_filter_detelecine.settings = (char *) [[fPictureController detelecineCustomString] UTF8String];
3078 hb_list_add( job->filters, &hb_filter_detelecine );
3080 if ([fPictureController useDecomb] == 1)
3083 if ([fPictureController decomb] == 1)
3085 /* Run old deinterlacer fd by default */
3086 //hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
3087 hb_list_add( job->filters, &hb_filter_decomb );
3089 /* we add the custom string if present */
3090 if ([fPictureController decomb] == 2)
3092 /* use a custom decomb string */
3093 hb_filter_decomb.settings = (char *) [[fPictureController decombCustomString] UTF8String];
3094 hb_list_add( job->filters, &hb_filter_decomb );
3101 if ([fPictureController deinterlace] == 1)
3103 /* Run old deinterlacer fd by default */
3104 hb_filter_deinterlace.settings = "-1";
3105 hb_list_add( job->filters, &hb_filter_deinterlace );
3107 else if ([fPictureController deinterlace] == 2)
3109 /* Yadif mode 0 (without spatial deinterlacing.) */
3110 hb_filter_deinterlace.settings = "2";
3111 hb_list_add( job->filters, &hb_filter_deinterlace );
3113 else if ([fPictureController deinterlace] == 3)
3115 /* Yadif (with spatial deinterlacing) */
3116 hb_filter_deinterlace.settings = "0";
3117 hb_list_add( job->filters, &hb_filter_deinterlace );
3119 else if ([fPictureController deinterlace] == 4)
3121 /* we add the custom string if present */
3122 hb_filter_deinterlace.settings = (char *) [[fPictureController deinterlaceCustomString] UTF8String];
3123 hb_list_add( job->filters, &hb_filter_deinterlace );
3128 if ([fPictureController denoise] == 1) // Weak in popup
3130 hb_filter_denoise.settings = "2:1:2:3";
3131 hb_list_add( job->filters, &hb_filter_denoise );
3133 else if ([fPictureController denoise] == 2) // Medium in popup
3135 hb_filter_denoise.settings = "3:2:2:3";
3136 hb_list_add( job->filters, &hb_filter_denoise );
3138 else if ([fPictureController denoise] == 3) // Strong in popup
3140 hb_filter_denoise.settings = "7:7:5:5";
3141 hb_list_add( job->filters, &hb_filter_denoise );
3143 else if ([fPictureController denoise] == 4) // custom in popup
3145 /* we add the custom string if present */
3146 hb_filter_denoise.settings = (char *) [[fPictureController denoiseCustomString] UTF8String];
3147 hb_list_add( job->filters, &hb_filter_denoise );
3150 /* Deblock (uses pp7 default) */
3151 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3152 * the macgui's purposes a value of 0 actually means to not even use the filter
3153 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3155 if ([fPictureController deblock] != 0)
3157 NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
3158 hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
3159 hb_list_add( job->filters, &hb_filter_deblock );
3166 #pragma mark Job Handling
3172 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
3173 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
3174 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
3175 hb_job_t * job = title->job;
3176 hb_audio_config_t * audio;
3177 /* Title Angle for dvdnav */
3178 job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
3179 /* Chapter selection */
3180 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
3181 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
3183 /* Format (Muxer) and Video Encoder */
3184 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
3185 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
3188 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
3189 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
3191 job->largeFileSize = 1;
3195 job->largeFileSize = 0;
3197 /* We set http optimized mp4 here */
3198 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
3200 job->mp4_optimize = 1;
3204 job->mp4_optimize = 0;
3208 /* We set the chapter marker extraction here based on the format being
3209 mpeg4 or mkv and the checkbox being checked */
3210 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
3212 job->chapter_markers = 1;
3214 /* now lets get our saved chapter names out the array in the queue file
3215 * and insert them back into the title chapter list. We have it here,
3216 * because unless we are inserting chapter markers there is no need to
3217 * spend the overhead of iterating through the chapter names array imo
3218 * Also, note that if for some reason we don't apply chapter names, the
3219 * chapters just come out 001, 002, etc. etc.
3222 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
3224 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
3226 while (tempObject = [enumerator nextObject])
3228 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3229 if( chapter != NULL )
3231 strncpy( chapter->title, [tempObject UTF8String], 1023);
3232 chapter->title[1023] = '\0';
3239 job->chapter_markers = 0;
3242 if( job->vcodec & HB_VCODEC_X264 )
3244 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
3253 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
3254 Currently only used with Constant Quality setting*/
3255 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
3259 /* Below Sends x264 options to the core library if x264 is selected*/
3260 /* Lets use this as per Nyx, Thanks Nyx!*/
3261 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
3262 /* Turbo first pass if two pass and Turbo First pass is selected */
3263 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
3265 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
3266 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
3267 /* append the "Turbo" string variable to the existing opts string.
3268 Note: the "Turbo" string must be appended, not prepended to work properly*/
3269 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
3270 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
3274 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
3280 /* Picture Size Settings */
3281 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
3282 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
3284 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
3285 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
3286 if ([[queueToApply objectForKey:@"PicturePAR"] intValue] == 3)
3288 /* insert our custom values here for capuj */
3289 job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"] intValue];
3290 job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"] intValue];
3292 job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"] intValue];
3293 job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"] intValue];
3295 job->anamorphic.dar_width = [[queueToApply objectForKey:@"PicturePARDisplayWidth"] floatValue];
3296 job->anamorphic.dar_height = [[queueToApply objectForKey:@"PicturePARDisplayHeight"] floatValue];
3299 /* Here we use the crop values saved at the time the preset was saved */
3300 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
3301 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
3302 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
3303 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
3305 /* Video settings */
3308 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
3309 * and detelecine is on, so we handle that in the logic below
3312 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
3314 /* a specific framerate has been chosen */
3315 job->vrate = 27000000;
3316 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
3317 /* We are not same as source so we set job->cfr to 1
3318 * to enable constant frame rate since user has specified
3319 * a specific framerate*/
3324 /* We are same as source (variable) */
3325 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
3326 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
3327 /* We are same as source so we set job->cfr to 0
3328 * to enable true same as source framerate */
3330 /* If we are same as source and we have detelecine on, we need to turn on
3333 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3339 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
3342 Bitrate should already have been calculated and displayed
3343 in fVidBitrateField, so let's just use it same as abr*/
3344 job->vquality = -1.0;
3345 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
3347 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
3349 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
3354 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
3359 #pragma mark Process Subtitles to libhb
3361 /* Map the settings in the dictionaries for the SubtitleList array to match title->list_subtitle
3362 * which means that we need to account for the offset of non source language settings in from
3363 * the NSPopUpCell menu. For all of the objects in the SubtitleList array this means 0 is "None"
3364 * from the popup menu, additionally the first track has "Foreign Audio Search" at 1. So we use
3365 * an int to offset the index number for the objectForKey:@"subtitleSourceTrackNum" to map that
3366 * to the source tracks position in title->list_subtitle.
3373 bool one_burned = FALSE;
3376 NSEnumerator *enumerator = [[queueToApply objectForKey:@"SubtitleList"] objectEnumerator];
3378 while (tempObject = [enumerator nextObject])
3381 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
3382 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
3383 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
3384 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
3386 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
3387 * we want to ignore it for display as well as encoding.
3391 /* if i is 0, then we are in the first item of the subtitles which we need to
3392 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
3393 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
3396 /* if we are on the first track and using "Foreign Audio Search" */
3397 if (i == 0 && subtitle == 1)
3399 [self writeToActivityLog: "Foreign Language Search: %d", 1];
3401 job->indepth_scan = 1;
3402 if (burned == 1 || job->mux != HB_MUX_MP4)
3404 if (burned != 1 && job->mux == HB_MUX_MKV)
3406 job->select_subtitle_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3410 job->select_subtitle_config.dest = hb_subtitle_config_s::RENDERSUB;
3413 job->select_subtitle_config.force = force;
3414 job->select_subtitle_config.default_track = def;
3422 /* for the actual source tracks, we must subtract the non source entries so
3423 * that the menu index matches the source subtitle_list index for convenience */
3426 /* for the first track, the source tracks start at menu index 2 ( None is 0,
3427 * Foreign Language Search is 1) so subtract 2 */
3428 subtitle = subtitle - 2;
3432 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
3435 subtitle = subtitle - 1;
3438 /* We are setting a source subtitle so access the source subtitle info */
3439 hb_subtitle_t * subt;
3441 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3445 [self writeToActivityLog: "Setting Subtitle: %s", subt];
3447 hb_subtitle_config_t sub_config = subt->config;
3449 if (!burned && job->mux == HB_MUX_MKV &&
3450 subt->format == hb_subtitle_s::PICTURESUB)
3452 sub_config.dest = hb_subtitle_config_s::PASSTHRUSUB;
3454 else if (!burned && job->mux == HB_MUX_MP4 &&
3455 subt->format == hb_subtitle_s::PICTURESUB)
3457 // Skip any non-burned vobsubs when output is mp4
3460 else if ( burned && subt->format == hb_subtitle_s::PICTURESUB )
3462 // Only allow one subtitle to be burned into the video
3467 sub_config.force = force;
3468 sub_config.default_track = def;
3469 hb_subtitle_add( job, &sub_config, subtitle );
3480 /* Audio tracks and mixdowns */
3481 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3482 int audiotrack_count = hb_list_count(job->list_audio);
3483 for( int i = 0; i < audiotrack_count;i++)
3485 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3486 hb_list_rem(job->list_audio, temp_audio);
3488 /* Now lets add our new tracks to the audio list here */
3489 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
3491 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3492 hb_audio_config_init(audio);
3493 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3494 /* We go ahead and assign values to our audio->out.<properties> */
3495 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3496 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
3497 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
3498 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
3499 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
3500 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
3502 hb_audio_add( job, audio );
3505 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
3508 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3509 hb_audio_config_init(audio);
3510 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3511 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
3512 /* We go ahead and assign values to our audio->out.<properties> */
3513 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3514 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
3515 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
3516 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
3517 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
3518 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
3520 hb_audio_add( job, audio );
3524 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
3526 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3527 hb_audio_config_init(audio);
3528 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3529 /* We go ahead and assign values to our audio->out.<properties> */
3530 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3531 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
3532 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
3533 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
3534 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
3535 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
3537 hb_audio_add( job, audio );
3541 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
3543 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3544 hb_audio_config_init(audio);
3545 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3546 /* We go ahead and assign values to our audio->out.<properties> */
3547 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3548 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
3549 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
3550 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
3551 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
3552 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue];
3554 hb_audio_add( job, audio );
3560 job->filters = hb_list_init();
3562 /* Now lets call the filters if applicable.
3563 * The order of the filters is critical
3566 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3568 //if ([queueToApply objectForKey:@"PictureDetelecineCustom"])
3569 hb_list_add( job->filters, &hb_filter_detelecine );
3571 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 2)
3573 /* use a custom detelecine string */
3574 hb_filter_detelecine.settings = (char *) [[queueToApply objectForKey:@"PictureDetelecineCustom"] UTF8String];
3575 hb_list_add( job->filters, &hb_filter_detelecine );
3578 if ([[queueToApply objectForKey:@"PictureDecombDeinterlace"] intValue] == 1)
3581 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
3583 /* Run old deinterlacer fd by default */
3584 hb_list_add( job->filters, &hb_filter_decomb );
3586 /* we add the custom string if present */
3587 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 2)
3589 /* use a custom decomb string */
3590 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"PictureDecombCustom"] UTF8String];
3591 hb_list_add( job->filters, &hb_filter_decomb );
3599 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
3601 /* Run old deinterlacer fd by default */
3602 hb_filter_deinterlace.settings = "-1";
3603 hb_list_add( job->filters, &hb_filter_deinterlace );
3605 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
3607 /* Yadif mode 0 (without spatial deinterlacing.) */
3608 hb_filter_deinterlace.settings = "2";
3609 hb_list_add( job->filters, &hb_filter_deinterlace );
3611 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
3613 /* Yadif (with spatial deinterlacing) */
3614 hb_filter_deinterlace.settings = "0";
3615 hb_list_add( job->filters, &hb_filter_deinterlace );
3617 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 4)
3619 /* we add the custom string if present */
3620 hb_filter_deinterlace.settings = (char *) [[queueToApply objectForKey:@"PictureDeinterlaceCustom"] UTF8String];
3621 hb_list_add( job->filters, &hb_filter_deinterlace );
3627 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
3629 hb_filter_denoise.settings = "2:1:2:3";
3630 hb_list_add( job->filters, &hb_filter_denoise );
3632 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
3634 hb_filter_denoise.settings = "3:2:2:3";
3635 hb_list_add( job->filters, &hb_filter_denoise );
3637 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
3639 hb_filter_denoise.settings = "7:7:5:5";
3640 hb_list_add( job->filters, &hb_filter_denoise );
3642 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 4) // Custom in popup
3644 /* we add the custom string if present */
3645 hb_filter_denoise.settings = (char *) [[queueToApply objectForKey:@"PictureDenoiseCustom"] UTF8String];
3646 hb_list_add( job->filters, &hb_filter_denoise );
3649 /* Deblock (uses pp7 default) */
3650 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3651 * the macgui's purposes a value of 0 actually means to not even use the filter
3652 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3654 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
3656 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
3657 hb_list_add( job->filters, &hb_filter_deblock );
3659 [self writeToActivityLog: "prepareJob exiting"];
3664 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
3666 - (IBAction) addToQueue: (id) sender
3668 /* We get the destination directory from the destination field here */
3669 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3670 /* We check for a valid destination here */
3671 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3673 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3680 BOOL fileExistsInQueue;
3681 fileExistsInQueue = NO;
3683 /* We check for and existing file here */
3684 if([[NSFileManager defaultManager] fileExistsAtPath: [fDstFile2Field stringValue]])
3689 /* We now run through the queue and make sure we are not overwriting an exisiting queue item */
3691 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
3693 while (tempObject = [enumerator nextObject])
3695 NSDictionary *thisQueueDict = tempObject;
3696 if ([[thisQueueDict objectForKey:@"DestinationPath"] isEqualToString: [fDstFile2Field stringValue]])
3698 fileExistsInQueue = YES;
3704 if(fileExists == YES)
3706 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists.", @"" ),
3707 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3708 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3709 NULL, NULL, [NSString stringWithFormat:
3710 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3711 [fDstFile2Field stringValue]] );
3713 else if (fileExistsInQueue == YES)
3715 NSBeginCriticalAlertSheet( NSLocalizedString( @"There is already a queue item for this destination.", @"" ),
3716 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3717 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3718 NULL, NULL, [NSString stringWithFormat:
3719 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3720 [fDstFile2Field stringValue]] );
3724 [self doAddToQueue];
3728 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
3729 the user if they want to overwrite an exiting movie file.
3731 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
3732 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3734 if( returnCode == NSAlertAlternateReturn )
3735 [self doAddToQueue];
3738 - (void) doAddToQueue
3740 [self addQueueFileItem ];
3745 /* Rip: puts up an alert before ultimately calling doRip
3747 - (IBAction) Rip: (id) sender
3749 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
3750 /* Rip or Cancel ? */
3752 hb_get_state2( fQueueEncodeLibhb, &s );
3754 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
3756 [self Cancel: sender];
3760 /* We check to see if we need to warn the user that the computer will go to sleep
3761 or shut down when encoding is finished */
3762 [self remindUserOfSleepOrShutdown];
3764 // If there are pending jobs in the queue, then this is a rip the queue
3765 if (fPendingCount > 0)
3767 /* here lets start the queue with the first pending item */
3768 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3773 // Before adding jobs to the queue, check for a valid destination.
3775 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3776 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3778 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3782 /* We check for duplicate name here */
3783 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
3785 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3786 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3787 @selector( overWriteAlertDone:returnCode:contextInfo: ),
3788 NULL, NULL, [NSString stringWithFormat:
3789 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3790 [fDstFile2Field stringValue]] );
3792 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
3796 /* if there are no pending jobs in the queue, then add this one to the queue and rip
3797 otherwise, just rip the queue */
3798 if(fPendingCount == 0)
3800 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
3801 [self doAddToQueue];
3804 /* go right to processing the new queue encode */
3805 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
3806 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3811 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3812 want to overwrite an exiting movie file.
3814 - (void) overWriteAlertDone: (NSWindow *) sheet
3815 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3817 if( returnCode == NSAlertAlternateReturn )
3819 /* if there are no jobs in the queue, then add this one to the queue and rip
3820 otherwise, just rip the queue */
3821 if( fPendingCount == 0 )
3823 [self doAddToQueue];
3826 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3827 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3828 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3833 - (void) remindUserOfSleepOrShutdown
3835 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
3837 /*Warn that computer will sleep after encoding*/
3840 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);
3841 [NSApp requestUserAttention:NSCriticalRequest];
3842 if ( reminduser == NSAlertAlternateReturn )
3844 [self showPreferencesWindow:nil];
3847 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
3849 /*Warn that computer will shut down after encoding*/
3852 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);
3853 [NSApp requestUserAttention:NSCriticalRequest];
3854 if ( reminduser == NSAlertAlternateReturn )
3856 [self showPreferencesWindow:nil];
3865 /* Let libhb do the job */
3866 hb_start( fQueueEncodeLibhb );
3867 /*set the fEncodeState State */
3872 //------------------------------------------------------------------------------------
3873 // Displays an alert asking user if the want to cancel encoding of current job.
3874 // Cancel: returns immediately after posting the alert. Later, when the user
3875 // acknowledges the alert, doCancelCurrentJob is called.
3876 //------------------------------------------------------------------------------------
3877 - (IBAction)Cancel: (id)sender
3879 if (!fQueueController) return;
3881 hb_pause( fQueueEncodeLibhb );
3882 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3884 // Which window to attach the sheet to?
3885 NSWindow * docWindow;
3886 if ([sender respondsToSelector: @selector(window)])
3887 docWindow = [sender window];
3889 docWindow = fWindow;
3891 NSBeginCriticalAlertSheet(
3893 NSLocalizedString(@"Continue Encoding", nil),
3894 NSLocalizedString(@"Cancel Current and Stop", nil),
3895 NSLocalizedString(@"Cancel Current and Continue", nil),
3897 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3898 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3900 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3903 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3905 hb_resume( fQueueEncodeLibhb );
3906 if (returnCode == NSAlertOtherReturn)
3908 [self doCancelCurrentJob]; // <- this also stops libhb
3910 if (returnCode == NSAlertAlternateReturn)
3912 [self doCancelCurrentJobAndStop];
3916 //------------------------------------------------------------------------------------
3917 // Cancels and deletes the current job and stops libhb from processing the remaining
3919 //------------------------------------------------------------------------------------
3920 - (void) doCancelCurrentJob
3922 // Stop the current job. hb_stop will only cancel the current pass and then set
3923 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3924 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3925 // remaining passes of the job and then start the queue back up if there are any
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 );
3936 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3938 // now that we've stopped the currently encoding job, lets mark it as cancelled
3939 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3940 // and as always, save it in the queue .plist...
3941 /* We save all of the Queue data here */
3942 [self saveQueueFileItem];
3943 // so now lets move to
3944 currentQueueEncodeIndex++ ;
3945 // ... and see if there are more items left in our queue
3946 int queueItems = [QueueFileArray count];
3947 /* If we still have more items in our queue, lets go to the next one */
3948 if (currentQueueEncodeIndex < queueItems)
3950 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3951 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3953 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3957 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3962 - (void) doCancelCurrentJobAndStop
3964 hb_stop( fQueueEncodeLibhb );
3966 // Delete all remaining jobs since libhb doesn't do this on its own.
3968 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3969 hb_rem( fQueueEncodeLibhb, job );
3972 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3974 // now that we've stopped the currently encoding job, lets mark it as cancelled
3975 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3976 // and as always, save it in the queue .plist...
3977 /* We save all of the Queue data here */
3978 [self saveQueueFileItem];
3979 // so now lets move to
3980 currentQueueEncodeIndex++ ;
3981 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3983 - (IBAction) Pause: (id) sender
3986 hb_get_state2( fQueueEncodeLibhb, &s );
3988 if( s.state == HB_STATE_PAUSED )
3990 hb_resume( fQueueEncodeLibhb );
3994 hb_pause( fQueueEncodeLibhb );
3999 #pragma mark GUI Controls Changed Methods
4001 - (IBAction) titlePopUpChanged: (id) sender
4003 hb_list_t * list = hb_get_titles( fHandle );
4004 hb_title_t * title = (hb_title_t*)
4005 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4007 /* If Auto Naming is on. We create an output filename of dvd name - title number */
4008 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
4010 [fDstFile2Field setStringValue: [NSString stringWithFormat:
4011 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
4012 [browsedSourceDisplayName stringByDeletingPathExtension],
4014 [[fDstFile2Field stringValue] pathExtension]]];
4017 /* Update chapter popups */
4018 [fSrcChapterStartPopUp removeAllItems];
4019 [fSrcChapterEndPopUp removeAllItems];
4020 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
4022 [fSrcChapterStartPopUp addItemWithTitle: [NSString
4023 stringWithFormat: @"%d", i + 1]];
4024 [fSrcChapterEndPopUp addItemWithTitle: [NSString
4025 stringWithFormat: @"%d", i + 1]];
4028 [fSrcChapterStartPopUp selectItemAtIndex: 0];
4029 [fSrcChapterEndPopUp selectItemAtIndex:
4030 hb_list_count( title->list_chapter ) - 1];
4031 [self chapterPopUpChanged:nil];
4033 /* if using dvd nav, show the angle widget */
4034 if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue])
4036 [fSrcAngleLabel setHidden:NO];
4037 [fSrcAnglePopUp setHidden:NO];
4039 [fSrcAnglePopUp removeAllItems];
4040 for( int i = 0; i < title->angle_count; i++ )
4042 [fSrcAnglePopUp addItemWithTitle: [NSString stringWithFormat: @"%d", i + 1]];
4044 [fSrcAnglePopUp selectItemAtIndex: 0];
4048 [fSrcAngleLabel setHidden:YES];
4049 [fSrcAnglePopUp setHidden:YES];
4052 /* Start Get and set the initial pic size for display */
4053 hb_job_t * job = title->job;
4056 /* Set Auto Crop to on upon selecting a new title */
4057 [fPictureController setAutoCrop:YES];
4059 /* We get the originial output picture width and height and put them
4060 in variables for use with some presets later on */
4061 PicOrigOutputWidth = job->width;
4062 PicOrigOutputHeight = job->height;
4063 AutoCropTop = job->crop[0];
4064 AutoCropBottom = job->crop[1];
4065 AutoCropLeft = job->crop[2];
4066 AutoCropRight = job->crop[3];
4068 /* Reset the new title in fPictureController && fPreviewController*/
4069 [fPictureController SetTitle:title];
4072 /* Update Subtitle Table */
4073 [fSubtitlesDelegate resetWithTitle:title];
4074 [fSubtitlesTable reloadData];
4077 /* Update chapter table */
4078 [fChapterTitlesDelegate resetWithTitle:title];
4079 [fChapterTable reloadData];
4081 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
4082 int audiotrack_count = hb_list_count(job->list_audio);
4083 for( int i = 0; i < audiotrack_count;i++)
4085 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4086 hb_list_rem(job->list_audio, temp_audio);
4089 /* Update audio popups */
4090 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
4091 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
4092 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
4093 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
4094 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
4095 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
4096 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
4097 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4098 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4099 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4101 /* changing the title may have changed the audio channels on offer, */
4102 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4103 [self audioTrackPopUpChanged: fAudLang1PopUp];
4104 [self audioTrackPopUpChanged: fAudLang2PopUp];
4105 [self audioTrackPopUpChanged: fAudLang3PopUp];
4106 [self audioTrackPopUpChanged: fAudLang4PopUp];
4108 [fVidRatePopUp selectItemAtIndex: 0];
4110 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
4111 [self calculatePictureSizing:nil];
4113 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
4114 [self selectPreset:nil];
4117 - (IBAction) chapterPopUpChanged: (id) sender
4120 /* If start chapter popup is greater than end chapter popup,
4121 we set the end chapter popup to the same as start chapter popup */
4122 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
4124 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
4128 hb_list_t * list = hb_get_titles( fHandle );
4129 hb_title_t * title = (hb_title_t *)
4130 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4132 hb_chapter_t * chapter;
4133 int64_t duration = 0;
4134 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
4135 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
4137 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
4138 duration += chapter->duration;
4141 duration /= 90000; /* pts -> seconds */
4142 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
4143 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
4146 [self calculateBitrate: sender];
4148 if ( [fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem] )
4150 /* Disable chapter markers for any source with less than two chapters as it makes no sense. */
4151 [fCreateChapterMarkers setEnabled: NO];
4152 [fCreateChapterMarkers setState: NSOffState];
4156 [fCreateChapterMarkers setEnabled: YES];
4160 - (IBAction) formatPopUpChanged: (id) sender
4162 NSString * string = [fDstFile2Field stringValue];
4163 int format = [fDstFormatPopUp indexOfSelectedItem];
4165 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
4166 [fDstMp4LargeFileCheck setHidden: YES];
4167 [fDstMp4HttpOptFileCheck setHidden: YES];
4168 [fDstMp4iPodFileCheck setHidden: YES];
4170 /* Update the Video Codec PopUp */
4171 /* lets get the tag of the currently selected item first so we might reset it later */
4172 int selectedVidEncoderTag;
4173 selectedVidEncoderTag = [[fVidEncoderPopUp selectedItem] tag];
4175 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
4176 [fVidEncoderPopUp removeAllItems];
4177 NSMenuItem *menuItem;
4178 /* These video encoders are available to all of our current muxers, so lets list them once here */
4179 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
4180 [menuItem setTag: HB_VCODEC_FFMPEG];
4185 /*Get Default MP4 File Extension*/
4186 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
4194 /* Add additional video encoders here */
4195 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4196 [menuItem setTag: HB_VCODEC_X264];
4197 /* We show the mp4 option checkboxes here since we are mp4 */
4198 [fCreateChapterMarkers setEnabled: YES];
4199 [fDstMp4LargeFileCheck setHidden: NO];
4200 [fDstMp4HttpOptFileCheck setHidden: NO];
4201 [fDstMp4iPodFileCheck setHidden: NO];
4206 /* Add additional video encoders here */
4207 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4208 [menuItem setTag: HB_VCODEC_X264];
4209 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
4210 [menuItem setTag: HB_VCODEC_THEORA];
4211 /* We enable the create chapters checkbox here */
4212 [fCreateChapterMarkers setEnabled: YES];
4217 /* tell fSubtitlesDelegate we have a new video container */
4219 [fSubtitlesDelegate containerChanged:[[fDstFormatPopUp selectedItem] tag]];
4220 [fSubtitlesTable reloadData];
4221 /* if we have a previously selected vid encoder tag, then try to select it */
4222 if (selectedVidEncoderTag)
4224 [fVidEncoderPopUp selectItemWithTag: selectedVidEncoderTag];
4228 [fVidEncoderPopUp selectItemAtIndex: 0];
4231 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4232 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4233 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4234 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4237 [self autoSetM4vExtension: sender];
4239 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
4241 if( SuccessfulScan )
4243 /* Add/replace to the correct extension */
4244 [self audioTrackPopUpChanged: fAudLang1PopUp];
4245 [self audioTrackPopUpChanged: fAudLang2PopUp];
4246 [self audioTrackPopUpChanged: fAudLang3PopUp];
4247 [self audioTrackPopUpChanged: fAudLang4PopUp];
4249 if( [fVidEncoderPopUp selectedItem] == nil )
4252 [fVidEncoderPopUp selectItemAtIndex:0];
4253 [self videoEncoderPopUpChanged:nil];
4255 /* changing the format may mean that we can / can't offer mono or 6ch, */
4256 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4258 /* We call the method to properly enable/disable turbo 2 pass */
4259 [self twoPassCheckboxChanged: sender];
4260 /* We call method method to change UI to reflect whether a preset is used or not*/
4263 [self customSettingUsed: sender];
4266 - (IBAction) autoSetM4vExtension: (id) sender
4268 if ( [fDstFormatPopUp indexOfSelectedItem] )
4271 NSString * extension = @"mp4";
4273 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4274 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4275 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4276 [fCreateChapterMarkers state] == NSOnState ||
4277 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
4282 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
4285 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
4286 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
4289 /* Method to determine if we should change the UI
4290 To reflect whether or not a Preset is being used or if
4291 the user is using "Custom" settings by determining the sender*/
4292 - (IBAction) customSettingUsed: (id) sender
4294 if ([sender stringValue])
4296 /* Deselect the currently selected Preset if there is one*/
4297 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
4298 /* Change UI to show "Custom" settings are being used */
4299 [fPresetSelectedDisplay setStringValue: @"Custom"];
4301 curUserPresetChosenNum = nil;
4303 [self calculateBitrate:nil];
4308 #pragma mark - Video
4310 - (IBAction) videoEncoderPopUpChanged: (id) sender
4312 hb_job_t * job = fTitle->job;
4313 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
4315 [fAdvancedOptions setHidden:YES];
4316 /* If we are using x264 then show the x264 advanced panel*/
4317 if (videoEncoder == HB_VCODEC_X264)
4319 [fAdvancedOptions setHidden:NO];
4320 [self autoSetM4vExtension: sender];
4323 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
4324 is being used as it borks up loose anamorphic .
4325 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
4326 to use the index itself but this is easier */
4327 if (videoEncoder == HB_VCODEC_FFMPEG)
4329 if (job->anamorphic.mode == 2)
4331 job->anamorphic.mode = 0;
4333 [fPictureController setAllowLooseAnamorphic:NO];
4334 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
4335 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
4336 anything other than MP4.
4338 [fDstMp4iPodFileCheck setEnabled: NO];
4339 [fDstMp4iPodFileCheck setState: NSOffState];
4343 [fPictureController setAllowLooseAnamorphic:YES];
4344 [fDstMp4iPodFileCheck setEnabled: YES];
4346 [self setupQualitySlider];
4347 [self calculatePictureSizing: sender];
4348 [self twoPassCheckboxChanged: sender];
4352 - (IBAction) twoPassCheckboxChanged: (id) sender
4354 /* check to see if x264 is chosen */
4355 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4357 if( [fVidTwoPassCheck state] == NSOnState)
4359 [fVidTurboPassCheck setHidden: NO];
4363 [fVidTurboPassCheck setHidden: YES];
4364 [fVidTurboPassCheck setState: NSOffState];
4366 /* Make sure Two Pass is checked if Turbo is checked */
4367 if( [fVidTurboPassCheck state] == NSOnState)
4369 [fVidTwoPassCheck setState: NSOnState];
4374 [fVidTurboPassCheck setHidden: YES];
4375 [fVidTurboPassCheck setState: NSOffState];
4378 /* We call method method to change UI to reflect whether a preset is used or not*/
4379 [self customSettingUsed: sender];
4382 - (IBAction ) videoFrameRateChanged: (id) sender
4384 /* We call method method to calculatePictureSizing to error check detelecine*/
4385 [self calculatePictureSizing: sender];
4387 /* We call method method to change UI to reflect whether a preset is used or not*/
4388 [self customSettingUsed: sender];
4390 - (IBAction) videoMatrixChanged: (id) sender;
4392 bool target, bitrate, quality;
4394 target = bitrate = quality = false;
4395 if( [fVidQualityMatrix isEnabled] )
4397 switch( [fVidQualityMatrix selectedRow] )
4410 [fVidTargetSizeField setEnabled: target];
4411 [fVidBitrateField setEnabled: bitrate];
4412 [fVidQualitySlider setEnabled: quality];
4413 [fVidQualityRFField setEnabled: quality];
4414 [fVidQualityRFLabel setEnabled: quality];
4415 [fVidTwoPassCheck setEnabled: !quality &&
4416 [fVidQualityMatrix isEnabled]];
4419 [fVidTwoPassCheck setState: NSOffState];
4420 [fVidTurboPassCheck setHidden: YES];
4421 [fVidTurboPassCheck setState: NSOffState];
4424 [self qualitySliderChanged: sender];
4425 [self calculateBitrate: sender];
4426 [self customSettingUsed: sender];
4429 /* Use this method to setup the quality slider for cq/rf values depending on
4430 * the video encoder selected.
4432 - (void) setupQualitySlider
4434 /* Get the current slider maxValue to check for a change in slider scale later
4435 * so that we can choose a new similar value on the new slider scale */
4436 float previousMaxValue = [fVidQualitySlider maxValue];
4437 float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1);
4438 NSString * qpRFLabelString = @"QP:";
4440 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4442 [fVidQualitySlider setMinValue:0.0];
4443 [fVidQualitySlider setMaxValue:51.0];
4444 /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
4445 int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
4446 [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
4447 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0)
4449 qpRFLabelString = @"RF:";
4453 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
4455 [fVidQualitySlider setMinValue:1.0];
4456 [fVidQualitySlider setMaxValue:31.0];
4457 [fVidQualitySlider setNumberOfTickMarks:31];
4460 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4462 [fVidQualitySlider setMinValue:0.0];
4463 [fVidQualitySlider setMaxValue:63.0];
4464 [fVidQualitySlider setNumberOfTickMarks:64];
4466 [fVidQualityRFLabel setStringValue:qpRFLabelString];
4468 /* check to see if we have changed slider scales */
4469 if (previousMaxValue != [fVidQualitySlider maxValue])
4471 /* if so, convert the old setting to the new scale as close as possible based on percentages */
4472 float rf = ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1) * previousPercentOfSliderScale;
4473 [fVidQualitySlider setFloatValue:rf];
4476 [self qualitySliderChanged:nil];
4479 - (IBAction) qualitySliderChanged: (id) sender
4481 /* Our constant quality slider is in a range based
4482 * on each encoders qp/rf values. The range depends
4483 * on the encoder. Also, the range is inverse of quality
4484 * for all of the encoders *except* for theora
4485 * (ie. as the "quality" goes up, the cq or rf value
4486 * actually goes down). Since the IB sliders always set
4487 * their max value at the right end of the slider, we
4488 * will calculate the inverse, so as the slider floatValue
4489 * goes up, we will show the inverse in the rf field
4490 * so, the floatValue at the right for x264 would be 51
4491 * and our rf field needs to show 0 and vice versa.
4494 float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue];
4495 /* If the encoder is theora, use the float, otherwise use the inverse float*/
4496 float sliderRfToPercent;
4497 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4499 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];
4500 sliderRfToPercent = [fVidQualityRFField floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4504 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]];
4505 sliderRfToPercent = ( ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - ([fVidQualityRFField floatValue] - [fVidQualitySlider minValue])) / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4507 [fVidConstantCell setTitle: [NSString stringWithFormat:
4508 NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]];
4510 [self customSettingUsed: sender];
4513 - (void) controlTextDidChange: (NSNotification *) notification
4515 [self calculateBitrate:nil];
4518 - (IBAction) calculateBitrate: (id) sender
4520 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
4525 hb_list_t * list = hb_get_titles( fHandle );
4526 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4527 [fSrcTitlePopUp indexOfSelectedItem] );
4528 hb_job_t * job = title->job;
4529 hb_audio_config_t * audio;
4530 /* For hb_calc_bitrate in addition to the Target Size in MB out of the
4531 * Target Size Field, we also need the job info for the Muxer, the Chapters
4532 * as well as all of the audio track info.
4533 * This used to be accomplished by simply calling prepareJob here, however
4534 * since the resilient queue sets the queue array values instead of the job
4535 * values directly, we duplicate the old prepareJob code here for the variables
4538 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
4539 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
4540 job->mux = [[fDstFormatPopUp selectedItem] tag];
4542 /* Audio goes here */
4543 int audiotrack_count = hb_list_count(job->list_audio);
4544 for( int i = 0; i < audiotrack_count;i++)
4546 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4547 hb_list_rem(job->list_audio, temp_audio);
4549 /* Now we need our audio info here for each track if applicable */
4550 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4552 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4553 hb_audio_config_init(audio);
4554 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4555 /* We go ahead and assign values to our audio->out.<properties> */
4556 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4557 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
4558 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
4559 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
4560 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
4561 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
4563 hb_audio_add( job, audio );
4566 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4568 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4569 hb_audio_config_init(audio);
4570 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4571 /* We go ahead and assign values to our audio->out.<properties> */
4572 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4573 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
4574 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
4575 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
4576 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
4577 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
4579 hb_audio_add( job, audio );
4584 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4586 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4587 hb_audio_config_init(audio);
4588 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4589 /* We go ahead and assign values to our audio->out.<properties> */
4590 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4591 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
4592 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
4593 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
4594 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
4595 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
4597 hb_audio_add( job, audio );
4602 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4604 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4605 hb_audio_config_init(audio);
4606 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4607 /* We go ahead and assign values to our audio->out.<properties> */
4608 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4609 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
4610 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
4611 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
4612 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
4613 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
4615 hb_audio_add( job, audio );
4620 [fVidBitrateField setIntValue: hb_calc_bitrate( job, [fVidTargetSizeField intValue] )];
4624 #pragma mark - Picture
4626 /* lets set the picture size back to the max from right after title scan
4627 Lets use an IBAction here as down the road we could always use a checkbox
4628 in the gui to easily take the user back to max. Remember, the compiler
4629 resolves IBActions down to -(void) during compile anyway */
4630 - (IBAction) revertPictureSizeToMax: (id) sender
4632 hb_job_t * job = fTitle->job;
4633 /* Here we apply the title source and height */
4634 job->width = fTitle->width;
4635 job->height = fTitle->height;
4637 [self calculatePictureSizing: sender];
4638 /* We call method to change UI to reflect whether a preset is used or not*/
4639 [self customSettingUsed: sender];
4643 * Registers changes made in the Picture Settings Window.
4646 - (void)pictureSettingsDidChange
4648 [self calculatePictureSizing:nil];
4651 /* Get and Display Current Pic Settings in main window */
4652 - (IBAction) calculatePictureSizing: (id) sender
4654 if (fTitle->job->anamorphic.mode > 0)
4656 fTitle->job->keep_ratio = 0;
4659 [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
4661 NSString *picCropping;
4662 /* Set the display field for crop as per boolean */
4663 if (![fPictureController autoCrop])
4665 picCropping = @"Custom";
4669 picCropping = @"Auto";
4671 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]]];
4673 [fPictureCroppingField setStringValue: [NSString stringWithFormat:@"Picture Cropping: %@",picCropping]];
4675 NSString *videoFilters;
4678 if ([fPictureController detelecine] == 1)
4680 videoFilters = [videoFilters stringByAppendingString:@" - Detelecine (Default)"];
4682 else if ([fPictureController detelecine] == 2)
4684 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Detelecine (%@)",[fPictureController detelecineCustomString]]];
4688 if ([fPictureController useDecomb] == 1)
4691 if ([fPictureController decomb] == 1)
4693 videoFilters = [videoFilters stringByAppendingString:@" - Decomb (Default)"];
4695 else if ([fPictureController decomb] == 2)
4697 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Decomb (%@)",[fPictureController decombCustomString]]];
4703 if ([fPictureController deinterlace] > 0)
4705 fTitle->job->deinterlace = 1;
4709 fTitle->job->deinterlace = 0;
4712 if ([fPictureController deinterlace] == 1)
4714 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Fast)"];
4716 else if ([fPictureController deinterlace] == 2)
4718 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slow)"];
4720 else if ([fPictureController deinterlace] == 3)
4722 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slower)"];
4724 else if ([fPictureController deinterlace] == 4)
4726 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deinterlace (%@)",[fPictureController deinterlaceCustomString]]];
4732 if ([fPictureController denoise] == 1)
4734 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Weak)"];
4736 else if ([fPictureController denoise] == 2)
4738 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Medium)"];
4740 else if ([fPictureController denoise] == 3)
4742 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Strong)"];
4744 else if ([fPictureController denoise] == 4)
4746 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Denoise (%@)",[fPictureController denoiseCustomString]]];
4750 if ([fPictureController deblock] > 0)
4752 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deblock (%d)",[fPictureController deblock]]];
4756 if ([fPictureController grayscale])
4758 videoFilters = [videoFilters stringByAppendingString:@" - Grayscale"];
4760 [fVideoFiltersField setStringValue: [NSString stringWithFormat:@"Video Filters: %@", videoFilters]];
4762 //[fPictureController reloadStillPreview];
4767 #pragma mark - Audio and Subtitles
4768 - (IBAction) audioCodecsPopUpChanged: (id) sender
4771 NSPopUpButton * audiotrackPopUp;
4772 NSPopUpButton * sampleratePopUp;
4773 NSPopUpButton * bitratePopUp;
4774 NSPopUpButton * audiocodecPopUp;
4775 if (sender == fAudTrack1CodecPopUp)
4777 audiotrackPopUp = fAudLang1PopUp;
4778 audiocodecPopUp = fAudTrack1CodecPopUp;
4779 sampleratePopUp = fAudTrack1RatePopUp;
4780 bitratePopUp = fAudTrack1BitratePopUp;
4782 else if (sender == fAudTrack2CodecPopUp)
4784 audiotrackPopUp = fAudLang2PopUp;
4785 audiocodecPopUp = fAudTrack2CodecPopUp;
4786 sampleratePopUp = fAudTrack2RatePopUp;
4787 bitratePopUp = fAudTrack2BitratePopUp;
4789 else if (sender == fAudTrack3CodecPopUp)
4791 audiotrackPopUp = fAudLang3PopUp;
4792 audiocodecPopUp = fAudTrack3CodecPopUp;
4793 sampleratePopUp = fAudTrack3RatePopUp;
4794 bitratePopUp = fAudTrack3BitratePopUp;
4798 audiotrackPopUp = fAudLang4PopUp;
4799 audiocodecPopUp = fAudTrack4CodecPopUp;
4800 sampleratePopUp = fAudTrack4RatePopUp;
4801 bitratePopUp = fAudTrack4BitratePopUp;
4804 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
4805 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4806 [self audioTrackPopUpChanged: audiotrackPopUp];
4810 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
4812 /* We will be setting the enabled/disabled state of each tracks audio controls based on
4813 * the settings of the source audio for that track. We leave the samplerate and bitrate
4814 * to audiotrackMixdownChanged
4817 /* We will first verify that a lower track number has been selected before enabling each track
4818 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
4820 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4822 [fAudLang2PopUp setEnabled: NO];
4823 [fAudLang2PopUp selectItemAtIndex: 0];
4827 [fAudLang2PopUp setEnabled: YES];
4830 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4832 [fAudLang3PopUp setEnabled: NO];
4833 [fAudLang3PopUp selectItemAtIndex: 0];
4837 [fAudLang3PopUp setEnabled: YES];
4839 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4841 [fAudLang4PopUp setEnabled: NO];
4842 [fAudLang4PopUp selectItemAtIndex: 0];
4846 [fAudLang4PopUp setEnabled: YES];
4848 /* enable/disable the mixdown text and popupbutton for audio track 1 */
4849 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4850 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4851 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4852 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4853 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4854 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4855 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4857 [fAudTrack1CodecPopUp removeAllItems];
4858 [fAudTrack1MixPopUp removeAllItems];
4859 [fAudTrack1RatePopUp removeAllItems];
4860 [fAudTrack1BitratePopUp removeAllItems];
4861 [fAudTrack1DrcSlider setFloatValue: 1.00];
4862 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
4864 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4866 [fAudTrack1RatePopUp setEnabled: NO];
4867 [fAudTrack1BitratePopUp setEnabled: NO];
4868 [fAudTrack1DrcSlider setEnabled: NO];
4869 [fAudTrack1DrcField setEnabled: NO];
4872 /* enable/disable the mixdown text and popupbutton for audio track 2 */
4873 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4874 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4875 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4876 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4877 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4878 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4879 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4881 [fAudTrack2CodecPopUp removeAllItems];
4882 [fAudTrack2MixPopUp removeAllItems];
4883 [fAudTrack2RatePopUp removeAllItems];
4884 [fAudTrack2BitratePopUp removeAllItems];
4885 [fAudTrack2DrcSlider setFloatValue: 1.00];
4886 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
4888 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4890 [fAudTrack2RatePopUp setEnabled: NO];
4891 [fAudTrack2BitratePopUp setEnabled: NO];
4892 [fAudTrack2DrcSlider setEnabled: NO];
4893 [fAudTrack2DrcField setEnabled: NO];
4896 /* enable/disable the mixdown text and popupbutton for audio track 3 */
4897 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4898 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4899 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4900 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4901 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4902 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4903 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4905 [fAudTrack3CodecPopUp removeAllItems];
4906 [fAudTrack3MixPopUp removeAllItems];
4907 [fAudTrack3RatePopUp removeAllItems];
4908 [fAudTrack3BitratePopUp removeAllItems];
4909 [fAudTrack3DrcSlider setFloatValue: 1.00];
4910 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
4912 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4914 [fAudTrack3RatePopUp setEnabled: NO];
4915 [fAudTrack3BitratePopUp setEnabled: NO];
4916 [fAudTrack3DrcSlider setEnabled: NO];
4917 [fAudTrack3DrcField setEnabled: NO];
4920 /* enable/disable the mixdown text and popupbutton for audio track 4 */
4921 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4922 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4923 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4924 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4925 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4926 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4927 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
4929 [fAudTrack4CodecPopUp removeAllItems];
4930 [fAudTrack4MixPopUp removeAllItems];
4931 [fAudTrack4RatePopUp removeAllItems];
4932 [fAudTrack4BitratePopUp removeAllItems];
4933 [fAudTrack4DrcSlider setFloatValue: 1.00];
4934 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
4936 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
4938 [fAudTrack4RatePopUp setEnabled: NO];
4939 [fAudTrack4BitratePopUp setEnabled: NO];
4940 [fAudTrack4DrcSlider setEnabled: NO];
4941 [fAudTrack4DrcField setEnabled: NO];
4946 - (IBAction) addAllAudioTracksToPopUp: (id) sender
4949 hb_list_t * list = hb_get_titles( fHandle );
4950 hb_title_t * title = (hb_title_t*)
4951 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4953 hb_audio_config_t * audio;
4955 [sender removeAllItems];
4956 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
4957 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
4959 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
4960 [[sender menu] addItemWithTitle:
4961 [NSString stringWithCString: audio->lang.description]
4962 action: NULL keyEquivalent: @""];
4964 [sender selectItemAtIndex: 0];
4968 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
4971 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
4972 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
4973 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
4974 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
4976 if (searchPrefixString)
4979 for( int i = 0; i < [sender numberOfItems]; i++ )
4981 /* Try to find the desired search string */
4982 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
4984 [sender selectItemAtIndex: i];
4988 /* couldn't find the string, so select the requested "search string not found" item */
4989 /* index of 0 means select the "none" item */
4990 /* index of 1 means select the first audio track */
4991 [sender selectItemAtIndex: selectIndexIfNotFound];
4995 /* if no search string is provided, then select the selectIndexIfNotFound item */
4996 [sender selectItemAtIndex: selectIndexIfNotFound];
5000 - (IBAction) audioAddAudioTrackCodecs: (id)sender
5002 int format = [fDstFormatPopUp indexOfSelectedItem];
5004 /* setup pointers to the appropriate popups for the correct track */
5005 NSPopUpButton * audiocodecPopUp;
5006 NSPopUpButton * audiotrackPopUp;
5007 if (sender == fAudTrack1CodecPopUp)
5009 audiotrackPopUp = fAudLang1PopUp;
5010 audiocodecPopUp = fAudTrack1CodecPopUp;
5012 else if (sender == fAudTrack2CodecPopUp)
5014 audiotrackPopUp = fAudLang2PopUp;
5015 audiocodecPopUp = fAudTrack2CodecPopUp;
5017 else if (sender == fAudTrack3CodecPopUp)
5019 audiotrackPopUp = fAudLang3PopUp;
5020 audiocodecPopUp = fAudTrack3CodecPopUp;
5024 audiotrackPopUp = fAudLang4PopUp;
5025 audiocodecPopUp = fAudTrack4CodecPopUp;
5028 [audiocodecPopUp removeAllItems];
5029 /* Make sure "None" isnt selected in the source track */
5030 if ([audiotrackPopUp indexOfSelectedItem] > 0)
5032 [audiocodecPopUp setEnabled:YES];
5033 NSMenuItem *menuItem;
5034 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
5040 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5041 [menuItem setTag: HB_ACODEC_FAAC];
5044 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5045 [menuItem setTag: HB_ACODEC_CA_AAC];
5048 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5049 [menuItem setTag: HB_ACODEC_AC3];
5055 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5056 [menuItem setTag: HB_ACODEC_FAAC];
5058 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5059 [menuItem setTag: HB_ACODEC_CA_AAC];
5061 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5062 [menuItem setTag: HB_ACODEC_AC3];
5064 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"DTS Passthru" action: NULL keyEquivalent: @""];
5065 [menuItem setTag: HB_ACODEC_DCA];
5067 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5068 [menuItem setTag: HB_ACODEC_LAME];
5070 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5071 [menuItem setTag: HB_ACODEC_VORBIS];
5077 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5078 [menuItem setTag: HB_ACODEC_LAME];
5080 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5081 [menuItem setTag: HB_ACODEC_AC3];
5087 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5088 [menuItem setTag: HB_ACODEC_VORBIS];
5090 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5091 [menuItem setTag: HB_ACODEC_LAME];
5094 [audiocodecPopUp selectItemAtIndex:0];
5098 [audiocodecPopUp setEnabled:NO];
5102 - (IBAction) audioTrackPopUpChanged: (id) sender
5104 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
5105 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
5108 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
5111 /* make sure we have a selected title before continuing */
5112 if (fTitle == NULL) return;
5113 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
5114 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
5116 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
5118 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
5120 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
5122 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
5124 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
5126 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
5128 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
5130 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
5133 /* Now lets make the sender the appropriate Audio Track popup from this point on */
5134 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
5136 sender = fAudLang1PopUp;
5138 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
5140 sender = fAudLang2PopUp;
5142 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
5144 sender = fAudLang3PopUp;
5146 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
5148 sender = fAudLang4PopUp;
5151 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
5152 NSPopUpButton * mixdownPopUp;
5153 NSPopUpButton * audiocodecPopUp;
5154 NSPopUpButton * sampleratePopUp;
5155 NSPopUpButton * bitratePopUp;
5156 if (sender == fAudLang1PopUp)
5158 mixdownPopUp = fAudTrack1MixPopUp;
5159 audiocodecPopUp = fAudTrack1CodecPopUp;
5160 sampleratePopUp = fAudTrack1RatePopUp;
5161 bitratePopUp = fAudTrack1BitratePopUp;
5163 else if (sender == fAudLang2PopUp)
5165 mixdownPopUp = fAudTrack2MixPopUp;
5166 audiocodecPopUp = fAudTrack2CodecPopUp;
5167 sampleratePopUp = fAudTrack2RatePopUp;
5168 bitratePopUp = fAudTrack2BitratePopUp;
5170 else if (sender == fAudLang3PopUp)
5172 mixdownPopUp = fAudTrack3MixPopUp;
5173 audiocodecPopUp = fAudTrack3CodecPopUp;
5174 sampleratePopUp = fAudTrack3RatePopUp;
5175 bitratePopUp = fAudTrack3BitratePopUp;
5179 mixdownPopUp = fAudTrack4MixPopUp;
5180 audiocodecPopUp = fAudTrack4CodecPopUp;
5181 sampleratePopUp = fAudTrack4RatePopUp;
5182 bitratePopUp = fAudTrack4BitratePopUp;
5185 /* get the index of the selected audio Track*/
5186 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
5188 /* pointer for the hb_audio_s struct we will use later on */
5189 hb_audio_config_t * audio;
5192 /* check if the audio mixdown controls need their enabled state changing */
5193 [self setEnabledStateOfAudioMixdownControls:nil];
5195 if (thisAudioIndex != -1)
5199 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
5201 /* actually manipulate the proper mixdowns here */
5202 /* delete the previous audio mixdown options */
5203 [mixdownPopUp removeAllItems];
5205 acodec = [[audiocodecPopUp selectedItem] tag];
5210 /* find out if our selected output audio codec supports mono and / or 6ch */
5211 /* we also check for an input codec of AC3 or DCA,
5212 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
5213 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
5214 but this may change in the future, so they are separated for flexibility */
5215 int audioCodecsSupportMono =
5216 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5217 (acodec != HB_ACODEC_LAME);
5218 int audioCodecsSupport6Ch =
5219 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5220 (acodec != HB_ACODEC_LAME);
5222 /* check for AC-3 passthru */
5223 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5226 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5227 [NSString stringWithCString: "AC3 Passthru"]
5228 action: NULL keyEquivalent: @""];
5229 [menuItem setTag: HB_ACODEC_AC3];
5231 else if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5233 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5234 [NSString stringWithCString: "DTS Passthru"]
5235 action: NULL keyEquivalent: @""];
5236 [menuItem setTag: HB_ACODEC_DCA];
5241 /* add the appropriate audio mixdown menuitems to the popupbutton */
5242 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
5243 so that we can reference the mixdown later */
5245 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
5246 int minMixdownUsed = 0;
5247 int maxMixdownUsed = 0;
5249 /* get the input channel layout without any lfe channels */
5250 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
5252 /* do we want to add a mono option? */
5253 if (audioCodecsSupportMono == 1)
5255 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5256 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
5257 action: NULL keyEquivalent: @""];
5258 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
5259 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
5260 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
5263 /* do we want to add a stereo option? */
5264 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
5265 /* also offer stereo if we have a stereo-or-better source */
5266 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
5268 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5269 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
5270 action: NULL keyEquivalent: @""];
5271 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
5272 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
5273 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
5276 /* do we want to add a dolby surround (DPL1) option? */
5277 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
5279 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5280 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
5281 action: NULL keyEquivalent: @""];
5282 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
5283 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
5284 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
5287 /* do we want to add a dolby pro logic 2 (DPL2) option? */
5288 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
5290 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5291 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
5292 action: NULL keyEquivalent: @""];
5293 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
5294 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
5295 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
5298 /* do we want to add a 6-channel discrete option? */
5299 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
5301 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5302 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
5303 action: NULL keyEquivalent: @""];
5304 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
5305 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
5306 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
5309 /* do we want to add an AC-3 passthrough option? */
5310 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5312 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5313 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5314 action: NULL keyEquivalent: @""];
5315 [menuItem setTag: HB_ACODEC_AC3];
5316 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5317 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5320 /* do we want to add a DTS Passthru option ? HB_ACODEC_DCA*/
5321 if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5323 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5324 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
5325 action: NULL keyEquivalent: @""];
5326 [menuItem setTag: HB_ACODEC_DCA];
5327 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5328 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5331 /* auto-select the best mixdown based on our saved mixdown preference */
5333 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
5334 /* ultimately this should be a prefs option */
5337 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
5338 if (mixdownToUse > 0)
5340 useMixdown = mixdownToUse;
5344 useMixdown = HB_AMIXDOWN_DOLBYPLII;
5347 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
5348 if (useMixdown > maxMixdownUsed)
5350 useMixdown = maxMixdownUsed;
5353 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
5354 if (useMixdown < minMixdownUsed)
5356 useMixdown = minMixdownUsed;
5359 /* select the (possibly-amended) preferred mixdown */
5360 [mixdownPopUp selectItemWithTag: useMixdown];
5363 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
5364 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5367 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
5369 /* If we are using the avi container, we select MP3 as there is no aac available*/
5370 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5372 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5376 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5380 /* In the case of a source track that is not DTS and the user tries to use DTS Passthru (which does not work)
5381 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5384 if (audio->in.codec != HB_ACODEC_DCA && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_DCA)
5386 /* If we are using the avi container, we select MP3 as there is no aac available*/
5387 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5389 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5393 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5397 /* Setup our samplerate and bitrate popups we will need based on mixdown */
5398 [self audioTrackMixdownChanged: mixdownPopUp];
5402 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
5404 [self autoSetM4vExtension: sender];
5408 - (IBAction) audioTrackMixdownChanged: (id) sender
5412 /* setup pointers to all of the other audio track controls
5413 * we will need later
5415 NSPopUpButton * mixdownPopUp;
5416 NSPopUpButton * sampleratePopUp;
5417 NSPopUpButton * bitratePopUp;
5418 NSPopUpButton * audiocodecPopUp;
5419 NSPopUpButton * audiotrackPopUp;
5420 NSSlider * drcSlider;
5421 NSTextField * drcField;
5422 if (sender == fAudTrack1MixPopUp)
5424 audiotrackPopUp = fAudLang1PopUp;
5425 audiocodecPopUp = fAudTrack1CodecPopUp;
5426 mixdownPopUp = fAudTrack1MixPopUp;
5427 sampleratePopUp = fAudTrack1RatePopUp;
5428 bitratePopUp = fAudTrack1BitratePopUp;
5429 drcSlider = fAudTrack1DrcSlider;
5430 drcField = fAudTrack1DrcField;
5432 else if (sender == fAudTrack2MixPopUp)
5434 audiotrackPopUp = fAudLang2PopUp;
5435 audiocodecPopUp = fAudTrack2CodecPopUp;
5436 mixdownPopUp = fAudTrack2MixPopUp;
5437 sampleratePopUp = fAudTrack2RatePopUp;
5438 bitratePopUp = fAudTrack2BitratePopUp;
5439 drcSlider = fAudTrack2DrcSlider;
5440 drcField = fAudTrack2DrcField;
5442 else if (sender == fAudTrack3MixPopUp)
5444 audiotrackPopUp = fAudLang3PopUp;
5445 audiocodecPopUp = fAudTrack3CodecPopUp;
5446 mixdownPopUp = fAudTrack3MixPopUp;
5447 sampleratePopUp = fAudTrack3RatePopUp;
5448 bitratePopUp = fAudTrack3BitratePopUp;
5449 drcSlider = fAudTrack3DrcSlider;
5450 drcField = fAudTrack3DrcField;
5454 audiotrackPopUp = fAudLang4PopUp;
5455 audiocodecPopUp = fAudTrack4CodecPopUp;
5456 mixdownPopUp = fAudTrack4MixPopUp;
5457 sampleratePopUp = fAudTrack4RatePopUp;
5458 bitratePopUp = fAudTrack4BitratePopUp;
5459 drcSlider = fAudTrack4DrcSlider;
5460 drcField = fAudTrack4DrcField;
5462 acodec = [[audiocodecPopUp selectedItem] tag];
5463 /* storage variable for the min and max bitrate allowed for this codec */
5469 case HB_ACODEC_FAAC:
5470 /* check if we have a 6ch discrete conversion in either audio track */
5471 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5473 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
5475 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5481 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
5483 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
5484 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
5489 case HB_ACODEC_CA_AAC:
5490 /* check if we have a 6ch discrete conversion in either audio track */
5491 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5504 case HB_ACODEC_LAME:
5505 /* Lame is happy using our min bitrate of 32 kbps */
5507 /* Lame won't encode if the bitrate is higher than 320 kbps */
5511 case HB_ACODEC_VORBIS:
5512 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5514 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
5516 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5522 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
5524 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
5530 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
5536 /* make sure we have a selected title before continuing */
5537 if (fTitle == NULL) return;
5538 /* get the audio so we can find out what input rates are*/
5539 hb_audio_config_t * audio;
5540 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
5541 int inputbitrate = audio->in.bitrate / 1000;
5542 int inputsamplerate = audio->in.samplerate;
5544 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3 && [[mixdownPopUp selectedItem] tag] != HB_ACODEC_DCA)
5546 [bitratePopUp removeAllItems];
5548 for( int i = 0; i < hb_audio_bitrates_count; i++ )
5550 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
5552 /* add a new menuitem for this bitrate */
5553 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5554 [NSString stringWithCString: hb_audio_bitrates[i].string]
5555 action: NULL keyEquivalent: @""];
5556 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
5557 [menuItem setTag: hb_audio_bitrates[i].rate];
5561 /* select the default bitrate (but use 384 for 6-ch AAC) */
5562 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5564 [bitratePopUp selectItemWithTag: 384];
5568 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
5571 /* populate and set the sample rate popup */
5572 /* Audio samplerate */
5573 [sampleratePopUp removeAllItems];
5574 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
5575 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
5576 [menuItem setTag: inputsamplerate];
5578 for( int i = 0; i < hb_audio_rates_count; i++ )
5580 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
5581 [NSString stringWithCString: hb_audio_rates[i].string]
5582 action: NULL keyEquivalent: @""];
5583 [menuItem setTag: hb_audio_rates[i].rate];
5585 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
5586 * and there is no compelling reason to use anything else as default, though the users default
5587 * preset will likely override any setting chosen here.
5589 [sampleratePopUp selectItemWithTag: inputsamplerate];
5592 /* Since AC3 Pass Thru and DTS Pass Thru uses the input bitrate and sample rate, we get the input tracks
5593 * bitrate and display it in the bitrate popup even though libhb happily ignores any bitrate input from
5594 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
5596 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[mixdownPopUp selectedItem] tag] == HB_ACODEC_DCA)
5599 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
5600 [bitratePopUp removeAllItems];
5601 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5602 [NSString stringWithFormat:@"%d", inputbitrate]
5603 action: NULL keyEquivalent: @""];
5604 [menuItem setTag: inputbitrate];
5605 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
5606 [bitratePopUp setEnabled: NO];
5607 [sampleratePopUp setEnabled: NO];
5609 [drcSlider setFloatValue: 1.00];
5610 [self audioDRCSliderChanged: drcSlider];
5611 [drcSlider setEnabled: NO];
5612 [drcField setEnabled: NO];
5616 [sampleratePopUp setEnabled: YES];
5617 [bitratePopUp setEnabled: YES];
5618 [drcSlider setEnabled: YES];
5619 [drcField setEnabled: YES];
5621 [self calculateBitrate:nil];
5624 - (IBAction) audioDRCSliderChanged: (id) sender
5626 NSSlider * drcSlider;
5627 NSTextField * drcField;
5628 if (sender == fAudTrack1DrcSlider)
5630 drcSlider = fAudTrack1DrcSlider;
5631 drcField = fAudTrack1DrcField;
5633 else if (sender == fAudTrack2DrcSlider)
5635 drcSlider = fAudTrack2DrcSlider;
5636 drcField = fAudTrack2DrcField;
5638 else if (sender == fAudTrack3DrcSlider)
5640 drcSlider = fAudTrack3DrcSlider;
5641 drcField = fAudTrack3DrcField;
5645 drcSlider = fAudTrack4DrcSlider;
5646 drcField = fAudTrack4DrcField;
5649 /* If we are between 0.0 and 1.0 on the slider, snap it to 1.0 */
5650 if ([drcSlider floatValue] > 0.0 && [drcSlider floatValue] < 1.0)
5652 [drcSlider setFloatValue:1.0];
5656 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
5657 /* For now, do not call this until we have an intelligent way to determine audio track selections
5658 * compared to presets
5660 //[self customSettingUsed: sender];
5665 #pragma mark Open New Windows
5667 - (IBAction) openHomepage: (id) sender
5669 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5670 URLWithString:@"http://handbrake.fr/"]];
5673 - (IBAction) openForums: (id) sender
5675 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5676 URLWithString:@"http://handbrake.fr/forum/"]];
5678 - (IBAction) openUserGuide: (id) sender
5680 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5681 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
5685 * Shows debug output window.
5687 - (IBAction)showDebugOutputPanel:(id)sender
5689 [outputPanel showOutputPanel:sender];
5693 * Shows preferences window.
5695 - (IBAction) showPreferencesWindow: (id) sender
5697 NSWindow * window = [fPreferencesController window];
5698 if (![window isVisible])
5701 [window makeKeyAndOrderFront: nil];
5705 * Shows queue window.
5707 - (IBAction) showQueueWindow:(id)sender
5709 [fQueueController showQueueWindow:sender];
5713 - (IBAction) toggleDrawer:(id)sender {
5714 [fPresetDrawer toggle:self];
5718 * Shows Picture Settings Window.
5721 - (IBAction) showPicturePanel: (id) sender
5723 [fPictureController showPictureWindow:sender];
5726 - (void) picturePanelFullScreen
5728 [fPictureController setToFullScreenMode];
5731 - (void) picturePanelWindowed
5733 [fPictureController setToWindowedMode];
5736 - (IBAction) showPreviewWindow: (id) sender
5738 [fPictureController showPreviewWindow:sender];
5742 #pragma mark Preset Outline View Methods
5743 #pragma mark - Required
5744 /* These are required by the NSOutlineView Datasource Delegate */
5747 /* used to specify the number of levels to show for each item */
5748 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
5750 /* currently use no levels to test outline view viability */
5751 if (item == nil) // for an outline view the root level of the hierarchy is always nil
5753 return [UserPresets count];
5757 /* we need to return the count of the array in ChildrenArray for this folder */
5758 NSArray *children = nil;
5759 children = [item objectForKey:@"ChildrenArray"];
5760 if ([children count] > 0)
5762 return [children count];
5771 /* We use this to deterimine children of an item */
5772 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
5775 /* we need to return the count of the array in ChildrenArray for this folder */
5776 NSArray *children = nil;
5779 children = UserPresets;
5783 if ([item objectForKey:@"ChildrenArray"])
5785 children = [item objectForKey:@"ChildrenArray"];
5788 if ((children == nil) || ( [children count] <= (NSUInteger) index))
5794 return [children objectAtIndex:index];
5798 // We are only one level deep, so we can't be asked about children
5799 //NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
5803 /* We use this to determine if an item should be expandable */
5804 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
5807 /* we need to return the count of the array in ChildrenArray for this folder */
5808 NSArray *children= nil;
5811 children = UserPresets;
5815 if ([item objectForKey:@"ChildrenArray"])
5817 children = [item objectForKey:@"ChildrenArray"];
5821 /* To deterimine if an item should show a disclosure triangle
5822 * we could do it by the children count as so:
5823 * if ([children count] < 1)
5824 * However, lets leave the triangle show even if there are no
5825 * children to help indicate a folder, just like folder in the
5826 * finder can show a disclosure triangle even when empty
5829 /* We need to determine if the item is a folder */
5830 if ([[item objectForKey:@"Folder"] intValue] == 1)
5841 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
5843 // Our outline view has no levels, but we can still expand every item. Doing so
5844 // just makes the row taller. See heightOfRowByItem below.
5845 //return ![(HBQueueOutlineView*)outlineView isDragging];
5851 /* Used to tell the outline view which information is to be displayed per item */
5852 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5854 /* We have two columns right now, icon and PresetName */
5856 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5858 return [item objectForKey:@"PresetName"];
5867 - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object
5869 return [NSKeyedUnarchiver unarchiveObjectWithData:object];
5871 - (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item
5873 return [NSKeyedArchiver archivedDataWithRootObject:item];
5876 #pragma mark - Added Functionality (optional)
5877 /* Use to customize the font and display characteristics of the title cell */
5878 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
5880 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5884 NSColor *shadowColor;
5885 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
5886 /*check to see if its a selected row */
5887 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
5890 fontColor = [NSColor blackColor];
5891 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
5895 if ([[item objectForKey:@"Type"] intValue] == 0)
5897 fontColor = [NSColor blueColor];
5899 else // User created preset, use a black font
5901 fontColor = [NSColor blackColor];
5903 /* check to see if its a folder */
5904 //if ([[item objectForKey:@"Folder"] intValue] == 1)
5906 //fontColor = [NSColor greenColor];
5911 /* We use Bold Text for the HB Default */
5912 if ([[item objectForKey:@"Default"] intValue] == 1)// 1 is HB default
5914 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5916 /* We use Bold Text for the User Specified Default */
5917 if ([[item objectForKey:@"Default"] intValue] == 2)// 2 is User default
5919 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5923 [cell setTextColor:fontColor];
5924 [cell setFont:txtFont];
5929 /* We use this to edit the name field in the outline view */
5930 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5932 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5937 [theRecord setObject:object forKey:@"PresetName"];
5941 [fPresetsOutlineView reloadData];
5942 /* We save all of the preset data here */
5946 /* We use this to provide tooltips for the items in the presets outline view */
5947 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
5949 //if ([[tc identifier] isEqualToString:@"PresetName"])
5951 /* initialize the tooltip contents variable */
5953 /* if there is a description for the preset, we show it in the tooltip */
5954 if ([item objectForKey:@"PresetDescription"])
5956 loc_tip = [item objectForKey:@"PresetDescription"];
5961 loc_tip = @"No description available";
5968 #pragma mark Preset Outline View Methods (dragging related)
5971 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
5973 // Dragging is only allowed for custom presets.
5974 //[[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1
5975 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
5979 // Don't retain since this is just holding temporaral drag information, and it is
5980 //only used during a drag! We could put this in the pboard actually.
5981 fDraggedNodes = items;
5982 // Provide data for our custom type, and simple NSStrings.
5983 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
5985 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
5986 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
5991 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
5994 // Don't allow dropping ONTO an item since they can't really contain any children.
5996 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
5997 if (isOnDropTypeProposal)
5998 return NSDragOperationNone;
6000 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
6003 index = [fPresetsOutlineView rowForItem: item] + 1;
6007 // Don't allow dropping into the Built In Presets.
6008 if (index < presetCurrentBuiltInCount)
6010 return NSDragOperationNone;
6011 index = MAX (index, presetCurrentBuiltInCount);
6014 [outlineView setDropItem:item dropChildIndex:index];
6015 return NSDragOperationGeneric;
6020 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
6022 /* first, lets see if we are dropping into a folder */
6023 if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
6025 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6026 childrenArray = [[fPresetsOutlineView itemAtRow:index] objectForKey:@"ChildrenArray"];
6027 [childrenArray addObject:item];
6028 [[fPresetsOutlineView itemAtRow:index] setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6029 [childrenArray autorelease];
6031 else // We are not, so we just move the preset into the existing array
6033 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
6035 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
6036 while (obj = [enumerator nextObject])
6038 [moveItems addIndex:[UserPresets indexOfObject:obj]];
6040 // Successful drop, lets rearrange the view and save it all
6041 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
6043 [fPresetsOutlineView reloadData];
6048 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
6050 NSUInteger index = [indexSet lastIndex];
6051 NSUInteger aboveInsertIndexCount = 0;
6053 NSUInteger removeIndex;
6055 if (index >= insertIndex)
6057 removeIndex = index + aboveInsertIndexCount;
6058 aboveInsertIndexCount++;
6062 removeIndex = index;
6066 id object = [[array objectAtIndex:removeIndex] retain];
6067 [array removeObjectAtIndex:removeIndex];
6068 [array insertObject:object atIndex:insertIndex];
6071 index = [indexSet indexLessThanIndex:index];
6076 #pragma mark - Functional Preset NSOutlineView Methods
6078 - (IBAction)selectPreset:(id)sender
6081 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
6083 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6084 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6086 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
6088 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
6092 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6096 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
6097 [self formatPopUpChanged:nil];
6099 /* Chapter Markers*/
6100 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
6101 /* check to see if we have only one chapter */
6102 [self chapterPopUpChanged:nil];
6104 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6105 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
6106 /* Mux mp4 with http optimization */
6107 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
6110 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
6111 /* We set the advanced opt string here if applicable*/
6112 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
6114 /* Lets run through the following functions to get variables set there */
6115 [self videoEncoderPopUpChanged:nil];
6116 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
6117 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
6118 [self calculateBitrate:nil];
6121 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
6123 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
6124 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
6126 /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float.
6127 * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type
6128 * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret
6129 * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet,
6130 * though it should be a corner case since it would pretty much be a preset for lossless encoding. */
6131 if ([[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue] < 1.0)
6133 /* For the quality slider we need to convert the old percent's to the new rf scales */
6134 float rf = (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]);
6135 [fVidQualitySlider setFloatValue:rf];
6140 /* Since theora's qp value goes up from left to right, we can just set the slider float value */
6141 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
6143 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6147 /* since ffmpeg and x264 use an "inverted" slider (lower qp/rf values indicate a higher quality) we invert the value on the slider */
6148 [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] + [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6152 [self videoMatrixChanged:nil];
6154 /* Video framerate */
6155 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
6156 detected framerate in the fVidRatePopUp so we use index 0*/
6157 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
6159 [fVidRatePopUp selectItemAtIndex: 0];
6163 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
6167 /* 2 Pass Encoding */
6168 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
6169 [self twoPassCheckboxChanged:nil];
6171 /* Turbo 1st pass for 2 Pass Encoding */
6172 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
6175 /* First we check to see if we are using the current audio track layout based on AudioList array */
6176 if ([chosenPreset objectForKey:@"AudioList"])
6178 /* Populate the audio widgets based on the contents of the AudioList array */
6180 NSEnumerator *enumerator = [[chosenPreset objectForKey:@"AudioList"] objectEnumerator];
6182 while (tempObject = [enumerator nextObject])
6187 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6189 [fAudLang1PopUp selectItemAtIndex: 1];
6191 [self audioTrackPopUpChanged: fAudLang1PopUp];
6192 [fAudTrack1CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6193 /* check our pref for core audio and use it in place of faac if applicable */
6194 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6195 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6197 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6200 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6201 [fAudTrack1MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6202 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6204 if ([fAudTrack1MixPopUp selectedItem] == nil)
6206 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6208 [fAudTrack1RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6209 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6210 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6212 [fAudTrack1BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6214 [fAudTrack1DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6215 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6221 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6223 [fAudLang2PopUp selectItemAtIndex: 1];
6225 [self audioTrackPopUpChanged: fAudLang2PopUp];
6226 [fAudTrack2CodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6227 /* check our pref for core audio and use it in place of faac if applicable */
6228 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6229 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6231 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6233 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6234 [fAudTrack2MixPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6235 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6237 if ([fAudTrack2MixPopUp selectedItem] == nil)
6239 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6241 [fAudTrack2RatePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6242 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6243 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6245 [fAudTrack2BitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6247 [fAudTrack2DrcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6248 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6254 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6258 [fAudLang4PopUp selectItemAtIndex: 0];
6259 [self audioTrackPopUpChanged: fAudLang4PopUp];
6263 [fAudLang3PopUp selectItemAtIndex: 0];
6264 [self audioTrackPopUpChanged: fAudLang3PopUp];
6268 [fAudLang2PopUp selectItemAtIndex: 0];
6269 [self audioTrackPopUpChanged: fAudLang2PopUp];
6277 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
6279 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6281 [fAudLang1PopUp selectItemAtIndex: 1];
6283 [self audioTrackPopUpChanged: fAudLang1PopUp];
6284 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
6285 /* check our pref for core audio and use it in place of faac if applicable */
6286 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6287 [[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString: @"AAC (faac)"])
6289 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6291 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6292 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
6293 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6295 if ([fAudTrack1MixPopUp selectedItem] == nil)
6297 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6299 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
6300 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6301 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
6303 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
6305 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
6306 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6308 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
6310 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6312 [fAudLang2PopUp selectItemAtIndex: 1];
6314 [self audioTrackPopUpChanged: fAudLang2PopUp];
6315 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
6316 /* check our pref for core audio and use it in place of faac if applicable */
6317 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6318 [[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString: @"AAC (faac)"])
6320 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6322 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6323 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
6324 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6326 if ([fAudTrack2MixPopUp selectedItem] == nil)
6328 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6330 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
6331 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6332 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
6334 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
6336 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
6337 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6339 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
6341 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
6343 [fAudLang3PopUp selectItemAtIndex: 1];
6345 [self audioTrackPopUpChanged: fAudLang3PopUp];
6346 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
6347 /* check our pref for core audio and use it in place of faac if applicable */
6348 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6349 [[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AAC (faac)"])
6351 [fAudTrack3CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6353 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6354 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
6355 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6357 if ([fAudTrack3MixPopUp selectedItem] == nil)
6359 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6361 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
6362 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6363 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
6365 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
6367 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
6368 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
6370 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
6372 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
6374 [fAudLang4PopUp selectItemAtIndex: 1];
6376 [self audioTrackPopUpChanged: fAudLang4PopUp];
6377 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
6378 /* check our pref for core audio and use it in place of faac if applicable */
6379 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6380 [[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString: @"AAC (faac)"])
6382 [fAudTrack4CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6384 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6385 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
6386 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6388 if ([fAudTrack4MixPopUp selectedItem] == nil)
6390 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6392 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
6393 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6394 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
6396 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
6398 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
6399 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
6402 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6404 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
6406 [fAudLang2PopUp selectItemAtIndex: 0];
6407 [self audioTrackPopUpChanged: fAudLang2PopUp];
6409 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
6411 [fAudLang3PopUp selectItemAtIndex: 0];
6412 [self audioTrackPopUpChanged: fAudLang3PopUp];
6414 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
6416 [fAudLang4PopUp selectItemAtIndex: 0];
6417 [self audioTrackPopUpChanged: fAudLang4PopUp];
6422 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
6423 /* Forced Subtitles */
6424 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
6426 /* Picture Settings */
6427 /* Note: objectForKey:@"UsesPictureSettings" refers to picture size, which encompasses:
6428 * height, width, keep ar, anamorphic and crop settings.
6429 * picture filters are handled separately below.
6431 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
6432 * ( 2 is use max for source and 1 is use exact size when the preset was created ) and the
6433 * preset completely ignores any picture sizing values in the preset.
6435 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
6437 hb_job_t * job = fTitle->job;
6439 /* If Cropping is set to custom, then recall all four crop values from
6440 when the preset was created and apply them */
6441 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
6443 [fPictureController setAutoCrop:NO];
6445 /* Here we use the custom crop values saved at the time the preset was saved */
6446 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
6447 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
6448 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
6449 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
6452 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
6454 [fPictureController setAutoCrop:YES];
6455 /* Here we use the auto crop values determined right after scan */
6456 job->crop[0] = AutoCropTop;
6457 job->crop[1] = AutoCropBottom;
6458 job->crop[2] = AutoCropLeft;
6459 job->crop[3] = AutoCropRight;
6464 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
6465 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
6467 /* Use Max Picture settings for whatever the dvd is.*/
6468 [self revertPictureSizeToMax:nil];
6469 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6470 if (job->keep_ratio == 1)
6472 hb_fix_aspect( job, HB_KEEP_WIDTH );
6473 if( job->height > fTitle->height )
6475 job->height = fTitle->height;
6476 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6479 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6481 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
6483 /* we check to make sure the presets width/height does not exceed the sources width/height */
6484 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
6486 /* if so, then we use the sources height and width to avoid scaling up */
6487 //job->width = fTitle->width;
6488 //job->height = fTitle->height;
6489 [self revertPictureSizeToMax:nil];
6491 else // source width/height is >= the preset height/width
6493 /* we can go ahead and use the presets values for height and width */
6494 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
6495 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
6497 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6498 if (job->keep_ratio == 1)
6500 hb_fix_aspect( job, HB_KEEP_WIDTH );
6501 if( job->height > fTitle->height )
6503 job->height = fTitle->height;
6504 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6507 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6513 /* If the preset has an objectForKey:@"UsesPictureFilters", and handle the filters here */
6514 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
6518 /* We only allow *either* Decomb or Deinterlace. So check for the PictureDecombDeinterlace key.
6519 * also, older presets may not have this key, in which case we also check to see if that preset had PictureDecomb
6520 * specified, in which case we use decomb and ignore any possible Deinterlace settings as using both was less than
6523 [fPictureController setUseDecomb:1];
6524 [fPictureController setDecomb:0];
6525 [fPictureController setDeinterlace:0];
6526 if ([[chosenPreset objectForKey:@"PictureDecombDeinterlace"] intValue] == 1 || [[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6528 /* we are using decomb */
6530 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6532 [fPictureController setDecomb:[[chosenPreset objectForKey:@"PictureDecomb"] intValue]];
6534 /* if we are using "Custom" in the decomb setting, also set the custom string*/
6535 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] == 2)
6537 [fPictureController setDecombCustomString:[chosenPreset objectForKey:@"PictureDecombCustom"]];
6543 /* We are using Deinterlace */
6545 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] > 0)
6547 [fPictureController setUseDecomb:0];
6548 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
6549 /* if we are using "Custom" in the deinterlace setting, also set the custom string*/
6550 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
6552 [fPictureController setDeinterlaceCustomString:[chosenPreset objectForKey:@"PictureDeinterlaceCustom"]];
6559 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] > 0)
6561 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
6562 /* if we are using "Custom" in the detelecine setting, also set the custom string*/
6563 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 2)
6565 [fPictureController setDetelecineCustomString:[chosenPreset objectForKey:@"PictureDetelecineCustom"]];
6570 [fPictureController setDetelecine:0];
6574 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] > 0)
6576 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
6577 /* if we are using "Custom" in the denoise setting, also set the custom string*/
6578 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] == 4)
6580 [fPictureController setDenoiseCustomString:[chosenPreset objectForKey:@"PictureDenoiseCustom"]];
6585 [fPictureController setDenoise:0];
6589 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
6591 /* if its a one, then its the old on/off deblock, set on to 5*/
6592 [fPictureController setDeblock:5];
6596 /* use the settings intValue */
6597 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
6600 if ([[chosenPreset objectForKey:@"VideoGrayScale"] intValue] == 1)
6602 [fPictureController setGrayscale:1];
6606 [fPictureController setGrayscale:0];
6609 /* we call SetTitle: in fPictureController so we get an instant update in the Picture Settings window */
6610 [fPictureController SetTitle:fTitle];
6611 [fPictureController SetTitle:fTitle];
6612 [self calculatePictureSizing:nil];
6618 #pragma mark Manage Presets
6620 - (void) loadPresets {
6621 /* We declare the default NSFileManager into fileManager */
6622 NSFileManager * fileManager = [NSFileManager defaultManager];
6623 /*We define the location of the user presets file */
6624 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
6625 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
6626 /* We check for the presets.plist */
6627 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
6629 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
6632 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
6633 if (nil == UserPresets)
6635 UserPresets = [[NSMutableArray alloc] init];
6636 [self addFactoryPresets:nil];
6638 [fPresetsOutlineView reloadData];
6640 [self checkBuiltInsForUpdates];
6643 - (void) checkBuiltInsForUpdates {
6645 BOOL updateBuiltInPresets = NO;
6647 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6649 while (tempObject = [enumerator nextObject])
6651 /* iterate through the built in presets to see if any have an old build number */
6652 NSMutableDictionary *thisPresetDict = tempObject;
6653 /*Key Type == 0 is built in, and key PresetBuildNumber is the build number it was created with */
6654 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0)
6656 if (![thisPresetDict objectForKey:@"PresetBuildNumber"] || [[thisPresetDict objectForKey:@"PresetBuildNumber"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue])
6658 updateBuiltInPresets = YES;
6663 /* if we have built in presets to update, then do so AlertBuiltInPresetUpdate*/
6664 if ( updateBuiltInPresets == YES)
6666 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"AlertBuiltInPresetUpdate"] == YES)
6668 /* Show an alert window that built in presets will be updated */
6669 /*On Screen Notification*/
6672 status = NSRunAlertPanel(@"HandBrake has determined your built in presets are out of date...",@"HandBrake will now update your built-in presets.", @"OK", nil, nil);
6673 [NSApp requestUserAttention:NSCriticalRequest];
6675 /* when alert is dismissed, go ahead and update the built in presets */
6676 [self addFactoryPresets:nil];
6682 - (IBAction) showAddPresetPanel: (id) sender
6684 /* Deselect the currently selected Preset if there is one*/
6685 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
6687 /* Populate the preset picture settings popup here */
6688 [fPresetNewPicSettingsPopUp removeAllItems];
6689 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
6690 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
6691 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
6692 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
6693 /* Uncheck the preset use filters checkbox */
6694 [fPresetNewPicFiltersCheck setState:NSOffState];
6695 // fPresetNewFolderCheck
6696 [fPresetNewFolderCheck setState:NSOffState];
6697 /* Erase info from the input fields*/
6698 [fPresetNewName setStringValue: @""];
6699 [fPresetNewDesc setStringValue: @""];
6700 /* Show the panel */
6701 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
6704 - (IBAction) closeAddPresetPanel: (id) sender
6706 [NSApp endSheet: fAddPresetPanel];
6707 [fAddPresetPanel orderOut: self];
6710 - (IBAction)addUserPreset:(id)sender
6712 if (![[fPresetNewName stringValue] length])
6713 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
6716 /* Here we create a custom user preset */
6717 [UserPresets addObject:[self createPreset]];
6720 [self closeAddPresetPanel:nil];
6727 /* We Reload the New Table data for presets */
6728 [fPresetsOutlineView reloadData];
6729 /* We save all of the preset data here */
6737 /* We Sort the Presets By Factory or Custom */
6738 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
6739 ascending:YES] autorelease];
6740 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
6742 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
6743 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
6744 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
6747 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
6748 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
6749 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
6750 [UserPresets setArray:sortedArray];
6755 - (IBAction)insertPreset:(id)sender
6757 int index = [fPresetsOutlineView selectedRow];
6758 [UserPresets insertObject:[self createPreset] atIndex:index];
6759 [fPresetsOutlineView reloadData];
6763 - (NSDictionary *)createPreset
6765 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
6766 /* Preset build number */
6767 [preset setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
6768 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6769 /* Get the New Preset Name from the field in the AddPresetPanel */
6770 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6771 /* Set whether or not this is to be a folder fPresetNewFolderCheck*/
6772 [preset setObject:[NSNumber numberWithBool:[fPresetNewFolderCheck state]] forKey:@"Folder"];
6773 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
6774 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
6775 /*Set whether or not this is default, at creation set to 0*/
6776 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6777 if ([fPresetNewFolderCheck state] == YES)
6779 /* initialize and set an empty array for children here since we are a new folder */
6780 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6781 [preset setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6782 [childrenArray autorelease];
6784 else // we are not creating a preset folder, so we go ahead with the rest of the preset info
6786 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
6787 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
6788 /* Get whether or not to use the current Picture Filter settings for the preset */
6789 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
6791 /* Get New Preset Description from the field in the AddPresetPanel*/
6792 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
6794 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
6795 /* Chapter Markers fCreateChapterMarkers*/
6796 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
6797 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6798 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
6799 /* Mux mp4 with http optimization */
6800 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
6801 /* Add iPod uuid atom */
6802 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
6806 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
6807 /* x264 Option String */
6808 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
6810 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
6811 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
6812 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
6813 [preset setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
6815 /* Video framerate */
6816 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
6818 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
6820 else // we can record the actual titleOfSelectedItem
6822 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
6825 /* 2 Pass Encoding */
6826 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
6827 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
6828 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
6829 /*Picture Settings*/
6830 hb_job_t * job = fTitle->job;
6831 /* Picture Sizing */
6832 /* Use Max Picture settings for whatever the dvd is.*/
6833 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
6834 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
6835 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
6836 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
6837 [preset setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
6839 /* Set crop settings here */
6840 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
6841 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
6842 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
6843 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
6844 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
6846 /* Picture Filters */
6847 [preset setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
6848 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
6849 [preset setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
6850 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
6851 [preset setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
6852 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
6853 [preset setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
6854 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
6855 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
6856 [preset setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
6857 [preset setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
6860 NSMutableArray *audioListArray = [[NSMutableArray alloc] init];
6861 /* we actually call the methods for the nests here */
6862 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
6864 NSMutableDictionary *audioTrack1Array = [[NSMutableDictionary alloc] init];
6865 [audioTrack1Array setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6866 [audioTrack1Array setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6867 [audioTrack1Array setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6868 [audioTrack1Array setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6869 [audioTrack1Array setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6870 [audioTrack1Array setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6871 [audioTrack1Array setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6872 [audioTrack1Array autorelease];
6873 [audioListArray addObject:audioTrack1Array];
6876 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
6878 NSMutableDictionary *audioTrack2Array = [[NSMutableDictionary alloc] init];
6879 [audioTrack2Array setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6880 [audioTrack2Array setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6881 [audioTrack2Array setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6882 [audioTrack2Array setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6883 [audioTrack2Array setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6884 [audioTrack2Array setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6885 [audioTrack2Array setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6886 [audioTrack2Array autorelease];
6887 [audioListArray addObject:audioTrack2Array];
6890 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
6892 NSMutableDictionary *audioTrack3Array = [[NSMutableDictionary alloc] init];
6893 [audioTrack3Array setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6894 [audioTrack3Array setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6895 [audioTrack3Array setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6896 [audioTrack3Array setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6897 [audioTrack3Array setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6898 [audioTrack3Array setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6899 [audioTrack3Array setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6900 [audioTrack3Array autorelease];
6901 [audioListArray addObject:audioTrack3Array];
6904 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
6906 NSMutableDictionary *audioTrack4Array = [[NSMutableDictionary alloc] init];
6907 [audioTrack4Array setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
6908 [audioTrack4Array setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
6909 [audioTrack4Array setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
6910 [audioTrack4Array setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
6911 [audioTrack4Array setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
6912 [audioTrack4Array setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
6913 [audioTrack4Array setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
6914 [audioTrack4Array autorelease];
6915 [audioListArray addObject:audioTrack4Array];
6919 [preset setObject:[NSMutableArray arrayWithArray: audioListArray] forKey:@"AudioList"];
6922 /* Temporarily remove subtitles from creating a new preset as it has to be converted over to use the new
6923 * subititle array code. */
6925 //[preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
6926 /* Forced Subtitles */
6927 //[preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
6929 [preset autorelease];
6936 [UserPresets writeToFile:UserPresetsFile atomically:YES];
6937 /* We get the default preset in case it changed */
6938 [self getDefaultPresets:nil];
6942 - (IBAction)deletePreset:(id)sender
6946 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
6950 /* Alert user before deleting preset */
6952 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
6954 if ( status == NSAlertDefaultReturn )
6956 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6957 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6958 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
6960 NSEnumerator *enumerator;
6961 NSMutableArray *presetsArrayToMod;
6962 NSMutableArray *tempArray;
6964 /* If we are a root level preset, we are modding the UserPresets array */
6965 if (presetToModLevel == 0)
6967 presetsArrayToMod = UserPresets;
6969 else // We have a parent preset, so we modify the chidren array object for key
6971 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
6974 enumerator = [presetsArrayToMod objectEnumerator];
6975 tempArray = [NSMutableArray array];
6977 while (tempObject = [enumerator nextObject])
6979 NSDictionary *thisPresetDict = tempObject;
6980 if (thisPresetDict == presetToMod)
6982 [tempArray addObject:tempObject];
6986 [presetsArrayToMod removeObjectsInArray:tempArray];
6987 [fPresetsOutlineView reloadData];
6994 #pragma mark Import Export Preset(s)
6996 - (IBAction) browseExportPresetFile: (id) sender
6998 /* Open a panel to let the user choose where and how to save the export file */
6999 NSSavePanel * panel = [NSSavePanel savePanel];
7000 /* We get the current file name and path from the destination field here */
7001 NSString *defaultExportDirectory = [NSString stringWithFormat: @"%@/Desktop/", NSHomeDirectory()];
7003 [panel beginSheetForDirectory: defaultExportDirectory file: @"HB_Export.plist"
7004 modalForWindow: fWindow modalDelegate: self
7005 didEndSelector: @selector( browseExportPresetFileDone:returnCode:contextInfo: )
7009 - (void) browseExportPresetFileDone: (NSSavePanel *) sheet
7010 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7012 if( returnCode == NSOKButton )
7014 NSString *presetExportDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7015 NSString *exportPresetsFile = [sheet filename];
7016 [[NSUserDefaults standardUserDefaults] setObject:presetExportDirectory forKey:@"LastPresetExportDirectory"];
7017 /* We check for the presets.plist */
7018 if ([[NSFileManager defaultManager] fileExistsAtPath:exportPresetsFile] == 0)
7020 [[NSFileManager defaultManager] createFileAtPath:exportPresetsFile contents:nil attributes:nil];
7022 NSMutableArray * presetsToExport = [[NSMutableArray alloc] initWithContentsOfFile:exportPresetsFile];
7023 if (nil == presetsToExport)
7025 presetsToExport = [[NSMutableArray alloc] init];
7027 /* now get and add selected presets to export */
7030 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
7032 [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7033 [presetsToExport writeToFile:exportPresetsFile atomically:YES];
7041 - (IBAction) browseImportPresetFile: (id) sender
7044 NSOpenPanel * panel;
7046 panel = [NSOpenPanel openPanel];
7047 [panel setAllowsMultipleSelection: NO];
7048 [panel setCanChooseFiles: YES];
7049 [panel setCanChooseDirectories: NO ];
7050 NSString * sourceDirectory;
7051 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"])
7053 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"];
7057 sourceDirectory = @"~/Desktop";
7058 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
7060 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
7061 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
7063 /* set this for allowed file types, not sure if we should allow xml or not */
7064 NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"xml", nil];
7065 [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes
7066 modalForWindow: fWindow modalDelegate: self
7067 didEndSelector: @selector( browseImportPresetDone:returnCode:contextInfo: )
7068 contextInfo: sender];
7071 - (void) browseImportPresetDone: (NSSavePanel *) sheet
7072 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7074 if( returnCode == NSOKButton )
7076 NSString *importPresetsDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7077 NSString *importPresetsFile = [sheet filename];
7078 [[NSUserDefaults standardUserDefaults] setObject:importPresetsDirectory forKey:@"LastPresetImportDirectory"];
7079 /* NOTE: here we need to do some sanity checking to verify we do not hose up our presets file */
7080 NSMutableArray * presetsToImport = [[NSMutableArray alloc] initWithContentsOfFile:importPresetsFile];
7081 /* iterate though the new array of presets to import and add them to our presets array */
7083 NSEnumerator *enumerator = [presetsToImport objectEnumerator];
7085 while (tempObject = [enumerator nextObject])
7087 /* make any changes to the incoming preset we see fit */
7088 /* make sure the incoming preset is not tagged as default */
7089 [tempObject setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7090 /* prepend "(imported) to the name of the incoming preset for clarification since it can be changed */
7091 NSString * prependedName = [@"(import) " stringByAppendingString:[tempObject objectForKey:@"PresetName"]] ;
7092 [tempObject setObject:prependedName forKey:@"PresetName"];
7094 /* actually add the new preset to our presets array */
7095 [UserPresets addObject:tempObject];
7098 [presetsToImport autorelease];
7106 #pragma mark Manage Default Preset
7108 - (IBAction)getDefaultPresets:(id)sender
7110 presetHbDefault = nil;
7111 presetUserDefault = nil;
7112 presetUserDefaultParent = nil;
7113 presetUserDefaultParentParent = nil;
7114 NSMutableDictionary *presetHbDefaultParent = nil;
7115 NSMutableDictionary *presetHbDefaultParentParent = nil;
7118 BOOL userDefaultFound = NO;
7119 presetCurrentBuiltInCount = 0;
7120 /* First we iterate through the root UserPresets array to check for defaults */
7121 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7123 while (tempObject = [enumerator nextObject])
7125 NSMutableDictionary *thisPresetDict = tempObject;
7126 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7128 presetHbDefault = thisPresetDict;
7130 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7132 presetUserDefault = thisPresetDict;
7133 userDefaultFound = YES;
7135 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7137 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
7141 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7142 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7144 NSMutableDictionary *thisPresetDictParent = thisPresetDict;
7145 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7147 while (tempObject = [enumerator nextObject])
7149 NSMutableDictionary *thisPresetDict = tempObject;
7150 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7152 presetHbDefault = thisPresetDict;
7153 presetHbDefaultParent = thisPresetDictParent;
7155 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7157 presetUserDefault = thisPresetDict;
7158 presetUserDefaultParent = thisPresetDictParent;
7159 userDefaultFound = YES;
7162 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7163 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7165 NSMutableDictionary *thisPresetDictParentParent = thisPresetDict;
7166 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7168 while (tempObject = [enumerator nextObject])
7170 NSMutableDictionary *thisPresetDict = tempObject;
7171 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7173 presetHbDefault = thisPresetDict;
7174 presetHbDefaultParent = thisPresetDictParent;
7175 presetHbDefaultParentParent = thisPresetDictParentParent;
7177 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7179 presetUserDefault = thisPresetDict;
7180 presetUserDefaultParent = thisPresetDictParent;
7181 presetUserDefaultParentParent = thisPresetDictParentParent;
7182 userDefaultFound = YES;
7191 /* check to see if a user specified preset was found, if not then assign the parents for
7192 * the presetHbDefault so that we can open the parents for the nested presets
7194 if (userDefaultFound == NO)
7196 presetUserDefaultParent = presetHbDefaultParent;
7197 presetUserDefaultParentParent = presetHbDefaultParentParent;
7201 - (IBAction)setDefaultPreset:(id)sender
7203 /* We need to determine if the item is a folder */
7204 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] == 1)
7210 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7212 /* First make sure the old user specified default preset is removed */
7213 while (tempObject = [enumerator nextObject])
7215 NSMutableDictionary *thisPresetDict = tempObject;
7216 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7218 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7221 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7222 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7224 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7227 while (tempObject = [enumerator nextObject])
7229 NSMutableDictionary *thisPresetDict1 = tempObject;
7230 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7232 [[[thisPresetDict objectForKey:@"ChildrenArray"] objectAtIndex:ii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7234 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7235 if ([thisPresetDict1 objectForKey:@"ChildrenArray"])
7237 NSEnumerator *enumerator = [[thisPresetDict1 objectForKey:@"ChildrenArray"] objectEnumerator];
7240 while (tempObject = [enumerator nextObject])
7242 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7244 [[[thisPresetDict1 objectForKey:@"ChildrenArray"] objectAtIndex:iii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7257 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7258 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
7259 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
7262 NSMutableArray *presetsArrayToMod;
7263 NSMutableArray *tempArray;
7265 /* If we are a root level preset, we are modding the UserPresets array */
7266 if (presetToModLevel == 0)
7268 presetsArrayToMod = UserPresets;
7270 else // We have a parent preset, so we modify the chidren array object for key
7272 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
7275 enumerator = [presetsArrayToMod objectEnumerator];
7276 tempArray = [NSMutableArray array];
7278 while (tempObject = [enumerator nextObject])
7280 NSDictionary *thisPresetDict = tempObject;
7281 if (thisPresetDict == presetToMod)
7283 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 2
7285 [[presetsArrayToMod objectAtIndex:iiii] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
7292 /* We save all of the preset data here */
7294 /* We Reload the New Table data for presets */
7295 [fPresetsOutlineView reloadData];
7298 - (IBAction)selectDefaultPreset:(id)sender
7300 NSMutableDictionary *presetToMod;
7301 /* if there is a user specified default, we use it */
7302 if (presetUserDefault)
7304 presetToMod = presetUserDefault;
7306 else if (presetHbDefault) //else we use the built in default presetHbDefault
7308 presetToMod = presetHbDefault;
7315 if (presetUserDefaultParent != nil)
7317 [fPresetsOutlineView expandItem:presetUserDefaultParent];
7320 if (presetUserDefaultParentParent != nil)
7322 [fPresetsOutlineView expandItem:presetUserDefaultParentParent];
7326 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[fPresetsOutlineView rowForItem: presetToMod]] byExtendingSelection:NO];
7327 [self selectPreset:nil];
7332 #pragma mark Manage Built In Presets
7335 - (IBAction)deleteFactoryPresets:(id)sender
7338 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7342 NSMutableArray *tempArray;
7345 tempArray = [NSMutableArray array];
7346 /* we look here to see if the preset is we move on to the next one */
7347 while ( tempObject = [enumerator nextObject] )
7349 /* if the preset is "Factory" then we put it in the array of
7350 presets to delete */
7351 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
7353 [tempArray addObject:tempObject];
7357 [UserPresets removeObjectsInArray:tempArray];
7358 [fPresetsOutlineView reloadData];
7363 /* We use this method to recreate new, updated factory presets */
7364 - (IBAction)addFactoryPresets:(id)sender
7367 /* First, we delete any existing built in presets */
7368 [self deleteFactoryPresets: sender];
7369 /* Then we generate new built in presets programmatically with fPresetsBuiltin
7370 * which is all setup in HBPresets.h and HBPresets.m*/
7371 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
7372 /* update build number for built in presets */
7373 /* iterate though the new array of presets to import and add them to our presets array */
7375 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7377 while (tempObject = [enumerator nextObject])
7379 /* Record the apps current build number in the PresetBuildNumber key */
7380 if ([[tempObject objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7382 /* Preset build number */
7383 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
7387 /* report the built in preset updating to the activity log */
7388 [self writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]];
7398 /*******************************
7399 * Subclass of the HBPresetsOutlineView *
7400 *******************************/
7402 @implementation HBPresetsOutlineView
7403 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
7407 // By default, NSTableView only drags an image of the first column. Change this to
7408 // drag an image of the queue's icon and PresetName columns.
7409 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"PresetName"], nil];
7410 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
7415 - (void) mouseDown:(NSEvent *)theEvent
7417 [super mouseDown:theEvent];
7423 - (BOOL) isDragging;