X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/0a1be7120daf3895af462672f59a2889a6c9c581..304ae643ec373b72dd98ad1cf52f09478e639a8b:/iTunesRemote.m diff --git a/iTunesRemote.m b/iTunesRemote.m index a5a1f82..5ec512b 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -54,7 +54,32 @@ - (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 @@ -113,22 +138,27 @@ 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]; - 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 @@ -136,11 +166,14 @@ 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 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 @@ -180,26 +213,25 @@ - (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:'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 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 { - 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 @@ -233,10 +265,65 @@ - (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 +{ + int result = [[ITAppleEventCenter sharedCenter] + sendTwoTierAEWithRequestedKeyForNumber:@"pShf" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; + return result; +} + +- (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]; +} + +- (ITMTRemotePlayerRepeatMode)repeatMode +{ + 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 +{ + 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]; @@ -287,7 +374,8 @@ - (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; }