~njh-aelius/maxosx/musicbrainz-tags

« back to all changes in this revision

Viewing changes to Frameworks/taglib/taglib/bindings/c/tag_c.cpp

  • Committer: stephen_booth
  • Date: 2008-04-30 02:09:12 UTC
  • Revision ID: svn-v4:6b6cea13-1402-0410-9567-a7afb52bf336:trunk:1372
Update to latest taglib SVN

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2003 by Scott Wheeler
 
3
    email                : wheeler@kde.org
 
4
 ***************************************************************************/
 
5
 
 
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.                     *
 
10
 *                                                                         *
 
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.                       *
 
15
 *                                                                         *
 
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  *
 
19
 *   USA                                                                   *
 
20
 ***************************************************************************/
 
21
 
 
22
#include "tag_c.h"
 
23
 
 
24
#include <stdlib.h>
 
25
#include <fileref.h>
 
26
#include <tfile.h>
 
27
#include <vorbisfile.h>
 
28
#include <mpegfile.h>
 
29
#include <flacfile.h>
 
30
#include <oggflacfile.h>
 
31
#include <mpcfile.h>
 
32
#include <wavpackfile.h>
 
33
#include <speexfile.h>
 
34
#include <trueaudiofile.h>
 
35
#include <tag.h>
 
36
#include <string.h>
 
37
#include <id3v2framefactory.h>
 
38
 
 
39
using namespace TagLib;
 
40
 
 
41
static List<char *> strings;
 
42
static bool unicodeStrings = true;
 
43
static bool stringManagementEnabled = true;
 
44
 
 
45
void taglib_set_strings_unicode(BOOL unicode)
 
46
{
 
47
  unicodeStrings = bool(unicode);
 
48
}
 
49
 
 
50
void taglib_set_string_management_enabled(BOOL management)
 
51
{
 
52
  stringManagementEnabled = bool(management);
 
53
}
 
54
 
 
55
////////////////////////////////////////////////////////////////////////////////
 
56
// TagLib::File wrapper
 
57
////////////////////////////////////////////////////////////////////////////////
 
58
 
 
59
TagLib_File *taglib_file_new(const char *filename)
 
60
{
 
61
  return reinterpret_cast<TagLib_File *>(FileRef::create(filename));
 
62
}
 
63
 
 
64
TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)
 
65
{
 
66
  switch(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));
 
73
  case TagLib_File_MPC:
 
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));
 
83
  }
 
84
 
 
85
  return 0;
 
86
}
 
87
 
 
88
void taglib_file_free(TagLib_File *file)
 
89
{
 
90
  delete reinterpret_cast<File *>(file);
 
91
}
 
92
 
 
93
BOOL taglib_file_is_valid(const TagLib_File *file)
 
94
{
 
95
        return reinterpret_cast<const File *>(file)->isValid();
 
96
}
 
97
 
 
98
TagLib_Tag *taglib_file_tag(const TagLib_File *file)
 
99
{
 
100
  const File *f = reinterpret_cast<const File *>(file);
 
101
  return reinterpret_cast<TagLib_Tag *>(f->tag());
 
102
}
 
103
 
 
104
const TagLib_AudioProperties *taglib_file_audioproperties(const TagLib_File *file)
 
105
{
 
106
  const File *f = reinterpret_cast<const File *>(file);
 
107
  return reinterpret_cast<const TagLib_AudioProperties *>(f->audioProperties());
 
108
}
 
109
 
 
110
BOOL taglib_file_save(TagLib_File *file)
 
111
{
 
112
  return reinterpret_cast<File *>(file)->save();
 
113
}
 
114
 
 
115
////////////////////////////////////////////////////////////////////////////////
 
116
// TagLib::Tag wrapper
 
117
////////////////////////////////////////////////////////////////////////////////
 
118
 
 
119
char *taglib_tag_title(const TagLib_Tag *tag)
 
120
{
 
121
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
122
  char *s = ::strdup(t->title().toCString(unicodeStrings));
 
123
  if(stringManagementEnabled)
 
124
    strings.append(s);
 
125
  return s;
 
126
}
 
127
 
 
128
char *taglib_tag_artist(const TagLib_Tag *tag)
 
129
{
 
130
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
131
  char *s = ::strdup(t->artist().toCString(unicodeStrings));
 
132
  if(stringManagementEnabled)
 
133
    strings.append(s);
 
134
  return s;
 
135
}
 
136
 
 
137
char *taglib_tag_album(const TagLib_Tag *tag)
 
138
{
 
139
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
140
  char *s = ::strdup(t->album().toCString(unicodeStrings));
 
141
  if(stringManagementEnabled)
 
142
    strings.append(s);
 
143
  return s;
 
144
}
 
145
 
 
146
char *taglib_tag_comment(const TagLib_Tag *tag)
 
147
{
 
148
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
149
  char *s = ::strdup(t->comment().toCString(unicodeStrings));
 
150
  if(stringManagementEnabled)
 
151
    strings.append(s);
 
152
  return s;
 
153
}
 
