Code

update lyrics screen when a new song starts
authorThomas Jansen <mithi@mithi.net>
Fri, 11 Sep 2009 14:11:30 +0000 (16:11 +0200)
committerThomas Jansen <mithi@mithi.net>
Fri, 11 Sep 2009 14:11:30 +0000 (16:11 +0200)
When a new song starts and the lyrics screen is displayed, fetch the lyrics
for the new song and display them. Don't switch to the new song's lyrics if
the lyrics screen was opened for a specific song.

src/screen.c
src/screen.h
src/screen_browser.c
src/screen_lyrics.c
src/screen_play.c
src/screen_song.c

index 1c44bf7e9cf991cf334e9d0f0d4f0d9dc69b7a9c..8e31d148ed7b804419ac69226b8da79cbc83ae95 100644 (file)
@@ -104,7 +104,7 @@ screen_swap(struct mpdclient *c, const struct mpd_song *song)
 #endif
 #ifdef ENABLE_LYRICS_SCREEN
                else if (mode_fn_prev == &screen_lyrics)
-                       screen_lyrics_switch(c, song);
+                       screen_lyrics_switch(c, song, true);
 #endif
                else
                        screen_switch(mode_fn_prev, c);
index 601548c0158ecf7edfd0d278b54aceccbb5a664e..343f9441ca65cb655fe57ca37ae5f437923edd4d 100644 (file)
@@ -133,7 +133,7 @@ screen_song_switch(struct mpdclient *c, const struct mpd_song *song);
 
 #ifdef ENABLE_LYRICS_SCREEN
 void
-screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song);
+screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song, bool follow);
 #endif
 
 #endif
index f8386bb426a45e1904ded9680882238fcb311ff1..e1b2e5fb6cf2688260ec95893d31615a564b6872 100644 (file)
@@ -544,7 +544,7 @@ browser_cmd(struct screen_browser *browser,
                    entry->entity->type != MPD_INFO_ENTITY_TYPE_SONG)
                        return true;
 
-               screen_lyrics_switch(c, entry->entity->info.song);
+               screen_lyrics_switch(c, entry->entity->info.song, false);
                return true;
 #endif
        case CMD_SCREEN_SWAP:
index 51bb903a88ad108edb153d7a9f946433021646fd..a1556aec582bbdf2cf2d2eb3ad9d013a41b3b812 100644 (file)
@@ -36,6 +36,7 @@
 static struct screen_text text;
 
 static const struct mpd_song *next_song;
+static bool follow = false;
 
 static struct {
        struct mpd_song *song;
@@ -212,6 +213,21 @@ lyrics_open(mpdclient_t *c)
        next_song = NULL;
 }
 
+static void
+lyrics_update(mpdclient_t *c)
+{
+       if (!follow)
+               return;
+
+       next_song = c->song;
+
+       if (next_song != NULL &&
+           (current.song == NULL ||
+            strcmp(next_song->file, current.song->file) != 0))
+               screen_lyrics_load(next_song);
+
+       next_song = NULL;
+}
 
 static const char *
 lyrics_title(char *str, size_t size)
@@ -297,6 +313,7 @@ const struct screen_functions screen_lyrics = {
        .init = lyrics_screen_init,
        .exit = lyrics_exit,
        .open = lyrics_open,
+       .update = lyrics_update,
        .close = NULL,
        .resize = lyrics_resize,
        .paint = lyrics_paint,
@@ -305,10 +322,11 @@ const struct screen_functions screen_lyrics = {
 };
 
 void
-screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song)
+screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song, bool f)
 {
        assert(song != NULL);
 
+       follow = f;
        next_song = song;
        screen_switch(&screen_lyrics, c);
 }
index 46ad68eb24dead84bafa53c51bd8fe6c3505d2e6..3f79ad75f7e71ed20ea5295ab37c6fa6ef4af146 100644 (file)
@@ -745,7 +745,14 @@ play_cmd(mpdclient_t *c, command_t cmd)
 #ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
                if (lw->selected < playlist_length(&c->playlist)) {
-                       screen_lyrics_switch(c, playlist_get(&c->playlist, lw->selected));
+                       struct mpd_song *selected = playlist_get(&c->playlist, lw->selected);
+                       bool follow = false;
+
+                       if (c->song && selected &&
+                           !strcmp(selected->file, c->song->file))
+                               follow = true;
+
+                       screen_lyrics_switch(c, selected, follow);
                        return true;
                }
 
index 8328415bf413a48bd63ba06c977e7733e91db68d..6d27e564a6ca8a23811f42f2f1986839cfdf493e 100644 (file)
@@ -373,11 +373,11 @@ screen_song_cmd(mpdclient_t *c, command_t cmd)
 #ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
                if (current.selected_song != NULL) {
-                       screen_lyrics_switch(c, current.selected_song);
+                       screen_lyrics_switch(c, current.selected_song, false);
                        return true;
                }
                if (current.played_song != NULL) {
-                       screen_lyrics_switch(c, current.played_song);
+                       screen_lyrics_switch(c, current.played_song, true);
                        return true;
                }
                return false;