diff --git a/apps/tagtree.c b/apps/tagtree.c index 575ab22..1dca249 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -759,18 +759,14 @@ static void tagtree_track_finish_event(void *data) tagcache_update_numeric(tagcache_idx, tag_lastplayed, lastplayed); } -#if CONFIG_CODEC == SWCODEC - if (global_settings.autoresume_enable) - { - unsigned long offset - = audio_automatic_skip() ? 0 : id3->offset; + /* The resume offset is needed for both autoresume and for + highlighting the last-played track -- do it unconditionally */ + unsigned long offset = audio_automatic_skip() ? 0 : id3->offset; - tagcache_update_numeric(tagcache_idx, tag_lastoffset, offset); + tagcache_update_numeric(tagcache_idx, tag_lastoffset, offset); - logf("tagtree_track_finish_event: Save offset for %s: %lX", - str_or_empty(id3->title), offset); - } -#endif + logf("tagtree_track_finish_event: Save offset for %s: %lX", + str_or_empty(id3->title), offset); } bool tagtree_export(void) @@ -1231,6 +1227,18 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init) { dptr->newtable = PLAYTRACK; dptr->extraseek = tcs.idx_id; + if (global_settings.runtimedb) + { + dptr->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); + + /* Take note of partially played track by negating + lastplayed. The negation is undone later when + computing the entry to highlight. */ + if (tagcache_get_numeric(&tcs, tag_lastoffset) != 0) + dptr->lastplayed = - dptr->lastplayed; + + // DEBUGF("age = %ld", tagcache_get_numeric(&tcs, tag_lastplayed)); + } } else dptr->extraseek = tcs.result_seek; @@ -1353,8 +1361,36 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init) } } - return total_count; + if (global_settings.runtimedb) /* find youngest. XXX merge with + loop in previous clause */ + { + long lastplayed = 0; + dptr = c->dircache; + for (i = 0; i < total_count; i++, dptr++) + { + long last = dptr->lastplayed; + bool partial = false; + if (last < 0) /* minus sign means track was not completed */ + { + last = -last; /* recover positive value */ + partial = true; + } + if (dptr->newtable == PLAYTRACK && lastplayed < last) + { + lastplayed = last; + if (partial) + c->selected_item = i; + else /* fully played track: highlight next one */ + { + c->selected_item = i + 1; + if (c->selected_item >= total_count) + c->selected_item = 0; + } + } + } + } + return total_count; } static int load_root(struct tree_context *c) diff --git a/apps/tagtree.h b/apps/tagtree.h index aaf5158..6b01acb 100644 --- a/apps/tagtree.h +++ b/apps/tagtree.h @@ -34,6 +34,7 @@ struct tagentry { char *name; int newtable; int extraseek; + long lastplayed; }; bool tagtree_export(void);