diff options
author | Romain Bignon <romain@peerfuse.org> | 2009-02-13 10:38:32 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-13 10:43:30 +0100 |
commit | 9fe459f62581be39228dfbd69c1151df04fb6abe (patch) | |
tree | 18bcaacf8c814e249ede958c30a4f2a5db424549 /src/playlist_edit.c | |
parent | beaf860a17eeae561c5e197274533b72b8f5398c (diff) | |
download | mpd-9fe459f62581be39228dfbd69c1151df04fb6abe.tar.gz mpd-9fe459f62581be39228dfbd69c1151df04fb6abe.tar.xz mpd-9fe459f62581be39228dfbd69c1151df04fb6abe.zip |
added the shufflerange command
This command shuffles a range of songs.
Diffstat (limited to 'src/playlist_edit.c')
-rw-r--r-- | src/playlist_edit.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/playlist_edit.c b/src/playlist_edit.c index 1a76273b4..2c0c62eb6 100644 --- a/src/playlist_edit.c +++ b/src/playlist_edit.c @@ -353,42 +353,40 @@ moveSongInPlaylistById(struct playlist *playlist, unsigned id1, int to) return moveSongInPlaylist(playlist, song, to); } -void shufflePlaylist(struct playlist *playlist) +void shufflePlaylist(struct playlist *playlist, unsigned start, unsigned end) { const struct song *queued; - unsigned i; - if (queue_length(&playlist->queue) <= 1) + if (end-1 <= start || end > queue_length(&playlist->queue)) return; queued = playlist_get_queued_song(playlist); + if (playlist->playing && playlist->current >= 0) { + unsigned current_position; + current_position = queue_order_to_position(&playlist->queue, + playlist->current); - if (playlist->playing) { - if (playlist->current >= 0) + if (current_position >= start && current_position < end) + { /* put current playing song first */ - queue_swap(&playlist->queue, 0, - queue_order_to_position(&playlist->queue, - playlist->current)); - - if (playlist->queue.random) { - playlist->current = - queue_position_to_order(&playlist->queue, 0); - } else - playlist->current = 0; - - /* start shuffle after the current song */ - i = 1; + queue_swap(&playlist->queue, start, current_position); + + if (playlist->queue.random) { + playlist->current = + queue_position_to_order(&playlist->queue, start); + } else + playlist->current = start; + + /* start shuffle after the current song */ + start++; + } } else { - /* no playback currently: shuffle everything, and - reset playlist->current */ + /* no playback currently: reset playlist->current */ - i = 0; playlist->current = -1; } - /* shuffle the rest of the list */ - queue_shuffle_range(&playlist->queue, i, - queue_length(&playlist->queue)); + queue_shuffle_range(&playlist->queue, start, end); incrPlaylistVersion(playlist); |