Permalink
Browse files

Add aaa_mode for random album shuffle

When reaching the end of the current album, pick another album at
random and start playing at the first track.

This might be better implemented by changing shuffle from just a
boolean to all/shuffle/off, but that seems much more invasive.
  • Loading branch information...
jcs committed Jul 5, 2018
1 parent 17bf542 commit 1bf405c51de366221024b605eeeb7a768b045e73
Showing with 50 additions and 7 deletions.
  1. +2 −2 Doc/cmus.txt
  2. +43 −1 lib.c
  3. +2 −1 lib.h
  4. +3 −3 options.c
View
@@ -612,7 +612,7 @@ source <filename>
Read and execute commands from <filename>.
toggle <option>
Toggle value of a toggle-able option (all booleans and tristate
Toggle value of a toggle-able option (all booleans and quadstate
*aaa_mode*).
tqueue [NUM]
@@ -795,7 +795,7 @@ auto_expand_albums_follow, auto_expand_albums_search, auto_expand_albums_selcur
auto_reshuffle (true)
Reshuffle playlist when end of shuffle list is reached.
aaa_mode (all) [all, artist, album]
aaa_mode (all) [all, artist, album, random album]
Defines what tracks should be played in the library view. Not used in
the other views. For example if set to *artist* the player behaves
like there were only the files of the currently playing artist in the
View
44 lib.c
@@ -204,7 +204,7 @@ static int aaa_mode_filter(const struct simple_track *track)
{
const struct album *album = ((struct tree_track *)track)->album;
if (aaa_mode == AAA_MODE_ALBUM)
if (aaa_mode == AAA_MODE_ALBUM || aaa_mode == AAA_MODE_RANDOM_ALBUM)
return CUR_ALBUM == album;
if (aaa_mode == AAA_MODE_ARTIST)
@@ -214,10 +214,20 @@ static int aaa_mode_filter(const struct simple_track *track)
return 1;
}
/* only for AAA_MODE_RANDOM_ALBUM */
static int next_random_album_filter(const struct simple_track *track)
{
const struct album *album = ((struct tree_track *)track)->album;
return CUR_ALBUM != album;
}
/* set next/prev (tree) {{{ */
static struct tree_track *normal_get_next(void)
{
struct tree_track *track;
if (lib_cur_track == NULL)
return normal_get_first();
@@ -234,6 +244,21 @@ static struct tree_track *normal_get_next(void)
return album_first_track(CUR_ALBUM);
}
if (aaa_mode == AAA_MODE_RANDOM_ALBUM) {
if (repeat)
/* first track of the current album */
return album_first_track(CUR_ALBUM);
/* go through shuffle list until we reach a song that is not on
* the current album */
track = (struct tree_track *)shuffle_list_get_next(&lib_shuffle_root,
(struct shuffle_track *)lib_cur_track,
next_random_album_filter);
if (!track)
return NULL;
return album_first_track(track->album);
}
/* not last album of the artist? */
if (rb_next(&CUR_ALBUM->tree_node) != NULL) {
/* first track of the next album */
@@ -262,6 +287,8 @@ static struct tree_track *normal_get_next(void)
static struct tree_track *normal_get_prev(void)
{
struct tree_track *track;
if (lib_cur_track == NULL)
return normal_get_first();
@@ -278,6 +305,21 @@ static struct tree_track *normal_get_prev(void)
return album_last_track(CUR_ALBUM);
}
if (aaa_mode == AAA_MODE_RANDOM_ALBUM) {
if (repeat)
/* last track of the current album */
return album_last_track(CUR_ALBUM);
/* go through shuffle list until we reach a song that is not on
* the current album */
track = (struct tree_track *)shuffle_list_get_next(&lib_shuffle_root,
(struct shuffle_track *)lib_cur_track,
next_random_album_filter);
if (!track)
return NULL;
return album_last_track(track->album);
}
/* not first album of the artist? */
if (rb_prev(&CUR_ALBUM->tree_node) != NULL) {
/* last track of the prev album of the artist */
View
3 lib.h
@@ -87,7 +87,8 @@ const char *artist_sort_name(const struct artist *);
enum aaa_mode {
AAA_MODE_ALL,
AAA_MODE_ARTIST,
AAA_MODE_ALBUM
AAA_MODE_ALBUM,
AAA_MODE_RANDOM_ALBUM
};
extern struct editable lib_editable;
View
@@ -649,7 +649,7 @@ static void toggle_display_artist_sort_name(void *data)
}
const char * const aaa_mode_names[] = {
"all", "artist", "album", NULL
"all", "artist", "album", "random album", NULL
};
static void get_aaa_mode(void *data, char *buf, size_t size)
@@ -661,7 +661,7 @@ static void set_aaa_mode(void *data, const char *buf)
{
int tmp;
if (!parse_enum(buf, 0, 2, aaa_mode_names, &tmp))
if (!parse_enum(buf, 0, 3, aaa_mode_names, &tmp))
return;
aaa_mode = tmp;
@@ -674,7 +674,7 @@ static void toggle_aaa_mode(void *data)
play_library = 1;
aaa_mode++;
aaa_mode %= 3;
aaa_mode %= 4;
update_statusline();
}

0 comments on commit 1bf405c

Please sign in to comment.