1 /***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
26 #ifndef TAGLIB_ID3V1TAG_H
27 #define TAGLIB_ID3V1TAG_H
30 #include "tbytevector.h"
31 #include "taglib_export.h"
37 //! An ID3v1 implementation
41 //! A abstraction for the string to data encoding in ID3v1 tags.
44 * ID3v1 should in theory always contain ISO-8859-1 (Latin1) data. In
45 * practice it does not. TagLib by default only supports ISO-8859-1 data
48 * However by subclassing this class and reimplementing parse() and render()
49 * and setting your reimplementation as the default with
50 * ID3v1::Tag::setStringHandler() you can define how you would like these
51 * transformations to be done.
53 * \warning It is advisable <b>not</b> to write non-ISO-8859-1 data to ID3v1
54 * tags. Please consider disabling the writing of ID3v1 tags in the case
55 * that the data is not ISO-8859-1.
57 * \see ID3v1::Tag::setStringHandler()
60 class TAGLIB_EXPORT StringHandler
62 TAGLIB_IGNORE_MISSING_DESTRUCTOR
64 // BIC: Add virtual destructor.
67 * Decode a string from \a data. The default implementation assumes that
68 * \a data is an ISO-8859-1 (Latin1) character array.
70 virtual String parse(const ByteVector &data) const;
73 * Encode a ByteVector with the data from \a s. The default implementation
74 * assumes that \a s is an ISO-8859-1 (Latin1) string. If the string is
75 * does not conform to ISO-8859-1, no value is written.
77 * \warning It is recommended that you <b>not</b> override this method, but
78 * instead do not write an ID3v1 tag in the case that the data is not
81 virtual ByteVector render(const String &s) const;
84 //! The main class in the ID3v1 implementation
87 * This is an implementation of the ID3v1 format. ID3v1 is both the simplist
88 * and most common of tag formats but is rather limited. Because of its
89 * pervasiveness and the way that applications have been written around the
90 * fields that it provides, the generic TagLib::Tag API is a mirror of what is
93 * ID3v1 tags should generally only contain Latin1 information. However because
94 * many applications do not follow this rule there is now support for overriding
95 * the ID3v1 string handling using the ID3v1::StringHandler class. Please see
96 * the documentation for that class for more information.
100 * \note Most fields are truncated to a maximum of 28-30 bytes. The
101 * truncation happens automatically when the tag is rendered.
104 class TAGLIB_EXPORT Tag : public TagLib::Tag
108 * Create an ID3v1 tag with default values.
113 * Create an ID3v1 tag and parse the data in \a file starting at
116 Tag(File *file, long tagOffset);
119 * Destroys this Tag instance.
124 * Renders the in memory values to a ByteVector suitable for writing to
127 ByteVector render() const;
130 * Returns the string "TAG" suitable for usage in locating the tag in a
133 static ByteVector fileIdentifier();
135 // Reimplementations.
137 virtual String title() const;
138 virtual String artist() const;
139 virtual String album() const;
140 virtual String comment() const;
141 virtual String genre() const;
142 virtual uint year() const;
143 virtual uint track() const;
145 virtual void setTitle(const String &s);
146 virtual void setArtist(const String &s);
147 virtual void setAlbum(const String &s);
148 virtual void setComment(const String &s);
149 virtual void setGenre(const String &s);
150 virtual void setYear(uint i);
151 virtual void setTrack(uint i);
154 * Sets the string handler that decides how the ID3v1 data will be
155 * converted to and from binary data.
159 static void setStringHandler(const StringHandler *handler);
163 * Reads from the file specified in the constructor.
167 * Pareses the body of the tag in \a data.
169 void parse(const ByteVector &data);
173 Tag &operator=(const Tag &);