implement methods in TempoMap for walking a given distance along a tempo map and...
[ardour.git] / libs / taglib / taglib / mpeg / id3v2 / id3v2frame.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_ID3V2FRAME_H
27 #define TAGLIB_ID3V2FRAME_H
28
29 #include "tstring.h"
30 #include "tbytevector.h"
31 #include "taglib_export.h"
32
33 namespace TagLib {
34
35   class StringList;
36
37   namespace ID3v2 {
38
39     class Tag;
40     class FrameFactory;
41
42     //! ID3v2 frame implementation
43
44     /*!
45      * This class is the main ID3v2 frame implementation.  In ID3v2, a tag is
46      * split between a collection of frames (which are in turn split into fields
47      * (Structure, <a href="id3v2-structure.html#4">4</a>)
48      * (<a href="id3v2-frames.html">Frames</a>).  This class provides an API for
49      * gathering information about and modifying ID3v2 frames.  Funtionallity
50      * specific to a given frame type is handed in one of the many subclasses.
51      */
52
53     class TAGLIB_EXPORT Frame
54     {
55       friend class Tag;
56       friend class FrameFactory;
57
58     public:
59       /*!
60        * Destroys this Frame instance.
61        */
62       virtual ~Frame();
63
64       /*!
65        * Returns the Frame ID (Structure, <a href="id3v2-structure.html#4">4</a>)
66        * (Frames, <a href="id3v2-frames.html#4">4</a>)
67        */
68       ByteVector frameID() const;
69
70       /*!
71        * Returns the size of the frame.
72        */
73       uint size() const;
74
75       /*!
76        * Returns the size of the frame header
77        *
78        * \deprecated This is only accurate for ID3v2.3 or ID3v2.4.  Please use
79        * the call below which accepts an ID3v2 version number.  In the next
80        * non-binary compatible release this will be made into a non-static
81        * member that checks the internal ID3v2 version.
82        */
83       static uint headerSize(); // BIC: remove and make non-static
84
85       /*!
86        * Returns the size of the frame header for the given ID3v2 version.
87        *
88        * \deprecated Please see the explanation above.
89        */
90       static uint headerSize(uint version); // BIC: remove and make non-static
91
92       /*!
93        * Sets the data that will be used as the frame.  Since the length is not
94        * known before the frame has been parsed, this should just be a pointer to
95        * the first byte of the frame.  It will determine the length internally
96        * and make that available through size().
97        */
98       void setData(const ByteVector &data);
99
100       /*!
101        * Set the text of frame in the sanest way possible.  This should only be
102        * reimplemented in frames where there is some logical mapping to text.
103        *
104        * \note If the frame type supports multiple text encodings, this will not
105        * change the text encoding of the frame; the string will be converted to
106        * that frame's encoding.  Please use the specific APIs of the frame types
107        * to set the encoding if that is desired.
108        */
109       virtual void setText(const String &text);
110
111       /*!
112        * This returns the textual representation of the data in the frame.
113        * Subclasses must reimplement this method to provide a string
114        * representation of the frame's data.
115        */
116       virtual String toString() const = 0;
117
118       /*!
119        * Render the frame back to its binary format in a ByteVector.
120        */
121       ByteVector render() const;
122
123       /*!
124        * Returns the text delimiter that is used between fields for the string
125        * type \a t.
126        */
127       static ByteVector textDelimiter(String::Type t);
128
129     protected:
130       class Header;
131
132       /*!
133        * Constructs an ID3v2 frame using \a data to read the header information.
134        * All other processing of \a data should be handled in a subclass.
135        *
136        * \note This need not contain anything more than a frame ID, but
137        * \e must constain at least that.
138        */
139       explicit Frame(const ByteVector &data);
140
141       /*!
142        * This creates an Frame using the header \a h.
143        *
144        * The ownership of this header will be assigned to the frame and the
145        * header will be deleted when the frame is destroyed.
146        */
147       Frame(Header *h);
148
149       /*!
150        * Returns a pointer to the frame header.
151        */
152       Header *header() const;
153
154       /*!
155        * Sets the header to \a h.  If \a deleteCurrent is true, this will free
156        * the memory of the current header.
157        *
158        * The ownership of this header will be assigned to the frame and the
159        * header will be deleted when the frame is destroyed.
160        */
161       void setHeader(Header *h, bool deleteCurrent = true);
162
163       /*!
164        * Called by setData() to parse the frame data.  It makes this information
165        * available through the public API.
166        */
167       void parse(const ByteVector &data);
168
169       /*!
170        * Called by parse() to parse the field data.  It makes this information
171        * available through the public API.  This must be overridden by the
172        * subclasses.
173        */
174       virtual void parseFields(const ByteVector &data) = 0;
175
176       /*!
177        * Render the field data back to a binary format in a ByteVector.  This
178        * must be overridden by subclasses.
179        */
180       virtual ByteVector renderFields() const = 0;
181
182       /*!
183        * Returns a ByteVector containing the field data given the frame data.
184        * This correctly adjusts for the header size plus any additional frame
185        * data that's specified in the frame header flags.
186        */
187       ByteVector fieldData(const ByteVector &frameData) const;
188
189       /*!
190        * Reads a String of type \a encodiong from the ByteVector \a data.  If \a
191        * position is passed in it is used both as the starting point and is
192        * updated to replect the position just after the string that has been read.
193        * This is useful for reading strings sequentially.
194        */
195       String readStringField(const ByteVector &data, String::Type encoding,
196                              int *positon = 0);
197
198       /*!
199        * Checks a the list of string values to see if they can be used with the
200        * specified encoding and returns the recommended encoding.
201        */
202       static String::Type checkEncoding(const StringList &fields,
203                                         String::Type encoding);
204
205     private:
206       Frame(const Frame &);
207       Frame &operator=(const Frame &);
208
209       class FramePrivate;
210       friend class FramePrivate;
211       FramePrivate *d;
212     };
213
214     //! ID3v2 frame header implementation
215
216     /*!
217      * The ID3v2 Frame Header (Structure, <a href="id3v2-structure.html#4">4</a>)
218      *
219      * Every ID3v2::Frame has an associated header that gives some general
220      * properties of the frame and also makes it possible to identify the frame
221      * type.
222      *
223      * As such when reading an ID3v2 tag ID3v2::FrameFactory first creates the
224      * frame headers and then creates the appropriate Frame subclass based on
225      * the type and attaches the header.
226      */
227
228     class TAGLIB_EXPORT Frame::Header
229     {
230     public:
231       /*!
232        * Construct a Frame Header based on \a data.  \a data must at least
233        * contain a 4 byte frame ID, and optionally can contain flag data and the
234        * frame size.  i.e. Just the frame id -- "TALB" -- is a valid value.
235        *
236        * \deprecated Please use the constructor below that accepts a version
237        * number.
238        */
239       Header(const ByteVector &data, bool synchSafeInts);
240
241       /*!
242        * Construct a Frame Header based on \a data.  \a data must at least
243        * contain a 4 byte frame ID, and optionally can contain flag data and the
244        * frame size.  i.e. Just the frame id -- "TALB" -- is a valid value.
245        *
246        * \a version should be the ID3v2 version of the tag.
247        */
248       explicit Header(const ByteVector &data, uint version = 4);
249
250       /*!
251        * Destroys this Header instance.
252        */
253       virtual ~Header();
254
255       /*!
256        * Sets the data for the Header.
257        *
258        * \deprecated Please use the version below that accepts an ID3v2 version
259        * number.
260        */
261       void setData(const ByteVector &data, bool synchSafeInts);
262
263       /*!
264        * Sets the data for the Header.  \a version should indicate the ID3v2
265        * version number of the tag that this frame is contained in.
266        */
267       void setData(const ByteVector &data, uint version = 4);
268
269       /*!
270        * Returns the Frame ID (Structure, <a href="id3v2-structure.html#4">4</a>)
271        * (Frames, <a href="id3v2-frames.html#4">4</a>)
272        */
273       ByteVector frameID() const;
274
275       /*!
276        * Sets the frame's ID to \a id.  Only the first four bytes of \a id will
277        * be used.
278        *
279        * \warning This method should in general be avoided.  It exists simply to
280        * provide a mechanism for transforming frames from a deprecated frame type
281        * to a newer one -- i.e. TYER to TDRC from ID3v2.3 to ID3v2.4.
282        */
283       void setFrameID(const ByteVector &id);
284
285       /*!
286        * Returns the size of the frame data portion, as set when setData() was
287        * called or set explicitly via setFrameSize().
288        */
289       uint frameSize() const;
290
291       /*!
292        * Sets the size of the frame data portion.
293        */
294       void setFrameSize(uint size);
295
296       /*!
297        * Returns the ID3v2 version of the header (as passed in from the
298        * construction of the header).
299        */
300       uint version() const;
301
302       /*!
303        * Returns the size of the frame header in bytes.
304        *
305        * \deprecated Please use the version of this method that accepts a
306        * version.  This is only accurate for ID3v2.3 and ID3v2.4.  This will be
307        * removed in the next binary incompatible release (2.0) and will be
308        * replaced with a non-static method that checks the frame version.
309        */
310       static uint size();
311
312       /*!
313        * Returns the size of the frame header in bytes for the ID3v2 version
314        * that's given.
315        *
316        * \deprecated Please see the explanation in the version above.
317        */
318       static uint size(uint version);
319
320       /*!
321        * Returns true if the flag for tag alter preservation is set.
322        *
323        * The semantics are a little backwards from what would seem natural
324        * (setting the preservation flag to throw away the frame), but this
325        * follows the ID3v2 standard.
326        *
327        * \see setTagAlterPreservation()
328        */
329       bool tagAlterPreservation() const;
330
331       /*!
332        * Sets the flag for preservation of this frame if the tag is set.  If
333        * this is set to true the frame will not be written when the tag is
334        * saved.
335        *
336        * The semantics are a little backwards from what would seem natural
337        * (setting the preservation flag to throw away the frame), but this
338        * follows the ID3v2 standard.
339        *
340        * \see tagAlterPreservation()
341        */
342       void setTagAlterPreservation(bool discard);
343
344       /*!
345        * Returns true if the flag for file alter preservation is set.
346        *
347        * \note This flag is currently ignored internally in TagLib.
348        */
349       bool fileAlterPreservation() const;
350
351       /*!
352        * Returns true if the frame is meant to be read only.
353        *
354        * \note This flag is currently ignored internally in TagLib.
355        */
356       bool readOnly() const;
357
358       /*!
359        * Returns true if the flag for the grouping identifity is set.
360        *
361        * \note This flag is currently ignored internally in TagLib.
362        */
363       bool groupingIdentity() const;
364
365       /*!
366        * Returns true if compression is enabled for this frame.
367        *
368        * \note This flag is currently ignored internally in TagLib.
369        */
370       bool compression() const;
371
372       /*!
373        * Returns true if encryption is enabled for this frame.
374        *
375        * \note This flag is currently ignored internally in TagLib.
376        */
377       bool encryption() const;
378
379 #ifndef DO_NOT_DOCUMENT
380       bool unsycronisation() const;
381 #endif
382
383       /*!
384        * Returns true if unsynchronisation is enabled for this frame.
385        */
386       bool unsynchronisation() const;
387
388       /*!
389        * Returns true if the flag for a data length indicator is set.
390        */
391       bool dataLengthIndicator() const;
392
393       /*!
394        * Render the Header back to binary format in a ByteVector.
395        */
396       ByteVector render() const;
397
398       /*!
399        * \deprecated
400        */
401       bool frameAlterPreservation() const;
402
403     private:
404       Header(const Header &);
405       Header &operator=(const Header &);
406
407       class HeaderPrivate;
408       HeaderPrivate *d;
409     };
410
411   }
412 }
413
414 #endif