From bc212f3e96bf33ec3f0719a2635d8900cdca1408 Mon Sep 17 00:00:00 2001 From: vspader Date: Mon, 15 Oct 2007 22:19:14 +0000 Subject: [PATCH] Fixed bugs dealing with multi-track files and playlist saving/loading. Fixed problem where cue sheets would play static. --- FileDrawer/SmartFolderNode.m | 2 ++ Playlist/PlaylistLoader.m | 7 ++++++- Plugins/CueSheet/CueSheet.m | 27 +++++++++++++++++++-------- Plugins/CueSheet/CueSheetDecoder.h | 9 ++++++--- Plugins/CueSheet/CueSheetDecoder.m | 11 +++++------ Plugins/M3u/M3uContainer.m | 24 ++++++++++++++++++------ Plugins/Pls/PlsContainer.m | 24 ++++++++++++++++++------ TODO | 4 +++- 8 files changed, 77 insertions(+), 31 deletions(-) diff --git a/FileDrawer/SmartFolderNode.m b/FileDrawer/SmartFolderNode.m index 85a0dba71..7475a7478 100644 --- a/FileDrawer/SmartFolderNode.m +++ b/FileDrawer/SmartFolderNode.m @@ -77,6 +77,8 @@ MDQueryEnableUpdates(query); [self processPaths:results]; + + [dataSource reloadPathNode:self]; } - (void)queryUpdate:(NSNotification *)notification diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 8ac241ce0..d7be1002f 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -48,11 +48,16 @@ { NSString *basePath = [[[filename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; - if ([entryURL isFileURL] && [[entryURL fragment] isEqualToString:@""]) { + if ([entryURL isFileURL]) { //We want relative paths. NSMutableString *entryPath = [[[[entryURL path] stringByStandardizingPath] mutableCopy] autorelease]; [entryPath replaceOccurrencesOfString:basePath withString:@"" options:(NSAnchoredSearch | NSLiteralSearch | NSCaseInsensitiveSearch) range:NSMakeRange(0, [entryPath length])]; + if ([entryURL fragment]) + { + [entryPath appendString:@"#"]; + [entryPath appendString:[entryURL fragment]]; + } return entryPath; } diff --git a/Plugins/CueSheet/CueSheet.m b/Plugins/CueSheet/CueSheet.m index f34c5f2d3..9adeda960 100644 --- a/Plugins/CueSheet/CueSheet.m +++ b/Plugins/CueSheet/CueSheet.m @@ -19,24 +19,35 @@ - (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename { if ([path hasPrefix:@"/"]) { - return [NSURL fileURLWithPath:path]; + return [NSURL URLWithString:[@"file://" stringByAppendingString:path]]; } - NSRange foundRange = [path rangeOfString:@"://"]; - if (foundRange.location != NSNotFound) + NSRange protocolRange = [path rangeOfString:@"://"]; + if (protocolRange.location != NSNotFound) { return [NSURL URLWithString:path]; } - - NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; - NSMutableString *unixPath = [path mutableCopy]; + NSMutableString *unixPath = [path mutableCopy]; + //Only relative paths would have windows backslashes. [unixPath replaceOccurrencesOfString:@"\\" withString:@"/" options:0 range:NSMakeRange(0, [unixPath length])]; - return [NSURL fileURLWithPath:[basePath stringByAppendingString:[unixPath autorelease]]]; -} + NSMutableString *urlString = [[NSMutableString alloc] init]; + [urlString setString:@"file://"]; + NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; + + [urlString appendString:basePath]; + [urlString appendString:unixPath]; + + [unixPath release]; + + NSURL *url = [NSURL URLWithString:urlString]; + [urlString release]; + + return url; +} - (void)parseFile:(NSString *)filename { diff --git a/Plugins/CueSheet/CueSheetDecoder.h b/Plugins/CueSheet/CueSheetDecoder.h index 40ffe965b..3bdd5c0cb 100644 --- a/Plugins/CueSheet/CueSheetDecoder.h +++ b/Plugins/CueSheet/CueSheetDecoder.h @@ -17,9 +17,12 @@ id source; id decoder; - int bytesPerSecond; - int bytePosition; - double trackEnd; + int bytesPerFrame; //Number of bytes per frame, ie channels * (bitsPerSample/8) + int bytesPerSecond; //Number of bytes per second, ie bytesPerFrame * sampleRate + + int bytePosition; //Current position in bytes. + + double trackEnd; //Seconds until end of track. CueSheet *cuesheet; CueSheetTrack *track; diff --git a/Plugins/CueSheet/CueSheetDecoder.m b/Plugins/CueSheet/CueSheetDecoder.m index f1c27239c..ebe1621d6 100644 --- a/Plugins/CueSheet/CueSheetDecoder.m +++ b/Plugins/CueSheet/CueSheetDecoder.m @@ -81,7 +81,8 @@ int channels = [[properties objectForKey:@"channels"] intValue]; float sampleRate = [[properties objectForKey:@"sampleRate"] floatValue]; - bytesPerSecond = (int)((bitsPerSample/8) * channels * sampleRate); + bytesPerFrame = (bitsPerSample/8) * channels; + bytesPerSecond = (int)(bytesPerFrame * sampleRate); [decoder seekToTime: [track time] * 1000.0]; @@ -170,12 +171,9 @@ time += trackStartMs; bytePosition = (time/1000.0) * bytesPerSecond; - - int bitsPerSample = [[[decoder properties] objectForKey:@"bitsPerSample"] intValue]; - int channels = [[[decoder properties] objectForKey:@"channels"] intValue]; - + NSLog(@"Before: %li", bytePosition); - bytePosition -= bytePosition % (bitsPerSample/8 * channels); + bytePosition -= bytePosition % bytesPerFrame; NSLog(@"After: %li", bytePosition); return [decoder seekToTime:time]; @@ -184,6 +182,7 @@ - (int)fillBuffer:(void *)buf ofSize:(UInt32)size { long trackByteEnd = trackEnd * bytesPerSecond; + trackByteEnd -= trackByteEnd % (bytesPerFrame); if (bytePosition + size > trackByteEnd) { size = trackByteEnd - bytePosition; diff --git a/Plugins/M3u/M3uContainer.m b/Plugins/M3u/M3uContainer.m index 212681639..8873b7dd5 100644 --- a/Plugins/M3u/M3uContainer.m +++ b/Plugins/M3u/M3uContainer.m @@ -24,22 +24,34 @@ + (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename { if ([path hasPrefix:@"/"]) { - return [NSURL fileURLWithPath:path]; + return [NSURL URLWithString:[@"file://" stringByAppendingString:path]]; } - NSRange foundRange = [path rangeOfString:@"://"]; - if (foundRange.location != NSNotFound) + NSRange protocolRange = [path rangeOfString:@"://"]; + if (protocolRange.location != NSNotFound) { return [NSURL URLWithString:path]; } - - NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; + NSMutableString *unixPath = [path mutableCopy]; //Only relative paths would have windows backslashes. [unixPath replaceOccurrencesOfString:@"\\" withString:@"/" options:0 range:NSMakeRange(0, [unixPath length])]; + + NSMutableString *urlString = [[NSMutableString alloc] init]; + [urlString setString:@"file://"]; + + NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; + + [urlString appendString:basePath]; + [urlString appendString:unixPath]; + + [unixPath release]; - return [NSURL fileURLWithPath:[basePath stringByAppendingString:[unixPath autorelease]]]; + NSURL *url = [NSURL URLWithString:urlString]; + [urlString release]; + + return url; } + (NSArray *)urlsForContainerURL:(NSURL *)url diff --git a/Plugins/Pls/PlsContainer.m b/Plugins/Pls/PlsContainer.m index bf42fb438..c3c12cdb6 100644 --- a/Plugins/Pls/PlsContainer.m +++ b/Plugins/Pls/PlsContainer.m @@ -24,22 +24,34 @@ + (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename { if ([path hasPrefix:@"/"]) { - return [NSURL fileURLWithPath:path]; + return [NSURL URLWithString:[@"file://" stringByAppendingString:path]]; } - NSRange foundRange = [path rangeOfString:@"://"]; - if (foundRange.location != NSNotFound) + NSRange protocolRange = [path rangeOfString:@"://"]; + if (protocolRange.location != NSNotFound) { return [NSURL URLWithString:path]; } - - NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; + NSMutableString *unixPath = [path mutableCopy]; //Only relative paths would have windows backslashes. [unixPath replaceOccurrencesOfString:@"\\" withString:@"/" options:0 range:NSMakeRange(0, [unixPath length])]; + + NSMutableString *urlString = [[NSMutableString alloc] init]; + [urlString setString:@"file://"]; + + NSString *basePath = [[[baseFilename stringByStandardizingPath] stringByDeletingLastPathComponent] stringByAppendingString:@"/"]; + + [urlString appendString:basePath]; + [urlString appendString:unixPath]; + + [unixPath release]; - return [NSURL fileURLWithPath:[basePath stringByAppendingString:[unixPath autorelease]]]; + NSURL *url = [NSURL URLWithString:urlString]; + [urlString release]; + + return url; } + (NSArray *)urlsForContainerURL:(NSURL *)url diff --git a/TODO b/TODO index 9b91915e0..77751fa83 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,4 @@ Ensure file drawer works with metadata search (Smart folders). -Add alias support. \ No newline at end of file +Add alias support. + +Note: International nibs are now BROKEN \ No newline at end of file