metadata.h 50 KB

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