Fix silly mistake
[maemo-rb.git] / apps / metadata / mod.c
blobde76823e9149dff86aa7923e33f1079a3a45e13d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <ctype.h>
24 #include <inttypes.h>
26 #include "system.h"
27 #include "metadata.h"
28 #include <string-extra.h>
29 #include "metadata_common.h"
30 #include "metadata_parsers.h"
31 #include "rbunicode.h"
33 #define MODULEHEADERSIZE 0x438
35 bool get_mod_metadata(int fd, struct mp3entry* id3)
37 /* Use the trackname part of the id3 structure as a temporary buffer */
38 unsigned char *buf = id3->id3v2buf;
39 unsigned char id[4];
40 bool is_mod_file = false;
42 /* Seek to file begin */
43 if (lseek(fd, 0, SEEK_SET) < 0)
44 return false;
45 /* Use id3v2buf as buffer for the track name */
46 if (read(fd, buf, sizeof(id3->id3v2buf)) < (ssize_t)sizeof(id3->id3v2buf))
47 return false;
48 /* Seek to MOD ID position */
49 if (lseek(fd, MODULEHEADERSIZE, SEEK_SET) < 0)
50 return false;
51 /* Read MOD ID */
52 if (read(fd, id, sizeof(id)) < (ssize_t)sizeof(id))
53 return false;
55 /* Mod type checking based on MikMod */
56 /* Protracker and variants */
57 if ((!memcmp(id, "M.K.", 4)) || (!memcmp(id, "M!K!", 4))) {
58 is_mod_file = true;
61 /* Star Tracker */
62 if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) &&
63 (isdigit(id[3]))) {
64 char numchn = id[3] - '0';
65 if (numchn == 4 || numchn == 8)
66 is_mod_file = true;
69 /* Oktalyzer (Amiga) */
70 if (!memcmp(id, "OKTA", 4)) {
71 is_mod_file = true;
74 /* Oktalyser (Atari) */
75 if (!memcmp(id, "CD81", 4)) {
76 is_mod_file = true;
79 /* Fasttracker */
80 if ((!memcmp(id + 1, "CHN", 3)) && (isdigit(id[0]))) {
81 is_mod_file = true;
83 /* Fasttracker or Taketracker */
84 if (((!memcmp(id + 2, "CH", 2)) || (!memcmp(id + 2, "CN", 2)))
85 && (isdigit(id[0])) && (isdigit(id[1]))) {
86 is_mod_file = true;
89 /* Don't try to play if we can't find a known mod type
90 * (there are mod files which have nothing to do with music) */
91 if (!is_mod_file)
92 return false;
94 id3->title = id3->id3v2buf; /* Point title to previous read ID3 buffer. */
95 id3->bitrate = filesize(fd)/1024; /* size in kb */
96 id3->frequency = 44100;
97 id3->length = 120*1000;
98 id3->vbr = false;
99 id3->filesize = filesize(fd);
101 return true;