mpeg/xingheader.h
mpeg/id3v1/id3v1tag.h
mpeg/id3v1/id3v1genres.h
+ mpeg/id3v2/id3v2.h
mpeg/id3v2/id3v2extendedheader.h
mpeg/id3v2/id3v2frame.h
mpeg/id3v2/id3v2header.h
#include "tbytevector.h"
#include "taglib_export.h"
+#include "id3v2.h"
namespace TagLib {
ByteVector ID3v2::Tag::render() const
{
- return render(4);
+ return render(ID3v2::v4);
}
void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
}
ByteVector ID3v2::Tag::render(int version) const
+{
+ return render(version == 3 ? v3 : v4);
+}
+
+ByteVector ID3v2::Tag::render(Version version) const
{
// We need to render the "tag data" first so that we have to correct size to
// render in the tag's header. The "tag data" -- everything that is included
// in ID3v2::Header::tagSize() -- includes the extended header, frames and
// padding, but does not include the tag's header or footer.
- if(version != 3 && version != 4) {
- debug("Unknown ID3v2 version, using ID3v2.4");
- version = 4;
- }
-
// TODO: Render the extended header.
// Downgrade the frames that ID3v2.3 doesn't support.
newFrames.setAutoDelete(true);
FrameList frameList;
- if(version == 4) {
+ if(version == v4) {
frameList = d->frameList;
}
else {
// Loop through the frames rendering them and adding them to the tagData.
for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) {
- (*it)->header()->setVersion(version);
+ (*it)->header()->setVersion(version == v3 ? 3 : 4);
if((*it)->header()->frameID().size() != 4) {
debug("An ID3v2 frame of unsupported or unknown type \'"
+ String((*it)->header()->frameID()) + "\' has been discarded");
#include "tmap.h"
#include "taglib_export.h"
+#include "id3v2.h"
#include "id3v2framefactory.h"
namespace TagLib {
class File;
- //! An ID3v2 implementation
-
- /*!
- * This is a relatively complete and flexible framework for working with ID3v2
- * tags.
- *
- * \see ID3v2::Tag
- */
-
namespace ID3v2 {
class Header;
*/
ByteVector render() const;
+ /*!
+ * \deprecated
+ */
+ ByteVector render(int version) const;
+
/*!
* Render the tag back to binary data, suitable to be written to disk.
*
- * The \a version parameter specifies the version of the rendered
- * ID3v2 tag. It can be either 4 or 3.
+ * The \a version parameter specifies whether ID3v2.4 (default) or ID3v2.3
+ * should be used.
*/
- // BIC: combine with the above method
- ByteVector render(int version) const;
+ ByteVector render(Version version) const;
/*!
* Gets the current string handler that decides how the "Latin-1" data
}
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags)
+{
+ return save(tags,
+ stripOthers ? StripOthers : StripNone,
+ id3v2Version == 3 ? ID3v2::v3 : ID3v2::v4,
+ duplicateTags ? Duplicate : DoNotDuplicate);
+}
+
+bool MPEG::File::save(int tags, StripTags strip, ID3v2::Version version, DuplicateTags duplicate)
{
if(readOnly()) {
debug("MPEG::File::save() -- File is read only.");
// Create the tags if we've been asked to.
- if(duplicateTags) {
+ if(duplicate == Duplicate) {
// Copy the values from the tag that does exist into the new tag,
// except if the existing tag is to be stripped.
- if((tags & ID3v2) && ID3v1Tag() && !(stripOthers && !(tags & ID3v1)))
+ if((tags & ID3v2) && ID3v1Tag() && !(strip == StripOthers && !(tags & ID3v1)))
Tag::duplicate(ID3v1Tag(), ID3v2Tag(true), false);
- if((tags & ID3v1) && d->tag[ID3v2Index] && !(stripOthers && !(tags & ID3v2)))
+ if((tags & ID3v1) && d->tag[ID3v2Index] && !(strip == StripOthers && !(tags & ID3v2)))
Tag::duplicate(ID3v2Tag(), ID3v1Tag(true), false);
}
// Remove all the tags not going to be saved.
- if(stripOthers)
- strip(~tags, false);
+ if(strip == StripOthers)
+ File::strip(~tags, false);
if(ID3v2 & tags) {
if(d->ID3v2Location < 0)
d->ID3v2Location = 0;
- const ByteVector data = ID3v2Tag()->render(id3v2Version);
+ const ByteVector data = ID3v2Tag()->render(version);
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
if(d->APELocation >= 0)
// ID3v2 tag is empty. Remove the old one.
- strip(ID3v2, false);
+ File::strip(ID3v2, false);
}
}
// ID3v1 tag is empty. Remove the old one.
- strip(ID3v1, false);
+ File::strip(ID3v1, false);
}
}
// APE tag is empty. Remove the old one.
- strip(APE, false);
+ File::strip(APE, false);
}
}
#include "mpegproperties.h"
+#include "id3v2.h"
+
namespace TagLib {
namespace ID3v2 { class Tag; class FrameFactory; }
bool save(int tags);
/*!
- * Save the file. This will attempt to save all of the tag types that are
- * specified by OR-ing together TagTypes values. The save() method above
- * uses AllTags. This returns true if saving was successful.
- *
- * If \a stripOthers is true this strips all tags not included in the mask,
- * but does not modify them in memory, so later calls to save() which make
- * use of these tags will remain valid. This also strips empty tags.
+ * \deprecated
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers);
/*!
- * Save the file. This will attempt to save all of the tag types that are
- * specified by OR-ing together TagTypes values. The save() method above
- * uses AllTags. This returns true if saving was successful.
- *
- * If \a stripOthers is true this strips all tags not included in the mask,
- * but does not modify them in memory, so later calls to save() which make
- * use of these tags will remain valid. This also strips empty tags.
- *
- * The \a id3v2Version parameter specifies the version of the saved
- * ID3v2 tag. It can be either 4 or 3.
+ * \deprecated
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers, int id3v2Version);
+ /*!
+ * \deprecated
+ */
+ // BIC: combine with the above method
+ bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
+
/*!
* Save the file. This will attempt to save all of the tag types that are
- * specified by OR-ing together TagTypes values. The save() method above
- * uses AllTags. This returns true if saving was successful.
+ * specified by OR-ing together TagTypes values.
*
- * If \a stripOthers is true this strips all tags not included in the mask,
- * but does not modify them in memory, so later calls to save() which make
- * use of these tags will remain valid. This also strips empty tags.
+ * \a strip can be set to strip all tags except those in \a tags. Those
+ * tags will not be modified in memory, and thus remain valid.
*
- * The \a id3v2Version parameter specifies the version of the saved
- * ID3v2 tag. It can be either 4 or 3.
+ * \a version specifies the ID3v2 version to be used for writing tags. By
+ * default, the latest standard, ID3v2.4 is used.
*
- * If \a duplicateTags is true and at least one tag -- ID3v1 or ID3v2 --
- * exists this will duplicate its content into the other tag.
+ * If \a duplicate is set to DuplicateTags and at least one tag -- ID3v1
+ * or ID3v2 -- exists this will duplicate its content into the other tag.
*/
- // BIC: combine with the above method
- bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
+ bool save(int tags, StripTags strip,
+ ID3v2::Version version = ID3v2::v4,
+ DuplicateTags duplicate = Duplicate);
/*!
* Returns a pointer to the ID3v2 tag of the file.
End
};
+ /*!
+ * Specify which tags to strip either explicitly, or on save.
+ */
+ enum StripTags {
+ StripNone, //<! Don't strip any tags
+ StripAll, //<! Strip all tags
+ StripOthers //<! Strip all tags not explicitly referenced in method call
+ };
+
+ /*!
+ * Used to specify if when saving files, if values between different tag
+ * types should be syncronized.
+ */
+ enum DuplicateTags {
+ Duplicate, //<! Syncronize values between different tag types
+ DoNotDuplicate //<! Do not syncronize values between different tag types
+ };
+
/*!
* Destroys this File instance.
*/
MPEG::File file(newname.c_str());
file.ID3v2Tag(true)->addFrame(f);
- file.save(MPEG::File::ID3v2, true, 3);
+ file.save(MPEG::File::ID3v2, File::StripOthers, ID3v2::v3);
CPPUNIT_ASSERT_EQUAL(true, file.hasID3v2Tag());
ByteVector data = f->render();
MPEG::File file(copy.fileName().c_str());
file.ID3v2Tag(true)->addFrame(f);
- file.save(MPEG::File::ID3v2, true, 3);
+ file.save(MPEG::File::ID3v2, File::StripOthers, ID3v2::v3);
CPPUNIT_ASSERT(file.hasID3v2Tag());
ByteVector data = f->render();
foo.ID3v2Tag()->addFrame(new ID3v2::TextIdentificationFrame("TSOT", String::Latin1));
foo.ID3v2Tag()->addFrame(new ID3v2::TextIdentificationFrame("TSST", String::Latin1));
foo.ID3v2Tag()->addFrame(new ID3v2::TextIdentificationFrame("TSOP", String::Latin1));
- foo.save(MPEG::File::AllTags, true, 3);
+ foo.save(MPEG::File::AllTags, File::StripOthers, ID3v2::v3);
}
{
MPEG::File bar(newname.c_str());
MPEG::File bar(newname.c_str());
bar.ID3v2Tag()->removeFrames("TPE1");
// Should strip ID3v1 here and not add old values to ID3v2 again
- bar.save(MPEG::File::ID3v2, true);
+ bar.save(MPEG::File::ID3v2, File::StripOthers);
}
MPEG::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
f.ID3v2Tag()->setArtist("Artist A");
- f.save(MPEG::File::ID3v2, true);
+ f.save(MPEG::File::ID3v2, File::StripOthers);
}
{
MPEG::File f(copy.fileName().c_str());
f.tag()->setTitle(xxx);
f.tag()->setArtist("Artist A");
- f.save(MPEG::File::AllTags, true, 4);
+ f.save(MPEG::File::AllTags, File::StripOthers, ID3v2::v4);
CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag());
}
{
f.tag()->setTitle(xxx);
f.tag()->setArtist("Artist A");
- f.save(MPEG::File::AllTags, true, 3);
+ f.save(MPEG::File::AllTags, File::StripOthers, ID3v2::v3);
CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag());
}
{
{
MPEG::File f(copy.fileName().c_str());
f.ID3v2Tag(true)->setTitle("");
- f.save(MPEG::File::ID3v2, false);
+ f.save(MPEG::File::ID3v2, File::StripNone);
}
{
MPEG::File f(copy.fileName().c_str());
{
MPEG::File f(copy.fileName().c_str());
f.ID3v1Tag(true)->setTitle("");
- f.save(MPEG::File::ID3v1, false);
+ f.save(MPEG::File::ID3v1, File::StripNone);
}
{
MPEG::File f(copy.fileName().c_str());
{
MPEG::File f(copy.fileName().c_str());
f.APETag(true)->setTitle("");
- f.save(MPEG::File::APE, false);
+ f.save(MPEG::File::APE, File::StripNone);
}
{
MPEG::File f(copy.fileName().c_str());