blob: 89f238c2d65b4908397f8f8d71d0dcd9aed0c9ee [file] [log] [blame]
Michiel Van Der Kolk4350eec2005-04-28 14:06:20 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Michiel Van Der Kolk4350eec2005-04-28 14:06:20 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Michiel Van Der Kolk238bea72005-04-28 18:49:23 +000021#include "searchengine.h"
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000022#include "token.h"
23#include "dbinterface.h"
24
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000025char *getstring(struct token *token) {
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000026 char buf[200];
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000027 switch(token->kind) {
28 case TOKEN_STRING:
29 return token->spelling;
30 case TOKEN_STRINGIDENTIFIER:
31 switch(token->intvalue) {
32 case INTVALUE_TITLE:
33 loadsongdata();
34 return currententry->title;
35 case INTVALUE_ARTIST:
36 loadartistname();
37 return currententry->artistname;
38 case INTVALUE_ALBUM:
39 loadalbumname();
40 return currententry->albumname;
41 case INTVALUE_GENRE:
42 loadsongdata();
43 return currententry->genre;
44 case INTVALUE_FILENAME:
45 return currententry->filename;
46 default:
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000047 rb->snprintf(buf,199,"unknown stringid intvalue %d",token->intvalue);
Jens Arnold4d6374c2007-03-16 21:56:08 +000048 rb->splash(HZ*2,buf);
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000049 return "";
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000050 }
51 break;
52 default:
53 // report error
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000054 rb->snprintf(buf,199,"unknown token %d in getstring..",token->kind);
Jens Arnold4d6374c2007-03-16 21:56:08 +000055 rb->splash(HZ*2,buf);
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000056 return "";
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000057 }
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000058}
59
60int getvalue(struct token *token) {
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +000061 char buf[200];
Michiel Van Der Kolkf34e4ff2005-05-11 00:12:33 +000062 int index,i;
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000063 switch(token->kind) {
64 case TOKEN_NUM:
65 return token->intvalue;
66 case TOKEN_NUMIDENTIFIER:
67 switch(token->intvalue) {
68 case INTVALUE_YEAR:
69 loadsongdata();
70 return currententry->year;
71 case INTVALUE_RATING:
72 loadrundbdata();
73 return currententry->rating;
74 case INTVALUE_PLAYCOUNT:
75 loadrundbdata();
76 return currententry->playcount;
Michiel Van Der Kolk261bb922005-06-06 19:34:35 +000077 case INTVALUE_PLAYTIME:
78 loadsongdata();
79 return currententry->playtime;
80 case INTVALUE_TRACKNUM:
81 loadsongdata();
82 return currententry->track;
83 case INTVALUE_BITRATE:
84 loadsongdata();
85 return currententry->bitrate;
86 case INTVALUE_SAMPLERATE:
87 loadsongdata();
88 return currententry->samplerate;
Michiel Van Der Kolkf5eae082005-05-10 23:44:22 +000089 case INTVALUE_AUTORATING:
Michiel Van Der Kolkf34e4ff2005-05-11 00:12:33 +000090 if(!dbglobal.gotplaycountlimits) {
91 index=dbglobal.currententryindex;
92 dbglobal.playcountmax=0;
93 dbglobal.playcountmin=0xFFFFFFFF;
94 for(i=0;i<rb->tagdbheader->filecount;i++) {
95 loadentry(i);
96 loadrundbdata();
97 if(currententry->playcount>dbglobal.playcountmax)
98 dbglobal.playcountmax=currententry->playcount;
99 if(currententry->playcount<dbglobal.playcountmin)
100 dbglobal.playcountmin=currententry->playcount;
101 }
102 dbglobal.gotplaycountlimits=1;
103 loadentry(index);
104 }
105 loadrundbdata();
106 return (currententry->playcount-dbglobal.playcountmin)*10/(dbglobal.playcountmax-dbglobal.playcountmin);
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +0000107 default:
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +0000108 rb->snprintf(buf,199,"unknown numid intvalue %d",token->intvalue);
Jens Arnold4d6374c2007-03-16 21:56:08 +0000109 rb->splash(HZ*2,buf);
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +0000110 // report error.
111 return 0;
112 }
113 default:
Michiel Van Der Kolka9e45552005-04-29 23:57:50 +0000114 rb->snprintf(buf,199,"unknown token %d in getvalue..",token->kind);
Jens Arnold4d6374c2007-03-16 21:56:08 +0000115 rb->splash(HZ*2,buf);
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +0000116 return 0;
117 }
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +0000118}