Fix outstanding crashes and issues with CUE reader
CUE reader was crashing due to nil metadata pointers, which the new inplace initializer I was using didn't like. Change it to use a mutable regular dictionary, and only add items if they're not nil. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
d7becdf01a
commit
d5aecaf6a2
|
@ -17,6 +17,8 @@
|
|||
id<CogSource> source;
|
||||
id<CogDecoder> decoder;
|
||||
|
||||
NSURL *sourceURL;
|
||||
|
||||
int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8)
|
||||
|
||||
long framePosition; // Current position in frames.
|
||||
|
|
|
@ -44,7 +44,10 @@
|
|||
}
|
||||
|
||||
- (NSDictionary *)metadata {
|
||||
return @{};
|
||||
if(decoder != nil)
|
||||
return [decoder metadata];
|
||||
else
|
||||
return @{};
|
||||
}
|
||||
|
||||
- (BOOL)open:(id<CogSource>)s {
|
||||
|
@ -54,6 +57,8 @@
|
|||
|
||||
NSURL *url = [s url];
|
||||
|
||||
sourceURL = url;
|
||||
|
||||
embedded = NO;
|
||||
cuesheet = nil;
|
||||
NSDictionary *fileMetadata;
|
||||
|
@ -225,14 +230,25 @@
|
|||
if(noFragment)
|
||||
return NO;
|
||||
|
||||
BOOL pathsAreFiles = NO;
|
||||
|
||||
if([url isFileURL] && [sourceURL isFileURL]) {
|
||||
pathsAreFiles = YES;
|
||||
}
|
||||
|
||||
// Same file, just next track...this may be unnecessary since frame-based decoding is done now...
|
||||
if(embedded || ([[[track url] path] isEqualToString:[url path]] && [[[track url] host] isEqualToString:[url host]] && [[url fragment] intValue] == [[track track] intValue] + 1)) {
|
||||
if(embedded || ([[sourceURL path] isEqualToString:[url path]] && (pathsAreFiles || [[sourceURL host] isEqualToString:[url host]]))) {
|
||||
NSArray *tracks = [cuesheet tracks];
|
||||
|
||||
int i;
|
||||
for(i = 0; i < [tracks count]; i++) {
|
||||
if([[[tracks objectAtIndex:i] track] isEqualToString:[url fragment]]) {
|
||||
track = [tracks objectAtIndex:i];
|
||||
CueSheetTrack *_track = [tracks objectAtIndex:i];
|
||||
|
||||
if(![[_track url] isEqualTo:[track url]])
|
||||
return NO;
|
||||
|
||||
track = _track;
|
||||
|
||||
float sampleRate = [[[decoder properties] objectForKey:@"sampleRate"] floatValue];
|
||||
|
||||
|
@ -253,8 +269,7 @@
|
|||
trackEnd = [[[decoder properties] objectForKey:@"totalFrames"] longValue];
|
||||
}
|
||||
|
||||
if(embedded)
|
||||
[self seek:0];
|
||||
[self seek:0];
|
||||
|
||||
DLog(@"CHANGING TRACK!");
|
||||
return YES;
|
||||
|
|
|
@ -52,8 +52,9 @@
|
|||
} else
|
||||
cuesheet = [CueSheet cueSheetWithFile:[url path]];
|
||||
|
||||
if(!cuesheet)
|
||||
return nil;
|
||||
if(!cuesheet) {
|
||||
return fileMetadata;
|
||||
}
|
||||
|
||||
NSArray *tracks = [cuesheet tracks];
|
||||
for(CueSheetTrack *track in tracks) {
|
||||
|
@ -61,16 +62,19 @@
|
|||
// Class supplied by CogAudio, which is guaranteed to be present
|
||||
if(!embedded)
|
||||
fileMetadata = [audioMetadataReader metadataForURL:[track url] skipCue:YES];
|
||||
NSDictionary *cuesheetMetadata = @{@"artist": [track artist],
|
||||
@"album": [track album],
|
||||
@"title": [track title],
|
||||
@"track": [NSNumber numberWithInt:[[track track] intValue]],
|
||||
@"genre": [track genre],
|
||||
@"year": [NSNumber numberWithInt:[[track year] intValue]],
|
||||
@"replayGainAlbumGain": [NSNumber numberWithFloat:[track albumGain]],
|
||||
@"replayGainAlbumPeak": [NSNumber numberWithFloat:[track albumPeak]],
|
||||
@"replayGainTrackGain": [NSNumber numberWithFloat:[track trackGain]],
|
||||
@"replayGainTrackPeak": [NSNumber numberWithFloat:[track trackPeak]]};
|
||||
|
||||
NSMutableDictionary *cuesheetMetadata = [[NSMutableDictionary alloc] init];
|
||||
|
||||
if([track artist]) [cuesheetMetadata setValue:[track artist] forKey:@"artist"];
|
||||
if([track album]) [cuesheetMetadata setValue:[track album] forKey:@"album"];
|
||||
if([track title]) [cuesheetMetadata setValue:[track title] forKey:@"title"];
|
||||
if([[track track] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track track] intValue]] forKey:@"track"];
|
||||
if([track genre]) [cuesheetMetadata setValue:[track genre] forKey:@"genre"];
|
||||
if([[track year] intValue]) [cuesheetMetadata setValue:[NSNumber numberWithInt:[[track year] intValue]] forKey:@"year"];
|
||||
if([track albumGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumGain]] forKey:@"replayGainAlbumGain"];
|
||||
if([track albumPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track albumPeak]] forKey:@"replayGainAlbumPeak"];
|
||||
if([track trackGain]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackGain]] forKey:@"replayGainTrackGain"];
|
||||
if([track trackPeak]) [cuesheetMetadata setValue:[NSNumber numberWithFloat:[track trackPeak]] forKey:@"replayGainTrackPeak"];
|
||||
|
||||
return [fileMetadata dictionaryByMergingWith:cuesheetMetadata];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue