changeset 9291:64b8c5a07c2c

- It adds an option enqueue/noenqueue, so users can choose if they want to have playlist overwritten by files on commandline or just enqueue them at the end ... - Playtree is finally cleared, as such gui has total control! - Autoplay if files are available on commandline and -enqueue is not set! - Fallback on Playlists finally does work with Gui and even with streaming Playlists! [ Before gui was broken as mplayer.c:playtree tried to have control] patch by Fabian Franz <FabianFranz@gmx.de>
author arpi
date Wed, 05 Feb 2003 23:02:35 +0000
parents 0e043196d176
children 0c9dda5f8b56
files Gui/interface.c Gui/interface.h Gui/mplayer/play.c Gui/mplayer/play.h cfg-mplayer.h mplayer.c
diffstat 6 files changed, 225 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Gui/interface.c	Wed Feb 05 23:02:05 2003 +0000
+++ b/Gui/interface.c	Wed Feb 05 23:02:35 2003 +0000
@@ -670,7 +670,7 @@
 	       break;
 #endif
 	 }
-	if ( guiIntfStruct.StreamType != STREAMTYPE_PLAYLIST )
+	//if ( guiIntfStruct.StreamType != STREAMTYPE_PLAYLIST ) // Does not make problems anymore!
 	 {	
 	  if ( guiIntfStruct.Filename ) filename=gstrdup( guiIntfStruct.Filename );
 	   else if ( filename ) guiSetFilename( guiIntfStruct.Filename,filename );
@@ -834,29 +834,68 @@
 	 } else { item->prev=item->next=NULL; plCurrent=plList=item; }
         list();
         return NULL;
-   case gtkGetNextPlItem: // get current item from playlist
+   case gtkInsertPlItem: // add item into playlist after current
 	if ( plCurrent )
 	 {
+	  plItem * curr = plCurrent;
+	  item->next=curr->next;
+	  if (item->next)
+	    item->next->prev=item;
+	  item->prev=curr;
+	  curr->next=item;
 	  plCurrent=plCurrent->next;
-	  if ( !plCurrent && plList ) 
+	  return plCurrent;
+	 }
+	 else
+	   return gtkSet(gtkAddPlItem,0,(void*)item);
+        return NULL;
+   case gtkGetNextPlItem: // get current item from playlist
+	if ( plCurrent && plCurrent->next)
+	 {
+	  plCurrent=plCurrent->next;
+	  /*if ( !plCurrent && plList ) 
 	   {
 	    plItem * next = plList;
 	    while ( next->next ) { if ( !next->next ) break; next=next->next; }
 	    plCurrent=next;
-	   }
+	   }*/
 	  return plCurrent;
 	 }
         return NULL;
    case gtkGetPrevPlItem:
-	if ( plCurrent )
+	if ( plCurrent && plCurrent->prev)
 	 {
 	  plCurrent=plCurrent->prev;
-	  if ( !plCurrent && plList ) plCurrent=plList;
+	  //if ( !plCurrent && plList ) plCurrent=plList;
 	  return plCurrent;
 	 }
 	return NULL;
+   case gtkSetCurrPlItem: // set current item
+	plCurrent=item;
+        return plCurrent;
    case gtkGetCurrPlItem: // get current item
         return plCurrent;
+   case gtkDelCurrPlItem: // delete current item
+	{
+	 plItem * curr = plCurrent;
+
+	 if (!curr)
+	   return NULL;
+	 if (curr->prev)
+	   curr->prev->next=curr->next;
+	 if (curr->next)
+	   curr->next->prev=curr->prev;
+	 if (curr==plList)
+	   plList=curr->next;
+	 plCurrent=curr->next;
+	 // Free it
+	 if ( curr->path ) free( curr->path );
+	 if ( curr->name ) free( curr->name );
+	 free( curr ); 
+        }
+	mplCurr(); // Instead of using mplNext && mplPrev
+
+	return plCurrent;
    case gtkDelPl: // delete list
         {
 	 plItem * curr = plList;
@@ -1002,3 +1041,108 @@
   }
  return NULL;
 }
