From 7dff5412bcd1fd92f164270931386237451588f5 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 20 Jul 2016 12:30:29 -0400 Subject: [PATCH] gui/artwork: Reduce time spent polling for artwork Since MusicBrainz limits us to one request each second, it doesn't really make sense to poll for new artwork every half second. Instead, let's just put this into a new timeout function that gets called every two seconds. This should also let us stop polling once artwork has been found. Signed-off-by: Anna Schumaker --- CHANGELOG | 1 + gui/artwork.c | 21 +++++++++++++++++++-- gui/audio.c | 3 --- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 21ba80ee..19d42066 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ 6.4.16: +- Reduce time spent polling for album art - Split album art code into a new file - Fix PKGBUILD dependencies diff --git a/gui/artwork.c b/gui/artwork.c index 9b8ed67e..7fd92952 100644 --- a/gui/artwork.c +++ b/gui/artwork.c @@ -6,6 +6,7 @@ #include static struct album *__artwork_cur_album = NULL; +static unsigned int __artwork_timeo_id = 0; static GdkPixbuf *__artwork_get_pixbuf(struct track *track) { @@ -24,14 +25,14 @@ static GdkPixbuf *__artwork_get_pixbuf(struct track *track) return pix; } -void gui_artwork_set_cover(void) +static bool __artwork_set_pixbuf(void) { GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover")); struct track *track = audio_cur_track(); GdkPixbuf *pix; if (!track || track->tr_album == __artwork_cur_album) - return; + return true; pix = __artwork_get_pixbuf(track); if (pix) { @@ -42,6 +43,22 @@ void gui_artwork_set_cover(void) gtk_widget_set_sensitive(GTK_WIDGET(cover), pix != NULL); __artwork_cur_album = pix ? track->tr_album : NULL; + return (pix != NULL); +} + +static gboolean __artwork_timeout(gpointer data) +{ + if (__artwork_set_pixbuf()) { + __artwork_timeo_id = 0; + return G_SOURCE_REMOVE; + } + return G_SOURCE_CONTINUE; +} + +void gui_artwork_set_cover(void) +{ + if (!__artwork_set_pixbuf() && __artwork_timeo_id == 0) + __artwork_timeo_id = g_timeout_add(2000, __artwork_timeout, NULL); } void __artwork_select_cover(GtkButton *button) diff --git a/gui/audio.c b/gui/audio.c index f0a01f5b..126ca662 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -95,9 +95,6 @@ static int __audio_timeout(gpointer data) gtk_adjustment_set_upper(progress, audio_duration() / GST_SECOND); gtk_adjustment_set_value(progress, audio_position() / GST_SECOND); __audio_set_time_label("o_position", audio_position() / GST_SECOND); - - gui_artwork_set_cover(); - return G_SOURCE_CONTINUE; }