1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002-2009 Josh Coalson
3 * Copyright (C) 2011-2013 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 // @@@ how to re-enable? the following doesn't work
245 // #pragma warning ( enable : 4800 )
248 inline bool Prototype::operator!=(const Prototype &object) const
249 { return !operator==(object); }
251 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
252 { return !operator==(object); }
254 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
255 { return !operator==(object); }
257 inline bool Prototype::is_valid() const
258 { return 0 != object_; }
260 inline Prototype::operator const ::FLAC__StreamMetadata *() const
263 /** Create a deep copy of an object and return it. */
264 FLACPP_API Prototype *clone(const Prototype *);
267 /** STREAMINFO metadata block.
268 * See the \link flacpp_metadata_object overview \endlink for more,
269 * and the <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
271 class FLACPP_API StreamInfo : public Prototype {
276 /** Constructs a copy of the given object. This form
277 * always performs a deep copy.
279 inline StreamInfo(const StreamInfo &object): Prototype(object) { }
280 inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
281 inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
284 /** Constructs an object with copy control. See
285 * Prototype(::FLAC__StreamMetadata *object, bool copy).
287 inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
292 /** Assign from another object. Always performs a deep copy. */
293 inline StreamInfo &operator=(const StreamInfo &object) { Prototype::operator=(object); return *this; }
294 inline StreamInfo &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
295 inline StreamInfo &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
298 /** Assigns an object with copy control. See
299 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
301 inline StreamInfo &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
304 /** Check for equality, performing a deep compare by following pointers. */
305 inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
306 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
307 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
311 /** Check for inequality, performing a deep compare by following pointers. */
312 inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
313 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
314 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
318 /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
319 unsigned get_min_blocksize() const;
320 unsigned get_max_blocksize() const;
321 unsigned get_min_framesize() const;
322 unsigned get_max_framesize() const;
323 unsigned get_sample_rate() const;
324 unsigned get_channels() const;
325 unsigned get_bits_per_sample() const;
326 FLAC__uint64 get_total_samples() const;
327 const FLAC__byte *get_md5sum() const;
329 void set_min_blocksize(unsigned value);
330 void set_max_blocksize(unsigned value);
331 void set_min_framesize(unsigned value);
332 void set_max_framesize(unsigned value);
333 void set_sample_rate(unsigned value);
334 void set_channels(unsigned value);
335 void set_bits_per_sample(unsigned value);
336 void set_total_samples(FLAC__uint64 value);
337 void set_md5sum(const FLAC__byte value[16]);
341 /** PADDING metadata block.
342 * See the \link flacpp_metadata_object overview \endlink for more,
343 * and the <A HREF="../format.html#metadata_block_padding">format specification</A>.
345 class FLACPP_API Padding : public Prototype {
350 /** Constructs a copy of the given object. This form
351 * always performs a deep copy.
353 inline Padding(const Padding &object): Prototype(object) { }
354 inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
355 inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
358 /** Constructs an object with copy control. See
359 * Prototype(::FLAC__StreamMetadata *object, bool copy).
361 inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
363 /** Constructs an object with the given length.
365 Padding(unsigned length);
370 /** Assign from another object. Always performs a deep copy. */
371 inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; }
372 inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
373 inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
376 /** Assigns an object with copy control. See
377 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
379 inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
382 /** Check for equality, performing a deep compare by following pointers. */
383 inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
384 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
385 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
389 /** Check for inequality, performing a deep compare by following pointers. */
390 inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
391 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
392 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
395 /** Sets the length in bytes of the padding block.
397 void set_length(unsigned length);
400 /** APPLICATION metadata block.
401 * See the \link flacpp_metadata_object overview \endlink for more,
402 * and the <A HREF="../format.html#metadata_block_application">format specification</A>.
404 class FLACPP_API Application : public Prototype {
409 /** Constructs a copy of the given object. This form
410 * always performs a deep copy.
412 inline Application(const Application &object): Prototype(object) { }
413 inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
414 inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
417 /** Constructs an object with copy control. See
418 * Prototype(::FLAC__StreamMetadata *object, bool copy).
420 inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
425 /** Assign from another object. Always performs a deep copy. */
426 inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; }
427 inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
428 inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
431 /** Assigns an object with copy control. See
432 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
434 inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
437 /** Check for equality, 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); }
444 /** Check for inequality, performing a deep compare by following pointers. */
445 inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
446 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
447 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
450 const FLAC__byte *get_id() const;
451 const FLAC__byte *get_data() const;
453 void set_id(const FLAC__byte value[4]);
454 //! This form always copies \a data
455 bool set_data(const FLAC__byte *data, unsigned length);
456 bool set_data(FLAC__byte *data, unsigned length, bool copy);
459 /** SEEKTABLE metadata block.
460 * See the \link flacpp_metadata_object overview \endlink for more,
461 * and the <A HREF="../format.html#metadata_block_seektable">format specification</A>.
463 class FLACPP_API SeekTable : public Prototype {
468 /** Constructs a copy of the given object. This form
469 * always performs a deep copy.
471 inline SeekTable(const SeekTable &object): Prototype(object) { }
472 inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
473 inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
476 /** Constructs an object with copy control. See
477 * Prototype(::FLAC__StreamMetadata *object, bool copy).
479 inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
484 /** Assign from another object. Always performs a deep copy. */
485 inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; }
486 inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
487 inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
490 /** Assigns an object with copy control. See
491 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
493 inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
496 /** Check for equality, 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); }
503 /** Check for inequality, performing a deep compare by following pointers. */
504 inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
505 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
506 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
509 unsigned get_num_points() const;
510 ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const;
512 //! See FLAC__metadata_object_seektable_resize_points()
513 bool resize_points(unsigned new_num_points);
515 //! See FLAC__metadata_object_seektable_set_point()
516 void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
518 //! See FLAC__metadata_object_seektable_insert_point()
519 bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
521 //! See FLAC__metadata_object_seektable_delete_point()
522 bool delete_point(unsigned index);
524 //! See FLAC__metadata_object_seektable_is_legal()
525 bool is_legal() const;
527 //! See FLAC__metadata_object_seektable_template_append_placeholders()
528 bool template_append_placeholders(unsigned num);
530 //! See FLAC__metadata_object_seektable_template_append_point()
531 bool template_append_point(FLAC__uint64 sample_number);
533 //! See FLAC__metadata_object_seektable_template_append_points()
534 bool template_append_points(FLAC__uint64 sample_numbers[], unsigned num);
536 //! See FLAC__metadata_object_seektable_template_append_spaced_points()
537 bool template_append_spaced_points(unsigned num, FLAC__uint64 total_samples);
539 //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
540 bool template_append_spaced_points_by_samples(unsigned samples, FLAC__uint64 total_samples);
542 //! See FLAC__metadata_object_seektable_template_sort()
543 bool template_sort(bool compact);
546 /** VORBIS_COMMENT metadata block.
547 * See the \link flacpp_metadata_object overview \endlink for more,
548 * and the <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
550 class FLACPP_API VorbisComment : public Prototype {
552 /** Convenience class for encapsulating Vorbis comment
553 * entries. An entry is a vendor string or a comment
554 * field. In the case of a vendor string, the field
555 * name is undefined; only the field value is relevant.
557 * A \a field as used in the methods refers to an
558 * entire 'NAME=VALUE' string; for convenience the
559 * string is NUL-terminated. A length field is
560 * required in the unlikely event that the value
561 * contains contain embedded NULs.
563 * A \a field_name is what is on the left side of the
564 * first '=' in the \a field. By definition it is ASCII
565 * and so is NUL-terminated and does not require a
566 * length to describe it. \a field_name is undefined
567 * for a vendor string entry.
569 * A \a field_value is what is on the right side of the
570 * first '=' in the \a field. By definition, this may
571 * contain embedded NULs and so a \a field_value_length
572 * is required to describe it. However in practice,
573 * embedded NULs are not known to be used, so it is
574 * generally safe to treat field values as NUL-
575 * terminated UTF-8 strings.
577 * Always check is_valid() after the constructor or operator=
578 * to make sure memory was properly allocated and that the
579 * Entry conforms to the Vorbis comment specification.
581 class FLACPP_API Entry {
585 Entry(const char *field, unsigned field_length);
586 Entry(const char *field); // assumes \a field is NUL-terminated
588 Entry(const char *field_name, const char *field_value, unsigned field_value_length);
589 Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
591 Entry(const Entry &entry);
593 Entry &operator=(const Entry &entry);
597 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
599 unsigned get_field_length() const;
600 unsigned get_field_name_length() const;
601 unsigned get_field_value_length() const;
603 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
604 const char *get_field() const;
605 const char *get_field_name() const;
606 const char *get_field_value() const;
608 bool set_field(const char *field, unsigned field_length);
609 bool set_field(const char *field); // assumes \a field is NUL-terminated
610 bool set_field_name(const char *field_name);
611 bool set_field_value(const char *field_value, unsigned field_value_length);
612 bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated
615 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
617 unsigned field_name_length_;
619 unsigned field_value_length_;
624 void clear_field_name();
625 void clear_field_value();
626 void construct(const char *field, unsigned field_length);
627 void construct(const char *field); // assumes \a field is NUL-terminated
628 void construct(const char *field_name, const char *field_value, unsigned field_value_length);
629 void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
630 void compose_field();
637 /** Constructs a copy of the given object. This form
638 * always performs a deep copy.
640 inline VorbisComment(const VorbisComment &object): Prototype(object) { }
641 inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
642 inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
645 /** Constructs an object with copy control. See
646 * Prototype(::FLAC__StreamMetadata *object, bool copy).
648 inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
653 /** Assign from another object. Always performs a deep copy. */
654 inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; }
655 inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
656 inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
659 /** Assigns an object with copy control. See
660 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
662 inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
665 /** Check for equality, 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); }
672 /** Check for inequality, performing a deep compare by following pointers. */
673 inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
674 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
675 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
678 unsigned get_num_comments() const;
679 const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string
680 Entry get_comment(unsigned index) const;
682 //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
683 bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string
685 //! See FLAC__metadata_object_vorbiscomment_resize_comments()
686 bool resize_comments(unsigned new_num_comments);
688 //! See FLAC__metadata_object_vorbiscomment_set_comment()
689 bool set_comment(unsigned index, const Entry &entry);
691 //! See FLAC__metadata_object_vorbiscomment_insert_comment()
692 bool insert_comment(unsigned index, const Entry &entry);
694 //! See FLAC__metadata_object_vorbiscomment_append_comment()
695 bool append_comment(const Entry &entry);
697 //! See FLAC__metadata_object_vorbiscomment_replace_comment()
698 bool replace_comment(const Entry &entry, bool all);
700 //! See FLAC__metadata_object_vorbiscomment_delete_comment()
701 bool delete_comment(unsigned index);
703 //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
704 int find_entry_from(unsigned offset, const char *field_name);
706 //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
707 int remove_entry_matching(const char *field_name);
709 //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
710 int remove_entries_matching(const char *field_name);
713 /** CUESHEET metadata block.
714 * See the \link flacpp_metadata_object overview \endlink for more,
715 * and the <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
717 class FLACPP_API CueSheet : public Prototype {
719 /** Convenience class for encapsulating a cue sheet
722 * Always check is_valid() after the constructor or operator=
723 * to make sure memory was properly allocated.
725 class FLACPP_API Track {
727 ::FLAC__StreamMetadata_CueSheet_Track *object_;
730 Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
731 Track(const Track &track);
732 Track &operator=(const Track &track);
736 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
739 inline FLAC__uint64 get_offset() const { return object_->offset; }
740 inline FLAC__byte get_number() const { return object_->number; }
741 inline const char *get_isrc() const { return object_->isrc; }
742 inline unsigned get_type() const { return object_->type; }
743 inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
745 inline FLAC__byte get_num_indices() const { return object_->num_indices; }
746 ::FLAC__StreamMetadata_CueSheet_Index get_index(unsigned i) const;
748 inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
750 inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
751 inline void set_number(FLAC__byte value) { object_->number = value; }
752 void set_isrc(const char value[12]);
753 void set_type(unsigned value);
754 inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
756 void set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
757 //@@@ It's awkward but to insert/delete index points
758 //@@@ you must use the routines in the CueSheet class.
764 /** Constructs a copy of the given object. This form
765 * always performs a deep copy.
767 inline CueSheet(const CueSheet &object): Prototype(object) { }
768 inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
769 inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
772 /** Constructs an object with copy control. See
773 * Prototype(::FLAC__StreamMetadata *object, bool copy).
775 inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
780 /** Assign from another object. Always performs a deep copy. */
781 inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; }
782 inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
783 inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
786 /** Assigns an object with copy control. See
787 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
789 inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
792 /** Check for equality, 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); }
799 /** Check for inequality, performing a deep compare by following pointers. */
800 inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
801 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
802 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
805 const char *get_media_catalog_number() const;
806 FLAC__uint64 get_lead_in() const;
807 bool get_is_cd() const;
809 unsigned get_num_tracks() const;
810 Track get_track(unsigned i) const;
812 void set_media_catalog_number(const char value[128]);
813 void set_lead_in(FLAC__uint64 value);
814 void set_is_cd(bool value);
816 void set_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
818 //! See FLAC__metadata_object_cuesheet_track_resize_indices()
819 bool resize_indices(unsigned track_num, unsigned new_num_indices);
821 //! See FLAC__metadata_object_cuesheet_track_insert_index()
822 bool insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
824 //! See FLAC__metadata_object_cuesheet_track_insert_blank_index()
825 bool insert_blank_index(unsigned track_num, unsigned index_num);
827 //! See FLAC__metadata_object_cuesheet_track_delete_index()
828 bool delete_index(unsigned track_num, unsigned index_num);
830 //! See FLAC__metadata_object_cuesheet_resize_tracks()
831 bool resize_tracks(unsigned new_num_tracks);
833 //! See FLAC__metadata_object_cuesheet_set_track()
834 bool set_track(unsigned i, const Track &track);
836 //! See FLAC__metadata_object_cuesheet_insert_track()
837 bool insert_track(unsigned i, const Track &track);
839 //! See FLAC__metadata_object_cuesheet_insert_blank_track()
840 bool insert_blank_track(unsigned i);
842 //! See FLAC__metadata_object_cuesheet_delete_track()
843 bool delete_track(unsigned i);
845 //! See FLAC__metadata_object_cuesheet_is_legal()
846 bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
848 //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
849 FLAC__uint32 calculate_cddb_id() const;
852 /** PICTURE metadata block.
853 * See the \link flacpp_metadata_object overview \endlink for more,
854 * and the <A HREF="../format.html#metadata_block_picture">format specification</A>.
856 class FLACPP_API Picture : public Prototype {
861 /** Constructs a copy of the given object. This form
862 * always performs a deep copy.
864 inline Picture(const Picture &object): Prototype(object) { }
865 inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { }
866 inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { }
869 /** Constructs an object with copy control. See
870 * Prototype(::FLAC__StreamMetadata *object, bool copy).
872 inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
877 /** Assign from another object. Always performs a deep copy. */
878 inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; }
879 inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
880 inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
883 /** Assigns an object with copy control. See
884 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
886 inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
889 /** Check for equality, performing a deep compare by following pointers. */
890 inline bool operator==(const Picture &object) const { return Prototype::operator==(object); }
891 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
892 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
896 /** Check for inequality, performing a deep compare by following pointers. */
897 inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); }
898 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
899 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
902 ::FLAC__StreamMetadata_Picture_Type get_type() const;
903 const char *get_mime_type() const; // NUL-terminated printable ASCII string
904 const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string
905 FLAC__uint32 get_width() const;
906 FLAC__uint32 get_height() const;
907 FLAC__uint32 get_depth() const;
908 FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
909 FLAC__uint32 get_data_length() const;
910 const FLAC__byte *get_data() const;
912 void set_type(::FLAC__StreamMetadata_Picture_Type type);
914 //! See FLAC__metadata_object_picture_set_mime_type()
915 bool set_mime_type(const char *string); // NUL-terminated printable ASCII string
917 //! See FLAC__metadata_object_picture_set_description()
918 bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string
920 void set_width(FLAC__uint32 value) const;
921 void set_height(FLAC__uint32 value) const;
922 void set_depth(FLAC__uint32 value) const;
923 void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
925 //! See FLAC__metadata_object_picture_set_data()
926 bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
928 //! See FLAC__metadata_object_picture_is_legal()
929 bool is_legal(const char **violation);
932 /** Opaque metadata block for storing unknown types.
933 * This should not be used unless you know what you are doing;
934 * it is currently used only internally to support forward
935 * compatibility of metadata blocks.
936 * See the \link flacpp_metadata_object overview \endlink for more,
938 class FLACPP_API Unknown : public Prototype {
943 /** Constructs a copy of the given object. This form
944 * always performs a deep copy.
946 inline Unknown(const Unknown &object): Prototype(object) { }
947 inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
948 inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
951 /** Constructs an object with copy control. See
952 * Prototype(::FLAC__StreamMetadata *object, bool copy).
954 inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
959 /** Assign from another object. Always performs a deep copy. */
960 inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; }
961 inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
962 inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
965 /** Assigns an object with copy control. See
966 * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
968 inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
971 /** Check for equality, performing a deep compare by following pointers. */
972 inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
973 inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
974 inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
978 /** Check for inequality, performing a deep compare by following pointers. */
979 inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
980 inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
981 inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
984 const FLAC__byte *get_data() const;
986 //! This form always copies \a data
987 bool set_data(const FLAC__byte *data, unsigned length);
988 bool set_data(FLAC__byte *data, unsigned length, bool copy);
994 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
995 * \ingroup flacpp_metadata
998 * Level 0 metadata iterators.
1000 * See the \link flac_metadata_level0 C layer equivalent \endlink
1006 FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo().
1008 FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags().
1009 FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags().
1011 FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet().
1012 FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet().
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().
1015 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().
1020 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
1021 * \ingroup flacpp_metadata
1024 * Level 1 metadata iterator.
1026 * The flow through the iterator in the C++ layer is similar
1028 * - Create a SimpleIterator instance
1029 * - Check SimpleIterator::is_valid()
1030 * - Call SimpleIterator::init() and check the return
1031 * - Traverse and/or edit. Edits are written to file
1033 * - Destroy the SimpleIterator instance
1035 * The ownership of pointers in the C++ layer follows that in
1037 * - The objects returned by get_block() are yours to
1038 * modify, but changes are not reflected in the FLAC file
1039 * until you call set_block(). The objects are also
1040 * yours to delete; they are not automatically deleted
1041 * when passed to set_block() or insert_block_after().
1043 * See the \link flac_metadata_level1 C layer equivalent \endlink
1049 /** This class is a wrapper around the FLAC__metadata_simple_iterator
1050 * structures and methods; see the
1051 * \link flacpp_metadata_level1 usage guide \endlink and
1052 * ::FLAC__Metadata_SimpleIterator.
1054 class FLACPP_API SimpleIterator {
1056 /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
1058 class FLACPP_API Status {
1060 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
1061 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
1062 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
1064 ::FLAC__Metadata_SimpleIteratorStatus status_;
1068 virtual ~SimpleIterator();
1070 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1072 bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init().
1074 Status status(); ///< See FLAC__metadata_simple_iterator_status().
1075 bool is_writable() const; ///< See FLAC__metadata_simple_iterator_is_writable().
1077 bool next(); ///< See FLAC__metadata_simple_iterator_next().
1078 bool prev(); ///< See FLAC__metadata_simple_iterator_prev().
1079 bool is_last() const; ///< See FLAC__metadata_simple_iterator_is_last().
1081 off_t get_block_offset() const; ///< See FLAC__metadata_simple_iterator_get_block_offset().
1082 ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_simple_iterator_get_block_type().
1083 unsigned get_block_length() const; ///< See FLAC__metadata_simple_iterator_get_block_length().
1084 bool get_application_id(FLAC__byte *id); ///< See FLAC__metadata_simple_iterator_get_application_id().
1085 Prototype *get_block(); ///< See FLAC__metadata_simple_iterator_get_block().
1086 bool set_block(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_set_block().
1087 bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
1088 bool delete_block(bool use_padding = true); ///< See FLAC__metadata_simple_iterator_delete_block().
1091 ::FLAC__Metadata_SimpleIterator *iterator_;
1098 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
1099 * \ingroup flacpp_metadata
1102 * Level 2 metadata iterator.
1104 * The flow through the iterator in the C++ layer is similar
1106 * - Create a Chain instance
1107 * - Check Chain::is_valid()
1108 * - Call Chain::read() and check the return
1109 * - Traverse and/or edit with an Iterator or with
1110 * Chain::merge_padding() or Chain::sort_padding()
1111 * - Write changes back to FLAC file with Chain::write()
1112 * - Destroy the Chain instance
1114 * The ownership of pointers in the C++ layer is slightly
1115 * different than in the C layer, i.e.
1116 * - The objects returned by Iterator::get_block() are NOT
1117 * owned by the iterator and should be deleted by the
1118 * caller when finished, BUT, when you modify the block,
1119 * it will directly edit what's in the chain and you do
1120 * not need to call Iterator::set_block(). However the
1121 * changes will not be reflected in the FLAC file until
1122 * the chain is written with Chain::write().
1123 * - When you pass an object to Iterator::set_block(),
1124 * Iterator::insert_block_before(), or
1125 * Iterator::insert_block_after(), the iterator takes
1126 * ownership of the block and it will be deleted by the
1129 * See the \link flac_metadata_level2 C layer equivalent \endlink
1135 /** This class is a wrapper around the FLAC__metadata_chain
1136 * structures and methods; see the
1137 * \link flacpp_metadata_level2 usage guide \endlink and
1138 * ::FLAC__Metadata_Chain.
1140 class FLACPP_API Chain {
1142 /** This class is a wrapper around FLAC__Metadata_ChainStatus.
1144 class FLACPP_API Status {
1146 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
1147 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
1148 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
1150 ::FLAC__Metadata_ChainStatus status_;
1156 friend class Iterator;
1158 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1160 Status status(); ///< See FLAC__metadata_chain_status().
1162 bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
1163 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().
1165 bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed().
1167 bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write().
1168 bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks().
1169 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().
1171 void merge_padding(); ///< See FLAC__metadata_chain_merge_padding().
1172 void sort_padding(); ///< See FLAC__metadata_chain_sort_padding().
1175 ::FLAC__Metadata_Chain *chain_;
1176 virtual void clear();
1179 /** This class is a wrapper around the FLAC__metadata_iterator
1180 * structures and methods; see the
1181 * \link flacpp_metadata_level2 usage guide \endlink and
1182 * ::FLAC__Metadata_Iterator.
1184 class FLACPP_API Iterator {
1187 virtual ~Iterator();
1189 bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1192 void init(Chain &chain); ///< See FLAC__metadata_iterator_init().
1194 bool next(); ///< See FLAC__metadata_iterator_next().
1195 bool prev(); ///< See FLAC__metadata_iterator_prev().
1197 ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_iterator_get_block_type().
1198 Prototype *get_block(); ///< See FLAC__metadata_iterator_get_block().
1199 bool set_block(Prototype *block); ///< See FLAC__metadata_iterator_set_block().
1200 bool delete_block(bool replace_with_padding); ///< See FLAC__metadata_iterator_delete_block().
1201 bool insert_block_before(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_before().
1202 bool insert_block_after(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_after().
1205 ::FLAC__Metadata_Iterator *iterator_;
1206 virtual void clear();