diff options
author | dynaflash <[email protected]> | 2010-11-08 21:47:52 +0000 |
---|---|---|
committer | dynaflash <[email protected]> | 2010-11-08 21:47:52 +0000 |
commit | 1c0082a4cb2670b9c0e5f5cbf1fc961a67e521bf (patch) | |
tree | 95712245fffa1c7907c490b290b114a7b63aa184 /macosx/HBAudio.m | |
parent | 98f4ed694fcd68a2967a5a85c565e90fe68881da (diff) |
MacGui: Audio
- Switched the audio object to use KVO internally to make the code more legible, to allow switching the codec to eventually cause the mp4 output extension to be re-evalutated, and to make sure the bitrate and mixdown popups are empty when the track is disable (the None track).
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3663 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAudio.m')
-rw-r--r-- | macosx/HBAudio.m | 167 |
1 files changed, 74 insertions, 93 deletions
diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m index 721e104ba..9e51a8d7f 100644 --- a/macosx/HBAudio.m +++ b/macosx/HBAudio.m @@ -312,7 +312,11 @@ static NSMutableArray *masterBitRateArray = nil; nil]]; } } - + + if (NO == [self enabled]) { + retval = nil; + } + // Now make sure the permitted list and the actual ones matches [self setMixdowns: retval]; @@ -386,7 +390,11 @@ static NSMutableArray *masterBitRateArray = nil; } [permittedBitRates addObject: missingBitRate]; } - + + if (NO == [self enabled]) { + permittedBitRates = nil; + } + // Make sure we are updated with the permitted list [self setBitRates: permittedBitRates]; @@ -402,6 +410,19 @@ static NSMutableArray *masterBitRateArray = nil; return; } +- (id) init + +{ + if (self = [super init]) { + [self addObserver: self forKeyPath: @"videoContainerTag" options: 0 context: NULL]; + [self addObserver: self forKeyPath: @"track" options: NSKeyValueObservingOptionOld context: NULL]; + [self addObserver: self forKeyPath: @"codec" options: 0 context: NULL]; + [self addObserver: self forKeyPath: @"mixdown" options: 0 context: NULL]; + [self addObserver: self forKeyPath: @"sampleRate" options: 0 context: NULL]; + } + return self; +} + #pragma mark - #pragma mark Accessors @@ -418,84 +439,6 @@ static NSMutableArray *masterBitRateArray = nil; @synthesize mixdowns; @synthesize bitRates; -- (void) setVideoContainerTag: (NSNumber *) aValue - -{ - if ((nil != aValue || nil != videoContainerTag) && NO == [aValue isEqual: videoContainerTag]) { - [aValue retain]; - [videoContainerTag release]; - videoContainerTag = aValue; - [self updateCodecs]; - } - return; -} - -// We do some detection of the None track to do special things. -- (void) setTrack: (NSDictionary *) aValue - -{ - if ((nil != aValue || nil != track) && NO == [aValue isEqual: track]) { - BOOL switchingFromNone = [track isEqual: [controller noneTrack]]; - BOOL switchingToNone = [aValue isEqual: [controller noneTrack]]; - - [aValue retain]; - [track release]; - track = aValue; - - if (nil != aValue) { - [self updateCodecs]; - if (YES == [self enabled]) { - [self setSampleRate: [[self sampleRates] objectAtIndex: 0]]; // default to Auto - } - if (YES == switchingFromNone) { - [controller switchingTrackFromNone: self]; - } - if (YES == switchingToNone) { - [controller settingTrackToNone: self]; - } - } - } - return; -} - -- (void) setCodec: (NSDictionary *) aValue - -{ - if ((nil != aValue || nil != codec) && NO == [aValue isEqual: codec]) { - [aValue retain]; - [codec release]; - codec = aValue; - [self updateMixdowns]; - [self updateBitRates: YES]; - } - return; -} - -- (void) setMixdown: (NSDictionary *) aValue - -{ - if ((nil != aValue || nil != mixdown) && NO == [aValue isEqual: mixdown]) { - [aValue retain]; - [mixdown release]; - mixdown = aValue; - [self updateBitRates: YES]; - [[NSNotificationCenter defaultCenter] postNotificationName: HBMixdownChangedNotification object: self]; - } - return; -} - -- (void) setSampleRate: (NSDictionary *) aValue - -{ - if ((nil != aValue || nil != sampleRate) && NO == [aValue isEqual: sampleRate]) { - [aValue retain]; - [sampleRate release]; - sampleRate = aValue; - [self updateBitRates: NO]; - } - return; -} - - (NSArray *) tracks { return [controller masterTrackArray]; } - (NSArray *) sampleRates { return masterSampleRateArray; } @@ -503,6 +446,11 @@ static NSMutableArray *masterBitRateArray = nil; - (void) dealloc { + [self removeObserver: self forKeyPath: @"videoContainerTag"]; + [self removeObserver: self forKeyPath: @"track"]; + [self removeObserver: self forKeyPath: @"codec"]; + [self removeObserver: self forKeyPath: @"mixdown"]; + [self removeObserver: self forKeyPath: @"sampleRate"]; [self setTrack: nil]; [self setCodec: nil]; [self setMixdown: nil]; @@ -518,6 +466,43 @@ static NSMutableArray *masterBitRateArray = nil; } #pragma mark - +#pragma mark KVO + +- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context + +{ + if (YES == [keyPath isEqualToString: @"videoContainerTag"]) { + [self updateCodecs]; + } + else if (YES == [keyPath isEqualToString: @"track"]) { + if (nil != [self track]) { + [self updateCodecs]; + if (YES == [self enabled]) { + [self setSampleRate: [[self sampleRates] objectAtIndex: 0]]; // default to Auto + } + if (YES == [[controller noneTrack] isEqual: [change objectForKey: NSKeyValueChangeOldKey]]) { + [controller switchingTrackFromNone: self]; + } + if (YES == [[controller noneTrack] isEqual: [self track]]) { + [controller settingTrackToNone: self]; + } + } + } + else if (YES == [keyPath isEqualToString: @"codec"]) { + [self updateMixdowns]; + [self updateBitRates: YES]; + } + else if (YES == [keyPath isEqualToString: @"mixdown"]) { + [self updateBitRates: YES]; + [[NSNotificationCenter defaultCenter] postNotificationName: HBMixdownChangedNotification object: self]; + } + else if (YES == [keyPath isEqualToString: @"sampleRate"]) { + [self updateBitRates: NO]; + } + return; +} + +#pragma mark - #pragma mark Special Setters - (void) setTrackFromIndex: (int) aValue @@ -629,22 +614,18 @@ static NSMutableArray *masterBitRateArray = nil; return retval; } -+ (NSSet *) keyPathsForValuesAffectingEnabled - -{ - return [NSSet setWithObjects: @"track", nil]; -} - -+ (NSSet *) keyPathsForValuesAffectingMixdownEnabled ++ (NSSet *) keyPathsForValuesAffectingValueForKey: (NSString *) key { - return [NSSet setWithObjects: @"track", @"mixdown", nil]; -} + NSSet *retval = nil; -+ (NSSet *) keyPathsForValuesAffectingAC3Enabled - -{ - return [NSSet setWithObjects: @"track", nil]; + if (YES == [key isEqualToString: @"enabled"] || YES == [key isEqualToString: @"AC3Enabled"]) { + retval = [NSSet setWithObjects: @"track", nil]; + } + else if (YES == [key isEqualToString: @"mixdownEnabled"]) { + retval = [NSSet setWithObjects: @"track", @"mixdown", nil]; + } + return retval; } @end |