summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2007-03-26 15:08:59 +0000
committerRobert Kukla <roolku@rockbox.org>2007-03-26 15:08:59 +0000
commit226cb7b0b82fe3d3736b8206d8a94c67c359ab64 (patch)
tree8c8b7e12ea5ac643b3c01b8c9aff4a948ae89214
parentcd1ccad9d6ef4f95d6cb0d02c77b58e6566dd203 (diff)
downloadrockbox-226cb7b0b82fe3d3736b8206d8a94c67c359ab64.tar.gz
rockbox-226cb7b0b82fe3d3736b8206d8a94c67c359ab64.zip
Rating support for database and WPS (based on FS# 6301). A value between 0 and 10 can be assigned to the currently playing track using the WPS context menu. This value is displayed in the WPS using the %rr tag (replacing autoscore) and can be used as "rating" in tagnavi.config (examples provided).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12922 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/onplay.c43
-rw-r--r--apps/tagcache.c11
-rw-r--r--apps/tagcache.h8
-rw-r--r--apps/tagnavi.config7
-rw-r--r--apps/tagtree.c10
-rw-r--r--firmware/export/id3.h1
-rw-r--r--manual/rockbox_interface/tagcache.tex8
-rw-r--r--manual/rockbox_interface/wps.tex5
8 files changed, 74 insertions, 19 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index be9f2d0703..60fc418d40 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -869,6 +869,34 @@ static int onplay_callback(int key, int menu)
869 return key; 869 return key;
870} 870}
871 871
872
873char rating_menu_string[32];
874
875static void create_rating_menu(void)
876{
877 struct mp3entry* id3 = audio_current_track();
878 if(id3)
879 snprintf(rating_menu_string, sizeof rating_menu_string,
880 "%s: %d", str(LANG_MENU_SET_RATING), id3->rating);
881 else
882 snprintf(rating_menu_string, sizeof rating_menu_string,
883 "%s: -", str(LANG_MENU_SET_RATING));
884}
885
886static bool set_rating_inline(void)
887{
888 struct mp3entry* id3 = audio_current_track();
889 if(id3) {
890 if(id3->rating<10)
891 id3->rating++;
892 else
893 id3->rating=0;
894 }
895 create_rating_menu();
896 return false;
897}
898
899
872int onplay(char* file, int attr, int from) 900int onplay(char* file, int attr, int from)
873{ 901{
874#if CONFIG_CODEC == SWCODEC 902#if CONFIG_CODEC == SWCODEC
@@ -908,6 +936,13 @@ int onplay(char* file, int attr, int from)
908 936
909 if (context == CONTEXT_WPS) 937 if (context == CONTEXT_WPS)
910 { 938 {
939 if(file && global_settings.runtimedb)
940 {
941 create_rating_menu();
942 items[i].desc = rating_menu_string;
943 items[i].function = set_rating_inline;
944 i++;
945 }
911 items[i].desc = ID2P(LANG_BOOKMARK_MENU); 946 items[i].desc = ID2P(LANG_BOOKMARK_MENU);
912 items[i].function = bookmark_menu; 947 items[i].function = bookmark_menu;
913 i++; 948 i++;
@@ -1037,9 +1072,11 @@ int onplay(char* file, int attr, int from)
1037 if (i) 1072 if (i)
1038 { 1073 {
1039 m = menu_init( items, i, onplay_callback, NULL, NULL, NULL ); 1074 m = menu_init( items, i, onplay_callback, NULL, NULL, NULL );
1040 result = menu_show(m); 1075 do {
1041 if (result >= 0) 1076 result = menu_show(m);
1042 items[result].function(); 1077 if (result >= 0)
1078 items[result].function();
1079 } while (items[result].function == set_rating_inline);
1043 menu_exit(m); 1080 menu_exit(m);
1044 1081
1045 if (exit_to_main) 1082 if (exit_to_main)
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 6f49d372e3..7a1fec75af 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -115,13 +115,13 @@ static const int unique_tags[] = { tag_artist, tag_album, tag_genre,
115 115
116/* Numeric tags (we can use these tags with conditional clauses). */ 116/* Numeric tags (we can use these tags with conditional clauses). */
117static const int numeric_tags[] = { tag_year, tag_tracknumber, tag_length, 117static const int numeric_tags[] = { tag_year, tag_tracknumber, tag_length,
118 tag_bitrate, tag_playcount, tag_playtime, tag_lastplayed, tag_commitid, 118 tag_bitrate, tag_playcount, tag_rating, tag_playtime, tag_lastplayed, tag_commitid,
119 tag_virt_entryage, tag_virt_autoscore }; 119 tag_virt_entryage, tag_virt_autoscore };
120 120
121/* String presentation of the tags defined in tagcache.h. Must be in correct order! */ 121/* String presentation of the tags defined in tagcache.h. Must be in correct order! */
122static const char *tags_str[] = { "artist", "album", "genre", "title", 122static const char *tags_str[] = { "artist", "album", "genre", "title",
123 "filename", "composer", "comment", "albumartist", "year", "tracknumber", 123 "filename", "composer", "comment", "albumartist", "year", "tracknumber",
124 "bitrate", "length", "playcount", "playtime", "lastplayed", "commitid" }; 124 "bitrate", "length", "playcount", "rating", "playtime", "lastplayed", "commitid" };
125 125
126/* Status information of the tagcache. */ 126/* Status information of the tagcache. */
127static struct tagcache_stat tc_stat; 127static struct tagcache_stat tc_stat;
@@ -167,7 +167,7 @@ struct master_header {
167 167
168/* For the endianess correction */ 168/* For the endianess correction */
169static const char *tagfile_entry_ec = "ss"; 169static const char *tagfile_entry_ec = "ss";
170static const char *index_entry_ec = "lllllllllllllllll"; /* (1 + TAG_COUNT) * l */ 170static const char *index_entry_ec = "llllllllllllllllll"; /* (1 + TAG_COUNT) * l */
171static const char *tagcache_header_ec = "lll"; 171static const char *tagcache_header_ec = "lll";
172static const char *master_header_ec = "llllll"; 172static const char *master_header_ec = "llllll";
173 173
@@ -1499,8 +1499,9 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
1499 id3->albumartist = get_tag_string(entry, tag_albumartist); 1499 id3->albumartist = get_tag_string(entry, tag_albumartist);
1500 1500
1501 id3->playcount = get_tag_numeric(entry, tag_playcount); 1501 id3->playcount = get_tag_numeric(entry, tag_playcount);
1502 id3->rating = get_tag_numeric(entry, tag_rating);
1502 id3->lastplayed = get_tag_numeric(entry, tag_lastplayed); 1503 id3->lastplayed = get_tag_numeric(entry, tag_lastplayed);
1503 id3->rating = get_tag_numeric(entry, tag_virt_autoscore) / 10; 1504 id3->score = get_tag_numeric(entry, tag_virt_autoscore) / 10;
1504 id3->year = get_tag_numeric(entry, tag_year); 1505 id3->year = get_tag_numeric(entry, tag_year);
1505 1506
1506 id3->tracknum = get_tag_numeric(entry, tag_tracknumber); 1507 id3->tracknum = get_tag_numeric(entry, tag_tracknumber);
@@ -2850,7 +2851,7 @@ static int parse_changelog_line(int line_n, const char *buf, void *parameters)
2850 char tag_data[TAG_MAXLEN+32]; 2851 char tag_data[TAG_MAXLEN+32];
2851 int idx_id; 2852 int idx_id;
2852 long masterfd = (long)parameters; 2853 long masterfd = (long)parameters;
2853 const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed, 2854 const int import_tags[] = { tag_playcount, tag_rating, tag_playtime, tag_lastplayed,
2854 tag_commitid }; 2855 tag_commitid };
2855 int i; 2856 int i;
2856 (void)line_n; 2857 (void)line_n;
diff --git a/apps/tagcache.h b/apps/tagcache.h
index 0cfdedf310..7b7aa021c3 100644
--- a/apps/tagcache.h
+++ b/apps/tagcache.h
@@ -24,12 +24,12 @@
24 24
25enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, 25enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
26 tag_filename, tag_composer, tag_comment, tag_albumartist, tag_year, 26 tag_filename, tag_composer, tag_comment, tag_albumartist, tag_year,
27 tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_playtime, 27 tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating,
28 tag_lastplayed, tag_commitid, 28 tag_playtime, tag_lastplayed, tag_commitid,
29 /* Virtual tags */ 29 /* Virtual tags */
30 tag_virt_entryage, tag_virt_autoscore }; 30 tag_virt_entryage, tag_virt_autoscore };
31 31
32#define TAG_COUNT 16 32#define TAG_COUNT 17
33 33
34/* Maximum length of a single tag. */ 34/* Maximum length of a single tag. */
35#define TAG_MAXLEN (MAX_PATH*2) 35#define TAG_MAXLEN (MAX_PATH*2)
@@ -41,7 +41,7 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title,
41#define IDX_BUF_DEPTH 64 41#define IDX_BUF_DEPTH 64
42 42
43/* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */ 43/* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */
44#define TAGCACHE_MAGIC 0x54434808 44#define TAGCACHE_MAGIC 0x54434809
45 45
46/* How much to allocate extra space for ramcache. */ 46/* How much to allocate extra space for ramcache. */
47#define TAGCACHE_RESERVE 32768 47#define TAGCACHE_RESERVE 32768
diff --git a/apps/tagnavi.config b/apps/tagnavi.config
index 24428e223a..5e9dd73b33 100644
--- a/apps/tagnavi.config
+++ b/apps/tagnavi.config
@@ -10,9 +10,10 @@
10%format "fmt_title" "%s" title 10%format "fmt_title" "%s" title
11%format "fmt_mostplayed" "(%3d) %s - %s" playcount artist title %sort = "inverse" %limit = "100" 11%format "fmt_mostplayed" "(%3d) %s - %s" playcount artist title %sort = "inverse" %limit = "100"
12%format "fmt_lastplayed" "%06d%s - %s" lastplayed artist title %sort = "inverse" %limit = "99" %strip = "6" 12%format "fmt_lastplayed" "%06d%s - %s" lastplayed artist title %sort = "inverse" %limit = "99" %strip = "6"
13%format "fmt_best_tracks" "%02d. %s (%3d)" tracknum title autoscore 13%format "fmt_best_tracks" "%02d. %s (%2d)" tracknum title rating %sort = "inverse"
14%format "fmt_played" "(%3d/%d) %s" autoscore playcount title 14%format "fmt_played" "(%3d/%d) %s" autoscore playcount title
15%format "fmt_score" "(%3d) %s" autoscore title 15%format "fmt_score" "(%3d) %s" autoscore title
16%format "fmt_rating" "(%2d) %s" rating title %sort = "inverse"
16 17
17# Include our custom menu 18# Include our custom menu
18%include "/.rockbox/tagnavi_custom.config" 19%include "/.rockbox/tagnavi_custom.config"
@@ -28,6 +29,7 @@
28"Title" -> title ? title ~ "" 29"Title" -> title ? title ~ ""
29"Filename" -> filename ? filename ~ "" 30"Filename" -> filename ? filename ~ ""
30"Score" -> title = "fmt_score" ? autoscore > "" 31"Score" -> title = "fmt_score" ? autoscore > ""
32"Rating" -> title = "fmt_rating" ? rating > ""
31 33
32# ^ An empy line ends the menu 34# ^ An empy line ends the menu
33 35
@@ -42,12 +44,13 @@
42"Genre" -> genre -> artist -> album -> title = "fmt_title" 44"Genre" -> genre -> artist -> album -> title = "fmt_title"
43"Composer" -> composer -> album -> title = "fmt_title" 45"Composer" -> composer -> album -> title = "fmt_title"
44"Track" -> title 46"Track" -> title
47"Rating" -> rating -> title = "fmt_rating"
45"Year" -> year ? year > "1000" & year < "2008" -> artist -> album -> title = "fmt_title" 48"Year" -> year ? year > "1000" & year < "2008" -> artist -> album -> title = "fmt_title"
46"Search..." ==> "search" 49"Search..." ==> "search"
47"Most played tracks" -> title = "fmt_mostplayed" ? playcount > "0" 50"Most played tracks" -> title = "fmt_mostplayed" ? playcount > "0"
48"Last played tracks" -> title = "fmt_lastplayed" ? playcount > "0" 51"Last played tracks" -> title = "fmt_lastplayed" ? playcount > "0"
49"Never played tracks" -> artist ? playcount == "0" -> album -> title = "fmt_title" 52"Never played tracks" -> artist ? playcount == "0" -> album -> title = "fmt_title"
50"Best tracks" -> artist ? playcount > "1" & autoscore > "85" -> album -> title = "fmt_best_tracks" 53"Best tracks" -> artist ? playcount > "1" & rating > "8" -> album -> title = "fmt_best_tracks"
51"List played tracks" -> title = "fmt_played" ? playcount > "0" 54"List played tracks" -> title = "fmt_played" ? playcount > "0"
52"Last added tracks" -> artist ? entryage == "0" -> album -> title = "fmt_title" 55"Last added tracks" -> artist ? entryage == "0" -> album -> title = "fmt_title"
53"Custom view..." ==> "custom" 56"Custom view..." ==> "custom"
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 33c36b7b83..66a644e59a 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -205,6 +205,7 @@ static int get_tag(int *tag)
205 MATCH(tag, buf, "tracknum", tag_tracknumber); 205 MATCH(tag, buf, "tracknum", tag_tracknumber);
206 MATCH(tag, buf, "year", tag_year); 206 MATCH(tag, buf, "year", tag_year);
207 MATCH(tag, buf, "playcount", tag_playcount); 207 MATCH(tag, buf, "playcount", tag_playcount);
208 MATCH(tag, buf, "rating", tag_rating);
208 MATCH(tag, buf, "lastplayed", tag_lastplayed); 209 MATCH(tag, buf, "lastplayed", tag_lastplayed);
209 MATCH(tag, buf, "commitid", tag_commitid); 210 MATCH(tag, buf, "commitid", tag_commitid);
210 MATCH(tag, buf, "entryage", tag_virt_entryage); 211 MATCH(tag, buf, "entryage", tag_virt_entryage);
@@ -603,8 +604,9 @@ static void tagtree_buffer_event(struct mp3entry *id3, bool last_track)
603 } 604 }
604 605
605 id3->playcount = tagcache_get_numeric(&tcs, tag_playcount); 606 id3->playcount = tagcache_get_numeric(&tcs, tag_playcount);
607 if(!id3->rating) id3->rating = tagcache_get_numeric(&tcs, tag_rating);
606 id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); 608 id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed);
607 id3->rating = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; 609 id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10;
608 610
609 tagcache_search_finish(&tcs); 611 tagcache_search_finish(&tcs);
610} 612}
@@ -613,6 +615,7 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
613{ 615{
614 (void)last_track; 616 (void)last_track;
615 long playcount; 617 long playcount;
618 long rating;
616 long playtime; 619 long playtime;
617 long lastplayed; 620 long lastplayed;
618 621
@@ -642,6 +645,8 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
642 645
643 playcount++; 646 playcount++;
644 647
648 rating = (long) id3->rating;
649
645 lastplayed = tagcache_increase_serial(); 650 lastplayed = tagcache_increase_serial();
646 if (lastplayed < 0) 651 if (lastplayed < 0)
647 { 652 {
@@ -654,12 +659,13 @@ static void tagtree_unbuffer_event(struct mp3entry *id3, bool last_track)
654 playtime += MIN(id3->length, id3->elapsed + 15 * 1000); 659 playtime += MIN(id3->length, id3->elapsed + 15 * 1000);
655 660
656 logf("ube:%s", id3->path); 661 logf("ube:%s", id3->path);
657 logf("-> %d/%ld/%ld", last_track, playcount, playtime); 662 logf("-> %d/%ld/%d/%ld", last_track, playcount, rating, playtime);
658 logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000)); 663 logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, MIN(id3->length, id3->elapsed + 15 * 1000));
659 664
660 /* lastplayed not yet supported. */ 665 /* lastplayed not yet supported. */
661 666
662 if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount) 667 if (!tagcache_modify_numeric_entry(&tcs, tag_playcount, playcount)
668 || !tagcache_modify_numeric_entry(&tcs, tag_rating, rating)
663 || !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime) 669 || !tagcache_modify_numeric_entry(&tcs, tag_playtime, playtime)
664 || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed)) 670 || !tagcache_modify_numeric_entry(&tcs, tag_lastplayed, lastplayed))
665 { 671 {
diff --git a/firmware/export/id3.h b/firmware/export/id3.h
index d3d5dd35ce..5cc600face 100644
--- a/firmware/export/id3.h
+++ b/firmware/export/id3.h
@@ -199,6 +199,7 @@ struct mp3entry {
199 199
200 /* runtime database fields */ 200 /* runtime database fields */
201 short rating; 201 short rating;
202 short score;
202 long playcount; 203 long playcount;
203 long lastplayed; 204 long lastplayed;
204 205
diff --git a/manual/rockbox_interface/tagcache.tex b/manual/rockbox_interface/tagcache.tex
index c6869c9348..8f7a942eb6 100644
--- a/manual/rockbox_interface/tagcache.tex
+++ b/manual/rockbox_interface/tagcache.tex
@@ -65,9 +65,11 @@ you can use the database.
65 Unlike \setting{Initialize Now}, the \setting{Update Now} function 65 Unlike \setting{Initialize Now}, the \setting{Update Now} function
66 does not remove runtime database information. 66 does not remove runtime database information.
67 67
68\item[Gather Runtime Data (Experimental).] 68\item[Gather Runtime Data.]
69 When enabled, this option allows the most played, unplayed and most recently 69 When enabled, rockbox will record how often and how long a track is being played,
70 played tracks to be logged and scored. 70 when it was last played and its rating. This information can be displayed in
71 the WPS and is used in the database browser to, for example, show the most played,
72 unplayed and most recently played tracks.
71 73
72\item[Export modifications.] 74\item[Export modifications.]
73 This allows for the runtime data to be exported to the file \\ 75 This allows for the runtime data to be exported to the file \\
diff --git a/manual/rockbox_interface/wps.tex b/manual/rockbox_interface/wps.tex
index 401128ea69..606672b7bc 100644
--- a/manual/rockbox_interface/wps.tex
+++ b/manual/rockbox_interface/wps.tex
@@ -164,6 +164,11 @@ to bring up the \setting{Playlist Viewer Menu}.
164 \item [Add to playlist] 164 \item [Add to playlist]
165 \item [Add to new playlist] 165 \item [Add to new playlist]
166 \end{description} 166 \end{description}
167\subsubsection{Rating}
168The menu entry is only shown if \setting{Gather Runtime Information} is enabled. It allows the
169asignment of a personal rating value (0..10) to a track which can be displayed in the WPS (%rr)
170and is used in the Database browser. Press \ButtonRight to increment the value (it wraps at 10).
171
167\subsubsection{Bookmarks} 172\subsubsection{Bookmarks}
168This allows you to create a bookmark in the currently-playing track. 173This allows you to create a bookmark in the currently-playing track.
169 174