TagLib::ID3v2::Tag Class Reference

The main class in the ID3v2 implementation. More...

`#include <id3v2tag.h>`

Inheritance diagram for TagLib::ID3v2::Tag:
[legend]
Collaboration diagram for TagLib::ID3v2::Tag:
[legend]

## Public Member Functions

| Tag ()
| Tag (File *file, offset_t tagOffset, const FrameFactory *factory=FrameFactory::instance())
| ~Tag () override
| Tag (const Tag &)=delete
Tag & | operator= (const Tag &)=delete
String | title () const override
String | artist () const override
String | album () const override
String | comment () const override
String | genre () const override
unsigned int | year () const override
unsigned int | track () const override
void | setTitle (const String &s) override
void | setArtist (const String &s) override
void | setAlbum (const String &s) override
void | setComment (const String &s) override
void | setGenre (const String &s) override
void | setYear (unsigned int i) override
void | setTrack (unsigned int i) override
bool | isEmpty () const override
Header * | header () const
ExtendedHeader * | extendedHeader () const
const FrameListMap & | frameListMap () const
const FrameList & | frameList () const
const FrameList & | frameList (const ByteVector &frameID) const
void | addFrame (Frame *frame)
void | removeFrame (Frame *frame, bool del=true)
void | removeFrames (const ByteVector &id)
PropertyMap | properties () const override
void | removeUnsupportedProperties (const StringList &properties) override
PropertyMap | setProperties (const PropertyMap &) override
StringList | complexPropertyKeys () const override
List< VariantMap > | complexProperties (const String &key) const override
bool | setComplexProperties (const String &key, const List< VariantMap > &value) override
ByteVector | render () const
ByteVector | render (Version version) const
Public Member Functions inherited from TagLib::Tag
| Tag (const Tag &)=delete
Tag & | operator= (const Tag &)=delete

## Static Public Member Functions

static Latin1StringHandler const * | latin1StringHandler ()
static void | setLatin1StringHandler (const Latin1StringHandler *handler)
Static Public Member Functions inherited from TagLib::Tag
static void | duplicate (const Tag *source, Tag *target, bool overwrite=true)
static String | joinTagValues (const StringList &values)

## Protected Member Functions

void | read ()
void | parse (const ByteVector &origData)
void | setTextFrame (const ByteVector &id, const String &value)
void | downgradeFrames (FrameList *frames, FrameList *newFrames) const
Protected Member Functions inherited from TagLib::Tag
| Tag ()

## Detailed Description

The main class in the ID3v2 implementation.

This is the main class in the ID3v2 implementation. It serves two functions. The first, as is obvious from the public API, is to provide a container for the other ID3v2 related classes. In addition, through the read() and parse() protected methods, it provides the most basic level of parsing. In these methods the ID3v2 tag is extracted from the file and split into data components.

ID3v2 tags have several parts, TagLib attempts to provide an interface for them all. header() and extendedHeader() correspond to those data structures in the ID3v2 standard and the APIs for the classes that they return attempt to reflect this.

Also ID3v2 tags are built up from a list of frames, which have a header and a list of fields. TagLib provides two ways of accessing the list of frames that are in a given ID3v2 tag. The first is simply via the frameList() method. This is just a list of pointers to the frames. The second is a map from the frame type – i.e. "COMM" for comments – and a list of frames of that type. (In some cases ID3v2 allows for multiple frames of the same type, hence this being a map to a list rather than just a map to an individual frame.)

More information on the structure of frames can be found in the ID3v2::Frame class.

read() and parse() pass binary data to the other ID3v2 class structures, they do not handle parsing of flags or fields, for instance. Those are handled by similar functions within those classes.

Note
  All pointers to data structures within the tag will become invalid when the tag is destroyed.

Warning
  Dealing with the nasty details of ID3v2 is not for the faint of heart and should not be done without much meditation on the spec. It's rather long, but if you're planning on messing with this class and others that deal with the details of ID3v2 (rather than the nice, safe, abstract TagLib::Tag and friends), it's worth your time to familiarize yourself with said spec (which is distributed with the TagLib sources). TagLib tries to do most of the work, but with a little luck, you can still convince it to generate invalid ID3v2 tags. The APIs for ID3v2 assume a working knowledge of ID3v2 structure. You've been warned.

## Constructor & Destructor Documentation

## Tag() [1/3]

TagLib::ID3v2::Tag::Tag | ( |  | ) |

Constructs an empty ID3v2 tag.

Note
  You must create at least one frame for this tag to be valid.

Referenced by operator=(), and Tag().

## Tag() [2/3]

