tmus

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

commit e5a55cc4cd55d33e8bfb50cda1bfbd2526108c13
parent 914add4cedb75bab216b5702e34e71b45005f905
Author: Louis Burda <quent.burda@gmail.com>
Date:   Mon, 28 Mar 2022 17:31:58 +0200

Fix track next selection not lru

Diffstat:
Msrc/data.c | 2+-
Msrc/main.c | 7-------
Msrc/player.h | 2+-
Msrc/player_mpd.c | 23+++++++++++++++--------
Msrc/tui.c | 4++--
5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/data.c b/src/data.c @@ -180,7 +180,7 @@ path_exists(const char *path) bool make_dir(const char *path) { - return mkdir(path, S_IRWXU | S_IRWXG) == 0; + return mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) == 0; } bool diff --git a/src/main.c b/src/main.c @@ -1,15 +1,8 @@ #include "data.h" -#include "history.h" -#include "list.h" -#include "listnav.h" #include "log.h" #include "mpris.h" -#include "pane.h" #include "player.h" -#include "ref.h" -#include "style.h" #include "tui.h" -#include "util.h" #include <locale.h> diff --git a/src/player.h b/src/player.h @@ -71,7 +71,7 @@ void player_deinit(void); void player_update(void); -int player_play_track(struct track *track); +int player_play_track(struct track *track, bool new); int player_toggle_pause(void); int player_pause(void); diff --git a/src/player_mpd.c b/src/player_mpd.c @@ -43,6 +43,7 @@ static int mpd_handle_status(int status); static bool history_contains(struct track *track, int depth); static struct track *playlist_track_lru(int skip); +static struct track *playlist_track_next_unused(int index); static void player_play_prev(void); static void player_play_next(void); @@ -127,7 +128,7 @@ playlist_track_lru(int skip) if (!history_contains(track, len - 1)) skip -= 1; - if (skip <= 0) break; + if (skip < 0) break; link = link->next; if (!LIST_INNER(link)) @@ -215,7 +216,7 @@ player_play_prev(void) } track = UPCAST(next, struct track, link_hs); - player_play_track(track); + player_play_track(track, false); } void @@ -223,23 +224,24 @@ player_play_next(void) { struct track *next_track; struct link *link; - - next_track = NULL; + bool new_entry; if (player.track && link_inuse(&player.track->link_hs) && LIST_INNER(player.track->link_hs.next)) { next_track = UPCAST(player.track->link_hs.next, struct track, link_hs); + new_entry = false; } else if (!list_empty(&player.queue)) { link = list_pop_front(&player.queue); next_track = UPCAST(link, struct track, link_pq); + new_entry = true; } else { next_track = player_next_from_playlist(); + if (!next_track) goto clear; + new_entry = true; } - if (!next_track) goto clear; - - player_play_track(next_track); + player_play_track(next_track, new_entry); return; clear: @@ -403,10 +405,12 @@ player_update(void) } int -player_play_track(struct track *track) +player_play_track(struct track *track, bool new) { int status; + ASSERT(track != NULL); + status = mpd_run_clear(mpd.conn); mpd_handle_status(status); @@ -422,6 +426,9 @@ player_play_track(struct track *track) if (player.track && !link_inuse(&player.track->link_hs)) player_add_history(player.track); + /* new invocations result in updated history pos */ + if (new) link_pop(&track->link_hs); + player.track = track; return PLAYER_STATUS_OK; diff --git a/src/tui.c b/src/tui.c @@ -455,7 +455,7 @@ play_selected_track(void) link = list_at(tracks_vis, track_nav.sel); if (!link) return false; track = tracks_vis_track(link); - player_play_track(track); + player_play_track(track, true); return true; } @@ -627,7 +627,7 @@ play_track(const char *query) for (LIST_ITER(&tracks, link)) { track = UPCAST(link, struct track, link); if (!strcmp(track->name, query)) { - player_play_track(track); + player_play_track(track, true); return true; } }