From: Kent Sutherland Date: Sat, 15 Feb 2003 10:49:58 +0000 (+0000) Subject: Added fast forward and rewind. Player state. More key equivalents. X-Git-Tag: v1.0~238 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/8c2086efaf1ee7419fc91275fdc7426de3fbe7fd Added fast forward and rewind. Player state. More key equivalents. --- diff --git a/English.lproj/KeyCodes.plist b/English.lproj/KeyCodes.plist index 7856ab6..b053008 100755 --- a/English.lproj/KeyCodes.plist +++ b/English.lproj/KeyCodes.plist @@ -50,7 +50,7 @@ 49 = "Space"; 50 = "\`"; 51 = "Delete"; - 53 = "ESC"; + 53 = "Escape"; 55 = "Command"; 56 = "Shift"; 57 = "Caps Lock"; diff --git a/ITMTRemote.h b/ITMTRemote.h index 9b36236..735e11e 100755 --- a/ITMTRemote.h +++ b/ITMTRemote.h @@ -28,6 +28,8 @@ #import +typedef enum {stopped = -1, paused, playing, rewinding, forwarding} PlayerState; + /*! @protocol ITMTRemote * @abstract Declares what a MenuTunes Remote must be able to do. * @discussion A MenuTunes Remote must be able to return and change state information. @@ -77,6 +79,8 @@ */ - (BOOL)halt; +- (PlayerState)playerState; + - (NSArray *)playlists; - (int)numberOfSongsInPlaylistAtIndex:(int)index; - (NSString *)classOfPlaylistAtIndex:(int)index; @@ -99,6 +103,8 @@ - (BOOL)pause; - (BOOL)goToNextSong; - (BOOL)goToPreviousSong; +- (BOOL)fastForward; +- (BOOL)rewind; - (BOOL)switchToPlaylistAtIndex:(int)index; - (BOOL)switchToSongAtIndex:(int)index; diff --git a/ITMTRemote.m b/ITMTRemote.m index 48058a9..a8270c6 100755 --- a/ITMTRemote.m +++ b/ITMTRemote.m @@ -33,6 +33,11 @@ return NO; } +- (PlayerState)playerState +{ + return stopped; +} + - (NSArray *)playlists { return nil; @@ -123,6 +128,16 @@ return NO; } +- (BOOL)fastForward +{ + return NO; +} + +- (BOOL)rewind +{ + return NO; +} + - (BOOL)switchToPlaylistAtIndex:(int)index { return NO; diff --git a/MenuTunes.m b/MenuTunes.m index 31509a1..ca96f36 100755 --- a/MenuTunes.m +++ b/MenuTunes.m @@ -770,6 +770,7 @@ andEventID:(AEEventID)eventID - (void)playPause:(id)sender { NSString *state = [self runScriptAndReturnResult:@"return player state"]; + NSLog(@"%i", [currentRemote playerState]); if ([state isEqualToString:@"playing"]) { [currentRemote play]; [playPauseMenuItem setTitle:@"Play"]; @@ -795,21 +796,25 @@ isEqualToString:@"rewinding"]) { - (void)fastForward:(id)sender { - [self sendAEWithEventClass:'hook' andEventID:'Fast']; + [currentRemote fastForward]; } - (void)rewind:(id)sender { - [self sendAEWithEventClass:'hook' andEventID:'Rwnd']; + [currentRemote rewind]; } +// +// // Plugin independent selectors - +// +// - (void)quitMenuTunes:(id)sender { [NSApp terminate:self]; } +//How is this going to work, now that we're pluginized? - (void)openiTunes:(id)sender { [[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"]; @@ -957,25 +962,39 @@ isEqualToString:@"rewinding"]) { switch (code) { case 36: + charcode = '\r'; break; case 48: + charcode = '\t'; break; + //Space -- ARGH! case 49: + { + /*MenuRef menuRef = _NSGetCarbonMenu([item menu]); + NSLog(@"%@", menuRef); + SetMenuItemCommandKey(menuRef, 0, NO, 49); + SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier); + SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph); + charcode = 'b';*/ + } break; case 51: charcode = NSDeleteFunctionKey; break; - + case 53: + charcode = '\e'; break; - + case 71: + charcode = '\e'; break; case 76: + charcode = '\r'; break; case 96: @@ -1031,6 +1050,7 @@ isEqualToString:@"rewinding"]) { break; case 115: + charcode = NSHomeFunctionKey; break; case 116: @@ -1088,7 +1108,7 @@ isEqualToString:@"rewinding"]) { keyTrans = KeyTranslate(kchr, code, &state); charCode = keyTrans; [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]]; - } else { + } else if (charcode != 'b') { [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]]; } } diff --git a/iTunesRemote.m b/iTunesRemote.m index 14e1ba3..8745044 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -42,6 +42,25 @@ return YES; } +- (PlayerState)playerState +{ + NSString *result = [self runScriptAndReturnResult:@"get player state"]; + + if ([result isEqualToString:@"playing"]) { + return playing; + } else if ([result isEqualToString:@"paused"]) { + return paused; + } else if ([result isEqualToString:@"stopped"]) { + return stopped; + } else if ([result isEqualToString:@"rewinding"]) { + return rewinding; + } else if ([result isEqualToString:@"fast forwarding"]) { + return forwarding; + } + + return stopped; +} + - (NSArray *)playlists { int i; @@ -199,6 +218,21 @@ return YES; } +- (BOOL)fastForward +{ + [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" + appPSN:[self iTunesPSN]]; + return YES; +} + +- (BOOL)rewind +{ + [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Rwnd" + appPSN:[self iTunesPSN]]; + return YES; +} + + - (BOOL)switchToPlaylistAtIndex:(int)index { [self runScriptAndReturnResult:[NSString stringWithFormat: