From 7697e0ab1a498793febb4819ee10cb3d14cea0d2 Mon Sep 17 00:00:00 2001 From: Gavin Troy Date: Sat, 22 Jul 2023 02:16:12 +0100 Subject: [PATCH] Experiment: Add option for flat library view --- Doc/cmus.txt | 7 +++++++ options.c | 24 ++++++++++++++++++++++++ options.h | 2 ++ tree.c | 41 ++++++++++++++++++++++++++--------------- ui_curses.c | 7 ++++++- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/Doc/cmus.txt b/Doc/cmus.txt index 1bd5bc3be..084340f74 100644 --- a/Doc/cmus.txt +++ b/Doc/cmus.txt @@ -1022,6 +1022,9 @@ display_artist_sort_name (false) regular ones in tree view (e.g. "Artist, The" instead of "The Artist"), so that artists column looks alphabetically sorted. +flat_library_view (false) + In the tree view, display artist and album names on the same line. + follow (false) If enabled, always select the currently playing track on track change. @@ -1070,6 +1073,10 @@ format_treewin [`Format String`] format_treewin_artist [`Format String`] Format string for artists in tree view's (1) tree window. +format_treewin_flat [`Format String`] + Format string for the tree view's (1) tree window when + *flat_library_view* is active. + smart_artist_sort (true) If enabled, makes the tree view sorting ignore "The" in front of artist names, preventing artists starting with "The" from clumping together. diff --git a/options.c b/options.c index 703729a7e..4c2963ee4 100644 --- a/options.c +++ b/options.c @@ -83,6 +83,7 @@ int ignore_duplicates = 0; int auto_expand_albums_follow = 1; int auto_expand_albums_search = 1; int auto_expand_albums_selcur = 1; +int flat_library_view = 0; int auto_hide_playlists_panel = 0; int show_all_tracks = 1; int mouse = 0; @@ -145,6 +146,7 @@ int attrs[NR_ATTRS] = { /* uninitialized option variables */ char *tree_win_format = NULL; +char *tree_win_flat_format = NULL; char *tree_win_artist_format = NULL; char *track_win_album_format = NULL; char *track_win_format = NULL; @@ -231,6 +233,7 @@ enum format_id { FMT_TRACKWIN_VA, FMT_TREEWIN, FMT_TREEWIN_ARTIST, + FMT_TREEWIN_FLAT, NR_FMTS }; @@ -265,6 +268,7 @@ static const struct { [FMT_TRACKWIN_VA] = { "format_trackwin_va" , "%3n. %t (%a)%= %y %d " }, [FMT_TREEWIN] = { "format_treewin" , " %l" }, [FMT_TREEWIN_ARTIST] = { "format_treewin_artist" , "%a" }, + [FMT_TREEWIN_FLAT] = { "format_treewin_flat" , "%-35%a: %l" }, [NR_FMTS] = @@ -566,6 +570,23 @@ static void set_pl_env_vars(void *data, const char *buf) /* callbacks for toggle options {{{ */ +static void get_flat_library_view(void *data, char *buf, size_t size) +{ + strscpy(buf, bool_names[flat_library_view], size); +} + +static void set_flat_library_view(void *data, const char *buf) +{ + parse_bool(buf, &flat_library_view); + window_set_contents(lib_tree_win, &lib_artist_root); +} + +static void toggle_flat_library_view(void *data) +{ + flat_library_view ^= 1; + window_set_contents(lib_tree_win, &lib_artist_root); +} + static void get_auto_hide_playlists_panel(void *data, char *buf, size_t size) { strscpy(buf, bool_names[auto_hide_playlists_panel], size); @@ -1478,6 +1499,8 @@ static char **id_to_fmt(enum format_id id) return &tree_win_format; case FMT_TREEWIN_ARTIST: return &tree_win_artist_format; + case FMT_TREEWIN_FLAT: + return &tree_win_flat_format; case FMT_STATUSLINE: return &statusline_format; default: @@ -1557,6 +1580,7 @@ static const struct { DT(auto_expand_albums_follow) DT(auto_expand_albums_search) DT(auto_expand_albums_selcur) + DT(flat_library_view) DT(auto_hide_playlists_panel) DT(show_all_tracks) DT(show_current_bitrate) diff --git a/options.h b/options.h index 521970778..fcea6259d 100644 --- a/options.h +++ b/options.h @@ -134,6 +134,7 @@ extern char *server_password; extern int auto_expand_albums_follow; extern int auto_expand_albums_search; extern int auto_expand_albums_selcur; +extern int flat_library_view; extern int auto_hide_playlists_panel; extern int show_all_tracks; extern int auto_reshuffle; @@ -172,6 +173,7 @@ extern int attrs[NR_ATTRS]; /* format string for tree window (tree view) */ extern char *tree_win_format; +extern char *tree_win_flat_format; extern char *tree_win_artist_format; /* format string for track window (tree view) */ diff --git a/tree.c b/tree.c index c383ed22d..1dbd41856 100644 --- a/tree.c +++ b/tree.c @@ -216,7 +216,7 @@ static int tree_get_prev(struct iter *iter) return 0; } artist = to_artist(rb_last(root)); - if (artist->expanded) { + if (artist->expanded || flat_library_view) { album = to_album(rb_last(&artist->album_root)); } else { album = NULL; @@ -225,11 +225,13 @@ static int tree_get_prev(struct iter *iter) iter->data2 = album; return 1; } - if (artist->expanded && album) { + if ((artist->expanded || flat_library_view) && album) { /* prev album */ if (rb_prev(&album->tree_node) == NULL) { - iter->data2 = NULL; - return 1; + if (!flat_library_view) { + iter->data2 = NULL; + return 1; + } } else { iter->data2 = to_album(rb_prev(&album->tree_node)); return 1; @@ -245,7 +247,7 @@ static int tree_get_prev(struct iter *iter) artist = to_artist(rb_prev(&artist->tree_node)); iter->data1 = artist; iter->data2 = NULL; - if (artist->expanded) { + if (artist->expanded || flat_library_view) { /* last album */ iter->data2 = to_album(rb_last(&artist->album_root)); } @@ -266,11 +268,13 @@ static int tree_get_next(struct iter *iter) /* empty, iter points to the head already */ return 0; } - iter->data1 = to_artist(rb_first(root)); - iter->data2 = NULL; - return 1; + iter->data1 = artist = to_artist(rb_first(root)); + if (!flat_library_view) { + iter->data2 = NULL; + return 1; + } } - if (artist->expanded) { + if (artist->expanded || flat_library_view) { /* next album */ if (album == NULL) { /* first album */ @@ -289,8 +293,12 @@ static int tree_get_next(struct iter *iter) iter->data2 = NULL; return 0; } - iter->data1 = to_artist(rb_next(&artist->tree_node)); - iter->data2 = NULL; + iter->data1 = artist = to_artist(rb_next(&artist->tree_node)); + if (!flat_library_view) { + iter->data2 = NULL; + return 1; + } + iter->data2 = to_album(rb_first(&artist->album_root)); return 1; } /* }}} */ @@ -732,7 +740,9 @@ static int tree_search_matches(void *data, struct iter *iter, const char *text) if (!track_info_matches(tree_track_info(track), text, flags)) return 0; - if (auto_expand_albums_search) { + if (flat_library_view) { + album_to_iter(track->album, &tmpiter); + } else if (auto_expand_albums_search) { /* collapse old search result */ if (collapse_artist) { struct artist *artist = do_find_artist(collapse_artist, &lib_artist_root, NULL, NULL); @@ -896,7 +906,7 @@ const char *tree_album_name(const struct track_info* ti) static void remove_album(struct album *album) { - if (album->artist->expanded) { + if (album->artist->expanded || flat_library_view) { struct iter iter; album_to_iter(album, &iter); @@ -910,7 +920,8 @@ static void remove_artist(struct artist *artist) struct iter iter; artist_to_iter(artist, &iter); - window_row_vanishes(lib_tree_win, &iter); + if (!flat_library_view) + window_row_vanishes(lib_tree_win, &iter); rb_erase(&artist->tree_node, &lib_artist_root); } @@ -1272,7 +1283,7 @@ void tree_sel_track(struct tree_track *t, int auto_expand_albums) if (auto_expand_albums) t->album->artist->expanded = 1; - if (t->album->artist->expanded) + if (t->album->artist->expanded || flat_library_view) album_to_iter(t->album, &iter); else artist_to_iter(t->album->artist, &iter); diff --git a/ui_curses.c b/ui_curses.c index 94702b18a..5b25e9609 100644 --- a/ui_curses.c +++ b/ui_curses.c @@ -684,7 +684,12 @@ static void print_tree(struct window *win, int row, struct iter *iter) } gbuf_add_ch(&print_buffer, ' '); - if (album) { + if (flat_library_view) { + if (album == NULL) + return; + fill_track_fopts_album(album); + format_print(&print_buffer, tree_win_w - 1, tree_win_flat_format, track_fopts); + } else if (album) { fill_track_fopts_album(album); format_print(&print_buffer, tree_win_w - 1, tree_win_format, track_fopts); } else {