#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <locale.h>
#include <time.h>
#include "window.h"
#include "main.h"
+#include "playlist.h"
#include "settings.h"
#include <cx/buffer.h>
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);
}
}
// random numbers used for creating tmp dirs and for random playback
srand(time(NULL));
+ if(playback != 0) {
+ PlayListSetMode(window, playback);
+ }
+
WindowShow(window);
AppMainLoop(app);
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);
+}
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);
void PlayListClear(MainWindow *win);
+void PlayListSetMode(MainWindow *win, PlaybackMode mode);
+
#ifdef __cplusplus
}
#endif