Skip to content

Add option to sort albums by name in tree view - #1276

Merged
flyingmutant merged 1 commit into
cmus:masterfrom
gavtroy:sort-albums-by-date
Aug 1, 2023
Merged

flyingmutant merged 1 commit into
cmus:masterfrom
gavtroy:sort-albums-by-date

Conversation

@gavtroy

@gavtroy gavtroy commented Jul 21, 2023

Copy link
Copy Markdown
Collaborator

By default they are still sorted by date, which is the current behavior.

I considered to also add an equivalent of smart_artist_sort, to strip "The" from album names when sorting. It could be nice to add for consistency, but I find it's not that useful when the list of albums under a given artist tends to be quite small anyway.

Closes #909.

@pgaskin
pgaskin self-requested a review July 22, 2023 02:11

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgaskin

pgaskin commented Jul 22, 2023

Copy link
Copy Markdown
Member

@flyingmutant

Comment thread tree.c Outdated
cmp = a->date - b->date;
if (cmp)
return cmp;
if (!sort_albums_by_name) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this is questionable: function is called special_album_cmp_date. PR should aim to make the code better after adding the new feature, not for the minimal possible diff.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True; this could be done in add_album, which already decides to do alphabetical sort for compilations, I think. Missed this while skimming the diff.

@gavtroy gavtroy Jul 22, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had actually done it properly in a previous draft. 🤦 I'm not sure what caused me to think this would be better, but originally I was calling the setting sort_albums_by_date=false so it stood out less then at least.

@gavtroy
gavtroy force-pushed the sort-albums-by-date branch from a3ecc06 to b339e82 Compare July 22, 2023 14:07
@pgaskin
pgaskin self-requested a review July 22, 2023 22:42

@pgaskin pgaskin left a comment

Copy link
Copy Markdown
Member

Comment thread tree.c
Comment on lines +1240 to +1241
remove_album(album);
add_album(album);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how much I like this, but it's okay, I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The artists / albums / tracks are originally inserted into their respective list in sorted order based on whatever the current sorting rules are. This function is only used to force a resort when the "smart_artist_sort" and "sort_albums_by_name" settings are changed.

The remove function just unlinks the album from the artist's album tree, and the add function just links it back in sorted position. It doesn't involve album_new()/album_free() like you might have expected from the name.

As for removing/inserting from inside the rb_for_each_safe loop -- although some elements may be visited twice if they are moved forwards in the rb_tree, all elements will be processed at least once and at most twice, thanks to the _safe part.

By default they are still sorted by date, which is the current behavior.

I considered to also add an equivalent of smart_artist_sort, to strip
"The" from album names when sorting. It could be nice to add for
consistency, but I find it's not that useful when the list of albums
under a given artist tends to be quite small anyway.

Closes cmus#909.
@flyingmutant
flyingmutant merged commit ea01908 into cmus:master Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View 1's album sort order doesn't suit

3 participants