From: Thomas Jansen Date: Fri, 11 Sep 2009 14:11:30 +0000 (+0200) Subject: update lyrics screen when a new song starts X-Git-Tag: release-0.15~22 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=444ca4c048001200a2d563c430e05d63fe2c8f3f;p=ncmpc.git update lyrics screen when a new song starts 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. --- diff --git a/src/screen.c b/src/screen.c index 1c44bf7..8e31d14 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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); diff --git a/src/screen.h b/src/screen.h index 601548c..343f944 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 diff --git a/src/screen_browser.c b/src/screen_browser.c index f8386bb..e1b2e5f 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -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: diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 51bb903..a1556ae 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -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); } diff --git a/src/screen_play.c b/src/screen_play.c index 46ad68e..3f79ad7 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -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; } diff --git a/src/screen_song.c b/src/screen_song.c index 8328415..6d27e56 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -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;