TagLib::ID3v2::Tag::Tag | ( | File * | file,
|  | offset_t | tagOffset,
|  | const FrameFactory * | factory = FrameFactory::instance() )

Constructs an ID3v2 tag read from file starting at tagOffset. factory specifies which FrameFactory will be used for the construction of new frames.

Note
  You should be able to ignore the factory parameter in almost all situations. You would want to specify your own FrameFactory subclass in the case that you are extending TagLib to support additional frame types, which would be incorporated into your factory.

See also
  FrameFactory

References TagLib::ID3v2::FrameFactory::instance().

## ~Tag()

TagLib::ID3v2::Tag::~Tag | ( |  | ) |

override virtual

Destroys this Tag instance.

Reimplemented from TagLib::Tag.

## Tag() [3/3]

TagLib::ID3v2::Tag::Tag | ( | const Tag & |  | ) |

delete

References Tag().

## Member Function Documentation

## addFrame()

void TagLib::ID3v2::Tag::addFrame | ( | Frame * | frame | ) |

Add a frame to the tag. At this point the tag takes ownership of the frame and will handle freeing its memory.

Note
  Using this method will invalidate any pointers on the list returned by frameList()

## album()

String TagLib::ID3v2::Tag::album | ( |  | ) | const

override virtual

Returns the album name; if no album name is present in the tag an empty string will be returned.

Implements TagLib::Tag.

## artist()

String TagLib::ID3v2::Tag::artist | ( |  | ) | const

override virtual

Returns the artist name; if no artist name is present in the tag an empty string will be returned.

Implements TagLib::Tag.

## comment()

String TagLib::ID3v2::Tag::comment | ( |  | ) | const

override virtual

Returns the track comment; if no comment is present in the tag an empty string will be returned.

Implements TagLib::Tag.

## complexProperties()

List< VariantMap > TagLib::ID3v2::Tag::complexProperties | ( | const String & | key | ) | const

override virtual

Get the complex properties for a given key. In order to be flexible for different metadata formats, the properties are represented as variant maps. Despite this dynamic nature, some degree of standardization should be achieved between formats:

- PICTURE
  - data: ByteVector with picture data
  - description: String with description
  - pictureType: String with type as specified for ID3v2, e.g. "Front Cover", "Back Cover", "Band"
  - mimeType: String with image format, e.g. "image/jpeg"
  - optionally more information found in the tag, such as "width", "height", "numColors", "colorDepth" int values in FLAC pictures
- GENERALOBJECT
  - data: ByteVector with object data
  - description: String with description
  - fileName: String with file name
  - mimeType: String with MIME type
  - this is currently only implemented for ID3v2 GEOB frames

Reimplemented from TagLib::Tag.

## complexPropertyKeys()

StringList TagLib::ID3v2::Tag::complexPropertyKeys | ( |  | ) | const

override virtual

Get the keys of complex properties, i.e. properties which cannot be represented simply by a string. Because such properties might be expensive to fetch, there are separate operations to get the available keys - which is expected to be cheap - and getting and setting the property values. The default implementation returns only an empty list. Reimplementations should provide "PICTURE" if embedded cover art is present, and optionally support other properties.

Reimplemented from TagLib::Tag.

## downgradeFrames()

void TagLib::ID3v2::Tag::downgradeFrames | ( | FrameList * | frames,
|  | FrameList * | newFrames ) const

protected

Downgrade frames from ID3v2.4 (used internally and by default) to ID3v2.3.

References TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE.

## extendedHeader()

ExtendedHeader * TagLib::ID3v2::Tag::extendedHeader | ( |  | ) | const

Returns a pointer to the tag's extended header or null if there is no extended header.

## frameList() [1/2]

const FrameList & TagLib::ID3v2::Tag::frameList | ( |  | ) | const

Returns a reference to the frame list. This is a FrameList of all of the frames in the tag in the order that they were parsed.

This can be useful if for example you want to iterate over the tag's frames in the order that they occur in the tag.

Warning
  You should not modify this data structure directly, instead use addFrame() and removeFrame().

## frameList() [2/2]

const FrameList & TagLib::ID3v2::Tag::frameList | ( | const ByteVector & | frameID | ) | const

Returns the frame list for frames with the id frameID or an empty list if there are no frames of that type. This is just a convenience and is equivalent to:

frameListMap()[frameID];
TagLib::ID3v2::Tag::frameListMap
const FrameListMap & frameListMap() const

See also
  frameListMap()

## frameListMap()

const FrameListMap & TagLib::ID3v2::Tag::frameListMap | ( |  | ) | const

Returns a reference to the frame list map. This is a FrameListMap of all of the frames in the tag.

