Added fast forward and rewind. Player state. More key equivalents.
authorKent Sutherland <ksuther@ithinksw.com>
Sat, 15 Feb 2003 10:49:58 +0000 (10:49 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Sat, 15 Feb 2003 10:49:58 +0000 (10:49 +0000)
English.lproj/KeyCodes.plist
ITMTRemote.h
ITMTRemote.m
MenuTunes.m
iTunesRemote.m

index 7856ab6..b053008 100755 (executable)
@@ -50,7 +50,7 @@
        49 = "Space";
        50 = "\`";
        51 = "Delete";
-       53 = "ESC";
+       53 = "Escape";
        55 = "Command";
        56 = "Shift";
        57 = "Caps Lock";
index 9b36236..735e11e 100755 (executable)
@@ -28,6 +28,8 @@
 
 #import <Cocoa/Cocoa.h>
 
+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;
 - (BOOL)pause;
 - (BOOL)goToNextSong;
 - (BOOL)goToPreviousSong;
+- (BOOL)fastForward;
+- (BOOL)rewind;
 
 - (BOOL)switchToPlaylistAtIndex:(int)index;
 - (BOOL)switchToSongAtIndex:(int)index;
index 48058a9..a8270c6 100755 (executable)
     return NO;
 }
 
+- (PlayerState)playerState
+{
+    return stopped;
+}
+
 - (NSArray *)playlists
 {
     return nil;
     return NO;
 }
 
+- (BOOL)fastForward
+{
+    return NO;
+}
+
+- (BOOL)rewind
+{
+    return NO;
+}
+
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
     return NO;
index 31509a1..ca96f36 100755 (executable)
@@ -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]];
     }
 }
index 14e1ba3..8745044 100755 (executable)
     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;
     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: