Skip to content

Commit

Permalink
Experiment: Add option for flat library view
Browse files Browse the repository at this point in the history
  • Loading branch information
gavtroy committed Jul 22, 2023
1 parent afa2bdb commit 7697e0a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -231,6 +233,7 @@ enum format_id {
FMT_TRACKWIN_VA,
FMT_TREEWIN,
FMT_TREEWIN_ARTIST,
FMT_TREEWIN_FLAT,

NR_FMTS
};
Expand Down Expand Up @@ -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] =

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) */
Expand Down
41 changes: 26 additions & 15 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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));
}
Expand All @@ -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 */
Expand All @@ -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;
}
/* }}} */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7697e0a

Please sign in to comment.