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
This commit is contained in:
Jonathan Gordon 2006-12-26 13:31:04 +00:00
parent 6ee5e38494
commit be3f29cc11
6 changed files with 80 additions and 2 deletions

View file

@ -10442,3 +10442,17 @@
*: "Clear Time?"
</voice>
</phrase>
<phrase>
id: LANG_REPLACE
desc: in onplay menu. Replace the current playlist with a new one.
user:
<source>
*: "Play Next"
</source>
<dest>
*: "Play Next"
</dest>
<voice>
*: "Play Next"
</voice>
</phrase>

View file

@ -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))

View file

@ -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 = &current_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
@ -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)

View file

@ -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__ */

View file

@ -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;

View file

@ -256,3 +256,4 @@ Robert Carboneau
Ye Wei
Bryan Childs
Mike Schmitt
Chris Taylor