X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/e980fa37a154b26625b8e9472bfd5404bde0aa85..701d53006945f9cf890e9b3d554f493d81f66640:/iTunesRemote.m diff --git a/iTunesRemote.m b/iTunesRemote.m index b89ccec..1ab3043 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -25,10 +25,6 @@ - (BOOL)begin { iTunesPSN = [self iTunesPSN]; - - [[[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; } @@ -72,12 +68,13 @@ - (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 + [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pisf'), from:'null'() }" eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN]; + // Still have to convert these to AEs: // set visible of browser window 1 to true + [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:true($$), ----:obj { form:'prop', want:'prop', seld:'pvis', from:obj { form:'indx', want:'cBrW', seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN]; // set minimized of browser window 1 to false - // set view of browser window 1 to (playlist (index of current playlist)) - //end tell + [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:fals($$), ----:obj { form:'prop', want:'prop', seld:'pMin', from:obj { form:'indx', want:'cBrW', seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN]; + return NO; } @@ -165,9 +162,19 @@ 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]; } +- (int)currentAlbumTrackCount +{ + return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrC" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; +} + +- (int)currentSongTrack +{ + return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrN" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; +} + - (NSString *)currentSongUniqueIdentifier { - return @"BBQ"; + return [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]]; } - (int)currentSongIndex @@ -213,7 +220,7 @@ - (float)currentSongRating { return [[ITAppleEventCenter sharedCenter] - sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN] / 100; + sendTwoTierAEWithRequestedKeyForNumber:@"pRte" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN] / 100.0; } - (BOOL)setCurrentSongRating:(float)rating @@ -222,16 +229,18 @@ return YES; } -- (BOOL)equalizerEnabled +/* - (BOOL)equalizerEnabled { - return [[ITAppleEventCenter sharedCenter] - sendAEWithRequestedKeyForNumber:@"pEQ " eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; + int thingy = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:type('prop'), want:type('prop'), seld:type('pEQ '), from:() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; + NSLog(@"Debug equalizerEnabled: %i", thingy); + return thingy; } - (BOOL)setEqualizerEnabled:(BOOL)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:iTunesPSN]; -} + [[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]; + return YES; +} */ - (NSArray *)eqPresets { @@ -278,12 +287,13 @@ - (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]; + return YES; } - (ITMTRemotePlayerRepeatMode)repeatMode { - FourCharCode m00f; - int result; + FourCharCode m00f = 0; + int result = 0; m00f = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pRpt" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]; @@ -305,7 +315,7 @@ - (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode { - FourCharCode m00f; + FourCharCode m00f = 0; switch (repeatMode) { case ITMTRemotePlayerRepeatOff: @@ -320,7 +330,7 @@ } [[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]; - + return YES; } - (BOOL)play @@ -402,26 +412,4 @@ return number; } -- (void)applicationLaunched:(NSNotification *)note -{ - NSDictionary *info = [note userInfo]; - - if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) { - iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue]; - iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue]; - - [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidLaunchNotification" object:nil]; - } -} - -- (void)applicationTerminated:(NSNotification *)note -{ - NSDictionary *info = [note userInfo]; - - if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) { - iTunesPSN.highLongOfPSN = kNoProcess; - [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidTerminateNotification" object:nil]; - } -} - @end