+
+#define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
+
+#include "../playtree.h"
+
+//This function adds/inserts one file into the gui playlist
+
+int import_file_into_gui(char* temp, int insert)
+{
+  char *filename, *pathname;
+  plItem * item;
+	
+  filename = strdup(mp_basename(temp));
+  pathname = strdup(temp);
+  if (strlen(pathname)-strlen(filename)>0)
+    pathname[strlen(pathname)-strlen(filename)-1]='\0'; // We have some path so remove / at end
+  else
+    pathname[strlen(pathname)-strlen(filename)]='\0';
+  mp_msg(MSGT_PLAYTREE,MSGL_V, "Adding filename %s && pathname %s\n",filename,pathname); //FIXME: Change to MSGL_DBG2 ?
+  item=calloc( 1,sizeof( plItem ) );
+  if (!item)
+     return 0;
+  item->name=filename;
+  item->path=pathname;
+  if (insert)
+    gtkSet( gtkInsertPlItem,0,(void*)item ); // Inserts the item after current, and makes current=item
+  else
+    gtkSet( gtkAddPlItem,0,(void*)item );
+  return 1;
+}
+
+#ifdef NEW_CONFIG
+  #include "../m_option.h"
+  #include "../m_config.h"
+#else
+  #include "../cfgparser.h"
+#endif
+
+// This function imports the initial playtree (based on cmd-line files) into the gui playlist
+// by either:
+//   - overwriting gui pl (enqueue=0)
+//   - appending it to gui pl (enqueue=1)
+
+int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue)
+{
+  play_tree_iter_t* my_pt_iter=NULL;
+  int result=0;
+  
+  if (!enqueue) // Delete playlist before "appending"
+    gtkSet(gtkDelPl,0,0);
+  
+  if((my_pt_iter=pt_iter_create(&my_playtree,config)))
+  {
+    while ((filename=pt_iter_get_next_file(my_pt_iter))!=NULL)
+    {
+      if (import_file_into_gui(filename, 0)) // Add it to end of list
+        result=1;
+    }
+  }
+
+  mplCurr(); // Update filename
+
+  if (!enqueue)
+    filename=guiIntfStruct.Filename; // Backward compatibility; if file is specified on commandline,
+  				     // gmplayer does directly start in Play-Mode.
+  else 
+    filename=NULL;
+
+  return result;
+}
+
+// This function imports and inserts an playtree, that is created "on the fly", for example by
+// parsing some MOV-Reference-File; or by loading an playlist with "File Open"
+//
+// The file which contained the playlist is thereby replaced with it's contents.
+
+int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config)
+{ 
+  play_tree_iter_t* my_pt_iter=NULL;
+  int result=0;
+  plItem * save=(plItem*)gtkSet( gtkGetCurrPlItem, 0, 0); // Save current item
+
+  if((my_pt_iter=pt_iter_create(&my_playtree,config)))
+  {
+    while ((filename=pt_iter_get_next_file(my_pt_iter))!=NULL)
+    {
+      if (import_file_into_gui(filename, 1)) // insert it into the list and set plCurrent=new item 
+        result=1;
+    }
+    pt_iter_destroy(&my_pt_iter);
+  }
+
+  if (save) 
+    gtkSet(gtkSetCurrPlItem, 0, (void*)save);
+  else
+    gtkSet(gtkSetCurrPlItem, 0, (void*)plList); // go to head, if plList was empty before
+
+  if (save && result)
+    gtkSet(gtkDelCurrPlItem, 0, 0);
+  
+  mplCurr();  // Update filename
+  filename=NULL;
+  
+  return result;
+}
--- a/Gui/interface.h	Wed Feb 05 23:02:05 2003 +0000
+++ b/Gui/interface.h	Wed Feb 05 23:02:35 2003 +0000
@@ -196,6 +196,9 @@
 #define gtkSetFontEncoding  20
 #define gtkSetFontAutoScale 21
 #define gtkSetSubEncoding   22
+#define gtkDelCurrPlItem    23
+#define gtkInsertPlItem     24
+#define gtkSetCurrPlItem    25
 
 extern float gtkEquChannels[6][10];
 
