From 7c5de680aa66988f2465b0870312f2976019a634 Mon Sep 17 00:00:00 2001 From: dynaflash Date: Mon, 20 Sep 2010 16:15:23 +0000 Subject: [PATCH] MacGui: Audio Fixes and Enhancements ... patch by circleone. Fixes issue where changing to custom from a preset then changing titles will cause an empty audio tab. Also: - Added the ability for HandBrake's language preference to be honored when it occurs in the title's tracks. - Ensured the limit (currently 24) is not passed when adding audios using presets. - If no preset is chosen, when a new title loads, one track is added (based on the language preference or the first if that is not met). - Reinitializing the audio array is now KVO-friendly, making the UI refresh more pleasant. - The "Add All Tracks" button has been made mini in size. - The audio table view no longer attempts to keep the selection. git-svn-id: svn://localhost/HandBrake/trunk@3549 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/Controller.h | 3 +- macosx/Controller.m | 22 +++++-- macosx/English.lproj/MainMenu.xib | 43 +++---------- macosx/HBAudioController.m | 130 +++++++++++++++++++++++++------------- 4 files changed, 111 insertions(+), 87 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index f9634abe..7bdc3c37 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -244,7 +244,6 @@ BOOL fIsDragging; NSString * browsedSourceDisplayName; double dockIconProgress; - BOOL hasValidPresetSelected; } - (int) getPidnum; - (IBAction) showAboutPanel:(id)sender; @@ -417,7 +416,7 @@ BOOL fIsDragging; returnCode: (int) returnCode contextInfo: (void *) contextInfo; + (unsigned int) maximumNumberOfAllowedAudioTracks; -@property (nonatomic, assign) BOOL hasValidPresetSelected; +@property (nonatomic, readonly) BOOL hasValidPresetSelected; - (IBAction) addAllAudioTracks: (id) sender; @end diff --git a/macosx/Controller.m b/macosx/Controller.m index 92d31a82..7fbd5f28 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -4958,7 +4958,11 @@ the user is using "Custom" settings by determining the sender*/ #pragma mark - -@synthesize hasValidPresetSelected; +- (BOOL) hasValidPresetSelected + +{ + return ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1); +} // This causes all audio tracks from the title to be used based on the current preset - (IBAction) addAllAudioTracks: (id) sender @@ -5315,6 +5319,14 @@ return YES; //} } +- (void) outlineViewSelectionDidChange: (NSNotification *) ignored + +{ + [self willChangeValueForKey: @"hasValidPresetSelected"]; + [self didChangeValueForKey: @"hasValidPresetSelected"]; + return; +} + #pragma mark - #pragma mark Preset Outline View Methods (dragging related) @@ -5429,9 +5441,8 @@ return YES; - (IBAction)selectPreset:(id)sender { - if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1) + if (YES == [self hasValidPresetSelected]) { - [self setHasValidPresetSelected: YES]; chosenPreset = [fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]; [fPresetSelectedDisplay setStringValue:[chosenPreset objectForKey:@"PresetName"]]; @@ -5752,9 +5763,6 @@ return YES; [fPictureController SetTitle:fTitle]; [self calculatePictureSizing:nil]; } - else { - [self setHasValidPresetSelected: NO]; - } } @@ -6136,7 +6144,7 @@ return YES; /* now get and add selected presets to export */ } - if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1) + if (YES == [self hasValidPresetSelected]) { [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]]; [presetsToExport writeToFile:exportPresetsFile atomically:YES]; diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index 5f6f04a5..62ae0d96 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -672,13 +672,13 @@ 256 - {682, 241} + {678, 241} YES 256 - {682, 17} + {678, 17} @@ -1011,7 +1011,7 @@ drctext - 32 + 28 10 3.4028229999999999e+38 @@ -1086,7 +1086,6 @@ -2147483392 {{-100, -100}, {685, 15}} - YES 1 _doScroller: @@ -1111,7 +1110,7 @@ {{17, 17}, {680, 259}} - 658 + 530 @@ -1122,14 +1121,14 @@ 268 - {{12, 277}, {116, 28}} + {{16, 282}, {116, 16}} YES 67239424 - 134348800 + 134479872 Add All Tracks - + -2038284033 129 @@ -1145,7 +1144,6 @@ {{10, 25}, {714, 305}} - Audio @@ -3694,7 +3692,7 @@ {1.79769e+308, 1.79769e+308} {338, 232} - + 256 YES @@ -3703,7 +3701,6 @@ 289 {{239, 12}, {85, 32}} - YES 67239424 @@ -3729,7 +3726,6 @@ 289 {{155, 12}, {84, 32}} - YES 67239424 @@ -3751,7 +3747,6 @@ 266 {{20, 264}, {298, 19}} - YES -1804468671 @@ -3769,7 +3764,6 @@ 266 {{128, 193}, {193, 22}} - YES -2076049856 @@ -3840,7 +3834,6 @@ 268 {{17, 286}, {114, 17}} - YES 67239424 @@ -3857,7 +3850,6 @@ 268 {{17, 217}, {91, 14}} - YES 67239424 @@ -3874,7 +3866,6 @@ 268 {{17, 100}, {114, 14}} - YES 67239424 @@ -3891,7 +3882,6 @@ 274 {{20, 51}, {298, 41}} - YES -1805517311 @@ -3909,7 +3899,6 @@ 268 {{27, 195}, {99, 14}} - YES 67239424 @@ -3926,7 +3915,6 @@ 268 {{128, 142}, {24, 18}} - YES -2080244224 @@ -3949,7 +3937,6 @@ -2147483380 {{17, 240}, {303, 18}} - YES 67239424 @@ -3972,7 +3959,6 @@ 268 {{113, 220}, {205, 5}} - {0, 0} 67239424 @@ -3995,7 +3981,6 @@ 268 {{12, 120}, {298, 5}} - {0, 0} 67239424 @@ -4018,7 +4003,6 @@ 268 {{17, 144}, {109, 15}} - YES 67239424 @@ -4045,7 +4029,6 @@ 266 {{11, 10}, {52, 16}} - YES -1804468671 @@ -4063,7 +4046,6 @@ 268 {{61, 10}, {29, 15}} - YES 67239424 @@ -4080,7 +4062,6 @@ 266 {{90, 10}, {52, 16}} - YES -1804468671 @@ -4096,12 +4077,10 @@ {155, 32} - {{128, 163}, {155, 32}} - {0, 0} 67239424 @@ -4122,8 +4101,6 @@ {338, 318} - - {{0, 0}, {1920, 1178}} {338, 254} @@ -4345,8 +4322,6 @@ YES - YES - YES YES YES YES @@ -8741,8 +8716,8 @@ YES - + diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m index ccd6363c..da58cfbc 100644 --- a/macosx/HBAudioController.m +++ b/macosx/HBAudioController.m @@ -32,6 +32,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { if (self = [super init]) { [self setVideoContainerTag: [NSNumber numberWithInt: HB_MUX_MP4]]; + audioArray = [[NSMutableArray alloc] init]; } return self; } @@ -60,6 +61,15 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; return; } +- (void) _clearAudioArray + +{ + while (0 < [self countOfAudioArray]) { + [self removeObjectFromAudioArrayAtIndex: 0]; + } + return; +} + #pragma mark - #pragma mark HBController Support @@ -165,8 +175,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; int maximumNumberOfAllowedAudioTracks = [HBController maximumNumberOfAllowedAudioTracks]; // Reinitialize the configured list of audio tracks - [audioArray release]; - audioArray = [[NSMutableArray alloc] init]; + [self _clearAudioArray]; // The following is the pattern to follow, but with Audio%dTrack being the key to seek... // Can we assume that there will be no skip in the data? @@ -228,68 +237,95 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; NSEnumerator *enumerator = [templateAudioArray objectEnumerator]; NSDictionary *dict; NSString *key; + int maximumNumberOfAllowedAudioTracks = [HBController maximumNumberOfAllowedAudioTracks]; while (nil != (dict = [enumerator nextObject])) { - HBAudio *newAudio = [[HBAudio alloc] init]; - [newAudio setController: self]; - [self insertObject: newAudio inAudioArrayAtIndex: [self countOfAudioArray]]; - [newAudio setVideoContainerTag: [self videoContainerTag]]; - [newAudio setTrackFromIndex: trackIndex]; - key = [dict objectForKey: @"AudioEncoder"]; - if (0 == aType && - YES == [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] && - YES == [key isEqualToString: @"AAC (faac)"] - ) { - key = @"AAC (CoreAudio)"; - } - // If our preset wants us to support a codec that the track does not support, instead - // of changing the codec we remove the audio instead. - if (YES == [newAudio setCodecFromName: key]) { - [newAudio setMixdownFromName: [dict objectForKey: @"AudioMixdown"]]; - [newAudio setSampleRateFromName: [dict objectForKey: @"AudioSamplerate"]]; - [newAudio setBitRateFromName: [dict objectForKey: @"AudioBitrate"]]; - [newAudio setDrc: [dict objectForKey: @"AudioTrackDRCSlider"]]; - } - else { - [self removeObjectFromAudioArrayAtIndex: [self countOfAudioArray] - 1]; + if ([self countOfAudioArray] < maximumNumberOfAllowedAudioTracks) { + HBAudio *newAudio = [[HBAudio alloc] init]; + [newAudio setController: self]; + [self insertObject: newAudio inAudioArrayAtIndex: [self countOfAudioArray]]; + [newAudio setVideoContainerTag: [self videoContainerTag]]; + [newAudio setTrackFromIndex: trackIndex]; + key = [dict objectForKey: @"AudioEncoder"]; + if (0 == aType && + YES == [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] && + YES == [key isEqualToString: @"AAC (faac)"] + ) { + key = @"AAC (CoreAudio)"; + } + // If our preset wants us to support a codec that the track does not support, instead + // of changing the codec we remove the audio instead. + if (YES == [newAudio setCodecFromName: key]) { + [newAudio setMixdownFromName: [dict objectForKey: @"AudioMixdown"]]; + [newAudio setSampleRateFromName: [dict objectForKey: @"AudioSamplerate"]]; + [newAudio setBitRateFromName: [dict objectForKey: @"AudioBitrate"]]; + [newAudio setDrc: [dict objectForKey: @"AudioTrackDRCSlider"]]; + } + else { + [self removeObjectFromAudioArrayAtIndex: [self countOfAudioArray] - 1]; + } + [newAudio release]; } - [newAudio release]; } return; } -- (void) addTracksFromPreset: (NSMutableDictionary *) aPreset +// This matches the FIRST track with the specified prefix, otherwise it uses the defaultIfNotFound value +- (unsigned int) _trackWithTitlePrefix: (NSString *) prefix defaultIfNotFound: (unsigned int) defaultIfNotFound + +{ + unsigned int retval = defaultIfNotFound; + int count = [masterTrackArray count]; + NSString *languageTitle; + BOOL found = NO; + + // We search for the prefix noting that our titles have the format %d: %s where the %s is the prefix + for (unsigned int i = 1; i < count && NO == found; i++) { // Note that we skip the "None" track + languageTitle = [[masterTrackArray objectAtIndex: i] objectForKey: keyAudioTrackName]; + if (YES == [[languageTitle substringFromIndex: [languageTitle rangeOfString: @" "].location + 1] hasPrefix: prefix]) { + retval = i; + found = YES; + } + } + return retval; +} + +- (void) addTracksFromPreset: (NSMutableDictionary *) aPreset allTracks: (BOOL) allTracks { id whatToUse = [self _presetAudioArrayFromPreset: aPreset]; + NSString *preferredLanguageName = [[NSUserDefaults standardUserDefaults] stringForKey: @"DefaultLanguage"]; + int preferredLanguage = [self _trackWithTitlePrefix: preferredLanguageName defaultIfNotFound: 1]; // Reinitialize the configured list of audio tracks - [audioArray release]; - audioArray = [[NSMutableArray alloc] init]; + [self _clearAudioArray]; - [self _processPresetAudioArray: whatToUse forTrack: 1 andType: [[aPreset objectForKey: @"Type"] intValue]]; + [self _processPresetAudioArray: whatToUse forTrack: preferredLanguage andType: [[aPreset objectForKey: @"Type"] intValue]]; + if (YES == allTracks) { + unsigned int count = [masterTrackArray count]; + for (unsigned int i = 1; i < count; i++) { + if (i != preferredLanguage) { + [self _processPresetAudioArray: whatToUse forTrack: i andType: [[aPreset objectForKey: @"Type"] intValue]]; + } + } + } [self switchingTrackFromNone: nil]; // see if we need to add one to the list return; } -- (void) addAllTracksFromPreset: (NSMutableDictionary *) aPreset +- (void) addTracksFromPreset: (NSMutableDictionary *) aPreset { - id whatToUse = [self _presetAudioArrayFromPreset: aPreset]; - - // Reinitialize the configured list of audio tracks - [audioArray release]; - audioArray = [[NSMutableArray alloc] init]; - - for (unsigned int i = 1; i < [masterTrackArray count]; i++) { - [self _processPresetAudioArray: whatToUse forTrack: i andType: [[aPreset objectForKey: @"Type"] intValue]]; - } - - [self switchingTrackFromNone: nil]; // see if we need to add one to the list - + [self addTracksFromPreset: aPreset allTracks: NO]; return; +} + +- (void) addAllTracksFromPreset: (NSMutableDictionary *) aPreset + +{ + [self addTracksFromPreset: aPreset allTracks: YES]; return; } @@ -419,9 +455,15 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; } // Reinitialize the configured list of audio tracks - [audioArray release]; - audioArray = [[NSMutableArray alloc] init]; + [self _clearAudioArray]; + if (NO == [myController hasValidPresetSelected]) { + NSString *preferredLanguageName = [[NSUserDefaults standardUserDefaults] stringForKey: @"DefaultLanguage"]; + int preferredLanguage = [self _trackWithTitlePrefix: preferredLanguageName defaultIfNotFound: 1]; + [self addNewAudioTrack]; + HBAudio *anAudio = [self objectInAudioArrayAtIndex: 0]; + [anAudio setTrackFromIndex: preferredLanguage]; + } return; } -- 2.11.0