From ff50fa8077634df562da6e4632fa4d7be66f0e9f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 18 Oct 2009 01:04:11 +0200 Subject: [PATCH] mpdclient: update mpdclient.playlist in mpdclient_cmd_clear() Reduce UI latency. --- src/mpdclient.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index dbe931c..04c1435 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -301,18 +301,43 @@ bool mpdclient_cmd_clear(struct mpdclient *c) { struct mpd_connection *connection = mpdclient_get_connection(c); - bool retval; + struct mpd_status *status; if (connection == NULL) return false; - mpd_send_clear(connection); - retval = mpdclient_finish_command(c); + /* send "clear" and "status" */ + if (!mpd_command_list_begin(connection, false) || + !mpd_send_clear(connection) || + !mpd_send_status(connection) || + !mpd_command_list_end(connection)) + return mpdclient_handle_error(c); - if (retval) - c->events |= MPD_IDLE_PLAYLIST; + /* receive the new status, store it in the mpdclient struct */ - return retval; + status = mpd_recv_status(connection); + if (status == NULL) + return mpdclient_handle_error(c); + + if (c->status != NULL) + mpd_status_free(c->status); + c->status = status; + + if (!mpd_response_finish(connection)) + return mpdclient_handle_error(c); + + /* update mpdclient.playlist */ + + if (mpd_status_get_queue_length(status) == 0) { + /* after the "clear" command, the queue is really + empty - this means we can clear it locally, + reducing the UI latency */ + playlist_clear(&c->playlist); + c->playlist.version = mpd_status_get_queue_version(status); + } + + c->events |= MPD_IDLE_QUEUE; + return true; } bool -- 2.30.2