Creating iTunes compatible COMM frames

patrick machielse patrick at hieper.nl
Wed Jan 27 15:39:11 CET 2010


Op 27 jan 2010, om 15:07 heeft Thomas Post het volgende geschreven:

> But what did you do to filter out the iTunes specific comments? I just check them manually. I'm not so into C++ so is there an easier way to do the following?
> 
> 	FrameList::ConstIterator it = comments.end();
> 	--it;
> 	while (it != comments.end()){

Shouldn't that be "while (it != comments.begin()) ?"
Reverse enumeration is an optimization?

> 		CommentsFrame *frame = dynamic_cast<CommentsFrame *>(*it);
> 		if (!(frame->description() == String("iTunNORM"))
> 			&& !(frame->description() == String("iTunSMPB"))
> 			&& !(frame->description() == String("iTunPGAP"))
> 			&& !(frame->description() == String("iTunes_CDDB_1"))
> 			&& !(frame->description() == String("iTunes_CDDB_IDs"))
> 			&& !(frame->description() == String("iTunes_CDDB_TrackNumber"))) {
> 			return (*it)->toString();
> 		}
> 		--it; //revers enumerate
> 	}
> 	return String::null;

Yes, that's another problem. The id3v2 tag class' comment() function has the annoying feature of returning a COMM frame with a description if a frame without description cannot be found.

In my Cocoa wrapper class I use a aprivate function to find the regular comment frame:

//  [private] find the normal comment, not a custom one. TagLib returns
//  other comment (f.i. iTunesNORM) if no regular comment is found
//
static CommentsFrame *findCommentsFrame(const ID3v2::Tag *tag)
{
    const FrameList &comments = tag->frameListMap()["COMM"];
    for ( FrameList::ConstIterator it = comments.begin(); it != comments.end(); it++ ) {
        CommentsFrame *commFrame = dynamic_cast<CommentsFrame *>(*it);
        if ( commFrame && commFrame->description().isEmpty() ) {
            return commFrame;
        }
    }
    return NULL;
}

(NOTE: I'm also not a C++ expert)

This filters out any comment with description, not just a limited set of iTunes comments. My app encounters many mp3's with specific Serato comment frames as well. I use this function in both - (NSString *)comment and - (void)setComment:(NSString *)newComment accessor implementations.

patrick
--
Patrick Machielse
Hieper Software

http://www.hieper.nl
info at hieper.nl



More information about the taglib-devel mailing list