[Event Handler] Fix observers for reused classes
Fix class handling so it cleans up observers if the InputNode is reused. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
789e8e432e
commit
7bc49ccb80
|
@ -33,6 +33,8 @@ static void *kInputNodeContext = &kInputNodeContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)openWithSource:(id<CogSource>)source {
|
- (BOOL)openWithSource:(id<CogSource>)source {
|
||||||
|
[self removeObservers];
|
||||||
|
|
||||||
decoder = [AudioDecoder audioDecoderForSource:source];
|
decoder = [AudioDecoder audioDecoderForSource:source];
|
||||||
|
|
||||||
if(decoder == nil)
|
if(decoder == nil)
|
||||||
|
@ -63,6 +65,8 @@ static void *kInputNodeContext = &kInputNodeContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)openWithDecoder:(id<CogDecoder>)d {
|
- (BOOL)openWithDecoder:(id<CogDecoder>)d {
|
||||||
|
[self removeObservers];
|
||||||
|
|
||||||
DLog(@"Opening with old decoder: %@", d);
|
DLog(@"Opening with old decoder: %@", d);
|
||||||
decoder = d;
|
decoder = d;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
@interface CogDecoderMulti : NSObject <CogDecoder> {
|
@interface CogDecoderMulti : NSObject <CogDecoder> {
|
||||||
NSArray *theDecoders;
|
NSArray *theDecoders;
|
||||||
id<CogDecoder> theDecoder;
|
id<CogDecoder> theDecoder;
|
||||||
|
BOOL observersAdded;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithDecoders:(NSArray *)decoders;
|
- (id)initWithDecoders:(NSArray *)decoders;
|
||||||
|
|
|
@ -113,6 +113,7 @@ static void *kCogDecoderMultiContext = &kCogDecoderMultiContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)registerObservers {
|
- (void)registerObservers {
|
||||||
|
if(!observersAdded) {
|
||||||
[theDecoder addObserver:self
|
[theDecoder addObserver:self
|
||||||
forKeyPath:@"properties"
|
forKeyPath:@"properties"
|
||||||
options:(NSKeyValueObservingOptionNew)
|
options:(NSKeyValueObservingOptionNew)
|
||||||
|
@ -122,12 +123,17 @@ static void *kCogDecoderMultiContext = &kCogDecoderMultiContext;
|
||||||
forKeyPath:@"metadata"
|
forKeyPath:@"metadata"
|
||||||
options:(NSKeyValueObservingOptionNew)
|
options:(NSKeyValueObservingOptionNew)
|
||||||
context:kCogDecoderMultiContext];
|
context:kCogDecoderMultiContext];
|
||||||
|
observersAdded = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObservers {
|
- (void)removeObservers {
|
||||||
|
if(observersAdded) {
|
||||||
|
observersAdded = NO;
|
||||||
[theDecoder removeObserver:self forKeyPath:@"properties" context:kCogDecoderMultiContext];
|
[theDecoder removeObserver:self forKeyPath:@"properties" context:kCogDecoderMultiContext];
|
||||||
[theDecoder removeObserver:self forKeyPath:@"metadata" context:kCogDecoderMultiContext];
|
[theDecoder removeObserver:self forKeyPath:@"metadata" context:kCogDecoderMultiContext];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)setTrack:(NSURL *)track {
|
- (BOOL)setTrack:(NSURL *)track {
|
||||||
if(theDecoder != nil && [theDecoder respondsToSelector:@selector(setTrack:)]) return [theDecoder setTrack:track];
|
if(theDecoder != nil && [theDecoder respondsToSelector:@selector(setTrack:)]) return [theDecoder setTrack:track];
|
||||||
|
|
Loading…
Reference in New Issue