]> uap-core.de Git - uwplayer.git/commitdiff
add arg parser + args for playback control
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 7 Aug 2025 18:55:37 +0000 (20:55 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 7 Aug 2025 18:55:37 +0000 (20:55 +0200)
application/main.c
application/playlist.c
application/playlist.h

index d49dc72a9a8cc3de1103b080f3d6c35e0b18c888..458fed02a3aee66bfe5fb2cd01195049a956242f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <locale.h>
 #include <time.h>
@@ -30,6 +31,7 @@
 
 #include "window.h"
 #include "main.h"
+#include "playlist.h"
 #include "settings.h"
 
 #include <cx/buffer.h>
@@ -104,17 +106,70 @@ int main(int argc, char** argv) {
        
     display =  XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv);
     
+    PlaybackMode playback = PLAYBACK_STOP;
+    bool fullscreen = FALSE;
+    bool adjust_window_size = FALSE;
+    bool single_instance = FALSE;
+    
+    bool file_args = 0;
     if(argc > 1) {
         open_file_arg = cxArrayListCreateSimple(CX_STORE_POINTERS, argc-1);
         for(int i=1;i<argc;i++) {
             char *arg = argv[i];
-            struct stat s;
-            if(stat(arg, &s)) {
-                fprintf(stderr, "Cannot open file: %s\n", argv[1]);
-                perror("");
-                return 1;
+            if(file_args || arg[0] != '-') {
+                struct stat s;
+                if(stat(arg, &s)) {
+                    fprintf(stderr, "Cannot open file: %s\n", argv[1]);
+                    perror("");
+                    return 1;
+                }
+                cxListAdd(open_file_arg, arg);
+            } else {
+                if(!strcmp(arg, "--")) {
+                    file_args = 1;
+                } else {
+                    size_t arglen = strlen(arg);
+                    for(int a=1;a<arglen;a++) {
+                        switch(arg[a]) {
+                            case 't': {
+                                // repeat (Track)
+                                playback = PLAYBACK_REPEAT;
+                                break;
+                            }
+                            case 'l': {
+                                // repeat List
+                                playback = PLAYBACK_REPEAT_LIST;
+                                break;
+                            }
+                            case 'r': {
+                                // Random playback
+                                playback = PLAYBACK_RANDOM;
+                                break;
+                            }
+                            case 'a': {
+                                // Autoplay
+                                playback = PLAYBACK_AUTOPLAY;
+                                break;
+                            }
+                            case 'w': {
+                                // adjust Window size
+                                adjust_window_size = TRUE;
+                                break;
+                            }
+                            case 'f': {
+                                // Fullscreen
+                                fullscreen = TRUE;
+                                break;
+                            }
+                            case 's': {
+                                // single instance
+                                single_instance = TRUE;
+                                break;
+                            }
+                        }
+                    }
+                }
             }
-            cxListAdd(open_file_arg, arg);
         }
     }
     
@@ -154,6 +209,10 @@ int main(int argc, char** argv) {
     // random numbers used for creating tmp dirs and for random playback
     srand(time(NULL));
     
+    if(playback != 0) {
+        PlayListSetMode(window, playback);
+    }
+    
     WindowShow(window);
     AppMainLoop(app);
     
index d7ffb64e39159646960aa7d1440839ce34b06141..7a2d93634d16447bc346fddf5b22a1984a88941e 100644 (file)
@@ -84,3 +84,41 @@ void PlayListPlayTrack(MainWindow *win, int i) {
 void PlayListClear(MainWindow *win) {
     cxListClear(win->playlist.tracks);
 }
+
+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);
+}
index 26df47b97880b8de6f665eb7e70858094da39ad5..553c2f89af586e5e6bbca33add847dadd42acf4a 100644 (file)
 extern "C" {
 #endif
 
+typedef enum PlaybackMode {
+    PLAYBACK_STOP = 0,
+    PLAYBACK_REPEAT,
+    PLAYBACK_REPEAT_LIST,
+    PLAYBACK_RANDOM,
+    PLAYBACK_AUTOPLAY
+} PlaybackMode;
+    
 void PlayListInit(MainWindow *win);
 
 void PlayListAddFile(MainWindow *win, const char *file);
@@ -39,6 +47,8 @@ void PlayListPlayTrack(MainWindow *win, int i);
 
 void PlayListClear(MainWindow *win);
 
+void PlayListSetMode(MainWindow *win, PlaybackMode mode);
+
 #ifdef __cplusplus
 }
 #endif