tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit fa85a8895cf8fb347f36801d7255a07662e1e09d
parent 5a77c503e7f9b19cbe6434167478151162b6c046
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 28 Feb 2022 12:23:18 +0100

Display loaded player track name if player.track not known

Diffstat:
Msrc/player.h | 3+++
Msrc/player_mpd.c | 9++++++++-
Msrc/tui.c | 10+++++++---
3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/player.h b/src/player.h @@ -40,6 +40,9 @@ struct player { /* last used track */ struct track *track; + /* player track name (not necessarily from player.track) */ + char *track_name; + /* player has a track is loaded (not necessarily player.track) */ bool loaded; diff --git a/src/player_mpd.c b/src/player_mpd.c @@ -230,6 +230,7 @@ player_init(void) list_init(&player.queue); player.track = NULL; + player.track_name = NULL; player.loaded = 0; player.autoplay = true; @@ -251,7 +252,9 @@ player_deinit(void) list_clear(&player.playlist); list_clear(&player.queue); list_clear(&player.history); - if (player.status) free(player.status); + + free(player.status); + free(player.track_name); if (mpd.conn) mpd_connection_free(mpd.conn); } @@ -315,11 +318,15 @@ player_update(void) current_song = mpd_run_current_song(mpd.conn); if (current_song) { + player.track_name = strdup(mpd_song_get_uri(current_song)); + OOM_CHECK(player.track_name); player.loaded = true; player.time_pos = mpd_status_get_elapsed_time(status); player.time_end = mpd_song_get_duration(current_song); mpd_song_free(current_song); } else { + free(player.track_name); + player.track_name = NULL; player.loaded = false; player.time_pos = 0; player.time_end = 0; diff --git a/src/tui.c b/src/tui.c @@ -56,7 +56,6 @@ static void tag_pane_vis(struct pane *pane, int sel); static bool play_selected_track(void); static bool seek_playing_track_tag(void); static bool seek_playing_track(void); - static void delete_selected_track(void); static bool track_pane_input(wint_t c); @@ -763,9 +762,14 @@ cmd_pane_vis(struct pane *pane, int sel) /* track name */ style_on(pane->win, STYLE_TITLE); pane_clearln(pane, 0); - if (player.loaded && player.track) { + if (player.loaded) { strbuf_clear(&line); - strbuf_append(&line, " %s", player.track->name); + if (player.track) + strbuf_append(&line, " %s", player.track->name); + else if (player.track_name) + strbuf_append(&line, " %s", player.track_name); + else + strbuf_append(&line, "<UNKNOWN>"); pane_writeln(pane, 0, line.buf); } style_off(pane->win, STYLE_TITLE);