summaryrefslogtreecommitdiff
path: root/apps/tagtree.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2007-07-21 17:35:19 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2007-07-21 17:35:19 +0000
commit9d756e2760a0926aa416b22e276c4a5b2685e84e (patch)
tree21502b59d472d57f6cdb267eb96177784beec706 /apps/tagtree.c
parent6ed7722db0f7e911684f5deb84cc4ae93d15ccac (diff)
downloadrockbox-9d756e2760a0926aa416b22e276c4a5b2685e84e.tar.gz
rockbox-9d756e2760a0926aa416b22e276c4a5b2685e84e.zip
Queue song statistical data to the tagcache system and update entirely in background. Fixes ratings disappearing or not saving in the DB at all. Fixes also UI delay when stopping playback and new statistics are committed to DB.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13955 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r--apps/tagtree.c49
1 files changed, 18 insertions, 31 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 03673fc653..271f30ffa8 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -624,9 +624,14 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
624 } 624 }
625 625
626 id3->playcount = tagcache_get_numeric(&tcs, tag_playcount); 626 id3->playcount = tagcache_get_numeric(&tcs, tag_playcount);
627 if(!id3->rating) id3->rating = tagcache_get_numeric(&tcs, tag_rating); 627 if (!id3->rating)
628 id3->rating = tagcache_get_numeric(&tcs, tag_rating);
628 id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); 629 id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
629 id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; 630 id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10;
631 id3->playtime = tagcache_get_numeric(&tcs, tag_playtime);
632
633 /* Store our tagcache index pointer. */
634 id3->tagcache_idx = tcs.idx_id;
630 635
631 tagcache_search_finish(&tcs); 636 tagcache_search_finish(&tcs);
632} 637}
@@ -635,7 +640,6 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
635{ 640{
636 (void)last_track; 641 (void)last_track;
637 long playcount; 642 long playcount;
638 long rating;
639 long playtime; 643 long playtime;
640 long lastplayed; 644 long lastplayed;
641 645
@@ -646,55 +650,38 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
646 return; 650 return;
647 } 651 }
648 652
649 /* Don't process unplayed tracks. */ 653 if (!id3->tagcache_idx)
650 if (id3->elapsed == 0)
651 { 654 {
652 logf("not logging unplayed track"); 655 logf("No tagcache index pointer found");
653 return; 656 return;
654 } 657 }
655 658
656 if (!tagcache_find_index(&tcs, id3->path)) 659 /* Don't process unplayed tracks. */
660 if (id3->elapsed == 0)
657 { 661 {
658 logf("tc stat: not found: %s", id3->path); 662 logf("not logging unplayed track");
659 return; 663 return;
660 } 664 }
661 665
662 playcount = tagcache_get_numeric(&tcs, tag_playcount); 666 playcount = id3->playcount + 1;
663 playtime = tagcache_get_numeric(&tcs, tag_playtime);
664 lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
665
666 playcount++;
667
668 rating = (long) id3->rating;
669
670 lastplayed = tagcache_increase_serial(); 667 lastplayed = tagcache_increase_serial();
671 if (lastplayed < 0) 668 if (lastplayed < 0)
672 { 669 {
673 logf("incorrect tc serial:%ld", lastplayed); 670 logf("incorrect tc serial:%ld", lastplayed);
674 tagcache_search_finish(&tcs);
675 return; 671 return;
676 } 672 }
677 673
678 /* Ignore the last 15s (crossfade etc.) */ 674 /* Ignore the last 15s (crossfade etc.) */
679 playtime += MIN(id3->length, id3->elapsed + 15 * 1000); 675 playtime = id3->playtime + MIN(id3->length, id3->elapsed + 15 * 1000);
680 676
681 logf("ube:%s", id3->path); 677 logf("ube:%s", id3->path);
682 logf("-> %d/%ld/%ld/%ld", last_track, playcount, rating, playtime); 678 logf("-> %d/%ld/%ld", last_track, playcount, playtime);
683 logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000)); 679 logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000));
684 680
685 /* lastplayed not yet supported. */ 681 /* Queue the updates to the tagcache system. */
686 682 tagcache_update_numeric(id3->tagcache_idx, tag_playcount, playcount);
687 if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount) 683 tagcache_update_numeric(id3->tagcache_idx, tag_playtime, playtime);
688 || !tagcache_modify_numeric_entry(&tcs, tag_rating, rating) 684 tagcache_update_numeric(id3->tagcache_idx, tag_lastplayed, lastplayed);
689 || !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime)
690 || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed))
691 {
692 logf("tc stat: modify failed!");
693 tagcache_search_finish(&tcs);
694 return;
695 }
696
697 tagcache_search_finish(&tcs);
698} 685}
699 686
700bool tagtree_export(void) 687bool tagtree_export(void)