154
 
 
155
char *taglib_tag_genre(const TagLib_Tag *tag)
 
156
{
 
157
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
158
  char *s = ::strdup(t->genre().toCString(unicodeStrings));
 
159
  if(stringManagementEnabled)
 
160
    strings.append(s);
 
161
  return s;
 
162
}
 
163
 
 
164
unsigned int taglib_tag_year(const TagLib_Tag *tag)
 
165
{
 
166
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
167
  return t->year();
 
168
}
 
169
 
 
170
unsigned int taglib_tag_track(const TagLib_Tag *tag)
 
171
{
 
172
  const Tag *t = reinterpret_cast<const Tag *>(tag);
 
173
  return t->track();
 
174
}
 
175
 
 
176
void taglib_tag_set_title(TagLib_Tag *tag, const char *title)
 
177
{
 
178
  Tag *t = reinterpret_cast<Tag *>(tag);
 
179
  t->setTitle(String(title, unicodeStrings ? String::UTF8 : String::Latin1));
 
180
}
 
181
 
 
182
void taglib_tag_set_artist(TagLib_Tag *tag, const char *artist)
 
183
{
 
184
  Tag *t = reinterpret_cast<Tag *>(tag);
 
185
  t->setArtist(String(artist, unicodeStrings ? String::UTF8 : String::Latin1));
 
186
}
 
187
 
 
188
void taglib_tag_set_album(TagLib_Tag *tag, const char *album)
 
189
{
 
190
  Tag *t = reinterpret_cast<Tag *>(tag);
 
191
  t->setAlbum(String(album, unicodeStrings ? String::UTF8 : String::Latin1));
 
192
}
 
193
 
 
194
void taglib_tag_set_comment(TagLib_Tag *tag, const char *comment)
 
195
{
 
196
  Tag *t = reinterpret_cast<Tag *>(tag);
 
197
  t->setComment(String(comment, unicodeStrings ? String::UTF8 : String::Latin1));
 
198
}
 
199
 
 
200
void taglib_tag_set_genre(TagLib_Tag *tag, const char *genre)
 
201
{
 
202
  Tag *t = reinterpret_cast<Tag *>(tag);
 
203
  t->setGenre(String(genre, unicodeStrings ? String::UTF8 : String::Latin1));
 
204
}
 
205
 
 
206
void taglib_tag_set_year(TagLib_Tag *tag, unsigned int year)
 
207
{
 
208
  Tag *t = reinterpret_cast<Tag *>(tag);
 
209
  t->setYear(year);
 
210
}
 
211
 
 
212
void taglib_tag_set_track(TagLib_Tag *tag, unsigned int track)
 
213
{
 
214
  Tag *t = reinterpret_cast<Tag *>(tag);
 
215
  t->setTrack(track);
 
216
}
 
217
 
 
218
void taglib_tag_free_strings()
 
219
{
 
220
  if(!stringManagementEnabled)
 
221
    return;
 
222
 
 
223
  for(List<char *>::Iterator it = strings.begin(); it != strings.end(); ++it)
 
224
    free(*it);
 
225
  strings.clear();
 
226
}
 
227
 
 
228
////////////////////////////////////////////////////////////////////////////////
 
229
// TagLib::AudioProperties wrapper
 
230
////////////////////////////////////////////////////////////////////////////////
 
231
 
 
232
int taglib_audioproperties_length(const TagLib_AudioProperties *audioProperties)
 
233
{
 
234
  const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
 
235
  return p->length();
 
236
}
 
237
 
 
238
int taglib_audioproperties_bitrate(const TagLib_AudioProperties *audioProperties)
 
239
{
 
240
  const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
 
241
  return p->bitrate();
 
242
}
 
243
 
 
244
int taglib_audioproperties_samplerate(const TagLib_AudioProperties *audioProperties)
 
245
{
 
246
  const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
 
247
  return p->sampleRate();
 
248
}
 
249
 
 
250
int taglib_audioproperties_channels(const TagLib_AudioProperties *audioProperties)
 
251
{
 
252
  const AudioProperties *p = reinterpret_cast<const AudioProperties *>(audioProperties);
 
253
  return p->channels();
 
254
}
 
255
 
 
256
void taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_Encoding encoding)
 
257
{
 
258
  String::Type type = String::Latin1;
 
259
 
 
260
  switch(encoding)
 
261
  {
 
262
  case TagLib_ID3v2_Latin1:
 
263
    type = String::Latin1;
 
264
    break;
 
265
  case TagLib_ID3v2_UTF16:
 
266
    type = String::UTF16;
 
267
    break;
 
268
  case TagLib_ID3v2_UTF16BE:
 
269
    type = String::UTF16BE;
 
270
    break;
 
271
  case TagLib_ID3v2_UTF8:
 
272
    type = String::UTF8;
 
273
    break;
 
274
  }
 
275
 
 
276
  ID3v2::FrameFactory::instance()->setDefaultTextEncoding(type);
 
277
}