]> uap-core.de Git - uwplayer.git/commitdiff
refactore PlayList struct: use new PlayBackMode enum
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 7 Aug 2025 19:15:04 +0000 (21:15 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 7 Aug 2025 19:15:04 +0000 (21:15 +0200)
application/player.c
application/playlist.c
application/playlist.h
application/window.c
application/window.h

index bed65677945a6f739cb5eae2a26949555bcded04..0eced5fdc575aacc9754a5903f1e0f2cf28c4cf0 100644 (file)
@@ -594,7 +594,7 @@ static Boolean play_next(XtPointer data) {
 
 void PlayerEOF(Player *p) {
     MainWindow *win = GetMainWindow();
-    if(win->playlist.repeatTrack) {
+    if(win->playlist.playback == PLAYBACK_REPEAT) {
         char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n";
         write(p->ipc, cmd, strlen(cmd));
         cmd = "{ \"command\": [\"set_property\", \"pause\", false] }\n";
index 7a2d93634d16447bc346fddf5b22a1984a88941e..17de3d59d24b9da3d1e7dc6a46566db22c7b171f 100644 (file)
@@ -47,22 +47,30 @@ void PlayListPlayNext(MainWindow *win, bool force) {
     size_t len = cxListSize(tracks);
     
     int current = win->playlist.current_track;
-    if(win->playlist.repeatTrack) {
-        if(force) {
-            current++;
+    switch(win->playlist.playback) {
+        default: {
+            current = 0;
+            break;
+        }
+        case PLAYBACK_REPEAT: {
+            if(force) {
+                current++;
+            }
+            break;
+        }
+        case PLAYBACK_REPEAT_LIST: {
+            return;
+        }
+        case PLAYBACK_RANDOM: {
+            current = random() % len;
+            break;
+        }
+        case PLAYBACK_AUTOPLAY: {
+            char *next_file = util_find_next_file(win->file);
+            cxListAdd(win->playlist.tracks, next_file);
+            current = len;
+            break;
         }
-    } else if(win->playlist.random) {
-        current = random() % len;
-    } else if(win->playlist.autoplayFolder) {
-        char *next_file = util_find_next_file(win->file);
-        cxListAdd(win->playlist.tracks, next_file);
-        current = len;
-    } else if(current+1 < len) {
-        current++;
-    } else if(!win->playlist.repeatList) {
-        return;
-    } else {
-        current = 0;
     }
     
     PlayListPlayTrack(win, current);
@@ -86,39 +94,9 @@ void PlayListClear(MainWindow *win) {
 }
 
 void PlayListSetMode(MainWindow *win, PlaybackMode mode) {
-    switch(mode) {
-        default: break;
-        case PLAYBACK_REPEAT: {
-            win->playlist.repeatTrack = TRUE;
-            win->playlist.repeatList = FALSE;
-            win->playlist.random = FALSE;
-            win->playlist.autoplayFolder = FALSE;
-            break;
-        }
-        case PLAYBACK_REPEAT_LIST: {
-            win->playlist.repeatTrack = TRUE;
-            win->playlist.repeatList = TRUE;
-            win->playlist.random = FALSE;
-            win->playlist.autoplayFolder = FALSE;
-            break;
-        }
-        case PLAYBACK_RANDOM: {
-            win->playlist.repeatTrack = TRUE;
-            win->playlist.repeatList = FALSE;
-            win->playlist.random = TRUE;
-            win->playlist.autoplayFolder = FALSE;
-            break;
-        }
-        case PLAYBACK_AUTOPLAY: {
-            win->playlist.repeatTrack = FALSE;
-            win->playlist.repeatList = FALSE;
-            win->playlist.random = FALSE;
-            win->playlist.autoplayFolder = TRUE;
-            break;
-        }
-    }
-    XtVaSetValues(win->playRepeatTrackButton, XmNset, win->playlist.repeatTrack, NULL);
-    XtVaSetValues(win->playRepeatListButton, XmNset, win->playlist.repeatList, NULL);
-    XtVaSetValues(win->playAutoPlayButton, XmNset, win->playlist.random, NULL);
-    XtVaSetValues(win->playRandom, XmNset, win->playlist.autoplayFolder, NULL);
+    win->playlist.playback = mode;
+    XtVaSetValues(win->playRepeatTrackButton, XmNset, mode == PLAYBACK_REPEAT, NULL);
+    XtVaSetValues(win->playRepeatListButton, XmNset, mode == PLAYBACK_REPEAT_LIST, NULL);
+    XtVaSetValues(win->playAutoPlayButton, XmNset, mode == PLAYBACK_RANDOM, NULL);
+    XtVaSetValues(win->playRandom, XmNset, mode == PLAYBACK_AUTOPLAY, NULL);
 }
index 553c2f89af586e5e6bbca33add847dadd42acf4a..b9d6f2127c01793bb15be8119648f7d319aa4d74 100644 (file)
 #ifdef __cplusplus
 extern "C" {
 #endif
-
-typedef enum PlaybackMode {
-    PLAYBACK_STOP = 0,
-    PLAYBACK_REPEAT,
-    PLAYBACK_REPEAT_LIST,
-    PLAYBACK_RANDOM,
-    PLAYBACK_AUTOPLAY
-} PlaybackMode;
     
 void PlayListInit(MainWindow *win);
 
index 7caf301362007de48590b42b0ef70de9239a1146..efdf2a00bb11a28ea8fbff44d496ceee78772f88 100644 (file)
@@ -637,10 +637,7 @@ static void FileQuitCB(Widget w, void *udata, void *cdata) {
 
 static void PlayRepeatCB(Widget w, void *udata, void *cdata) {
     MainWindow *win = udata;
-    win->playlist.repeatTrack = XmToggleButtonGadgetGetState(w);
-    win->playlist.repeatList = 0;
-    win->playlist.autoplayFolder = 0;
-    win->playlist.random = 0;
+    win->playlist.playback = XmToggleButtonGadgetGetState(w) ? PLAYBACK_REPEAT : PLAYBACK_STOP;
     XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
     XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
     XtVaSetValues(win->playRandom, XmNset, 0, NULL);
@@ -648,10 +645,7 @@ static void PlayRepeatCB(Widget w, void *udata, void *cdata) {
 
 static void PlayRepeatListCB(Widget w, void *udata, void *cdata) {
     MainWindow *win = udata;
-    win->playlist.repeatList = XmToggleButtonGadgetGetState(w);
-    win->playlist.repeatTrack = 0;
-    win->playlist.autoplayFolder = 0;
-    win->playlist.random = 0;
+    win->playlist.playback = XmToggleButtonGadgetGetState(w) ? PLAYBACK_REPEAT_LIST : PLAYBACK_STOP;
     XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
     XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
     XtVaSetValues(win->playRandom, XmNset, 0, NULL);
@@ -659,10 +653,7 @@ static void PlayRepeatListCB(Widget w, void *udata, void *cdata) {
 
 static void PlayAutoPlayCB(Widget w, void *udata, void *cdata) {
     MainWindow *win = udata;
-    win->playlist.autoplayFolder = XmToggleButtonGadgetGetState(w);
-    win->playlist.repeatTrack = 0;
-    win->playlist.repeatList = 0;
-    win->playlist.random = 0;
+    win->playlist.playback = XmToggleButtonGadgetGetState(w) ? PLAYBACK_AUTOPLAY : PLAYBACK_STOP;
     XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
     XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
     XtVaSetValues(win->playRandom, XmNset, 0, NULL);
@@ -670,10 +661,7 @@ static void PlayAutoPlayCB(Widget w, void *udata, void *cdata) {
 
 static void PlayRandomCB(Widget w, void *udata, void *cdata) {
     MainWindow *win = udata;
-    win->playlist.random = XmToggleButtonGadgetGetState(w);
-    win->playlist.repeatTrack = 0;
-    win->playlist.repeatList = 0;
-    win->playlist.autoplayFolder = 0;
+    win->playlist.playback = XmToggleButtonGadgetGetState(w) ? PLAYBACK_RANDOM : PLAYBACK_STOP;
     XtVaSetValues(win->playRepeatTrackButton, XmNset, 0, NULL);
     XtVaSetValues(win->playRepeatListButton, XmNset, 0, NULL);
     XtVaSetValues(win->playAutoPlayButton, XmNset, 0, NULL);
index a7a9c1c74fa83f53236224c0d499ec3de4639da0..7519308f8e3748b4d348e831065783196a30becc 100644 (file)
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+typedef enum PlaybackMode {
+    PLAYBACK_STOP = 0,
+    PLAYBACK_REPEAT,
+    PLAYBACK_REPEAT_LIST,
+    PLAYBACK_RANDOM,
+    PLAYBACK_AUTOPLAY
+} PlaybackMode;
 
 typedef struct Player {
     char *tmp;
@@ -52,11 +60,7 @@ typedef struct Player {
 typedef struct {
     CxList *tracks;
     int current_track;
-    
-    Boolean repeatTrack;
-    Boolean repeatList;
-    Boolean autoplayFolder;
-    Boolean random;
+    PlaybackMode playback;
 } PlayList;
 
 typedef struct MainWindow {