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 stringWithUTF8String: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
432 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
433 [NSString stringWithUTF8String: hb_video_rates[i].string], @" (NTSC Film)"]];
435 else if ([[NSString stringWithUTF8String: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
437 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
438 [NSString stringWithUTF8String: hb_video_rates[i].string], @" (PAL Film/Video)"]];
440 else if ([[NSString stringWithUTF8String: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
442 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
443 [NSString stringWithUTF8String: hb_video_rates[i].string], @" (NTSC Video)"]];
447 [fVidRatePopUp addItemWithTitle:
448 [NSString stringWithUTF8String: 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 stringWithUTF8String: 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 stringWithUTF8String: 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];
1102 hb_get_state( fHandle, &s );
1103 if (s.state == HB_STATE_SCANNING)
1106 if ([ident isEqualToString: ChooseSourceIdentifier])
1108 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
1109 [toolbarItem setLabel: @"Cancel Scan"];
1110 [toolbarItem setPaletteLabel: @"Cancel Scanning"];
1111 [toolbarItem setToolTip: @"Cancel Scanning Source"];
1115 if ([ident isEqualToString: StartEncodingIdentifier] || [ident isEqualToString: AddToQueueIdentifier])
1120 if ([ident isEqualToString: ChooseSourceIdentifier])
1122 [toolbarItem setImage: [NSImage imageNamed: @"Source"]];
1123 [toolbarItem setLabel: @"Source"];
1124 [toolbarItem setPaletteLabel: @"Source"];
1125 [toolbarItem setToolTip: @"Choose Video Source"];
1130 hb_get_state2( fQueueEncodeLibhb, &s );
1132 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
1134 if ([ident isEqualToString: StartEncodingIdentifier])
1136 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
1137 [toolbarItem setLabel: @"Stop"];
1138 [toolbarItem setPaletteLabel: @"Stop"];
1139 [toolbarItem setToolTip: @"Stop Encoding"];
1142 if ([ident isEqualToString: PauseEncodingIdentifier])
1144 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
1145 [toolbarItem setLabel: @"Pause"];
1146 [toolbarItem setPaletteLabel: @"Pause Encoding"];
1147 [toolbarItem setToolTip: @"Pause Encoding"];
1152 if ([ident isEqualToString: AddToQueueIdentifier])
1154 if ([ident isEqualToString: ShowPictureIdentifier])
1156 if ([ident isEqualToString: ShowPreviewIdentifier])
1160 else if (s.state == HB_STATE_PAUSED)
1162 if ([ident isEqualToString: PauseEncodingIdentifier])
1164 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1165 [toolbarItem setLabel: @"Resume"];
1166 [toolbarItem setPaletteLabel: @"Resume Encoding"];
1167 [toolbarItem setToolTip: @"Resume Encoding"];
1170 if ([ident isEqualToString: StartEncodingIdentifier])
1172 if ([ident isEqualToString: AddToQueueIdentifier])
1174 if ([ident isEqualToString: ShowPictureIdentifier])
1176 if ([ident isEqualToString: ShowPreviewIdentifier])
1179 else if (s.state == HB_STATE_SCANNING)
1181 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
1183 if ([ident isEqualToString: StartEncodingIdentifier])
1185 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1186 if (hb_count(fHandle) > 0)
1187 [toolbarItem setLabel: @"Start Queue"];
1189 [toolbarItem setLabel: @"Start"];
1190 [toolbarItem setPaletteLabel: @"Start Encoding"];
1191 [toolbarItem setToolTip: @"Start Encoding"];
1194 if ([ident isEqualToString: AddToQueueIdentifier])
1196 if ([ident isEqualToString: ShowPictureIdentifier])
1198 if ([ident isEqualToString: ShowPreviewIdentifier])
1203 /* If there are any pending queue items, make sure the start/stop button is active */
1204 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1206 if ([ident isEqualToString: ShowQueueIdentifier])
1208 if ([ident isEqualToString: ToggleDrawerIdentifier])
1210 if ([ident isEqualToString: ChooseSourceIdentifier])
1212 if ([ident isEqualToString: ShowActivityIdentifier])
1218 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1220 SEL action = [menuItem action];
1223 hb_get_state2( fHandle, &s );
1227 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1228 return SuccessfulScan && [fWindow attachedSheet] == nil;
1230 if (action == @selector(browseSources:))
1232 if (s.state == HB_STATE_SCANNING)
1235 return [fWindow attachedSheet] == nil;
1237 if (action == @selector(selectDefaultPreset:))
1238 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1239 if (action == @selector(Pause:))
1241 if (s.state == HB_STATE_WORKING)
1243 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1244 [menuItem setTitle:@"Pause Encoding"];
1247 else if (s.state == HB_STATE_PAUSED)
1249 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1250 [menuItem setTitle:@"Resume Encoding"];
1256 if (action == @selector(Rip:))
1258 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1260 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1261 [menuItem setTitle:@"Stop Encoding"];
1264 else if (SuccessfulScan)
1266 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1267 [menuItem setTitle:@"Start Encoding"];
1268 return [fWindow attachedSheet] == nil;
1274 if( action == @selector(setDefaultPreset:) )
1276 return [fPresetsOutlineView selectedRow] != -1;
1283 #pragma mark Encode Done Actions
1284 // register a test notification and make
1285 // it enabled by default
1286 #define SERVICE_NAME @"Encode Done"
1287 - (NSDictionary *)registrationDictionaryForGrowl
1289 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1290 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1291 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1294 return registrationDictionary;
1297 -(void)showGrowlDoneNotification:(NSString *) filePath
1299 /* This end of encode action is called as each encode rolls off of the queue */
1300 NSString * finishedEncode = filePath;
1301 /* strip off the path to just show the file name */
1302 finishedEncode = [finishedEncode lastPathComponent];
1303 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1304 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1306 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1307 [GrowlApplicationBridge
1308 notifyWithTitle:@"Put down that cocktail..."
1309 description:growlMssg
1310 notificationName:SERVICE_NAME
1318 -(void)sendToMetaX:(NSString *) filePath
1320 /* This end of encode action is called as each encode rolls off of the queue */
1321 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1323 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1324 [myScript executeAndReturnError: nil];
1329 #pragma mark Get New Source
1331 /*Opens the source browse window, called from Open Source widgets */
1332 - (IBAction) browseSources: (id) sender
1336 hb_get_state( fHandle, &s );
1337 if (s.state == HB_STATE_SCANNING)
1339 [self cancelScanning:nil];
1344 NSOpenPanel * panel;
1346 panel = [NSOpenPanel openPanel];
1347 [panel setAllowsMultipleSelection: NO];
1348 [panel setCanChooseFiles: YES];
1349 [panel setCanChooseDirectories: YES ];
1350 NSString * sourceDirectory;
1351 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1353 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1357 sourceDirectory = @"~/Desktop";
1358 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1360 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1361 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1363 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1364 modalForWindow: fWindow modalDelegate: self
1365 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1366 contextInfo: sender];
1369 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1370 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1372 /* we convert the sender content of contextInfo back into a variable called sender
1373 * mostly just for consistency for evaluation later
1375 id sender = (id)contextInfo;
1376 /* User selected a file to open */
1377 if( returnCode == NSOKButton )
1379 /* Free display name allocated previously by this code */
1380 [browsedSourceDisplayName release];
1382 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1383 /* we set the last searched source directory in the prefs here */
1384 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1385 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1386 /* we order out sheet, which is the browse window as we need to open
1387 * the title selection sheet right away
1389 [sheet orderOut: self];
1391 if (sender == fOpenSourceTitleMMenu || [[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
1393 /* We put the chosen source path in the source display text field for the
1394 * source title selection sheet in which the user specifies the specific title to be
1395 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1396 * purposes in the title panel
1399 [fScanSrcTitlePathField setStringValue:scanPath];
1400 NSString *displayTitlescanSourceName;
1402 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1404 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1405 we have to use the title->path value so we get the proper name of the volume if a physical dvd is the source*/
1406 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1410 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1411 displayTitlescanSourceName = [scanPath lastPathComponent];
1413 /* we set the source display name in the title selection dialogue */
1414 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1415 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1416 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1417 /* We show the actual sheet where the user specifies the title to be scanned
1418 * as we are going to do a title specific scan
1420 [self showSourceTitleScanPanel:nil];
1424 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1425 NSString *path = [[sheet filenames] objectAtIndex: 0];
1427 /* We check to see if the chosen file at path is a package */
1428 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1430 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1431 /* We check to see if this is an .eyetv package */
1432 if ([[path pathExtension] isEqualToString: @"eyetv"])
1434 [self writeToActivityLog:"trying to open eyetv package"];
1435 /* We're looking at an EyeTV package - try to open its enclosed
1437 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1439 int n = [[path stringByAppendingString: @"/"]
1440 completePathIntoString: &mpgname caseSensitive: YES
1441 matchesIntoArray: nil
1442 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1445 /* Found an mpeg inside the eyetv package, make it our scan path
1446 and call performScan on the enclosed mpeg */
1448 [self writeToActivityLog:"found mpeg in eyetv package"];
1449 [self performScan:path scanTitleNum:0];
1453 /* We did not find an mpeg file in our package, so we do not call performScan */
1454 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1457 /* We check to see if this is a .dvdmedia package */
1458 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1460 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1461 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1462 [self writeToActivityLog:"trying to open dvdmedia package"];
1463 [self performScan:path scanTitleNum:0];
1467 /* The package is not an eyetv package, so we do not call performScan */
1468 [self writeToActivityLog:"unable to open package"];
1471 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1473 /* path is not a package, so we call perform scan directly on our file */
1474 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1476 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1477 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1478 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1482 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1483 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1484 /* make sure we remove any path extension as this can also be an '.mpg' file */
1485 browsedSourceDisplayName = [[path lastPathComponent] retain];
1487 [self performScan:path scanTitleNum:0];
1495 - (IBAction)showAboutPanel:(id)sender
1497 NSMutableDictionary* d = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
1498 fApplicationIcon, @"ApplicationIcon",
1500 [NSApp orderFrontStandardAboutPanelWithOptions:d];
1504 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1505 - (IBAction) showSourceTitleScanPanel: (id) sender
1507 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1510 [fScanSrcTitleNumField setStringValue: @"0"];
1511 /* Show the panel */
1512 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1515 - (IBAction) closeSourceTitleScanPanel: (id) sender
1517 [NSApp endSheet: fScanSrcTitlePanel];
1518 [fScanSrcTitlePanel orderOut: self];
1520 if(sender == fScanSrcTitleOpenButton)
1522 /* We setup the scan status in the main window to indicate a source title scan */
1523 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1524 [fScanIndicator setHidden: NO];
1525 [fScanIndicator setIndeterminate: YES];
1526 [fScanIndicator startAnimation: nil];
1528 /* We use the performScan method to actually perform the specified scan passing the path and the title
1531 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1535 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1536 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1538 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1539 applyQueueToScan = NO;
1540 /* use a bool to determine whether or not we can decrypt using vlc */
1541 BOOL cancelScanDecrypt = 0;
1542 NSString *path = scanPath;
1543 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1545 // Notify ChapterTitles that there's no title
1546 [fChapterTitlesDelegate resetWithTitle:nil];
1547 [fChapterTable reloadData];
1549 // Notify Subtitles that there's no title
1550 [fSubtitlesDelegate resetWithTitle:nil];
1551 [fSubtitlesTable reloadData];
1553 [self enableUI: NO];
1555 if( [detector isVideoDVD] )
1558 #if defined( __LP64__ )
1567 // The chosen path was actually on a DVD, so use the raw block
1568 // device path instead.
1569 path = [detector devicePath];
1570 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1572 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1573 NSString *vlcPath = @"/Applications/VLC.app/Contents/MacOS/lib/libdvdcss.2.dylib";
1574 NSFileManager * fileManager = [NSFileManager defaultManager];
1575 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1577 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1578 cancelScanDecrypt = 1;
1579 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1581 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");
1582 [NSApp requestUserAttention:NSCriticalRequest];
1584 if (status == NSAlertDefaultReturn)
1586 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1587 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/vlc/download-macosx.html"]];
1589 else if (status == NSAlertAlternateReturn)
1591 /* User chose to cancel the scan */
1592 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1596 /* 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 */
1597 cancelScanDecrypt = 0;
1598 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1604 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1605 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1607 /* test for architecture of the vlc app */
1608 NSArray *vlc_architecturesArray = [[NSBundle bundleWithPath:@"/Applications/VLC.app"] executableArchitectures];
1609 BOOL vlcIntel32bit = NO;
1610 BOOL vlcIntel64bit = NO;
1611 BOOL vlcPPC32bit = NO;
1612 BOOL vlcPPC64bit = NO;
1613 /* check the available architectures for vlc and note accordingly */
1614 NSEnumerator *enumerator = [vlc_architecturesArray objectEnumerator];
1616 while (tempObject = [enumerator nextObject])
1619 if ([tempObject intValue] == NSBundleExecutableArchitectureI386)
1621 vlcIntel32bit = YES;
1623 if ([tempObject intValue] == NSBundleExecutableArchitectureX86_64)
1625 vlcIntel64bit = YES;
1627 if ([tempObject intValue] == NSBundleExecutableArchitecturePPC)
1631 if ([tempObject intValue] == NSBundleExecutableArchitecturePPC64)
1637 /* Write vlc architecture findings to activity window */
1640 [self writeToActivityLog: " 32-Bit VLC app found for decrypting physical dvd"];
1644 [self writeToActivityLog: " 64-Bit VLC app found for decrypting physical dvd"];
1649 if (hb_arch == 64 && !vlcIntel64bit && cancelScanDecrypt != 1)
1654 /* Appropriate VLC not found, so cancel */
1655 cancelScanDecrypt = 1;
1656 [self writeToActivityLog: "This version of HandBrake is 64 bit, 64 bit version of vlc not found, scan cancelled"];
1657 /*On Screen Notification*/
1660 status = NSRunAlertPanel(@"This version of HandBrake is 64 bit, VLC found but not 64 bit!",@"", @"Cancel Scan", @"Attempt Scan Anyway", @"Get 64 bit VLC", nil);
1661 [NSApp requestUserAttention:NSCriticalRequest];
1663 if (status == NSAlertDefaultReturn)
1665 /* User chose to cancel the scan */
1666 [self writeToActivityLog: "cannot open physical dvd VLC found but not 64 bit, scan cancelled"];
1667 cancelScanDecrypt = 1;
1669 else if (status == NSAlertDefaultReturn)
1671 [self writeToActivityLog: "user overrode 64-bit warning trying to open physical dvd without proper decryption"];
1672 cancelScanDecrypt = 0;
1676 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1677 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/vlc/download-macosx.html"]];
1681 else if (hb_arch == 32 && !vlcIntel32bit && cancelScanDecrypt != 1)
1684 /* Appropriate VLC not found, so cancel */
1685 cancelScanDecrypt = 1;
1686 [self writeToActivityLog: "This version of HandBrake is 32 bit, 32 bit version of vlc not found, scan cancelled"];
1687 /*On Screen Notification*/
1690 status = NSRunAlertPanel(@"This version of HandBrake is 32 bit, VLC found but not 32 bit!",@"", @"Cancel Scan", @"Attempt Scan Anyway", @"Get 32 bit VLC", nil);
1691 [NSApp requestUserAttention:NSCriticalRequest];
1693 if (status == NSAlertDefaultReturn)
1695 /* User chose to cancel the scan */
1696 [self writeToActivityLog: "cannot open physical dvd VLC found but not 32 bit, scan cancelled"];
1697 cancelScanDecrypt = 1;
1699 else if (status == NSAlertDefaultReturn)
1701 [self writeToActivityLog: "user overrode 32-bit warning trying to open physical dvd without proper decryption"];
1702 cancelScanDecrypt = 0;
1706 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1707 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/vlc/download-macosx.html"]];
1713 if (cancelScanDecrypt == 0)
1715 /* we actually pass the scan off to libhb here */
1716 /* If there is no title number passed to scan, we use "0"
1717 * which causes the default behavior of a full source scan
1723 if (scanTitleNum > 0)
1725 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1727 /* We use our advance pref to determine how many previews to scan */
1728 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
1729 /* set title to NULL */
1731 hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
1732 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1736 - (IBAction) cancelScanning:(id)sender
1738 hb_scan_stop(fHandle);
1741 - (IBAction) showNewScan:(id)sender
1745 int indxpri=0; // Used to search the longuest title (default in combobox)
1746 int longuestpri=0; // Used to search the longuest title (default in combobox)
1749 list = hb_get_titles( fHandle );
1751 if( !hb_list_count( list ) )
1753 /* We display a message if a valid dvd source was not chosen */
1754 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1755 SuccessfulScan = NO;
1757 // Notify ChapterTitles that there's no title
1758 [fSubtitlesDelegate resetWithTitle:nil];
1759 [fSubtitlesTable reloadData];
1761 // Notify Subtitles that there's no title
1762 [fChapterTitlesDelegate resetWithTitle:nil];
1763 [fChapterTable reloadData];
1767 /* We increment the successful scancount here by one,
1768 which we use at the end of this function to tell the gui
1769 if this is the first successful scan since launch and whether
1770 or not we should set all settings to the defaults */
1772 currentSuccessfulScanCount++;
1774 [[fWindow toolbar] validateVisibleItems];
1776 [fSrcTitlePopUp removeAllItems];
1777 for( int i = 0; i < hb_list_count( list ); i++ )
1779 title = (hb_title_t *) hb_list_item( list, i );
1781 currentSource = [NSString stringWithUTF8String: title->name];
1782 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1783 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1785 /* Use the dvd name in the default output field here
1786 May want to add code to remove blank spaces for some dvd names*/
1787 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1788 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1790 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1791 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1795 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1796 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1800 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1802 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1806 [fSrcTitlePopUp addItemWithTitle: [NSString
1807 stringWithFormat: @"%s %d - %02dh%02dm%02ds",
1808 title->name,title->index, title->hours, title->minutes,
1812 /* if we are a stream, select the first title */
1813 if (title->type == HB_STREAM_TYPE)
1815 [fSrcTitlePopUp selectItemAtIndex: 0];
1819 /* if not then select the longest title (dvd) */
1820 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1822 [self titlePopUpChanged:nil];
1824 SuccessfulScan = YES;
1825 [self enableUI: YES];
1827 /* if its the initial successful scan after awakeFromNib */
1828 if (currentSuccessfulScanCount == 1)
1830 [self selectDefaultPreset:nil];
1832 // Open preview window now if it was visible when HB was closed
1833 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PreviewWindowIsOpen"])
1834 [self showPreviewWindow:nil];
1836 // Open picture sizing window now if it was visible when HB was closed
1837 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PictureSizeWindowIsOpen"])
1838 [self showPicturePanel:nil];
1849 #pragma mark New Output Destination
1851 - (IBAction) browseFile: (id) sender
1853 /* Open a panel to let the user choose and update the text field */
1854 NSSavePanel * panel = [NSSavePanel savePanel];
1855 /* We get the current file name and path from the destination field here */
1856 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1857 modalForWindow: fWindow modalDelegate: self
1858 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1862 - (void) browseFileDone: (NSSavePanel *) sheet
1863 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1865 if( returnCode == NSOKButton )
1867 [fDstFile2Field setStringValue: [sheet filename]];
1868 /* Save this path to the prefs so that on next browse destination window it opens there */
1869 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
1870 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
1876 #pragma mark Main Window Control
1878 - (IBAction) openMainWindow: (id) sender
1880 [fWindow makeKeyAndOrderFront:nil];
1883 - (BOOL) windowShouldClose: (id) sender
1888 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1891 [fWindow makeKeyAndOrderFront:nil];
1899 - (NSSize) drawerWillResizeContents:(NSDrawer *) drawer toSize:(NSSize) contentSize {
1900 [[NSUserDefaults standardUserDefaults] setObject:NSStringFromSize( contentSize ) forKey:@"Drawer Size"];
1905 #pragma mark Queue File
1907 - (void) loadQueueFile {
1908 /* We declare the default NSFileManager into fileManager */
1909 NSFileManager * fileManager = [NSFileManager defaultManager];
1910 /*We define the location of the user presets file */
1911 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1912 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1913 /* We check for the presets.plist */
1914 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1916 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1919 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1920 /* lets check to see if there is anything in the queue file .plist */
1921 if (nil == QueueFileArray)
1923 /* if not, then lets initialize an empty array */
1924 QueueFileArray = [[NSMutableArray alloc] init];
1926 /* Initialize our curQueueEncodeIndex to 0
1927 * so we can use it to track which queue
1928 * item is to be used to track our encodes */
1929 /* NOTE: this should be changed if and when we
1930 * are able to get the last unfinished encode
1931 * in the case of a crash or shutdown */
1936 [self clearQueueEncodedItems];
1938 currentQueueEncodeIndex = 0;
1941 - (void)addQueueFileItem
1943 [QueueFileArray addObject:[self createQueueFileItem]];
1944 [self saveQueueFileItem];
1948 - (void) removeQueueFileItem:(int) queueItemToRemove
1951 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1952 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1954 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1955 * by one to keep in sync with the queue array
1957 currentQueueEncodeIndex--;
1958 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1960 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1961 [self saveQueueFileItem];
1965 - (void)saveQueueFileItem
1967 [QueueFileArray writeToFile:QueueFile atomically:YES];
1968 [fQueueController setQueueArray: QueueFileArray];
1969 [self getQueueStats];
1972 - (void)getQueueStats
1974 /* lets get the stats on the status of the queue array */
1976 fEncodingQueueItem = 0;
1978 fCompletedCount = 0;
1982 /* We use a number system to set the encode status of the queue item
1984 * 0 == already encoded
1985 * 1 == is being encoded
1986 * 2 == is yet to be encoded
1991 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1993 while (tempObject = [enumerator nextObject])
1995 NSDictionary *thisQueueDict = tempObject;
1996 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
2000 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
2003 fEncodingQueueItem = i;
2005 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
2009 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
2016 /* Set the queue status field in the main window */
2017 NSMutableString * string;
2018 if (fPendingCount == 1)
2020 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
2024 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
2026 [fQueueStatus setStringValue:string];
2029 /* This method will set any item marked as encoding back to pending
2030 * currently used right after a queue reload
2032 - (void) setQueueEncodingItemsAsPending
2034 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
2036 NSMutableArray *tempArray;
2037 tempArray = [NSMutableArray array];
2038 /* we look here to see if the preset is we move on to the next one */
2039 while ( tempObject = [enumerator nextObject] )
2041 /* If the queue item is marked as "encoding" (1)
2042 * then change its status back to pending (2) which effectively
2043 * puts it back into the queue to be encoded
2045 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
2047 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
2049 [tempArray addObject:tempObject];
2052 [QueueFileArray setArray:tempArray];
2053 [self saveQueueFileItem];
2057 /* This method will clear the queue of any encodes that are not still pending
2058 * this includes both successfully completed encodes as well as cancelled encodes */
2059 - (void) clearQueueEncodedItems
2061 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
2063 NSMutableArray *tempArray;
2064 tempArray = [NSMutableArray array];
2065 /* we look here to see if the preset is we move on to the next one */
2066 while ( tempObject = [enumerator nextObject] )
2068 /* If the queue item is either completed (0) or cancelled (3) from the
2069 * last session, then we put it in tempArray to be deleted from QueueFileArray.
2070 * NOTE: this means we retain pending (2) and also an item that is marked as
2071 * still encoding (1). If the queue has an item that is still marked as encoding
2072 * from a previous session, we can conlude that HB was either shutdown, or crashed
2073 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
2075 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
2077 [tempArray addObject:tempObject];
2081 [QueueFileArray removeObjectsInArray:tempArray];
2082 [self saveQueueFileItem];
2085 /* This method will clear the queue of all encodes. effectively creating an empty queue */
2086 - (void) clearQueueAllItems
2088 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
2090 NSMutableArray *tempArray;
2091 tempArray = [NSMutableArray array];
2092 /* we look here to see if the preset is we move on to the next one */
2093 while ( tempObject = [enumerator nextObject] )
2095 [tempArray addObject:tempObject];
2098 [QueueFileArray removeObjectsInArray:tempArray];
2099 [self saveQueueFileItem];
2102 /* This method will duplicate prepareJob however into the
2103 * queue .plist instead of into the job structure so it can
2104 * be recalled later */
2105 - (NSDictionary *)createQueueFileItem
2107 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
2109 hb_list_t * list = hb_get_titles( fHandle );
2110 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2111 [fSrcTitlePopUp indexOfSelectedItem] );
2112 hb_job_t * job = title->job;
2116 /* We use a number system to set the encode status of the queue item
2117 * 0 == already encoded
2118 * 1 == is being encoded
2119 * 2 == is yet to be encoded
2122 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
2123 /* Source and Destination Information */
2125 [queueFileJob setObject:[NSString stringWithUTF8String: title->path] forKey:@"SourcePath"];
2126 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
2127 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
2128 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcAnglePopUp indexOfSelectedItem] + 1] forKey:@"TitleAngle"];
2129 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
2131 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
2133 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
2135 /* Lets get the preset info if there is any */
2136 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2137 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2139 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
2140 /* Chapter Markers*/
2141 /* If we have only one chapter or a title without chapters, set chapter markers to off */
2142 if ([fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem])
2144 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"ChapterMarkers"];
2148 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
2151 /* We need to get the list of chapter names to put into an array and store
2152 * in our queue, so they can be reapplied in prepareJob when this queue
2153 * item comes up if Chapter Markers is set to on.
2156 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
2157 int chaptercount = hb_list_count( fTitle->list_chapter );
2158 for( i = 0; i < chaptercount; i++ )
2160 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
2161 if( chapter != NULL )
2163 [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
2166 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
2167 [ChapterNamesArray autorelease];
2169 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2170 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
2171 /* Mux mp4 with http optimization */
2172 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
2173 /* Add iPod uuid atom */
2174 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
2178 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
2179 /* x264 Option String */
2180 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
2182 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
2183 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
2184 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
2185 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
2187 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
2189 /* 2 Pass Encoding */
2190 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
2191 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
2192 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
2194 /* Picture Sizing */
2195 /* Use Max Picture settings for whatever the dvd is.*/
2196 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2197 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2198 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2199 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2200 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2201 /* if we are custom anamorphic, store the exact storage, par and display dims */
2202 if (fTitle->job->anamorphic.mode == 3)
2204 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.modulus] forKey:@"PicturePARModulus"];
2206 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
2207 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
2209 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_width] forKey:@"PicturePARPixelWidth"];
2210 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.par_height] forKey:@"PicturePARPixelHeight"];
2212 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_width] forKey:@"PicturePARDisplayWidth"];
2213 [queueFileJob setObject:[NSNumber numberWithFloat:fTitle->job->anamorphic.dar_height] forKey:@"PicturePARDisplayHeight"];
2216 NSString * pictureSummary;
2217 pictureSummary = [fPictureSizeField stringValue];
2218 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
2219 /* Set crop settings here */
2220 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2221 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2222 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2223 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2224 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2226 /* Picture Filters */
2227 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
2228 [queueFileJob setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
2230 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
2231 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
2232 [queueFileJob setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
2234 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
2235 [queueFileJob setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
2237 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
2238 [queueFileJob setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
2240 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
2242 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
2245 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2247 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
2248 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
2249 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
2250 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
2251 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
2252 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
2253 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
2255 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2257 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
2258 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
2259 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
2260 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
2261 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
2262 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
2263 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
2265 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2267 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
2268 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
2269 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
2270 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
2271 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
2272 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
2273 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
2275 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2277 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
2278 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
2279 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
2280 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
2281 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
2282 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
2283 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
2287 NSMutableArray *subtitlesArray = [[NSMutableArray alloc] init];
2288 [queueFileJob setObject:[NSArray arrayWithArray: [fSubtitlesDelegate getSubtitleArray: subtitlesArray]] forKey:@"SubtitleList"];
2289 [subtitlesArray autorelease];
2291 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
2293 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
2295 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
2298 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
2302 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
2305 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
2306 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
2307 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
2309 /* Picture Sizing */
2310 /* Use Max Picture settings for whatever the dvd is.*/
2311 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
2312 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
2313 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
2314 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
2315 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
2317 /* Set crop settings here */
2318 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
2319 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
2320 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
2321 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
2322 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
2326 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2328 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
2329 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
2330 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
2331 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
2332 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
2334 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2336 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
2337 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
2338 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
2339 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
2340 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
2342 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2344 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
2345 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
2346 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
2347 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
2348 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
2350 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2352 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
2353 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
2354 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
2355 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
2356 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
2360 /* we need to auto relase the queueFileJob and return it */
2361 [queueFileJob autorelease];
2362 return queueFileJob;
2366 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
2367 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
2369 NSUInteger index = [indexSet lastIndex];
2370 NSUInteger aboveInsertIndexCount = 0;
2373 NSUInteger removeIndex;
2375 if (index >= insertIndex)
2377 removeIndex = index + aboveInsertIndexCount;
2378 aboveInsertIndexCount++;
2382 removeIndex = index;
2386 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2387 [QueueFileArray removeObjectAtIndex:removeIndex];
2388 [QueueFileArray insertObject:object atIndex:insertIndex];
2391 index = [indexSet indexLessThanIndex:index];
2393 /* We save all of the Queue data here
2394 * and it also gets sent back to the queue controller*/
2395 [self saveQueueFileItem];
2401 #pragma mark Queue Job Processing
2403 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2405 int i = currentQueueEncodeIndex;
2406 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2408 /* We save all of the Queue data here */
2409 [self saveQueueFileItem];
2410 /* We Reload the New Table data for presets */
2411 //[fPresetsOutlineView reloadData];
2413 /* Since we have now marked a queue item as done
2414 * we can go ahead and increment currentQueueEncodeIndex
2415 * so that if there is anything left in the queue we can
2416 * go ahead and move to the next item if we want to */
2417 currentQueueEncodeIndex++ ;
2418 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2419 int queueItems = [QueueFileArray count];
2420 /* If we still have more items in our queue, lets go to the next one */
2421 if (currentQueueEncodeIndex < queueItems)
2423 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2424 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2428 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2432 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2433 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2435 /* Tell HB to output a new activity log file for this encode */
2436 [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
2439 /* use a bool to determine whether or not we can decrypt using vlc */
2440 BOOL cancelScanDecrypt = 0;
2441 /* set the bool so that showNewScan knows to apply the appropriate queue
2442 * settings as this is a queue rescan
2444 applyQueueToScan = YES;
2445 NSString *path = scanPath;
2446 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2448 /*On Screen Notification*/
2450 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2451 //[NSApp requestUserAttention:NSCriticalRequest];
2453 if( [detector isVideoDVD] )
2455 // The chosen path was actually on a DVD, so use the raw block
2456 // device path instead.
2457 path = [detector devicePath];
2458 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2460 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2461 NSString *vlcPath = @"/Applications/VLC.app";
2462 NSFileManager * fileManager = [NSFileManager defaultManager];
2463 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2465 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2466 cancelScanDecrypt = 1;
2467 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2469 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");
2470 [NSApp requestUserAttention:NSCriticalRequest];
2472 if (status == NSAlertDefaultReturn)
2474 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2475 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2477 else if (status == NSAlertAlternateReturn)
2479 /* User chose to cancel the scan */
2480 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2484 /* 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 */
2485 cancelScanDecrypt = 0;
2486 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2492 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2493 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2497 if (cancelScanDecrypt == 0)
2499 /* we actually pass the scan off to libhb here */
2500 /* If there is no title number passed to scan, we use "0"
2501 * which causes the default behavior of a full source scan
2507 if (scanTitleNum > 0)
2509 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2512 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2513 /* We use our advance pref to determine how many previews to scan */
2514 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
2515 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
2519 /* This method was originally used to load up a new queue item in the gui and
2520 * then start processing it. However we now have modified -prepareJob and use a second
2521 * instance of libhb to do our actual encoding, therefor right now it is not required.
2522 * Nonetheless I want to leave this in here
2523 * because basically its everything we need to be able to actually modify a pending queue
2524 * item in the gui and resave it. At least for now - dynaflash
2527 - (IBAction)applyQueueSettings:(id)sender
2529 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2530 hb_job_t * job = fTitle->job;
2532 /* Set title number and chapters */
2533 /* since the queue only scans a single title, we really don't need to pick a title */
2534 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2536 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2537 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2540 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2541 [self formatPopUpChanged:nil];
2543 /* Chapter Markers*/
2544 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2545 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2546 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2547 /* Mux mp4 with http optimization */
2548 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2551 /* We set the advanced opt string here if applicable*/
2552 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2553 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2555 /* Lets run through the following functions to get variables set there */
2556 [self videoEncoderPopUpChanged:nil];
2557 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2558 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2559 [self calculateBitrate:nil];
2562 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2564 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2565 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2566 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2568 [self videoMatrixChanged:nil];
2570 /* Video framerate */
2571 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2572 detected framerate in the fVidRatePopUp so we use index 0*/
2573 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2575 [fVidRatePopUp selectItemAtIndex: 0];
2579 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2582 /* 2 Pass Encoding */
2583 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2584 [self twoPassCheckboxChanged:nil];
2585 /* Turbo 1st pass for 2 Pass Encoding */
2586 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2589 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2591 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2593 [fAudLang1PopUp selectItemAtIndex: 1];
2595 [self audioTrackPopUpChanged: fAudLang1PopUp];
2596 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2597 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2598 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2599 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2601 if ([fAudTrack1MixPopUp selectedItem] == nil)
2603 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2605 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2606 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2607 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2609 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2611 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2612 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2614 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2616 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2618 [fAudLang2PopUp selectItemAtIndex: 1];
2620 [self audioTrackPopUpChanged: fAudLang2PopUp];
2621 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2622 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2623 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2624 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2626 if ([fAudTrack2MixPopUp selectedItem] == nil)
2628 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2630 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2631 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2632 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2634 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2636 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2637 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2639 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2641 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2643 [fAudLang3PopUp selectItemAtIndex: 1];
2645 [self audioTrackPopUpChanged: fAudLang3PopUp];
2646 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2647 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2648 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2649 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2651 if ([fAudTrack3MixPopUp selectedItem] == nil)
2653 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2655 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2656 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2657 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2659 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2661 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2662 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2664 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2666 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2668 [fAudLang4PopUp selectItemAtIndex: 1];
2670 [self audioTrackPopUpChanged: fAudLang4PopUp];
2671 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2672 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2673 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2674 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2676 if ([fAudTrack4MixPopUp selectedItem] == nil)
2678 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2680 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2681 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2682 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2684 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2686 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2687 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2692 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2693 /* Forced Subtitles */
2694 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2696 /* Picture Settings */
2697 /* we check to make sure the presets width/height does not exceed the sources width/height */
2698 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2700 /* if so, then we use the sources height and width to avoid scaling up */
2701 job->width = fTitle->width;
2702 job->height = fTitle->height;
2704 else // source width/height is >= the preset height/width
2706 /* we can go ahead and use the presets values for height and width */
2707 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2708 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2710 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2711 if (job->keep_ratio == 1)
2713 hb_fix_aspect( job, HB_KEEP_WIDTH );
2714 if( job->height > fTitle->height )
2716 job->height = fTitle->height;
2717 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2720 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2723 /* If Cropping is set to custom, then recall all four crop values from
2724 when the preset was created and apply them */
2725 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2727 [fPictureController setAutoCrop:NO];
2729 /* Here we use the custom crop values saved at the time the preset was saved */
2730 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2731 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2732 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2733 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2736 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2738 [fPictureController setAutoCrop:YES];
2739 /* Here we use the auto crop values determined right after scan */
2740 job->crop[0] = AutoCropTop;
2741 job->crop[1] = AutoCropBottom;
2742 job->crop[2] = AutoCropLeft;
2743 job->crop[3] = AutoCropRight;
2749 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2752 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2754 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2756 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2758 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2760 [fPictureController setGrayscale:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2762 [self calculatePictureSizing:nil];
2765 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2766 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2767 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2768 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2770 /* Deselect the currently selected Preset if there is one*/
2771 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2772 //[self selectPreset:nil];
2774 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2775 /* Change UI to show "Custom" settings are being used */
2776 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2778 curUserPresetChosenNum = nil;
2782 /* Deselect the currently selected Preset if there is one*/
2783 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2784 /* Change UI to show "Custom" settings are being used */
2785 [fPresetSelectedDisplay setStringValue: @"Custom"];
2787 //curUserPresetChosenNum = nil;
2790 /* We need to set this bool back to NO, in case the user wants to do a scan */
2791 //applyQueueToScan = NO;
2793 /* so now we go ahead and process the new settings */
2794 [self processNewQueueEncode];
2799 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2800 - (void) processNewQueueEncode
2802 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2803 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2804 hb_job_t * job = title->job;
2806 if( !hb_list_count( list ) )
2808 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2811 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2812 [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
2813 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2814 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2815 //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2819 * If scanning we need to do some extra setup of the job.
2821 if( job->indepth_scan == 1 )
2826 * When subtitle scan is enabled do a fast pre-scan job
2827 * which will determine which subtitles to enable, if any.
2830 x264opts_tmp = job->x264opts;
2832 job->x264opts = NULL;
2834 job->indepth_scan = 1;
2838 * Add the pre-scan job
2840 hb_add( fQueueEncodeLibhb, job );
2841 job->x264opts = x264opts_tmp;
2845 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2847 job->indepth_scan = 0;
2853 hb_add( fQueueEncodeLibhb, job );
2857 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2858 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2860 hb_add( fQueueEncodeLibhb, job );
2865 job->indepth_scan = 0;
2868 hb_add( fQueueEncodeLibhb, job );
2871 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2872 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2873 /* Lets mark our new encode as 1 or "Encoding" */
2874 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2875 [self saveQueueFileItem];
2877 /* we need to clean up the subtitle tracks after the job(s) have been set */
2878 int num_subtitle_tracks = hb_list_count(job->list_subtitle);
2880 for(ii = 0; ii < num_subtitle_tracks; ii++)
2882 hb_subtitle_t * subtitle;
2883 subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
2886 hb_list_rem(job->list_subtitle, subtitle);
2891 /* We should be all setup so let 'er rip */
2896 #pragma mark Live Preview
2897 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
2898 * can encode to its temp preview directory and playback. This is *not* used for any actual user
2901 - (void) prepareJobForPreview
2903 hb_list_t * list = hb_get_titles( fHandle );
2904 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2905 [fSrcTitlePopUp indexOfSelectedItem] );
2906 hb_job_t * job = title->job;
2907 hb_audio_config_t * audio;
2908 /* set job->angle for libdvdnav */
2909 job->angle = [fSrcAnglePopUp indexOfSelectedItem] + 1;
2910 /* Chapter selection */
2911 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
2912 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
2914 /* Format (Muxer) and Video Encoder */
2915 job->mux = [[fDstFormatPopUp selectedItem] tag];
2916 job->vcodec = [[fVidEncoderPopUp selectedItem] tag];
2918 job->chapter_markers = 0;
2920 if( job->vcodec & HB_VCODEC_X264 )
2923 /* Below Sends x264 options to the core library if x264 is selected*/
2924 /* Lets use this as per Nyx, Thanks Nyx!*/
2925 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2926 /* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
2927 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
2932 /* Video settings */
2933 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2934 * and detelecine is on, so we handle that in the logic below
2937 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
2939 /* a specific framerate has been chosen */
2940 job->vrate = 27000000;
2941 job->vrate_base = hb_video_rates[[fVidRatePopUp indexOfSelectedItem]-1].rate;
2942 /* We are not same as source so we set job->cfr to 1
2943 * to enable constant frame rate since user has specified
2944 * a specific framerate*/
2949 /* We are same as source (variable) */
2950 job->vrate = title->rate;
2951 job->vrate_base = title->rate_base;
2952 /* We are same as source so we set job->cfr to 0
2953 * to enable true same as source framerate */
2955 /* If we are same as source and we have detelecine on, we need to turn on
2958 if ([fPictureController detelecine] == 1)
2964 switch( [fVidQualityMatrix selectedRow] )
2968 Bitrate should already have been calculated and displayed
2969 in fVidBitrateField, so let's just use it */
2971 job->vquality = -1.0;
2972 job->vbitrate = [fVidBitrateField intValue];
2975 job->vquality = [fVidQualityRFField floatValue];
2980 /* Subtitle settings */
2981 NSMutableArray *subtitlesArray = nil;
2982 subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray: subtitlesArray]];
2990 bool one_burned = FALSE;
2993 NSEnumerator *enumerator = [subtitlesArray objectEnumerator];
2995 while (tempObject = [enumerator nextObject])
2998 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
2999 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
3000 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
3001 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
3003 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
3004 * we want to ignore it for display as well as encoding.
3008 /* if i is 0, then we are in the first item of the subtitles which we need to
3009 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
3010 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
3013 /* if we are on the first track and using "Foreign Audio Search" */
3014 if (i == 0 && subtitle == 1)
3016 /* NOTE: Currently foreign language search is borked for preview.
3017 * Commented out but left in for initial commit. */
3020 [self writeToActivityLog: "Foreign Language Search: %d", 1];
3022 job->indepth_scan = 1;
3023 if (burned == 1 || job->mux != HB_MUX_MP4)
3025 if (burned != 1 && job->mux == HB_MUX_MKV)
3027 job->select_subtitle_config.dest = PASSTHRUSUB;
3031 job->select_subtitle_config.dest = RENDERSUB;
3034 job->select_subtitle_config.force = force;
3035 job->select_subtitle_config.default_track = def;
3044 /* for the actual source tracks, we must subtract the non source entries so
3045 * that the menu index matches the source subtitle_list index for convenience */
3048 /* for the first track, the source tracks start at menu index 2 ( None is 0,
3049 * Foreign Language Search is 1) so subtract 2 */
3050 subtitle = subtitle - 2;
3054 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
3057 subtitle = subtitle - 1;
3060 /* We are setting a source subtitle so access the source subtitle info */
3061 hb_subtitle_t * subt;
3063 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3065 /* if we are getting the subtitles from an external srt file */
3066 if ([[tempObject objectForKey:@"subtitleSourceTrackType"] isEqualToString:@"SRT"])
3068 hb_subtitle_config_t sub_config;
3070 sub_config.offset = [[tempObject objectForKey:@"subtitleTrackSrtOffset"] intValue];
3072 /* we need to srncpy file path and char code */
3073 strncpy(sub_config.src_filename, [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String], 128);
3074 strncpy(sub_config.src_codeset, [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String], 40);
3076 sub_config.force = 0;
3077 sub_config.dest = PASSTHRUSUB;
3078 sub_config.default_track = def;
3080 hb_srt_add( job, &sub_config, [[tempObject objectForKey:@"subtitleTrackSrtLanguageIso3"] UTF8String]);
3085 [self writeToActivityLog: "Setting Subtitle: %s", subt];
3087 hb_subtitle_config_t sub_config = subt->config;
3089 if (!burned && job->mux == HB_MUX_MKV &&
3090 subt->format == PICTURESUB)
3092 sub_config.dest = PASSTHRUSUB;
3094 else if (!burned && job->mux == HB_MUX_MP4 &&
3095 subt->format == PICTURESUB)
3097 // Skip any non-burned vobsubs when output is mp4
3100 else if ( burned && subt->format == PICTURESUB )
3102 // Only allow one subtitle to be burned into the video
3107 sub_config.force = force;
3108 sub_config.default_track = def;
3109 hb_subtitle_add( job, &sub_config, subtitle );
3119 [subtitlesArray autorelease];
3122 /* Audio tracks and mixdowns */
3123 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3124 int audiotrack_count = hb_list_count(job->list_audio);
3125 for( int i = 0; i < audiotrack_count;i++)
3127 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3128 hb_list_rem(job->list_audio, temp_audio);
3130 /* Now lets add our new tracks to the audio list here */
3131 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
3133 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3134 hb_audio_config_init(audio);
3135 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
3136 /* We go ahead and assign values to our audio->out.<properties> */
3137 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
3138 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
3139 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
3140 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
3141 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
3142 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
3144 hb_audio_add( job, audio );
3147 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
3149 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3150 hb_audio_config_init(audio);
3151 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
3152 /* We go ahead and assign values to our audio->out.<properties> */
3153 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
3154 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
3155 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
3156 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
3157 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
3158 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
3160 hb_audio_add( job, audio );
3165 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
3167 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3168 hb_audio_config_init(audio);
3169 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3170 /* We go ahead and assign values to our audio->out.<properties> */
3171 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3172 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
3173 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
3174 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
3175 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
3176 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
3178 hb_audio_add( job, audio );
3183 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
3185 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3186 hb_audio_config_init(audio);
3187 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3188 /* We go ahead and assign values to our audio->out.<properties> */
3189 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
3190 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
3191 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
3192 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
3193 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
3194 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
3196 hb_audio_add( job, audio );
3205 /* Though Grayscale is not really a filter, per se
3206 * we put it here since its in the filters panel
3209 if ([fPictureController grayscale])
3218 /* Initialize the filters list */
3219 job->filters = hb_list_init();
3221 /* Now lets call the filters if applicable.
3222 * The order of the filters is critical
3226 if ([fPictureController detelecine] == 1)
3228 /* use a custom detelecine string */
3229 hb_filter_detelecine.settings = (char *) [[fPictureController detelecineCustomString] UTF8String];
3230 hb_list_add( job->filters, &hb_filter_detelecine );
3232 if ([fPictureController detelecine] == 2)
3235 hb_list_add( job->filters, &hb_filter_detelecine );
3240 if ([fPictureController useDecomb] == 1)
3243 /* we add the custom string if present */
3244 if ([fPictureController decomb] == 1)
3246 /* use a custom decomb string */
3247 hb_filter_decomb.settings = (char *) [[fPictureController decombCustomString] UTF8String];
3248 hb_list_add( job->filters, &hb_filter_decomb );
3250 if ([fPictureController decomb] == 2)
3252 /* Run old deinterlacer fd by default */
3253 //hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
3254 hb_list_add( job->filters, &hb_filter_decomb );
3261 if ([fPictureController deinterlace] == 1)
3263 /* we add the custom string if present */
3264 hb_filter_deinterlace.settings = (char *) [[fPictureController deinterlaceCustomString] UTF8String];
3265 hb_list_add( job->filters, &hb_filter_deinterlace );
3267 else if ([fPictureController deinterlace] == 2)
3269 /* Run old deinterlacer fd by default */
3270 hb_filter_deinterlace.settings = "-1";
3271 hb_list_add( job->filters, &hb_filter_deinterlace );
3273 else if ([fPictureController deinterlace] == 3)
3275 /* Yadif mode 0 (without spatial deinterlacing.) */
3276 hb_filter_deinterlace.settings = "2";
3277 hb_list_add( job->filters, &hb_filter_deinterlace );
3279 else if ([fPictureController deinterlace] == 4)
3281 /* Yadif (with spatial deinterlacing) */
3282 hb_filter_deinterlace.settings = "0";
3283 hb_list_add( job->filters, &hb_filter_deinterlace );
3289 if ([fPictureController denoise] == 1) // custom in popup
3291 /* we add the custom string if present */
3292 hb_filter_denoise.settings = (char *) [[fPictureController denoiseCustomString] UTF8String];
3293 hb_list_add( job->filters, &hb_filter_denoise );
3295 else if ([fPictureController denoise] == 2) // Weak in popup
3297 hb_filter_denoise.settings = "2:1:2:3";
3298 hb_list_add( job->filters, &hb_filter_denoise );
3300 else if ([fPictureController denoise] == 3) // Medium in popup
3302 hb_filter_denoise.settings = "3:2:2:3";
3303 hb_list_add( job->filters, &hb_filter_denoise );
3305 else if ([fPictureController denoise] == 4) // Strong in popup
3307 hb_filter_denoise.settings = "7:7:5:5";
3308 hb_list_add( job->filters, &hb_filter_denoise );
3312 /* Deblock (uses pp7 default) */
3313 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3314 * the macgui's purposes a value of 0 actually means to not even use the filter
3315 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3317 if ([fPictureController deblock] != 0)
3319 NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
3320 hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
3321 hb_list_add( job->filters, &hb_filter_deblock );
3328 #pragma mark Job Handling
3334 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
3335 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
3336 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
3337 hb_job_t * job = title->job;
3338 hb_audio_config_t * audio;
3339 /* Title Angle for dvdnav */
3340 job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
3341 /* Chapter selection */
3342 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
3343 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
3345 /* Format (Muxer) and Video Encoder */
3346 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
3347 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
3350 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
3351 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
3353 job->largeFileSize = 1;
3357 job->largeFileSize = 0;
3359 /* We set http optimized mp4 here */
3360 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
3362 job->mp4_optimize = 1;
3366 job->mp4_optimize = 0;
3370 /* We set the chapter marker extraction here based on the format being
3371 mpeg4 or mkv and the checkbox being checked */
3372 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
3374 job->chapter_markers = 1;
3376 /* now lets get our saved chapter names out the array in the queue file
3377 * and insert them back into the title chapter list. We have it here,
3378 * because unless we are inserting chapter markers there is no need to
3379 * spend the overhead of iterating through the chapter names array imo
3380 * Also, note that if for some reason we don't apply chapter names, the
3381 * chapters just come out 001, 002, etc. etc.
3384 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
3386 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
3388 while (tempObject = [enumerator nextObject])
3390 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3391 if( chapter != NULL )
3393 strncpy( chapter->title, [tempObject UTF8String], 1023);
3394 chapter->title[1023] = '\0';
3401 job->chapter_markers = 0;
3404 if( job->vcodec & HB_VCODEC_X264 )
3406 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
3416 /* Below Sends x264 options to the core library if x264 is selected*/
3417 /* Lets use this as per Nyx, Thanks Nyx!*/
3418 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
3419 /* Turbo first pass if two pass and Turbo First pass is selected */
3420 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
3422 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
3423 NSString *firstPassOptStringTurbo = @":ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
3424 /* append the "Turbo" string variable to the existing opts string.
3425 Note: the "Turbo" string must be appended, not prepended to work properly*/
3426 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
3427 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
3431 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
3437 /* Picture Size Settings */
3438 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
3439 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
3441 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
3442 job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"] intValue];
3443 if ([[queueToApply objectForKey:@"PicturePAR"] intValue] == 3)
3445 /* insert our custom values here for capuj */
3446 job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"] intValue];
3447 job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"] intValue];
3449 job->anamorphic.modulus = [[queueToApply objectForKey:@"PicturePARModulus"] intValue];
3451 job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"] intValue];
3452 job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"] intValue];
3454 job->anamorphic.dar_width = [[queueToApply objectForKey:@"PicturePARDisplayWidth"] floatValue];
3455 job->anamorphic.dar_height = [[queueToApply objectForKey:@"PicturePARDisplayHeight"] floatValue];
3458 /* Here we use the crop values saved at the time the preset was saved */
3459 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
3460 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
3461 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
3462 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
3464 /* Video settings */
3467 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
3468 * and detelecine is on, so we handle that in the logic below
3471 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
3473 /* a specific framerate has been chosen */
3474 job->vrate = 27000000;
3475 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
3476 /* We are not same as source so we set job->cfr to 1
3477 * to enable constant frame rate since user has specified
3478 * a specific framerate*/
3483 /* We are same as source (variable) */
3484 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
3485 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
3486 /* We are same as source so we set job->cfr to 0
3487 * to enable true same as source framerate */
3489 /* If we are same as source and we have detelecine on, we need to turn on
3492 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3498 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
3501 Bitrate should already have been calculated and displayed
3502 in fVidBitrateField, so let's just use it same as abr*/
3503 job->vquality = -1.0;
3504 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
3506 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
3508 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
3513 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
3518 #pragma mark Process Subtitles to libhb
3520 /* Map the settings in the dictionaries for the SubtitleList array to match title->list_subtitle
3521 * which means that we need to account for the offset of non source language settings in from
3522 * the NSPopUpCell menu. For all of the objects in the SubtitleList array this means 0 is "None"
3523 * from the popup menu, additionally the first track has "Foreign Audio Search" at 1. So we use
3524 * an int to offset the index number for the objectForKey:@"subtitleSourceTrackNum" to map that
3525 * to the source tracks position in title->list_subtitle.
3532 bool one_burned = FALSE;
3535 NSEnumerator *enumerator = [[queueToApply objectForKey:@"SubtitleList"] objectEnumerator];
3537 while (tempObject = [enumerator nextObject])
3540 subtitle = [[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue];
3541 force = [[tempObject objectForKey:@"subtitleTrackForced"] intValue];
3542 burned = [[tempObject objectForKey:@"subtitleTrackBurned"] intValue];
3543 def = [[tempObject objectForKey:@"subtitleTrackDefault"] intValue];
3545 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
3546 * we want to ignore it for display as well as encoding.
3550 /* if i is 0, then we are in the first item of the subtitles which we need to
3551 * check for the "Foreign Audio Search" which would be subtitleSourceTrackNum of 1
3552 * bearing in mind that for all tracks subtitleSourceTrackNum of 0 is None.
3555 /* if we are on the first track and using "Foreign Audio Search" */
3556 if (i == 0 && subtitle == 1)
3558 [self writeToActivityLog: "Foreign Language Search: %d", 1];
3560 job->indepth_scan = 1;
3561 if (burned == 1 || job->mux != HB_MUX_MP4)
3563 if (burned != 1 && job->mux == HB_MUX_MKV)
3565 job->select_subtitle_config.dest = PASSTHRUSUB;
3569 job->select_subtitle_config.dest = RENDERSUB;
3572 job->select_subtitle_config.force = force;
3573 job->select_subtitle_config.default_track = def;
3581 /* for the actual source tracks, we must subtract the non source entries so
3582 * that the menu index matches the source subtitle_list index for convenience */
3585 /* for the first track, the source tracks start at menu index 2 ( None is 0,
3586 * Foreign Language Search is 1) so subtract 2 */
3587 subtitle = subtitle - 2;
3591 /* for all other tracks, the source tracks start at menu index 1 (None is 0)
3594 subtitle = subtitle - 1;
3597 /* We are setting a source subtitle so access the source subtitle info */
3598 hb_subtitle_t * subt;
3600 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3602 /* if we are getting the subtitles from an external srt file */
3603 if ([[tempObject objectForKey:@"subtitleSourceTrackType"] isEqualToString:@"SRT"])
3605 hb_subtitle_config_t sub_config;
3607 sub_config.offset = [[tempObject objectForKey:@"subtitleTrackSrtOffset"] intValue];
3609 /* we need to srncpy file name and codeset */
3610 //sub_config.src_filename = [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String];
3611 strncpy(sub_config.src_filename, [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String], 128);
3612 //sub_config.src_codeset = [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String];
3613 strncpy(sub_config.src_codeset, [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String], 40);
3615 sub_config.force = 0;
3616 sub_config.dest = PASSTHRUSUB;
3617 sub_config.default_track = def;
3619 hb_srt_add( job, &sub_config, [[tempObject objectForKey:@"subtitleTrackSrtLanguageIso3"] UTF8String]);
3625 [self writeToActivityLog: "Setting Subtitle: %s", subt];
3627 hb_subtitle_config_t sub_config = subt->config;
3629 if (!burned && job->mux == HB_MUX_MKV &&
3630 subt->format == PICTURESUB)
3632 sub_config.dest = PASSTHRUSUB;
3634 else if (!burned && job->mux == HB_MUX_MP4 &&
3635 subt->format == PICTURESUB)
3637 // Skip any non-burned vobsubs when output is mp4
3640 else if ( burned && subt->format == PICTURESUB )
3642 // Only allow one subtitle to be burned into the video
3647 sub_config.force = force;
3648 sub_config.default_track = def;
3649 hb_subtitle_add( job, &sub_config, subtitle );
3660 /* Audio tracks and mixdowns */
3661 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3662 int audiotrack_count = hb_list_count(job->list_audio);
3663 for( int i = 0; i < audiotrack_count;i++)
3665 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3666 hb_list_rem(job->list_audio, temp_audio);
3668 /* Now lets add our new tracks to the audio list here */
3669 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
3671 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3672 hb_audio_config_init(audio);
3673 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3674 /* We go ahead and assign values to our audio->out.<properties> */
3675 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3676 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
3677 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
3678 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
3679 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
3680 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
3682 hb_audio_add( job, audio );
3685 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
3688 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3689 hb_audio_config_init(audio);
3690 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3691 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
3692 /* We go ahead and assign values to our audio->out.<properties> */
3693 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3694 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
3695 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
3696 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
3697 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
3698 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
3700 hb_audio_add( job, audio );
3704 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
3706 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3707 hb_audio_config_init(audio);
3708 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3709 /* We go ahead and assign values to our audio->out.<properties> */
3710 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3711 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
3712 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
3713 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
3714 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
3715 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
3717 hb_audio_add( job, audio );
3721 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
3723 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3724 hb_audio_config_init(audio);
3725 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3726 /* We go ahead and assign values to our audio->out.<properties> */
3727 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3728 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
3729 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
3730 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
3731 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
3732 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue];
3734 hb_audio_add( job, audio );
3740 job->filters = hb_list_init();
3742 /* Now lets call the filters if applicable.
3743 * The order of the filters is critical
3746 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3748 /* use a custom detelecine string */
3749 hb_filter_detelecine.settings = (char *) [[queueToApply objectForKey:@"PictureDetelecineCustom"] UTF8String];
3750 hb_list_add( job->filters, &hb_filter_detelecine );
3752 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 2)
3754 /* Use libhb's default values */
3755 hb_list_add( job->filters, &hb_filter_detelecine );
3758 if ([[queueToApply objectForKey:@"PictureDecombDeinterlace"] intValue] == 1)
3761 /* we add the custom string if present */
3762 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
3764 /* use a custom decomb string */
3765 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"PictureDecombCustom"] UTF8String];
3766 hb_list_add( job->filters, &hb_filter_decomb );
3768 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 2)
3770 /* Use libhb default */
3771 hb_list_add( job->filters, &hb_filter_decomb );
3779 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
3781 /* we add the custom string if present */
3782 hb_filter_deinterlace.settings = (char *) [[queueToApply objectForKey:@"PictureDeinterlaceCustom"] UTF8String];
3783 hb_list_add( job->filters, &hb_filter_deinterlace );
3785 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
3787 /* Run old deinterlacer fd by default */
3788 hb_filter_deinterlace.settings = "-1";
3789 hb_list_add( job->filters, &hb_filter_deinterlace );
3791 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
3793 /* Yadif mode 0 (without spatial deinterlacing.) */
3794 hb_filter_deinterlace.settings = "2";
3795 hb_list_add( job->filters, &hb_filter_deinterlace );
3797 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 4)
3799 /* Yadif (with spatial deinterlacing) */
3800 hb_filter_deinterlace.settings = "0";
3801 hb_list_add( job->filters, &hb_filter_deinterlace );
3807 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Custom in popup
3809 /* we add the custom string if present */
3810 hb_filter_denoise.settings = (char *) [[queueToApply objectForKey:@"PictureDenoiseCustom"] UTF8String];
3811 hb_list_add( job->filters, &hb_filter_denoise );
3813 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Weak in popup
3815 hb_filter_denoise.settings = "2:1:2:3";
3816 hb_list_add( job->filters, &hb_filter_denoise );
3818 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Medium in popup
3820 hb_filter_denoise.settings = "3:2:2:3";
3821 hb_list_add( job->filters, &hb_filter_denoise );
3823 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 4) // Strong in popup
3825 hb_filter_denoise.settings = "7:7:5:5";
3826 hb_list_add( job->filters, &hb_filter_denoise );
3830 /* Deblock (uses pp7 default) */
3831 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3832 * the macgui's purposes a value of 0 actually means to not even use the filter
3833 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3835 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
3837 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
3838 hb_list_add( job->filters, &hb_filter_deblock );
3840 [self writeToActivityLog: "prepareJob exiting"];
3845 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
3847 - (IBAction) addToQueue: (id) sender
3849 /* We get the destination directory from the destination field here */
3850 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3851 /* We check for a valid destination here */
3852 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3854 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3861 BOOL fileExistsInQueue;
3862 fileExistsInQueue = NO;
3864 /* We check for and existing file here */
3865 if([[NSFileManager defaultManager] fileExistsAtPath: [fDstFile2Field stringValue]])
3870 /* We now run through the queue and make sure we are not overwriting an exisiting queue item */
3872 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
3874 while (tempObject = [enumerator nextObject])
3876 NSDictionary *thisQueueDict = tempObject;
3877 if ([[thisQueueDict objectForKey:@"DestinationPath"] isEqualToString: [fDstFile2Field stringValue]])
3879 fileExistsInQueue = YES;
3885 if(fileExists == YES)
3887 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists.", @"" ),
3888 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3889 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3890 NULL, NULL, [NSString stringWithFormat:
3891 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3892 [fDstFile2Field stringValue]] );
3894 else if (fileExistsInQueue == YES)
3896 NSBeginCriticalAlertSheet( NSLocalizedString( @"There is already a queue item for this destination.", @"" ),
3897 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3898 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3899 NULL, NULL, [NSString stringWithFormat:
3900 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3901 [fDstFile2Field stringValue]] );
3905 [self doAddToQueue];
3909 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
3910 the user if they want to overwrite an exiting movie file.
3912 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
3913 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3915 if( returnCode == NSAlertAlternateReturn )
3916 [self doAddToQueue];
3919 - (void) doAddToQueue
3921 [self addQueueFileItem ];
3926 /* Rip: puts up an alert before ultimately calling doRip
3928 - (IBAction) Rip: (id) sender
3930 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
3931 /* Rip or Cancel ? */
3933 hb_get_state2( fQueueEncodeLibhb, &s );
3935 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
3937 [self Cancel: sender];
3941 /* We check to see if we need to warn the user that the computer will go to sleep
3942 or shut down when encoding is finished */
3943 [self remindUserOfSleepOrShutdown];
3945 // If there are pending jobs in the queue, then this is a rip the queue
3946 if (fPendingCount > 0)
3948 /* here lets start the queue with the first pending item */
3949 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3954 // Before adding jobs to the queue, check for a valid destination.
3956 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3957 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3959 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3963 /* We check for duplicate name here */
3964 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
3966 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3967 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3968 @selector( overWriteAlertDone:returnCode:contextInfo: ),
3969 NULL, NULL, [NSString stringWithFormat:
3970 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3971 [fDstFile2Field stringValue]] );
3973 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
3977 /* if there are no pending jobs in the queue, then add this one to the queue and rip
3978 otherwise, just rip the queue */
3979 if(fPendingCount == 0)
3981 [self doAddToQueue];
3984 /* go right to processing the new queue encode */
3985 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3990 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3991 want to overwrite an exiting movie file.
3993 - (void) overWriteAlertDone: (NSWindow *) sheet
3994 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3996 if( returnCode == NSAlertAlternateReturn )
3998 /* if there are no jobs in the queue, then add this one to the queue and rip
3999 otherwise, just rip the queue */
4000 if( fPendingCount == 0 )
4002 [self doAddToQueue];
4005 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
4006 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
4007 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
4012 - (void) remindUserOfSleepOrShutdown
4014 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
4016 /*Warn that computer will sleep after encoding*/
4019 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);
4020 [NSApp requestUserAttention:NSCriticalRequest];
4021 if ( reminduser == NSAlertAlternateReturn )
4023 [self showPreferencesWindow:nil];
4026 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
4028 /*Warn that computer will shut down after encoding*/
4031 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);
4032 [NSApp requestUserAttention:NSCriticalRequest];
4033 if ( reminduser == NSAlertAlternateReturn )
4035 [self showPreferencesWindow:nil];
4044 /* Let libhb do the job */
4045 hb_start( fQueueEncodeLibhb );
4046 /*set the fEncodeState State */
4051 //------------------------------------------------------------------------------------
4052 // Displays an alert asking user if the want to cancel encoding of current job.
4053 // Cancel: returns immediately after posting the alert. Later, when the user
4054 // acknowledges the alert, doCancelCurrentJob is called.
4055 //------------------------------------------------------------------------------------
4056 - (IBAction)Cancel: (id)sender
4058 if (!fQueueController) return;
4060 hb_pause( fQueueEncodeLibhb );
4061 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
4063 // Which window to attach the sheet to?
4064 NSWindow * docWindow;
4065 if ([sender respondsToSelector: @selector(window)])
4066 docWindow = [sender window];
4068 docWindow = fWindow;
4070 NSBeginCriticalAlertSheet(
4072 NSLocalizedString(@"Continue Encoding", nil),
4073 NSLocalizedString(@"Cancel Current and Stop", nil),
4074 NSLocalizedString(@"Cancel Current and Continue", nil),
4076 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
4077 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
4079 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
4082 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
4084 hb_resume( fQueueEncodeLibhb );
4085 if (returnCode == NSAlertOtherReturn)
4087 [self doCancelCurrentJob]; // <- this also stops libhb
4089 if (returnCode == NSAlertAlternateReturn)
4091 [self doCancelCurrentJobAndStop];
4095 //------------------------------------------------------------------------------------
4096 // Cancels and deletes the current job and stops libhb from processing the remaining
4098 //------------------------------------------------------------------------------------
4099 - (void) doCancelCurrentJob
4101 // Stop the current job. hb_stop will only cancel the current pass and then set
4102 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
4103 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
4104 // remaining passes of the job and then start the queue back up if there are any
4108 hb_stop( fQueueEncodeLibhb );
4110 // Delete all remaining jobs since libhb doesn't do this on its own.
4112 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
4113 hb_rem( fQueueEncodeLibhb, job );
4115 fEncodeState = 2; // don't alert at end of processing since this was a cancel
4117 // now that we've stopped the currently encoding job, lets mark it as cancelled
4118 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
4119 // and as always, save it in the queue .plist...
4120 /* We save all of the Queue data here */
4121 [self saveQueueFileItem];
4122 // so now lets move to
4123 currentQueueEncodeIndex++ ;
4124 // ... and see if there are more items left in our queue
4125 int queueItems = [QueueFileArray count];
4126 /* If we still have more items in our queue, lets go to the next one */
4127 if (currentQueueEncodeIndex < queueItems)
4129 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
4130 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
4132 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
4136 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
4141 - (void) doCancelCurrentJobAndStop
4143 hb_stop( fQueueEncodeLibhb );
4145 // Delete all remaining jobs since libhb doesn't do this on its own.
4147 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
4148 hb_rem( fQueueEncodeLibhb, job );
4151 fEncodeState = 2; // don't alert at end of processing since this was a cancel
4153 // now that we've stopped the currently encoding job, lets mark it as cancelled
4154 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
4155 // and as always, save it in the queue .plist...
4156 /* We save all of the Queue data here */
4157 [self saveQueueFileItem];
4158 // so now lets move to
4159 currentQueueEncodeIndex++ ;
4160 [self writeToActivityLog: "cancelling current job and stopping the queue"];
4162 - (IBAction) Pause: (id) sender
4165 hb_get_state2( fQueueEncodeLibhb, &s );
4167 if( s.state == HB_STATE_PAUSED )
4169 hb_resume( fQueueEncodeLibhb );
4173 hb_pause( fQueueEncodeLibhb );
4178 #pragma mark GUI Controls Changed Methods
4180 - (IBAction) titlePopUpChanged: (id) sender
4182 hb_list_t * list = hb_get_titles( fHandle );
4183 hb_title_t * title = (hb_title_t*)
4184 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4186 /* If we are a stream type, grok the output file name from title->name upon title change */
4187 if (title->type == HB_STREAM_TYPE)
4189 /* we set the default name according to the new title->name */
4190 [fDstFile2Field setStringValue: [NSString stringWithFormat:
4191 @"%@/%@.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
4192 [NSString stringWithUTF8String: title->name],
4193 [[fDstFile2Field stringValue] pathExtension]]];
4194 /* If we have more than one title and are stream then we have a batch, change the source to read out the parent folder also */
4195 if ( hb_list_count( list ) > 1 )
4197 [fSrcDVD2Field setStringValue:[NSString stringWithFormat:@"%@/%@", browsedSourceDisplayName,[NSString stringWithUTF8String: title->name]]];
4202 /* If Auto Naming is on. We create an output filename of dvd name - title number */
4203 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
4205 [fDstFile2Field setStringValue: [NSString stringWithFormat:
4206 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
4207 [browsedSourceDisplayName stringByDeletingPathExtension],
4209 [[fDstFile2Field stringValue] pathExtension]]];
4212 /* Update chapter popups */
4213 [fSrcChapterStartPopUp removeAllItems];
4214 [fSrcChapterEndPopUp removeAllItems];
4215 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
4217 [fSrcChapterStartPopUp addItemWithTitle: [NSString
4218 stringWithFormat: @"%d", i + 1]];
4219 [fSrcChapterEndPopUp addItemWithTitle: [NSString
4220 stringWithFormat: @"%d", i + 1]];
4223 [fSrcChapterStartPopUp selectItemAtIndex: 0];
4224 [fSrcChapterEndPopUp selectItemAtIndex:
4225 hb_list_count( title->list_chapter ) - 1];
4226 [self chapterPopUpChanged:nil];
4228 /* if using dvd nav, show the angle widget */
4229 if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue])
4231 [fSrcAngleLabel setHidden:NO];
4232 [fSrcAnglePopUp setHidden:NO];
4234 [fSrcAnglePopUp removeAllItems];
4235 for( int i = 0; i < title->angle_count; i++ )
4237 [fSrcAnglePopUp addItemWithTitle: [NSString stringWithFormat: @"%d", i + 1]];
4239 [fSrcAnglePopUp selectItemAtIndex: 0];
4243 [fSrcAngleLabel setHidden:YES];
4244 [fSrcAnglePopUp setHidden:YES];
4247 /* Start Get and set the initial pic size for display */
4248 hb_job_t * job = title->job;
4251 /* Set Auto Crop to on upon selecting a new title */
4252 [fPictureController setAutoCrop:YES];
4254 /* We get the originial output picture width and height and put them
4255 in variables for use with some presets later on */
4256 PicOrigOutputWidth = job->width;
4257 PicOrigOutputHeight = job->height;
4258 AutoCropTop = job->crop[0];
4259 AutoCropBottom = job->crop[1];
4260 AutoCropLeft = job->crop[2];
4261 AutoCropRight = job->crop[3];
4263 /* Reset the new title in fPictureController && fPreviewController*/
4264 [fPictureController SetTitle:title];
4267 /* Update Subtitle Table */
4268 [fSubtitlesDelegate resetWithTitle:title];
4269 [fSubtitlesTable reloadData];
4272 /* Update chapter table */
4273 [fChapterTitlesDelegate resetWithTitle:title];
4274 [fChapterTable reloadData];
4276 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
4277 int audiotrack_count = hb_list_count(job->list_audio);
4278 for( int i = 0; i < audiotrack_count;i++)
4280 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4281 hb_list_rem(job->list_audio, temp_audio);
4284 /* Update audio popups */
4285 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
4286 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
4287 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
4288 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
4289 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
4290 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
4291 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
4292 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4293 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4294 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
4296 /* changing the title may have changed the audio channels on offer, */
4297 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4298 [self audioTrackPopUpChanged: fAudLang1PopUp];
4299 [self audioTrackPopUpChanged: fAudLang2PopUp];
4300 [self audioTrackPopUpChanged: fAudLang3PopUp];
4301 [self audioTrackPopUpChanged: fAudLang4PopUp];
4303 [fVidRatePopUp selectItemAtIndex: 0];
4305 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
4306 [self calculatePictureSizing:nil];
4308 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
4309 [self selectPreset:nil];
4312 - (IBAction) chapterPopUpChanged: (id) sender
4315 /* If start chapter popup is greater than end chapter popup,
4316 we set the end chapter popup to the same as start chapter popup */
4317 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
4319 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
4323 hb_list_t * list = hb_get_titles( fHandle );
4324 hb_title_t * title = (hb_title_t *)
4325 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4327 hb_chapter_t * chapter;
4328 int64_t duration = 0;
4329 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
4330 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
4332 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
4333 duration += chapter->duration;
4336 duration /= 90000; /* pts -> seconds */
4337 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
4338 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
4341 [self calculateBitrate: sender];
4343 if ( [fSrcChapterStartPopUp indexOfSelectedItem] == [fSrcChapterEndPopUp indexOfSelectedItem] )
4345 /* Disable chapter markers for any source with less than two chapters as it makes no sense. */
4346 [fCreateChapterMarkers setEnabled: NO];
4347 [fCreateChapterMarkers setState: NSOffState];
4351 [fCreateChapterMarkers setEnabled: YES];
4355 - (IBAction) formatPopUpChanged: (id) sender
4357 NSString * string = [fDstFile2Field stringValue];
4358 int format = [fDstFormatPopUp indexOfSelectedItem];
4360 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
4361 [fDstMp4LargeFileCheck setHidden: YES];
4362 [fDstMp4HttpOptFileCheck setHidden: YES];
4363 [fDstMp4iPodFileCheck setHidden: YES];
4365 /* Update the Video Codec PopUp */
4366 /* lets get the tag of the currently selected item first so we might reset it later */
4367 int selectedVidEncoderTag;
4368 selectedVidEncoderTag = [[fVidEncoderPopUp selectedItem] tag];
4370 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
4371 [fVidEncoderPopUp removeAllItems];
4372 NSMenuItem *menuItem;
4373 /* These video encoders are available to all of our current muxers, so lets list them once here */
4374 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
4375 [menuItem setTag: HB_VCODEC_FFMPEG];
4380 /*Get Default MP4 File Extension*/
4381 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
4389 /* Add additional video encoders here */
4390 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4391 [menuItem setTag: HB_VCODEC_X264];
4392 /* We show the mp4 option checkboxes here since we are mp4 */
4393 [fCreateChapterMarkers setEnabled: YES];
4394 [fDstMp4LargeFileCheck setHidden: NO];
4395 [fDstMp4HttpOptFileCheck setHidden: NO];
4396 [fDstMp4iPodFileCheck setHidden: NO];
4401 /* Add additional video encoders here */
4402 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
4403 [menuItem setTag: HB_VCODEC_X264];
4404 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
4405 [menuItem setTag: HB_VCODEC_THEORA];
4406 /* We enable the create chapters checkbox here */
4407 [fCreateChapterMarkers setEnabled: YES];
4412 /* tell fSubtitlesDelegate we have a new video container */
4414 [fSubtitlesDelegate containerChanged:[[fDstFormatPopUp selectedItem] tag]];
4415 [fSubtitlesTable reloadData];
4416 /* if we have a previously selected vid encoder tag, then try to select it */
4417 if (selectedVidEncoderTag)
4419 [fVidEncoderPopUp selectItemWithTag: selectedVidEncoderTag];
4423 [fVidEncoderPopUp selectItemAtIndex: 0];
4426 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4427 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4428 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4429 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4432 [self autoSetM4vExtension: sender];
4434 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
4436 if( SuccessfulScan )
4438 /* Add/replace to the correct extension */
4439 [self audioTrackPopUpChanged: fAudLang1PopUp];
4440 [self audioTrackPopUpChanged: fAudLang2PopUp];
4441 [self audioTrackPopUpChanged: fAudLang3PopUp];
4442 [self audioTrackPopUpChanged: fAudLang4PopUp];
4444 if( [fVidEncoderPopUp selectedItem] == nil )
4447 [fVidEncoderPopUp selectItemAtIndex:0];
4448 [self videoEncoderPopUpChanged:nil];
4450 /* changing the format may mean that we can / can't offer mono or 6ch, */
4451 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4453 /* We call the method to properly enable/disable turbo 2 pass */
4454 [self twoPassCheckboxChanged: sender];
4455 /* We call method method to change UI to reflect whether a preset is used or not*/
4458 [self customSettingUsed: sender];
4461 - (IBAction) autoSetM4vExtension: (id) sender
4463 if ( [fDstFormatPopUp indexOfSelectedItem] )
4466 NSString * extension = @"mp4";
4468 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4469 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4470 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
4471 [fCreateChapterMarkers state] == NSOnState ||
4472 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
4477 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
4480 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
4481 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
4484 /* Method to determine if we should change the UI
4485 To reflect whether or not a Preset is being used or if
4486 the user is using "Custom" settings by determining the sender*/
4487 - (IBAction) customSettingUsed: (id) sender
4489 if ([sender stringValue])
4491 /* Deselect the currently selected Preset if there is one*/
4492 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
4493 /* Change UI to show "Custom" settings are being used */
4494 [fPresetSelectedDisplay setStringValue: @"Custom"];
4496 curUserPresetChosenNum = nil;
4498 [self calculateBitrate:nil];
4503 #pragma mark - Video
4505 - (IBAction) videoEncoderPopUpChanged: (id) sender
4507 hb_job_t * job = fTitle->job;
4508 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
4510 [fAdvancedOptions setHidden:YES];
4511 /* If we are using x264 then show the x264 advanced panel*/
4512 if (videoEncoder == HB_VCODEC_X264)
4514 [fAdvancedOptions setHidden:NO];
4515 [self autoSetM4vExtension: sender];
4518 if (videoEncoder == HB_VCODEC_FFMPEG)
4520 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
4521 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
4522 anything other than MP4.
4524 [fDstMp4iPodFileCheck setEnabled: NO];
4525 [fDstMp4iPodFileCheck setState: NSOffState];
4529 [fDstMp4iPodFileCheck setEnabled: YES];
4531 [self setupQualitySlider];
4532 [self calculatePictureSizing: sender];
4533 [self twoPassCheckboxChanged: sender];
4537 - (IBAction) twoPassCheckboxChanged: (id) sender
4539 /* check to see if x264 is chosen */
4540 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4542 if( [fVidTwoPassCheck state] == NSOnState)
4544 [fVidTurboPassCheck setHidden: NO];
4548 [fVidTurboPassCheck setHidden: YES];
4549 [fVidTurboPassCheck setState: NSOffState];
4551 /* Make sure Two Pass is checked if Turbo is checked */
4552 if( [fVidTurboPassCheck state] == NSOnState)
4554 [fVidTwoPassCheck setState: NSOnState];
4559 [fVidTurboPassCheck setHidden: YES];
4560 [fVidTurboPassCheck setState: NSOffState];
4563 /* We call method method to change UI to reflect whether a preset is used or not*/
4564 [self customSettingUsed: sender];
4567 - (IBAction ) videoFrameRateChanged: (id) sender
4569 /* We call method method to calculatePictureSizing to error check detelecine*/
4570 [self calculatePictureSizing: sender];
4572 /* We call method method to change UI to reflect whether a preset is used or not*/
4573 [self customSettingUsed: sender];
4575 - (IBAction) videoMatrixChanged: (id) sender;
4577 bool target, bitrate, quality;
4579 target = bitrate = quality = false;
4580 if( [fVidQualityMatrix isEnabled] )
4582 switch( [fVidQualityMatrix selectedRow] )
4595 [fVidTargetSizeField setEnabled: target];
4596 [fVidBitrateField setEnabled: bitrate];
4597 [fVidQualitySlider setEnabled: quality];
4598 [fVidQualityRFField setEnabled: quality];
4599 [fVidQualityRFLabel setEnabled: quality];
4600 [fVidTwoPassCheck setEnabled: !quality &&
4601 [fVidQualityMatrix isEnabled]];
4604 [fVidTwoPassCheck setState: NSOffState];
4605 [fVidTurboPassCheck setHidden: YES];
4606 [fVidTurboPassCheck setState: NSOffState];
4609 [self qualitySliderChanged: sender];
4610 [self calculateBitrate: sender];
4611 [self customSettingUsed: sender];
4614 /* Use this method to setup the quality slider for cq/rf values depending on
4615 * the video encoder selected.
4617 - (void) setupQualitySlider
4619 /* Get the current slider maxValue to check for a change in slider scale later
4620 * so that we can choose a new similar value on the new slider scale */
4621 float previousMaxValue = [fVidQualitySlider maxValue];
4622 float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1);
4623 NSString * qpRFLabelString = @"QP:";
4625 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
4627 [fVidQualitySlider setMinValue:0.0];
4628 [fVidQualitySlider setMaxValue:51.0];
4629 /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
4630 int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
4631 [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
4632 qpRFLabelString = @"RF:";
4635 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
4637 [fVidQualitySlider setMinValue:1.0];
4638 [fVidQualitySlider setMaxValue:31.0];
4639 [fVidQualitySlider setNumberOfTickMarks:31];
4642 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4644 [fVidQualitySlider setMinValue:0.0];
4645 [fVidQualitySlider setMaxValue:63.0];
4646 [fVidQualitySlider setNumberOfTickMarks:64];
4648 [fVidQualityRFLabel setStringValue:qpRFLabelString];
4650 /* check to see if we have changed slider scales */
4651 if (previousMaxValue != [fVidQualitySlider maxValue])
4653 /* if so, convert the old setting to the new scale as close as possible based on percentages */
4654 float rf = ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1) * previousPercentOfSliderScale;
4655 [fVidQualitySlider setFloatValue:rf];
4658 [self qualitySliderChanged:nil];
4661 - (IBAction) qualitySliderChanged: (id) sender
4663 /* Our constant quality slider is in a range based
4664 * on each encoders qp/rf values. The range depends
4665 * on the encoder. Also, the range is inverse of quality
4666 * for all of the encoders *except* for theora
4667 * (ie. as the "quality" goes up, the cq or rf value
4668 * actually goes down). Since the IB sliders always set
4669 * their max value at the right end of the slider, we
4670 * will calculate the inverse, so as the slider floatValue
4671 * goes up, we will show the inverse in the rf field
4672 * so, the floatValue at the right for x264 would be 51
4673 * and our rf field needs to show 0 and vice versa.
4676 float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue];
4677 /* If the encoder is theora, use the float, otherwise use the inverse float*/
4678 float sliderRfToPercent;
4679 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
4681 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];
4682 sliderRfToPercent = [fVidQualityRFField floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4686 [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]];
4687 sliderRfToPercent = ( ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) - ([fVidQualityRFField floatValue] - [fVidQualitySlider minValue])) / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
4689 [fVidConstantCell setTitle: [NSString stringWithFormat:
4690 NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]];
4692 [self customSettingUsed: sender];
4695 - (void) controlTextDidChange: (NSNotification *) notification
4697 [self calculateBitrate:nil];
4700 - (IBAction) calculateBitrate: (id) sender
4702 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
4707 hb_list_t * list = hb_get_titles( fHandle );
4708 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4709 [fSrcTitlePopUp indexOfSelectedItem] );
4710 hb_job_t * job = title->job;
4711 hb_audio_config_t * audio;
4712 /* For hb_calc_bitrate in addition to the Target Size in MB out of the
4713 * Target Size Field, we also need the job info for the Muxer, the Chapters
4714 * as well as all of the audio track info.
4715 * This used to be accomplished by simply calling prepareJob here, however
4716 * since the resilient queue sets the queue array values instead of the job
4717 * values directly, we duplicate the old prepareJob code here for the variables
4720 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
4721 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
4722 job->mux = [[fDstFormatPopUp selectedItem] tag];
4724 /* Audio goes here */
4725 int audiotrack_count = hb_list_count(job->list_audio);
4726 for( int i = 0; i < audiotrack_count;i++)
4728 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
4729 hb_list_rem(job->list_audio, temp_audio);
4731 /* Now we need our audio info here for each track if applicable */
4732 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4734 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4735 hb_audio_config_init(audio);
4736 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4737 /* We go ahead and assign values to our audio->out.<properties> */
4738 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
4739 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
4740 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
4741 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
4742 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
4743 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
4745 hb_audio_add( job, audio );
4748 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4750 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4751 hb_audio_config_init(audio);
4752 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4753 /* We go ahead and assign values to our audio->out.<properties> */
4754 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
4755 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
4756 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
4757 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
4758 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
4759 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
4761 hb_audio_add( job, audio );
4766 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4768 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4769 hb_audio_config_init(audio);
4770 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4771 /* We go ahead and assign values to our audio->out.<properties> */
4772 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
4773 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
4774 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
4775 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
4776 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
4777 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
4779 hb_audio_add( job, audio );
4784 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4786 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4787 hb_audio_config_init(audio);
4788 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4789 /* We go ahead and assign values to our audio->out.<properties> */
4790 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4791 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
4792 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
4793 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
4794 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
4795 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
4797 hb_audio_add( job, audio );
4802 [fVidBitrateField setIntValue: hb_calc_bitrate( job, [fVidTargetSizeField intValue] )];
4806 #pragma mark - Picture
4808 /* lets set the picture size back to the max from right after title scan
4809 Lets use an IBAction here as down the road we could always use a checkbox
4810 in the gui to easily take the user back to max. Remember, the compiler
4811 resolves IBActions down to -(void) during compile anyway */
4812 - (IBAction) revertPictureSizeToMax: (id) sender
4814 hb_job_t * job = fTitle->job;
4815 /* Here we apply the title source and height */
4816 job->width = fTitle->width;
4817 job->height = fTitle->height;
4819 [self calculatePictureSizing: sender];
4820 /* We call method to change UI to reflect whether a preset is used or not*/
4821 [self customSettingUsed: sender];
4825 * Registers changes made in the Picture Settings Window.
4828 - (void)pictureSettingsDidChange
4830 [self calculatePictureSizing:nil];
4833 /* Get and Display Current Pic Settings in main window */
4834 - (IBAction) calculatePictureSizing: (id) sender
4836 if (fTitle->job->anamorphic.mode > 0)
4838 fTitle->job->keep_ratio = 0;
4841 [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
4843 NSString *picCropping;
4844 /* Set the display field for crop as per boolean */
4845 if (![fPictureController autoCrop])
4847 picCropping = @"Custom";
4851 picCropping = @"Auto";
4853 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]]];
4855 [fPictureCroppingField setStringValue: [NSString stringWithFormat:@"Picture Cropping: %@",picCropping]];
4857 NSString *videoFilters;
4860 if ([fPictureController detelecine] == 2)
4862 videoFilters = [videoFilters stringByAppendingString:@" - Detelecine (Default)"];
4864 else if ([fPictureController detelecine] == 1)
4866 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Detelecine (%@)",[fPictureController detelecineCustomString]]];
4870 if ([fPictureController useDecomb] == 1)
4873 if ([fPictureController decomb] == 2)
4875 videoFilters = [videoFilters stringByAppendingString:@" - Decomb (Default)"];
4877 else if ([fPictureController decomb] == 1)
4879 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Decomb (%@)",[fPictureController decombCustomString]]];
4885 if ([fPictureController deinterlace] > 0)
4887 fTitle->job->deinterlace = 1;
4891 fTitle->job->deinterlace = 0;
4894 if ([fPictureController deinterlace] == 2)
4896 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Fast)"];
4898 else if ([fPictureController deinterlace] == 3)
4900 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slow)"];
4902 else if ([fPictureController deinterlace] == 4)
4904 videoFilters = [videoFilters stringByAppendingString:@" - Deinterlace (Slower)"];
4906 else if ([fPictureController deinterlace] == 1)
4908 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deinterlace (%@)",[fPictureController deinterlaceCustomString]]];
4914 if ([fPictureController denoise] == 2)
4916 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Weak)"];
4918 else if ([fPictureController denoise] == 3)
4920 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Medium)"];
4922 else if ([fPictureController denoise] == 4)
4924 videoFilters = [videoFilters stringByAppendingString:@" - Denoise (Strong)"];
4926 else if ([fPictureController denoise] == 1)
4928 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Denoise (%@)",[fPictureController denoiseCustomString]]];
4932 if ([fPictureController deblock] > 0)
4934 videoFilters = [videoFilters stringByAppendingString:[NSString stringWithFormat:@" - Deblock (%d)",[fPictureController deblock]]];
4938 if ([fPictureController grayscale])
4940 videoFilters = [videoFilters stringByAppendingString:@" - Grayscale"];
4942 [fVideoFiltersField setStringValue: [NSString stringWithFormat:@"Video Filters: %@", videoFilters]];
4944 //[fPictureController reloadStillPreview];
4949 #pragma mark - Audio and Subtitles
4950 - (IBAction) audioCodecsPopUpChanged: (id) sender
4953 NSPopUpButton * audiotrackPopUp;
4954 NSPopUpButton * sampleratePopUp;
4955 NSPopUpButton * bitratePopUp;
4956 NSPopUpButton * audiocodecPopUp;
4957 if (sender == fAudTrack1CodecPopUp)
4959 audiotrackPopUp = fAudLang1PopUp;
4960 audiocodecPopUp = fAudTrack1CodecPopUp;
4961 sampleratePopUp = fAudTrack1RatePopUp;
4962 bitratePopUp = fAudTrack1BitratePopUp;
4964 else if (sender == fAudTrack2CodecPopUp)
4966 audiotrackPopUp = fAudLang2PopUp;
4967 audiocodecPopUp = fAudTrack2CodecPopUp;
4968 sampleratePopUp = fAudTrack2RatePopUp;
4969 bitratePopUp = fAudTrack2BitratePopUp;
4971 else if (sender == fAudTrack3CodecPopUp)
4973 audiotrackPopUp = fAudLang3PopUp;
4974 audiocodecPopUp = fAudTrack3CodecPopUp;
4975 sampleratePopUp = fAudTrack3RatePopUp;
4976 bitratePopUp = fAudTrack3BitratePopUp;
4980 audiotrackPopUp = fAudLang4PopUp;
4981 audiocodecPopUp = fAudTrack4CodecPopUp;
4982 sampleratePopUp = fAudTrack4RatePopUp;
4983 bitratePopUp = fAudTrack4BitratePopUp;
4986 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
4987 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4988 [self audioTrackPopUpChanged: audiotrackPopUp];
4992 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
4994 /* We will be setting the enabled/disabled state of each tracks audio controls based on
4995 * the settings of the source audio for that track. We leave the samplerate and bitrate
4996 * to audiotrackMixdownChanged
4999 /* We will first verify that a lower track number has been selected before enabling each track
5000 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
5002 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5004 [fAudLang2PopUp setEnabled: NO];
5005 [fAudLang2PopUp selectItemAtIndex: 0];
5009 [fAudLang2PopUp setEnabled: YES];
5012 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5014 [fAudLang3PopUp setEnabled: NO];
5015 [fAudLang3PopUp selectItemAtIndex: 0];
5019 [fAudLang3PopUp setEnabled: YES];
5021 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5023 [fAudLang4PopUp setEnabled: NO];
5024 [fAudLang4PopUp selectItemAtIndex: 0];
5028 [fAudLang4PopUp setEnabled: YES];
5030 /* enable/disable the mixdown text and popupbutton for audio track 1 */
5031 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5032 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5033 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5034 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5035 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5036 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
5037 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5039 [fAudTrack1CodecPopUp removeAllItems];
5040 [fAudTrack1MixPopUp removeAllItems];
5041 [fAudTrack1RatePopUp removeAllItems];
5042 [fAudTrack1BitratePopUp removeAllItems];
5043 [fAudTrack1DrcSlider setFloatValue: 0.00];
5044 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5046 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
5048 [fAudTrack1RatePopUp setEnabled: NO];
5049 [fAudTrack1BitratePopUp setEnabled: NO];
5050 [fAudTrack1DrcSlider setEnabled: NO];
5051 [fAudTrack1DrcField setEnabled: NO];
5054 /* enable/disable the mixdown text and popupbutton for audio track 2 */
5055 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5056 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5057 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5058 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5059 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5060 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
5061 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5063 [fAudTrack2CodecPopUp removeAllItems];
5064 [fAudTrack2MixPopUp removeAllItems];
5065 [fAudTrack2RatePopUp removeAllItems];
5066 [fAudTrack2BitratePopUp removeAllItems];
5067 [fAudTrack2DrcSlider setFloatValue: 0.00];
5068 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5070 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
5072 [fAudTrack2RatePopUp setEnabled: NO];
5073 [fAudTrack2BitratePopUp setEnabled: NO];
5074 [fAudTrack2DrcSlider setEnabled: NO];
5075 [fAudTrack2DrcField setEnabled: NO];
5078 /* enable/disable the mixdown text and popupbutton for audio track 3 */
5079 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5080 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5081 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5082 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5083 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5084 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
5085 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5087 [fAudTrack3CodecPopUp removeAllItems];
5088 [fAudTrack3MixPopUp removeAllItems];
5089 [fAudTrack3RatePopUp removeAllItems];
5090 [fAudTrack3BitratePopUp removeAllItems];
5091 [fAudTrack3DrcSlider setFloatValue: 0.00];
5092 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5094 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
5096 [fAudTrack3RatePopUp setEnabled: NO];
5097 [fAudTrack3BitratePopUp setEnabled: NO];
5098 [fAudTrack3DrcSlider setEnabled: NO];
5099 [fAudTrack3DrcField setEnabled: NO];
5102 /* enable/disable the mixdown text and popupbutton for audio track 4 */
5103 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5104 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5105 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5106 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5107 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5108 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
5109 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
5111 [fAudTrack4CodecPopUp removeAllItems];
5112 [fAudTrack4MixPopUp removeAllItems];
5113 [fAudTrack4RatePopUp removeAllItems];
5114 [fAudTrack4BitratePopUp removeAllItems];
5115 [fAudTrack4DrcSlider setFloatValue: 0.00];
5116 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5118 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
5120 [fAudTrack4RatePopUp setEnabled: NO];
5121 [fAudTrack4BitratePopUp setEnabled: NO];
5122 [fAudTrack4DrcSlider setEnabled: NO];
5123 [fAudTrack4DrcField setEnabled: NO];
5128 - (IBAction) addAllAudioTracksToPopUp: (id) sender
5131 hb_list_t * list = hb_get_titles( fHandle );
5132 hb_title_t * title = (hb_title_t*)
5133 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
5135 hb_audio_config_t * audio;
5137 [sender removeAllItems];
5138 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
5139 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
5141 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
5142 [[sender menu] addItemWithTitle:
5143 [NSString stringWithUTF8String: audio->lang.description]
5144 action: NULL keyEquivalent: @""];
5146 [sender selectItemAtIndex: 0];
5150 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
5153 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
5154 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
5155 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
5156 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
5158 if (searchPrefixString)
5161 for( int i = 0; i < [sender numberOfItems]; i++ )
5163 /* Try to find the desired search string */
5164 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
5166 [sender selectItemAtIndex: i];
5170 /* couldn't find the string, so select the requested "search string not found" item */
5171 /* index of 0 means select the "none" item */
5172 /* index of 1 means select the first audio track */
5173 [sender selectItemAtIndex: selectIndexIfNotFound];
5177 /* if no search string is provided, then select the selectIndexIfNotFound item */
5178 [sender selectItemAtIndex: selectIndexIfNotFound];
5182 - (IBAction) audioAddAudioTrackCodecs: (id)sender
5184 int format = [fDstFormatPopUp indexOfSelectedItem];
5186 /* setup pointers to the appropriate popups for the correct track */
5187 NSPopUpButton * audiocodecPopUp;
5188 NSPopUpButton * audiotrackPopUp;
5189 if (sender == fAudTrack1CodecPopUp)
5191 audiotrackPopUp = fAudLang1PopUp;
5192 audiocodecPopUp = fAudTrack1CodecPopUp;
5194 else if (sender == fAudTrack2CodecPopUp)
5196 audiotrackPopUp = fAudLang2PopUp;
5197 audiocodecPopUp = fAudTrack2CodecPopUp;
5199 else if (sender == fAudTrack3CodecPopUp)
5201 audiotrackPopUp = fAudLang3PopUp;
5202 audiocodecPopUp = fAudTrack3CodecPopUp;
5206 audiotrackPopUp = fAudLang4PopUp;
5207 audiocodecPopUp = fAudTrack4CodecPopUp;
5210 [audiocodecPopUp removeAllItems];
5211 /* Make sure "None" isnt selected in the source track */
5212 if ([audiotrackPopUp indexOfSelectedItem] > 0)
5214 [audiocodecPopUp setEnabled:YES];
5215 NSMenuItem *menuItem;
5216 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
5222 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5223 [menuItem setTag: HB_ACODEC_FAAC];
5226 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5227 [menuItem setTag: HB_ACODEC_CA_AAC];
5230 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5231 [menuItem setTag: HB_ACODEC_AC3];
5237 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
5238 [menuItem setTag: HB_ACODEC_FAAC];
5240 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
5241 [menuItem setTag: HB_ACODEC_CA_AAC];
5243 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5244 [menuItem setTag: HB_ACODEC_AC3];
5246 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"DTS Passthru" action: NULL keyEquivalent: @""];
5247 [menuItem setTag: HB_ACODEC_DCA];
5249 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5250 [menuItem setTag: HB_ACODEC_LAME];
5252 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5253 [menuItem setTag: HB_ACODEC_VORBIS];
5259 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5260 [menuItem setTag: HB_ACODEC_LAME];
5262 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
5263 [menuItem setTag: HB_ACODEC_AC3];
5269 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
5270 [menuItem setTag: HB_ACODEC_VORBIS];
5272 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
5273 [menuItem setTag: HB_ACODEC_LAME];
5276 [audiocodecPopUp selectItemAtIndex:0];
5280 [audiocodecPopUp setEnabled:NO];
5284 - (IBAction) audioTrackPopUpChanged: (id) sender
5286 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
5287 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
5290 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
5293 /* make sure we have a selected title before continuing */
5294 if (fTitle == NULL) return;
5295 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
5296 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
5298 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
5300 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
5302 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
5304 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
5306 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
5308 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
5310 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
5312 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
5315 /* Now lets make the sender the appropriate Audio Track popup from this point on */
5316 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
5318 sender = fAudLang1PopUp;
5320 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
5322 sender = fAudLang2PopUp;
5324 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
5326 sender = fAudLang3PopUp;
5328 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
5330 sender = fAudLang4PopUp;
5333 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
5334 NSPopUpButton * mixdownPopUp;
5335 NSPopUpButton * audiocodecPopUp;
5336 NSPopUpButton * sampleratePopUp;
5337 NSPopUpButton * bitratePopUp;
5338 if (sender == fAudLang1PopUp)
5340 mixdownPopUp = fAudTrack1MixPopUp;
5341 audiocodecPopUp = fAudTrack1CodecPopUp;
5342 sampleratePopUp = fAudTrack1RatePopUp;
5343 bitratePopUp = fAudTrack1BitratePopUp;
5345 else if (sender == fAudLang2PopUp)
5347 mixdownPopUp = fAudTrack2MixPopUp;
5348 audiocodecPopUp = fAudTrack2CodecPopUp;
5349 sampleratePopUp = fAudTrack2RatePopUp;
5350 bitratePopUp = fAudTrack2BitratePopUp;
5352 else if (sender == fAudLang3PopUp)
5354 mixdownPopUp = fAudTrack3MixPopUp;
5355 audiocodecPopUp = fAudTrack3CodecPopUp;
5356 sampleratePopUp = fAudTrack3RatePopUp;
5357 bitratePopUp = fAudTrack3BitratePopUp;
5361 mixdownPopUp = fAudTrack4MixPopUp;
5362 audiocodecPopUp = fAudTrack4CodecPopUp;
5363 sampleratePopUp = fAudTrack4RatePopUp;
5364 bitratePopUp = fAudTrack4BitratePopUp;
5367 /* get the index of the selected audio Track*/
5368 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
5370 /* pointer for the hb_audio_s struct we will use later on */
5371 hb_audio_config_t * audio;
5374 /* check if the audio mixdown controls need their enabled state changing */
5375 [self setEnabledStateOfAudioMixdownControls:nil];
5377 if (thisAudioIndex != -1)
5381 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
5383 /* actually manipulate the proper mixdowns here */
5384 /* delete the previous audio mixdown options */
5385 [mixdownPopUp removeAllItems];
5387 acodec = [[audiocodecPopUp selectedItem] tag];
5392 /* find out if our selected output audio codec supports mono and / or 6ch */
5393 /* we also check for an input codec of AC3 or DCA,
5394 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
5395 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
5396 but this may change in the future, so they are separated for flexibility */
5397 int audioCodecsSupportMono =
5398 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5399 (acodec != HB_ACODEC_LAME);
5400 int audioCodecsSupport6Ch =
5401 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
5402 (acodec != HB_ACODEC_LAME);
5404 /* check for AC-3 passthru */
5405 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5408 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5409 [NSString stringWithUTF8String: "AC3 Passthru"]
5410 action: NULL keyEquivalent: @""];
5411 [menuItem setTag: HB_ACODEC_AC3];
5413 else if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5415 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5416 [NSString stringWithUTF8String: "DTS Passthru"]
5417 action: NULL keyEquivalent: @""];
5418 [menuItem setTag: HB_ACODEC_DCA];
5423 /* add the appropriate audio mixdown menuitems to the popupbutton */
5424 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
5425 so that we can reference the mixdown later */
5427 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
5428 int minMixdownUsed = 0;
5429 int maxMixdownUsed = 0;
5431 /* get the input channel layout without any lfe channels */
5432 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
5434 /* do we want to add a mono option? */
5435 if (audioCodecsSupportMono == 1)
5437 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5438 [NSString stringWithUTF8String: hb_audio_mixdowns[0].human_readable_name]
5439 action: NULL keyEquivalent: @""];
5440 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
5441 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
5442 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
5445 /* do we want to add a stereo option? */
5446 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
5447 /* also offer stereo if we have a stereo-or-better source */
5448 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
5450 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5451 [NSString stringWithUTF8String: hb_audio_mixdowns[1].human_readable_name]
5452 action: NULL keyEquivalent: @""];
5453 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
5454 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
5455 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
5458 /* do we want to add a dolby surround (DPL1) option? */
5459 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
5461 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5462 [NSString stringWithUTF8String: hb_audio_mixdowns[2].human_readable_name]
5463 action: NULL keyEquivalent: @""];
5464 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
5465 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
5466 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
5469 /* do we want to add a dolby pro logic 2 (DPL2) option? */
5470 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
5472 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5473 [NSString stringWithUTF8String: hb_audio_mixdowns[3].human_readable_name]
5474 action: NULL keyEquivalent: @""];
5475 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
5476 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
5477 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
5480 /* do we want to add a 6-channel discrete option? */
5481 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
5483 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5484 [NSString stringWithUTF8String: hb_audio_mixdowns[4].human_readable_name]
5485 action: NULL keyEquivalent: @""];
5486 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
5487 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
5488 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
5491 /* do we want to add an AC-3 passthrough option? */
5492 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
5494 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5495 [NSString stringWithUTF8String: hb_audio_mixdowns[5].human_readable_name]
5496 action: NULL keyEquivalent: @""];
5497 [menuItem setTag: HB_ACODEC_AC3];
5498 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5499 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5502 /* do we want to add a DTS Passthru option ? HB_ACODEC_DCA*/
5503 if (audio->in.codec == HB_ACODEC_DCA && acodec == HB_ACODEC_DCA)
5505 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
5506 [NSString stringWithUTF8String: hb_audio_mixdowns[5].human_readable_name]
5507 action: NULL keyEquivalent: @""];
5508 [menuItem setTag: HB_ACODEC_DCA];
5509 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
5510 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
5513 /* auto-select the best mixdown based on our saved mixdown preference */
5515 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
5516 /* ultimately this should be a prefs option */
5519 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
5520 if (mixdownToUse > 0)
5522 useMixdown = mixdownToUse;
5526 useMixdown = HB_AMIXDOWN_DOLBYPLII;
5529 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
5530 if (useMixdown > maxMixdownUsed)
5532 useMixdown = maxMixdownUsed;
5535 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
5536 if (useMixdown < minMixdownUsed)
5538 useMixdown = minMixdownUsed;
5541 /* select the (possibly-amended) preferred mixdown */
5542 [mixdownPopUp selectItemWithTag: useMixdown];
5545 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
5546 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5549 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
5551 /* If we are using the avi container, we select MP3 as there is no aac available*/
5552 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5554 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5558 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5562 /* In the case of a source track that is not DTS and the user tries to use DTS Passthru (which does not work)
5563 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
5566 if (audio->in.codec != HB_ACODEC_DCA && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_DCA)
5568 /* If we are using the avi container, we select MP3 as there is no aac available*/
5569 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
5571 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
5575 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
5579 /* Setup our samplerate and bitrate popups we will need based on mixdown */
5580 [self audioTrackMixdownChanged: mixdownPopUp];
5584 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
5586 [self autoSetM4vExtension: sender];
5590 - (IBAction) audioTrackMixdownChanged: (id) sender
5594 /* setup pointers to all of the other audio track controls
5595 * we will need later
5597 NSPopUpButton * mixdownPopUp;
5598 NSPopUpButton * sampleratePopUp;
5599 NSPopUpButton * bitratePopUp;
5600 NSPopUpButton * audiocodecPopUp;
5601 NSPopUpButton * audiotrackPopUp;
5602 NSSlider * drcSlider;
5603 NSTextField * drcField;
5604 if (sender == fAudTrack1MixPopUp)
5606 audiotrackPopUp = fAudLang1PopUp;
5607 audiocodecPopUp = fAudTrack1CodecPopUp;
5608 mixdownPopUp = fAudTrack1MixPopUp;
5609 sampleratePopUp = fAudTrack1RatePopUp;
5610 bitratePopUp = fAudTrack1BitratePopUp;
5611 drcSlider = fAudTrack1DrcSlider;
5612 drcField = fAudTrack1DrcField;
5614 else if (sender == fAudTrack2MixPopUp)
5616 audiotrackPopUp = fAudLang2PopUp;
5617 audiocodecPopUp = fAudTrack2CodecPopUp;
5618 mixdownPopUp = fAudTrack2MixPopUp;
5619 sampleratePopUp = fAudTrack2RatePopUp;
5620 bitratePopUp = fAudTrack2BitratePopUp;
5621 drcSlider = fAudTrack2DrcSlider;
5622 drcField = fAudTrack2DrcField;
5624 else if (sender == fAudTrack3MixPopUp)
5626 audiotrackPopUp = fAudLang3PopUp;
5627 audiocodecPopUp = fAudTrack3CodecPopUp;
5628 mixdownPopUp = fAudTrack3MixPopUp;
5629 sampleratePopUp = fAudTrack3RatePopUp;
5630 bitratePopUp = fAudTrack3BitratePopUp;
5631 drcSlider = fAudTrack3DrcSlider;
5632 drcField = fAudTrack3DrcField;
5636 audiotrackPopUp = fAudLang4PopUp;
5637 audiocodecPopUp = fAudTrack4CodecPopUp;
5638 mixdownPopUp = fAudTrack4MixPopUp;
5639 sampleratePopUp = fAudTrack4RatePopUp;
5640 bitratePopUp = fAudTrack4BitratePopUp;
5641 drcSlider = fAudTrack4DrcSlider;
5642 drcField = fAudTrack4DrcField;
5644 acodec = [[audiocodecPopUp selectedItem] tag];
5645 /* storage variable for the min and max bitrate allowed for this codec */
5651 case HB_ACODEC_FAAC:
5652 /* check if we have a 6ch discrete conversion in either audio track */
5653 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5655 /* FAAC has a minimum of 192 kbps for 6-channel discrete */
5657 /* If either mixdown popup includes 6-channel discrete, then allow up to 448 kbps */
5663 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
5665 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
5666 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
5671 case HB_ACODEC_CA_AAC:
5672 /* check if we have a 6ch discrete conversion in either audio track */
5673 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5686 case HB_ACODEC_LAME:
5687 /* Lame is happy using our min bitrate of 32 kbps */
5689 /* Lame won't encode if the bitrate is higher than 320 kbps */
5693 case HB_ACODEC_VORBIS:
5694 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5696 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
5698 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
5704 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
5706 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
5712 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
5718 /* make sure we have a selected title before continuing */
5719 if (fTitle == NULL) return;
5720 /* get the audio so we can find out what input rates are*/
5721 hb_audio_config_t * audio;
5722 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
5723 int inputbitrate = audio->in.bitrate / 1000;
5724 int inputsamplerate = audio->in.samplerate;
5726 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3 && [[mixdownPopUp selectedItem] tag] != HB_ACODEC_DCA)
5728 [bitratePopUp removeAllItems];
5730 for( int i = 0; i < hb_audio_bitrates_count; i++ )
5732 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
5734 /* add a new menuitem for this bitrate */
5735 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5736 [NSString stringWithUTF8String: hb_audio_bitrates[i].string]
5737 action: NULL keyEquivalent: @""];
5738 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
5739 [menuItem setTag: hb_audio_bitrates[i].rate];
5743 /* select the default bitrate (but use 384 for 6-ch AAC) */
5744 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
5746 [bitratePopUp selectItemWithTag: 384];
5750 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
5753 /* populate and set the sample rate popup */
5754 /* Audio samplerate */
5755 [sampleratePopUp removeAllItems];
5756 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
5757 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
5758 [menuItem setTag: inputsamplerate];
5760 for( int i = 0; i < hb_audio_rates_count; i++ )
5762 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
5763 [NSString stringWithUTF8String: hb_audio_rates[i].string]
5764 action: NULL keyEquivalent: @""];
5765 [menuItem setTag: hb_audio_rates[i].rate];
5767 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
5768 * and there is no compelling reason to use anything else as default, though the users default
5769 * preset will likely override any setting chosen here.
5771 [sampleratePopUp selectItemWithTag: inputsamplerate];
5774 /* Since AC3 Pass Thru and DTS Pass Thru uses the input bitrate and sample rate, we get the input tracks
5775 * bitrate and display it in the bitrate popup even though libhb happily ignores any bitrate input from
5776 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
5778 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[mixdownPopUp selectedItem] tag] == HB_ACODEC_DCA)
5781 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
5782 [bitratePopUp removeAllItems];
5783 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
5784 [NSString stringWithFormat:@"%d", inputbitrate]
5785 action: NULL keyEquivalent: @""];
5786 [menuItem setTag: inputbitrate];
5787 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
5788 [bitratePopUp setEnabled: NO];
5789 [sampleratePopUp setEnabled: NO];
5791 [drcSlider setFloatValue: 0.00];
5792 [self audioDRCSliderChanged: drcSlider];
5793 [drcSlider setEnabled: NO];
5794 [drcField setEnabled: NO];
5798 [sampleratePopUp setEnabled: YES];
5799 [bitratePopUp setEnabled: YES];
5800 [drcSlider setEnabled: YES];
5801 [drcField setEnabled: YES];
5803 [self calculateBitrate:nil];
5806 - (IBAction) audioDRCSliderChanged: (id) sender
5808 NSSlider * drcSlider;
5809 NSTextField * drcField;
5810 if (sender == fAudTrack1DrcSlider)
5812 drcSlider = fAudTrack1DrcSlider;
5813 drcField = fAudTrack1DrcField;
5815 else if (sender == fAudTrack2DrcSlider)
5817 drcSlider = fAudTrack2DrcSlider;
5818 drcField = fAudTrack2DrcField;
5820 else if (sender == fAudTrack3DrcSlider)
5822 drcSlider = fAudTrack3DrcSlider;
5823 drcField = fAudTrack3DrcField;
5827 drcSlider = fAudTrack4DrcSlider;
5828 drcField = fAudTrack4DrcField;
5831 /* If we are between 0.0 and 1.0 on the slider, snap it to 1.0 */
5832 if ([drcSlider floatValue] > 0.0 && [drcSlider floatValue] < 1.0)
5834 [drcSlider setFloatValue:1.0];
5838 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
5839 /* For now, do not call this until we have an intelligent way to determine audio track selections
5840 * compared to presets
5842 //[self customSettingUsed: sender];
5847 - (IBAction) browseImportSrtFile: (id) sender
5850 NSOpenPanel * panel;
5852 panel = [NSOpenPanel openPanel];
5853 [panel setAllowsMultipleSelection: NO];
5854 [panel setCanChooseFiles: YES];
5855 [panel setCanChooseDirectories: NO ];
5856 NSString * sourceDirectory;
5857 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSrtImportDirectory"])
5859 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSrtImportDirectory"];
5863 sourceDirectory = @"~/Desktop";
5864 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
5866 /* we open up the browse srt sheet here and call for browseImportSrtFileDone after the sheet is closed */
5867 NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"srt", nil];
5868 [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes
5869 modalForWindow: fWindow modalDelegate: self
5870 didEndSelector: @selector( browseImportSrtFileDone:returnCode:contextInfo: )
5871 contextInfo: sender];
5874 - (void) browseImportSrtFileDone: (NSSavePanel *) sheet
5875 returnCode: (int) returnCode contextInfo: (void *) contextInfo
5877 if( returnCode == NSOKButton )
5879 NSString *importSrtDirectory = [[sheet filename] stringByDeletingLastPathComponent];
5880 NSString *importSrtFilePath = [sheet filename];
5881 [[NSUserDefaults standardUserDefaults] setObject:importSrtDirectory forKey:@"LastSrtImportDirectory"];
5883 /* now pass the string off to fSubtitlesDelegate to add the srt file to the dropdown */
5884 [fSubtitlesDelegate createSubtitleSrtTrack:importSrtFilePath];
5886 [fSubtitlesTable reloadData];
5892 #pragma mark Open New Windows
5894 - (IBAction) openHomepage: (id) sender
5896 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5897 URLWithString:@"http://handbrake.fr/"]];
5900 - (IBAction) openForums: (id) sender
5902 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5903 URLWithString:@"http://handbrake.fr/forum/"]];
5905 - (IBAction) openUserGuide: (id) sender
5907 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5908 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
5912 * Shows debug output window.
5914 - (IBAction)showDebugOutputPanel:(id)sender
5916 [outputPanel showOutputPanel:sender];
5920 * Shows preferences window.
5922 - (IBAction) showPreferencesWindow: (id) sender
5924 NSWindow * window = [fPreferencesController window];
5925 if (![window isVisible])
5928 [window makeKeyAndOrderFront: nil];
5932 * Shows queue window.
5934 - (IBAction) showQueueWindow:(id)sender
5936 [fQueueController showQueueWindow:sender];
5940 - (IBAction) toggleDrawer:(id)sender {
5941 [fPresetDrawer toggle:self];
5945 * Shows Picture Settings Window.
5948 - (IBAction) showPicturePanel: (id) sender
5950 [fPictureController showPictureWindow:sender];
5953 - (void) picturePanelFullScreen
5955 [fPictureController setToFullScreenMode];
5958 - (void) picturePanelWindowed
5960 [fPictureController setToWindowedMode];
5963 - (IBAction) showPreviewWindow: (id) sender
5965 [fPictureController showPreviewWindow:sender];
5969 #pragma mark Preset Outline View Methods
5970 #pragma mark - Required
5971 /* These are required by the NSOutlineView Datasource Delegate */
5974 /* used to specify the number of levels to show for each item */
5975 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
5977 /* currently use no levels to test outline view viability */
5978 if (item == nil) // for an outline view the root level of the hierarchy is always nil
5980 return [UserPresets count];
5984 /* we need to return the count of the array in ChildrenArray for this folder */
5985 NSArray *children = nil;
5986 children = [item objectForKey:@"ChildrenArray"];
5987 if ([children count] > 0)
5989 return [children count];
5998 /* We use this to deterimine children of an item */
5999 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
6002 /* we need to return the count of the array in ChildrenArray for this folder */
6003 NSArray *children = nil;
6006 children = UserPresets;
6010 if ([item objectForKey:@"ChildrenArray"])
6012 children = [item objectForKey:@"ChildrenArray"];
6015 if ((children == nil) || ( [children count] <= (NSUInteger) index))
6021 return [children objectAtIndex:index];
6025 // We are only one level deep, so we can't be asked about children
6026 //NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
6030 /* We use this to determine if an item should be expandable */
6031 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
6034 /* we need to return the count of the array in ChildrenArray for this folder */
6035 NSArray *children= nil;
6038 children = UserPresets;
6042 if ([item objectForKey:@"ChildrenArray"])
6044 children = [item objectForKey:@"ChildrenArray"];
6048 /* To deterimine if an item should show a disclosure triangle
6049 * we could do it by the children count as so:
6050 * if ([children count] < 1)
6051 * However, lets leave the triangle show even if there are no
6052 * children to help indicate a folder, just like folder in the
6053 * finder can show a disclosure triangle even when empty
6056 /* We need to determine if the item is a folder */
6057 if ([[item objectForKey:@"Folder"] intValue] == 1)
6068 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
6070 // Our outline view has no levels, but we can still expand every item. Doing so
6071 // just makes the row taller. See heightOfRowByItem below.
6072 //return ![(HBQueueOutlineView*)outlineView isDragging];
6078 /* Used to tell the outline view which information is to be displayed per item */
6079 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
6081 /* We have two columns right now, icon and PresetName */
6083 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
6085 return [item objectForKey:@"PresetName"];
6094 - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object
6096 return [NSKeyedUnarchiver unarchiveObjectWithData:object];
6098 - (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item
6100 return [NSKeyedArchiver archivedDataWithRootObject:item];
6103 #pragma mark - Added Functionality (optional)
6104 /* Use to customize the font and display characteristics of the title cell */
6105 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
6107 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
6111 NSColor *shadowColor;
6112 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
6113 /*check to see if its a selected row */
6114 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
6117 fontColor = [NSColor blackColor];
6118 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
6122 if ([[item objectForKey:@"Type"] intValue] == 0)
6124 fontColor = [NSColor blueColor];
6126 else // User created preset, use a black font
6128 fontColor = [NSColor blackColor];
6130 /* check to see if its a folder */
6131 //if ([[item objectForKey:@"Folder"] intValue] == 1)
6133 //fontColor = [NSColor greenColor];
6138 /* We use Bold Text for the HB Default */
6139 if ([[item objectForKey:@"Default"] intValue] == 1)// 1 is HB default
6141 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
6143 /* We use Bold Text for the User Specified Default */
6144 if ([[item objectForKey:@"Default"] intValue] == 2)// 2 is User default
6146 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
6150 [cell setTextColor:fontColor];
6151 [cell setFont:txtFont];
6156 /* We use this to edit the name field in the outline view */
6157 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
6159 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
6164 [theRecord setObject:object forKey:@"PresetName"];
6168 [fPresetsOutlineView reloadData];
6169 /* We save all of the preset data here */
6173 /* We use this to provide tooltips for the items in the presets outline view */
6174 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
6176 //if ([[tc identifier] isEqualToString:@"PresetName"])
6178 /* initialize the tooltip contents variable */
6180 /* if there is a description for the preset, we show it in the tooltip */
6181 if ([item objectForKey:@"PresetDescription"])
6183 loc_tip = [item objectForKey:@"PresetDescription"];
6188 loc_tip = @"No description available";
6195 #pragma mark Preset Outline View Methods (dragging related)
6198 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
6200 // Dragging is only allowed for custom presets.
6201 //[[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1
6202 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
6206 // Don't retain since this is just holding temporaral drag information, and it is
6207 //only used during a drag! We could put this in the pboard actually.
6208 fDraggedNodes = items;
6209 // Provide data for our custom type, and simple NSStrings.
6210 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
6212 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
6213 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
6218 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
6221 // Don't allow dropping ONTO an item since they can't really contain any children.
6223 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
6224 if (isOnDropTypeProposal)
6225 return NSDragOperationNone;
6227 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
6230 index = [fPresetsOutlineView rowForItem: item] + 1;
6234 // Don't allow dropping into the Built In Presets.
6235 if (index < presetCurrentBuiltInCount)
6237 return NSDragOperationNone;
6238 index = MAX (index, presetCurrentBuiltInCount);
6241 [outlineView setDropItem:item dropChildIndex:index];
6242 return NSDragOperationGeneric;
6247 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
6249 /* first, lets see if we are dropping into a folder */
6250 if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
6252 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6253 childrenArray = [[fPresetsOutlineView itemAtRow:index] objectForKey:@"ChildrenArray"];
6254 [childrenArray addObject:item];
6255 [[fPresetsOutlineView itemAtRow:index] setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6256 [childrenArray autorelease];
6258 else // We are not, so we just move the preset into the existing array
6260 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
6262 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
6263 while (obj = [enumerator nextObject])
6265 [moveItems addIndex:[UserPresets indexOfObject:obj]];
6267 // Successful drop, lets rearrange the view and save it all
6268 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
6270 [fPresetsOutlineView reloadData];
6275 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
6277 NSUInteger index = [indexSet lastIndex];
6278 NSUInteger aboveInsertIndexCount = 0;
6280 NSUInteger removeIndex;
6282 if (index >= insertIndex)
6284 removeIndex = index + aboveInsertIndexCount;
6285 aboveInsertIndexCount++;
6289 removeIndex = index;
6293 id object = [[array objectAtIndex:removeIndex] retain];
6294 [array removeObjectAtIndex:removeIndex];
6295 [array insertObject:object atIndex:insertIndex];
6298 index = [indexSet indexLessThanIndex:index];
6303 #pragma mark - Functional Preset NSOutlineView Methods
6305 - (IBAction)selectPreset:(id)sender
6308 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
6310 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6311 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6313 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
6315 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
6319 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
6323 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
6324 [self formatPopUpChanged:nil];
6326 /* Chapter Markers*/
6327 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
6328 /* check to see if we have only one chapter */
6329 [self chapterPopUpChanged:nil];
6331 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6332 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
6333 /* Mux mp4 with http optimization */
6334 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
6337 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
6338 /* We set the advanced opt string here if applicable*/
6339 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
6341 /* Lets run through the following functions to get variables set there */
6342 [self videoEncoderPopUpChanged:nil];
6343 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
6344 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
6345 [self calculateBitrate:nil];
6348 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
6350 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
6351 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
6353 /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float.
6354 * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type
6355 * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret
6356 * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet,
6357 * though it should be a corner case since it would pretty much be a preset for lossless encoding. */
6358 if ([[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue] < 1.0)
6360 /* For the quality slider we need to convert the old percent's to the new rf scales */
6361 float rf = (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]);
6362 [fVidQualitySlider setFloatValue:rf];
6367 /* Since theora's qp value goes up from left to right, we can just set the slider float value */
6368 if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
6370 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6374 /* since ffmpeg and x264 use an "inverted" slider (lower qp/rf values indicate a higher quality) we invert the value on the slider */
6375 [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] + [fVidQualitySlider minValue]) - [[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
6379 [self videoMatrixChanged:nil];
6381 /* Video framerate */
6382 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
6383 detected framerate in the fVidRatePopUp so we use index 0*/
6384 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
6386 [fVidRatePopUp selectItemAtIndex: 0];
6390 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
6394 /* 2 Pass Encoding */
6395 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
6396 [self twoPassCheckboxChanged:nil];
6398 /* Turbo 1st pass for 2 Pass Encoding */
6399 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
6402 /* First we check to see if we are using the current audio track layout based on AudioList array */
6403 if ([chosenPreset objectForKey:@"AudioList"])
6406 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
6407 NSPopUpButton * trackLangPopUp = nil;
6408 NSPopUpButton * mixdownPopUp = nil;
6409 NSPopUpButton * audiocodecPopUp = nil;
6410 NSPopUpButton * sampleratePopUp = nil;
6411 NSPopUpButton * bitratePopUp = nil;
6412 NSSlider * drcSlider = nil;
6415 /* Populate the audio widgets based on the contents of the AudioList array */
6417 NSEnumerator *enumerator = [[chosenPreset objectForKey:@"AudioList"] objectEnumerator];
6419 while (tempObject = [enumerator nextObject])
6424 trackLangPopUp = fAudLang1PopUp;
6425 mixdownPopUp = fAudTrack1MixPopUp;
6426 audiocodecPopUp = fAudTrack1CodecPopUp;
6427 sampleratePopUp = fAudTrack1RatePopUp;
6428 bitratePopUp = fAudTrack1BitratePopUp;
6429 drcSlider = fAudTrack1DrcSlider;
6433 trackLangPopUp = fAudLang2PopUp;
6434 mixdownPopUp = fAudTrack2MixPopUp;
6435 audiocodecPopUp = fAudTrack2CodecPopUp;
6436 sampleratePopUp = fAudTrack2RatePopUp;
6437 bitratePopUp = fAudTrack2BitratePopUp;
6438 drcSlider = fAudTrack2DrcSlider;
6442 trackLangPopUp = fAudLang3PopUp;
6443 mixdownPopUp = fAudTrack3MixPopUp;
6444 audiocodecPopUp = fAudTrack3CodecPopUp;
6445 sampleratePopUp = fAudTrack3RatePopUp;
6446 bitratePopUp = fAudTrack3BitratePopUp;
6447 drcSlider = fAudTrack3DrcSlider;
6451 trackLangPopUp = fAudLang4PopUp;
6452 mixdownPopUp = fAudTrack4MixPopUp;
6453 audiocodecPopUp = fAudTrack4CodecPopUp;
6454 sampleratePopUp = fAudTrack4RatePopUp;
6455 bitratePopUp = fAudTrack4BitratePopUp;
6456 drcSlider = fAudTrack4DrcSlider;
6460 if ([trackLangPopUp indexOfSelectedItem] == 0)
6462 [trackLangPopUp selectItemAtIndex: 1];
6464 [self audioTrackPopUpChanged: trackLangPopUp];
6465 [audiocodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
6466 /* check our pref for core audio and use it in place of faac if applicable */
6467 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6468 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
6470 [audiocodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6473 [self audioTrackPopUpChanged: audiocodecPopUp];
6474 [mixdownPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
6475 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6477 if ([mixdownPopUp selectedItem] == nil)
6479 [self audioTrackPopUpChanged: audiocodecPopUp];
6481 [sampleratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
6482 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6483 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6485 [bitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
6487 [drcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
6488 [self audioDRCSliderChanged: drcSlider];
6491 /* If we are any track greater than 1 check to make sure we have a matching source codec is using ac3 passthru or dts passthru,
6492 * if not we will set the track to "None". Track 1 is allowed to mixdown to a suitable DPL2 mix if we cannot passthru */
6496 /* Check to see if the preset asks for a passhthru track (AC3 or DTS) and verify there is a matching source track if not, set the track to "None". */
6497 if (([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] || [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"]) && [trackLangPopUp indexOfSelectedItem] != 0)
6499 hb_audio_config_t * audio;
6500 /* get the audio source audio codec */
6501 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [trackLangPopUp indexOfSelectedItem] - 1 );
6502 if (audio != NULL && [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] && audio->in.codec != HB_ACODEC_AC3 ||
6503 [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"] && audio->in.codec != HB_ACODEC_DCA )
6505 /* We have a preset using ac3 passthru but no ac3 source audio, so set the track to "None" and bail */
6506 if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
6508 [self writeToActivityLog: "Preset calls for AC3 Pass thru ..."];
6510 if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"])
6512 [self writeToActivityLog: "Preset calls for DTS Pass thru ..."];
6514 [self writeToActivityLog: "No matching source codec, setting track %d to None", i];
6515 [trackLangPopUp selectItemAtIndex: 0];
6516 [self audioTrackPopUpChanged: trackLangPopUp];
6522 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6526 [fAudLang4PopUp selectItemAtIndex: 0];
6527 [self audioTrackPopUpChanged: fAudLang4PopUp];
6531 [fAudLang3PopUp selectItemAtIndex: 0];
6532 [self audioTrackPopUpChanged: fAudLang3PopUp];
6536 [fAudLang2PopUp selectItemAtIndex: 0];
6537 [self audioTrackPopUpChanged: fAudLang2PopUp];
6545 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
6547 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
6549 [fAudLang1PopUp selectItemAtIndex: 1];
6551 [self audioTrackPopUpChanged: fAudLang1PopUp];
6552 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
6553 /* check our pref for core audio and use it in place of faac if applicable */
6554 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6555 [[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString: @"AAC (faac)"])
6557 [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6559 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6560 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
6561 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6563 if ([fAudTrack1MixPopUp selectedItem] == nil)
6565 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
6567 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
6568 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6569 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
6571 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
6573 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
6574 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
6577 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
6579 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
6581 [fAudLang2PopUp selectItemAtIndex: 1];
6583 [self audioTrackPopUpChanged: fAudLang2PopUp];
6584 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
6585 /* check our pref for core audio and use it in place of faac if applicable */
6586 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6587 [[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString: @"AAC (faac)"])
6589 [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6591 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6592 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
6593 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6595 if ([fAudTrack2MixPopUp selectedItem] == nil)
6597 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
6599 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
6600 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6601 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
6603 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
6605 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
6606 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
6608 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
6610 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
6612 [fAudLang3PopUp selectItemAtIndex: 1];
6614 [self audioTrackPopUpChanged: fAudLang3PopUp];
6615 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
6616 /* check our pref for core audio and use it in place of faac if applicable */
6617 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6618 [[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AAC (faac)"])
6620 [fAudTrack3CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6622 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6623 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
6624 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6626 if ([fAudTrack3MixPopUp selectedItem] == nil)
6628 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
6630 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
6631 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6632 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
6634 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
6636 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
6637 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
6639 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
6641 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
6643 [fAudLang4PopUp selectItemAtIndex: 1];
6645 [self audioTrackPopUpChanged: fAudLang4PopUp];
6646 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
6647 /* check our pref for core audio and use it in place of faac if applicable */
6648 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES &&
6649 [[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString: @"AAC (faac)"])
6651 [fAudTrack4CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
6653 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6654 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
6655 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
6657 if ([fAudTrack4MixPopUp selectedItem] == nil)
6659 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
6661 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
6662 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
6663 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
6665 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
6667 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
6668 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
6671 /* We now cleanup any extra audio tracks that may have been previously set if we need to */
6673 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
6675 [fAudLang2PopUp selectItemAtIndex: 0];
6676 [self audioTrackPopUpChanged: fAudLang2PopUp];
6678 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
6680 [fAudLang3PopUp selectItemAtIndex: 0];
6681 [self audioTrackPopUpChanged: fAudLang3PopUp];
6683 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
6685 [fAudLang4PopUp selectItemAtIndex: 0];
6686 [self audioTrackPopUpChanged: fAudLang4PopUp];
6691 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
6692 /* Forced Subtitles */
6693 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
6695 /* Picture Settings */
6696 /* Note: objectForKey:@"UsesPictureSettings" refers to picture size, which encompasses:
6697 * height, width, keep ar, anamorphic and crop settings.
6698 * picture filters are handled separately below.
6700 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
6701 * ( 2 is use max for source and 1 is use exact size when the preset was created ) and the
6702 * preset completely ignores any picture sizing values in the preset.
6704 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
6706 hb_job_t * job = fTitle->job;
6708 /* If Cropping is set to custom, then recall all four crop values from
6709 when the preset was created and apply them */
6710 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
6712 [fPictureController setAutoCrop:NO];
6714 /* Here we use the custom crop values saved at the time the preset was saved */
6715 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
6716 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
6717 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
6718 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
6721 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
6723 [fPictureController setAutoCrop:YES];
6724 /* Here we use the auto crop values determined right after scan */
6725 job->crop[0] = AutoCropTop;
6726 job->crop[1] = AutoCropBottom;
6727 job->crop[2] = AutoCropLeft;
6728 job->crop[3] = AutoCropRight;
6733 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
6734 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
6736 /* Use Max Picture settings for whatever the dvd is.*/
6737 [self revertPictureSizeToMax:nil];
6738 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6739 if (job->keep_ratio == 1)
6741 hb_fix_aspect( job, HB_KEEP_WIDTH );
6742 if( job->height > fTitle->height )
6744 job->height = fTitle->height;
6745 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6748 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6750 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
6752 /* we check to make sure the presets width/height does not exceed the sources width/height */
6753 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
6755 /* if so, then we use the sources height and width to avoid scaling up */
6756 //job->width = fTitle->width;
6757 //job->height = fTitle->height;
6758 [self revertPictureSizeToMax:nil];
6760 else // source width/height is >= the preset height/width
6762 /* we can go ahead and use the presets values for height and width */
6763 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
6764 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
6766 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
6767 if (job->keep_ratio == 1)
6769 hb_fix_aspect( job, HB_KEEP_WIDTH );
6770 if( job->height > fTitle->height )
6772 job->height = fTitle->height;
6773 hb_fix_aspect( job, HB_KEEP_HEIGHT );
6776 job->anamorphic.mode = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
6782 /* If the preset has an objectForKey:@"UsesPictureFilters", and handle the filters here */
6783 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
6787 /* We only allow *either* Decomb or Deinterlace. So check for the PictureDecombDeinterlace key.
6788 * also, older presets may not have this key, in which case we also check to see if that preset had PictureDecomb
6789 * specified, in which case we use decomb and ignore any possible Deinterlace settings as using both was less than
6792 [fPictureController setUseDecomb:1];
6793 [fPictureController setDecomb:0];
6794 [fPictureController setDeinterlace:0];
6795 if ([[chosenPreset objectForKey:@"PictureDecombDeinterlace"] intValue] == 1 || [[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6797 /* we are using decomb */
6799 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
6801 [fPictureController setDecomb:[[chosenPreset objectForKey:@"PictureDecomb"] intValue]];
6803 /* if we are using "Custom" in the decomb setting, also set the custom string*/
6804 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] == 1)
6806 [fPictureController setDecombCustomString:[chosenPreset objectForKey:@"PictureDecombCustom"]];
6812 /* We are using Deinterlace */
6814 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] > 0)
6816 [fPictureController setUseDecomb:0];
6817 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
6818 /* if we are using "Custom" in the deinterlace setting, also set the custom string*/
6819 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 1)
6821 [fPictureController setDeinterlaceCustomString:[chosenPreset objectForKey:@"PictureDeinterlaceCustom"]];
6828 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] > 0)
6830 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
6831 /* if we are using "Custom" in the detelecine setting, also set the custom string*/
6832 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
6834 [fPictureController setDetelecineCustomString:[chosenPreset objectForKey:@"PictureDetelecineCustom"]];
6839 [fPictureController setDetelecine:0];
6843 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] > 0)
6845 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
6846 /* if we are using "Custom" in the denoise setting, also set the custom string*/
6847 if ([[chosenPreset objectForKey:@"PictureDenoise"] intValue] == 1)
6849 [fPictureController setDenoiseCustomString:[chosenPreset objectForKey:@"PictureDenoiseCustom"]];
6854 [fPictureController setDenoise:0];
6858 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
6860 /* if its a one, then its the old on/off deblock, set on to 5*/
6861 [fPictureController setDeblock:5];
6865 /* use the settings intValue */
6866 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
6869 if ([[chosenPreset objectForKey:@"VideoGrayScale"] intValue] == 1)
6871 [fPictureController setGrayscale:1];
6875 [fPictureController setGrayscale:0];
6878 /* we call SetTitle: in fPictureController so we get an instant update in the Picture Settings window */
6879 [fPictureController SetTitle:fTitle];
6880 [fPictureController SetTitle:fTitle];
6881 [self calculatePictureSizing:nil];
6887 #pragma mark Manage Presets
6889 - (void) loadPresets {
6890 /* We declare the default NSFileManager into fileManager */
6891 NSFileManager * fileManager = [NSFileManager defaultManager];
6892 /*We define the location of the user presets file */
6893 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
6894 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
6895 /* We check for the presets.plist */
6896 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
6898 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
6901 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
6902 if (nil == UserPresets)
6904 UserPresets = [[NSMutableArray alloc] init];
6905 [self addFactoryPresets:nil];
6907 [fPresetsOutlineView reloadData];
6909 [self checkBuiltInsForUpdates];
6912 - (void) checkBuiltInsForUpdates {
6914 BOOL updateBuiltInPresets = NO;
6916 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6918 while (tempObject = [enumerator nextObject])
6920 /* iterate through the built in presets to see if any have an old build number */
6921 NSMutableDictionary *thisPresetDict = tempObject;
6922 /*Key Type == 0 is built in, and key PresetBuildNumber is the build number it was created with */
6923 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0)
6925 if (![thisPresetDict objectForKey:@"PresetBuildNumber"] || [[thisPresetDict objectForKey:@"PresetBuildNumber"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue])
6927 updateBuiltInPresets = YES;
6932 /* if we have built in presets to update, then do so AlertBuiltInPresetUpdate*/
6933 if ( updateBuiltInPresets == YES)
6935 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"AlertBuiltInPresetUpdate"] == YES)
6937 /* Show an alert window that built in presets will be updated */
6938 /*On Screen Notification*/
6941 status = NSRunAlertPanel(@"HandBrake has determined your built in presets are out of date...",@"HandBrake will now update your built-in presets.", @"OK", nil, nil);
6942 [NSApp requestUserAttention:NSCriticalRequest];
6944 /* when alert is dismissed, go ahead and update the built in presets */
6945 [self addFactoryPresets:nil];
6951 - (IBAction) showAddPresetPanel: (id) sender
6953 /* Deselect the currently selected Preset if there is one*/
6954 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
6956 /* Populate the preset picture settings popup here */
6957 [fPresetNewPicSettingsPopUp removeAllItems];
6958 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
6959 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
6960 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
6961 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
6962 /* Uncheck the preset use filters checkbox */
6963 [fPresetNewPicFiltersCheck setState:NSOffState];
6964 // fPresetNewFolderCheck
6965 [fPresetNewFolderCheck setState:NSOffState];
6966 /* Erase info from the input fields*/
6967 [fPresetNewName setStringValue: @""];
6968 [fPresetNewDesc setStringValue: @""];
6969 /* Show the panel */
6970 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
6973 - (IBAction) closeAddPresetPanel: (id) sender
6975 [NSApp endSheet: fAddPresetPanel];
6976 [fAddPresetPanel orderOut: self];
6979 - (IBAction)addUserPreset:(id)sender
6981 if (![[fPresetNewName stringValue] length])
6982 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
6985 /* Here we create a custom user preset */
6986 [UserPresets addObject:[self createPreset]];
6989 [self closeAddPresetPanel:nil];
6996 /* We Reload the New Table data for presets */
6997 [fPresetsOutlineView reloadData];
6998 /* We save all of the preset data here */
7006 /* We Sort the Presets By Factory or Custom */
7007 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
7008 ascending:YES] autorelease];
7009 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
7011 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
7012 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
7013 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
7016 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
7017 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
7018 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
7019 [UserPresets setArray:sortedArray];
7024 - (IBAction)insertPreset:(id)sender
7026 int index = [fPresetsOutlineView selectedRow];
7027 [UserPresets insertObject:[self createPreset] atIndex:index];
7028 [fPresetsOutlineView reloadData];
7032 - (NSDictionary *)createPreset
7034 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
7035 /* Preset build number */
7036 [preset setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
7037 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
7038 /* Get the New Preset Name from the field in the AddPresetPanel */
7039 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
7040 /* Set whether or not this is to be a folder fPresetNewFolderCheck*/
7041 [preset setObject:[NSNumber numberWithBool:[fPresetNewFolderCheck state]] forKey:@"Folder"];
7042 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
7043 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
7044 /*Set whether or not this is default, at creation set to 0*/
7045 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7046 if ([fPresetNewFolderCheck state] == YES)
7048 /* initialize and set an empty array for children here since we are a new folder */
7049 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
7050 [preset setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
7051 [childrenArray autorelease];
7053 else // we are not creating a preset folder, so we go ahead with the rest of the preset info
7055 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
7056 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
7057 /* Get whether or not to use the current Picture Filter settings for the preset */
7058 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
7060 /* Get New Preset Description from the field in the AddPresetPanel*/
7061 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
7063 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
7064 /* Chapter Markers fCreateChapterMarkers*/
7065 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
7066 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
7067 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
7068 /* Mux mp4 with http optimization */
7069 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
7070 /* Add iPod uuid atom */
7071 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
7075 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
7076 /* x264 Option String */
7077 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
7079 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
7080 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
7081 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
7082 [preset setObject:[NSNumber numberWithFloat:[fVidQualityRFField floatValue]] forKey:@"VideoQualitySlider"];
7084 /* Video framerate */
7085 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
7087 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
7089 else // we can record the actual titleOfSelectedItem
7091 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
7094 /* 2 Pass Encoding */
7095 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
7096 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
7097 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
7098 /*Picture Settings*/
7099 hb_job_t * job = fTitle->job;
7100 /* Picture Sizing */
7101 /* Use Max Picture settings for whatever the dvd is.*/
7102 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
7103 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
7104 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
7105 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
7106 [preset setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
7108 /* Set crop settings here */
7109 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
7110 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
7111 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
7112 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
7113 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
7115 /* Picture Filters */
7116 [preset setObject:[NSNumber numberWithInt:[fPictureController useDecomb]] forKey:@"PictureDecombDeinterlace"];
7117 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
7118 [preset setObject:[fPictureController deinterlaceCustomString] forKey:@"PictureDeinterlaceCustom"];
7119 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
7120 [preset setObject:[fPictureController detelecineCustomString] forKey:@"PictureDetelecineCustom"];
7121 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
7122 [preset setObject:[fPictureController denoiseCustomString] forKey:@"PictureDenoiseCustom"];
7123 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
7124 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
7125 [preset setObject:[fPictureController decombCustomString] forKey:@"PictureDecombCustom"];
7126 [preset setObject:[NSNumber numberWithInt:[fPictureController grayscale]] forKey:@"VideoGrayScale"];
7129 NSMutableArray *audioListArray = [[NSMutableArray alloc] init];
7130 /* we actually call the methods for the nests here */
7131 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
7133 NSMutableDictionary *audioTrack1Array = [[NSMutableDictionary alloc] init];
7134 [audioTrack1Array setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
7135 [audioTrack1Array setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
7136 [audioTrack1Array setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
7137 [audioTrack1Array setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
7138 [audioTrack1Array setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
7139 [audioTrack1Array setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
7140 [audioTrack1Array setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
7141 [audioTrack1Array autorelease];
7142 [audioListArray addObject:audioTrack1Array];
7145 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
7147 NSMutableDictionary *audioTrack2Array = [[NSMutableDictionary alloc] init];
7148 [audioTrack2Array setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
7149 [audioTrack2Array setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
7150 [audioTrack2Array setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
7151 [audioTrack2Array setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
7152 [audioTrack2Array setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
7153 [audioTrack2Array setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
7154 [audioTrack2Array setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
7155 [audioTrack2Array autorelease];
7156 [audioListArray addObject:audioTrack2Array];
7159 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
7161 NSMutableDictionary *audioTrack3Array = [[NSMutableDictionary alloc] init];
7162 [audioTrack3Array setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
7163 [audioTrack3Array setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
7164 [audioTrack3Array setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
7165 [audioTrack3Array setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
7166 [audioTrack3Array setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
7167 [audioTrack3Array setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
7168 [audioTrack3Array setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
7169 [audioTrack3Array autorelease];
7170 [audioListArray addObject:audioTrack3Array];
7173 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
7175 NSMutableDictionary *audioTrack4Array = [[NSMutableDictionary alloc] init];
7176 [audioTrack4Array setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"AudioTrack"];
7177 [audioTrack4Array setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"AudioTrackDescription"];
7178 [audioTrack4Array setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"AudioEncoder"];
7179 [audioTrack4Array setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"AudioMixdown"];
7180 [audioTrack4Array setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"AudioSamplerate"];
7181 [audioTrack4Array setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"AudioBitrate"];
7182 [audioTrack4Array setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"AudioTrackDRCSlider"];
7183 [audioTrack4Array autorelease];
7184 [audioListArray addObject:audioTrack4Array];
7188 [preset setObject:[NSMutableArray arrayWithArray: audioListArray] forKey:@"AudioList"];
7191 /* Temporarily remove subtitles from creating a new preset as it has to be converted over to use the new
7192 * subititle array code. */
7194 //[preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
7195 /* Forced Subtitles */
7196 //[preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
7198 [preset autorelease];
7205 [UserPresets writeToFile:UserPresetsFile atomically:YES];
7206 /* We get the default preset in case it changed */
7207 [self getDefaultPresets:nil];
7211 - (IBAction)deletePreset:(id)sender
7215 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
7219 /* Alert user before deleting preset */
7221 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
7223 if ( status == NSAlertDefaultReturn )
7225 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7226 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
7227 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
7229 NSEnumerator *enumerator;
7230 NSMutableArray *presetsArrayToMod;
7231 NSMutableArray *tempArray;
7233 /* If we are a root level preset, we are modding the UserPresets array */
7234 if (presetToModLevel == 0)
7236 presetsArrayToMod = UserPresets;
7238 else // We have a parent preset, so we modify the chidren array object for key
7240 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
7243 enumerator = [presetsArrayToMod objectEnumerator];
7244 tempArray = [NSMutableArray array];
7246 while (tempObject = [enumerator nextObject])
7248 NSDictionary *thisPresetDict = tempObject;
7249 if (thisPresetDict == presetToMod)
7251 [tempArray addObject:tempObject];
7255 [presetsArrayToMod removeObjectsInArray:tempArray];
7256 [fPresetsOutlineView reloadData];
7263 #pragma mark Import Export Preset(s)
7265 - (IBAction) browseExportPresetFile: (id) sender
7267 /* Open a panel to let the user choose where and how to save the export file */
7268 NSSavePanel * panel = [NSSavePanel savePanel];
7269 /* We get the current file name and path from the destination field here */
7270 NSString *defaultExportDirectory = [NSString stringWithFormat: @"%@/Desktop/", NSHomeDirectory()];
7272 [panel beginSheetForDirectory: defaultExportDirectory file: @"HB_Export.plist"
7273 modalForWindow: fWindow modalDelegate: self
7274 didEndSelector: @selector( browseExportPresetFileDone:returnCode:contextInfo: )
7278 - (void) browseExportPresetFileDone: (NSSavePanel *) sheet
7279 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7281 if( returnCode == NSOKButton )
7283 NSString *presetExportDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7284 NSString *exportPresetsFile = [sheet filename];
7285 [[NSUserDefaults standardUserDefaults] setObject:presetExportDirectory forKey:@"LastPresetExportDirectory"];
7286 /* We check for the presets.plist */
7287 if ([[NSFileManager defaultManager] fileExistsAtPath:exportPresetsFile] == 0)
7289 [[NSFileManager defaultManager] createFileAtPath:exportPresetsFile contents:nil attributes:nil];
7291 NSMutableArray * presetsToExport = [[NSMutableArray alloc] initWithContentsOfFile:exportPresetsFile];
7292 if (nil == presetsToExport)
7294 presetsToExport = [[NSMutableArray alloc] init];
7296 /* now get and add selected presets to export */
7299 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
7301 [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7302 [presetsToExport writeToFile:exportPresetsFile atomically:YES];
7310 - (IBAction) browseImportPresetFile: (id) sender
7313 NSOpenPanel * panel;
7315 panel = [NSOpenPanel openPanel];
7316 [panel setAllowsMultipleSelection: NO];
7317 [panel setCanChooseFiles: YES];
7318 [panel setCanChooseDirectories: NO ];
7319 NSString * sourceDirectory;
7320 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"])
7322 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"];
7326 sourceDirectory = @"~/Desktop";
7327 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
7329 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
7330 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
7332 /* set this for allowed file types, not sure if we should allow xml or not */
7333 NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"xml", nil];
7334 [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes
7335 modalForWindow: fWindow modalDelegate: self
7336 didEndSelector: @selector( browseImportPresetDone:returnCode:contextInfo: )
7337 contextInfo: sender];
7340 - (void) browseImportPresetDone: (NSSavePanel *) sheet
7341 returnCode: (int) returnCode contextInfo: (void *) contextInfo
7343 if( returnCode == NSOKButton )
7345 NSString *importPresetsDirectory = [[sheet filename] stringByDeletingLastPathComponent];
7346 NSString *importPresetsFile = [sheet filename];
7347 [[NSUserDefaults standardUserDefaults] setObject:importPresetsDirectory forKey:@"LastPresetImportDirectory"];
7348 /* NOTE: here we need to do some sanity checking to verify we do not hose up our presets file */
7349 NSMutableArray * presetsToImport = [[NSMutableArray alloc] initWithContentsOfFile:importPresetsFile];
7350 /* iterate though the new array of presets to import and add them to our presets array */
7352 NSEnumerator *enumerator = [presetsToImport objectEnumerator];
7354 while (tempObject = [enumerator nextObject])
7356 /* make any changes to the incoming preset we see fit */
7357 /* make sure the incoming preset is not tagged as default */
7358 [tempObject setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7359 /* prepend "(imported) to the name of the incoming preset for clarification since it can be changed */
7360 NSString * prependedName = [@"(import) " stringByAppendingString:[tempObject objectForKey:@"PresetName"]] ;
7361 [tempObject setObject:prependedName forKey:@"PresetName"];
7363 /* actually add the new preset to our presets array */
7364 [UserPresets addObject:tempObject];
7367 [presetsToImport autorelease];
7375 #pragma mark Manage Default Preset
7377 - (IBAction)getDefaultPresets:(id)sender
7379 presetHbDefault = nil;
7380 presetUserDefault = nil;
7381 presetUserDefaultParent = nil;
7382 presetUserDefaultParentParent = nil;
7383 NSMutableDictionary *presetHbDefaultParent = nil;
7384 NSMutableDictionary *presetHbDefaultParentParent = nil;
7387 BOOL userDefaultFound = NO;
7388 presetCurrentBuiltInCount = 0;
7389 /* First we iterate through the root UserPresets array to check for defaults */
7390 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7392 while (tempObject = [enumerator nextObject])
7394 NSMutableDictionary *thisPresetDict = tempObject;
7395 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7397 presetHbDefault = thisPresetDict;
7399 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7401 presetUserDefault = thisPresetDict;
7402 userDefaultFound = YES;
7404 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7406 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
7410 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7411 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7413 NSMutableDictionary *thisPresetDictParent = thisPresetDict;
7414 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7416 while (tempObject = [enumerator nextObject])
7418 NSMutableDictionary *thisPresetDict = tempObject;
7419 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7421 presetHbDefault = thisPresetDict;
7422 presetHbDefaultParent = thisPresetDictParent;
7424 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7426 presetUserDefault = thisPresetDict;
7427 presetUserDefaultParent = thisPresetDictParent;
7428 userDefaultFound = YES;
7431 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7432 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7434 NSMutableDictionary *thisPresetDictParentParent = thisPresetDict;
7435 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7437 while (tempObject = [enumerator nextObject])
7439 NSMutableDictionary *thisPresetDict = tempObject;
7440 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
7442 presetHbDefault = thisPresetDict;
7443 presetHbDefaultParent = thisPresetDictParent;
7444 presetHbDefaultParentParent = thisPresetDictParentParent;
7446 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
7448 presetUserDefault = thisPresetDict;
7449 presetUserDefaultParent = thisPresetDictParent;
7450 presetUserDefaultParentParent = thisPresetDictParentParent;
7451 userDefaultFound = YES;
7460 /* check to see if a user specified preset was found, if not then assign the parents for
7461 * the presetHbDefault so that we can open the parents for the nested presets
7463 if (userDefaultFound == NO)
7465 presetUserDefaultParent = presetHbDefaultParent;
7466 presetUserDefaultParentParent = presetHbDefaultParentParent;
7470 - (IBAction)setDefaultPreset:(id)sender
7472 /* We need to determine if the item is a folder */
7473 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] == 1)
7479 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7481 /* First make sure the old user specified default preset is removed */
7482 while (tempObject = [enumerator nextObject])
7484 NSMutableDictionary *thisPresetDict = tempObject;
7485 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7487 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7490 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
7491 if ([thisPresetDict objectForKey:@"ChildrenArray"])
7493 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
7496 while (tempObject = [enumerator nextObject])
7498 NSMutableDictionary *thisPresetDict1 = tempObject;
7499 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7501 [[[thisPresetDict objectForKey:@"ChildrenArray"] objectAtIndex:ii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7503 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
7504 if ([thisPresetDict1 objectForKey:@"ChildrenArray"])
7506 NSEnumerator *enumerator = [[thisPresetDict1 objectForKey:@"ChildrenArray"] objectEnumerator];
7509 while (tempObject = [enumerator nextObject])
7511 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
7513 [[[thisPresetDict1 objectForKey:@"ChildrenArray"] objectAtIndex:iii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
7526 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
7527 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
7528 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
7531 NSMutableArray *presetsArrayToMod;
7532 NSMutableArray *tempArray;
7534 /* If we are a root level preset, we are modding the UserPresets array */
7535 if (presetToModLevel == 0)
7537 presetsArrayToMod = UserPresets;
7539 else // We have a parent preset, so we modify the chidren array object for key
7541 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
7544 enumerator = [presetsArrayToMod objectEnumerator];
7545 tempArray = [NSMutableArray array];
7547 while (tempObject = [enumerator nextObject])
7549 NSDictionary *thisPresetDict = tempObject;
7550 if (thisPresetDict == presetToMod)
7552 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 2
7554 [[presetsArrayToMod objectAtIndex:iiii] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
7561 /* We save all of the preset data here */
7563 /* We Reload the New Table data for presets */
7564 [fPresetsOutlineView reloadData];
7567 - (IBAction)selectDefaultPreset:(id)sender
7569 NSMutableDictionary *presetToMod;
7570 /* if there is a user specified default, we use it */
7571 if (presetUserDefault)
7573 presetToMod = presetUserDefault;
7575 else if (presetHbDefault) //else we use the built in default presetHbDefault
7577 presetToMod = presetHbDefault;
7584 if (presetUserDefaultParent != nil)
7586 [fPresetsOutlineView expandItem:presetUserDefaultParent];
7589 if (presetUserDefaultParentParent != nil)
7591 [fPresetsOutlineView expandItem:presetUserDefaultParentParent];
7595 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[fPresetsOutlineView rowForItem: presetToMod]] byExtendingSelection:NO];
7596 [self selectPreset:nil];
7601 #pragma mark Manage Built In Presets
7604 - (IBAction)deleteFactoryPresets:(id)sender
7607 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7611 NSMutableArray *tempArray;
7614 tempArray = [NSMutableArray array];
7615 /* we look here to see if the preset is we move on to the next one */
7616 while ( tempObject = [enumerator nextObject] )
7618 /* if the preset is "Factory" then we put it in the array of
7619 presets to delete */
7620 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
7622 [tempArray addObject:tempObject];
7626 [UserPresets removeObjectsInArray:tempArray];
7627 [fPresetsOutlineView reloadData];
7632 /* We use this method to recreate new, updated factory presets */
7633 - (IBAction)addFactoryPresets:(id)sender
7636 /* First, we delete any existing built in presets */
7637 [self deleteFactoryPresets: sender];
7638 /* Then we generate new built in presets programmatically with fPresetsBuiltin
7639 * which is all setup in HBPresets.h and HBPresets.m*/
7640 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
7641 /* update build number for built in presets */
7642 /* iterate though the new array of presets to import and add them to our presets array */
7644 NSEnumerator *enumerator = [UserPresets objectEnumerator];
7646 while (tempObject = [enumerator nextObject])
7648 /* Record the apps current build number in the PresetBuildNumber key */
7649 if ([[tempObject objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
7651 /* Preset build number */
7652 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"];
7656 /* report the built in preset updating to the activity log */
7657 [self writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]];
7667 /*******************************
7668 * Subclass of the HBPresetsOutlineView *
7669 *******************************/
7671 @implementation HBPresetsOutlineView
7672 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
7676 // By default, NSTableView only drags an image of the first column. Change this to
7677 // drag an image of the queue's icon and PresetName columns.
7678 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"PresetName"], nil];
7679 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
7684 - (void) mouseDown:(NSEvent *)theEvent
7686 [super mouseDown:theEvent];
7692 - (BOOL) isDragging;