Repository navigation
Add option to sort albums by name in tree view - #1276
Conversation
pgaskin
left a comment
There was a problem hiding this comment.
Tested. Works as expected. Code looks good.
https://copr.fedorainfracloud.org/coprs/pgaskin/cmus-testing/build/6202738/
https://github.com/pgaskin/cmus/commits/d8a248a46900629c1726a10f4122ff0cb529b734
https://nightly.link/pgaskin/rpms/actions/runs/5628400179
| cmp = a->date - b->date; | ||
| if (cmp) | ||
| return cmp; | ||
| if (!sort_albums_by_name) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a3ecc06 to
b339e82
Compare
pgaskin
left a comment
There was a problem hiding this comment.
Tested. Works as expected.
https://copr.fedorainfracloud.org/coprs/pgaskin/cmus-testing/build/6204539/
https://github.com/pgaskin/cmus/commits/def777cecad32711b30da1f0b3b43a9d6481d19e
https://nightly.link/pgaskin/rpms/actions/runs/5633236513
| remove_album(album); | ||
| add_album(album); |
There was a problem hiding this comment.
I'm not sure how much I like this, but it's okay, I think.
There was a problem hiding this comment.
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.
b339e82 to
0918d4f
Compare
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.