changeset 35458:2a6113c08e20

Add listMgr command PLAYLIST_ITEM_GET_CURR_POS. Use this command to retrieve the "track number" of a playlist playback instead of simply incrementing or decrementing it.
author ib
date Sun, 02 Dec 2012 00:36:56 +0000
parents f4991a47d0c8
children 1edb306bc754
files gui/interface.c gui/ui/actions.c gui/util/list.c gui/util/list.h
diffstat 4 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Sat Dec 01 23:45:59 2012 +0000
+++ b/gui/interface.c	Sun Dec 02 00:36:56 2012 +0000
@@ -787,7 +787,7 @@
         if (guiInfo.Playing && next) {
             uiSetFile(next->path, next->name, STREAMTYPE_FILE);
             guiInfo.NewPlay = GUI_FILE_NEW;
-            guiInfo.Track++;
+            guiInfo.Track   = (int)listMgr(PLAYLIST_ITEM_GET_POS, next);
         } else {
             if (guiInfo.NewPlay == GUI_FILE_NEW)
                 break;
--- a/gui/ui/actions.c	Sat Dec 01 23:45:59 2012 +0000
+++ b/gui/ui/actions.c	Sun Dec 02 00:36:56 2012 +0000
@@ -384,7 +384,7 @@
         if (prev) {
             uiSetFile(prev->path, prev->name, STREAMTYPE_FILE);
             guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1);
-            guiInfo.Track--;
+            guiInfo.Track = (int)listMgr(PLAYLIST_ITEM_GET_POS, prev);
             break;
         }
 
@@ -440,7 +440,7 @@
         if (next) {
             uiSetFile(next->path, next->name, STREAMTYPE_FILE);
             guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1);
-            guiInfo.Track++;
+            guiInfo.Track = (int)listMgr(PLAYLIST_ITEM_GET_POS, next);
             break;
         }
 
--- a/gui/util/list.c	Sat Dec 01 23:45:59 2012 +0000
+++ b/gui/util/list.c	Sun Dec 02 00:36:56 2012 +0000
@@ -45,9 +45,12 @@
  *         pointer to current list item (ITEM command) or
  *         NULL (DELETE or unknown command)
  *
+ * @note PLAYLIST_ITEM_GET_POS returns the position number as pointer,
+ *       and position 0 means "not found"
  */
 void *listMgr(int cmd, void *data)
 {
+    unsigned int pos;
     plItem *pdat  = (plItem *)data;
     urlItem *udat = (urlItem *)data;
 
@@ -102,6 +105,28 @@
 
         return plCurrent;
 
+    case PLAYLIST_ITEM_GET_POS:
+
+        pos = 0;
+
+        if (plList) {
+            unsigned int i = 0;
+            plItem *item   = plList;
+
+            do {
+                i++;
+
+                if (item == pdat) {
+                    pos = i;
+                    break;
+                }
+
+                item = item->next;
+            } while (item);
+        }
+
+        return (void *)pos;
+
     case PLAYLIST_ITEM_GET_PREV:
 
         if (plCurrent && plCurrent->prev) {
--- a/gui/util/list.h	Sat Dec 01 23:45:59 2012 +0000
+++ b/gui/util/list.h	Sun Dec 02 00:36:56 2012 +0000
@@ -26,6 +26,7 @@
     PLAYLIST_ITEM_INSERT,
     PLAYLIST_ITEM_SET_CURR,
     PLAYLIST_ITEM_GET_CURR,
+    PLAYLIST_ITEM_GET_POS,
     PLAYLIST_ITEM_GET_PREV,
     PLAYLIST_ITEM_GET_NEXT,
     PLAYLIST_ITEM_DEL_CURR,