Menu

[4a5ff5]: / PlayerPROKit / PPLibrary.m  Maximize  Restore  History

Download this file

151 lines (126 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// PPLibrary.m
// PPMacho
//
// Created by C.W. Betts on 10/28/12.
//
//
#import "PPLibrary.h"
#import "PPLibrary_PPKPrivate.h"
@interface PPLibraryObject ()
@property (readwrite, copy) NSString *menuName;
@property (readwrite, copy) NSString *authorString;
#if !TARGET_OS_IPHONE
@property (readwrite, strong) NSBundle *plugFile;
#endif
@property (readwrite, strong) NSString *plugType;
@property (readwrite, copy) NSArray* UTItypes;
@property (readwrite) BOOL canExport;
@property (readwrite) BOOL canImport;
@property (readwrite) UInt32 plugVersion;
@end
@implementation PPLibraryObject
- (instancetype)initWithPlugInfo:(PlugInfo*)pi
{
if (self = [super init]) {
self.menuName = (__bridge NSString *)pi->MenuName;
self.authorString = (__bridge NSString *)pi->AuthorString;
#if !TARGET_OS_IPHONE
self.plugFile = [NSBundle bundleWithURL:CFBridgingRelease(CFBundleCopyBundleURL(pi->file))];
#endif
self.plugType = [NSString stringWithCString:pi->type encoding:NSMacOSRomanStringEncoding];
self.UTItypes = (__bridge NSArray *)pi->UTItypes;
self.plugVersion = pi->version;
switch (pi->mode) {
case MADPlugImportExport:
self.canExport = YES;
self.canImport = YES;
break;
case MADPlugExport:
self.canExport = YES;
self.canImport = NO;
break;
case MADPlugImport:
default:
self.canExport = NO;
self.canImport = YES;
break;
}
}
return self;
}
- (OSType)plugMode
{
if (self.canExport && self.canImport)
return MADPlugImportExport;
else if (self.canExport)
return MADPlugExport;
else
return MADPlugImport;
}
@end
@implementation PPLibrary
@synthesize _madLib = theLibrary;
@synthesize trackerLibs;
- (instancetype)initWithPlugInCPath:(const char*)cPath
{
if (self = [super init]) {
if (MADInitLibrary(cPath, &theLibrary) != MADNoErr) {
return nil;
}
NSMutableArray *tmpArray = [NSMutableArray arrayWithCapacity:theLibrary->TotalPlug];
for (int i = 0; i < theLibrary->TotalPlug; i++) {
PPLibraryObject *tmp = [[PPLibraryObject alloc] initWithPlugInfo:&theLibrary->ThePlug[i]];
[tmpArray addObject:tmp];
}
trackerLibs = [[NSArray alloc] initWithArray:tmpArray];
}
return self;
}
- (instancetype)init
{
return [self initWithPlugInCPath:NULL];
}
- (instancetype)initWithPlugInPath:(NSString *)path
{
return [self initWithPlugInCPath:[path fileSystemRepresentation]];
}
- (instancetype)initWithPlugInURL:(NSURL *)URL
{
return [self initWithPlugInPath:[URL path]];
}
- (PPLibraryObject *)pluginAtIndex:(NSUInteger)idx
{
return trackerLibs[idx];
}
- (NSUInteger)pluginCount
{
return [trackerLibs count];
}
- (void)dealloc
{
if (theLibrary)
MADDisposeLibrary(theLibrary);
}
- (MADErr)identifyFileAtPath:(NSString*)apath type:(char*)atype
{
return [self identifyFileAtURL:[NSURL fileURLWithPath:apath] type:atype];
}
- (MADErr)identifyFileAtURL:(NSURL*)apath type:(char*)atype
{
return MADMusicIdentifyCFURL(theLibrary, atype, (__bridge CFURLRef)apath);
}
- (MADErr)getInformationFromFileAtPath:(NSString*)apath type:(char*)atype info:(PPInfoRec*)infoRec
{
return [self getInformationFromFileAtURL:[NSURL fileURLWithPath:apath] type:atype info:infoRec];
}
- (MADErr)getInformationFromFileAtURL:(NSURL*)apath type:(char*)atype info:(PPInfoRec*)infoRec
{
return MADMusicInfoCFURL(theLibrary, atype, (__bridge CFURLRef)apath, infoRec);
}
#pragma mark NSFastEnumeration protocol
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len
{
return [trackerLibs countByEnumeratingWithState:state objects:buffer count:len];
}
@end