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
54 /* Check for and create the App Support Preview directory if necessary */
55 NSString *PreviewDirectory = [AppSupportDirectory stringByAppendingPathComponent:@"Previews"];
56 if( ![[NSFileManager defaultManager] fileExistsAtPath:PreviewDirectory] )
58 [[NSFileManager defaultManager] createDirectoryAtPath:PreviewDirectory
61 outputPanel = [[HBOutputPanelController alloc] init];
62 fPictureController = [[PictureController alloc] initWithDelegate:self];
63 fQueueController = [[HBQueueController alloc] init];
64 fAdvancedOptions = [[HBAdvancedController alloc] init];
65 /* we init the HBPresets class which currently is only used
66 * for updating built in presets, may move more functionality
69 fPresetsBuiltin = [[HBPresets alloc] init];
70 fPreferencesController = [[HBPreferencesController alloc] init];
71 /* Lets report the HandBrake version number here to the activity log and text log file */
72 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
73 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
79 - (void) applicationDidFinishLaunching: (NSNotification *) notification
81 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
82 int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
83 fHandle = hb_init(loggingLevel, 0);
84 /* Init a separate instance of libhb for user scanning and setting up jobs */
85 fQueueEncodeLibhb = hb_init(loggingLevel, 0);
87 // Set the Growl Delegate
88 [GrowlApplicationBridge setGrowlDelegate: self];
89 /* Init others controllers */
90 [fPictureController SetHandle: fHandle];
91 [fQueueController setHandle: fQueueEncodeLibhb];
92 [fQueueController setHBController: self];
94 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
95 [fChapterTable setDataSource:fChapterTitlesDelegate];
96 [fChapterTable setDelegate:fChapterTitlesDelegate];
98 /* Call UpdateUI every 1/2 sec */
99 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
100 scheduledTimerWithTimeInterval:0.5 target:self
101 selector:@selector(updateUI:) userInfo:nil repeats:YES]
102 forMode:NSEventTrackingRunLoopMode];
104 // Open debug output window now if it was visible when HB was closed
105 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
106 [self showDebugOutputPanel:nil];
108 // Open queue window now if it was visible when HB was closed
109 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
110 [self showQueueWindow:nil];
112 [self openMainWindow:nil];
114 /* We have to set the bool to tell hb what to do after a scan
115 * Initially we set it to NO until we start processing the queue
117 applyQueueToScan = NO;
119 /* Now we re-check the queue array to see if there are
120 * any remaining encodes to be done in it and ask the
121 * user if they want to reload the queue */
122 if ([QueueFileArray count] > 0)
124 /* run getQueueStats to see whats in the queue file */
125 [self getQueueStats];
126 /* this results in these values
127 * fEncodingQueueItem = 0;
129 * fCompletedCount = 0;
130 * fCanceledCount = 0;
134 /*On Screen Notification*/
135 NSString * alertTitle;
136 if (fWorkingCount > 0)
138 alertTitle = [NSString stringWithFormat:
139 NSLocalizedString(@"HandBrake Has Detected %d Previously Encoding Item and %d Pending Item(s) In Your Queue.", @""),
140 fWorkingCount,fPendingCount];
144 alertTitle = [NSString stringWithFormat:
145 NSLocalizedString(@"HandBrake Has Detected %d Pending Item(s) In Your Queue.", @""),
148 NSBeginCriticalAlertSheet(
150 NSLocalizedString(@"Reload Queue", nil),
152 NSLocalizedString(@"Empty Queue", nil),
154 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
155 NSLocalizedString(@" Do you want to reload them ?", nil));
156 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
157 // right below to either clear the old queue or keep it loaded up.
162 /* Show Browse Sources Window ASAP */
163 [self performSelectorOnMainThread:@selector(browseSources:)
164 withObject:nil waitUntilDone:NO];
168 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
170 if (returnCode == NSAlertOtherReturn)
172 [self clearQueueAllItems];
173 [self performSelectorOnMainThread:@selector(browseSources:)
174 withObject:nil waitUntilDone:NO];
178 [self setQueueEncodingItemsAsPending];
179 [self showQueueWindow:NULL];
183 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
186 // Warn if encoding a movie
188 hb_get_state( fQueueEncodeLibhb, &s );
190 if ( s.state != HB_STATE_IDLE )
192 int result = NSRunCriticalAlertPanel(
193 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
194 NSLocalizedString(@"If you quit HandBrake your current encode will be reloaded into your queue at next launch. Do you want to quit anyway?", nil),
195 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
197 if (result == NSAlertDefaultReturn)
199 return NSTerminateNow;
202 return NSTerminateCancel;
205 // Warn if items still in the queue
206 else if ( fPendingCount > 0 )
208 int result = NSRunCriticalAlertPanel(
209 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
210 NSLocalizedString(@"There are pending encodes in your queue. Do you want to quit anyway?",nil),
211 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
213 if ( result == NSAlertDefaultReturn )
214 return NSTerminateNow;
216 return NSTerminateCancel;
219 return NSTerminateNow;
222 - (void)applicationWillTerminate:(NSNotification *)aNotification
224 [browsedSourceDisplayName release];
225 [outputPanel release];
226 [fQueueController release];
228 hb_close(&fQueueEncodeLibhb);
232 - (void) awakeFromNib
235 [fWindow setExcludedFromWindowsMenu:YES];
236 [fAdvancedOptions setView:fAdvancedView];
238 /* lets setup our presets drawer for drag and drop here */
239 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
240 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
241 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
243 /* Initialize currentScanCount so HB can use it to
244 evaluate successive scans */
245 currentScanCount = 0;
248 /* Init UserPresets .plist */
251 /* Init QueueFile .plist */
252 [self loadQueueFile];
254 fRipIndicatorShown = NO; // initially out of view in the nib
256 /* Show/Dont Show Presets drawer upon launch based
257 on user preference DefaultPresetsDrawerShow*/
258 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
260 [fPresetDrawer open];
266 NSMenuItem *menuItem;
267 [fDstFormatPopUp removeAllItems];
269 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
270 [menuItem setTag: HB_MUX_MP4];
272 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
273 [menuItem setTag: HB_MUX_MKV];
275 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"AVI file" action: NULL keyEquivalent: @""];
276 [menuItem setTag: HB_MUX_AVI];
278 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"OGM file" action: NULL keyEquivalent: @""];
279 [menuItem setTag: HB_MUX_OGM];
280 [fDstFormatPopUp selectItemAtIndex: 0];
282 [self formatPopUpChanged:nil];
284 /* We enable the create chapters checkbox here since we are .mp4 */
285 [fCreateChapterMarkers setEnabled: YES];
286 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
288 [fCreateChapterMarkers setState: NSOnState];
294 [fDstFile2Field setStringValue: [NSString stringWithFormat:
295 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
298 [fVidEncoderPopUp removeAllItems];
299 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
300 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
305 [fVidTargetSizeField setIntValue: 700];
306 [fVidBitrateField setIntValue: 1000];
308 [fVidQualityMatrix selectCell: fVidBitrateCell];
309 [self videoMatrixChanged:nil];
311 /* Video framerate */
312 [fVidRatePopUp removeAllItems];
313 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
314 for( int i = 0; i < hb_video_rates_count; i++ )
316 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
318 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
319 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
321 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
323 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
324 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
326 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
328 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
329 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
333 [fVidRatePopUp addItemWithTitle:
334 [NSString stringWithCString: hb_video_rates[i].string]];
337 [fVidRatePopUp selectItemAtIndex: 0];
339 /* Set Auto Crop to On at launch */
340 [fPictureController setAutoCrop:YES];
343 [fAudTrack1BitratePopUp removeAllItems];
344 for( int i = 0; i < hb_audio_bitrates_count; i++ )
346 [fAudTrack1BitratePopUp addItemWithTitle:
347 [NSString stringWithCString: hb_audio_bitrates[i].string]];
350 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
352 /* Audio samplerate */
353 [fAudTrack1RatePopUp removeAllItems];
354 for( int i = 0; i < hb_audio_rates_count; i++ )
356 [fAudTrack1RatePopUp addItemWithTitle:
357 [NSString stringWithCString: hb_audio_rates[i].string]];
359 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
362 [fStatusField setStringValue: @""];
367 /* We disable the Turbo 1st pass checkbox since we are not x264 */
368 [fVidTurboPassCheck setEnabled: NO];
369 [fVidTurboPassCheck setState: NSOffState];
372 /* lets get our default prefs here */
373 [self getDefaultPresets:nil];
374 /* lets initialize the current successful scancount here to 0 */
375 currentSuccessfulScanCount = 0;
380 - (void) enableUI: (bool) b
382 NSControl * controls[] =
383 { fSrcTitleField, fSrcTitlePopUp,
384 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
385 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
386 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
387 fDstBrowseButton, fVidRateField, fVidRatePopUp,
388 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
389 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
390 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
391 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
392 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
393 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
394 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
395 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
396 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
397 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
398 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
399 fPictureButton,fQueueStatus,fPicSettingARkeep, fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,
400 fPicLabelOutp,fPicSettingsSrc,fPicSettingsOutp,fPicSettingsAnamorphic,
401 fPicLabelAr,fPicLabelDeinterlace,fPicSettingPAR,fPicLabelAnamorphic,fPresetsAdd,fPresetsDelete,
402 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fPicLabelAutoCrop,
403 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,
404 fSubForcedCheck,fPicSettingDeblock,fPicLabelDeblock,fPicLabelDecomb,fPicSettingDecomb,fPresetsOutlineView,
405 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck};
408 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
410 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
412 NSTextField * tf = (NSTextField *) controls[i];
413 if( ![tf isBezeled] )
415 [tf setTextColor: b ? [NSColor controlTextColor] :
416 [NSColor disabledControlTextColor]];
420 [controls[i] setEnabled: b];
426 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
427 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
428 [self setEnabledStateOfAudioMixdownControls:nil];
429 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
430 [self calculatePictureSizing:nil];
434 [fPresetsOutlineView setEnabled: NO];
438 [self videoMatrixChanged:nil];
439 [fAdvancedOptions enableUI:b];
443 /***********************************************************************
445 ***********************************************************************
446 * Shows a progression bar on the dock icon, filled according to
447 * 'progress' (0.0 <= progress <= 1.0).
448 * Called with progress < 0.0 or progress > 1.0, restores the original
450 **********************************************************************/
451 - (void) UpdateDockIcon: (float) progress
455 NSBitmapImageRep * bmp;
457 uint32_t black = htonl( 0x000000FF );
458 uint32_t red = htonl( 0xFF0000FF );
459 uint32_t white = htonl( 0xFFFFFFFF );
460 int row_start, row_end;
463 /* Get application original icon */
464 icon = [NSImage imageNamed: @"NSApplicationIcon"];
466 if( progress < 0.0 || progress > 1.0 )
468 [NSApp setApplicationIconImage: icon];
472 /* Get it in a raw bitmap form */
473 tiff = [icon TIFFRepresentationUsingCompression:
474 NSTIFFCompressionNone factor: 1.0];
475 bmp = [NSBitmapImageRep imageRepWithData: tiff];
477 /* Draw the progression bar */
478 /* It's pretty simple (ugly?) now, but I'm no designer */
480 row_start = 3 * (int) [bmp size].height / 4;
481 row_end = 7 * (int) [bmp size].height / 8;
483 for( i = row_start; i < row_start + 2; i++ )
485 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
486 for( j = 0; j < (int) [bmp size].width; j++ )
491 for( i = row_start + 2; i < row_end - 2; i++ )
493 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
496 for( j = 2; j < (int) [bmp size].width - 2; j++ )
498 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
510 for( i = row_end - 2; i < row_end; i++ )
512 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
513 for( j = 0; j < (int) [bmp size].width; j++ )
519 /* Now update the dock icon */
520 tiff = [bmp TIFFRepresentationUsingCompression:
521 NSTIFFCompressionNone factor: 1.0];
522 icon = [[NSImage alloc] initWithData: tiff];
523 [NSApp setApplicationIconImage: icon];
527 - (void) updateUI: (NSTimer *) timer
530 /* Update UI for fHandle (user scanning instance of libhb ) */
533 list = hb_get_titles( fHandle );
534 /* check to see if there has been a new scan done
535 this bypasses the constraints of HB_STATE_WORKING
536 not allowing setting a newly scanned source */
537 int checkScanCount = hb_get_scancount( fHandle );
538 if( checkScanCount > currentScanCount )
540 currentScanCount = checkScanCount;
541 [fScanIndicator setIndeterminate: NO];
542 [fScanIndicator setDoubleValue: 0.0];
543 [fScanIndicator setHidden: YES];
544 [self showNewScan:nil];
548 hb_get_state( fHandle, &s );
554 #define p s.param.scanning
555 case HB_STATE_SCANNING:
557 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
558 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
559 p.title_cur, p.title_count]];
560 [fScanIndicator setHidden: NO];
561 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
566 #define p s.param.scandone
567 case HB_STATE_SCANDONE:
569 [fScanIndicator setIndeterminate: NO];
570 [fScanIndicator setDoubleValue: 0.0];
571 [fScanIndicator setHidden: YES];
572 [self writeToActivityLog:"ScanDone state received from fHandle"];
573 [self showNewScan:nil];
574 [[fWindow toolbar] validateVisibleItems];
580 #define p s.param.working
581 case HB_STATE_WORKING:
588 #define p s.param.muxing
589 case HB_STATE_MUXING:
596 case HB_STATE_PAUSED:
599 case HB_STATE_WORKDONE:
606 /* Update UI for fQueueEncodeLibhb */
608 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
609 /* check to see if there has been a new scan done
610 this bypasses the constraints of HB_STATE_WORKING
611 not allowing setting a newly scanned source */
613 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
614 if( checkScanCount > currentScanCount )
616 currentScanCount = checkScanCount;
617 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
621 hb_get_state( fQueueEncodeLibhb, &s );
627 #define p s.param.scanning
628 case HB_STATE_SCANNING:
630 [fStatusField setStringValue: [NSString stringWithFormat:
631 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
632 p.title_cur, p.title_count]];
634 /* Set the status string in fQueueController as well */
635 [fQueueController setQueueStatusString: [NSString stringWithFormat:
636 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
637 p.title_cur, p.title_count]];
639 [fRipIndicator setHidden: NO];
640 [fRipIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
645 #define p s.param.scandone
646 case HB_STATE_SCANDONE:
648 [fRipIndicator setIndeterminate: NO];
649 [fRipIndicator setDoubleValue: 0.0];
651 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
652 [self processNewQueueEncode];
653 [[fWindow toolbar] validateVisibleItems];
659 #define p s.param.working
660 case HB_STATE_WORKING:
662 float progress_total;
663 NSMutableString * string;
664 /* Update text field */
665 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
669 [string appendFormat:
670 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
671 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
674 [fStatusField setStringValue: string];
675 /* Set the status string in fQueueController as well */
676 [fQueueController setQueueStatusString: string];
678 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
679 [fRipIndicator setIndeterminate: NO];
680 [fRipIndicator setDoubleValue: 100.0 * progress_total];
682 // If progress bar hasn't been revealed at the bottom of the window, do
683 // that now. This code used to be in doRip. I moved it to here to handle
684 // the case where hb_start is called by HBQueueController and not from
686 if( !fRipIndicatorShown )
688 NSRect frame = [fWindow frame];
689 if( frame.size.width <= 591 )
690 frame.size.width = 591;
691 frame.size.height += 36;
692 frame.origin.y -= 36;
693 [fWindow setFrame:frame display:YES animate:YES];
694 fRipIndicatorShown = YES;
698 /* Update dock icon */
699 [self UpdateDockIcon: progress_total];
705 #define p s.param.muxing
706 case HB_STATE_MUXING:
708 /* Update text field */
709 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
710 /* Set the status string in fQueueController as well */
711 [fQueueController setQueueStatusString: NSLocalizedString( @"Muxing...", @"" )];
713 [fRipIndicator setIndeterminate: YES];
714 [fRipIndicator startAnimation: nil];
716 /* Update dock icon */
717 [self UpdateDockIcon: 1.0];
723 case HB_STATE_PAUSED:
724 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
725 [fQueueController setQueueStatusString: NSLocalizedString( @"Paused", @"" )];
729 case HB_STATE_WORKDONE:
731 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
732 // or someone calling hb_stop. In the latter case, hb_stop does not clear
733 // out the remaining passes/jobs in the queue. We'll do that here.
735 // Delete all remaining jobs of this encode.
736 [fStatusField setStringValue: NSLocalizedString( @"Encode Finished.", @"" )];
737 /* Set the status string in fQueueController as well */
738 [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
739 [fRipIndicator setIndeterminate: NO];
740 [fRipIndicator setDoubleValue: 0.0];
741 [[fWindow toolbar] validateVisibleItems];
743 /* Restore dock icon */
744 [self UpdateDockIcon: -1.0];
746 if( fRipIndicatorShown )
748 NSRect frame = [fWindow frame];
749 if( frame.size.width <= 591 )
750 frame.size.width = 591;
751 frame.size.height += -36;
752 frame.origin.y -= -36;
753 [fWindow setFrame:frame display:YES animate:YES];
754 fRipIndicatorShown = NO;
756 /* Since we are done with this encode, tell output to stop writing to the
757 * individual encode log
759 [outputPanel endEncodeLog];
760 /* Check to see if the encode state has not been cancelled
761 to determine if we should check for encode done notifications */
762 if( fEncodeState != 2 )
764 NSString *pathOfFinishedEncode;
765 /* Get the output file name for the finished encode */
766 pathOfFinishedEncode = [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"];
768 /* Both the Growl Alert and Sending to MetaX can be done as encodes roll off the queue */
770 [self showGrowlDoneNotification:pathOfFinishedEncode];
772 [self sendToMetaX:pathOfFinishedEncode];
774 /* since we have successfully completed an encode, we increment the queue counter */
775 [self incrementQueueItemDone:nil];
777 /* all end of queue actions below need to be done after all queue encodes have finished
778 * and there are no pending jobs left to process
780 if (fPendingCount == 0)
782 /* If Alert Window or Window and Growl has been selected */
783 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
784 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
786 /*On Screen Notification*/
789 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake queue is done!", @"OK", nil, nil);
790 [NSApp requestUserAttention:NSCriticalRequest];
793 /* If sleep has been selected */
794 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
797 NSDictionary* errorDict;
798 NSAppleEventDescriptor* returnDescriptor = nil;
799 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
800 @"tell application \"Finder\" to sleep"];
801 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
802 [scriptObject release];
804 /* If Shutdown has been selected */
805 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
808 NSDictionary* errorDict;
809 NSAppleEventDescriptor* returnDescriptor = nil;
810 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
811 @"tell application \"Finder\" to shut down"];
812 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
813 [scriptObject release];
827 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
828 - (void) writeToActivityLog:(char *) format, ...
831 va_start(args, format);
835 vsnprintf( str, 1024, format, args );
837 time_t _now = time( NULL );
838 struct tm * now = localtime( &_now );
839 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
846 // ============================================================
847 // NSToolbar Related Methods
848 // ============================================================
850 - (void) setupToolbar {
851 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
853 [toolbar setAllowsUserCustomization: YES];
854 [toolbar setAutosavesConfiguration: YES];
855 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
857 [toolbar setDelegate: self];
859 [fWindow setToolbar: toolbar];
862 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
863 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
864 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
866 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
868 [item setLabel: @"Toggle Presets"];
869 [item setPaletteLabel: @"Toggler Presets"];
870 [item setToolTip: @"Open/Close Preset Drawer"];
871 [item setImage: [NSImage imageNamed: @"Drawer"]];
872 [item setTarget: self];
873 [item setAction: @selector(toggleDrawer:)];
874 [item setAutovalidates: NO];
876 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
878 [item setLabel: @"Start"];
879 [item setPaletteLabel: @"Start Encoding"];
880 [item setToolTip: @"Start Encoding"];
881 [item setImage: [NSImage imageNamed: @"Play"]];
882 [item setTarget: self];
883 [item setAction: @selector(Rip:)];
885 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
887 [item setLabel: @"Show Queue"];
888 [item setPaletteLabel: @"Show Queue"];
889 [item setToolTip: @"Show Queue"];
890 [item setImage: [NSImage imageNamed: @"Queue"]];
891 [item setTarget: self];
892 [item setAction: @selector(showQueueWindow:)];
893 [item setAutovalidates: NO];
895 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
897 [item setLabel: @"Add to Queue"];
898 [item setPaletteLabel: @"Add to Queue"];
899 [item setToolTip: @"Add to Queue"];
900 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
901 [item setTarget: self];
902 [item setAction: @selector(addToQueue:)];
904 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
906 [item setLabel: @"Pause"];
907 [item setPaletteLabel: @"Pause Encoding"];
908 [item setToolTip: @"Pause Encoding"];
909 [item setImage: [NSImage imageNamed: @"Pause"]];
910 [item setTarget: self];
911 [item setAction: @selector(Pause:)];
913 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
914 [item setLabel: @"Activity Window"];
915 [item setPaletteLabel: @"Show Activity Window"];
916 [item setToolTip: @"Show Activity Window"];
917 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
918 [item setTarget: self];
919 [item setAction: @selector(showDebugOutputPanel:)];
920 [item setAutovalidates: NO];
922 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
924 [item setLabel: @"Source"];
925 [item setPaletteLabel: @"Source"];
926 [item setToolTip: @"Choose Video Source"];
927 [item setImage: [NSImage imageNamed: @"Source"]];
928 [item setTarget: self];
929 [item setAction: @selector(browseSources:)];
939 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
941 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
942 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
943 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
946 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
948 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
949 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
950 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
951 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
954 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
956 NSString * ident = [toolbarItem itemIdentifier];
961 hb_get_state2( fQueueEncodeLibhb, &s );
963 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
965 if ([ident isEqualToString: StartEncodingIdentifier])
967 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
968 [toolbarItem setLabel: @"Stop"];
969 [toolbarItem setPaletteLabel: @"Stop"];
970 [toolbarItem setToolTip: @"Stop Encoding"];
973 if ([ident isEqualToString: PauseEncodingIdentifier])
975 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
976 [toolbarItem setLabel: @"Pause"];
977 [toolbarItem setPaletteLabel: @"Pause Encoding"];
978 [toolbarItem setToolTip: @"Pause Encoding"];
982 if ([ident isEqualToString: AddToQueueIdentifier])
985 else if (s.state == HB_STATE_PAUSED)
987 if ([ident isEqualToString: PauseEncodingIdentifier])
989 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
990 [toolbarItem setLabel: @"Resume"];
991 [toolbarItem setPaletteLabel: @"Resume Encoding"];
992 [toolbarItem setToolTip: @"Resume Encoding"];
995 if ([ident isEqualToString: StartEncodingIdentifier])
997 if ([ident isEqualToString: AddToQueueIdentifier])
1000 else if (s.state == HB_STATE_SCANNING)
1002 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
1004 if ([ident isEqualToString: StartEncodingIdentifier])
1006 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
1007 if (hb_count(fHandle) > 0)
1008 [toolbarItem setLabel: @"Start Queue"];
1010 [toolbarItem setLabel: @"Start"];
1011 [toolbarItem setPaletteLabel: @"Start Encoding"];
1012 [toolbarItem setToolTip: @"Start Encoding"];
1015 if ([ident isEqualToString: AddToQueueIdentifier])
1020 /* If there are any pending queue items, make sure the start/stop button is active */
1021 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
1023 if ([ident isEqualToString: ShowQueueIdentifier])
1025 if ([ident isEqualToString: ToggleDrawerIdentifier])
1027 if ([ident isEqualToString: ChooseSourceIdentifier])
1029 if ([ident isEqualToString: ShowActivityIdentifier])
1035 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
1037 SEL action = [menuItem action];
1040 hb_get_state2( fHandle, &s );
1044 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
1045 return SuccessfulScan && [fWindow attachedSheet] == nil;
1047 if (action == @selector(browseSources:))
1049 if (s.state == HB_STATE_SCANNING)
1052 return [fWindow attachedSheet] == nil;
1054 if (action == @selector(selectDefaultPreset:))
1055 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
1056 if (action == @selector(Pause:))
1058 if (s.state == HB_STATE_WORKING)
1060 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
1061 [menuItem setTitle:@"Pause Encoding"];
1064 else if (s.state == HB_STATE_PAUSED)
1066 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1067 [menuItem setTitle:@"Resume Encoding"];
1073 if (action == @selector(Rip:))
1075 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1077 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1078 [menuItem setTitle:@"Stop Encoding"];
1081 else if (SuccessfulScan)
1083 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1084 [menuItem setTitle:@"Start Encoding"];
1085 return [fWindow attachedSheet] == nil;
1091 if( action == @selector(setDefaultPreset:) )
1093 return [fPresetsOutlineView selectedRow] != -1;
1100 #pragma mark Encode Done Actions
1101 // register a test notification and make
1102 // it enabled by default
1103 #define SERVICE_NAME @"Encode Done"
1104 - (NSDictionary *)registrationDictionaryForGrowl
1106 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1107 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1108 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1111 return registrationDictionary;
1114 -(void)showGrowlDoneNotification:(NSString *) filePath
1116 /* This end of encode action is called as each encode rolls off of the queue */
1117 NSString * finishedEncode = filePath;
1118 /* strip off the path to just show the file name */
1119 finishedEncode = [finishedEncode lastPathComponent];
1120 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1121 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1123 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1124 [GrowlApplicationBridge
1125 notifyWithTitle:@"Put down that cocktail..."
1126 description:growlMssg
1127 notificationName:SERVICE_NAME
1135 -(void)sendToMetaX:(NSString *) filePath
1137 /* This end of encode action is called as each encode rolls off of the queue */
1138 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1140 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1141 [myScript executeAndReturnError: nil];
1146 #pragma mark Get New Source
1148 /*Opens the source browse window, called from Open Source widgets */
1149 - (IBAction) browseSources: (id) sender
1151 NSOpenPanel * panel;
1153 panel = [NSOpenPanel openPanel];
1154 [panel setAllowsMultipleSelection: NO];
1155 [panel setCanChooseFiles: YES];
1156 [panel setCanChooseDirectories: YES ];
1157 NSString * sourceDirectory;
1158 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1160 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1164 sourceDirectory = @"~/Desktop";
1165 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1167 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1168 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1170 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1171 modalForWindow: fWindow modalDelegate: self
1172 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1173 contextInfo: sender];
1176 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1177 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1179 /* we convert the sender content of contextInfo back into a variable called sender
1180 * mostly just for consistency for evaluation later
1182 id sender = (id)contextInfo;
1183 /* User selected a file to open */
1184 if( returnCode == NSOKButton )
1186 /* Free display name allocated previously by this code */
1187 [browsedSourceDisplayName release];
1189 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1190 /* we set the last searched source directory in the prefs here */
1191 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1192 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1193 /* we order out sheet, which is the browse window as we need to open
1194 * the title selection sheet right away
1196 [sheet orderOut: self];
1198 if (sender == fOpenSourceTitleMMenu)
1200 /* We put the chosen source path in the source display text field for the
1201 * source title selection sheet in which the user specifies the specific title to be
1202 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1203 * purposes in the title panel
1206 [fScanSrcTitlePathField setStringValue:scanPath];
1207 NSString *displayTitlescanSourceName;
1209 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1211 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1212 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1213 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1217 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1218 displayTitlescanSourceName = [scanPath lastPathComponent];
1220 /* we set the source display name in the title selection dialogue */
1221 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1222 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1223 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1224 /* We show the actual sheet where the user specifies the title to be scanned
1225 * as we are going to do a title specific scan
1227 [self showSourceTitleScanPanel:nil];
1231 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1232 NSString *path = [[sheet filenames] objectAtIndex: 0];
1234 /* We check to see if the chosen file at path is a package */
1235 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1237 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1238 /* We check to see if this is an .eyetv package */
1239 if ([[path pathExtension] isEqualToString: @"eyetv"])
1241 [self writeToActivityLog:"trying to open eyetv package"];
1242 /* We're looking at an EyeTV package - try to open its enclosed
1244 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1246 int n = [[path stringByAppendingString: @"/"]
1247 completePathIntoString: &mpgname caseSensitive: NO
1248 matchesIntoArray: nil
1249 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1252 /* Found an mpeg inside the eyetv package, make it our scan path
1253 and call performScan on the enclosed mpeg */
1255 [self writeToActivityLog:"found mpeg in eyetv package"];
1256 [self performScan:path scanTitleNum:0];
1260 /* We did not find an mpeg file in our package, so we do not call performScan */
1261 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1264 /* We check to see if this is a .dvdmedia package */
1265 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1267 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1268 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1269 [self writeToActivityLog:"trying to open dvdmedia package"];
1270 [self performScan:path scanTitleNum:0];
1274 /* The package is not an eyetv package, so we do not call performScan */
1275 [self writeToActivityLog:"unable to open package"];
1278 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1280 /* path is not a package, so we call perform scan directly on our file */
1281 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1283 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1284 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1285 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1289 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1290 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1291 /* make sure we remove any path extension as this can also be an '.mpg' file */
1292 browsedSourceDisplayName = [[path lastPathComponent] retain];
1294 [self performScan:path scanTitleNum:0];
1302 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1303 - (IBAction) showSourceTitleScanPanel: (id) sender
1305 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1308 [fScanSrcTitleNumField setStringValue: @"0"];
1309 /* Show the panel */
1310 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1313 - (IBAction) closeSourceTitleScanPanel: (id) sender
1315 [NSApp endSheet: fScanSrcTitlePanel];
1316 [fScanSrcTitlePanel orderOut: self];
1318 if(sender == fScanSrcTitleOpenButton)
1320 /* We setup the scan status in the main window to indicate a source title scan */
1321 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1322 [fScanIndicator setHidden: NO];
1323 [fScanIndicator setIndeterminate: YES];
1324 [fScanIndicator startAnimation: nil];
1326 /* We use the performScan method to actually perform the specified scan passing the path and the title
1329 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1333 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1334 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1336 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1337 applyQueueToScan = NO;
1338 /* use a bool to determine whether or not we can decrypt using vlc */
1339 BOOL cancelScanDecrypt = 0;
1340 NSString *path = scanPath;
1341 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1343 // Notify ChapterTitles that there's no title
1344 [fChapterTitlesDelegate resetWithTitle:nil];
1345 [fChapterTable reloadData];
1347 [self enableUI: NO];
1349 if( [detector isVideoDVD] )
1351 // The chosen path was actually on a DVD, so use the raw block
1352 // device path instead.
1353 path = [detector devicePath];
1354 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1356 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1357 NSString *vlcPath = @"/Applications/VLC.app";
1358 NSFileManager * fileManager = [NSFileManager defaultManager];
1359 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1361 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1362 cancelScanDecrypt = 1;
1363 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1365 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");
1366 [NSApp requestUserAttention:NSCriticalRequest];
1368 if (status == NSAlertDefaultReturn)
1370 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1371 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1373 else if (status == NSAlertAlternateReturn)
1375 /* User chose to cancel the scan */
1376 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1380 /* 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 */
1381 cancelScanDecrypt = 0;
1382 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1388 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1389 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1393 if (cancelScanDecrypt == 0)
1395 /* we actually pass the scan off to libhb here */
1396 /* If there is no title number passed to scan, we use "0"
1397 * which causes the default behavior of a full source scan
1403 if (scanTitleNum > 0)
1405 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1407 /* We use our advance pref to determine how many previews to scan */
1408 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
1409 hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
1410 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1414 - (IBAction) showNewScan:(id)sender
1418 int indxpri=0; // Used to search the longuest title (default in combobox)
1419 int longuestpri=0; // Used to search the longuest title (default in combobox)
1422 list = hb_get_titles( fHandle );
1424 if( !hb_list_count( list ) )
1426 /* We display a message if a valid dvd source was not chosen */
1427 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1428 SuccessfulScan = NO;
1430 // Notify ChapterTitles that there's no title
1431 [fChapterTitlesDelegate resetWithTitle:nil];
1432 [fChapterTable reloadData];
1436 /* We increment the successful scancount here by one,
1437 which we use at the end of this function to tell the gui
1438 if this is the first successful scan since launch and whether
1439 or not we should set all settings to the defaults */
1441 currentSuccessfulScanCount++;
1443 [[fWindow toolbar] validateVisibleItems];
1445 [fSrcTitlePopUp removeAllItems];
1446 for( int i = 0; i < hb_list_count( list ); i++ )
1448 title = (hb_title_t *) hb_list_item( list, i );
1450 currentSource = [NSString stringWithUTF8String: title->name];
1451 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1452 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1454 /* Use the dvd name in the default output field here
1455 May want to add code to remove blank spaces for some dvd names*/
1456 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1457 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1459 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1460 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1464 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1465 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1469 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1471 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1475 [fSrcTitlePopUp addItemWithTitle: [NSString
1476 stringWithFormat: @"%d - %02dh%02dm%02ds",
1477 title->index, title->hours, title->minutes,
1481 // Select the longuest title
1482 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1483 [self titlePopUpChanged:nil];
1485 SuccessfulScan = YES;
1486 [self enableUI: YES];
1488 /* if its the initial successful scan after awakeFromNib */
1489 if (currentSuccessfulScanCount == 1)
1491 [self selectDefaultPreset:nil];
1492 /* initially set deinterlace to 0, will be overridden reset by the default preset anyway */
1493 //[fPictureController setDeinterlace:0];
1495 /* lets set Denoise to index 0 or "None" since this is the first scan */
1496 //[fPictureController setDenoise:0];
1498 [fPictureController setInitialPictureFilters];
1508 #pragma mark New Output Destination
1510 - (IBAction) browseFile: (id) sender
1512 /* Open a panel to let the user choose and update the text field */
1513 NSSavePanel * panel = [NSSavePanel savePanel];
1514 /* We get the current file name and path from the destination field here */
1515 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1516 modalForWindow: fWindow modalDelegate: self
1517 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1521 - (void) browseFileDone: (NSSavePanel *) sheet
1522 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1524 if( returnCode == NSOKButton )
1526 [fDstFile2Field setStringValue: [sheet filename]];
1532 #pragma mark Main Window Control
1534 - (IBAction) openMainWindow: (id) sender
1536 [fWindow makeKeyAndOrderFront:nil];
1539 - (BOOL) windowShouldClose: (id) sender
1544 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1547 [fWindow makeKeyAndOrderFront:nil];
1557 #pragma mark Queue File
1559 - (void) loadQueueFile {
1560 /* We declare the default NSFileManager into fileManager */
1561 NSFileManager * fileManager = [NSFileManager defaultManager];
1562 /*We define the location of the user presets file */
1563 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1564 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1565 /* We check for the presets.plist */
1566 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1568 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1571 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1572 /* lets check to see if there is anything in the queue file .plist */
1573 if (nil == QueueFileArray)
1575 /* if not, then lets initialize an empty array */
1576 QueueFileArray = [[NSMutableArray alloc] init];
1578 /* Initialize our curQueueEncodeIndex to 0
1579 * so we can use it to track which queue
1580 * item is to be used to track our encodes */
1581 /* NOTE: this should be changed if and when we
1582 * are able to get the last unfinished encode
1583 * in the case of a crash or shutdown */
1588 [self clearQueueEncodedItems];
1590 currentQueueEncodeIndex = 0;
1593 - (void)addQueueFileItem
1595 [QueueFileArray addObject:[self createQueueFileItem]];
1596 [self saveQueueFileItem];
1600 - (void) removeQueueFileItem:(int) queueItemToRemove
1603 /* Find out if the item we are removing is a cancelled (3) or a finished (0) item*/
1604 if ([[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 3 || [[[QueueFileArray objectAtIndex:queueItemToRemove] objectForKey:@"Status"] intValue] == 0)
1606 /* Since we are removing a cancelled or finished item, WE need to decrement the currentQueueEncodeIndex
1607 * by one to keep in sync with the queue array
1609 currentQueueEncodeIndex--;
1610 [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
1612 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1613 [self saveQueueFileItem];
1617 - (void)saveQueueFileItem
1619 [QueueFileArray writeToFile:QueueFile atomically:YES];
1620 [fQueueController setQueueArray: QueueFileArray];
1621 [self getQueueStats];
1624 - (void)getQueueStats
1626 /* lets get the stats on the status of the queue array */
1628 fEncodingQueueItem = 0;
1630 fCompletedCount = 0;
1634 /* We use a number system to set the encode status of the queue item
1636 * 0 == already encoded
1637 * 1 == is being encoded
1638 * 2 == is yet to be encoded
1643 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1645 while (tempObject = [enumerator nextObject])
1647 NSDictionary *thisQueueDict = tempObject;
1648 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1652 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1655 fEncodingQueueItem = i;
1657 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1661 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1668 /* Set the queue status field in the main window */
1669 NSMutableString * string;
1670 if (fPendingCount == 1)
1672 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1676 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1678 [fQueueStatus setStringValue:string];
1681 /* This method will set any item marked as encoding back to pending
1682 * currently used right after a queue reload
1684 - (void) setQueueEncodingItemsAsPending
1686 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1688 NSMutableArray *tempArray;
1689 tempArray = [NSMutableArray array];
1690 /* we look here to see if the preset is we move on to the next one */
1691 while ( tempObject = [enumerator nextObject] )
1693 /* If the queue item is marked as "encoding" (1)
1694 * then change its status back to pending (2) which effectively
1695 * puts it back into the queue to be encoded
1697 if ([[tempObject objectForKey:@"Status"] intValue] == 1)
1699 [tempObject setObject:[NSNumber numberWithInt: 2] forKey:@"Status"];
1701 [tempArray addObject:tempObject];
1704 [QueueFileArray setArray:tempArray];
1705 [self saveQueueFileItem];
1709 /* This method will clear the queue of any encodes that are not still pending
1710 * this includes both successfully completed encodes as well as cancelled encodes */
1711 - (void) clearQueueEncodedItems
1713 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1715 NSMutableArray *tempArray;
1716 tempArray = [NSMutableArray array];
1717 /* we look here to see if the preset is we move on to the next one */
1718 while ( tempObject = [enumerator nextObject] )
1720 /* If the queue item is either completed (0) or cancelled (3) from the
1721 * last session, then we put it in tempArray to be deleted from QueueFileArray.
1722 * NOTE: this means we retain pending (2) and also an item that is marked as
1723 * still encoding (1). If the queue has an item that is still marked as encoding
1724 * from a previous session, we can conlude that HB was either shutdown, or crashed
1725 * during the encodes so we keep it and tell the user in the "Load Queue Alert"
1727 if ([[tempObject objectForKey:@"Status"] intValue] == 0 || [[tempObject objectForKey:@"Status"] intValue] == 3)
1729 [tempArray addObject:tempObject];
1733 [QueueFileArray removeObjectsInArray:tempArray];
1734 [self saveQueueFileItem];
1737 /* This method will clear the queue of all encodes. effectively creating an empty queue */
1738 - (void) clearQueueAllItems
1740 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1742 NSMutableArray *tempArray;
1743 tempArray = [NSMutableArray array];
1744 /* we look here to see if the preset is we move on to the next one */
1745 while ( tempObject = [enumerator nextObject] )
1747 [tempArray addObject:tempObject];
1750 [QueueFileArray removeObjectsInArray:tempArray];
1751 [self saveQueueFileItem];
1754 /* This method will duplicate prepareJob however into the
1755 * queue .plist instead of into the job structure so it can
1756 * be recalled later */
1757 - (NSDictionary *)createQueueFileItem
1759 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1761 hb_list_t * list = hb_get_titles( fHandle );
1762 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1763 [fSrcTitlePopUp indexOfSelectedItem] );
1764 hb_job_t * job = title->job;
1768 /* We use a number system to set the encode status of the queue item
1769 * 0 == already encoded
1770 * 1 == is being encoded
1771 * 2 == is yet to be encoded
1774 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1775 /* Source and Destination Information */
1777 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1778 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1779 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1780 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1782 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1784 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1786 /* Lets get the preset info if there is any */
1787 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1788 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1790 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1791 /* Chapter Markers fCreateChapterMarkers*/
1792 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1794 /* We need to get the list of chapter names to put into an array and store
1795 * in our queue, so they can be reapplied in prepareJob when this queue
1796 * item comes up if Chapter Markers is set to on.
1799 NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
1800 int chaptercount = hb_list_count( fTitle->list_chapter );
1801 for( i = 0; i < chaptercount; i++ )
1803 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
1804 if( chapter != NULL )
1806 [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
1809 [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
1810 [ChapterNamesArray autorelease];
1812 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1813 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1814 /* Mux mp4 with http optimization */
1815 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1816 /* Add iPod uuid atom */
1817 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1821 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
1822 /* x264 Option String */
1823 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1825 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1826 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1827 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1828 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1830 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
1833 [queueFileJob setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
1834 /* 2 Pass Encoding */
1835 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
1836 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
1837 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
1839 /* Picture Sizing */
1840 /* Use Max Picture settings for whatever the dvd is.*/
1841 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1842 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1843 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1844 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1845 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1846 NSString * pictureSummary;
1847 pictureSummary = [NSString stringWithFormat:@"Source: %@ Output: %@ Anamorphic: %@",
1848 [fPicSettingsSrc stringValue],
1849 [fPicSettingsOutp stringValue],
1850 [fPicSettingsAnamorphic stringValue]];
1851 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
1852 /* Set crop settings here */
1853 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1854 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1855 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1856 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1857 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1859 /* Picture Filters */
1860 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
1861 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
1862 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
1863 [queueFileJob setObject:[NSString stringWithFormat:@"%d",[fPictureController deblock]] forKey:@"PictureDeblock"];
1864 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
1867 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1869 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
1870 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
1871 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
1872 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
1873 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
1874 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
1875 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
1877 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1879 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
1880 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
1881 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
1882 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
1883 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
1884 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
1885 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
1887 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1889 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
1890 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
1891 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
1892 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
1893 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
1894 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
1895 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
1897 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1899 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
1900 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
1901 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
1902 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
1903 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
1904 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
1905 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
1909 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1910 [queueFileJob setObject:[NSNumber numberWithInt:[fSubPopUp indexOfSelectedItem]] forKey:@"JobSubtitlesIndex"];
1911 /* Forced Subtitles */
1912 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1916 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
1918 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
1920 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
1923 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
1927 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
1930 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
1931 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
1932 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
1934 /* Picture Sizing */
1935 /* Use Max Picture settings for whatever the dvd is.*/
1936 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1937 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1938 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1939 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1940 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1942 /* Set crop settings here */
1943 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1944 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1945 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1946 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1947 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1949 /* Picture Filters */
1950 [queueFileJob setObject:[fPicSettingDecomb stringValue] forKey:@"JobPictureDecomb"];
1953 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1955 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
1956 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
1957 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
1958 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
1959 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
1961 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1963 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
1964 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
1965 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
1966 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
1967 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
1969 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1971 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
1972 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
1973 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
1974 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
1975 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
1977 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1979 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
1980 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
1981 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
1982 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
1983 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
1986 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1987 /* Forced Subtitles */
1988 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1990 /* we need to auto relase the queueFileJob and return it */
1991 [queueFileJob autorelease];
1992 return queueFileJob;
1996 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
1997 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
1999 unsigned index = [indexSet lastIndex];
2000 unsigned aboveInsertIndexCount = 0;
2002 while (index != NSNotFound)
2004 unsigned removeIndex;
2006 if (index >= insertIndex)
2008 removeIndex = index + aboveInsertIndexCount;
2009 aboveInsertIndexCount++;
2013 removeIndex = index;
2017 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
2018 [QueueFileArray removeObjectAtIndex:removeIndex];
2019 [QueueFileArray insertObject:object atIndex:insertIndex];
2022 index = [indexSet indexLessThanIndex:index];
2024 /* We save all of the Queue data here
2025 * and it also gets sent back to the queue controller*/
2026 [self saveQueueFileItem];
2032 #pragma mark Queue Job Processing
2034 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
2036 int i = currentQueueEncodeIndex;
2037 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
2039 /* We save all of the Queue data here */
2040 [self saveQueueFileItem];
2041 /* We Reload the New Table data for presets */
2042 //[fPresetsOutlineView reloadData];
2044 /* Since we have now marked a queue item as done
2045 * we can go ahead and increment currentQueueEncodeIndex
2046 * so that if there is anything left in the queue we can
2047 * go ahead and move to the next item if we want to */
2048 currentQueueEncodeIndex++ ;
2049 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2050 int queueItems = [QueueFileArray count];
2051 /* If we still have more items in our queue, lets go to the next one */
2052 if (currentQueueEncodeIndex < queueItems)
2054 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2055 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2059 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
2063 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
2064 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
2066 /* Tell HB to output a new activity log file for this encode */
2067 [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
2070 /* use a bool to determine whether or not we can decrypt using vlc */
2071 BOOL cancelScanDecrypt = 0;
2072 /* set the bool so that showNewScan knows to apply the appropriate queue
2073 * settings as this is a queue rescan
2075 applyQueueToScan = YES;
2076 NSString *path = scanPath;
2077 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
2079 /*On Screen Notification*/
2081 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
2082 //[NSApp requestUserAttention:NSCriticalRequest];
2084 // Notify ChapterTitles that there's no title
2085 [fChapterTitlesDelegate resetWithTitle:nil];
2086 [fChapterTable reloadData];
2088 //[self enableUI: NO];
2090 if( [detector isVideoDVD] )
2092 // The chosen path was actually on a DVD, so use the raw block
2093 // device path instead.
2094 path = [detector devicePath];
2095 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
2097 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
2098 NSString *vlcPath = @"/Applications/VLC.app";
2099 NSFileManager * fileManager = [NSFileManager defaultManager];
2100 if ([fileManager fileExistsAtPath:vlcPath] == 0)
2102 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
2103 cancelScanDecrypt = 1;
2104 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2106 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");
2107 [NSApp requestUserAttention:NSCriticalRequest];
2109 if (status == NSAlertDefaultReturn)
2111 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2112 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2114 else if (status == NSAlertAlternateReturn)
2116 /* User chose to cancel the scan */
2117 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2121 /* 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 */
2122 cancelScanDecrypt = 0;
2123 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2129 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2130 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2134 if (cancelScanDecrypt == 0)
2136 /* we actually pass the scan off to libhb here */
2137 /* If there is no title number passed to scan, we use "0"
2138 * which causes the default behavior of a full source scan
2144 if (scanTitleNum > 0)
2146 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2149 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2150 /* We use our advance pref to determine how many previews to scan */
2151 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
2152 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
2156 /* This method was originally used to load up a new queue item in the gui and
2157 * then start processing it. However we now have modified -prepareJob and use a second
2158 * instance of libhb to do our actual encoding, therefor right now it is not required.
2159 * Nonetheless I want to leave this in here
2160 * because basically its everything we need to be able to actually modify a pending queue
2161 * item in the gui and resave it. At least for now - dynaflash
2164 - (IBAction)applyQueueSettings:(id)sender
2166 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2167 hb_job_t * job = fTitle->job;
2169 /* Set title number and chapters */
2170 /* since the queue only scans a single title, we really don't need to pick a title */
2171 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2173 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2174 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2177 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2178 [self formatPopUpChanged:nil];
2180 /* Chapter Markers*/
2181 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2182 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2183 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2184 /* Mux mp4 with http optimization */
2185 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2188 /* We set the advanced opt string here if applicable*/
2189 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2190 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2192 /* Lets run through the following functions to get variables set there */
2193 [self videoEncoderPopUpChanged:nil];
2194 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2195 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2196 [self calculateBitrate:nil];
2199 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2201 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2202 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2203 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2205 [self videoMatrixChanged:nil];
2207 /* Video framerate */
2208 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2209 detected framerate in the fVidRatePopUp so we use index 0*/
2210 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2212 [fVidRatePopUp selectItemAtIndex: 0];
2216 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2220 [fVidGrayscaleCheck setState:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2222 /* 2 Pass Encoding */
2223 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2224 [self twoPassCheckboxChanged:nil];
2225 /* Turbo 1st pass for 2 Pass Encoding */
2226 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2229 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2231 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2233 [fAudLang1PopUp selectItemAtIndex: 1];
2235 [self audioTrackPopUpChanged: fAudLang1PopUp];
2236 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2237 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2238 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2239 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2241 if ([fAudTrack1MixPopUp selectedItem] == nil)
2243 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2245 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2246 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2247 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2249 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2251 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2252 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2254 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2256 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2258 [fAudLang2PopUp selectItemAtIndex: 1];
2260 [self audioTrackPopUpChanged: fAudLang2PopUp];
2261 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2262 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2263 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2264 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2266 if ([fAudTrack2MixPopUp selectedItem] == nil)
2268 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2270 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2271 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2272 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2274 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2276 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2277 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2279 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2281 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2283 [fAudLang3PopUp selectItemAtIndex: 1];
2285 [self audioTrackPopUpChanged: fAudLang3PopUp];
2286 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2287 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2288 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2289 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2291 if ([fAudTrack3MixPopUp selectedItem] == nil)
2293 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2295 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2296 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2297 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2299 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2301 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2302 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2304 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2306 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2308 [fAudLang4PopUp selectItemAtIndex: 1];
2310 [self audioTrackPopUpChanged: fAudLang4PopUp];
2311 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2312 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2313 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2314 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2316 if ([fAudTrack4MixPopUp selectedItem] == nil)
2318 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2320 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2321 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2322 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2324 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2326 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2327 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2332 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2333 /* Forced Subtitles */
2334 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2336 /* Picture Settings */
2337 /* we check to make sure the presets width/height does not exceed the sources width/height */
2338 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2340 /* if so, then we use the sources height and width to avoid scaling up */
2341 job->width = fTitle->width;
2342 job->height = fTitle->height;
2344 else // source width/height is >= the preset height/width
2346 /* we can go ahead and use the presets values for height and width */
2347 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2348 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2350 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2351 if (job->keep_ratio == 1)
2353 hb_fix_aspect( job, HB_KEEP_WIDTH );
2354 if( job->height > fTitle->height )
2356 job->height = fTitle->height;
2357 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2360 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2363 /* If Cropping is set to custom, then recall all four crop values from
2364 when the preset was created and apply them */
2365 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2367 [fPictureController setAutoCrop:NO];
2369 /* Here we use the custom crop values saved at the time the preset was saved */
2370 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2371 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2372 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2373 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2376 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2378 [fPictureController setAutoCrop:YES];
2379 /* Here we use the auto crop values determined right after scan */
2380 job->crop[0] = AutoCropTop;
2381 job->crop[1] = AutoCropBottom;
2382 job->crop[2] = AutoCropLeft;
2383 job->crop[3] = AutoCropRight;
2389 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2392 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2394 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2396 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2398 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2400 [self calculatePictureSizing:nil];
2403 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2404 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2405 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2406 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2408 /* Deselect the currently selected Preset if there is one*/
2409 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2410 //[self selectPreset:nil];
2412 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2413 /* Change UI to show "Custom" settings are being used */
2414 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2416 curUserPresetChosenNum = nil;
2420 /* Deselect the currently selected Preset if there is one*/
2421 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2422 /* Change UI to show "Custom" settings are being used */
2423 [fPresetSelectedDisplay setStringValue: @"Custom"];
2425 //curUserPresetChosenNum = nil;
2428 /* We need to set this bool back to NO, in case the user wants to do a scan */
2429 //applyQueueToScan = NO;
2431 /* so now we go ahead and process the new settings */
2432 [self processNewQueueEncode];
2437 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2438 - (void) processNewQueueEncode
2440 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2441 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2442 hb_job_t * job = title->job;
2444 if( !hb_list_count( list ) )
2446 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2450 [self writeToActivityLog: "processNewQueueEncode title list is: %d", hb_list_count( list )];
2453 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2454 [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
2455 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2456 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2457 //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2459 if( [[queueToApply objectForKey:@"SubtitlesForced"] intValue] == 1 )
2460 job->subtitle_force = 1;
2462 job->subtitle_force = 0;
2465 * subtitle of -1 is a scan
2467 if( job->subtitle == -1 )
2472 * When subtitle scan is enabled do a fast pre-scan job
2473 * which will determine which subtitles to enable, if any.
2476 x264opts_tmp = job->x264opts;
2479 job->x264opts = NULL;
2481 job->indepth_scan = 1;
2483 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
2484 *(job->select_subtitle) = NULL;
2487 * Add the pre-scan job
2489 hb_add( fQueueEncodeLibhb, job );
2490 job->x264opts = x264opts_tmp;
2493 job->select_subtitle = NULL;
2495 /* No subtitle were selected, so reset the subtitle to -1 (which before
2496 * this point meant we were scanning
2498 if( job->subtitle == -2 )
2501 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2503 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
2504 job->indepth_scan = 0;
2507 * Do not autoselect subtitles on the first pass of a two pass
2509 job->select_subtitle = NULL;
2513 hb_add( fQueueEncodeLibhb, job );
2517 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2518 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2520 job->select_subtitle = subtitle_tmp;
2522 hb_add( fQueueEncodeLibhb, job );
2527 job->indepth_scan = 0;
2530 hb_add( fQueueEncodeLibhb, job );
2533 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2534 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2535 /* Lets mark our new encode as 1 or "Encoding" */
2536 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2537 [self saveQueueFileItem];
2538 /* We should be all setup so let 'er rip */
2543 #pragma mark Live Preview
2544 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
2545 * can encode to its temp preview directory and playback. This is *not* used for any actual user
2548 - (void) prepareJobForPreview
2550 hb_list_t * list = hb_get_titles( fHandle );
2551 hb_title_t * title = (hb_title_t *) hb_list_item( list,
2552 [fSrcTitlePopUp indexOfSelectedItem] );
2553 hb_job_t * job = title->job;
2554 hb_audio_config_t * audio;
2556 /* Chapter selection */
2557 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
2558 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
2560 /* Format (Muxer) and Video Encoder */
2561 job->mux = [[fDstFormatPopUp selectedItem] tag];
2562 job->vcodec = [[fVidEncoderPopUp selectedItem] tag];
2565 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
2566 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
2568 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
2569 mpeg4 and the checkbox being checked
2570 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
2571 if( [fDstMp4LargeFileCheck state] == NSOnState )
2573 job->largeFileSize = 1;
2577 job->largeFileSize = 0;
2579 /* We set http optimized mp4 here */
2580 if( [fDstMp4HttpOptFileCheck state] == NSOnState && [fDstMp4HttpOptFileCheck isEnabled] )
2582 job->mp4_optimize = 1;
2586 job->mp4_optimize = 0;
2589 if( [fDstFormatPopUp indexOfSelectedItem] == 0 || [fDstFormatPopUp indexOfSelectedItem] == 1 )
2591 /* We set the chapter marker extraction here based on the format being
2592 mpeg4 or mkv and the checkbox being checked */
2593 if ([fCreateChapterMarkers state] == NSOnState)
2595 job->chapter_markers = 1;
2599 job->chapter_markers = 0;
2603 if( job->vcodec & HB_VCODEC_X264 )
2605 if ([fDstMp4iPodFileCheck state] == NSOnState)
2614 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2615 Currently only used with Constant Quality setting*/
2616 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [fVidQualityMatrix selectedRow] == 2)
2621 /* Below Sends x264 options to the core library if x264 is selected*/
2622 /* Lets use this as per Nyx, Thanks Nyx!*/
2623 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2624 /* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
2625 strcpy(job->x264opts, [[fAdvancedOptions optionsString] UTF8String]);
2630 /* Video settings */
2631 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2632 * and detelecine is on, so we handle that in the logic below
2635 if( [fVidRatePopUp indexOfSelectedItem] > 0 )
2637 /* a specific framerate has been chosen */
2638 job->vrate = 27000000;
2639 job->vrate_base = hb_video_rates[[fVidRatePopUp indexOfSelectedItem]-1].rate;
2640 /* We are not same as source so we set job->cfr to 1
2641 * to enable constant frame rate since user has specified
2642 * a specific framerate*/
2647 /* We are same as source (variable) */
2648 job->vrate = title->rate;
2649 job->vrate_base = title->rate_base;
2650 /* We are same as source so we set job->cfr to 0
2651 * to enable true same as source framerate */
2653 /* If we are same as source and we have detelecine on, we need to turn on
2656 if ([fPictureController detelecine] == 1)
2662 switch( [fVidQualityMatrix selectedRow] )
2666 Bitrate should already have been calculated and displayed
2667 in fVidBitrateField, so let's just use it */
2669 job->vquality = -1.0;
2670 job->vbitrate = [fVidBitrateField intValue];
2673 job->vquality = [fVidQualitySlider floatValue];
2678 job->grayscale = ( [fVidGrayscaleCheck state] == NSOnState );
2680 /* Subtitle settings */
2681 job->subtitle = [fSubPopUp indexOfSelectedItem] - 2;
2683 /* Audio tracks and mixdowns */
2684 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2685 int audiotrack_count = hb_list_count(job->list_audio);
2686 for( int i = 0; i < audiotrack_count;i++)
2688 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2689 hb_list_rem(job->list_audio, temp_audio);
2691 /* Now lets add our new tracks to the audio list here */
2692 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
2694 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2695 hb_audio_config_init(audio);
2696 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2697 /* We go ahead and assign values to our audio->out.<properties> */
2698 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
2699 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
2700 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
2701 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
2702 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
2703 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
2705 hb_audio_add( job, audio );
2708 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
2710 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2711 hb_audio_config_init(audio);
2712 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2713 /* We go ahead and assign values to our audio->out.<properties> */
2714 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
2715 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
2716 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
2717 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
2718 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
2719 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
2721 hb_audio_add( job, audio );
2726 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
2728 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2729 hb_audio_config_init(audio);
2730 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2731 /* We go ahead and assign values to our audio->out.<properties> */
2732 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
2733 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
2734 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
2735 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
2736 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
2737 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
2739 hb_audio_add( job, audio );
2744 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
2746 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2747 hb_audio_config_init(audio);
2748 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
2749 /* We go ahead and assign values to our audio->out.<properties> */
2750 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
2751 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
2752 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
2753 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
2754 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
2755 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
2757 hb_audio_add( job, audio );
2765 job->filters = hb_list_init();
2767 /* Now lets call the filters if applicable.
2768 * The order of the filters is critical
2772 if ([fPictureController detelecine])
2774 hb_list_add( job->filters, &hb_filter_detelecine );
2778 if ([fPictureController decomb] > 0)
2780 /* Run old deinterlacer fd by default */
2782 hb_filter_decomb.settings = (char *) [[fPicSettingDecomb stringValue] UTF8String];
2783 //hb_filter_decomb.settings = "4:10:15:9:10:35:9"; // <-- jbrjakes recommended parameters as of 5/23/08
2784 hb_list_add( job->filters, &hb_filter_decomb );
2789 if ([fPictureController deinterlace] == 1)
2791 /* Run old deinterlacer fd by default */
2792 hb_filter_deinterlace.settings = "-1";
2793 hb_list_add( job->filters, &hb_filter_deinterlace );
2795 else if ([fPictureController deinterlace] == 2)
2797 /* Yadif mode 0 (without spatial deinterlacing.) */
2798 hb_filter_deinterlace.settings = "2";
2799 hb_list_add( job->filters, &hb_filter_deinterlace );
2801 else if ([fPictureController deinterlace] == 3)
2803 /* Yadif (with spatial deinterlacing) */
2804 hb_filter_deinterlace.settings = "0";
2805 hb_list_add( job->filters, &hb_filter_deinterlace );
2809 if ([fPictureController denoise] == 1) // Weak in popup
2811 hb_filter_denoise.settings = "2:1:2:3";
2812 hb_list_add( job->filters, &hb_filter_denoise );
2814 else if ([fPictureController denoise] == 2) // Medium in popup
2816 hb_filter_denoise.settings = "3:2:2:3";
2817 hb_list_add( job->filters, &hb_filter_denoise );
2819 else if ([fPictureController denoise] == 3) // Strong in popup
2821 hb_filter_denoise.settings = "7:7:5:5";
2822 hb_list_add( job->filters, &hb_filter_denoise );
2825 /* Deblock (uses pp7 default) */
2826 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
2827 * the macgui's purposes a value of 0 actually means to not even use the filter
2828 * current hb_filter_deblock.settings valid ranges are from 5 - 15
2830 if ([fPictureController deblock] != 0)
2832 NSString *deblockStringValue = [NSString stringWithFormat: @"%d",[fPictureController deblock]];
2833 hb_filter_deblock.settings = (char *) [deblockStringValue UTF8String];
2834 hb_list_add( job->filters, &hb_filter_deblock );
2841 #pragma mark Job Handling
2847 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2848 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2849 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2850 hb_job_t * job = title->job;
2851 hb_audio_config_t * audio;
2852 /* Chapter selection */
2853 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
2854 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
2856 /* Format (Muxer) and Video Encoder */
2857 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
2858 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
2861 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
2862 //if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
2864 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
2865 mpeg4 and the checkbox being checked
2866 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
2867 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
2869 job->largeFileSize = 1;
2873 job->largeFileSize = 0;
2875 /* We set http optimized mp4 here */
2876 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
2878 job->mp4_optimize = 1;
2882 job->mp4_optimize = 0;
2887 /* We set the chapter marker extraction here based on the format being
2888 mpeg4 or mkv and the checkbox being checked */
2889 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
2891 job->chapter_markers = 1;
2893 /* now lets get our saved chapter names out the array in the queue file
2894 * and insert them back into the title chapter list. We have it here,
2895 * because unless we are inserting chapter markers there is no need to
2896 * spend the overhead of iterating through the chapter names array imo
2897 * Also, note that if for some reason we don't apply chapter names, the
2898 * chapters just come out 001, 002, etc. etc.
2901 NSMutableArray *ChapterNamesArray = [queueToApply objectForKey:@"ChapterNames"];
2903 NSEnumerator *enumerator = [ChapterNamesArray objectEnumerator];
2905 while (tempObject = [enumerator nextObject])
2907 hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
2908 if( chapter != NULL )
2910 strncpy( chapter->title, [tempObject UTF8String], 1023);
2911 chapter->title[1023] = '\0';
2918 job->chapter_markers = 0;
2921 if( job->vcodec & HB_VCODEC_X264 )
2923 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
2932 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2933 Currently only used with Constant Quality setting*/
2934 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
2938 /* Below Sends x264 options to the core library if x264 is selected*/
2939 /* Lets use this as per Nyx, Thanks Nyx!*/
2940 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2941 /* Turbo first pass if two pass and Turbo First pass is selected */
2942 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
2944 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
2945 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
2946 /* append the "Turbo" string variable to the existing opts string.
2947 Note: the "Turbo" string must be appended, not prepended to work properly*/
2948 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
2949 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
2953 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2959 /* Picture Size Settings */
2960 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2961 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2963 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2964 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2967 /* Here we use the crop values saved at the time the preset was saved */
2968 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2969 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2970 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2971 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2973 /* Video settings */
2976 /* Set vfr to 0 as it's only on if using same as source in the framerate popup
2977 * and detelecine is on, so we handle that in the logic below
2980 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
2982 /* a specific framerate has been chosen */
2983 job->vrate = 27000000;
2984 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
2985 /* We are not same as source so we set job->cfr to 1
2986 * to enable constant frame rate since user has specified
2987 * a specific framerate*/
2992 /* We are same as source (variable) */
2993 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
2994 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
2995 /* We are same as source so we set job->cfr to 0
2996 * to enable true same as source framerate */
2998 /* If we are same as source and we have detelecine on, we need to turn on
3001 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3007 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] != 2 )
3010 Bitrate should already have been calculated and displayed
3011 in fVidBitrateField, so let's just use it same as abr*/
3012 job->vquality = -1.0;
3013 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
3015 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
3017 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
3022 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
3023 /* Subtitle settings */
3024 job->subtitle = [[queueToApply objectForKey:@"JobSubtitlesIndex"] intValue] - 2;
3026 /* Audio tracks and mixdowns */
3027 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3028 int audiotrack_count = hb_list_count(job->list_audio);
3029 for( int i = 0; i < audiotrack_count;i++)
3031 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3032 hb_list_rem(job->list_audio, temp_audio);
3034 /* Now lets add our new tracks to the audio list here */
3035 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
3037 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3038 hb_audio_config_init(audio);
3039 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3040 /* We go ahead and assign values to our audio->out.<properties> */
3041 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
3042 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
3043 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
3044 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
3045 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
3046 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
3048 hb_audio_add( job, audio );
3051 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
3054 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3055 hb_audio_config_init(audio);
3056 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3057 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
3058 /* We go ahead and assign values to our audio->out.<properties> */
3059 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
3060 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
3061 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
3062 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
3063 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
3064 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
3066 hb_audio_add( job, audio );
3070 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
3072 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3073 hb_audio_config_init(audio);
3074 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3075 /* We go ahead and assign values to our audio->out.<properties> */
3076 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
3077 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
3078 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
3079 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
3080 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
3081 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
3083 hb_audio_add( job, audio );
3087 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
3089 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3090 hb_audio_config_init(audio);
3091 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3092 /* We go ahead and assign values to our audio->out.<properties> */
3093 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
3094 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
3095 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
3096 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
3097 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
3098 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue];
3100 hb_audio_add( job, audio );
3105 job->filters = hb_list_init();
3107 /* Now lets call the filters if applicable.
3108 * The order of the filters is critical
3111 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
3113 hb_list_add( job->filters, &hb_filter_detelecine );
3117 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
3119 /* Run old deinterlacer fd by default */
3120 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"JobPictureDecomb"] UTF8String];
3121 hb_list_add( job->filters, &hb_filter_decomb );
3125 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
3127 /* Run old deinterlacer fd by default */
3128 hb_filter_deinterlace.settings = "-1";
3129 hb_list_add( job->filters, &hb_filter_deinterlace );
3131 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
3133 /* Yadif mode 0 (without spatial deinterlacing.) */
3134 hb_filter_deinterlace.settings = "2";
3135 hb_list_add( job->filters, &hb_filter_deinterlace );
3137 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
3139 /* Yadif (with spatial deinterlacing) */
3140 hb_filter_deinterlace.settings = "0";
3141 hb_list_add( job->filters, &hb_filter_deinterlace );
3145 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
3147 hb_filter_denoise.settings = "2:1:2:3";
3148 hb_list_add( job->filters, &hb_filter_denoise );
3150 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
3152 hb_filter_denoise.settings = "3:2:2:3";
3153 hb_list_add( job->filters, &hb_filter_denoise );
3155 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
3157 hb_filter_denoise.settings = "7:7:5:5";
3158 hb_list_add( job->filters, &hb_filter_denoise );
3161 /* Deblock (uses pp7 default) */
3162 /* NOTE: even though there is a valid deblock setting of 0 for the filter, for
3163 * the macgui's purposes a value of 0 actually means to not even use the filter
3164 * current hb_filter_deblock.settings valid ranges are from 5 - 15
3166 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] != 0)
3168 hb_filter_deblock.settings = (char *) [[queueToApply objectForKey:@"PictureDeblock"] UTF8String];
3169 hb_list_add( job->filters, &hb_filter_deblock );
3171 [self writeToActivityLog: "prepareJob exiting"];
3176 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
3178 - (IBAction) addToQueue: (id) sender
3180 /* We get the destination directory from the destination field here */
3181 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3182 /* We check for a valid destination here */
3183 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3185 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3189 /* We check for duplicate name here */
3190 if( [[NSFileManager defaultManager] fileExistsAtPath:
3191 [fDstFile2Field stringValue]] )
3193 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3194 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3195 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
3196 NULL, NULL, [NSString stringWithFormat:
3197 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3198 [fDstFile2Field stringValue]] );
3199 // overwriteAddToQueueAlertDone: will be called when the alert is dismissed.
3203 [self doAddToQueue];
3207 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
3208 the user if they want to overwrite an exiting movie file.
3210 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
3211 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3213 if( returnCode == NSAlertAlternateReturn )
3214 [self doAddToQueue];
3217 - (void) doAddToQueue
3219 [self addQueueFileItem ];
3224 /* Rip: puts up an alert before ultimately calling doRip
3226 - (IBAction) Rip: (id) sender
3228 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
3229 /* Rip or Cancel ? */
3231 hb_get_state2( fQueueEncodeLibhb, &s );
3233 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
3235 [self Cancel: sender];
3239 /* We check to see if we need to warn the user that the computer will go to sleep
3240 or shut down when encoding is finished */
3241 [self remindUserOfSleepOrShutdown];
3243 // If there are pending jobs in the queue, then this is a rip the queue
3244 if (fPendingCount > 0)
3246 /* here lets start the queue with the first pending item */
3247 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3252 // Before adding jobs to the queue, check for a valid destination.
3254 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3255 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
3257 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
3261 /* We check for duplicate name here */
3262 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
3264 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
3265 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
3266 @selector( overWriteAlertDone:returnCode:contextInfo: ),
3267 NULL, NULL, [NSString stringWithFormat:
3268 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
3269 [fDstFile2Field stringValue]] );
3271 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
3275 /* if there are no pending jobs in the queue, then add this one to the queue and rip
3276 otherwise, just rip the queue */
3277 if(fPendingCount == 0)
3279 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
3280 [self doAddToQueue];
3283 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3284 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3285 /* go right to processing the new queue encode */
3286 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
3287 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3292 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
3293 want to overwrite an exiting movie file.
3295 - (void) overWriteAlertDone: (NSWindow *) sheet
3296 returnCode: (int) returnCode contextInfo: (void *) contextInfo
3298 if( returnCode == NSAlertAlternateReturn )
3300 /* if there are no jobs in the queue, then add this one to the queue and rip
3301 otherwise, just rip the queue */
3302 if( fPendingCount == 0 )
3304 [self doAddToQueue];
3307 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
3308 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
3309 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3314 - (void) remindUserOfSleepOrShutdown
3316 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
3318 /*Warn that computer will sleep after encoding*/
3321 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);
3322 [NSApp requestUserAttention:NSCriticalRequest];
3323 if ( reminduser == NSAlertAlternateReturn )
3325 [self showPreferencesWindow:nil];
3328 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
3330 /*Warn that computer will shut down after encoding*/
3333 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);
3334 [NSApp requestUserAttention:NSCriticalRequest];
3335 if ( reminduser == NSAlertAlternateReturn )
3337 [self showPreferencesWindow:nil];
3346 /* Let libhb do the job */
3347 hb_start( fQueueEncodeLibhb );
3348 /*set the fEncodeState State */
3353 //------------------------------------------------------------------------------------
3354 // Displays an alert asking user if the want to cancel encoding of current job.
3355 // Cancel: returns immediately after posting the alert. Later, when the user
3356 // acknowledges the alert, doCancelCurrentJob is called.
3357 //------------------------------------------------------------------------------------
3358 - (IBAction)Cancel: (id)sender
3360 if (!fQueueController) return;
3362 hb_pause( fQueueEncodeLibhb );
3363 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"You are currently encoding. What would you like to do ?", nil)];
3365 // Which window to attach the sheet to?
3366 NSWindow * docWindow;
3367 if ([sender respondsToSelector: @selector(window)])
3368 docWindow = [sender window];
3370 docWindow = fWindow;
3372 NSBeginCriticalAlertSheet(
3374 NSLocalizedString(@"Continue Encoding", nil),
3375 NSLocalizedString(@"Cancel Current and Stop", nil),
3376 NSLocalizedString(@"Cancel Current and Continue", nil),
3378 nil, @selector(didDimissCancel:returnCode:contextInfo:), nil,
3379 NSLocalizedString(@"Your encode will be cancelled if you don't continue encoding.", nil));
3381 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
3384 - (void) didDimissCancel: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
3386 hb_resume( fQueueEncodeLibhb );
3387 if (returnCode == NSAlertOtherReturn)
3389 [self doCancelCurrentJob]; // <- this also stops libhb
3391 if (returnCode == NSAlertAlternateReturn)
3393 [self doCancelCurrentJobAndStop];
3397 //------------------------------------------------------------------------------------
3398 // Cancels and deletes the current job and stops libhb from processing the remaining
3400 //------------------------------------------------------------------------------------
3401 - (void) doCancelCurrentJob
3403 // Stop the current job. hb_stop will only cancel the current pass and then set
3404 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
3405 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
3406 // remaining passes of the job and then start the queue back up if there are any
3410 hb_stop( fQueueEncodeLibhb );
3412 // Delete all remaining jobs since libhb doesn't do this on its own.
3414 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3415 hb_rem( fQueueEncodeLibhb, job );
3417 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3419 // now that we've stopped the currently encoding job, lets mark it as cancelled
3420 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3421 // and as always, save it in the queue .plist...
3422 /* We save all of the Queue data here */
3423 [self saveQueueFileItem];
3424 // so now lets move to
3425 currentQueueEncodeIndex++ ;
3426 // ... and see if there are more items left in our queue
3427 int queueItems = [QueueFileArray count];
3428 /* If we still have more items in our queue, lets go to the next one */
3429 if (currentQueueEncodeIndex < queueItems)
3431 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
3432 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
3434 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
3438 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
3443 - (void) doCancelCurrentJobAndStop
3445 hb_stop( fQueueEncodeLibhb );
3447 // Delete all remaining jobs since libhb doesn't do this on its own.
3449 while( ( job = hb_job(fQueueEncodeLibhb, 0) ) )
3450 hb_rem( fQueueEncodeLibhb, job );
3453 fEncodeState = 2; // don't alert at end of processing since this was a cancel
3455 // now that we've stopped the currently encoding job, lets mark it as cancelled
3456 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
3457 // and as always, save it in the queue .plist...
3458 /* We save all of the Queue data here */
3459 [self saveQueueFileItem];
3460 // so now lets move to
3461 currentQueueEncodeIndex++ ;
3462 [self writeToActivityLog: "cancelling current job and stopping the queue"];
3464 - (IBAction) Pause: (id) sender
3467 hb_get_state2( fQueueEncodeLibhb, &s );
3469 if( s.state == HB_STATE_PAUSED )
3471 hb_resume( fQueueEncodeLibhb );
3475 hb_pause( fQueueEncodeLibhb );
3480 #pragma mark GUI Controls Changed Methods
3482 - (IBAction) titlePopUpChanged: (id) sender
3484 hb_list_t * list = hb_get_titles( fHandle );
3485 hb_title_t * title = (hb_title_t*)
3486 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3488 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3489 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3491 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3492 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3493 [browsedSourceDisplayName stringByDeletingPathExtension],
3495 [[fDstFile2Field stringValue] pathExtension]]];
3498 /* Update chapter popups */
3499 [fSrcChapterStartPopUp removeAllItems];
3500 [fSrcChapterEndPopUp removeAllItems];
3501 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
3503 [fSrcChapterStartPopUp addItemWithTitle: [NSString
3504 stringWithFormat: @"%d", i + 1]];
3505 [fSrcChapterEndPopUp addItemWithTitle: [NSString
3506 stringWithFormat: @"%d", i + 1]];
3509 [fSrcChapterStartPopUp selectItemAtIndex: 0];
3510 [fSrcChapterEndPopUp selectItemAtIndex:
3511 hb_list_count( title->list_chapter ) - 1];
3512 [self chapterPopUpChanged:nil];
3514 /* Start Get and set the initial pic size for display */
3515 hb_job_t * job = title->job;
3518 /* Reset the new title in fPictureController */
3519 [fPictureController SetTitle:title];
3521 /*Set Source Size Field Here */
3522 [fPicSettingsSrc setStringValue: [NSString stringWithFormat: @"%d x %d", fTitle->width, fTitle->height]];
3524 /* Set Auto Crop to on upon selecting a new title */
3525 [fPictureController setAutoCrop:YES];
3527 /* We get the originial output picture width and height and put them
3528 in variables for use with some presets later on */
3529 PicOrigOutputWidth = job->width;
3530 PicOrigOutputHeight = job->height;
3531 AutoCropTop = job->crop[0];
3532 AutoCropBottom = job->crop[1];
3533 AutoCropLeft = job->crop[2];
3534 AutoCropRight = job->crop[3];
3536 /* Run Through encoderPopUpChanged to see if there
3537 needs to be any pic value modifications based on encoder settings */
3538 //[self encoderPopUpChanged: NULL];
3539 /* END Get and set the initial pic size for display */
3541 /* Update subtitle popups */
3542 hb_subtitle_t * subtitle;
3543 [fSubPopUp removeAllItems];
3544 [fSubPopUp addItemWithTitle: @"None"];
3545 [fSubPopUp addItemWithTitle: @"Autoselect"];
3546 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
3548 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
3550 /* We cannot use NSPopUpButton's addItemWithTitle because
3551 it checks for duplicate entries */
3552 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
3553 subtitle->lang] action: NULL keyEquivalent: @""];
3555 [fSubPopUp selectItemAtIndex: 0];
3557 [self subtitleSelectionChanged:nil];
3559 /* Update chapter table */
3560 [fChapterTitlesDelegate resetWithTitle:title];
3561 [fChapterTable reloadData];
3563 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3564 int audiotrack_count = hb_list_count(job->list_audio);
3565 for( int i = 0; i < audiotrack_count;i++)
3567 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3568 hb_list_rem(job->list_audio, temp_audio);
3571 /* Update audio popups */
3572 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
3573 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
3574 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
3575 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
3576 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
3577 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
3578 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
3579 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3580 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3581 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3583 /* changing the title may have changed the audio channels on offer, */
3584 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3585 [self audioTrackPopUpChanged: fAudLang1PopUp];
3586 [self audioTrackPopUpChanged: fAudLang2PopUp];
3587 [self audioTrackPopUpChanged: fAudLang3PopUp];
3588 [self audioTrackPopUpChanged: fAudLang4PopUp];
3590 [fVidRatePopUp selectItemAtIndex: 0];
3592 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
3593 [self calculatePictureSizing:nil];
3595 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
3596 [self selectPreset:nil];
3599 - (IBAction) chapterPopUpChanged: (id) sender
3602 /* If start chapter popup is greater than end chapter popup,
3603 we set the end chapter popup to the same as start chapter popup */
3604 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
3606 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
3610 hb_list_t * list = hb_get_titles( fHandle );
3611 hb_title_t * title = (hb_title_t *)
3612 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3614 hb_chapter_t * chapter;
3615 int64_t duration = 0;
3616 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
3617 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
3619 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3620 duration += chapter->duration;
3623 duration /= 90000; /* pts -> seconds */
3624 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
3625 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
3628 [self calculateBitrate: sender];
3631 - (IBAction) formatPopUpChanged: (id) sender
3633 NSString * string = [fDstFile2Field stringValue];
3634 int format = [fDstFormatPopUp indexOfSelectedItem];
3636 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
3637 [fDstMp4LargeFileCheck setHidden: YES];
3638 [fDstMp4HttpOptFileCheck setHidden: YES];
3639 [fDstMp4iPodFileCheck setHidden: YES];
3641 /* Update the Video Codec PopUp */
3642 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
3643 [fVidEncoderPopUp removeAllItems];
3644 NSMenuItem *menuItem;
3645 /* These video encoders are available to all of our current muxers, so lets list them once here */
3646 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
3647 [menuItem setTag: HB_VCODEC_FFMPEG];
3649 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (XviD)" action: NULL keyEquivalent: @""];
3650 [menuItem setTag: HB_VCODEC_XVID];
3654 /*Get Default MP4 File Extension*/
3655 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
3663 /* Add additional video encoders here */
3664 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3665 [menuItem setTag: HB_VCODEC_X264];
3666 /* We show the mp4 option checkboxes here since we are mp4 */
3667 [fCreateChapterMarkers setEnabled: YES];
3668 [fDstMp4LargeFileCheck setHidden: NO];
3669 [fDstMp4HttpOptFileCheck setHidden: NO];
3670 [fDstMp4iPodFileCheck setHidden: NO];
3675 /* Add additional video encoders here */
3676 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3677 [menuItem setTag: HB_VCODEC_X264];
3678 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3679 [menuItem setTag: HB_VCODEC_THEORA];
3680 /* We enable the create chapters checkbox here */
3681 [fCreateChapterMarkers setEnabled: YES];
3686 /* Add additional video encoders here */
3687 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3688 [menuItem setTag: HB_VCODEC_X264];
3689 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3690 [fCreateChapterMarkers setEnabled: NO];
3691 [fCreateChapterMarkers setState: NSOffState];
3696 /* Add additional video encoders here */
3697 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3698 [menuItem setTag: HB_VCODEC_THEORA];
3699 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3700 [fCreateChapterMarkers setEnabled: NO];
3701 [fCreateChapterMarkers setState: NSOffState];
3704 [fVidEncoderPopUp selectItemAtIndex: 0];
3706 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
3707 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
3708 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
3709 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
3712 [self autoSetM4vExtension: sender];
3714 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
3716 if( SuccessfulScan )
3718 /* Add/replace to the correct extension */
3719 [self audioTrackPopUpChanged: fAudLang1PopUp];
3720 [self audioTrackPopUpChanged: fAudLang2PopUp];
3721 [self audioTrackPopUpChanged: fAudLang3PopUp];
3722 [self audioTrackPopUpChanged: fAudLang4PopUp];
3724 if( [fVidEncoderPopUp selectedItem] == nil )
3727 [fVidEncoderPopUp selectItemAtIndex:0];
3728 [self videoEncoderPopUpChanged:nil];
3730 /* changing the format may mean that we can / can't offer mono or 6ch, */
3731 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3733 /* We call the method to properly enable/disable turbo 2 pass */
3734 [self twoPassCheckboxChanged: sender];
3735 /* We call method method to change UI to reflect whether a preset is used or not*/
3738 [self customSettingUsed: sender];
3741 - (IBAction) autoSetM4vExtension: (id) sender
3743 if ( [fDstFormatPopUp indexOfSelectedItem] )
3746 NSString * extension = @"mp4";
3748 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3749 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3750 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3751 [fCreateChapterMarkers state] == NSOnState ||
3752 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
3757 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
3760 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
3761 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
3764 /* Method to determine if we should change the UI
3765 To reflect whether or not a Preset is being used or if
3766 the user is using "Custom" settings by determining the sender*/
3767 - (IBAction) customSettingUsed: (id) sender
3769 if ([sender stringValue])
3771 /* Deselect the currently selected Preset if there is one*/
3772 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
3773 /* Change UI to show "Custom" settings are being used */
3774 [fPresetSelectedDisplay setStringValue: @"Custom"];
3776 curUserPresetChosenNum = nil;
3778 [self calculateBitrate:nil];
3783 #pragma mark - Video
3785 - (IBAction) videoEncoderPopUpChanged: (id) sender
3787 hb_job_t * job = fTitle->job;
3788 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
3790 [fAdvancedOptions setHidden:YES];
3791 /* If we are using x264 then show the x264 advanced panel*/
3792 if (videoEncoder == HB_VCODEC_X264)
3794 [fAdvancedOptions setHidden:NO];
3795 [self autoSetM4vExtension: sender];
3798 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
3799 is being used as it borks up loose anamorphic .
3800 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
3801 to use the index itself but this is easier */
3802 if (videoEncoder == HB_VCODEC_FFMPEG)
3804 if (job->pixel_ratio == 2)
3806 job->pixel_ratio = 0;
3808 [fPictureController setAllowLooseAnamorphic:NO];
3809 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
3810 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
3811 anything other than MP4.
3813 [fDstMp4iPodFileCheck setEnabled: NO];
3814 [fDstMp4iPodFileCheck setState: NSOffState];
3818 [fPictureController setAllowLooseAnamorphic:YES];
3819 [fDstMp4iPodFileCheck setEnabled: YES];
3822 [self calculatePictureSizing: sender];
3823 [self twoPassCheckboxChanged: sender];
3827 - (IBAction) twoPassCheckboxChanged: (id) sender
3829 /* check to see if x264 is chosen */
3830 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
3832 if( [fVidTwoPassCheck state] == NSOnState)
3834 [fVidTurboPassCheck setHidden: NO];
3838 [fVidTurboPassCheck setHidden: YES];
3839 [fVidTurboPassCheck setState: NSOffState];
3841 /* Make sure Two Pass is checked if Turbo is checked */
3842 if( [fVidTurboPassCheck state] == NSOnState)
3844 [fVidTwoPassCheck setState: NSOnState];
3849 [fVidTurboPassCheck setHidden: YES];
3850 [fVidTurboPassCheck setState: NSOffState];
3853 /* We call method method to change UI to reflect whether a preset is used or not*/
3854 [self customSettingUsed: sender];
3857 - (IBAction ) videoFrameRateChanged: (id) sender
3859 /* We call method method to calculatePictureSizing to error check detelecine*/
3860 [self calculatePictureSizing: sender];
3862 /* We call method method to change UI to reflect whether a preset is used or not*/
3863 [self customSettingUsed: sender];
3865 - (IBAction) videoMatrixChanged: (id) sender;
3867 bool target, bitrate, quality;
3869 target = bitrate = quality = false;
3870 if( [fVidQualityMatrix isEnabled] )
3872 switch( [fVidQualityMatrix selectedRow] )
3885 [fVidTargetSizeField setEnabled: target];
3886 [fVidBitrateField setEnabled: bitrate];
3887 [fVidQualitySlider setEnabled: quality];
3888 [fVidTwoPassCheck setEnabled: !quality &&
3889 [fVidQualityMatrix isEnabled]];
3892 [fVidTwoPassCheck setState: NSOffState];
3893 [fVidTurboPassCheck setHidden: YES];
3894 [fVidTurboPassCheck setState: NSOffState];
3897 [self qualitySliderChanged: sender];
3898 [self calculateBitrate: sender];
3899 [self customSettingUsed: sender];
3902 - (IBAction) qualitySliderChanged: (id) sender
3904 [fVidConstantCell setTitle: [NSString stringWithFormat:
3905 NSLocalizedString( @"Constant quality: %.0f %%", @"" ), 100.0 *
3906 [fVidQualitySlider floatValue]]];
3907 [self customSettingUsed: sender];
3910 - (void) controlTextDidChange: (NSNotification *) notification
3912 [self calculateBitrate:nil];
3915 - (IBAction) calculateBitrate: (id) sender
3917 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
3922 hb_list_t * list = hb_get_titles( fHandle );
3923 hb_title_t * title = (hb_title_t *) hb_list_item( list,
3924 [fSrcTitlePopUp indexOfSelectedItem] );
3925 hb_job_t * job = title->job;
3926 hb_audio_config_t * audio;
3927 /* For hb_calc_bitrate in addition to the Target Size in MB out of the
3928 * Target Size Field, we also need the job info for the Muxer, the Chapters
3929 * as well as all of the audio track info.
3930 * This used to be accomplished by simply calling prepareJob here, however
3931 * since the resilient queue sets the queue array values instead of the job
3932 * values directly, we duplicate the old prepareJob code here for the variables
3935 job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
3936 job->chapter_end = [fSrcChapterEndPopUp indexOfSelectedItem] + 1;
3937 job->mux = [[fDstFormatPopUp selectedItem] tag];
3939 /* Audio goes here */
3940 int audiotrack_count = hb_list_count(job->list_audio);
3941 for( int i = 0; i < audiotrack_count;i++)
3943 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3944 hb_list_rem(job->list_audio, temp_audio);
3946 /* Now we need our audio info here for each track if applicable */
3947 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
3949 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3950 hb_audio_config_init(audio);
3951 audio->in.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
3952 /* We go ahead and assign values to our audio->out.<properties> */
3953 audio->out.track = [fAudLang1PopUp indexOfSelectedItem] - 1;
3954 audio->out.codec = [[fAudTrack1CodecPopUp selectedItem] tag];
3955 audio->out.mixdown = [[fAudTrack1MixPopUp selectedItem] tag];
3956 audio->out.bitrate = [[fAudTrack1BitratePopUp selectedItem] tag];
3957 audio->out.samplerate = [[fAudTrack1RatePopUp selectedItem] tag];
3958 audio->out.dynamic_range_compression = [fAudTrack1DrcField floatValue];
3960 hb_audio_add( job, audio );
3963 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
3965 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3966 hb_audio_config_init(audio);
3967 audio->in.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
3968 /* We go ahead and assign values to our audio->out.<properties> */
3969 audio->out.track = [fAudLang2PopUp indexOfSelectedItem] - 1;
3970 audio->out.codec = [[fAudTrack2CodecPopUp selectedItem] tag];
3971 audio->out.mixdown = [[fAudTrack2MixPopUp selectedItem] tag];
3972 audio->out.bitrate = [[fAudTrack2BitratePopUp selectedItem] tag];
3973 audio->out.samplerate = [[fAudTrack2RatePopUp selectedItem] tag];
3974 audio->out.dynamic_range_compression = [fAudTrack2DrcField floatValue];
3976 hb_audio_add( job, audio );
3981 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
3983 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
3984 hb_audio_config_init(audio);
3985 audio->in.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3986 /* We go ahead and assign values to our audio->out.<properties> */
3987 audio->out.track = [fAudLang3PopUp indexOfSelectedItem] - 1;
3988 audio->out.codec = [[fAudTrack3CodecPopUp selectedItem] tag];
3989 audio->out.mixdown = [[fAudTrack3MixPopUp selectedItem] tag];
3990 audio->out.bitrate = [[fAudTrack3BitratePopUp selectedItem] tag];
3991 audio->out.samplerate = [[fAudTrack3RatePopUp selectedItem] tag];
3992 audio->out.dynamic_range_compression = [fAudTrack3DrcField floatValue];
3994 hb_audio_add( job, audio );
3999 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4001 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
4002 hb_audio_config_init(audio);
4003 audio->in.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4004 /* We go ahead and assign values to our audio->out.<properties> */
4005 audio->out.track = [fAudLang4PopUp indexOfSelectedItem] - 1;
4006 audio->out.codec = [[fAudTrack4CodecPopUp selectedItem] tag];
4007 audio->out.mixdown = [[fAudTrack4MixPopUp selectedItem] tag];
4008 audio->out.bitrate = [[fAudTrack4BitratePopUp selectedItem] tag];
4009 audio->out.samplerate = [[fAudTrack4RatePopUp selectedItem] tag];
4010 audio->out.dynamic_range_compression = [fAudTrack4DrcField floatValue];
4012 hb_audio_add( job, audio );
4017 [fVidBitrateField setIntValue: hb_calc_bitrate( job, [fVidTargetSizeField intValue] )];
4021 #pragma mark - Picture
4023 /* lets set the picture size back to the max from right after title scan
4024 Lets use an IBAction here as down the road we could always use a checkbox
4025 in the gui to easily take the user back to max. Remember, the compiler
4026 resolves IBActions down to -(void) during compile anyway */
4027 - (IBAction) revertPictureSizeToMax: (id) sender
4029 hb_job_t * job = fTitle->job;
4030 /* Here we apply the max source storage width and height */
4031 job->width = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
4032 job->height = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
4034 [self calculatePictureSizing: sender];
4035 /* We call method to change UI to reflect whether a preset is used or not*/
4036 [self customSettingUsed: sender];
4040 * Registers changes made in the Picture Settings Window.
4043 - (void)pictureSettingsDidChange {
4044 [self calculatePictureSizing:nil];
4047 /* Get and Display Current Pic Settings in main window */
4048 - (IBAction) calculatePictureSizing: (id) sender
4050 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", fTitle->job->width, fTitle->job->height]];
4052 if (fTitle->job->pixel_ratio == 1)
4054 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
4055 int arpwidth = fTitle->job->pixel_aspect_width;
4056 int arpheight = fTitle->job->pixel_aspect_height;
4057 int displayparwidth = titlewidth * arpwidth / arpheight;
4058 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
4059 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", titlewidth, displayparheight]];
4060 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Strict", displayparwidth, displayparheight]];
4061 fTitle->job->keep_ratio = 0;
4063 else if (fTitle->job->pixel_ratio == 2)
4065 hb_job_t * job = fTitle->job;
4066 int output_width, output_height, output_par_width, output_par_height;
4067 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
4069 display_width = output_width * output_par_width / output_par_height;
4071 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", output_width, output_height]];
4072 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Loose", display_width, output_height]];
4074 fTitle->job->keep_ratio = 0;
4078 [fPicSettingsAnamorphic setStringValue:@"Off"];
4081 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
4082 if (fTitle->job->keep_ratio > 0)
4084 [fPicSettingARkeep setStringValue: @"On"];
4088 [fPicSettingARkeep setStringValue: @"Off"];
4092 if ([fPictureController detelecine])
4094 [fPicSettingDetelecine setStringValue: @"Yes"];
4098 [fPicSettingDetelecine setStringValue: @"Off"];
4102 if ([fPictureController decomb])
4104 [fPicSettingDecomb setStringValue: @"1:2:6:9:80:16:16"];
4108 [fPicSettingDecomb setStringValue: @"Off"];
4112 /* VFR (Variable Frame Rate) */
4116 if ([fPictureController deinterlace] == 0)
4118 [fPicSettingDeinterlace setStringValue: @"Off"];
4120 else if ([fPictureController deinterlace] == 1)
4122 [fPicSettingDeinterlace setStringValue: @"Fast"];
4124 else if ([fPictureController deinterlace] == 2)
4126 [fPicSettingDeinterlace setStringValue: @"Slow"];
4128 else if ([fPictureController deinterlace] == 3)
4130 [fPicSettingDeinterlace setStringValue: @"Slower"];
4134 if ([fPictureController denoise] == 0)
4136 [fPicSettingDenoise setStringValue: @"Off"];
4138 else if ([fPictureController denoise] == 1)
4140 [fPicSettingDenoise setStringValue: @"Weak"];
4142 else if ([fPictureController denoise] == 2)
4144 [fPicSettingDenoise setStringValue: @"Medium"];
4146 else if ([fPictureController denoise] == 3)
4148 [fPicSettingDenoise setStringValue: @"Strong"];
4152 if ([fPictureController deblock] == 0)
4154 [fPicSettingDeblock setStringValue: @"Off"];
4158 [fPicSettingDeblock setStringValue: [NSString stringWithFormat:@"%d",[fPictureController deblock]]];
4161 if (fTitle->job->pixel_ratio > 0)
4163 [fPicSettingPAR setStringValue: @""];
4167 [fPicSettingPAR setStringValue: @"Off"];
4170 /* Set the display field for crop as per boolean */
4171 if (![fPictureController autoCrop])
4173 [fPicSettingAutoCrop setStringValue: @"Custom"];
4177 [fPicSettingAutoCrop setStringValue: @"Auto"];
4180 //[self showPicturePanel:self];
4181 hb_list_t * list = hb_get_titles( fHandle );
4182 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4183 [fSrcTitlePopUp indexOfSelectedItem] );
4184 [fPictureController SetTitle:title];
4189 #pragma mark - Audio and Subtitles
4190 - (IBAction) audioCodecsPopUpChanged: (id) sender
4193 NSPopUpButton * audiotrackPopUp;
4194 NSPopUpButton * sampleratePopUp;
4195 NSPopUpButton * bitratePopUp;
4196 NSPopUpButton * audiocodecPopUp;
4197 if (sender == fAudTrack1CodecPopUp)
4199 audiotrackPopUp = fAudLang1PopUp;
4200 audiocodecPopUp = fAudTrack1CodecPopUp;
4201 sampleratePopUp = fAudTrack1RatePopUp;
4202 bitratePopUp = fAudTrack1BitratePopUp;
4204 else if (sender == fAudTrack2CodecPopUp)
4206 audiotrackPopUp = fAudLang2PopUp;
4207 audiocodecPopUp = fAudTrack2CodecPopUp;
4208 sampleratePopUp = fAudTrack2RatePopUp;
4209 bitratePopUp = fAudTrack2BitratePopUp;
4211 else if (sender == fAudTrack3CodecPopUp)
4213 audiotrackPopUp = fAudLang3PopUp;
4214 audiocodecPopUp = fAudTrack3CodecPopUp;
4215 sampleratePopUp = fAudTrack3RatePopUp;
4216 bitratePopUp = fAudTrack3BitratePopUp;
4220 audiotrackPopUp = fAudLang4PopUp;
4221 audiocodecPopUp = fAudTrack4CodecPopUp;
4222 sampleratePopUp = fAudTrack4RatePopUp;
4223 bitratePopUp = fAudTrack4BitratePopUp;
4226 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
4227 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
4228 [self audioTrackPopUpChanged: audiotrackPopUp];
4232 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
4234 /* We will be setting the enabled/disabled state of each tracks audio controls based on
4235 * the settings of the source audio for that track. We leave the samplerate and bitrate
4236 * to audiotrackMixdownChanged
4239 /* We will first verify that a lower track number has been selected before enabling each track
4240 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
4242 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4244 [fAudLang2PopUp setEnabled: NO];
4245 [fAudLang2PopUp selectItemAtIndex: 0];
4249 [fAudLang2PopUp setEnabled: YES];
4252 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4254 [fAudLang3PopUp setEnabled: NO];
4255 [fAudLang3PopUp selectItemAtIndex: 0];
4259 [fAudLang3PopUp setEnabled: YES];
4261 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4263 [fAudLang4PopUp setEnabled: NO];
4264 [fAudLang4PopUp selectItemAtIndex: 0];
4268 [fAudLang4PopUp setEnabled: YES];
4270 /* enable/disable the mixdown text and popupbutton for audio track 1 */
4271 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4272 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4273 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4274 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4275 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4276 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
4277 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4279 [fAudTrack1CodecPopUp removeAllItems];
4280 [fAudTrack1MixPopUp removeAllItems];
4281 [fAudTrack1RatePopUp removeAllItems];
4282 [fAudTrack1BitratePopUp removeAllItems];
4283 [fAudTrack1DrcSlider setFloatValue: 1.00];
4284 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
4286 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
4288 [fAudTrack1RatePopUp setEnabled: NO];
4289 [fAudTrack1BitratePopUp setEnabled: NO];
4290 [fAudTrack1DrcSlider setEnabled: NO];
4291 [fAudTrack1DrcField setEnabled: NO];
4294 /* enable/disable the mixdown text and popupbutton for audio track 2 */
4295 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4296 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4297 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4298 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4299 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4300 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
4301 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
4303 [fAudTrack2CodecPopUp removeAllItems];
4304 [fAudTrack2MixPopUp removeAllItems];
4305 [fAudTrack2RatePopUp removeAllItems];
4306 [fAudTrack2BitratePopUp removeAllItems];
4307 [fAudTrack2DrcSlider setFloatValue: 1.00];
4308 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
4310 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
4312 [fAudTrack2RatePopUp setEnabled: NO];
4313 [fAudTrack2BitratePopUp setEnabled: NO];
4314 [fAudTrack2DrcSlider setEnabled: NO];
4315 [fAudTrack2DrcField setEnabled: NO];
4318 /* enable/disable the mixdown text and popupbutton for audio track 3 */
4319 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4320 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4321 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4322 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4323 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4324 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
4325 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
4327 [fAudTrack3CodecPopUp removeAllItems];
4328 [fAudTrack3MixPopUp removeAllItems];
4329 [fAudTrack3RatePopUp removeAllItems];
4330 [fAudTrack3BitratePopUp removeAllItems];
4331 [fAudTrack3DrcSlider setFloatValue: 1.00];
4332 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
4334 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
4336 [fAudTrack3RatePopUp setEnabled: NO];
4337 [fAudTrack3BitratePopUp setEnabled: NO];
4338 [fAudTrack3DrcSlider setEnabled: NO];
4339 [fAudTrack3DrcField setEnabled: NO];
4342 /* enable/disable the mixdown text and popupbutton for audio track 4 */
4343 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4344 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4345 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4346 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4347 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4348 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
4349 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
4351 [fAudTrack4CodecPopUp removeAllItems];
4352 [fAudTrack4MixPopUp removeAllItems];
4353 [fAudTrack4RatePopUp removeAllItems];
4354 [fAudTrack4BitratePopUp removeAllItems];
4355 [fAudTrack4DrcSlider setFloatValue: 1.00];
4356 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
4358 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
4360 [fAudTrack4RatePopUp setEnabled: NO];
4361 [fAudTrack4BitratePopUp setEnabled: NO];
4362 [fAudTrack4DrcSlider setEnabled: NO];
4363 [fAudTrack4DrcField setEnabled: NO];
4368 - (IBAction) addAllAudioTracksToPopUp: (id) sender
4371 hb_list_t * list = hb_get_titles( fHandle );
4372 hb_title_t * title = (hb_title_t*)
4373 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
4375 hb_audio_config_t * audio;
4377 [sender removeAllItems];
4378 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
4379 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
4381 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
4382 [[sender menu] addItemWithTitle:
4383 [NSString stringWithCString: audio->lang.description]
4384 action: NULL keyEquivalent: @""];
4386 [sender selectItemAtIndex: 0];
4390 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
4393 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
4394 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
4395 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
4396 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
4398 if (searchPrefixString)
4401 for( int i = 0; i < [sender numberOfItems]; i++ )
4403 /* Try to find the desired search string */
4404 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
4406 [sender selectItemAtIndex: i];
4410 /* couldn't find the string, so select the requested "search string not found" item */
4411 /* index of 0 means select the "none" item */
4412 /* index of 1 means select the first audio track */
4413 [sender selectItemAtIndex: selectIndexIfNotFound];
4417 /* if no search string is provided, then select the selectIndexIfNotFound item */
4418 [sender selectItemAtIndex: selectIndexIfNotFound];
4422 - (IBAction) audioAddAudioTrackCodecs: (id)sender
4424 int format = [fDstFormatPopUp indexOfSelectedItem];
4426 /* setup pointers to the appropriate popups for the correct track */
4427 NSPopUpButton * audiocodecPopUp;
4428 NSPopUpButton * audiotrackPopUp;
4429 if (sender == fAudTrack1CodecPopUp)
4431 audiotrackPopUp = fAudLang1PopUp;
4432 audiocodecPopUp = fAudTrack1CodecPopUp;
4434 else if (sender == fAudTrack2CodecPopUp)
4436 audiotrackPopUp = fAudLang2PopUp;
4437 audiocodecPopUp = fAudTrack2CodecPopUp;
4439 else if (sender == fAudTrack3CodecPopUp)
4441 audiotrackPopUp = fAudLang3PopUp;
4442 audiocodecPopUp = fAudTrack3CodecPopUp;
4446 audiotrackPopUp = fAudLang4PopUp;
4447 audiocodecPopUp = fAudTrack4CodecPopUp;
4450 [audiocodecPopUp removeAllItems];
4451 /* Make sure "None" isnt selected in the source track */
4452 if ([audiotrackPopUp indexOfSelectedItem] > 0)
4454 [audiocodecPopUp setEnabled:YES];
4455 NSMenuItem *menuItem;
4456 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
4462 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4463 [menuItem setTag: HB_ACODEC_FAAC];
4466 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4467 [menuItem setTag: HB_ACODEC_AC3];
4473 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
4474 [menuItem setTag: HB_ACODEC_FAAC];
4476 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4477 [menuItem setTag: HB_ACODEC_AC3];
4479 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4480 [menuItem setTag: HB_ACODEC_LAME];
4482 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4483 [menuItem setTag: HB_ACODEC_VORBIS];
4489 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4490 [menuItem setTag: HB_ACODEC_LAME];
4492 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
4493 [menuItem setTag: HB_ACODEC_AC3];
4499 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
4500 [menuItem setTag: HB_ACODEC_VORBIS];
4502 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
4503 [menuItem setTag: HB_ACODEC_LAME];
4506 [audiocodecPopUp selectItemAtIndex:0];
4510 [audiocodecPopUp setEnabled:NO];
4514 - (IBAction) audioTrackPopUpChanged: (id) sender
4516 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
4517 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
4520 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
4523 /* make sure we have a selected title before continuing */
4524 if (fTitle == NULL) return;
4525 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
4526 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
4528 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
4530 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4532 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
4534 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4536 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
4538 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4540 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
4542 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4545 /* Now lets make the sender the appropriate Audio Track popup from this point on */
4546 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
4548 sender = fAudLang1PopUp;
4550 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
4552 sender = fAudLang2PopUp;
4554 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
4556 sender = fAudLang3PopUp;
4558 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
4560 sender = fAudLang4PopUp;
4563 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
4564 NSPopUpButton * mixdownPopUp;
4565 NSPopUpButton * audiocodecPopUp;
4566 NSPopUpButton * sampleratePopUp;
4567 NSPopUpButton * bitratePopUp;
4568 if (sender == fAudLang1PopUp)
4570 mixdownPopUp = fAudTrack1MixPopUp;
4571 audiocodecPopUp = fAudTrack1CodecPopUp;
4572 sampleratePopUp = fAudTrack1RatePopUp;
4573 bitratePopUp = fAudTrack1BitratePopUp;
4575 else if (sender == fAudLang2PopUp)
4577 mixdownPopUp = fAudTrack2MixPopUp;
4578 audiocodecPopUp = fAudTrack2CodecPopUp;
4579 sampleratePopUp = fAudTrack2RatePopUp;
4580 bitratePopUp = fAudTrack2BitratePopUp;
4582 else if (sender == fAudLang3PopUp)
4584 mixdownPopUp = fAudTrack3MixPopUp;
4585 audiocodecPopUp = fAudTrack3CodecPopUp;
4586 sampleratePopUp = fAudTrack3RatePopUp;
4587 bitratePopUp = fAudTrack3BitratePopUp;
4591 mixdownPopUp = fAudTrack4MixPopUp;
4592 audiocodecPopUp = fAudTrack4CodecPopUp;
4593 sampleratePopUp = fAudTrack4RatePopUp;
4594 bitratePopUp = fAudTrack4BitratePopUp;
4597 /* get the index of the selected audio Track*/
4598 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
4600 /* pointer for the hb_audio_s struct we will use later on */
4601 hb_audio_config_t * audio;
4604 /* check if the audio mixdown controls need their enabled state changing */
4605 [self setEnabledStateOfAudioMixdownControls:nil];
4607 if (thisAudioIndex != -1)
4611 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
4613 /* actually manipulate the proper mixdowns here */
4614 /* delete the previous audio mixdown options */
4615 [mixdownPopUp removeAllItems];
4617 acodec = [[audiocodecPopUp selectedItem] tag];
4622 /* find out if our selected output audio codec supports mono and / or 6ch */
4623 /* we also check for an input codec of AC3 or DCA,
4624 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
4625 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
4626 but this may change in the future, so they are separated for flexibility */
4627 int audioCodecsSupportMono =
4628 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4629 (acodec != HB_ACODEC_LAME);
4630 int audioCodecsSupport6Ch =
4631 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4632 (acodec != HB_ACODEC_LAME);
4634 /* check for AC-3 passthru */
4635 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4638 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4639 [NSString stringWithCString: "AC3 Passthru"]
4640 action: NULL keyEquivalent: @""];
4641 [menuItem setTag: HB_ACODEC_AC3];
4646 /* add the appropriate audio mixdown menuitems to the popupbutton */
4647 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
4648 so that we can reference the mixdown later */
4650 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
4651 int minMixdownUsed = 0;
4652 int maxMixdownUsed = 0;
4654 /* get the input channel layout without any lfe channels */
4655 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4657 /* do we want to add a mono option? */
4658 if (audioCodecsSupportMono == 1)
4660 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4661 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
4662 action: NULL keyEquivalent: @""];
4663 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
4664 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
4665 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
4668 /* do we want to add a stereo option? */
4669 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
4670 /* also offer stereo if we have a stereo-or-better source */
4671 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
4673 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4674 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
4675 action: NULL keyEquivalent: @""];
4676 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
4677 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
4678 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
4681 /* do we want to add a dolby surround (DPL1) option? */
4682 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
4684 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4685 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
4686 action: NULL keyEquivalent: @""];
4687 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
4688 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
4689 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
4692 /* do we want to add a dolby pro logic 2 (DPL2) option? */
4693 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
4695 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4696 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
4697 action: NULL keyEquivalent: @""];
4698 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
4699 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
4700 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
4703 /* do we want to add a 6-channel discrete option? */
4704 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
4706 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4707 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
4708 action: NULL keyEquivalent: @""];
4709 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
4710 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
4711 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
4714 /* do we want to add an AC-3 passthrough option? */
4715 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4717 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4718 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
4719 action: NULL keyEquivalent: @""];
4720 [menuItem setTag: HB_ACODEC_AC3];
4721 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
4722 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
4725 /* auto-select the best mixdown based on our saved mixdown preference */
4727 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
4728 /* ultimately this should be a prefs option */
4731 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
4732 if (mixdownToUse > 0)
4734 useMixdown = mixdownToUse;
4738 useMixdown = HB_AMIXDOWN_DOLBYPLII;
4741 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
4742 if (useMixdown > maxMixdownUsed)
4744 useMixdown = maxMixdownUsed;
4747 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
4748 if (useMixdown < minMixdownUsed)
4750 useMixdown = minMixdownUsed;
4753 /* select the (possibly-amended) preferred mixdown */
4754 [mixdownPopUp selectItemWithTag: useMixdown];
4757 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
4758 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
4761 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
4763 /* If we are using the avi container, we select MP3 as there is no aac available*/
4764 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
4766 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
4770 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
4773 /* Setup our samplerate and bitrate popups we will need based on mixdown */
4774 [self audioTrackMixdownChanged: mixdownPopUp];
4778 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
4780 [self autoSetM4vExtension: sender];
4784 - (IBAction) audioTrackMixdownChanged: (id) sender
4788 /* setup pointers to all of the other audio track controls
4789 * we will need later
4791 NSPopUpButton * mixdownPopUp;
4792 NSPopUpButton * sampleratePopUp;
4793 NSPopUpButton * bitratePopUp;
4794 NSPopUpButton * audiocodecPopUp;
4795 NSPopUpButton * audiotrackPopUp;
4796 NSSlider * drcSlider;
4797 NSTextField * drcField;
4798 if (sender == fAudTrack1MixPopUp)
4800 audiotrackPopUp = fAudLang1PopUp;
4801 audiocodecPopUp = fAudTrack1CodecPopUp;
4802 mixdownPopUp = fAudTrack1MixPopUp;
4803 sampleratePopUp = fAudTrack1RatePopUp;
4804 bitratePopUp = fAudTrack1BitratePopUp;
4805 drcSlider = fAudTrack1DrcSlider;
4806 drcField = fAudTrack1DrcField;
4808 else if (sender == fAudTrack2MixPopUp)
4810 audiotrackPopUp = fAudLang2PopUp;
4811 audiocodecPopUp = fAudTrack2CodecPopUp;
4812 mixdownPopUp = fAudTrack2MixPopUp;
4813 sampleratePopUp = fAudTrack2RatePopUp;
4814 bitratePopUp = fAudTrack2BitratePopUp;
4815 drcSlider = fAudTrack2DrcSlider;
4816 drcField = fAudTrack2DrcField;
4818 else if (sender == fAudTrack3MixPopUp)
4820 audiotrackPopUp = fAudLang3PopUp;
4821 audiocodecPopUp = fAudTrack3CodecPopUp;
4822 mixdownPopUp = fAudTrack3MixPopUp;
4823 sampleratePopUp = fAudTrack3RatePopUp;
4824 bitratePopUp = fAudTrack3BitratePopUp;
4825 drcSlider = fAudTrack3DrcSlider;
4826 drcField = fAudTrack3DrcField;
4830 audiotrackPopUp = fAudLang4PopUp;
4831 audiocodecPopUp = fAudTrack4CodecPopUp;
4832 mixdownPopUp = fAudTrack4MixPopUp;
4833 sampleratePopUp = fAudTrack4RatePopUp;
4834 bitratePopUp = fAudTrack4BitratePopUp;
4835 drcSlider = fAudTrack4DrcSlider;
4836 drcField = fAudTrack4DrcField;
4838 acodec = [[audiocodecPopUp selectedItem] tag];
4839 /* storage variable for the min and max bitrate allowed for this codec */
4845 case HB_ACODEC_FAAC:
4846 /* check if we have a 6ch discrete conversion in either audio track */
4847 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4849 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
4851 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4857 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
4859 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
4860 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
4865 case HB_ACODEC_LAME:
4866 /* Lame is happy using our min bitrate of 32 kbps */
4868 /* Lame won't encode if the bitrate is higher than 320 kbps */
4872 case HB_ACODEC_VORBIS:
4873 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4875 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
4877 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4883 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
4885 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
4891 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
4897 /* make sure we have a selected title before continuing */
4898 if (fTitle == NULL) return;
4899 /* get the audio so we can find out what input rates are*/
4900 hb_audio_config_t * audio;
4901 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
4902 int inputbitrate = audio->in.bitrate / 1000;
4903 int inputsamplerate = audio->in.samplerate;
4905 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3)
4907 [bitratePopUp removeAllItems];
4909 for( int i = 0; i < hb_audio_bitrates_count; i++ )
4911 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
4913 /* add a new menuitem for this bitrate */
4914 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4915 [NSString stringWithCString: hb_audio_bitrates[i].string]
4916 action: NULL keyEquivalent: @""];
4917 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
4918 [menuItem setTag: hb_audio_bitrates[i].rate];
4922 /* select the default bitrate (but use 384 for 6-ch AAC) */
4923 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4925 [bitratePopUp selectItemWithTag: 384];
4929 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
4932 /* populate and set the sample rate popup */
4933 /* Audio samplerate */
4934 [sampleratePopUp removeAllItems];
4935 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
4936 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
4937 [menuItem setTag: inputsamplerate];
4939 for( int i = 0; i < hb_audio_rates_count; i++ )
4941 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
4942 [NSString stringWithCString: hb_audio_rates[i].string]
4943 action: NULL keyEquivalent: @""];
4944 [menuItem setTag: hb_audio_rates[i].rate];
4946 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
4947 * and there is no compelling reason to use anything else as default, though the users default
4948 * preset will likely override any setting chosen here.
4950 [sampleratePopUp selectItemWithTag: inputsamplerate];
4953 /* Since AC3 Pass Thru uses the input ac3 bitrate and sample rate, we get the input tracks
4954 * bitrate and dispay it in the bitrate popup even though libhb happily ignores any bitrate input from
4955 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
4957 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3)
4960 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
4961 [bitratePopUp removeAllItems];
4962 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4963 [NSString stringWithFormat:@"%d", inputbitrate]
4964 action: NULL keyEquivalent: @""];
4965 [menuItem setTag: inputbitrate];
4966 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
4967 [bitratePopUp setEnabled: NO];
4968 [sampleratePopUp setEnabled: NO];
4970 [drcSlider setFloatValue: 1.00];
4971 [self audioDRCSliderChanged: drcSlider];
4972 [drcSlider setEnabled: NO];
4973 [drcField setEnabled: NO];
4977 [sampleratePopUp setEnabled: YES];
4978 [bitratePopUp setEnabled: YES];
4979 [drcSlider setEnabled: YES];
4980 [drcField setEnabled: YES];
4982 [self calculateBitrate:nil];
4985 - (IBAction) audioDRCSliderChanged: (id) sender
4987 NSSlider * drcSlider;
4988 NSTextField * drcField;
4989 if (sender == fAudTrack1DrcSlider)
4991 drcSlider = fAudTrack1DrcSlider;
4992 drcField = fAudTrack1DrcField;
4994 else if (sender == fAudTrack2DrcSlider)
4996 drcSlider = fAudTrack2DrcSlider;
4997 drcField = fAudTrack2DrcField;
4999 else if (sender == fAudTrack3DrcSlider)
5001 drcSlider = fAudTrack3DrcSlider;
5002 drcField = fAudTrack3DrcField;
5006 drcSlider = fAudTrack4DrcSlider;
5007 drcField = fAudTrack4DrcField;
5009 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
5010 /* For now, do not call this until we have an intelligent way to determine audio track selections
5011 * compared to presets
5013 //[self customSettingUsed: sender];
5016 - (IBAction) subtitleSelectionChanged: (id) sender
5018 if ([fSubPopUp indexOfSelectedItem] == 0)
5020 [fSubForcedCheck setState: NSOffState];
5021 [fSubForcedCheck setEnabled: NO];
5025 [fSubForcedCheck setEnabled: YES];
5034 #pragma mark Open New Windows
5036 - (IBAction) openHomepage: (id) sender
5038 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5039 URLWithString:@"http://handbrake.fr/"]];
5042 - (IBAction) openForums: (id) sender
5044 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5045 URLWithString:@"http://handbrake.fr/forum/"]];
5047 - (IBAction) openUserGuide: (id) sender
5049 [[NSWorkspace sharedWorkspace] openURL: [NSURL
5050 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
5054 * Shows debug output window.
5056 - (IBAction)showDebugOutputPanel:(id)sender
5058 [outputPanel showOutputPanel:sender];
5062 * Shows preferences window.
5064 - (IBAction) showPreferencesWindow: (id) sender
5066 NSWindow * window = [fPreferencesController window];
5067 if (![window isVisible])
5070 [window makeKeyAndOrderFront: nil];
5074 * Shows queue window.
5076 - (IBAction) showQueueWindow:(id)sender
5078 [fQueueController showQueueWindow:sender];
5082 - (IBAction) toggleDrawer:(id)sender {
5083 [fPresetDrawer toggle:self];
5087 * Shows Picture Settings Window.
5090 - (IBAction) showPicturePanel: (id) sender
5092 hb_list_t * list = hb_get_titles( fHandle );
5093 hb_title_t * title = (hb_title_t *) hb_list_item( list,
5094 [fSrcTitlePopUp indexOfSelectedItem] );
5095 //[fPictureController SetTitle:title];
5096 [fPictureController showPreviewPanel:sender forTitle:title];
5100 #pragma mark Preset Outline View Methods
5101 #pragma mark - Required
5102 /* These are required by the NSOutlineView Datasource Delegate */
5105 /* used to specify the number of levels to show for each item */
5106 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
5108 /* currently use no levels to test outline view viability */
5109 if (item == nil) // for an outline view the root level of the hierarchy is always nil
5111 return [UserPresets count];
5115 /* we need to return the count of the array in ChildrenArray for this folder */
5116 NSArray *children = nil;
5117 children = [item objectForKey:@"ChildrenArray"];
5118 if ([children count] > 0)
5120 return [children count];
5129 /* We use this to deterimine children of an item */
5130 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(int)index ofItem:(id)item
5133 /* we need to return the count of the array in ChildrenArray for this folder */
5134 NSArray *children = nil;
5137 children = UserPresets;
5141 if ([item objectForKey:@"ChildrenArray"])
5143 children = [item objectForKey:@"ChildrenArray"];
5146 if ((children == nil) || ([children count] <= index))
5152 return [children objectAtIndex:index];
5156 // We are only one level deep, so we can't be asked about children
5157 //NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
5161 /* We use this to determine if an item should be expandable */
5162 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
5165 /* we need to return the count of the array in ChildrenArray for this folder */
5166 NSArray *children= nil;
5169 children = UserPresets;
5173 if ([item objectForKey:@"ChildrenArray"])
5175 children = [item objectForKey:@"ChildrenArray"];
5179 /* To deterimine if an item should show a disclosure triangle
5180 * we could do it by the children count as so:
5181 * if ([children count] < 1)
5182 * However, lets leave the triangle show even if there are no
5183 * children to help indicate a folder, just like folder in the
5184 * finder can show a disclosure triangle even when empty
5187 /* We need to determine if the item is a folder */
5188 if ([[item objectForKey:@"Folder"] intValue] == 1)
5199 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
5201 // Our outline view has no levels, but we can still expand every item. Doing so
5202 // just makes the row taller. See heightOfRowByItem below.
5203 //return ![(HBQueueOutlineView*)outlineView isDragging];
5209 /* Used to tell the outline view which information is to be displayed per item */
5210 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5212 /* We have two columns right now, icon and PresetName */
5214 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5216 return [item objectForKey:@"PresetName"];
5225 #pragma mark - Added Functionality (optional)
5226 /* Use to customize the font and display characteristics of the title cell */
5227 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
5229 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5233 NSColor *shadowColor;
5234 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
5235 /*check to see if its a selected row */
5236 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
5239 fontColor = [NSColor blackColor];
5240 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
5244 if ([[item objectForKey:@"Type"] intValue] == 0)
5246 fontColor = [NSColor blueColor];
5248 else // User created preset, use a black font
5250 fontColor = [NSColor blackColor];
5252 /* check to see if its a folder */
5253 //if ([[item objectForKey:@"Folder"] intValue] == 1)
5255 //fontColor = [NSColor greenColor];
5260 /* We use Bold Text for the HB Default */
5261 if ([[item objectForKey:@"Default"] intValue] == 1)// 1 is HB default
5263 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5265 /* We use Bold Text for the User Specified Default */
5266 if ([[item objectForKey:@"Default"] intValue] == 2)// 2 is User default
5268 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
5272 [cell setTextColor:fontColor];
5273 [cell setFont:txtFont];
5278 /* We use this to edit the name field in the outline view */
5279 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
5281 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
5286 [theRecord setObject:object forKey:@"PresetName"];
5290 [fPresetsOutlineView reloadData];
5291 /* We save all of the preset data here */
5295 /* We use this to provide tooltips for the items in the presets outline view */
5296 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
5298 //if ([[tc identifier] isEqualToString:@"PresetName"])
5300 /* initialize the tooltip contents variable */
5302 /* if there is a description for the preset, we show it in the tooltip */
5303 if ([item objectForKey:@"PresetDescription"])
5305 loc_tip = [item objectForKey:@"PresetDescription"];
5310 loc_tip = @"No description available";
5317 #pragma mark Preset Outline View Methods (dragging related)
5320 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
5322 // Dragging is only allowed for custom presets.
5323 //[[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1
5324 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
5328 // Don't retain since this is just holding temporaral drag information, and it is
5329 //only used during a drag! We could put this in the pboard actually.
5330 fDraggedNodes = items;
5331 // Provide data for our custom type, and simple NSStrings.
5332 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
5334 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
5335 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
5340 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
5343 // Don't allow dropping ONTO an item since they can't really contain any children.
5345 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
5346 if (isOnDropTypeProposal)
5347 return NSDragOperationNone;
5349 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
5352 index = [fPresetsOutlineView rowForItem: item] + 1;
5356 // Don't allow dropping into the Built In Presets.
5357 if (index < presetCurrentBuiltInCount)
5359 return NSDragOperationNone;
5360 index = MAX (index, presetCurrentBuiltInCount);
5363 [outlineView setDropItem:item dropChildIndex:index];
5364 return NSDragOperationGeneric;
5369 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
5371 /* first, lets see if we are dropping into a folder */
5372 if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
5374 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
5375 childrenArray = [[fPresetsOutlineView itemAtRow:index] objectForKey:@"ChildrenArray"];
5376 [childrenArray addObject:item];
5377 [[fPresetsOutlineView itemAtRow:index] setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
5378 [childrenArray autorelease];
5380 else // We are not, so we just move the preset into the existing array
5382 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
5384 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
5385 while (obj = [enumerator nextObject])
5387 [moveItems addIndex:[UserPresets indexOfObject:obj]];
5389 // Successful drop, lets rearrange the view and save it all
5390 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
5392 [fPresetsOutlineView reloadData];
5397 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
5399 unsigned index = [indexSet lastIndex];
5400 unsigned aboveInsertIndexCount = 0;
5402 while (index != NSNotFound)
5404 unsigned removeIndex;
5406 if (index >= insertIndex)
5408 removeIndex = index + aboveInsertIndexCount;
5409 aboveInsertIndexCount++;
5413 removeIndex = index;
5417 id object = [[array objectAtIndex:removeIndex] retain];
5418 [array removeObjectAtIndex:removeIndex];
5419 [array insertObject:object atIndex:insertIndex];
5422 index = [indexSet indexLessThanIndex:index];
5428 #pragma mark - Functional Preset NSOutlineView Methods
5430 - (IBAction)selectPreset:(id)sender
5433 if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1)
5435 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
5436 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
5438 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
5440 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
5444 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
5448 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
5449 [self formatPopUpChanged:nil];
5451 /* Chapter Markers*/
5452 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
5453 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
5454 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
5455 /* Mux mp4 with http optimization */
5456 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
5459 /* We set the advanced opt string here if applicable*/
5460 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
5461 /* We use a conditional to account for the new x264 encoder dropdown as well as presets made using legacy x264 settings*/
5462 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 Main)"] ||
5463 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"] ||
5464 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264"])
5466 [fVidEncoderPopUp selectItemWithTitle:@"H.264 (x264)"];
5467 /* special case for legacy preset to check the new fDstMp4HttpOptFileCheck checkbox to set the ipod atom */
5468 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"])
5470 [fDstMp4iPodFileCheck setState:NSOnState];
5471 /* We also need to add "level=30:" to the advanced opts string to set the correct level for the iPod when
5472 encountering a legacy preset as it used to be handled separately from the opt string*/
5473 [fAdvancedOptions setOptions:[@"level=30:" stringByAppendingString:[fAdvancedOptions optionsString]]];
5477 [fDstMp4iPodFileCheck setState:NSOffState];
5480 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"FFmpeg"])
5482 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (FFmpeg)"];
5484 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"XviD"])
5486 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (XviD)"];
5490 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
5493 /* Lets run through the following functions to get variables set there */
5494 [self videoEncoderPopUpChanged:nil];
5495 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
5496 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
5497 [self calculateBitrate:nil];
5500 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
5502 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
5503 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
5504 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
5506 [self videoMatrixChanged:nil];
5508 /* Video framerate */
5509 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
5510 detected framerate in the fVidRatePopUp so we use index 0*/
5511 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
5513 [fVidRatePopUp selectItemAtIndex: 0];
5517 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
5521 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
5523 /* 2 Pass Encoding */
5524 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
5525 [self twoPassCheckboxChanged:nil];
5526 /* Turbo 1st pass for 2 Pass Encoding */
5527 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
5530 if ([chosenPreset objectForKey:@"FileCodecs"])
5532 /* We need to handle the audio codec popup by determining what was chosen from the deprecated Codecs PopUp for past presets*/
5533 if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString: @"AVC/H.264 Video / AAC + AC3 Audio"])
5535 /* We need to address setting languages etc. here in the new multi track audio panel */
5536 /* Track One set here */
5537 /*for track one though a track should be selected but lets check here anyway and use track one if its not.*/
5538 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5540 [fAudLang1PopUp selectItemAtIndex: 1];
5541 [self audioTrackPopUpChanged: fAudLang1PopUp];
5543 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5544 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5545 /* Track Two, set source same as track one */
5546 [fAudLang2PopUp selectItemAtIndex: [fAudLang1PopUp indexOfSelectedItem]];
5547 [self audioTrackPopUpChanged: fAudLang2PopUp];
5548 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5549 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5551 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AAC Audio"] ||
5552 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC Audio"])
5554 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5556 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5557 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5559 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5561 [fAudTrack2CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5562 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5564 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5566 [fAudTrack3CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5567 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5569 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5571 [fAudTrack4CodecPopUp selectItemWithTitle: @"AAC (faac)"];
5572 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5575 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AC-3 Audio"] ||
5576 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AC-3 Audio"])
5578 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5580 [fAudTrack1CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5581 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5583 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5585 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5586 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5588 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5590 [fAudTrack3CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5591 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5593 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5595 [fAudTrack4CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
5596 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5599 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / MP3 Audio"] ||
5600 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / MP3 Audio"])
5602 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5604 [fAudTrack1CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5605 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5607 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5609 [fAudTrack2CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5610 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5612 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5614 [fAudTrack3CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5615 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5617 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5619 [fAudTrack4CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
5620 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5623 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / Vorbis Audio"])
5625 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5627 [fAudTrack1CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5628 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5630 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5632 [fAudTrack2CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5633 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5635 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5637 [fAudTrack3CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5638 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5640 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5642 [fAudTrack4CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5643 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5646 /* 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
5647 * UNLESS the CodecPopUp is AC3 in which case the preset values are ignored in favor of rates set in audioTrackMixdownChanged*/
5648 if ([chosenPreset objectForKey:@"AudioSampleRate"])
5650 if ([fAudLang1PopUp indexOfSelectedItem] > 0 && [fAudTrack1CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5652 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5653 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5655 if ([fAudLang2PopUp indexOfSelectedItem] > 0 && [fAudTrack2CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5657 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5658 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5660 if ([fAudLang3PopUp indexOfSelectedItem] > 0 && [fAudTrack3CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5662 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5663 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5665 if ([fAudLang4PopUp indexOfSelectedItem] > 0 && [fAudTrack4CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5667 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5668 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5671 /* We detect here if we have the old DRC Slider and if so we apply it to the existing four tracks if chosen */
5672 if ([chosenPreset objectForKey:@"AudioDRCSlider"])
5674 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5676 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5677 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5679 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5681 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5682 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5684 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5686 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5687 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5689 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5691 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5692 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5696 else // since there was no codecs key in the preset we know we can use new multi-audio track presets
5698 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
5700 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5702 [fAudLang1PopUp selectItemAtIndex: 1];
5704 [self audioTrackPopUpChanged: fAudLang1PopUp];
5705 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
5706 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5707 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
5708 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5710 if ([fAudTrack1MixPopUp selectedItem] == nil)
5712 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5714 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
5715 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5716 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
5718 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
5720 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
5721 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5723 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
5725 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5727 [fAudLang2PopUp selectItemAtIndex: 1];
5729 [self audioTrackPopUpChanged: fAudLang2PopUp];
5730 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
5731 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5732 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
5733 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5735 if ([fAudTrack2MixPopUp selectedItem] == nil)
5737 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5739 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
5740 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5741 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
5743 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
5745 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
5746 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5748 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
5750 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5752 [fAudLang3PopUp selectItemAtIndex: 1];
5754 [self audioTrackPopUpChanged: fAudLang3PopUp];
5755 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
5756 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5757 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
5758 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5760 if ([fAudTrack3MixPopUp selectedItem] == nil)
5762 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5764 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
5765 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5766 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
5768 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
5770 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
5771 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5773 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
5775 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
5777 [fAudLang4PopUp selectItemAtIndex: 1];
5779 [self audioTrackPopUpChanged: fAudLang4PopUp];
5780 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
5781 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5782 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
5783 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5785 if ([fAudTrack4MixPopUp selectedItem] == nil)
5787 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5789 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
5790 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5791 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
5793 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
5795 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
5796 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5802 /* 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
5803 * duplicate any code for legacy presets.*/
5804 /* First we handle the legacy Codecs crazy AVC/H.264 Video / AAC + AC3 Audio atv hybrid */
5805 if ([chosenPreset objectForKey:@"FileCodecs"] && [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC + AC3 Audio"])
5807 [fAudLang3PopUp selectItemAtIndex: 0];
5808 [self audioTrackPopUpChanged: fAudLang3PopUp];
5809 [fAudLang4PopUp selectItemAtIndex: 0];
5810 [self audioTrackPopUpChanged: fAudLang4PopUp];
5814 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
5816 [fAudLang2PopUp selectItemAtIndex: 0];
5817 [self audioTrackPopUpChanged: fAudLang2PopUp];
5819 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
5821 [fAudLang3PopUp selectItemAtIndex: 0];
5822 [self audioTrackPopUpChanged: fAudLang3PopUp];
5824 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
5826 [fAudLang4PopUp selectItemAtIndex: 0];
5827 [self audioTrackPopUpChanged: fAudLang4PopUp];
5832 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
5833 /* Forced Subtitles */
5834 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
5836 /* Picture Settings */
5837 /* Note: objectForKey:@"UsesPictureSettings" now refers to picture size, this encompasses:
5838 * height, width, keep ar, anamorphic and crop settings.
5839 * picture filters are now handled separately.
5840 * We will be able to actually change the key names for legacy preset keys when preset file
5841 * update code is done. But for now, lets hang onto the old legacy key name for backwards compatibility.
5843 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
5844 * and the preset completely ignores any picture sizing values in the preset.
5846 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
5848 hb_job_t * job = fTitle->job;
5850 /* If Cropping is set to custom, then recall all four crop values from
5851 when the preset was created and apply them */
5852 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
5854 [fPictureController setAutoCrop:NO];
5856 /* Here we use the custom crop values saved at the time the preset was saved */
5857 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
5858 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
5859 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
5860 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
5863 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
5865 [fPictureController setAutoCrop:YES];
5866 /* Here we use the auto crop values determined right after scan */
5867 job->crop[0] = AutoCropTop;
5868 job->crop[1] = AutoCropBottom;
5869 job->crop[2] = AutoCropLeft;
5870 job->crop[3] = AutoCropRight;
5875 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
5876 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
5878 /* Use Max Picture settings for whatever the dvd is.*/
5879 [self revertPictureSizeToMax:nil];
5880 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5881 if (job->keep_ratio == 1)
5883 hb_fix_aspect( job, HB_KEEP_WIDTH );
5884 if( job->height > fTitle->height )
5886 job->height = fTitle->height;
5887 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5890 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5892 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
5894 /* we check to make sure the presets width/height does not exceed the sources width/height */
5895 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
5897 /* if so, then we use the sources height and width to avoid scaling up */
5898 job->width = fTitle->width;
5899 job->height = fTitle->height;
5901 else // source width/height is >= the preset height/width
5903 /* we can go ahead and use the presets values for height and width */
5904 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
5905 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
5907 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5908 if (job->keep_ratio == 1)
5910 hb_fix_aspect( job, HB_KEEP_WIDTH );
5911 if( job->height > fTitle->height )
5913 job->height = fTitle->height;
5914 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5917 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5920 /* If the preset has no objectForKey:@"UsesPictureFilters", then we know it is a legacy preset
5921 * and handle the filters here as before.
5922 * NOTE: This should be removed when the update presets code is done as we can be assured that legacy
5923 * presets are updated to work properly with new keys.
5925 if (![chosenPreset objectForKey:@"UsesPictureFilters"])
5929 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5931 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5932 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5933 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5935 [fPictureController setDeinterlace:3];
5940 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5945 [fPictureController setDeinterlace:0];
5948 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5950 // We make sure that framerate is set to Same as source variable
5951 // detelecine will take care of itself right below
5952 //[fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5956 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5958 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5962 [fPictureController setDetelecine:0];
5965 if ([chosenPreset objectForKey:@"PictureDenoise"])
5967 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5971 [fPictureController setDenoise:0];
5974 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5976 /* since we used to use 1 to turn on deblock, we now use a 5 in our sliding scale */
5977 [fPictureController setDeblock:5];
5981 [fPictureController setDeblock:0];
5985 [self calculatePictureSizing:nil];
5992 /* If the preset has an objectForKey:@"UsesPictureFilters", then we know it is a newer style filters preset
5993 * and handle the filters here depending on whether or not the preset specifies applying the filter.
5995 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
5999 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
6001 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
6002 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
6003 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
6005 [fPictureController setDeinterlace:3];
6009 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
6014 [fPictureController setDeinterlace:0];
6018 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
6020 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
6024 [fPictureController setDetelecine:0];
6027 if ([chosenPreset objectForKey:@"PictureDenoise"])
6029 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
6033 [fPictureController setDenoise:0];
6036 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
6038 /* if its a one, then its the old on/off deblock, set on to 5*/
6039 [fPictureController setDeblock:5];
6043 /* use the settings intValue */
6044 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
6047 /* Even though we currently allow for a custom setting for decomb, ultimately it will only have Off and
6048 * Default so we just pay attention to anything greater than 0 as 1 (Default). 0 is Off. */
6049 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] == 1)
6051 [fPictureController setDecomb:1];
6055 [fPictureController setDecomb:0];
6058 [self calculatePictureSizing:nil];
6064 #pragma mark Manage Presets
6066 - (void) loadPresets {
6067 /* We declare the default NSFileManager into fileManager */
6068 NSFileManager * fileManager = [NSFileManager defaultManager];
6069 /*We define the location of the user presets file */
6070 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
6071 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
6072 /* We check for the presets.plist */
6073 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
6075 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
6078 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
6079 if (nil == UserPresets)
6081 UserPresets = [[NSMutableArray alloc] init];
6082 [self addFactoryPresets:nil];
6084 [fPresetsOutlineView reloadData];
6088 - (IBAction) showAddPresetPanel: (id) sender
6090 /* Deselect the currently selected Preset if there is one*/
6091 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
6093 /* Populate the preset picture settings popup here */
6094 [fPresetNewPicSettingsPopUp removeAllItems];
6095 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
6096 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
6097 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
6098 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
6099 /* Uncheck the preset use filters checkbox */
6100 [fPresetNewPicFiltersCheck setState:NSOffState];
6101 // fPresetNewFolderCheck
6102 [fPresetNewFolderCheck setState:NSOffState];
6103 /* Erase info from the input fields*/
6104 [fPresetNewName setStringValue: @""];
6105 [fPresetNewDesc setStringValue: @""];
6106 /* Show the panel */
6107 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
6110 - (IBAction) closeAddPresetPanel: (id) sender
6112 [NSApp endSheet: fAddPresetPanel];
6113 [fAddPresetPanel orderOut: self];
6116 - (IBAction)addUserPreset:(id)sender
6118 if (![[fPresetNewName stringValue] length])
6119 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
6122 /* Here we create a custom user preset */
6123 [UserPresets addObject:[self createPreset]];
6126 [self closeAddPresetPanel:nil];
6133 /* We Reload the New Table data for presets */
6134 [fPresetsOutlineView reloadData];
6135 /* We save all of the preset data here */
6143 /* We Sort the Presets By Factory or Custom */
6144 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
6145 ascending:YES] autorelease];
6146 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
6148 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
6149 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
6150 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
6153 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
6154 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
6155 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
6156 [UserPresets setArray:sortedArray];
6161 - (IBAction)insertPreset:(id)sender
6163 int index = [fPresetsOutlineView selectedRow];
6164 [UserPresets insertObject:[self createPreset] atIndex:index];
6165 [fPresetsOutlineView reloadData];
6169 - (NSDictionary *)createPreset
6171 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
6172 /* Get the New Preset Name from the field in the AddPresetPanel */
6173 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
6174 /* Set whether or not this is to be a folder fPresetNewFolderCheck*/
6175 [preset setObject:[NSNumber numberWithBool:[fPresetNewFolderCheck state]] forKey:@"Folder"];
6176 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
6177 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
6178 /*Set whether or not this is default, at creation set to 0*/
6179 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6180 if ([fPresetNewFolderCheck state] == YES)
6182 /* initialize and set an empty array for children here since we are a new folder */
6183 NSMutableArray *childrenArray = [[NSMutableArray alloc] init];
6184 [preset setObject:[NSMutableArray arrayWithArray: childrenArray] forKey:@"ChildrenArray"];
6185 [childrenArray autorelease];
6187 else // we are not creating a preset folder, so we go ahead with the rest of the preset info
6189 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
6190 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
6191 /* Get whether or not to use the current Picture Filter settings for the preset */
6192 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
6194 /* Get New Preset Description from the field in the AddPresetPanel*/
6195 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
6197 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
6198 /* Chapter Markers fCreateChapterMarkers*/
6199 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
6200 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
6201 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
6202 /* Mux mp4 with http optimization */
6203 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
6204 /* Add iPod uuid atom */
6205 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
6209 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
6210 /* x264 Option String */
6211 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
6213 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
6214 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
6215 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
6216 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
6218 /* Video framerate */
6219 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
6221 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
6223 else // we can record the actual titleOfSelectedItem
6225 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
6228 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
6229 /* 2 Pass Encoding */
6230 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
6231 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
6232 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
6233 /*Picture Settings*/
6234 hb_job_t * job = fTitle->job;
6235 /* Picture Sizing */
6236 /* Use Max Picture settings for whatever the dvd is.*/
6237 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
6238 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
6239 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
6240 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
6241 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
6243 /* Set crop settings here */
6244 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
6245 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
6246 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
6247 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
6248 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
6250 /* Picture Filters */
6251 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
6252 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
6253 //[preset setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
6254 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
6255 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
6256 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
6260 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
6262 [preset setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
6263 [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
6264 [preset setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
6265 [preset setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
6266 [preset setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
6267 [preset setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
6268 [preset setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
6270 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
6272 [preset setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
6273 [preset setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
6274 [preset setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
6275 [preset setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
6276 [preset setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
6277 [preset setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
6278 [preset setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
6280 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
6282 [preset setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
6283 [preset setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
6284 [preset setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
6285 [preset setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
6286 [preset setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
6287 [preset setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
6288 [preset setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
6290 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
6292 [preset setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
6293 [preset setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
6294 [preset setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
6295 [preset setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
6296 [preset setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
6297 [preset setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
6298 [preset setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
6302 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
6303 /* Forced Subtitles */
6304 [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
6306 [preset autorelease];
6313 [UserPresets writeToFile:UserPresetsFile atomically:YES];
6314 /* We get the default preset in case it changed */
6315 [self getDefaultPresets:nil];
6319 - (IBAction)deletePreset:(id)sender
6323 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
6327 /* Alert user before deleting preset */
6329 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
6331 if ( status == NSAlertDefaultReturn )
6333 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6334 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6335 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
6337 NSEnumerator *enumerator;
6338 NSMutableArray *presetsArrayToMod;
6339 NSMutableArray *tempArray;
6341 /* If we are a root level preset, we are modding the UserPresets array */
6342 if (presetToModLevel == 0)
6344 presetsArrayToMod = UserPresets;
6346 else // We have a parent preset, so we modify the chidren array object for key
6348 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
6351 enumerator = [presetsArrayToMod objectEnumerator];
6352 tempArray = [NSMutableArray array];
6354 while (tempObject = [enumerator nextObject])
6356 NSDictionary *thisPresetDict = tempObject;
6357 if (thisPresetDict == presetToMod)
6359 [tempArray addObject:tempObject];
6363 [presetsArrayToMod removeObjectsInArray:tempArray];
6364 [fPresetsOutlineView reloadData];
6370 #pragma mark Manage Default Preset
6372 - (IBAction)getDefaultPresets:(id)sender
6374 presetHbDefault = nil;
6375 presetUserDefault = nil;
6376 presetUserDefaultParent = nil;
6377 presetUserDefaultParentParent = nil;
6378 NSMutableDictionary *presetHbDefaultParent = nil;
6379 NSMutableDictionary *presetHbDefaultParentParent = nil;
6382 BOOL userDefaultFound = NO;
6383 presetCurrentBuiltInCount = 0;
6384 /* First we iterate through the root UserPresets array to check for defaults */
6385 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6387 while (tempObject = [enumerator nextObject])
6389 NSMutableDictionary *thisPresetDict = tempObject;
6390 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
6392 presetHbDefault = thisPresetDict;
6394 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
6396 presetUserDefault = thisPresetDict;
6397 userDefaultFound = YES;
6399 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
6401 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
6405 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
6406 if ([thisPresetDict objectForKey:@"ChildrenArray"])
6408 NSMutableDictionary *thisPresetDictParent = thisPresetDict;
6409 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
6411 while (tempObject = [enumerator nextObject])
6413 NSMutableDictionary *thisPresetDict = tempObject;
6414 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
6416 presetHbDefault = thisPresetDict;
6417 presetHbDefaultParent = thisPresetDictParent;
6419 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
6421 presetUserDefault = thisPresetDict;
6422 presetUserDefaultParent = thisPresetDictParent;
6423 userDefaultFound = YES;
6426 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
6427 if ([thisPresetDict objectForKey:@"ChildrenArray"])
6429 NSMutableDictionary *thisPresetDictParentParent = thisPresetDict;
6430 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
6432 while (tempObject = [enumerator nextObject])
6434 NSMutableDictionary *thisPresetDict = tempObject;
6435 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
6437 presetHbDefault = thisPresetDict;
6438 presetHbDefaultParent = thisPresetDictParent;
6439 presetHbDefaultParentParent = thisPresetDictParentParent;
6441 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
6443 presetUserDefault = thisPresetDict;
6444 presetUserDefaultParent = thisPresetDictParent;
6445 presetUserDefaultParentParent = thisPresetDictParentParent;
6446 userDefaultFound = YES;
6455 /* check to see if a user specified preset was found, if not then assign the parents for
6456 * the presetHbDefault so that we can open the parents for the nested presets
6458 if (userDefaultFound == NO)
6460 presetUserDefaultParent = presetHbDefaultParent;
6461 presetUserDefaultParentParent = presetHbDefaultParentParent;
6465 - (IBAction)setDefaultPreset:(id)sender
6467 /* We need to determine if the item is a folder */
6468 if ([[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] == 1)
6474 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6476 /* First make sure the old user specified default preset is removed */
6477 while (tempObject = [enumerator nextObject])
6479 NSMutableDictionary *thisPresetDict = tempObject;
6480 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
6482 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6485 /* if we run into a folder, go to level 1 and iterate through the children arrays for the default */
6486 if ([thisPresetDict objectForKey:@"ChildrenArray"])
6488 NSEnumerator *enumerator = [[thisPresetDict objectForKey:@"ChildrenArray"] objectEnumerator];
6491 while (tempObject = [enumerator nextObject])
6493 NSMutableDictionary *thisPresetDict1 = tempObject;
6494 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
6496 [[[thisPresetDict objectForKey:@"ChildrenArray"] objectAtIndex:ii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6498 /* if we run into a folder, go to level 2 and iterate through the children arrays for the default */
6499 if ([thisPresetDict1 objectForKey:@"ChildrenArray"])
6501 NSEnumerator *enumerator = [[thisPresetDict1 objectForKey:@"ChildrenArray"] objectEnumerator];
6504 while (tempObject = [enumerator nextObject])
6506 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 0
6508 [[[thisPresetDict1 objectForKey:@"ChildrenArray"] objectAtIndex:iii] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
6521 int presetToModLevel = [fPresetsOutlineView levelForItem: [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]];
6522 NSDictionary *presetToMod = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
6523 NSDictionary *presetToModParent = [fPresetsOutlineView parentForItem: presetToMod];
6526 NSMutableArray *presetsArrayToMod;
6527 NSMutableArray *tempArray;
6529 /* If we are a root level preset, we are modding the UserPresets array */
6530 if (presetToModLevel == 0)
6532 presetsArrayToMod = UserPresets;
6534 else // We have a parent preset, so we modify the chidren array object for key
6536 presetsArrayToMod = [presetToModParent objectForKey:@"ChildrenArray"];
6539 enumerator = [presetsArrayToMod objectEnumerator];
6540 tempArray = [NSMutableArray array];
6542 while (tempObject = [enumerator nextObject])
6544 NSDictionary *thisPresetDict = tempObject;
6545 if (thisPresetDict == presetToMod)
6547 if ([[tempObject objectForKey:@"Default"] intValue] != 1) // if not the default HB Preset, set to 2
6549 [[presetsArrayToMod objectAtIndex:iiii] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
6556 /* We save all of the preset data here */
6558 /* We Reload the New Table data for presets */
6559 [fPresetsOutlineView reloadData];
6562 - (IBAction)selectDefaultPreset:(id)sender
6564 NSMutableDictionary *presetToMod;
6565 /* if there is a user specified default, we use it */
6566 if (presetUserDefault)
6568 presetToMod = presetUserDefault;
6570 else if (presetHbDefault) //else we use the built in default presetHbDefault
6572 presetToMod = presetHbDefault;
6579 if (presetUserDefaultParent != nil)
6581 [fPresetsOutlineView expandItem:presetUserDefaultParent];
6584 if (presetUserDefaultParentParent != nil)
6586 [fPresetsOutlineView expandItem:presetUserDefaultParentParent];
6590 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[fPresetsOutlineView rowForItem: presetToMod]] byExtendingSelection:NO];
6591 [self selectPreset:nil];
6596 #pragma mark Manage Built In Presets
6599 - (IBAction)deleteFactoryPresets:(id)sender
6602 NSEnumerator *enumerator = [UserPresets objectEnumerator];
6606 NSMutableArray *tempArray;
6609 tempArray = [NSMutableArray array];
6610 /* we look here to see if the preset is we move on to the next one */
6611 while ( tempObject = [enumerator nextObject] )
6613 /* if the preset is "Factory" then we put it in the array of
6614 presets to delete */
6615 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
6617 [tempArray addObject:tempObject];
6621 [UserPresets removeObjectsInArray:tempArray];
6622 [fPresetsOutlineView reloadData];
6627 /* We use this method to recreate new, updated factory
6629 - (IBAction)addFactoryPresets:(id)sender
6632 /* First, we delete any existing built in presets */
6633 [self deleteFactoryPresets: sender];
6634 /* Then we generate new built in presets programmatically with fPresetsBuiltin
6635 * which is all setup in HBPresets.h and HBPresets.m*/
6636 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
6648 /*******************************
6649 * Subclass of the HBPresetsOutlineView *
6650 *******************************/
6652 @implementation HBPresetsOutlineView
6653 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
6657 // By default, NSTableView only drags an image of the first column. Change this to
6658 // drag an image of the queue's icon and PresetName columns.
6659 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"PresetName"], nil];
6660 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
6665 - (void) mouseDown:(NSEvent *)theEvent
6667 [super mouseDown:theEvent];
6673 - (BOOL) isDragging;