From be3f29cc11a1d31a4bacee16a8ca2f1a9de2caed Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Tue, 26 Dec 2006 13:31:04 +0000 Subject: Accept FS#6464 by Chris Taylor. Adds a "Play Next" playlist insertion option which replaces the current playlist with the new selection but keeps the current track queued so playback doesnt stop. (minor fixes by me) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11842 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 14 ++++++++++++++ apps/onplay.c | 5 +++++ apps/playlist.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- apps/playlist.h | 4 +++- apps/tagtree.c | 6 ++++++ 5 files changed, 79 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 6681639aaa..84dea29f1b 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -10442,3 +10442,17 @@ *: "Clear Time?" + + id: LANG_REPLACE + desc: in onplay menu. Replace the current playlist with a new one. + user: + + *: "Play Next" + + + *: "Play Next" + + + *: "Play Next" + + diff --git a/apps/onplay.c b/apps/onplay.c index af6fa9cc57..98b1270b89 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -368,6 +368,11 @@ static bool playlist_options(void) args[i].position = PLAYLIST_INSERT_SHUFFLED; args[i].queue = true; i++; + + items[i].desc = ID2P(LANG_REPLACE); + args[i].position = PLAYLIST_REPLACE; + args[i].queue = false; + i++; } else if (((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) || (selected_file_attr & ATTR_DIRECTORY)) diff --git a/apps/playlist.c b/apps/playlist.c index e8f9d48ce0..27c8676b96 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -560,6 +560,33 @@ exit: return result; } +/* + * Removes all tracks, from the playlist, leaving the presently playing + * track queued. + */ +int remove_all_tracks(struct playlist_info *playlist) +{ + int result; + + if (playlist == NULL) + playlist = ¤t_playlist; + + while (playlist->index > 0) + if ((result = remove_track_from_playlist(playlist, 0, true)) < 0) + return result; + + while (playlist->amount > 1) + if ((result = remove_track_from_playlist(playlist, 1, true)) < 0) + return result; + + if (playlist->amount == 1) { + playlist->indices[0] |= PLAYLIST_QUEUED; + } + + return 0; +} + + /* * Add track to playlist at specified position. There are five special * positions that can be specified: @@ -572,6 +599,8 @@ exit: * PLAYLIST_INSERT_LAST - Add track to end of playlist * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the * current playing track and end of playlist + * PLAYLIST_REPLACE - Erase current playlist, Cue the current track + * and inster this track at the end. */ static int add_track_to_playlist(struct playlist_info* playlist, const char *filename, int position, @@ -648,6 +677,12 @@ static int add_track_to_playlist(struct playlist_info* playlist, position = insert_position = (rand() % (playlist->amount+1)); break; } + case PLAYLIST_REPLACE: + if (remove_all_tracks(playlist) < 0) + return -1; + + position = insert_position = playlist->index + 1; + break; } if (queue) @@ -2860,6 +2895,14 @@ int playlist_insert_directory(struct playlist_info* playlist, return -1; } + if (position == PLAYLIST_REPLACE) + { + if (remove_all_tracks(playlist) == 0) + position = PLAYLIST_INSERT_LAST; + else + return -1; + } + if (queue) count_str = str(LANG_PLAYLIST_QUEUE_COUNT); else @@ -2871,7 +2914,7 @@ int playlist_insert_directory(struct playlist_info* playlist, context.position = position; context.queue = queue; context.count = 0; - + cpu_boost(true); result = playlist_directory_tracksearch(dirname, recurse, @@ -2941,6 +2984,13 @@ int playlist_insert_playlist(struct playlist_info* playlist, char *filename, display_playlist_count(count, count_str); + if (position == PLAYLIST_REPLACE) + { + if (remove_all_tracks(playlist) == 0) + position = PLAYLIST_INSERT_LAST; + else return -1; + } + cpu_boost(true); while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) diff --git a/apps/playlist.h b/apps/playlist.h index 3270bc55fa..af9a09523f 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -48,7 +48,8 @@ enum { PLAYLIST_INSERT = -2, PLAYLIST_INSERT_LAST = -3, PLAYLIST_INSERT_FIRST = -4, - PLAYLIST_INSERT_SHUFFLED = -5 + PLAYLIST_INSERT_SHUFFLED = -5, + PLAYLIST_REPLACE = -6 }; enum { @@ -163,5 +164,6 @@ int playlist_save(struct playlist_info* playlist, char *filename); int playlist_directory_tracksearch(const char* dirname, bool recurse, int (*callback)(char*, void*), void* context); +int remove_all_tracks(struct playlist_info *playlist); #endif /* __PLAYLIST_H__ */ diff --git a/apps/tagtree.c b/apps/tagtree.c index d75b9eb667..d5d70ac206 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -1468,6 +1468,12 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue return false; } + if (position == PLAYLIST_REPLACE) + { + if (remove_all_tracks(NULL) == 0) + position = PLAYLIST_INSERT_LAST; + else return -1; } + if (position == PLAYLIST_INSERT_FIRST) { from = c->filesindir - 1; -- cgit