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"
13 #define DragDropSimplePboardType @"MyCustomOutlineViewPboardType"
15 /* We setup the toolbar values here */
16 static NSString * ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
17 static NSString * StartEncodingIdentifier = @"Start Encoding Item Identifier";
18 static NSString * PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
19 static NSString * ShowQueueIdentifier = @"Show Queue Item Identifier";
20 static NSString * AddToQueueIdentifier = @"Add to Queue Item Identifier";
21 static NSString * ShowActivityIdentifier = @"Debug Output Item Identifier";
22 static NSString * ChooseSourceIdentifier = @"Choose Source Item Identifier";
25 /*******************************
26 * HBController implementation *
27 *******************************/
28 @implementation HBController
38 [HBPreferencesController registerUserDefaults];
40 fQueueEncodeLibhb = NULL;
41 /* Check for check for the app support directory here as
42 * outputPanel needs it right away, as may other future methods
44 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
46 YES ) objectAtIndex:0];
47 AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
48 stringByAppendingPathComponent:@"HandBrake"];
49 if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
51 [[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
55 outputPanel = [[HBOutputPanelController alloc] init];
56 fPictureController = [[PictureController alloc] initWithDelegate:self];
57 fQueueController = [[HBQueueController alloc] init];
58 fAdvancedOptions = [[HBAdvancedController alloc] init];
59 /* we init the HBPresets class which currently is only used
60 * for updating built in presets, may move more functionality
63 fPresetsBuiltin = [[HBPresets alloc] init];
64 fPreferencesController = [[HBPreferencesController alloc] init];
65 /* Lets report the HandBrake version number here to the activity log and text log file */
66 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
67 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
73 - (void) applicationDidFinishLaunching: (NSNotification *) notification
75 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
76 fHandle = hb_init(HB_DEBUG_ALL, 0);
77 /* Init a separate instance of libhb for user scanning and setting up jobs */
78 fQueueEncodeLibhb = hb_init(HB_DEBUG_ALL, 0);
80 // Set the Growl Delegate
81 [GrowlApplicationBridge setGrowlDelegate: self];
82 /* Init others controllers */
83 [fPictureController SetHandle: fHandle];
84 [fQueueController setHandle: fQueueEncodeLibhb];
85 [fQueueController setHBController: self];
87 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
88 [fChapterTable setDataSource:fChapterTitlesDelegate];
89 [fChapterTable setDelegate:fChapterTitlesDelegate];
91 /* Call UpdateUI every 1/2 sec */
92 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
93 scheduledTimerWithTimeInterval:0.5 target:self
94 selector:@selector(updateUI:) userInfo:nil repeats:YES]
95 forMode:NSEventTrackingRunLoopMode];
97 // Open debug output window now if it was visible when HB was closed
98 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
99 [self showDebugOutputPanel:nil];
101 // Open queue window now if it was visible when HB was closed
102 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
103 [self showQueueWindow:nil];
105 [self openMainWindow:nil];
107 /* We have to set the bool to tell hb what to do after a scan
108 * Initially we set it to NO until we start processing the queue
110 applyQueueToScan = NO;
112 /* Now we re-check the queue array to see if there are
113 * any remaining encodes to be done in it and ask the
114 * user if they want to reload the queue */
115 if ([QueueFileArray count] > 0)
117 /* run getQueueStats to see whats in the queue file */
118 [self getQueueStats];
119 /* this results in these values
120 * fEncodingQueueItem = 0;
122 * fCompletedCount = 0;
123 * fCanceledCount = 0;
127 /*On Screen Notification*/
128 NSString * alertTitle;
129 if (fWorkingCount > 0)
131 alertTitle = [NSString stringWithFormat:
132 NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
133 fWorkingCount,fPendingCount];
137 alertTitle = [NSString stringWithFormat:
138 NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
141 NSBeginCriticalAlertSheet(
143 NSLocalizedString(@"Reload Queue", nil),
145 NSLocalizedString(@"Empty Queue", nil),
147 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
148 NSLocalizedString(@" Do you want to reload them ?", nil));
149 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
150 // right below to either clear the old queue or keep it loaded up.
155 /* Show Browse Sources Window ASAP */
156 [self performSelectorOnMainThread:@selector(browseSources:)
157 withObject:nil waitUntilDone:NO];
161 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
163 if (returnCode == NSAlertOtherReturn)
165 [self clearQueueAllItems];
166 [self performSelectorOnMainThread:@selector(browseSources:)
167 withObject:nil waitUntilDone:NO];
171 [self setQueueEncodingItemsAsPending];
172 [self showQueueWindow:NULL];
176 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
179 // Warn if encoding a movie
181 hb_get_state( fQueueEncodeLibhb, &s );
183 if ( s.state != HB_STATE_IDLE )
185 int result = NSRunCriticalAlertPanel(
186 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
187 NSLocalizedString(@"If you quit HandBrake your current encode will be reloaded into your queue at next launch. Do you want to quit anyway?", nil),
188 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
190 if (result == NSAlertDefaultReturn)
192 return NSTerminateNow;
195 return NSTerminateCancel;
198 // Warn if items still in the queue
199 else if ( fPendingCount > 0 )
201 int result = NSRunCriticalAlertPanel(
202 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
203 NSLocalizedString(@"There are pending encodes in your queue. Do you want to quit anyway?",nil),
204 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
206 if ( result == NSAlertDefaultReturn )
207 return NSTerminateNow;
209 return NSTerminateCancel;
212 return NSTerminateNow;
215 - (void)applicationWillTerminate:(NSNotification *)aNotification
217 [browsedSourceDisplayName release];
218 [outputPanel release];
219 [fQueueController release];
221 hb_close(&fQueueEncodeLibhb);
225 - (void) awakeFromNib
228 [fWindow setExcludedFromWindowsMenu:YES];
229 [fAdvancedOptions setView:fAdvancedView];
231 /* lets setup our presets drawer for drag and drop here */
232 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
233 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
234 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
236 /* Initialize currentScanCount so HB can use it to
237 evaluate successive scans */
238 currentScanCount = 0;
241 /* Init UserPresets .plist */
244 /* Init QueueFile .plist */
245 [self loadQueueFile];
247 fRipIndicatorShown = NO; // initially out of view in the nib
249 /* Show/Dont Show Presets drawer upon launch based
250 on user preference DefaultPresetsDrawerShow*/
251 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
253 [fPresetDrawer open];
259 NSMenuItem *menuItem;
260 [fDstFormatPopUp removeAllItems];
262 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
263 [menuItem setTag: HB_MUX_MP4];
265 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
266 [menuItem setTag: HB_MUX_MKV];
268 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"AVI file" action: NULL keyEquivalent: @""];
269 [menuItem setTag: HB_MUX_AVI];
271 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"OGM file" action: NULL keyEquivalent: @""];
272 [menuItem setTag: HB_MUX_OGM];
273 [fDstFormatPopUp selectItemAtIndex: 0];
275 [self formatPopUpChanged:nil];
277 /* We enable the create chapters checkbox here since we are .mp4 */
278 [fCreateChapterMarkers setEnabled: YES];
279 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
281 [fCreateChapterMarkers setState: NSOnState];
287 [fDstFile2Field setStringValue: [NSString stringWithFormat:
288 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
291 [fVidEncoderPopUp removeAllItems];
292 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
293 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
298 [fVidTargetSizeField setIntValue: 700];
299 [fVidBitrateField setIntValue: 1000];
301 [fVidQualityMatrix selectCell: fVidBitrateCell];
302 [self videoMatrixChanged:nil];
304 /* Video framerate */
305 [fVidRatePopUp removeAllItems];
306 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
307 for( int i = 0; i < hb_video_rates_count; i++ )
309 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
311 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
312 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
314 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
316 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
317 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
319 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
321 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
322 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
326 [fVidRatePopUp addItemWithTitle:
327 [NSString stringWithCString: hb_video_rates[i].string]];
330 [fVidRatePopUp selectItemAtIndex: 0];
332 /* Set Auto Crop to On at launch */
333 [fPictureController setAutoCrop:YES];
336 [fAudTrack1BitratePopUp removeAllItems];
337 for( int i = 0; i < hb_audio_bitrates_count; i++ )
339 [fAudTrack1BitratePopUp addItemWithTitle:
340 [NSString stringWithCString: hb_audio_bitrates[i].string]];
343 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
345 /* Audio samplerate */
346 [fAudTrack1RatePopUp removeAllItems];
347 for( int i = 0; i < hb_audio_rates_count; i++ )
349 [fAudTrack1RatePopUp addItemWithTitle:
350 [NSString stringWithCString: hb_audio_rates[i].string]];
352 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
355 [fStatusField setStringValue: @""];
360 /* We disable the Turbo 1st pass checkbox since we are not x264 */
361 [fVidTurboPassCheck setEnabled: NO];
362 [fVidTurboPassCheck setState: NSOffState];
365 /* lets get our default prefs here */
366 [self getDefaultPresets:nil];
367 /* lets initialize the current successful scancount here to 0 */
368 currentSuccessfulScanCount = 0;
373 - (void) enableUI: (bool) b
375 NSControl * controls[] =
376 { fSrcTitleField, fSrcTitlePopUp,
377 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
378 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
379 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
380 fDstBrowseButton, fVidRateField, fVidRatePopUp,
381 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
382 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
383 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
384 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
385 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
386 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
387 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
388 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
389 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
390 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
391 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
392 fPictureButton,fQueueStatus,fPicSettingARkeep, fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,
393 fPicLabelOutp,fPicSettingsSrc,fPicSettingsOutp,fPicSettingsAnamorphic,
394 fPicLabelAr,fPicLabelDeinterlace,fPicSettingPAR,fPicLabelAnamorphic,fPresetsAdd,fPresetsDelete,
395 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fPicLabelAutoCrop,
396 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,
397 fSubForcedCheck,fPicSettingDeblock,fPicLabelDeblock,fPicLabelDecomb,fPicSettingDecomb,fPresetsOutlineView,
398 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck};
401 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
403 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
405 NSTextField * tf = (NSTextField *) controls[i];
406 if( ![tf isBezeled] )
408 [tf setTextColor: b ? [NSColor controlTextColor] :
409 [NSColor disabledControlTextColor]];
413 [controls[i] setEnabled: b];
419 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
420 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
421 [self setEnabledStateOfAudioMixdownControls:nil];
422 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
423 [self calculatePictureSizing:nil];
424 [self shouldEnableHttpMp4CheckBox: nil];
428 [fPresetsOutlineView setEnabled: NO];
432 [self videoMatrixChanged:nil];
433 [fAdvancedOptions enableUI:b];
437 /***********************************************************************
439 ***********************************************************************
440 * Shows a progression bar on the dock icon, filled according to
441 * 'progress' (0.0 <= progress <= 1.0).
442 * Called with progress < 0.0 or progress > 1.0, restores the original
444 **********************************************************************/
445 - (void) UpdateDockIcon: (float) progress
449 NSBitmapImageRep * bmp;
451 uint32_t black = htonl( 0x000000FF );
452 uint32_t red = htonl( 0xFF0000FF );
453 uint32_t white = htonl( 0xFFFFFFFF );
454 int row_start, row_end;
457 /* Get application original icon */
458 icon = [NSImage imageNamed: @"NSApplicationIcon"];
460 if( progress < 0.0 || progress > 1.0 )
462 [NSApp setApplicationIconImage: icon];
466 /* Get it in a raw bitmap form */
467 tiff = [icon TIFFRepresentationUsingCompression:
468 NSTIFFCompressionNone factor: 1.0];
469 bmp = [NSBitmapImageRep imageRepWithData: tiff];
471 /* Draw the progression bar */
472 /* It's pretty simple (ugly?) now, but I'm no designer */
474 row_start = 3 * (int) [bmp size].height / 4;
475 row_end = 7 * (int) [bmp size].height / 8;
477 for( i = row_start; i < row_start + 2; i++ )
479 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
480 for( j = 0; j < (int) [bmp size].width; j++ )
485 for( i = row_start + 2; i < row_end - 2; i++ )
487 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
490 for( j = 2; j < (int) [bmp size].width - 2; j++ )
492 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
504 for( i = row_end - 2; i < row_end; i++ )
506 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
507 for( j = 0; j < (int) [bmp size].width; j++ )
513 /* Now update the dock icon */
514 tiff = [bmp TIFFRepresentationUsingCompression:
515 NSTIFFCompressionNone factor: 1.0];
516 icon = [[NSImage alloc] initWithData: tiff];
517 [NSApp setApplicationIconImage: icon];
521 - (void) updateUI: (NSTimer *) timer
524 /* Update UI for fHandle (user scanning instance of libhb ) */
527 list = hb_get_titles( fHandle );
528 /* check to see if there has been a new scan done
529 this bypasses the constraints of HB_STATE_WORKING
530 not allowing setting a newly scanned source */
531 int checkScanCount = hb_get_scancount( fHandle );
532 if( checkScanCount > currentScanCount )
534 currentScanCount = checkScanCount;
535 [fScanIndicator setIndeterminate: NO];
536 [fScanIndicator setDoubleValue: 0.0];
537 [fScanIndicator setHidden: YES];
538 [self showNewScan:nil];
542 hb_get_state( fHandle, &s );
548 #define p s.param.scanning
549 case HB_STATE_SCANNING:
551 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
552 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
553 p.title_cur, p.title_count]];
554 [fScanIndicator setHidden: NO];
555 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
560 #define p s.param.scandone
561 case HB_STATE_SCANDONE:
563 [fScanIndicator setIndeterminate: NO];
564 [fScanIndicator setDoubleValue: 0.0];
565 [fScanIndicator setHidden: YES];
566 [self writeToActivityLog:"ScanDone state received from fHandle"];
567 [self showNewScan:nil];
568 [[fWindow toolbar] validateVisibleItems];
574 #define p s.param.working
575 case HB_STATE_WORKING:
582 #define p s.param.muxing
583 case HB_STATE_MUXING:
590 case HB_STATE_PAUSED:
593 case HB_STATE_WORKDONE:
600 /* Update UI for fQueueEncodeLibhb */
602 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
603 /* check to see if there has been a new scan done
604 this bypasses the constraints of HB_STATE_WORKING
605 not allowing setting a newly scanned source */
607 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
608 if( checkScanCount > currentScanCount )
610 currentScanCount = checkScanCount;
611 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
615 hb_get_state( fQueueEncodeLibhb, &s );
621 #define p s.param.scanning
622 case HB_STATE_SCANNING:
624 [fStatusField setStringValue: [NSString stringWithFormat:
625 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
626 p.title_cur, p.title_count]];
628 /* Set the status string in fQueueController as well */
629 [fQueueController setQueueStatusString: [NSString stringWithFormat:
630 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
631 p.title_cur, p.title_count]];
633 [fRipIndicator setHidden: NO];
634 [fRipIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
639 #define p s.param.scandone
640 case HB_STATE_SCANDONE:
642 [fRipIndicator setIndeterminate: NO];
643 [fRipIndicator setDoubleValue: 0.0];
645 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
646 [self processNewQueueEncode];
647 [[fWindow toolbar] validateVisibleItems];
653 #define p s.param.working
654 case HB_STATE_WORKING:
656 float progress_total;
657 NSMutableString * string;
658 /* Update text field */
659 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
663 [string appendFormat:
664 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
665 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
668 [fStatusField setStringValue: string];
669 /* Set the status string in fQueueController as well */
670 [fQueueController setQueueStatusString: string];
672 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
673 [fRipIndicator setIndeterminate: NO];
674 [fRipIndicator setDoubleValue: 100.0 * progress_total];
676 // If progress bar hasn't been revealed at the bottom of the window, do
677 // that now. This code used to be in doRip. I moved it to here to handle
678 // the case where hb_start is called by HBQueueController and not from
680 if( !fRipIndicatorShown )
682 NSRect frame = [fWindow frame];
683 if( frame.size.width <= 591 )
684 frame.size.width = 591;
685 frame.size.height += 36;
686 frame.origin.y -= 36;
687 [fWindow setFrame:frame display:YES animate:YES];
688 fRipIndicatorShown = YES;
692 /* Update dock icon */
693 [self UpdateDockIcon: progress_total];
699 #define p s.param.muxing
700 case HB_STATE_MUXING:
702 /* Update text field */
703 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
704 /* Set the status string in fQueueController as well */
705 [fQueueController setQueueStatusString: NSLocalizedString( @"Muxing...", @"" )];
707 [fRipIndicator setIndeterminate: YES];
708 [fRipIndicator startAnimation: nil];
710 /* Update dock icon */
711 [self UpdateDockIcon: 1.0];
717 case HB_STATE_PAUSED:
718 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
719 [fQueueController setQueueStatusString: NSLocalizedString( @"Paused", @"" )];
723 case HB_STATE_WORKDONE:
725 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
726 // or someone calling hb_stop. In the latter case, hb_stop does not clear
727 // out the remaining passes/jobs in the queue. We'll do that here.
729 // Delete all remaining jobs of this encode.
730 [fStatusField setStringValue: NSLocalizedString( @"Encode Finished.", @"" )];
731 /* Set the status string in fQueueController as well */
732 [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
733 [fRipIndicator setIndeterminate: NO];
734 [fRipIndicator setDoubleValue: 0.0];
735 [[fWindow toolbar] validateVisibleItems];
737 /* Restore dock icon */
738 [self UpdateDockIcon: -1.0];
740 if( fRipIndicatorShown )
742 NSRect frame = [fWindow frame];
743 if( frame.size.width <= 591 )
744 frame.size.width = 591;
745 frame.size.height += -36;
746 frame.origin.y -= -36;
747 [fWindow setFrame:frame display:YES animate:YES];
748 fRipIndicatorShown = NO;
751 /* Check to see if the encode state has not been cancelled
752 to determine if we should check for encode done notifications */
753 if( fEncodeState != 2 )
755 NSString *pathOfFinishedEncode;
756 /* Get the output file name for the finished encode */
757 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
759 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
761 [self showGrowlDoneNotification:pathOfFinishedEncode];
763 [self sendToMetaX:pathOfFinishedEncode];
765 /* since we have successfully completed an encode, we increment the queue counter */
766 [self incrementQueueItemDone:nil];
768 /* all end of queue actions below need to be done after all queue encodes have finished
769 * and there are no pending jobs left to process
771 if (fPendingCount == 0)
773 /* If Alert Window or Window and Growl has been selected */
774 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
775 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
777 /*On Screen Notification*/
780 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
781 [NSApp requestUserAttention:NSCriticalRequest];
784 /* If sleep has been selected */
785 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
788 NSDictionary* errorDict;
789 NSAppleEventDescriptor* returnDescriptor = nil;
790 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
791 @"tell application \"Finder\" to sleep"];
792 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
793 [scriptObject release];
795 /* If Shutdown has been selected */
796 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
799 NSDictionary* errorDict;
800 NSAppleEventDescriptor* returnDescriptor = nil;
801 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
802 @"tell application \"Finder\" to shut down"];
803 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
804 [scriptObject release];
818 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
819 - (void) writeToActivityLog:(char *) format, ...
822 va_start(args, format);
826 vsnprintf( str, 1024, format, args );
828 time_t _now = time( NULL );
829 struct tm * now = localtime( &_now );
830 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
837 // ============================================================
838 // NSToolbar Related Methods
839 // ============================================================
841 - (void) setupToolbar {
842 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
844 [toolbar setAllowsUserCustomization: YES];
845 [toolbar setAutosavesConfiguration: YES];
846 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
848 [toolbar setDelegate: self];
850 [fWindow setToolbar: toolbar];
853 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
854 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
855 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
857 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
859 [item setLabel: @"Toggle Presets"];
860 [item setPaletteLabel: @"Toggler Presets"];
861 [item setToolTip: @"Open/Close Preset Drawer"];
862 [item setImage: [NSImage imageNamed: @"Drawer"]];
863 [item setTarget: self];
864 [item setAction: @selector(toggleDrawer:)];
865 [item setAutovalidates: NO];
867 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
869 [item setLabel: @"Start"];
870 [item setPaletteLabel: @"Start Encoding"];
871 [item setToolTip: @"Start Encoding"];
872 [item setImage: [NSImage imageNamed: @"Play"]];
873 [item setTarget: self];
874 [item setAction: @selector(Rip:)];
876 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
878 [item setLabel: @"Show Queue"];
879 [item setPaletteLabel: @"Show Queue"];
880 [item setToolTip: @"Show Queue"];
881 [item setImage: [NSImage imageNamed: @"Queue"]];
882 [item setTarget: self];
883 [item setAction: @selector(showQueueWindow:)];
884 [item setAutovalidates: NO];
886 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
888 [item setLabel: @"Add to Queue"];
889 [item setPaletteLabel: @"Add to Queue"];
890 [item setToolTip: @"Add to Queue"];
891 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
892 [item setTarget: self];
893 [item setAction: @selector(addToQueue:)];
895 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
897 [item setLabel: @"Pause"];
898 [item setPaletteLabel: @"Pause Encoding"];
899 [item setToolTip: @"Pause Encoding"];
900 [item setImage: [NSImage imageNamed: @"Pause"]];
901 [item setTarget: self];
902 [item setAction: @selector(Pause:)];
904 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
905 [item setLabel: @"Activity Window"];
906 [item setPaletteLabel: @"Show Activity Window"];
907 [item setToolTip: @"Show Activity Window"];
908 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
909 [item setTarget: self];
910 [item setAction: @selector(showDebugOutputPanel:)];
911 [item setAutovalidates: NO];
913 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
915 [item setLabel: @"Source"];
916 [item setPaletteLabel: @"Source"];
917 [item setToolTip: @"Choose Video Source"];
918 [item setImage: [NSImage imageNamed: @"Source"]];
919 [item setTarget: self];
920 [item setAction: @selector(browseSources:)];
930 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
932 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
933 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
934 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
937 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
939 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
940 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
941 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
942 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
945 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
947 NSString * ident = [toolbarItem itemIdentifier];
952 hb_get_state2( fQueueEncodeLibhb, &s );
954 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
956 if ([ident isEqualToString: StartEncodingIdentifier])
958 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
959 [toolbarItem setLabel: @"Stop"];
960 [toolbarItem setPaletteLabel: @"Stop"];
961 [toolbarItem setToolTip: @"Stop Encoding"];
964 if ([ident isEqualToString: PauseEncodingIdentifier])
966 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
967 [toolbarItem setLabel: @"Pause"];
968 [toolbarItem setPaletteLabel: @"Pause Encoding"];
969 [toolbarItem setToolTip: @"Pause Encoding"];
973 if ([ident isEqualToString: AddToQueueIdentifier])
976 else if (s.state == HB_STATE_PAUSED)
978 if ([ident isEqualToString: PauseEncodingIdentifier])
980 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
981 [toolbarItem setLabel: @"Resume"];
982 [toolbarItem setPaletteLabel: @"Resume Encoding"];
983 [toolbarItem setToolTip: @"Resume Encoding"];
986 if ([ident isEqualToString: StartEncodingIdentifier])
988 if ([ident isEqualToString: AddToQueueIdentifier])
991 else if (s.state == HB_STATE_SCANNING)
993 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
995 if ([ident isEqualToString: StartEncodingIdentifier])
997 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
998 if (hb_count(fHandle) > 0)
999 [toolbarItem setLabel: @"Start Queue"];
1001 [toolbarItem setLabel: @"Start"];
1002 [toolbarItem setPaletteLabel: @"Start Encoding"];
1003 [toolbarItem setToolTip: @"Start Encoding"];
1006 if ([ident isEqualToString: AddToQueueIdentifier])
1011 /* If there are any pending queue items, make sure the start/stop button is active */
1012 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1014 if ([ident isEqualToString: ShowQueueIdentifier])
1016 if ([ident isEqualToString: ToggleDrawerIdentifier])
1018 if ([ident isEqualToString: ChooseSourceIdentifier])
1020 if ([ident isEqualToString: ShowActivityIdentifier])
1026 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1028 SEL action = [menuItem action];
1031 hb_get_state2( fHandle, &s );
1035 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1036 return SuccessfulScan && [fWindow attachedSheet] == nil;
1038 if (action == @selector(browseSources:))
1040 if (s.state == HB_STATE_SCANNING)
1043 return [fWindow attachedSheet] == nil;
1045 if (action == @selector(selectDefaultPreset:))
1046 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1047 if (action == @selector(Pause:))
1049 if (s.state == HB_STATE_WORKING)
1051 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1052 [menuItem setTitle:@"Pause Encoding"];
1055 else if (s.state == HB_STATE_PAUSED)
1057 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1058 [menuItem setTitle:@"Resume Encoding"];
1064 if (action == @selector(Rip:))
1066 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1068 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1069 [menuItem setTitle:@"Stop Encoding"];
1072 else if (SuccessfulScan)
1074 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1075 [menuItem setTitle:@"Start Encoding"];
1076 return [fWindow attachedSheet] == nil;
1082 if( action == @selector(setDefaultPreset:) )
1084 return [fPresetsOutlineView selectedRow] != -1;
1091 #pragma mark Encode Done Actions
1092 // register a test notification and make
1093 // it enabled by default
1094 #define SERVICE_NAME @"Encode Done"
1095 - (NSDictionary *)registrationDictionaryForGrowl
1097 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1098 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1099 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1102 return registrationDictionary;
1105 -(void)showGrowlDoneNotification:(NSString *) filePath
1107 /* This end of encode action is called as each encode rolls off of the queue */
1108 NSString * finishedEncode = filePath;
1109 /* strip off the path to just show the file name */
1110 finishedEncode = [finishedEncode lastPathComponent];
1111 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1112 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1114 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1115 [GrowlApplicationBridge
1116 notifyWithTitle:@"Put down that cocktail..."
1117 description:growlMssg
1118 notificationName:SERVICE_NAME
1126 -(void)sendToMetaX:(NSString *) filePath
1128 /* This end of encode action is called as each encode rolls off of the queue */
1129 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1131 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1132 [myScript executeAndReturnError: nil];
1137 #pragma mark Get New Source
1139 /*Opens the source browse window, called from Open Source widgets */
1140 - (IBAction) browseSources: (id) sender
1142 NSOpenPanel * panel;
1144 panel = [NSOpenPanel openPanel];
1145 [panel setAllowsMultipleSelection: NO];
1146 [panel setCanChooseFiles: YES];
1147 [panel setCanChooseDirectories: YES ];
1148 NSString * sourceDirectory;
1149 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1151 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1155 sourceDirectory = @"~/Desktop";
1156 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1158 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1159 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1161 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1162 modalForWindow: fWindow modalDelegate: self
1163 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1164 contextInfo: sender];
1167 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1168 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1170 /* we convert the sender content of contextInfo back into a variable called sender
1171 * mostly just for consistency for evaluation later
1173 id sender = (id)contextInfo;
1174 /* User selected a file to open */
1175 if( returnCode == NSOKButton )
1177 /* Free display name allocated previously by this code */
1178 [browsedSourceDisplayName release];
1180 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1181 /* we set the last searched source directory in the prefs here */
1182 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1183 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1184 /* we order out sheet, which is the browse window as we need to open
1185 * the title selection sheet right away
1187 [sheet orderOut: self];
1189 if (sender == fOpenSourceTitleMMenu)
1191 /* We put the chosen source path in the source display text field for the
1192 * source title selection sheet in which the user specifies the specific title to be
1193 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1194 * purposes in the title panel
1197 [fScanSrcTitlePathField setStringValue:scanPath];
1198 NSString *displayTitlescanSourceName;
1200 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1202 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1203 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1204 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1208 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1209 displayTitlescanSourceName = [scanPath lastPathComponent];
1211 /* we set the source display name in the title selection dialogue */
1212 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1213 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1214 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1215 /* We show the actual sheet where the user specifies the title to be scanned
1216 * as we are going to do a title specific scan
1218 [self showSourceTitleScanPanel:nil];
1222 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1223 NSString *path = [[sheet filenames] objectAtIndex: 0];
1225 /* We check to see if the chosen file at path is a package */
1226 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1228 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1229 /* We check to see if this is an .eyetv package */
1230 if ([[path pathExtension] isEqualToString: @"eyetv"])
1232 [self writeToActivityLog:"trying to open eyetv package"];
1233 /* We're looking at an EyeTV package - try to open its enclosed
1235 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1237 int n = [[path stringByAppendingString: @"/"]
1238 completePathIntoString: &mpgname caseSensitive: NO
1239 matchesIntoArray: nil
1240 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1243 /* Found an mpeg inside the eyetv package, make it our scan path
1244 and call performScan on the enclosed mpeg */
1246 [self writeToActivityLog:"found mpeg in eyetv package"];
1247 [self performScan:path scanTitleNum:0];
1251 /* We did not find an mpeg file in our package, so we do not call performScan */
1252 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1255 /* We check to see if this is a .dvdmedia package */
1256 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1258 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1259 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1260 [self writeToActivityLog:"trying to open dvdmedia package"];
1261 [self performScan:path scanTitleNum:0];
1265 /* The package is not an eyetv package, so we do not call performScan */
1266 [self writeToActivityLog:"unable to open package"];
1269 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1271 /* path is not a package, so we call perform scan directly on our file */
1272 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1274 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1275 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1276 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1280 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1281 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1282 /* make sure we remove any path extension as this can also be an '.mpg' file */
1283 browsedSourceDisplayName = [[path lastPathComponent] retain];
1285 [self performScan:path scanTitleNum:0];
1293 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1294 - (IBAction) showSourceTitleScanPanel: (id) sender
1296 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1299 [fScanSrcTitleNumField setStringValue: @"0"];
1300 /* Show the panel */
1301 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1304 - (IBAction) closeSourceTitleScanPanel: (id) sender
1306 [NSApp endSheet: fScanSrcTitlePanel];
1307 [fScanSrcTitlePanel orderOut: self];
1309 if(sender == fScanSrcTitleOpenButton)
1311 /* We setup the scan status in the main window to indicate a source title scan */
1312 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1313 [fScanIndicator setHidden: NO];
1314 [fScanIndicator setIndeterminate: YES];
1315 [fScanIndicator startAnimation: nil];
1317 /* We use the performScan method to actually perform the specified scan passing the path and the title
1320 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1324 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1325 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1327 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1328 applyQueueToScan = NO;
1329 /* use a bool to determine whether or not we can decrypt using vlc */
1330 BOOL cancelScanDecrypt = 0;
1331 NSString *path = scanPath;
1332 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1334 // Notify ChapterTitles that there's no title
1335 [fChapterTitlesDelegate resetWithTitle:nil];
1336 [fChapterTable reloadData];
1338 [self enableUI: NO];
1340 if( [detector isVideoDVD] )
1342 // The chosen path was actually on a DVD, so use the raw block
1343 // device path instead.
1344 path = [detector devicePath];
1345 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1347 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1348 NSString *vlcPath = @"/Applications/VLC.app";
1349 NSFileManager * fileManager = [NSFileManager defaultManager];
1350 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1352 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1353 cancelScanDecrypt = 1;
1354 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1356 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");
1357 [NSApp requestUserAttention:NSCriticalRequest];
1359 if (status == NSAlertDefaultReturn)
1361 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1362 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1364 else if (status == NSAlertAlternateReturn)
1366 /* User chose to cancel the scan */
1367 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1371 /* 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 */
1372 cancelScanDecrypt = 0;
1373 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1379 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1380 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1384 if (cancelScanDecrypt == 0)
1386 /* we actually pass the scan off to libhb here */
1387 /* If there is no title number passed to scan, we use "0"
1388 * which causes the default behavior of a full source scan
1394 if (scanTitleNum > 0)
1396 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1399 hb_scan( fHandle, [path UTF8String], scanTitleNum );
1400 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1404 - (IBAction) showNewScan:(id)sender
1408 int indxpri=0; // Used to search the longuest title (default in combobox)
1409 int longuestpri=0; // Used to search the longuest title (default in combobox)
1412 list = hb_get_titles( fHandle );
1414 if( !hb_list_count( list ) )
1416 /* We display a message if a valid dvd source was not chosen */
1417 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1418 SuccessfulScan = NO;
1420 // Notify ChapterTitles that there's no title
1421 [fChapterTitlesDelegate resetWithTitle:nil];
1422 [fChapterTable reloadData];
1426 /* We increment the successful scancount here by one,
1427 which we use at the end of this function to tell the gui
1428 if this is the first successful scan since launch and whether
1429 or not we should set all settings to the defaults */
1431 currentSuccessfulScanCount++;
1433 [[fWindow toolbar] validateVisibleItems];
1435 [fSrcTitlePopUp removeAllItems];
1436 for( int i = 0; i < hb_list_count( list ); i++ )
1438 title = (hb_title_t *) hb_list_item( list, i );
1440 currentSource = [NSString stringWithUTF8String: title->name];
1441 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1442 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1444 /* Use the dvd name in the default output field here
1445 May want to add code to remove blank spaces for some dvd names*/
1446 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1447 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1449 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1450 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1454 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1455 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1459 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1461 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1465 [fSrcTitlePopUp addItemWithTitle: [NSString
1466 stringWithFormat: @"%d - %02dh%02dm%02ds",
1467 title->index, title->hours, title->minutes,
1471 // Select the longuest title
1472 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1473 [self titlePopUpChanged:nil];
1475 SuccessfulScan = YES;
1476 [self enableUI: YES];
1478 /* if its the initial successful scan after awakeFromNib */
1479 if (currentSuccessfulScanCount == 1)
1481 [self selectDefaultPreset:nil];
1482 /* initially set deinterlace to 0, will be overridden reset by the default preset anyway */
1483 //[fPictureController setDeinterlace:0];
1485 /* lets set Denoise to index 0 or "None" since this is the first scan */
1486 //[fPictureController setDenoise:0];
1488 [fPictureController setInitialPictureFilters];
1498 #pragma mark New Output Destination
1500 - (IBAction) browseFile: (id) sender
1502 /* Open a panel to let the user choose and update the text field */
1503 NSSavePanel * panel = [NSSavePanel savePanel];
1504 /* We get the current file name and path from the destination field here */
1505 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1506 modalForWindow: fWindow modalDelegate: self
1507 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1511 - (void) browseFileDone: (NSSavePanel *) sheet
1512 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1514 if( returnCode == NSOKButton )
1516 [fDstFile2Field setStringValue: [sheet filename]];
1522 #pragma mark Main Window Control
1524 - (IBAction) openMainWindow: (id) sender
1526 [fWindow makeKeyAndOrderFront:nil];
1529 - (BOOL) windowShouldClose: (id) sender
1534 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1537 [fWindow makeKeyAndOrderFront:nil];
1547 #pragma mark Queue File
1549 - (void) loadQueueFile {
1550 /* We declare the default NSFileManager into fileManager */
1551 NSFileManager * fileManager = [NSFileManager defaultManager];
1552 /*We define the location of the user presets file */
1553 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1554 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1555 /* We check for the presets.plist */
1556 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1558 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1561 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1562 /* lets check to see if there is anything in the queue file .plist */
1563 if (nil == QueueFileArray)
1565 /* if not, then lets initialize an empty array */
1566 QueueFileArray = [[NSMutableArray alloc] init];
1568 /* Initialize our curQueueEncodeIndex to 0
1569 * so we can use it to track which queue
1570 * item is to be used to track our encodes */
1571 /* NOTE: this should be changed if and when we
1572 * are able to get the last unfinished encode
1573 * in the case of a crash or shutdown */
1578 [self clearQueueEncodedItems];
1580 currentQueueEncodeIndex = 0;
1583 - (void)addQueueFileItem
1585 [QueueFileArray addObject:[self createQueueFileItem]];
1586 [self saveQueueFileItem];
1590 - (void) removeQueueFileItem:(int) queueItemToRemove
1593 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1594 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1596 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1597 * by one to keep in sync with the queue array
1599 currentQueueEncodeIndex--;
1600 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1602 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1603 [self saveQueueFileItem];
1607 - (void)saveQueueFileItem
1609 [QueueFileArray writeToFile:QueueFile atomically:YES];
1610 [fQueueController setQueueArray: QueueFileArray];
1611 [self getQueueStats];
1614 - (void)getQueueStats
1616 /* lets get the stats on the status of the queue array */
1618 fEncodingQueueItem = 0;
1620 fCompletedCount = 0;
1624 /* We use a number system to set the encode status of the queue item
1626 * 0 == already encoded
1627 * 1 == is being encoded
1628 * 2 == is yet to be encoded
1633 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1635 while (tempObject = [enumerator nextObject])
1637 NSDictionary *thisQueueDict = tempObject;
1638 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1642 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1645 fEncodingQueueItem = i;
1647 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1651 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1658 /* Set the queue status field in the main window */
1659 NSMutableString * string;
1660 if (fPendingCount == 1)
1662 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1666 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1668 [fQueueStatus setStringValue:string];
1671 /* This method will set any item marked as encoding back to pending
1672 * currently used right after a queue reload
1674 - (void) setQueueEncodingItemsAsPending
1676 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1678 NSMutableArray *tempArray;
1679 tempArray = [NSMutableArray array];
1680 /* we look here to see if the preset is we move on to the next one */
1681 while ( tempObject = [enumerator nextObject] )
1683 /* If the queue item is marked as "encoding" (1)
1684 * then change its status back to pending (2) which effectively
1685 * puts it back into the queue to be encoded
1687 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
1689 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
1691 [tempArray addObject:tempObject];
1694 [QueueFileArray setArray:tempArray];
1695 [self saveQueueFileItem];
1699 /* This method will clear the queue of any encodes that are not still pending
1700 * this includes both successfully completed encodes as well as cancelled encodes */
1701 - (void) clearQueueEncodedItems
1703 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1705 NSMutableArray *tempArray;
1706 tempArray = [NSMutableArray array];
1707 /* we look here to see if the preset is we move on to the next one */
1708 while ( tempObject = [enumerator nextObject] )
1710 /* If the queue item is either completed (0) or cancelled (3) from the
1711 * last session, then we put it in tempArray to be deleted from QueueFileArray.
1712 * NOTE: this means we retain pending (2) and also an item that is marked as
1713 * still encoding (1). If the queue has an item that is still marked as encoding
1714 * from a previous session, we can conlude that HB was either shutdown, or crashed
1715 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
1717 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
1719 [tempArray addObject:tempObject];
1723 [QueueFileArray removeObjectsInArray:tempArray];
1724 [self saveQueueFileItem];
1727 /* This method will clear the queue of all encodes. effectively creating an empty queue */
1728 - (void) clearQueueAllItems
1730 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1732 NSMutableArray *tempArray;
1733 tempArray = [NSMutableArray array];
1734 /* we look here to see if the preset is we move on to the next one */
1735 while ( tempObject = [enumerator nextObject] )
1737 [tempArray addObject:tempObject];
1740 [QueueFileArray removeObjectsInArray:tempArray];
1741 [self saveQueueFileItem];
1744 /* This method will duplicate prepareJob however into the
1745 * queue .plist instead of into the job structure so it can
1746 * be recalled later */
1747 - (NSDictionary *)createQueueFileItem
1749 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1751 hb_list_t * list = hb_get_titles( fHandle );
1752 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1753 [fSrcTitlePopUp indexOfSelectedItem] );
1754 hb_job_t * job = title->job;
1758 /* We use a number system to set the encode status of the queue item
1759 * 0 == already encoded
1760 * 1 == is being encoded
1761 * 2 == is yet to be encoded
1764 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1765 /* Source and Destination Information */
1767 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1768 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1769 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1770 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1772 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1774 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1776 /* Lets get the preset info if there is any */
1777 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1778 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1780 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1781 /* Chapter Markers fCreateChapterMarkers*/
1782 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1784 /* We need to get the list of chapter names to put into an array and store
1785 * in our queue, so they can be reapplied in prepareJob when this queue
1786 * item comes up if Chapter Markers is set to on.
1789 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
1790 int chaptercount = hb_list_count( fTitle->list_chapter );
1791 for( i = 0; i < chaptercount; i++ )
1793 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
1794 if( chapter != NULL )
1796 [ChapterNamesArray addObject:[NSString stringWithFormat:@"%s",chapter->title]];
1799 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
1800 [ChapterNamesArray autorelease];
1802 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1803 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1804 /* Mux mp4 with http optimization */
1805 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1806 /* Add iPod uuid atom */
1807 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1811 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
1812 /* x264 Option String */
1813 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1815 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1816 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1817 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1818 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1820 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
1823 [queueFileJob setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
1824 /* 2 Pass Encoding */
1825 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
1826 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
1827 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
1829 /* Picture Sizing */
1830 /* Use Max Picture settings for whatever the dvd is.*/
1831 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1832 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1833 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1834 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1835 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1836 NSString * pictureSummary;
1837 pictureSummary = [NSString stringWithFormat:@"Source: %@ Output: %@ Anamorphic: %@",
1838 [fPicSettingsSrc stringValue],
1839 [fPicSettingsOutp stringValue],
1840 [fPicSettingsAnamorphic stringValue]];
1841 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
1842 /* Set crop settings here */
1843 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1844 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1845 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1846 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1847 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1849 /* Picture Filters */
1850 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
1851 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
1852 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
1853 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
1854 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
1857 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1859 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
1860 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
1861 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
1862 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
1863 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
1864 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
1865 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
1867 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1869 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
1870 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
1871 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
1872 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
1873 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
1874 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
1875 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
1877 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1879 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
1880 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
1881 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
1882 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
1883 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
1884 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
1885 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
1887 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1889 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
1890 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
1891 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
1892 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
1893 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
1894 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
1895 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
1899 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1900 [queueFileJob setObject:[NSNumber numberWithInt:[fSubPopUp indexOfSelectedItem]] forKey:@"JobSubtitlesIndex"];
1901 /* Forced Subtitles */
1902 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1906 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
1908 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
1910 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
1913 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
1914 /* Chapter Markers fCreateChapterMarkers*/
1915 //[queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1916 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1917 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1918 /* Mux mp4 with http optimization */
1919 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1920 /* Add iPod uuid atom */
1921 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1925 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
1926 /* x264 Option String */
1927 //[queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1929 //[queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1930 //[queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1931 //[queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1932 //[queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1934 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
1935 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
1936 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
1937 /* Picture Sizing */
1938 /* Use Max Picture settings for whatever the dvd is.*/
1939 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1940 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1941 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1942 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1943 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1945 /* Set crop settings here */
1946 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1947 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1948 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1949 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1950 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1952 /* Picture Filters */
1953 [queueFileJob setObject:[fPicSettingDecomb stringValue] forKey:@"JobPictureDecomb"];
1956 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1958 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
1959 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
1960 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
1961 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
1962 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
1964 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1966 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
1967 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
1968 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
1969 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
1970 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
1972 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1974 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
1975 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
1976 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
1977 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
1978 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
1980 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1982 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
1983 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
1984 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
1985 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
1986 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
1989 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1990 /* Forced Subtitles */
1991 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1993 /* we need to auto relase the queueFileJob and return it */
1994 [queueFileJob autorelease];
1995 return queueFileJob;
1999 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
2000 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
2002 unsigned index = [indexSet lastIndex];
2003 unsigned aboveInsertIndexCount = 0;
2005 while (index != NSNotFound)
2007 unsigned removeIndex;
2009 if (index >= insertIndex)
2011 removeIndex = index + aboveInsertIndexCount;
2012 aboveInsertIndexCount++;
2016 removeIndex = index;
2020 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2021 [QueueFileArray removeObjectAtIndex:removeIndex];
2022 [QueueFileArray insertObject:object atIndex:insertIndex];
2025 index = [indexSet indexLessThanIndex:index];
2027 /* We save all of the Queue data here
2028 * and it also gets sent back to the queue controller*/
2029 [self saveQueueFileItem];
2035 #pragma mark Queue Job Processing
2037 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2039 int i = currentQueueEncodeIndex;
2040 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2042 /* We save all of the Queue data here */
2043 [self saveQueueFileItem];
2044 /* We Reload the New Table data for presets */
2045 //[fPresetsOutlineView reloadData];
2047 /* Since we have now marked a queue item as done
2048 * we can go ahead and increment currentQueueEncodeIndex
2049 * so that if there is anything left in the queue we can
2050 * go ahead and move to the next item if we want to */
2051 currentQueueEncodeIndex++ ;
2052 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2053 int queueItems = [QueueFileArray count];
2054 /* If we still have more items in our queue, lets go to the next one */
2055 if (currentQueueEncodeIndex < queueItems)
2057 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2058 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2062 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2066 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2067 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2069 //NSRunAlertPanel(@"Hello!", @"We are now performing a new queue scan!", @"OK", nil, nil);
2071 /* use a bool to determine whether or not we can decrypt using vlc */
2072 BOOL cancelScanDecrypt = 0;
2073 /* set the bool so that showNewScan knows to apply the appropriate queue
2074 * settings as this is a queue rescan
2076 applyQueueToScan = YES;
2077 NSString *path = scanPath;
2078 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2080 /*On Screen Notification*/
2082 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2083 //[NSApp requestUserAttention:NSCriticalRequest];
2085 // Notify ChapterTitles that there's no title
2086 [fChapterTitlesDelegate resetWithTitle:nil];
2087 [fChapterTable reloadData];
2089 //[self enableUI: NO];
2091 if( [detector isVideoDVD] )
2093 // The chosen path was actually on a DVD, so use the raw block
2094 // device path instead.
2095 path = [detector devicePath];
2096 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2098 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2099 NSString *vlcPath = @"/Applications/VLC.app";
2100 NSFileManager * fileManager = [NSFileManager defaultManager];
2101 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2103 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2104 cancelScanDecrypt = 1;
2105 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2107 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");
2108 [NSApp requestUserAttention:NSCriticalRequest];
2110 if (status == NSAlertDefaultReturn)
2112 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2113 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2115 else if (status == NSAlertAlternateReturn)
2117 /* User chose to cancel the scan */
2118 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2122 /* 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 */
2123 cancelScanDecrypt = 0;
2124 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2130 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2131 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2135 if (cancelScanDecrypt == 0)
2137 /* we actually pass the scan off to libhb here */
2138 /* If there is no title number passed to scan, we use "0"
2139 * which causes the default behavior of a full source scan
2145 if (scanTitleNum > 0)
2147 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2149 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2150 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum );
2154 /* This method was originally used to load up a new queue item in the gui and
2155 * then start processing it. However we now have modified -prepareJob and use a second
2156 * instance of libhb to do our actual encoding, therefor right now it is not required.
2157 * Nonetheless I want to leave this in here
2158 * because basically its everything we need to be able to actually modify a pending queue
2159 * item in the gui and resave it. At least for now - dynaflash
2162 - (IBAction)applyQueueSettings:(id)sender
2164 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2165 hb_job_t * job = fTitle->job;
2167 /* Set title number and chapters */
2168 /* since the queue only scans a single title, we really don't need to pick a title */
2169 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2171 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2172 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2175 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2176 [self formatPopUpChanged:nil];
2178 /* Chapter Markers*/
2179 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2180 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2181 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2182 /* Mux mp4 with http optimization */
2183 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2186 /* We set the advanced opt string here if applicable*/
2187 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2188 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2190 /* Lets run through the following functions to get variables set there */
2191 [self videoEncoderPopUpChanged:nil];
2192 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2193 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2194 [self calculateBitrate:nil];
2197 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2199 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2200 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2201 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2203 [self videoMatrixChanged:nil];
2205 /* Video framerate */
2206 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2207 detected framerate in the fVidRatePopUp so we use index 0*/
2208 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2210 [fVidRatePopUp selectItemAtIndex: 0];
2214 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2218 [fVidGrayscaleCheck setState:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2220 /* 2 Pass Encoding */
2221 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2222 [self twoPassCheckboxChanged:nil];
2223 /* Turbo 1st pass for 2 Pass Encoding */
2224 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2227 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2229 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2231 [fAudLang1PopUp selectItemAtIndex: 1];
2233 [self audioTrackPopUpChanged: fAudLang1PopUp];
2234 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2235 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2236 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2237 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2239 if ([fAudTrack1MixPopUp selectedItem] == nil)
2241 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2243 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2244 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2245 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2247 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2249 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2250 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2252 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2254 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2256 [fAudLang2PopUp selectItemAtIndex: 1];
2258 [self audioTrackPopUpChanged: fAudLang2PopUp];
2259 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2260 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2261 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2262 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2264 if ([fAudTrack2MixPopUp selectedItem] == nil)
2266 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2268 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2269 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2270 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2272 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2274 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2275 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2277 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2279 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2281 [fAudLang3PopUp selectItemAtIndex: 1];
2283 [self audioTrackPopUpChanged: fAudLang3PopUp];
2284 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2285 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2286 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2287 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2289 if ([fAudTrack3MixPopUp selectedItem] == nil)
2291 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2293 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2294 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2295 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2297 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2299 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2300 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2302 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2304 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2306 [fAudLang4PopUp selectItemAtIndex: 1];
2308 [self audioTrackPopUpChanged: fAudLang4PopUp];
2309 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2310 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2311 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2312 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2314 if ([fAudTrack4MixPopUp selectedItem] == nil)
2316 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2318 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2319 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2320 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2322 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2324 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2325 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2330 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2331 /* Forced Subtitles */
2332 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2334 /* Picture Settings */
2335 /* we check to make sure the presets width/height does not exceed the sources width/height */
2336 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2338 /* if so, then we use the sources height and width to avoid scaling up */
2339 job->width = fTitle->width;
2340 job->height = fTitle->height;
2342 else // source width/height is >= the preset height/width
2344 /* we can go ahead and use the presets values for height and width */
2345 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2346 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2348 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2349 if (job->keep_ratio == 1)
2351 hb_fix_aspect( job, HB_KEEP_WIDTH );
2352 if( job->height > fTitle->height )
2354 job->height = fTitle->height;
2355 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2358 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2361 /* If Cropping is set to custom, then recall all four crop values from
2362 when the preset was created and apply them */
2363 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2365 [fPictureController setAutoCrop:NO];
2367 /* Here we use the custom crop values saved at the time the preset was saved */
2368 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2369 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2370 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2371 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2374 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2376 [fPictureController setAutoCrop:YES];
2377 /* Here we use the auto crop values determined right after scan */
2378 job->crop[0] = AutoCropTop;
2379 job->crop[1] = AutoCropBottom;
2380 job->crop[2] = AutoCropLeft;
2381 job->crop[3] = AutoCropRight;
2387 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2390 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2392 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2394 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2396 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2398 [self calculatePictureSizing:nil];
2401 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2402 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2403 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2404 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2406 /* Deselect the currently selected Preset if there is one*/
2407 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2408 //[self selectPreset:nil];
2410 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2411 /* Change UI to show "Custom" settings are being used */
2412 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2414 curUserPresetChosenNum = nil;
2418 /* Deselect the currently selected Preset if there is one*/
2419 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2420 /* Change UI to show "Custom" settings are being used */
2421 [fPresetSelectedDisplay setStringValue: @"Custom"];
2423 //curUserPresetChosenNum = nil;
2426 /* We need to set this bool back to NO, in case the user wants to do a scan */
2427 //applyQueueToScan = NO;
2429 /* so now we go ahead and process the new settings */
2430 [self processNewQueueEncode];
2435 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2436 - (void) processNewQueueEncode
2438 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2439 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2440 hb_job_t * job = title->job;
2442 if( !hb_list_count( list ) )
2444 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2448 [self writeToActivityLog: "processNewQueueEncode title list is: %d", hb_list_count( list )];
2451 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2452 [self writeToActivityLog: "processNewQueueEncode currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2453 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2454 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2455 [self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2457 [self writeToActivityLog: "processNewQueueEncode back from prepareJob"];
2458 if( [[queueToApply objectForKey:@"SubtitlesForced"] intValue] == 1 )
2459 job->subtitle_force = 1;
2461 job->subtitle_force = 0;
2464 * subtitle of -1 is a scan
2466 if( job->subtitle == -1 )
2471 * When subtitle scan is enabled do a fast pre-scan job
2472 * which will determine which subtitles to enable, if any.
2475 x264opts_tmp = job->x264opts;
2478 job->x264opts = NULL;
2480 job->indepth_scan = 1;
2482 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
2483 *(job->select_subtitle) = NULL;
2486 * Add the pre-scan job
2488 hb_add( fQueueEncodeLibhb, job );
2489 job->x264opts = x264opts_tmp;
2492 job->select_subtitle = NULL;
2494 /* No subtitle were selected, so reset the subtitle to -1 (which before
2495 * this point meant we were scanning
2497 if( job->subtitle == -2 )
2500 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2502 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
2503 job->indepth_scan = 0;
2506 * Do not autoselect subtitles on the first pass of a two pass
2508 job->select_subtitle = NULL;
2512 hb_add( fQueueEncodeLibhb, job );
2516 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2517 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2519 job->select_subtitle = subtitle_tmp;
2521 hb_add( fQueueEncodeLibhb, job );
2526 job->indepth_scan = 0;
2529 hb_add( fQueueEncodeLibhb, job );
2532 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2533 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2534 /* Lets mark our new encode as 1 or "Encoding" */
2535 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2536 [self saveQueueFileItem];
2537 /* We should be all setup so let 'er rip */
2543 #pragma mark Job Handling
2549 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2550 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2551 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2552 hb_job_t * job = title->job;
2553 hb_audio_config_t * audio;
2554 [self writeToActivityLog: "prepareJob reached"];
2555 /* Chapter selection */
2556 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
2557 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
2559 /* Format (Muxer) and Video Encoder */
2560 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
2561 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
2564 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
2565 //if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
2567 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
2568 mpeg4 and the checkbox being checked
2569 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
2570 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
2572 job->largeFileSize = 1;
2576 job->largeFileSize = 0;
2578 /* We set http optimized mp4 here */
2579 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
2581 job->mp4_optimize = 1;
2585 job->mp4_optimize = 0;
2590 /* We set the chapter marker extraction here based on the format being
2591 mpeg4 or mkv and the checkbox being checked */
2592 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
2594 job->chapter_markers = 1;
2596 /* now lets get our saved chapter names out the array in the queue file
2597 * and insert them back into the title chapter list. We have it here,
2598 * because unless we are inserting chapter markers there is no need to
2599 * spend the overhead of iterating through the chapter names array imo
2600 * Also, note that if for some reason we don't apply chapter names, the
2601 * chapters just come out 001, 002, etc. etc.
2604 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
2606 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
2608 while (tempObject = [enumerator nextObject])
2610 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
2611 if( chapter != NULL )
2613 strncpy( chapter->title, [tempObject UTF8String], 1023);
2614 chapter->title[1023] = '\0';
2621 job->chapter_markers = 0;
2628 if( job->vcodec & HB_VCODEC_X264 )
2630 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
2639 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2640 Currently only used with Constant Quality setting*/
2641 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
2645 /* Below Sends x264 options to the core library if x264 is selected*/
2646 /* Lets use this as per Nyx, Thanks Nyx!*/
2647 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2648 /* Turbo first pass if two pass and Turbo First pass is selected */
2649 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
2651 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
2652 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
2653 /* append the "Turbo" string variable to the existing opts string.
2654 Note: the "Turbo" string must be appended, not prepended to work properly*/
2655 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
2656 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
2660 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2666 [self writeToActivityLog: "prepareJob reached Picture Settings"];
2667 /* Picture Size Settings */
2668 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2669 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2671 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2672 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2675 /* Here we use the crop values saved at the time the preset was saved */
2676 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2677 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2678 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2679 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2681 /* Video settings */
2682 [self writeToActivityLog: "prepareJob reached Frame Rate"];
2685 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2686 * and detelecine is on, so we handle that in the logic below
2689 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
2691 /* a specific framerate has been chosen */
2692 job->vrate = 27000000;
2693 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
2694 /* We are not same as source so we set job->cfr to 1
2695 * to enable constant frame rate since user has specified
2696 * a specific framerate*/
2701 /* We are same as source (variable) */
2702 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
2703 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
2704 /* We are same as source so we set job->cfr to 0
2705 * to enable true same as source framerate */
2707 /* If we are same as source and we have detelecine on, we need to turn on
2710 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
2715 [self writeToActivityLog: "prepareJob reached Bitrate Video Quality"];
2716 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 0 )
2719 Bitrate should already have been calculated and displayed
2720 in fVidBitrateField, so let's just use it */
2722 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 1 )
2724 job->vquality = -1.0;
2725 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
2727 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
2729 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
2734 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
2735 /* Subtitle settings */
2736 job->subtitle = [[queueToApply objectForKey:@"JobSubtitlesIndex"] intValue] - 2;
2738 [self writeToActivityLog: "prepareJob reached Audio"];
2739 /* Audio tracks and mixdowns */
2740 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2741 int audiotrack_count = hb_list_count(job->list_audio);
2742 for( int i = 0; i < audiotrack_count;i++)
2744 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2745 hb_list_rem(job->list_audio, temp_audio);
2747 /* Now lets add our new tracks to the audio list here */
2748 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
2750 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2751 hb_audio_config_init(audio);
2752 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2753 /* We go ahead and assign values to our audio->out.<properties> */
2754 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2755 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
2756 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
2757 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
2758 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
2759 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
2761 hb_audio_add( job, audio );
2764 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
2767 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2768 hb_audio_config_init(audio);
2769 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2770 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
2771 /* We go ahead and assign values to our audio->out.<properties> */
2772 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2773 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
2774 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
2775 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
2776 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
2777 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
2779 hb_audio_add( job, audio );
2783 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
2785 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2786 hb_audio_config_init(audio);
2787 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2788 /* We go ahead and assign values to our audio->out.<properties> */
2789 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2790 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
2791 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
2792 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
2793 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
2794 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2796 hb_audio_add( job, audio );
2800 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
2802 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2803 hb_audio_config_init(audio);
2804 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2805 /* We go ahead and assign values to our audio->out.<properties> */
2806 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2807 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
2808 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
2809 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
2810 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
2811 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2813 hb_audio_add( job, audio );
2817 [self writeToActivityLog: "prepareJob reached Filters"];
2819 job->filters = hb_list_init();
2821 /* Now lets call the filters if applicable.
2822 * The order of the filters is critical
2825 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
2827 hb_list_add( job->filters, &hb_filter_detelecine );
2831 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
2833 /* Run old deinterlacer fd by default */
2834 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"JobPictureDecomb"] UTF8String];
2835 hb_list_add( job->filters, &hb_filter_decomb );
2839 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
2841 /* Run old deinterlacer fd by default */
2842 hb_filter_deinterlace.settings = "-1";
2843 hb_list_add( job->filters, &hb_filter_deinterlace );
2845 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
2847 /* Yadif mode 0 (without spatial deinterlacing.) */
2848 hb_filter_deinterlace.settings = "2";
2849 hb_list_add( job->filters, &hb_filter_deinterlace );
2851 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
2853 /* Yadif (with spatial deinterlacing) */
2854 hb_filter_deinterlace.settings = "0";
2855 hb_list_add( job->filters, &hb_filter_deinterlace );
2859 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
2861 hb_filter_denoise.settings = "2:1:2:3";
2862 hb_list_add( job->filters, &hb_filter_denoise );
2864 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
2866 hb_filter_denoise.settings = "3:2:2:3";
2867 hb_list_add( job->filters, &hb_filter_denoise );
2869 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
2871 hb_filter_denoise.settings = "7:7:5:5";
2872 hb_list_add( job->filters, &hb_filter_denoise );
2875 /* Deblock (uses pp7 default) */
2876 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
2877 * the macgui's purposes a value of 0 actually means to not even use the filter
2878 * current hb_filter_deblock.settings valid ranges are from 5 - 15
2880 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
2882 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
2883 hb_list_add( job->filters, &hb_filter_deblock );
2885 [self writeToActivityLog: "prepareJob exiting"];
2890 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
2892 - (IBAction) addToQueue: (id) sender
2894 /* We get the destination directory from the destination field here */
2895 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2896 /* We check for a valid destination here */
2897 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2899 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2903 /* We check for duplicate name here */
2904 if( [[NSFileManager defaultManager] fileExistsAtPath:
2905 [fDstFile2Field stringValue]] )
2907 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2908 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2909 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
2910 NULL, NULL, [NSString stringWithFormat:
2911 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2912 [fDstFile2Field stringValue]] );
2913 // overwriteAddToQueueAlertDone: will be called when the alert is dismissed.
2917 [self doAddToQueue];
2921 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
2922 the user if they want to overwrite an exiting movie file.
2924 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
2925 returnCode: (int) returnCode contextInfo: (void *) contextInfo
2927 if( returnCode == NSAlertAlternateReturn )
2928 [self doAddToQueue];
2931 - (void) doAddToQueue
2933 [self addQueueFileItem ];
2938 /* Rip: puts up an alert before ultimately calling doRip
2940 - (IBAction) Rip: (id) sender
2942 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
2943 /* Rip or Cancel ? */
2945 hb_get_state2( fQueueEncodeLibhb, &s );
2947 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
2949 [self Cancel: sender];
2953 /* We check to see if we need to warn the user that the computer will go to sleep
2954 or shut down when encoding is finished */
2955 [self remindUserOfSleepOrShutdown];
2957 // If there are pending jobs in the queue, then this is a rip the queue
2958 if (fPendingCount > 0)
2960 /* here lets start the queue with the first pending item */
2961 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2966 // Before adding jobs to the queue, check for a valid destination.
2968 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2969 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2971 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2975 /* We check for duplicate name here */
2976 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
2978 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2979 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2980 @selector( overWriteAlertDone:returnCode:contextInfo: ),
2981 NULL, NULL, [NSString stringWithFormat:
2982 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2983 [fDstFile2Field stringValue]] );
2985 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
2989 /* if there are no pending jobs in the queue, then add this one to the queue and rip
2990 otherwise, just rip the queue */
2991 if(fPendingCount == 0)
2993 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
2994 [self doAddToQueue];
2997 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2998 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2999 /* go right to processing the new queue encode */
3000 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
3001 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3006 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3007 want to overwrite an exiting movie file.
3009 - (void) overWriteAlertDone: (NSWindow *) sheet
3010 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3012 if( returnCode == NSAlertAlternateReturn )
3014 /* if there are no jobs in the queue, then add this one to the queue and rip
3015 otherwise, just rip the queue */
3016 if( fPendingCount == 0 )
3018 [self doAddToQueue];
3021 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3022 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3023 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3028 - (void) remindUserOfSleepOrShutdown
3030 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
3032 /*Warn that computer will sleep after encoding*/
3035 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);
3036 [NSApp requestUserAttention:NSCriticalRequest];
3037 if ( reminduser == NSAlertAlternateReturn )
3039 [self showPreferencesWindow:nil];
3042 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
3044 /*Warn that computer will shut down after encoding*/
3047 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);
3048 [NSApp requestUserAttention:NSCriticalRequest];
3049 if ( reminduser == NSAlertAlternateReturn )
3051 [self showPreferencesWindow:nil];
3060 /* Let libhb do the job */
3061 hb_start( fQueueEncodeLibhb );
3062 /*set the fEncodeState State */
3067 //------------------------------------------------------------------------------------
3068 // Cancels and deletes the current job and stops libhb from processing the remaining
3070 //------------------------------------------------------------------------------------
3071 - (void) doCancelCurrentJob
3073 // Stop the current job. hb_stop will only cancel the current pass and then set
3074 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3075 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3076 // remaining passes of the job and then start the queue back up if there are any
3080 hb_stop( fQueueEncodeLibhb );
3081 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3083 // now that we've stopped the currently encoding job, lets mark it as cancelled
3084 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3085 // and as always, save it in the queue .plist...
3086 /* We save all of the Queue data here */
3087 [self saveQueueFileItem];
3088 // so now lets move to
3089 currentQueueEncodeIndex++ ;
3090 // ... and see if there are more items left in our queue
3091 int queueItems = [QueueFileArray count];
3092 /* If we still have more items in our queue, lets go to the next one */
3093 if (currentQueueEncodeIndex < queueItems)
3095 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3096 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3098 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3102 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3107 //------------------------------------------------------------------------------------
3108 // Displays an alert asking user if the want to cancel encoding of current job.
3109 // Cancel: returns immediately after posting the alert. Later, when the user
3110 // acknowledges the alert, doCancelCurrentJob is called.
3111 //------------------------------------------------------------------------------------
3112 - (IBAction)Cancel: (id)sender
3114 if (!fQueueController) return;
3116 hb_pause( fQueueEncodeLibhb );
3117 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3119 // Which window to attach the sheet to?
3120 NSWindow * docWindow;
3121 if ([sender respondsToSelector: @selector(window)])
3122 docWindow = [sender window];
3124 docWindow = fWindow;
3126 NSBeginCriticalAlertSheet(
3128 NSLocalizedString(@"Continue Encoding", nil),
3129 NSLocalizedString(@"Cancel Current and Stop", nil),
3130 NSLocalizedString(@"Cancel Current and Continue", nil),
3132 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3133 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3135 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3138 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3140 hb_resume( fQueueEncodeLibhb );
3141 if (returnCode == NSAlertOtherReturn)
3143 [self doCancelCurrentJob]; // <- this also stops libhb
3145 if (returnCode == NSAlertAlternateReturn)
3147 [self doCancelCurrentJobAndStop];
3151 - (void) doCancelCurrentJobAndStop
3153 hb_stop( fQueueEncodeLibhb );
3154 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3156 // now that we've stopped the currently encoding job, lets mark it as cancelled
3157 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3158 // and as always, save it in the queue .plist...
3159 /* We save all of the Queue data here */
3160 [self saveQueueFileItem];
3161 // so now lets move to
3162 currentQueueEncodeIndex++ ;
3163 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3165 - (IBAction) Pause: (id) sender
3168 hb_get_state2( fQueueEncodeLibhb, &s );
3170 if( s.state == HB_STATE_PAUSED )
3172 hb_resume( fQueueEncodeLibhb );
3176 hb_pause( fQueueEncodeLibhb );
3181 #pragma mark GUI Controls Changed Methods
3183 - (IBAction) titlePopUpChanged: (id) sender
3185 hb_list_t * list = hb_get_titles( fHandle );
3186 hb_title_t * title = (hb_title_t*)
3187 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3189 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3190 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3192 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3193 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3194 [browsedSourceDisplayName stringByDeletingPathExtension],
3196 [[fDstFile2Field stringValue] pathExtension]]];
3199 /* Update chapter popups */
3200 [fSrcChapterStartPopUp removeAllItems];
3201 [fSrcChapterEndPopUp removeAllItems];
3202 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
3204 [fSrcChapterStartPopUp addItemWithTitle: [NSString
3205 stringWithFormat: @"%d", i + 1]];
3206 [fSrcChapterEndPopUp addItemWithTitle: [NSString
3207 stringWithFormat: @"%d", i + 1]];
3210 [fSrcChapterStartPopUp selectItemAtIndex: 0];
3211 [fSrcChapterEndPopUp selectItemAtIndex:
3212 hb_list_count( title->list_chapter ) - 1];
3213 [self chapterPopUpChanged:nil];
3215 /* Start Get and set the initial pic size for display */
3216 hb_job_t * job = title->job;
3219 /*Set Source Size Field Here */
3220 [fPicSettingsSrc setStringValue: [NSString stringWithFormat: @"%d x %d", fTitle->width, fTitle->height]];
3222 /* Set Auto Crop to on upon selecting a new title */
3223 [fPictureController setAutoCrop:YES];
3225 /* We get the originial output picture width and height and put them
3226 in variables for use with some presets later on */
3227 PicOrigOutputWidth = job->width;
3228 PicOrigOutputHeight = job->height;
3229 AutoCropTop = job->crop[0];
3230 AutoCropBottom = job->crop[1];
3231 AutoCropLeft = job->crop[2];
3232 AutoCropRight = job->crop[3];
3234 /* Run Through encoderPopUpChanged to see if there
3235 needs to be any pic value modifications based on encoder settings */
3236 //[self encoderPopUpChanged: NULL];
3237 /* END Get and set the initial pic size for display */
3239 /* Update subtitle popups */
3240 hb_subtitle_t * subtitle;
3241 [fSubPopUp removeAllItems];
3242 [fSubPopUp addItemWithTitle: @"None"];
3243 [fSubPopUp addItemWithTitle: @"Autoselect"];
3244 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
3246 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
3248 /* We cannot use NSPopUpButton's addItemWithTitle because
3249 it checks for duplicate entries */
3250 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
3251 subtitle->lang] action: NULL keyEquivalent: @""];
3253 [fSubPopUp selectItemAtIndex: 0];
3255 [self subtitleSelectionChanged:nil];
3257 /* Update chapter table */
3258 [fChapterTitlesDelegate resetWithTitle:title];
3259 [fChapterTable reloadData];
3261 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3262 int audiotrack_count = hb_list_count(job->list_audio);
3263 for( int i = 0; i < audiotrack_count;i++)
3265 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3266 hb_list_rem(job->list_audio, temp_audio);
3269 /* Update audio popups */
3270 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
3271 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
3272 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
3273 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
3274 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
3275 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
3276 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
3277 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3278 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3279 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3281 /* changing the title may have changed the audio channels on offer, */
3282 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3283 [self audioTrackPopUpChanged: fAudLang1PopUp];
3284 [self audioTrackPopUpChanged: fAudLang2PopUp];
3285 [self audioTrackPopUpChanged: fAudLang3PopUp];
3286 [self audioTrackPopUpChanged: fAudLang4PopUp];
3288 [fVidRatePopUp selectItemAtIndex: 0];
3290 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
3291 [self calculatePictureSizing:nil];
3293 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
3294 [self selectPreset:nil];
3297 - (IBAction) chapterPopUpChanged: (id) sender
3300 /* If start chapter popup is greater than end chapter popup,
3301 we set the end chapter popup to the same as start chapter popup */
3302 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
3304 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
3308 hb_list_t * list = hb_get_titles( fHandle );
3309 hb_title_t * title = (hb_title_t *)
3310 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3312 hb_chapter_t * chapter;
3313 int64_t duration = 0;
3314 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
3315 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
3317 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3318 duration += chapter->duration;
3321 duration /= 90000; /* pts -> seconds */
3322 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
3323 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
3326 [self calculateBitrate: sender];
3329 - (IBAction) formatPopUpChanged: (id) sender
3331 NSString * string = [fDstFile2Field stringValue];
3332 int format = [fDstFormatPopUp indexOfSelectedItem];
3334 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
3335 [fDstMp4LargeFileCheck setHidden: YES];
3336 [fDstMp4HttpOptFileCheck setHidden: YES];
3337 [fDstMp4iPodFileCheck setHidden: YES];
3339 /* Update the Video Codec PopUp */
3340 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
3341 [fVidEncoderPopUp removeAllItems];
3342 NSMenuItem *menuItem;
3343 /* These video encoders are available to all of our current muxers, so lets list them once here */
3344 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
3345 [menuItem setTag: HB_VCODEC_FFMPEG];
3347 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (XviD)" action: NULL keyEquivalent: @""];
3348 [menuItem setTag: HB_VCODEC_XVID];
3352 /*Get Default MP4 File Extension*/
3353 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
3361 /* Add additional video encoders here */
3362 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3363 [menuItem setTag: HB_VCODEC_X264];
3364 /* We show the mp4 option checkboxes here since we are mp4 */
3365 [fCreateChapterMarkers setEnabled: YES];
3366 [fDstMp4LargeFileCheck setHidden: NO];
3367 [fDstMp4HttpOptFileCheck setHidden: NO];
3368 [fDstMp4iPodFileCheck setHidden: NO];
3373 /* Add additional video encoders here */
3374 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3375 [menuItem setTag: HB_VCODEC_X264];
3376 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3377 [menuItem setTag: HB_VCODEC_THEORA];
3378 /* We enable the create chapters checkbox here */
3379 [fCreateChapterMarkers setEnabled: YES];
3384 /* Add additional video encoders here */
3385 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3386 [menuItem setTag: HB_VCODEC_X264];
3387 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3388 [fCreateChapterMarkers setEnabled: NO];
3389 [fCreateChapterMarkers setState: NSOffState];
3394 /* Add additional video encoders here */
3395 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3396 [menuItem setTag: HB_VCODEC_THEORA];
3397 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3398 [fCreateChapterMarkers setEnabled: NO];
3399 [fCreateChapterMarkers setState: NSOffState];
3402 [fVidEncoderPopUp selectItemAtIndex: 0];
3404 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
3405 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
3406 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
3407 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
3410 [self autoSetM4vExtension: sender];
3412 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
3414 if( SuccessfulScan )
3416 /* Add/replace to the correct extension */
3417 [self audioTrackPopUpChanged: fAudLang1PopUp];
3418 [self audioTrackPopUpChanged: fAudLang2PopUp];
3419 [self audioTrackPopUpChanged: fAudLang3PopUp];
3420 [self audioTrackPopUpChanged: fAudLang4PopUp];
3422 if( [fVidEncoderPopUp selectedItem] == nil )
3425 [fVidEncoderPopUp selectItemAtIndex:0];
3426 [self videoEncoderPopUpChanged:nil];
3428 /* changing the format may mean that we can / can't offer mono or 6ch, */
3429 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3431 /* We call the method to properly enable/disable turbo 2 pass */
3432 [self twoPassCheckboxChanged: sender];
3433 /* We call method method to change UI to reflect whether a preset is used or not*/
3436 [self customSettingUsed: sender];
3439 - (IBAction) autoSetM4vExtension: (id) sender
3441 if ( [fDstFormatPopUp indexOfSelectedItem] )
3444 NSString * extension = @"mp4";
3446 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3447 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3448 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3449 [fCreateChapterMarkers state] == NSOnState ||
3450 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
3455 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
3458 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
3459 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
3462 - (void) shouldEnableHttpMp4CheckBox: (id) sender
3464 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3465 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3466 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 )
3467 [fDstMp4HttpOptFileCheck setEnabled: NO];
3469 [fDstMp4HttpOptFileCheck setEnabled: YES];
3472 /* Method to determine if we should change the UI
3473 To reflect whether or not a Preset is being used or if
3474 the user is using "Custom" settings by determining the sender*/
3475 - (IBAction) customSettingUsed: (id) sender
3477 if ([sender stringValue])
3479 /* Deselect the currently selected Preset if there is one*/
3480 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
3481 /* Change UI to show "Custom" settings are being used */
3482 [fPresetSelectedDisplay setStringValue: @"Custom"];
3484 curUserPresetChosenNum = nil;
3490 #pragma mark - Video
3492 - (IBAction) videoEncoderPopUpChanged: (id) sender
3494 hb_job_t * job = fTitle->job;
3495 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
3497 [fAdvancedOptions setHidden:YES];
3498 /* If we are using x264 then show the x264 advanced panel*/
3499 if (videoEncoder == HB_VCODEC_X264)
3501 [fAdvancedOptions setHidden:NO];
3502 [self autoSetM4vExtension: sender];
3505 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
3506 is being used as it borks up loose anamorphic .
3507 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
3508 to use the index itself but this is easier */
3509 if (videoEncoder == HB_VCODEC_FFMPEG)
3511 if (job->pixel_ratio == 2)
3513 job->pixel_ratio = 0;
3515 [fPictureController setAllowLooseAnamorphic:NO];
3516 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
3517 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
3518 anything other than MP4.
3520 [fDstMp4iPodFileCheck setEnabled: NO];
3521 [fDstMp4iPodFileCheck setState: NSOffState];
3525 [fPictureController setAllowLooseAnamorphic:YES];
3526 [fDstMp4iPodFileCheck setEnabled: YES];
3529 [self calculatePictureSizing: sender];
3530 [self twoPassCheckboxChanged: sender];
3534 - (IBAction) twoPassCheckboxChanged: (id) sender
3536 /* check to see if x264 is chosen */
3537 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
3539 if( [fVidTwoPassCheck state] == NSOnState)
3541 [fVidTurboPassCheck setHidden: NO];
3545 [fVidTurboPassCheck setHidden: YES];
3546 [fVidTurboPassCheck setState: NSOffState];
3548 /* Make sure Two Pass is checked if Turbo is checked */
3549 if( [fVidTurboPassCheck state] == NSOnState)
3551 [fVidTwoPassCheck setState: NSOnState];
3556 [fVidTurboPassCheck setHidden: YES];
3557 [fVidTurboPassCheck setState: NSOffState];
3560 /* We call method method to change UI to reflect whether a preset is used or not*/
3561 [self customSettingUsed: sender];
3564 - (IBAction ) videoFrameRateChanged: (id) sender
3566 /* We call method method to calculatePictureSizing to error check detelecine*/
3567 [self calculatePictureSizing: sender];
3569 /* We call method method to change UI to reflect whether a preset is used or not*/
3570 [self customSettingUsed: sender];
3572 - (IBAction) videoMatrixChanged: (id) sender;
3574 bool target, bitrate, quality;
3576 target = bitrate = quality = false;
3577 if( [fVidQualityMatrix isEnabled] )
3579 switch( [fVidQualityMatrix selectedRow] )
3592 [fVidTargetSizeField setEnabled: target];
3593 [fVidBitrateField setEnabled: bitrate];
3594 [fVidQualitySlider setEnabled: quality];
3595 [fVidTwoPassCheck setEnabled: !quality &&
3596 [fVidQualityMatrix isEnabled]];
3599 [fVidTwoPassCheck setState: NSOffState];
3600 [fVidTurboPassCheck setHidden: YES];
3601 [fVidTurboPassCheck setState: NSOffState];
3604 [self qualitySliderChanged: sender];
3605 [self calculateBitrate: sender];
3606 [self customSettingUsed: sender];
3609 - (IBAction) qualitySliderChanged: (id) sender
3611 [fVidConstantCell setTitle: [NSString stringWithFormat:
3612 NSLocalizedString( @"Constant quality: %.0f %%", @"" ), 100.0 *
3613 [fVidQualitySlider floatValue]]];
3614 [self customSettingUsed: sender];
3617 - (void) controlTextDidChange: (NSNotification *) notification
3619 [self calculateBitrate:nil];
3622 - (IBAction) calculateBitrate: (id) sender
3624 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
3629 hb_list_t * list = hb_get_titles( fHandle );
3630 hb_title_t * title = (hb_title_t *) hb_list_item( list,
3631 [fSrcTitlePopUp indexOfSelectedItem] );
3632 hb_job_t * job = title->job;
3634 [fVidBitrateField setIntValue: hb_calc_bitrate( job,
3635 [fVidTargetSizeField intValue] )];
3639 #pragma mark - Picture
3641 /* lets set the picture size back to the max from right after title scan
3642 Lets use an IBAction here as down the road we could always use a checkbox
3643 in the gui to easily take the user back to max. Remember, the compiler
3644 resolves IBActions down to -(void) during compile anyway */
3645 - (IBAction) revertPictureSizeToMax: (id) sender
3647 hb_job_t * job = fTitle->job;
3648 [fPictureController setAutoCrop:YES];
3649 /* Here we use the auto crop values determined right after scan */
3650 job->crop[0] = AutoCropTop;
3651 job->crop[1] = AutoCropBottom;
3652 job->crop[2] = AutoCropLeft;
3653 job->crop[3] = AutoCropRight;
3654 /* Here we apply the max source storage width and height */
3655 job->width = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
3656 job->height = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
3658 [self calculatePictureSizing: sender];
3659 /* We call method to change UI to reflect whether a preset is used or not*/
3660 [self customSettingUsed: sender];
3664 * Registers changes made in the Picture Settings Window.
3667 - (void)pictureSettingsDidChange {
3668 [self calculatePictureSizing:nil];
3671 /* Get and Display Current Pic Settings in main window */
3672 - (IBAction) calculatePictureSizing: (id) sender
3674 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", fTitle->job->width, fTitle->job->height]];
3676 if (fTitle->job->pixel_ratio == 1)
3678 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
3679 int arpwidth = fTitle->job->pixel_aspect_width;
3680 int arpheight = fTitle->job->pixel_aspect_height;
3681 int displayparwidth = titlewidth * arpwidth / arpheight;
3682 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
3683 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", titlewidth, displayparheight]];
3684 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Strict", displayparwidth, displayparheight]];
3685 fTitle->job->keep_ratio = 0;
3687 else if (fTitle->job->pixel_ratio == 2)
3689 hb_job_t * job = fTitle->job;
3690 int output_width, output_height, output_par_width, output_par_height;
3691 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
3693 display_width = output_width * output_par_width / output_par_height;
3695 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", output_width, output_height]];
3696 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Loose", display_width, output_height]];
3698 fTitle->job->keep_ratio = 0;
3702 [fPicSettingsAnamorphic setStringValue:@"Off"];
3705 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
3706 if (fTitle->job->keep_ratio > 0)
3708 [fPicSettingARkeep setStringValue: @"On"];
3712 [fPicSettingARkeep setStringValue: @"Off"];
3716 if ([fPictureController detelecine]) {
3717 [fPicSettingDetelecine setStringValue: @"Yes"];
3720 [fPicSettingDetelecine setStringValue: @"No"];
3724 if ([fPictureController decomb] == 0)
3726 [fPicSettingDecomb setStringValue: @"Off"];
3728 else if ([fPictureController decomb] == 1)
3730 [fPicSettingDecomb setStringValue: @"1:2:6:9:80:16:16"];
3732 else if ([fPictureController decomb] == 2)
3734 [fPicSettingDecomb setStringValue:[[NSUserDefaults standardUserDefaults] stringForKey:@"DecombCustomString"]];
3737 /* VFR (Variable Frame Rate) */
3741 if ([fPictureController deinterlace] == 0)
3743 [fPicSettingDeinterlace setStringValue: @"Off"];
3745 else if ([fPictureController deinterlace] == 1)
3747 [fPicSettingDeinterlace setStringValue: @"Fast"];
3749 else if ([fPictureController deinterlace] == 2)
3751 [fPicSettingDeinterlace setStringValue: @"Slow"];
3753 else if ([fPictureController deinterlace] == 3)
3755 [fPicSettingDeinterlace setStringValue: @"Slower"];
3759 if ([fPictureController denoise] == 0)
3761 [fPicSettingDenoise setStringValue: @"Off"];
3763 else if ([fPictureController denoise] == 1)
3765 [fPicSettingDenoise setStringValue: @"Weak"];
3767 else if ([fPictureController denoise] == 2)
3769 [fPicSettingDenoise setStringValue: @"Medium"];
3771 else if ([fPictureController denoise] == 3)
3773 [fPicSettingDenoise setStringValue: @"Strong"];
3777 if ([fPictureController deblock] == 0)
3779 [fPicSettingDeblock setStringValue: @"Off"];
3783 [fPicSettingDeblock setStringValue: [NSString stringWithFormat:@"%d",[fPictureController deblock]]];
3786 if (fTitle->job->pixel_ratio > 0)
3788 [fPicSettingPAR setStringValue: @""];
3792 [fPicSettingPAR setStringValue: @"Off"];
3795 /* Set the display field for crop as per boolean */
3796 if (![fPictureController autoCrop])
3798 [fPicSettingAutoCrop setStringValue: @"Custom"];
3802 [fPicSettingAutoCrop setStringValue: @"Auto"];
3810 #pragma mark - Audio and Subtitles
3811 - (IBAction) audioCodecsPopUpChanged: (id) sender
3814 NSPopUpButton * audiotrackPopUp;
3815 NSPopUpButton * sampleratePopUp;
3816 NSPopUpButton * bitratePopUp;
3817 NSPopUpButton * audiocodecPopUp;
3818 if (sender == fAudTrack1CodecPopUp)
3820 audiotrackPopUp = fAudLang1PopUp;
3821 audiocodecPopUp = fAudTrack1CodecPopUp;
3822 sampleratePopUp = fAudTrack1RatePopUp;
3823 bitratePopUp = fAudTrack1BitratePopUp;
3825 else if (sender == fAudTrack2CodecPopUp)
3827 audiotrackPopUp = fAudLang2PopUp;
3828 audiocodecPopUp = fAudTrack2CodecPopUp;
3829 sampleratePopUp = fAudTrack2RatePopUp;
3830 bitratePopUp = fAudTrack2BitratePopUp;
3832 else if (sender == fAudTrack3CodecPopUp)
3834 audiotrackPopUp = fAudLang3PopUp;
3835 audiocodecPopUp = fAudTrack3CodecPopUp;
3836 sampleratePopUp = fAudTrack3RatePopUp;
3837 bitratePopUp = fAudTrack3BitratePopUp;
3841 audiotrackPopUp = fAudLang4PopUp;
3842 audiocodecPopUp = fAudTrack4CodecPopUp;
3843 sampleratePopUp = fAudTrack4RatePopUp;
3844 bitratePopUp = fAudTrack4BitratePopUp;
3847 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
3848 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3849 [self audioTrackPopUpChanged: audiotrackPopUp];
3853 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
3855 /* We will be setting the enabled/disabled state of each tracks audio controls based on
3856 * the settings of the source audio for that track. We leave the samplerate and bitrate
3857 * to audiotrackMixdownChanged
3860 /* We will first verify that a lower track number has been selected before enabling each track
3861 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
3863 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3865 [fAudLang2PopUp setEnabled: NO];
3866 [fAudLang2PopUp selectItemAtIndex: 0];
3870 [fAudLang2PopUp setEnabled: YES];
3873 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3875 [fAudLang3PopUp setEnabled: NO];
3876 [fAudLang3PopUp selectItemAtIndex: 0];
3880 [fAudLang3PopUp setEnabled: YES];
3882 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3884 [fAudLang4PopUp setEnabled: NO];
3885 [fAudLang4PopUp selectItemAtIndex: 0];
3889 [fAudLang4PopUp setEnabled: YES];
3891 /* enable/disable the mixdown text and popupbutton for audio track 1 */
3892 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3893 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3894 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3895 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3896 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3897 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3898 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3900 [fAudTrack1CodecPopUp removeAllItems];
3901 [fAudTrack1MixPopUp removeAllItems];
3902 [fAudTrack1RatePopUp removeAllItems];
3903 [fAudTrack1BitratePopUp removeAllItems];
3904 [fAudTrack1DrcSlider setFloatValue: 1.00];
3905 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
3907 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3909 [fAudTrack1RatePopUp setEnabled: NO];
3910 [fAudTrack1BitratePopUp setEnabled: NO];
3911 [fAudTrack1DrcSlider setEnabled: NO];
3912 [fAudTrack1DrcField setEnabled: NO];
3915 /* enable/disable the mixdown text and popupbutton for audio track 2 */
3916 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3917 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3918 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3919 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3920 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3921 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3922 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3924 [fAudTrack2CodecPopUp removeAllItems];
3925 [fAudTrack2MixPopUp removeAllItems];
3926 [fAudTrack2RatePopUp removeAllItems];
3927 [fAudTrack2BitratePopUp removeAllItems];
3928 [fAudTrack2DrcSlider setFloatValue: 1.00];
3929 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
3931 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3933 [fAudTrack2RatePopUp setEnabled: NO];
3934 [fAudTrack2BitratePopUp setEnabled: NO];
3935 [fAudTrack2DrcSlider setEnabled: NO];
3936 [fAudTrack2DrcField setEnabled: NO];
3939 /* enable/disable the mixdown text and popupbutton for audio track 3 */
3940 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3941 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3942 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3943 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3944 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3945 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3946 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3948 [fAudTrack3CodecPopUp removeAllItems];
3949 [fAudTrack3MixPopUp removeAllItems];
3950 [fAudTrack3RatePopUp removeAllItems];
3951 [fAudTrack3BitratePopUp removeAllItems];
3952 [fAudTrack3DrcSlider setFloatValue: 1.00];
3953 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
3955 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3957 [fAudTrack3RatePopUp setEnabled: NO];
3958 [fAudTrack3BitratePopUp setEnabled: NO];
3959 [fAudTrack3DrcSlider setEnabled: NO];
3960 [fAudTrack3DrcField setEnabled: NO];
3963 /* enable/disable the mixdown text and popupbutton for audio track 4 */
3964 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3965 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3966 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3967 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3968 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3969 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3970 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
3972 [fAudTrack4CodecPopUp removeAllItems];
3973 [fAudTrack4MixPopUp removeAllItems];
3974 [fAudTrack4RatePopUp removeAllItems];
3975 [fAudTrack4BitratePopUp removeAllItems];
3976 [fAudTrack4DrcSlider setFloatValue: 1.00];
3977 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
3979 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3981 [fAudTrack4RatePopUp setEnabled: NO];
3982 [fAudTrack4BitratePopUp setEnabled: NO];
3983 [fAudTrack4DrcSlider setEnabled: NO];
3984 [fAudTrack4DrcField setEnabled: NO];
3989 - (IBAction) addAllAudioTracksToPopUp: (id) sender
3992 hb_list_t * list = hb_get_titles( fHandle );
3993 hb_title_t * title = (hb_title_t*)
3994 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3996 hb_audio_config_t * audio;
3998 [sender removeAllItems];
3999 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
4000 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
4002 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
4003 [[sender menu] addItemWithTitle:
4004 [NSString stringWithCString: audio->lang.description]
4005 action: NULL keyEquivalent: @""];
4007 [sender selectItemAtIndex: 0];
4011 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
4014 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
4015 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
4016 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
4017 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
4019 if (searchPrefixString)
4022 for( int i = 0; i < [sender numberOfItems]; i++ )
4024 /* Try to find the desired search string */
4025 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
4027 [sender selectItemAtIndex: i];
4031 /* couldn't find the string, so select the requested "search string not found" item */
4032 /* index of 0 means select the "none" item */
4033 /* index of 1 means select the first audio track */
4034 [sender selectItemAtIndex: selectIndexIfNotFound];
4038 /* if no search string is provided, then select the selectIndexIfNotFound item */
4039 [sender selectItemAtIndex: selectIndexIfNotFound];
4043 - (IBAction) audioAddAudioTrackCodecs: (id)sender
4045 int format = [fDstFormatPopUp indexOfSelectedItem];
4047 /* setup pointers to the appropriate popups for the correct track */
4048 NSPopUpButton * audiocodecPopUp;
4049 NSPopUpButton * audiotrackPopUp;
4050 if (sender == fAudTrack1CodecPopUp)
4052 audiotrackPopUp = fAudLang1PopUp;
4053 audiocodecPopUp = fAudTrack1CodecPopUp;
4055 else if (sender == fAudTrack2CodecPopUp)
4057 audiotrackPopUp = fAudLang2PopUp;
4058 audiocodecPopUp = fAudTrack2CodecPopUp;
4060 else if (sender == fAudTrack3CodecPopUp)
4062 audiotrackPopUp = fAudLang3PopUp;
4063 audiocodecPopUp = fAudTrack3CodecPopUp;
4067 audiotrackPopUp = fAudLang4PopUp;
4068 audiocodecPopUp = fAudTrack4CodecPopUp;
4071 [audiocodecPopUp removeAllItems];
4072 /* Make sure "None" isnt selected in the source track */
4073 if ([audiotrackPopUp indexOfSelectedItem] > 0)
4075 [audiocodecPopUp setEnabled:YES];
4076 NSMenuItem *menuItem;
4077 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
4083 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4084 [menuItem setTag: HB_ACODEC_FAAC];
4087 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4088 [menuItem setTag: HB_ACODEC_AC3];
4094 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4095 [menuItem setTag: HB_ACODEC_FAAC];
4097 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4098 [menuItem setTag: HB_ACODEC_AC3];
4100 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4101 [menuItem setTag: HB_ACODEC_LAME];
4103 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4104 [menuItem setTag: HB_ACODEC_VORBIS];
4110 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4111 [menuItem setTag: HB_ACODEC_LAME];
4113 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4114 [menuItem setTag: HB_ACODEC_AC3];
4120 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4121 [menuItem setTag: HB_ACODEC_VORBIS];
4123 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4124 [menuItem setTag: HB_ACODEC_LAME];
4127 [audiocodecPopUp selectItemAtIndex:0];
4131 [audiocodecPopUp setEnabled:NO];
4135 - (IBAction) audioTrackPopUpChanged: (id) sender
4137 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
4138 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
4141 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
4144 /* make sure we have a selected title before continuing */
4145 if (fTitle == NULL) return;
4146 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
4147 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
4149 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
4151 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4153 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
4155 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4157 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
4159 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4161 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
4163 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4166 /* Now lets make the sender the appropriate Audio Track popup from this point on */
4167 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
4169 sender = fAudLang1PopUp;
4171 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
4173 sender = fAudLang2PopUp;
4175 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
4177 sender = fAudLang3PopUp;
4179 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
4181 sender = fAudLang4PopUp;
4184 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
4185 NSPopUpButton * mixdownPopUp;
4186 NSPopUpButton * audiocodecPopUp;
4187 NSPopUpButton * sampleratePopUp;
4188 NSPopUpButton * bitratePopUp;
4189 if (sender == fAudLang1PopUp)
4191 mixdownPopUp = fAudTrack1MixPopUp;
4192 audiocodecPopUp = fAudTrack1CodecPopUp;
4193 sampleratePopUp = fAudTrack1RatePopUp;
4194 bitratePopUp = fAudTrack1BitratePopUp;
4196 else if (sender == fAudLang2PopUp)
4198 mixdownPopUp = fAudTrack2MixPopUp;
4199 audiocodecPopUp = fAudTrack2CodecPopUp;
4200 sampleratePopUp = fAudTrack2RatePopUp;
4201 bitratePopUp = fAudTrack2BitratePopUp;
4203 else if (sender == fAudLang3PopUp)
4205 mixdownPopUp = fAudTrack3MixPopUp;
4206 audiocodecPopUp = fAudTrack3CodecPopUp;
4207 sampleratePopUp = fAudTrack3RatePopUp;
4208 bitratePopUp = fAudTrack3BitratePopUp;
4212 mixdownPopUp = fAudTrack4MixPopUp;
4213 audiocodecPopUp = fAudTrack4CodecPopUp;
4214 sampleratePopUp = fAudTrack4RatePopUp;
4215 bitratePopUp = fAudTrack4BitratePopUp;
4218 /* get the index of the selected audio Track*/
4219 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
4221 /* pointer for the hb_audio_s struct we will use later on */
4222 hb_audio_config_t * audio;
4225 /* check if the audio mixdown controls need their enabled state changing */
4226 [self setEnabledStateOfAudioMixdownControls:nil];
4228 if (thisAudioIndex != -1)
4232 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
4234 /* actually manipulate the proper mixdowns here */
4235 /* delete the previous audio mixdown options */
4236 [mixdownPopUp removeAllItems];
4238 acodec = [[audiocodecPopUp selectedItem] tag];
4243 /* find out if our selected output audio codec supports mono and / or 6ch */
4244 /* we also check for an input codec of AC3 or DCA,
4245 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
4246 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
4247 but this may change in the future, so they are separated for flexibility */
4248 int audioCodecsSupportMono =
4249 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4250 (acodec != HB_ACODEC_LAME);
4251 int audioCodecsSupport6Ch =
4252 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4253 (acodec != HB_ACODEC_LAME);
4255 /* check for AC-3 passthru */
4256 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4259 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4260 [NSString stringWithCString: "AC3 Passthru"]
4261 action: NULL keyEquivalent: @""];
4262 [menuItem setTag: HB_ACODEC_AC3];
4267 /* add the appropriate audio mixdown menuitems to the popupbutton */
4268 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
4269 so that we can reference the mixdown later */
4271 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
4272 int minMixdownUsed = 0;
4273 int maxMixdownUsed = 0;
4275 /* get the input channel layout without any lfe channels */
4276 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4278 /* do we want to add a mono option? */
4279 if (audioCodecsSupportMono == 1)
4281 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4282 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
4283 action: NULL keyEquivalent: @""];
4284 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
4285 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
4286 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
4289 /* do we want to add a stereo option? */
4290 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
4291 /* also offer stereo if we have a stereo-or-better source */
4292 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
4294 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4295 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
4296 action: NULL keyEquivalent: @""];
4297 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
4298 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
4299 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
4302 /* do we want to add a dolby surround (DPL1) option? */
4303 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
4305 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4306 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
4307 action: NULL keyEquivalent: @""];
4308 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
4309 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
4310 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
4313 /* do we want to add a dolby pro logic 2 (DPL2) option? */
4314 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
4316 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4317 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
4318 action: NULL keyEquivalent: @""];
4319 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
4320 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
4321 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
4324 /* do we want to add a 6-channel discrete option? */
4325 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
4327 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4328 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
4329 action: NULL keyEquivalent: @""];
4330 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
4331 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
4332 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
4335 /* do we want to add an AC-3 passthrough option? */
4336 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4338 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4339 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
4340 action: NULL keyEquivalent: @""];
4341 [menuItem setTag: HB_ACODEC_AC3];
4342 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
4343 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
4346 /* auto-select the best mixdown based on our saved mixdown preference */
4348 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
4349 /* ultimately this should be a prefs option */
4352 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
4353 if (mixdownToUse > 0)
4355 useMixdown = mixdownToUse;
4359 useMixdown = HB_AMIXDOWN_DOLBYPLII;
4362 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
4363 if (useMixdown > maxMixdownUsed)
4365 useMixdown = maxMixdownUsed;
4368 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
4369 if (useMixdown < minMixdownUsed)
4371 useMixdown = minMixdownUsed;
4374 /* select the (possibly-amended) preferred mixdown */
4375 [mixdownPopUp selectItemWithTag: useMixdown];
4378 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
4379 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
4382 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
4384 /* If we are using the avi container, we select MP3 as there is no aac available*/
4385 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
4387 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
4391 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
4394 /* Setup our samplerate and bitrate popups we will need based on mixdown */
4395 [self audioTrackMixdownChanged: mixdownPopUp];
4399 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
4401 [self autoSetM4vExtension: sender];
4402 [self shouldEnableHttpMp4CheckBox: sender];
4406 - (IBAction) audioTrackMixdownChanged: (id) sender
4410 /* setup pointers to all of the other audio track controls
4411 * we will need later
4413 NSPopUpButton * mixdownPopUp;
4414 NSPopUpButton * sampleratePopUp;
4415 NSPopUpButton * bitratePopUp;
4416 NSPopUpButton * audiocodecPopUp;
4417 NSPopUpButton * audiotrackPopUp;
4418 NSSlider * drcSlider;
4419 NSTextField * drcField;
4420 if (sender == fAudTrack1MixPopUp)
4422 audiotrackPopUp = fAudLang1PopUp;
4423 audiocodecPopUp = fAudTrack1CodecPopUp;
4424 mixdownPopUp = fAudTrack1MixPopUp;
4425 sampleratePopUp = fAudTrack1RatePopUp;
4426 bitratePopUp = fAudTrack1BitratePopUp;
4427 drcSlider = fAudTrack1DrcSlider;
4428 drcField = fAudTrack1DrcField;
4430 else if (sender == fAudTrack2MixPopUp)
4432 audiotrackPopUp = fAudLang2PopUp;
4433 audiocodecPopUp = fAudTrack2CodecPopUp;
4434 mixdownPopUp = fAudTrack2MixPopUp;
4435 sampleratePopUp = fAudTrack2RatePopUp;
4436 bitratePopUp = fAudTrack2BitratePopUp;
4437 drcSlider = fAudTrack2DrcSlider;
4438 drcField = fAudTrack2DrcField;
4440 else if (sender == fAudTrack3MixPopUp)
4442 audiotrackPopUp = fAudLang3PopUp;
4443 audiocodecPopUp = fAudTrack3CodecPopUp;
4444 mixdownPopUp = fAudTrack3MixPopUp;
4445 sampleratePopUp = fAudTrack3RatePopUp;
4446 bitratePopUp = fAudTrack3BitratePopUp;
4447 drcSlider = fAudTrack3DrcSlider;
4448 drcField = fAudTrack3DrcField;
4452 audiotrackPopUp = fAudLang4PopUp;
4453 audiocodecPopUp = fAudTrack4CodecPopUp;
4454 mixdownPopUp = fAudTrack4MixPopUp;
4455 sampleratePopUp = fAudTrack4RatePopUp;
4456 bitratePopUp = fAudTrack4BitratePopUp;
4457 drcSlider = fAudTrack4DrcSlider;
4458 drcField = fAudTrack4DrcField;
4460 acodec = [[audiocodecPopUp selectedItem] tag];
4461 /* storage variable for the min and max bitrate allowed for this codec */
4467 case HB_ACODEC_FAAC:
4468 /* check if we have a 6ch discrete conversion in either audio track */
4469 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4471 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
4473 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4479 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
4481 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
4482 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
4487 case HB_ACODEC_LAME:
4488 /* Lame is happy using our min bitrate of 32 kbps */
4490 /* Lame won't encode if the bitrate is higher than 320 kbps */
4494 case HB_ACODEC_VORBIS:
4495 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4497 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
4499 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4505 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
4507 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
4513 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
4519 /* make sure we have a selected title before continuing */
4520 if (fTitle == NULL) return;
4521 /* get the audio so we can find out what input rates are*/
4522 hb_audio_config_t * audio;
4523 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
4524 int inputbitrate = audio->in.bitrate / 1000;
4525 int inputsamplerate = audio->in.samplerate;
4527 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3)
4529 [bitratePopUp removeAllItems];
4531 for( int i = 0; i < hb_audio_bitrates_count; i++ )
4533 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
4535 /* add a new menuitem for this bitrate */
4536 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4537 [NSString stringWithCString: hb_audio_bitrates[i].string]
4538 action: NULL keyEquivalent: @""];
4539 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
4540 [menuItem setTag: hb_audio_bitrates[i].rate];
4544 /* select the default bitrate (but use 384 for 6-ch AAC) */
4545 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4547 [bitratePopUp selectItemWithTag: 384];
4551 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
4554 /* populate and set the sample rate popup */
4555 /* Audio samplerate */
4556 [sampleratePopUp removeAllItems];
4557 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
4558 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
4559 [menuItem setTag: inputsamplerate];
4561 for( int i = 0; i < hb_audio_rates_count; i++ )
4563 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
4564 [NSString stringWithCString: hb_audio_rates[i].string]
4565 action: NULL keyEquivalent: @""];
4566 [menuItem setTag: hb_audio_rates[i].rate];
4568 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
4569 * and there is no compelling reason to use anything else as default, though the users default
4570 * preset will likely override any setting chosen here.
4572 [sampleratePopUp selectItemWithTag: inputsamplerate];
4575 /* Since AC3 Pass Thru uses the input ac3 bitrate and sample rate, we get the input tracks
4576 * bitrate and dispay it in the bitrate popup even though libhb happily ignores any bitrate input from
4577 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
4579 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3)
4582 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
4583 [bitratePopUp removeAllItems];
4584 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4585 [NSString stringWithFormat:@"%d", inputbitrate]
4586 action: NULL keyEquivalent: @""];
4587 [menuItem setTag: inputbitrate];
4588 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
4589 [bitratePopUp setEnabled: NO];
4590 [sampleratePopUp setEnabled: NO];
4592 [drcSlider setFloatValue: 1.00];
4593 [self audioDRCSliderChanged: drcSlider];
4594 [drcSlider setEnabled: NO];
4595 [drcField setEnabled: NO];
4599 [sampleratePopUp setEnabled: YES];
4600 [bitratePopUp setEnabled: YES];
4601 [drcSlider setEnabled: YES];
4602 [drcField setEnabled: YES];
4607 - (IBAction) audioDRCSliderChanged: (id) sender
4609 NSSlider * drcSlider;
4610 NSTextField * drcField;
4611 if (sender == fAudTrack1DrcSlider)
4613 drcSlider = fAudTrack1DrcSlider;
4614 drcField = fAudTrack1DrcField;
4616 else if (sender == fAudTrack2DrcSlider)
4618 drcSlider = fAudTrack2DrcSlider;
4619 drcField = fAudTrack2DrcField;
4621 else if (sender == fAudTrack3DrcSlider)
4623 drcSlider = fAudTrack3DrcSlider;
4624 drcField = fAudTrack3DrcField;
4628 drcSlider = fAudTrack4DrcSlider;
4629 drcField = fAudTrack4DrcField;
4631 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
4632 /* For now, do not call this until we have an intelligent way to determine audio track selections
4633 * compared to presets
4635 //[self customSettingUsed: sender];
4638 - (IBAction) subtitleSelectionChanged: (id) sender
4640 if ([fSubPopUp indexOfSelectedItem] == 0)
4642 [fSubForcedCheck setState: NSOffState];
4643 [fSubForcedCheck setEnabled: NO];
4647 [fSubForcedCheck setEnabled: YES];
4656 #pragma mark Open New Windows
4658 - (IBAction) openHomepage: (id) sender
4660 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4661 URLWithString:@"http://handbrake.fr/"]];
4664 - (IBAction) openForums: (id) sender
4666 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4667 URLWithString:@"http://handbrake.fr/forum/"]];
4669 - (IBAction) openUserGuide: (id) sender
4671 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4672 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
4676 * Shows debug output window.
4678 - (IBAction)showDebugOutputPanel:(id)sender
4680 [outputPanel showOutputPanel:sender];
4684 * Shows preferences window.
4686 - (IBAction) showPreferencesWindow: (id) sender
4688 NSWindow * window = [fPreferencesController window];
4689 if (![window isVisible])
4692 [window makeKeyAndOrderFront: nil];
4696 * Shows queue window.
4698 - (IBAction) showQueueWindow:(id)sender
4700 [fQueueController showQueueWindow:sender];
4704 - (IBAction) toggleDrawer:(id)sender {
4705 [fPresetDrawer toggle:self];
4709 * Shows Picture Settings Window.
4712 - (IBAction) showPicturePanel: (id) sender
4714 hb_list_t * list = hb_get_titles( fHandle );
4715 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4716 [fSrcTitlePopUp indexOfSelectedItem] );
4717 [fPictureController showPanelInWindow:fWindow forTitle:title];
4721 #pragma mark Preset Outline View Methods
4722 #pragma mark - Required
4723 /* These are required by the NSOutlineView Datasource Delegate */
4724 /* We use this to deterimine children of an item */
4725 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
4728 return [UserPresets objectAtIndex:index];
4730 // We are only one level deep, so we can't be asked about children
4731 NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
4734 /* We use this to determine if an item should be expandable */
4735 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
4738 /* For now, we maintain one level, so set to no
4739 * when nested, we set to yes for any preset "folders"
4744 /* used to specify the number of levels to show for each item */
4745 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
4747 /* currently use no levels to test outline view viability */
4749 return [UserPresets count];
4753 /* Used to tell the outline view which information is to be displayed per item */
4754 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4756 /* We have two columns right now, icon and PresetName */
4758 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4760 return [item objectForKey:@"PresetName"];
4764 return @"something";
4768 #pragma mark - Added Functionality (optional)
4769 /* Use to customize the font and display characteristics of the title cell */
4770 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
4772 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4774 NSDictionary *userPresetDict = item;
4777 NSColor *shadowColor;
4778 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4779 /*check to see if its a selected row */
4780 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
4783 fontColor = [NSColor blackColor];
4784 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4788 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4790 fontColor = [NSColor blueColor];
4792 else // User created preset, use a black font
4794 fontColor = [NSColor blackColor];
4798 /* We use Bold Text for the HB Default */
4799 if ([[userPresetDict objectForKey:@"Default"] intValue] == 1)// 1 is HB default
4801 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4803 /* We use Bold Text for the User Specified Default */
4804 if ([[userPresetDict objectForKey:@"Default"] intValue] == 2)// 2 is User default
4806 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4810 [cell setTextColor:fontColor];
4811 [cell setFont:txtFont];
4816 /* We use this to edit the name field in the outline view */
4817 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4819 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4824 [theRecord setObject:object forKey:@"PresetName"];
4828 [fPresetsOutlineView reloadData];
4829 /* We save all of the preset data here */
4833 /* We use this to provide tooltips for the items in the presets outline view */
4834 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
4836 //if ([[tc identifier] isEqualToString:@"PresetName"])
4838 /* initialize the tooltip contents variable */
4840 /* if there is a description for the preset, we show it in the tooltip */
4841 if ([item objectForKey:@"PresetDescription"])
4843 loc_tip = [item objectForKey:@"PresetDescription"];
4848 loc_tip = @"No description available";
4855 #pragma mark Preset Outline View Methods (dragging related)
4858 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
4860 // Dragging is only allowed for custom presets.
4861 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
4865 // Don't retain since this is just holding temporaral drag information, and it is
4866 //only used during a drag! We could put this in the pboard actually.
4867 fDraggedNodes = items;
4868 // Provide data for our custom type, and simple NSStrings.
4869 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
4871 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
4872 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
4877 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
4879 // Don't allow dropping ONTO an item since they can't really contain any children.
4881 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
4882 if (isOnDropTypeProposal)
4883 return NSDragOperationNone;
4886 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
4890 index = [fPresetsOutlineView rowForItem: item] + 1;
4894 // Don't allow dropping into the Built In Presets.
4895 if (index < presetCurrentBuiltInCount)
4897 return NSDragOperationNone;
4898 index = MAX (index, presetCurrentBuiltInCount);
4901 [outlineView setDropItem:item dropChildIndex:index];
4902 return NSDragOperationGeneric;
4907 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
4909 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
4912 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
4913 while (obj = [enumerator nextObject])
4915 [moveItems addIndex:[UserPresets indexOfObject:obj]];
4917 // Successful drop, lets rearrange the view and save it all
4918 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
4919 [fPresetsOutlineView reloadData];
4924 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
4926 unsigned index = [indexSet lastIndex];
4927 unsigned aboveInsertIndexCount = 0;
4929 while (index != NSNotFound)
4931 unsigned removeIndex;
4933 if (index >= insertIndex)
4935 removeIndex = index + aboveInsertIndexCount;
4936 aboveInsertIndexCount++;
4940 removeIndex = index;
4944 id object = [[array objectAtIndex:removeIndex] retain];
4945 [array removeObjectAtIndex:removeIndex];
4946 [array insertObject:object atIndex:insertIndex];
4949 index = [indexSet indexLessThanIndex:index];
4955 #pragma mark - Functional Preset NSOutlineView Methods
4957 - (IBAction)selectPreset:(id)sender
4960 if ([fPresetsOutlineView selectedRow] >= 0)
4962 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
4963 /* we set the preset display field in main window here */
4964 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4965 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4967 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
4971 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4974 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
4975 [self formatPopUpChanged:nil];
4977 /* Chapter Markers*/
4978 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4979 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4980 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4981 /* Mux mp4 with http optimization */
4982 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
4985 /* We set the advanced opt string here if applicable*/
4986 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
4987 /* We use a conditional to account for the new x264 encoder dropdown as well as presets made using legacy x264 settings*/
4988 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 Main)"] ||
4989 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"] ||
4990 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264"])
4992 [fVidEncoderPopUp selectItemWithTitle:@"H.264 (x264)"];
4993 /* special case for legacy preset to check the new fDstMp4HttpOptFileCheck checkbox to set the ipod atom */
4994 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"])
4996 [fDstMp4iPodFileCheck setState:NSOnState];
4997 /* We also need to add "level=30:" to the advanced opts string to set the correct level for the iPod when
4998 encountering a legacy preset as it used to be handled separately from the opt string*/
4999 [fAdvancedOptions setOptions:[@"level=30:" stringByAppendingString:[fAdvancedOptions optionsString]]];
5003 [fDstMp4iPodFileCheck setState:NSOffState];
5006 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"FFmpeg"])
5008 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (FFmpeg)"];
5010 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"XviD"])
5012 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (XviD)"];
5016 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
5019 /* Lets run through the following functions to get variables set there */
5020 [self videoEncoderPopUpChanged:nil];
5021 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
5022 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
5023 [self calculateBitrate:nil];
5026 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
5028 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
5029 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
5030 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
5032 [self videoMatrixChanged:nil];
5034 /* Video framerate */
5035 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
5036 detected framerate in the fVidRatePopUp so we use index 0*/
5037 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
5039 [fVidRatePopUp selectItemAtIndex: 0];
5043 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
5047 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
5049 /* 2 Pass Encoding */
5050 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
5051 [self twoPassCheckboxChanged:nil];
5052 /* Turbo 1st pass for 2 Pass Encoding */
5053 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
5056 if ([chosenPreset objectForKey:@"FileCodecs"])
5058 /* We need to handle the audio codec popup by determining what was chosen from the deprecated Codecs PopUp for past presets*/
5059 if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString: @"AVC/H.264 Video / AAC + AC3 Audio"])
5061 /* We need to address setting languages etc. here in the new multi track audio panel */
5062 /* Track One set here */
5063 /*for track one though a track should be selected but lets check here anyway and use track one if its not.*/
5064 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5066 [fAudLang1PopUp selectItemAtIndex: 1];
5067 [self audioTrackPopUpChanged: fAudLang1PopUp];
5069 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5070 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5071 /* Track Two, set source same as track one */
5072 [fAudLang2PopUp selectItemAtIndex: [fAudLang1PopUp indexOfSelectedItem]];
5073 [self audioTrackPopUpChanged: fAudLang2PopUp];
5074 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5075 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5077 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AAC Audio"] ||
5078 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC Audio"])
5080 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5082 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5083 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5085 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5087 [fAudTrack2CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5088 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5090 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5092 [fAudTrack3CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5093 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5095 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5097 [fAudTrack4CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5098 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5101 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AC-3 Audio"] ||
5102 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AC-3 Audio"])
5104 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5106 [fAudTrack1CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5107 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5109 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5111 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5112 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5114 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5116 [fAudTrack3CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5117 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5119 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5121 [fAudTrack4CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5122 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5125 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / MP3 Audio"] ||
5126 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / MP3 Audio"])
5128 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5130 [fAudTrack1CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5131 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5133 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5135 [fAudTrack2CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5136 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5138 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5140 [fAudTrack3CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5141 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5143 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5145 [fAudTrack4CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5146 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5149 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / Vorbis Audio"])
5151 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5153 [fAudTrack1CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5154 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5156 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5158 [fAudTrack2CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5159 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5161 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5163 [fAudTrack3CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5164 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5166 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5168 [fAudTrack4CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5169 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5172 /* We detect here if we have the old audio sample rate and if so we apply samplerate and bitrate to the existing four tracks if chosen
5173 * UNLESS the CodecPopUp is AC3 in which case the preset values are ignored in favor of rates set in audioTrackMixdownChanged*/
5174 if ([chosenPreset objectForKey:@"AudioSampleRate"])
5176 if ([fAudLang1PopUp indexOfSelectedItem] > 0 && [fAudTrack1CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5178 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5179 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5181 if ([fAudLang2PopUp indexOfSelectedItem] > 0 && [fAudTrack2CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5183 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5184 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5186 if ([fAudLang3PopUp indexOfSelectedItem] > 0 && [fAudTrack3CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5188 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5189 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5191 if ([fAudLang4PopUp indexOfSelectedItem] > 0 && [fAudTrack4CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5193 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5194 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5197 /* We detect here if we have the old DRC Slider and if so we apply it to the existing four tracks if chosen */
5198 if ([chosenPreset objectForKey:@"AudioDRCSlider"])
5200 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5202 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5203 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5205 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5207 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5208 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5210 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5212 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5213 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5215 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5217 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5218 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5222 else // since there was no codecs key in the preset we know we can use new multi-audio track presets
5224 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
5226 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5228 [fAudLang1PopUp selectItemAtIndex: 1];
5230 [self audioTrackPopUpChanged: fAudLang1PopUp];
5231 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
5232 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5233 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
5234 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5236 if ([fAudTrack1MixPopUp selectedItem] == nil)
5238 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5240 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
5241 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5242 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
5244 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
5246 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
5247 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5249 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
5251 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5253 [fAudLang2PopUp selectItemAtIndex: 1];
5255 [self audioTrackPopUpChanged: fAudLang2PopUp];
5256 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
5257 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5258 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
5259 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5261 if ([fAudTrack2MixPopUp selectedItem] == nil)
5263 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5265 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
5266 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5267 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
5269 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
5271 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
5272 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5274 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
5276 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5278 [fAudLang3PopUp selectItemAtIndex: 1];
5280 [self audioTrackPopUpChanged: fAudLang3PopUp];
5281 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
5282 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5283 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
5284 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5286 if ([fAudTrack3MixPopUp selectedItem] == nil)
5288 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5290 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
5291 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5292 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
5294 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
5296 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
5297 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5299 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
5301 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
5303 [fAudLang4PopUp selectItemAtIndex: 1];
5305 [self audioTrackPopUpChanged: fAudLang4PopUp];
5306 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
5307 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5308 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
5309 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5311 if ([fAudTrack4MixPopUp selectedItem] == nil)
5313 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5315 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
5316 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5317 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
5319 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
5321 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
5322 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5328 /* We now cleanup any extra audio tracks that may be previously set if we need to, we do it here so we don't have to
5329 * duplicate any code for legacy presets.*/
5330 /* First we handle the legacy Codecs crazy AVC/H.264 Video / AAC + AC3 Audio atv hybrid */
5331 if ([chosenPreset objectForKey:@"FileCodecs"] && [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC + AC3 Audio"])
5333 [fAudLang3PopUp selectItemAtIndex: 0];
5334 [self audioTrackPopUpChanged: fAudLang3PopUp];
5335 [fAudLang4PopUp selectItemAtIndex: 0];
5336 [self audioTrackPopUpChanged: fAudLang4PopUp];
5340 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
5342 [fAudLang2PopUp selectItemAtIndex: 0];
5343 [self audioTrackPopUpChanged: fAudLang2PopUp];
5345 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
5347 [fAudLang3PopUp selectItemAtIndex: 0];
5348 [self audioTrackPopUpChanged: fAudLang3PopUp];
5350 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
5352 [fAudLang4PopUp selectItemAtIndex: 0];
5353 [self audioTrackPopUpChanged: fAudLang4PopUp];
5358 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
5359 /* Forced Subtitles */
5360 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
5362 /* Picture Settings */
5363 /* Note: objectForKey:@"UsesPictureSettings" now refers to picture size, this encompasses:
5364 * height, width, keep ar, anamorphic and crop settings.
5365 * picture filters are now handled separately.
5366 * We will be able to actually change the key names for legacy preset keys when preset file
5367 * update code is done. But for now, lets hang onto the old legacy key name for backwards compatibility.
5369 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
5370 * and the preset completely ignores any picture sizing values in the preset.
5372 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
5374 hb_job_t * job = fTitle->job;
5375 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
5376 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
5378 /* Use Max Picture settings for whatever the dvd is.*/
5379 [self revertPictureSizeToMax:nil];
5380 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5381 if (job->keep_ratio == 1)
5383 hb_fix_aspect( job, HB_KEEP_WIDTH );
5384 if( job->height > fTitle->height )
5386 job->height = fTitle->height;
5387 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5390 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5392 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
5394 /* we check to make sure the presets width/height does not exceed the sources width/height */
5395 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
5397 /* if so, then we use the sources height and width to avoid scaling up */
5398 job->width = fTitle->width;
5399 job->height = fTitle->height;
5401 else // source width/height is >= the preset height/width
5403 /* we can go ahead and use the presets values for height and width */
5404 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
5405 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
5407 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5408 if (job->keep_ratio == 1)
5410 hb_fix_aspect( job, HB_KEEP_WIDTH );
5411 if( job->height > fTitle->height )
5413 job->height = fTitle->height;
5414 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5417 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5420 /* If Cropping is set to custom, then recall all four crop values from
5421 when the preset was created and apply them */
5422 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
5424 [fPictureController setAutoCrop:NO];
5426 /* Here we use the custom crop values saved at the time the preset was saved */
5427 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
5428 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
5429 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
5430 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
5433 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
5435 [fPictureController setAutoCrop:YES];
5436 /* Here we use the auto crop values determined right after scan */
5437 job->crop[0] = AutoCropTop;
5438 job->crop[1] = AutoCropBottom;
5439 job->crop[2] = AutoCropLeft;
5440 job->crop[3] = AutoCropRight;
5443 /* If the preset has no objectForKey:@"UsesPictureFilters", then we know it is a legacy preset
5444 * and handle the filters here as before.
5445 * NOTE: This should be removed when the update presets code is done as we can be assured that legacy
5446 * presets are updated to work properly with new keys.
5448 if (![chosenPreset objectForKey:@"UsesPictureFilters"])
5452 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5454 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5455 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5456 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5458 [fPictureController setDeinterlace:3];
5463 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5468 [fPictureController setDeinterlace:0];
5471 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5473 // We make sure that framerate is set to Same as source variable
5474 // detelecine will take care of itself right below
5475 //[fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5479 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5481 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5485 [fPictureController setDetelecine:0];
5488 if ([chosenPreset objectForKey:@"PictureDenoise"])
5490 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5494 [fPictureController setDenoise:0];
5497 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5499 /* since we used to use 1 to turn on deblock, we now use a 5 in our sliding scale */
5500 [fPictureController setDeblock:5];
5504 [fPictureController setDeblock:0];
5508 [self calculatePictureSizing:nil];
5515 /* If the preset has an objectForKey:@"UsesPictureFilters", then we know it is a newer style filters preset
5516 * and handle the filters here depending on whether or not the preset specifies applying the filter.
5518 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
5522 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5524 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5525 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5526 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5528 [fPictureController setDeinterlace:3];
5532 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5537 [fPictureController setDeinterlace:0];
5541 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5543 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5547 [fPictureController setDetelecine:0];
5550 if ([chosenPreset objectForKey:@"PictureDenoise"])
5552 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5556 [fPictureController setDenoise:0];
5559 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5561 /* if its a one, then its the old on/off deblock, set on to 5*/
5562 [fPictureController setDeblock:5];
5566 /* use the settings intValue */
5567 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
5570 /* Even though we currently allow for a custom setting for decomb, ultimately it will only have Off and
5571 * Default so we just pay attention to anything greater than 0 as 1 (Default). 0 is Off. */
5572 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
5574 [fPictureController setDecomb:1];
5578 [fPictureController setDecomb:0];
5581 [self calculatePictureSizing:nil];
5587 #pragma mark Manage Presets
5589 - (void) loadPresets {
5590 /* We declare the default NSFileManager into fileManager */
5591 NSFileManager * fileManager = [NSFileManager defaultManager];
5592 /*We define the location of the user presets file */
5593 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
5594 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
5595 /* We check for the presets.plist */
5596 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
5598 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
5601 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
5602 if (nil == UserPresets)
5604 UserPresets = [[NSMutableArray alloc] init];
5605 [self addFactoryPresets:nil];
5607 [fPresetsOutlineView reloadData];
5611 - (IBAction) showAddPresetPanel: (id) sender
5613 /* Deselect the currently selected Preset if there is one*/
5614 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
5616 /* Populate the preset picture settings popup here */
5617 [fPresetNewPicSettingsPopUp removeAllItems];
5618 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
5619 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
5620 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
5621 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
5622 /* Uncheck the preset use filters checkbox */
5623 [fPresetNewPicFiltersCheck setState:NSOffState];
5624 /* Erase info from the input fields*/
5625 [fPresetNewName setStringValue: @""];
5626 [fPresetNewDesc setStringValue: @""];
5627 /* Show the panel */
5628 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
5631 - (IBAction) closeAddPresetPanel: (id) sender
5633 [NSApp endSheet: fAddPresetPanel];
5634 [fAddPresetPanel orderOut: self];
5637 - (IBAction)addUserPreset:(id)sender
5639 if (![[fPresetNewName stringValue] length])
5640 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
5643 /* Here we create a custom user preset */
5644 [UserPresets addObject:[self createPreset]];
5647 [self closeAddPresetPanel:nil];
5654 /* We Reload the New Table data for presets */
5655 [fPresetsOutlineView reloadData];
5656 /* We save all of the preset data here */
5664 /* We Sort the Presets By Factory or Custom */
5665 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
5666 ascending:YES] autorelease];
5667 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
5669 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
5670 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
5671 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
5674 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
5675 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
5676 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
5677 [UserPresets setArray:sortedArray];
5682 - (IBAction)insertPreset:(id)sender
5684 int index = [fPresetsOutlineView selectedRow];
5685 [UserPresets insertObject:[self createPreset] atIndex:index];
5686 [fPresetsOutlineView reloadData];
5690 - (NSDictionary *)createPreset
5692 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
5693 /* Get the New Preset Name from the field in the AddPresetPanel */
5694 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
5695 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
5696 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
5697 /*Set whether or not this is default, at creation set to 0*/
5698 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5699 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
5700 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
5701 /* Get whether or not to use the current Picture Filter settings for the preset */
5702 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
5704 /* Get New Preset Description from the field in the AddPresetPanel*/
5705 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
5707 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
5708 /* Chapter Markers fCreateChapterMarkers*/
5709 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
5710 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
5711 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
5712 /* Mux mp4 with http optimization */
5713 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
5714 /* Add iPod uuid atom */
5715 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
5719 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
5720 /* x264 Option String */
5721 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
5723 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
5724 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
5725 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
5726 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
5728 /* Video framerate */
5729 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
5731 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
5733 else // we can record the actual titleOfSelectedItem
5735 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
5738 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
5739 /* 2 Pass Encoding */
5740 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
5741 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
5742 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
5743 /*Picture Settings*/
5744 hb_job_t * job = fTitle->job;
5745 /* Picture Sizing */
5746 /* Use Max Picture settings for whatever the dvd is.*/
5747 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
5748 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
5749 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
5750 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
5751 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
5753 /* Set crop settings here */
5754 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
5755 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
5756 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
5757 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
5758 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
5760 /* Picture Filters */
5761 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
5762 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
5763 //[preset setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
5764 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
5765 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
5766 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
5770 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5772 [preset setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
5773 [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
5774 [preset setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
5775 [preset setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
5776 [preset setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
5777 [preset setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
5778 [preset setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
5780 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5782 [preset setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
5783 [preset setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
5784 [preset setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
5785 [preset setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
5786 [preset setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
5787 [preset setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
5788 [preset setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
5790 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5792 [preset setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
5793 [preset setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
5794 [preset setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
5795 [preset setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
5796 [preset setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
5797 [preset setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
5798 [preset setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
5800 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5802 [preset setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
5803 [preset setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
5804 [preset setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
5805 [preset setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
5806 [preset setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
5807 [preset setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
5808 [preset setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
5812 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
5813 /* Forced Subtitles */
5814 [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
5816 [preset autorelease];
5823 [UserPresets writeToFile:UserPresetsFile atomically:YES];
5824 /* We get the default preset in case it changed */
5825 [self getDefaultPresets:nil];
5829 - (IBAction)deletePreset:(id)sender
5832 NSEnumerator *enumerator;
5834 NSMutableArray *tempArray;
5837 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
5839 /* Alert user before deleting preset */
5840 /* Comment out for now, tie to user pref eventually */
5843 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
5845 if ( status == NSAlertDefaultReturn ) {
5846 enumerator = [fPresetsOutlineView selectedRowEnumerator];
5847 tempArray = [NSMutableArray array];
5849 while ( (index = [enumerator nextObject]) ) {
5850 tempObject = [UserPresets objectAtIndex:[index intValue]];
5851 [tempArray addObject:tempObject];
5854 [UserPresets removeObjectsInArray:tempArray];
5855 [fPresetsOutlineView reloadData];
5861 #pragma mark Manage Default Preset
5863 - (IBAction)getDefaultPresets:(id)sender
5866 presetCurrentBuiltInCount = 0;
5867 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5869 while (tempObject = [enumerator nextObject])
5871 NSDictionary *thisPresetDict = tempObject;
5872 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
5874 presetHbDefault = i;
5876 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
5878 presetUserDefault = i;
5880 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
5882 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
5888 - (IBAction)setDefaultPreset:(id)sender
5891 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5893 /* First make sure the old user specified default preset is removed */
5894 while (tempObject = [enumerator nextObject])
5896 /* make sure we are not removing the default HB preset */
5897 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5899 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5903 /* Second, go ahead and set the appropriate user specfied preset */
5904 /* we get the chosen preset from the UserPresets array */
5905 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5907 [[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
5909 /*FIX ME: I think we now need to use the items not rows in NSOutlineView */
5910 presetUserDefault = [fPresetsOutlineView selectedRow];
5912 /* We save all of the preset data here */
5914 /* We Reload the New Table data for presets */
5915 [fPresetsOutlineView reloadData];
5918 - (IBAction)selectDefaultPreset:(id)sender
5920 /* if there is a user specified default, we use it */
5921 if (presetUserDefault)
5923 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
5924 [self selectPreset:nil];
5926 else if (presetHbDefault) //else we use the built in default presetHbDefault
5928 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
5929 [self selectPreset:nil];
5935 #pragma mark Manage Built In Presets
5938 - (IBAction)deleteFactoryPresets:(id)sender
5941 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5945 NSMutableArray *tempArray;
5948 tempArray = [NSMutableArray array];
5949 /* we look here to see if the preset is we move on to the next one */
5950 while ( tempObject = [enumerator nextObject] )
5952 /* if the preset is "Factory" then we put it in the array of
5953 presets to delete */
5954 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
5956 [tempArray addObject:tempObject];
5960 [UserPresets removeObjectsInArray:tempArray];
5961 [fPresetsOutlineView reloadData];
5966 /* We use this method to recreate new, updated factory
5968 - (IBAction)addFactoryPresets:(id)sender
5971 /* First, we delete any existing built in presets */
5972 [self deleteFactoryPresets: sender];
5973 /* Then we generate new built in presets programmatically with fPresetsBuiltin
5974 * which is all setup in HBPresets.h and HBPresets.m*/
5975 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
5987 /*******************************
5988 * Subclass of the HBPresetsOutlineView *
5989 *******************************/
5991 @implementation HBPresetsOutlineView
5992 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
5996 // By default, NSTableView only drags an image of the first column. Change this to
5997 // drag an image of the queue's icon and PresetName columns.
5998 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"icon"], [self tableColumnWithIdentifier:@"PresetName"], nil];
5999 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
6004 - (void) mouseDown:(NSEvent *)theEvent
6006 [super mouseDown:theEvent];
6012 - (BOOL) isDragging;