void PlayListInit(MainWindow *win) {
win->playlist.tracks = cxArrayListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS, 64);
win->playlist.tracks->collection.simple_destructor = free;
+ win->playlist.tracks->collection.cmpfunc = (cx_compare_func)strcmp;
+ win->playlist.history = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS);
+ win->playlist.history->collection.simple_destructor = free;
+ win->playlist.history->collection.cmpfunc = (cx_compare_func)strcmp;
win->playlist.current_track = -1;
+ win->playlist.current_history_pos = -1;
}
void PlayListAddFile(MainWindow *win, const char *file) {
switch(win->playlist.playback) {
default: {
if(current+1 < cxListSize(win->playlist.tracks)) {
- current++;
+ current = PlayListGetNextFromHistory(win);
break;
}
return;
if(current+1 == cxListSize(win->playlist.tracks)) {
current = 0;
} else {
- current++;
+ current = PlayListGetNextFromHistory(win);
}
break;
}
}
}
- PlayListPlayTrack(win, current);
+ PlayListPlayTrack(win, current, true);
+}
+
+void PlayListPlayPrev(MainWindow *win) {
+ CxList *hist = win->playlist.history;
+ if(cxListSize(hist) > 1 && win->playlist.current_history_pos > 0) {
+ win->playlist.current_history_pos--;
+ char *file = cxListAt(hist, win->playlist.current_history_pos);
+ size_t fileIndex = cxListFind(win->playlist.tracks, file);
+ if(cxListIndexValid(win->playlist.tracks, fileIndex)) {
+ PlayListPlayTrack(win, fileIndex, false);
+ }
+ }
}
-void PlayListPlayTrack(MainWindow *win, int i) {
+void PlayListPlayTrack(MainWindow *win, int i, bool add2history) {
CxList *tracks = win->playlist.tracks;
if(i < cxListSize(tracks)) {
char *file = cxListAt(tracks, i);
win->file = file;
PlayerOpenFile(win);
win->playlist.current_track = i;
+ if(add2history) {
+ cxListAdd(win->playlist.history, strdup(file));
+ size_t histlen = cxListSize(win->playlist.history);
+ win->playlist.current_history_pos = histlen-1;
+ if(histlen > PLAYLIST_HISTORY_MAX) {
+ cxListRemove(win->playlist.history, 0);
+ win->playlist.current_history_pos--;
+ }
+ }
}
}
}
XtVaSetValues(win->playAutoPlayButton, XmNset, mode == PLAYBACK_RANDOM, NULL);
XtVaSetValues(win->playRandom, XmNset, mode == PLAYBACK_AUTOPLAY, NULL);
}
+
+int PlayListGetNextFromHistory(MainWindow *win) {
+ size_t histlen = cxListSize(win->playlist.history);
+ if(win->playlist.current_history_pos+1 < histlen) {
+ char *hist_file = cxListAt(win->playlist.history, win->playlist.current_history_pos);
+ if(hist_file) {
+ size_t index = cxListFind(win->playlist.tracks, hist_file);
+ if(cxListIndexValid(win->playlist.tracks, index)) {
+ win->playlist.current_history_pos++;
+ return index;
+ }
+ }
+ }
+
+ if(win->playlist.current_track+1 < cxListSize(win->playlist.tracks)) {
+ return win->playlist.current_track+1;
+ }
+
+ return 0;
+}
extern "C" {
#endif
+#define PLAYLIST_HISTORY_MAX 255
+
void PlayListInit(MainWindow *win);
void PlayListAddFile(MainWindow *win, const char *file);
void PlayListPlayNext(MainWindow *win, bool force);
-void PlayListPlayTrack(MainWindow *win, int i);
+void PlayListPlayPrev(MainWindow *win);
+
+void PlayListPlayTrack(MainWindow *win, int i, bool add2history);
void PlayListClear(MainWindow *win);
void PlayListSetMode(MainWindow *win, PlaybackMode mode);
+int PlayListGetNextFromHistory(MainWindow *win);
+
#ifdef __cplusplus
}
#endif
win->playRandom = createToggleMenuItem(playMenu, "playRandom", "Random Playback", 'a', False, NULL, NULL, PlayRandomCB, win);
win->playAutoPlayButton = createToggleMenuItem(playMenu, "playAutoNext", "Autoplay Folder", 'A', False, NULL, NULL, PlayAutoPlayCB, win);
createMenuSeparator(playMenu);
- //createMenuItem(playMenu, "playPrev", "Previous", 'P', NULL, NULL, PlayPreviousCB, win);
+ createMenuItem(playMenu, "playPrev", "Previous", 'P', NULL, NULL, PlayPreviousCB, win);
createMenuItem(playMenu, "playPrev", "Next", 'N', NULL, NULL, PlayNextCB, win);
XtVaSetValues(win->playRepeatTrackButton, XmNindicatorType, XmONE_OF_MANY, NULL);
XtVaSetValues(win->playRepeatListButton, XmNindicatorType, XmONE_OF_MANY, NULL);
}
static void PlayPreviousCB(Widget w, void *udata, void *cdata) {
-
+ MainWindow *win = udata;
+ PlayListPlayPrev(win);
}
static void PlayNextCB(Widget w, void *udata, void *cdata) {