aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist_edit.c
diff options
context:
space:
mode:
authorJeffrey Middleton <jeffrey.r.middleton@nasa.gov>2009-03-26 22:02:56 +0100
committerMax Kellermann <max@duempel.org>2009-03-26 22:02:56 +0100
commit13208bf5a7c91a6406195139f1068f173ccdac94 (patch)
tree9e4d346b9ec78eb84be3f7cb079206eb86977fe4 /src/playlist_edit.c
parent7684c446c6f9b699ae4ea30b59cde81ec31efa53 (diff)
downloadmpd-13208bf5a7c91a6406195139f1068f173ccdac94.tar.gz
mpd-13208bf5a7c91a6406195139f1068f173ccdac94.tar.xz
mpd-13208bf5a7c91a6406195139f1068f173ccdac94.zip
queue/playlist/command: move range
The move command now accepts a range for the first argument, in the same form as other range commands, e.g. move 15:17 3. The first song in the range is placed at the destination position. Note that as with other range commands, the range is inclusive on the left only; this example would move only songs 15 and 16, not 17. [mk: fixed signed/unsigned warnings; use G_MAXUINT instead of UINT_MAX]
Diffstat (limited to '')
-rw-r--r--src/playlist_edit.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/playlist_edit.c b/src/playlist_edit.c
index 8580a5030..b83dc0933 100644
--- a/src/playlist_edit.c
+++ b/src/playlist_edit.c
@@ -290,19 +290,21 @@ deleteASongFromPlaylist(struct playlist *playlist, const struct song *song)
}
enum playlist_result
-moveSongInPlaylist(struct playlist *playlist, unsigned from, int to)
+moveSongRangeInPlaylist(struct playlist *playlist, unsigned start, unsigned end, int to)
{
const struct song *queued;
int currentSong;
- if (!queue_valid_position(&playlist->queue, from))
+ if (!queue_valid_position(&playlist->queue, start) ||
+ !queue_valid_position(&playlist->queue, end - 1))
return PLAYLIST_RESULT_BAD_RANGE;
- if ((to >= 0 && to >= (int)queue_length(&playlist->queue)) ||
+ if ((to >= 0 && to + end - start - 1 >= queue_length(&playlist->queue)) ||
(to < 0 && abs(to) > (int)queue_length(&playlist->queue)))
return PLAYLIST_RESULT_BAD_RANGE;
- if ((int)from == to) /* no-op */
+ if ((int)start == to)
+ /* nothing happens */
return PLAYLIST_RESULT_SUCCESS;
queued = playlist_get_queued_song(playlist);
@@ -316,24 +318,27 @@ moveSongInPlaylist(struct playlist *playlist, unsigned from, int to)
playlist->current)
: -1;
if (to < 0 && playlist->current >= 0) {
- if ((unsigned)currentSong == from)
+ if (start <= (unsigned)currentSong && (unsigned)currentSong <= end)
/* no-op, can't be moved to offset of itself */
return PLAYLIST_RESULT_SUCCESS;
to = (currentSong + abs(to)) % queue_length(&playlist->queue);
+ if (start < (unsigned)to)
+ to--;
}
- queue_move(&playlist->queue, from, to);
+ queue_move_range(&playlist->queue, start, end, to);
if (!playlist->queue.random) {
/* update current/queued */
- if (playlist->current == (int)from)
- playlist->current = to;
- else if (playlist->current > (int)from &&
+ if ((int)start <= playlist->current &&
+ (unsigned)playlist->current < end)
+ playlist->current += to - start;
+ else if (playlist->current >= (int)end &&
playlist->current <= to) {
- playlist->current--;
+ playlist->current -= end - start;
} else if (playlist->current >= to &&
- playlist->current < (int)from) {
- playlist->current++;
+ playlist->current < (int)start) {
+ playlist->current += end - start;
}
}
@@ -351,7 +356,7 @@ moveSongInPlaylistById(struct playlist *playlist, unsigned id1, int to)
if (song < 0)
return PLAYLIST_RESULT_NO_SUCH_SONG;
- return moveSongInPlaylist(playlist, song, to);
+ return moveSongRangeInPlaylist(playlist, song, song+1, to);
}
void shufflePlaylist(struct playlist *playlist, unsigned start, unsigned end)