blob: 6b34e2d7676d1bcde41f807240aa878219ccf7ff [file] [log] [blame]
Josh Coalsonfda98fb2002-05-17 06:33:39 +00001/* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef FLACPP__METADATA_H
21#define FLACPP__METADATA_H
22
23#include "FLAC/metadata.h"
24
Josh Coalsonfb74f102002-05-22 05:33:29 +000025// ===============================================================
26//
27// Full documentation for the metadata interface can be found
28// in the C layer in include/FLAC/metadata.h
29//
30// ===============================================================
31
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000032/** \file include/FLAC++/metadata.h
33 *
34 * \brief
35 * This module provides classes for creating and manipulating FLAC
36 * metadata blocks in memory, and three progressively more powerful
37 * interfaces for traversing and editing metadata in FLAC files.
38 *
39 * See the detailed documentation for each interface in the
40 * \link flacpp_metadata metadata \endlink module.
41 */
42
43/** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
44 * \ingroup flacpp
45 *
46 * \brief
47 * This module provides classes for creating and manipulating FLAC
48 * metadata blocks in memory, and three progressively more powerful
49 * interfaces for traversing and editing metadata in FLAC files.
50 *
51 * The behavior closely mimics the C layer interface; be sure to read
52 * the detailed description of the
53 * \link flac_metadata C metadata module \endlink.
54 */
55
Josh Coalsonfb74f102002-05-22 05:33:29 +000056
Josh Coalsonfda98fb2002-05-17 06:33:39 +000057namespace FLAC {
58 namespace Metadata {
59
Josh Coalsonfb74f102002-05-22 05:33:29 +000060 // ============================================================
61 //
62 // Metadata objects
63 //
64 // ============================================================
65
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000066 /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
67 * \ingroup flacpp_metadata
68 *
69 * This module contains classes representing FLAC metadata
70 * blocks in memory.
71 *
72 * The behavior closely mimics the C layer interface; be
73 * sure to read the detailed description of the
74 * \link flac_metadata_object C metadata object module \endlink.
75 *
76 * Any time a metadata object is constructed or assigned, you
77 * should check is_valid() to make sure the underlying
78 * ::FLAC__StreamMetadata object was able to be created.
79 *
80 * \warning
81 * When the get_*() methods of any metadata object method
82 * return you a const pointer, DO NOT disobey and write into it.
83 * Always use the set_*() methods.
84 *
85 * \{
86 */
Josh Coalsoncc682512002-06-08 04:53:42 +000087
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000088 /** Base class for all metadata block types.
89 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +000090 class Prototype {
91 protected:
Josh Coalsonf6efd9c2002-07-27 04:59:54 +000092 //@{
93 /** Constructs a copy of the given object. This form
94 * always performs a deep copy.
95 */
96 Prototype(const Prototype &);
97 Prototype(const ::FLAC__StreamMetadata &);
98 Prototype(const ::FLAC__StreamMetadata *);
99 //@}
Josh Coalson83961752002-07-09 06:12:59 +0000100
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000101 /** Constructs an object with copy control. When \a copy
102 * is \c true, behaves identically to
103 * FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
104 * When \a copy is \c false, the instance takes ownership of
105 * the pointer and the ::FLAC__StreamMetadata object will
106 * be freed by the destructor.
107 *
108 * \assert
109 * \code object != NULL \endcode
110 */
Josh Coalson83961752002-07-09 06:12:59 +0000111 Prototype(::FLAC__StreamMetadata *object, bool copy);
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000112
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000113 //@{
114 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000115 void operator=(const Prototype &);
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000116 void operator=(const ::FLAC__StreamMetadata &);
117 void operator=(const ::FLAC__StreamMetadata *);
118 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000119
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000120 /** Deletes the underlying ::FLAC__StreamMetadata object.
121 */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000122 virtual void clear();
123
Josh Coalsoncc682512002-06-08 04:53:42 +0000124 ::FLAC__StreamMetadata *object_;
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000125 public:
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000126 /** Deletes the underlying ::FLAC__StreamMetadata object.
127 */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000128 virtual ~Prototype();
129
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000130 //@{
131 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalsoncc682512002-06-08 04:53:42 +0000132 inline bool operator==(const Prototype &) const;
133 inline bool operator==(const ::FLAC__StreamMetadata &) const;
134 inline bool operator==(const ::FLAC__StreamMetadata *) const;
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000135 //@}
136
137 //@{
138 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalsoncc682512002-06-08 04:53:42 +0000139 inline bool operator!=(const Prototype &) const;
140 inline bool operator!=(const ::FLAC__StreamMetadata &) const;
141 inline bool operator!=(const ::FLAC__StreamMetadata *) const;
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000142 //@}
Josh Coalsoncc682512002-06-08 04:53:42 +0000143
Josh Coalsonfb74f102002-05-22 05:33:29 +0000144 friend class SimpleIterator;
145 friend class Iterator;
146
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000147 /** Returns \c true if the object was correctly constructed
148 * (i.e. the underlying ::FLAC__StreamMetadata object was
149 * properly allocated), else \c false.
150 */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000151 inline bool is_valid() const;
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000152
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000153 /** Returns \c true if this block is the last block in a
154 * stream, else \c false.
155 *
156 * \assert
157 * \code is_valid() \endcode
158 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000159 bool get_is_last() const;
Josh Coalsoncc682512002-06-08 04:53:42 +0000160
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000161 /** Returns the type of the block.
162 *
163 * \assert
164 * \code is_valid() \endcode
165 */
166 ::FLAC__MetadataType get_type() const;
167
168 /** Returns the stream length of the metadata block.
169 *
170 * \note
171 * The length does not include the metadata block header,
172 * per spec.
173 *
174 * \assert
175 * \code is_valid() \endcode
176 */
177 unsigned get_length() const;
178
179 /** Sets the "is_last" flag for the block. When using the iterators
180 * it is not necessary to set this flag; they will do it for you.
181 *
182 * \assert
183 * \code is_valid() \endcode
184 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000185 void set_is_last(bool);
Josh Coalsonfb74f102002-05-22 05:33:29 +0000186 private:
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000187 /** Private and undefined so you can't use it. */
188 Prototype();
Josh Coalsonfb74f102002-05-22 05:33:29 +0000189
190 // These are used only by Iterator
191 bool is_reference_;
192 inline void set_reference(bool x) { is_reference_ = x; }
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000193 };
194
Josh Coalson765ff502002-08-27 05:46:11 +0000195 inline bool Prototype::operator==(const Prototype &object) const
Josh Coalsond57c8d32002-06-11 06:15:28 +0000196 { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000197
Josh Coalson765ff502002-08-27 05:46:11 +0000198 inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
Josh Coalsond57c8d32002-06-11 06:15:28 +0000199 { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000200
Josh Coalson765ff502002-08-27 05:46:11 +0000201 inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
Josh Coalsond57c8d32002-06-11 06:15:28 +0000202 { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000203
Josh Coalson765ff502002-08-27 05:46:11 +0000204 inline bool Prototype::operator!=(const Prototype &object) const
Josh Coalson57ba6f42002-06-07 05:27:37 +0000205 { return !operator==(object); }
206
Josh Coalson765ff502002-08-27 05:46:11 +0000207 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
Josh Coalson57ba6f42002-06-07 05:27:37 +0000208 { return !operator==(object); }
209
Josh Coalson765ff502002-08-27 05:46:11 +0000210 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
Josh Coalson57ba6f42002-06-07 05:27:37 +0000211 { return !operator==(object); }
212
213 inline bool Prototype::is_valid() const
214 { return 0 != object_; }
215
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000216 /** Create a deep copy of an object and return it. */
217 Prototype *clone(const Prototype *);
Josh Coalson57ba6f42002-06-07 05:27:37 +0000218
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000219
220 /** STREAMINFO metadata block.
Josh Coalson4dc35072002-08-20 03:56:52 +0000221 * See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000222 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000223 class StreamInfo : public Prototype {
224 public:
225 StreamInfo();
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000226
227 //@{
228 /** Constructs a copy of the given object. This form
229 * always performs a deep copy.
230 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000231 inline StreamInfo(const StreamInfo &object): Prototype(object) { }
232 inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
233 inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000234 //@}
235
236 /** Constructs an object with copy control. See
237 * Prototype(::FLAC__StreamMetadata *object, bool copy).
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000238 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000239 inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000240
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000241 ~StreamInfo();
242
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000243 //@{
244 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000245 inline void operator=(const StreamInfo &object) { Prototype::operator=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000246 inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
247 inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000248 //@}
Josh Coalsonfb74f102002-05-22 05:33:29 +0000249
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000250 //@{
251 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000252 inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000253 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
254 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000255 //@}
256
257 //@{
258 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000259 inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000260 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
261 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000262 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000263
Josh Coalson4dc35072002-08-20 03:56:52 +0000264 //@{
265 /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000266 unsigned get_min_blocksize() const;
267 unsigned get_max_blocksize() const;
268 unsigned get_min_framesize() const;
269 unsigned get_max_framesize() const;
270 unsigned get_sample_rate() const;
271 unsigned get_channels() const;
272 unsigned get_bits_per_sample() const;
273 FLAC__uint64 get_total_samples() const;
274 const FLAC__byte *get_md5sum() const;
275
276 void set_min_blocksize(unsigned value);
277 void set_max_blocksize(unsigned value);
278 void set_min_framesize(unsigned value);
279 void set_max_framesize(unsigned value);
280 void set_sample_rate(unsigned value);
281 void set_channels(unsigned value);
282 void set_bits_per_sample(unsigned value);
283 void set_total_samples(FLAC__uint64 value);
284 void set_md5sum(const FLAC__byte value[16]);
Josh Coalson4dc35072002-08-20 03:56:52 +0000285 //@}
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000286 };
287
Josh Coalson4dc35072002-08-20 03:56:52 +0000288 /** PADDING metadata block.
289 * See <A HREF="../format.html#metadata_block_padding">format specification</A>.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000290 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000291 class Padding : public Prototype {
292 public:
293 Padding();
Josh Coalson4dc35072002-08-20 03:56:52 +0000294
295 //@{
296 /** Constructs a copy of the given object. This form
297 * always performs a deep copy.
298 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000299 inline Padding(const Padding &object): Prototype(object) { }
300 inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
301 inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000302 //@}
303
304 /** Constructs an object with copy control. See
305 * Prototype(::FLAC__StreamMetadata *object, bool copy).
306 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000307 inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000308
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000309 ~Padding();
Josh Coalsonfb74f102002-05-22 05:33:29 +0000310
Josh Coalson4dc35072002-08-20 03:56:52 +0000311 //@{
312 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000313 inline void operator=(const Padding &object) { Prototype::operator=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000314 inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
315 inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000316 //@}
Josh Coalsonb2b53582002-05-31 06:20:50 +0000317
Josh Coalson4dc35072002-08-20 03:56:52 +0000318 //@{
319 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000320 inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000321 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
322 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000323 //@}
324
325 //@{
326 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000327 inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000328 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
329 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000330 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000331
Josh Coalsonb2b53582002-05-31 06:20:50 +0000332 void set_length(unsigned length);
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000333 };
334
Josh Coalson4dc35072002-08-20 03:56:52 +0000335 /** APPLICATION metadata block.
336 * See <A HREF="../format.html#metadata_block_application">format specification</A>.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000337 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000338 class Application : public Prototype {
339 public:
340 Application();
Josh Coalson4dc35072002-08-20 03:56:52 +0000341 //
342 //@{
343 /** Constructs a copy of the given object. This form
344 * always performs a deep copy.
345 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000346 inline Application(const Application &object): Prototype(object) { }
347 inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
348 inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000349 //@}
350
351 /** Constructs an object with copy control. See
352 * Prototype(::FLAC__StreamMetadata *object, bool copy).
353 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000354 inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000355
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000356 ~Application();
357
Josh Coalson4dc35072002-08-20 03:56:52 +0000358 //@{
359 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000360 inline void operator=(const Application &object) { Prototype::operator=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000361 inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
362 inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000363 //@}
Josh Coalsonfb74f102002-05-22 05:33:29 +0000364
Josh Coalson4dc35072002-08-20 03:56:52 +0000365 //@{
366 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000367 inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000368 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
369 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000370 //@}
371
372 //@{
373 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000374 inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000375 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
376 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000377 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000378
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000379 const FLAC__byte *get_id() const;
380 const FLAC__byte *get_data() const;
381
Josh Coalsoncc682512002-06-08 04:53:42 +0000382 void set_id(const FLAC__byte value[4]);
Josh Coalson4dc35072002-08-20 03:56:52 +0000383 //! This form always copies \a data
384 bool set_data(const FLAC__byte *data, unsigned length);
Josh Coalsoncc682512002-06-08 04:53:42 +0000385 bool set_data(FLAC__byte *data, unsigned length, bool copy);
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000386 };
387
Josh Coalson4dc35072002-08-20 03:56:52 +0000388 /** SEEKTABLE metadata block.
389 * See <A HREF="../format.html#metadata_block_seektable">format specification</A>.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000390 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000391 class SeekTable : public Prototype {
392 public:
393 SeekTable();
Josh Coalson4dc35072002-08-20 03:56:52 +0000394
395 //@{
396 /** Constructs a copy of the given object. This form
397 * always performs a deep copy.
398 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000399 inline SeekTable(const SeekTable &object): Prototype(object) { }
400 inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
401 inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000402 //@}
403
404 /** Constructs an object with copy control. See
405 * Prototype(::FLAC__StreamMetadata *object, bool copy).
406 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000407 inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000408
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000409 ~SeekTable();
Josh Coalsonfb74f102002-05-22 05:33:29 +0000410
Josh Coalson4dc35072002-08-20 03:56:52 +0000411 //@{
412 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000413 inline void operator=(const SeekTable &object) { Prototype::operator=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000414 inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
415 inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000416 //@}
Josh Coalsonb2b53582002-05-31 06:20:50 +0000417
Josh Coalson4dc35072002-08-20 03:56:52 +0000418 //@{
419 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000420 inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000421 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
422 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000423 //@}
424
425 //@{
426 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000427 inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000428 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
429 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000430 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000431
Josh Coalsonb2b53582002-05-31 06:20:50 +0000432 unsigned get_num_points() const;
Josh Coalsoncc682512002-06-08 04:53:42 +0000433 ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const;
Josh Coalsonb2b53582002-05-31 06:20:50 +0000434
Josh Coalson4dc35072002-08-20 03:56:52 +0000435 //! See FLAC__metadata_object_seektable_set_point()
Josh Coalsoncc682512002-06-08 04:53:42 +0000436 void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
Josh Coalson4dc35072002-08-20 03:56:52 +0000437
438 //! See FLAC__metadata_object_seektable_insert_point()
Josh Coalsoncc682512002-06-08 04:53:42 +0000439 bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
Josh Coalson4dc35072002-08-20 03:56:52 +0000440
441 //! See FLAC__metadata_object_seektable_delete_point()
Josh Coalsonb2b53582002-05-31 06:20:50 +0000442 bool delete_point(unsigned index);
Josh Coalson28e08d82002-06-05 05:56:41 +0000443
Josh Coalson4dc35072002-08-20 03:56:52 +0000444 //! See FLAC__metadata_object_seektable_is_legal()
Josh Coalson28e08d82002-06-05 05:56:41 +0000445 bool is_legal() const;
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000446 };
447
Josh Coalson4dc35072002-08-20 03:56:52 +0000448 /** VORBIS_COMMENT metadata block.
449 * See <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000450 */
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000451 class VorbisComment : public Prototype {
452 public:
Josh Coalson4dc35072002-08-20 03:56:52 +0000453 /** Convenience class for encapsulating Vorbis comment
454 * entries. An entry is a vendor string or a comment
455 * field. In the case of a vendor string, the field
456 * name is undefined; only the field value is relevant.
457 *
458 * A \a field as used in the methods refers to an
459 * entire 'NAME=VALUE' string; the string is not null-
460 * terminated and a length field is required since the
461 * string may contain embedded nulls.
462 *
463 * A \a field_name is what is on the left side of the
464 * first '=' in the \a field. By definition it is ASCII
465 * and so is null-terminated and does not require a
466 * length to describe it. \a field_name is undefined
467 * for a vendor string entry.
468 *
469 * A \a field_value is what is on the right side of the
470 * first '=' in the \a field. By definition, this may
471 * contain embedded nulls and so a \a field_value_length
472 * is requires to describe it.
473 *
474 * Always check is_valid() after the constructor or operator=
475 * to make sure memory was properly allocated.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000476 */
Josh Coalsonb2b53582002-05-31 06:20:50 +0000477 class Entry {
478 public:
479 Entry();
480 Entry(const char *field, unsigned field_length);
481 Entry(const char *field_name, const char *field_value, unsigned field_value_length);
482 Entry(const Entry &entry);
483 void operator=(const Entry &entry);
484
485 virtual ~Entry();
486
487 virtual bool is_valid() const;
Josh Coalsonb2b53582002-05-31 06:20:50 +0000488
489 unsigned get_field_length() const;
490 unsigned get_field_name_length() const;
491 unsigned get_field_value_length() const;
492
Josh Coalsoncc682512002-06-08 04:53:42 +0000493 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
Josh Coalsonb2b53582002-05-31 06:20:50 +0000494 const char *get_field() const;
495 const char *get_field_name() const;
496 const char *get_field_value() const;
497
498 bool set_field(const char *field, unsigned field_length);
499 bool set_field_name(const char *field_name);
500 bool set_field_value(const char *field_value, unsigned field_value_length);
501 protected:
502 bool is_valid_;
Josh Coalsoncc682512002-06-08 04:53:42 +0000503 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
Josh Coalsonb2b53582002-05-31 06:20:50 +0000504 char *field_name_;
505 unsigned field_name_length_;
506 char *field_value_;
507 unsigned field_value_length_;
508 private:
509 void zero();
510 void clear();
511 void clear_entry();
512 void clear_field_name();
513 void clear_field_value();
514 void construct(const char *field, unsigned field_length);
515 void construct(const char *field_name, const char *field_value, unsigned field_value_length);
516 void compose_field();
517 void parse_field();
518 };
519
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000520 VorbisComment();
Josh Coalson4dc35072002-08-20 03:56:52 +0000521
522 //@{
523 /** Constructs a copy of the given object. This form
524 * always performs a deep copy.
525 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000526 inline VorbisComment(const VorbisComment &object): Prototype(object) { }
527 inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
528 inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000529 //@}
530
531 /** Constructs an object with copy control. See
532 * Prototype(::FLAC__StreamMetadata *object, bool copy).
533 */
Josh Coalsoncc682512002-06-08 04:53:42 +0000534 inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
Josh Coalson4dc35072002-08-20 03:56:52 +0000535
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000536 ~VorbisComment();
Josh Coalsonfb74f102002-05-22 05:33:29 +0000537
Josh Coalson4dc35072002-08-20 03:56:52 +0000538 //@{
539 /** Assign from another object. Always performs a deep copy. */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000540 inline void operator=(const VorbisComment &object) { Prototype::operator=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000541 inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
542 inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000543 //@}
Josh Coalsonb2b53582002-05-31 06:20:50 +0000544
Josh Coalson4dc35072002-08-20 03:56:52 +0000545 //@{
546 /** Check for equality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000547 inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000548 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
549 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000550 //@}
551
552 //@{
553 /** Check for inequality, performing a deep compare by following pointers. */
Josh Coalson57ba6f42002-06-07 05:27:37 +0000554 inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
Josh Coalsoncc682512002-06-08 04:53:42 +0000555 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
556 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
Josh Coalson4dc35072002-08-20 03:56:52 +0000557 //@}
Josh Coalson57ba6f42002-06-07 05:27:37 +0000558
Josh Coalsonb2b53582002-05-31 06:20:50 +0000559 unsigned get_num_comments() const;
Josh Coalsoncc682512002-06-08 04:53:42 +0000560 Entry get_vendor_string() const; // only the Entry's field name should be used
Josh Coalsonb2b53582002-05-31 06:20:50 +0000561 Entry get_comment(unsigned index) const;
562
Josh Coalson87977ba2002-08-20 07:09:33 +0000563 //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
Josh Coalson4dc35072002-08-20 03:56:52 +0000564 //! \note Only the Entry's field name will be used.
Josh Coalsoncc682512002-06-08 04:53:42 +0000565 bool set_vendor_string(const Entry &entry); // only the Entry's field name will be used
Josh Coalson4dc35072002-08-20 03:56:52 +0000566
Josh Coalson87977ba2002-08-20 07:09:33 +0000567 //! See FLAC__metadata_object_vorbiscomment_set_comment()
Josh Coalsonb2b53582002-05-31 06:20:50 +0000568 bool set_comment(unsigned index, const Entry &entry);
Josh Coalson4dc35072002-08-20 03:56:52 +0000569
Josh Coalson87977ba2002-08-20 07:09:33 +0000570 //! See FLAC__metadata_object_vorbiscomment_insert_comment()
Josh Coalsonb2b53582002-05-31 06:20:50 +0000571 bool insert_comment(unsigned index, const Entry &entry);
Josh Coalson4dc35072002-08-20 03:56:52 +0000572
Josh Coalson87977ba2002-08-20 07:09:33 +0000573 //! See FLAC__metadata_object_vorbiscomment_delete_comment()
Josh Coalsonb2b53582002-05-31 06:20:50 +0000574 bool delete_comment(unsigned index);
Josh Coalsonfb74f102002-05-22 05:33:29 +0000575 };
576
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000577 /* \} */
578
Josh Coalsonb2b53582002-05-31 06:20:50 +0000579
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000580 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
581 * \ingroup flacpp_metadata
582 *
583 * \brief
Josh Coalson4dc35072002-08-20 03:56:52 +0000584 * Level 0 metadata iterator.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000585 *
Josh Coalson4dc35072002-08-20 03:56:52 +0000586 * See the \link flac_metadata_level0 C layer equivalent \endlink
587 * for more.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000588 *
589 * \{
590 */
591
Josh Coalson4dc35072002-08-20 03:56:52 +0000592 //! See FLAC__metadata_get_streaminfo().
Josh Coalsonfb74f102002-05-22 05:33:29 +0000593 bool get_streaminfo(const char *filename, StreamInfo &streaminfo);
594
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000595 /* \} */
596
Josh Coalsonb2b53582002-05-31 06:20:50 +0000597
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000598 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
599 * \ingroup flacpp_metadata
600 *
Josh Coalson4dc35072002-08-20 03:56:52 +0000601 * \brief
602 * Level 1 metadata iterator.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000603 *
Josh Coalson4dc35072002-08-20 03:56:52 +0000604 * The flow through the iterator in the C++ layer is similar
605 * to the C layer:
606 * - Create a SimpleIterator instance
607 * - Check SimpleIterator::is_valid()
608 * - Call SimpleIterator::init() and check the return
609 * - Traverse and/or edit. Edits are written to file
610 * immediately.
611 * - Destroy the SimpleIterator instance
612 *
613 * The ownership of pointers in the C++ layer follows that in
614 * the C layer, i.e.
615 * - The objects returned by get_block() are yours to
616 * modify, but changes are not reflected in the FLAC file
617 * until you call set_block(). The objects are also
618 * yours to delete; they are not automatically deleted
619 * when passed to set_block() or insert_block_after().
620 *
621 * See the \link flac_metadata_level1 C layer equivalent \endlink
622 * for more.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000623 *
624 * \{
625 */
626
Josh Coalson402da702002-08-21 03:40:11 +0000627 /** This class is a wrapper around the FLAC__metadata_simple_iterator
628 * structures and methods; see ::FLAC__Metadata_SimpleIterator.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000629 */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000630 class SimpleIterator {
631 public:
632 class Status {
633 public:
Josh Coalsoncc682512002-06-08 04:53:42 +0000634 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
635 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
636 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
Josh Coalsonfb74f102002-05-22 05:33:29 +0000637 protected:
Josh Coalsoncc682512002-06-08 04:53:42 +0000638 ::FLAC__Metadata_SimpleIteratorStatus status_;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000639 };
640
641 SimpleIterator();
642 virtual ~SimpleIterator();
643
644 bool init(const char *filename, bool preserve_file_stats = false);
645
646 bool is_valid() const;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000647 Status status();
648 bool is_writable() const;
649
650 bool next();
651 bool prev();
652
Josh Coalsoncc682512002-06-08 04:53:42 +0000653 ::FLAC__MetadataType get_block_type() const;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000654 Prototype *get_block();
655 bool set_block(Prototype *block, bool use_padding = true);
656 bool insert_block_after(Prototype *block, bool use_padding = true);
657 bool delete_block(bool use_padding = true);
658
659 protected:
Josh Coalsoncc682512002-06-08 04:53:42 +0000660 ::FLAC__Metadata_SimpleIterator *iterator_;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000661 void clear();
662 };
663
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000664 /* \} */
665
Josh Coalsonb2b53582002-05-31 06:20:50 +0000666
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000667 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
668 * \ingroup flacpp_metadata
669 *
Josh Coalson4dc35072002-08-20 03:56:52 +0000670 * \brief
671 * Level 2 metadata iterator.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000672 *
Josh Coalson4dc35072002-08-20 03:56:52 +0000673 * The flow through the iterator in the C++ layer is similar
674 * to the C layer:
675 * - Create a Chain instance
676 * - Check Chain::is_valid()
677 * - Call Chain::read() and check the return
678 * - Traverse and/or edit with an Iterator or with
679 * Chain::merge_padding() or Chain::sort_padding()
680 * - Write changes back to FLAC file with Chain::write()
681 * - Destroy the Chain instance
682 *
683 * The ownership of pointers in the C++ layer follows that in
684 * the C layer, i.e.
685 * - The objects returned by Iterator::get_block() are
686 * owned by the iterator and should not be deleted.
687 * When you modify the block, you are directly editing
688 * what's in the chain and do not need to call
689 * Iterator::set_block(). However the changes will not
690 * be reflected in the FLAC file until the chain is
691 * written with Chain::write().
692 * - When you pass an object to Iterator::set_block(),
693 * Iterator::insert_block_before(), or
694 * Iterator::insert_block_after(), the iterator takes
695 * ownership of the block and it will be deleted with the
696 * chain.
697 *
698 * See the \link flac_metadata_level2 C layer equivalent \endlink
699 * for more.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000700 *
701 * \{
702 */
703
Josh Coalson402da702002-08-21 03:40:11 +0000704 /** This class is a wrapper around the FLAC__metadata_chain
705 * structures and methods; see ::FLAC__Metadata_Chain.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000706 */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000707 class Chain {
708 public:
709 class Status {
710 public:
Josh Coalsoncc682512002-06-08 04:53:42 +0000711 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
712 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
713 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
Josh Coalsonfb74f102002-05-22 05:33:29 +0000714 protected:
Josh Coalsoncc682512002-06-08 04:53:42 +0000715 ::FLAC__Metadata_ChainStatus status_;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000716 };
717
718 Chain();
719 virtual ~Chain();
720
721 friend class Iterator;
722
723 bool is_valid() const;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000724 Status status();
725
726 bool read(const char *filename);
727 bool write(bool use_padding = true, bool preserve_file_stats = false);
728
729 void merge_padding();
730 void sort_padding();
731
732 protected:
Josh Coalsoncc682512002-06-08 04:53:42 +0000733 ::FLAC__Metadata_Chain *chain_;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000734 virtual void clear();
735 };
736
Josh Coalson402da702002-08-21 03:40:11 +0000737 /** This class is a wrapper around the FLAC__metadata_iterator
738 * structures and methods; see ::FLAC__Metadata_Iterator.
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000739 */
Josh Coalsonfb74f102002-05-22 05:33:29 +0000740 class Iterator {
741 public:
742 Iterator();
743 virtual ~Iterator();
744
745 bool is_valid() const;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000746
Josh Coalson999be3b2002-06-10 04:42:35 +0000747 void init(Chain &chain);
Josh Coalsonfb74f102002-05-22 05:33:29 +0000748
749 bool next();
750 bool prev();
751
Josh Coalsoncc682512002-06-08 04:53:42 +0000752 ::FLAC__MetadataType get_block_type() const;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000753 Prototype *get_block();
754 bool set_block(Prototype *block);
755 bool delete_block(bool replace_with_padding);
756 bool insert_block_before(Prototype *block);
757 bool insert_block_after(Prototype *block);
758
759 protected:
Josh Coalsoncc682512002-06-08 04:53:42 +0000760 ::FLAC__Metadata_Iterator *iterator_;
Josh Coalsonfb74f102002-05-22 05:33:29 +0000761 virtual void clear();
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000762 };
763
Josh Coalsonf6efd9c2002-07-27 04:59:54 +0000764 /* \} */
765
Josh Coalsonfda98fb2002-05-17 06:33:39 +0000766 };
767};
768
769#endif