1 /* $Id: Controller.mm,v 1.79 2005/11/04 19:41:32 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
8 #import "HBOutputPanelController.h"
9 #import "HBPreferencesController.h"
10 #import "HBDVDDetector.h"
13 #define DragDropSimplePboardType @"MyCustomOutlineViewPboardType"
15 /* We setup the toolbar values here */
16 static NSString * ToggleDrawerIdentifier = @"Toggle Drawer Item Identifier";
17 static NSString * StartEncodingIdentifier = @"Start Encoding Item Identifier";
18 static NSString * PauseEncodingIdentifier = @"Pause Encoding Item Identifier";
19 static NSString * ShowQueueIdentifier = @"Show Queue Item Identifier";
20 static NSString * AddToQueueIdentifier = @"Add to Queue Item Identifier";
21 static NSString * ShowActivityIdentifier = @"Debug Output Item Identifier";
22 static NSString * ChooseSourceIdentifier = @"Choose Source Item Identifier";
25 /*******************************
26 * HBController implementation *
27 *******************************/
28 @implementation HBController
38 [HBPreferencesController registerUserDefaults];
40 fQueueEncodeLibhb = NULL;
41 /* Check for check for the app support directory here as
42 * outputPanel needs it right away, as may other future methods
44 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
46 YES ) objectAtIndex:0];
47 AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
48 stringByAppendingPathComponent:@"HandBrake"];
49 if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
51 [[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
55 outputPanel = [[HBOutputPanelController alloc] init];
56 fPictureController = [[PictureController alloc] initWithDelegate:self];
57 fQueueController = [[HBQueueController alloc] init];
58 fAdvancedOptions = [[HBAdvancedController alloc] init];
59 /* we init the HBPresets class which currently is only used
60 * for updating built in presets, may move more functionality
63 fPresetsBuiltin = [[HBPresets alloc] init];
64 fPreferencesController = [[HBPreferencesController alloc] init];
65 /* Lets report the HandBrake version number here to the activity log and text log file */
66 NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
67 [self writeToActivityLog: "%s", [versionStringFull UTF8String]];
73 - (void) applicationDidFinishLaunching: (NSNotification *) notification
75 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
76 fHandle = hb_init(HB_DEBUG_ALL, 0);
77 /* Init a separate instance of libhb for user scanning and setting up jobs */
78 fQueueEncodeLibhb = hb_init(HB_DEBUG_ALL, 0);
80 // Set the Growl Delegate
81 [GrowlApplicationBridge setGrowlDelegate: self];
82 /* Init others controllers */
83 [fPictureController SetHandle: fHandle];
84 [fQueueController setHandle: fQueueEncodeLibhb];
85 [fQueueController setHBController: self];
87 fChapterTitlesDelegate = [[ChapterTitles alloc] init];
88 [fChapterTable setDataSource:fChapterTitlesDelegate];
89 [fChapterTable setDelegate:fChapterTitlesDelegate];
91 /* Call UpdateUI every 1/2 sec */
92 [[NSRunLoop currentRunLoop] addTimer:[NSTimer
93 scheduledTimerWithTimeInterval:0.5 target:self
94 selector:@selector(updateUI:) userInfo:nil repeats:YES]
95 forMode:NSEventTrackingRunLoopMode];
97 // Open debug output window now if it was visible when HB was closed
98 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OutputPanelIsOpen"])
99 [self showDebugOutputPanel:nil];
101 // Open queue window now if it was visible when HB was closed
102 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"])
103 [self showQueueWindow:nil];
105 [self openMainWindow:nil];
107 /* We have to set the bool to tell hb what to do after a scan
108 * Initially we set it to NO until we start processing the queue
110 applyQueueToScan = NO;
112 /* Now we re-check the queue array to see if there are
113 * any remaining encodes to be done in it and ask the
114 * user if they want to reload the queue */
115 if ([QueueFileArray count] > 0)
117 /*On Screen Notification*/
118 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"HandBrake Has Detected Item(s) From Your Previous Queue.", nil)];
119 NSBeginCriticalAlertSheet(
121 NSLocalizedString(@"Reload Queue", nil),
123 NSLocalizedString(@"Empty Queue", nil),
125 nil, @selector(didDimissReloadQueue:returnCode:contextInfo:), nil,
126 NSLocalizedString(@" Do you want to reload them ?", nil));
127 // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
128 // right below to either clear the old queue or keep it loaded up.
133 /* Show Browse Sources Window ASAP */
134 [self performSelectorOnMainThread:@selector(browseSources:)
135 withObject:nil waitUntilDone:NO];
139 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
141 if (returnCode == NSAlertOtherReturn)
143 [self clearQueueAllItems];
146 [self performSelectorOnMainThread:@selector(browseSources:)
147 withObject:nil waitUntilDone:NO];
150 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
152 // Warn if encoding a movie
154 hb_get_state( fHandle, &s );
156 if ( s.state != HB_STATE_IDLE )
158 int result = NSRunCriticalAlertPanel(
159 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
160 NSLocalizedString(@"If you quit HandBrake, your movie will be lost. Do you want to quit anyway?", nil),
161 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil, @"A movie" );
163 if (result == NSAlertDefaultReturn)
165 [self doCancelCurrentJob];
166 return NSTerminateNow;
169 return NSTerminateCancel;
172 // Warn if items still in the queue
173 else if ( hb_count( fHandle ) > 0 )
175 int result = NSRunCriticalAlertPanel(
176 NSLocalizedString(@"Are you sure you want to quit HandBrake?", nil),
177 NSLocalizedString(@"One or more encodes are queued for encoding. Do you want to quit anyway?", nil),
178 NSLocalizedString(@"Quit", nil), NSLocalizedString(@"Don't Quit", nil), nil);
180 if ( result == NSAlertDefaultReturn )
181 return NSTerminateNow;
183 return NSTerminateCancel;
186 return NSTerminateNow;
189 - (void)applicationWillTerminate:(NSNotification *)aNotification
191 [browsedSourceDisplayName release];
192 [outputPanel release];
193 [fQueueController release];
195 hb_close(&fQueueEncodeLibhb);
199 - (void) awakeFromNib
202 [fWindow setExcludedFromWindowsMenu:YES];
203 [fAdvancedOptions setView:fAdvancedView];
205 /* lets setup our presets drawer for drag and drop here */
206 [fPresetsOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
207 [fPresetsOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
208 [fPresetsOutlineView setVerticalMotionCanBeginDrag: YES];
210 /* Initialize currentScanCount so HB can use it to
211 evaluate successive scans */
212 currentScanCount = 0;
215 /* Init UserPresets .plist */
218 /* Init QueueFile .plist */
219 [self loadQueueFile];
221 fRipIndicatorShown = NO; // initially out of view in the nib
223 /* Show/Dont Show Presets drawer upon launch based
224 on user preference DefaultPresetsDrawerShow*/
225 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow"] > 0)
227 [fPresetDrawer open];
233 NSMenuItem *menuItem;
234 [fDstFormatPopUp removeAllItems];
236 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MP4 file" action: NULL keyEquivalent: @""];
237 [menuItem setTag: HB_MUX_MP4];
239 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"MKV file" action: NULL keyEquivalent: @""];
240 [menuItem setTag: HB_MUX_MKV];
242 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"AVI file" action: NULL keyEquivalent: @""];
243 [menuItem setTag: HB_MUX_AVI];
245 menuItem = [[fDstFormatPopUp menu] addItemWithTitle:@"OGM file" action: NULL keyEquivalent: @""];
246 [menuItem setTag: HB_MUX_OGM];
247 [fDstFormatPopUp selectItemAtIndex: 0];
249 [self formatPopUpChanged:nil];
251 /* We enable the create chapters checkbox here since we are .mp4 */
252 [fCreateChapterMarkers setEnabled: YES];
253 if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
255 [fCreateChapterMarkers setState: NSOnState];
261 [fDstFile2Field setStringValue: [NSString stringWithFormat:
262 @"%@/Desktop/Movie.mp4", NSHomeDirectory()]];
265 [fVidEncoderPopUp removeAllItems];
266 [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
267 [fVidEncoderPopUp addItemWithTitle: @"XviD"];
272 [fVidTargetSizeField setIntValue: 700];
273 [fVidBitrateField setIntValue: 1000];
275 [fVidQualityMatrix selectCell: fVidBitrateCell];
276 [self videoMatrixChanged:nil];
278 /* Video framerate */
279 [fVidRatePopUp removeAllItems];
280 [fVidRatePopUp addItemWithTitle: NSLocalizedString( @"Same as source", @"" )];
281 for( int i = 0; i < hb_video_rates_count; i++ )
283 if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.3f",23.976]])
285 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
286 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Film)"]];
288 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%d",25]])
290 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
291 [NSString stringWithCString: hb_video_rates[i].string], @" (PAL Film/Video)"]];
293 else if ([[NSString stringWithCString: hb_video_rates[i].string] isEqualToString: [NSString stringWithFormat: @"%.2f",29.97]])
295 [fVidRatePopUp addItemWithTitle:[NSString stringWithFormat: @"%@%@",
296 [NSString stringWithCString: hb_video_rates[i].string], @" (NTSC Video)"]];
300 [fVidRatePopUp addItemWithTitle:
301 [NSString stringWithCString: hb_video_rates[i].string]];
304 [fVidRatePopUp selectItemAtIndex: 0];
306 /* Set Auto Crop to On at launch */
307 [fPictureController setAutoCrop:YES];
310 [fAudTrack1BitratePopUp removeAllItems];
311 for( int i = 0; i < hb_audio_bitrates_count; i++ )
313 [fAudTrack1BitratePopUp addItemWithTitle:
314 [NSString stringWithCString: hb_audio_bitrates[i].string]];
317 [fAudTrack1BitratePopUp selectItemAtIndex: hb_audio_bitrates_default];
319 /* Audio samplerate */
320 [fAudTrack1RatePopUp removeAllItems];
321 for( int i = 0; i < hb_audio_rates_count; i++ )
323 [fAudTrack1RatePopUp addItemWithTitle:
324 [NSString stringWithCString: hb_audio_rates[i].string]];
326 [fAudTrack1RatePopUp selectItemAtIndex: hb_audio_rates_default];
329 [fStatusField setStringValue: @""];
334 /* We disable the Turbo 1st pass checkbox since we are not x264 */
335 [fVidTurboPassCheck setEnabled: NO];
336 [fVidTurboPassCheck setState: NSOffState];
339 /* lets get our default prefs here */
340 [self getDefaultPresets:nil];
341 /* lets initialize the current successful scancount here to 0 */
342 currentSuccessfulScanCount = 0;
347 - (void) enableUI: (bool) b
349 NSControl * controls[] =
350 { fSrcTitleField, fSrcTitlePopUp,
351 fSrcChapterField, fSrcChapterStartPopUp, fSrcChapterToField,
352 fSrcChapterEndPopUp, fSrcDuration1Field, fSrcDuration2Field,
353 fDstFormatField, fDstFormatPopUp, fDstFile1Field, fDstFile2Field,
354 fDstBrowseButton, fVidRateField, fVidRatePopUp,
355 fVidEncoderField, fVidEncoderPopUp, fVidQualityField,
356 fVidQualityMatrix, fVidGrayscaleCheck, fSubField, fSubPopUp,
357 fAudSourceLabel, fAudCodecLabel, fAudMixdownLabel, fAudSamplerateLabel, fAudBitrateLabel,
358 fAudTrack1Label, fAudTrack2Label, fAudTrack3Label, fAudTrack4Label,
359 fAudLang1PopUp, fAudLang2PopUp, fAudLang3PopUp, fAudLang4PopUp,
360 fAudTrack1CodecPopUp, fAudTrack2CodecPopUp, fAudTrack3CodecPopUp, fAudTrack4CodecPopUp,
361 fAudTrack1MixPopUp, fAudTrack2MixPopUp, fAudTrack3MixPopUp, fAudTrack4MixPopUp,
362 fAudTrack1RatePopUp, fAudTrack2RatePopUp, fAudTrack3RatePopUp, fAudTrack4RatePopUp,
363 fAudTrack1BitratePopUp, fAudTrack2BitratePopUp, fAudTrack3BitratePopUp, fAudTrack4BitratePopUp,
364 fAudDrcLabel, fAudTrack1DrcSlider, fAudTrack1DrcField, fAudTrack2DrcSlider,
365 fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
366 fPictureButton,fQueueStatus,fPicSettingARkeep, fPicSettingDeinterlace,fPicLabelSettings,fPicLabelSrc,
367 fPicLabelOutp,fPicSettingsSrc,fPicSettingsOutp,fPicSettingsAnamorphic,
368 fPicLabelAr,fPicLabelDeinterlace,fPicSettingPAR,fPicLabelAnamorphic,fPresetsAdd,fPresetsDelete,
369 fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fPicLabelAutoCrop,
370 fPicSettingAutoCrop,fPicSettingDetelecine,fPicLabelDetelecine,fPicLabelDenoise,fPicSettingDenoise,
371 fSubForcedCheck,fPicSettingDeblock,fPicLabelDeblock,fPicLabelDecomb,fPicSettingDecomb,fPresetsOutlineView,
372 fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck};
375 i < sizeof( controls ) / sizeof( NSControl * ); i++ )
377 if( [[controls[i] className] isEqualToString: @"NSTextField"] )
379 NSTextField * tf = (NSTextField *) controls[i];
380 if( ![tf isBezeled] )
382 [tf setTextColor: b ? [NSColor controlTextColor] :
383 [NSColor disabledControlTextColor]];
387 [controls[i] setEnabled: b];
393 /* if we're enabling the interface, check if the audio mixdown controls need to be enabled or not */
394 /* these will have been enabled by the mass control enablement above anyway, so we're sense-checking it here */
395 [self setEnabledStateOfAudioMixdownControls:nil];
396 /* we also call calculatePictureSizing here to sense check if we already have vfr selected */
397 [self calculatePictureSizing:nil];
398 [self shouldEnableHttpMp4CheckBox: nil];
402 [fPresetsOutlineView setEnabled: NO];
406 [self videoMatrixChanged:nil];
407 [fAdvancedOptions enableUI:b];
411 /***********************************************************************
413 ***********************************************************************
414 * Shows a progression bar on the dock icon, filled according to
415 * 'progress' (0.0 <= progress <= 1.0).
416 * Called with progress < 0.0 or progress > 1.0, restores the original
418 **********************************************************************/
419 - (void) UpdateDockIcon: (float) progress
423 NSBitmapImageRep * bmp;
425 uint32_t black = htonl( 0x000000FF );
426 uint32_t red = htonl( 0xFF0000FF );
427 uint32_t white = htonl( 0xFFFFFFFF );
428 int row_start, row_end;
431 /* Get application original icon */
432 icon = [NSImage imageNamed: @"NSApplicationIcon"];
434 if( progress < 0.0 || progress > 1.0 )
436 [NSApp setApplicationIconImage: icon];
440 /* Get it in a raw bitmap form */
441 tiff = [icon TIFFRepresentationUsingCompression:
442 NSTIFFCompressionNone factor: 1.0];
443 bmp = [NSBitmapImageRep imageRepWithData: tiff];
445 /* Draw the progression bar */
446 /* It's pretty simple (ugly?) now, but I'm no designer */
448 row_start = 3 * (int) [bmp size].height / 4;
449 row_end = 7 * (int) [bmp size].height / 8;
451 for( i = row_start; i < row_start + 2; i++ )
453 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
454 for( j = 0; j < (int) [bmp size].width; j++ )
459 for( i = row_start + 2; i < row_end - 2; i++ )
461 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
464 for( j = 2; j < (int) [bmp size].width - 2; j++ )
466 if( j < 2 + (int) ( ( [bmp size].width - 4.0 ) * progress ) )
478 for( i = row_end - 2; i < row_end; i++ )
480 pen = (uint32_t *) ( [bmp bitmapData] + i * [bmp bytesPerRow] );
481 for( j = 0; j < (int) [bmp size].width; j++ )
487 /* Now update the dock icon */
488 tiff = [bmp TIFFRepresentationUsingCompression:
489 NSTIFFCompressionNone factor: 1.0];
490 icon = [[NSImage alloc] initWithData: tiff];
491 [NSApp setApplicationIconImage: icon];
495 - (void) updateUI: (NSTimer *) timer
498 /* Update UI for fHandle (user scanning instance of libhb ) */
501 list = hb_get_titles( fHandle );
502 /* check to see if there has been a new scan done
503 this bypasses the constraints of HB_STATE_WORKING
504 not allowing setting a newly scanned source */
505 int checkScanCount = hb_get_scancount( fHandle );
506 if( checkScanCount > currentScanCount )
508 currentScanCount = checkScanCount;
509 [fScanIndicator setIndeterminate: NO];
510 [fScanIndicator setDoubleValue: 0.0];
511 [fScanIndicator setHidden: YES];
512 [self showNewScan:nil];
516 hb_get_state( fHandle, &s );
522 #define p s.param.scanning
523 case HB_STATE_SCANNING:
525 [fSrcDVD2Field setStringValue: [NSString stringWithFormat:
526 NSLocalizedString( @"Scanning title %d of %d...", @"" ),
527 p.title_cur, p.title_count]];
528 [fScanIndicator setHidden: NO];
529 [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
534 #define p s.param.scandone
535 case HB_STATE_SCANDONE:
537 [fScanIndicator setIndeterminate: NO];
538 [fScanIndicator setDoubleValue: 0.0];
539 [fScanIndicator setHidden: YES];
540 [self writeToActivityLog:"ScanDone state received from fHandle"];
541 [self showNewScan:nil];
542 [[fWindow toolbar] validateVisibleItems];
548 #define p s.param.working
549 case HB_STATE_WORKING:
556 #define p s.param.muxing
557 case HB_STATE_MUXING:
564 case HB_STATE_PAUSED:
567 case HB_STATE_WORKDONE:
574 /* Update UI for fQueueEncodeLibhb */
576 // list = hb_get_titles( fQueueEncodeLibhb ); //fQueueEncodeLibhb
577 /* check to see if there has been a new scan done
578 this bypasses the constraints of HB_STATE_WORKING
579 not allowing setting a newly scanned source */
581 checkScanCount = hb_get_scancount( fQueueEncodeLibhb );
582 if( checkScanCount > currentScanCount )
584 currentScanCount = checkScanCount;
585 [self writeToActivityLog:"currentScanCount received from fQueueEncodeLibhb"];
589 hb_get_state( fQueueEncodeLibhb, &s );
595 #define p s.param.scanning
596 case HB_STATE_SCANNING:
598 [fStatusField setStringValue: [NSString stringWithFormat:
599 NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
600 p.title_cur, p.title_count]];
601 [fRipIndicator setHidden: NO];
602 [fRipIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
607 #define p s.param.scandone
608 case HB_STATE_SCANDONE:
610 [fRipIndicator setIndeterminate: NO];
611 [fRipIndicator setDoubleValue: 0.0];
613 [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
614 [self processNewQueueEncode];
615 [[fWindow toolbar] validateVisibleItems];
621 #define p s.param.working
622 case HB_STATE_WORKING:
624 float progress_total;
625 NSMutableString * string;
626 /* Update text field */
627 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
631 [string appendFormat:
632 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
633 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
636 [fStatusField setStringValue: string];
639 progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
640 [fRipIndicator setIndeterminate: NO];
641 [fRipIndicator setDoubleValue: 100.0 * progress_total];
643 // If progress bar hasn't been revealed at the bottom of the window, do
644 // that now. This code used to be in doRip. I moved it to here to handle
645 // the case where hb_start is called by HBQueueController and not from
647 if( !fRipIndicatorShown )
649 NSRect frame = [fWindow frame];
650 if( frame.size.width <= 591 )
651 frame.size.width = 591;
652 frame.size.height += 36;
653 frame.origin.y -= 36;
654 [fWindow setFrame:frame display:YES animate:YES];
655 fRipIndicatorShown = YES;
656 /* We check to see if we need to warn the user that the computer will go to sleep
657 or shut down when encoding is finished */
658 [self remindUserOfSleepOrShutdown];
661 /* Update dock icon */
662 [self UpdateDockIcon: progress_total];
668 #define p s.param.muxing
669 case HB_STATE_MUXING:
671 /* Update text field */
672 [fStatusField setStringValue: NSLocalizedString( @"Muxing...", @"" )];
675 [fRipIndicator setIndeterminate: YES];
676 [fRipIndicator startAnimation: nil];
678 /* Update dock icon */
679 [self UpdateDockIcon: 1.0];
685 case HB_STATE_PAUSED:
686 [fStatusField setStringValue: NSLocalizedString( @"Paused", @"" )];
690 case HB_STATE_WORKDONE:
692 // HB_STATE_WORKDONE happpens as a result of libhb finishing all its jobs
693 // or someone calling hb_stop. In the latter case, hb_stop does not clear
694 // out the remaining passes/jobs in the queue. We'll do that here.
696 // Delete all remaining jobs of this encode.
697 [fStatusField setStringValue: NSLocalizedString( @"Done.", @"" )];
698 [fRipIndicator setIndeterminate: NO];
699 [fRipIndicator setDoubleValue: 0.0];
700 [[fWindow toolbar] validateVisibleItems];
702 /* Restore dock icon */
703 [self UpdateDockIcon: -1.0];
705 if( fRipIndicatorShown )
707 NSRect frame = [fWindow frame];
708 if( frame.size.width <= 591 )
709 frame.size.width = 591;
710 frame.size.height += -36;
711 frame.origin.y -= -36;
712 [fWindow setFrame:frame display:YES animate:YES];
713 fRipIndicatorShown = NO;
716 /* Check to see if the encode state has not been cancelled
717 to determine if we should check for encode done notifications */
718 if( fEncodeState != 2 )
720 /* since we have successfully completed an encode, we increment the queue counter */
721 [self incrementQueueItemDone:nil];
722 /* If Alert Window or Window and Growl has been selected */
723 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window"] ||
724 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"] )
726 /*On Screen Notification*/
729 status = NSRunAlertPanel(@"Put down that cocktail...",@"Your HandBrake encode is done!", @"OK", nil, nil);
730 [NSApp requestUserAttention:NSCriticalRequest];
732 /* If sleep has been selected */
733 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"] )
736 NSDictionary* errorDict;
737 NSAppleEventDescriptor* returnDescriptor = nil;
738 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
739 @"tell application \"Finder\" to sleep"];
740 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
741 [scriptObject release];
743 /* If Shutdown has been selected */
744 if( [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"] )
747 NSDictionary* errorDict;
748 NSAppleEventDescriptor* returnDescriptor = nil;
749 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
750 @"tell application \"Finder\" to shut down"];
751 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
752 [scriptObject release];
764 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
765 - (void) writeToActivityLog:(char *) format, ...
768 va_start(args, format);
772 vsnprintf( str, 1024, format, args );
774 time_t _now = time( NULL );
775 struct tm * now = localtime( &_now );
776 fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, str );
783 // ============================================================
784 // NSToolbar Related Methods
785 // ============================================================
787 - (void) setupToolbar {
788 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: @"HandBrake Toolbar"] autorelease];
790 [toolbar setAllowsUserCustomization: YES];
791 [toolbar setAutosavesConfiguration: YES];
792 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
794 [toolbar setDelegate: self];
796 [fWindow setToolbar: toolbar];
799 - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier:
800 (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
801 NSToolbarItem * item = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
803 if ([itemIdent isEqualToString: ToggleDrawerIdentifier])
805 [item setLabel: @"Toggle Presets"];
806 [item setPaletteLabel: @"Toggler Presets"];
807 [item setToolTip: @"Open/Close Preset Drawer"];
808 [item setImage: [NSImage imageNamed: @"Drawer"]];
809 [item setTarget: self];
810 [item setAction: @selector(toggleDrawer:)];
811 [item setAutovalidates: NO];
813 else if ([itemIdent isEqualToString: StartEncodingIdentifier])
815 [item setLabel: @"Start"];
816 [item setPaletteLabel: @"Start Encoding"];
817 [item setToolTip: @"Start Encoding"];
818 [item setImage: [NSImage imageNamed: @"Play"]];
819 [item setTarget: self];
820 [item setAction: @selector(Rip:)];
822 else if ([itemIdent isEqualToString: ShowQueueIdentifier])
824 [item setLabel: @"Show Queue"];
825 [item setPaletteLabel: @"Show Queue"];
826 [item setToolTip: @"Show Queue"];
827 [item setImage: [NSImage imageNamed: @"Queue"]];
828 [item setTarget: self];
829 [item setAction: @selector(showQueueWindow:)];
830 [item setAutovalidates: NO];
832 else if ([itemIdent isEqualToString: AddToQueueIdentifier])
834 [item setLabel: @"Add to Queue"];
835 [item setPaletteLabel: @"Add to Queue"];
836 [item setToolTip: @"Add to Queue"];
837 [item setImage: [NSImage imageNamed: @"AddToQueue"]];
838 [item setTarget: self];
839 [item setAction: @selector(addToQueue:)];
841 else if ([itemIdent isEqualToString: PauseEncodingIdentifier])
843 [item setLabel: @"Pause"];
844 [item setPaletteLabel: @"Pause Encoding"];
845 [item setToolTip: @"Pause Encoding"];
846 [item setImage: [NSImage imageNamed: @"Pause"]];
847 [item setTarget: self];
848 [item setAction: @selector(Pause:)];
850 else if ([itemIdent isEqualToString: ShowActivityIdentifier]) {
851 [item setLabel: @"Activity Window"];
852 [item setPaletteLabel: @"Show Activity Window"];
853 [item setToolTip: @"Show Activity Window"];
854 [item setImage: [NSImage imageNamed: @"ActivityWindow"]];
855 [item setTarget: self];
856 [item setAction: @selector(showDebugOutputPanel:)];
857 [item setAutovalidates: NO];
859 else if ([itemIdent isEqualToString: ChooseSourceIdentifier])
861 [item setLabel: @"Source"];
862 [item setPaletteLabel: @"Source"];
863 [item setToolTip: @"Choose Video Source"];
864 [item setImage: [NSImage imageNamed: @"Source"]];
865 [item setTarget: self];
866 [item setAction: @selector(browseSources:)];
876 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
878 return [NSArray arrayWithObjects: ChooseSourceIdentifier, NSToolbarSeparatorItemIdentifier, StartEncodingIdentifier,
879 PauseEncodingIdentifier, AddToQueueIdentifier, ShowQueueIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
880 NSToolbarSpaceItemIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier, nil];
883 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
885 return [NSArray arrayWithObjects: StartEncodingIdentifier, PauseEncodingIdentifier, AddToQueueIdentifier,
886 ChooseSourceIdentifier, ShowQueueIdentifier, ShowActivityIdentifier, ToggleDrawerIdentifier,
887 NSToolbarCustomizeToolbarItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,
888 NSToolbarSpaceItemIdentifier, NSToolbarSeparatorItemIdentifier, nil];
891 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
893 NSString * ident = [toolbarItem itemIdentifier];
898 hb_get_state2( fQueueEncodeLibhb, &s );
900 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
902 if ([ident isEqualToString: StartEncodingIdentifier])
904 [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
905 [toolbarItem setLabel: @"Stop"];
906 [toolbarItem setPaletteLabel: @"Stop"];
907 [toolbarItem setToolTip: @"Stop Encoding"];
910 if ([ident isEqualToString: PauseEncodingIdentifier])
912 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
913 [toolbarItem setLabel: @"Pause"];
914 [toolbarItem setPaletteLabel: @"Pause Encoding"];
915 [toolbarItem setToolTip: @"Pause Encoding"];
919 if ([ident isEqualToString: AddToQueueIdentifier])
922 else if (s.state == HB_STATE_PAUSED)
924 if ([ident isEqualToString: PauseEncodingIdentifier])
926 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
927 [toolbarItem setLabel: @"Resume"];
928 [toolbarItem setPaletteLabel: @"Resume Encoding"];
929 [toolbarItem setToolTip: @"Resume Encoding"];
932 if ([ident isEqualToString: StartEncodingIdentifier])
934 if ([ident isEqualToString: AddToQueueIdentifier])
937 else if (s.state == HB_STATE_SCANNING)
939 else if (s.state == HB_STATE_WORKDONE || s.state == HB_STATE_SCANDONE || SuccessfulScan)
941 if ([ident isEqualToString: StartEncodingIdentifier])
943 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
944 if (hb_count(fHandle) > 0)
945 [toolbarItem setLabel: @"Start Queue"];
947 [toolbarItem setLabel: @"Start"];
948 [toolbarItem setPaletteLabel: @"Start Encoding"];
949 [toolbarItem setToolTip: @"Start Encoding"];
952 if ([ident isEqualToString: AddToQueueIdentifier])
957 /* If there are any pending queue items, make sure the start/stop button is active */
958 if ([ident isEqualToString: StartEncodingIdentifier] && fPendingCount > 0)
960 if ([ident isEqualToString: ShowQueueIdentifier])
962 if ([ident isEqualToString: ToggleDrawerIdentifier])
964 if ([ident isEqualToString: ChooseSourceIdentifier])
966 if ([ident isEqualToString: ShowActivityIdentifier])
972 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
974 SEL action = [menuItem action];
977 hb_get_state2( fHandle, &s );
981 if (action == @selector(addToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
982 return SuccessfulScan && [fWindow attachedSheet] == nil;
984 if (action == @selector(browseSources:))
986 if (s.state == HB_STATE_SCANNING)
989 return [fWindow attachedSheet] == nil;
991 if (action == @selector(selectDefaultPreset:))
992 return [fPresetsOutlineView selectedRow] >= 0 && [fWindow attachedSheet] == nil;
993 if (action == @selector(Pause:))
995 if (s.state == HB_STATE_WORKING)
997 if(![[menuItem title] isEqualToString:@"Pause Encoding"])
998 [menuItem setTitle:@"Pause Encoding"];
1001 else if (s.state == HB_STATE_PAUSED)
1003 if(![[menuItem title] isEqualToString:@"Resume Encoding"])
1004 [menuItem setTitle:@"Resume Encoding"];
1010 if (action == @selector(Rip:))
1012 if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING || s.state == HB_STATE_PAUSED)
1014 if(![[menuItem title] isEqualToString:@"Stop Encoding"])
1015 [menuItem setTitle:@"Stop Encoding"];
1018 else if (SuccessfulScan)
1020 if(![[menuItem title] isEqualToString:@"Start Encoding"])
1021 [menuItem setTitle:@"Start Encoding"];
1022 return [fWindow attachedSheet] == nil;
1028 if( action == @selector(setDefaultPreset:) )
1030 return [fPresetsOutlineView selectedRow] != -1;
1037 #pragma mark Encode Done Actions
1038 // register a test notification and make
1039 // it enabled by default
1040 #define SERVICE_NAME @"Encode Done"
1041 - (NSDictionary *)registrationDictionaryForGrowl
1043 NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
1044 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL,
1045 [NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT,
1048 return registrationDictionary;
1051 -(void)showGrowlDoneNotification:(NSString *) filePath
1053 /* This is called from HBQueueController as jobs roll off of the queue in currentJobChanged */
1054 NSString * finishedEncode = filePath;
1055 /* strip off the path to just show the file name */
1056 finishedEncode = [finishedEncode lastPathComponent];
1057 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Growl Notification"] ||
1058 [[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Alert Window And Growl"])
1060 NSString * growlMssg = [NSString stringWithFormat: @"your HandBrake encode %@ is done!",finishedEncode];
1061 [GrowlApplicationBridge
1062 notifyWithTitle:@"Put down that cocktail..."
1063 description:growlMssg
1064 notificationName:SERVICE_NAME
1072 -(void)sendToMetaX:(NSString *) filePath
1074 /* This is called from HBQueueController as jobs roll off of the queue in currentJobChanged */
1075 if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
1077 NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
1078 [myScript executeAndReturnError: nil];
1083 #pragma mark Get New Source
1085 /*Opens the source browse window, called from Open Source widgets */
1086 - (IBAction) browseSources: (id) sender
1088 NSOpenPanel * panel;
1090 panel = [NSOpenPanel openPanel];
1091 [panel setAllowsMultipleSelection: NO];
1092 [panel setCanChooseFiles: YES];
1093 [panel setCanChooseDirectories: YES ];
1094 NSString * sourceDirectory;
1095 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"])
1097 sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastSourceDirectory"];
1101 sourceDirectory = @"~/Desktop";
1102 sourceDirectory = [sourceDirectory stringByExpandingTildeInPath];
1104 /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed
1105 * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable
1107 [panel beginSheetForDirectory: sourceDirectory file: nil types: nil
1108 modalForWindow: fWindow modalDelegate: self
1109 didEndSelector: @selector( browseSourcesDone:returnCode:contextInfo: )
1110 contextInfo: sender];
1113 - (void) browseSourcesDone: (NSOpenPanel *) sheet
1114 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1116 /* we convert the sender content of contextInfo back into a variable called sender
1117 * mostly just for consistency for evaluation later
1119 id sender = (id)contextInfo;
1120 /* User selected a file to open */
1121 if( returnCode == NSOKButton )
1123 /* Free display name allocated previously by this code */
1124 [browsedSourceDisplayName release];
1126 NSString *scanPath = [[sheet filenames] objectAtIndex: 0];
1127 /* we set the last searched source directory in the prefs here */
1128 NSString *sourceDirectory = [scanPath stringByDeletingLastPathComponent];
1129 [[NSUserDefaults standardUserDefaults] setObject:sourceDirectory forKey:@"LastSourceDirectory"];
1130 /* we order out sheet, which is the browse window as we need to open
1131 * the title selection sheet right away
1133 [sheet orderOut: self];
1135 if (sender == fOpenSourceTitleMMenu)
1137 /* We put the chosen source path in the source display text field for the
1138 * source title selection sheet in which the user specifies the specific title to be
1139 * scanned as well as the short source name in fSrcDsplyNameTitleScan just for display
1140 * purposes in the title panel
1143 [fScanSrcTitlePathField setStringValue:scanPath];
1144 NSString *displayTitlescanSourceName;
1146 if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
1148 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
1149 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
1150 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
1154 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1155 displayTitlescanSourceName = [scanPath lastPathComponent];
1157 /* we set the source display name in the title selection dialogue */
1158 [fSrcDsplyNameTitleScan setStringValue:displayTitlescanSourceName];
1159 /* we set the attempted scans display name for main window to displayTitlescanSourceName*/
1160 browsedSourceDisplayName = [displayTitlescanSourceName retain];
1161 /* We show the actual sheet where the user specifies the title to be scanned
1162 * as we are going to do a title specific scan
1164 [self showSourceTitleScanPanel:nil];
1168 /* We are just doing a standard full source scan, so we specify "0" to libhb */
1169 NSString *path = [[sheet filenames] objectAtIndex: 0];
1171 /* We check to see if the chosen file at path is a package */
1172 if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:path])
1174 [self writeToActivityLog: "trying to open a package at: %s", [path UTF8String]];
1175 /* We check to see if this is an .eyetv package */
1176 if ([[path pathExtension] isEqualToString: @"eyetv"])
1178 [self writeToActivityLog:"trying to open eyetv package"];
1179 /* We're looking at an EyeTV package - try to open its enclosed
1181 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1183 int n = [[path stringByAppendingString: @"/"]
1184 completePathIntoString: &mpgname caseSensitive: NO
1185 matchesIntoArray: nil
1186 filterTypes: [NSArray arrayWithObject: @"mpg"]];
1189 /* Found an mpeg inside the eyetv package, make it our scan path
1190 and call performScan on the enclosed mpeg */
1192 [self writeToActivityLog:"found mpeg in eyetv package"];
1193 [self performScan:path scanTitleNum:0];
1197 /* We did not find an mpeg file in our package, so we do not call performScan */
1198 [self writeToActivityLog:"no valid mpeg in eyetv package"];
1201 /* We check to see if this is a .dvdmedia package */
1202 else if ([[path pathExtension] isEqualToString: @"dvdmedia"])
1204 /* path IS a package - but dvdmedia packages can be treaded like normal directories */
1205 browsedSourceDisplayName = [[[path stringByDeletingPathExtension] lastPathComponent] retain];
1206 [self writeToActivityLog:"trying to open dvdmedia package"];
1207 [self performScan:path scanTitleNum:0];
1211 /* The package is not an eyetv package, so we do not call performScan */
1212 [self writeToActivityLog:"unable to open package"];
1215 else // path is not a package, so we treat it as a dvd parent folder or VIDEO_TS folder
1217 /* path is not a package, so we call perform scan directly on our file */
1218 if ([[path lastPathComponent] isEqualToString: @"VIDEO_TS"])
1220 [self writeToActivityLog:"trying to open video_ts folder (video_ts folder chosen)"];
1221 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name*/
1222 browsedSourceDisplayName = [[[path stringByDeletingLastPathComponent] lastPathComponent] retain];
1226 [self writeToActivityLog:"trying to open video_ts folder (parent directory chosen)"];
1227 /* if not the VIDEO_TS Folder, we can assume the chosen folder is the source name */
1228 /* make sure we remove any path extension as this can also be an '.mpg' file */
1229 browsedSourceDisplayName = [[path lastPathComponent] retain];
1231 [self performScan:path scanTitleNum:0];
1239 /* Here we open the title selection sheet where we can specify an exact title to be scanned */
1240 - (IBAction) showSourceTitleScanPanel: (id) sender
1242 /* We default the title number to be scanned to "0" which results in a full source scan, unless the
1245 [fScanSrcTitleNumField setStringValue: @"0"];
1246 /* Show the panel */
1247 [NSApp beginSheet:fScanSrcTitlePanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
1250 - (IBAction) closeSourceTitleScanPanel: (id) sender
1252 [NSApp endSheet: fScanSrcTitlePanel];
1253 [fScanSrcTitlePanel orderOut: self];
1255 if(sender == fScanSrcTitleOpenButton)
1257 /* We setup the scan status in the main window to indicate a source title scan */
1258 [fSrcDVD2Field setStringValue: @"Opening a new source title ..."];
1259 [fScanIndicator setHidden: NO];
1260 [fScanIndicator setIndeterminate: YES];
1261 [fScanIndicator startAnimation: nil];
1263 /* We use the performScan method to actually perform the specified scan passing the path and the title
1266 [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
1270 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1271 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1273 /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
1274 applyQueueToScan = NO;
1275 /* use a bool to determine whether or not we can decrypt using vlc */
1276 BOOL cancelScanDecrypt = 0;
1277 NSString *path = scanPath;
1278 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1280 // Notify ChapterTitles that there's no title
1281 [fChapterTitlesDelegate resetWithTitle:nil];
1282 [fChapterTable reloadData];
1284 [self enableUI: NO];
1286 if( [detector isVideoDVD] )
1288 // The chosen path was actually on a DVD, so use the raw block
1289 // device path instead.
1290 path = [detector devicePath];
1291 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1293 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1294 NSString *vlcPath = @"/Applications/VLC.app";
1295 NSFileManager * fileManager = [NSFileManager defaultManager];
1296 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1298 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1299 cancelScanDecrypt = 1;
1300 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
1302 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");
1303 [NSApp requestUserAttention:NSCriticalRequest];
1305 if (status == NSAlertDefaultReturn)
1307 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
1308 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
1310 else if (status == NSAlertAlternateReturn)
1312 /* User chose to cancel the scan */
1313 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
1317 /* 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 */
1318 cancelScanDecrypt = 0;
1319 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
1325 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
1326 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
1330 if (cancelScanDecrypt == 0)
1332 /* we actually pass the scan off to libhb here */
1333 /* If there is no title number passed to scan, we use "0"
1334 * which causes the default behavior of a full source scan
1340 if (scanTitleNum > 0)
1342 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
1345 hb_scan( fHandle, [path UTF8String], scanTitleNum );
1346 [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
1350 - (IBAction) showNewScan:(id)sender
1354 int indxpri=0; // Used to search the longuest title (default in combobox)
1355 int longuestpri=0; // Used to search the longuest title (default in combobox)
1358 list = hb_get_titles( fHandle );
1360 if( !hb_list_count( list ) )
1362 /* We display a message if a valid dvd source was not chosen */
1363 [fSrcDVD2Field setStringValue: @"No Valid Source Found"];
1364 SuccessfulScan = NO;
1366 // Notify ChapterTitles that there's no title
1367 [fChapterTitlesDelegate resetWithTitle:nil];
1368 [fChapterTable reloadData];
1372 /* We increment the successful scancount here by one,
1373 which we use at the end of this function to tell the gui
1374 if this is the first successful scan since launch and whether
1375 or not we should set all settings to the defaults */
1377 currentSuccessfulScanCount++;
1379 [[fWindow toolbar] validateVisibleItems];
1381 [fSrcTitlePopUp removeAllItems];
1382 for( int i = 0; i < hb_list_count( list ); i++ )
1384 title = (hb_title_t *) hb_list_item( list, i );
1386 currentSource = [NSString stringWithUTF8String: title->name];
1387 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
1388 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
1390 /* Use the dvd name in the default output field here
1391 May want to add code to remove blank spaces for some dvd names*/
1392 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
1393 if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
1395 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1396 @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
1400 [fDstFile2Field setStringValue: [NSString stringWithFormat:
1401 @"%@/Desktop/%@.mp4", NSHomeDirectory(),[browsedSourceDisplayName stringByDeletingPathExtension]]];
1405 if (longuestpri < title->hours*60*60 + title->minutes *60 + title->seconds)
1407 longuestpri=title->hours*60*60 + title->minutes *60 + title->seconds;
1411 [fSrcTitlePopUp addItemWithTitle: [NSString
1412 stringWithFormat: @"%d - %02dh%02dm%02ds",
1413 title->index, title->hours, title->minutes,
1417 // Select the longuest title
1418 [fSrcTitlePopUp selectItemAtIndex: indxpri];
1419 [self titlePopUpChanged:nil];
1421 SuccessfulScan = YES;
1422 [self enableUI: YES];
1424 /* if its the initial successful scan after awakeFromNib */
1425 if (currentSuccessfulScanCount == 1)
1427 [self selectDefaultPreset:nil];
1428 /* initially set deinterlace to 0, will be overridden reset by the default preset anyway */
1429 //[fPictureController setDeinterlace:0];
1431 /* lets set Denoise to index 0 or "None" since this is the first scan */
1432 //[fPictureController setDenoise:0];
1434 [fPictureController setInitialPictureFilters];
1444 #pragma mark New Output Destination
1446 - (IBAction) browseFile: (id) sender
1448 /* Open a panel to let the user choose and update the text field */
1449 NSSavePanel * panel = [NSSavePanel savePanel];
1450 /* We get the current file name and path from the destination field here */
1451 [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
1452 modalForWindow: fWindow modalDelegate: self
1453 didEndSelector: @selector( browseFileDone:returnCode:contextInfo: )
1457 - (void) browseFileDone: (NSSavePanel *) sheet
1458 returnCode: (int) returnCode contextInfo: (void *) contextInfo
1460 if( returnCode == NSOKButton )
1462 [fDstFile2Field setStringValue: [sheet filename]];
1468 #pragma mark Main Window Control
1470 - (IBAction) openMainWindow: (id) sender
1472 [fWindow makeKeyAndOrderFront:nil];
1475 - (BOOL) windowShouldClose: (id) sender
1480 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
1483 [fWindow makeKeyAndOrderFront:nil];
1493 #pragma mark Queue File
1495 - (void) loadQueueFile {
1496 /* We declare the default NSFileManager into fileManager */
1497 NSFileManager * fileManager = [NSFileManager defaultManager];
1498 /*We define the location of the user presets file */
1499 QueueFile = @"~/Library/Application Support/HandBrake/Queue.plist";
1500 QueueFile = [[QueueFile stringByExpandingTildeInPath]retain];
1501 /* We check for the presets.plist */
1502 if ([fileManager fileExistsAtPath:QueueFile] == 0)
1504 [fileManager createFileAtPath:QueueFile contents:nil attributes:nil];
1507 QueueFileArray = [[NSMutableArray alloc] initWithContentsOfFile:QueueFile];
1508 /* lets check to see if there is anything in the queue file .plist */
1509 if (nil == QueueFileArray)
1511 /* if not, then lets initialize an empty array */
1512 QueueFileArray = [[NSMutableArray alloc] init];
1514 /* Initialize our curQueueEncodeIndex to 0
1515 * so we can use it to track which queue
1516 * item is to be used to track our encodes */
1517 /* NOTE: this should be changed if and when we
1518 * are able to get the last unfinished encode
1519 * in the case of a crash or shutdown */
1524 [self clearQueueEncodedItems];
1526 currentQueueEncodeIndex = 0;
1529 - (void)addQueueFileItem
1531 [QueueFileArray addObject:[self createQueueFileItem]];
1532 [self saveQueueFileItem];
1536 - (void) removeQueueFileItem:(int) queueItemToRemove
1539 // FIX ME: WE NEED TO IDENTIFY AN ENCODING ITEM AND CALL
1541 [QueueFileArray removeObjectAtIndex:queueItemToRemove];
1542 [self saveQueueFileItem];
1546 - (void)saveQueueFileItem
1548 [QueueFileArray writeToFile:QueueFile atomically:YES];
1549 [fQueueController setQueueArray: QueueFileArray];
1550 [self getQueueStats];
1553 - (void)getQueueStats
1555 /* lets get the stats on the status of the queue array */
1557 fEncodingQueueItem = 0;
1559 fCompletedCount = 0;
1563 /* We use a number system to set the encode status of the queue item
1565 * 0 == already encoded
1566 * 1 == is being encoded
1567 * 2 == is yet to be encoded
1572 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1574 while (tempObject = [enumerator nextObject])
1576 NSDictionary *thisQueueDict = tempObject;
1577 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
1581 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
1584 fEncodingQueueItem = i;
1586 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
1590 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
1597 /* Set the queue status field in the main window */
1598 NSMutableString * string;
1599 if (fPendingCount == 1)
1601 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending in the queue", @"" ), fPendingCount];
1605 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending in the queue", @"" ), fPendingCount];
1607 [fQueueStatus setStringValue:string];
1611 /* This method will clear the queue of any encodes that are not still pending
1612 * this includes both successfully completed encodes as well as cancelled encodes */
1613 - (void) clearQueueEncodedItems
1615 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1617 NSMutableArray *tempArray;
1618 tempArray = [NSMutableArray array];
1619 /* we look here to see if the preset is we move on to the next one */
1620 while ( tempObject = [enumerator nextObject] )
1622 /* If the queue item is not still pending (finished successfully or it was cancelled
1623 * during the last session, then we put it in tempArray to be deleted from QueueFileArray*/
1624 if ([[tempObject objectForKey:@"Status"] intValue] != 2)
1626 [tempArray addObject:tempObject];
1630 [QueueFileArray removeObjectsInArray:tempArray];
1631 [self saveQueueFileItem];
1635 /* This method will clear the queue of any encodes that are not still pending
1636 * this includes both successfully completed encodes as well as cancelled encodes */
1637 - (void) clearQueueAllItems
1639 NSEnumerator *enumerator = [QueueFileArray objectEnumerator];
1641 NSMutableArray *tempArray;
1642 tempArray = [NSMutableArray array];
1643 /* we look here to see if the preset is we move on to the next one */
1644 while ( tempObject = [enumerator nextObject] )
1646 [tempArray addObject:tempObject];
1649 [QueueFileArray removeObjectsInArray:tempArray];
1650 [self saveQueueFileItem];
1654 /* This method will duplicate prepareJob however into the
1655 * queue .plist instead of into the job structure so it can
1656 * be recalled later */
1657 - (NSDictionary *)createQueueFileItem
1659 NSMutableDictionary *queueFileJob = [[NSMutableDictionary alloc] init];
1661 hb_list_t * list = hb_get_titles( fHandle );
1662 hb_title_t * title = (hb_title_t *) hb_list_item( list,
1663 [fSrcTitlePopUp indexOfSelectedItem] );
1664 hb_job_t * job = title->job;
1665 //hb_audio_config_t * audio;
1667 // For picture filters
1668 //hb_job_t * job = fTitle->job;
1670 /* We use a number system to set the encode status of the queue item
1671 * 0 == already encoded
1672 * 1 == is being encoded
1673 * 2 == is yet to be encoded
1676 [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
1677 /* Source and Destination Information */
1679 [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
1680 [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
1681 [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
1682 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
1684 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
1686 [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
1688 /* Lets get the preset info if there is any */
1689 [queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
1690 [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
1692 [queueFileJob setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
1693 /* Chapter Markers fCreateChapterMarkers*/
1694 [queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1695 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1696 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1697 /* Mux mp4 with http optimization */
1698 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1699 /* Add iPod uuid atom */
1700 [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1704 [queueFileJob setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
1705 /* x264 Option String */
1706 [queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1708 [queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1709 [queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1710 [queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1711 [queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1713 [queueFileJob setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
1716 [queueFileJob setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
1717 /* 2 Pass Encoding */
1718 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
1719 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
1720 [queueFileJob setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
1722 /* Picture Sizing */
1723 /* Use Max Picture settings for whatever the dvd is.*/
1724 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1725 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1726 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1727 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1728 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1729 NSString * pictureSummary;
1730 pictureSummary = [NSString stringWithFormat:@"Source: %@ Output: %@ Anamorphic: %@",
1731 [fPicSettingsSrc stringValue],
1732 [fPicSettingsOutp stringValue],
1733 [fPicSettingsAnamorphic stringValue]];
1734 [queueFileJob setObject:pictureSummary forKey:@"PictureSizingSummary"];
1735 /* Set crop settings here */
1736 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1737 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1738 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1739 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1740 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1742 /* Picture Filters */
1743 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
1744 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
1745 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
1746 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
1747 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
1748 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
1751 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1753 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
1754 [queueFileJob setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
1755 [queueFileJob setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
1756 [queueFileJob setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
1757 [queueFileJob setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
1758 [queueFileJob setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
1759 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
1761 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1763 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
1764 [queueFileJob setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
1765 [queueFileJob setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
1766 [queueFileJob setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
1767 [queueFileJob setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
1768 [queueFileJob setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
1769 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
1771 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1773 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
1774 [queueFileJob setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
1775 [queueFileJob setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
1776 [queueFileJob setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
1777 [queueFileJob setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
1778 [queueFileJob setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
1779 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
1781 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1783 [queueFileJob setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
1784 [queueFileJob setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
1785 [queueFileJob setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
1786 [queueFileJob setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
1787 [queueFileJob setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
1788 [queueFileJob setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
1789 [queueFileJob setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
1793 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1794 [queueFileJob setObject:[NSNumber numberWithInt:[fSubPopUp indexOfSelectedItem]] forKey:@"JobSubtitlesIndex"];
1795 /* Forced Subtitles */
1796 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1800 /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
1802 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterStart"];
1804 [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"JobChapterEnd"];
1807 [queueFileJob setObject:[NSNumber numberWithInt:[[fDstFormatPopUp selectedItem] tag]] forKey:@"JobFileFormatMux"];
1808 /* Chapter Markers fCreateChapterMarkers*/
1809 //[queueFileJob setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
1810 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
1811 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
1812 /* Mux mp4 with http optimization */
1813 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
1814 /* Add iPod uuid atom */
1815 //[queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
1819 [queueFileJob setObject:[NSNumber numberWithInt:[[fVidEncoderPopUp selectedItem] tag]] forKey:@"JobVideoEncoderVcodec"];
1820 /* x264 Option String */
1821 //[queueFileJob setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
1823 //[queueFileJob setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
1824 //[queueFileJob setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
1825 //[queueFileJob setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
1826 //[queueFileJob setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
1828 [queueFileJob setObject:[NSNumber numberWithInt:[fVidRatePopUp indexOfSelectedItem]] forKey:@"JobIndexVideoFramerate"];
1829 [queueFileJob setObject:[NSNumber numberWithInt:title->rate] forKey:@"JobVrate"];
1830 [queueFileJob setObject:[NSNumber numberWithInt:title->rate_base] forKey:@"JobVrateBase"];
1831 /* Picture Sizing */
1832 /* Use Max Picture settings for whatever the dvd is.*/
1833 [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
1834 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
1835 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
1836 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
1837 [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
1839 /* Set crop settings here */
1840 [queueFileJob setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
1841 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
1842 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
1843 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
1844 [queueFileJob setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
1846 /* Picture Filters */
1847 [queueFileJob setObject:[fPicSettingDecomb stringValue] forKey:@"JobPictureDecomb"];
1850 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
1852 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
1853 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
1854 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
1855 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
1856 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1BitratePopUp selectedItem] tag]] forKey:@"JobAudio1Bitrate"];
1858 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
1860 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
1861 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
1862 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
1863 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
1864 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2BitratePopUp selectedItem] tag]] forKey:@"JobAudio2Bitrate"];
1866 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
1868 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
1869 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
1870 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
1871 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
1872 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3BitratePopUp selectedItem] tag]] forKey:@"JobAudio3Bitrate"];
1874 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
1876 //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
1877 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
1878 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
1879 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
1880 [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
1883 [queueFileJob setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
1884 /* Forced Subtitles */
1885 [queueFileJob setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
1887 /* we need to auto relase the queueFileJob and return it */
1888 [queueFileJob autorelease];
1889 return queueFileJob;
1893 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
1894 - (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
1896 unsigned index = [indexSet lastIndex];
1897 unsigned aboveInsertIndexCount = 0;
1899 while (index != NSNotFound)
1901 unsigned removeIndex;
1903 if (index >= insertIndex)
1905 removeIndex = index + aboveInsertIndexCount;
1906 aboveInsertIndexCount++;
1910 removeIndex = index;
1914 id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
1915 [QueueFileArray removeObjectAtIndex:removeIndex];
1916 [QueueFileArray insertObject:object atIndex:insertIndex];
1919 index = [indexSet indexLessThanIndex:index];
1921 /* We save all of the Queue data here
1922 * and it also gets sent back to the queue controller*/
1923 [self saveQueueFileItem];
1929 #pragma mark Queue Job Processing
1931 - (void) incrementQueueItemDone:(int) queueItemDoneIndexNum
1933 int i = currentQueueEncodeIndex;
1934 [[QueueFileArray objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Status"];
1936 /* We save all of the Queue data here */
1937 [self saveQueueFileItem];
1938 /* We Reload the New Table data for presets */
1939 //[fPresetsOutlineView reloadData];
1941 /* Since we have now marked a queue item as done
1942 * we can go ahead and increment currentQueueEncodeIndex
1943 * so that if there is anything left in the queue we can
1944 * go ahead and move to the next item if we want to */
1945 currentQueueEncodeIndex++ ;
1946 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
1947 int queueItems = [QueueFileArray count];
1948 /* If we still have more items in our queue, lets go to the next one */
1949 if (currentQueueEncodeIndex < queueItems)
1951 [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
1952 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
1956 [self writeToActivityLog: "incrementQueueItemDone the %d item queue is complete", currentQueueEncodeIndex - 1];
1960 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
1961 - (void) performNewQueueScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
1963 //NSRunAlertPanel(@"Hello!", @"We are now performing a new queue scan!", @"OK", nil, nil);
1965 /* use a bool to determine whether or not we can decrypt using vlc */
1966 BOOL cancelScanDecrypt = 0;
1967 /* set the bool so that showNewScan knows to apply the appropriate queue
1968 * settings as this is a queue rescan
1970 applyQueueToScan = YES;
1971 NSString *path = scanPath;
1972 HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
1974 /*On Screen Notification*/
1976 //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
1977 //[NSApp requestUserAttention:NSCriticalRequest];
1979 // Notify ChapterTitles that there's no title
1980 [fChapterTitlesDelegate resetWithTitle:nil];
1981 [fChapterTable reloadData];
1983 //[self enableUI: NO];
1985 if( [detector isVideoDVD] )
1987 // The chosen path was actually on a DVD, so use the raw block
1988 // device path instead.
1989 path = [detector devicePath];
1990 [self writeToActivityLog: "trying to open a physical dvd at: %s", [scanPath UTF8String]];
1992 /* lets check for vlc here to make sure we have a dylib available to use for decrypting */
1993 NSString *vlcPath = @"/Applications/VLC.app";
1994 NSFileManager * fileManager = [NSFileManager defaultManager];
1995 if ([fileManager fileExistsAtPath:vlcPath] == 0)
1997 /*vlc not found in /Applications so we set the bool to cancel scanning to 1 */
1998 cancelScanDecrypt = 1;
1999 [self writeToActivityLog: "VLC app not found for decrypting physical dvd"];
2001 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");
2002 [NSApp requestUserAttention:NSCriticalRequest];
2004 if (status == NSAlertDefaultReturn)
2006 /* User chose to go download vlc (as they rightfully should) so we send them to the vlc site */
2007 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.videolan.org/"]];
2009 else if (status == NSAlertAlternateReturn)
2011 /* User chose to cancel the scan */
2012 [self writeToActivityLog: "cannot open physical dvd , scan cancelled"];
2016 /* 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 */
2017 cancelScanDecrypt = 0;
2018 [self writeToActivityLog: "user overrode vlc warning -trying to open physical dvd without decryption"];
2024 /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
2025 [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
2029 if (cancelScanDecrypt == 0)
2031 /* we actually pass the scan off to libhb here */
2032 /* If there is no title number passed to scan, we use "0"
2033 * which causes the default behavior of a full source scan
2039 if (scanTitleNum > 0)
2041 [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
2043 [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2044 hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum );
2048 /* This method was originally used to load up a new queue item in the gui and
2049 * then start processing it. However we now have modified -prepareJob and use a second
2050 * instance of libhb to do our actual encoding, therefor right now it is not required.
2051 * Nonetheless I want to leave this in here
2052 * because basically its everything we need to be able to actually modify a pending queue
2053 * item in the gui and resave it. At least for now - dynaflash
2056 - (IBAction)applyQueueSettings:(id)sender
2058 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2059 hb_job_t * job = fTitle->job;
2061 /* Set title number and chapters */
2062 /* since the queue only scans a single title, we really don't need to pick a title */
2063 //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
2065 [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
2066 [fSrcChapterEndPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterEnd"] intValue] - 1];
2069 [fDstFormatPopUp selectItemWithTitle:[queueToApply objectForKey:@"FileFormat"]];
2070 [self formatPopUpChanged:nil];
2072 /* Chapter Markers*/
2073 [fCreateChapterMarkers setState:[[queueToApply objectForKey:@"ChapterMarkers"] intValue]];
2074 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
2075 [fDstMp4LargeFileCheck setState:[[queueToApply objectForKey:@"Mp4LargeFile"] intValue]];
2076 /* Mux mp4 with http optimization */
2077 [fDstMp4HttpOptFileCheck setState:[[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue]];
2080 /* We set the advanced opt string here if applicable*/
2081 [fVidEncoderPopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoEncoder"]];
2082 [fAdvancedOptions setOptions:[queueToApply objectForKey:@"x264Option"]];
2084 /* Lets run through the following functions to get variables set there */
2085 [self videoEncoderPopUpChanged:nil];
2086 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
2087 [fDstMp4iPodFileCheck setState:[[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue]];
2088 [self calculateBitrate:nil];
2091 [fVidQualityMatrix selectCellAtRow:[[queueToApply objectForKey:@"VideoQualityType"] intValue] column:0];
2093 [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
2094 [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
2095 [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
2097 [self videoMatrixChanged:nil];
2099 /* Video framerate */
2100 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
2101 detected framerate in the fVidRatePopUp so we use index 0*/
2102 if ([[queueToApply objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
2104 [fVidRatePopUp selectItemAtIndex: 0];
2108 [fVidRatePopUp selectItemWithTitle:[queueToApply objectForKey:@"VideoFramerate"]];
2112 [fVidGrayscaleCheck setState:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
2114 /* 2 Pass Encoding */
2115 [fVidTwoPassCheck setState:[[queueToApply objectForKey:@"VideoTwoPass"] intValue]];
2116 [self twoPassCheckboxChanged:nil];
2117 /* Turbo 1st pass for 2 Pass Encoding */
2118 [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
2121 if ([queueToApply objectForKey:@"Audio1Track"] > 0)
2123 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
2125 [fAudLang1PopUp selectItemAtIndex: 1];
2127 [self audioTrackPopUpChanged: fAudLang1PopUp];
2128 [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
2129 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2130 [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
2131 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2133 if ([fAudTrack1MixPopUp selectedItem] == nil)
2135 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
2137 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
2138 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2139 if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
2141 [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
2143 [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
2144 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
2146 if ([queueToApply objectForKey:@"Audio2Track"] > 0)
2148 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
2150 [fAudLang2PopUp selectItemAtIndex: 1];
2152 [self audioTrackPopUpChanged: fAudLang2PopUp];
2153 [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
2154 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2155 [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
2156 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2158 if ([fAudTrack2MixPopUp selectedItem] == nil)
2160 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
2162 [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
2163 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2164 if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
2166 [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
2168 [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
2169 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
2171 if ([queueToApply objectForKey:@"Audio3Track"] > 0)
2173 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
2175 [fAudLang3PopUp selectItemAtIndex: 1];
2177 [self audioTrackPopUpChanged: fAudLang3PopUp];
2178 [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
2179 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2180 [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
2181 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2183 if ([fAudTrack3MixPopUp selectedItem] == nil)
2185 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
2187 [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
2188 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2189 if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
2191 [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
2193 [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
2194 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
2196 if ([queueToApply objectForKey:@"Audio4Track"] > 0)
2198 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
2200 [fAudLang4PopUp selectItemAtIndex: 1];
2202 [self audioTrackPopUpChanged: fAudLang4PopUp];
2203 [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
2204 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2205 [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
2206 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
2208 if ([fAudTrack4MixPopUp selectedItem] == nil)
2210 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
2212 [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
2213 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
2214 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
2216 [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
2218 [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
2219 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
2224 [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
2225 /* Forced Subtitles */
2226 [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
2228 /* Picture Settings */
2229 /* we check to make sure the presets width/height does not exceed the sources width/height */
2230 if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"] intValue])
2232 /* if so, then we use the sources height and width to avoid scaling up */
2233 job->width = fTitle->width;
2234 job->height = fTitle->height;
2236 else // source width/height is >= the preset height/width
2238 /* we can go ahead and use the presets values for height and width */
2239 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2240 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2242 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2243 if (job->keep_ratio == 1)
2245 hb_fix_aspect( job, HB_KEEP_WIDTH );
2246 if( job->height > fTitle->height )
2248 job->height = fTitle->height;
2249 hb_fix_aspect( job, HB_KEEP_HEIGHT );
2252 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2255 /* If Cropping is set to custom, then recall all four crop values from
2256 when the preset was created and apply them */
2257 if ([[queueToApply objectForKey:@"PictureAutoCrop"] intValue] == 0)
2259 [fPictureController setAutoCrop:NO];
2261 /* Here we use the custom crop values saved at the time the preset was saved */
2262 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2263 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2264 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2265 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2268 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
2270 [fPictureController setAutoCrop:YES];
2271 /* Here we use the auto crop values determined right after scan */
2272 job->crop[0] = AutoCropTop;
2273 job->crop[1] = AutoCropBottom;
2274 job->crop[2] = AutoCropLeft;
2275 job->crop[3] = AutoCropRight;
2281 [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
2283 [fPictureController setVFR:[[queueToApply objectForKey:@"VFR"] intValue]];
2285 [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
2287 [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
2289 [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
2291 [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
2293 [self calculatePictureSizing:nil];
2296 /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
2297 //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
2298 // [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
2299 if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
2301 /* Deselect the currently selected Preset if there is one*/
2302 //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
2303 //[self selectPreset:nil];
2305 //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
2306 /* Change UI to show "Custom" settings are being used */
2307 //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
2309 curUserPresetChosenNum = nil;
2313 /* Deselect the currently selected Preset if there is one*/
2314 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
2315 /* Change UI to show "Custom" settings are being used */
2316 [fPresetSelectedDisplay setStringValue: @"Custom"];
2318 //curUserPresetChosenNum = nil;
2321 /* We need to set this bool back to NO, in case the user wants to do a scan */
2322 //applyQueueToScan = NO;
2324 /* so now we go ahead and process the new settings */
2325 [self processNewQueueEncode];
2330 /* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
2331 - (void) processNewQueueEncode
2333 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2334 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2335 hb_job_t * job = title->job;
2337 if( !hb_list_count( list ) )
2339 [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
2343 [self writeToActivityLog: "processNewQueueEncode title list is: %d", hb_list_count( list )];
2346 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2347 [self writeToActivityLog: "processNewQueueEncode currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
2348 [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
2349 job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
2350 [self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
2352 [self writeToActivityLog: "processNewQueueEncode back from prepareJob"];
2353 if( [[queueToApply objectForKey:@"SubtitlesForced"] intValue] == 1 )
2354 job->subtitle_force = 1;
2356 job->subtitle_force = 0;
2359 * subtitle of -1 is a scan
2361 if( job->subtitle == -1 )
2366 * When subtitle scan is enabled do a fast pre-scan job
2367 * which will determine which subtitles to enable, if any.
2370 x264opts_tmp = job->x264opts;
2373 job->x264opts = NULL;
2375 job->indepth_scan = 1;
2377 job->select_subtitle = (hb_subtitle_t**)malloc(sizeof(hb_subtitle_t*));
2378 *(job->select_subtitle) = NULL;
2381 * Add the pre-scan job
2383 hb_add( fQueueEncodeLibhb, job );
2384 job->x264opts = x264opts_tmp;
2387 job->select_subtitle = NULL;
2389 /* No subtitle were selected, so reset the subtitle to -1 (which before
2390 * this point meant we were scanning
2392 if( job->subtitle == -2 )
2395 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
2397 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
2398 job->indepth_scan = 0;
2401 * Do not autoselect subtitles on the first pass of a two pass
2403 job->select_subtitle = NULL;
2407 hb_add( fQueueEncodeLibhb, job );
2411 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2412 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2414 job->select_subtitle = subtitle_tmp;
2416 hb_add( fQueueEncodeLibhb, job );
2421 job->indepth_scan = 0;
2424 hb_add( fQueueEncodeLibhb, job );
2427 NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
2428 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2429 /* Lets mark our new encode as 1 or "Encoding" */
2430 [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
2431 [self saveQueueFileItem];
2432 /* We should be all setup so let 'er rip */
2438 #pragma mark Job Handling
2444 NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
2445 hb_list_t * list = hb_get_titles( fQueueEncodeLibhb );
2446 hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
2447 hb_job_t * job = title->job;
2448 hb_audio_config_t * audio;
2449 [self writeToActivityLog: "prepareJob reached"];
2450 /* Chapter selection */
2451 job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
2452 job->chapter_end = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
2454 /* Format (Muxer) and Video Encoder */
2455 job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
2456 job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
2459 /* If mpeg-4, then set mpeg-4 specific options like chapters and > 4gb file sizes */
2460 //if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
2462 /* We set the largeFileSize (64 bit formatting) variable here to allow for > 4gb files based on the format being
2463 mpeg4 and the checkbox being checked
2464 *Note: this will break compatibility with some target devices like iPod, etc.!!!!*/
2465 if( [[queueToApply objectForKey:@"Mp4LargeFile"] intValue] == 1)
2467 job->largeFileSize = 1;
2471 job->largeFileSize = 0;
2473 /* We set http optimized mp4 here */
2474 if( [[queueToApply objectForKey:@"Mp4HttpOptimize"] intValue] == 1 )
2476 job->mp4_optimize = 1;
2480 job->mp4_optimize = 0;
2484 /* We set the chapter marker extraction here based on the format being
2485 mpeg4 or mkv and the checkbox being checked */
2486 if ([[queueToApply objectForKey:@"ChapterMarkers"] intValue] == 1)
2488 job->chapter_markers = 1;
2492 job->chapter_markers = 0;
2496 if( job->vcodec & HB_VCODEC_X264 )
2498 if ([[queueToApply objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
2507 /* Set this flag to switch from Constant Quantizer(default) to Constant Rate Factor Thanks jbrjake
2508 Currently only used with Constant Quality setting*/
2509 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultCrf"] > 0 && [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2)
2513 /* Below Sends x264 options to the core library if x264 is selected*/
2514 /* Lets use this as per Nyx, Thanks Nyx!*/
2515 job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
2516 /* Turbo first pass if two pass and Turbo First pass is selected */
2517 if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
2519 /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
2520 NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
2521 /* append the "Turbo" string variable to the existing opts string.
2522 Note: the "Turbo" string must be appended, not prepended to work properly*/
2523 NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
2524 strcpy(job->x264opts, [firstPassOptStringCombined UTF8String]);
2528 strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
2534 [self writeToActivityLog: "prepareJob reached Picture Settings"];
2535 /* Picture Size Settings */
2536 job->width = [[queueToApply objectForKey:@"PictureWidth"] intValue];
2537 job->height = [[queueToApply objectForKey:@"PictureHeight"] intValue];
2539 job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"] intValue];
2540 job->pixel_ratio = [[queueToApply objectForKey:@"PicturePAR"] intValue];
2543 /* Here we use the crop values saved at the time the preset was saved */
2544 job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"] intValue];
2545 job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"] intValue];
2546 job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"] intValue];
2547 job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"] intValue];
2549 [self writeToActivityLog: "prepareJob reached Frame Rate"];
2551 /* Video settings */
2552 if( [[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue] > 0 )
2554 job->vrate = 27000000;
2555 job->vrate_base = hb_video_rates[[[queueToApply objectForKey:@"JobIndexVideoFramerate"] intValue]-1].rate;
2556 /* We are not same as source so we set job->cfr to 1
2557 * to enable constant frame rate since user has specified
2558 * a specific framerate*/
2563 job->vrate = [[queueToApply objectForKey:@"JobVrate"] intValue];
2564 job->vrate_base = [[queueToApply objectForKey:@"JobVrateBase"] intValue];
2565 /* We are same as source so we set job->cfr to 0
2566 * to enable true same as source framerate */
2569 [self writeToActivityLog: "prepareJob reached Bitrate Video Quality"];
2570 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 0 )
2573 Bitrate should already have been calculated and displayed
2574 in fVidBitrateField, so let's just use it */
2576 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 1 )
2578 job->vquality = -1.0;
2579 job->vbitrate = [[queueToApply objectForKey:@"VideoAvgBitrate"] intValue];
2581 if ( [[queueToApply objectForKey:@"VideoQualityType"] intValue] == 2 )
2583 job->vquality = [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue];
2588 job->grayscale = [[queueToApply objectForKey:@"VideoGrayScale"] intValue];
2589 /* Subtitle settings */
2590 job->subtitle = [[queueToApply objectForKey:@"JobSubtitlesIndex"] intValue] - 2;
2592 [self writeToActivityLog: "prepareJob reached Audio"];
2593 /* Audio tracks and mixdowns */
2594 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
2595 int audiotrack_count = hb_list_count(job->list_audio);
2596 for( int i = 0; i < audiotrack_count;i++)
2598 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
2599 hb_list_rem(job->list_audio, temp_audio);
2601 /* Now lets add our new tracks to the audio list here */
2602 if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
2604 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2605 hb_audio_config_init(audio);
2606 audio->in.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2607 /* We go ahead and assign values to our audio->out.<properties> */
2608 audio->out.track = [[queueToApply objectForKey:@"Audio1Track"] intValue] - 1;
2609 audio->out.codec = [[queueToApply objectForKey:@"JobAudio1Encoder"] intValue];
2610 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio1Mixdown"] intValue];
2611 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio1Bitrate"] intValue];
2612 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio1Samplerate"] intValue];
2613 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue];
2615 hb_audio_add( job, audio );
2618 if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
2621 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2622 hb_audio_config_init(audio);
2623 audio->in.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2624 [self writeToActivityLog: "prepareJob audiotrack 2 is: %d", audio->in.track];
2625 /* We go ahead and assign values to our audio->out.<properties> */
2626 audio->out.track = [[queueToApply objectForKey:@"Audio2Track"] intValue] - 1;
2627 audio->out.codec = [[queueToApply objectForKey:@"JobAudio2Encoder"] intValue];
2628 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio2Mixdown"] intValue];
2629 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio2Bitrate"] intValue];
2630 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio2Samplerate"] intValue];
2631 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue];
2633 hb_audio_add( job, audio );
2637 if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
2639 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2640 hb_audio_config_init(audio);
2641 audio->in.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2642 /* We go ahead and assign values to our audio->out.<properties> */
2643 audio->out.track = [[queueToApply objectForKey:@"Audio3Track"] intValue] - 1;
2644 audio->out.codec = [[queueToApply objectForKey:@"JobAudio3Encoder"] intValue];
2645 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio3Mixdown"] intValue];
2646 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio3Bitrate"] intValue];
2647 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio3Samplerate"] intValue];
2648 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2650 hb_audio_add( job, audio );
2654 if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
2656 audio = (hb_audio_config_t *) calloc(1, sizeof(*audio));
2657 hb_audio_config_init(audio);
2658 audio->in.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2659 /* We go ahead and assign values to our audio->out.<properties> */
2660 audio->out.track = [[queueToApply objectForKey:@"Audio4Track"] intValue] - 1;
2661 audio->out.codec = [[queueToApply objectForKey:@"JobAudio4Encoder"] intValue];
2662 audio->out.mixdown = [[queueToApply objectForKey:@"JobAudio4Mixdown"] intValue];
2663 audio->out.bitrate = [[queueToApply objectForKey:@"JobAudio4Bitrate"] intValue];
2664 audio->out.samplerate = [[queueToApply objectForKey:@"JobAudio4Samplerate"] intValue];
2665 audio->out.dynamic_range_compression = [[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue];
2667 hb_audio_add( job, audio );
2671 /* set vfr according to the Picture Window */
2672 if ([[queueToApply objectForKey:@"VFR"] intValue] == 1)
2681 [self writeToActivityLog: "prepareJob reached Filters"];
2683 job->filters = hb_list_init();
2685 /* Now lets call the filters if applicable.
2686 * The order of the filters is critical
2689 if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
2691 hb_list_add( job->filters, &hb_filter_detelecine );
2695 if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
2697 /* Run old deinterlacer fd by default */
2698 hb_filter_decomb.settings = (char *) [[queueToApply objectForKey:@"JobPictureDecomb"] UTF8String];
2699 hb_list_add( job->filters, &hb_filter_decomb );
2703 if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
2705 /* Run old deinterlacer fd by default */
2706 hb_filter_deinterlace.settings = "-1";
2707 hb_list_add( job->filters, &hb_filter_deinterlace );
2709 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 2)
2711 /* Yadif mode 0 (without spatial deinterlacing.) */
2712 hb_filter_deinterlace.settings = "2";
2713 hb_list_add( job->filters, &hb_filter_deinterlace );
2715 else if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 3)
2717 /* Yadif (with spatial deinterlacing) */
2718 hb_filter_deinterlace.settings = "0";
2719 hb_list_add( job->filters, &hb_filter_deinterlace );
2723 if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1) // Weak in popup
2725 hb_filter_denoise.settings = "2:1:2:3";
2726 hb_list_add( job->filters, &hb_filter_denoise );
2728 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 2) // Medium in popup
2730 hb_filter_denoise.settings = "3:2:2:3";
2731 hb_list_add( job->filters, &hb_filter_denoise );
2733 else if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 3) // Strong in popup
2735 hb_filter_denoise.settings = "7:7:5:5";
2736 hb_list_add( job->filters, &hb_filter_denoise );
2739 /* Deblock (uses pp7 default) */
2740 if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] == 1)
2742 hb_list_add( job->filters, &hb_filter_deblock );
2744 [self writeToActivityLog: "prepareJob exiting"];
2749 /* addToQueue: puts up an alert before ultimately calling doAddToQueue
2751 - (IBAction) addToQueue: (id) sender
2753 /* We get the destination directory from the destination field here */
2754 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2755 /* We check for a valid destination here */
2756 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2758 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2762 /* We check for duplicate name here */
2763 if( [[NSFileManager defaultManager] fileExistsAtPath:
2764 [fDstFile2Field stringValue]] )
2766 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2767 NSLocalizedString( @"Cancel", @"" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2768 @selector( overwriteAddToQueueAlertDone:returnCode:contextInfo: ),
2769 NULL, NULL, [NSString stringWithFormat:
2770 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2771 [fDstFile2Field stringValue]] );
2772 // overwriteAddToQueueAlertDone: will be called when the alert is dismissed.
2776 [self doAddToQueue];
2780 /* overwriteAddToQueueAlertDone: called from the alert posted by addToQueue that asks
2781 the user if they want to overwrite an exiting movie file.
2783 - (void) overwriteAddToQueueAlertDone: (NSWindow *) sheet
2784 returnCode: (int) returnCode contextInfo: (void *) contextInfo
2786 if( returnCode == NSAlertAlternateReturn )
2787 [self doAddToQueue];
2790 - (void) doAddToQueue
2792 [self addQueueFileItem ];
2797 /* Rip: puts up an alert before ultimately calling doRip
2799 - (IBAction) Rip: (id) sender
2801 [self writeToActivityLog: "Rip: Pending queue count is %d", fPendingCount];
2802 /* Rip or Cancel ? */
2804 hb_get_state2( fQueueEncodeLibhb, &s );
2806 if(s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED)
2808 [self Cancel: sender];
2812 // If there are pending jobs in the queue, then this is a rip the queue
2814 if (fPendingCount > 0)
2816 /* here lets start the queue with the first pending item */
2817 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2822 // Before adding jobs to the queue, check for a valid destination.
2824 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2825 if ([[NSFileManager defaultManager] fileExistsAtPath:destinationDirectory] == 0)
2827 NSRunAlertPanel(@"Warning!", @"This is not a valid destination directory!", @"OK", nil, nil);
2831 /* We check for duplicate name here */
2832 if( [[NSFileManager defaultManager] fileExistsAtPath:[fDstFile2Field stringValue]] )
2834 NSBeginCriticalAlertSheet( NSLocalizedString( @"File already exists", @"" ),
2835 NSLocalizedString( @"Cancel", "" ), NSLocalizedString( @"Overwrite", @"" ), nil, fWindow, self,
2836 @selector( overWriteAlertDone:returnCode:contextInfo: ),
2837 NULL, NULL, [NSString stringWithFormat:
2838 NSLocalizedString( @"Do you want to overwrite %@?", @"" ),
2839 [fDstFile2Field stringValue]] );
2841 // overWriteAlertDone: will be called when the alert is dismissed. It will call doRip.
2845 /* if there are no pending jobs in the queue, then add this one to the queue and rip
2846 otherwise, just rip the queue */
2847 if(fPendingCount == 0)
2849 [self writeToActivityLog: "Rip: No pending jobs, so sending this one to doAddToQueue"];
2850 [self doAddToQueue];
2853 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2854 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2855 /* go right to processing the new queue encode */
2856 [self writeToActivityLog: "Rip: Going right to performNewQueueScan"];
2857 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2862 /* overWriteAlertDone: called from the alert posted by Rip: that asks the user if they
2863 want to overwrite an exiting movie file.
2865 - (void) overWriteAlertDone: (NSWindow *) sheet
2866 returnCode: (int) returnCode contextInfo: (void *) contextInfo
2868 if( returnCode == NSAlertAlternateReturn )
2870 /* if there are no jobs in the queue, then add this one to the queue and rip
2871 otherwise, just rip the queue */
2872 if( fPendingCount == 0 )
2874 [self doAddToQueue];
2877 NSString *destinationDirectory = [[fDstFile2Field stringValue] stringByDeletingLastPathComponent];
2878 [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
2879 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2884 - (void) remindUserOfSleepOrShutdown
2886 if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Put Computer To Sleep"])
2888 /*Warn that computer will sleep after encoding*/
2891 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);
2892 [NSApp requestUserAttention:NSCriticalRequest];
2893 if ( reminduser == NSAlertAlternateReturn )
2895 [self showPreferencesWindow:nil];
2898 else if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AlertWhenDone"] isEqualToString: @"Shut Down Computer"])
2900 /*Warn that computer will shut down after encoding*/
2903 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);
2904 [NSApp requestUserAttention:NSCriticalRequest];
2905 if ( reminduser == NSAlertAlternateReturn )
2907 [self showPreferencesWindow:nil];
2916 /* Let libhb do the job */
2917 hb_start( fQueueEncodeLibhb );
2918 /*set the fEncodeState State */
2923 //------------------------------------------------------------------------------------
2924 // Cancels and deletes the current job and stops libhb from processing the remaining
2926 //------------------------------------------------------------------------------------
2927 - (void) doCancelCurrentJob
2929 // Stop the current job. hb_stop will only cancel the current pass and then set
2930 // its state to HB_STATE_WORKDONE. It also does this asynchronously. So when we
2931 // see the state has changed to HB_STATE_WORKDONE (in updateUI), we'll delete the
2932 // remaining passes of the job and then start the queue back up if there are any
2936 hb_stop( fQueueEncodeLibhb );
2937 fEncodeState = 2; // don't alert at end of processing since this was a cancel
2939 // now that we've stopped the currently encoding job, lets mark it as cancelled
2940 [[QueueFileArray objectAtIndex:currentQueueEncodeIndex] setObject:[NSNumber numberWithInt:3] forKey:@"Status"];
2941 // and as always, save it in the queue .plist...
2942 /* We save all of the Queue data here */
2943 [self saveQueueFileItem];
2944 // so now lets move to
2945 currentQueueEncodeIndex++ ;
2946 // ... and see if there are more items left in our queue
2947 int queueItems = [QueueFileArray count];
2948 /* If we still have more items in our queue, lets go to the next one */
2949 if (currentQueueEncodeIndex < queueItems)
2951 [self writeToActivityLog: "doCancelCurrentJob currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
2952 [self writeToActivityLog: "doCancelCurrentJob moving to the next job"];
2954 [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
2958 [self writeToActivityLog: "doCancelCurrentJob the item queue is complete"];
2963 //------------------------------------------------------------------------------------
2964 // Displays an alert asking user if the want to cancel encoding of current job.
2965 // Cancel: returns immediately after posting the alert. Later, when the user
2966 // acknowledges the alert, doCancelCurrentJob is called.
2967 //------------------------------------------------------------------------------------
2968 - (IBAction)Cancel: (id)sender
2970 if (!fQueueController) return;
2973 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"Stop encoding ?", nil)];
2975 // Which window to attach the sheet to?
2976 NSWindow * docWindow;
2977 if ([sender respondsToSelector: @selector(window)])
2978 docWindow = [sender window];
2980 docWindow = fWindow;
2982 NSBeginCriticalAlertSheet(
2984 NSLocalizedString(@"Keep Encoding", nil),
2986 NSLocalizedString(@"Stop Encoding", nil),
2988 nil, @selector(didDimissCancelCurrentJob:returnCode:contextInfo:), nil,
2989 NSLocalizedString(@"Your movie will be lost if you don't continue encoding.", nil));
2991 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
2994 - (void) didDimissCancelCurrentJob: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
2996 if (returnCode == NSAlertOtherReturn)
2997 [self doCancelCurrentJob]; // <- this also stops libhb
3000 - (IBAction) Pause: (id) sender
3003 hb_get_state2( fHandle, &s );
3005 if( s.state == HB_STATE_PAUSED )
3007 hb_resume( fHandle );
3011 hb_pause( fHandle );
3016 #pragma mark GUI Controls Changed Methods
3018 - (IBAction) titlePopUpChanged: (id) sender
3020 hb_list_t * list = hb_get_titles( fHandle );
3021 hb_title_t * title = (hb_title_t*)
3022 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3024 /* If Auto Naming is on. We create an output filename of dvd name - title number */
3025 if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
3027 [fDstFile2Field setStringValue: [NSString stringWithFormat:
3028 @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
3029 [browsedSourceDisplayName stringByDeletingPathExtension],
3031 [[fDstFile2Field stringValue] pathExtension]]];
3034 /* Update chapter popups */
3035 [fSrcChapterStartPopUp removeAllItems];
3036 [fSrcChapterEndPopUp removeAllItems];
3037 for( int i = 0; i < hb_list_count( title->list_chapter ); i++ )
3039 [fSrcChapterStartPopUp addItemWithTitle: [NSString
3040 stringWithFormat: @"%d", i + 1]];
3041 [fSrcChapterEndPopUp addItemWithTitle: [NSString
3042 stringWithFormat: @"%d", i + 1]];
3045 [fSrcChapterStartPopUp selectItemAtIndex: 0];
3046 [fSrcChapterEndPopUp selectItemAtIndex:
3047 hb_list_count( title->list_chapter ) - 1];
3048 [self chapterPopUpChanged:nil];
3050 /* Start Get and set the initial pic size for display */
3051 hb_job_t * job = title->job;
3054 /*Set Source Size Field Here */
3055 [fPicSettingsSrc setStringValue: [NSString stringWithFormat: @"%d x %d", fTitle->width, fTitle->height]];
3057 /* Set Auto Crop to on upon selecting a new title */
3058 [fPictureController setAutoCrop:YES];
3060 /* We get the originial output picture width and height and put them
3061 in variables for use with some presets later on */
3062 PicOrigOutputWidth = job->width;
3063 PicOrigOutputHeight = job->height;
3064 AutoCropTop = job->crop[0];
3065 AutoCropBottom = job->crop[1];
3066 AutoCropLeft = job->crop[2];
3067 AutoCropRight = job->crop[3];
3069 /* Run Through encoderPopUpChanged to see if there
3070 needs to be any pic value modifications based on encoder settings */
3071 //[self encoderPopUpChanged: NULL];
3072 /* END Get and set the initial pic size for display */
3074 /* Update subtitle popups */
3075 hb_subtitle_t * subtitle;
3076 [fSubPopUp removeAllItems];
3077 [fSubPopUp addItemWithTitle: @"None"];
3078 [fSubPopUp addItemWithTitle: @"Autoselect"];
3079 for( int i = 0; i < hb_list_count( title->list_subtitle ); i++ )
3081 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, i );
3083 /* We cannot use NSPopUpButton's addItemWithTitle because
3084 it checks for duplicate entries */
3085 [[fSubPopUp menu] addItemWithTitle: [NSString stringWithCString:
3086 subtitle->lang] action: NULL keyEquivalent: @""];
3088 [fSubPopUp selectItemAtIndex: 0];
3090 [self subtitleSelectionChanged:nil];
3092 /* Update chapter table */
3093 [fChapterTitlesDelegate resetWithTitle:title];
3094 [fChapterTable reloadData];
3096 /* Lets make sure there arent any erroneous audio tracks in the job list, so lets make sure its empty*/
3097 int audiotrack_count = hb_list_count(job->list_audio);
3098 for( int i = 0; i < audiotrack_count;i++)
3100 hb_audio_t * temp_audio = (hb_audio_t*) hb_list_item( job->list_audio, 0 );
3101 hb_list_rem(job->list_audio, temp_audio);
3104 /* Update audio popups */
3105 [self addAllAudioTracksToPopUp: fAudLang1PopUp];
3106 [self addAllAudioTracksToPopUp: fAudLang2PopUp];
3107 [self addAllAudioTracksToPopUp: fAudLang3PopUp];
3108 [self addAllAudioTracksToPopUp: fAudLang4PopUp];
3109 /* search for the first instance of our prefs default language for track 1, and set track 2 to "none" */
3110 NSString * audioSearchPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"DefaultLanguage"];
3111 [self selectAudioTrackInPopUp: fAudLang1PopUp searchPrefixString: audioSearchPrefix selectIndexIfNotFound: 1];
3112 [self selectAudioTrackInPopUp:fAudLang2PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3113 [self selectAudioTrackInPopUp:fAudLang3PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3114 [self selectAudioTrackInPopUp:fAudLang4PopUp searchPrefixString:nil selectIndexIfNotFound:0];
3116 /* changing the title may have changed the audio channels on offer, */
3117 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3118 [self audioTrackPopUpChanged: fAudLang1PopUp];
3119 [self audioTrackPopUpChanged: fAudLang2PopUp];
3120 [self audioTrackPopUpChanged: fAudLang3PopUp];
3121 [self audioTrackPopUpChanged: fAudLang4PopUp];
3123 [fVidRatePopUp selectItemAtIndex: 0];
3125 /* we run the picture size values through calculatePictureSizing to get all picture setting information*/
3126 [self calculatePictureSizing:nil];
3128 /* lets call tableViewSelected to make sure that any preset we have selected is enforced after a title change */
3129 [self selectPreset:nil];
3132 - (IBAction) chapterPopUpChanged: (id) sender
3135 /* If start chapter popup is greater than end chapter popup,
3136 we set the end chapter popup to the same as start chapter popup */
3137 if ([fSrcChapterStartPopUp indexOfSelectedItem] > [fSrcChapterEndPopUp indexOfSelectedItem])
3139 [fSrcChapterEndPopUp selectItemAtIndex: [fSrcChapterStartPopUp indexOfSelectedItem]];
3143 hb_list_t * list = hb_get_titles( fHandle );
3144 hb_title_t * title = (hb_title_t *)
3145 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3147 hb_chapter_t * chapter;
3148 int64_t duration = 0;
3149 for( int i = [fSrcChapterStartPopUp indexOfSelectedItem];
3150 i <= [fSrcChapterEndPopUp indexOfSelectedItem]; i++ )
3152 chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
3153 duration += chapter->duration;
3156 duration /= 90000; /* pts -> seconds */
3157 [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
3158 @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
3161 [self calculateBitrate: sender];
3164 - (IBAction) formatPopUpChanged: (id) sender
3166 NSString * string = [fDstFile2Field stringValue];
3167 int format = [fDstFormatPopUp indexOfSelectedItem];
3169 /* Initially set the large file (64 bit formatting) output checkbox to hidden */
3170 [fDstMp4LargeFileCheck setHidden: YES];
3171 [fDstMp4HttpOptFileCheck setHidden: YES];
3172 [fDstMp4iPodFileCheck setHidden: YES];
3174 /* Update the Video Codec PopUp */
3175 /* Note: we now store the video encoder int values from common.c in the tags of each popup for easy retrieval later */
3176 [fVidEncoderPopUp removeAllItems];
3177 NSMenuItem *menuItem;
3178 /* These video encoders are available to all of our current muxers, so lets list them once here */
3179 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (FFmpeg)" action: NULL keyEquivalent: @""];
3180 [menuItem setTag: HB_VCODEC_FFMPEG];
3182 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"MPEG-4 (XviD)" action: NULL keyEquivalent: @""];
3183 [menuItem setTag: HB_VCODEC_XVID];
3187 /*Get Default MP4 File Extension*/
3188 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0)
3196 /* Add additional video encoders here */
3197 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3198 [menuItem setTag: HB_VCODEC_X264];
3199 /* We show the mp4 option checkboxes here since we are mp4 */
3200 [fCreateChapterMarkers setEnabled: YES];
3201 [fDstMp4LargeFileCheck setHidden: NO];
3202 [fDstMp4HttpOptFileCheck setHidden: NO];
3203 [fDstMp4iPodFileCheck setHidden: NO];
3208 /* Add additional video encoders here */
3209 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3210 [menuItem setTag: HB_VCODEC_X264];
3211 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3212 [menuItem setTag: HB_VCODEC_THEORA];
3213 /* We enable the create chapters checkbox here */
3214 [fCreateChapterMarkers setEnabled: YES];
3219 /* Add additional video encoders here */
3220 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"H.264 (x264)" action: NULL keyEquivalent: @""];
3221 [menuItem setTag: HB_VCODEC_X264];
3222 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3223 [fCreateChapterMarkers setEnabled: NO];
3224 [fCreateChapterMarkers setState: NSOffState];
3229 /* Add additional video encoders here */
3230 menuItem = [[fVidEncoderPopUp menu] addItemWithTitle:@"VP3 (Theora)" action: NULL keyEquivalent: @""];
3231 [menuItem setTag: HB_VCODEC_THEORA];
3232 /* We disable the create chapters checkbox here and make sure it is unchecked*/
3233 [fCreateChapterMarkers setEnabled: NO];
3234 [fCreateChapterMarkers setState: NSOffState];
3237 [fVidEncoderPopUp selectItemAtIndex: 0];
3239 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
3240 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
3241 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
3242 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
3245 [self autoSetM4vExtension: sender];
3247 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%s", [string stringByDeletingPathExtension], ext]];
3249 if( SuccessfulScan )
3251 /* Add/replace to the correct extension */
3252 [self audioTrackPopUpChanged: fAudLang1PopUp];
3253 [self audioTrackPopUpChanged: fAudLang2PopUp];
3254 [self audioTrackPopUpChanged: fAudLang3PopUp];
3255 [self audioTrackPopUpChanged: fAudLang4PopUp];
3257 if( [fVidEncoderPopUp selectedItem] == nil )
3260 [fVidEncoderPopUp selectItemAtIndex:0];
3261 [self videoEncoderPopUpChanged:nil];
3263 /* changing the format may mean that we can / can't offer mono or 6ch, */
3264 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3266 /* We call the method to properly enable/disable turbo 2 pass */
3267 [self twoPassCheckboxChanged: sender];
3268 /* We call method method to change UI to reflect whether a preset is used or not*/
3271 [self customSettingUsed: sender];
3274 - (IBAction) autoSetM4vExtension: (id) sender
3276 if ( [fDstFormatPopUp indexOfSelectedItem] )
3279 NSString * extension = @"mp4";
3281 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3282 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3283 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3284 [fCreateChapterMarkers state] == NSOnState ||
3285 [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultMpegName"] > 0 )
3290 if( [extension isEqualTo: [[fDstFile2Field stringValue] pathExtension]] )
3293 [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@.%@",
3294 [[fDstFile2Field stringValue] stringByDeletingPathExtension], extension]];
3297 - (void) shouldEnableHttpMp4CheckBox: (id) sender
3299 if( [[fAudTrack1CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3300 [[fAudTrack3CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 ||
3301 [[fAudTrack4CodecPopUp selectedItem] tag] == HB_ACODEC_AC3 )
3302 [fDstMp4HttpOptFileCheck setEnabled: NO];
3304 [fDstMp4HttpOptFileCheck setEnabled: YES];
3307 /* Method to determine if we should change the UI
3308 To reflect whether or not a Preset is being used or if
3309 the user is using "Custom" settings by determining the sender*/
3310 - (IBAction) customSettingUsed: (id) sender
3312 if ([sender stringValue])
3314 /* Deselect the currently selected Preset if there is one*/
3315 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
3316 /* Change UI to show "Custom" settings are being used */
3317 [fPresetSelectedDisplay setStringValue: @"Custom"];
3319 curUserPresetChosenNum = nil;
3325 #pragma mark - Video
3327 - (IBAction) videoEncoderPopUpChanged: (id) sender
3329 hb_job_t * job = fTitle->job;
3330 int videoEncoder = [[fVidEncoderPopUp selectedItem] tag];
3332 [fAdvancedOptions setHidden:YES];
3333 /* If we are using x264 then show the x264 advanced panel*/
3334 if (videoEncoder == HB_VCODEC_X264)
3336 [fAdvancedOptions setHidden:NO];
3337 [self autoSetM4vExtension: sender];
3340 /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
3341 is being used as it borks up loose anamorphic .
3342 For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
3343 to use the index itself but this is easier */
3344 if (videoEncoder == HB_VCODEC_FFMPEG)
3346 if (job->pixel_ratio == 2)
3348 job->pixel_ratio = 0;
3350 [fPictureController setAllowLooseAnamorphic:NO];
3351 /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
3352 container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
3353 anything other than MP4.
3355 [fDstMp4iPodFileCheck setEnabled: NO];
3356 [fDstMp4iPodFileCheck setState: NSOffState];
3360 [fPictureController setAllowLooseAnamorphic:YES];
3361 [fDstMp4iPodFileCheck setEnabled: YES];
3364 [self calculatePictureSizing: sender];
3365 [self twoPassCheckboxChanged: sender];
3369 - (IBAction) twoPassCheckboxChanged: (id) sender
3371 /* check to see if x264 is chosen */
3372 if([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
3374 if( [fVidTwoPassCheck state] == NSOnState)
3376 [fVidTurboPassCheck setHidden: NO];
3380 [fVidTurboPassCheck setHidden: YES];
3381 [fVidTurboPassCheck setState: NSOffState];
3383 /* Make sure Two Pass is checked if Turbo is checked */
3384 if( [fVidTurboPassCheck state] == NSOnState)
3386 [fVidTwoPassCheck setState: NSOnState];
3391 [fVidTurboPassCheck setHidden: YES];
3392 [fVidTurboPassCheck setState: NSOffState];
3395 /* We call method method to change UI to reflect whether a preset is used or not*/
3396 [self customSettingUsed: sender];
3399 - (IBAction ) videoFrameRateChanged: (id) sender
3401 /* We call method method to calculatePictureSizing to error check detelecine*/
3402 [self calculatePictureSizing: sender];
3404 /* We call method method to change UI to reflect whether a preset is used or not*/
3405 [self customSettingUsed: sender];
3407 - (IBAction) videoMatrixChanged: (id) sender;
3409 bool target, bitrate, quality;
3411 target = bitrate = quality = false;
3412 if( [fVidQualityMatrix isEnabled] )
3414 switch( [fVidQualityMatrix selectedRow] )
3427 [fVidTargetSizeField setEnabled: target];
3428 [fVidBitrateField setEnabled: bitrate];
3429 [fVidQualitySlider setEnabled: quality];
3430 [fVidTwoPassCheck setEnabled: !quality &&
3431 [fVidQualityMatrix isEnabled]];
3434 [fVidTwoPassCheck setState: NSOffState];
3435 [fVidTurboPassCheck setHidden: YES];
3436 [fVidTurboPassCheck setState: NSOffState];
3439 [self qualitySliderChanged: sender];
3440 [self calculateBitrate: sender];
3441 [self customSettingUsed: sender];
3444 - (IBAction) qualitySliderChanged: (id) sender
3446 [fVidConstantCell setTitle: [NSString stringWithFormat:
3447 NSLocalizedString( @"Constant quality: %.0f %%", @"" ), 100.0 *
3448 [fVidQualitySlider floatValue]]];
3449 [self customSettingUsed: sender];
3452 - (void) controlTextDidChange: (NSNotification *) notification
3454 [self calculateBitrate:nil];
3457 - (IBAction) calculateBitrate: (id) sender
3459 if( !fHandle || [fVidQualityMatrix selectedRow] != 0 || !SuccessfulScan )
3464 hb_list_t * list = hb_get_titles( fHandle );
3465 hb_title_t * title = (hb_title_t *) hb_list_item( list,
3466 [fSrcTitlePopUp indexOfSelectedItem] );
3467 hb_job_t * job = title->job;
3469 [fVidBitrateField setIntValue: hb_calc_bitrate( job,
3470 [fVidTargetSizeField intValue] )];
3474 #pragma mark - Picture
3476 /* lets set the picture size back to the max from right after title scan
3477 Lets use an IBAction here as down the road we could always use a checkbox
3478 in the gui to easily take the user back to max. Remember, the compiler
3479 resolves IBActions down to -(void) during compile anyway */
3480 - (IBAction) revertPictureSizeToMax: (id) sender
3482 hb_job_t * job = fTitle->job;
3483 /* We use the output picture width and height
3484 as calculated from libhb right after title is set
3485 in TitlePopUpChanged */
3486 job->width = PicOrigOutputWidth;
3487 job->height = PicOrigOutputHeight;
3488 [fPictureController setAutoCrop:YES];
3489 /* Here we use the auto crop values determined right after scan */
3490 job->crop[0] = AutoCropTop;
3491 job->crop[1] = AutoCropBottom;
3492 job->crop[2] = AutoCropLeft;
3493 job->crop[3] = AutoCropRight;
3496 [self calculatePictureSizing: sender];
3497 /* We call method to change UI to reflect whether a preset is used or not*/
3498 [self customSettingUsed: sender];
3502 * Registers changes made in the Picture Settings Window.
3505 - (void)pictureSettingsDidChange {
3506 [self calculatePictureSizing:nil];
3509 /* Get and Display Current Pic Settings in main window */
3510 - (IBAction) calculatePictureSizing: (id) sender
3512 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", fTitle->job->width, fTitle->job->height]];
3514 if (fTitle->job->pixel_ratio == 1)
3516 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
3517 int arpwidth = fTitle->job->pixel_aspect_width;
3518 int arpheight = fTitle->job->pixel_aspect_height;
3519 int displayparwidth = titlewidth * arpwidth / arpheight;
3520 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
3521 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", titlewidth, displayparheight]];
3522 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Strict", displayparwidth, displayparheight]];
3523 fTitle->job->keep_ratio = 0;
3525 else if (fTitle->job->pixel_ratio == 2)
3527 hb_job_t * job = fTitle->job;
3528 int output_width, output_height, output_par_width, output_par_height;
3529 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
3531 display_width = output_width * output_par_width / output_par_height;
3533 [fPicSettingsOutp setStringValue: [NSString stringWithFormat:@"%d x %d", output_width, output_height]];
3534 [fPicSettingsAnamorphic setStringValue: [NSString stringWithFormat:@"%d x %d Loose", display_width, output_height]];
3536 fTitle->job->keep_ratio = 0;
3540 [fPicSettingsAnamorphic setStringValue:@"Off"];
3543 /* Set ON/Off values for the deinterlace/keep aspect ratio according to boolean */
3544 if (fTitle->job->keep_ratio > 0)
3546 [fPicSettingARkeep setStringValue: @"On"];
3550 [fPicSettingARkeep setStringValue: @"Off"];
3554 if ([fPictureController detelecine]) {
3555 [fPicSettingDetelecine setStringValue: @"Yes"];
3558 [fPicSettingDetelecine setStringValue: @"No"];
3562 if ([fPictureController decomb] == 0)
3564 [fPicSettingDecomb setStringValue: @"Off"];
3566 else if ([fPictureController decomb] == 1)
3568 [fPicSettingDecomb setStringValue: @"1:2:6:9:80:16:16"];
3570 else if ([fPictureController decomb] == 2)
3572 [fPicSettingDecomb setStringValue:[[NSUserDefaults standardUserDefaults] stringForKey:@"DecombCustomString"]];
3575 /* VFR (Variable Frame Rate) */
3576 if ([fPictureController vfr]) {
3577 /* We change the string of the fps popup to warn that vfr is on Framerate (FPS): */
3578 [fVidRateField setStringValue: @"Framerate (VFR On):"];
3579 /* for VFR we select same as source (or title framerate) and disable the popup.
3580 * We know its index 0 as that is determined in titlePopUpChanged */
3581 [fVidRatePopUp selectItemAtIndex: 0];
3582 [fVidRatePopUp setEnabled: NO];
3586 /* make sure the label for framerate is set to its default */
3587 [fVidRateField setStringValue: @"Framerate (FPS):"];
3588 [fVidRatePopUp setEnabled: YES];
3592 if ([fPictureController deinterlace] == 0)
3594 [fPicSettingDeinterlace setStringValue: @"Off"];
3596 else if ([fPictureController deinterlace] == 1)
3598 [fPicSettingDeinterlace setStringValue: @"Fast"];
3600 else if ([fPictureController deinterlace] == 2)
3602 [fPicSettingDeinterlace setStringValue: @"Slow"];
3604 else if ([fPictureController deinterlace] == 3)
3606 [fPicSettingDeinterlace setStringValue: @"Slower"];
3610 if ([fPictureController denoise] == 0)
3612 [fPicSettingDenoise setStringValue: @"Off"];
3614 else if ([fPictureController denoise] == 1)
3616 [fPicSettingDenoise setStringValue: @"Weak"];
3618 else if ([fPictureController denoise] == 2)
3620 [fPicSettingDenoise setStringValue: @"Medium"];
3622 else if ([fPictureController denoise] == 3)
3624 [fPicSettingDenoise setStringValue: @"Strong"];
3628 if ([fPictureController deblock]) {
3629 [fPicSettingDeblock setStringValue: @"Yes"];
3632 [fPicSettingDeblock setStringValue: @"No"];
3635 if (fTitle->job->pixel_ratio > 0)
3637 [fPicSettingPAR setStringValue: @""];
3641 [fPicSettingPAR setStringValue: @"Off"];
3644 /* Set the display field for crop as per boolean */
3645 if (![fPictureController autoCrop])
3647 [fPicSettingAutoCrop setStringValue: @"Custom"];
3651 [fPicSettingAutoCrop setStringValue: @"Auto"];
3659 #pragma mark - Audio and Subtitles
3660 - (IBAction) audioCodecsPopUpChanged: (id) sender
3663 NSPopUpButton * audiotrackPopUp;
3664 NSPopUpButton * sampleratePopUp;
3665 NSPopUpButton * bitratePopUp;
3666 NSPopUpButton * audiocodecPopUp;
3667 if (sender == fAudTrack1CodecPopUp)
3669 audiotrackPopUp = fAudLang1PopUp;
3670 audiocodecPopUp = fAudTrack1CodecPopUp;
3671 sampleratePopUp = fAudTrack1RatePopUp;
3672 bitratePopUp = fAudTrack1BitratePopUp;
3674 else if (sender == fAudTrack2CodecPopUp)
3676 audiotrackPopUp = fAudLang2PopUp;
3677 audiocodecPopUp = fAudTrack2CodecPopUp;
3678 sampleratePopUp = fAudTrack2RatePopUp;
3679 bitratePopUp = fAudTrack2BitratePopUp;
3681 else if (sender == fAudTrack3CodecPopUp)
3683 audiotrackPopUp = fAudLang3PopUp;
3684 audiocodecPopUp = fAudTrack3CodecPopUp;
3685 sampleratePopUp = fAudTrack3RatePopUp;
3686 bitratePopUp = fAudTrack3BitratePopUp;
3690 audiotrackPopUp = fAudLang4PopUp;
3691 audiocodecPopUp = fAudTrack4CodecPopUp;
3692 sampleratePopUp = fAudTrack4RatePopUp;
3693 bitratePopUp = fAudTrack4BitratePopUp;
3696 /* changing the codecs on offer may mean that we can / can't offer mono or 6ch, */
3697 /* so call audioTrackPopUpChanged for both audio tracks to update the mixdown popups */
3698 [self audioTrackPopUpChanged: audiotrackPopUp];
3702 - (IBAction) setEnabledStateOfAudioMixdownControls: (id) sender
3704 /* We will be setting the enabled/disabled state of each tracks audio controls based on
3705 * the settings of the source audio for that track. We leave the samplerate and bitrate
3706 * to audiotrackMixdownChanged
3709 /* We will first verify that a lower track number has been selected before enabling each track
3710 * for example, make sure a track is selected for track 1 before enabling track 2, etc.
3712 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3714 [fAudLang2PopUp setEnabled: NO];
3715 [fAudLang2PopUp selectItemAtIndex: 0];
3719 [fAudLang2PopUp setEnabled: YES];
3722 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3724 [fAudLang3PopUp setEnabled: NO];
3725 [fAudLang3PopUp selectItemAtIndex: 0];
3729 [fAudLang3PopUp setEnabled: YES];
3731 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3733 [fAudLang4PopUp setEnabled: NO];
3734 [fAudLang4PopUp selectItemAtIndex: 0];
3738 [fAudLang4PopUp setEnabled: YES];
3740 /* enable/disable the mixdown text and popupbutton for audio track 1 */
3741 [fAudTrack1CodecPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3742 [fAudTrack1MixPopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3743 [fAudTrack1RatePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3744 [fAudTrack1BitratePopUp setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3745 [fAudTrack1DrcSlider setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3746 [fAudTrack1DrcField setEnabled: ([fAudLang1PopUp indexOfSelectedItem] == 0) ? NO : YES];
3747 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
3749 [fAudTrack1CodecPopUp removeAllItems];
3750 [fAudTrack1MixPopUp removeAllItems];
3751 [fAudTrack1RatePopUp removeAllItems];
3752 [fAudTrack1BitratePopUp removeAllItems];
3753 [fAudTrack1DrcSlider setFloatValue: 1.00];
3754 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
3756 else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3758 [fAudTrack1RatePopUp setEnabled: NO];
3759 [fAudTrack1BitratePopUp setEnabled: NO];
3760 [fAudTrack1DrcSlider setEnabled: NO];
3761 [fAudTrack1DrcField setEnabled: NO];
3764 /* enable/disable the mixdown text and popupbutton for audio track 2 */
3765 [fAudTrack2CodecPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3766 [fAudTrack2MixPopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3767 [fAudTrack2RatePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3768 [fAudTrack2BitratePopUp setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3769 [fAudTrack2DrcSlider setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3770 [fAudTrack2DrcField setEnabled: ([fAudLang2PopUp indexOfSelectedItem] == 0) ? NO : YES];
3771 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
3773 [fAudTrack2CodecPopUp removeAllItems];
3774 [fAudTrack2MixPopUp removeAllItems];
3775 [fAudTrack2RatePopUp removeAllItems];
3776 [fAudTrack2BitratePopUp removeAllItems];
3777 [fAudTrack2DrcSlider setFloatValue: 1.00];
3778 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
3780 else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3782 [fAudTrack2RatePopUp setEnabled: NO];
3783 [fAudTrack2BitratePopUp setEnabled: NO];
3784 [fAudTrack2DrcSlider setEnabled: NO];
3785 [fAudTrack2DrcField setEnabled: NO];
3788 /* enable/disable the mixdown text and popupbutton for audio track 3 */
3789 [fAudTrack3CodecPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3790 [fAudTrack3MixPopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3791 [fAudTrack3RatePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3792 [fAudTrack3BitratePopUp setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3793 [fAudTrack3DrcSlider setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3794 [fAudTrack3DrcField setEnabled: ([fAudLang3PopUp indexOfSelectedItem] == 0) ? NO : YES];
3795 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
3797 [fAudTrack3CodecPopUp removeAllItems];
3798 [fAudTrack3MixPopUp removeAllItems];
3799 [fAudTrack3RatePopUp removeAllItems];
3800 [fAudTrack3BitratePopUp removeAllItems];
3801 [fAudTrack3DrcSlider setFloatValue: 1.00];
3802 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
3804 else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3806 [fAudTrack3RatePopUp setEnabled: NO];
3807 [fAudTrack3BitratePopUp setEnabled: NO];
3808 [fAudTrack3DrcSlider setEnabled: NO];
3809 [fAudTrack3DrcField setEnabled: NO];
3812 /* enable/disable the mixdown text and popupbutton for audio track 4 */
3813 [fAudTrack4CodecPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3814 [fAudTrack4MixPopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3815 [fAudTrack4RatePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3816 [fAudTrack4BitratePopUp setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3817 [fAudTrack4DrcSlider setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3818 [fAudTrack4DrcField setEnabled: ([fAudLang4PopUp indexOfSelectedItem] == 0) ? NO : YES];
3819 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
3821 [fAudTrack4CodecPopUp removeAllItems];
3822 [fAudTrack4MixPopUp removeAllItems];
3823 [fAudTrack4RatePopUp removeAllItems];
3824 [fAudTrack4BitratePopUp removeAllItems];
3825 [fAudTrack4DrcSlider setFloatValue: 1.00];
3826 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
3828 else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3)
3830 [fAudTrack4RatePopUp setEnabled: NO];
3831 [fAudTrack4BitratePopUp setEnabled: NO];
3832 [fAudTrack4DrcSlider setEnabled: NO];
3833 [fAudTrack4DrcField setEnabled: NO];
3838 - (IBAction) addAllAudioTracksToPopUp: (id) sender
3841 hb_list_t * list = hb_get_titles( fHandle );
3842 hb_title_t * title = (hb_title_t*)
3843 hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
3845 hb_audio_config_t * audio;
3847 [sender removeAllItems];
3848 [sender addItemWithTitle: NSLocalizedString( @"None", @"" )];
3849 for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
3851 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, i );
3852 [[sender menu] addItemWithTitle:
3853 [NSString stringWithCString: audio->lang.description]
3854 action: NULL keyEquivalent: @""];
3856 [sender selectItemAtIndex: 0];
3860 - (IBAction) selectAudioTrackInPopUp: (id) sender searchPrefixString: (NSString *) searchPrefixString selectIndexIfNotFound: (int) selectIndexIfNotFound
3863 /* this method can be used to find a language, or a language-and-source-format combination, by passing in the appropriate string */
3864 /* e.g. to find the first French track, pass in an NSString * of "Francais" */
3865 /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
3866 /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
3868 if (searchPrefixString)
3871 for( int i = 0; i < [sender numberOfItems]; i++ )
3873 /* Try to find the desired search string */
3874 if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
3876 [sender selectItemAtIndex: i];
3880 /* couldn't find the string, so select the requested "search string not found" item */
3881 /* index of 0 means select the "none" item */
3882 /* index of 1 means select the first audio track */
3883 [sender selectItemAtIndex: selectIndexIfNotFound];
3887 /* if no search string is provided, then select the selectIndexIfNotFound item */
3888 [sender selectItemAtIndex: selectIndexIfNotFound];
3892 - (IBAction) audioAddAudioTrackCodecs: (id)sender
3894 int format = [fDstFormatPopUp indexOfSelectedItem];
3896 /* setup pointers to the appropriate popups for the correct track */
3897 NSPopUpButton * audiocodecPopUp;
3898 NSPopUpButton * audiotrackPopUp;
3899 if (sender == fAudTrack1CodecPopUp)
3901 audiotrackPopUp = fAudLang1PopUp;
3902 audiocodecPopUp = fAudTrack1CodecPopUp;
3904 else if (sender == fAudTrack2CodecPopUp)
3906 audiotrackPopUp = fAudLang2PopUp;
3907 audiocodecPopUp = fAudTrack2CodecPopUp;
3909 else if (sender == fAudTrack3CodecPopUp)
3911 audiotrackPopUp = fAudLang3PopUp;
3912 audiocodecPopUp = fAudTrack3CodecPopUp;
3916 audiotrackPopUp = fAudLang4PopUp;
3917 audiocodecPopUp = fAudTrack4CodecPopUp;
3920 [audiocodecPopUp removeAllItems];
3921 /* Make sure "None" isnt selected in the source track */
3922 if ([audiotrackPopUp indexOfSelectedItem] > 0)
3924 [audiocodecPopUp setEnabled:YES];
3925 NSMenuItem *menuItem;
3926 /* We setup our appropriate popups for codecs and put the int value in the popup tag for easy retrieval */
3932 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
3933 [menuItem setTag: HB_ACODEC_FAAC];
3936 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
3937 [menuItem setTag: HB_ACODEC_AC3];
3943 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
3944 [menuItem setTag: HB_ACODEC_FAAC];
3946 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
3947 [menuItem setTag: HB_ACODEC_AC3];
3949 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
3950 [menuItem setTag: HB_ACODEC_LAME];
3952 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
3953 [menuItem setTag: HB_ACODEC_VORBIS];
3959 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
3960 [menuItem setTag: HB_ACODEC_LAME];
3962 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
3963 [menuItem setTag: HB_ACODEC_AC3];
3969 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
3970 [menuItem setTag: HB_ACODEC_VORBIS];
3972 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
3973 [menuItem setTag: HB_ACODEC_LAME];
3976 [audiocodecPopUp selectItemAtIndex:0];
3980 [audiocodecPopUp setEnabled:NO];
3984 - (IBAction) audioTrackPopUpChanged: (id) sender
3986 /* utility function to call audioTrackPopUpChanged without passing in a mixdown-to-use */
3987 [self audioTrackPopUpChanged: sender mixdownToUse: 0];
3990 - (IBAction) audioTrackPopUpChanged: (id) sender mixdownToUse: (int) mixdownToUse
3993 /* make sure we have a selected title before continuing */
3994 if (fTitle == NULL) return;
3995 /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
3996 * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
3998 if (sender == fAudLang1PopUp && [[fAudTrack1CodecPopUp menu] numberOfItems] == 0)
4000 [self audioAddAudioTrackCodecs: fAudTrack1CodecPopUp];
4002 if (sender == fAudLang2PopUp && [[fAudTrack2CodecPopUp menu] numberOfItems] == 0)
4004 [self audioAddAudioTrackCodecs: fAudTrack2CodecPopUp];
4006 if (sender == fAudLang3PopUp && [[fAudTrack3CodecPopUp menu] numberOfItems] == 0)
4008 [self audioAddAudioTrackCodecs: fAudTrack3CodecPopUp];
4010 if (sender == fAudLang4PopUp && [[fAudTrack4CodecPopUp menu] numberOfItems] == 0)
4012 [self audioAddAudioTrackCodecs: fAudTrack4CodecPopUp];
4015 /* Now lets make the sender the appropriate Audio Track popup from this point on */
4016 if (sender == fAudTrack1CodecPopUp || sender == fAudTrack1MixPopUp)
4018 sender = fAudLang1PopUp;
4020 if (sender == fAudTrack2CodecPopUp || sender == fAudTrack2MixPopUp)
4022 sender = fAudLang2PopUp;
4024 if (sender == fAudTrack3CodecPopUp || sender == fAudTrack3MixPopUp)
4026 sender = fAudLang3PopUp;
4028 if (sender == fAudTrack4CodecPopUp || sender == fAudTrack4MixPopUp)
4030 sender = fAudLang4PopUp;
4033 /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
4034 NSPopUpButton * mixdownPopUp;
4035 NSPopUpButton * audiocodecPopUp;
4036 NSPopUpButton * sampleratePopUp;
4037 NSPopUpButton * bitratePopUp;
4038 if (sender == fAudLang1PopUp)
4040 mixdownPopUp = fAudTrack1MixPopUp;
4041 audiocodecPopUp = fAudTrack1CodecPopUp;
4042 sampleratePopUp = fAudTrack1RatePopUp;
4043 bitratePopUp = fAudTrack1BitratePopUp;
4045 else if (sender == fAudLang2PopUp)
4047 mixdownPopUp = fAudTrack2MixPopUp;
4048 audiocodecPopUp = fAudTrack2CodecPopUp;
4049 sampleratePopUp = fAudTrack2RatePopUp;
4050 bitratePopUp = fAudTrack2BitratePopUp;
4052 else if (sender == fAudLang3PopUp)
4054 mixdownPopUp = fAudTrack3MixPopUp;
4055 audiocodecPopUp = fAudTrack3CodecPopUp;
4056 sampleratePopUp = fAudTrack3RatePopUp;
4057 bitratePopUp = fAudTrack3BitratePopUp;
4061 mixdownPopUp = fAudTrack4MixPopUp;
4062 audiocodecPopUp = fAudTrack4CodecPopUp;
4063 sampleratePopUp = fAudTrack4RatePopUp;
4064 bitratePopUp = fAudTrack4BitratePopUp;
4067 /* get the index of the selected audio Track*/
4068 int thisAudioIndex = [sender indexOfSelectedItem] - 1;
4070 /* pointer for the hb_audio_s struct we will use later on */
4071 hb_audio_config_t * audio;
4074 /* check if the audio mixdown controls need their enabled state changing */
4075 [self setEnabledStateOfAudioMixdownControls:nil];
4077 if (thisAudioIndex != -1)
4081 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, thisAudioIndex );// Should "fTitle" be title and be setup ?
4083 /* actually manipulate the proper mixdowns here */
4084 /* delete the previous audio mixdown options */
4085 [mixdownPopUp removeAllItems];
4087 acodec = [[audiocodecPopUp selectedItem] tag];
4092 /* find out if our selected output audio codec supports mono and / or 6ch */
4093 /* we also check for an input codec of AC3 or DCA,
4094 as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
4095 /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
4096 but this may change in the future, so they are separated for flexibility */
4097 int audioCodecsSupportMono =
4098 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4099 (acodec != HB_ACODEC_LAME);
4100 int audioCodecsSupport6Ch =
4101 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4102 (acodec != HB_ACODEC_LAME);
4104 /* check for AC-3 passthru */
4105 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4108 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4109 [NSString stringWithCString: "AC3 Passthru"]
4110 action: NULL keyEquivalent: @""];
4111 [menuItem setTag: HB_ACODEC_AC3];
4116 /* add the appropriate audio mixdown menuitems to the popupbutton */
4117 /* in each case, we set the new menuitem's tag to be the amixdown value for that mixdown,
4118 so that we can reference the mixdown later */
4120 /* keep a track of the min and max mixdowns we used, so we can select the best match later */
4121 int minMixdownUsed = 0;
4122 int maxMixdownUsed = 0;
4124 /* get the input channel layout without any lfe channels */
4125 int layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4127 /* do we want to add a mono option? */
4128 if (audioCodecsSupportMono == 1)
4130 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4131 [NSString stringWithCString: hb_audio_mixdowns[0].human_readable_name]
4132 action: NULL keyEquivalent: @""];
4133 [menuItem setTag: hb_audio_mixdowns[0].amixdown];
4134 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[0].amixdown;
4135 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[0].amixdown);
4138 /* do we want to add a stereo option? */
4139 /* offer stereo if we have a mono source and non-mono-supporting codecs, as otherwise we won't have a mixdown at all */
4140 /* also offer stereo if we have a stereo-or-better source */
4141 if ((layout == HB_INPUT_CH_LAYOUT_MONO && audioCodecsSupportMono == 0) || layout >= HB_INPUT_CH_LAYOUT_STEREO)
4143 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4144 [NSString stringWithCString: hb_audio_mixdowns[1].human_readable_name]
4145 action: NULL keyEquivalent: @""];
4146 [menuItem setTag: hb_audio_mixdowns[1].amixdown];
4147 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[1].amixdown;
4148 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[1].amixdown);
4151 /* do we want to add a dolby surround (DPL1) option? */
4152 if (layout == HB_INPUT_CH_LAYOUT_3F1R || layout == HB_INPUT_CH_LAYOUT_3F2R || layout == HB_INPUT_CH_LAYOUT_DOLBY)
4154 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4155 [NSString stringWithCString: hb_audio_mixdowns[2].human_readable_name]
4156 action: NULL keyEquivalent: @""];
4157 [menuItem setTag: hb_audio_mixdowns[2].amixdown];
4158 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[2].amixdown;
4159 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[2].amixdown);
4162 /* do we want to add a dolby pro logic 2 (DPL2) option? */
4163 if (layout == HB_INPUT_CH_LAYOUT_3F2R)
4165 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4166 [NSString stringWithCString: hb_audio_mixdowns[3].human_readable_name]
4167 action: NULL keyEquivalent: @""];
4168 [menuItem setTag: hb_audio_mixdowns[3].amixdown];
4169 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[3].amixdown;
4170 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[3].amixdown);
4173 /* do we want to add a 6-channel discrete option? */
4174 if (audioCodecsSupport6Ch == 1 && layout == HB_INPUT_CH_LAYOUT_3F2R && (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE))
4176 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4177 [NSString stringWithCString: hb_audio_mixdowns[4].human_readable_name]
4178 action: NULL keyEquivalent: @""];
4179 [menuItem setTag: hb_audio_mixdowns[4].amixdown];
4180 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[4].amixdown;
4181 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[4].amixdown);
4184 /* do we want to add an AC-3 passthrough option? */
4185 if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
4187 NSMenuItem *menuItem = [[mixdownPopUp menu] addItemWithTitle:
4188 [NSString stringWithCString: hb_audio_mixdowns[5].human_readable_name]
4189 action: NULL keyEquivalent: @""];
4190 [menuItem setTag: HB_ACODEC_AC3];
4191 if (minMixdownUsed == 0) minMixdownUsed = hb_audio_mixdowns[5].amixdown;
4192 maxMixdownUsed = MAX(maxMixdownUsed, hb_audio_mixdowns[5].amixdown);
4195 /* auto-select the best mixdown based on our saved mixdown preference */
4197 /* for now, this is hard-coded to a "best" mixdown of HB_AMIXDOWN_DOLBYPLII */
4198 /* ultimately this should be a prefs option */
4201 /* if we passed in a mixdown to use - in order to load a preset - then try and use it */
4202 if (mixdownToUse > 0)
4204 useMixdown = mixdownToUse;
4208 useMixdown = HB_AMIXDOWN_DOLBYPLII;
4211 /* if useMixdown > maxMixdownUsed, then use maxMixdownUsed */
4212 if (useMixdown > maxMixdownUsed)
4214 useMixdown = maxMixdownUsed;
4217 /* if useMixdown < minMixdownUsed, then use minMixdownUsed */
4218 if (useMixdown < minMixdownUsed)
4220 useMixdown = minMixdownUsed;
4223 /* select the (possibly-amended) preferred mixdown */
4224 [mixdownPopUp selectItemWithTag: useMixdown];
4227 /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
4228 * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
4231 if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
4233 /* If we are using the avi container, we select MP3 as there is no aac available*/
4234 if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
4236 [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
4240 [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
4243 /* Setup our samplerate and bitrate popups we will need based on mixdown */
4244 [self audioTrackMixdownChanged: mixdownPopUp];
4248 if( [fDstFormatPopUp indexOfSelectedItem] == 0 )
4250 [self autoSetM4vExtension: sender];
4251 [self shouldEnableHttpMp4CheckBox: sender];
4255 - (IBAction) audioTrackMixdownChanged: (id) sender
4259 /* setup pointers to all of the other audio track controls
4260 * we will need later
4262 NSPopUpButton * mixdownPopUp;
4263 NSPopUpButton * sampleratePopUp;
4264 NSPopUpButton * bitratePopUp;
4265 NSPopUpButton * audiocodecPopUp;
4266 NSPopUpButton * audiotrackPopUp;
4267 NSSlider * drcSlider;
4268 NSTextField * drcField;
4269 if (sender == fAudTrack1MixPopUp)
4271 audiotrackPopUp = fAudLang1PopUp;
4272 audiocodecPopUp = fAudTrack1CodecPopUp;
4273 mixdownPopUp = fAudTrack1MixPopUp;
4274 sampleratePopUp = fAudTrack1RatePopUp;
4275 bitratePopUp = fAudTrack1BitratePopUp;
4276 drcSlider = fAudTrack1DrcSlider;
4277 drcField = fAudTrack1DrcField;
4279 else if (sender == fAudTrack2MixPopUp)
4281 audiotrackPopUp = fAudLang2PopUp;
4282 audiocodecPopUp = fAudTrack2CodecPopUp;
4283 mixdownPopUp = fAudTrack2MixPopUp;
4284 sampleratePopUp = fAudTrack2RatePopUp;
4285 bitratePopUp = fAudTrack2BitratePopUp;
4286 drcSlider = fAudTrack2DrcSlider;
4287 drcField = fAudTrack2DrcField;
4289 else if (sender == fAudTrack3MixPopUp)
4291 audiotrackPopUp = fAudLang3PopUp;
4292 audiocodecPopUp = fAudTrack3CodecPopUp;
4293 mixdownPopUp = fAudTrack3MixPopUp;
4294 sampleratePopUp = fAudTrack3RatePopUp;
4295 bitratePopUp = fAudTrack3BitratePopUp;
4296 drcSlider = fAudTrack3DrcSlider;
4297 drcField = fAudTrack3DrcField;
4301 audiotrackPopUp = fAudLang4PopUp;
4302 audiocodecPopUp = fAudTrack4CodecPopUp;
4303 mixdownPopUp = fAudTrack4MixPopUp;
4304 sampleratePopUp = fAudTrack4RatePopUp;
4305 bitratePopUp = fAudTrack4BitratePopUp;
4306 drcSlider = fAudTrack4DrcSlider;
4307 drcField = fAudTrack4DrcField;
4309 acodec = [[audiocodecPopUp selectedItem] tag];
4310 /* storage variable for the min and max bitrate allowed for this codec */
4316 case HB_ACODEC_FAAC:
4317 /* check if we have a 6ch discrete conversion in either audio track */
4318 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4320 /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
4322 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4328 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
4330 /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
4331 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
4336 case HB_ACODEC_LAME:
4337 /* Lame is happy using our min bitrate of 32 kbps */
4339 /* Lame won't encode if the bitrate is higher than 320 kbps */
4343 case HB_ACODEC_VORBIS:
4344 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4346 /* Vorbis causes a crash if we use a bitrate below 192 kbps with 6 channel */
4348 /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
4354 /* Vorbis causes a crash if we use a bitrate below 48 kbps */
4356 /* Vorbis can cope with 384 kbps quite happily, even for stereo */
4362 /* AC3 passthru disables the bitrate dropdown anyway, so we might as well just use the min and max bitrate */
4368 /* make sure we have a selected title before continuing */
4369 if (fTitle == NULL) return;
4370 /* get the audio so we can find out what input rates are*/
4371 hb_audio_config_t * audio;
4372 audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
4373 int inputbitrate = audio->in.bitrate / 1000;
4374 int inputsamplerate = audio->in.samplerate;
4376 if ([[mixdownPopUp selectedItem] tag] != HB_ACODEC_AC3)
4378 [bitratePopUp removeAllItems];
4380 for( int i = 0; i < hb_audio_bitrates_count; i++ )
4382 if (hb_audio_bitrates[i].rate >= minbitrate && hb_audio_bitrates[i].rate <= maxbitrate)
4384 /* add a new menuitem for this bitrate */
4385 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4386 [NSString stringWithCString: hb_audio_bitrates[i].string]
4387 action: NULL keyEquivalent: @""];
4388 /* set its tag to be the actual bitrate as an integer, so we can retrieve it later */
4389 [menuItem setTag: hb_audio_bitrates[i].rate];
4393 /* select the default bitrate (but use 384 for 6-ch AAC) */
4394 if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
4396 [bitratePopUp selectItemWithTag: 384];
4400 [bitratePopUp selectItemWithTag: hb_audio_bitrates[hb_audio_bitrates_default].rate];
4403 /* populate and set the sample rate popup */
4404 /* Audio samplerate */
4405 [sampleratePopUp removeAllItems];
4406 /* we create a same as source selection (Auto) so that we can choose to use the input sample rate */
4407 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle: @"Auto" action: NULL keyEquivalent: @""];
4408 [menuItem setTag: inputsamplerate];
4410 for( int i = 0; i < hb_audio_rates_count; i++ )
4412 NSMenuItem *menuItem = [[sampleratePopUp menu] addItemWithTitle:
4413 [NSString stringWithCString: hb_audio_rates[i].string]
4414 action: NULL keyEquivalent: @""];
4415 [menuItem setTag: hb_audio_rates[i].rate];
4417 /* We use the input sample rate as the default sample rate as downsampling just makes audio worse
4418 * and there is no compelling reason to use anything else as default, though the users default
4419 * preset will likely override any setting chosen here.
4421 [sampleratePopUp selectItemWithTag: inputsamplerate];
4424 /* Since AC3 Pass Thru uses the input ac3 bitrate and sample rate, we get the input tracks
4425 * bitrate and dispay it in the bitrate popup even though libhb happily ignores any bitrate input from
4426 * the gui. We do this for better user feedback in the audio tab as well as the queue for the most part
4428 if ([[mixdownPopUp selectedItem] tag] == HB_ACODEC_AC3)
4431 /* lets also set the bitrate popup to the input bitrate as thats what passthru will use */
4432 [bitratePopUp removeAllItems];
4433 NSMenuItem *menuItem = [[bitratePopUp menu] addItemWithTitle:
4434 [NSString stringWithFormat:@"%d", inputbitrate]
4435 action: NULL keyEquivalent: @""];
4436 [menuItem setTag: inputbitrate];
4437 /* For ac3 passthru we disable the sample rate and bitrate popups as well as the drc slider*/
4438 [bitratePopUp setEnabled: NO];
4439 [sampleratePopUp setEnabled: NO];
4441 [drcSlider setFloatValue: 1.00];
4442 [self audioDRCSliderChanged: drcSlider];
4443 [drcSlider setEnabled: NO];
4444 [drcField setEnabled: NO];
4448 [sampleratePopUp setEnabled: YES];
4449 [bitratePopUp setEnabled: YES];
4450 [drcSlider setEnabled: YES];
4451 [drcField setEnabled: YES];
4456 - (IBAction) audioDRCSliderChanged: (id) sender
4458 NSSlider * drcSlider;
4459 NSTextField * drcField;
4460 if (sender == fAudTrack1DrcSlider)
4462 drcSlider = fAudTrack1DrcSlider;
4463 drcField = fAudTrack1DrcField;
4465 else if (sender == fAudTrack2DrcSlider)
4467 drcSlider = fAudTrack2DrcSlider;
4468 drcField = fAudTrack2DrcField;
4470 else if (sender == fAudTrack3DrcSlider)
4472 drcSlider = fAudTrack3DrcSlider;
4473 drcField = fAudTrack3DrcField;
4477 drcSlider = fAudTrack4DrcSlider;
4478 drcField = fAudTrack4DrcField;
4480 [drcField setStringValue: [NSString stringWithFormat: @"%.2f", [drcSlider floatValue]]];
4481 /* For now, do not call this until we have an intelligent way to determine audio track selections
4482 * compared to presets
4484 //[self customSettingUsed: sender];
4487 - (IBAction) subtitleSelectionChanged: (id) sender
4489 if ([fSubPopUp indexOfSelectedItem] == 0)
4491 [fSubForcedCheck setState: NSOffState];
4492 [fSubForcedCheck setEnabled: NO];
4496 [fSubForcedCheck setEnabled: YES];
4505 #pragma mark Open New Windows
4507 - (IBAction) openHomepage: (id) sender
4509 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4510 URLWithString:@"http://handbrake.fr/"]];
4513 - (IBAction) openForums: (id) sender
4515 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4516 URLWithString:@"http://handbrake.fr/forum/"]];
4518 - (IBAction) openUserGuide: (id) sender
4520 [[NSWorkspace sharedWorkspace] openURL: [NSURL
4521 URLWithString:@"http://handbrake.fr/trac/wiki/HandBrakeGuide"]];
4525 * Shows debug output window.
4527 - (IBAction)showDebugOutputPanel:(id)sender
4529 [outputPanel showOutputPanel:sender];
4533 * Shows preferences window.
4535 - (IBAction) showPreferencesWindow: (id) sender
4537 NSWindow * window = [fPreferencesController window];
4538 if (![window isVisible])
4541 [window makeKeyAndOrderFront: nil];
4545 * Shows queue window.
4547 - (IBAction) showQueueWindow:(id)sender
4549 [fQueueController showQueueWindow:sender];
4553 - (IBAction) toggleDrawer:(id)sender {
4554 [fPresetDrawer toggle:self];
4558 * Shows Picture Settings Window.
4561 - (IBAction) showPicturePanel: (id) sender
4563 hb_list_t * list = hb_get_titles( fHandle );
4564 hb_title_t * title = (hb_title_t *) hb_list_item( list,
4565 [fSrcTitlePopUp indexOfSelectedItem] );
4566 [fPictureController showPanelInWindow:fWindow forTitle:title];
4570 #pragma mark Preset Outline View Methods
4571 #pragma mark - Required
4572 /* These are required by the NSOutlineView Datasource Delegate */
4573 /* We use this to deterimine children of an item */
4574 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
4577 return [UserPresets objectAtIndex:index];
4579 // We are only one level deep, so we can't be asked about children
4580 NSAssert (NO, @"Presets View outlineView:child:ofItem: currently can't handle nested items.");
4583 /* We use this to determine if an item should be expandable */
4584 - (BOOL)outlineView:(NSOutlineView *)fPresetsOutlineView isItemExpandable:(id)item
4587 /* For now, we maintain one level, so set to no
4588 * when nested, we set to yes for any preset "folders"
4593 /* used to specify the number of levels to show for each item */
4594 - (int)outlineView:(NSOutlineView *)fPresetsOutlineView numberOfChildrenOfItem:(id)item
4596 /* currently use no levels to test outline view viability */
4598 return [UserPresets count];
4602 /* Used to tell the outline view which information is to be displayed per item */
4603 - (id)outlineView:(NSOutlineView *)fPresetsOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4605 /* We have two columns right now, icon and PresetName */
4607 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4609 return [item objectForKey:@"PresetName"];
4613 return @"something";
4617 #pragma mark - Added Functionality (optional)
4618 /* Use to customize the font and display characteristics of the title cell */
4619 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
4621 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4623 NSDictionary *userPresetDict = item;
4626 NSColor *shadowColor;
4627 txtFont = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
4628 /*check to see if its a selected row */
4629 if ([fPresetsOutlineView selectedRow] == [fPresetsOutlineView rowForItem:item])
4632 fontColor = [NSColor blackColor];
4633 shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
4637 if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
4639 fontColor = [NSColor blueColor];
4641 else // User created preset, use a black font
4643 fontColor = [NSColor blackColor];
4647 /* We use Bold Text for the HB Default */
4648 if ([[userPresetDict objectForKey:@"Default"] intValue] == 1)// 1 is HB default
4650 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4652 /* We use Bold Text for the User Specified Default */
4653 if ([[userPresetDict objectForKey:@"Default"] intValue] == 2)// 2 is User default
4655 txtFont = [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]];
4659 [cell setTextColor:fontColor];
4660 [cell setFont:txtFont];
4665 /* We use this to edit the name field in the outline view */
4666 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
4668 if ([[tableColumn identifier] isEqualToString:@"PresetName"])
4673 [theRecord setObject:object forKey:@"PresetName"];
4677 [fPresetsOutlineView reloadData];
4678 /* We save all of the preset data here */
4682 /* We use this to provide tooltips for the items in the presets outline view */
4683 - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation
4685 //if ([[tc identifier] isEqualToString:@"PresetName"])
4687 /* initialize the tooltip contents variable */
4689 /* if there is a description for the preset, we show it in the tooltip */
4690 if ([item objectForKey:@"PresetDescription"])
4692 loc_tip = [item objectForKey:@"PresetDescription"];
4697 loc_tip = @"No description available";
4704 #pragma mark Preset Outline View Methods (dragging related)
4707 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
4709 // Dragging is only allowed for custom presets.
4710 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Type"] intValue] == 0) // 0 is built in preset
4714 // Don't retain since this is just holding temporaral drag information, and it is
4715 //only used during a drag! We could put this in the pboard actually.
4716 fDraggedNodes = items;
4717 // Provide data for our custom type, and simple NSStrings.
4718 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
4720 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
4721 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
4726 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
4728 // Don't allow dropping ONTO an item since they can't really contain any children.
4730 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
4731 if (isOnDropTypeProposal)
4732 return NSDragOperationNone;
4735 // Don't allow dropping INTO an item since they can't really contain any children as of yet.
4739 index = [fPresetsOutlineView rowForItem: item] + 1;
4743 // Don't allow dropping into the Built In Presets.
4744 if (index < presetCurrentBuiltInCount)
4746 return NSDragOperationNone;
4747 index = MAX (index, presetCurrentBuiltInCount);
4750 [outlineView setDropItem:item dropChildIndex:index];
4751 return NSDragOperationGeneric;
4756 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
4758 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
4761 NSEnumerator *enumerator = [fDraggedNodes objectEnumerator];
4762 while (obj = [enumerator nextObject])
4764 [moveItems addIndex:[UserPresets indexOfObject:obj]];
4766 // Successful drop, lets rearrange the view and save it all
4767 [self moveObjectsInPresetsArray:UserPresets fromIndexes:moveItems toIndex: index];
4768 [fPresetsOutlineView reloadData];
4773 - (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
4775 unsigned index = [indexSet lastIndex];
4776 unsigned aboveInsertIndexCount = 0;
4778 while (index != NSNotFound)
4780 unsigned removeIndex;
4782 if (index >= insertIndex)
4784 removeIndex = index + aboveInsertIndexCount;
4785 aboveInsertIndexCount++;
4789 removeIndex = index;
4793 id object = [[array objectAtIndex:removeIndex] retain];
4794 [array removeObjectAtIndex:removeIndex];
4795 [array insertObject:object atIndex:insertIndex];
4798 index = [indexSet indexLessThanIndex:index];
4804 #pragma mark - Functional Preset NSOutlineView Methods
4806 - (IBAction)selectPreset:(id)sender
4809 if ([fPresetsOutlineView selectedRow] >= 0)
4811 chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]];
4812 /* we set the preset display field in main window here */
4813 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4814 if ([[chosenPreset objectForKey:@"Default"] intValue] == 1)
4816 [fPresetSelectedDisplay setStringValue:[NSString stringWithFormat:@"%@ (Default)", [chosenPreset objectForKey:@"PresetName"]]];
4820 [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]];
4823 [fDstFormatPopUp selectItemWithTitle:[chosenPreset objectForKey:@"FileFormat"]];
4824 [self formatPopUpChanged:nil];
4826 /* Chapter Markers*/
4827 [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
4828 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
4829 [fDstMp4LargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
4830 /* Mux mp4 with http optimization */
4831 [fDstMp4HttpOptFileCheck setState:[[chosenPreset objectForKey:@"Mp4HttpOptimize"] intValue]];
4834 /* We set the advanced opt string here if applicable*/
4835 [fAdvancedOptions setOptions:[chosenPreset objectForKey:@"x264Option"]];
4836 /* We use a conditional to account for the new x264 encoder dropdown as well as presets made using legacy x264 settings*/
4837 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 Main)"] ||
4838 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"] ||
4839 [[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264"])
4841 [fVidEncoderPopUp selectItemWithTitle:@"H.264 (x264)"];
4842 /* special case for legacy preset to check the new fDstMp4HttpOptFileCheck checkbox to set the ipod atom */
4843 if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"x264 (h.264 iPod)"])
4845 [fDstMp4iPodFileCheck setState:NSOnState];
4846 /* We also need to add "level=30:" to the advanced opts string to set the correct level for the iPod when
4847 encountering a legacy preset as it used to be handled separately from the opt string*/
4848 [fAdvancedOptions setOptions:[@"level=30:" stringByAppendingString:[fAdvancedOptions optionsString]]];
4852 [fDstMp4iPodFileCheck setState:NSOffState];
4855 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"FFmpeg"])
4857 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (FFmpeg)"];
4859 else if ([[chosenPreset objectForKey:@"VideoEncoder"] isEqualToString:@"XviD"])
4861 [fVidEncoderPopUp selectItemWithTitle:@"MPEG-4 (XviD)"];
4865 [fVidEncoderPopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoEncoder"]];
4868 /* Lets run through the following functions to get variables set there */
4869 [self videoEncoderPopUpChanged:nil];
4870 /* Set the state of ipod compatible with Mp4iPodCompatible. Only for x264*/
4871 [fDstMp4iPodFileCheck setState:[[chosenPreset objectForKey:@"Mp4iPodCompatible"] intValue]];
4872 [self calculateBitrate:nil];
4875 [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
4877 [fVidTargetSizeField setStringValue:[chosenPreset objectForKey:@"VideoTargetSize"]];
4878 [fVidBitrateField setStringValue:[chosenPreset objectForKey:@"VideoAvgBitrate"]];
4879 [fVidQualitySlider setFloatValue:[[chosenPreset objectForKey:@"VideoQualitySlider"] floatValue]];
4881 [self videoMatrixChanged:nil];
4883 /* Video framerate */
4884 /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
4885 detected framerate in the fVidRatePopUp so we use index 0*/
4886 if ([[chosenPreset objectForKey:@"VideoFramerate"] isEqualToString:@"Same as source"])
4888 [fVidRatePopUp selectItemAtIndex: 0];
4892 [fVidRatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"VideoFramerate"]];
4896 [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
4898 /* 2 Pass Encoding */
4899 [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
4900 [self twoPassCheckboxChanged:nil];
4901 /* Turbo 1st pass for 2 Pass Encoding */
4902 [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
4905 if ([chosenPreset objectForKey:@"FileCodecs"])
4907 /* We need to handle the audio codec popup by determining what was chosen from the deprecated Codecs PopUp for past presets*/
4908 if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString: @"AVC/H.264 Video / AAC + AC3 Audio"])
4910 /* We need to address setting languages etc. here in the new multi track audio panel */
4911 /* Track One set here */
4912 /*for track one though a track should be selected but lets check here anyway and use track one if its not.*/
4913 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
4915 [fAudLang1PopUp selectItemAtIndex: 1];
4916 [self audioTrackPopUpChanged: fAudLang1PopUp];
4918 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
4919 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
4920 /* Track Two, set source same as track one */
4921 [fAudLang2PopUp selectItemAtIndex: [fAudLang1PopUp indexOfSelectedItem]];
4922 [self audioTrackPopUpChanged: fAudLang2PopUp];
4923 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
4924 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
4926 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AAC Audio"] ||
4927 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC Audio"])
4929 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4931 [fAudTrack1CodecPopUp selectItemWithTitle: @"AAC (faac)"];
4932 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
4934 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4936 [fAudTrack2CodecPopUp selectItemWithTitle: @"AAC (faac)"];
4937 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
4939 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4941 [fAudTrack3CodecPopUp selectItemWithTitle: @"AAC (faac)"];
4942 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
4944 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4946 [fAudTrack4CodecPopUp selectItemWithTitle: @"AAC (faac)"];
4947 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
4950 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / AC-3 Audio"] ||
4951 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AC-3 Audio"])
4953 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4955 [fAudTrack1CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
4956 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
4958 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4960 [fAudTrack2CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
4961 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
4963 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4965 [fAudTrack3CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
4966 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
4968 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4970 [fAudTrack4CodecPopUp selectItemWithTitle: @"AC3 Passthru"];
4971 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
4974 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / MP3 Audio"] ||
4975 [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / MP3 Audio"])
4977 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
4979 [fAudTrack1CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
4980 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
4982 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
4984 [fAudTrack2CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
4985 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
4987 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
4989 [fAudTrack3CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
4990 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
4992 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
4994 [fAudTrack4CodecPopUp selectItemWithTitle: @"MP3 (lame)"];
4995 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
4998 else if ([[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"MPEG-4 Video / Vorbis Audio"])
5000 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5002 [fAudTrack1CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5003 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5005 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5007 [fAudTrack2CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5008 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5010 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5012 [fAudTrack3CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5013 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5015 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5017 [fAudTrack4CodecPopUp selectItemWithTitle: @"Vorbis (vorbis)"];
5018 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5021 /* 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
5022 * UNLESS the CodecPopUp is AC3 in which case the preset values are ignored in favor of rates set in audioTrackMixdownChanged*/
5023 if ([chosenPreset objectForKey:@"AudioSampleRate"])
5025 if ([fAudLang1PopUp indexOfSelectedItem] > 0 && [fAudTrack1CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5027 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5028 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5030 if ([fAudLang2PopUp indexOfSelectedItem] > 0 && [fAudTrack2CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5032 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5033 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5035 if ([fAudLang3PopUp indexOfSelectedItem] > 0 && [fAudTrack3CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5037 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5038 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5040 if ([fAudLang4PopUp indexOfSelectedItem] > 0 && [fAudTrack4CodecPopUp titleOfSelectedItem] != @"AC3 Passthru")
5042 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioSampleRate"]];
5043 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"AudioBitRate"]];
5046 /* We detect here if we have the old DRC Slider and if so we apply it to the existing four tracks if chosen */
5047 if ([chosenPreset objectForKey:@"AudioDRCSlider"])
5049 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5051 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5052 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5054 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5056 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5057 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5059 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5061 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5062 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5064 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5066 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"AudioDRCSlider"] floatValue]];
5067 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5071 else // since there was no codecs key in the preset we know we can use new multi-audio track presets
5073 if ([chosenPreset objectForKey:@"Audio1Track"] > 0)
5075 if ([fAudLang1PopUp indexOfSelectedItem] == 0)
5077 [fAudLang1PopUp selectItemAtIndex: 1];
5079 [self audioTrackPopUpChanged: fAudLang1PopUp];
5080 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
5081 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5082 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
5083 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5085 if ([fAudTrack1MixPopUp selectedItem] == nil)
5087 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
5089 [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
5090 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5091 if (![[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
5093 [fAudTrack1BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Bitrate"]];
5095 [fAudTrack1DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
5096 [self audioDRCSliderChanged: fAudTrack1DrcSlider];
5098 if ([chosenPreset objectForKey:@"Audio2Track"] > 0)
5100 if ([fAudLang2PopUp indexOfSelectedItem] == 0)
5102 [fAudLang2PopUp selectItemAtIndex: 1];
5104 [self audioTrackPopUpChanged: fAudLang2PopUp];
5105 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
5106 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5107 [fAudTrack2MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Mixdown"]];
5108 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5110 if ([fAudTrack2MixPopUp selectedItem] == nil)
5112 [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
5114 [fAudTrack2RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Samplerate"]];
5115 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5116 if (![[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
5118 [fAudTrack2BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Bitrate"]];
5120 [fAudTrack2DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
5121 [self audioDRCSliderChanged: fAudTrack2DrcSlider];
5123 if ([chosenPreset objectForKey:@"Audio3Track"] > 0)
5125 if ([fAudLang3PopUp indexOfSelectedItem] == 0)
5127 [fAudLang3PopUp selectItemAtIndex: 1];
5129 [self audioTrackPopUpChanged: fAudLang3PopUp];
5130 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
5131 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5132 [fAudTrack3MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Mixdown"]];
5133 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5135 if ([fAudTrack3MixPopUp selectedItem] == nil)
5137 [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
5139 [fAudTrack3RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Samplerate"]];
5140 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5141 if (![[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
5143 [fAudTrack3BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Bitrate"]];
5145 [fAudTrack3DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
5146 [self audioDRCSliderChanged: fAudTrack3DrcSlider];
5148 if ([chosenPreset objectForKey:@"Audio4Track"] > 0)
5150 if ([fAudLang4PopUp indexOfSelectedItem] == 0)
5152 [fAudLang4PopUp selectItemAtIndex: 1];
5154 [self audioTrackPopUpChanged: fAudLang4PopUp];
5155 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
5156 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5157 [fAudTrack4MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Mixdown"]];
5158 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
5160 if ([fAudTrack4MixPopUp selectedItem] == nil)
5162 [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
5164 [fAudTrack4RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Samplerate"]];
5165 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
5166 if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
5168 [fAudTrack4BitratePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Bitrate"]];
5170 [fAudTrack4DrcSlider setFloatValue:[[chosenPreset objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
5171 [self audioDRCSliderChanged: fAudTrack4DrcSlider];
5177 /* 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
5178 * duplicate any code for legacy presets.*/
5179 /* First we handle the legacy Codecs crazy AVC/H.264 Video / AAC + AC3 Audio atv hybrid */
5180 if ([chosenPreset objectForKey:@"FileCodecs"] && [[chosenPreset objectForKey:@"FileCodecs"] isEqualToString:@"AVC/H.264 Video / AAC + AC3 Audio"])
5182 [fAudLang3PopUp selectItemAtIndex: 0];
5183 [self audioTrackPopUpChanged: fAudLang3PopUp];
5184 [fAudLang4PopUp selectItemAtIndex: 0];
5185 [self audioTrackPopUpChanged: fAudLang4PopUp];
5189 if (![chosenPreset objectForKey:@"Audio2Track"] || [chosenPreset objectForKey:@"Audio2Track"] == 0)
5191 [fAudLang2PopUp selectItemAtIndex: 0];
5192 [self audioTrackPopUpChanged: fAudLang2PopUp];
5194 if (![chosenPreset objectForKey:@"Audio3Track"] || [chosenPreset objectForKey:@"Audio3Track"] > 0)
5196 [fAudLang3PopUp selectItemAtIndex: 0];
5197 [self audioTrackPopUpChanged: fAudLang3PopUp];
5199 if (![chosenPreset objectForKey:@"Audio4Track"] || [chosenPreset objectForKey:@"Audio4Track"] > 0)
5201 [fAudLang4PopUp selectItemAtIndex: 0];
5202 [self audioTrackPopUpChanged: fAudLang4PopUp];
5207 [fSubPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Subtitles"]];
5208 /* Forced Subtitles */
5209 [fSubForcedCheck setState:[[chosenPreset objectForKey:@"SubtitlesForced"] intValue]];
5211 /* Picture Settings */
5212 /* Note: objectForKey:@"UsesPictureSettings" now refers to picture size, this encompasses:
5213 * height, width, keep ar, anamorphic and crop settings.
5214 * picture filters are now handled separately.
5215 * We will be able to actually change the key names for legacy preset keys when preset file
5216 * update code is done. But for now, lets hang onto the old legacy key name for backwards compatibility.
5218 /* Check to see if the objectForKey:@"UsesPictureSettings is greater than 0, as 0 means use picture sizing "None"
5219 * and the preset completely ignores any picture sizing values in the preset.
5221 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
5223 hb_job_t * job = fTitle->job;
5224 /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
5225 if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
5227 /* Use Max Picture settings for whatever the dvd is.*/
5228 [self revertPictureSizeToMax:nil];
5229 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5230 if (job->keep_ratio == 1)
5232 hb_fix_aspect( job, HB_KEEP_WIDTH );
5233 if( job->height > fTitle->height )
5235 job->height = fTitle->height;
5236 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5239 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5241 else // /* If not 0 or 2 we assume objectForKey:@"UsesPictureSettings is 1 which is "Use picture sizing from when the preset was set" */
5243 /* we check to make sure the presets width/height does not exceed the sources width/height */
5244 if (fTitle->width < [[chosenPreset objectForKey:@"PictureWidth"] intValue] || fTitle->height < [[chosenPreset objectForKey:@"PictureHeight"] intValue])
5246 /* if so, then we use the sources height and width to avoid scaling up */
5247 job->width = fTitle->width;
5248 job->height = fTitle->height;
5250 else // source width/height is >= the preset height/width
5252 /* we can go ahead and use the presets values for height and width */
5253 job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
5254 job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
5256 job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
5257 if (job->keep_ratio == 1)
5259 hb_fix_aspect( job, HB_KEEP_WIDTH );
5260 if( job->height > fTitle->height )
5262 job->height = fTitle->height;
5263 hb_fix_aspect( job, HB_KEEP_HEIGHT );
5266 job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
5269 /* If Cropping is set to custom, then recall all four crop values from
5270 when the preset was created and apply them */
5271 if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 0)
5273 [fPictureController setAutoCrop:NO];
5275 /* Here we use the custom crop values saved at the time the preset was saved */
5276 job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
5277 job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
5278 job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
5279 job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
5282 else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
5284 [fPictureController setAutoCrop:YES];
5285 /* Here we use the auto crop values determined right after scan */
5286 job->crop[0] = AutoCropTop;
5287 job->crop[1] = AutoCropBottom;
5288 job->crop[2] = AutoCropLeft;
5289 job->crop[3] = AutoCropRight;
5292 /* If the preset has no objectForKey:@"UsesPictureFilters", then we know it is a legacy preset
5293 * and handle the filters here as before.
5294 * NOTE: This should be removed when the update presets code is done as we can be assured that legacy
5295 * presets are updated to work properly with new keys.
5297 if (![chosenPreset objectForKey:@"UsesPictureFilters"])
5301 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5303 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5304 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5305 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5307 [fPictureController setDeinterlace:3];
5312 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5317 [fPictureController setDeinterlace:0];
5320 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5322 [fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5326 [fPictureController setVFR:0];
5329 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5331 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5335 [fPictureController setDetelecine:0];
5338 if ([chosenPreset objectForKey:@"PictureDenoise"])
5340 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5344 [fPictureController setDenoise:0];
5347 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5349 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
5353 [fPictureController setDeblock:0];
5356 [self calculatePictureSizing:nil];
5363 /* If the preset has an objectForKey:@"UsesPictureFilters", then we know it is a newer style filters preset
5364 * and handle the filters here depending on whether or not the preset specifies applying the filter.
5366 if ([chosenPreset objectForKey:@"UsesPictureFilters"] && [[chosenPreset objectForKey:@"UsesPictureFilters"] intValue] > 0)
5370 if ([chosenPreset objectForKey:@"PictureDeinterlace"])
5372 /* We check to see if the preset used the past fourth "Slowest" deinterlaceing and set that to "Slower
5373 * since we no longer have a fourth "Slowest" deinterlacing due to the mcdeint bug */
5374 if ([[chosenPreset objectForKey:@"PictureDeinterlace"] intValue] == 4)
5376 [fPictureController setDeinterlace:3];
5380 [fPictureController setDeinterlace:[[chosenPreset objectForKey:@"PictureDeinterlace"] intValue]];
5385 [fPictureController setDeinterlace:0];
5388 if ([[chosenPreset objectForKey:@"VFR"] intValue] == 1)
5390 [fPictureController setVFR:[[chosenPreset objectForKey:@"VFR"] intValue]];
5394 [fPictureController setVFR:0];
5397 if ([[chosenPreset objectForKey:@"PictureDetelecine"] intValue] == 1)
5399 [fPictureController setDetelecine:[[chosenPreset objectForKey:@"PictureDetelecine"] intValue]];
5403 [fPictureController setDetelecine:0];
5406 if ([chosenPreset objectForKey:@"PictureDenoise"])
5408 [fPictureController setDenoise:[[chosenPreset objectForKey:@"PictureDenoise"] intValue]];
5412 [fPictureController setDenoise:0];
5415 if ([[chosenPreset objectForKey:@"PictureDeblock"] intValue] == 1)
5417 [fPictureController setDeblock:[[chosenPreset objectForKey:@"PictureDeblock"] intValue]];
5421 [fPictureController setDeblock:0];
5424 /* Even though we currently allow for a custom setting for decomb, ultimately it will only have Off and
5425 * Default so we just pay attention to anything greater than 0 as 1 (Default). 0 is Off. */
5426 if ([[chosenPreset objectForKey:@"PictureDecomb"] intValue] > 0)
5428 [fPictureController setDecomb:1];
5432 [fPictureController setDecomb:0];
5435 [self calculatePictureSizing:nil];
5441 #pragma mark Manage Presets
5443 - (void) loadPresets {
5444 /* We declare the default NSFileManager into fileManager */
5445 NSFileManager * fileManager = [NSFileManager defaultManager];
5446 /*We define the location of the user presets file */
5447 UserPresetsFile = @"~/Library/Application Support/HandBrake/UserPresets.plist";
5448 UserPresetsFile = [[UserPresetsFile stringByExpandingTildeInPath]retain];
5449 /* We check for the presets.plist */
5450 if ([fileManager fileExistsAtPath:UserPresetsFile] == 0)
5452 [fileManager createFileAtPath:UserPresetsFile contents:nil attributes:nil];
5455 UserPresets = [[NSMutableArray alloc] initWithContentsOfFile:UserPresetsFile];
5456 if (nil == UserPresets)
5458 UserPresets = [[NSMutableArray alloc] init];
5459 [self addFactoryPresets:nil];
5461 [fPresetsOutlineView reloadData];
5465 - (IBAction) showAddPresetPanel: (id) sender
5467 /* Deselect the currently selected Preset if there is one*/
5468 [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
5470 /* Populate the preset picture settings popup here */
5471 [fPresetNewPicSettingsPopUp removeAllItems];
5472 [fPresetNewPicSettingsPopUp addItemWithTitle:@"None"];
5473 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Current"];
5474 [fPresetNewPicSettingsPopUp addItemWithTitle:@"Source Maximum (post source scan)"];
5475 [fPresetNewPicSettingsPopUp selectItemAtIndex: 0];
5476 /* Uncheck the preset use filters checkbox */
5477 [fPresetNewPicFiltersCheck setState:NSOffState];
5478 /* Erase info from the input fields*/
5479 [fPresetNewName setStringValue: @""];
5480 [fPresetNewDesc setStringValue: @""];
5481 /* Show the panel */
5482 [NSApp beginSheet:fAddPresetPanel modalForWindow:fWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
5485 - (IBAction) closeAddPresetPanel: (id) sender
5487 [NSApp endSheet: fAddPresetPanel];
5488 [fAddPresetPanel orderOut: self];
5491 - (IBAction)addUserPreset:(id)sender
5493 if (![[fPresetNewName stringValue] length])
5494 NSRunAlertPanel(@"Warning!", @"You need to insert a name for the preset.", @"OK", nil , nil);
5497 /* Here we create a custom user preset */
5498 [UserPresets addObject:[self createPreset]];
5501 [self closeAddPresetPanel:nil];
5508 /* We Reload the New Table data for presets */
5509 [fPresetsOutlineView reloadData];
5510 /* We save all of the preset data here */
5518 /* We Sort the Presets By Factory or Custom */
5519 NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
5520 ascending:YES] autorelease];
5521 /* We Sort the Presets Alphabetically by name We do not use this now as we have drag and drop*/
5523 NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
5524 ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
5525 //NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
5528 /* Since we can drag and drop our custom presets, lets just sort by type and not name */
5529 NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,nil];
5530 NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
5531 [UserPresets setArray:sortedArray];
5536 - (IBAction)insertPreset:(id)sender
5538 int index = [fPresetsOutlineView selectedRow];
5539 [UserPresets insertObject:[self createPreset] atIndex:index];
5540 [fPresetsOutlineView reloadData];
5544 - (NSDictionary *)createPreset
5546 NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
5547 /* Get the New Preset Name from the field in the AddPresetPanel */
5548 [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
5549 /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
5550 [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
5551 /*Set whether or not this is default, at creation set to 0*/
5552 [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5553 /*Get the whether or not to apply pic Size and Cropping (includes Anamorphic)*/
5554 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsPopUp indexOfSelectedItem]] forKey:@"UsesPictureSettings"];
5555 /* Get whether or not to use the current Picture Filter settings for the preset */
5556 [preset setObject:[NSNumber numberWithInt:[fPresetNewPicFiltersCheck state]] forKey:@"UsesPictureFilters"];
5558 /* Get New Preset Description from the field in the AddPresetPanel*/
5559 [preset setObject:[fPresetNewDesc stringValue] forKey:@"PresetDescription"];
5561 [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
5562 /* Chapter Markers fCreateChapterMarkers*/
5563 [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
5564 /* Allow Mpeg4 64 bit formatting +4GB file sizes */
5565 [preset setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"];
5566 /* Mux mp4 with http optimization */
5567 [preset setObject:[NSNumber numberWithInt:[fDstMp4HttpOptFileCheck state]] forKey:@"Mp4HttpOptimize"];
5568 /* Add iPod uuid atom */
5569 [preset setObject:[NSNumber numberWithInt:[fDstMp4iPodFileCheck state]] forKey:@"Mp4iPodCompatible"];
5573 [preset setObject:[fVidEncoderPopUp titleOfSelectedItem] forKey:@"VideoEncoder"];
5574 /* x264 Option String */
5575 [preset setObject:[fAdvancedOptions optionsString] forKey:@"x264Option"];
5577 [preset setObject:[NSNumber numberWithInt:[fVidQualityMatrix selectedRow]] forKey:@"VideoQualityType"];
5578 [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
5579 [preset setObject:[fVidBitrateField stringValue] forKey:@"VideoAvgBitrate"];
5580 [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
5582 /* Video framerate */
5583 if ([fVidRatePopUp indexOfSelectedItem] == 0) // Same as source is selected
5585 [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
5587 else // we can record the actual titleOfSelectedItem
5589 [preset setObject:[fVidRatePopUp titleOfSelectedItem] forKey:@"VideoFramerate"];
5592 [preset setObject:[NSNumber numberWithInt:[fVidGrayscaleCheck state]] forKey:@"VideoGrayScale"];
5593 /* 2 Pass Encoding */
5594 [preset setObject:[NSNumber numberWithInt:[fVidTwoPassCheck state]] forKey:@"VideoTwoPass"];
5595 /* Turbo 2 pass Encoding fVidTurboPassCheck*/
5596 [preset setObject:[NSNumber numberWithInt:[fVidTurboPassCheck state]] forKey:@"VideoTurboTwoPass"];
5597 /*Picture Settings*/
5598 hb_job_t * job = fTitle->job;
5599 /* Picture Sizing */
5600 /* Use Max Picture settings for whatever the dvd is.*/
5601 [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
5602 [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
5603 [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
5604 [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
5605 [preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
5607 /* Set crop settings here */
5608 [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];
5609 [preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
5610 [preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
5611 [preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
5612 [preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
5614 /* Picture Filters */
5615 [preset setObject:[NSNumber numberWithInt:[fPictureController deinterlace]] forKey:@"PictureDeinterlace"];
5616 [preset setObject:[NSNumber numberWithInt:[fPictureController detelecine]] forKey:@"PictureDetelecine"];
5617 [preset setObject:[NSNumber numberWithInt:[fPictureController vfr]] forKey:@"VFR"];
5618 [preset setObject:[NSNumber numberWithInt:[fPictureController denoise]] forKey:@"PictureDenoise"];
5619 [preset setObject:[NSNumber numberWithInt:[fPictureController deblock]] forKey:@"PictureDeblock"];
5620 [preset setObject:[NSNumber numberWithInt:[fPictureController decomb]] forKey:@"PictureDecomb"];
5624 if ([fAudLang1PopUp indexOfSelectedItem] > 0)
5626 [preset setObject:[NSNumber numberWithInt:[fAudLang1PopUp indexOfSelectedItem]] forKey:@"Audio1Track"];
5627 [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"Audio1TrackDescription"];
5628 [preset setObject:[fAudTrack1CodecPopUp titleOfSelectedItem] forKey:@"Audio1Encoder"];
5629 [preset setObject:[fAudTrack1MixPopUp titleOfSelectedItem] forKey:@"Audio1Mixdown"];
5630 [preset setObject:[fAudTrack1RatePopUp titleOfSelectedItem] forKey:@"Audio1Samplerate"];
5631 [preset setObject:[fAudTrack1BitratePopUp titleOfSelectedItem] forKey:@"Audio1Bitrate"];
5632 [preset setObject:[NSNumber numberWithFloat:[fAudTrack1DrcSlider floatValue]] forKey:@"Audio1TrackDRCSlider"];
5634 if ([fAudLang2PopUp indexOfSelectedItem] > 0)
5636 [preset setObject:[NSNumber numberWithInt:[fAudLang2PopUp indexOfSelectedItem]] forKey:@"Audio2Track"];
5637 [preset setObject:[fAudLang2PopUp titleOfSelectedItem] forKey:@"Audio2TrackDescription"];
5638 [preset setObject:[fAudTrack2CodecPopUp titleOfSelectedItem] forKey:@"Audio2Encoder"];
5639 [preset setObject:[fAudTrack2MixPopUp titleOfSelectedItem] forKey:@"Audio2Mixdown"];
5640 [preset setObject:[fAudTrack2RatePopUp titleOfSelectedItem] forKey:@"Audio2Samplerate"];
5641 [preset setObject:[fAudTrack2BitratePopUp titleOfSelectedItem] forKey:@"Audio2Bitrate"];
5642 [preset setObject:[NSNumber numberWithFloat:[fAudTrack2DrcSlider floatValue]] forKey:@"Audio2TrackDRCSlider"];
5644 if ([fAudLang3PopUp indexOfSelectedItem] > 0)
5646 [preset setObject:[NSNumber numberWithInt:[fAudLang3PopUp indexOfSelectedItem]] forKey:@"Audio3Track"];
5647 [preset setObject:[fAudLang3PopUp titleOfSelectedItem] forKey:@"Audio3TrackDescription"];
5648 [preset setObject:[fAudTrack3CodecPopUp titleOfSelectedItem] forKey:@"Audio3Encoder"];
5649 [preset setObject:[fAudTrack3MixPopUp titleOfSelectedItem] forKey:@"Audio3Mixdown"];
5650 [preset setObject:[fAudTrack3RatePopUp titleOfSelectedItem] forKey:@"Audio3Samplerate"];
5651 [preset setObject:[fAudTrack3BitratePopUp titleOfSelectedItem] forKey:@"Audio3Bitrate"];
5652 [preset setObject:[NSNumber numberWithFloat:[fAudTrack3DrcSlider floatValue]] forKey:@"Audio3TrackDRCSlider"];
5654 if ([fAudLang4PopUp indexOfSelectedItem] > 0)
5656 [preset setObject:[NSNumber numberWithInt:[fAudLang4PopUp indexOfSelectedItem]] forKey:@"Audio4Track"];
5657 [preset setObject:[fAudLang4PopUp titleOfSelectedItem] forKey:@"Audio4TrackDescription"];
5658 [preset setObject:[fAudTrack4CodecPopUp titleOfSelectedItem] forKey:@"Audio4Encoder"];
5659 [preset setObject:[fAudTrack4MixPopUp titleOfSelectedItem] forKey:@"Audio4Mixdown"];
5660 [preset setObject:[fAudTrack4RatePopUp titleOfSelectedItem] forKey:@"Audio4Samplerate"];
5661 [preset setObject:[fAudTrack4BitratePopUp titleOfSelectedItem] forKey:@"Audio4Bitrate"];
5662 [preset setObject:[NSNumber numberWithFloat:[fAudTrack4DrcSlider floatValue]] forKey:@"Audio4TrackDRCSlider"];
5666 [preset setObject:[fSubPopUp titleOfSelectedItem] forKey:@"Subtitles"];
5667 /* Forced Subtitles */
5668 [preset setObject:[NSNumber numberWithInt:[fSubForcedCheck state]] forKey:@"SubtitlesForced"];
5670 [preset autorelease];
5677 [UserPresets writeToFile:UserPresetsFile atomically:YES];
5678 /* We get the default preset in case it changed */
5679 [self getDefaultPresets:nil];
5683 - (IBAction)deletePreset:(id)sender
5686 NSEnumerator *enumerator;
5688 NSMutableArray *tempArray;
5691 if ( [fPresetsOutlineView numberOfSelectedRows] == 0 )
5693 /* Alert user before deleting preset */
5694 /* Comment out for now, tie to user pref eventually */
5697 status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
5699 if ( status == NSAlertDefaultReturn ) {
5700 enumerator = [fPresetsOutlineView selectedRowEnumerator];
5701 tempArray = [NSMutableArray array];
5703 while ( (index = [enumerator nextObject]) ) {
5704 tempObject = [UserPresets objectAtIndex:[index intValue]];
5705 [tempArray addObject:tempObject];
5708 [UserPresets removeObjectsInArray:tempArray];
5709 [fPresetsOutlineView reloadData];
5715 #pragma mark Manage Default Preset
5717 - (IBAction)getDefaultPresets:(id)sender
5720 presetCurrentBuiltInCount = 0;
5721 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5723 while (tempObject = [enumerator nextObject])
5725 NSDictionary *thisPresetDict = tempObject;
5726 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 1) // 1 is HB default
5728 presetHbDefault = i;
5730 if ([[thisPresetDict objectForKey:@"Default"] intValue] == 2) // 2 is User specified default
5732 presetUserDefault = i;
5734 if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset
5736 presetCurrentBuiltInCount++; // <--increment the current number of built in presets
5742 - (IBAction)setDefaultPreset:(id)sender
5745 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5747 /* First make sure the old user specified default preset is removed */
5748 while (tempObject = [enumerator nextObject])
5750 /* make sure we are not removing the default HB preset */
5751 if ([[[UserPresets objectAtIndex:i] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5753 [[UserPresets objectAtIndex:i] setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
5757 /* Second, go ahead and set the appropriate user specfied preset */
5758 /* we get the chosen preset from the UserPresets array */
5759 if ([[[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] objectForKey:@"Default"] intValue] != 1) // 1 is HB default
5761 [[UserPresets objectAtIndex:[fPresetsOutlineView selectedRow]] setObject:[NSNumber numberWithInt:2] forKey:@"Default"];
5763 /*FIX ME: I think we now need to use the items not rows in NSOutlineView */
5764 presetUserDefault = [fPresetsOutlineView selectedRow];
5766 /* We save all of the preset data here */
5768 /* We Reload the New Table data for presets */
5769 [fPresetsOutlineView reloadData];
5772 - (IBAction)selectDefaultPreset:(id)sender
5774 /* if there is a user specified default, we use it */
5775 if (presetUserDefault)
5777 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetUserDefault] byExtendingSelection:NO];
5778 [self selectPreset:nil];
5780 else if (presetHbDefault) //else we use the built in default presetHbDefault
5782 [fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:presetHbDefault] byExtendingSelection:NO];
5783 [self selectPreset:nil];
5789 #pragma mark Manage Built In Presets
5792 - (IBAction)deleteFactoryPresets:(id)sender
5795 NSEnumerator *enumerator = [UserPresets objectEnumerator];
5799 NSMutableArray *tempArray;
5802 tempArray = [NSMutableArray array];
5803 /* we look here to see if the preset is we move on to the next one */
5804 while ( tempObject = [enumerator nextObject] )
5806 /* if the preset is "Factory" then we put it in the array of
5807 presets to delete */
5808 if ([[tempObject objectForKey:@"Type"] intValue] == 0)
5810 [tempArray addObject:tempObject];
5814 [UserPresets removeObjectsInArray:tempArray];
5815 [fPresetsOutlineView reloadData];
5820 /* We use this method to recreate new, updated factory
5822 - (IBAction)addFactoryPresets:(id)sender
5825 /* First, we delete any existing built in presets */
5826 [self deleteFactoryPresets: sender];
5827 /* Then we generate new built in presets programmatically with fPresetsBuiltin
5828 * which is all setup in HBPresets.h and HBPresets.m*/
5829 [fPresetsBuiltin generateBuiltinPresets:UserPresets];
5841 /*******************************
5842 * Subclass of the HBPresetsOutlineView *
5843 *******************************/
5845 @implementation HBPresetsOutlineView
5846 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
5850 // By default, NSTableView only drags an image of the first column. Change this to
5851 // drag an image of the queue's icon and PresetName columns.
5852 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"icon"], [self tableColumnWithIdentifier:@"PresetName"], nil];
5853 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
5858 - (void) mouseDown:(NSEvent *)theEvent
5860 [super mouseDown:theEvent];
5866 - (BOOL) isDragging;