Configurable MPlayer slave keys (was Featurerequest mplayer-plugin)

Message ID dauahh$kb0$2@video.local.muempf.de
State New
Headers

Commit Message

Stefan Huelswitt July 11, 2005, 5:33 p.m. UTC
  On 08 Jul 2005 s.huelswitt@gmx.de (Stefan Huelswitt) wrote:
> 
> Proposal:
> 
> We have a conf-file with "keyname text" like this:
> 
> 1 sub_delay -100
> 3 sub_delay +100
> 6 osd
> 
> This is read by the plugin and the command is send to mplayer if
> the key is pressed.
> Keys which are used by the plugin internaly cannot be mapped.

Attached is a patch which implements this (the patch is against
vanilla 0.9.12, so you shouldn't have applied the AID patch
discussed earlier).

I found that it's easier to use the plugin setup menu for
configuring the keys, so there is not conf-file.

Enter the plugin setup menu to configure the slave commands. Keys
3 & 9 are not available as they are used to move VDR's progress
display.

Please give feedback ;)

Regards.
  

Comments

Carsten Presser July 13, 2005, 4:15 p.m. UTC | #1
Stefan Huelswitt wrote:
> Enter the plugin setup menu to configure the slave commands. Keys
> 3 & 9 are not available as they are used to move VDR's progress
> display.
> 
> Please give feedback ;)

works fine for me. not just fine: its perfect.
only thing i changed: i also freed the keys 3 & 9 for slavecommands (i 
have no need in moving the progressbar).

Carsten
  

Patch

diff -urN -X mp3-unstable/.exclude mp3-0.9.12/i18n.c mp3-unstable/i18n.c
--- mp3-0.9.12/i18n.c	2005-02-20 21:52:04.000000000 +0100
+++ mp3-unstable/i18n.c	2005-07-09 09:49:43.000000000 +0200
@@ -2126,6 +2145,26 @@ 
     "",
 #endif
   },
+  { "Setup.MPlayer$Slave command key",
+    "Slave Kommando Taste",
+    "", // TODO
+    "", // TODO
+    "", // TODO
+    "", // TODO
+    "",
+    "", // TODO
+    "",
+    "", // TODO
+    "", 
+    "", // TODO
+    "",
+    "", // TODO
+    "", // TODO
+    "",
+#if VDRVERSNUM >= 10302
+    "",
+#endif
+  },
   { "MPlayer Audio ID",
     "MPlayer Audio ID",
     "", // TODO
diff -urN -X mp3-unstable/.exclude mp3-0.9.12/mplayer.c mp3-unstable/mplayer.c
--- mp3-0.9.12/mplayer.c	2005-02-21 18:30:01.000000000 +0100
+++ mp3-unstable/mplayer.c	2005-07-11 18:46:00.000000000 +0200
@@ -71,6 +76,13 @@ 
   res[2]=tr("local first");
   Add(new cMenuEditStraItem(tr("Setup.MPlayer$Resume mode"),   &data.ResumeMode, 3, res));
   Add(new cMenuEditBoolItem(tr("Hide mainmenu entry"),         &data.HideMainMenu));
+  for(int i=0; i<10; i++) {
+    if(i==3 || i==9) continue;
+    char name[32];
+    snprintf(name,sizeof(name),"%s %d",tr("Setup.MPlayer$Slave command key"),i);
+    static const char allowed[] = { "abcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?{}[]\\+*~#',;.:-_<>|@Ž`^°" };
+    Add(new cMenuEditStrItem(name, data.KeyCmd[i],MAX_KEYCMD,allowed));
+    }
 }
 
 void cMenuSetupMPlayer::Store(void)
@@ -79,6 +91,12 @@ 
   SetupStore("ControlMode", MPlayerSetup.SlaveMode);
   SetupStore("HideMainMenu",MPlayerSetup.HideMainMenu);
   SetupStore("ResumeMode",  MPlayerSetup.ResumeMode);
+  for(int i=0; i<10; i++) {
+    if(i==3 || i==9) continue;
+    char name[16];
+    snprintf(name,sizeof(name),"KeyCmd%d",i);
+    SetupStore(name,MPlayerSetup.KeyCmd[i]);
+    }
 }
 
 // --- cMPlayerControl ---------------------------------------------------------
