summaryrefslogtreecommitdiff
path: root/src/playlist.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-01-26 12:47:00 +0000
committerEric Wong <normalperson@yhbt.net>2008-01-26 12:47:00 +0000
commite213ca4f8bf7b5cf309d6735a64fd799009d398c (patch)
treed043809558c99f13b16495030bcc3386e9fc70aa /src/playlist.c
parent9eee1a81cf99d351d78bd6550dfa6646be364f3e (diff)
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
Diffstat (limited to 'src/playlist.c')
-rw-r--r--src/playlist.c11
1 files changed, 10 insertions, 1 deletions
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];