--- a/Gui/mplayer/play.c	Wed Feb 05 23:02:05 2003 +0000
+++ b/Gui/mplayer/play.c	Wed Feb 05 23:02:35 2003 +0000
@@ -69,7 +69,7 @@
 {
  plItem * next;
 
- if ( !mplGotoTheNext ) { mplGotoTheNext=1; return; }
+ if ( !mplGotoTheNext && guiIntfStruct.Playing) { mplGotoTheNext=1; return; }
 
  if ( guiIntfStruct.Playing && (next=gtkSet( gtkGetNextPlItem,0,NULL )) && plLastPlayed != next )
   {
@@ -268,6 +268,36 @@
  gfree( (void **)&guiIntfStruct.Subtitlename );
 }
 
+void mplCurr( void )
+{
+ plItem * curr;
+ int      stop = 0;
+ 
+ if ( guiIntfStruct.Playing == 2 ) return;
+ switch ( guiIntfStruct.StreamType )
+  {
+#ifdef USE_DVDREAD
+   case STREAMTYPE_DVD:
+	break;
+#endif
+#ifdef HAVE_VCD
+   case STREAMTYPE_VCD:
+	break;
+#endif
+   default: 
+	if ( (curr=gtkSet( gtkGetCurrPlItem,0,NULL)) )
+	 {
+	  mplSetFileName( curr->path,curr->name,STREAMTYPE_FILE );
+	  mplGotoTheNext=0;
+	  break;
+	 }
+	return;
+  }
+ if ( stop ) mplEventHandling( evStop,0 );
+ if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
+}
+
+
 void mplPrev( void )
 {
  plItem * prev;
--- a/Gui/mplayer/play.h	Wed Feb 05 23:02:05 2003 +0000
+++ b/Gui/mplayer/play.h	Wed Feb 05 23:02:35 2003 +0000
@@ -13,6 +13,7 @@
 extern void mplState( void );
 extern void mplPrev( void );
 extern void mplNext( void );
+extern void mplCurr( void );
 
 extern void mplIncAudioBufDelay( void );
 extern void mplDecAudioBufDelay( void );
--- a/cfg-mplayer.h	Wed Feb 05 23:02:05 2003 +0000
+++ b/cfg-mplayer.h	Wed Feb 05 23:02:35 2003 +0000
@@ -106,6 +106,7 @@
 
 #ifdef HAVE_NEW_GUI
 extern char * skinName;
+extern int enqueue;
 #endif
 
 #ifdef HAVE_ODIVX_POSTPROCESS
@@ -395,6 +396,8 @@
       
 #ifdef HAVE_NEW_GUI
 	{"skin", &skinName, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
+	{"enqueue", &enqueue, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"noenqueue", &enqueue, CONF_TYPE_FLAG, 0, 0, 0, NULL},
 #endif
 
 	{"noloop", &loop_times, CONF_TYPE_FLAG, 0, 0, -1, NULL},
--- a/mplayer.c	Wed Feb 05 23:02:05 2003 +0000
+++ b/mplayer.c	Wed Feb 05 23:02:35 2003 +0000
@@ -181,6 +181,11 @@
 float playback_speed=1.0;
 
 int use_gui=0;
+
+#ifdef HAVE_NEW_GUI
+int enqueue=0;
+#endif
+
 #define MAX_OSD_LEVEL 3
 
 int osd_level=1;
@@ -577,6 +582,15 @@
 
 int playtree_add_playlist(play_tree_t* entry)
 {
+#ifdef HAVE_NEW_GUI
+  if (use_gui) {
+    if (entry) {
+      import_playtree_playlist_into_gui(entry, mconfig);
+      play_tree_free_list(entry,1);
+    }
+  } else
+#endif
+  {
   if(!entry) {      
     entry = playtree_iter->tree;
     if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
@@ -597,6 +611,7 @@
     return PT_NEXT_ENTRY;
   }      
   play_tree_remove(entry,1,1);
+  }
   return PT_NEXT_SRC;
 }
 
@@ -743,6 +758,13 @@
       mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);
       use_gui=0;
     }
+    if (use_gui && playtree_iter){
+      // Remove Playtree and Playtree-Iter from memory as its not used by gui
+      play_tree_iter_free(playtree_iter);
+      playtree_iter=NULL;
+      // Import initital playtree into gui
+      import_initial_playtree_into_gui(playtree, mconfig, enqueue);
+    }
 #endif
 
     if(vo_plugin_args && vo_plugin_args[0] && strcmp(vo_plugin_args[0],"help")==0){
@@ -2303,7 +2325,19 @@
       int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
       int force = cmd->args[1].v.i;
 
-      if(!force) {
+#ifdef HAVE_NEW_GUI
+     if (use_gui) {
+	int i=0;
+        if (n>0)
+	  for (i=0;i<n;i++)
+	    mplNext();
+        else
+	  for (i=0;i<-1*n;i++)
+	    mplPrev();
+     } else
+#endif
+     {
+      if(!force && playtree_iter) {
 	play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
 	
 	if(play_tree_iter_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
@@ -2313,12 +2347,13 @@
 	eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
       if(eof)
 	play_tree_step = n;
+     }
     } break;
     case MP_CMD_PLAY_TREE_UP_STEP : {
       int n = cmd->args[0].v.i > 0 ? 1 : -1;
       int force = cmd->args[1].v.i;
 
-      if(!force) {
+      if(!force && playtree_iter) {
 	play_tree_iter_t* i = play_tree_iter_new_copy(playtree_iter);
 	if(play_tree_iter_up_step(i,n,0) == PLAY_TREE_ITER_ENTRY)
 	  eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;