X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=macosx%2FHBAudioController.m;h=da58cfbc1977a3fa767c78196f392e34f61b82ee;hb=7c5de680aa66988f2465b0870312f2976019a634;hp=ccd6363c71ff1269f7792e88d79fe51f05dd97b4;hpb=58ba3978c9fd270d150e0b271a80c46cabf0431c;p=handbrake-jp%2Fhandbrake-jp-git.git 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; }