diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp index e7b8dc8a..cab8b33b 100644 --- a/taglib/riff/wav/wavfile.cpp +++ b/taglib/riff/wav/wavfile.cpp @@ -106,6 +106,17 @@ RIFF::Info::Tag *RIFF::WAV::File::InfoTag() const return d->tag.access(InfoIndex, false); } +void RIFF::WAV::File::strip(TagTypes tags) +{ + removeTagChunks(tags); + + if(tags & ID3v2) + d->tag.set(ID3v2Index, new ID3v2::Tag()); + + if(tags & Info) + d->tag.set(InfoIndex, new RIFF::Info::Tag()); +} + PropertyMap RIFF::WAV::File::properties() const { return tag()->properties(); @@ -146,28 +157,20 @@ bool RIFF::WAV::File::save(TagTypes tags, bool stripOthers, int id3v2Version) if(stripOthers) strip(static_cast(AllTags & ~tags)); - const ID3v2::Tag *id3v2tag = d->tag.access(ID3v2Index, false); if(tags & ID3v2) { - if(d->hasID3v2) { - removeChunk(d->tagChunkID); - d->hasID3v2 = false; - } + removeTagChunks(ID3v2); - if(!id3v2tag->isEmpty()) { - setChunkData(d->tagChunkID, id3v2tag->render(id3v2Version)); + if(ID3v2Tag() && !ID3v2Tag()->isEmpty()) { + setChunkData(d->tagChunkID, ID3v2Tag()->render(id3v2Version)); d->hasID3v2 = true; } } - const Info::Tag *infotag = d->tag.access(InfoIndex, false); if(tags & Info) { - if(d->hasInfo) { - removeChunk(findInfoTagChunk()); - d->hasInfo = false; - } + removeTagChunks(Info); - if(!infotag->isEmpty()) { - setChunkData("LIST", infotag->render(), true); + if(InfoTag() && !InfoTag()->isEmpty()) { + setChunkData("LIST", InfoTag()->render(), true); d->hasInfo = true; } } @@ -227,29 +230,21 @@ void RIFF::WAV::File::read(bool readProperties) d->properties = new Properties(this, Properties::Average); } -void RIFF::WAV::File::strip(TagTypes tags) +void RIFF::WAV::File::removeTagChunks(TagTypes tags) { - if(tags & ID3v2) { - removeChunk(d->tagChunkID); + if((tags & ID3v2) && d->hasID3v2) { + removeChunk("ID3 "); + removeChunk("id3 "); + d->hasID3v2 = false; } - if(tags & Info){ - TagLib::uint chunkId = findInfoTagChunk(); - if(chunkId != TagLib::uint(-1)) { - removeChunk(chunkId); - d->hasInfo = false; + if((tags & Info) && d->hasInfo) { + for(int i = static_cast(chunkCount()) - 1; i >= 0; --i) { + if(chunkName(i) == "LIST" && chunkData(i).startsWith("INFO")) + removeChunk(i); } + + d->hasInfo = false; } } - -TagLib::uint RIFF::WAV::File::findInfoTagChunk() -{ - for(uint i = 0; i < chunkCount(); ++i) { - if(chunkName(i) == "LIST" && chunkData(i).startsWith("INFO")) { - return i; - } - } - - return TagLib::uint(-1); -} diff --git a/taglib/riff/wav/wavfile.h b/taglib/riff/wav/wavfile.h index 129d9537..80f17a85 100644 --- a/taglib/riff/wav/wavfile.h +++ b/taglib/riff/wav/wavfile.h @@ -125,6 +125,15 @@ namespace TagLib { */ Info::Tag *InfoTag() const; + /*! + * This will strip the tags that match the OR-ed together TagTypes from the + * file. By default it strips all tags. It returns true if the tags are + * successfully stripped. + * + * \note This will update the file immediately. + */ + void strip(TagTypes tags = AllTags); + /*! * Implements the unified property interface -- export function. * This method forwards to ID3v2::Tag::properties(). @@ -171,13 +180,7 @@ namespace TagLib { File &operator=(const File &); void read(bool readProperties); - - void strip(TagTypes tags); - - /*! - * Returns the index of the chunk that its name is "LIST" and list type is "INFO". - */ - uint findInfoTagChunk(); + void removeTagChunks(TagTypes tags); friend class Properties;