2005-04-28 14:06:20 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Michiel van der Kolk
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-04-28 12:33:38 +00:00
|
|
|
#include "searchengine.h"
|
|
|
|
#include "dbinterface.h"
|
|
|
|
|
|
|
|
#undef SONGENTRY_SIZE
|
|
|
|
#undef FILEENTRY_SIZE
|
|
|
|
#undef ALBUMENTRY_SIZE
|
|
|
|
#undef ARTISTENTRY_SIZE
|
|
|
|
#undef FILERECORD2OFFSET
|
|
|
|
|
2005-06-05 23:00:42 +00:00
|
|
|
#define SONGENTRY_SIZE (rb->tagdbheader->songlen+12+rb->tagdbheader->genrelen+12)
|
2005-04-28 12:33:38 +00:00
|
|
|
#define FILEENTRY_SIZE (rb->tagdbheader->filelen+12)
|
|
|
|
#define ALBUMENTRY_SIZE (rb->tagdbheader->albumlen+4+rb->tagdbheader->songarraylen*4)
|
|
|
|
#define ARTISTENTRY_SIZE (rb->tagdbheader->artistlen+rb->tagdbheader->albumarraylen*4)
|
|
|
|
|
|
|
|
#define FILERECORD2OFFSET(_x_) (rb->tagdbheader->filestart + _x_ * FILEENTRY_SIZE)
|
|
|
|
|
|
|
|
struct entry *currententry;
|
2005-05-11 00:12:33 +00:00
|
|
|
struct dbglobals dbglobal;
|
2005-04-28 12:33:38 +00:00
|
|
|
static struct entry *entryarray;
|
|
|
|
|
|
|
|
int database_init() {
|
|
|
|
char *p;
|
|
|
|
unsigned int i;
|
|
|
|
// allocate room for all entries
|
|
|
|
entryarray=(struct entry *)my_malloc(sizeof(struct entry)*rb->tagdbheader->filecount);
|
|
|
|
p=(char *)entryarray;
|
|
|
|
// zero all entries.
|
|
|
|
for(i=0;i<sizeof(struct entry)*rb->tagdbheader->filecount;i++)
|
2005-04-29 21:02:17 +00:00
|
|
|
*(p++)=0;
|
2005-04-28 12:33:38 +00:00
|
|
|
if(*rb->tagdb_initialized!=1) {
|
|
|
|
if(!rb->tagdb_init()) {
|
|
|
|
// failed loading db
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2005-05-11 00:12:33 +00:00
|
|
|
dbglobal.playcountmin=0;
|
|
|
|
dbglobal.playcountmax=0;
|
|
|
|
dbglobal.gotplaycountlimits=0;
|
2005-04-28 12:33:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-28 14:20:23 +00:00
|
|
|
long readlong(int fd) {
|
2005-04-29 21:02:17 +00:00
|
|
|
long num;
|
|
|
|
rb->read(fd,&num,4);
|
2005-04-28 14:20:23 +00:00
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
2005-04-29 21:02:17 +00:00
|
|
|
num=BE32(num);
|
2005-04-28 14:20:23 +00:00
|
|
|
#endif
|
2005-04-29 21:02:17 +00:00
|
|
|
return num;
|
2005-04-28 14:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short readshort(int fd) {
|
2005-04-29 21:02:17 +00:00
|
|
|
short num;
|
|
|
|
rb->read(fd,&num,2);
|
2005-04-28 14:20:23 +00:00
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
2005-04-29 21:02:17 +00:00
|
|
|
num=BE16(num);
|
2005-04-28 14:20:23 +00:00
|
|
|
#endif
|
2005-04-29 21:02:17 +00:00
|
|
|
return num;
|
2005-04-28 14:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-28 12:33:38 +00:00
|
|
|
void loadentry(int filerecord) {
|
|
|
|
if(entryarray[filerecord].loadedfiledata==0) {
|
|
|
|
rb->lseek(*rb->tagdb_fd,FILERECORD2OFFSET(filerecord),SEEK_SET);
|
|
|
|
entryarray[filerecord].filename=(char *)my_malloc(rb->tagdbheader->filelen);
|
2005-04-29 21:02:17 +00:00
|
|
|
rb->read(*rb->tagdb_fd,entryarray[filerecord].filename,rb->tagdbheader->filelen);
|
|
|
|
entryarray[filerecord].hash=readlong(*rb->tagdb_fd);
|
|
|
|
entryarray[filerecord].songentry=readlong(*rb->tagdb_fd);
|
|
|
|
entryarray[filerecord].rundbentry=readlong(*rb->tagdb_fd);
|
|
|
|
entryarray[filerecord].loadedfiledata=1;
|
2005-04-28 12:33:38 +00:00
|
|
|
}
|
|
|
|
currententry=&entryarray[filerecord];
|
2005-05-11 00:12:33 +00:00
|
|
|
dbglobal.currententryindex=filerecord;
|
2005-04-28 12:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loadsongdata() {
|
2005-04-28 18:49:23 +00:00
|
|
|
if(currententry->loadedsongdata)
|
2005-04-28 12:33:38 +00:00
|
|
|
return;
|
|
|
|
currententry->title=(char *)my_malloc(rb->tagdbheader->songlen);
|
|
|
|
currententry->genre=(char *)my_malloc(rb->tagdbheader->genrelen);
|
|
|
|
rb->lseek(*rb->tagdb_fd,currententry->songentry,SEEK_SET);
|
|
|
|
rb->read(*rb->tagdb_fd,currententry->title,rb->tagdbheader->songlen);
|
2005-04-28 14:20:23 +00:00
|
|
|
currententry->artistoffset=readlong(*rb->tagdb_fd);
|
|
|
|
currententry->albumoffset=readlong(*rb->tagdb_fd);
|
2005-04-28 12:33:38 +00:00
|
|
|
rb->lseek(*rb->tagdb_fd,4,SEEK_CUR);
|
|
|
|
rb->read(*rb->tagdb_fd,currententry->genre,rb->tagdbheader->genrelen);
|
2005-04-28 14:20:23 +00:00
|
|
|
currententry->bitrate=readshort(*rb->tagdb_fd);
|
|
|
|
currententry->year=readshort(*rb->tagdb_fd);
|
2005-06-05 23:00:42 +00:00
|
|
|
currententry->playtime=readlong(*rb->tagdb_fd);
|
|
|
|
currententry->track=readshort(*rb->tagdb_fd);
|
|
|
|
currententry->samplerate=readshort(*rb->tagdb_fd);
|
2005-04-28 12:33:38 +00:00
|
|
|
currententry->loadedsongdata=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadrundbdata() {
|
2005-04-29 21:02:17 +00:00
|
|
|
// we don't do this yet.
|
2005-04-28 12:33:38 +00:00
|
|
|
currententry->loadedrundbdata=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadartistname() {
|
|
|
|
/* memory optimization possible, only malloc for an album name once, then
|
|
|
|
* write that pointer to the entrys using it.
|
|
|
|
*/
|
2005-04-28 18:49:23 +00:00
|
|
|
if(currententry->loadedartistname)
|
2005-04-29 21:02:17 +00:00
|
|
|
return;
|
2005-04-28 18:49:23 +00:00
|
|
|
loadsongdata();
|
2005-04-28 12:33:38 +00:00
|
|
|
currententry->artistname=(char *)my_malloc(rb->tagdbheader->artistlen);
|
|
|
|
rb->lseek(*rb->tagdb_fd,currententry->artistoffset,SEEK_SET);
|
|
|
|
rb->read(*rb->tagdb_fd,currententry->artistname,rb->tagdbheader->artistlen);
|
|
|
|
currententry->loadedartistname=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadalbumname() {
|
|
|
|
/* see the note at loadartistname */
|
2005-04-28 18:49:23 +00:00
|
|
|
if(currententry->loadedalbumname)
|
2005-04-29 21:02:17 +00:00
|
|
|
return;
|
2005-04-28 18:49:23 +00:00
|
|
|
loadsongdata();
|
2005-04-28 12:33:38 +00:00
|
|
|
currententry->albumname=(char *)my_malloc(rb->tagdbheader->albumlen);
|
|
|
|
rb->lseek(*rb->tagdb_fd,currententry->albumoffset,SEEK_SET);
|
|
|
|
rb->read(*rb->tagdb_fd,currententry->albumname,rb->tagdbheader->albumlen);
|
|
|
|
currententry->loadedalbumname=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *getfilename(int entry) {
|
|
|
|
if(entryarray[entry].loadedfiledata==0)
|
2005-04-29 21:02:17 +00:00
|
|
|
return "error O.o;;;";
|
2005-04-28 12:33:38 +00:00
|
|
|
else
|
2005-04-29 21:02:17 +00:00
|
|
|
return entryarray[entry].filename;
|
2005-04-28 12:33:38 +00:00
|
|
|
}
|