This is the most convenient structure for accessing the tag's frames. Many frame types allow multiple instances of the same frame type so this is a map of lists. In most cases however there will only be a single frame of a certain type.

Let's say for instance that you wanted to access the frame for total beats per minute – the TBPM frame.

TagLib::MPEG::File f("foo.mp3");
// Check to make sure that it has an ID3v2 tag
if(f.ID3v2Tag()) {
// Get the list of frames for a specific frame type
TagLib::ID3v2::FrameList l = f.ID3v2Tag()->frameListMap()["TBPM"];
if(!l.isEmpty())
std::cout << l.front()->toString() << std::endl;
}
TagLib::List::front
const T & front() const
TagLib::List::isEmpty
bool isEmpty() const
TagLib::MPEG::File
An MPEG file class with some useful methods specific to MPEG.
Definition mpegfile.h:54
TagLib::ID3v2::FrameList
List< Frame * > FrameList
Definition id3v2tag.h:48

Warning
  You should not modify this data structure directly, instead use addFrame() and removeFrame().

See also
  frameList()

## genre()

String TagLib::ID3v2::Tag::genre | ( |  | ) | const

override virtual

Returns the genre name; if no genre is present in the tag an empty string will be returned.

Implements TagLib::Tag.

## header()

Header * TagLib::ID3v2::Tag::header | ( |  | ) | const

Returns a pointer to the tag's header.

## isEmpty()

bool TagLib::ID3v2::Tag::isEmpty | ( |  | ) | const

override virtual

Returns `true` if the tag does not contain any data. This should be reimplemented in subclasses that provide more than the basic tagging abilities in this class.

Reimplemented from TagLib::Tag.

## latin1StringHandler()

Latin1StringHandler const * TagLib::ID3v2::Tag::latin1StringHandler | ( |  | ) |

static

Gets the current string handler that decides how the "Latin-1" data will be converted to and from binary data.

See also
  Latin1StringHandler

## operator=()

Tag & TagLib::ID3v2::Tag::operator= | ( | const Tag & |  | ) |

delete

References Tag().

## parse()

void TagLib::ID3v2::Tag::parse | ( | const ByteVector & | origData | ) |

protected

This is called by read to parse the body of the tag. It determines if an extended header exists and adds frames to the FrameListMap.

## properties()

PropertyMap TagLib::ID3v2::Tag::properties | ( |  | ) | const

override virtual

Implements the unified property interface – export function. This function does some work to translate the hard-specified ID3v2 frame types into a free-form string-to-stringlist PropertyMap:

- if ID3v2 frame ID is known by Frame::frameIDToKey(), the returned key is used
- if the frame ID is "TXXX" (user text frame), the description() is used as key
- if the frame ID is "WXXX" (user url frame),
  - if the description is empty or "URL", the key "URL" is used
  - otherwise, the key "URL:<description>" is used;
- if the frame ID is "COMM" (comments frame),
  - if the description is empty or "COMMENT", the key "COMMENT" is used
  - otherwise, the key "COMMENT:<description>" is used;
- if the frame ID is "USLT" (unsynchronized lyrics),
  - if the description is empty or "LYRICS", the key "LYRICS" is used
  - otherwise, the key "LYRICS:<description>" is used;
- if the frame ID is "TIPL" (involved peoples list), and if all the roles defined in the frame are known in TextIdentificationFrame::involvedPeopleMap(), then "<role>=<name>" will be contained in the returned object for each
- if the frame ID is "TMCL" (musician credit list), then "PERFORMER:<instrument>=<name>" will be contained in the returned PropertyMap for each defined musician In any other case, the unsupportedData() of the returned object will contain the frame's ID and, in case of a frame ID which is allowed to appear more than once, the description, separated by a "/".

Reimplemented from TagLib::Tag.

Referenced by removeUnsupportedProperties().

## read()

void TagLib::ID3v2::Tag::read | ( |  | ) |

protected

Reads data from the file specified in the constructor. It does basic parsing of the data in the largest chunks. It partitions the tag into the Header, the body of the tag (which contains the ExtendedHeader and frames) and Footer.

## removeFrame()

void TagLib::ID3v2::Tag::removeFrame | ( | Frame * | frame,
|  | bool | del = true )

Remove a frame from the tag. If del is `true` the frame's memory will be freed; if it is `false`, it must be deleted by the user.

Note
  Using this method will invalidate any pointers on the list returned by frameList()

## removeFrames()

void TagLib::ID3v2::Tag::removeFrames | ( | const ByteVector & | id | ) |

Remove all frames of type id from the tag and free their memory.

Note
  Using this method will invalidate any pointers on the list returned by frameList()

