diff options
author | dynaflash <[email protected]> | 2012-08-27 18:36:17 +0000 |
---|---|---|
committer | dynaflash <[email protected]> | 2012-08-27 18:36:17 +0000 |
commit | 09a30794cb6388909e273f0801ede2e6001bf955 (patch) | |
tree | a3f44f9cb2d3d65f7b7f7521a79a4730c357b0c1 /macosx/HBAudioController.m | |
parent | 60bf93c65e36a456e35eb7556a59acca281a282e (diff) |
MacGui: Add support for a secondary audio language track.
- Patch courtesy of Dennis Frommknecht ... thank you!
- Adds a second language preference in Preferences > Audio
-- If the corresponding language is not available in the source, the group for this language is not added. If neither default nor alternate language is found, the first audio track would be added (as it is already). The alternate language can also be left empty in which case no second group is added.
-- The implementation ensures that the same track is not added twice (if default and alternate language are identical). It is also flexible enough to support an arbitrary number of languages. They just have to be added to array "preferredLanguages" at the beginning of method "addTracksFromPreset" (HBAudioController.m).
The original patch and explanation can be found at https://reviews.handbrake.fr/r/262/
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4921 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAudioController.m')
-rw-r--r-- | macosx/HBAudioController.m | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m index 2c60b0fca..235e39f43 100644 --- a/macosx/HBAudioController.m +++ b/macosx/HBAudioController.m @@ -426,24 +426,51 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { id whatToUse = [self _presetAudioArrayFromPreset: aPreset]; - NSString *preferredLanguageName = [[NSUserDefaults standardUserDefaults] stringForKey: @"DefaultLanguage"]; - int preferredLanguage = [self _trackWithTitlePrefix: preferredLanguageName defaultIfNotFound: 1]; + NSMutableArray *tracksToAdd = [[NSMutableArray alloc] init]; - // Reinitialize the configured list of audio tracks - [self _clearAudioArray]; + NSArray* preferredLanguages = [NSArray arrayWithObjects: + [[NSUserDefaults standardUserDefaults] stringForKey: @"DefaultLanguage"], + [[NSUserDefaults standardUserDefaults] stringForKey: @"AlternateLanguage"], + nil]; + + // Add tracks of Default and Alternate Language by name + for(id languageName in preferredLanguages) + { + int trackNumber = [self _trackWithTitlePrefix: languageName defaultIfNotFound: 0]; + + if(trackNumber > 0 && [tracksToAdd indexOfObject:[NSNumber numberWithInt:trackNumber]] == NSNotFound) + { + [tracksToAdd addObject:[NSNumber numberWithInt:trackNumber]]; + } + } - [self _processPresetAudioArray: whatToUse forTrack: preferredLanguage andType: [[aPreset objectForKey: @"Type"] intValue]]; + // If no preferred Language was found, add standard track 1 + if([tracksToAdd count] == 0) + { + [tracksToAdd addObject:[NSNumber numberWithInt:1]]; + } + + // If all tracks should be added, add all track numbers that are not yet processed if (allTracks) { unsigned int count = [masterTrackArray count]; for (unsigned int i = 1; i < count; i++) { - if (i != preferredLanguage) + NSNumber *trackNumber = [NSNumber numberWithInt:i]; + if([tracksToAdd indexOfObject:trackNumber] == NSNotFound) { - [self _processPresetAudioArray: whatToUse forTrack: i andType: [[aPreset objectForKey: @"Type"] intValue]]; + [tracksToAdd addObject:trackNumber]; } } } + + // Reinitialize the configured list of audio tracks + [self _clearAudioArray]; + + for(id trackNumber in tracksToAdd) + { + [self _processPresetAudioArray: whatToUse forTrack:[trackNumber intValue] andType: [[aPreset objectForKey: @"Type"] intValue]]; + } } - (void) _ensureAtLeastOneNonEmptyTrackExists |