From: Olaf Wintermann Date: Thu, 7 Aug 2025 19:15:04 +0000 (+0200) Subject: refactore PlayList struct: use new PlayBackMode enum X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=d1163e37fdf862f620610d58a0f7ffe93b8caadd;p=uwplayer.git refactore PlayList struct: use new PlayBackMode enum --- diff --git a/application/player.c b/application/player.c index bed6567..0eced5f 100644 --- a/application/player.c +++ b/application/player.c @@ -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"; diff --git a/application/playlist.c b/application/playlist.c index 7a2d936..17de3d5 100644 --- a/application/playlist.c +++ b/application/playlist.c @@ -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); } diff --git a/application/playlist.h b/application/playlist.h index 553c2f8..b9d6f21 100644 --- a/application/playlist.h +++ b/application/playlist.h @@ -28,14 +28,6 @@ #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); diff --git a/application/window.c b/application/window.c index 7caf301..efdf2a0 100644 --- a/application/window.c +++ b/application/window.c @@ -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); diff --git a/application/window.h b/application/window.h index a7a9c1c..7519308 100644 --- a/application/window.h +++ b/application/window.h @@ -33,6 +33,14 @@ #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 {