Iterating through and removing Frames

Festus Hagen festushagenlists at yahoo.com
Tue Dec 4 09:05:45 UTC 2012


Michael, AWESOME ... The final key!

I'm going to post my mess, I was this close!

            ID3v2::FrameList lDelete;
   
         for(ID3v2::FrameList::ConstIterator it = 
id3v2tag->frameList().begin(); it != id3v2tag->frameList().end(); 
it++) {
                if (    (*it)->frameID() != "TIT2"
                     && (*it)->frameID() != "TPE1"
                     && (*it)->frameID() != "TALB"
                     && (*it)->frameID() != "TRCK"
                     ) {
//   
                 cout << "  " << (*it)->frameID() 
<< " - DELETE - " << (*it)->toString() << endl;
                    lDelete.addFrame((*it));
                    bSave = true;
                }
            }
            if (bSave) {
//1                cout << "Saved ..." << endl;
//  FrameList l = d->frameListMap[id];
//  for(FrameList::Iterator it = l.begin(); it != l.end(); ++it)
//    removeFrame(*it, true);
                for(ID3v2::FrameList::Iterator fIt = lDelete.begin(); fIt != lDelete.end(); fIt++)
                id3v2tag->removeFrame(*fIt, true);
            f.save(MPEG::File::ID3v2);
            }

NOTE the "lDelete.addFrame((*it));" ...
That
 is how far I got before I noticed a new mail and saw the Error of my 
addFrame() ways, changed it to append() and it WORKED!!!
The clue 
that set me on that track was that little commented snippet following 
the "//1" that is from removeFrames() and how it created a list from the
 frameListMap[id]

AWESOME!

I will sleep, then clean it up and re-post it for the next searching soul ...

Thank ya much.

-Enjoy
fh : )_~


----- Original Message -----
From: Michael Helmling <helmling at mathematik.uni-kl.de>
To: Festus Hagen <festushagenlists at yahoo.com>; taglib-devel at kde.org
Cc: 
Sent: Tuesday, December 4, 2012 3:01 AM
Subject: Re: Iterating through and removing Frames

Hi Festus,

you are right about the iterator getting invalid. You should use 
something like:

ID3v2::FrameList toRemove;
for(....)
     if(...)
         toRemove.append(it);

And then:
for(ID3v2::FrameList::ConstIterator it = toRemove.begin(); ....)
     id3v2tag->removeFrame(*it);

That construct is used on several places in the unified string key API 
of taglib.

Regards,
Michael
Am 04.12.2012 07:52, schrieb Festus Hagen:
> Hi all,
>
> I have been searching for an example or info leading to the correct method to do the following with out success.
> (hopefully it's readable)
>
>              for(ID3v2::FrameList::ConstIterator it = id3v2tag->frameList().begin();
>                      it != id3v2tag->frameList().end(); it++) {
>                  if (    (*it)->frameID() != "TIT2"
>                       && (*it)->frameID() != "TPE1"
>                       && (*it)->frameID() != "TALB"
>                       && (*it)->frameID() != "TRCK"
>                       ) {
>                      id3v2tag->removeFrames((*it)->frameID());
>                      bSave = true;
>                  }
>              }
>              if (bSave)
>              f.save(MPEG::File::ID3v2);
>
> Obviously it doesn't work.
> Could someone please give me a kick in the right direction.
>
> I believe I understand whats wrong, I just don't know how to overcome it.
> The iterator gets invalidated when a frame(s) is deleted ??
>
> Thanks
> fh : )_~
> _______________________________________________
> taglib-devel mailing list
> taglib-devel at kde.org
> https://mail.kde.org/mailman/listinfo/taglib-devel


More information about the taglib-devel mailing list