--- /dev/null
+/***************************************************************************
+ copyright : (C) 2002 - 2008 by Scott Wheeler
+ email : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#include <tbytevectorlist.h>
+#include <tpropertymap.h>
+#include <tdebug.h>
+
+#include "id3v2tag.h"
+#include "uniquefileidentifierframe.h"
+
+using namespace TagLib;
+using namespace ID3v2;
+
+class UniqueFileIdentifierFrame::UniqueFileIdentifierFramePrivate
+{
+public:
+ String owner;
+ ByteVector identifier;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data) :
+ ID3v2::Frame(data)
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ setData(data);
+}
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const String &owner, const ByteVector &id) :
+ ID3v2::Frame("UFID")
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ d->owner = owner;
+ d->identifier = id;
+}
+
+UniqueFileIdentifierFrame::~UniqueFileIdentifierFrame()
+{
+ delete d;
+}
+
+String UniqueFileIdentifierFrame::owner() const
+{
+ return d->owner;
+}
+
+ByteVector UniqueFileIdentifierFrame::identifier() const
+{
+ return d->identifier;
+}
+
+void UniqueFileIdentifierFrame::setOwner(const String &s)
+{
+ d->owner = s;
+}
+
+void UniqueFileIdentifierFrame::setIdentifier(const ByteVector &v)
+{
+ d->identifier = v;
+}
+
+String UniqueFileIdentifierFrame::toString() const
+{
+ return String::null;
+}
+
+PropertyMap UniqueFileIdentifierFrame::asProperties() const
+{
+ PropertyMap map;
+ if(d->owner == "http://musicbrainz.org") {
+ map.insert("MUSICBRAINZ_TRACKID", String(d->identifier));
+ }
+ else {
+ map.unsupportedData().append(frameID() + String("/") + d->owner);
+ }
+ return map;
+}
+
+UniqueFileIdentifierFrame *UniqueFileIdentifierFrame::findByOwner(const ID3v2::Tag *tag, const String &o) // static
+{
+ ID3v2::FrameList comments = tag->frameList("UFID");
+
+ for(ID3v2::FrameList::ConstIterator it = comments.begin();
+ it != comments.end();
+ ++it)
+ {
+ UniqueFileIdentifierFrame *frame = dynamic_cast<UniqueFileIdentifierFrame *>(*it);
+ if(frame && frame->owner() == o)
+ return frame;
+ }
+
+ return 0;
+}
+
+void UniqueFileIdentifierFrame::parseFields(const ByteVector &data)
+{
+ if(data.size() < 1) {
+ debug("An UFID frame must contain at least 1 byte.");
+ return;
+ }
+
+ int pos = 0;
+ d->owner = readStringField(data, String::Latin1, &pos);
+ d->identifier = data.mid(pos);
+}
+
+ByteVector UniqueFileIdentifierFrame::renderFields() const
+{
+ ByteVector data;
+
+ data.append(d->owner.data(String::Latin1));
+ data.append(char(0));
+ data.append(d->identifier);
+
+ return data;
+}
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data, Header *h) :
+ Frame(h)
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ parseFields(fieldData(data));
+}
--- /dev/null
+/***************************************************************************
+ copyright : (C) 2002 - 2008 by Scott Wheeler
+ email : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#ifndef TAGLIB_CHAPTERFRAME
+#define TAGLIB_CHAPTERFRAME
+
+#include "id3v2frame.h"
+
+namespace TagLib {
+
+ namespace ID3v2 {
+
+ /*!
+ * This is an implementation of ID3v2 chapter frames. The purpose of this
+ * frame is to describe a single chapter within an audio file.
+ */
+
+ //! An implementation of ID3v2 chapter frames
+
+ class TAGLIB_EXPORT ChapterFrame : public ID3v2::Frame
+ {
+ friend class FrameFactory;
+
+ public:
+ /*!
+ * Creates a chapter frame based on \a data.
+ */
+ ChapterFrame(const ByteVector &data);
+
+ /*!
+ * Creates a chapter frame with the element ID \a eID,
+ * start time \a sT, end time \a eT, start offset \a sO
+ * and end offset \a eO.
+ */
+ ChapterFrame(const ByteVector &eID, const int &sT, const int &eT, const int &sO, const int &eO);
+
+ /*!
+ * Destroys the frame.
+ */
+ ~ChapterFrame();
+
+ /*!
+ * Returns the elementID of the frame. Element ID
+ * is a null terminated string, however it's not human-readable.
+ *
+ * \see setElementID()
+ */
+ ByteVector elementID() const;
+
+ /*!
+ * Returns time of chapter's start (in miliseconds).
+ *
+ * \see setStartTime()
+ */
+ uint startTime() const;
+
+ /*!
+ * Returns time of chapter's end (in miliseconds).
+ *
+ * \see setEndTime()
+ */
+ uint endTime() const;
+
+ /*!
+ * Returns zero based byte offset (count of bytes from the beginning
+ * of the audio file) of chapter's start.
+ *
+ * \see setStartOffset()
+ */
+ uint startOffset() const;
+
+ /*!
+ * Returns zero based byte offset (count of bytes from the beginning
+ * of the audio file) of chapter's end.
+ *
+ * \see setEndOffset()
+ */
+ uint endOffset() const;
+
+ /*!
+ * Sets the elementID of the frame to \a eID.
+ *
+ * \warning Element ID must be null terminated.
+ * \see elementID()
+ */
+ void setElementID(const ByteVector &eID);
+
+ /*!
+ * Sets time of chapter's start (in miliseconds) to \a sT.
+ *
+ * \see startTime()
+ */
+ void setStartTime(const uint &sT);
+
+ /*!
+ * Sets time of chapter's end (in miliseconds) to \a eT.
+ *
+ * \see endTime()
+ */
+ void setEndTime(const uint &eT);
+
+ /*!
+ * Sets zero based byte offset (count of bytes from the beginning
+ * of the audio file) of chapter's start to \a sO.
+ *
+ * \see startOffset()
+ */
+ void setStartOffset(const uint &sO);
+
+ /*!
+ * Sets zero based byte offset (count of bytes from the beginning
+ * of the audio file) of chapter's end to \a eO.
+ *
+ * \see endOffset()
+ */
+ void endOffset(const uint &eO);
+
+ virtual String toString() const;
+
+ PropertyMap asProperties() const;
+
+ /*!
+ * CHAP frames each have a unique element ID. This searches for a CHAP
+ * frame with the element ID \a eID and returns a pointer to it.
+ *
+ * \see elementID()
+ */
+ static ChapterFrame *findByElementID(const Tag *tag, const ByteVector &eID);
+
+ protected:
+ virtual void parseFields(const ByteVector &data);
+ virtual ByteVector renderFields() const;
+
+ private:
+ ChapterFrame(const ChapterFrame &);
+ ChapterFrame &operator=(const ChapterFrame &);
+
+ ChapterFrame(const ByteVector &data, Header *h);
+
+ class ChapterFramePrivate;
+ ChapterFramePrivate *d;
+ };
+ }
+}
+
+#endif
--- /dev/null
+/***************************************************************************
+ copyright : (C) 2002 - 2008 by Scott Wheeler
+ email : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#include <tbytevectorlist.h>
+#include <tpropertymap.h>
+#include <tdebug.h>
+
+#include "id3v2tag.h"
+#include "uniquefileidentifierframe.h"
+
+using namespace TagLib;
+using namespace ID3v2;
+
+class UniqueFileIdentifierFrame::UniqueFileIdentifierFramePrivate
+{
+public:
+ String owner;
+ ByteVector identifier;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data) :
+ ID3v2::Frame(data)
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ setData(data);
+}
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const String &owner, const ByteVector &id) :
+ ID3v2::Frame("UFID")
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ d->owner = owner;
+ d->identifier = id;
+}
+
+UniqueFileIdentifierFrame::~UniqueFileIdentifierFrame()
+{
+ delete d;
+}
+
+String UniqueFileIdentifierFrame::owner() const
+{
+ return d->owner;
+}
+
+ByteVector UniqueFileIdentifierFrame::identifier() const
+{
+ return d->identifier;
+}
+
+void UniqueFileIdentifierFrame::setOwner(const String &s)
+{
+ d->owner = s;
+}
+
+void UniqueFileIdentifierFrame::setIdentifier(const ByteVector &v)
+{
+ d->identifier = v;
+}
+
+String UniqueFileIdentifierFrame::toString() const
+{
+ return String::null;
+}
+
+PropertyMap UniqueFileIdentifierFrame::asProperties() const
+{
+ PropertyMap map;
+ if(d->owner == "http://musicbrainz.org") {
+ map.insert("MUSICBRAINZ_TRACKID", String(d->identifier));
+ }
+ else {
+ map.unsupportedData().append(frameID() + String("/") + d->owner);
+ }
+ return map;
+}
+
+UniqueFileIdentifierFrame *UniqueFileIdentifierFrame::findByOwner(const ID3v2::Tag *tag, const String &o) // static
+{
+ ID3v2::FrameList comments = tag->frameList("UFID");
+
+ for(ID3v2::FrameList::ConstIterator it = comments.begin();
+ it != comments.end();
+ ++it)
+ {
+ UniqueFileIdentifierFrame *frame = dynamic_cast<UniqueFileIdentifierFrame *>(*it);
+ if(frame && frame->owner() == o)
+ return frame;
+ }
+
+ return 0;
+}
+
+void UniqueFileIdentifierFrame::parseFields(const ByteVector &data)
+{
+ if(data.size() < 1) {
+ debug("An UFID frame must contain at least 1 byte.");
+ return;
+ }
+
+ int pos = 0;
+ d->owner = readStringField(data, String::Latin1, &pos);
+ d->identifier = data.mid(pos);
+}
+
+ByteVector UniqueFileIdentifierFrame::renderFields() const
+{
+ ByteVector data;
+
+ data.append(d->owner.data(String::Latin1));
+ data.append(char(0));
+ data.append(d->identifier);
+
+ return data;
+}
+
+UniqueFileIdentifierFrame::UniqueFileIdentifierFrame(const ByteVector &data, Header *h) :
+ Frame(h)
+{
+ d = new UniqueFileIdentifierFramePrivate;
+ parseFields(fieldData(data));
+}
--- /dev/null
+/***************************************************************************
+ copyright : (C) 2002 - 2008 by Scott Wheeler
+ email : wheeler@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * This library is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License version *
+ * 2.1 as published by the Free Software Foundation. *
+ * *
+ * This library is distributed in the hope that it will be useful, but *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
+ * 02110-1301 USA *
+ * *
+ * Alternatively, this file is available under the Mozilla Public *
+ * License Version 1.1. You may obtain a copy of the License at *
+ * http://www.mozilla.org/MPL/ *
+ ***************************************************************************/
+
+#ifndef TAGLIB_TABLEOFCONTENTSFRAME
+#define TAGLIB_TABLEOFCONTENTSFRAME
+
+#include "id3v2frame.h"
+
+namespace TagLib {
+
+ namespace ID3v2 {
+
+ /*!
+ * This is an implementation of ID3v2 table of contents frames. Purpose
+ * of this frame is to allow a table of contents to be defined.
+ */
+
+ //! An implementation of ID3v2 table of contents frames
+
+ class TAGLIB_EXPORT TableOfContentsFrame : public ID3v2::Frame
+ {
+ friend class FrameFactory;
+
+ public:
+ /*!
+ * Creates a table of contents frame based on \a data.
+ */
+ TableOfContentsFrame(const ByteVector &data);
+
+ /*!
+ * Creates a table of contents frame with the element ID \a eID and
+ * the child elements \a ch.
+ */
+ UniqueFileIdentifierFrame(const ByteVector &eID, const List<ByteVector> &ch);
+
+ /*!
+ * Destroys the frame.
+ */
+ ~UniqueFileIdentifierFrame();
+
+ /*!
+ * Returns the elementID of the frame. Element ID
+ * is a null terminated string, however it's not human-readable.
+ *
+ * \see setElementID()
+ */
+ ByteVector elementID() const;
+
+ /*!
+ * Returns true, if the frame is top-level (doen't have
+ * any parent CTOC frame).
+ *
+ * \see setIsTopLevel()
+ */
+ bool isTopLevel() const;
+
+ /*!
+ * Returns true, if the child elements list entries
+ * are ordered.
+ *
+ * \see setIsOrdered()
+ */
+ bool isOrdered() const;
+
+ /*!
+ * Returns count of child elements of the frame. It allways
+ * corresponds to size of child elements list.
+ *
+ * \note Return type should be uint8_t.
+ * \see childElements()
+ */
+ unsigned char entryCount() const;
+
+ /*!
+ * Returns list of child elements of the frame.
+ *
+ * \see setChildElements()
+ */
+ List<ByteVector> childElements() const;
+
+ /*!
+ * Sets the elementID of the frame to \a eID.
+ *
+ * \warning Element ID must be null terminated.
+ * \see elementID()
+ */
+ void setElementID(const ByteVector &eID);
+
+ /*!
+ * Sets, if the frame is top-level (doen't have
+ * any parent CTOC frame).
+ *
+ * \see isTopLevel()
+ */
+ void setIsTopLevel(const bool &t);
+
+ /*!
+ * Sets, if the child elements list entries
+ * are ordered.
+ *
+ * \see isOrdered()
+ */
+ void setIsOrdered(const bool &o);
+
+ /*!
+ * Sets list of child elements of the frame to \a l.
+ *
+ * \see childElements()
+ */
+ void setChildElements(const List<ByteVector> &l);
+
+ virtual String toString() const;
+
+ PropertyMap asProperties() const;
+
+ /*!
+ * CTOC frames each have a unique element ID. This searches for a CTOC
+ * frame with the element ID \a eID and returns a pointer to it.
+ *
+ * \see elementID()
+ */
+ static UniqueFileIdentifierFrame *findByElementID(const Tag *tag, const ByteVector &eID);
+
+ protected:
+ virtual void parseFields(const ByteVector &data);
+ virtual ByteVector renderFields() const;
+
+ private:
+ TableOfContentsFrame(const TableOfContentsFrame &);
+ TableOfContentsFrame &operator=(const TableOfContentsFrame &);
+
+ TableOfContentsFrame(const ByteVector &data, Header *h);
+
+ class TableOfContentsFramePrivate;
+ TableOfContentsFramePrivate *d;
+ };
+ }
+}
+
+#endif