Added TagLib (with AUTORS and COPYING files)
[someplayer] / src / taglib / mpeg / id3v1 / id3v1tag.h
1 /***************************************************************************
2     copyright            : (C) 2002 - 2008 by Scott Wheeler
3     email                : wheeler@kde.org
4  ***************************************************************************/
5
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.                     *
10  *                                                                         *
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.                       *
15  *                                                                         *
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  *
19  *   USA                                                                   *
20  *                                                                         *
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  ***************************************************************************/
25
26 #ifndef TAGLIB_ID3V1TAG_H
27 #define TAGLIB_ID3V1TAG_H
28
29 #include "tag.h"
30 #include "tbytevector.h"
31 #include "taglib_export.h"
32
33 namespace TagLib {
34
35   class File;
36
37   //! An ID3v1 implementation
38
39   namespace ID3v1 {
40
41     //! A abstraction for the string to data encoding in ID3v1 tags.
42
43     /*!
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
46      * in ID3v1 tags.
47      *
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.
52      *
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.
56      *
57      * \see ID3v1::Tag::setStringHandler()
58      */
59
60     class TAGLIB_EXPORT StringHandler
61     {
62       TAGLIB_IGNORE_MISSING_DESTRUCTOR
63     public:
64       // BIC: Add virtual destructor.
65
66       /*!
67        * Decode a string from \a data.  The default implementation assumes that
68        * \a data is an ISO-8859-1 (Latin1) character array.
69        */
70       virtual String parse(const ByteVector &data) const;
71
72       /*!
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.
76        *
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
79        * ISO-8859-1.
80        */
81       virtual ByteVector render(const String &s) const;
82     };
83
84     //! The main class in the ID3v1 implementation
85
86     /*!
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
91      * provided by ID3v1.
92      *
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.
97      *
98      * \see StringHandler
99      *
100      * \note Most fields are truncated to a maximum of 28-30 bytes.  The
101      * truncation happens automatically when the tag is rendered.
102      */
103
104     class TAGLIB_EXPORT Tag : public TagLib::Tag
105     {
106     public:
107       /*!
108        * Create an ID3v1 tag with default values.
109        */
110       Tag();
111
112       /*!
113        * Create an ID3v1 tag and parse the data in \a file starting at
114        * \a tagOffset.
115        */
116       Tag(File *file, long tagOffset);
117
118       /*!
119        * Destroys this Tag instance.
120        */
121       virtual ~Tag();
122
123       /*!
124        * Renders the in memory values to a ByteVector suitable for writing to
125        * the file.
126        */
127       ByteVector render() const;
128
129       /*!
130        * Returns the string "TAG" suitable for usage in locating the tag in a
131        * file.
132        */
133       static ByteVector fileIdentifier();
134
135       // Reimplementations.
136
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;
144
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);
152
153       /*!
154        * Sets the string handler that decides how the ID3v1 data will be
155        * converted to and from binary data.
156        *
157        * \see StringHandler
158        */
159       static void setStringHandler(const StringHandler *handler);
160
161     protected:
162       /*!
163        * Reads from the file specified in the constructor.
164        */
165       void read();
166       /*!
167        * Pareses the body of the tag in \a data.
168        */
169       void parse(const ByteVector &data);
170
171     private:
172       Tag(const Tag &);
173       Tag &operator=(const Tag &);
174
175       class TagPrivate;
176       TagPrivate *d;
177     };
178   }
179 }
180
181 #endif