tmus

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

commit 5d8e3d19823a3c193b0ad4e8d8fd3ccdf8f77c80
parent c22fd8aeac8906739cf947b7da732876efba8d20
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat, 26 Feb 2022 13:34:44 +0100

Update player playlist on changes to tag tracks

Diffstat:
Msrc/cmd.c | 2++
Msrc/data.c | 36+++++++++++++++++++++++++-----------
Msrc/data.h | 2++
Msrc/history.c | 2+-
Msrc/tui.c | 12+-----------
5 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/cmd.c b/src/cmd.c @@ -71,6 +71,8 @@ cmd_move(const char *name) link_pop(link); list_push_back(&tag->tracks, link); + playlist_update(); + return 1; } diff --git a/src/data.c b/src/data.c @@ -233,11 +233,33 @@ tracks_update(struct tag *tag) list_sort(&tracks, track_fid_compare); + playlist_update(); + closedir(dir); return true; } void +playlist_update(void) +{ + struct link *link, *link2; + struct track *track; + struct ref *ref; + struct tag *tag; + + refs_free(&player.playlist); + for (LIST_ITER(&tags_sel, link)) { + tag = UPCAST(link, struct ref)->data; + for (LIST_ITER(&tag->tracks, link2)) { + track = UPCAST(link2, struct ref)->data; + ref = ref_alloc(track); + ASSERT(ref != NULL); + list_push_back(&player.playlist, LINK(ref)); + } + } +} + +void tracks_load(struct tag *tag) { char linebuf[1024]; @@ -325,23 +347,13 @@ track_rm(struct track *track) struct link *link; struct ref *ref; struct tag *tag; - bool found; if (!rm_file(track->fpath)) { CMD_SET_STATUS("Failed to remove track"); return false; } - found = false; - for (LIST_ITER(&tracks, link)) { - ref = UPCAST(link, struct ref); - if (ref->data == track) { - link_pop(link); - ref_free(ref); - found = true; - break; - } - } + refs_rm(&tracks, track); for (LIST_ITER(&track->tags, link)) { ref = UPCAST(link, struct ref); @@ -349,6 +361,8 @@ track_rm(struct track *track) refs_rm(&tag->tracks, track); } + refs_rm(&player.playlist, track); + if (player.track == track) player.track = NULL; diff --git a/src/data.h b/src/data.h @@ -11,6 +11,8 @@ int get_fid(const char *path); int track_fid_compare(struct link *a, struct link *b); void index_update(struct tag *tag); bool tracks_update(struct tag *tag); +void playlist_update(void); + void tracks_load(struct tag *tag); void tracks_save(struct tag *tag); diff --git a/src/history.c b/src/history.c @@ -234,7 +234,7 @@ inputln_replace(struct inputln *line, const char *str) line->len = strlen(str); if (line->cap <= line->len) inputln_resize(line, line->len + 1); - strncpy(line->buf, str, line->len); + strncpy(line->buf, str, line->len + 1); line->cur = line->len; } diff --git a/src/tui.c b/src/tui.c @@ -237,15 +237,7 @@ toggle_current_tag(void) } /* rebuild the full playlist */ - refs_free(&player.playlist); - for (LIST_ITER(&tags_sel, link)) { - tag = UPCAST(link, struct ref)->data; - for (LIST_ITER(&tag->tracks, iter)) { - ref = ref_alloc(UPCAST(iter, struct ref)->data); - ASSERT(ref != NULL); - list_push_back(&player.playlist, LINK(ref)); - } - } + playlist_update(); } bool @@ -755,11 +747,9 @@ main_input(wint_t c) case L'c': player_toggle_pause(); break; - case L'n': case L'>': player_next(); break; - case L'p': case L'<': player_prev(); break;