## removeUnsupportedProperties()

void TagLib::ID3v2::Tag::removeUnsupportedProperties | ( | const StringList & | properties | ) |

override virtual

Removes unsupported frames given by properties. The elements of properties must be taken from properties().unsupportedData(); they are of one of the following forms:

- a four-character frame ID, if the ID3 specification allows only one frame with that ID (thus, the frame is uniquely determined)
- frameID + "/" + description(), when the ID is one of "TXXX", "WXXX", "COMM", or "USLT",
- "UNKNOWN/" + frameID, for frames that could not be parsed by TagLib. In that case, all unknown frames with the given ID will be removed.

Reimplemented from TagLib::Tag.

References properties().

## render() [1/2]

ByteVector TagLib::ID3v2::Tag::render | ( |  | ) | const

Render the tag back to binary data, suitable to be written to disk.

## render() [2/2]

ByteVector TagLib::ID3v2::Tag::render | ( | Version | version | ) | const

Render the tag back to binary data, suitable to be written to disk.

The version parameter specifies whether ID3v2.4 (default) or ID3v2.3 should be used.

## setAlbum()

void TagLib::ID3v2::Tag::setAlbum | ( | const String & | s | ) |

override virtual

Sets the album to s. If s is an empty string then this value will be cleared.

Implements TagLib::Tag.

## setArtist()

void TagLib::ID3v2::Tag::setArtist | ( | const String & | s | ) |

override virtual

Sets the artist to s. If s is an empty string then this value will be cleared.

Implements TagLib::Tag.

## setComment()

void TagLib::ID3v2::Tag::setComment | ( | const String & | s | ) |

override virtual

Sets the comment to s. If s is an empty string then this value will be cleared.

Implements TagLib::Tag.

## setComplexProperties()

bool TagLib::ID3v2::Tag::setComplexProperties | ( | const String & | key,
|  | const List< VariantMap > & | value )

override virtual

Set all complex properties for a given key using variant maps as value with the same format as returned by complexProperties(). An empty list as value removes all complex properties for key.

Reimplemented from TagLib::Tag.

## setGenre()

void TagLib::ID3v2::Tag::setGenre | ( | const String & | s | ) |

override virtual

Sets the genre to s. If s is an empty string then this value will be cleared. For tag formats that use a fixed set of genres, the appropriate value will be selected based on a string comparison. A list of available genres for those formats should be available in that type's implementation.

Implements TagLib::Tag.

## setLatin1StringHandler()

void TagLib::ID3v2::Tag::setLatin1StringHandler | ( | const Latin1StringHandler * | handler | ) |

static

Sets the string handler that decides how the "Latin-1" data will be converted to and from binary data. If the parameter handler is null, the previous handler is released and default ISO-8859-1 handler is restored.

Note
  The caller is responsible for deleting the previous handler as needed after it is released.

See also
  Latin1StringHandler

## setProperties()

PropertyMap TagLib::ID3v2::Tag::setProperties | ( | const PropertyMap & |  | ) |

override virtual

Implements the unified property interface – import function. See the comments in properties().

Reimplemented from TagLib::Tag.

## setTextFrame()

void TagLib::ID3v2::Tag::setTextFrame | ( | const ByteVector & | id,
|  | const String & | value )

protected

Sets the value of the text frame with the Frame ID id to value. If the frame does not exist, it is created.

## setTitle()

void TagLib::ID3v2::Tag::setTitle | ( | const String & | s | ) |

override virtual

Sets the title to s. If s is an empty string then this value will be cleared.

Implements TagLib::Tag.

## setTrack()

void TagLib::ID3v2::Tag::setTrack | ( | unsigned int | i | ) |

override virtual

Sets the track to i. If s is 0 then this value will be cleared.

Implements TagLib::Tag.

## setYear()

void TagLib::ID3v2::Tag::setYear | ( | unsigned int | i | ) |

override virtual

Sets the year to i. If s is 0 then this value will be cleared.

Implements TagLib::Tag.

## title()

String TagLib::ID3v2::Tag::title | ( |  | ) | const

override virtual

Returns the track name; if no track name is present in the tag an empty string will be returned.

Implements TagLib::Tag.

## track()

unsigned int TagLib::ID3v2::Tag::track | ( |  | ) | const

override virtual

Returns the track number; if there is no track number set, this will return 0.

Implements TagLib::Tag.

## year()

unsigned int TagLib::ID3v2::Tag::year | ( |  | ) | const

override virtual

Returns the year; if there is no year set, this will return 0.

Implements TagLib::Tag.

The documentation for this class was generated from the following file:

- id3v2tag.h