From cde4cb944ebcc5b4db46afa5458a5d0a728c4866 Mon Sep 17 00:00:00 2001 From: Vladimir S Eremin Date: Sun, 8 Feb 2009 06:21:00 +0100 Subject: [PATCH] playlist: provide information about "next song" In random mode, this patch allows clients to see the "next song" in the queue. --- src/command.c | 10 ++++++++++ src/playlist.c | 15 +++++++++++++++ src/playlist.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/command.c b/src/command.c index a8a72b670..3b8ae9567 100644 --- a/src/command.c +++ b/src/command.c @@ -62,6 +62,8 @@ #define COMMAND_STATUS_PLAYLIST_LENGTH "playlistlength" #define COMMAND_STATUS_SONG "song" #define COMMAND_STATUS_SONGID "songid" +#define COMMAND_STATUS_NEXTSONG "nextsong" +#define COMMAND_STATUS_NEXTSONGID "nextsongid" #define COMMAND_STATUS_TIME "time" #define COMMAND_STATUS_BITRATE "bitrate" #define COMMAND_STATUS_ERROR "error" @@ -508,6 +510,14 @@ handle_status(struct client *client, getPlayerErrorStr()); } + song = getPlaylistNextSong(&g_playlist); + if (song >= 0) { + client_printf(client, + COMMAND_STATUS_NEXTSONG ": %i\n" + COMMAND_STATUS_NEXTSONGID ": %u\n", + song, getPlaylistSongId(&g_playlist, song)); + } + return COMMAND_RETURN_OK; } diff --git a/src/playlist.c b/src/playlist.c index 3b9c33ce8..ed430bf6e 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -334,6 +334,21 @@ int getPlaylistCurrentSong(const struct playlist *playlist) return -1; } +int getPlaylistNextSong(const struct playlist *playlist) +{ + if (playlist->current >= 0) + { + if (queue_length(&playlist->queue) > 1) + return queue_order_to_position(&playlist->queue, + playlist->current + 1); + else if (playlist->queue.repeat == 1) + return queue_order_to_position(&playlist->queue, + playlist->current); + } + + return -1; +} + unsigned long getPlaylistVersion(const struct playlist *playlist) { diff --git a/src/playlist.h b/src/playlist.h index b0e296bc5..7c3eb337a 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -180,6 +180,8 @@ void setPlaylistRandomStatus(struct playlist *playlist, bool status); int getPlaylistCurrentSong(const struct playlist *playlist); +int getPlaylistNextSong(const struct playlist *playlist); + unsigned getPlaylistSongId(const struct playlist *playlist, unsigned song);