From 06932304140a75a65b6eb3f68939e50a36e2398d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 18 Oct 2009 02:20:11 +0200 Subject: [PATCH] playlist: added function playlist_move() --- src/playlist.c | 26 ++++++++++++++++++++++++++ src/playlist.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/src/playlist.c b/src/playlist.c index dfe9cad..2ce7ae2 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -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) { diff --git a/src/playlist.h b/src/playlist.h index 4504688..8768b9e 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -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); -- 2.30.2