Added -artists and -albums methods to the iTunes remote. Added an artists
[MenuTunes.git] / iTunesRemote.m
index 41afb6d..b4479a9 100755 (executable)
     }
     
     for (k = 1; k <= numSources ; k++) {
-        const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cPly'), '----':obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() }",k] eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+        const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cPly'), '----':obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() }",k] eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];;
         unsigned long fourcc = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
         NSString *sourceName = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
         unsigned long index = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pidx'), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } }",k] eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
     return [allSources autorelease];
 }
 
+- (NSArray *)artists
+{
+    NSAppleEventDescriptor *rawr = ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pArt'), from:obj { form:'indx', want:type('cTrk'), seld:abso($616C6C20$), from:obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:() } } } }", 'core', 'getd', &savedPSN);
+    int i;
+    NSMutableArray *array = [[NSMutableArray alloc] init];
+    NSArray *returnArray;
+    for (i = 1; i <= [rawr numberOfItems]; i++) {
+        NSString *artist = [[rawr descriptorAtIndex:i] stringValue];
+        if (artist && [artist length] && ![array containsObject:artist]) {
+            [array addObject:artist];
+        }
+    }
+    [array sortUsingSelector:@selector(caseInsensitiveCompare:)];
+    returnArray = [NSArray arrayWithArray:array];
+    [array release];
+    return returnArray;
+}
+
+- (NSArray *)albums
+{
+    NSAppleEventDescriptor *rawr = ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pAlb'), from:obj { form:'indx', want:type('cTrk'), seld:abso($616C6C20$), from:obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:() } } } }", 'core', 'getd', &savedPSN);
+    int i;
+    NSMutableArray *array = [[NSMutableArray alloc] init];
+    NSArray *returnArray;
+    for (i = 1; i <= [rawr numberOfItems]; i++) {
+        NSString *album = [[rawr descriptorAtIndex:i] stringValue];
+        if (album && [album length] && ![array containsObject:album]) {
+            [array addObject:album];
+        }
+    }
+    [array sortUsingSelector:@selector(caseInsensitiveCompare:)];
+    returnArray = [NSArray arrayWithArray:array];
+    [array release];
+    return returnArray;
+}
+
 - (int)numberOfSongsInPlaylistAtIndex:(int)index
 {
     int temp1;