+ ITDebugLog(@"Player running state: 0");
+ return ITMTRemotePlayerNotRunning;
+}
+
+- (ITMTRemotePlayerPlayingState)playerPlayingState
+{
+ long result;
+
+ ITDebugLog(@"Getting player playing state");
+
+ result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ switch (result)
+ {
+ case 'kPSP':
+ ITDebugLog(@"Getting player playing state done. Player state: Playing");
+ return ITMTRemotePlayerPlaying;
+ case 'kPSp':
+ ITDebugLog(@"Getting player playing state done. Player state: Paused");
+ return ITMTRemotePlayerPaused;
+ case 'kPSR':
+ ITDebugLog(@"Getting player playing state done. Player state: Rewinding");
+ return ITMTRemotePlayerRewinding;
+ case 'kPSF':
+ ITDebugLog(@"Getting player playing state done. Player state: Forwarding");
+ return ITMTRemotePlayerForwarding;
+ case 'kPSS':
+ default:
+ ITDebugLog(@"Getting player playing state done. Player state: Stopped");
+ return ITMTRemotePlayerStopped;
+ }
+ ITDebugLog(@"Getting player playing state done. Player state: Stopped");
+ return ITMTRemotePlayerStopped;
+}
+
+- (NSArray *)playlists
+{
+ unsigned long i,k;
+ const signed long numSources = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cSrc'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+ NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:1];
+
+ ITDebugLog(@"Getting playlists.");
+ 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];
+ for (i = 1; i <= numPlaylists; i++) {
+ NSString *sendStr = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cPly'), seld:long(%u), from:obj { form:'indx', want:type('cSrc'), seld:long(%u), from:() } } }",i,k];
+ NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ [playlists addObject:theObj];
+ }
+ }
+ ITDebugLog(@"Finished getting playlists.");
+ return [playlists autorelease];
+}
+
+- (int)numberOfSongsInPlaylistAtIndex:(int)index
+{
+ int temp1;
+ ITDebugLog(@"Getting number of songs in playlist at index %i", index);
+ temp1 = [[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:savedPSN];
+ ITDebugLog(@"Getting number of songs in playlist at index %i done", index);
+ return temp1;
+}
+
+- (ITMTRemotePlayerSource)currentSource
+{
+ unsigned long fourcc;
+
+ ITDebugLog(@"Getting current source.");
+
+ fourcc = (unsigned long)[[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber :[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }"] eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ switch (fourcc) {
+ case 'kTun':
+ ITDebugLog(@"Getting current source done. Source: Radio.");
+ return ITMTRemoteRadioSource;
+ break;
+ case 'kDev':
+ ITDebugLog(@"Getting current source done. Source: Generic Device.");
+ return ITMTRemoteGenericDeviceSource;
+ case 'kPod':
+ ITDebugLog(@"Getting current source done. Source: iPod.");
+ return ITMTRemoteiPodSource; //this is stupid
+ break;
+ case 'kMCD':
+ case 'kACD':
+ ITDebugLog(@"Getting current source done. Source: CD.");
+ return ITMTRemoteCDSource;
+ break;
+ case 'kUnk':
+ case 'kLib':
+ case 'kShd':
+ ITDebugLog(@"Getting current source done. Source: Shared Library.");
+ return ITMTRemoteSharedLibrarySource;
+ break;
+ default:
+ ITDebugLog(@"Getting current source done. Source: Library.");
+ return ITMTRemoteLibrarySource;
+ break;
+ }
+}
+
+- (ITMTRemotePlayerPlaylistClass)currentPlaylistClass
+{
+ int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ ITDebugLog(@"Getting current playlist class");
+ switch (realResult)
+ {
+ case 'cLiP':
+ ITDebugLog(@"Getting current playlist class done. Class: Library.");
+ return ITMTRemotePlayerLibraryPlaylist;
+ break;
+ case 'cRTP':
+ ITDebugLog(@"Getting current playlist class done. Class: Radio.");
+ return ITMTRemotePlayerRadioPlaylist;
+ break;
+ default:
+ ITDebugLog(@"Getting current playlist class done. Class: Standard playlist.");
+ return ITMTRemotePlayerPlaylist;
+ }
+}
+
+- (int)currentPlaylistIndex
+{
+ int temp1;
+ ITDebugLog(@"Getting current playlist index.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current playlist index done.");
+ return temp1;
+}
+
+- (NSString *)songTitleAtIndex:(int)index
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting song title at index %i.", index);
+ temp1 = [[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:savedPSN];
+ ITDebugLog(@"Getting song title at index %i done.", index);
+ return ( ([temp1 length]) ? temp1 : nil ) ;
+}
+
+- (int)currentAlbumTrackCount
+{
+ int temp1;
+ ITDebugLog(@"Getting current album track count.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrC" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { temp1 = 0; }
+ ITDebugLog(@"Getting current album track count done.");
+ return temp1;
+}
+
+- (int)currentSongTrack
+{
+ int temp1;
+ ITDebugLog(@"Getting current song track.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrN" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { temp1 = 0; }
+ ITDebugLog(@"Getting current song track done.");
+ return temp1;
+}
+
+- (NSString *)playerStateUniqueIdentifier
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current unique identifier.");
+ temp1 = [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]];
+ ITDebugLog(@"Getting current unique identifier done.");
+ return ( ([temp1 length]) ? temp1 : nil ) ;
+}
+
+- (int)currentSongIndex
+{
+ int temp1;
+ ITDebugLog(@"Getting current song index.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song index done.");
+ return temp1;
+}
+
+- (NSString *)currentSongTitle
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current song title.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song title done.");
+ return ( ([temp1 length]) ? temp1 : nil ) ;