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;
}
- (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];
-
+
return YES;
}
return YES;
}
-- (ITMTRemotePlayerRunningStatus)playerRunningStatus
+- (NSString *)playerFullName
+{
+ return @"iTunes";
+}
+
+- (NSString *)playerSimpleName
+{
+ return @"iTunes";
+}
+
+- (NSDictionary *)capabilities
+{
+ 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
+{
+ return NO;
+}
+
+- (ITMTRemotePlayerRunningState)playerRunningState
{
NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
int i;
int count = [apps count];
-
+
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;
}
-- (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 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
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 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
- (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
- (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
{
- [[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:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }",(long)rating*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
return YES;
}
- (BOOL)equalizerEnabled
{
- return NO;
+ return [[ITAppleEventCenter sharedCenter]
+ sendAEWithRequestedKeyForNumber:@"pEQ " eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
}
- (BOOL)setEqualizerEnabled:(BOOL)enabled
{
- return NO;
+[[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu) ----:obj { form:'prop', want:type('prop'), seld:type('pEQ '), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }",enabled] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+}
+
+- (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];
+
+ 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]
+ sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+ return result;
}
- (float)volume
return NO;
}
-- (NSArray *)eqPresets;
+- (BOOL)shuffleEnabled
{
- int i;
- long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
- NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
+ int result = [[ITAppleEventCenter sharedCenter]
+ sendTwoTierAEWithRequestedKeyForNumber:@"pShf" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+ return result;
+}
- 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];
+- (BOOL)setShuffleEnabled:(BOOL)enabled
+{
+ [[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];
}
-- (int)currentEQPresetIndex
+- (ITMTRemotePlayerRepeatMode)repeatMode
{
+ FourCharCode m00f;
int result;
- result = [[ITAppleEventCenter sharedCenter]
- sendTwoTierAEWithRequestedKeyForNumber:@"pidx"fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd"appPSN:iTunesPSN];
+ 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
+{
+ 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
{
[[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
return YES;
}
-- (BOOL)fastForward
+- (BOOL)forward
{
[[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:iTunesPSN];
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];