From e213ca4f8bf7b5cf309d6735a64fd799009d398c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Jan 2008 12:47:00 +0000 Subject: 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 --- src/playlist.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 16fb4693c..a2dfd0602 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -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]; -- cgit v1.2.3