From 928e334831f87dfe3b35b50e119b0ade9980b944 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Wed, 26 Jun 2002 21:11:29 +0000 Subject: Added id3 tracknum (Yusef Napora) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1204 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/atoi.c | 31 +++++++++++++++++++++++++++++++ firmware/common/atoi.h | 25 +++++++++++++++++++++++++ firmware/id3.c | 22 +++++++++++++++++++++- firmware/id3.h | 1 + 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 firmware/common/atoi.c create mode 100644 firmware/common/atoi.h 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Gary Czvitkovicz + * + * 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. + * + ****************************************************************************/ + +#include "string.h" + +int atoi (const char *str) +{ + int val = 0, mlt = 1; + char *p; + p = (char *) (str + strlen(str) - 1); + for (; p >= str; --p, mlt *=10) + val += (mlt * ((int)*p - '0')); + return val; +} + 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Felix Arends + * + * 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. + * + ****************************************************************************/ + +#ifndef __ATOI_H__ +#define __ATOI_H__ + +int atoi (const char *str); + +#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 @@ #include #include "file.h" #include "debug.h" +#include "atoi.h" #include "id3.h" @@ -164,9 +165,10 @@ setid3v2title(int fd, struct mp3entry *entry) char *title = NULL; char *artist = NULL; char *album = NULL; + char *tracknum = NULL; char header[10]; unsigned short int version; - int titlen=0, artistn=0, albumn=0; + int titlen=0, artistn=0, albumn=0, tracknumn=0; char *buffer = entry->id3v2buf; /* 10 = headerlength */ @@ -249,6 +251,17 @@ setid3v2title(int fd, struct mp3entry *entry) albumn = headerlen; readsize += headerlen; } + else if(!strncmp(header, "TRCK", strlen("TRCK"))) { + readsize++; + headerlen--; + if(headerlen > (size - readsize)) + headerlen = (size - readsize); + tracknum = buffer + readsize; + tracknumn = headerlen; + readsize += headerlen; + } else { + readsize += headerlen; + } } if(artist) { @@ -265,6 +278,11 @@ setid3v2title(int fd, struct mp3entry *entry) entry->album = album; album[albumn]=0; } + + if(tracknum) { + tracknum[tracknumn] = 0; + entry->tracknum = atoi(tracknum); + } } /* @@ -493,6 +511,8 @@ mp3info(struct mp3entry *entry, char *filename) entry->title = NULL; entry->filesize = getfilesize(fd); entry->id3v2len = getid3v2len(fd); + entry->tracknum = 0; + if(HASID3V2(entry)) setid3v2title(fd, entry); 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 { char *title; char *artist; char *album; + int tracknum; int version; int layer; int bitrate; -- cgit v1.2.3