// // MIDIContainer.mm // MIDI // // Created by Christopher Snowhill on 10/16/13. // Copyright 2013 __NoWork, Inc__. All rights reserved. // #import "MIDIContainer.h" #import "MIDIDecoder.h" #import #import "Logging.h" @implementation MIDIContainer + (NSArray *)fileTypes { return [MIDIDecoder fileTypes]; } + (NSArray *)mimeTypes { return [MIDIDecoder mimeTypes]; } + (float)priority { return 1.0f; } // This really should be source... + (NSArray *)urlsForContainerURL:(NSURL *)url { if([url fragment]) { // input url already has fragment defined - no need to expand further return [NSMutableArray arrayWithObject:url]; } id audioSourceClass = NSClassFromString(@"AudioSource"); id source = [audioSourceClass audioSourceForURL:url]; if(![source open:url]) return @[]; if(![source seekable]) return @[]; [source seek:0 whence:SEEK_END]; long size = [source tell]; [source seek:0 whence:SEEK_SET]; size_t track_count = 0; try { std::vector data; data.resize(size); [source read:&data[0] amount:size]; if(!midi_processor::process_track_count(data, [[url pathExtension] UTF8String], track_count)) return @[]; } catch (std::exception &e) { ALog(@"Exception caught processing MIDI track count: %s", e.what()); return @[]; } NSMutableArray *tracks = [NSMutableArray array]; long i; for(i = 0; i < track_count; i++) { [tracks addObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%li", i]]]; } return tracks; } @end