1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef FLACPP__METADATA_H
33 #define FLACPP__METADATA_H
37 #include "FLAC/metadata.h"
39 // ===============================================================
41 // Full documentation for the metadata interface can be found
42 // in the C layer in include/FLAC/metadata.h
44 // ===============================================================
46 /** \file include/FLAC++/metadata.h
49 * This module provides classes for creating and manipulating FLAC
50 * metadata blocks in memory, and three progressively more powerful
51 * interfaces for traversing and editing metadata in FLAC files.
53 * See the detailed documentation for each interface in the
54 * \link flacpp_metadata metadata \endlink module.
57 /** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
61 * This module provides classes for creating and manipulating FLAC
62 * metadata blocks in memory, and three progressively more powerful
63 * interfaces for traversing and editing metadata in FLAC files.
65 * The behavior closely mimics the C layer interface; be sure to read
66 * the detailed description of the
67 * \link flac_metadata C metadata module \endlink. Note that like the
68 * C layer, currently only the Chain interface (level 2) supports Ogg
69 * FLAC files, and it is read-only i.e. no writing back changed
77 // ============================================================
81 // ============================================================
83 /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
84 * \ingroup flacpp_metadata
86 * This module contains classes representing FLAC metadata
89 * The behavior closely mimics the C layer interface; be
90 * sure to read the detailed description of the
91 * \link flac_metadata_object C metadata object module \endlink.
93 * Any time a metadata object is constructed or assigned, you
94 * should check is_valid() to make sure the underlying
95 * ::FLAC__StreamMetadata object was able to be created.
98 * When the get_*() methods of any metadata object method
99 * return you a const pointer, DO NOT disobey and write into it.
100 * Always use the set_*() methods.
105 /** Base class for all metadata block types.
106 * See the \link flacpp_metadata_object overview \endlink for more.
108 class FLACPP_API Prototype
{
111 /** Constructs a copy of the given object. This form
112 * always performs a deep copy.
114 Prototype(const Prototype
&);
115 Prototype(const ::FLAC__StreamMetadata
&);
116 Prototype(const ::FLAC__StreamMetadata
*);
119 /** Constructs an object with copy control. When \a copy
120 * is \c true, behaves identically to
121 * FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
122 * When \a copy is \c false, the instance takes ownership of
123 * the pointer and the ::FLAC__StreamMetadata object will
124 * be freed by the destructor.
127 * \code object != NULL \endcode
129 Prototype(::FLAC__StreamMetadata
*object
, bool copy
);
132 /** Assign from another object. Always performs a deep copy. */
133 Prototype
&operator=(const Prototype
&);
134 Prototype
&operator=(const ::FLAC__StreamMetadata
&);
135 Prototype
&operator=(const ::FLAC__StreamMetadata
*);
138 /** Assigns an object with copy control. See
139 * Prototype(::FLAC__StreamMetadata *object, bool copy).
141 Prototype
&assign_object(::FLAC__StreamMetadata
*object
, bool copy
);
143 /** Deletes the underlying ::FLAC__StreamMetadata object.
145 virtual void clear();
147 ::FLAC__StreamMetadata
*object_
;
149 /** Deletes the underlying ::FLAC__StreamMetadata object.
151 virtual ~Prototype();
154 /** Check for equality, performing a deep compare by following pointers.
156 inline bool operator==(const Prototype
&) const;
157 inline bool operator==(const ::FLAC__StreamMetadata
&) const;
158 inline bool operator==(const ::FLAC__StreamMetadata
*) const;
162 /** Check for inequality, performing a deep compare by following pointers. */
163 inline bool operator!=(const Prototype
&) const;
164 inline bool operator!=(const ::FLAC__StreamMetadata
&) const;
165 inline bool operator!=(const ::FLAC__StreamMetadata
*) const;
168 friend class SimpleIterator
;
169 friend class Iterator
;
171 /** Returns \c true if the object was correctly constructed
172 * (i.e. the underlying ::FLAC__StreamMetadata object was
173 * properly allocated), else \c false.
175 inline bool is_valid() const;
177 /** Returns \c true if this block is the last block in a
178 * stream, else \c false.
181 * \code is_valid() \endcode
183 bool get_is_last() const;
185 /** Returns the type of the block.
188 * \code is_valid() \endcode
190 ::FLAC__MetadataType
get_type() const;
192 /** Returns the stream length of the metadata block.
195 * The length does not include the metadata block header,
199 * \code is_valid() \endcode
201 unsigned get_length() const;
203 /** Sets the "is_last" flag for the block. When using the iterators
204 * it is not necessary to set this flag; they will do it for you.
207 * \code is_valid() \endcode
209 void set_is_last(bool);
211 /** Returns a pointer to the underlying ::FLAC__StreamMetadata
212 * object. This can be useful for plugging any holes between
213 * the C++ and C interfaces.
216 * \code is_valid() \endcode
218 inline operator const ::FLAC__StreamMetadata
*() const;
220 /** Private and undefined so you can't use it. */
223 // These are used only by Iterator
225 inline void set_reference(bool x
) { is_reference_
= x
; }
229 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
230 #pragma warning ( disable : 4800 )
233 inline bool Prototype::operator==(const Prototype
&object
) const
234 { return (bool)::FLAC__metadata_object_is_equal(object_
, object
.object_
); }
236 inline bool Prototype::operator==(const ::FLAC__StreamMetadata
&object
) const
237 { return (bool)::FLAC__metadata_object_is_equal(object_
, &object
); }
239 inline bool Prototype::operator==(const ::FLAC__StreamMetadata
*object
) const
240 { return (bool)::FLAC__metadata_object_is_equal(object_
, object
); }
243 // @@@ how to re-enable? the following doesn't work
244 // #pragma warning ( enable : 4800 )
247 inline bool Prototype::operator!=(const Prototype
&object
) const
248 { return !operator==(object
); }
250 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata
&object
) const
251 { return !operator==(object
); }
253 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata
*object
) const
254 { return !operator==(object
); }
256 inline bool Prototype::is_valid() const
257 { return 0 != object_
; }
259 inline Prototype::operator const ::FLAC__StreamMetadata
*() const
262 /** Create a deep copy of an object and return it. */
263 FLACPP_API Prototype
*clone(const Prototype
*);
266 /** STREAMINFO metadata block.
267 * See the \link flacpp_metadata_object overview \endlink for more,
268 * and the <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
270 class FLACPP_API StreamInfo
: public Prototype
{
275 /** Constructs a copy of the given object. This form
276 * always performs a deep copy.
278 inline StreamInfo(const StreamInfo
&object
): Prototype(object
) { }
279 inline StreamInfo(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
280 inline StreamInfo(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
283 /** Constructs an object with copy control. See
284 * Prototype(::FLAC__StreamMetadata *object, bool copy).
286 inline StreamInfo(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
291 /** Assign from another object. Always performs a deep copy. */
292 inline StreamInfo
&operator=(const StreamInfo
&object
) { Prototype::operator=(object
); return *this; }
293 inline StreamInfo
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
294 inline StreamInfo
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
297 /** Assigns an object with copy control. See
298 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
300 inline StreamInfo
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
303 /** Check for equality, performing a deep compare by following pointers. */
304 inline bool operator==(const StreamInfo
&object
) const { return Prototype::operator==(object
); }
305 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
306 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
310 /** Check for inequality, performing a deep compare by following pointers. */
311 inline bool operator!=(const StreamInfo
&object
) const { return Prototype::operator!=(object
); }
312 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
313 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
317 /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
318 unsigned get_min_blocksize() const;
319 unsigned get_max_blocksize() const;
320 unsigned get_min_framesize() const;
321 unsigned get_max_framesize() const;
322 unsigned get_sample_rate() const;
323 unsigned get_channels() const;
324 unsigned get_bits_per_sample() const;
325 FLAC__uint64
get_total_samples() const;
326 const FLAC__byte
*get_md5sum() const;
328 void set_min_blocksize(unsigned value
);
329 void set_max_blocksize(unsigned value
);
330 void set_min_framesize(unsigned value
);
331 void set_max_framesize(unsigned value
);
332 void set_sample_rate(unsigned value
);
333 void set_channels(unsigned value
);
334 void set_bits_per_sample(unsigned value
);
335 void set_total_samples(FLAC__uint64 value
);
336 void set_md5sum(const FLAC__byte value
[16]);
340 /** PADDING metadata block.
341 * See the \link flacpp_metadata_object overview \endlink for more,
342 * and the <A HREF="../format.html#metadata_block_padding">format specification</A>.
344 class FLACPP_API Padding
: public Prototype
{
349 /** Constructs a copy of the given object. This form
350 * always performs a deep copy.
352 inline Padding(const Padding
&object
): Prototype(object
) { }
353 inline Padding(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
354 inline Padding(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
357 /** Constructs an object with copy control. See
358 * Prototype(::FLAC__StreamMetadata *object, bool copy).
360 inline Padding(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
365 /** Assign from another object. Always performs a deep copy. */
366 inline Padding
&operator=(const Padding
&object
) { Prototype::operator=(object
); return *this; }
367 inline Padding
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
368 inline Padding
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
371 /** Assigns an object with copy control. See
372 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
374 inline Padding
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
377 /** Check for equality, performing a deep compare by following pointers. */
378 inline bool operator==(const Padding
&object
) const { return Prototype::operator==(object
); }
379 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
380 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
384 /** Check for inequality, performing a deep compare by following pointers. */
385 inline bool operator!=(const Padding
&object
) const { return Prototype::operator!=(object
); }
386 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
387 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
390 void set_length(unsigned length
);
393 /** APPLICATION metadata block.
394 * See the \link flacpp_metadata_object overview \endlink for more,
395 * and the <A HREF="../format.html#metadata_block_application">format specification</A>.
397 class FLACPP_API Application
: public Prototype
{
402 /** Constructs a copy of the given object. This form
403 * always performs a deep copy.
405 inline Application(const Application
&object
): Prototype(object
) { }
406 inline Application(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
407 inline Application(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
410 /** Constructs an object with copy control. See
411 * Prototype(::FLAC__StreamMetadata *object, bool copy).
413 inline Application(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
418 /** Assign from another object. Always performs a deep copy. */
419 inline Application
&operator=(const Application
&object
) { Prototype::operator=(object
); return *this; }
420 inline Application
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
421 inline Application
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
424 /** Assigns an object with copy control. See
425 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
427 inline Application
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
430 /** Check for equality, performing a deep compare by following pointers. */
431 inline bool operator==(const Application
&object
) const { return Prototype::operator==(object
); }
432 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
433 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
437 /** Check for inequality, performing a deep compare by following pointers. */
438 inline bool operator!=(const Application
&object
) const { return Prototype::operator!=(object
); }
439 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
440 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
443 const FLAC__byte
*get_id() const;
444 const FLAC__byte
*get_data() const;
446 void set_id(const FLAC__byte value
[4]);
447 //! This form always copies \a data
448 bool set_data(const FLAC__byte
*data
, unsigned length
);
449 bool set_data(FLAC__byte
*data
, unsigned length
, bool copy
);
452 /** SEEKTABLE metadata block.
453 * See the \link flacpp_metadata_object overview \endlink for more,
454 * and the <A HREF="../format.html#metadata_block_seektable">format specification</A>.
456 class FLACPP_API SeekTable
: public Prototype
{
461 /** Constructs a copy of the given object. This form
462 * always performs a deep copy.
464 inline SeekTable(const SeekTable
&object
): Prototype(object
) { }
465 inline SeekTable(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
466 inline SeekTable(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
469 /** Constructs an object with copy control. See
470 * Prototype(::FLAC__StreamMetadata *object, bool copy).
472 inline SeekTable(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
477 /** Assign from another object. Always performs a deep copy. */
478 inline SeekTable
&operator=(const SeekTable
&object
) { Prototype::operator=(object
); return *this; }
479 inline SeekTable
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
480 inline SeekTable
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
483 /** Assigns an object with copy control. See
484 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
486 inline SeekTable
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
489 /** Check for equality, performing a deep compare by following pointers. */
490 inline bool operator==(const SeekTable
&object
) const { return Prototype::operator==(object
); }
491 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
492 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
496 /** Check for inequality, performing a deep compare by following pointers. */
497 inline bool operator!=(const SeekTable
&object
) const { return Prototype::operator!=(object
); }
498 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
499 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
502 unsigned get_num_points() const;
503 ::FLAC__StreamMetadata_SeekPoint
get_point(unsigned index
) const;
505 //! See FLAC__metadata_object_seektable_resize_points()
506 bool resize_points(unsigned new_num_points
);
508 //! See FLAC__metadata_object_seektable_set_point()
509 void set_point(unsigned index
, const ::FLAC__StreamMetadata_SeekPoint
&point
);
511 //! See FLAC__metadata_object_seektable_insert_point()
512 bool insert_point(unsigned index
, const ::FLAC__StreamMetadata_SeekPoint
&point
);
514 //! See FLAC__metadata_object_seektable_delete_point()
515 bool delete_point(unsigned index
);
517 //! See FLAC__metadata_object_seektable_is_legal()
518 bool is_legal() const;
520 //! See FLAC__metadata_object_seektable_template_append_placeholders()
521 bool template_append_placeholders(unsigned num
);
523 //! See FLAC__metadata_object_seektable_template_append_point()
524 bool template_append_point(FLAC__uint64 sample_number
);
526 //! See FLAC__metadata_object_seektable_template_append_points()
527 bool template_append_points(FLAC__uint64 sample_numbers
[], unsigned num
);
529 //! See FLAC__metadata_object_seektable_template_append_spaced_points()
530 bool template_append_spaced_points(unsigned num
, FLAC__uint64 total_samples
);
532 //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
533 bool template_append_spaced_points_by_samples(unsigned samples
, FLAC__uint64 total_samples
);
535 //! See FLAC__metadata_object_seektable_template_sort()
536 bool template_sort(bool compact
);
539 /** VORBIS_COMMENT metadata block.
540 * See the \link flacpp_metadata_object overview \endlink for more,
541 * and the <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
543 class FLACPP_API VorbisComment
: public Prototype
{
545 /** Convenience class for encapsulating Vorbis comment
546 * entries. An entry is a vendor string or a comment
547 * field. In the case of a vendor string, the field
548 * name is undefined; only the field value is relevant.
550 * A \a field as used in the methods refers to an
551 * entire 'NAME=VALUE' string; for convenience the
552 * string is NUL-terminated. A length field is
553 * required in the unlikely event that the value
554 * contains contain embedded NULs.
556 * A \a field_name is what is on the left side of the
557 * first '=' in the \a field. By definition it is ASCII
558 * and so is NUL-terminated and does not require a
559 * length to describe it. \a field_name is undefined
560 * for a vendor string entry.
562 * A \a field_value is what is on the right side of the
563 * first '=' in the \a field. By definition, this may
564 * contain embedded NULs and so a \a field_value_length
565 * is required to describe it. However in practice,
566 * embedded NULs are not known to be used, so it is
567 * generally safe to treat field values as NUL-
568 * terminated UTF-8 strings.
570 * Always check is_valid() after the constructor or operator=
571 * to make sure memory was properly allocated and that the
572 * Entry conforms to the Vorbis comment specification.
574 class FLACPP_API Entry
{
578 Entry(const char *field
, unsigned field_length
);
579 Entry(const char *field
); // assumes \a field is NUL-terminated
581 Entry(const char *field_name
, const char *field_value
, unsigned field_value_length
);
582 Entry(const char *field_name
, const char *field_value
); // assumes \a field_value is NUL-terminated
584 Entry(const Entry
&entry
);
586 Entry
&operator=(const Entry
&entry
);
590 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
592 unsigned get_field_length() const;
593 unsigned get_field_name_length() const;
594 unsigned get_field_value_length() const;
596 ::FLAC__StreamMetadata_VorbisComment_Entry
get_entry() const;
597 const char *get_field() const;
598 const char *get_field_name() const;
599 const char *get_field_value() const;
601 bool set_field(const char *field
, unsigned field_length
);
602 bool set_field(const char *field
); // assumes \a field is NUL-terminated
603 bool set_field_name(const char *field_name
);
604 bool set_field_value(const char *field_value
, unsigned field_value_length
);
605 bool set_field_value(const char *field_value
); // assumes \a field_value is NUL-terminated
608 ::FLAC__StreamMetadata_VorbisComment_Entry entry_
;
610 unsigned field_name_length_
;
612 unsigned field_value_length_
;
617 void clear_field_name();
618 void clear_field_value();
619 void construct(const char *field
, unsigned field_length
);
620 void construct(const char *field
); // assumes \a field is NUL-terminated
621 void construct(const char *field_name
, const char *field_value
, unsigned field_value_length
);
622 void construct(const char *field_name
, const char *field_value
); // assumes \a field_value is NUL-terminated
623 void compose_field();
630 /** Constructs a copy of the given object. This form
631 * always performs a deep copy.
633 inline VorbisComment(const VorbisComment
&object
): Prototype(object
) { }
634 inline VorbisComment(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
635 inline VorbisComment(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
638 /** Constructs an object with copy control. See
639 * Prototype(::FLAC__StreamMetadata *object, bool copy).
641 inline VorbisComment(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
646 /** Assign from another object. Always performs a deep copy. */
647 inline VorbisComment
&operator=(const VorbisComment
&object
) { Prototype::operator=(object
); return *this; }
648 inline VorbisComment
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
649 inline VorbisComment
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
652 /** Assigns an object with copy control. See
653 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
655 inline VorbisComment
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
658 /** Check for equality, performing a deep compare by following pointers. */
659 inline bool operator==(const VorbisComment
&object
) const { return Prototype::operator==(object
); }
660 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
661 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
665 /** Check for inequality, performing a deep compare by following pointers. */
666 inline bool operator!=(const VorbisComment
&object
) const { return Prototype::operator!=(object
); }
667 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
668 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
671 unsigned get_num_comments() const;
672 const FLAC__byte
*get_vendor_string() const; // NUL-terminated UTF-8 string
673 Entry
get_comment(unsigned index
) const;
675 //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
676 bool set_vendor_string(const FLAC__byte
*string
); // NUL-terminated UTF-8 string
678 //! See FLAC__metadata_object_vorbiscomment_resize_comments()
679 bool resize_comments(unsigned new_num_comments
);
681 //! See FLAC__metadata_object_vorbiscomment_set_comment()
682 bool set_comment(unsigned index
, const Entry
&entry
);
684 //! See FLAC__metadata_object_vorbiscomment_insert_comment()
685 bool insert_comment(unsigned index
, const Entry
&entry
);
687 //! See FLAC__metadata_object_vorbiscomment_append_comment()
688 bool append_comment(const Entry
&entry
);
690 //! See FLAC__metadata_object_vorbiscomment_replace_comment()
691 bool replace_comment(const Entry
&entry
, bool all
);
693 //! See FLAC__metadata_object_vorbiscomment_delete_comment()
694 bool delete_comment(unsigned index
);
696 //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
697 int find_entry_from(unsigned offset
, const char *field_name
);
699 //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
700 int remove_entry_matching(const char *field_name
);
702 //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
703 int remove_entries_matching(const char *field_name
);
706 /** CUESHEET metadata block.
707 * See the \link flacpp_metadata_object overview \endlink for more,
708 * and the <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
710 class FLACPP_API CueSheet
: public Prototype
{
712 /** Convenience class for encapsulating a cue sheet
715 * Always check is_valid() after the constructor or operator=
716 * to make sure memory was properly allocated.
718 class FLACPP_API Track
{
720 ::FLAC__StreamMetadata_CueSheet_Track
*object_
;
723 Track(const ::FLAC__StreamMetadata_CueSheet_Track
*track
);
724 Track(const Track
&track
);
725 Track
&operator=(const Track
&track
);
729 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
732 inline FLAC__uint64
get_offset() const { return object_
->offset
; }
733 inline FLAC__byte
get_number() const { return object_
->number
; }
734 inline const char *get_isrc() const { return object_
->isrc
; }
735 inline unsigned get_type() const { return object_
->type
; }
736 inline bool get_pre_emphasis() const { return object_
->pre_emphasis
; }
738 inline FLAC__byte
get_num_indices() const { return object_
->num_indices
; }
739 ::FLAC__StreamMetadata_CueSheet_Index
get_index(unsigned i
) const;
741 inline const ::FLAC__StreamMetadata_CueSheet_Track
*get_track() const { return object_
; }
743 inline void set_offset(FLAC__uint64 value
) { object_
->offset
= value
; }
744 inline void set_number(FLAC__byte value
) { object_
->number
= value
; }
745 void set_isrc(const char value
[12]);
746 void set_type(unsigned value
);
747 inline void set_pre_emphasis(bool value
) { object_
->pre_emphasis
= value
? 1 : 0; }
749 void set_index(unsigned i
, const ::FLAC__StreamMetadata_CueSheet_Index
&index
);
750 //@@@ It's awkward but to insert/delete index points
751 //@@@ you must use the routines in the CueSheet class.
757 /** Constructs a copy of the given object. This form
758 * always performs a deep copy.
760 inline CueSheet(const CueSheet
&object
): Prototype(object
) { }
761 inline CueSheet(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
762 inline CueSheet(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
765 /** Constructs an object with copy control. See
766 * Prototype(::FLAC__StreamMetadata *object, bool copy).
768 inline CueSheet(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
773 /** Assign from another object. Always performs a deep copy. */
774 inline CueSheet
&operator=(const CueSheet
&object
) { Prototype::operator=(object
); return *this; }
775 inline CueSheet
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
776 inline CueSheet
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
779 /** Assigns an object with copy control. See
780 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
782 inline CueSheet
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
785 /** Check for equality, performing a deep compare by following pointers. */
786 inline bool operator==(const CueSheet
&object
) const { return Prototype::operator==(object
); }
787 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
788 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
792 /** Check for inequality, performing a deep compare by following pointers. */
793 inline bool operator!=(const CueSheet
&object
) const { return Prototype::operator!=(object
); }
794 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
795 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
798 const char *get_media_catalog_number() const;
799 FLAC__uint64
get_lead_in() const;
800 bool get_is_cd() const;
802 unsigned get_num_tracks() const;
803 Track
get_track(unsigned i
) const;
805 void set_media_catalog_number(const char value
[128]);
806 void set_lead_in(FLAC__uint64 value
);
807 void set_is_cd(bool value
);
809 void set_index(unsigned track_num
, unsigned index_num
, const ::FLAC__StreamMetadata_CueSheet_Index
&index
);
811 //! See FLAC__metadata_object_cuesheet_track_insert_index()
812 bool insert_index(unsigned track_num
, unsigned index_num
, const ::FLAC__StreamMetadata_CueSheet_Index
&index
);
814 //! See FLAC__metadata_object_cuesheet_track_delete_index()
815 bool delete_index(unsigned track_num
, unsigned index_num
);
817 //! See FLAC__metadata_object_cuesheet_set_track()
818 bool set_track(unsigned i
, const Track
&track
);
820 //! See FLAC__metadata_object_cuesheet_insert_track()
821 bool insert_track(unsigned i
, const Track
&track
);
823 //! See FLAC__metadata_object_cuesheet_delete_track()
824 bool delete_track(unsigned i
);
826 //! See FLAC__metadata_object_cuesheet_is_legal()
827 bool is_legal(bool check_cd_da_subset
= false, const char **violation
= 0) const;
829 //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
830 FLAC__uint32
calculate_cddb_id() const;
833 /** PICTURE metadata block.
834 * See the \link flacpp_metadata_object overview \endlink for more,
835 * and the <A HREF="../format.html#metadata_block_picture">format specification</A>.
837 class FLACPP_API Picture
: public Prototype
{
842 /** Constructs a copy of the given object. This form
843 * always performs a deep copy.
845 inline Picture(const Picture
&object
): Prototype(object
) { }
846 inline Picture(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
847 inline Picture(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
850 /** Constructs an object with copy control. See
851 * Prototype(::FLAC__StreamMetadata *object, bool copy).
853 inline Picture(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
858 /** Assign from another object. Always performs a deep copy. */
859 inline Picture
&operator=(const Picture
&object
) { Prototype::operator=(object
); return *this; }
860 inline Picture
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
861 inline Picture
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
864 /** Assigns an object with copy control. See
865 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
867 inline Picture
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
870 /** Check for equality, performing a deep compare by following pointers. */
871 inline bool operator==(const Picture
&object
) const { return Prototype::operator==(object
); }
872 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
873 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
877 /** Check for inequality, performing a deep compare by following pointers. */
878 inline bool operator!=(const Picture
&object
) const { return Prototype::operator!=(object
); }
879 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
880 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
883 ::FLAC__StreamMetadata_Picture_Type
get_type() const;
884 const char *get_mime_type() const; // NUL-terminated printable ASCII string
885 const FLAC__byte
*get_description() const; // NUL-terminated UTF-8 string
886 FLAC__uint32
get_width() const;
887 FLAC__uint32
get_height() const;
888 FLAC__uint32
get_depth() const;
889 FLAC__uint32
get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
890 FLAC__uint32
get_data_length() const;
891 const FLAC__byte
*get_data() const;
893 void set_type(::FLAC__StreamMetadata_Picture_Type type
);
895 //! See FLAC__metadata_object_picture_set_mime_type()
896 bool set_mime_type(const char *string
); // NUL-terminated printable ASCII string
898 //! See FLAC__metadata_object_picture_set_description()
899 bool set_description(const FLAC__byte
*string
); // NUL-terminated UTF-8 string
901 void set_width(FLAC__uint32 value
) const;
902 void set_height(FLAC__uint32 value
) const;
903 void set_depth(FLAC__uint32 value
) const;
904 void set_colors(FLAC__uint32 value
) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
906 //! See FLAC__metadata_object_picture_set_data()
907 bool set_data(const FLAC__byte
*data
, FLAC__uint32 data_length
);
910 /** Opaque metadata block for storing unknown types.
911 * This should not be used unless you know what you are doing;
912 * it is currently used only internally to support forward
913 * compatibility of metadata blocks.
914 * See the \link flacpp_metadata_object overview \endlink for more,
916 class FLACPP_API Unknown
: public Prototype
{
921 /** Constructs a copy of the given object. This form
922 * always performs a deep copy.
924 inline Unknown(const Unknown
&object
): Prototype(object
) { }
925 inline Unknown(const ::FLAC__StreamMetadata
&object
): Prototype(object
) { }
926 inline Unknown(const ::FLAC__StreamMetadata
*object
): Prototype(object
) { }
929 /** Constructs an object with copy control. See
930 * Prototype(::FLAC__StreamMetadata *object, bool copy).
932 inline Unknown(::FLAC__StreamMetadata
*object
, bool copy
): Prototype(object
, copy
) { }
937 /** Assign from another object. Always performs a deep copy. */
938 inline Unknown
&operator=(const Unknown
&object
) { Prototype::operator=(object
); return *this; }
939 inline Unknown
&operator=(const ::FLAC__StreamMetadata
&object
) { Prototype::operator=(object
); return *this; }
940 inline Unknown
&operator=(const ::FLAC__StreamMetadata
*object
) { Prototype::operator=(object
); return *this; }
943 /** Assigns an object with copy control. See
944 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
946 inline Unknown
&assign(::FLAC__StreamMetadata
*object
, bool copy
) { Prototype::assign_object(object
, copy
); return *this; }
949 /** Check for equality, performing a deep compare by following pointers. */
950 inline bool operator==(const Unknown
&object
) const { return Prototype::operator==(object
); }
951 inline bool operator==(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator==(object
); }
952 inline bool operator==(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator==(object
); }
956 /** Check for inequality, performing a deep compare by following pointers. */
957 inline bool operator!=(const Unknown
&object
) const { return Prototype::operator!=(object
); }
958 inline bool operator!=(const ::FLAC__StreamMetadata
&object
) const { return Prototype::operator!=(object
); }
959 inline bool operator!=(const ::FLAC__StreamMetadata
*object
) const { return Prototype::operator!=(object
); }
962 const FLAC__byte
*get_data() const;
964 //! This form always copies \a data
965 bool set_data(const FLAC__byte
*data
, unsigned length
);
966 bool set_data(FLAC__byte
*data
, unsigned length
, bool copy
);
972 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
973 * \ingroup flacpp_metadata
976 * Level 0 metadata iterators.
978 * See the \link flac_metadata_level0 C layer equivalent \endlink
984 FLACPP_API
bool get_streaminfo(const char *filename
, StreamInfo
&streaminfo
); ///< See FLAC__metadata_get_streaminfo().
986 FLACPP_API
bool get_tags(const char *filename
, VorbisComment
*&tags
); ///< See FLAC__metadata_get_tags().
987 FLACPP_API
bool get_tags(const char *filename
, VorbisComment
&tags
); ///< See FLAC__metadata_get_tags().
989 FLACPP_API
bool get_cuesheet(const char *filename
, CueSheet
*&cuesheet
); ///< See FLAC__metadata_get_cuesheet().
990 FLACPP_API
bool get_cuesheet(const char *filename
, CueSheet
&cuesheet
); ///< See FLAC__metadata_get_cuesheet().
992 FLACPP_API
bool get_picture(const char *filename
, Picture
*&picture
, ::FLAC__StreamMetadata_Picture_Type type
, const char *mime_type
, const FLAC__byte
*description
, unsigned max_width
, unsigned max_height
, unsigned max_depth
, unsigned max_colors
); ///< See FLAC__metadata_get_picture().
993 FLACPP_API
bool get_picture(const char *filename
, Picture
&picture
, ::FLAC__StreamMetadata_Picture_Type type
, const char *mime_type
, const FLAC__byte
*description
, unsigned max_width
, unsigned max_height
, unsigned max_depth
, unsigned max_colors
); ///< See FLAC__metadata_get_picture().
998 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
999 * \ingroup flacpp_metadata
1002 * Level 1 metadata iterator.
1004 * The flow through the iterator in the C++ layer is similar
1006 * - Create a SimpleIterator instance
1007 * - Check SimpleIterator::is_valid()
1008 * - Call SimpleIterator::init() and check the return
1009 * - Traverse and/or edit. Edits are written to file
1011 * - Destroy the SimpleIterator instance
1013 * The ownership of pointers in the C++ layer follows that in
1015 * - The objects returned by get_block() are yours to
1016 * modify, but changes are not reflected in the FLAC file
1017 * until you call set_block(). The objects are also
1018 * yours to delete; they are not automatically deleted
1019 * when passed to set_block() or insert_block_after().
1021 * See the \link flac_metadata_level1 C layer equivalent \endlink
1027 /** This class is a wrapper around the FLAC__metadata_simple_iterator
1028 * structures and methods; see the
1029 * \link flacpp_metadata_level1 usage guide \endlink and
1030 * ::FLAC__Metadata_SimpleIterator.
1032 class FLACPP_API SimpleIterator
{
1034 /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
1036 class FLACPP_API Status
{
1038 inline Status(::FLAC__Metadata_SimpleIteratorStatus status
): status_(status
) { }
1039 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_
; }
1040 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString
[status_
]; }
1042 ::FLAC__Metadata_SimpleIteratorStatus status_
;
1046 virtual ~SimpleIterator();
1048 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1050 bool init(const char *filename
, bool read_only
, bool preserve_file_stats
); ///< See FLAC__metadata_simple_iterator_init().
1052 Status
status(); ///< See FLAC__metadata_simple_iterator_status().
1053 bool is_writable() const; ///< See FLAC__metadata_simple_iterator_is_writable().
1055 bool next(); ///< See FLAC__metadata_simple_iterator_next().
1056 bool prev(); ///< See FLAC__metadata_simple_iterator_prev().
1057 bool is_last() const; ///< See FLAC__metadata_simple_iterator_is_last().
1059 off_t
get_block_offset() const; ///< See FLAC__metadata_simple_iterator_get_block_offset().
1060 ::FLAC__MetadataType
get_block_type() const; ///< See FLAC__metadata_simple_iterator_get_block_type().
1061 unsigned get_block_length() const; ///< See FLAC__metadata_simple_iterator_get_block_length().
1062 bool get_application_id(FLAC__byte
*id
); ///< See FLAC__metadata_simple_iterator_get_application_id().
1063 Prototype
*get_block(); ///< See FLAC__metadata_simple_iterator_get_block().
1064 bool set_block(Prototype
*block
, bool use_padding
= true); ///< See FLAC__metadata_simple_iterator_set_block().
1065 bool insert_block_after(Prototype
*block
, bool use_padding
= true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
1066 bool delete_block(bool use_padding
= true); ///< See FLAC__metadata_simple_iterator_delete_block().
1069 ::FLAC__Metadata_SimpleIterator
*iterator_
;
1076 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
1077 * \ingroup flacpp_metadata
1080 * Level 2 metadata iterator.
1082 * The flow through the iterator in the C++ layer is similar
1084 * - Create a Chain instance
1085 * - Check Chain::is_valid()
1086 * - Call Chain::read() and check the return
1087 * - Traverse and/or edit with an Iterator or with
1088 * Chain::merge_padding() or Chain::sort_padding()
1089 * - Write changes back to FLAC file with Chain::write()
1090 * - Destroy the Chain instance
1092 * The ownership of pointers in the C++ layer is slightly
1093 * different than in the C layer, i.e.
1094 * - The objects returned by Iterator::get_block() are NOT
1095 * owned by the iterator and should be deleted by the
1096 * caller when finished, BUT, when you modify the block,
1097 * it will directly edit what's in the chain and you do
1098 * not need to call Iterator::set_block(). However the
1099 * changes will not be reflected in the FLAC file until
1100 * the chain is written with Chain::write().
1101 * - When you pass an object to Iterator::set_block(),
1102 * Iterator::insert_block_before(), or
1103 * Iterator::insert_block_after(), the iterator takes
1104 * ownership of the block and it will be deleted by the
1107 * See the \link flac_metadata_level2 C layer equivalent \endlink
1113 /** This class is a wrapper around the FLAC__metadata_chain
1114 * structures and methods; see the
1115 * \link flacpp_metadata_level2 usage guide \endlink and
1116 * ::FLAC__Metadata_Chain.
1118 class FLACPP_API Chain
{
1120 /** This class is a wrapper around FLAC__Metadata_ChainStatus.
1122 class FLACPP_API Status
{
1124 inline Status(::FLAC__Metadata_ChainStatus status
): status_(status
) { }
1125 inline operator ::FLAC__Metadata_ChainStatus() const { return status_
; }
1126 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString
[status_
]; }
1128 ::FLAC__Metadata_ChainStatus status_
;
1134 friend class Iterator
;
1136 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1138 Status
status(); ///< See FLAC__metadata_chain_status().
1140 bool read(const char *filename
, bool is_ogg
= false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
1141 bool read(FLAC__IOHandle handle
, FLAC__IOCallbacks callbacks
, bool is_ogg
= false); ///< See FLAC__metadata_chain_read_with_callbacks(), FLAC__metadata_chain_read_ogg_with_callbacks().
1143 bool check_if_tempfile_needed(bool use_padding
); ///< See FLAC__metadata_chain_check_if_tempfile_needed().
1145 bool write(bool use_padding
= true, bool preserve_file_stats
= false); ///< See FLAC__metadata_chain_write().
1146 bool write(bool use_padding
, ::FLAC__IOHandle handle
, ::FLAC__IOCallbacks callbacks
); ///< See FLAC__metadata_chain_write_with_callbacks().
1147 bool write(bool use_padding
, ::FLAC__IOHandle handle
, ::FLAC__IOCallbacks callbacks
, ::FLAC__IOHandle temp_handle
, ::FLAC__IOCallbacks temp_callbacks
); ///< See FLAC__metadata_chain_write_with_callbacks_and_tempfile().
1149 void merge_padding(); ///< See FLAC__metadata_chain_merge_padding().
1150 void sort_padding(); ///< See FLAC__metadata_chain_sort_padding().
1153 ::FLAC__Metadata_Chain
*chain_
;
1154 virtual void clear();
1157 /** This class is a wrapper around the FLAC__metadata_iterator
1158 * structures and methods; see the
1159 * \link flacpp_metadata_level2 usage guide \endlink and
1160 * ::FLAC__Metadata_Iterator.
1162 class FLACPP_API Iterator
{
1165 virtual ~Iterator();
1167 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1170 void init(Chain
&chain
); ///< See FLAC__metadata_iterator_init().
1172 bool next(); ///< See FLAC__metadata_iterator_next().
1173 bool prev(); ///< See FLAC__metadata_iterator_prev().
1175 ::FLAC__MetadataType
get_block_type() const; ///< See FLAC__metadata_iterator_get_block_type().
1176 Prototype
*get_block(); ///< See FLAC__metadata_iterator_get_block().
1177 bool set_block(Prototype
*block
); ///< See FLAC__metadata_iterator_set_block().
1178 bool delete_block(bool replace_with_padding
); ///< See FLAC__metadata_iterator_delete_block().
1179 bool insert_block_before(Prototype
*block
); ///< See FLAC__metadata_iterator_insert_block_before().
1180 bool insert_block_after(Prototype
*block
); ///< See FLAC__metadata_iterator_insert_block_after().
1183 ::FLAC__Metadata_Iterator
*iterator_
;
1184 virtual void clear();