metadata.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. /* libFLAC++ - Free Lossless Audio Codec library
  2. * Copyright (C) 2002-2009 Josh Coalson
  3. * Copyright (C) 2011-2023 Xiph.Org Foundation
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  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.
  15. *
  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.
  19. *
  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.
  31. */
  32. #ifndef FLACPP__METADATA_H
  33. #define FLACPP__METADATA_H
  34. #include "export.h"
  35. #include "FLAC/metadata.h"
  36. // ===============================================================
  37. //
  38. // Full documentation for the metadata interface can be found
  39. // in the C layer in include/FLAC/metadata.h
  40. //
  41. // ===============================================================
  42. /** \file include/FLAC++/metadata.h
  43. *
  44. * \brief
  45. * This module provides classes for creating and manipulating FLAC
  46. * metadata blocks in memory, and three progressively more powerful
  47. * interfaces for traversing and editing metadata in FLAC files.
  48. *
  49. * See the detailed documentation for each interface in the
  50. * \link flacpp_metadata metadata \endlink module.
  51. */
  52. /** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
  53. * \ingroup flacpp
  54. *
  55. * \brief
  56. * This module provides classes for creating and manipulating FLAC
  57. * metadata blocks in memory, and three progressively more powerful
  58. * interfaces for traversing and editing metadata in FLAC files.
  59. *
  60. * The behavior closely mimics the C layer interface; be sure to read
  61. * the detailed description of the
  62. * \link flac_metadata C metadata module \endlink. Note that like the
  63. * C layer, currently only the Chain interface (level 2) supports Ogg
  64. * FLAC files, and it is read-only i.e. no writing back changed
  65. * metadata to file.
  66. */
  67. namespace FLAC {
  68. namespace Metadata {
  69. // ============================================================
  70. //
  71. // Metadata objects
  72. //
  73. // ============================================================
  74. /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
  75. * \ingroup flacpp_metadata
  76. *
  77. * This module contains classes representing FLAC metadata
  78. * blocks in memory.
  79. *
  80. * The behavior closely mimics the C layer interface; be
  81. * sure to read the detailed description of the
  82. * \link flac_metadata_object C metadata object module \endlink.
  83. *
  84. * Any time a metadata object is constructed or assigned, you
  85. * should check is_valid() to make sure the underlying
  86. * ::FLAC__StreamMetadata object was able to be created.
  87. *
  88. * \warning
  89. * When the get_*() methods of any metadata object method
  90. * return you a const pointer, DO NOT disobey and write into it.
  91. * Always use the set_*() methods.
  92. *
  93. * \{
  94. */
  95. /** Base class for all metadata block types.
  96. * See the \link flacpp_metadata_object overview \endlink for more.
  97. */
  98. class FLACPP_API Prototype {
  99. protected:
  100. //@{
  101. /** Constructs a copy of the given object. This form
  102. * always performs a deep copy.
  103. */
  104. Prototype(const Prototype &);
  105. Prototype(const ::FLAC__StreamMetadata &);
  106. Prototype(const ::FLAC__StreamMetadata *);
  107. //@}
  108. /** Constructs an object with copy control. When \a copy
  109. * is \c true, behaves identically to
  110. * FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
  111. * When \a copy is \c false, the instance takes ownership of
  112. * the pointer and the ::FLAC__StreamMetadata object will
  113. * be freed by the destructor.
  114. *
  115. * \assert
  116. * \code object != NULL \endcode
  117. */
  118. Prototype(::FLAC__StreamMetadata *object, bool copy);
  119. //@{
  120. /** Assign from another object. Always performs a deep copy. */
  121. Prototype &operator=(const Prototype &);
  122. Prototype &operator=(const ::FLAC__StreamMetadata &);
  123. Prototype &operator=(const ::FLAC__StreamMetadata *);
  124. //@}
  125. /** Assigns an object with copy control. See
  126. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  127. */
  128. Prototype &assign_object(::FLAC__StreamMetadata *object, bool copy);
  129. /** Deletes the underlying ::FLAC__StreamMetadata object.
  130. */
  131. virtual void clear();
  132. ::FLAC__StreamMetadata *object_;
  133. public:
  134. /** Deletes the underlying ::FLAC__StreamMetadata object.
  135. */
  136. virtual ~Prototype();
  137. //@{
  138. /** Check for equality, performing a deep compare by following pointers.
  139. */
  140. inline bool operator==(const Prototype &) const;
  141. inline bool operator==(const ::FLAC__StreamMetadata &) const;
  142. inline bool operator==(const ::FLAC__StreamMetadata *) const;
  143. //@}
  144. //@{
  145. /** Check for inequality, performing a deep compare by following pointers. */
  146. inline bool operator!=(const Prototype &) const;
  147. inline bool operator!=(const ::FLAC__StreamMetadata &) const;
  148. inline bool operator!=(const ::FLAC__StreamMetadata *) const;
  149. //@}
  150. friend class SimpleIterator;
  151. friend class Iterator;
  152. /** Returns \c true if the object was correctly constructed
  153. * (i.e. the underlying ::FLAC__StreamMetadata object was
  154. * properly allocated), else \c false.
  155. */
  156. inline bool is_valid() const;
  157. /** Returns \c true if this block is the last block in a
  158. * stream, else \c false.
  159. *
  160. * \assert
  161. * \code is_valid() \endcode
  162. */
  163. bool get_is_last() const;
  164. /** Returns the type of the block.
  165. *
  166. * \assert
  167. * \code is_valid() \endcode
  168. */
  169. ::FLAC__MetadataType get_type() const;
  170. /** Returns the stream length of the metadata block.
  171. *
  172. * \note
  173. * The length does not include the metadata block header,
  174. * per spec.
  175. *
  176. * \assert
  177. * \code is_valid() \endcode
  178. */
  179. uint32_t get_length() const;
  180. /** Sets the "is_last" flag for the block. When using the iterators
  181. * it is not necessary to set this flag; they will do it for you.
  182. *
  183. * \assert
  184. * \code is_valid() \endcode
  185. */
  186. void set_is_last(bool);
  187. /** Returns a pointer to the underlying ::FLAC__StreamMetadata
  188. * object. This can be useful for plugging any holes between
  189. * the C++ and C interfaces.
  190. *
  191. * \assert
  192. * \code is_valid() \endcode
  193. */
  194. inline operator const ::FLAC__StreamMetadata *() const;
  195. private:
  196. /** Private and undefined so you can't use it. */
  197. Prototype();
  198. // These are used only by Iterator
  199. bool is_reference_;
  200. inline void set_reference(bool x) { is_reference_ = x; }
  201. };
  202. // local utility routines
  203. namespace local {
  204. /** Construct a new object of the type provided in object->type and return it. */
  205. Prototype *construct_block(::FLAC__StreamMetadata *object);
  206. }
  207. #ifdef _MSC_VER
  208. // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
  209. #pragma warning ( disable : 4800 )
  210. #endif
  211. inline bool Prototype::operator==(const Prototype &object) const
  212. { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
  213. inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
  214. { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
  215. inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
  216. { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
  217. #ifdef _MSC_VER
  218. #pragma warning ( default : 4800 )
  219. #endif
  220. inline bool Prototype::operator!=(const Prototype &object) const
  221. { return !operator==(object); }
  222. inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
  223. { return !operator==(object); }
  224. inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
  225. { return !operator==(object); }
  226. inline bool Prototype::is_valid() const
  227. { return 0 != object_; }
  228. inline Prototype::operator const ::FLAC__StreamMetadata *() const
  229. { return object_; }
  230. /** Create a deep copy of an object and return it. */
  231. FLACPP_API Prototype *clone(const Prototype *);
  232. /** STREAMINFO metadata block.
  233. * See the \link flacpp_metadata_object overview \endlink for more,
  234. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_streaminfo">format specification</A>.
  235. */
  236. class FLACPP_API StreamInfo : public Prototype {
  237. public:
  238. StreamInfo();
  239. //@{
  240. /** Constructs a copy of the given object. This form
  241. * always performs a deep copy.
  242. */
  243. inline StreamInfo(const StreamInfo &object): Prototype(object) { }
  244. inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  245. inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  246. //@}
  247. /** Constructs an object with copy control. See
  248. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  249. */
  250. inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  251. ~StreamInfo();
  252. //@{
  253. /** Assign from another object. Always performs a deep copy. */
  254. inline StreamInfo &operator=(const StreamInfo &object) { Prototype::operator=(object); return *this; }
  255. inline StreamInfo &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  256. inline StreamInfo &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  257. //@}
  258. /** Assigns an object with copy control. See
  259. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  260. */
  261. inline StreamInfo &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  262. //@{
  263. /** Check for equality, performing a deep compare by following pointers. */
  264. inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
  265. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  266. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  267. //@}
  268. //@{
  269. /** Check for inequality, performing a deep compare by following pointers. */
  270. inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
  271. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  272. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  273. //@}
  274. //@{
  275. /** See <A HREF="https://xiph.org/flac/format.html#metadata_block_streaminfo">format specification</A>. */
  276. uint32_t get_min_blocksize() const;
  277. uint32_t get_max_blocksize() const;
  278. uint32_t get_min_framesize() const;
  279. uint32_t get_max_framesize() const;
  280. uint32_t get_sample_rate() const;
  281. uint32_t get_channels() const;
  282. uint32_t get_bits_per_sample() const;
  283. FLAC__uint64 get_total_samples() const;
  284. const FLAC__byte *get_md5sum() const;
  285. void set_min_blocksize(uint32_t value);
  286. void set_max_blocksize(uint32_t value);
  287. void set_min_framesize(uint32_t value);
  288. void set_max_framesize(uint32_t value);
  289. void set_sample_rate(uint32_t value);
  290. void set_channels(uint32_t value);
  291. void set_bits_per_sample(uint32_t value);
  292. void set_total_samples(FLAC__uint64 value);
  293. void set_md5sum(const FLAC__byte value[16]);
  294. //@}
  295. };
  296. /** PADDING metadata block.
  297. * See the \link flacpp_metadata_object overview \endlink for more,
  298. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_padding">format specification</A>.
  299. */
  300. class FLACPP_API Padding : public Prototype {
  301. public:
  302. Padding();
  303. //@{
  304. /** Constructs a copy of the given object. This form
  305. * always performs a deep copy.
  306. */
  307. inline Padding(const Padding &object): Prototype(object) { }
  308. inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  309. inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  310. //@}
  311. /** Constructs an object with copy control. See
  312. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  313. */
  314. inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  315. /** Constructs an object with the given length.
  316. */
  317. Padding(uint32_t length);
  318. ~Padding();
  319. //@{
  320. /** Assign from another object. Always performs a deep copy. */
  321. inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; }
  322. inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  323. inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  324. //@}
  325. /** Assigns an object with copy control. See
  326. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  327. */
  328. inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  329. //@{
  330. /** Check for equality, performing a deep compare by following pointers. */
  331. inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
  332. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  333. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  334. //@}
  335. //@{
  336. /** Check for inequality, performing a deep compare by following pointers. */
  337. inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
  338. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  339. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  340. //@}
  341. /** Sets the length in bytes of the padding block.
  342. */
  343. void set_length(uint32_t length);
  344. };
  345. /** APPLICATION metadata block.
  346. * See the \link flacpp_metadata_object overview \endlink for more,
  347. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_application">format specification</A>.
  348. */
  349. class FLACPP_API Application : public Prototype {
  350. public:
  351. Application();
  352. //
  353. //@{
  354. /** Constructs a copy of the given object. This form
  355. * always performs a deep copy.
  356. */
  357. inline Application(const Application &object): Prototype(object) { }
  358. inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  359. inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  360. //@}
  361. /** Constructs an object with copy control. See
  362. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  363. */
  364. inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  365. ~Application();
  366. //@{
  367. /** Assign from another object. Always performs a deep copy. */
  368. inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; }
  369. inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  370. inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  371. //@}
  372. /** Assigns an object with copy control. See
  373. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  374. */
  375. inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  376. //@{
  377. /** Check for equality, performing a deep compare by following pointers. */
  378. inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
  379. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  380. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  381. //@}
  382. //@{
  383. /** Check for inequality, performing a deep compare by following pointers. */
  384. inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
  385. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  386. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  387. //@}
  388. const FLAC__byte *get_id() const;
  389. const FLAC__byte *get_data() const;
  390. void set_id(const FLAC__byte value[4]);
  391. //! This form always copies \a data
  392. bool set_data(const FLAC__byte *data, uint32_t length);
  393. bool set_data(FLAC__byte *data, uint32_t length, bool copy);
  394. };
  395. /** SEEKTABLE metadata block.
  396. * See the \link flacpp_metadata_object overview \endlink for more,
  397. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_seektable">format specification</A>.
  398. */
  399. class FLACPP_API SeekTable : public Prototype {
  400. public:
  401. SeekTable();
  402. //@{
  403. /** Constructs a copy of the given object. This form
  404. * always performs a deep copy.
  405. */
  406. inline SeekTable(const SeekTable &object): Prototype(object) { }
  407. inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  408. inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  409. //@}
  410. /** Constructs an object with copy control. See
  411. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  412. */
  413. inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  414. ~SeekTable();
  415. //@{
  416. /** Assign from another object. Always performs a deep copy. */
  417. inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; }
  418. inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  419. inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  420. //@}
  421. /** Assigns an object with copy control. See
  422. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  423. */
  424. inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  425. //@{
  426. /** Check for equality, performing a deep compare by following pointers. */
  427. inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
  428. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  429. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  430. //@}
  431. //@{
  432. /** Check for inequality, performing a deep compare by following pointers. */
  433. inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
  434. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  435. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  436. //@}
  437. uint32_t get_num_points() const;
  438. ::FLAC__StreamMetadata_SeekPoint get_point(uint32_t index) const;
  439. //! See FLAC__metadata_object_seektable_resize_points()
  440. bool resize_points(uint32_t new_num_points);
  441. //! See FLAC__metadata_object_seektable_set_point()
  442. void set_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point);
  443. //! See FLAC__metadata_object_seektable_insert_point()
  444. bool insert_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point);
  445. //! See FLAC__metadata_object_seektable_delete_point()
  446. bool delete_point(uint32_t index);
  447. //! See FLAC__metadata_object_seektable_is_legal()
  448. bool is_legal() const;
  449. //! See FLAC__metadata_object_seektable_template_append_placeholders()
  450. bool template_append_placeholders(uint32_t num);
  451. //! See FLAC__metadata_object_seektable_template_append_point()
  452. bool template_append_point(FLAC__uint64 sample_number);
  453. //! See FLAC__metadata_object_seektable_template_append_points()
  454. bool template_append_points(FLAC__uint64 sample_numbers[], uint32_t num);
  455. //! See FLAC__metadata_object_seektable_template_append_spaced_points()
  456. bool template_append_spaced_points(uint32_t num, FLAC__uint64 total_samples);
  457. //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
  458. bool template_append_spaced_points_by_samples(uint32_t samples, FLAC__uint64 total_samples);
  459. //! See FLAC__metadata_object_seektable_template_sort()
  460. bool template_sort(bool compact);
  461. };
  462. /** VORBIS_COMMENT metadata block.
  463. * See the \link flacpp_metadata_object overview \endlink for more,
  464. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_vorbis_comment">format specification</A>.
  465. */
  466. class FLACPP_API VorbisComment : public Prototype {
  467. public:
  468. /** Convenience class for encapsulating Vorbis comment
  469. * entries. An entry is a vendor string or a comment
  470. * field. In the case of a vendor string, the field
  471. * name is undefined; only the field value is relevant.
  472. *
  473. * A \a field as used in the methods refers to an
  474. * entire 'NAME=VALUE' string; for convenience the
  475. * string is NUL-terminated. A length field is
  476. * required in the unlikely event that the value
  477. * contains contain embedded NULs.
  478. *
  479. * A \a field_name is what is on the left side of the
  480. * first '=' in the \a field. By definition it is ASCII
  481. * and so is NUL-terminated and does not require a
  482. * length to describe it. \a field_name is undefined
  483. * for a vendor string entry.
  484. *
  485. * A \a field_value is what is on the right side of the
  486. * first '=' in the \a field. By definition, this may
  487. * contain embedded NULs and so a \a field_value_length
  488. * is required to describe it. However in practice,
  489. * embedded NULs are not known to be used, so it is
  490. * generally safe to treat field values as NUL-
  491. * terminated UTF-8 strings.
  492. *
  493. * Always check is_valid() after the constructor or operator=
  494. * to make sure memory was properly allocated and that the
  495. * Entry conforms to the Vorbis comment specification.
  496. */
  497. class FLACPP_API Entry {
  498. public:
  499. Entry();
  500. Entry(const char *field, uint32_t field_length);
  501. Entry(const char *field); // assumes \a field is NUL-terminated
  502. Entry(const char *field_name, const char *field_value, uint32_t field_value_length);
  503. Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
  504. Entry(const Entry &entry);
  505. Entry &operator=(const Entry &entry);
  506. virtual ~Entry();
  507. virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
  508. uint32_t get_field_length() const;
  509. uint32_t get_field_name_length() const;
  510. uint32_t get_field_value_length() const;
  511. ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
  512. const char *get_field() const;
  513. const char *get_field_name() const;
  514. const char *get_field_value() const;
  515. bool set_field(const char *field, uint32_t field_length);
  516. bool set_field(const char *field); // assumes \a field is NUL-terminated
  517. bool set_field_name(const char *field_name);
  518. bool set_field_value(const char *field_value, uint32_t field_value_length);
  519. bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated
  520. protected:
  521. bool is_valid_;
  522. ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
  523. char *field_name_;
  524. uint32_t field_name_length_;
  525. char *field_value_;
  526. uint32_t field_value_length_;
  527. private:
  528. void zero();
  529. void clear();
  530. void clear_entry();
  531. void clear_field_name();
  532. void clear_field_value();
  533. void construct(const char *field, uint32_t field_length);
  534. void construct(const char *field); // assumes \a field is NUL-terminated
  535. void construct(const char *field_name, const char *field_value, uint32_t field_value_length);
  536. void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
  537. void compose_field();
  538. void parse_field();
  539. };
  540. VorbisComment();
  541. //@{
  542. /** Constructs a copy of the given object. This form
  543. * always performs a deep copy.
  544. */
  545. inline VorbisComment(const VorbisComment &object): Prototype(object) { }
  546. inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  547. inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  548. //@}
  549. /** Constructs an object with copy control. See
  550. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  551. */
  552. inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  553. ~VorbisComment();
  554. //@{
  555. /** Assign from another object. Always performs a deep copy. */
  556. inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; }
  557. inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  558. inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  559. //@}
  560. /** Assigns an object with copy control. See
  561. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  562. */
  563. inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  564. //@{
  565. /** Check for equality, performing a deep compare by following pointers. */
  566. inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
  567. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  568. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  569. //@}
  570. //@{
  571. /** Check for inequality, performing a deep compare by following pointers. */
  572. inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
  573. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  574. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  575. //@}
  576. uint32_t get_num_comments() const;
  577. const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string
  578. Entry get_comment(uint32_t index) const;
  579. //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
  580. bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string
  581. //! See FLAC__metadata_object_vorbiscomment_resize_comments()
  582. bool resize_comments(uint32_t new_num_comments);
  583. //! See FLAC__metadata_object_vorbiscomment_set_comment()
  584. bool set_comment(uint32_t index, const Entry &entry);
  585. //! See FLAC__metadata_object_vorbiscomment_insert_comment()
  586. bool insert_comment(uint32_t index, const Entry &entry);
  587. //! See FLAC__metadata_object_vorbiscomment_append_comment()
  588. bool append_comment(const Entry &entry);
  589. //! See FLAC__metadata_object_vorbiscomment_replace_comment()
  590. bool replace_comment(const Entry &entry, bool all);
  591. //! See FLAC__metadata_object_vorbiscomment_delete_comment()
  592. bool delete_comment(uint32_t index);
  593. //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
  594. int find_entry_from(uint32_t offset, const char *field_name);
  595. //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
  596. int remove_entry_matching(const char *field_name);
  597. //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
  598. int remove_entries_matching(const char *field_name);
  599. };
  600. /** CUESHEET metadata block.
  601. * See the \link flacpp_metadata_object overview \endlink for more,
  602. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_cuesheet">format specification</A>.
  603. */
  604. class FLACPP_API CueSheet : public Prototype {
  605. public:
  606. /** Convenience class for encapsulating a cue sheet
  607. * track.
  608. *
  609. * Always check is_valid() after the constructor or operator=
  610. * to make sure memory was properly allocated.
  611. */
  612. class FLACPP_API Track {
  613. protected:
  614. ::FLAC__StreamMetadata_CueSheet_Track *object_;
  615. public:
  616. Track();
  617. Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
  618. Track(const Track &track);
  619. Track &operator=(const Track &track);
  620. virtual ~Track();
  621. virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
  622. inline FLAC__uint64 get_offset() const { return object_->offset; }
  623. inline FLAC__byte get_number() const { return object_->number; }
  624. inline const char *get_isrc() const { return object_->isrc; }
  625. inline uint32_t get_type() const { return object_->type; }
  626. inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
  627. inline FLAC__byte get_num_indices() const { return object_->num_indices; }
  628. ::FLAC__StreamMetadata_CueSheet_Index get_index(uint32_t i) const;
  629. inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
  630. inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
  631. inline void set_number(FLAC__byte value) { object_->number = value; }
  632. void set_isrc(const char value[12]);
  633. void set_type(uint32_t value);
  634. inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
  635. void set_index(uint32_t i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  636. //@@@ It's awkward but to insert/delete index points
  637. //@@@ you must use the routines in the CueSheet class.
  638. };
  639. CueSheet();
  640. //@{
  641. /** Constructs a copy of the given object. This form
  642. * always performs a deep copy.
  643. */
  644. inline CueSheet(const CueSheet &object): Prototype(object) { }
  645. inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  646. inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  647. //@}
  648. /** Constructs an object with copy control. See
  649. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  650. */
  651. inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  652. ~CueSheet();
  653. //@{
  654. /** Assign from another object. Always performs a deep copy. */
  655. inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; }
  656. inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  657. inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  658. //@}
  659. /** Assigns an object with copy control. See
  660. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  661. */
  662. inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  663. //@{
  664. /** Check for equality, performing a deep compare by following pointers. */
  665. inline bool operator==(const CueSheet &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); }
  668. //@}
  669. //@{
  670. /** Check for inequality, performing a deep compare by following pointers. */
  671. inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
  672. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  673. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  674. //@}
  675. const char *get_media_catalog_number() const;
  676. FLAC__uint64 get_lead_in() const;
  677. bool get_is_cd() const;
  678. uint32_t get_num_tracks() const;
  679. Track get_track(uint32_t i) const;
  680. void set_media_catalog_number(const char value[128]);
  681. void set_lead_in(FLAC__uint64 value);
  682. void set_is_cd(bool value);
  683. void set_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  684. //! See FLAC__metadata_object_cuesheet_track_resize_indices()
  685. bool resize_indices(uint32_t track_num, uint32_t new_num_indices);
  686. //! See FLAC__metadata_object_cuesheet_track_insert_index()
  687. bool insert_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  688. //! See FLAC__metadata_object_cuesheet_track_insert_blank_index()
  689. bool insert_blank_index(uint32_t track_num, uint32_t index_num);
  690. //! See FLAC__metadata_object_cuesheet_track_delete_index()
  691. bool delete_index(uint32_t track_num, uint32_t index_num);
  692. //! See FLAC__metadata_object_cuesheet_resize_tracks()
  693. bool resize_tracks(uint32_t new_num_tracks);
  694. //! See FLAC__metadata_object_cuesheet_set_track()
  695. bool set_track(uint32_t i, const Track &track);
  696. //! See FLAC__metadata_object_cuesheet_insert_track()
  697. bool insert_track(uint32_t i, const Track &track);
  698. //! See FLAC__metadata_object_cuesheet_insert_blank_track()
  699. bool insert_blank_track(uint32_t i);
  700. //! See FLAC__metadata_object_cuesheet_delete_track()
  701. bool delete_track(uint32_t i);
  702. //! See FLAC__metadata_object_cuesheet_is_legal()
  703. bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
  704. //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
  705. FLAC__uint32 calculate_cddb_id() const;
  706. };
  707. /** PICTURE metadata block.
  708. * See the \link flacpp_metadata_object overview \endlink for more,
  709. * and the <A HREF="https://xiph.org/flac/format.html#metadata_block_picture">format specification</A>.
  710. */
  711. class FLACPP_API Picture : public Prototype {
  712. public:
  713. Picture();
  714. //@{
  715. /** Constructs a copy of the given object. This form
  716. * always performs a deep copy.
  717. */
  718. inline Picture(const Picture &object): Prototype(object) { }
  719. inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  720. inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  721. //@}
  722. /** Constructs an object with copy control. See
  723. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  724. */
  725. inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  726. ~Picture();
  727. //@{
  728. /** Assign from another object. Always performs a deep copy. */
  729. inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; }
  730. inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  731. inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  732. //@}
  733. /** Assigns an object with copy control. See
  734. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  735. */
  736. inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  737. //@{
  738. /** Check for equality, performing a deep compare by following pointers. */
  739. inline bool operator==(const Picture &object) const { return Prototype::operator==(object); }
  740. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  741. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  742. //@}
  743. //@{
  744. /** Check for inequality, performing a deep compare by following pointers. */
  745. inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); }
  746. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  747. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  748. //@}
  749. ::FLAC__StreamMetadata_Picture_Type get_type() const;
  750. const char *get_mime_type() const; // NUL-terminated printable ASCII string
  751. const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string
  752. FLAC__uint32 get_width() const;
  753. FLAC__uint32 get_height() const;
  754. FLAC__uint32 get_depth() const;
  755. FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
  756. FLAC__uint32 get_data_length() const;
  757. const FLAC__byte *get_data() const;
  758. void set_type(::FLAC__StreamMetadata_Picture_Type type);
  759. //! See FLAC__metadata_object_picture_set_mime_type()
  760. bool set_mime_type(const char *string); // NUL-terminated printable ASCII string
  761. //! See FLAC__metadata_object_picture_set_description()
  762. bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string
  763. void set_width(FLAC__uint32 value) const;
  764. void set_height(FLAC__uint32 value) const;
  765. void set_depth(FLAC__uint32 value) const;
  766. void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
  767. //! See FLAC__metadata_object_picture_set_data()
  768. bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
  769. //! See FLAC__metadata_object_picture_is_legal()
  770. bool is_legal(const char **violation);
  771. };
  772. /** Opaque metadata block for storing unknown types.
  773. * This should not be used unless you know what you are doing;
  774. * it is currently used only internally to support forward
  775. * compatibility of metadata blocks.
  776. * See the \link flacpp_metadata_object overview \endlink for more,
  777. */
  778. class FLACPP_API Unknown : public Prototype {
  779. public:
  780. Unknown();
  781. //
  782. //@{
  783. /** Constructs a copy of the given object. This form
  784. * always performs a deep copy.
  785. */
  786. inline Unknown(const Unknown &object): Prototype(object) { }
  787. inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  788. inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  789. //@}
  790. /** Constructs an object with copy control. See
  791. * Prototype(::FLAC__StreamMetadata *object, bool copy).
  792. */
  793. inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  794. ~Unknown();
  795. //@{
  796. /** Assign from another object. Always performs a deep copy. */
  797. inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; }
  798. inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
  799. inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
  800. //@}
  801. /** Assigns an object with copy control. See
  802. * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
  803. */
  804. inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
  805. //@{
  806. /** Check for equality, performing a deep compare by following pointers. */
  807. inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
  808. inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  809. inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  810. //@}
  811. //@{
  812. /** Check for inequality, performing a deep compare by following pointers. */
  813. inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
  814. inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  815. inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  816. //@}
  817. const FLAC__byte *get_data() const;
  818. //! This form always copies \a data
  819. bool set_data(const FLAC__byte *data, uint32_t length);
  820. bool set_data(FLAC__byte *data, uint32_t length, bool copy);
  821. };
  822. /* \} */
  823. /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
  824. * \ingroup flacpp_metadata
  825. *
  826. * \brief
  827. * Level 0 metadata iterators.
  828. *
  829. * See the \link flac_metadata_level0 C layer equivalent \endlink
  830. * for more.
  831. *
  832. * \{
  833. */
  834. FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo().
  835. FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags().
  836. FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags().
  837. FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet().
  838. FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet().
  839. FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture().
  840. FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture().
  841. /* \} */
  842. /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
  843. * \ingroup flacpp_metadata
  844. *
  845. * \brief
  846. * Level 1 metadata iterator.
  847. *
  848. * The flow through the iterator in the C++ layer is similar
  849. * to the C layer:
  850. * - Create a SimpleIterator instance
  851. * - Check SimpleIterator::is_valid()
  852. * - Call SimpleIterator::init() and check the return
  853. * - Traverse and/or edit. Edits are written to file
  854. * immediately.
  855. * - Destroy the SimpleIterator instance
  856. *
  857. * The ownership of pointers in the C++ layer follows that in
  858. * the C layer, i.e.
  859. * - The objects returned by get_block() are yours to
  860. * modify, but changes are not reflected in the FLAC file
  861. * until you call set_block(). The objects are also
  862. * yours to delete; they are not automatically deleted
  863. * when passed to set_block() or insert_block_after().
  864. *
  865. * See the \link flac_metadata_level1 C layer equivalent \endlink
  866. * for more.
  867. *
  868. * \{
  869. */
  870. /** This class is a wrapper around the FLAC__metadata_simple_iterator
  871. * structures and methods; see the
  872. * \link flacpp_metadata_level1 usage guide \endlink and
  873. * ::FLAC__Metadata_SimpleIterator.
  874. */
  875. class FLACPP_API SimpleIterator {
  876. public:
  877. /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
  878. */
  879. class FLACPP_API Status {
  880. public:
  881. inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
  882. inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
  883. inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
  884. protected:
  885. ::FLAC__Metadata_SimpleIteratorStatus status_;
  886. };
  887. SimpleIterator();
  888. virtual ~SimpleIterator();
  889. bool is_valid() const; ///< Returns \c true iff object was properly constructed.
  890. bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init().
  891. Status status(); ///< See FLAC__metadata_simple_iterator_status().
  892. bool is_writable() const; ///< See FLAC__metadata_simple_iterator_is_writable().
  893. bool next(); ///< See FLAC__metadata_simple_iterator_next().
  894. bool prev(); ///< See FLAC__metadata_simple_iterator_prev().
  895. bool is_last() const; ///< See FLAC__metadata_simple_iterator_is_last().
  896. off_t get_block_offset() const; ///< See FLAC__metadata_simple_iterator_get_block_offset().
  897. ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_simple_iterator_get_block_type().
  898. uint32_t get_block_length() const; ///< See FLAC__metadata_simple_iterator_get_block_length().
  899. bool get_application_id(FLAC__byte *id); ///< See FLAC__metadata_simple_iterator_get_application_id().
  900. Prototype *get_block(); ///< See FLAC__metadata_simple_iterator_get_block().
  901. bool set_block(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_set_block().
  902. bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
  903. bool delete_block(bool use_padding = true); ///< See FLAC__metadata_simple_iterator_delete_block().
  904. protected:
  905. ::FLAC__Metadata_SimpleIterator *iterator_;
  906. void clear();
  907. private: // Do not use.
  908. SimpleIterator(const SimpleIterator&);
  909. SimpleIterator&operator=(const SimpleIterator&);
  910. };
  911. /* \} */
  912. /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
  913. * \ingroup flacpp_metadata
  914. *
  915. * \brief
  916. * Level 2 metadata iterator.
  917. *
  918. * The flow through the iterator in the C++ layer is similar
  919. * to the C layer:
  920. * - Create a Chain instance
  921. * - Check Chain::is_valid()
  922. * - Call Chain::read() and check the return
  923. * - Traverse and/or edit with an Iterator or with
  924. * Chain::merge_padding() or Chain::sort_padding()
  925. * - Write changes back to FLAC file with Chain::write()
  926. * - Destroy the Chain instance
  927. *
  928. * The ownership of pointers in the C++ layer is slightly
  929. * different than in the C layer, i.e.
  930. * - The objects returned by Iterator::get_block() are NOT
  931. * owned by the iterator and should be deleted by the
  932. * caller when finished, BUT, when you modify the block,
  933. * it will directly edit what's in the chain and you do
  934. * not need to call Iterator::set_block(). However the
  935. * changes will not be reflected in the FLAC file until
  936. * the chain is written with Chain::write().
  937. * - When you pass an object to Iterator::set_block(),
  938. * Iterator::insert_block_before(), or
  939. * Iterator::insert_block_after(), the iterator takes
  940. * ownership of the block and it will be deleted by the
  941. * chain.
  942. *
  943. * See the \link flac_metadata_level2 C layer equivalent \endlink
  944. * for more.
  945. *
  946. * \{
  947. */
  948. /** This class is a wrapper around the FLAC__metadata_chain
  949. * structures and methods; see the
  950. * \link flacpp_metadata_level2 usage guide \endlink and
  951. * ::FLAC__Metadata_Chain.
  952. */
  953. class FLACPP_API Chain {
  954. public:
  955. /** This class is a wrapper around FLAC__Metadata_ChainStatus.
  956. */
  957. class FLACPP_API Status {
  958. public:
  959. inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
  960. inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
  961. inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
  962. protected:
  963. ::FLAC__Metadata_ChainStatus status_;
  964. };
  965. Chain();
  966. virtual ~Chain();
  967. friend class Iterator;
  968. bool is_valid() const; ///< Returns \c true iff object was properly constructed.
  969. Status status(); ///< See FLAC__metadata_chain_status().
  970. bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
  971. 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().
  972. bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed().
  973. bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write().
  974. bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks().
  975. 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().
  976. void merge_padding(); ///< See FLAC__metadata_chain_merge_padding().
  977. void sort_padding(); ///< See FLAC__metadata_chain_sort_padding().
  978. protected:
  979. ::FLAC__Metadata_Chain *chain_;
  980. virtual void clear();
  981. private: // Do not use.
  982. Chain(const Chain&);
  983. Chain&operator=(const Chain&);
  984. };
  985. /** This class is a wrapper around the FLAC__metadata_iterator
  986. * structures and methods; see the
  987. * \link flacpp_metadata_level2 usage guide \endlink and
  988. * ::FLAC__Metadata_Iterator.
  989. */
  990. class FLACPP_API Iterator {
  991. public:
  992. Iterator();
  993. virtual ~Iterator();
  994. bool is_valid() const; ///< Returns \c true iff object was properly constructed.
  995. void init(Chain &chain); ///< See FLAC__metadata_iterator_init().
  996. bool next(); ///< See FLAC__metadata_iterator_next().
  997. bool prev(); ///< See FLAC__metadata_iterator_prev().
  998. ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_iterator_get_block_type().
  999. Prototype *get_block(); ///< See FLAC__metadata_iterator_get_block().
  1000. bool set_block(Prototype *block); ///< See FLAC__metadata_iterator_set_block().
  1001. bool delete_block(bool replace_with_padding); ///< See FLAC__metadata_iterator_delete_block().
  1002. bool insert_block_before(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_before().
  1003. bool insert_block_after(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_after().
  1004. protected:
  1005. ::FLAC__Metadata_Iterator *iterator_;
  1006. virtual void clear();
  1007. private: // Do not use.
  1008. Iterator(const Iterator&);
  1009. Iterator&operator=(const Iterator&);
  1010. };
  1011. /* \} */
  1012. }
  1013. }
  1014. #endif