@@ -458,26 +476,30 @@ 
           case kOk: if(visible && !modeOnly) { Hide(); DoShowMode=true; }
                     else ShowTimed();
                     break;
-          case k0:  player->DvdNav(navMenu); break;
-          case k1:  player->AudioDelay(1); break;
-          case k2:  player->DvdNav(navUp); break;
           case k3:  if(visible && !modeOnly) {
                       Hide();
                       osdPos--; if(osdPos<-6) osdPos=-6;
                       ShowTimed();
                       }
                     break;
-          case k4:  player->DvdNav(navLeft); break;
-          case k5:  player->DvdNav(navSelect); break;
-          case k6:  player->DvdNav(navRight); break;
-          case k7:  player->AudioDelay(-1); break;
-          case k8:  player->DvdNav(navDown); break;
           case k9:  if(visible && !modeOnly) {
                       Hide();
                       osdPos++; if(osdPos>0) osdPos=0;
                       ShowTimed();
                       }
                     break;
+          case k0:
+          case k1:
+          case k2:
+          case k4:
+          case k5:
+          case k6:
+          case k7:
+          case k8:  {
+                    const char *cmd=MPlayerSetup.KeyCmd[Key-k0];
+                    if(cmd[0]) player->KeyCmd(cmd);
+                    }
+                    break;
           default:  break;
           }
         break;
@@ -499,7 +521,7 @@ 
 cMenuMPlayAid::cMenuMPlayAid(void)
 :cOsdMenu(tr("MPlayer Audio ID"),20)
 {
-  Add(new cMenuEditIntItem(tr("Audiostream ID"),&MPlayerAid,0,255));
+  Add(new cMenuEditIntItem(tr("Audiostream ID"),&MPlayerAid,-1,255));
   Display();
 }
 
@@ -538,7 +563,7 @@ 
 void cMenuMPlayBrowse::SetButtons(void)
 {
   static char blue[12];
-  snprintf(blue,sizeof(blue),"AID:%d",MPlayerAid);
+  snprintf(blue,sizeof(blue),MPlayerAid>=0 ? "AID:%d" : "AID:def",MPlayerAid);
   SetHelp(tr("Play"), MPlayerSetup.ResumeMode ? tr("Rewind"):0, tr("Source"), blue);
   Display();
 }
@@ -713,6 +763,8 @@ 
   if(      !strcasecmp(Name, "ControlMode"))  MPlayerSetup.SlaveMode    = atoi(Value);
   else if (!strcasecmp(Name, "HideMainMenu")) MPlayerSetup.HideMainMenu = atoi(Value);
   else if (!strcasecmp(Name, "ResumeMode"))   MPlayerSetup.ResumeMode   = atoi(Value);
+  else if (!strncasecmp(Name, "KeyCmd", 6) && strlen(Name)==7 && isdigit(Name[6]))
+    strn0cpy(MPlayerSetup.KeyCmd[Name[6]-'0'],Value,sizeof(MPlayerSetup.KeyCmd[0]));
   else return false;
   return true;
 }
diff -urN -X mp3-unstable/.exclude mp3-0.9.12/player-mplayer.c mp3-unstable/player-mplayer.c
--- mp3-0.9.12/player-mplayer.c	2005-01-12 18:07:22.000000000 +0100
+++ mp3-unstable/player-mplayer.c	2005-07-09 09:27:58.000000000 +0200
@@ -48,7 +49,7 @@ 
 #define MPLAYER_2_VDR(x) (MIN((int)((x)*2.55),255))
 
 const char *MPlayerCmd = "mplayer.sh";
-int MPlayerAid=0;
+int MPlayerAid=-1;
 
 // -- cMPlayerStatus -----------------------------------------------------------
 
@@ -378,7 +380,7 @@ 
 
     char cmd[64+PATH_MAX*2], aid[20];
     char *fname=Quote(file->FullPath());
