summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-05-11 00:12:33 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-05-11 00:12:33 +0000
commitf34e4ff6a42a003bcfc063896f390dcb94052cde (patch)
tree2678613f7014d9a7d86987e3dab02fdb2c211ad3
parentf5eae08361c4b1c9d7c846c7b4b54fabf7467e31 (diff)
downloadrockbox-f34e4ff6a42a003bcfc063896f390dcb94052cde.tar.gz
rockbox-f34e4ff6a42a003bcfc063896f390dcb94052cde.zip
Autorating should work now. at least. it would. but there is no runtime data to work with (yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6455 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/searchengine/dbinterface.c6
-rw-r--r--apps/plugins/searchengine/dbinterface.h46
-rw-r--r--apps/plugins/searchengine/token.c20
3 files changed, 50 insertions, 22 deletions
diff --git a/apps/plugins/searchengine/dbinterface.c b/apps/plugins/searchengine/dbinterface.c
index 7cded01642..fe3ff2dd45 100644
--- a/apps/plugins/searchengine/dbinterface.c
+++ b/apps/plugins/searchengine/dbinterface.c
@@ -33,7 +33,7 @@
#define FILERECORD2OFFSET(_x_) (rb->tagdbheader->filestart + _x_ * FILEENTRY_SIZE)
struct entry *currententry;
-
+struct dbglobals dbglobal;
static struct entry *entryarray;
int database_init() {
@@ -51,6 +51,9 @@ int database_init() {
return -1;
}
}
+ dbglobal.playcountmin=0;
+ dbglobal.playcountmax=0;
+ dbglobal.gotplaycountlimits=0;
return 0;
}
@@ -84,6 +87,7 @@ void loadentry(int filerecord) {
entryarray[filerecord].loadedfiledata=1;
}
currententry=&entryarray[filerecord];
+ dbglobal.currententryindex=filerecord;
}
void loadsongdata() {
diff --git a/apps/plugins/searchengine/dbinterface.h b/apps/plugins/searchengine/dbinterface.h
index ef90d63483..6a33248166 100644
--- a/apps/plugins/searchengine/dbinterface.h
+++ b/apps/plugins/searchengine/dbinterface.h
@@ -16,30 +16,38 @@
* KIND, either express or implied.
*
****************************************************************************/
+struct dbglobals {
+ int playcountmin;
+ int playcountmax;
+ int gotplaycountlimits;
+ int currententryindex;
+};
+
struct entry {
- int loadedfiledata,
- loadedsongdata,
- loadedrundbdata,
- loadedalbumname,
- loadedartistname;
- char *filename;
- long hash;
- long songentry;
- long rundbentry;
- short year;
- short bitrate;
- long rating;
- long playcount;
- char *title;
- char *genre;
- long artistoffset;
- long albumoffset;
- char *artistname;
- char *albumname;
+ int loadedfiledata,
+ loadedsongdata,
+ loadedrundbdata,
+ loadedalbumname,
+ loadedartistname;
+ char *filename;
+ long hash;
+ long songentry;
+ long rundbentry;
+ short year;
+ short bitrate;
+ long rating;
+ long playcount;
+ char *title;
+ char *genre;
+ long artistoffset;
+ long albumoffset;
+ char *artistname;
+ char *albumname;
};
extern struct entry *currententry;
extern struct entry *entryarray;
+extern struct dbglobals dbglobal;
int database_init(void);
void loadentry(int filerecord);
diff --git a/apps/plugins/searchengine/token.c b/apps/plugins/searchengine/token.c
index d8cd64072f..5950605ade 100644
--- a/apps/plugins/searchengine/token.c
+++ b/apps/plugins/searchengine/token.c
@@ -57,6 +57,7 @@ char *getstring(struct token *token) {
int getvalue(struct token *token) {
char buf[200];
+ int index,i;
switch(token->kind) {
case TOKEN_NUM:
return token->intvalue;
@@ -72,8 +73,23 @@ int getvalue(struct token *token) {
loadrundbdata();
return currententry->playcount;
case INTVALUE_AUTORATING:
- // todo.
- return 0;
+ if(!dbglobal.gotplaycountlimits) {
+ index=dbglobal.currententryindex;
+ dbglobal.playcountmax=0;
+ dbglobal.playcountmin=0xFFFFFFFF;
+ for(i=0;i<rb->tagdbheader->filecount;i++) {
+ loadentry(i);
+ loadrundbdata();
+ if(currententry->playcount>dbglobal.playcountmax)
+ dbglobal.playcountmax=currententry->playcount;
+ if(currententry->playcount<dbglobal.playcountmin)
+ dbglobal.playcountmin=currententry->playcount;
+ }
+ dbglobal.gotplaycountlimits=1;
+ loadentry(index);
+ }
+ loadrundbdata();
+ return (currententry->playcount-dbglobal.playcountmin)*10/(dbglobal.playcountmax-dbglobal.playcountmin);
default:
rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
rb->splash(HZ*2,true,buf);