tmus

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

commit c22fd8aeac8906739cf947b7da732876efba8d20
parent 53cb5a2a0d1540a37e6e5d1c1673e8354d5208a5
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat, 26 Feb 2022 03:21:10 +0100

Keybind for seek to playing, keybind for delete

Diffstat:
Msrc/cmd.h | 5-----
Msrc/data.c | 39+++++++++++++++++++++++++++++++++++++++
Msrc/data.h | 3+++
Msrc/tui.c | 18++++++++++++++++++
Msrc/tui.h | 5+++++
5 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/src/cmd.h b/src/cmd.h @@ -3,11 +3,6 @@ #include <stdlib.h> #include <stdbool.h> -#define CMD_SET_STATUS(...) do { \ - free(cmd_status); \ - cmd_status = aprintf(__VA_ARGS__); \ - } while (0) - typedef bool (*cmd_func)(const char *args); struct cmd { diff --git a/src/data.c b/src/data.c @@ -6,6 +6,7 @@ #include "ref.h" #include "track.h" #include "tag.h" +#include "tui.h" #include <fts.h> #include <dirent.h> @@ -319,6 +320,44 @@ tracks_save(struct tag *tag) } bool +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; + } + } + + for (LIST_ITER(&track->tags, link)) { + ref = UPCAST(link, struct ref); + tag = ref->data; + refs_rm(&tag->tracks, track); + } + + if (player.track == track) + player.track = NULL; + + track_free(track); + + return true; +} + +bool make_dir(const char *path) { return mkdir(path, S_IRWXU | S_IRWXG) == 0; diff --git a/src/data.h b/src/data.h @@ -1,6 +1,7 @@ #pragma once #include "tag.h" +#include "track.h" void data_load(void); void data_save(void); @@ -13,6 +14,8 @@ bool tracks_update(struct tag *tag); void tracks_load(struct tag *tag); void tracks_save(struct tag *tag); +bool track_rm(struct track *track); + bool make_dir(const char *path); bool rm_dir(const char *path, bool recursive); bool rm_file(const char *path); diff --git a/src/tui.c b/src/tui.c @@ -331,6 +331,7 @@ track_pane_input(wint_t c) { struct link *link; struct track *track; + int index; switch (c) { case KEY_UP: @@ -359,6 +360,23 @@ track_pane_input(wint_t c) case 'G': listnav_update_sel(&track_nav, track_nav.max - 1); break; + case 'n': + index = 0; + for (LIST_ITER(tracks_vis, link)) { + track = UPCAST(link, struct ref)->data; + if (track == player.track) { + listnav_update_sel(&track_nav, index); + break; + } + index += 1; + } + break; + case 'D': + link = list_at(tracks_vis, track_nav.sel); + ASSERT(link != NULL); + track = UPCAST(link, struct ref)->data; + track_rm(track); + break; } return false; diff --git a/src/tui.h b/src/tui.h @@ -6,6 +6,11 @@ #include <stdbool.h> +#define CMD_SET_STATUS(...) do { \ + free(cmd_status); \ + cmd_status = aprintf(__VA_ARGS__); \ + } while (0) + void tui_init(void); void tui_deinit(void);