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 /*On Screen Notification*/
118 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"HandBrake Has Detected Item(s) From Your Previous Queue.", nil)];
119 NSBeginCriticalAlertSheet(
121 NSLocalizedString(@"Reload Queue", nil),
123 NSLocalizedString(@"Empty Queue", nil),
125 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
126 NSLocalizedString(@" Do you want to reload them ?", nil));
127 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
128 // right below to either clear the old queue or keep it loaded up.
133 /* Show Browse Sources Window ASAP */
134 [self performSelectorOnMainThread:@selector(browseSources:)
135 withObject:nil waitUntilDone:NO];
139 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
141 if (returnCode == NSAlertOtherReturn)
143 [self clearQueueAllItems];
144 [self performSelectorOnMainThread:@selector(browseSources:)
145 withObject:nil waitUntilDone:NO];
151 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
153 // Warn if encoding a movie
155 hb_get_state( fHandle, &s );
157 if ( s.state != HB_STATE_IDLE )
159 int result = NSRunCriticalAlertPanel(
160 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
161 NSLocalizedString(@"If you quit HandBrake, your movie will be lost. Do you want to quit anyway?", nil),
162 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
164 if (result == NSAlertDefaultReturn)
166 [self doCancelCurrentJob];
167 return NSTerminateNow;
170 return NSTerminateCancel;
173 // Warn if items still in the queue
174 else if ( hb_count( fHandle ) > 0 )
176 int result = NSRunCriticalAlertPanel(
177 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
178 NSLocalizedString(@"One or more encodes are queued for encoding. Do you want to quit anyway?", nil),
179 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
181 if ( result == NSAlertDefaultReturn )
182 return NSTerminateNow;
184 return NSTerminateCancel;
187 return NSTerminateNow;
190 - (void)applicationWillTerminate:(NSNotification *)aNotification
192 [browsedSourceDisplayName release];
193 [outputPanel release];
194 [fQueueController release];
196 hb_close(&fQueueEncodeLibhb);
200 - (void) awakeFromNib
203 [fWindow setExcludedFromWindowsMenu:YES];
204 [fAdvancedOptions setView:fAdvancedView];
206 /* lets setup our presets drawer for drag and drop here */
207 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
208 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
209 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
211 /* Initialize currentScanCount so HB can use it to
212 evaluate successive scans */
213 currentScanCount = 0;
216 /* Init UserPresets .plist */
219 /* Init QueueFile .plist */
220 [self loadQueueFile];
222 fRipIndicatorShown = NO; // initially out of view in the nib
224 /* Show/Dont Show Presets drawer upon launch based
225 on user preference DefaultPresetsDrawerShow*/
226 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
228 [fPresetDrawer open];
234 NSMenuItem *menuItem;
235 [fDstFormatPopUp removeAllItems];
237 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
238 [menuItem setTag: HB_MUX_MP4];
240 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
241 [menuItem setTag: HB_MUX_MKV];
243 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"AVI file" action: NULL keyEquivalent: @""];
244 [menuItem setTag: HB_MUX_AVI];
246 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"OGM file" action: NULL keyEquivalent: @""];
247 [menuItem setTag: HB_MUX_OGM];
248 [fDstFormatPopUp selectItemAtIndex: 0];
250 [self formatPopUpChanged:nil];
252 /* We enable the create chapters checkbox here since we are .mp4 */
253 [fCreateChapterMarkers setEnabled: YES];
254 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
256 [fCreateChapterMarkers setState: NSOnState];
262 [fDstFile2Field setStringValue: [NSString stringWithFormat:
263 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
266 [fVidEncoderPopUp removeAllItems];
267 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
268 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
273 [fVidTargetSizeField setIntValue: 700];
274 [fVidBitrateField setIntValue: 1000];
276 [fVidQualityMatrix selectCell: fVidBitrateCell];
277 [self videoMatrixChanged:nil];
279 /* Video framerate */
280 [fVidRatePopUp removeAllItems];
281 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
282 for( int i = 0; i < hb_video_rates_count; i++ )
284 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
286 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
287 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
289 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
291 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
292 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
294 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
296 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
297 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
301 [fVidRatePopUp addItemWithTitle:
302 [NSString stringWithCString: hb_video_rates[i].string]];
305 [fVidRatePopUp selectItemAtIndex: 0];
307 /* Set Auto Crop to On at launch */
308 [fPictureController setAutoCrop:YES];
311 [fAudTrack1BitratePopUp removeAllItems];
312 for( int i = 0; i < hb_audio_bitrates_count; i++ )
314 [fAudTrack1BitratePopUp addItemWithTitle:
315 [NSString stringWithCString: hb_audio_bitrates[i].string]];
318 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
320 /* Audio samplerate */
321 [fAudTrack1RatePopUp removeAllItems];
322 for( int i = 0; i < hb_audio_rates_count; i++ )
324 [fAudTrack1RatePopUp addItemWithTitle:
325 [NSString stringWithCString: hb_audio_rates[i].string]];
327 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
330 [fStatusField setStringValue: @""];
335 /* We disable the Turbo 1st pass checkbox since we are not x264 */
336 [fVidTurboPassCheck setEnabled: NO];
337 [fVidTurboPassCheck setState: NSOffState];
340 /* lets get our default prefs here */
341 [self getDefaultPresets:nil];
342 /* lets initialize the current successful scancount here to 0 */
343 currentSuccessfulScanCount = 0;
348 - (void) enableUI: (bool) b
350 NSControl * controls[] =
351 { fSrcTitleField, fSrcTitlePopUp,
352 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
353 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
354 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
355 fDstBrowseButton, fVidRateField, fVidRatePopUp,
356 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
357 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
358 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
359 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
360 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
361 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
362 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
363 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
364 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
365 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
366 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
367 fPictureButton,fQueueStatus,fPicSettingARkeep, fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,
368 fPicLabelOutp,fPicSettingsSrc,fPicSettingsOutp,fPicSettingsAnamorphic,
369 fPicLabelAr,fPicLabelDeinterlace,fPicSettingPAR,fPicLabelAnamorphic,fPresetsAdd,fPresetsDelete,
370 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fPicLabelAutoCrop,
371 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,
372 fSubForcedCheck,fPicSettingDeblock,fPicLabelDeblock,fPicLabelDecomb,fPicSettingDecomb,fPresetsOutlineView,
373 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck};
376 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
378 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
380 NSTextField * tf = (NSTextField *) controls[i];
381 if( ![tf isBezeled] )
383 [tf setTextColor: b ? [NSColor controlTextColor] :
384 [NSColor disabledControlTextColor]];
388 [controls[i] setEnabled: b];
394 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
395 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
396 [self setEnabledStateOfAudioMixdownControls:nil];
397 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
398 [self calculatePictureSizing:nil];
399 [self shouldEnableHttpMp4CheckBox: nil];
403 [fPresetsOutlineView setEnabled: NO];
407 [self videoMatrixChanged:nil];
408 [fAdvancedOptions enableUI:b];
412 /***********************************************************************
414 ***********************************************************************
415 * Shows a progression bar on the dock icon, filled according to
416 * 'progress' (0.0 <= progress <= 1.0).
417 * Called with progress < 0.0 or progress > 1.0, restores the original
419 **********************************************************************/
420 - (void) UpdateDockIcon: (float) progress
424 NSBitmapImageRep * bmp;
426 uint32_t black = htonl( 0x000000FF );
427 uint32_t red = htonl( 0xFF0000FF );
428 uint32_t white = htonl( 0xFFFFFFFF );
429 int row_start, row_end;
432 /* Get application original icon */
433 icon = [NSImage imageNamed: @"NSApplicationIcon"];
435 if( progress < 0.0 || progress > 1.0 )
437 [NSApp setApplicationIconImage: icon];
441 /* Get it in a raw bitmap form */
442 tiff = [icon TIFFRepresentationUsingCompression:
443 NSTIFFCompressionNone factor: 1.0];
444 bmp = [NSBitmapImageRep imageRepWithData: tiff];
446 /* Draw the progression bar */
447 /* It's pretty simple (ugly?) now, but I'm no designer */
449 row_start = 3 * (int) [bmp size].height / 4;
450 row_end = 7 * (int) [bmp size].height / 8;
452 for( i = row_start; i < row_start + 2; i++ )
454 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
455 for( j = 0; j < (int) [bmp size].width; j++ )
460 for( i = row_start + 2; i < row_end - 2; i++ )
462 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
465 for( j = 2; j < (int) [bmp size].width - 2; j++ )
467 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
479 for( i = row_end - 2; i < row_end; i++ )
481 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
482 for( j = 0; j < (int) [bmp size].width; j++ )
488 /* Now update the dock icon */
489 tiff = [bmp TIFFRepresentationUsingCompression:
490 NSTIFFCompressionNone factor: 1.0];
491 icon = [[NSImage alloc] initWithData: tiff];
492 [NSApp setApplicationIconImage: icon];
496 - (void) updateUI: (NSTimer *) timer
499 /* Update UI for fHandle (user scanning instance of libhb ) */
502 list = hb_get_titles( fHandle );
503 /* check to see if there has been a new scan done
504 this bypasses the constraints of HB_STATE_WORKING
505 not allowing setting a newly scanned source */
506 int checkScanCount = hb_get_scancount( fHandle );
507 if( checkScanCount > currentScanCount )
509 currentScanCount = checkScanCount;
510 [fScanIndicator setIndeterminate: NO];
511 [fScanIndicator setDoubleValue: 0.0];
512 [fScanIndicator setHidden: YES];
513 [self showNewScan:nil];
517 hb_get_state( fHandle, &s );
523 #define p s.param.scanning
524 case HB_STATE_SCANNING:
526 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
527 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
528 p.title_cur, p.title_count]];
529 [fScanIndicator setHidden: NO];
530 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
535 #define p s.param.scandone
536 case HB_STATE_SCANDONE:
538 [fScanIndicator setIndeterminate: NO];
539 [fScanIndicator setDoubleValue: 0.0];
540 [fScanIndicator setHidden: YES];
541 [self writeToActivityLog:"ScanDone state received from fHandle"];
542 [self showNewScan:nil];
543 [[fWindow toolbar] validateVisibleItems];
549 #define p s.param.working
550 case HB_STATE_WORKING:
557 #define p s.param.muxing
558 case HB_STATE_MUXING:
565 case HB_STATE_PAUSED:
568 case HB_STATE_WORKDONE:
575 /* Update UI for fQueueEncodeLibhb */
577 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
578 /* check to see if there has been a new scan done
579 this bypasses the constraints of HB_STATE_WORKING
580 not allowing setting a newly scanned source */
582 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
583 if( checkScanCount > currentScanCount )
585 currentScanCount = checkScanCount;
586 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
590 hb_get_state( fQueueEncodeLibhb, &s );
596 #define p s.param.scanning
597 case HB_STATE_SCANNING:
599 [fStatusField setStringValue: [NSString stringWithFormat:
600 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
601 p.title_cur, p.title_count]];
602 [fRipIndicator setHidden: NO];
603 [fRipIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
608 #define p s.param.scandone
609 case HB_STATE_SCANDONE:
611 [fRipIndicator setIndeterminate: NO];
612 [fRipIndicator setDoubleValue: 0.0];
614 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
615 [self processNewQueueEncode];
616 [[fWindow toolbar] validateVisibleItems];
622 #define p s.param.working
623 case HB_STATE_WORKING:
625 float progress_total;
626 NSMutableString * string;
627 /* Update text field */
628 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
632 [string appendFormat:
633 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
634 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
637 [fStatusField setStringValue: string];
640 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
641 [fRipIndicator setIndeterminate: NO];
642 [fRipIndicator setDoubleValue: 100.0 * progress_total];
644 // If progress bar hasn't been revealed at the bottom of the window, do
645 // that now. This code used to be in doRip. I moved it to here to handle
646 // the case where hb_start is called by HBQueueController and not from
648 if( !fRipIndicatorShown )
650 NSRect frame = [fWindow frame];
651 if( frame.size.width <= 591 )
652 frame.size.width = 591;
653 frame.size.height += 36;
654 frame.origin.y -= 36;
655 [fWindow setFrame:frame display:YES animate:YES];
656 fRipIndicatorShown = YES;
657 /* We check to see if we need to warn the user that the computer will go to sleep
658 or shut down when encoding is finished */
659 [self remindUserOfSleepOrShutdown];
662 /* Update dock icon */
663 [self UpdateDockIcon: progress_total];
669 #define p s.param.muxing
670 case HB_STATE_MUXING:
672 /* Update text field */
673 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
676 [fRipIndicator setIndeterminate: YES];
677 [fRipIndicator startAnimation: nil];
679 /* Update dock icon */
680 [self UpdateDockIcon: 1.0];
686 case HB_STATE_PAUSED:
687 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
691 case HB_STATE_WORKDONE:
693 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
694 // or someone calling hb_stop. In the latter case, hb_stop does not clear
695 // out the remaining passes/jobs in the queue. We'll do that here.
697 // Delete all remaining jobs of this encode.
698 [fStatusField setStringValue: NSLocalizedString( @"Done.", @"" )];
699 [fRipIndicator setIndeterminate: NO];
700 [fRipIndicator setDoubleValue: 0.0];
701 [[fWindow toolbar] validateVisibleItems];
703 /* Restore dock icon */
704 [self UpdateDockIcon: -1.0];
706 if( fRipIndicatorShown )
708 NSRect frame = [fWindow frame];
709 if( frame.size.width <= 591 )
710 frame.size.width = 591;
711 frame.size.height += -36;
712 frame.origin.y -= -36;
713 [fWindow setFrame:frame display:YES animate:YES];
714 fRipIndicatorShown = NO;
717 /* Check to see if the encode state has not been cancelled
718 to determine if we should check for encode done notifications */
719 if( fEncodeState != 2 )
721 NSString *pathOfFinishedEncode;
722 /* Get the output file name for the finished encode */
723 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
725 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
727 [self showGrowlDoneNotification:pathOfFinishedEncode];
729 [self sendToMetaX:pathOfFinishedEncode];
731 /* since we have successfully completed an encode, we increment the queue counter */
732 [self incrementQueueItemDone:nil];
734 /* all end of queue actions below need to be done after all queue encodes have finished
735 * and there are no pending jobs left to process
737 if (fPendingCount == 0)
739 /* If Alert Window or Window and Growl has been selected */
740 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
741 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
743 /*On Screen Notification*/
746 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
747 [NSApp requestUserAttention:NSCriticalRequest];
750 /* If sleep has been selected */
751 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
754 NSDictionary* errorDict;
755 NSAppleEventDescriptor* returnDescriptor = nil;
756 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
757 @"tell application \"Finder\" to sleep"];
758 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
759 [scriptObject release];
761 /* If Shutdown has been selected */
762 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
765 NSDictionary* errorDict;
766 NSAppleEventDescriptor* returnDescriptor = nil;
767 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
768 @"tell application \"Finder\" to shut down"];
769 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
770 [scriptObject release];
784 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
785 - (void) writeToActivityLog:(char *) format, ...
788 va_start(args, format);
792 vsnprintf( str, 1024, format, args );
794 time_t _now = time( NULL );
795 struct tm * now = localtime( &_now );
796 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
803 // ============================================================
804 // NSToolbar Related Methods
805 // ============================================================
807 - (void) setupToolbar {
808 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
810 [toolbar setAllowsUserCustomization: YES];
811 [toolbar setAutosavesConfiguration: YES];
812 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
814 [toolbar setDelegate: self];
816 [fWindow setToolbar: toolbar];
819 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
820 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
821 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
823 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
825 [item setLabel: @"Toggle Presets"];
826 [item setPaletteLabel: @"Toggler Presets"];
827 [item setToolTip: @"Open/Close Preset Drawer"];
828 [item setImage: [NSImage imageNamed: @"Drawer"]];
829 [item setTarget: self];
830 [item setAction: @selector(toggleDrawer:)];
831 [item setAutovalidates: NO];
833 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
835 [item setLabel: @"Start"];
836 [item setPaletteLabel: @"Start Encoding"];
837 [item setToolTip: @"Start Encoding"];
838 [item setImage: [NSImage imageNamed: @"Play"]];
839 [item setTarget: self];
840 [item setAction: @selector(Rip:)];
842 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
844 [item setLabel: @"Show Queue"];
845 [item setPaletteLabel: @"Show Queue"];
846 [item setToolTip: @"Show Queue"];
847 [item setImage: [NSImage imageNamed: @"Queue"]];
848 [item setTarget: self];
849 [item setAction: @selector(showQueueWindow:)];
850 [item setAutovalidates: NO];
852 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
854 [item setLabel: @"Add to Queue"];
855 [item setPaletteLabel: @"Add to Queue"];
856 [item setToolTip: @"Add to Queue"];
857 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
858 [item setTarget: self];
859 [item setAction: @selector(addToQueue:)];
861 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
863 [item setLabel: @"Pause"];
864 [item setPaletteLabel: @"Pause Encoding"];
865 [item setToolTip: @"Pause Encoding"];
866 [item setImage: [NSImage imageNamed: @"Pause"]];
867 [item setTarget: self];
868 [item setAction: @selector(Pause:)];
870 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
871 [item setLabel: @"Activity Window"];
872 [item setPaletteLabel: @"Show Activity Window"];
873 [item setToolTip: @"Show Activity Window"];
874 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
875 [item setTarget: self];
876 [item setAction: @selector(showDebugOutputPanel:)];
877 [item setAutovalidates: NO];
879 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
881 [item setLabel: @"Source"];
882 [item setPaletteLabel: @"Source"];
883 [item setToolTip: @"Choose Video Source"];
884 [item setImage: [NSImage imageNamed: @"Source"]];
885 [item setTarget: self];
886 [item setAction: @selector(browseSources:)];
896 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
898 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
899 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
900 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
903 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
905 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
906 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
907 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
908 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
911 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
913 NSString * ident = [toolbarItem itemIdentifier];
918 hb_get_state2( fQueueEncodeLibhb, &s );
920 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
922 if ([ident isEqualToString: StartEncodingIdentifier])
924 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
925 [toolbarItem setLabel: @"Stop"];
926 [toolbarItem setPaletteLabel: @"Stop"];
927 [toolbarItem setToolTip: @"Stop Encoding"];
930 if ([ident isEqualToString: PauseEncodingIdentifier])
932 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
933 [toolbarItem setLabel: @"Pause"];
934 [toolbarItem setPaletteLabel: @"Pause Encoding"];
935 [toolbarItem setToolTip: @"Pause Encoding"];
939 if ([ident isEqualToString: AddToQueueIdentifier])
942 else if (s.state == HB_STATE_PAUSED)
944 if ([ident isEqualToString: PauseEncodingIdentifier])
946 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
947 [toolbarItem setLabel: @"Resume"];
948 [toolbarItem setPaletteLabel: @"Resume Encoding"];
949 [toolbarItem setToolTip: @"Resume Encoding"];
952 if ([ident isEqualToString: StartEncodingIdentifier])
954 if ([ident isEqualToString: AddToQueueIdentifier])
957 else if (s.state == HB_STATE_SCANNING)
959 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
961 if ([ident isEqualToString: StartEncodingIdentifier])
963 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
964 if (hb_count(fHandle) > 0)
965 [toolbarItem setLabel: @"Start Queue"];
967 [toolbarItem setLabel: @"Start"];
968 [toolbarItem setPaletteLabel: @"Start Encoding"];
969 [toolbarItem setToolTip: @"Start Encoding"];
972 if ([ident isEqualToString: AddToQueueIdentifier])
977 /* If there are any pending queue items, make sure the start/stop button is active */
978 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
980 if ([ident isEqualToString: ShowQueueIdentifier])
982 if ([ident isEqualToString: ToggleDrawerIdentifier])
984 if ([ident isEqualToString: ChooseSourceIdentifier])
986 if ([ident isEqualToString: ShowActivityIdentifier])
992 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
994 SEL action = [menuItem action];
997 hb_get_state2( fHandle, &s );
1001 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1002 return SuccessfulScan && [fWindow attachedSheet] == nil;
1004 if (action == @selector(browseSources:))
1006 if (s.state == HB_STATE_SCANNING)
1009 return [fWindow attachedSheet] == nil;
1011 if (action == @selector(selectDefaultPreset:))
1012 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1013 if (action == @selector(Pause:))
1015 if (s.state == HB_STATE_WORKING)
1017 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1018 [menuItem setTitle:@"Pause Encoding"];
1021 else if (s.state == HB_STATE_PAUSED)
1023 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1024 [menuItem setTitle:@"Resume Encoding"];
1030 if (action == @selector(Rip:))
1032 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1034 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1035 [menuItem setTitle:@"Stop Encoding"];
1038 else if (SuccessfulScan)
1040 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1041 [menuItem setTitle:@"Start Encoding"];
1042 return [fWindow attachedSheet] == nil;
1048 if( action == @selector(setDefaultPreset:) )
1050 return [fPresetsOutlineView selectedRow] != -1;
1057 #pragma mark Encode Done Actions
1058 // register a test notification and make
1059 // it enabled by default
1060 #define SERVICE_NAME @"Encode Done"
1061 - (NSDictionary *)registrationDictionaryForGrowl
1063 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1064 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1065 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1068 return registrationDictionary;
1071 -(void)showGrowlDoneNotification:(NSString *) filePath
1073 /* This end of encode action is called as each encode rolls off of the queue */
1074 NSString * finishedEncode = filePath;
1075 /* strip off the path to just show the file name */
1076 finishedEncode = [finishedEncode lastPathComponent];
1077 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1078 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1080 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1081 [GrowlApplicationBridge
1082 notifyWithTitle:@"Put down that cocktail..."
1083 description:growlMssg
1084 notificationName:SERVICE_NAME
1092 -(void)sendToMetaX:(NSString *) filePath
1094 /* This end of encode action is called as each encode rolls off of the queue */
1095 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1097 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1098 [myScript executeAndReturnError: nil];
1103 #pragma mark Get New Source
1105 /*Opens the source browse window, called from Open Source widgets */
1106 - (IBAction) browseSources: (id) sender
1108 NSOpenPanel * panel;
1110 panel = [NSOpenPanel openPanel];
1111 [panel setAllowsMultipleSelection: NO];
1112 [panel setCanChooseFiles: YES];
1113 [panel setCanChooseDirectories: YES ];
1114 NSString * sourceDirectory;
1115 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1117 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1121 sourceDirectory = @"~/Desktop";
1122 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1124 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1125 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1127 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1128 modalForWindow: fWindow modalDelegate: self
1129 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1130 contextInfo: sender];
1133 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1134 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1136 /* we convert the sender content of contextInfo back into a variable called sender
1137 * mostly just for consistency for evaluation later
1139 id sender = (id)contextInfo;
1140 /* User selected a file to open */
1141 if( returnCode == NSOKButton )
1143 /* Free display name allocated previously by this code */
1144 [browsedSourceDisplayName release];
1146 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1147 /* we set the last searched source directory in the prefs here */
1148 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1149 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1150 /* we order out sheet, which is the browse window as we need to open
1151 * the title selection sheet right away
1153 [sheet orderOut: self];
1155 if (sender == fOpenSourceTitleMMenu)
1157 /* We put the chosen source path in the source display text field for the
1158 * source title selection sheet in which the user specifies the specific title to be
1159 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1160 * purposes in the title panel
1163 [fScanSrcTitlePathField setStringValue:scanPath];
1164 NSString *displayTitlescanSourceName;
1166 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1168 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1169 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1170 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1174 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1175 displayTitlescanSourceName = [scanPath lastPathComponent];
1177 /* we set the source display name in the title selection dialogue */
1178 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1179 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1180 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1181 /* We show the actual sheet where the user specifies the title to be scanned
1182 * as we are going to do a title specific scan
1184 [self showSourceTitleScanPanel:nil];
1188 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1189 NSString *path = [[sheet filenames] objectAtIndex: 0];
1191 /* We check to see if the chosen file at path is a package */
1192 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1194 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1195 /* We check to see if this is an .eyetv package */
1196 if ([[path pathExtension] isEqualToString: @"eyetv"])
1198 [self writeToActivityLog:"trying to open eyetv package"];
1199 /* We're looking at an EyeTV package - try to open its enclosed
1201 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1203 int n = [[path stringByAppendingString: @"/"]
1204 completePathIntoString: &mpgname caseSensitive: NO
1205 matchesIntoArray: nil
1206 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1209 /* Found an mpeg inside the eyetv package, make it our scan path
1210 and call performScan on the enclosed mpeg */
1212 [self writeToActivityLog:"found mpeg in eyetv package"];
1213 [self performScan:path scanTitleNum:0];
1217 /* We did not find an mpeg file in our package, so we do not call performScan */
1218 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1221 /* We check to see if this is a .dvdmedia package */
1222 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1224 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1225 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1226 [self writeToActivityLog:"trying to open dvdmedia package"];
1227 [self performScan:path scanTitleNum:0];
1231 /* The package is not an eyetv package, so we do not call performScan */
1232 [self writeToActivityLog:"unable to open package"];
1235 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1237 /* path is not a package, so we call perform scan directly on our file */
1238 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1240 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1241 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1242 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1246 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1247 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1248 /* make sure we remove any path extension as this can also be an '.mpg' file */
1249 browsedSourceDisplayName = [[path lastPathComponent] retain];
1251 [self performScan:path scanTitleNum:0];
1259 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1260 - (IBAction) showSourceTitleScanPanel: (id) sender
1262 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1265 [fScanSrcTitleNumField setStringValue: @"0"];
1266 /* Show the panel */
1267 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1270 - (IBAction) closeSourceTitleScanPanel: (id) sender
1272 [NSApp endSheet: fScanSrcTitlePanel];
1273 [fScanSrcTitlePanel orderOut: self];
1275 if(sender == fScanSrcTitleOpenButton)
1277 /* We setup the scan status in the main window to indicate a source title scan */
1278 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1279 [fScanIndicator setHidden: NO];
1280 [fScanIndicator setIndeterminate: YES];
1281 [fScanIndicator startAnimation: nil];
1283 /* We use the performScan method to actually perform the specified scan passing the path and the title
1286 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1290 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1291 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1293 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1294 applyQueueToScan = NO;
1295 /* use a bool to determine whether or not we can decrypt using vlc */
1296 BOOL cancelScanDecrypt = 0;
1297 NSString *path = scanPath;
1298 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1300 // Notify ChapterTitles that there's no title
1301 [fChapterTitlesDelegate resetWithTitle:nil];
1302 [fChapterTable reloadData];
1304 [self enableUI: NO];
1306 if( [detector isVideoDVD] )
1308 // The chosen path was actually on a DVD, so use the raw block
1309 // device path instead.
1310 path = [detector devicePath];
1311 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1313 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1314 NSString *vlcPath = @"/Applications/VLC.app";
1315 NSFileManager * fileManager = [NSFileManager defaultManager];
1316 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1318 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1319 cancelScanDecrypt = 1;
1320 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1322 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");
1323 [NSApp requestUserAttention:NSCriticalRequest];
1325 if (status == NSAlertDefaultReturn)
1327 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1328 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1330 else if (status == NSAlertAlternateReturn)
1332 /* User chose to cancel the scan */
1333 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1337 /* 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 */
1338 cancelScanDecrypt = 0;
1339 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1345 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1346 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1350 if (cancelScanDecrypt == 0)
1352 /* we actually pass the scan off to libhb here */
1353 /* If there is no title number passed to scan, we use "0"
1354 * which causes the default behavior of a full source scan
1360 if (scanTitleNum > 0)
1362 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1365 hb_scan( fHandle, [path UTF8String], scanTitleNum );
1366 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1370 - (IBAction) showNewScan:(id)sender
1374 int indxpri=0; // Used to search the longuest title (default in combobox)
1375 int longuestpri=0; // Used to search the longuest title (default in combobox)
1378 list = hb_get_titles( fHandle );
1380 if( !hb_list_count( list ) )
1382 /* We display a message if a valid dvd source was not chosen */
1383 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1384 SuccessfulScan = NO;
1386 // Notify ChapterTitles that there's no title
1387 [fChapterTitlesDelegate resetWithTitle:nil];
1388 [fChapterTable reloadData];
1392 /* We increment the successful scancount here by one,
1393 which we use at the end of this function to tell the gui
1394 if this is the first successful scan since launch and whether
1395 or not we should set all settings to the defaults */
1397 currentSuccessfulScanCount++;
1399 [[fWindow toolbar] validateVisibleItems];
1401 [fSrcTitlePopUp removeAllItems];
1402 for( int i = 0; i < hb_list_count( list ); i++ )
1404 title = (hb_title_t *) hb_list_item( list, i );
1406 currentSource = [NSString stringWithUTF8String: title->name];
1407 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1408 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1410 /* Use the dvd name in the default output field here
1411 May want to add code to remove blank spaces for some dvd names*/
1412 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1413 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1415 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1416 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1420 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1421 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1425 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1427 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1431 [fSrcTitlePopUp addItemWithTitle: [NSString
1432 stringWithFormat: @"%d - %02dh%02dm%02ds",
1433 title->index, title->hours, title->minutes,
1437 // Select the longuest title
1438 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1439 [self titlePopUpChanged:nil];
1441 SuccessfulScan = YES;
1442 [self enableUI: YES];
1444 /* if its the initial successful scan after awakeFromNib */
1445 if (currentSuccessfulScanCount == 1)
1447 [self selectDefaultPreset:nil];
1448 /* initially set deinterlace to 0, will be overridden reset by the default preset anyway */
1449 //[fPictureController setDeinterlace:0];
1451 /* lets set Denoise to index 0 or "None" since this is the first scan */
1452 //[fPictureController setDenoise:0];
1454 [fPictureController setInitialPictureFilters];
1464 #pragma mark New Output Destination
1466 - (IBAction) browseFile: (id) sender
1468 /* Open a panel to let the user choose and update the text field */
1469 NSSavePanel * panel = [NSSavePanel savePanel];
1470 /* We get the current file name and path from the destination field here */
1471 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1472 modalForWindow: fWindow modalDelegate: self
1473 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1477 - (void) browseFileDone: (NSSavePanel *) sheet
1478 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1480 if( returnCode == NSOKButton )
1482 [fDstFile2Field setStringValue: [sheet filename]];
1488 #pragma mark Main Window Control
1490 - (IBAction) openMainWindow: (id) sender
1492 [fWindow makeKeyAndOrderFront:nil];
1495 - (BOOL) windowShouldClose: (id) sender
1500 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1503 [fWindow makeKeyAndOrderFront:nil];
1513 #pragma mark Queue File
1515 - (void) loadQueueFile {
1516 /* We declare the default NSFileManager into fileManager */
1517 NSFileManager * fileManager = [NSFileManager defaultManager];
1518 /*We define the location of the user presets file */
1519 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1520 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1521 /* We check for the presets.plist */
1522 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1524 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1527 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1528 /* lets check to see if there is anything in the queue file .plist */
1529 if (nil == QueueFileArray)
1531 /* if not, then lets initialize an empty array */
1532 QueueFileArray = [[NSMutableArray alloc] init];
1534 /* Initialize our curQueueEncodeIndex to 0
1535 * so we can use it to track which queue
1536 * item is to be used to track our encodes */
1537 /* NOTE: this should be changed if and when we
1538 * are able to get the last unfinished encode
1539 * in the case of a crash or shutdown */
1544 [self clearQueueEncodedItems];
1546 currentQueueEncodeIndex = 0;
1549 - (void)addQueueFileItem
1551 [QueueFileArray addObject:[self createQueueFileItem]];
1552 [self saveQueueFileItem];
1556 - (void) removeQueueFileItem:(int) queueItemToRemove
1559 /* Find out if the item we are removing is a cancelled item*/
1560 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3)
1562 /* Since we are removing a cancelled item, WE need to decrement the currentQueueEncodeIndex
1563 * by one to keep in sync with the queue array
1565 currentQueueEncodeIndex--;
1566 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1568 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1569 [self saveQueueFileItem];
1573 - (void)saveQueueFileItem
1575 [QueueFileArray writeToFile:QueueFile atomically:YES];
1576 [fQueueController setQueueArray: QueueFileArray];
1577 [self getQueueStats];
1580 - (void)getQueueStats
1582 /* lets get the stats on the status of the queue array */
1584 fEncodingQueueItem = 0;
1586 fCompletedCount = 0;
1590 /* We use a number system to set the encode status of the queue item
1592 * 0 == already encoded
1593 * 1 == is being encoded
1594 * 2 == is yet to be encoded
1599 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1601 while (tempObject = [enumerator nextObject])
1603 NSDictionary *thisQueueDict = tempObject;
1604 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1608 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1611 fEncodingQueueItem = i;
1613 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1617 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1624 /* Set the queue status field in the main window */
1625 NSMutableString * string;
1626 if (fPendingCount == 1)
1628 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1632 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1634 [fQueueStatus setStringValue:string];
1638 /* This method will clear the queue of any encodes that are not still pending
1639 * this includes both successfully completed encodes as well as cancelled encodes */
1640 - (void) clearQueueEncodedItems
1642 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1644 NSMutableArray *tempArray;
1645 tempArray = [NSMutableArray array];
1646 /* we look here to see if the preset is we move on to the next one */
1647 while ( tempObject = [enumerator nextObject] )
1649 /* If the queue item is not still pending (finished successfully or it was cancelled
1650 * during the last session, then we put it in tempArray to be deleted from QueueFileArray*/
1651 if ([[tempObject objectForKey:@"Status"] intValue] != 2)
1653 [tempArray addObject:tempObject];
1657 [QueueFileArray removeObjectsInArray:tempArray];
1658 [self saveQueueFileItem];
1662 /* This method will clear the queue of any encodes that are not still pending
1663 * this includes both successfully completed encodes as well as cancelled encodes */
1664 - (void) clearQueueAllItems
1666 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1668 NSMutableArray *tempArray;
1669 tempArray = [NSMutableArray array];
1670 /* we look here to see if the preset is we move on to the next one */
1671 while ( tempObject = [enumerator nextObject] )
1673 [tempArray addObject:tempObject];
1676 [QueueFileArray removeObjectsInArray:tempArray];
1677 [self saveQueueFileItem];
1681 /* This method will duplicate prepareJob however into the
1682 * queue .plist instead of into the job structure so it can
1683 * be recalled later */
1684 - (NSDictionary *)createQueueFileItem
1686 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1688 hb_list_t * list = hb_get_titles( fHandle );
1689 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1690 [fSrcTitlePopUp indexOfSelectedItem] );
1691 hb_job_t * job = title->job;
1695 /* We use a number system to set the encode status of the queue item
1696 * 0 == already encoded
1697 * 1 == is being encoded
1698 * 2 == is yet to be encoded
1701 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1702 /* Source and Destination Information */
1704 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1705 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1706 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1707 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1709 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1711 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1713 /* Lets get the preset info if there is any */
1714 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1715 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1717 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1718 /* Chapter Markers fCreateChapterMarkers*/
1719 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1721 /* We need to get the list of chapter names to put into an array and store
1722 * in our queue, so they can be reapplied in prepareJob when this queue
1723 * item comes up if Chapter Markers is set to on.
1726 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
1727 int chaptercount = hb_list_count( fTitle->list_chapter );
1728 for( i = 0; i < chaptercount; i++ )
1730 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
1731 if( chapter != NULL )
1733 [ChapterNamesArray addObject:[NSString stringWithFormat:@"%s",chapter->title]];
1736 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
1737 [ChapterNamesArray autorelease];
1739 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1740 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1741 /* Mux mp4 with http optimization */
1742 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1743 /* Add iPod uuid atom */
1744 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1748 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
1749 /* x264 Option String */
1750 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1752 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1753 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1754 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1755 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1757 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
1760 [queueFileJob setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
1761 /* 2 Pass Encoding */
1762 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
1763 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
1764 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
1766 /* Picture Sizing */
1767 /* Use Max Picture settings for whatever the dvd is.*/
1768 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1769 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1770 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1771 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1772 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1773 NSString * pictureSummary;
1774 pictureSummary = [NSString stringWithFormat:@"Source: %@ Output: %@ Anamorphic: %@",
1775 [fPicSettingsSrc stringValue],
1776 [fPicSettingsOutp stringValue],
1777 [fPicSettingsAnamorphic stringValue]];
1778 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
1779 /* Set crop settings here */
1780 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1781 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1782 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1783 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1784 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1786 /* Picture Filters */
1787 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
1788 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
1789 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
1790 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
1791 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
1792 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
1795 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1797 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
1798 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
1799 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
1800 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
1801 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
1802 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
1803 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
1805 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1807 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
1808 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
1809 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
1810 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
1811 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
1812 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
1813 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
1815 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1817 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
1818 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
1819 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
1820 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
1821 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
1822 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
1823 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
1825 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1827 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
1828 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
1829 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
1830 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
1831 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
1832 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
1833 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
1837 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1838 [queueFileJob setObject:[NSNumber numberWithInt:[fSubPopUp indexOfSelectedItem]] forKey:@"JobSubtitlesIndex"];
1839 /* Forced Subtitles */
1840 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1844 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
1846 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
1848 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
1851 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
1852 /* Chapter Markers fCreateChapterMarkers*/
1853 //[queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1854 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1855 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1856 /* Mux mp4 with http optimization */
1857 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1858 /* Add iPod uuid atom */
1859 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1863 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
1864 /* x264 Option String */
1865 //[queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1867 //[queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1868 //[queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1869 //[queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1870 //[queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1872 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
1873 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
1874 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
1875 /* Picture Sizing */
1876 /* Use Max Picture settings for whatever the dvd is.*/
1877 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1878 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1879 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1880 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1881 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1883 /* Set crop settings here */
1884 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1885 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1886 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1887 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1888 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1890 /* Picture Filters */
1891 [queueFileJob setObject:[fPicSettingDecomb stringValue] forKey:@"JobPictureDecomb"];
1894 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1896 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
1897 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
1898 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
1899 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
1900 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
1902 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1904 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
1905 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
1906 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
1907 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
1908 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
1910 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1912 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
1913 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
1914 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
1915 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
1916 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
1918 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1920 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
1921 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
1922 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
1923 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
1924 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
1927 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1928 /* Forced Subtitles */
1929 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1931 /* we need to auto relase the queueFileJob and return it */
1932 [queueFileJob autorelease];
1933 return queueFileJob;
1937 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
1938 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
1940 unsigned index = [indexSet lastIndex];
1941 unsigned aboveInsertIndexCount = 0;
1943 while (index != NSNotFound)
1945 unsigned removeIndex;
1947 if (index >= insertIndex)
1949 removeIndex = index + aboveInsertIndexCount;
1950 aboveInsertIndexCount++;
1954 removeIndex = index;
1958 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
1959 [QueueFileArray removeObjectAtIndex:removeIndex];
1960 [QueueFileArray insertObject:object atIndex:insertIndex];
1963 index = [indexSet indexLessThanIndex:index];
1965 /* We save all of the Queue data here
1966 * and it also gets sent back to the queue controller*/
1967 [self saveQueueFileItem];
1973 #pragma mark Queue Job Processing
1975 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
1977 int i = currentQueueEncodeIndex;
1978 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
1980 /* We save all of the Queue data here */
1981 [self saveQueueFileItem];
1982 /* We Reload the New Table data for presets */
1983 //[fPresetsOutlineView reloadData];
1985 /* Since we have now marked a queue item as done
1986 * we can go ahead and increment currentQueueEncodeIndex
1987 * so that if there is anything left in the queue we can
1988 * go ahead and move to the next item if we want to */
1989 currentQueueEncodeIndex++ ;
1990 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
1991 int queueItems = [QueueFileArray count];
1992 /* If we still have more items in our queue, lets go to the next one */
1993 if (currentQueueEncodeIndex < queueItems)
1995 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
1996 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2000 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2004 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2005 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2007 //NSRunAlertPanel(@"Hello!", @"We are now performing a new queue scan!", @"OK", nil, nil);
2009 /* use a bool to determine whether or not we can decrypt using vlc */
2010 BOOL cancelScanDecrypt = 0;
2011 /* set the bool so that showNewScan knows to apply the appropriate queue
2012 * settings as this is a queue rescan
2014 applyQueueToScan = YES;
2015 NSString *path = scanPath;
2016 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2018 /*On Screen Notification*/
2020 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2021 //[NSApp requestUserAttention:NSCriticalRequest];
2023 // Notify ChapterTitles that there's no title
2024 [fChapterTitlesDelegate resetWithTitle:nil];
2025 [fChapterTable reloadData];
2027 //[self enableUI: NO];
2029 if( [detector isVideoDVD] )
2031 // The chosen path was actually on a DVD, so use the raw block
2032 // device path instead.
2033 path = [detector devicePath];
2034 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2036 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2037 NSString *vlcPath = @"/Applications/VLC.app";
2038 NSFileManager * fileManager = [NSFileManager defaultManager];
2039 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2041 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2042 cancelScanDecrypt = 1;
2043 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2045 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");
2046 [NSApp requestUserAttention:NSCriticalRequest];
2048 if (status == NSAlertDefaultReturn)
2050 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2051 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2053 else if (status == NSAlertAlternateReturn)
2055 /* User chose to cancel the scan */
2056 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2060 /* 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 */
2061 cancelScanDecrypt = 0;
2062 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2068 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2069 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2073 if (cancelScanDecrypt == 0)
2075 /* we actually pass the scan off to libhb here */
2076 /* If there is no title number passed to scan, we use "0"
2077 * which causes the default behavior of a full source scan
2083 if (scanTitleNum > 0)
2085 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2087 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2088 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum );
2092 /* This method was originally used to load up a new queue item in the gui and
2093 * then start processing it. However we now have modified -prepareJob and use a second
2094 * instance of libhb to do our actual encoding, therefor right now it is not required.
2095 * Nonetheless I want to leave this in here
2096 * because basically its everything we need to be able to actually modify a pending queue
2097 * item in the gui and resave it. At least for now - dynaflash
2100 - (IBAction)applyQueueSettings:(id)sender
2102 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2103 hb_job_t * job = fTitle->job;
2105 /* Set title number and chapters */
2106 /* since the queue only scans a single title, we really don't need to pick a title */
2107 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2109 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2110 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2113 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2114 [self formatPopUpChanged:nil];
2116 /* Chapter Markers*/
2117 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2118 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2119 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2120 /* Mux mp4 with http optimization */
2121 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2124 /* We set the advanced opt string here if applicable*/
2125 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2126 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2128 /* Lets run through the following functions to get variables set there */
2129 [self videoEncoderPopUpChanged:nil];
2130 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2131 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2132 [self calculateBitrate:nil];
2135 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2137 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2138 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2139 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2141 [self videoMatrixChanged:nil];
2143 /* Video framerate */
2144 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2145 detected framerate in the fVidRatePopUp so we use index 0*/
2146 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2148 [fVidRatePopUp selectItemAtIndex: 0];
2152 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2156 [fVidGrayscaleCheck setState:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2158 /* 2 Pass Encoding */
2159 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2160 [self twoPassCheckboxChanged:nil];
2161 /* Turbo 1st pass for 2 Pass Encoding */
2162 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2165 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2167 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2169 [fAudLang1PopUp selectItemAtIndex: 1];
2171 [self audioTrackPopUpChanged: fAudLang1PopUp];
2172 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2173 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2174 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2175 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2177 if ([fAudTrack1MixPopUp selectedItem] == nil)
2179 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2181 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2182 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2183 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2185 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2187 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2188 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2190 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2192 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2194 [fAudLang2PopUp selectItemAtIndex: 1];
2196 [self audioTrackPopUpChanged: fAudLang2PopUp];
2197 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2198 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2199 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2200 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2202 if ([fAudTrack2MixPopUp selectedItem] == nil)
2204 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2206 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2207 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2208 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2210 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2212 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2213 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2215 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2217 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2219 [fAudLang3PopUp selectItemAtIndex: 1];
2221 [self audioTrackPopUpChanged: fAudLang3PopUp];
2222 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2223 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2224 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2225 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2227 if ([fAudTrack3MixPopUp selectedItem] == nil)
2229 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2231 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2232 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2233 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2235 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2237 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2238 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2240 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2242 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2244 [fAudLang4PopUp selectItemAtIndex: 1];
2246 [self audioTrackPopUpChanged: fAudLang4PopUp];
2247 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2248 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2249 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2250 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2252 if ([fAudTrack4MixPopUp selectedItem] == nil)
2254 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2256 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2257 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2258 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2260 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2262 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2263 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2268 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2269 /* Forced Subtitles */
2270 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2272 /* Picture Settings */
2273 /* we check to make sure the presets width/height does not exceed the sources width/height */
2274 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2276 /* if so, then we use the sources height and width to avoid scaling up */
2277 job->width = fTitle->width;
2278 job->height = fTitle->height;
2280 else // source width/height is >= the preset height/width
2282 /* we can go ahead and use the presets values for height and width */
2283 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2284 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2286 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2287 if (job->keep_ratio == 1)
2289 hb_fix_aspect( job, HB_KEEP_WIDTH );
2290 if( job->height > fTitle->height )
2292 job->height = fTitle->height;
2293 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2296 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2299 /* If Cropping is set to custom, then recall all four crop values from
2300 when the preset was created and apply them */
2301 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2303 [fPictureController setAutoCrop:NO];
2305 /* Here we use the custom crop values saved at the time the preset was saved */
2306 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2307 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2308 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2309 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2312 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2314 [fPictureController setAutoCrop:YES];
2315 /* Here we use the auto crop values determined right after scan */
2316 job->crop[0] = AutoCropTop;
2317 job->crop[1] = AutoCropBottom;
2318 job->crop[2] = AutoCropLeft;
2319 job->crop[3] = AutoCropRight;
2325 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2327 [fPictureController setVFR:[[queueToApply objectForKey:@"VFR"] intValue]];
2329 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2331 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2333 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2335 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2337 [self calculatePictureSizing:nil];
2340 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2341 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2342 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2343 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2345 /* Deselect the currently selected Preset if there is one*/
2346 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2347 //[self selectPreset:nil];
2349 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2350 /* Change UI to show "Custom" settings are being used */
2351 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2353 curUserPresetChosenNum = nil;
2357 /* Deselect the currently selected Preset if there is one*/
2358 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2359 /* Change UI to show "Custom" settings are being used */
2360 [fPresetSelectedDisplay setStringValue: @"Custom"];
2362 //curUserPresetChosenNum = nil;
2365 /* We need to set this bool back to NO, in case the user wants to do a scan */
2366 //applyQueueToScan = NO;
2368 /* so now we go ahead and process the new settings */
2369 [self processNewQueueEncode];
2374 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2375 - (void) processNewQueueEncode
2377 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2378 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2379 hb_job_t * job = title->job;
2381 if( !hb_list_count( list ) )
2383 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2387 [self writeToActivityLog: "processNewQueueEncode title list is: %d", hb_list_count( list )];
2390 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2391 [self writeToActivityLog: "processNewQueueEncode currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2392 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2393 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2394 [self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2396 [self writeToActivityLog: "processNewQueueEncode back from prepareJob"];
2397 if( [[queueToApply objectForKey:@"SubtitlesForced"] intValue] == 1 )
2398 job->subtitle_force = 1;
2400 job->subtitle_force = 0;
2403 * subtitle of -1 is a scan
2405 if( job->subtitle == -1 )
2410 * When subtitle scan is enabled do a fast pre-scan job
2411 * which will determine which subtitles to enable, if any.
2414 x264opts_tmp = job->x264opts;
2417 job->x264opts = NULL;
2419 job->indepth_scan = 1;
2421 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
2422 *(job->select_subtitle) = NULL;
2425 * Add the pre-scan job
2427 hb_add( fQueueEncodeLibhb, job );
2428 job->x264opts = x264opts_tmp;
2431 job->select_subtitle = NULL;
2433 /* No subtitle were selected, so reset the subtitle to -1 (which before
2434 * this point meant we were scanning
2436 if( job->subtitle == -2 )
2439 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2441 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
2442 job->indepth_scan = 0;
2445 * Do not autoselect subtitles on the first pass of a two pass
2447 job->select_subtitle = NULL;
2451 hb_add( fQueueEncodeLibhb, job );
2455 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2456 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2458 job->select_subtitle = subtitle_tmp;
2460 hb_add( fQueueEncodeLibhb, job );
2465 job->indepth_scan = 0;
2468 hb_add( fQueueEncodeLibhb, job );
2471 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2472 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2473 /* Lets mark our new encode as 1 or "Encoding" */
2474 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2475 [self saveQueueFileItem];
2476 /* We should be all setup so let 'er rip */
2482 #pragma mark Job Handling
2488 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2489 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2490 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2491 hb_job_t * job = title->job;
2492 hb_audio_config_t * audio;
2493 [self writeToActivityLog: "prepareJob reached"];
2494 /* Chapter selection */
2495 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
2496 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
2498 /* Format (Muxer) and Video Encoder */
2499 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
2500 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
2503 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
2504 //if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
2506 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
2507 mpeg4 and the checkbox being checked
2508 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
2509 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
2511 job->largeFileSize = 1;
2515 job->largeFileSize = 0;
2517 /* We set http optimized mp4 here */
2518 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
2520 job->mp4_optimize = 1;
2524 job->mp4_optimize = 0;
2529 /* We set the chapter marker extraction here based on the format being
2530 mpeg4 or mkv and the checkbox being checked */
2531 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
2533 job->chapter_markers = 1;
2535 /* now lets get our saved chapter names out the array in the queue file
2536 * and insert them back into the title chapter list. We have it here,
2537 * because unless we are inserting chapter markers there is no need to
2538 * spend the overhead of iterating through the chapter names array imo
2539 * Also, note that if for some reason we don't apply chapter names, the
2540 * chapters just come out 001, 002, etc. etc.
2543 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
2545 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
2547 while (tempObject = [enumerator nextObject])
2549 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
2550 if( chapter != NULL )
2552 strncpy( chapter->title, [tempObject UTF8String], 1023);
2553 chapter->title[1023] = '\0';
2560 job->chapter_markers = 0;
2567 if( job->vcodec & HB_VCODEC_X264 )
2569 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
2578 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2579 Currently only used with Constant Quality setting*/
2580 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
2584 /* Below Sends x264 options to the core library if x264 is selected*/
2585 /* Lets use this as per Nyx, Thanks Nyx!*/
2586 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2587 /* Turbo first pass if two pass and Turbo First pass is selected */
2588 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
2590 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
2591 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
2592 /* append the "Turbo" string variable to the existing opts string.
2593 Note: the "Turbo" string must be appended, not prepended to work properly*/
2594 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
2595 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
2599 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2605 [self writeToActivityLog: "prepareJob reached Picture Settings"];
2606 /* Picture Size Settings */
2607 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2608 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2610 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2611 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2614 /* Here we use the crop values saved at the time the preset was saved */
2615 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2616 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2617 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2618 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2620 [self writeToActivityLog: "prepareJob reached Frame Rate"];
2622 /* Video settings */
2623 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
2625 job->vrate = 27000000;
2626 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
2627 /* We are not same as source so we set job->cfr to 1
2628 * to enable constant frame rate since user has specified
2629 * a specific framerate*/
2634 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
2635 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
2636 /* We are same as source so we set job->cfr to 0
2637 * to enable true same as source framerate */
2640 [self writeToActivityLog: "prepareJob reached Bitrate Video Quality"];
2641 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 0 )
2644 Bitrate should already have been calculated and displayed
2645 in fVidBitrateField, so let's just use it */
2647 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 1 )
2649 job->vquality = -1.0;
2650 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
2652 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
2654 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
2659 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
2660 /* Subtitle settings */
2661 job->subtitle = [[queueToApply objectForKey:@"JobSubtitlesIndex"] intValue] - 2;
2663 [self writeToActivityLog: "prepareJob reached Audio"];
2664 /* Audio tracks and mixdowns */
2665 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2666 int audiotrack_count = hb_list_count(job->list_audio);
2667 for( int i = 0; i < audiotrack_count;i++)
2669 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2670 hb_list_rem(job->list_audio, temp_audio);
2672 /* Now lets add our new tracks to the audio list here */
2673 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
2675 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2676 hb_audio_config_init(audio);
2677 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2678 /* We go ahead and assign values to our audio->out.<properties> */
2679 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2680 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
2681 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
2682 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
2683 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
2684 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
2686 hb_audio_add( job, audio );
2689 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
2692 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2693 hb_audio_config_init(audio);
2694 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2695 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
2696 /* We go ahead and assign values to our audio->out.<properties> */
2697 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2698 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
2699 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
2700 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
2701 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
2702 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
2704 hb_audio_add( job, audio );
2708 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
2710 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2711 hb_audio_config_init(audio);
2712 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2713 /* We go ahead and assign values to our audio->out.<properties> */
2714 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2715 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
2716 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
2717 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
2718 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
2719 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2721 hb_audio_add( job, audio );
2725 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
2727 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2728 hb_audio_config_init(audio);
2729 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2730 /* We go ahead and assign values to our audio->out.<properties> */
2731 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2732 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
2733 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
2734 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
2735 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
2736 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2738 hb_audio_add( job, audio );
2742 /* set vfr according to the Picture Window */
2743 if ([[queueToApply objectForKey:@"VFR"] intValue] == 1)
2752 [self writeToActivityLog: "prepareJob reached Filters"];
2754 job->filters = hb_list_init();
2756 /* Now lets call the filters if applicable.
2757 * The order of the filters is critical
2760 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
2762 hb_list_add( job->filters, &hb_filter_detelecine );
2766 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
2768 /* Run old deinterlacer fd by default */
2769 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"JobPictureDecomb"] UTF8String];
2770 hb_list_add( job->filters, &hb_filter_decomb );
2774 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
2776 /* Run old deinterlacer fd by default */
2777 hb_filter_deinterlace.settings = "-1";
2778 hb_list_add( job->filters, &hb_filter_deinterlace );
2780 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
2782 /* Yadif mode 0 (without spatial deinterlacing.) */
2783 hb_filter_deinterlace.settings = "2";
2784 hb_list_add( job->filters, &hb_filter_deinterlace );
2786 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
2788 /* Yadif (with spatial deinterlacing) */
2789 hb_filter_deinterlace.settings = "0";
2790 hb_list_add( job->filters, &hb_filter_deinterlace );
2794 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
2796 hb_filter_denoise.settings = "2:1:2:3";
2797 hb_list_add( job->filters, &hb_filter_denoise );
2799 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
2801 hb_filter_denoise.settings = "3:2:2:3";
2802 hb_list_add( job->filters, &hb_filter_denoise );
2804 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
2806 hb_filter_denoise.settings = "7:7:5:5";
2807 hb_list_add( job->filters, &hb_filter_denoise );
2810 /* Deblock (uses pp7 default) */
2811 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] == 1)
2813 hb_list_add( job->filters, &hb_filter_deblock );
2815 [self writeToActivityLog: "prepareJob exiting"];
2820 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
2822 - (IBAction) addToQueue: (id) sender
2824 /* We get the destination directory from the destination field here */
2825 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2826 /* We check for a valid destination here */
2827 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2829 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2833 /* We check for duplicate name here */
2834 if( [[NSFileManager defaultManager] fileExistsAtPath:
2835 [fDstFile2Field stringValue]] )
2837 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2838 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2839 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
2840 NULL, NULL, [NSString stringWithFormat:
2841 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2842 [fDstFile2Field stringValue]] );
2843 // overwriteAddToQueueAlertDone: will be called when the alert is dismissed.
2847 [self doAddToQueue];
2851 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
2852 the user if they want to overwrite an exiting movie file.
2854 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
2855 returnCode: (int) returnCode contextInfo: (void *) contextInfo
2857 if( returnCode == NSAlertAlternateReturn )
2858 [self doAddToQueue];
2861 - (void) doAddToQueue
2863 [self addQueueFileItem ];
2868 /* Rip: puts up an alert before ultimately calling doRip
2870 - (IBAction) Rip: (id) sender
2872 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
2873 /* Rip or Cancel ? */
2875 hb_get_state2( fQueueEncodeLibhb, &s );
2877 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
2879 [self Cancel: sender];
2883 // If there are pending jobs in the queue, then this is a rip the queue
2885 if (fPendingCount > 0)
2887 /* here lets start the queue with the first pending item */
2888 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2893 // Before adding jobs to the queue, check for a valid destination.
2895 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2896 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2898 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2902 /* We check for duplicate name here */
2903 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
2905 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2906 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2907 @selector( overWriteAlertDone:returnCode:contextInfo: ),
2908 NULL, NULL, [NSString stringWithFormat:
2909 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2910 [fDstFile2Field stringValue]] );
2912 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
2916 /* if there are no pending jobs in the queue, then add this one to the queue and rip
2917 otherwise, just rip the queue */
2918 if(fPendingCount == 0)
2920 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
2921 [self doAddToQueue];
2924 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2925 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2926 /* go right to processing the new queue encode */
2927 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
2928 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2933 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
2934 want to overwrite an exiting movie file.
2936 - (void) overWriteAlertDone: (NSWindow *) sheet
2937 returnCode: (int) returnCode contextInfo: (void *) contextInfo
2939 if( returnCode == NSAlertAlternateReturn )
2941 /* if there are no jobs in the queue, then add this one to the queue and rip
2942 otherwise, just rip the queue */
2943 if( fPendingCount == 0 )
2945 [self doAddToQueue];
2948 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2949 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2950 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2955 - (void) remindUserOfSleepOrShutdown
2957 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
2959 /*Warn that computer will sleep after encoding*/
2962 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);
2963 [NSApp requestUserAttention:NSCriticalRequest];
2964 if ( reminduser == NSAlertAlternateReturn )
2966 [self showPreferencesWindow:nil];
2969 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
2971 /*Warn that computer will shut down after encoding*/
2974 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);
2975 [NSApp requestUserAttention:NSCriticalRequest];
2976 if ( reminduser == NSAlertAlternateReturn )
2978 [self showPreferencesWindow:nil];
2987 /* Let libhb do the job */
2988 hb_start( fQueueEncodeLibhb );
2989 /*set the fEncodeState State */
2994 //------------------------------------------------------------------------------------
2995 // Cancels and deletes the current job and stops libhb from processing the remaining
2997 //------------------------------------------------------------------------------------
2998 - (void) doCancelCurrentJob
3000 // Stop the current job. hb_stop will only cancel the current pass and then set
3001 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3002 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3003 // remaining passes of the job and then start the queue back up if there are any
3007 hb_stop( fQueueEncodeLibhb );
3008 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3010 // now that we've stopped the currently encoding job, lets mark it as cancelled
3011 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3012 // and as always, save it in the queue .plist...
3013 /* We save all of the Queue data here */
3014 [self saveQueueFileItem];
3015 // so now lets move to
3016 currentQueueEncodeIndex++ ;
3017 // ... and see if there are more items left in our queue
3018 int queueItems = [QueueFileArray count];
3019 /* If we still have more items in our queue, lets go to the next one */
3020 if (currentQueueEncodeIndex < queueItems)
3022 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3023 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3025 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3029 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3034 //------------------------------------------------------------------------------------
3035 // Displays an alert asking user if the want to cancel encoding of current job.
3036 // Cancel: returns immediately after posting the alert. Later, when the user
3037 // acknowledges the alert, doCancelCurrentJob is called.
3038 //------------------------------------------------------------------------------------
3039 - (IBAction)Cancel: (id)sender
3041 if (!fQueueController) return;
3043 hb_pause( fQueueEncodeLibhb );
3044 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3046 // Which window to attach the sheet to?
3047 NSWindow * docWindow;
3048 if ([sender respondsToSelector: @selector(window)])
3049 docWindow = [sender window];
3051 docWindow = fWindow;
3053 NSBeginCriticalAlertSheet(
3055 NSLocalizedString(@"Continue Encoding", nil),
3056 NSLocalizedString(@"Cancel Current and Stop", nil),
3057 NSLocalizedString(@"Cancel Current and Continue", nil),
3059 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3060 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3062 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3065 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3067 hb_resume( fQueueEncodeLibhb );
3068 if (returnCode == NSAlertOtherReturn)
3070 [self doCancelCurrentJob]; // <- this also stops libhb
3072 if (returnCode == NSAlertAlternateReturn)
3074 [self doCancelCurrentJobAndStop];
3078 - (void) doCancelCurrentJobAndStop
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 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3092 - (IBAction) Pause: (id) sender
3095 hb_get_state2( fQueueEncodeLibhb, &s );
3097 if( s.state == HB_STATE_PAUSED )
3099 hb_resume( fQueueEncodeLibhb );
3103 hb_pause( fQueueEncodeLibhb );
3108 #pragma mark GUI Controls Changed Methods
3110 - (IBAction) titlePopUpChanged: (id) sender
3112 hb_list_t * list = hb_get_titles( fHandle );
3113 hb_title_t * title = (hb_title_t*)
3114 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3116 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3117 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3119 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3120 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3121 [browsedSourceDisplayName stringByDeletingPathExtension],
3123 [[fDstFile2Field stringValue] pathExtension]]];
3126 /* Update chapter popups */
3127 [fSrcChapterStartPopUp removeAllItems];
3128 [fSrcChapterEndPopUp removeAllItems];
3129 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
3131 [fSrcChapterStartPopUp addItemWithTitle: [NSString
3132 stringWithFormat: @"%d", i + 1]];
3133 [fSrcChapterEndPopUp addItemWithTitle: [NSString
3134 stringWithFormat: @"%d", i + 1]];
3137 [fSrcChapterStartPopUp selectItemAtIndex: 0];
3138 [fSrcChapterEndPopUp selectItemAtIndex:
3139 hb_list_count( title->list_chapter ) - 1];
3140 [self chapterPopUpChanged:nil];
3142 /* Start Get and set the initial pic size for display */
3143 hb_job_t * job = title->job;
3146 /*Set Source Size Field Here */
3147 [fPicSettingsSrc setStringValue: [NSString stringWithFormat: @"%d x %d", fTitle->width, fTitle->height]];
3149 /* Set Auto Crop to on upon selecting a new title */
3150 [fPictureController setAutoCrop:YES];
3152 /* We get the originial output picture width and height and put them
3153 in variables for use with some presets later on */
3154 PicOrigOutputWidth = job->width;
3155 PicOrigOutputHeight = job->height;
3156 AutoCropTop = job->crop[0];
3157 AutoCropBottom = job->crop[1];
3158 AutoCropLeft = job->crop[2];
3159 AutoCropRight = job->crop[3];
3161 /* Run Through encoderPopUpChanged to see if there
3162 needs to be any pic value modifications based on encoder settings */
3163 //[self encoderPopUpChanged: NULL];
3164 /* END Get and set the initial pic size for display */
3166 /* Update subtitle popups */
3167 hb_subtitle_t * subtitle;
3168 [fSubPopUp removeAllItems];
3169 [fSubPopUp addItemWithTitle: @"None"];
3170 [fSubPopUp addItemWithTitle: @"Autoselect"];
3171 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
3173 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
3175 /* We cannot use NSPopUpButton's addItemWithTitle because
3176 it checks for duplicate entries */
3177 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
3178 subtitle->lang] action: NULL keyEquivalent: @""];
3180 [fSubPopUp selectItemAtIndex: 0];
3182 [self subtitleSelectionChanged:nil];
3184 /* Update chapter table */
3185 [fChapterTitlesDelegate resetWithTitle:title];
3186 [fChapterTable reloadData];
3188 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3189 int audiotrack_count = hb_list_count(job->list_audio);
3190 for( int i = 0; i < audiotrack_count;i++)
3192 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3193 hb_list_rem(job->list_audio, temp_audio);
3196 /* Update audio popups */
3197 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
3198 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
3199 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
3200 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
3201 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
3202 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
3203 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
3204 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3205 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3206 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3208 /* changing the title may have changed the audio channels on offer, */
3209 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3210 [self audioTrackPopUpChanged: fAudLang1PopUp];
3211 [self audioTrackPopUpChanged: fAudLang2PopUp];
3212 [self audioTrackPopUpChanged: fAudLang3PopUp];
3213 [self audioTrackPopUpChanged: fAudLang4PopUp];
3215 [fVidRatePopUp selectItemAtIndex: 0];
3217 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
3218 [self calculatePictureSizing:nil];
3220 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
3221 [self selectPreset:nil];
3224 - (IBAction) chapterPopUpChanged: (id) sender
3227 /* If start chapter popup is greater than end chapter popup,
3228 we set the end chapter popup to the same as start chapter popup */
3229 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
3231 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
3235 hb_list_t * list = hb_get_titles( fHandle );
3236 hb_title_t * title = (hb_title_t *)
3237 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3239 hb_chapter_t * chapter;
3240 int64_t duration = 0;
3241 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
3242 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
3244 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3245 duration += chapter->duration;
3248 duration /= 90000; /* pts -> seconds */
3249 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
3250 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
3253 [self calculateBitrate: sender];
3256 - (IBAction) formatPopUpChanged: (id) sender
3258 NSString * string = [fDstFile2Field stringValue];
3259 int format = [fDstFormatPopUp indexOfSelectedItem];
3261 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
3262 [fDstMp4LargeFileCheck setHidden: YES];
3263 [fDstMp4HttpOptFileCheck setHidden: YES];
3264 [fDstMp4iPodFileCheck setHidden: YES];
3266 /* Update the Video Codec PopUp */
3267 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
3268 [fVidEncoderPopUp removeAllItems];
3269 NSMenuItem *menuItem;
3270 /* These video encoders are available to all of our current muxers, so lets list them once here */
3271 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
3272 [menuItem setTag: HB_VCODEC_FFMPEG];
3274 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (XviD)" action: NULL keyEquivalent: @""];
3275 [menuItem setTag: HB_VCODEC_XVID];
3279 /*Get Default MP4 File Extension*/
3280 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
3288 /* Add additional video encoders here */
3289 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3290 [menuItem setTag: HB_VCODEC_X264];
3291 /* We show the mp4 option checkboxes here since we are mp4 */
3292 [fCreateChapterMarkers setEnabled: YES];
3293 [fDstMp4LargeFileCheck setHidden: NO];
3294 [fDstMp4HttpOptFileCheck setHidden: NO];
3295 [fDstMp4iPodFileCheck setHidden: NO];
3300 /* Add additional video encoders here */
3301 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3302 [menuItem setTag: HB_VCODEC_X264];
3303 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3304 [menuItem setTag: HB_VCODEC_THEORA];
3305 /* We enable the create chapters checkbox here */
3306 [fCreateChapterMarkers setEnabled: YES];
3311 /* Add additional video encoders here */
3312 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3313 [menuItem setTag: HB_VCODEC_X264];
3314 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3315 [fCreateChapterMarkers setEnabled: NO];
3316 [fCreateChapterMarkers setState: NSOffState];
3321 /* Add additional video encoders here */
3322 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3323 [menuItem setTag: HB_VCODEC_THEORA];
3324 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3325 [fCreateChapterMarkers setEnabled: NO];
3326 [fCreateChapterMarkers setState: NSOffState];
3329 [fVidEncoderPopUp selectItemAtIndex: 0];
3331 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
3332 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
3333 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
3334 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
3337 [self autoSetM4vExtension: sender];
3339 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
3341 if( SuccessfulScan )
3343 /* Add/replace to the correct extension */
3344 [self audioTrackPopUpChanged: fAudLang1PopUp];
3345 [self audioTrackPopUpChanged: fAudLang2PopUp];
3346 [self audioTrackPopUpChanged: fAudLang3PopUp];
3347 [self audioTrackPopUpChanged: fAudLang4PopUp];
3349 if( [fVidEncoderPopUp selectedItem] == nil )
3352 [fVidEncoderPopUp selectItemAtIndex:0];
3353 [self videoEncoderPopUpChanged:nil];
3355 /* changing the format may mean that we can / can't offer mono or 6ch, */
3356 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3358 /* We call the method to properly enable/disable turbo 2 pass */
3359 [self twoPassCheckboxChanged: sender];
3360 /* We call method method to change UI to reflect whether a preset is used or not*/
3363 [self customSettingUsed: sender];
3366 - (IBAction) autoSetM4vExtension: (id) sender
3368 if ( [fDstFormatPopUp indexOfSelectedItem] )
3371 NSString * extension = @"mp4";
3373 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3374 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3375 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3376 [fCreateChapterMarkers state] == NSOnState ||
3377 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
3382 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
3385 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
3386 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
3389 - (void) shouldEnableHttpMp4CheckBox: (id) sender
3391 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3392 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3393 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 )
3394 [fDstMp4HttpOptFileCheck setEnabled: NO];
3396 [fDstMp4HttpOptFileCheck setEnabled: YES];
3399 /* Method to determine if we should change the UI
3400 To reflect whether or not a Preset is being used or if
3401 the user is using "Custom" settings by determining the sender*/
3402 - (IBAction) customSettingUsed: (id) sender
3404 if ([sender stringValue])
3406 /* Deselect the currently selected Preset if there is one*/
3407 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
3408 /* Change UI to show "Custom" settings are being used */
3409 [fPresetSelectedDisplay setStringValue: @"Custom"];
3411 curUserPresetChosenNum = nil;
3417 #pragma mark - Video
3419 - (IBAction) videoEncoderPopUpChanged: (id) sender
3421 hb_job_t * job = fTitle->job;
3422 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
3424 [fAdvancedOptions setHidden:YES];
3425 /* If we are using x264 then show the x264 advanced panel*/
3426 if (videoEncoder == HB_VCODEC_X264)
3428 [fAdvancedOptions setHidden:NO];
3429 [self autoSetM4vExtension: sender];
3432 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
3433 is being used as it borks up loose anamorphic .
3434 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
3435 to use the index itself but this is easier */
3436 if (videoEncoder == HB_VCODEC_FFMPEG)
3438 if (job->pixel_ratio == 2)
3440 job->pixel_ratio = 0;
3442 [fPictureController setAllowLooseAnamorphic:NO];
3443 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
3444 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
3445 anything other than MP4.
3447 [fDstMp4iPodFileCheck setEnabled: NO];
3448 [fDstMp4iPodFileCheck setState: NSOffState];
3452 [fPictureController setAllowLooseAnamorphic:YES];
3453 [fDstMp4iPodFileCheck setEnabled: YES];
3456 [self calculatePictureSizing: sender];
3457 [self twoPassCheckboxChanged: sender];
3461 - (IBAction) twoPassCheckboxChanged: (id) sender
3463 /* check to see if x264 is chosen */
3464 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
3466 if( [fVidTwoPassCheck state] == NSOnState)
3468 [fVidTurboPassCheck setHidden: NO];
3472 [fVidTurboPassCheck setHidden: YES];
3473 [fVidTurboPassCheck setState: NSOffState];
3475 /* Make sure Two Pass is checked if Turbo is checked */
3476 if( [fVidTurboPassCheck state] == NSOnState)
3478 [fVidTwoPassCheck setState: NSOnState];
3483 [fVidTurboPassCheck setHidden: YES];
3484 [fVidTurboPassCheck setState: NSOffState];
3487 /* We call method method to change UI to reflect whether a preset is used or not*/
3488 [self customSettingUsed: sender];
3491 - (IBAction ) videoFrameRateChanged: (id) sender
3493 /* We call method method to calculatePictureSizing to error check detelecine*/
3494 [self calculatePictureSizing: sender];
3496 /* We call method method to change UI to reflect whether a preset is used or not*/
3497 [self customSettingUsed: sender];
3499 - (IBAction) videoMatrixChanged: (id) sender;
3501 bool target, bitrate, quality;
3503 target = bitrate = quality = false;
3504 if( [fVidQualityMatrix isEnabled] )
3506 switch( [fVidQualityMatrix selectedRow] )
3519 [fVidTargetSizeField setEnabled: target];
3520 [fVidBitrateField setEnabled: bitrate];
3521 [fVidQualitySlider setEnabled: quality];
3522 [fVidTwoPassCheck setEnabled: !quality &&
3523 [fVidQualityMatrix isEnabled]];
3526 [fVidTwoPassCheck setState: NSOffState];
3527 [fVidTurboPassCheck setHidden: YES];
3528 [fVidTurboPassCheck setState: NSOffState];
3531 [self qualitySliderChanged: sender];
3532 [self calculateBitrate: sender];
3533 [self customSettingUsed: sender];
3536 - (IBAction) qualitySliderChanged: (id) sender
3538 [fVidConstantCell setTitle: [NSString stringWithFormat:
3539 NSLocalizedString( @"Constant quality: %.0f %%", @"" ), 100.0 *
3540 [fVidQualitySlider floatValue]]];
3541 [self customSettingUsed: sender];
3544 - (void) controlTextDidChange: (NSNotification *) notification
3546 [self calculateBitrate:nil];
3549 - (IBAction) calculateBitrate: (id) sender
3551 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
3556 hb_list_t * list = hb_get_titles( fHandle );
3557 hb_title_t * title = (hb_title_t *) hb_list_item( list,
3558 [fSrcTitlePopUp indexOfSelectedItem] );
3559 hb_job_t * job = title->job;
3561 [fVidBitrateField setIntValue: hb_calc_bitrate( job,
3562 [fVidTargetSizeField intValue] )];
3566 #pragma mark - Picture
3568 /* lets set the picture size back to the max from right after title scan
3569 Lets use an IBAction here as down the road we could always use a checkbox
3570 in the gui to easily take the user back to max. Remember, the compiler
3571 resolves IBActions down to -(void) during compile anyway */
3572 - (IBAction) revertPictureSizeToMax: (id) sender
3574 hb_job_t * job = fTitle->job;
3575 /* We use the output picture width and height
3576 as calculated from libhb right after title is set
3577 in TitlePopUpChanged */
3578 job->width = PicOrigOutputWidth;
3579 job->height = PicOrigOutputHeight;
3580 [fPictureController setAutoCrop:YES];
3581 /* Here we use the auto crop values determined right after scan */
3582 job->crop[0] = AutoCropTop;
3583 job->crop[1] = AutoCropBottom;
3584 job->crop[2] = AutoCropLeft;
3585 job->crop[3] = AutoCropRight;
3588 [self calculatePictureSizing: sender];
3589 /* We call method to change UI to reflect whether a preset is used or not*/
3590 [self customSettingUsed: sender];
3594 * Registers changes made in the Picture Settings Window.
3597 - (void)pictureSettingsDidChange {
3598 [self calculatePictureSizing:nil];
3601 /* Get and Display Current Pic Settings in main window */
3602 - (IBAction) calculatePictureSizing: (id) sender
3604 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", fTitle->job->width, fTitle->job->height]];
3606 if (fTitle->job->pixel_ratio == 1)
3608 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
3609 int arpwidth = fTitle->job->pixel_aspect_width;
3610 int arpheight = fTitle->job->pixel_aspect_height;
3611 int displayparwidth = titlewidth * arpwidth / arpheight;
3612 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
3613 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", titlewidth, displayparheight]];
3614 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Strict", displayparwidth, displayparheight]];
3615 fTitle->job->keep_ratio = 0;
3617 else if (fTitle->job->pixel_ratio == 2)
3619 hb_job_t * job = fTitle->job;
3620 int output_width, output_height, output_par_width, output_par_height;
3621 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
3623 display_width = output_width * output_par_width / output_par_height;
3625 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", output_width, output_height]];
3626 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Loose", display_width, output_height]];
3628 fTitle->job->keep_ratio = 0;
3632 [fPicSettingsAnamorphic setStringValue:@"Off"];
3635 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
3636 if (fTitle->job->keep_ratio > 0)
3638 [fPicSettingARkeep setStringValue: @"On"];
3642 [fPicSettingARkeep setStringValue: @"Off"];
3646 if ([fPictureController detelecine]) {
3647 [fPicSettingDetelecine setStringValue: @"Yes"];
3650 [fPicSettingDetelecine setStringValue: @"No"];
3654 if ([fPictureController decomb] == 0)
3656 [fPicSettingDecomb setStringValue: @"Off"];
3658 else if ([fPictureController decomb] == 1)
3660 [fPicSettingDecomb setStringValue: @"1:2:6:9:80:16:16"];
3662 else if ([fPictureController decomb] == 2)
3664 [fPicSettingDecomb setStringValue:[[NSUserDefaults standardUserDefaults] stringForKey:@"DecombCustomString"]];
3667 /* VFR (Variable Frame Rate) */
3668 if ([fPictureController vfr]) {
3669 /* We change the string of the fps popup to warn that vfr is on Framerate (FPS): */
3670 [fVidRateField setStringValue: @"Framerate (VFR On):"];
3671 /* for VFR we select same as source (or title framerate) and disable the popup.
3672 * We know its index 0 as that is determined in titlePopUpChanged */
3673 [fVidRatePopUp selectItemAtIndex: 0];
3674 [fVidRatePopUp setEnabled: NO];
3678 /* make sure the label for framerate is set to its default */
3679 [fVidRateField setStringValue: @"Framerate (FPS):"];
3680 [fVidRatePopUp setEnabled: YES];
3684 if ([fPictureController deinterlace] == 0)
3686 [fPicSettingDeinterlace setStringValue: @"Off"];
3688 else if ([fPictureController deinterlace] == 1)
3690 [fPicSettingDeinterlace setStringValue: @"Fast"];
3692 else if ([fPictureController deinterlace] == 2)
3694 [fPicSettingDeinterlace setStringValue: @"Slow"];
3696 else if ([fPictureController deinterlace] == 3)
3698 [fPicSettingDeinterlace setStringValue: @"Slower"];
3702 if ([fPictureController denoise] == 0)
3704 [fPicSettingDenoise setStringValue: @"Off"];
3706 else if ([fPictureController denoise] == 1)
3708 [fPicSettingDenoise setStringValue: @"Weak"];
3710 else if ([fPictureController denoise] == 2)
3712 [fPicSettingDenoise setStringValue: @"Medium"];
3714 else if ([fPictureController denoise] == 3)
3716 [fPicSettingDenoise setStringValue: @"Strong"];
3720 if ([fPictureController deblock]) {
3721 [fPicSettingDeblock setStringValue: @"Yes"];
3724 [fPicSettingDeblock setStringValue: @"No"];
3727 if (fTitle->job->pixel_ratio > 0)
3729 [fPicSettingPAR setStringValue: @""];
3733 [fPicSettingPAR setStringValue: @"Off"];
3736 /* Set the display field for crop as per boolean */
3737 if (![fPictureController autoCrop])
3739 [fPicSettingAutoCrop setStringValue: @"Custom"];
3743 [fPicSettingAutoCrop setStringValue: @"Auto"];
3751 #pragma mark - Audio and Subtitles
3752 - (IBAction) audioCodecsPopUpChanged: (id) sender
3755 NSPopUpButton * audiotrackPopUp;
3756 NSPopUpButton * sampleratePopUp;
3757 NSPopUpButton * bitratePopUp;
3758 NSPopUpButton * audiocodecPopUp;
3759 if (sender == fAudTrack1CodecPopUp)
3761 audiotrackPopUp = fAudLang1PopUp;
3762 audiocodecPopUp = fAudTrack1CodecPopUp;
3763 sampleratePopUp = fAudTrack1RatePopUp;
3764 bitratePopUp = fAudTrack1BitratePopUp;
3766 else if (sender == fAudTrack2CodecPopUp)
3768 audiotrackPopUp = fAudLang2PopUp;
3769 audiocodecPopUp = fAudTrack2CodecPopUp;
3770 sampleratePopUp = fAudTrack2RatePopUp;
3771 bitratePopUp = fAudTrack2BitratePopUp;
3773 else if (sender == fAudTrack3CodecPopUp)
3775 audiotrackPopUp = fAudLang3PopUp;
3776 audiocodecPopUp = fAudTrack3CodecPopUp;
3777 sampleratePopUp = fAudTrack3RatePopUp;
3778 bitratePopUp = fAudTrack3BitratePopUp;
3782 audiotrackPopUp = fAudLang4PopUp;
3783 audiocodecPopUp = fAudTrack4CodecPopUp;
3784 sampleratePopUp = fAudTrack4RatePopUp;
3785 bitratePopUp = fAudTrack4BitratePopUp;
3788 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
3789 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3790 [self audioTrackPopUpChanged: audiotrackPopUp];
3794 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
3796 /* We will be setting the enabled/disabled state of each tracks audio controls based on
3797 * the settings of the source audio for that track. We leave the samplerate and bitrate
3798 * to audiotrackMixdownChanged
3801 /* We will first verify that a lower track number has been selected before enabling each track
3802 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
3804 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3806 [fAudLang2PopUp setEnabled: NO];
3807 [fAudLang2PopUp selectItemAtIndex: 0];
3811 [fAudLang2PopUp setEnabled: YES];
3814 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3816 [fAudLang3PopUp setEnabled: NO];
3817 [fAudLang3PopUp selectItemAtIndex: 0];
3821 [fAudLang3PopUp setEnabled: YES];
3823 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3825 [fAudLang4PopUp setEnabled: NO];
3826 [fAudLang4PopUp selectItemAtIndex: 0];
3830 [fAudLang4PopUp setEnabled: YES];
3832 /* enable/disable the mixdown text and popupbutton for audio track 1 */
3833 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3834 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3835 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3836 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3837 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3838 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3839 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3841 [fAudTrack1CodecPopUp removeAllItems];
3842 [fAudTrack1MixPopUp removeAllItems];
3843 [fAudTrack1RatePopUp removeAllItems];
3844 [fAudTrack1BitratePopUp removeAllItems];
3845 [fAudTrack1DrcSlider setFloatValue: 1.00];
3846 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
3848 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3850 [fAudTrack1RatePopUp setEnabled: NO];
3851 [fAudTrack1BitratePopUp setEnabled: NO];
3852 [fAudTrack1DrcSlider setEnabled: NO];
3853 [fAudTrack1DrcField setEnabled: NO];
3856 /* enable/disable the mixdown text and popupbutton for audio track 2 */
3857 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3858 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3859 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3860 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3861 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3862 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3863 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3865 [fAudTrack2CodecPopUp removeAllItems];
3866 [fAudTrack2MixPopUp removeAllItems];
3867 [fAudTrack2RatePopUp removeAllItems];
3868 [fAudTrack2BitratePopUp removeAllItems];
3869 [fAudTrack2DrcSlider setFloatValue: 1.00];
3870 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
3872 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3874 [fAudTrack2RatePopUp setEnabled: NO];
3875 [fAudTrack2BitratePopUp setEnabled: NO];
3876 [fAudTrack2DrcSlider setEnabled: NO];
3877 [fAudTrack2DrcField setEnabled: NO];
3880 /* enable/disable the mixdown text and popupbutton for audio track 3 */
3881 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3882 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3883 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3884 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3885 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3886 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3887 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3889 [fAudTrack3CodecPopUp removeAllItems];
3890 [fAudTrack3MixPopUp removeAllItems];
3891 [fAudTrack3RatePopUp removeAllItems];
3892 [fAudTrack3BitratePopUp removeAllItems];
3893 [fAudTrack3DrcSlider setFloatValue: 1.00];
3894 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
3896 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3898 [fAudTrack3RatePopUp setEnabled: NO];
3899 [fAudTrack3BitratePopUp setEnabled: NO];
3900 [fAudTrack3DrcSlider setEnabled: NO];
3901 [fAudTrack3DrcField setEnabled: NO];
3904 /* enable/disable the mixdown text and popupbutton for audio track 4 */
3905 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3906 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3907 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3908 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3909 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3910 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3911 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
3913 [fAudTrack4CodecPopUp removeAllItems];
3914 [fAudTrack4MixPopUp removeAllItems];
3915 [fAudTrack4RatePopUp removeAllItems];
3916 [fAudTrack4BitratePopUp removeAllItems];
3917 [fAudTrack4DrcSlider setFloatValue: 1.00];
3918 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
3920 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3922 [fAudTrack4RatePopUp setEnabled: NO];
3923 [fAudTrack4BitratePopUp setEnabled: NO];
3924 [fAudTrack4DrcSlider setEnabled: NO];
3925 [fAudTrack4DrcField setEnabled: NO];
3930 - (IBAction) addAllAudioTracksToPopUp: (id) sender
3933 hb_list_t * list = hb_get_titles( fHandle );
3934 hb_title_t * title = (hb_title_t*)
3935 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3937 hb_audio_config_t * audio;
3939 [sender removeAllItems];
3940 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
3941 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
3943 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
3944 [[sender menu] addItemWithTitle:
3945 [NSString stringWithCString: audio->lang.description]
3946 action: NULL keyEquivalent: @""];
3948 [sender selectItemAtIndex: 0];
3952 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
3955 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
3956 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
3957 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
3958 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
3960 if (searchPrefixString)
3963 for( int i = 0; i < [sender numberOfItems]; i++ )
3965 /* Try to find the desired search string */
3966 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
3968 [sender selectItemAtIndex: i];
3972 /* couldn't find the string, so select the requested "search string not found" item */
3973 /* index of 0 means select the "none" item */
3974 /* index of 1 means select the first audio track */
3975 [sender selectItemAtIndex: selectIndexIfNotFound];
3979 /* if no search string is provided, then select the selectIndexIfNotFound item */
3980 [sender selectItemAtIndex: selectIndexIfNotFound];
3984 - (IBAction) audioAddAudioTrackCodecs: (id)sender
3986 int format = [fDstFormatPopUp indexOfSelectedItem];
3988 /* setup pointers to the appropriate popups for the correct track */
3989 NSPopUpButton * audiocodecPopUp;
3990 NSPopUpButton * audiotrackPopUp;
3991 if (sender == fAudTrack1CodecPopUp)
3993 audiotrackPopUp = fAudLang1PopUp;
3994 audiocodecPopUp = fAudTrack1CodecPopUp;
3996 else if (sender == fAudTrack2CodecPopUp)
3998 audiotrackPopUp = fAudLang2PopUp;
3999 audiocodecPopUp = fAudTrack2CodecPopUp;
4001 else if (sender == fAudTrack3CodecPopUp)
4003 audiotrackPopUp = fAudLang3PopUp;
4004 audiocodecPopUp = fAudTrack3CodecPopUp;
4008 audiotrackPopUp = fAudLang4PopUp;
4009 audiocodecPopUp = fAudTrack4CodecPopUp;
4012 [audiocodecPopUp removeAllItems];
4013 /* Make sure "None" isnt selected in the source track */
4014 if ([audiotrackPopUp indexOfSelectedItem] > 0)
4016 [audiocodecPopUp setEnabled:YES];
4017 NSMenuItem *menuItem;
4018 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
4024 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4025 [menuItem setTag: HB_ACODEC_FAAC];
4028 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4029 [menuItem setTag: HB_ACODEC_AC3];
4035 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4036 [menuItem setTag: HB_ACODEC_FAAC];
4038 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4039 [menuItem setTag: HB_ACODEC_AC3];
4041 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4042 [menuItem setTag: HB_ACODEC_LAME];
4044 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4045 [menuItem setTag: HB_ACODEC_VORBIS];
4051 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4052 [menuItem setTag: HB_ACODEC_LAME];
4054 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4055 [menuItem setTag: HB_ACODEC_AC3];
4061 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4062 [menuItem setTag: HB_ACODEC_VORBIS];
4064 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4065 [menuItem setTag: HB_ACODEC_LAME];
4068 [audiocodecPopUp selectItemAtIndex:0];
4072 [audiocodecPopUp setEnabled:NO];
4076 - (IBAction) audioTrackPopUpChanged: (id) sender
4078 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
4079 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
4082 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
4085 /* make sure we have a selected title before continuing */
4086 if (fTitle == NULL) return;
4087 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
4088 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
4090 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
4092 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4094 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
4096 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4098 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
4100 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4102 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
4104 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4107 /* Now lets make the sender the appropriate Audio Track popup from this point on */
4108 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
4110 sender = fAudLang1PopUp;
4112 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
4114 sender = fAudLang2PopUp;
4116 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
4118 sender = fAudLang3PopUp;
4120 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
4122 sender = fAudLang4PopUp;
4125 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
4126 NSPopUpButton * mixdownPopUp;
4127 NSPopUpButton * audiocodecPopUp;
4128 NSPopUpButton * sampleratePopUp;
4129 NSPopUpButton * bitratePopUp;
4130 if (sender == fAudLang1PopUp)
4132 mixdownPopUp = fAudTrack1MixPopUp;
4133 audiocodecPopUp = fAudTrack1CodecPopUp;
4134 sampleratePopUp = fAudTrack1RatePopUp;
4135 bitratePopUp = fAudTrack1BitratePopUp;
4137 else if (sender == fAudLang2PopUp)
4139 mixdownPopUp = fAudTrack2MixPopUp;
4140 audiocodecPopUp = fAudTrack2CodecPopUp;
4141 sampleratePopUp = fAudTrack2RatePopUp;
4142 bitratePopUp = fAudTrack2BitratePopUp;
4144 else if (sender == fAudLang3PopUp)
4146 mixdownPopUp = fAudTrack3MixPopUp;
4147 audiocodecPopUp = fAudTrack3CodecPopUp;
4148 sampleratePopUp = fAudTrack3RatePopUp;
4149 bitratePopUp = fAudTrack3BitratePopUp;
4153 mixdownPopUp = fAudTrack4MixPopUp;
4154 audiocodecPopUp = fAudTrack4CodecPopUp;
4155 sampleratePopUp = fAudTrack4RatePopUp;
4156 bitratePopUp = fAudTrack4BitratePopUp;
4159 /* get the index of the selected audio Track*/
4160 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
4162 /* pointer for the hb_audio_s struct we will use later on */
4163 hb_audio_config_t * audio;
4166 /* check if the audio mixdown controls need their enabled state changing */
4167 [self setEnabledStateOfAudioMixdownControls:nil];
4169 if (thisAudioIndex != -1)
4173 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
4175 /* actually manipulate the proper mixdowns here */
4176 /* delete the previous audio mixdown options */
4177 [mixdownPopUp removeAllItems];
4179 acodec = [[audiocodecPopUp selectedItem] tag];
4184 /* find out if our selected output audio codec supports mono and / or 6ch */
4185 /* we also check for an input codec of AC3 or DCA,
4186 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
4187 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
4188 but this may change in the future, so they are separated for flexibility */
4189 int audioCodecsSupportMono =
4190 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4191 (acodec != HB_ACODEC_LAME);
4192 int audioCodecsSupport6Ch =
4193 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4194 (acodec != HB_ACODEC_LAME);
4196 /* check for AC-3 passthru */
4197 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4200 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4201 [NSString stringWithCString: "AC3 Passthru"]
4202 action: NULL keyEquivalent: @""];
4203 [menuItem setTag: HB_ACODEC_AC3];
4208 /* add the appropriate audio mixdown menuitems to the popupbutton */
4209 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
4210 so that we can reference the mixdown later */
4212 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
4213 int minMixdownUsed = 0;
4214 int maxMixdownUsed = 0;
4216 /* get the input channel layout without any lfe channels */
4217 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4219 /* do we want to add a mono option? */
4220 if (audioCodecsSupportMono == 1)
4222 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4223 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
4224 action: NULL keyEquivalent: @""];
4225 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
4226 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
4227 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
4230 /* do we want to add a stereo option? */
4231 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
4232 /* also offer stereo if we have a stereo-or-better source */
4233 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
4235 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4236 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
4237 action: NULL keyEquivalent: @""];
4238 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
4239 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
4240 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
4243 /* do we want to add a dolby surround (DPL1) option? */
4244 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
4246 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4247 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
4248 action: NULL keyEquivalent: @""];
4249 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
4250 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
4251 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
4254 /* do we want to add a dolby pro logic 2 (DPL2) option? */
4255 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
4257 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4258 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
4259 action: NULL keyEquivalent: @""];
4260 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
4261 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
4262 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
4265 /* do we want to add a 6-channel discrete option? */
4266 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
4268 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4269 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
4270 action: NULL keyEquivalent: @""];
4271 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
4272 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
4273 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
4276 /* do we want to add an AC-3 passthrough option? */
4277 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4279 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4280 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
4281 action: NULL keyEquivalent: @""];
4282 [menuItem setTag: HB_ACODEC_AC3];
4283 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
4284 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
4287 /* auto-select the best mixdown based on our saved mixdown preference */
4289 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
4290 /* ultimately this should be a prefs option */
4293 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
4294 if (mixdownToUse > 0)
4296 useMixdown = mixdownToUse;
4300 useMixdown = HB_AMIXDOWN_DOLBYPLII;
4303 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
4304 if (useMixdown > maxMixdownUsed)
4306 useMixdown = maxMixdownUsed;
4309 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
4310 if (useMixdown < minMixdownUsed)
4312 useMixdown = minMixdownUsed;
4315 /* select the (possibly-amended) preferred mixdown */
4316 [mixdownPopUp selectItemWithTag: useMixdown];
4319 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
4320 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
4323 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
4325 /* If we are using the avi container, we select MP3 as there is no aac available*/
4326 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
4328 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
4332 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
4335 /* Setup our samplerate and bitrate popups we will need based on mixdown */
4336 [self audioTrackMixdownChanged: mixdownPopUp];
4340 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
4342 [self autoSetM4vExtension: sender];
4343 [self shouldEnableHttpMp4CheckBox: sender];
4347 - (IBAction) audioTrackMixdownChanged: (id) sender
4351 /* setup pointers to all of the other audio track controls
4352 * we will need later
4354 NSPopUpButton * mixdownPopUp;
4355 NSPopUpButton * sampleratePopUp;
4356 NSPopUpButton * bitratePopUp;
4357 NSPopUpButton * audiocodecPopUp;
4358 NSPopUpButton * audiotrackPopUp;
4359 NSSlider * drcSlider;
4360 NSTextField * drcField;
4361 if (sender == fAudTrack1MixPopUp)
4363 audiotrackPopUp = fAudLang1PopUp;
4364 audiocodecPopUp = fAudTrack1CodecPopUp;
4365 mixdownPopUp = fAudTrack1MixPopUp;
4366 sampleratePopUp = fAudTrack1RatePopUp;
4367 bitratePopUp = fAudTrack1BitratePopUp;
4368 drcSlider = fAudTrack1DrcSlider;
4369 drcField = fAudTrack1DrcField;
4371 else if (sender == fAudTrack2MixPopUp)
4373 audiotrackPopUp = fAudLang2PopUp;
4374 audiocodecPopUp = fAudTrack2CodecPopUp;
4375 mixdownPopUp = fAudTrack2MixPopUp;
4376 sampleratePopUp = fAudTrack2RatePopUp;
4377 bitratePopUp = fAudTrack2BitratePopUp;
4378 drcSlider = fAudTrack2DrcSlider;
4379 drcField = fAudTrack2DrcField;
4381 else if (sender == fAudTrack3MixPopUp)
4383 audiotrackPopUp = fAudLang3PopUp;
4384 audiocodecPopUp = fAudTrack3CodecPopUp;
4385 mixdownPopUp = fAudTrack3MixPopUp;
4386 sampleratePopUp = fAudTrack3RatePopUp;
4387 bitratePopUp = fAudTrack3BitratePopUp;
4388 drcSlider = fAudTrack3DrcSlider;
4389 drcField = fAudTrack3DrcField;
4393 audiotrackPopUp = fAudLang4PopUp;
4394 audiocodecPopUp = fAudTrack4CodecPopUp;
4395 mixdownPopUp = fAudTrack4MixPopUp;
4396 sampleratePopUp = fAudTrack4RatePopUp;
4397 bitratePopUp = fAudTrack4BitratePopUp;
4398 drcSlider = fAudTrack4DrcSlider;
4399 drcField = fAudTrack4DrcField;
4401 acodec = [[audiocodecPopUp selectedItem] tag];
4402 /* storage variable for the min and max bitrate allowed for this codec */
4408 case HB_ACODEC_FAAC:
4409 /* check if we have a 6ch discrete conversion in either audio track */
4410 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4412 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
4414 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4420 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
4422 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
4423 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
4428 case HB_ACODEC_LAME:
4429 /* Lame is happy using our min bitrate of 32 kbps */
4431 /* Lame won't encode if the bitrate is higher than 320 kbps */
4435 case HB_ACODEC_VORBIS:
4436 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4438 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
4440 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4446 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
4448 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
4454 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
4460 /* make sure we have a selected title before continuing */
4461 if (fTitle == NULL) return;
4462 /* get the audio so we can find out what input rates are*/
4463 hb_audio_config_t * audio;
4464 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
4465 int inputbitrate = audio->in.bitrate / 1000;
4466 int inputsamplerate = audio->in.samplerate;
4468 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3)
4470 [bitratePopUp removeAllItems];
4472 for( int i = 0; i < hb_audio_bitrates_count; i++ )
4474 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
4476 /* add a new menuitem for this bitrate */
4477 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4478 [NSString stringWithCString: hb_audio_bitrates[i].string]
4479 action: NULL keyEquivalent: @""];
4480 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
4481 [menuItem setTag: hb_audio_bitrates[i].rate];
4485 /* select the default bitrate (but use 384 for 6-ch AAC) */
4486 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4488 [bitratePopUp selectItemWithTag: 384];
4492 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
4495 /* populate and set the sample rate popup */
4496 /* Audio samplerate */
4497 [sampleratePopUp removeAllItems];
4498 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
4499 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
4500 [menuItem setTag: inputsamplerate];
4502 for( int i = 0; i < hb_audio_rates_count; i++ )
4504 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
4505 [NSString stringWithCString: hb_audio_rates[i].string]
4506 action: NULL keyEquivalent: @""];
4507 [menuItem setTag: hb_audio_rates[i].rate];
4509 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
4510 * and there is no compelling reason to use anything else as default, though the users default
4511 * preset will likely override any setting chosen here.
4513 [sampleratePopUp selectItemWithTag: inputsamplerate];
4516 /* Since AC3 Pass Thru uses the input ac3 bitrate and sample rate, we get the input tracks
4517 * bitrate and dispay it in the bitrate popup even though libhb happily ignores any bitrate input from
4518 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
4520 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3)
4523 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
4524 [bitratePopUp removeAllItems];
4525 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4526 [NSString stringWithFormat:@"%d", inputbitrate]
4527 action: NULL keyEquivalent: @""];
4528 [menuItem setTag: inputbitrate];
4529 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
4530 [bitratePopUp setEnabled: NO];
4531 [sampleratePopUp setEnabled: NO];
4533 [drcSlider setFloatValue: 1.00];
4534 [self audioDRCSliderChanged: drcSlider];
4535 [drcSlider setEnabled: NO];
4536 [drcField setEnabled: NO];
4540 [sampleratePopUp setEnabled: YES];
4541 [bitratePopUp setEnabled: YES];
4542 [drcSlider setEnabled: YES];
4543 [drcField setEnabled: YES];
4548 - (IBAction) audioDRCSliderChanged: (id) sender
4550 NSSlider * drcSlider;
4551 NSTextField * drcField;
4552 if (sender == fAudTrack1DrcSlider)
4554 drcSlider = fAudTrack1DrcSlider;
4555 drcField = fAudTrack1DrcField;
4557 else if (sender == fAudTrack2DrcSlider)
4559 drcSlider = fAudTrack2DrcSlider;
4560 drcField = fAudTrack2DrcField;
4562 else if (sender == fAudTrack3DrcSlider)
4564 drcSlider = fAudTrack3DrcSlider;
4565 drcField = fAudTrack3DrcField;
4569 drcSlider = fAudTrack4DrcSlider;
4570 drcField = fAudTrack4DrcField;
4572 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
4573 /* For now, do not call this until we have an intelligent way to determine audio track selections
4574 * compared to presets
4576 //[self customSettingUsed: sender];
4579 - (IBAction) subtitleSelectionChanged: (id) sender
4581 if ([fSubPopUp indexOfSelectedItem] == 0)
4583 [fSubForcedCheck setState: NSOffState];
4584 [fSubForcedCheck setEnabled: NO];
4588 [fSubForcedCheck setEnabled: YES];
4597 #pragma mark Open New Windows
4599 - (IBAction) openHomepage: (id) sender
4601 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4602 URLWithString:@"http://handbrake.fr/"]];
4605 - (IBAction) openForums: (id) sender
4607 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4608 URLWithString:@"http://handbrake.fr/forum/"]];
4610 - (IBAction) openUserGuide: (id) sender
4612 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4613 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
4617 * Shows debug output window.
4619 - (IBAction)showDebugOutputPanel:(id)sender
4621 [outputPanel showOutputPanel:sender];
4625 * Shows preferences window.
4627 - (IBAction) showPreferencesWindow: (id) sender
4629 NSWindow * window = [fPreferencesController window];
4630 if (![window isVisible])
4633 [window makeKeyAndOrderFront: nil];
4637 * Shows queue window.
4639 - (IBAction) showQueueWindow:(id)sender
4641 [fQueueController showQueueWindow:sender];
4645 - (IBAction) toggleDrawer:(id)sender {
4646 [fPresetDrawer toggle:self];
4650 * Shows Picture Settings Window.
4653 - (IBAction) showPicturePanel: (id) sender
4655 hb_list_t * list = hb_get_titles( fHandle );
4656 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4657 [fSrcTitlePopUp indexOfSelectedItem] );
4658 [fPictureController showPanelInWindow:fWindow forTitle:title];
4662 #pragma mark Preset Outline View Methods
4663 #pragma mark - Required
4664 /* These are required by the NSOutlineView Datasource Delegate */
4665 /* We use this to deterimine children of an item */
4666 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
4669 return [UserPresets objectAtIndex:index];
4671 // We are only one level deep, so we can't be asked about children
4672 NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
4675 /* We use this to determine if an item should be expandable */
4676 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
4679 /* For now, we maintain one level, so set to no
4680 * when nested, we set to yes for any preset "folders"
4685 /* used to specify the number of levels to show for each item */
4686 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
4688 /* currently use no levels to test outline view viability */
4690 return [UserPresets count];
4694 /* Used to tell the outline view which information is to be displayed per item */
4695 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4697 /* We have two columns right now, icon and PresetName */
4699 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4701 return [item objectForKey:@"PresetName"];
4705 return @"something";
4709 #pragma mark - Added Functionality (optional)
4710 /* Use to customize the font and display characteristics of the title cell */
4711 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
4713 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4715 NSDictionary *userPresetDict = item;
4718 NSColor *shadowColor;
4719 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4720 /*check to see if its a selected row */
4721 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
4724 fontColor = [NSColor blackColor];
4725 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4729 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4731 fontColor = [NSColor blueColor];
4733 else // User created preset, use a black font
4735 fontColor = [NSColor blackColor];
4739 /* We use Bold Text for the HB Default */
4740 if ([[userPresetDict objectForKey:@"Default"] intValue] == 1)// 1 is HB default
4742 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4744 /* We use Bold Text for the User Specified Default */
4745 if ([[userPresetDict objectForKey:@"Default"] intValue] == 2)// 2 is User default
4747 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4751 [cell setTextColor:fontColor];
4752 [cell setFont:txtFont];
4757 /* We use this to edit the name field in the outline view */
4758 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4760 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4765 [theRecord setObject:object forKey:@"PresetName"];
4769 [fPresetsOutlineView reloadData];
4770 /* We save all of the preset data here */
4774 /* We use this to provide tooltips for the items in the presets outline view */
4775 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
4777 //if ([[tc identifier] isEqualToString:@"PresetName"])
4779 /* initialize the tooltip contents variable */
4781 /* if there is a description for the preset, we show it in the tooltip */
4782 if ([item objectForKey:@"PresetDescription"])
4784 loc_tip = [item objectForKey:@"PresetDescription"];
4789 loc_tip = @"No description available";
4796 #pragma mark Preset Outline View Methods (dragging related)
4799 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
4801 // Dragging is only allowed for custom presets.
4802 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
4806 // Don't retain since this is just holding temporaral drag information, and it is
4807 //only used during a drag! We could put this in the pboard actually.
4808 fDraggedNodes = items;
4809 // Provide data for our custom type, and simple NSStrings.
4810 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
4812 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
4813 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
4818 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
4820 // Don't allow dropping ONTO an item since they can't really contain any children.
4822 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
4823 if (isOnDropTypeProposal)
4824 return NSDragOperationNone;
4827 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
4831 index = [fPresetsOutlineView rowForItem: item] + 1;
4835 // Don't allow dropping into the Built In Presets.
4836 if (index < presetCurrentBuiltInCount)
4838 return NSDragOperationNone;
4839 index = MAX (index, presetCurrentBuiltInCount);
4842 [outlineView setDropItem:item dropChildIndex:index];
4843 return NSDragOperationGeneric;
4848 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
4850 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
4853 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
4854 while (obj = [enumerator nextObject])
4856 [moveItems addIndex:[UserPresets indexOfObject:obj]];
4858 // Successful drop, lets rearrange the view and save it all
4859 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
4860 [fPresetsOutlineView reloadData];
4865 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
4867 unsigned index = [indexSet lastIndex];
4868 unsigned aboveInsertIndexCount = 0;
4870 while (index != NSNotFound)
4872 unsigned removeIndex;
4874 if (index >= insertIndex)
4876 removeIndex = index + aboveInsertIndexCount;
4877 aboveInsertIndexCount++;
4881 removeIndex = index;
4885 id object = [[array objectAtIndex:removeIndex] retain];
4886 [array removeObjectAtIndex:removeIndex];
4887 [array insertObject:object atIndex:insertIndex];
4890 index = [indexSet indexLessThanIndex:index];
4896 #pragma mark - Functional Preset NSOutlineView Methods
4898 - (IBAction)selectPreset:(id)sender
4901 if ([fPresetsOutlineView selectedRow] >= 0)
4903 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
4904 /* we set the preset display field in main window here */
4905 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4906 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4908 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
4912 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4915 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
4916 [self formatPopUpChanged:nil];
4918 /* Chapter Markers*/
4919 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4920 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4921 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4922 /* Mux mp4 with http optimization */
4923 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
4926 /* We set the advanced opt string here if applicable*/
4927 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
4928 /* We use a conditional to account for the new x264 encoder dropdown as well as presets made using legacy x264 settings*/
4929 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 Main)"] ||
4930 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"] ||
4931 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264"])
4933 [fVidEncoderPopUp selectItemWithTitle:@"H.264 (x264)"];
4934 /* special case for legacy preset to check the new fDstMp4HttpOptFileCheck checkbox to set the ipod atom */
4935 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"])
4937 [fDstMp4iPodFileCheck setState:NSOnState];
4938 /* We also need to add "level=30:" to the advanced opts string to set the correct level for the iPod when
4939 encountering a legacy preset as it used to be handled separately from the opt string*/
4940 [fAdvancedOptions setOptions:[@"level=30:" stringByAppendingString:[fAdvancedOptions optionsString]]];
4944 [fDstMp4iPodFileCheck setState:NSOffState];
4947 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"FFmpeg"])
4949 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (FFmpeg)"];
4951 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"XviD"])
4953 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (XviD)"];
4957 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
4960 /* Lets run through the following functions to get variables set there */
4961 [self videoEncoderPopUpChanged:nil];
4962 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
4963 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
4964 [self calculateBitrate:nil];
4967 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4969 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
4970 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
4971 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
4973 [self videoMatrixChanged:nil];
4975 /* Video framerate */
4976 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
4977 detected framerate in the fVidRatePopUp so we use index 0*/
4978 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
4980 [fVidRatePopUp selectItemAtIndex: 0];
4984 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
4988 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4990 /* 2 Pass Encoding */
4991 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4992 [self twoPassCheckboxChanged:nil];
4993 /* Turbo 1st pass for 2 Pass Encoding */
4994 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4997 if ([chosenPreset objectForKey:@"FileCodecs"])
4999 /* We need to handle the audio codec popup by determining what was chosen from the deprecated Codecs PopUp for past presets*/
5000 if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString: @"AVC/H.264 Video / AAC + AC3 Audio"])
5002 /* We need to address setting languages etc. here in the new multi track audio panel */
5003 /* Track One set here */
5004 /*for track one though a track should be selected but lets check here anyway and use track one if its not.*/
5005 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5007 [fAudLang1PopUp selectItemAtIndex: 1];
5008 [self audioTrackPopUpChanged: fAudLang1PopUp];
5010 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5011 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5012 /* Track Two, set source same as track one */
5013 [fAudLang2PopUp selectItemAtIndex: [fAudLang1PopUp indexOfSelectedItem]];
5014 [self audioTrackPopUpChanged: fAudLang2PopUp];
5015 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5016 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5018 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AAC Audio"] ||
5019 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC Audio"])
5021 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5023 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5024 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5026 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5028 [fAudTrack2CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5029 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5031 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5033 [fAudTrack3CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5034 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5036 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5038 [fAudTrack4CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5039 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5042 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AC-3 Audio"] ||
5043 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AC-3 Audio"])
5045 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5047 [fAudTrack1CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5048 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5050 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5052 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5053 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5055 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5057 [fAudTrack3CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5058 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5060 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5062 [fAudTrack4CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5063 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5066 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / MP3 Audio"] ||
5067 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / MP3 Audio"])
5069 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5071 [fAudTrack1CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5072 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5074 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5076 [fAudTrack2CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5077 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5079 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5081 [fAudTrack3CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5082 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5084 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5086 [fAudTrack4CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5087 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5090 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / Vorbis Audio"])
5092 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5094 [fAudTrack1CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5095 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5097 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5099 [fAudTrack2CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5100 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5102 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5104 [fAudTrack3CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5105 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5107 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5109 [fAudTrack4CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5110 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5113 /* 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
5114 * UNLESS the CodecPopUp is AC3 in which case the preset values are ignored in favor of rates set in audioTrackMixdownChanged*/
5115 if ([chosenPreset objectForKey:@"AudioSampleRate"])
5117 if ([fAudLang1PopUp indexOfSelectedItem] > 0 && [fAudTrack1CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5119 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5120 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5122 if ([fAudLang2PopUp indexOfSelectedItem] > 0 && [fAudTrack2CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5124 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5125 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5127 if ([fAudLang3PopUp indexOfSelectedItem] > 0 && [fAudTrack3CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5129 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5130 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5132 if ([fAudLang4PopUp indexOfSelectedItem] > 0 && [fAudTrack4CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5134 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5135 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5138 /* We detect here if we have the old DRC Slider and if so we apply it to the existing four tracks if chosen */
5139 if ([chosenPreset objectForKey:@"AudioDRCSlider"])
5141 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5143 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5144 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5146 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5148 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5149 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5151 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5153 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5154 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5156 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5158 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5159 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5163 else // since there was no codecs key in the preset we know we can use new multi-audio track presets
5165 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
5167 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5169 [fAudLang1PopUp selectItemAtIndex: 1];
5171 [self audioTrackPopUpChanged: fAudLang1PopUp];
5172 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
5173 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5174 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
5175 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5177 if ([fAudTrack1MixPopUp selectedItem] == nil)
5179 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5181 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
5182 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5183 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
5185 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
5187 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
5188 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5190 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
5192 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5194 [fAudLang2PopUp selectItemAtIndex: 1];
5196 [self audioTrackPopUpChanged: fAudLang2PopUp];
5197 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
5198 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5199 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
5200 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5202 if ([fAudTrack2MixPopUp selectedItem] == nil)
5204 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5206 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
5207 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5208 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
5210 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
5212 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
5213 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5215 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
5217 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5219 [fAudLang3PopUp selectItemAtIndex: 1];
5221 [self audioTrackPopUpChanged: fAudLang3PopUp];
5222 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
5223 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5224 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
5225 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5227 if ([fAudTrack3MixPopUp selectedItem] == nil)
5229 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5231 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
5232 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5233 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
5235 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
5237 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
5238 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5240 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
5242 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
5244 [fAudLang4PopUp selectItemAtIndex: 1];
5246 [self audioTrackPopUpChanged: fAudLang4PopUp];
5247 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
5248 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5249 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
5250 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5252 if ([fAudTrack4MixPopUp selectedItem] == nil)
5254 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5256 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
5257 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5258 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
5260 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
5262 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
5263 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5269 /* 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
5270 * duplicate any code for legacy presets.*/
5271 /* First we handle the legacy Codecs crazy AVC/H.264 Video / AAC + AC3 Audio atv hybrid */
5272 if ([chosenPreset objectForKey:@"FileCodecs"] && [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC + AC3 Audio"])
5274 [fAudLang3PopUp selectItemAtIndex: 0];
5275 [self audioTrackPopUpChanged: fAudLang3PopUp];
5276 [fAudLang4PopUp selectItemAtIndex: 0];
5277 [self audioTrackPopUpChanged: fAudLang4PopUp];
5281 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
5283 [fAudLang2PopUp selectItemAtIndex: 0];
5284 [self audioTrackPopUpChanged: fAudLang2PopUp];
5286 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
5288 [fAudLang3PopUp selectItemAtIndex: 0];
5289 [self audioTrackPopUpChanged: fAudLang3PopUp];
5291 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
5293 [fAudLang4PopUp selectItemAtIndex: 0];
5294 [self audioTrackPopUpChanged: fAudLang4PopUp];
5299 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
5300 /* Forced Subtitles */
5301 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
5303 /* Picture Settings */
5304 /* Note: objectForKey:@"UsesPictureSettings" now refers to picture size, this encompasses:
5305 * height, width, keep ar, anamorphic and crop settings.
5306 * picture filters are now handled separately.
5307 * We will be able to actually change the key names for legacy preset keys when preset file
5308 * update code is done. But for now, lets hang onto the old legacy key name for backwards compatibility.
5310 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
5311 * and the preset completely ignores any picture sizing values in the preset.
5313 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
5315 hb_job_t * job = fTitle->job;
5316 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
5317 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
5319 /* Use Max Picture settings for whatever the dvd is.*/
5320 [self revertPictureSizeToMax:nil];
5321 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5322 if (job->keep_ratio == 1)
5324 hb_fix_aspect( job, HB_KEEP_WIDTH );
5325 if( job->height > fTitle->height )
5327 job->height = fTitle->height;
5328 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5331 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5333 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
5335 /* we check to make sure the presets width/height does not exceed the sources width/height */
5336 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
5338 /* if so, then we use the sources height and width to avoid scaling up */
5339 job->width = fTitle->width;
5340 job->height = fTitle->height;
5342 else // source width/height is >= the preset height/width
5344 /* we can go ahead and use the presets values for height and width */
5345 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
5346 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
5348 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5349 if (job->keep_ratio == 1)
5351 hb_fix_aspect( job, HB_KEEP_WIDTH );
5352 if( job->height > fTitle->height )
5354 job->height = fTitle->height;
5355 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5358 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5361 /* If Cropping is set to custom, then recall all four crop values from
5362 when the preset was created and apply them */
5363 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
5365 [fPictureController setAutoCrop:NO];
5367 /* Here we use the custom crop values saved at the time the preset was saved */
5368 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
5369 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
5370 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
5371 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
5374 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
5376 [fPictureController setAutoCrop:YES];
5377 /* Here we use the auto crop values determined right after scan */
5378 job->crop[0] = AutoCropTop;
5379 job->crop[1] = AutoCropBottom;
5380 job->crop[2] = AutoCropLeft;
5381 job->crop[3] = AutoCropRight;
5384 /* If the preset has no objectForKey:@"UsesPictureFilters", then we know it is a legacy preset
5385 * and handle the filters here as before.
5386 * NOTE: This should be removed when the update presets code is done as we can be assured that legacy
5387 * presets are updated to work properly with new keys.
5389 if (![chosenPreset objectForKey:@"UsesPictureFilters"])
5393 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5395 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5396 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5397 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5399 [fPictureController setDeinterlace:3];
5404 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5409 [fPictureController setDeinterlace:0];
5412 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5414 [fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5418 [fPictureController setVFR:0];
5421 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5423 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5427 [fPictureController setDetelecine:0];
5430 if ([chosenPreset objectForKey:@"PictureDenoise"])
5432 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5436 [fPictureController setDenoise:0];
5439 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5441 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
5445 [fPictureController setDeblock:0];
5448 [self calculatePictureSizing:nil];
5455 /* If the preset has an objectForKey:@"UsesPictureFilters", then we know it is a newer style filters preset
5456 * and handle the filters here depending on whether or not the preset specifies applying the filter.
5458 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
5462 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5464 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5465 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5466 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5468 [fPictureController setDeinterlace:3];
5472 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5477 [fPictureController setDeinterlace:0];
5480 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5482 [fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5486 [fPictureController setVFR:0];
5489 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5491 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5495 [fPictureController setDetelecine:0];
5498 if ([chosenPreset objectForKey:@"PictureDenoise"])
5500 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5504 [fPictureController setDenoise:0];
5507 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5509 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
5513 [fPictureController setDeblock:0];
5516 /* Even though we currently allow for a custom setting for decomb, ultimately it will only have Off and
5517 * Default so we just pay attention to anything greater than 0 as 1 (Default). 0 is Off. */
5518 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
5520 [fPictureController setDecomb:1];
5524 [fPictureController setDecomb:0];
5527 [self calculatePictureSizing:nil];
5533 #pragma mark Manage Presets
5535 - (void) loadPresets {
5536 /* We declare the default NSFileManager into fileManager */
5537 NSFileManager * fileManager = [NSFileManager defaultManager];
5538 /*We define the location of the user presets file */
5539 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
5540 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
5541 /* We check for the presets.plist */
5542 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
5544 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
5547 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
5548 if (nil == UserPresets)
5550 UserPresets = [[NSMutableArray alloc] init];
5551 [self addFactoryPresets:nil];
5553 [fPresetsOutlineView reloadData];
5557 - (IBAction) showAddPresetPanel: (id) sender
5559 /* Deselect the currently selected Preset if there is one*/
5560 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
5562 /* Populate the preset picture settings popup here */
5563 [fPresetNewPicSettingsPopUp removeAllItems];
5564 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
5565 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
5566 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
5567 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
5568 /* Uncheck the preset use filters checkbox */
5569 [fPresetNewPicFiltersCheck setState:NSOffState];
5570 /* Erase info from the input fields*/
5571 [fPresetNewName setStringValue: @""];
5572 [fPresetNewDesc setStringValue: @""];
5573 /* Show the panel */
5574 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
5577 - (IBAction) closeAddPresetPanel: (id) sender
5579 [NSApp endSheet: fAddPresetPanel];
5580 [fAddPresetPanel orderOut: self];
5583 - (IBAction)addUserPreset:(id)sender
5585 if (![[fPresetNewName stringValue] length])
5586 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
5589 /* Here we create a custom user preset */
5590 [UserPresets addObject:[self createPreset]];
5593 [self closeAddPresetPanel:nil];
5600 /* We Reload the New Table data for presets */
5601 [fPresetsOutlineView reloadData];
5602 /* We save all of the preset data here */
5610 /* We Sort the Presets By Factory or Custom */
5611 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
5612 ascending:YES] autorelease];
5613 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
5615 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
5616 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
5617 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
5620 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
5621 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
5622 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
5623 [UserPresets setArray:sortedArray];
5628 - (IBAction)insertPreset:(id)sender
5630 int index = [fPresetsOutlineView selectedRow];
5631 [UserPresets insertObject:[self createPreset] atIndex:index];
5632 [fPresetsOutlineView reloadData];
5636 - (NSDictionary *)createPreset
5638 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
5639 /* Get the New Preset Name from the field in the AddPresetPanel */
5640 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
5641 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
5642 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
5643 /*Set whether or not this is default, at creation set to 0*/
5644 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5645 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
5646 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
5647 /* Get whether or not to use the current Picture Filter settings for the preset */
5648 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
5650 /* Get New Preset Description from the field in the AddPresetPanel*/
5651 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
5653 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
5654 /* Chapter Markers fCreateChapterMarkers*/
5655 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
5656 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
5657 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
5658 /* Mux mp4 with http optimization */
5659 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
5660 /* Add iPod uuid atom */
5661 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
5665 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
5666 /* x264 Option String */
5667 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
5669 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
5670 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
5671 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
5672 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
5674 /* Video framerate */
5675 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
5677 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
5679 else // we can record the actual titleOfSelectedItem
5681 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
5684 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
5685 /* 2 Pass Encoding */
5686 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
5687 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
5688 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
5689 /*Picture Settings*/
5690 hb_job_t * job = fTitle->job;
5691 /* Picture Sizing */
5692 /* Use Max Picture settings for whatever the dvd is.*/
5693 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
5694 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
5695 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
5696 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
5697 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
5699 /* Set crop settings here */
5700 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
5701 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
5702 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
5703 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
5704 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
5706 /* Picture Filters */
5707 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
5708 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
5709 [preset setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
5710 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
5711 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
5712 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
5716 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5718 [preset setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
5719 [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
5720 [preset setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
5721 [preset setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
5722 [preset setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
5723 [preset setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
5724 [preset setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
5726 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5728 [preset setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
5729 [preset setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
5730 [preset setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
5731 [preset setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
5732 [preset setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
5733 [preset setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
5734 [preset setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
5736 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5738 [preset setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
5739 [preset setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
5740 [preset setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
5741 [preset setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
5742 [preset setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
5743 [preset setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
5744 [preset setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
5746 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5748 [preset setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
5749 [preset setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
5750 [preset setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
5751 [preset setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
5752 [preset setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
5753 [preset setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
5754 [preset setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
5758 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
5759 /* Forced Subtitles */
5760 [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
5762 [preset autorelease];
5769 [UserPresets writeToFile:UserPresetsFile atomically:YES];
5770 /* We get the default preset in case it changed */
5771 [self getDefaultPresets:nil];
5775 - (IBAction)deletePreset:(id)sender
5778 NSEnumerator *enumerator;
5780 NSMutableArray *tempArray;
5783 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
5785 /* Alert user before deleting preset */
5786 /* Comment out for now, tie to user pref eventually */
5789 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
5791 if ( status == NSAlertDefaultReturn ) {
5792 enumerator = [fPresetsOutlineView selectedRowEnumerator];
5793 tempArray = [NSMutableArray array];
5795 while ( (index = [enumerator nextObject]) ) {
5796 tempObject = [UserPresets objectAtIndex:[index intValue]];
5797 [tempArray addObject:tempObject];
5800 [UserPresets removeObjectsInArray:tempArray];
5801 [fPresetsOutlineView reloadData];
5807 #pragma mark Manage Default Preset
5809 - (IBAction)getDefaultPresets:(id)sender
5812 presetCurrentBuiltInCount = 0;
5813 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5815 while (tempObject = [enumerator nextObject])
5817 NSDictionary *thisPresetDict = tempObject;
5818 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
5820 presetHbDefault = i;
5822 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
5824 presetUserDefault = i;
5826 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
5828 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
5834 - (IBAction)setDefaultPreset:(id)sender
5837 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5839 /* First make sure the old user specified default preset is removed */
5840 while (tempObject = [enumerator nextObject])
5842 /* make sure we are not removing the default HB preset */
5843 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5845 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5849 /* Second, go ahead and set the appropriate user specfied preset */
5850 /* we get the chosen preset from the UserPresets array */
5851 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5853 [[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
5855 /*FIX ME: I think we now need to use the items not rows in NSOutlineView */
5856 presetUserDefault = [fPresetsOutlineView selectedRow];
5858 /* We save all of the preset data here */
5860 /* We Reload the New Table data for presets */
5861 [fPresetsOutlineView reloadData];
5864 - (IBAction)selectDefaultPreset:(id)sender
5866 /* if there is a user specified default, we use it */
5867 if (presetUserDefault)
5869 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
5870 [self selectPreset:nil];
5872 else if (presetHbDefault) //else we use the built in default presetHbDefault
5874 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
5875 [self selectPreset:nil];
5881 #pragma mark Manage Built In Presets
5884 - (IBAction)deleteFactoryPresets:(id)sender
5887 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5891 NSMutableArray *tempArray;
5894 tempArray = [NSMutableArray array];
5895 /* we look here to see if the preset is we move on to the next one */
5896 while ( tempObject = [enumerator nextObject] )
5898 /* if the preset is "Factory" then we put it in the array of
5899 presets to delete */
5900 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
5902 [tempArray addObject:tempObject];
5906 [UserPresets removeObjectsInArray:tempArray];
5907 [fPresetsOutlineView reloadData];
5912 /* We use this method to recreate new, updated factory
5914 - (IBAction)addFactoryPresets:(id)sender
5917 /* First, we delete any existing built in presets */
5918 [self deleteFactoryPresets: sender];
5919 /* Then we generate new built in presets programmatically with fPresetsBuiltin
5920 * which is all setup in HBPresets.h and HBPresets.m*/
5921 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
5933 /*******************************
5934 * Subclass of the HBPresetsOutlineView *
5935 *******************************/
5937 @implementation HBPresetsOutlineView
5938 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
5942 // By default, NSTableView only drags an image of the first column. Change this to
5943 // drag an image of the queue's icon and PresetName columns.
5944 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"icon"], [self tableColumnWithIdentifier:@"PresetName"], nil];
5945 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
5950 - (void) mouseDown:(NSEvent *)theEvent
5952 [super mouseDown:theEvent];
5958 - (BOOL) isDragging;