diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-08-19 12:45:01 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-08-19 12:45:01 +0000 |
commit | 5e5f1e247b8f8596a8651f9119ec769d3e84c428 (patch) | |
tree | 3d730bc8137ef94404e4fee511ff0c259586341a /apps | |
parent | 43bcd823b7258ff763b93ca868f8ed9745a4f9df (diff) |
When shuffle is ENABLED. And you press PLAY in a dir, the selected song
is now the first song to get played. To do this, we first remember which
song that was selected, shuffle the list and then find the selected song
in the shuffled list and play that.
This will have some interesting side effects if the song ends up for example
last in the shuffled list when we consider not always doing repeat-all as
then it'll reach the end of the playlist after one song.
We could optionally put the selected song first in the playlist and then
shuffle all the rest, as that would possibly be closer to what people will
assume it will do.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1803 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/playlist.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index f3081397f6..9bd42941bc 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -167,15 +167,18 @@ char* playlist_next(int steps, int* index) } } -void play_list(char *dir, - char *file, - int start_index, - int start_offset, - int random_seed ) +/* + * This function is called to start playback of a given playlist. This + * playlist may be stored in RAM (when using full-dir playback). + */ +void play_list(char *dir, /* "current directory" */ + char *file, /* playlist */ + int start_index, /* index in the playlist */ + int start_offset, /* offset in the file */ + int random_seed ) /* used for shuffling */ { char *sep=""; int dirlen; - empty_playlist(); playlist.index = start_index; @@ -216,8 +219,31 @@ void play_list(char *dir, lcd_puts(0,LINE_Y,"Shuffling..."); status_draw(); lcd_update(); + randomise_playlist( random_seed ); + } + else { + int i; + + /* store the seek position before the shuffle */ + int seek_pos = playlist.indices[start_index]; + + /* now shuffle around the indices */ + randomise_playlist( random_seed ); + + /* Because the playlists in RAM is always dir-based playlists, + we want the selected file played first so we scan the list + for that file to be able to play that one first. */ + + for(i=0; i< playlist.amount; i++) { + if(seek_pos == playlist.indices[i]) { + /* here's the start song! yiepee! */ + playlist.index = i; + break; /* now stop searching */ + } + } + /* if we for any reason wouldn't find the index again, it won't + set the index again and we should start at index 0 instead */ } - randomise_playlist( random_seed ); } if(!playlist.in_ram) { |