1
/***************************************************************************
2
copyright : (C) 2003 by Scott Wheeler
3
email : wheeler@kde.org
4
***************************************************************************/
6
/***************************************************************************
7
* This library is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU Lesser General Public License version *
9
* 2.1 as published by the Free Software Foundation. *
11
* This library is distributed in the hope that it will be useful, but *
12
* WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with this library; if not, write to the Free Software *
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20
***************************************************************************/
27
#include <vorbisfile.h>
30
#include <oggflacfile.h>
32
#include <wavpackfile.h>
33
#include <speexfile.h>
34
#include <trueaudiofile.h>
37
#include <id3v2framefactory.h>
39
using namespace TagLib;
41
static List<char *> strings;
42
static bool unicodeStrings = true;
43
static bool stringManagementEnabled = true;
45
void taglib_set_strings_unicode(BOOL unicode)
47
unicodeStrings = bool(unicode);
50
void taglib_set_string_management_enabled(BOOL management)
52
stringManagementEnabled = bool(management);
55
////////////////////////////////////////////////////////////////////////////////
56
// TagLib::File wrapper
57
////////////////////////////////////////////////////////////////////////////////
59
TagLib_File *taglib_file_new(const char *filename)
61
return reinterpret_cast<TagLib_File *>(FileRef::create(filename));
64
TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)
67
case TagLib_File_MPEG:
68
return reinterpret_cast<TagLib_File *>(new MPEG::File(filename));
69
case TagLib_File_OggVorbis:
70
return reinterpret_cast<TagLib_File *>(new Ogg::Vorbis::File(filename));
71
case TagLib_File_FLAC:
72
return reinterpret_cast<TagLib_File *>(new FLAC::File(filename));
74
return reinterpret_cast<TagLib_File *>(new MPC::File(filename));
75
case TagLib_File_OggFlac:
76
return reinterpret_cast<TagLib_File *>(new Ogg::FLAC::File(filename));
77
case TagLib_File_WavPack:
78
return reinterpret_cast<TagLib_File *>(new WavPack::File(filename));
79
case TagLib_File_Speex:
80
return reinterpret_cast<TagLib_File *>(new Ogg::Speex::File(filename));
81
case TagLib_File_TrueAudio:
82
return reinterpret_cast<TagLib_File *>(new TrueAudio::File(filename));
88
void taglib_file_free(TagLib_File *file)
90
delete reinterpret_cast<File *>(file);
93
BOOL taglib_file_is_valid(const TagLib_File *file)
95
return reinterpret_cast<const File *>(file)->isValid();
98
TagLib_Tag *taglib_file_tag(const TagLib_File *file)
100
const File *f = reinterpret_cast<const File *>(file);
101
return reinterpret_cast<TagLib_Tag *>(f->tag());
104
const TagLib_AudioProperties *taglib_file_audioproperties(const TagLib_File *file)
106
const File *f = reinterpret_cast<const File *>(file);
107
return reinterpret_cast<const TagLib_AudioProperties *>(f->audioProperties());
110
BOOL taglib_file_save(TagLib_File *file)
112
return reinterpret_cast<File *>(file)->save();
115
////////////////////////////////////////////////////////////////////////////////
116
// TagLib::Tag wrapper
117
////////////////////////////////////////////////////////////////////////////////
119
char *taglib_tag_title(const TagLib_Tag *tag)
121
const Tag *t = reinterpret_cast<const Tag *>(tag);
122
char *s = ::strdup(t->title().toCString(unicodeStrings));
123
if(stringManagementEnabled)
128
char *taglib_tag_artist(const TagLib_Tag *tag)
130
const Tag *t = reinterpret_cast<const Tag *>(tag);
131
char *s = ::strdup(t->artist().toCString(unicodeStrings));
132
if(stringManagementEnabled)
137
char *taglib_tag_album(const TagLib_Tag *tag)
139
const Tag *t = reinterpret_cast<const Tag *>(tag);
140
char *s = ::strdup(t->album().toCString(unicodeStrings));
141
if(stringManagementEnabled)
146
char *taglib_tag_comment(const TagLib_Tag *tag)
148
const Tag *t = reinterpret_cast<const Tag *>(tag);
149
char *s = ::strdup(t->comment().toCString(unicodeStrings));
150
if(stringManagementEnabled)
155
char *taglib_tag_genre(const TagLib_Tag *tag)
157
const Tag *t = reinterpret_cast<const Tag *>(tag);
158
char *s = ::strdup(t->genre().toCString(unicodeStrings));
159
if(stringManagementEnabled)
164
unsigned int taglib_tag_year(const TagLib_Tag *tag)
166
const Tag *t = reinterpret_cast<const Tag *>(tag);
170
unsigned int taglib_tag_track(const TagLib_Tag *tag)
172
const Tag *t = reinterpret_cast<const Tag *>(tag);
176
void taglib_tag_set_title(TagLib_Tag *tag, const char *title)
178
Tag *t = reinterpret_cast<Tag *>(tag);
179
t->setTitle(String(title, unicodeStrings ? String::UTF8 : String::Latin1));
182
void taglib_tag_set_artist(TagLib_Tag *tag, const char *artist)
184
Tag *t = reinterpret_cast<Tag *>(tag);
185
t->setArtist(String(artist, unicodeStrings ? String::UTF8 : String::Latin1));
188
void taglib_tag_set_album(TagLib_Tag *tag, const char *album)
190
Tag *t = reinterpret_cast<Tag *>(tag);
191
t->setAlbum(String(album, unicodeStrings ? String::UTF8 : String::Latin1));
194
void taglib_tag_set_comment(TagLib_Tag *tag, const char *comment)
196
Tag *t = reinterpret_cast<Tag *>(tag);
197
t->setComment(String(comment, unicodeStrings ? String::UTF8 : String::Latin1));
200
void taglib_tag_set_genre(TagLib_Tag *tag, const char *genre)
202
Tag *t = reinterpret_cast<Tag *>(tag);
203
t->setGenre(String(genre, unicodeStrings ? String::UTF8 : String::Latin1));
206
void taglib_tag_set_year(TagLib_Tag *tag, unsigned int year)
208
Tag *t = reinterpret_cast<Tag *>(tag);
212
void taglib_tag_set_track(TagLib_Tag *tag, unsigned int track)
214
Tag *t = reinterpret_cast<Tag *>(tag);
218
void taglib_tag_free_strings()
220
if(!stringManagementEnabled)
223
for(List<char *>::Iterator it = strings.begin(); it != strings.end(); ++it)
228
////////////////////////////////////////////////////////////////////////////////
229
// TagLib::AudioProperties wrapper
230
////////////////////////////////////////////////////////////////////////////////
232
int taglib_audioproperties_length(const TagLib_AudioProperties *audioProperties)
234
const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
238
int taglib_audioproperties_bitrate(const TagLib_AudioProperties *audioProperties)
240
const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
244
int taglib_audioproperties_samplerate(const TagLib_AudioProperties *audioProperties)
246
const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
247
return p->sampleRate();
250
int taglib_audioproperties_channels(const TagLib_AudioProperties *audioProperties)
252
const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
253
return p->channels();
256
void taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_Encoding encoding)
258
String::Type type = String::Latin1;
262
case TagLib_ID3v2_Latin1:
263
type = String::Latin1;
265
case TagLib_ID3v2_UTF16:
266
type = String::UTF16;
268
case TagLib_ID3v2_UTF16BE:
269
type = String::UTF16BE;
271
case TagLib_ID3v2_UTF8:
276
ID3v2::FrameFactory::instance()->setDefaultTextEncoding(type);