New Icon :-). I heard Matt's working on yet another revision, but we
[MenuTunes.git] / iTunesRemote.m
index 0a02b1b..5ec512b 100755 (executable)
 
 - (NSDictionary *)capabilities
 {
 
 - (NSDictionary *)capabilities
 {
-    return nil;
+    return [NSDictionary dictionaryWithObjectsAndKeys:
+                [NSNumber numberWithBool: YES], @"Remote",
+                [NSNumber numberWithBool: YES], @"Basic Track Control",
+                [NSNumber numberWithBool: YES], @"Track Information",
+                [NSNumber numberWithBool: YES], @"Track Navigation",
+                [NSNumber numberWithBool: YES], @"Upcoming Songs",
+                [NSNumber numberWithBool: YES], @"Playlists",
+                [NSNumber numberWithBool: YES], @"Volume",
+                [NSNumber numberWithBool: YES], @"Shuffle",
+                [NSNumber numberWithBool: YES], @"Repeat Modes",
+                [NSNumber numberWithBool: YES], @"Equalizer",
+                [NSNumber numberWithBool: YES], @"Track Rating",
+                nil];
+}
+
+- (BOOL)showPrimaryInterface
+{
+    // Make this into AppleEvents... shouldn't be too hard, I'm just too tired to do it right now.
+    //tell application "iTunes"
+    // set frontmost to true
+    // set visible of browser window 1 to true
+    // set minimized of browser window 1 to false
+    // set view of browser window 1 to (playlist (index of current playlist))
+    //end tell
+    //Someone do this plz kthx
+    return NO;
 }
 
 - (ITMTRemotePlayerRunningState)playerRunningState
 }
 
 - (ITMTRemotePlayerRunningState)playerRunningState
     return [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() }",index] eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
 }
 
     return [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() }",index] eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
 }
 
-- (NSString *)classOfPlaylistAtIndex:(int)index
+- (ITMTRemotePlayerPlaylistClass)classOfPlaylistAtIndex:(int)index
 {
     int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     
 {
     int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     
-    if (realResult == 'cRTP') {
-        return @"radio tuner playlist";
-    } else {
-        return @"playlist";
-    }
+
+    switch (realResult)
+          {
+          case 'cLiP':
+                 return ITMTRemotePlayerLibraryPlaylist;
+                 break;
+          case 'cRTP':
+                 return ITMTRemotePlayerRadioPlaylist;
+                 break;
+          default:
+                 return ITMTRemotePlayerPlaylist;
+          }
 }
 
 - (int)currentPlaylistIndex
 {
 }
 
 - (int)currentPlaylistIndex
 {
-    int result;
-    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-    return result;
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)songTitleAtIndex:(int)index
 }
 
 - (NSString *)songTitleAtIndex:(int)index
     return [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",index] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
     return [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",index] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
+- (NSString *)currentSongUniqueIdentifier
+{
+    return @"BBQ";
+}
+
 - (int)currentSongIndex
 {
 - (int)currentSongIndex
 {
-    int result;
-    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-    return result;
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
 - (NSString *)currentSongTitle
 }
 
 - (NSString *)currentSongTitle
 
 - (float)currentSongRating
 {
 
 - (float)currentSongRating
 {
-    int realResult = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-
-    return realResult / 100;
+    return [[ITAppleEventCenter sharedCenter]
+                sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN] / 100;
 }
 
 - (BOOL)setCurrentSongRating:(float)rating
 {
 }
 
 - (BOOL)setCurrentSongRating:(float)rating
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pRte'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } ",(long)rating*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), '----':obj { form:'prop', want:type('prop'), seld:type('pRte'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",(long)(rating*100),[self currentSongIndex]] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
     return YES;
 }
 
 - (BOOL)equalizerEnabled
 {
     return YES;
 }
 
 - (BOOL)equalizerEnabled
 {
-    return NO;
+    return [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:type('prop'), want:type('prop'), seld:type('pEQ '), from:() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    
 }
 
 - (BOOL)setEqualizerEnabled:(BOOL)enabled
 {
 }
 
 - (BOOL)setEqualizerEnabled:(BOOL)enabled
 {
-    return NO;
+[[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), '----':obj { form:'prop', want:type('prop'), seld:type('pEQ '), from:'null'() }",enabled] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
 }
 
 - (NSArray *)eqPresets
 }
 
 - (NSArray *)eqPresets
 
 - (BOOL)setVolume:(float)volume
 {
 
 - (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];
+    [[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)shuffleEnabled
 {
-    return NO;
+    int result = [[ITAppleEventCenter sharedCenter]
+                sendTwoTierAEWithRequestedKeyForNumber:@"pShf" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    return result;
 }
 
 - (BOOL)setShuffleEnabled:(BOOL)enabled
 {
 }
 
 - (BOOL)setShuffleEnabled:(BOOL)enabled
 {
-    return NO;
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu) ----:obj { form:'prop', want:type('prop'), seld:type('pShf'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }",enabled] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
 }
 
 - (ITMTRemotePlayerRepeatMode)repeatMode
 {
 }
 
 - (ITMTRemotePlayerRepeatMode)repeatMode
 {
-    return ITMTRemotePlayerRepeatOff;
+    FourCharCode m00f;
+    int result;
+    m00f = [[ITAppleEventCenter sharedCenter]
+                sendTwoTierAEWithRequestedKeyForNumber:@"pRpt" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+
+    switch (m00f)
+          {
+          case 'kRp0':
+                 result = ITMTRemotePlayerRepeatOff;
+                 break;
+          case 'kRp1':
+                 result = ITMTRemotePlayerRepeatOne;
+                 break;
+          case 'kRpA':
+                 result = ITMTRemotePlayerRepeatAll;
+                 break;
+          }
+    
+    return result;
 }
 
 - (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
 {
 }
 
 - (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
 {
-    return NO;
+    FourCharCode m00f;
+    switch (repeatMode)
+          {
+          case ITMTRemotePlayerRepeatOff:
+                 m00f = 'kRp0';
+                 break;
+          case ITMTRemotePlayerRepeatOne:
+                 m00f = 'kRp1';
+                 break;
+          case ITMTRemotePlayerRepeatAll:
+                 m00f = 'kRpA';
+                 break;
+          }
+
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu) ----:obj { form:'prop', want:type('pRpt'), seld:type('pShf'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }",m00f] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+
 }
 
 - (BOOL)play
 }
 
 - (BOOL)play
 
 - (BOOL)switchToEQAtIndex:(int)index
 {
 
 - (BOOL)switchToEQAtIndex:(int)index
 {
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:obj { form:'ID  ', want:type('cEQP'), seld:long(%lu), from:'null'() }, ----:obj { form:'prop', want:type('prop'), seld:type('pEQP'), from:'null'() }",index] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    // index should count from 0, but itunes counts from 1, so let's add 1.
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pEQP'), from:'null'() }, data:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() }",(index+1)] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
     return YES;
 }
 
     return YES;
 }