Fix FS#9660 - make warn on playlist erase work correctly when creating a new playlist...
[kugel-rb.git] / apps / metadata.h
blob6144543aa6be4ceff583542bd8e0ac224710d5d3
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, /* Amiga 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 #endif
70 /* add new formats at any index above this line to have a sensible order -
71 specified array index inits are used */
72 /* format arrays defined in id3.c */
74 AFMT_NUM_CODECS,
76 #if CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING)
77 /* masks to decompose parts */
78 CODEC_AFMT_MASK = 0x0fff,
79 CODEC_TYPE_MASK = 0x7000,
81 /* switch for specifying codec type when requesting a filename */
82 CODEC_TYPE_DECODER = (0 << 12), /* default */
83 CODEC_TYPE_ENCODER = (1 << 12),
84 #endif /* CONFIG_CODEC == SWCODEC && defined(HAVE_RECORDING) */
87 #if CONFIG_CODEC == SWCODEC
88 #define CODEC_EXTENSION "codec"
90 #ifdef HAVE_RECORDING
91 #define ENCODER_SUFFIX "_enc"
92 enum rec_format_indexes
94 __REC_FORMAT_START_INDEX = -1,
96 /* start formats */
98 REC_FORMAT_PCM_WAV,
99 REC_FORMAT_AIFF,
100 REC_FORMAT_WAVPACK,
101 REC_FORMAT_MPA_L3,
103 /* add new formats at any index above this line to have a sensible order -
104 specified array index inits are used
105 REC_FORMAT_CFG_NUM_BITS should allocate enough bits to hold the range
106 REC_FORMAT_CFG_VALUE_LIST should be in same order as indexes
109 REC_NUM_FORMATS,
111 REC_FORMAT_DEFAULT = REC_FORMAT_PCM_WAV,
112 REC_FORMAT_CFG_NUM_BITS = 2
115 #define REC_FORMAT_CFG_VAL_LIST "wave,aiff,wvpk,mpa3"
117 /* get REC_FORMAT_* corresponding AFMT_* */
118 extern const int rec_format_afmt[REC_NUM_FORMATS];
119 /* get AFMT_* corresponding REC_FORMAT_* */
120 extern const int afmt_rec_format[AFMT_NUM_CODECS];
122 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
123 { label, root_fname, enc_root_fname, ext_list }
124 #else /* !HAVE_RECORDING */
125 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
126 { label, root_fname, ext_list }
127 #endif /* HAVE_RECORDING */
129 #else /* !SWCODEC */
131 #define AFMT_ENTRY(label, root_fname, enc_root_fname, ext_list) \
132 { label, ext_list }
133 #endif /* CONFIG_CODEC == SWCODEC */
135 /** Database of audio formats **/
136 /* record describing the audio format */
137 struct afmt_entry
139 char label[8]; /* format label */
140 #if CONFIG_CODEC == SWCODEC
141 char *codec_root_fn; /* root codec filename (sans _enc and .codec) */
142 #ifdef HAVE_RECORDING
143 char *codec_enc_root_fn; /* filename of encoder codec */
144 #endif
145 #endif
146 char *ext_list; /* double NULL terminated extension
147 list for type with the first as
148 the default for recording */
151 /* database of labels and codecs. add formats per above enum */
152 extern const struct afmt_entry audio_formats[AFMT_NUM_CODECS];
154 #if MEMORYSIZE > 2
155 #define ID3V2_BUF_SIZE 900
156 #else
157 #define ID3V2_BUF_SIZE 300
158 #endif
160 enum {
161 ID3_VER_1_0 = 1,
162 ID3_VER_1_1,
163 ID3_VER_2_2,
164 ID3_VER_2_3,
165 ID3_VER_2_4
168 struct mp3entry {
169 char path[MAX_PATH];
170 char* title;
171 char* artist;
172 char* album;
173 char* genre_string;
174 char* disc_string;
175 char* track_string;
176 char* year_string;
177 char* composer;
178 char* comment;
179 char* albumartist;
180 char* grouping;
181 int discnum;
182 int tracknum;
183 int version;
184 int layer;
185 int year;
186 unsigned char id3version;
187 unsigned int codectype;
188 unsigned int bitrate;
189 unsigned long frequency;
190 unsigned long id3v2len;
191 unsigned long id3v1len;
192 unsigned long first_frame_offset; /* Byte offset to first real MP3 frame.
193 Used for skipping leading garbage to
194 avoid gaps between tracks. */
195 unsigned long vbr_header_pos;
196 unsigned long filesize; /* without headers; in bytes */
197 unsigned long length; /* song length in ms */
198 unsigned long elapsed; /* ms played */
200 int lead_trim; /* Number of samples to skip at the beginning */
201 int tail_trim; /* Number of samples to remove from the end */
203 /* Added for Vorbis */
204 unsigned long samples; /* number of samples in track */
206 /* MP3 stream specific info */
207 unsigned long frame_count; /* number of frames in the file (if VBR) */
209 /* Used for A52/AC3 */
210 unsigned long bytesperframe; /* number of bytes per frame (if CBR) */
212 /* Xing VBR fields */
213 bool vbr;
214 bool has_toc; /* True if there is a VBR header in the file */
215 unsigned char toc[100]; /* table of contents */
217 /* these following two fields are used for local buffering */
218 char id3v2buf[ID3V2_BUF_SIZE];
219 char id3v1buf[4][92];
221 /* resume related */
222 unsigned long offset; /* bytes played */
223 int index; /* playlist index */
225 /* runtime database fields */
226 long tagcache_idx; /* 0=invalid, otherwise idx+1 */
227 int rating;
228 int score;
229 long playcount;
230 long lastplayed;
231 long playtime;
233 /* replaygain support */
235 #if CONFIG_CODEC == SWCODEC
236 char* track_gain_string;
237 char* album_gain_string;
238 long track_gain; /* 7.24 signed fixed point. 0 for no gain. */
239 long album_gain;
240 long track_peak; /* 7.24 signed fixed point. 0 for no peak. */
241 long album_peak;
242 #endif
244 /* Cuesheet support */
245 struct cuesheet *cuesheet;
247 /* Musicbrainz Track ID */
248 char* mb_track_id;
251 unsigned int probe_file_format(const char *filename);
252 bool get_metadata(struct mp3entry* id3, int fd, const char* trackname);
253 bool mp3info(struct mp3entry *entry, const char *filename);
254 void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig);
255 void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig);
256 #if CONFIG_CODEC == SWCODEC
257 void strip_tags(int handle_id);
258 #endif
260 #endif