-
Notifications
You must be signed in to change notification settings - Fork 6
/
audiotags.cpp
105 lines (90 loc) · 3.72 KB
/
audiotags.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/***************************************************************************
copyright : (C) 2003 by Scott Wheeler
email : [email protected]
***************************************************************************/
/***************************************************************************
copyright : (C) 2014 by Nick Sellen
email : [email protected]
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************/
#include <stdlib.h>
#include <fileref.h>
#include <tfile.h>
#include <tpropertymap.h>
#include <string.h>
#include <typeinfo>
#include "audiotags.h"
static bool unicodeStrings = true;
void TagLib_free(void* pointer)
{
free(pointer);
}
TagLib_File *audiotags_file_new(const char *filename)
{
TagLib::File *f = TagLib::FileRef::create(filename);
if (f == NULL || !f->isValid() || f->tag() == NULL) {
if (f) {
delete f;
f = NULL;
}
return NULL;
}
return reinterpret_cast<TagLib_File *>(f);
}
void audiotags_file_close(TagLib_File *file)
{
delete reinterpret_cast<TagLib::File *>(file);
}
void audiotags_file_properties(const TagLib_File *file, int id)
{
const TagLib::File *f = reinterpret_cast<const TagLib::File *>(file);
TagLib::PropertyMap tags = f->properties();
for(TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) {
for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) {
char *key = ::strdup(i->first.toCString(unicodeStrings));
char *val = ::strdup((*j).toCString(unicodeStrings));
go_map_put(id, key, val);
free(key);
free(val);
}
}
}
const TagLib_AudioProperties *audiotags_file_audioproperties(const TagLib_File *file)
{
const TagLib::File *f = reinterpret_cast<const TagLib::File *>(file);
return reinterpret_cast<const TagLib_AudioProperties *>(f->audioProperties());
}
const TagLib::AudioProperties *props(const TagLib_AudioProperties *audioProperties)
{
return reinterpret_cast<const TagLib::AudioProperties *>(audioProperties);
}
int audiotags_audioproperties_length(const TagLib_AudioProperties *audioProperties)
{
return props(audioProperties)->length();
}
int audiotags_audioproperties_bitrate(const TagLib_AudioProperties *audioProperties)
{
return props(audioProperties)->bitrate();
}
int audiotags_audioproperties_samplerate(const TagLib_AudioProperties *audioProperties)
{
return props(audioProperties)->sampleRate();
}
int audiotags_audioproperties_channels(const TagLib_AudioProperties *audioProperties)
{
return props(audioProperties)->channels();
}