1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002-2009 Josh Coalson
3 * Copyright (C) 2011-2016 Xiph.Org Foundation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * - Neither the name of the Xiph.org Foundation nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef FLACPP__METADATA_H
34 #define FLACPP__METADATA_H
38 #include "FLAC/metadata.h"
40 // ===============================================================
42 // Full documentation for the metadata interface can be found
43 // in the C layer in include/FLAC/metadata.h
45 // ===============================================================
47 /** \file include/FLAC++/metadata.h
50 * This module provides classes for creating and manipulating FLAC
51 * metadata blocks in memory, and three progressively more powerful
52 * interfaces for traversing and editing metadata in FLAC files.
54 * See the detailed documentation for each interface in the
55 * \link flacpp_metadata metadata \endlink module.
58 /** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
62 * This module provides classes for creating and manipulating FLAC
63 * metadata blocks in memory, and three progressively more powerful
64 * interfaces for traversing and editing metadata in FLAC files.
66 * The behavior closely mimics the C layer interface; be sure to read
67 * the detailed description of the
68 * \link flac_metadata C metadata module \endlink. Note that like the
69 * C layer, currently only the Chain interface (level 2) supports Ogg
70 * FLAC files, and it is read-only i.e. no writing back changed
78 // ============================================================
82 // ============================================================
84 /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
85 * \ingroup flacpp_metadata
87 * This module contains classes representing FLAC metadata
90 * The behavior closely mimics the C layer interface; be
91 * sure to read the detailed description of the
92 * \link flac_metadata_object C metadata object module \endlink.
94 * Any time a metadata object is constructed or assigned, you
95 * should check is_valid() to make sure the underlying
96 * ::FLAC__StreamMetadata object was able to be created.
99 * When the get_*() methods of any metadata object method
100 * return you a const pointer, DO NOT disobey and write into it.
101 * Always use the set_*() methods.
106 /** Base class for all metadata block types.
107 * See the \link flacpp_metadata_object overview \endlink for more.
109 class FLACPP_API Prototype {
112 /** Constructs a copy of the given object. This form
113 * always performs a deep copy.
115 Prototype(const Prototype &);
116 Prototype(const ::FLAC__StreamMetadata &);
117 Prototype(const ::FLAC__StreamMetadata *);
120 /** Constructs an object with copy control. When \a copy
121 * is \c true, behaves identically to
122 * FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
123 * When \a copy is \c false, the instance takes ownership of
124 * the pointer and the ::FLAC__StreamMetadata object will
125 * be freed by the destructor.
128 * \code object != NULL \endcode
130 Prototype(::FLAC__StreamMetadata *object, bool copy);
133 /** Assign from another object. Always performs a deep copy. */
134 Prototype &operator=(const Prototype &);
135 Prototype &operator=(const ::FLAC__StreamMetadata &);
136 Prototype &operator=(const ::FLAC__StreamMetadata *);
139 /** Assigns an object with copy control. See
140 * Prototype(::FLAC__StreamMetadata *object, bool copy).
142 Prototype &assign_object(::FLAC__StreamMetadata *object, bool copy);
144 /** Deletes the underlying ::FLAC__StreamMetadata object.
146 virtual void clear();
148 ::FLAC__StreamMetadata *object_;
150 /** Deletes the underlying ::FLAC__StreamMetadata object.
152 virtual ~Prototype();
155 /** Check for equality, performing a deep compare by following pointers.
157 inline bool operator==(const Prototype &) const;
158 inline bool operator==(const ::FLAC__StreamMetadata &) const;
159 inline bool operator==(const ::FLAC__StreamMetadata *) const;
163 /** Check for inequality, performing a deep compare by following pointers. */
164 inline bool operator!=(const Prototype &) const;
165 inline bool operator!=(const ::FLAC__StreamMetadata &) const;
166 inline bool operator!=(const ::FLAC__StreamMetadata *) const;
169 friend class SimpleIterator;
170 friend class Iterator;
172 /** Returns \c true if the object was correctly constructed
173 * (i.e. the underlying ::FLAC__StreamMetadata object was
174 * properly allocated), else \c false.
176 inline bool is_valid() const;
178 /** Returns \c true if this block is the last block in a
179 * stream, else \c false.
182 * \code is_valid() \endcode
184 bool get_is_last() const;
186 /** Returns the type of the block.
189 * \code is_valid() \endcode
191 ::FLAC__MetadataType get_type() const;
193 /** Returns the stream length of the metadata block.
196 * The length does not include the metadata block header,
200 * \code is_valid() \endcode
202 unsigned get_length() const;
204 /** Sets the "is_last" flag for the block. When using the iterators
205 * it is not necessary to set this flag; they will do it for you.
208 * \code is_valid() \endcode
210 void set_is_last(bool);
212 /** Returns a pointer to the underlying ::FLAC__StreamMetadata
213 * object. This can be useful for plugging any holes between
214 * the C++ and C interfaces.
217 * \code is_valid() \endcode
219 inline operator const ::FLAC__StreamMetadata *() const;
221 /** Private and undefined so you can't use it. */
224 // These are used only by Iterator
226 inline void set_reference(bool x) { is_reference_ = x; }
230 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
231 #pragma warning ( disable : 4800 )
234 inline bool Prototype::operator==(const Prototype &object) const
235 { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
237 inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
238 { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
240 inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
241 { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
244 #pragma warning ( default : 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) { }
362 /** Constructs an object with the given length.
364 Padding(unsigned length);
369 /** Assign from another object. Always performs a deep copy. */
370 inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; }
371 inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
372 inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
375 /** Assigns an object with copy control. See
376 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
378 inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
381 /** Check for equality, performing a deep compare by following pointers. */
382 inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
383 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
384 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
388 /** Check for inequality, performing a deep compare by following pointers. */
389 inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
390 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
391 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
394 /** Sets the length in bytes of the padding block.
396 void set_length(unsigned length);
399 /** APPLICATION metadata block.
400 * See the \link flacpp_metadata_object overview \endlink for more,
401 * and the <A HREF="../format.html#metadata_block_application">format specification</A>.
403 class FLACPP_API Application : public Prototype {
408 /** Constructs a copy of the given object. This form
409 * always performs a deep copy.
411 inline Application(const Application &object): Prototype(object) { }
412 inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
413 inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
416 /** Constructs an object with copy control. See
417 * Prototype(::FLAC__StreamMetadata *object, bool copy).
419 inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
424 /** Assign from another object. Always performs a deep copy. */
425 inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; }
426 inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
427 inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
430 /** Assigns an object with copy control. See
431 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
433 inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
436 /** Check for equality, performing a deep compare by following pointers. */
437 inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
438 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
439 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
443 /** Check for inequality, performing a deep compare by following pointers. */
444 inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
445 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
446 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
449 const FLAC__byte *get_id() const;
450 const FLAC__byte *get_data() const;
452 void set_id(const FLAC__byte value[4]);
453 //! This form always copies \a data
454 bool set_data(const FLAC__byte *data, unsigned length);
455 bool set_data(FLAC__byte *data, unsigned length, bool copy);
458 /** SEEKTABLE metadata block.
459 * See the \link flacpp_metadata_object overview \endlink for more,
460 * and the <A HREF="../format.html#metadata_block_seektable">format specification</A>.
462 class FLACPP_API SeekTable : public Prototype {
467 /** Constructs a copy of the given object. This form
468 * always performs a deep copy.
470 inline SeekTable(const SeekTable &object): Prototype(object) { }
471 inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
472 inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
475 /** Constructs an object with copy control. See
476 * Prototype(::FLAC__StreamMetadata *object, bool copy).
478 inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
483 /** Assign from another object. Always performs a deep copy. */
484 inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; }
485 inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
486 inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
489 /** Assigns an object with copy control. See
490 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
492 inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
495 /** Check for equality, performing a deep compare by following pointers. */
496 inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
497 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
498 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
502 /** Check for inequality, performing a deep compare by following pointers. */
503 inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
504 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
505 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
508 unsigned get_num_points() const;
509 ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const;
511 //! See FLAC__metadata_object_seektable_resize_points()
512 bool resize_points(unsigned new_num_points);
514 //! See FLAC__metadata_object_seektable_set_point()
515 void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
517 //! See FLAC__metadata_object_seektable_insert_point()
518 bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
520 //! See FLAC__metadata_object_seektable_delete_point()
521 bool delete_point(unsigned index);
523 //! See FLAC__metadata_object_seektable_is_legal()
524 bool is_legal() const;
526 //! See FLAC__metadata_object_seektable_template_append_placeholders()
527 bool template_append_placeholders(unsigned num);
529 //! See FLAC__metadata_object_seektable_template_append_point()
530 bool template_append_point(FLAC__uint64 sample_number);
532 //! See FLAC__metadata_object_seektable_template_append_points()
533 bool template_append_points(FLAC__uint64 sample_numbers[], unsigned num);
535 //! See FLAC__metadata_object_seektable_template_append_spaced_points()
536 bool template_append_spaced_points(unsigned num, FLAC__uint64 total_samples);
538 //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
539 bool template_append_spaced_points_by_samples(unsigned samples, FLAC__uint64 total_samples);
541 //! See FLAC__metadata_object_seektable_template_sort()
542 bool template_sort(bool compact);
545 /** VORBIS_COMMENT metadata block.
546 * See the \link flacpp_metadata_object overview \endlink for more,
547 * and the <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
549 class FLACPP_API VorbisComment : public Prototype {
551 /** Convenience class for encapsulating Vorbis comment
552 * entries. An entry is a vendor string or a comment
553 * field. In the case of a vendor string, the field
554 * name is undefined; only the field value is relevant.
556 * A \a field as used in the methods refers to an
557 * entire 'NAME=VALUE' string; for convenience the
558 * string is NUL-terminated. A length field is
559 * required in the unlikely event that the value
560 * contains contain embedded NULs.
562 * A \a field_name is what is on the left side of the
563 * first '=' in the \a field. By definition it is ASCII
564 * and so is NUL-terminated and does not require a
565 * length to describe it. \a field_name is undefined
566 * for a vendor string entry.
568 * A \a field_value is what is on the right side of the
569 * first '=' in the \a field. By definition, this may
570 * contain embedded NULs and so a \a field_value_length
571 * is required to describe it. However in practice,
572 * embedded NULs are not known to be used, so it is
573 * generally safe to treat field values as NUL-
574 * terminated UTF-8 strings.
576 * Always check is_valid() after the constructor or operator=
577 * to make sure memory was properly allocated and that the
578 * Entry conforms to the Vorbis comment specification.
580 class FLACPP_API Entry {
584 Entry(const char *field, unsigned field_length);
585 Entry(const char *field); // assumes \a field is NUL-terminated
587 Entry(const char *field_name, const char *field_value, unsigned field_value_length);
588 Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
590 Entry(const Entry &entry);
592 Entry &operator=(const Entry &entry);
596 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
598 unsigned get_field_length() const;
599 unsigned get_field_name_length() const;
600 unsigned get_field_value_length() const;
602 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
603 const char *get_field() const;
604 const char *get_field_name() const;
605 const char *get_field_value() const;
607 bool set_field(const char *field, unsigned field_length);
608 bool set_field(const char *field); // assumes \a field is NUL-terminated
609 bool set_field_name(const char *field_name);
610 bool set_field_value(const char *field_value, unsigned field_value_length);
611 bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated
614 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
616 unsigned field_name_length_;
618 unsigned field_value_length_;
623 void clear_field_name();
624 void clear_field_value();
625 void construct(const char *field, unsigned field_length);
626 void construct(const char *field); // assumes \a field is NUL-terminated
627 void construct(const char *field_name, const char *field_value, unsigned field_value_length);
628 void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
629 void compose_field();
636 /** Constructs a copy of the given object. This form
637 * always performs a deep copy.
639 inline VorbisComment(const VorbisComment &object): Prototype(object) { }
640 inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
641 inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
644 /** Constructs an object with copy control. See
645 * Prototype(::FLAC__StreamMetadata *object, bool copy).
647 inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
652 /** Assign from another object. Always performs a deep copy. */
653 inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; }
654 inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
655 inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
658 /** Assigns an object with copy control. See
659 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
661 inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
664 /** Check for equality, performing a deep compare by following pointers. */
665 inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
666 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
667 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
671 /** Check for inequality, performing a deep compare by following pointers. */
672 inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
673 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
674 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
677 unsigned get_num_comments() const;
678 const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string
679 Entry get_comment(unsigned index) const;
681 //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
682 bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string
684 //! See FLAC__metadata_object_vorbiscomment_resize_comments()
685 bool resize_comments(unsigned new_num_comments);
687 //! See FLAC__metadata_object_vorbiscomment_set_comment()
688 bool set_comment(unsigned index, const Entry &entry);
690 //! See FLAC__metadata_object_vorbiscomment_insert_comment()
691 bool insert_comment(unsigned index, const Entry &entry);
693 //! See FLAC__metadata_object_vorbiscomment_append_comment()
694 bool append_comment(const Entry &entry);
696 //! See FLAC__metadata_object_vorbiscomment_replace_comment()
697 bool replace_comment(const Entry &entry, bool all);
699 //! See FLAC__metadata_object_vorbiscomment_delete_comment()
700 bool delete_comment(unsigned index);
702 //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
703 int find_entry_from(unsigned offset, const char *field_name);
705 //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
706 int remove_entry_matching(const char *field_name);
708 //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
709 int remove_entries_matching(const char *field_name);
712 /** CUESHEET metadata block.
713 * See the \link flacpp_metadata_object overview \endlink for more,
714 * and the <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
716 class FLACPP_API CueSheet : public Prototype {
718 /** Convenience class for encapsulating a cue sheet
721 * Always check is_valid() after the constructor or operator=
722 * to make sure memory was properly allocated.
724 class FLACPP_API Track {
726 ::FLAC__StreamMetadata_CueSheet_Track *object_;
729 Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
730 Track(const Track &track);
731 Track &operator=(const Track &track);
735 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
738 inline FLAC__uint64 get_offset() const { return object_->offset; }
739 inline FLAC__byte get_number() const { return object_->number; }
740 inline const char *get_isrc() const { return object_->isrc; }
741 inline unsigned get_type() const { return object_->type; }
742 inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
744 inline FLAC__byte get_num_indices() const { return object_->num_indices; }
745 ::FLAC__StreamMetadata_CueSheet_Index get_index(unsigned i) const;
747 inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
749 inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
750 inline void set_number(FLAC__byte value) { object_->number = value; }
751 void set_isrc(const char value[12]);
752 void set_type(unsigned value);
753 inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
755 void set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
756 //@@@ It's awkward but to insert/delete index points
757 //@@@ you must use the routines in the CueSheet class.
763 /** Constructs a copy of the given object. This form
764 * always performs a deep copy.
766 inline CueSheet(const CueSheet &object): Prototype(object) { }
767 inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
768 inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
771 /** Constructs an object with copy control. See
772 * Prototype(::FLAC__StreamMetadata *object, bool copy).
774 inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
779 /** Assign from another object. Always performs a deep copy. */
780 inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; }
781 inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
782 inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
785 /** Assigns an object with copy control. See
786 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
788 inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
791 /** Check for equality, performing a deep compare by following pointers. */
792 inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); }
793 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
794 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
798 /** Check for inequality, performing a deep compare by following pointers. */
799 inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
800 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
801 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
804 const char *get_media_catalog_number() const;
805 FLAC__uint64 get_lead_in() const;
806 bool get_is_cd() const;
808 unsigned get_num_tracks() const;
809 Track get_track(unsigned i) const;
811 void set_media_catalog_number(const char value[128]);
812 void set_lead_in(FLAC__uint64 value);
813 void set_is_cd(bool value);
815 void set_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
817 //! See FLAC__metadata_object_cuesheet_track_resize_indices()
818 bool resize_indices(unsigned track_num, unsigned new_num_indices);
820 //! See FLAC__metadata_object_cuesheet_track_insert_index()
821 bool insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
823 //! See FLAC__metadata_object_cuesheet_track_insert_blank_index()
824 bool insert_blank_index(unsigned track_num, unsigned index_num);
826 //! See FLAC__metadata_object_cuesheet_track_delete_index()
827 bool delete_index(unsigned track_num, unsigned index_num);
829 //! See FLAC__metadata_object_cuesheet_resize_tracks()
830 bool resize_tracks(unsigned new_num_tracks);
832 //! See FLAC__metadata_object_cuesheet_set_track()
833 bool set_track(unsigned i, const Track &track);
835 //! See FLAC__metadata_object_cuesheet_insert_track()
836 bool insert_track(unsigned i, const Track &track);
838 //! See FLAC__metadata_object_cuesheet_insert_blank_track()
839 bool insert_blank_track(unsigned i);
841 //! See FLAC__metadata_object_cuesheet_delete_track()
842 bool delete_track(unsigned i);
844 //! See FLAC__metadata_object_cuesheet_is_legal()
845 bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
847 //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
848 FLAC__uint32 calculate_cddb_id() const;
851 /** PICTURE metadata block.
852 * See the \link flacpp_metadata_object overview \endlink for more,
853 * and the <A HREF="../format.html#metadata_block_picture">format specification</A>.
855 class FLACPP_API Picture : public Prototype {
860 /** Constructs a copy of the given object. This form
861 * always performs a deep copy.
863 inline Picture(const Picture &object): Prototype(object) { }
864 inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { }
865 inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { }
868 /** Constructs an object with copy control. See
869 * Prototype(::FLAC__StreamMetadata *object, bool copy).
871 inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
876 /** Assign from another object. Always performs a deep copy. */
877 inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; }
878 inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
879 inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
882 /** Assigns an object with copy control. See
883 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
885 inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
888 /** Check for equality, performing a deep compare by following pointers. */
889 inline bool operator==(const Picture &object) const { return Prototype::operator==(object); }
890 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
891 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
895 /** Check for inequality, performing a deep compare by following pointers. */
896 inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); }
897 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
898 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
901 ::FLAC__StreamMetadata_Picture_Type get_type() const;
902 const char *get_mime_type() const; // NUL-terminated printable ASCII string
903 const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string
904 FLAC__uint32 get_width() const;
905 FLAC__uint32 get_height() const;
906 FLAC__uint32 get_depth() const;
907 FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
908 FLAC__uint32 get_data_length() const;
909 const FLAC__byte *get_data() const;
911 void set_type(::FLAC__StreamMetadata_Picture_Type type);
913 //! See FLAC__metadata_object_picture_set_mime_type()
914 bool set_mime_type(const char *string); // NUL-terminated printable ASCII string
916 //! See FLAC__metadata_object_picture_set_description()
917 bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string
919 void set_width(FLAC__uint32 value) const;
920 void set_height(FLAC__uint32 value) const;
921 void set_depth(FLAC__uint32 value) const;
922 void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
924 //! See FLAC__metadata_object_picture_set_data()
925 bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
927 //! See FLAC__metadata_object_picture_is_legal()
928 bool is_legal(const char **violation);
931 /** Opaque metadata block for storing unknown types.
932 * This should not be used unless you know what you are doing;
933 * it is currently used only internally to support forward
934 * compatibility of metadata blocks.
935 * See the \link flacpp_metadata_object overview \endlink for more,
937 class FLACPP_API Unknown : public Prototype {
942 /** Constructs a copy of the given object. This form
943 * always performs a deep copy.
945 inline Unknown(const Unknown &object): Prototype(object) { }
946 inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
947 inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
950 /** Constructs an object with copy control. See
951 * Prototype(::FLAC__StreamMetadata *object, bool copy).
953 inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
958 /** Assign from another object. Always performs a deep copy. */
959 inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; }
960 inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
961 inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
964 /** Assigns an object with copy control. See
965 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
967 inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
970 /** Check for equality, performing a deep compare by following pointers. */
971 inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
972 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
973 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
977 /** Check for inequality, performing a deep compare by following pointers. */
978 inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
979 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
980 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
983 const FLAC__byte *get_data() const;
985 //! This form always copies \a data
986 bool set_data(const FLAC__byte *data, unsigned length);
987 bool set_data(FLAC__byte *data, unsigned length, bool copy);
993 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
994 * \ingroup flacpp_metadata
997 * Level 0 metadata iterators.
999 * See the \link flac_metadata_level0 C layer equivalent \endlink
1005 FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo().
1007 FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags().
1008 FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags().
1010 FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet().
1011 FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet().
1013 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().
1014 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().
1019 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
1020 * \ingroup flacpp_metadata
1023 * Level 1 metadata iterator.
1025 * The flow through the iterator in the C++ layer is similar
1027 * - Create a SimpleIterator instance
1028 * - Check SimpleIterator::is_valid()
1029 * - Call SimpleIterator::init() and check the return
1030 * - Traverse and/or edit. Edits are written to file
1032 * - Destroy the SimpleIterator instance
1034 * The ownership of pointers in the C++ layer follows that in
1036 * - The objects returned by get_block() are yours to
1037 * modify, but changes are not reflected in the FLAC file
1038 * until you call set_block(). The objects are also
1039 * yours to delete; they are not automatically deleted
1040 * when passed to set_block() or insert_block_after().
1042 * See the \link flac_metadata_level1 C layer equivalent \endlink
1048 /** This class is a wrapper around the FLAC__metadata_simple_iterator
1049 * structures and methods; see the
1050 * \link flacpp_metadata_level1 usage guide \endlink and
1051 * ::FLAC__Metadata_SimpleIterator.
1053 class FLACPP_API SimpleIterator {
1055 /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
1057 class FLACPP_API Status {
1059 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
1060 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
1061 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
1063 ::FLAC__Metadata_SimpleIteratorStatus status_;
1067 virtual ~SimpleIterator();
1069 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1071 bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init().
1073 Status status(); ///< See FLAC__metadata_simple_iterator_status().
1074 bool is_writable() const; ///< See FLAC__metadata_simple_iterator_is_writable().
1076 bool next(); ///< See FLAC__metadata_simple_iterator_next().
1077 bool prev(); ///< See FLAC__metadata_simple_iterator_prev().
1078 bool is_last() const; ///< See FLAC__metadata_simple_iterator_is_last().
1080 off_t get_block_offset() const; ///< See FLAC__metadata_simple_iterator_get_block_offset().
1081 ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_simple_iterator_get_block_type().
1082 unsigned get_block_length() const; ///< See FLAC__metadata_simple_iterator_get_block_length().
1083 bool get_application_id(FLAC__byte *id); ///< See FLAC__metadata_simple_iterator_get_application_id().
1084 Prototype *get_block(); ///< See FLAC__metadata_simple_iterator_get_block().
1085 bool set_block(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_set_block().
1086 bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
1087 bool delete_block(bool use_padding = true); ///< See FLAC__metadata_simple_iterator_delete_block().
1090 ::FLAC__Metadata_SimpleIterator *iterator_;
1093 private: // Do not use.
1094 SimpleIterator(const SimpleIterator&);
1095 SimpleIterator&operator=(const SimpleIterator&);
1101 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
1102 * \ingroup flacpp_metadata
1105 * Level 2 metadata iterator.
1107 * The flow through the iterator in the C++ layer is similar
1109 * - Create a Chain instance
1110 * - Check Chain::is_valid()
1111 * - Call Chain::read() and check the return
1112 * - Traverse and/or edit with an Iterator or with
1113 * Chain::merge_padding() or Chain::sort_padding()
1114 * - Write changes back to FLAC file with Chain::write()
1115 * - Destroy the Chain instance
1117 * The ownership of pointers in the C++ layer is slightly
1118 * different than in the C layer, i.e.
1119 * - The objects returned by Iterator::get_block() are NOT
1120 * owned by the iterator and should be deleted by the
1121 * caller when finished, BUT, when you modify the block,
1122 * it will directly edit what's in the chain and you do
1123 * not need to call Iterator::set_block(). However the
1124 * changes will not be reflected in the FLAC file until
1125 * the chain is written with Chain::write().
1126 * - When you pass an object to Iterator::set_block(),
1127 * Iterator::insert_block_before(), or
1128 * Iterator::insert_block_after(), the iterator takes
1129 * ownership of the block and it will be deleted by the
1132 * See the \link flac_metadata_level2 C layer equivalent \endlink
1138 /** This class is a wrapper around the FLAC__metadata_chain
1139 * structures and methods; see the
1140 * \link flacpp_metadata_level2 usage guide \endlink and
1141 * ::FLAC__Metadata_Chain.
1143 class FLACPP_API Chain {
1145 /** This class is a wrapper around FLAC__Metadata_ChainStatus.
1147 class FLACPP_API Status {
1149 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
1150 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
1151 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
1153 ::FLAC__Metadata_ChainStatus status_;
1159 friend class Iterator;
1161 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1163 Status status(); ///< See FLAC__metadata_chain_status().
1165 bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
1166 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().
1168 bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed().
1170 bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write().
1171 bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks().
1172 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().
1174 void merge_padding(); ///< See FLAC__metadata_chain_merge_padding().
1175 void sort_padding(); ///< See FLAC__metadata_chain_sort_padding().
1178 ::FLAC__Metadata_Chain *chain_;
1179 virtual void clear();
1181 private: // Do not use.
1182 Chain(const Chain&);
1183 Chain&operator=(const Chain&);
1186 /** This class is a wrapper around the FLAC__metadata_iterator
1187 * structures and methods; see the
1188 * \link flacpp_metadata_level2 usage guide \endlink and
1189 * ::FLAC__Metadata_Iterator.
1191 class FLACPP_API Iterator {
1194 virtual ~Iterator();
1196 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1199 void init(Chain &chain); ///< See FLAC__metadata_iterator_init().
1201 bool next(); ///< See FLAC__metadata_iterator_next().
1202 bool prev(); ///< See FLAC__metadata_iterator_prev().
1204 ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_iterator_get_block_type().
1205 Prototype *get_block(); ///< See FLAC__metadata_iterator_get_block().
1206 bool set_block(Prototype *block); ///< See FLAC__metadata_iterator_set_block().
1207 bool delete_block(bool replace_with_padding); ///< See FLAC__metadata_iterator_delete_block().
1208 bool insert_block_before(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_before().
1209 bool insert_block_after(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_after().
1212 ::FLAC__Metadata_Iterator *iterator_;
1213 virtual void clear();
1215 private: // Do not use.
1216 Iterator(const Iterator&);
1217 Iterator&operator=(const Iterator&);