Discussion:
[PATCH 1/2] tree: better album date calculation
Gregory Petrosyan
2011-03-02 22:54:29 UTC
Permalink
Ensure that album's date is always equal to the max of dates of tracks. This
makes the order in which tracks are added to the tree irrelevant.

Signed-off-by: Gregory Petrosyan <***@gmail.com>
---
tree.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tree.c b/tree.c
index a53b75b..b365b0c 100644
--- a/tree.c
+++ b/tree.c
@@ -714,7 +714,7 @@ void tree_add_track(struct tree_track *track)
album_add_track(album, track);

/* If it makes sense to update album date, do it */
- if (date != -1 && album->date == -1) {
+ if (album->date < date) {
album->date = date;
window_changed(lib_tree_win);
}
--
1.7.1
Gregory Petrosyan
2011-03-02 22:54:30 UTC
Permalink
Ensure that dates are only compared if album names differ. Otherwise, we might
end up with tree with same album split into several, in case tracks in it have
different dates.

Signed-off-by: Gregory Petrosyan <***@gmail.com>
---
tree.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tree.c b/tree.c
index b365b0c..9ccff0f 100644
--- a/tree.c
+++ b/tree.c
@@ -483,10 +483,12 @@ static int special_album_cmp(const struct album *a, const struct album *b)
* Sort regular albums by date, but sort compilations
* alphabetically.
*/
- if (a->date != b->date && !a->is_compilation && !b->is_compilation)
+ cmp = strcmp(a->collkey_name, b->collkey_name);
+
+ if (cmp && a->date != b->date && !a->is_compilation && !b->is_compilation)
return a->date - b->date;

- return strcmp(a->collkey_name, b->collkey_name);
+ return cmp;
}

/* has to follow the same logic as artist_sort_name() */
--
1.7.1
Gregory Petrosyan
2011-03-03 01:18:50 UTC
Permalink
Signed-off-by: Gregory Petrosyan <***@gmail.com>
---
tree.c | 50 ++++++++++++++++++++++++++++----------------------
1 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/tree.c b/tree.c
index 9ccff0f..0220bc2 100644
--- a/tree.c
+++ b/tree.c
@@ -668,6 +668,26 @@ static const char *tree_album_name(const struct track_info* ti)
return val;
}

+static void remove_album(struct album *album)
+{
+ if (album->artist->expanded) {
+ struct iter iter;
+
+ album_to_iter(album, &iter);
+ window_row_vanishes(lib_tree_win, &iter);
+ }
+ rb_erase(&album->tree_node, &album->artist->album_root);
+}
+
+static void remove_artist(struct artist *artist)
+{
+ struct iter iter;
+
+ artist_to_iter(artist, &iter);
+ window_row_vanishes(lib_tree_win, &iter);
+ rb_erase(&artist->tree_node, &lib_artist_root);
+}
+
void tree_add_track(struct tree_track *track)
{
const struct track_info *ti = tree_track_info(track);
@@ -708,6 +728,9 @@ void tree_add_track(struct tree_track *track)
if (!artist->sort_name && artistsort_name) {
artist->sort_name = xstrdup(artistsort_name);
artist->collkey_sort_name = u_strcasecoll_key(artistsort_name);
+
+ remove_artist(artist);
+ add_artist(artist);
window_changed(lib_tree_win);
}
}
@@ -718,7 +741,11 @@ void tree_add_track(struct tree_track *track)
/* If it makes sense to update album date, do it */
if (album->date < date) {
album->date = date;
- window_changed(lib_tree_win);
+
+ remove_album(album);
+ add_album(album);
+ if (artist->expanded)
+ window_changed(lib_tree_win);
}

if (album_selected(album))
@@ -728,7 +755,6 @@ void tree_add_track(struct tree_track *track)
album_add_track(new_album, track);

if (artist->expanded)
- /* album is not selected => no need to update track_win */
window_changed(lib_tree_win);
} else {
add_artist(new_artist);
@@ -900,26 +926,6 @@ static void remove_track(struct tree_track *track)
rb_erase(&track->tree_node, &track->album->track_root);
}

-static void remove_album(struct album *album)
-{
- if (album->artist->expanded) {
- struct iter iter;
-
- album_to_iter(album, &iter);
- window_row_vanishes(lib_tree_win, &iter);
- }
- rb_erase(&album->tree_node, &album->artist->album_root);
-}
-
-static void remove_artist(struct artist *artist)
-{
- struct iter iter;
-
- artist_to_iter(artist, &iter);
- window_row_vanishes(lib_tree_win, &iter);
- rb_erase(&artist->tree_node, &lib_artist_root);
-}
-
void tree_remove(struct tree_track *track)
{
struct album *album = track->album;
--
1.7.1
Johannes Weißl
2011-03-08 23:00:28 UTC
Permalink
tree: properly update artist/album position when changing their sort
attributes
Good catch! I always wanted to test/fix this (even had the test data
somewhere, so I could easily verify that your patch works), but somehow
forgot...

Johannes

Loading...