Added methods for shuffle and repeat modes.
[MenuTunes.git] / iTunesRemote.m
index e8b3098..0a02b1b 100755 (executable)
@@ -7,17 +7,17 @@
     return [[[iTunesRemote alloc] init] autorelease];
 }
 
     return [[[iTunesRemote alloc] init] autorelease];
 }
 
-- (NSString *)title
+- (NSString *)remoteTitle
 {
 {
-    return @"iTunes";
+    return @"iTunes Remote";
 }
 
 }
 
-- (NSString *)information;
+- (NSString *)remoteInformation
 {
 {
-    return @"Default MenuTunes plugin to control iTunes. Written by iThink Software.";
+    return @"Default MenuTunes plugin to control iTunes, by iThink Software.";
 }
 
 }
 
-- (NSImage *)icon
+- (NSImage *)remoteIcon
 {
     return nil;
 }
 {
     return nil;
 }
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
-
-    //Register for application termination in NSWorkspace
+    
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
-
+    
     return YES;
 }
 
     return YES;
 }
 
     return YES;
 }
 
     return YES;
 }
 
-- (ITMTRemotePlayerRunningStatus)playerRunningStatus
+- (NSString *)playerFullName
+{
+    return @"iTunes";
+}
+
+- (NSString *)playerSimpleName
+{
+    return @"iTunes";
+}
+
+- (NSDictionary *)capabilities
+{
+    return nil;
+}
+
+- (ITMTRemotePlayerRunningState)playerRunningState
 {
     NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
     int i;
     int count = [apps count];
 {
     NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
     int i;
     int count = [apps count];
-
+    
     for (i = 0; i < count; i++) {
     for (i = 0; i < count; i++) {
-        if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"]
-                isEqualToString:@"iTunes"]) {
+        if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
             return ITMTRemotePlayerRunning;
         }
     }
     return ITMTRemotePlayerNotRunning;
 }
 
             return ITMTRemotePlayerRunning;
         }
     }
     return ITMTRemotePlayerNotRunning;
 }
 
-- (ITMTRemotePlayerState)playerState
+- (ITMTRemotePlayerPlayingState)playerPlayingState
 {
     long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     
 {
     long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     
     long i = 0;
     const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
     long i = 0;
     const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
-
-
-          for (i = 1; i <= numPlaylists; i++) {
-                 const long j = i;
-                 NSString *sendStr = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() } }",(unsigned long)j];
-                 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-                 //NSLog(@"sent event cur %d max %d",i,numPlaylists);
-                 [playlists addObject:theObj];
-          }
-          return [playlists autorelease];
+    
+    for (i = 1; i <= numPlaylists; i++) {
+        const long j = i;
+        NSString *sendStr = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() } }",(unsigned long)j];
+        NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+        [playlists addObject:theObj];
+    }
+    return [playlists autorelease];
 }
 
 - (int)numberOfSongsInPlaylistAtIndex:(int)index
 }
 
 - (int)numberOfSongsInPlaylistAtIndex:(int)index
 
 - (NSString *)classOfPlaylistAtIndex:(int)index
 {
 
 - (NSString *)classOfPlaylistAtIndex:(int)index
 {
-    int realResult = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-
-    if (realResult == 'cRTP') return @"radio tuner playlist";
-    else return @"playlist";
+    int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    
+    if (realResult == 'cRTP') {
+        return @"radio tuner playlist";
+    } else {
+        return @"playlist";
+    }
 }
 
 - (int)currentPlaylistIndex
 {
     int result;
 }
 
 - (int)currentPlaylistIndex
 {
     int result;
-    result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
     return result;
 }
 
     return YES;
 }
 
     return YES;
 }
 
-- (float)volume
+- (BOOL)equalizerEnabled
 {
 {
-    long vol = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-    return vol / 100;
+    return NO;
 }
 
 }
 
-- (BOOL)setVolume:(float)volume
+- (BOOL)setEqualizerEnabled:(BOOL)enabled
 {
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pVol'), from:'null'() }",(long)volume*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
     return NO;
 }
 
     return NO;
 }
 
-- (NSArray *)eqPresets;
+- (NSArray *)eqPresets
 {
     int i;
     long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
 {
     int i;
     long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
-
-          for (i = 1; i <= numPresets; i++) {
-                 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-                 if (theObj) [presets addObject:theObj];
-          }
-          return [presets autorelease];
+    
+    for (i = 1; i <= numPresets; i++) {
+        NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+        if (theObj) {
+            [presets addObject:theObj];
+        }
+    }
+    return [presets autorelease];
 }
 
 - (int)currentEQPresetIndex
 {
     int result;
     result = [[ITAppleEventCenter sharedCenter]
 }
 
 - (int)currentEQPresetIndex
 {
     int result;
     result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx"fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd"appPSN:iTunesPSN];
+                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
     return result;
 }
 
+- (float)volume
+{
+    long vol = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    return vol / 100;
+}
+
+- (BOOL)setVolume:(float)volume
+{
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pVol'), from:'null'() }",(long)volume*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    return NO;
+}
+
+- (BOOL)shuffleEnabled
+{
+    return NO;
+}
+
+- (BOOL)setShuffleEnabled:(BOOL)enabled
+{
+    return NO;
+}
+
+- (ITMTRemotePlayerRepeatMode)repeatMode
+{
+    return ITMTRemotePlayerRepeatOff;
+}
+
+- (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
+{
+    return NO;
+}
+
 - (BOOL)play
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
 - (BOOL)play
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
     return YES;
 }
 
     return YES;
 }
 
-- (BOOL)fastForward
+- (BOOL)forward
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:iTunesPSN];
     return YES;
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:iTunesPSN];
     return YES;
     return YES;
 }
 
     return YES;
 }
 
-
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:() }",index] eventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:() }",index] eventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];