-    if(MPlayerAid>0) snprintf(aid,sizeof(aid)," AID %d",MPlayerAid);
+    if(MPlayerAid>=0) snprintf(aid,sizeof(aid)," AID %d",MPlayerAid);
     else aid[0]=0;
     snprintf(cmd,sizeof(cmd),"%s \"%s\" %s%s",MPlayerCmd,fname,MPlayerSetup.SlaveMode?"SLAVE":"",aid);
     free(fname);
@@ -597,32 +626,9 @@ 
     }
 }
 
-void cMPlayerPlayer::Osd(void)
-{
-  if(slave) {
-    MPlayerControl("osd");
-    }
-}
-
-void cMPlayerPlayer::AudioDelay(int del)
-{
-  if(slave) {
-    MPlayerControl("audio_delay %+.1f",(float)del/10.0);
-    }
-}
-
-void cMPlayerPlayer::DvdNav(eDvdNav mode)
+void cMPlayerPlayer::KeyCmd(const char *cmd)
 {
-  if(slave) {
-    switch(mode) {
-      case navUp:     MPlayerControl("dvdnav 1"); break;
-      case navDown:   MPlayerControl("dvdnav 2"); break;
-      case navLeft:   MPlayerControl("dvdnav 3"); break;
-      case navRight:  MPlayerControl("dvdnav 4"); break;
-      case navMenu:   MPlayerControl("dvdnav 5"); break;
-      case navSelect: MPlayerControl("dvdnav 6"); break;
-      }
-    }
+  if(slave) MPlayerControl(cmd);
 }
 
 bool cMPlayerPlayer::GetIndex(int &Current, int &Total, bool SnapToIFrame)
diff -urN -X mp3-unstable/.exclude mp3-0.9.12/player-mplayer.h mp3-unstable/player-mplayer.h
--- mp3-0.9.12/player-mplayer.h	2005-01-09 13:33:23.000000000 +0100
+++ mp3-unstable/player-mplayer.h	2005-07-09 09:27:14.000000000 +0200
@@ -48,8 +48,6 @@ 
 
 // ----------------------------------------------------------------
 
-enum eDvdNav { navUp, navDown, navLeft, navRight, navMenu, navSelect };
-
 class cMPlayerPlayer : public cPlayer, cThread {
 private:
   cFileObj *file;
@@ -80,9 +79,7 @@ 
   void Play(void);
   void Goto(int Index, bool percent, bool still);
   void SkipSeconds(int secs);
-  void Osd(void);
-  void AudioDelay(int del);
-  void DvdNav(eDvdNav mode);
+  void KeyCmd(const char *cmd);
   virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame);
   virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
   };
diff -urN -X mp3-unstable/.exclude mp3-0.9.12/setup-mplayer.c mp3-unstable/setup-mplayer.c
--- mp3-0.9.12/setup-mplayer.c	2005-01-09 13:13:00.000000000 +0100
+++ mp3-unstable/setup-mplayer.c	2005-07-11 18:54:02.000000000 +0200
@@ -19,6 +19,8 @@ 
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
+#include <string.h>
+
 #include "common.h"
 #include "setup-mplayer.h"
 
@@ -31,4 +33,8 @@ 
   SlaveMode = 0;
   ResumeMode = 2;
   HideMainMenu = 0;
+  memset(KeyCmd,0,sizeof(KeyCmd));
+  strcpy(KeyCmd[1],"audio_delay +0.1");
+  strcpy(KeyCmd[7],"audio_delay -0.1");
+  strcpy(KeyCmd[4],"switch_audio");
 }
diff -urN -X mp3-unstable/.exclude mp3-0.9.12/setup-mplayer.h mp3-unstable/setup-mplayer.h
--- mp3-0.9.12/setup-mplayer.h	2005-01-09 13:12:01.000000000 +0100
+++ mp3-unstable/setup-mplayer.h	2005-07-09 09:26:34.000000000 +0200
@@ -26,11 +26,14 @@ 
 
 // ----------------------------------------------------------------
 
+#define MAX_KEYCMD 32
+
 class cMPlayerSetup {
 public:
   int SlaveMode;
   int ResumeMode;
   int HideMainMenu;
+  char KeyCmd[10][MAX_KEYCMD];
 public:
   cMPlayerSetup(void);
   };