From c225eea4edfb8cf8ede845cc6f9b7e858aabe6e8 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 26 Feb 2011 14:44:52 +0100 Subject: Always add song to history --- src/main.c | 38 +++----------------------------------- src/ui.c | 30 ++++++++++++++++++++++++++++++ src/ui.h | 1 + src/ui_act.c | 10 +++++++--- 4 files changed, 41 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 3104898..6886afc 100644 --- a/src/main.c +++ b/src/main.c @@ -157,40 +157,6 @@ static void BarMainHandleUserInput (BarApp_t *app) { } } -/* append current song to history list and move to the next song - */ -static void BarMainNextSong (BarApp_t *app) { - if (app->settings.history != 0) { - /* prepend song to history list */ - PianoSong_t *tmpSong = app->songHistory; - app->songHistory = app->playlist; - /* select next song */ - app->playlist = app->playlist->next; - app->songHistory->next = tmpSong; - - /* limit history's length */ - /* start with 1, so we're stopping at n-1 and have the - * chance to set ->next = NULL */ - unsigned int i = 1; - tmpSong = app->songHistory; - while (i < app->settings.history && tmpSong != NULL) { - tmpSong = tmpSong->next; - ++i; - } - /* if too many songs in history... */ - if (tmpSong != NULL) { - PianoSong_t *delSong = tmpSong->next; - tmpSong->next = NULL; - if (delSong != NULL) { - PianoDestroyPlaylist (delSong); - } - } - } else { - /* don't keep history */ - app->playlist = app->playlist->next; - } -} - /* fetch new playlist */ static void BarMainGetPlaylist (BarApp_t *app) { @@ -338,7 +304,9 @@ static void BarMainLoop (BarApp_t *app) { if (app->curStation != NULL) { /* what's next? */ if (app->playlist != NULL) { - BarMainNextSong (app); + PianoSong_t *histsong = app->playlist; + app->playlist = app->playlist->next; + BarUiHistoryPrepend (app, histsong); } if (app->playlist == NULL) { BarMainGetPlaylist (app); diff --git a/src/ui.c b/src/ui.c index 0e8f80b..cd0b7d2 100644 --- a/src/ui.c +++ b/src/ui.c @@ -694,3 +694,33 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type, waitpid (chld, &status, 0); } } + +/* prepend song to history, must not be a list of songs as ->next is modified! + */ +void BarUiHistoryPrepend (BarApp_t *app, PianoSong_t *song) { + if (app->settings.history != 0) { + PianoSong_t *tmpSong; + + song->next = app->songHistory; + app->songHistory = song; + + /* limit history's length */ + /* start with 1, so we're stopping at n-1 and have the + * chance to set ->next = NULL */ + unsigned int i = 1; + tmpSong = app->songHistory; + while (i < app->settings.history && tmpSong != NULL) { + tmpSong = tmpSong->next; + ++i; + } + /* if too many songs in history... */ + if (tmpSong != NULL) { + PianoSong_t *delSong = tmpSong->next; + tmpSong->next = NULL; + if (delSong != NULL) { + PianoDestroyPlaylist (delSong); + } + } + } +} + diff --git a/src/ui.h b/src/ui.h index 4d4b555..adc7565 100644 --- a/src/ui.h +++ b/src/ui.h @@ -53,5 +53,6 @@ void BarUiStartEventCmd (const BarSettings_t *, const char *, PianoStation_t *, PianoReturn_t, WaitressReturn_t); int BarUiPianoCall (BarApp_t * const, PianoRequestType_t, void *, PianoReturn_t *, WaitressReturn_t *); +void BarUiHistoryPrepend (BarApp_t *app, PianoSong_t *song); #endif /* _UI_H */ diff --git a/src/ui_act.c b/src/ui_act.c index a57cb01..096daa1 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -190,7 +190,8 @@ BarUiActCallback(BarUiActDeleteStation) { if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION, selStation) && selStation == app->curStation) { BarUiDoSkipSong (&app->player); - PianoDestroyPlaylist (app->playlist); + PianoDestroyPlaylist (app->playlist->next); + BarUiHistoryPrepend (app, app->playlist); app->playlist = NULL; app->curStation = NULL; } @@ -381,8 +382,11 @@ BarUiActCallback(BarUiActSelectStation) { app->curStation = newStation; BarUiPrintStation (app->curStation); BarUiDoSkipSong (&app->player); - PianoDestroyPlaylist (app->playlist); - app->playlist = NULL; + if (app->playlist != NULL) { + PianoDestroyPlaylist (app->playlist->next); + BarUiHistoryPrepend (app, app->playlist); + app->playlist = NULL; + } } } -- cgit v1.2.3