+ }
+ 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
+{
+ long i = 0;
+ const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+ NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
+
+ ITDebugLog(@"Getting playlists.");
+
+ 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:savedPSN];
+ ITDebugLog(@"Adding playlist: %@", theObj);
+ [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':
+ 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];
+ 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];
+ 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 ) ;
+}
+
+- (NSString *)currentSongArtist
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current song artist.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song artist done.");
+ return ( ([temp1 length]) ? temp1 : nil ) ;
+}
+
+- (NSString *)currentSongAlbum
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current song album.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song album done.");
+ return ( ([temp1 length]) ? temp1 : nil ) ;
+}
+
+- (NSString *)currentSongGenre
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current song genre.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song genre done.");
+ return ( ([temp1 length]) ? temp1 : nil ) ;
+}
+
+- (NSString *)currentSongLength
+{
+ NSString *temp1;
+ ITDebugLog(@"Getting current song length.");
+ temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pTim" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Getting current song length done.");
+ return temp1;
+}
+
+- (NSString *)currentSongRemaining
+{
+ long duration;
+ long current;
+ long final;
+ NSString *finalString;
+
+ ITDebugLog(@"Getting current song remaining time.");
+
+ duration = [[ITAppleEventCenter sharedCenter]
+ sendTwoTierAEWithRequestedKeyForNumber:@"pDur" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ current = [[ITAppleEventCenter sharedCenter]
+ sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ final = duration - current;
+ finalString = [self formatTimeInSeconds:final];
+
+ ITDebugLog(@"Getting current song remaining time done.");
+
+ return finalString;
+}
+
+- (NSString *)currentSongElapsed
+{
+ long final;
+ NSString *finalString;
+
+ ITDebugLog(@"Getting current song elapsed time.");
+
+ final = [[ITAppleEventCenter sharedCenter]
+ sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ finalString = [self formatTimeInSeconds:final];
+ ITDebugLog(@"Getting current song elapsed time done.");
+ return finalString;
+}
+
+- (float)currentSongRating
+{
+ float temp1;
+ ITDebugLog(@"Getting current song rating.");
+ temp1 = ((float)[[ITAppleEventCenter sharedCenter]
+ sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN] / 100.0);
+ ITDebugLog(@"Getting current song rating done.");
+ return temp1;
+}
+
+- (BOOL)setCurrentSongRating:(float)rating
+{
+ ITDebugLog(@"Setting current song rating to %f.", rating);
+ [[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:savedPSN];
+ ITDebugLog(@"Setting current song rating to %f done.", rating);
+ return YES;
+}
+
+- (BOOL)equalizerEnabled
+{
+ ITDebugLog(@"Getting equalizer enabled status.");
+ int thingy = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:type('prop'), want:type('prop'), seld:type('pEQ '), from:() }" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Done getting equalizer enabled status.");
+ return thingy;
+}
+
+- (BOOL)setEqualizerEnabled:(BOOL)enabled
+{
+ ITDebugLog(@"Setting equalizer enabled to %i.", enabled);
+ [[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:savedPSN];
+ ITDebugLog(@"Done setting equalizer enabled to %i.", enabled);
+ return YES;
+}
+
+- (NSArray *)eqPresets
+{
+ int i;
+ long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+ NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
+ ITDebugLog(@"Getting EQ presets");
+ 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:savedPSN];
+ if (theObj) {
+ ITDebugLog(@"Adding preset %@", theObj);
+ [presets addObject:theObj];