Code

playlist: added function playlist_move()
authorMax Kellermann <max@duempel.org>
Sun, 18 Oct 2009 00:20:11 +0000 (02:20 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 18 Oct 2009 00:20:11 +0000 (02:20 +0200)
src/playlist.c
src/playlist.h

index dfe9cad57b32b0a763eb50cc4aa233312565560c..2ce7ae2b697d9e9f3d277192aafe8d3c5c078377 100644 (file)
@@ -65,6 +65,32 @@ playlist_get_song(const struct mpdclient_playlist *playlist, gint idx)
        return playlist_get(playlist, idx);
 }
 
+void
+playlist_move(struct mpdclient_playlist *playlist,
+             unsigned dest, unsigned src)
+{
+       struct mpd_song *song;
+
+       assert(playlist != NULL);
+       assert(src < playlist_length(playlist));
+       assert(dest < playlist_length(playlist));
+       assert(src != dest);
+
+       song = playlist_get(playlist, src);
+
+       if (src < dest) {
+               memmove(&playlist->list->pdata[src],
+                       &playlist->list->pdata[src + 1],
+                       sizeof(playlist->list->pdata[0]) * (dest - src));
+               playlist->list->pdata[dest] = song;
+       } else {
+               memmove(&playlist->list->pdata[dest + 1],
+                       &playlist->list->pdata[dest],
+                       sizeof(playlist->list->pdata[0]) * (src - dest));
+               playlist->list->pdata[dest] = song;
+       }
+}
+
 const struct mpd_song *
 playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id)
 {
index 45046880869d3c545f42158c767c8dd32b3f8ad9..8768b9e5a5bcd366cd9438cb591e80d30f7a515a 100644 (file)
@@ -113,6 +113,10 @@ playlist_swap(struct mpdclient_playlist *playlist, guint idx1, guint idx2)
        g_ptr_array_index(playlist->list, idx2) = song1;
 }
 
+void
+playlist_move(struct mpdclient_playlist *playlist,
+             unsigned dest, unsigned src);
+
 const struct mpd_song *
 playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id);