diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1d59f902..f991739d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v1 ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2 + ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2/frames ${CMAKE_CURRENT_SOURCE_DIR}/../bindings/c/ ) diff --git a/examples/framelist.cpp b/examples/framelist.cpp index 679aa393..44914cc9 100644 --- a/examples/framelist.cpp +++ b/examples/framelist.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -65,8 +66,15 @@ int main(int argc, char *argv[]) << endl; ID3v2::FrameList::ConstIterator it = id3v2tag->frameList().begin(); - for(; it != id3v2tag->frameList().end(); it++) - cout << (*it)->frameID() << " - \"" << (*it)->toString() << "\"" << endl; + for(; it != id3v2tag->frameList().end(); it++) { + cout << (*it)->frameID(); + + if(ID3v2::CommentsFrame *comment = dynamic_cast(*it)) + if(!comment->description().isEmpty()) + cout << " [" << comment->description() << "]"; + + cout << " - \"" << (*it)->toString() << "\"" << endl; + } } else cout << "file does not have a valid id3v2 tag" << endl; diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index cf7f191a..ef4cef4b 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -250,13 +250,24 @@ void ID3v2::Tag::setComment(const String &s) return; } - if(!d->frameListMap["COMM"].isEmpty()) - d->frameListMap["COMM"].front()->setText(s); - else { - CommentsFrame *f = new CommentsFrame(d->factory->defaultTextEncoding()); - addFrame(f); - f->setText(s); + const FrameList &comments = d->frameListMap["COMM"]; + + if(!comments.isEmpty()) { + for(FrameList::ConstIterator it = comments.begin(); it != comments.end(); ++it) { + CommentsFrame *frame = dynamic_cast(*it); + if(frame && frame->description().isEmpty()) { + (*it)->setText(s); + return; + } + } + + comments.front()->setText(s); + return; } + + CommentsFrame *f = new CommentsFrame(d->factory->defaultTextEncoding()); + addFrame(f); + f->setText(s); } void ID3v2::Tag::setGenre(const String &s)