Bubbles: Don't save scores when quit without saving is selected and reduce splash...
[kugel-rb.git] / apps / metadata.h
blob9b9cf9dfd1875a9e24b7d5fe09be0d27497027ee
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 ****************************************************************************/
22 #ifndef _METADATA_H
23 #define _METADATA_H
25 #include <stdbool.h>
26 #include "file.h"
27 #include "config.h"
30 /* Audio file types. */
31 /* NOTE: The values of the AFMT_* items are used for the %fc tag in the WPS
32 - so new entries MUST be added to the end to maintain compatibility.
34 enum
36 AFMT_UNKNOWN = 0, /* Unknown file format */
38 /* start formats */
40 AFMT_MPA_L1, /* MPEG Audio layer 1 */
41 AFMT_MPA_L2, /* MPEG Audio layer 2 */
42 AFMT_MPA_L3, /* MPEG Audio layer 3 */
44 #if CONFIG_CODEC == SWCODEC
45 AFMT_AIFF, /* Audio Interchange File Format */
46 AFMT_PCM_WAV, /* Uncompressed PCM in a WAV file */
47 AFMT_OGG_VORBIS, /* Ogg Vorbis */
48 AFMT_FLAC, /* FLAC */
49 AFMT_MPC, /* Musepack */
50 AFMT_A52, /* A/52 (aka AC3) audio */
51 AFMT_WAVPACK, /* WavPack */
52 AFMT_MP4_ALAC, /* Apple Lossless Audio Codec */
53 AFMT_MP4_AAC, /* Advanced Audio Coding (AAC) in M4A container */
54 AFMT_SHN, /* Shorten */
55 AFMT_SID, /* SID File Format */
56 AFMT_ADX, /* ADX File Format */
57 AFMT_NSF, /* NESM (NES Sound Format) */
58 AFMT_SPEEX, /* Ogg Speex speech */
59 AFMT_SPC, /* SPC700 save state */
60 AFMT_APE, /* Monkey's Audio (APE) */
61 AFMT_WMA, /* WMAV1/V2 in ASF */
62 AFMT_MOD, /* Amiga MOD File Format */
63 AFMT_SAP, /* Atari 8Bit SAP Format */
64 AFMT_RM_COOK, /* Cook in RM/RA */
65 AFMT_RM_AAC, /* AAC in RM/RA */
66 AFMT_RM_AC3, /* AC3 in RM/RA */
67 AFMT_RM_ATRAC3, /* ATRAC3 in RM/RA */
68 AFMT_CMC, /* Atari 8bit cmc format */
69 AFMT_CM3, /* Atari 8bit cm3 format */
70 AFMT_CMR, /* Atari 8bit cmr format */
71 AFMT_CMS, /* Atari 8bit cms format */
72 AFMT_DMC, /* Atari 8bit dmc format */
73 AFMT_DLT, /* Atari 8bit dlt format */
74 AFMT_MPT, /* Atari 8bit mpt format */
75 AFMT_MPD, /* Atari 8bit mpd format */
76 AFMT_RMT, /* Atari 8bit rmt format */
77 AFMT_TMC, /* Atari 8bit tmc format */
78 AFMT_TM8, /* Atari 8bit tm8 format */
79 AFMT_TM2, /* Atari 8bit tm2 format */
80 #endif
82 /* add new formats at any index above this line to have a sensible order -
83 specified array index inits are used */
84 /* format arrays defined in id3.c */
86 AFMT_NUM_CODECS,
88 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
89 /* masks to decompose parts */
90 CODEC_AFMT_MASK = 0x0fff,
91 CODEC_TYPE_MASK = 0x7000,
93 /* switch for specifying codec type when requesting a filename */
94 CODEC_TYPE_DECODER = (0 << 12), /* default */
95 CODEC_TYPE_ENCODER = (1 << 12),
96 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
99 #if CONFIG_CODEC == SWCODEC
100 #define CODEC_EXTENSION "codec"
102 #ifdef HAVE_RECORDING
103 #define ENCODER_SUFFIX "_enc"
104 enum rec_format_indexes
106 __REC_FORMAT_START_INDEX = -1,
108 /* start formats */
110 REC_FORMAT_PCM_WAV,
111 REC_FORMAT_AIFF,
112 REC_FORMAT_WAVPACK,
113 REC_FORMAT_MPA_L3,
115 /* add new formats at any index above this line to have a sensible order -
116 specified array index inits are used
117 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
118 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
121 REC_NUM_FORMATS,
123 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
124 REC_FORMAT_CFG_NUM_BITS = 2
127 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
129 /* get REC_FORMAT_* corresponding AFMT_* */
130 extern const int rec_format_afmt[REC_NUM_FORMATS];
131 /* get AFMT_* corresponding REC_FORMAT_* */
132 extern const int afmt_rec_format[AFMT_NUM_CODECS];
134 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
135 { label, root_fname, enc_root_fname, ext_list }
136 #else /* !HAVE_RECORDING */
137 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
138 { label, root_fname, ext_list }
139 #endif /* HAVE_RECORDING */
141 #else /* !SWCODEC */
143 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
144 { label, ext_list }
145 #endif /* CONFIG_CODEC == SWCODEC */
147 /** Database of audio formats **/
148 /* record describing the audio format */
149 struct afmt_entry
151 char label[8]; /* format label */
152 #if CONFIG_CODEC == SWCODEC
153 char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
154 #ifdef HAVE_RECORDING
155 char *codec_enc_root_fn; /* filename of encoder codec */
156 #endif
157 #endif
158 char *ext_list; /* double NULL terminated extension
159 list for type with the first as
160 the default for recording */
163 /* database of labels and codecs. add formats per above enum */
164 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
166 #if MEMORYSIZE > 2
167 #define ID3V2_BUF_SIZE 900
168 #else
169 #define ID3V2_BUF_SIZE 300
170 #endif
172 enum {
173 ID3_VER_1_0 = 1,
174 ID3_VER_1_1,
175 ID3_VER_2_2,
176 ID3_VER_2_3,
177 ID3_VER_2_4
180 struct mp3entry {
181 char path[MAX_PATH];
182 char* title;
183 char* artist;
184 char* album;
185 char* genre_string;
186 char* disc_string;
187 char* track_string;
188 char* year_string;
189 char* composer;
190 char* comment;
191 char* albumartist;
192 char* grouping;
193 int discnum;
194 int tracknum;
195 int version;
196 int layer;
197 int year;
198 unsigned char id3version;
199 unsigned int codectype;
200 unsigned int bitrate;
201 unsigned long frequency;
202 unsigned long id3v2len;
203 unsigned long id3v1len;
204 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
205 Used for skipping leading garbage to
206 avoid gaps between tracks. */
207 unsigned long vbr_header_pos;
208 unsigned long filesize; /* without headers; in bytes */
209 unsigned long length; /* song length in ms */
210 unsigned long elapsed; /* ms played */
212 int lead_trim; /* Number of samples to skip at the beginning */
213 int tail_trim; /* Number of samples to remove from the end */
215 /* Added for Vorbis */
216 unsigned long samples; /* number of samples in track */
218 /* MP3 stream specific info */
219 unsigned long frame_count; /* number of frames in the file (if VBR) */
221 /* Used for A52/AC3 */
222 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
224 /* Xing VBR fields */
225 bool vbr;
226 bool has_toc; /* True if there is a VBR header in the file */
227 unsigned char toc[100]; /* table of contents */
229 /* these following two fields are used for local buffering */
230 char id3v2buf[ID3V2_BUF_SIZE];
231 char id3v1buf[4][92];
233 /* resume related */
234 unsigned long offset; /* bytes played */
235 int index; /* playlist index */
237 /* runtime database fields */
238 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
239 int rating;
240 int score;
241 long playcount;
242 long lastplayed;
243 long playtime;
245 /* replaygain support */
247 #if CONFIG_CODEC == SWCODEC
248 char* track_gain_string;
249 char* album_gain_string;
250 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
251 long album_gain;
252 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
253 long album_peak;
254 #endif
256 /* Cuesheet support */
257 struct cuesheet *cuesheet;
259 /* Musicbrainz Track ID */
260 char* mb_track_id;
263 unsigned int probe_file_format(const char *filename);
264 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
265 bool mp3info(struct mp3entry *entry, const char *filename);
266 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
267 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
268 #if CONFIG_CODEC == SWCODEC
269 void strip_tags(int handle_id);
270 #endif
272 #endif