summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-06-26 21:11:29 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-06-26 21:11:29 +0000
commit928e334831f87dfe3b35b50e119b0ade9980b944 (patch)
tree40f96984dc3c51136efcebb84202e03ebba0ccda
parentf186f46f5d10fde5ff9585928f9343cab2c15287 (diff)
downloadrockbox-928e334831f87dfe3b35b50e119b0ade9980b944.tar.gz
rockbox-928e334831f87dfe3b35b50e119b0ade9980b944.zip
Added id3 tracknum (Yusef Napora)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1204 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/atoi.c31
-rw-r--r--firmware/common/atoi.h25
-rw-r--r--firmware/id3.c22
-rw-r--r--firmware/id3.h1
4 files changed, 78 insertions, 1 deletions
diff --git a/firmware/common/atoi.c b/firmware/common/atoi.c
new file mode 100644
index 0000000000..4911d93e92
--- /dev/null
+++ b/firmware/common/atoi.c
@@ -0,0 +1,31 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Gary Czvitkovicz
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "string.h"
21
22int atoi (const char *str)
23{
24 int val = 0, mlt = 1;
25 char *p;
26 p = (char *) (str + strlen(str) - 1);
27 for (; p >= str; --p, mlt *=10)
28 val += (mlt * ((int)*p - '0'));
29 return val;
30}
31
diff --git a/firmware/common/atoi.h b/firmware/common/atoi.h
new file mode 100644
index 0000000000..118879622b
--- /dev/null
+++ b/firmware/common/atoi.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __ATOI_H__
21#define __ATOI_H__
22
23int atoi (const char *str);
24
25#endif /* __ATOI_H__ */
diff --git a/firmware/id3.c b/firmware/id3.c
index 0cb7118a19..902b0527bb 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -29,6 +29,7 @@
29#include <stdbool.h> 29#include <stdbool.h>
30#include "file.h" 30#include "file.h"
31#include "debug.h" 31#include "debug.h"
32#include "atoi.h"
32 33
33#include "id3.h" 34#include "id3.h"
34 35
@@ -164,9 +165,10 @@ setid3v2title(int fd, struct mp3entry *entry)
164 char *title = NULL; 165 char *title = NULL;
165 char *artist = NULL; 166 char *artist = NULL;
166 char *album = NULL; 167 char *album = NULL;
168 char *tracknum = NULL;
167 char header[10]; 169 char header[10];
168 unsigned short int version; 170 unsigned short int version;
169 int titlen=0, artistn=0, albumn=0; 171 int titlen=0, artistn=0, albumn=0, tracknumn=0;
170 char *buffer = entry->id3v2buf; 172 char *buffer = entry->id3v2buf;
171 173
172 /* 10 = headerlength */ 174 /* 10 = headerlength */
@@ -249,6 +251,17 @@ setid3v2title(int fd, struct mp3entry *entry)
249 albumn = headerlen; 251 albumn = headerlen;
250 readsize += headerlen; 252 readsize += headerlen;
251 } 253 }
254 else if(!strncmp(header, "TRCK", strlen("TRCK"))) {
255 readsize++;
256 headerlen--;
257 if(headerlen > (size - readsize))
258 headerlen = (size - readsize);
259 tracknum = buffer + readsize;
260 tracknumn = headerlen;
261 readsize += headerlen;
262 } else {
263 readsize += headerlen;
264 }
252 } 265 }
253 266
254 if(artist) { 267 if(artist) {
@@ -265,6 +278,11 @@ setid3v2title(int fd, struct mp3entry *entry)
265 entry->album = album; 278 entry->album = album;
266 album[albumn]=0; 279 album[albumn]=0;
267 } 280 }
281
282 if(tracknum) {
283 tracknum[tracknumn] = 0;
284 entry->tracknum = atoi(tracknum);
285 }
268} 286}
269 287
270/* 288/*
@@ -493,6 +511,8 @@ mp3info(struct mp3entry *entry, char *filename)
493 entry->title = NULL; 511 entry->title = NULL;
494 entry->filesize = getfilesize(fd); 512 entry->filesize = getfilesize(fd);
495 entry->id3v2len = getid3v2len(fd); 513 entry->id3v2len = getid3v2len(fd);
514 entry->tracknum = 0;
515
496 if(HASID3V2(entry)) 516 if(HASID3V2(entry))
497 setid3v2title(fd, entry); 517 setid3v2title(fd, entry);
498 entry->length = getsonglength(fd, entry); 518 entry->length = getsonglength(fd, entry);
diff --git a/firmware/id3.h b/firmware/id3.h
index 90a2efa1b5..798753ab97 100644
--- a/firmware/id3.h
+++ b/firmware/id3.h
@@ -24,6 +24,7 @@ struct mp3entry {
24 char *title; 24 char *title;
25 char *artist; 25 char *artist;
26 char *album; 26 char *album;
27 int tracknum;
27 int version; 28 int version;
28 int layer; 29 int layer;
29 int bitrate; 30 int bitrate;