tmus

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

commit 4b0b3da65906ae892fa3f46a3482dd36b32c816c
parent 69e7a9341e811bf658f8d75bb43f6613d298c87d
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat, 18 Dec 2021 13:11:07 +0100

Add player queuing

Diffstat:
Mlist.c | 6++++++
Mlist.h | 1+
Mmain.c | 28++++++++++++++++++++++++----
Mplayer.c | 22++++++++++++++++++----
4 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/list.c b/list.c @@ -2,6 +2,12 @@ #include "util.h" int +list_empty(struct link *head) +{ + return head->next == NULL; +} + +int list_len(struct link *head) { struct link *iter; diff --git a/list.h b/list.h @@ -19,6 +19,7 @@ struct link { /* list_XXX functions operate on the list head */ +int list_empty(struct link *head); int list_len(struct link *head); int list_ffind(struct link *head, struct link *link); diff --git a/main.c b/main.c @@ -14,6 +14,7 @@ #include "curses.h" #include <dirent.h> +#include <locale.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -157,6 +158,8 @@ init(void) { quit = 0; + setlocale(LC_ALL, ""); + /* TODO handle as character intead of signal */ signal(SIGINT, exit); atexit(cleanup); @@ -532,10 +535,10 @@ track_input(wint_t c) player_play_track(track); return 1; case KEY_PPAGE: - listnav_update_sel(&track_nav, track_nav.sel + track_nav.wlen / 2); + listnav_update_sel(&track_nav, track_nav.sel - track_nav.wlen / 2); return 1; case KEY_NPAGE: - listnav_update_sel(&track_nav, track_nav.sel - track_nav.wlen / 2); + listnav_update_sel(&track_nav, track_nav.sel + track_nav.wlen / 2); return 1; } @@ -667,7 +670,8 @@ cmd_input(wint_t c) inputln_copy(&completion_query, history->query); } - res = completion(completion_query.buf, c == KEY_TAB, completion_reset); + res = completion(completion_query.buf, + c == KEY_TAB, completion_reset); if (res) inputln_replace(history->query, res); free(res); @@ -703,7 +707,7 @@ cmd_vis(struct pane *pane, int sel) wmove(pane->win, 0, 0); style_on(pane->win, STYLE_TITLE); wprintw(pane->win, " %-*.*ls\n", pane->w - 1, pane->w - 1, - player->track ? player->track->name : L""); + player->track ? player->track->name : L""); style_off(pane->win, STYLE_TITLE); if (player->loaded) { @@ -714,6 +718,9 @@ cmd_vis(struct pane *pane, int sel) line = appendstrf(line, " - vol: %u%%", player->volume); if (player->msg) line = appendstrf(line, " | [PLAYER] %s", player->msg); + if (!list_empty(&player->queue)) + line = appendstrf(line, " | [QUEUE] %i tracks", + list_len(&player->queue)); wmove(pane->win, 1, 0); ATTR_ON(pane->win, A_REVERSE); @@ -755,6 +762,16 @@ cmd_vis(struct pane *pane, int sel) } void +queue_hover(void) +{ + struct link *link; + + link = link_iter(playlist.next, track_nav.sel); + ASSERT(link != NULL); + player_queue_append(UPCAST(link, struct ref)->data); +} + +void main_input(wint_t c) { switch (c) { @@ -781,6 +798,9 @@ main_input(wint_t c) } } break; + case L'y': + queue_hover(); + break; case L'c': player_toggle_pause(); break; diff --git a/player.c b/player.c @@ -62,6 +62,7 @@ player_update(void) { struct mpd_status *status; struct mpd_song *song; + struct ref *track; const char *tmp; status = mpd_run_status(player->conn); @@ -86,7 +87,15 @@ player_update(void) player->seek_delay -= 1; if (!player->seek_delay) player_play(); - } + } + + if (!mpd_run_current_song(player->conn) + && !list_empty(&player->queue)) { + track = UPCAST(link_pop(player->queue.next), + struct ref); + player_play_track(track->data); + ref_free(track); + } song = mpd_run_current_song(player->conn); if (song) { @@ -118,7 +127,12 @@ player_queue_clear(void) void player_queue_append(struct track *track) { - player_queue_insert(track, list_len(&player->queue)); + struct ref *ref; + struct link *link; + + ref = ref_init(track); + link = link_back(&player->queue); + link_append(link, LINK(ref)); } void @@ -128,8 +142,8 @@ player_queue_insert(struct track *track, size_t pos) struct link *link; ref = ref_init(track); - link = link_iter(&player->queue, pos); - link_append(link, &ref->link); + link = link_iter(player->queue.next, pos); + link_prepend(link, LINK(ref)); } int