tmus

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

commit 2517cc93304c0783deaa89aaa01d4e665013fc3e
parent 2ae8c06105a9323d6e3869b7ec01fd73c9bb148e
Author: Louis Burda <quent.burda@gmail.com>
Date:   Tue,  7 Mar 2023 12:01:31 +0100

Remember playing track when reindexing tags

Diffstat:
Msrc/tui.c | 49++++++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/tui.c b/src/tui.c @@ -77,7 +77,6 @@ static void cmd_pane_vis(struct pane *pane, int sel); static void update_tracks_vis(void); static void reindex_selected_tags(void); -static void reindex_current_tag(void); static void main_input(wint_t c); static void main_vis(void); @@ -1101,24 +1100,39 @@ reindex_selected_tags(void) { struct link *link; struct tag *tag; + struct track *track; + struct tag *playing_tag; + char *playing_name; - for (LIST_ITER(&tags_sel, link)) { - tag = UPCAST(link, struct tag, link_sel); - tracks_update(tag); - } -} + playing_tag = NULL; + playing_name = NULL; -void -reindex_current_tag(void) -{ - struct link *link; - struct tag *tag; + if (player.track) { + playing_tag = player.track->tag; + playing_name = astrdup(player.track->name); + } - link = list_at(&tags, tag_nav.sel); - if (!link) return; + if (track_show_playlist) { + for (LIST_ITER(&tags_sel, link)) { + tag = UPCAST(link, struct tag, link_sel); + tracks_update(tag); + } + } else { + link = list_at(&tags, tag_nav.sel); + if (!link) return; + tag = UPCAST(link, struct tag, link); + tracks_update(tag); + } - tag = UPCAST(link, struct tag, link); - tracks_update(tag); + if (playing_tag) { + for (LIST_ITER(&playing_tag->tracks, link)) { + track = UPCAST(link, struct track, link_tt); + if (!strcmp(track->name, playing_name)) { + player.track = track; + break; + } + } + } } void @@ -1203,10 +1217,7 @@ main_input(wint_t c) refresh(); break; case KEY_CTRL(L'r'): - if (track_show_playlist) - reindex_selected_tags(); - else - reindex_current_tag(); + reindex_selected_tags(); break; case L'q': quit = 1;