diff options
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | playlist.c | 28 | ||||
-rw-r--r-- | playlist.h | 6 | ||||
-rw-r--r-- | streamer.c | 7 |
4 files changed, 38 insertions, 9 deletions
@@ -440,6 +440,12 @@ player_mainloop (void) { output->stop (); pl_playqueue_clear (); streamer_set_nextsong (p1, 1); + if (pl_get_order () == PLAYBACK_ORDER_SHUFFLE_ALBUMS) { + int pl = streamer_get_current_playlist (); + playlist_t *plt = plt_get_for_idx (pl); + plt_init_shuffle_albums (plt, p1); + plt_unref (plt); + } break; case DB_EV_STOP: streamer_set_nextsong (-2, 0); @@ -2703,11 +2703,6 @@ plt_reshuffle (playlist_t *playlist, playItem_t **ppmin, playItem_t **ppmax) { } void -pl_reshuffle (playItem_t **ppmin, playItem_t **ppmax) { - plt_reshuffle (playlist, ppmin, ppmax); -} - -void plt_set_item_duration (playlist_t *playlist, playItem_t *it, float duration) { LOCK; if (it->in_playlist) { @@ -3873,3 +3868,26 @@ pl_get_playlist (playItem_t *it) { UNLOCK; return NULL; } + +// this function must be called user starts track manually in shuffle albums mode +// r is an index of current track +// mark previous songs in the album as played +void +plt_init_shuffle_albums (playlist_t *plt, int r) { + printf ("init_shuffle_albums %d\n", r); + pl_lock (); + playItem_t *first = plt_get_item_for_idx (plt, r, PL_MAIN); + if (first->played) { + plt_reshuffle (plt, NULL, NULL); + } + if (first) { + int rating = first->shufflerating; + playItem_t *it = first->prev[PL_MAIN]; + pl_item_unref (first); + while (it && rating == it->shufflerating) { + it->played = 1; + it = it->prev[PL_MAIN]; + } + } + pl_unlock (); +} @@ -304,9 +304,6 @@ pl_select_all (void); void plt_reshuffle (playlist_t *playlist, playItem_t **ppmin, playItem_t **ppmax); -void -pl_reshuffle (playItem_t **ppmin, playItem_t **ppmax); - // required to calculate total playtime void plt_set_item_duration (playlist_t *playlist, playItem_t *it, float duration); @@ -437,4 +434,7 @@ pl_get_order (void); playlist_t * pl_get_playlist (playItem_t *it); +void +plt_init_shuffle_albums (playlist_t *plt, int r); + #endif // __PLAYLIST_H @@ -547,7 +547,7 @@ streamer_move_to_prevsong (void) { // that means 1st in playlist, take amax if (pl_loop_mode == PLAYBACK_MODE_LOOP_ALL) { if (!amax) { - pl_reshuffle (NULL, &amax); + plt_reshuffle (streamer_playlist, NULL, &amax); } it = amax; } @@ -615,6 +615,11 @@ streamer_move_to_randomsong (void) { r = 0; } } + + if (pl_get_order () == PLAYBACK_ORDER_SHUFFLE_ALBUMS) { + plt_init_shuffle_albums (plt, r); + } + streamer_set_nextsong (r, 1); return 0; } |