40
AudioTagger::~AudioTagger ( )
39
AudioTagger::~AudioTagger ( ) {
46
void AudioTagger::setArtist (QString artist )
42
void AudioTagger::setArtist (QString artist ) {
53
void AudioTagger::setTitle (QString title )
46
void AudioTagger::setTitle (QString title ) {
60
void AudioTagger::setAlbum (QString album )
50
void AudioTagger::setAlbum (QString album ) {
67
void AudioTagger::setGenre (QString genre )
54
void AudioTagger::setGenre (QString genre ) {
73
void AudioTagger::setComposer (QString composer )
58
void AudioTagger::setComposer (QString composer ) {
75
59
m_composer = composer;
79
void AudioTagger::setYear (QString year )
62
void AudioTagger::setYear (QString year ) {
86
void AudioTagger::setComment (QString comment )
66
void AudioTagger::setComment (QString comment ) {
88
67
m_comment = comment;
91
void AudioTagger::setKey (QString key )
70
void AudioTagger::setKey (QString key ) {
96
void AudioTagger::setBpm (QString bpm )
74
void AudioTagger::setBpm (QString bpm ) {
101
void AudioTagger::setTracknumber (QString tracknumber )
78
void AudioTagger::setTracknumber (QString tracknumber ) {
103
79
m_tracknumber = tracknumber;
105
bool AudioTagger::save ()
82
bool AudioTagger::save () {
107
83
TagLib::File* file = NULL;
109
if(m_file.endsWith(".mp3", Qt::CaseInsensitive)){
85
if (m_file.endsWith(".mp3", Qt::CaseInsensitive)) {
110
86
file = new TagLib::MPEG::File(m_file.toUtf8().constData());
111
87
//process special ID3 fields, APEv2 fiels, etc
116
92
addAPETag( ((TagLib::MPEG::File*) file)->APETag(false) );
119
if(m_file.endsWith(".m4a", Qt::CaseInsensitive)){
95
if (m_file.endsWith(".m4a", Qt::CaseInsensitive)) {
120
96
file = new TagLib::MP4::File(m_file.toUtf8().constData());
121
97
//process special ID3 fields, APEv2 fiels, etc
122
98
processMP4Tag(((TagLib::MP4::File*) file)->tag());
125
if(m_file.endsWith(".ogg", Qt::CaseInsensitive)){
101
if (m_file.endsWith(".ogg", Qt::CaseInsensitive)) {
126
102
file = new TagLib::Ogg::Vorbis::File(m_file.toUtf8().constData());
127
103
//process special ID3 fields, APEv2 fiels, etc
128
104
addXiphComment( ((TagLib::Ogg::Vorbis::File*) file)->tag() );
131
if(m_file.endsWith(".wav", Qt::CaseInsensitive)){
107
if (m_file.endsWith(".wav", Qt::CaseInsensitive)) {
132
108
file = new TagLib::RIFF::WAV::File(m_file.toUtf8().constData());
133
109
//If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
134
110
addID3v2Tag( ((TagLib::RIFF::WAV::File*) file)->tag() );
137
if(m_file.endsWith(".flac", Qt::CaseInsensitive)){
113
if (m_file.endsWith(".flac", Qt::CaseInsensitive)) {
138
114
file = new TagLib::FLAC::File(m_file.toUtf8().constData());
140
116
//If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
143
119
addXiphComment( ((TagLib::FLAC::File*) file)->xiphComment (true) );
146
if(m_file.endsWith(".aif", Qt::CaseInsensitive) || m_file.endsWith(".aiff", Qt::CaseInsensitive)){
122
if (m_file.endsWith(".aif", Qt::CaseInsensitive) || m_file.endsWith(".aiff", Qt::CaseInsensitive)) {
147
123
file = new TagLib::RIFF::AIFF::File(m_file.toUtf8().constData());
148
124
//If the flac has no ID3v2 tag, we create a new one and add the TBPM and TKEY frame
149
125
addID3v2Tag( ((TagLib::RIFF::AIFF::File*) file)->tag() );
153
129
//process standard tags
155
131
TagLib::Tag *tag = file->tag();
158
133
tag->setArtist(m_artist.toStdString());
159
134
tag->setTitle(m_title.toStdString());
160
135
tag->setAlbum(m_album.toStdString());
161
136
tag->setGenre(m_genre.toStdString());
162
137
tag->setComment(m_comment.toStdString());
163
138
uint year = m_year.toUInt();
165
140
tag->setYear(year);
166
141
uint tracknumber = m_tracknumber.toUInt();
168
143
tag->setTrack(tracknumber);
174
149
qDebug() << "Successfully updated metadata of track " << m_file;
176
151
qDebug() << "Could not update metadata of track " << m_file;
178
153
//delete file and return
188
void AudioTagger::addID3v2Tag(TagLib::ID3v2::Tag* id3v2)
161
void AudioTagger::addID3v2Tag(TagLib::ID3v2::Tag* id3v2) {
192
165
TagLib::ID3v2::FrameList bpmFrame = id3v2->frameListMap()["TBPM"];
193
if (!bpmFrame.isEmpty())
166
if (!bpmFrame.isEmpty()) {
195
167
bpmFrame.front()->setText(m_bpm.toStdString());
201
* add new frame TextIdentificationFrame which is responsible for TKEY and TBPM
202
* see http://developer.kde.org/~wheeler/taglib/api/classTagLib_1_1ID3v2_1_1TextIdentificationFrame.html
169
// add new frame TextIdentificationFrame which is responsible for TKEY and TBPM
170
// see http://developer.kde.org/~wheeler/taglib/api/classTagLib_1_1ID3v2_1_1TextIdentificationFrame.html
205
172
TagLib::ID3v2::TextIdentificationFrame* newFrame = new TagLib::ID3v2::TextIdentificationFrame("TBPM", TagLib::String::Latin1);
212
179
TagLib::ID3v2::FrameList keyFrame = id3v2->frameListMap()["TKEY"];
213
if (!keyFrame.isEmpty())
180
if (!keyFrame.isEmpty()) {
215
181
keyFrame.front()->setText(m_key.toStdString());
221
184
TagLib::ID3v2::TextIdentificationFrame* newFrame = new TagLib::ID3v2::TextIdentificationFrame("TKEY", TagLib::String::Latin1);
228
191
TagLib::ID3v2::FrameList composerFrame = id3v2->frameListMap()["TCOM"];
229
if (!composerFrame.isEmpty())
192
if (!composerFrame.isEmpty()) {
231
193
composerFrame.front()->setText(m_composer.toStdString());
236
196
TagLib::ID3v2::TextIdentificationFrame* newFrame =
237
197
new TagLib::ID3v2::TextIdentificationFrame(
240
200
id3v2->addFrame(newFrame);
243
void AudioTagger::addAPETag(TagLib::APE::Tag* ape)
247
* Adds to the item specified by key the data value.
248
* If replace is true, then all of the other values on the same key will be removed first.
204
void AudioTagger::addAPETag(TagLib::APE::Tag* ape) {
207
// Adds to the item specified by key the data value.
208
// If replace is true, then all of the other values on the same key will be removed first.
250
209
ape->addValue("BPM",m_bpm.toStdString(), true);
251
210
ape->addValue("BPM",m_bpm.toStdString(), true);
252
211
ape->addValue("Composer",m_composer.toStdString(), true);
255
void AudioTagger::addXiphComment(TagLib::Ogg::XiphComment* xiph)
214
void AudioTagger::addXiphComment(TagLib::Ogg::XiphComment* xiph) {
259
218
// Some tools use "BPM" so check for that.
261
/* Taglib does not support the update of Vorbis comments.
262
* thus, we have to reomve the old comment and add the new one
220
// Taglib does not support the update of Vorbis comments.
221
// thus, we have to reomve the old comment and add the new one
264
222
xiph->removeField("BPM");
265
223
xiph->addField("BPM", m_bpm.toStdString());
275
233
xiph->removeField("COMPOSER");
276
234
xiph->addField("COMPOSER", m_key.toStdString());
278
void AudioTagger::processMP4Tag(TagLib::MP4::Tag* mp4)
236
void AudioTagger::processMP4Tag(TagLib::MP4::Tag* mp4) {