playlist: allow move to specify offset from current song

If (and only if) there is a current song in the playlist,
(player could be stopped), allow the move destination
argument to be specified as a negative number.

This means moving any song (besides the current one) to the -1
position will allow it to be moved to the next song in the
playlist.  Moving any song to position -2 will move it
to the song after the next, and so forth.

Moving a song to -playlist.length will move it to the song
_before_ the current song on the playlist; so this will
work for repeating playlists, too.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7152 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2008-01-26 12:47:00 +00:00
parent 9eee1a81cf
commit e213ca4f8b

View File

@ -1153,12 +1153,21 @@ int moveSongInPlaylist(int fd, int from, int to)
return -1;
}
if (to < 0 || to >= playlist.length) {
if ((to >= 0 && to >= playlist.length) ||
(to < 0 && abs(to) > playlist.length)) {
commandError(fd, ACK_ERROR_NO_EXIST,
"song doesn't exist: \"%i\"", to);
return -1;
}
/*
* (to < 0) => move to offset from current song
* (-playlist.length == to) => move to position BEFORE current song
*/
if (to < 0 && playlist.current >= 0)
to = (playlist.order[playlist.current] + abs(to)) %
playlist.length;
if (playlist_state == PLAYLIST_STATE_PLAY) {
if (playlist.queued >= 0) {
queuedSong = playlist.order[playlist.queued];