diff --git a/Plugins/vgmstream/vgmstream.xcodeproj/project.pbxproj b/Plugins/vgmstream/vgmstream.xcodeproj/project.pbxproj index 6a9c2683a..27f016092 100644 --- a/Plugins/vgmstream/vgmstream.xcodeproj/project.pbxproj +++ b/Plugins/vgmstream/vgmstream.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 8340888E1F6F604C00DCD404 /* VGMMetadataReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 8340888B1F6F604A00DCD404 /* VGMMetadataReader.m */; }; 836F6B1418BDB80D0095E648 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 836F6B1318BDB80D0095E648 /* Cocoa.framework */; }; 836F6B1E18BDB80D0095E648 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 836F6B1C18BDB80D0095E648 /* InfoPlist.strings */; }; 836F705C18BDC40E0095E648 /* VGMDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 836F705B18BDC40E0095E648 /* VGMDecoder.m */; }; @@ -41,6 +42,8 @@ /* Begin PBXFileReference section */ 833F68491CDBCAC000AFB9F0 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; + 8340888B1F6F604A00DCD404 /* VGMMetadataReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VGMMetadataReader.m; sourceTree = ""; }; + 8340888D1F6F604B00DCD404 /* VGMMetadataReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VGMMetadataReader.h; sourceTree = ""; }; 836F6B1018BDB80D0095E648 /* vgmstream.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = vgmstream.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 836F6B1318BDB80D0095E648 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 836F6B1618BDB80D0095E648 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -114,15 +117,17 @@ 836F6B1918BDB80D0095E648 /* vgmstream */ = { isa = PBXGroup; children = ( - 83AA5D2F1F6E301B0020821C /* Logging.h */, + 8340888D1F6F604B00DCD404 /* VGMMetadataReader.h */, + 8340888B1F6F604A00DCD404 /* VGMMetadataReader.m */, 83AA5D2C1F6E30080020821C /* VGMContainer.h */, 83AA5D2A1F6E30080020821C /* VGMContainer.m */, 83AA5D2B1F6E30080020821C /* VGMInterface.h */, 83AA5D281F6E30080020821C /* VGMInterface.m */, 836F706118BDC8650095E648 /* PlaylistController.h */, - 836F706018BDC84D0095E648 /* Plugin.h */, 836F705A18BDC40E0095E648 /* VGMDecoder.h */, 836F705B18BDC40E0095E648 /* VGMDecoder.m */, + 83AA5D2F1F6E301B0020821C /* Logging.h */, + 836F706018BDC84D0095E648 /* Plugin.h */, 836F6B1A18BDB80D0095E648 /* Supporting Files */, ); path = vgmstream; @@ -231,6 +236,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8340888E1F6F604C00DCD404 /* VGMMetadataReader.m in Sources */, 83AA5D2D1F6E30080020821C /* VGMInterface.m in Sources */, 83AA5D2E1F6E30080020821C /* VGMContainer.m in Sources */, 836F705C18BDC40E0095E648 /* VGMDecoder.m in Sources */, diff --git a/Plugins/vgmstream/vgmstream/VGMDecoder.h b/Plugins/vgmstream/vgmstream/VGMDecoder.h index fa783a73f..77670e60b 100644 --- a/Plugins/vgmstream/vgmstream/VGMDecoder.h +++ b/Plugins/vgmstream/vgmstream/VGMDecoder.h @@ -17,8 +17,6 @@ @interface VGMDecoder : NSObject { VGMSTREAM *stream; - NSString *title; - int sampleRate; int channels; int bitrate; diff --git a/Plugins/vgmstream/vgmstream/VGMDecoder.m b/Plugins/vgmstream/vgmstream/VGMDecoder.m index 1f5732ca2..59467fd58 100644 --- a/Plugins/vgmstream/vgmstream/VGMDecoder.m +++ b/Plugins/vgmstream/vgmstream/VGMDecoder.m @@ -16,8 +16,14 @@ - (BOOL)open:(id)s { int track_num = [[[s url] fragment] intValue]; + + NSString * path = [[s url] absoluteString]; + NSRange fragmentRange = [path rangeOfString:@"#" options:NSBackwardsSearch]; + if (fragmentRange.location != NSNotFound) { + path = [path substringToIndex:fragmentRange.location]; + } - stream = init_vgmstream_from_cogfile([[[[s url] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], track_num); + stream = init_vgmstream_from_cogfile([[path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], track_num); if ( !stream ) return NO; @@ -31,12 +37,6 @@ bitrate = get_vgmstream_average_bitrate(stream); - if (stream->num_streams > 1) { - title = [NSString stringWithFormat:@"%@ - %@", [[[s url] URLByDeletingPathExtension] lastPathComponent], stream->stream_name]; - } else { - title = [[[s url] URLByDeletingPathExtension] lastPathComponent]; - } - [self willChangeValueForKey:@"properties"]; [self didChangeValueForKey:@"properties"]; @@ -53,7 +53,6 @@ [NSNumber numberWithBool:NO], @"floatingPoint", [NSNumber numberWithInt:channels], @"channels", [NSNumber numberWithBool:YES], @"seekable", - title, @"title", @"host", @"endian", nil]; } @@ -65,7 +64,7 @@ if (!repeatone) { if (framesRead >= totalFrames) return 0; else if (framesRead + frames > totalFrames) - frames = totalFrames - framesRead; + frames = (UInt32)(totalFrames - framesRead); } sample * sbuf = (sample *) buf; diff --git a/Plugins/vgmstream/vgmstream/VGMMetadataReader.h b/Plugins/vgmstream/vgmstream/VGMMetadataReader.h new file mode 100644 index 000000000..67cad9034 --- /dev/null +++ b/Plugins/vgmstream/vgmstream/VGMMetadataReader.h @@ -0,0 +1,17 @@ +// +// VGMMetadataReader.h +// VGMStream +// +// Created by Christopher Snowhill on 9/18/17. +// Copyright 2017 __LoSnoCo__. All rights reserved. +// + +#import + +#import "Plugin.h" + +@interface VGMMetadataReader : NSObject { + +} + +@end diff --git a/Plugins/vgmstream/vgmstream/VGMMetadataReader.m b/Plugins/vgmstream/vgmstream/VGMMetadataReader.m new file mode 100644 index 000000000..8a0cf2466 --- /dev/null +++ b/Plugins/vgmstream/vgmstream/VGMMetadataReader.m @@ -0,0 +1,58 @@ +// +// VGMMetadataReader.m +// VGMStream +// +// Created by Christopher Snowhill on 9/18/17. +// Copyright 2017 __LoSnoCo__. All rights reserved. +// + +#import "VGMMetadataReader.h" +#import "VGMDecoder.h" +#import "VGMInterface.h" + +@implementation VGMMetadataReader + ++ (NSArray *)fileTypes +{ + return [VGMDecoder fileTypes]; +} + ++ (NSArray *)mimeTypes +{ + return [VGMDecoder mimeTypes]; +} + ++ (float)priority +{ + return [VGMDecoder priority]; +} + ++ (NSDictionary *)metadataForURL:(NSURL *)url +{ + int track_num = [[url fragment] intValue]; + + NSString * path = [url absoluteString]; + NSRange fragmentRange = [path rangeOfString:@"#" options:NSBackwardsSearch]; + if (fragmentRange.location != NSNotFound) { + path = [path substringToIndex:fragmentRange.location]; + } + + VGMSTREAM * stream = init_vgmstream_from_cogfile([[path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], track_num); + if ( !stream ) + return nil; + + NSString * title; + + if ( stream->num_streams > 1 ) { + title = [NSString stringWithFormat:@"%@ - %s", [[url URLByDeletingPathExtension] lastPathComponent], stream->stream_name]; + } else { + title = [[url URLByDeletingPathExtension] lastPathComponent]; + } + + return [NSDictionary dictionaryWithObjectsAndKeys: + title, @"title", + track_num, @"track", + nil]; +} + +@end