1 #import "iTunesRemote.h"
3 @implementation iTunesRemote
7 return [[[iTunesRemote alloc] init] autorelease];
10 - (NSString *)remoteTitle
12 return @"iTunes Remote";
15 - (NSString *)remoteInformation
17 return @"Default MenuTunes plugin to control iTunes, by iThink Software.";
20 - (NSImage *)remoteIcon
27 ITDebugLog(@"iTunesRemote begun");
28 savedPSN = [self iTunesPSN];
34 ITDebugLog(@"iTunesRemote halted");
38 - (NSString *)playerFullName
43 - (NSString *)playerSimpleName
48 - (NSDictionary *)capabilities
50 return [NSDictionary dictionaryWithObjectsAndKeys:
51 [NSNumber numberWithBool: YES], @"Remote",
52 [NSNumber numberWithBool: YES], @"Basic Track Control",
53 [NSNumber numberWithBool: YES], @"Track Information",
54 [NSNumber numberWithBool: YES], @"Track Navigation",
55 [NSNumber numberWithBool: YES], @"Upcoming Songs",
56 [NSNumber numberWithBool: YES], @"Playlists",
57 [NSNumber numberWithBool: YES], @"Volume",
58 [NSNumber numberWithBool: YES], @"Shuffle",
59 [NSNumber numberWithBool: YES], @"Repeat Modes",
60 [NSNumber numberWithBool: YES], @"Equalizer",
61 [NSNumber numberWithBool: YES], @"Track Rating",
65 - (BOOL)showPrimaryInterface
67 ITDebugLog(@"Showing player primary interface.");
68 // Still have to convert these to AEs:
69 // set minimized of browser window 1 to false
70 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(0), '----':obj { form:'prop', want:type('prop'), seld:type('pMin'), from:obj { form:'indx', want:type('cBrW'), seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
71 // set visible of browser window 1 to true
72 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pvis'), from:obj { form:'indx', want:type('cBrW'), seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
73 // Make this into AppleEvents... shouldn't be too hard, I'm just too tired to do it right now.
74 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pisf'), from:'null'() }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
75 ITDebugLog(@"Done showing player primary interface.");
79 - (ITMTRemotePlayerRunningState)playerRunningState
81 NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
83 int count = [apps count];
85 for (i = 0; i < count; i++) {
86 if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
87 ITDebugLog(@"Player running state: 1");
88 return ITMTRemotePlayerRunning;
91 ITDebugLog(@"Player running state: 0");
92 return ITMTRemotePlayerNotRunning;
95 - (ITMTRemotePlayerPlayingState)playerPlayingState
99 ITDebugLog(@"Getting player playing state");
101 result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
106 ITDebugLog(@"Getting player playing state done. Player state: Playing");
107 return ITMTRemotePlayerPlaying;
109 ITDebugLog(@"Getting player playing state done. Player state: Paused");
110 return ITMTRemotePlayerPaused;
112 ITDebugLog(@"Getting player playing state done. Player state: Rewinding");
113 return ITMTRemotePlayerRewinding;
115 ITDebugLog(@"Getting player playing state done. Player state: Forwarding");
116 return ITMTRemotePlayerForwarding;
119 ITDebugLog(@"Getting player playing state done. Player state: Stopped");
120 return ITMTRemotePlayerStopped;
122 ITDebugLog(@"Getting player playing state done. Player state: Stopped");
123 return ITMTRemotePlayerStopped;
126 - (NSArray *)playlists
129 const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
130 NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
132 ITDebugLog(@"Getting playlists.");
134 for (i = 1; i <= numPlaylists; i++) {
136 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];
137 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
138 ITDebugLog(@"Adding playlist: %@", theObj);
139 [playlists addObject:theObj];
141 ITDebugLog(@"Finished getting playlists.");
142 return [playlists autorelease];
145 - (int)numberOfSongsInPlaylistAtIndex:(int)index
148 ITDebugLog(@"Getting number of songs in playlist at index %i", index);
149 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];
150 ITDebugLog(@"Getting number of songs in playlist at index %i done", index);
154 - (ITMTRemotePlayerSource)currentSource
156 unsigned long fourcc;
158 ITDebugLog(@"Getting current source.");
160 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];
164 ITDebugLog(@"Getting current source done. Source: Radio.");
165 return ITMTRemoteRadioSource;
168 ITDebugLog(@"Getting current source done. Source: Generic Device.");
169 return ITMTRemoteGenericDeviceSource;
171 ITDebugLog(@"Getting current source done. Source: iPod.");
172 return ITMTRemoteiPodSource; //this is stupid
176 ITDebugLog(@"Getting current source done. Source: CD.");
177 return ITMTRemoteCDSource;
183 ITDebugLog(@"Getting current source done. Source: Library.");
184 return ITMTRemoteLibrarySource;
189 - (ITMTRemotePlayerPlaylistClass)currentPlaylistClass
191 int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
193 ITDebugLog(@"Getting current playlist class");
197 ITDebugLog(@"Getting current playlist class done. Class: Library.");
198 return ITMTRemotePlayerLibraryPlaylist;
201 ITDebugLog(@"Getting current playlist class done. Class: Radio.");
202 return ITMTRemotePlayerRadioPlaylist;
205 ITDebugLog(@"Getting current playlist class done. Class: Standard playlist.");
206 return ITMTRemotePlayerPlaylist;
210 - (int)currentPlaylistIndex
213 ITDebugLog(@"Getting current playlist index.");
214 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
215 ITDebugLog(@"Getting current playlist index done.");
219 - (NSString *)songTitleAtIndex:(int)index
222 ITDebugLog(@"Getting song title at index %i.", index);
223 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];
224 ITDebugLog(@"Getting song title at index %i done.", index);
225 return ( ([temp1 length]) ? temp1 : nil ) ;
228 - (int)currentAlbumTrackCount
231 ITDebugLog(@"Getting current album track count.");
232 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrC" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
233 if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { temp1 = 0; }
234 ITDebugLog(@"Getting current album track count done.");
238 - (int)currentSongTrack
241 ITDebugLog(@"Getting current song track.");
242 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrN" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
243 if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { temp1 = 0; }
244 ITDebugLog(@"Getting current song track done.");
248 - (NSString *)playerStateUniqueIdentifier
251 ITDebugLog(@"Getting current unique identifier.");
252 temp1 = [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN]];
253 ITDebugLog(@"Getting current unique identifier done.");
254 return ( ([temp1 length]) ? temp1 : nil ) ;
257 - (int)currentSongIndex
260 ITDebugLog(@"Getting current song index.");
261 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
262 ITDebugLog(@"Getting current song index done.");
266 - (NSString *)currentSongTitle
269 ITDebugLog(@"Getting current song title.");
270 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pnam" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
271 ITDebugLog(@"Getting current song title done.");
272 return ( ([temp1 length]) ? temp1 : nil ) ;
275 - (NSString *)currentSongArtist
278 ITDebugLog(@"Getting current song artist.");
279 if ( [self currentPlaylistClass] != ITMTRemotePlayerRadioPlaylist ) {
280 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pArt" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
284 ITDebugLog(@"Getting current song artist done.");
285 return ( ([temp1 length]) ? temp1 : nil ) ;
288 - (NSString *)currentSongAlbum
291 ITDebugLog(@"Getting current song album.");
292 if ( [self currentPlaylistClass] != ITMTRemotePlayerRadioPlaylist ) {
293 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pAlb" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
297 ITDebugLog(@"Getting current song album done.");
298 return ( ([temp1 length]) ? temp1 : nil ) ;
301 - (NSString *)currentSongGenre
304 ITDebugLog(@"Getting current song genre.");
305 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pGen" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
306 ITDebugLog(@"Getting current song genre done.");
307 return ( ([temp1 length]) ? temp1 : nil ) ;
310 - (NSString *)currentSongLength
314 ITDebugLog(@"Getting current song length.");
315 temp1 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
316 temp2 = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKey:@"pTim" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
317 if ( ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) || (temp1 == 'cURT') ) { temp2 = @"Continuous"; }
318 ITDebugLog(@"Getting current song length done.");
322 - (NSString *)currentSongRemaining
327 NSString *finalString;
329 ITDebugLog(@"Getting current song remaining time.");
331 duration = [[ITAppleEventCenter sharedCenter]
332 sendTwoTierAEWithRequestedKeyForNumber:@"pDur" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
333 current = [[ITAppleEventCenter sharedCenter]
334 sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
336 final = duration - current;
337 finalString = [self formatTimeInSeconds:final];
339 if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { finalString = nil; }
341 ITDebugLog(@"Getting current song remaining time done.");
346 - (NSString *)currentSongElapsed
349 NSString *finalString;
351 ITDebugLog(@"Getting current song elapsed time.");
353 final = [[ITAppleEventCenter sharedCenter]
354 sendAEWithRequestedKeyForNumber:@"pPos" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
356 finalString = [self formatTimeInSeconds:final];
357 ITDebugLog(@"Getting current song elapsed time done.");
361 - (float)currentSongRating
364 ITDebugLog(@"Getting current song rating.");
365 temp1 = ((float)[[ITAppleEventCenter sharedCenter]
366 sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:savedPSN] / 100.0);
367 if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { temp1 = -1.0; }
368 ITDebugLog(@"Getting current song rating done.");
372 - (BOOL)setCurrentSongRating:(float)rating
374 ITDebugLog(@"Setting current song rating to %f.", rating);
375 if ( [self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist ) { return NO; }
376 [[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];
377 ITDebugLog(@"Setting current song rating to %f done.", rating);
381 - (BOOL)equalizerEnabled
383 ITDebugLog(@"Getting equalizer enabled status.");
384 int thingy = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:type('prop'), want:type('prop'), seld:type('pEQ '), from:() }" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
385 ITDebugLog(@"Done getting equalizer enabled status.");
389 - (BOOL)setEqualizerEnabled:(BOOL)enabled
391 ITDebugLog(@"Setting equalizer enabled to %i.", enabled);
392 [[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];
393 ITDebugLog(@"Done setting equalizer enabled to %i.", enabled);
397 - (NSArray *)eqPresets
400 long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
401 NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
402 ITDebugLog(@"Getting EQ presets");
403 for (i = 1; i <= numPresets; i++) {
404 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];
406 ITDebugLog(@"Adding preset %@", theObj);
407 [presets addObject:theObj];
410 ITDebugLog(@"Done getting EQ presets");
411 return [presets autorelease];
414 - (int)currentEQPresetIndex
417 ITDebugLog(@"Getting current EQ preset index.");
418 result = [[ITAppleEventCenter sharedCenter]
419 sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
420 ITDebugLog(@"Getting current EQ preset index done.");
426 ITDebugLog(@"Getting volume.");
427 ITDebugLog(@"Getting volume done.");
428 return (float)[[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:savedPSN] / 100;
431 - (BOOL)setVolume:(float)volume
433 ITDebugLog(@"Setting volume to %f.", volume);
434 [[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:savedPSN];
435 ITDebugLog(@"Setting volume to %f done.", volume);
439 - (BOOL)shuffleEnabled
441 ITDebugLog(@"Getting shuffle enabled status.");
443 int result = [[ITAppleEventCenter sharedCenter]
444 sendTwoTierAEWithRequestedKeyForNumber:@"pShf" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
450 ITDebugLog(@"Getting shuffle enabled status done.");
454 - (BOOL)setShuffleEnabled:(BOOL)enabled
456 ITDebugLog(@"Set shuffle enabled to %i", enabled);
457 [[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'() } }",(unsigned long)enabled] eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
458 ITDebugLog(@"Set shuffle enabled to %i done", enabled);
462 - (ITMTRemotePlayerRepeatMode)repeatMode
464 FourCharCode m00f = 0;
466 m00f = [[ITAppleEventCenter sharedCenter]
467 sendTwoTierAEWithRequestedKeyForNumber:@"pRpt" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
468 ITDebugLog(@"Getting repeat mode.");
473 ITDebugLog(@"Repeat off");
474 result = ITMTRemotePlayerRepeatOff;
477 ITDebugLog(@"Repeat one");
478 result = ITMTRemotePlayerRepeatOne;
481 ITDebugLog(@"Repeat all");
482 result = ITMTRemotePlayerRepeatAll;
485 ITDebugLog(@"Getting repeat mode done.");
489 - (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
492 ITDebugLog(@"Setting repeat mode to %i", repeatMode);
495 case ITMTRemotePlayerRepeatOne:
498 case ITMTRemotePlayerRepeatAll:
501 case ITMTRemotePlayerRepeatOff:
506 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:'%s', '----':obj { form:'prop', want:type('prop'), seld:type('pRpt'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:() } }",m00f] eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
507 ITDebugLog(@"Setting repeat mode to %c done", m00f);
514 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:savedPSN];
515 ITDebugLog(@"Play done");
521 ITDebugLog(@"Pause");
522 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Paus" appPSN:savedPSN];
523 ITDebugLog(@"Pause done");
529 ITDebugLog(@"Go to next track");
530 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Next" appPSN:savedPSN];
531 ITDebugLog(@"Go to next track done");
535 - (BOOL)goToPreviousSong
537 ITDebugLog(@"Go to previous track");
538 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Prev" appPSN:savedPSN];
539 ITDebugLog(@"Go to previous track done");
545 ITDebugLog(@"Fast forward action");
546 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:savedPSN];
547 ITDebugLog(@"Fast forward action done");
553 ITDebugLog(@"Rewind action");
554 [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Rwnd" appPSN:savedPSN];
555 ITDebugLog(@"Rewind action done");
559 - (BOOL)switchToPlaylistAtIndex:(int)index
561 ITDebugLog(@"Switching to playlist at index %i", index);
562 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:() }",index] eventClass:@"hook" eventID:@"Play" appPSN:savedPSN];
563 ITDebugLog(@"Done switching to playlist at index %i", index);
567 - (BOOL)switchToSongAtIndex:(int)index
569 ITDebugLog(@"Switching to track at index %i", index);
570 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:() } }",index] eventClass:@"hook" eventID:@"Play" appPSN:savedPSN];
571 ITDebugLog(@"Done switching to track at index %i", index);
575 - (BOOL)switchToEQAtIndex:(int)index
577 ITDebugLog(@"Switching to EQ preset at index %i", index);
578 // index should count from 0, but itunes counts from 1, so let's add 1.
579 [self setEqualizerEnabled:YES];
580 [[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:savedPSN];
581 ITDebugLog(@"Done switching to EQ preset at index %i", index);
585 - (ProcessSerialNumber)iTunesPSN
587 /*NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
588 ProcessSerialNumber number;
590 int count = [apps count];
592 number.highLongOfPSN = kNoProcess;
594 for (i = 0; i < count; i++)
596 NSDictionary *curApp = [apps objectAtIndex:i];
598 if ([[curApp objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"])
600 number.highLongOfPSN = [[curApp objectForKey:
601 @"NSApplicationProcessSerialNumberHigh"] intValue];
602 number.lowLongOfPSN = [[curApp objectForKey:
603 @"NSApplicationProcessSerialNumberLow"] intValue];
607 ProcessSerialNumber number;
608 number.highLongOfPSN = kNoProcess;
609 number.lowLongOfPSN = 0;
610 ITDebugLog(@"Getting iTunes' PSN.");
611 while ( (GetNextProcess(&number) == noErr) )
614 if ( (CopyProcessName(&number, &name) == noErr) )
616 if ([(NSString *)name isEqualToString:@"iTunes"])
618 ITDebugLog(@"iTunes' highLongOfPSN: %lu.", number.highLongOfPSN);
619 ITDebugLog(@"iTunes' lowLongOfPSN: %lu.", number.lowLongOfPSN);
620 ITDebugLog(@"Done getting iTunes' PSN.");
623 [(NSString *)name release];
626 ITDebugLog(@"Failed getting iTunes' PSN.");
630 - (NSString*)formatTimeInSeconds:(long)seconds {
631 long final = seconds;
632 NSString *finalString;
635 finalString = [NSString stringWithFormat:@"%i:%@:%@",(final / 3600),[self zeroSixty:(int)((final % 3600) / 60)],[self zeroSixty:(int)((final % 3600) % 60)]];
637 finalString = [NSString stringWithFormat:@"%i:%@",(final / 60),[self zeroSixty:(int)(final % 60)]];
640 finalString = [NSString stringWithFormat:@"0:%@",[self zeroSixty:(int)final]];
644 - (NSString*)zeroSixty:(int)seconds {
645 if ( (seconds < 10) && (seconds > 0) ) {
646 return [NSString stringWithFormat:@"0%i",seconds];
647 } else if ( (seconds == 0) ) {
648 return [NSString stringWithFormat:@"00"];
650 return [NSString stringWithFormat:@"%i",seconds];