1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2001,2002,2003,2004 Josh Coalson
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef FLAC__METADATA_H
33 #define FLAC__METADATA_H
38 /******************************************************************************
39 (For an example of how all these routines are used, see the source
40 code for the unit tests in src/test_libFLAC/metadata_*.c, or metaflac
42 ******************************************************************************/
44 /** \file include/FLAC/metadata.h
47 * This module provides functions for creating and manipulating FLAC
48 * metadata blocks in memory, and three progressively more powerful
49 * interfaces for traversing and editing metadata in FLAC files.
51 * See the detailed documentation for each interface in the
52 * \link flac_metadata metadata \endlink module.
55 /** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces
59 * This module provides functions for creating and manipulating FLAC
60 * metadata blocks in memory, and three progressively more powerful
61 * interfaces for traversing and editing metadata in FLAC files.
63 * There are three metadata interfaces of increasing complexity:
66 * Read-only access to the STREAMINFO block.
69 * Read-write access to all metadata blocks. This level is write-
70 * efficient in most cases (more on this below), and uses less memory
74 * Read-write access to all metadata blocks. This level is write-
75 * efficient in all cases, but uses more memory since all metadata for
76 * the whole file is read into memory and manipulated before writing
79 * What do we mean by efficient? When writing metadata back to a FLAC
80 * file it is possible to grow or shrink the metadata such that the entire
81 * file must be rewritten. However, if the size remains the same during
82 * changes or PADDING blocks are utilized, only the metadata needs to be
83 * overwritten, which is much faster.
85 * Efficient means the whole file is rewritten at most one time, and only
86 * when necessary. Level 1 is not efficient only in the case that you
87 * cause more than one metadata block to grow or shrink beyond what can
88 * be accomodated by padding. In this case you should probably use level
89 * 2, which allows you to edit all the metadata for a file in memory and
90 * write it out all at once.
92 * All levels know how to skip over and not disturb an ID3v2 tag at the
95 * In addition to the three interfaces, this module defines functions for
96 * creating and manipulating various metadata objects in memory. As we see
97 * from the Format module, FLAC metadata blocks in memory are very primitive
98 * structures for storing information in an efficient way. Reading
99 * information from the structures is easy but creating or modifying them
100 * directly is more complex. The metadata object routines here facilitate
101 * this by taking care of the consistency and memory management drudgery.
103 * Unless you will be using the level 1 or 2 interfaces to modify existing
104 * metadata however, you will not probably not need these.
106 * From a dependency standpoint, none of the encoders or decoders require
107 * the metadata module. This is so that embedded users can strip out the
108 * metadata module from libFLAC to reduce the size and complexity.
116 /** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface
117 * \ingroup flac_metadata
120 * The level 0 interface consists of a single routine to read the
123 * It skips any ID3v2 tag at the head of the file.
128 /** Read the STREAMINFO metadata block of the given FLAC file. This function
129 * will skip any ID3v2 tag at the head of the file.
131 * \param filename The path to the FLAC file to read.
132 * \param streaminfo A pointer to space for the STREAMINFO block.
134 * \code filename != NULL \endcode
135 * \code streaminfo != NULL \endcode
137 * \c true if a valid STREAMINFO block was read from \a filename. Returns
138 * \c false if there was a memory allocation error, a file decoder error,
139 * or the file contained no STREAMINFO block.
141 FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
146 /** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface
147 * \ingroup flac_metadata
150 * The level 1 interface provides read-write access to FLAC file metadata and
151 * operates directly on the FLAC file.
153 * The general usage of this interface is:
155 * - Create an iterator using FLAC__metadata_simple_iterator_new()
156 * - Attach it to a file using FLAC__metadata_simple_iterator_init() and check
157 * the exit code. Call FLAC__metadata_simple_iterator_is_writable() to
158 * see if the file is writable, or read-only access is allowed.
159 * - Use FLAC__metadata_simple_iterator_next() and
160 * FLAC__metadata_simple_iterator_prev() to move around the blocks.
161 * This is does not read the actual blocks themselves.
162 * FLAC__metadata_simple_iterator_next() is relatively fast.
163 * FLAC__metadata_simple_iterator_prev() is slower since it needs to search
164 * forward from the front of the file.
165 * - Use FLAC__metadata_simple_iterator_get_block_type() or
166 * FLAC__metadata_simple_iterator_get_block() to access the actual data at
167 * the current iterator position. The returned object is yours to modify
169 * - Use FLAC__metadata_simple_iterator_set_block() to write a modified block
170 * back. You must have write permission to the original file. Make sure to
171 * read the whole comment to FLAC__metadata_simple_iterator_set_block()
173 * - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks.
174 * Use the object creation functions from
175 * \link flac_metadata_object here \endlink to generate new objects.
176 * - Use FLAC__metadata_simple_iterator_delete_block() to remove the block
177 * currently referred to by the iterator, or replace it with padding.
178 * - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when
182 * The FLAC file remains open the whole time between
183 * FLAC__metadata_simple_iterator_init() and
184 * FLAC__metadata_simple_iterator_delete(), so make sure you are not altering
185 * the file during this time.
188 * Do not modify the \a is_last, \a length, or \a type fields of returned
189 * FLAC__MetadataType objects. These are managed automatically.
192 * If any of the modification functions
193 * (FLAC__metadata_simple_iterator_set_block(),
194 * FLAC__metadata_simple_iterator_delete_block(),
195 * FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false,
196 * you should delete the iterator as it may no longer be valid.
201 struct FLAC__Metadata_SimpleIterator;
202 /** The opaque structure definition for the level 1 iterator type.
204 * \link flac_metadata_level1 metadata level 1 module \endlink
205 * for a detailed description.
207 typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
209 /** Status type for FLAC__Metadata_SimpleIterator.
211 * The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status().
215 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
216 /**< The iterator is in the normal OK state */
218 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
219 /**< The data passed into a function violated the function's usage criteria */
221 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
222 /**< The iterator could not open the target file */
224 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
225 /**< The iterator could not find the FLAC signature at the start of the file */
227 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
228 /**< The iterator tried to write to a file that was not writable */
230 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
231 /**< The iterator encountered input that does not conform to the FLAC metadata specification */
233 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
234 /**< The iterator encountered an error while reading the FLAC file */
236 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
237 /**< The iterator encountered an error while seeking in the FLAC file */
239 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
240 /**< The iterator encountered an error while writing the FLAC file */
242 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
243 /**< The iterator encountered an error renaming the FLAC file */
245 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
246 /**< The iterator encountered an error removing the temporary file */
248 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
249 /**< Memory allocation failed */
251 FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
252 /**< The caller violated an assertion or an unexpected error occurred */
254 } FLAC__Metadata_SimpleIteratorStatus;
256 /** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string.
258 * Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array
259 * will give the string equivalent. The contents should not be modified.
261 extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
264 /** Create a new iterator instance.
266 * \retval FLAC__Metadata_SimpleIterator*
267 * \c NULL if there was an error allocating memory, else the new instance.
269 FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new();
271 /** Free an iterator instance. Deletes the object pointed to by \a iterator.
273 * \param iterator A pointer to an existing iterator.
275 * \code iterator != NULL \endcode
277 FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
279 /** Get the current status of the iterator. Call this after a function
280 * returns \c false to get the reason for the error. Also resets the status
281 * to FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK.
283 * \param iterator A pointer to an existing iterator.
285 * \code iterator != NULL \endcode
286 * \retval FLAC__Metadata_SimpleIteratorStatus
287 * The current status of the iterator.
289 FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
291 /** Initialize the iterator to point to the first metadata block in the
294 * \param iterator A pointer to an existing iterator.
295 * \param filename The path to the FLAC file.
296 * \param read_only If \c true, the FLAC file will be opened
297 * in read-only mode; if \c false, the FLAC
298 * file will be opened for edit even if no
299 * edits are performed.
300 * \param preserve_file_stats If \c true, the owner and modification
301 * time will be preserved even if the FLAC
302 * file is written to.
304 * \code iterator != NULL \endcode
305 * \code filename != NULL \endcode
307 * \c false if a memory allocation error occurs, the file can't be
308 * opened, or another error occurs, else \c true.
310 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
312 /** Returns \c true if the FLAC file is writable. If \c false, calls to
313 * FLAC__metadata_simple_iterator_set_block() and
314 * FLAC__metadata_simple_iterator_insert_block_after() will fail.
316 * \param iterator A pointer to an existing iterator.
318 * \code iterator != NULL \endcode
322 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
324 /** Moves the iterator forward one metadata block, returning \c false if
325 * already at the end.
327 * \param iterator A pointer to an existing initialized iterator.
329 * \code iterator != NULL \endcode
330 * \a iterator has been successfully initialized with
331 * FLAC__metadata_simple_iterator_init()
333 * \c false if already at the last metadata block of the chain, else
336 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
338 /** Moves the iterator backward one metadata block, returning \c false if
339 * already at the beginning.
341 * \param iterator A pointer to an existing initialized iterator.
343 * \code iterator != NULL \endcode
344 * \a iterator has been successfully initialized with
345 * FLAC__metadata_simple_iterator_init()
347 * \c false if already at the first metadata block of the chain, else
350 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
352 /** Get the type of the metadata block at the current position. This
353 * avoids reading the actual block data which can save time for large
356 * \param iterator A pointer to an existing initialized iterator.
358 * \code iterator != NULL \endcode
359 * \a iterator has been successfully initialized with
360 * FLAC__metadata_simple_iterator_init()
361 * \retval FLAC__MetadataType
362 * The type of the metadata block at the current iterator position.
365 FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
367 /** Get the metadata block at the current position. You can modify the
368 * block but must use FLAC__metadata_simple_iterator_set_block() to
369 * write it back to the FLAC file.
371 * You must call FLAC__metadata_object_delete() on the returned object
372 * when you are finished with it.
374 * \param iterator A pointer to an existing initialized iterator.
376 * \code iterator != NULL \endcode
377 * \a iterator has been successfully initialized with
378 * FLAC__metadata_simple_iterator_init()
379 * \retval FLAC__StreamMetadata*
380 * The current metadata block.
382 FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
384 /** Write a block back to the FLAC file. This function tries to be
385 * as efficient as possible; how the block is actually written is
386 * shown by the following:
388 * Existing block is a STREAMINFO block and the new block is a
389 * STREAMINFO block: the new block is written in place. Make sure
390 * you know what you're doing when changing the values of a
393 * Existing block is a STREAMINFO block and the new block is a
394 * not a STREAMINFO block: this is an error since the first block
395 * must be a STREAMINFO block. Returns \c false without altering the
398 * Existing block is not a STREAMINFO block and the new block is a
399 * STREAMINFO block: this is an error since there may be only one
400 * STREAMINFO block. Returns \c false without altering the file.
402 * Existing block and new block are the same length: the existing
403 * block will be replaced by the new block, written in place.
405 * Existing block is longer than new block: if use_padding is \c true,
406 * the existing block will be overwritten in place with the new
407 * block followed by a PADDING block, if possible, to make the total
408 * size the same as the existing block. Remember that a padding
409 * block requires at least four bytes so if the difference in size
410 * between the new block and existing block is less than that, the
411 * entire file will have to be rewritten, using the new block's
412 * exact size. If use_padding is \c false, the entire file will be
413 * rewritten, replacing the existing block by the new block.
415 * Existing block is shorter than new block: if use_padding is \c true,
416 * the function will try and expand the new block into the following
417 * PADDING block, if it exists and doing so won't shrink the PADDING
418 * block to less than 4 bytes. If there is no following PADDING
419 * block, or it will shrink to less than 4 bytes, or use_padding is
420 * \c false, the entire file is rewritten, replacing the existing block
421 * with the new block. Note that in this case any following PADDING
422 * block is preserved as is.
424 * After writing the block, the iterator will remain in the same
425 * place, i.e. pointing to the new block.
427 * \param iterator A pointer to an existing initialized iterator.
428 * \param block The block to set.
429 * \param use_padding See above.
431 * \code iterator != NULL \endcode
432 * \a iterator has been successfully initialized with
433 * FLAC__metadata_simple_iterator_init()
434 * \code block != NULL \endcode
436 * \c true if successful, else \c false.
438 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
440 /** This is similar to FLAC__metadata_simple_iterator_set_block()
441 * except that instead of writing over an existing block, it appends
442 * a block after the existing block. \a use_padding is again used to
443 * tell the function to try an expand into following padding in an
444 * attempt to avoid rewriting the entire file.
446 * This function will fail and return \c false if given a STREAMINFO
449 * After writing the block, the iterator will be pointing to the
452 * \param iterator A pointer to an existing initialized iterator.
453 * \param block The block to set.
454 * \param use_padding See above.
456 * \code iterator != NULL \endcode
457 * \a iterator has been successfully initialized with
458 * FLAC__metadata_simple_iterator_init()
459 * \code block != NULL \endcode
461 * \c true if successful, else \c false.
463 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
465 /** Deletes the block at the current position. This will cause the
466 * entire FLAC file to be rewritten, unless \a use_padding is \c true,
467 * in which case the block will be replaced by an equal-sized PADDING
468 * block. The iterator will be left pointing to the block before the
471 * You may not delete the STREAMINFO block.
473 * \param iterator A pointer to an existing initialized iterator.
474 * \param use_padding See above.
476 * \code iterator != NULL \endcode
477 * \a iterator has been successfully initialized with
478 * FLAC__metadata_simple_iterator_init()
480 * \c true if successful, else \c false.
482 FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
487 /** \defgroup flac_metadata_level2 FLAC/metadata.h: metadata level 2 interface
488 * \ingroup flac_metadata
491 * The level 2 interface provides read-write access to FLAC file metadata;
492 * all metadata is read into memory, operated on in memory, and then written
493 * to file, which is more efficient than level 1 when editing multiple blocks.
495 * The general usage of this interface is:
497 * - Create a new chain using FLAC__metadata_chain_new(). A chain is a
498 * linked list of FLAC metadata blocks.
499 * - Read all metadata into the the chain from a FLAC file using
500 * FLAC__metadata_chain_read() and check the status.
501 * - Optionally, consolidate the padding using
502 * FLAC__metadata_chain_merge_padding() or
503 * FLAC__metadata_chain_sort_padding().
504 * - Create a new iterator using FLAC__metadata_iterator_new()
505 * - Initialize the iterator to point to the first element in the chain
506 * using FLAC__metadata_iterator_init()
507 * - Traverse the chain using FLAC__metadata_iterator_next and
508 * FLAC__metadata_iterator_prev().
509 * - Get a block for reading or modification using
510 * FLAC__metadata_iterator_get_block(). The pointer to the object
511 * inside the chain is returned, so the block is yours to modify.
512 * Changes will be reflected in the FLAC file when you write the
513 * chain. You can also add and delete blocks (see functions below).
514 * - When done, write out the chain using FLAC__metadata_chain_write().
515 * Make sure to read the whole comment to the function below.
516 * - Delete the chain using FLAC__metadata_chain_delete().
519 * Even though the FLAC file is not open while the chain is being
520 * manipulated, you must not alter the file externally during
521 * this time. The chain assumes the FLAC file will not change
522 * between the time of FLAC__metadata_chain_read() and
523 * FLAC__metadata_chain_write().
526 * Do not modify the is_last, length, or type fields of returned
527 * FLAC__MetadataType objects. These are managed automatically.
530 * The metadata objects returned by FLAC__metadata_iterator_get_block()
531 * are owned by the chain; do not FLAC__metadata_object_delete() them.
532 * In the same way, blocks passed to FLAC__metadata_iterator_set_block()
533 * become owned by the chain and they will be deleted when the chain is
539 struct FLAC__Metadata_Chain;
540 /** The opaque structure definition for the level 2 chain type.
542 typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
544 struct FLAC__Metadata_Iterator;
545 /** The opaque structure definition for the level 2 iterator type.
547 typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
550 FLAC__METADATA_CHAIN_STATUS_OK = 0,
551 /**< The chain is in the normal OK state */
553 FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
554 /**< The data passed into a function violated the function's usage criteria */
556 FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
557 /**< The chain could not open the target file */
559 FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
560 /**< The chain could not find the FLAC signature at the start of the file */
562 FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
563 /**< The chain tried to write to a file that was not writable */
565 FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
566 /**< The chain encountered input that does not conform to the FLAC metadata specification */
568 FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
569 /**< The chain encountered an error while reading the FLAC file */
571 FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
572 /**< The chain encountered an error while seeking in the FLAC file */
574 FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
575 /**< The chain encountered an error while writing the FLAC file */
577 FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
578 /**< The chain encountered an error renaming the FLAC file */
580 FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
581 /**< The chain encountered an error removing the temporary file */
583 FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
584 /**< Memory allocation failed */
586 FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR
587 /**< The caller violated an assertion or an unexpected error occurred */
589 } FLAC__Metadata_ChainStatus;
591 /** Maps a FLAC__Metadata_ChainStatus to a C string.
593 * Using a FLAC__Metadata_ChainStatus as the index to this array
594 * will give the string equivalent. The contents should not be modified.
596 extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
598 /*********** FLAC__Metadata_Chain ***********/
600 /** Create a new chain instance.
602 * \retval FLAC__Metadata_Chain*
603 * \c NULL if there was an error allocating memory, else the new instance.
605 FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new();
607 /** Free a chain instance. Deletes the object pointed to by \a chain.
609 * \param chain A pointer to an existing chain.
611 * \code chain != NULL \endcode
613 FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
615 /** Get the current status of the chain. Call this after a function
616 * returns \c false to get the reason for the error. Also resets the
617 * status to FLAC__METADATA_CHAIN_STATUS_OK.
619 * \param chain A pointer to an existing chain.
621 * \code chain != NULL \endcode
622 * \retval FLAC__Metadata_ChainStatus
623 * The current status of the chain.
625 FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
627 /** Read all metadata from a FLAC file into the chain.
629 * \param chain A pointer to an existing chain.
630 * \param filename The path to the FLAC file to read.
632 * \code chain != NULL \endcode
633 * \code filename != NULL \endcode
635 * \c true if a valid list of metadata blocks was read from
636 * \a filename, else \c false. On failure, check the status with
637 * FLAC__metadata_chain_status().
639 FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
641 /** Write all metadata out to the FLAC file. This function tries to be as
642 * efficient as possible; how the metadata is actually written is shown by
645 * If the current chain is the same size as the existing metadata, the new
646 * data is written in place.
648 * If the current chain is longer than the existing metadata, and
649 * \a use_padding is \c true, and the last block is a PADDING block of
650 * sufficient length, the function will truncate the final padding block
651 * so that the overall size of the metadata is the same as the existing
652 * metadata, and then just rewrite the metadata. Otherwise, if not all of
653 * the above conditions are met, the entire FLAC file must be rewritten.
654 * If you want to use padding this way it is a good idea to call
655 * FLAC__metadata_chain_sort_padding() first so that you have the maximum
656 * amount of padding to work with, unless you need to preserve ordering
657 * of the PADDING blocks for some reason.
659 * If the current chain is shorter than the existing metadata, and
660 * \a use_padding is \c true, and the final block is a PADDING block, the padding
661 * is extended to make the overall size the same as the existing data. If
662 * \a use_padding is \c true and the last block is not a PADDING block, a new
663 * PADDING block is added to the end of the new data to make it the same
664 * size as the existing data (if possible, see the note to
665 * FLAC__metadata_simple_iterator_set_block() about the four byte limit)
666 * and the new data is written in place. If none of the above apply or
667 * \a use_padding is \c false, the entire FLAC file is rewritten.
669 * If \a preserve_file_stats is \c true, the owner and modification time will
670 * be preserved even if the FLAC file is written.
672 * \param chain A pointer to an existing chain.
673 * \param use_padding See above.
674 * \param preserve_file_stats See above.
676 * \code chain != NULL \endcode
678 * \c true if the write succeeded, else \c false. On failure,
679 * check the status with FLAC__metadata_chain_status().
681 FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
683 /** Merge adjacent PADDING blocks into a single block.
685 * \note This function does not write to the FLAC file, it only
686 * modifies the chain.
688 * \warning Any iterator on the current chain will become invalid after this
689 * call. You should delete the iterator and get a new one.
691 * \param chain A pointer to an existing chain.
693 * \code chain != NULL \endcode
695 FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
697 /** This function will move all PADDING blocks to the end on the metadata,
698 * then merge them into a single block.
700 * \note This function does not write to the FLAC file, it only
701 * modifies the chain.
703 * \warning Any iterator on the current chain will become invalid after this
704 * call. You should delete the iterator and get a new one.
706 * \param chain A pointer to an existing chain.
708 * \code chain != NULL \endcode
710 FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
713 /*********** FLAC__Metadata_Iterator ***********/
715 /** Create a new iterator instance.
717 * \retval FLAC__Metadata_Iterator*
718 * \c NULL if there was an error allocating memory, else the new instance.
720 FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new();
722 /** Free an iterator instance. Deletes the object pointed to by \a iterator.
724 * \param iterator A pointer to an existing iterator.
726 * \code iterator != NULL \endcode
728 FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
730 /** Initialize the iterator to point to the first metadata block in the
733 * \param iterator A pointer to an existing iterator.
734 * \param chain A pointer to an existing and initialized (read) chain.
736 * \code iterator != NULL \endcode
737 * \code chain != NULL \endcode
739 FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
741 /** Moves the iterator forward one metadata block, returning \c false if
742 * already at the end.
744 * \param iterator A pointer to an existing initialized iterator.
746 * \code iterator != NULL \endcode
747 * \a iterator has been successfully initialized with
748 * FLAC__metadata_iterator_init()
750 * \c false if already at the last metadata block of the chain, else
753 FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
755 /** Moves the iterator backward one metadata block, returning \c false if
756 * already at the beginning.
758 * \param iterator A pointer to an existing initialized iterator.
760 * \code iterator != NULL \endcode
761 * \a iterator has been successfully initialized with
762 * FLAC__metadata_iterator_init()
764 * \c false if already at the first metadata block of the chain, else
767 FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
769 /** Get the type of the metadata block at the current position.
771 * \param iterator A pointer to an existing initialized iterator.
773 * \code iterator != NULL \endcode
774 * \a iterator has been successfully initialized with
775 * FLAC__metadata_iterator_init()
776 * \retval FLAC__MetadataType
777 * The type of the metadata block at the current iterator position.
779 FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
781 /** Get the metadata block at the current position. You can modify
782 * the block in place but must write the chain before the changes
783 * are reflected to the FLAC file. You do not need to call
784 * FLAC__metadata_iterator_set_block() to reflect the changes;
785 * the pointer returned by FLAC__metadata_iterator_get_block()
786 * points directly into the chain.
789 * Do not call FLAC__metadata_object_delete() on the returned object;
790 * to delete a block use FLAC__metadata_iterator_delete_block().
792 * \param iterator A pointer to an existing initialized iterator.
794 * \code iterator != NULL \endcode
795 * \a iterator has been successfully initialized with
796 * FLAC__metadata_iterator_init()
797 * \retval FLAC__StreamMetadata*
798 * The current metadata block.
800 FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
802 /** Set the metadata block at the current position, replacing the existing
803 * block. The new block passed in becomes owned by the chain and it will be
804 * deleted when the chain is deleted.
806 * \param iterator A pointer to an existing initialized iterator.
807 * \param block A pointer to a metadata block.
809 * \code iterator != NULL \endcode
810 * \a iterator has been successfully initialized with
811 * FLAC__metadata_iterator_init()
812 * \code block != NULL \endcode
814 * \c false if the conditions in the above description are not met, or
815 * a memory allocation error occurs, otherwise \c true.
817 FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
819 /** Removes the current block from the chain. If \a replace_with_padding is
820 * \c true, the block will instead be replaced with a padding block of equal
821 * size. You can not delete the STREAMINFO block. The iterator will be
822 * left pointing to the block before the one just "deleted", even if
823 * \a replace_with_padding is \c true.
825 * \param iterator A pointer to an existing initialized iterator.
826 * \param replace_with_padding See above.
828 * \code iterator != NULL \endcode
829 * \a iterator has been successfully initialized with
830 * FLAC__metadata_iterator_init()
832 * \c false if the conditions in the above description are not met,
835 FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
837 /** Insert a new block before the current block. You cannot insert a block
838 * before the first STREAMINFO block. You cannot insert a STREAMINFO block
839 * as there can be only one, the one that already exists at the head when you
840 * read in a chain. The chain takes ownership of the new block and it will be
841 * deleted when the chain is deleted. The iterator will be left pointing to
844 * \param iterator A pointer to an existing initialized iterator.
845 * \param block A pointer to a metadata block to insert.
847 * \code iterator != NULL \endcode
848 * \a iterator has been successfully initialized with
849 * FLAC__metadata_iterator_init()
851 * \c false if the conditions in the above description are not met, or
852 * a memory allocation error occurs, otherwise \c true.
854 FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
856 /** Insert a new block after the current block. You cannot insert a STREAMINFO
857 * block as there can be only one, the one that already exists at the head when
858 * you read in a chain. The chain takes ownership of the new block and it will
859 * be deleted when the chain is deleted. The iterator will be left pointing to
862 * \param iterator A pointer to an existing initialized iterator.
863 * \param block A pointer to a metadata block to insert.
865 * \code iterator != NULL \endcode
866 * \a iterator has been successfully initialized with
867 * FLAC__metadata_iterator_init()
869 * \c false if the conditions in the above description are not met, or
870 * a memory allocation error occurs, otherwise \c true.
872 FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
877 /** \defgroup flac_metadata_object FLAC/metadata.h: metadata object methods
878 * \ingroup flac_metadata
881 * This module contains methods for manipulating FLAC metadata objects.
883 * Since many are variable length we have to be careful about the memory
884 * management. We decree that all pointers to data in the object are
885 * owned by the object and memory-managed by the object.
887 * Use the FLAC__metadata_object_new() and FLAC__metadata_object_delete()
888 * functions to create all instances. When using the
889 * FLAC__metadata_object_set_*() functions to set pointers to data, set
890 * \a copy to \c true to have the function make it's own copy of the data, or
891 * to \c false to give the object ownership of your data. In the latter case
892 * your pointer must be freeable by free() and will be free()d when the object
893 * is FLAC__metadata_object_delete()d. It is legal to pass a null pointer as
894 * the data pointer to a FLAC__metadata_object_set_*() function as long as
895 * the length argument is 0 and the \a copy argument is \c false.
897 * The FLAC__metadata_object_new() and FLAC__metadata_object_clone() function
898 * will return \c NULL in the case of a memory allocation error, otherwise a new
899 * object. The FLAC__metadata_object_set_*() functions return \c false in the
900 * case of a memory allocation error.
902 * We don't have the convenience of C++ here, so note that the library relies
903 * on you to keep the types straight. In other words, if you pass, for
904 * example, a FLAC__StreamMetadata* that represents a STREAMINFO block to
905 * FLAC__metadata_object_application_set_data(), you will get an assertion
908 * There is no need to recalculate the length field on metadata blocks you
909 * have modified. They will be calculated automatically before they are
910 * written back to a file.
916 /** Create a new metadata object instance of the given type.
918 * The object will be "empty"; i.e. values and data pointers will be \c 0,
919 * with the exception of FLAC__METADATA_TYPE_VORBIS_COMMENT, which will have
920 * the vendor string set (but zero comments).
922 * Do not pass in a value greater than or equal to
923 * \a FLAC__METADATA_TYPE_UNDEFINED unless you really know what you're
926 * \param type Type of object to create
927 * \retval FLAC__StreamMetadata*
928 * \c NULL if there was an error allocating memory, else the new instance.
930 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
932 /** Create a copy of an existing metadata object.
934 * The copy is a "deep" copy, i.e. dynamically allocated data within the
935 * object is also copied. The caller takes ownership of the new block and
936 * is responsible for freeing it with FLAC__metadata_object_delete().
938 * \param object Pointer to object to copy.
940 * \code object != NULL \endcode
941 * \retval FLAC__StreamMetadata*
942 * \c NULL if there was an error allocating memory, else the new instance.
944 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
946 /** Free a metadata object. Deletes the object pointed to by \a object.
948 * The delete is a "deep" delete, i.e. dynamically allocated data within the
949 * object is also deleted.
951 * \param object A pointer to an existing object.
953 * \code object != NULL \endcode
955 FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
957 /** Compares two metadata objects.
959 * The compare is "deep", i.e. dynamically allocated data within the
960 * object is also compared.
962 * \param block1 A pointer to an existing object.
963 * \param block2 A pointer to an existing object.
965 * \code block1 != NULL \endcode
966 * \code block2 != NULL \endcode
968 * \c true if objects are identical, else \c false.
970 FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
972 /** Sets the application data of an APPLICATION block.
974 * If \a copy is \c true, a copy of the data is stored; otherwise, the object
975 * takes ownership of the pointer. Returns \c false if \a copy == \c true
978 * \param object A pointer to an existing APPLICATION object.
979 * \param data A pointer to the data to set.
980 * \param length The length of \a data in bytes.
981 * \param copy See above.
983 * \code object != NULL \endcode
984 * \code object->type == FLAC__METADATA_TYPE_APPLICATION \endcode
985 * \code (data != NULL && length > 0) ||
986 * (data == NULL && length == 0 && copy == false) \endcode
988 * \c false if \a copy is \c true and malloc fails, else \c true.
990 FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
992 /** Resize the seekpoint array.
994 * If the size shrinks, elements will truncated; if it grows, new placeholder
995 * points will be added to the end.
997 * \param object A pointer to an existing SEEKTABLE object.
998 * \param new_num_points The desired length of the array; may be \c 0.
1000 * \code object != NULL \endcode
1001 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1002 * \code (object->data.seek_table.points == NULL && object->data.seek_table.num_points == 0) ||
1003 * (object->data.seek_table.points != NULL && object->data.seek_table.num_points > 0) \endcode
1004 * \retval FLAC__bool
1005 * \c false if memory allocation error, else \c true.
1007 FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
1009 /** Set a seekpoint in a seektable.
1011 * \param object A pointer to an existing SEEKTABLE object.
1012 * \param point_num Index into seekpoint array to set.
1013 * \param point The point to set.
1015 * \code object != NULL \endcode
1016 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1017 * \code object->data.seek_table.num_points > point_num \endcode
1019 FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
1021 /** Insert a seekpoint into a seektable.
1023 * \param object A pointer to an existing SEEKTABLE object.
1024 * \param point_num Index into seekpoint array to set.
1025 * \param point The point to set.
1027 * \code object != NULL \endcode
1028 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1029 * \code object->data.seek_table.num_points >= point_num \endcode
1030 * \retval FLAC__bool
1031 * \c false if memory allocation error, else \c true.
1033 FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
1035 /** Delete a seekpoint from a seektable.
1037 * \param object A pointer to an existing SEEKTABLE object.
1038 * \param point_num Index into seekpoint array to set.
1040 * \code object != NULL \endcode
1041 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1042 * \code object->data.seek_table.num_points > point_num \endcode
1043 * \retval FLAC__bool
1044 * \c false if memory allocation error, else \c true.
1046 FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
1048 /** Check a seektable to see if it conforms to the FLAC specification.
1049 * See the format specification for limits on the contents of the
1052 * \param object A pointer to an existing SEEKTABLE object.
1054 * \code object != NULL \endcode
1055 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1056 * \retval FLAC__bool
1057 * \c false if seek table is illegal, else \c true.
1059 FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
1061 /** Append a number of placeholder points to the end of a seek table.
1064 * As with the other ..._seektable_template_... functions, you should
1065 * call FLAC__metadata_object_seektable_template_sort() when finished
1066 * to make the seek table legal.
1068 * \param object A pointer to an existing SEEKTABLE object.
1069 * \param num The number of placeholder points to append.
1071 * \code object != NULL \endcode
1072 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1073 * \retval FLAC__bool
1074 * \c false if memory allocation fails, else \c true.
1076 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
1078 /** Append a specific seek point template to the end of a seek table.
1081 * As with the other ..._seektable_template_... functions, you should
1082 * call FLAC__metadata_object_seektable_template_sort() when finished
1083 * to make the seek table legal.
1085 * \param object A pointer to an existing SEEKTABLE object.
1086 * \param sample_number The sample number of the seek point template.
1088 * \code object != NULL \endcode
1089 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1090 * \retval FLAC__bool
1091 * \c false if memory allocation fails, else \c true.
1093 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
1095 /** Append specific seek point templates to the end of a seek table.
1098 * As with the other ..._seektable_template_... functions, you should
1099 * call FLAC__metadata_object_seektable_template_sort() when finished
1100 * to make the seek table legal.
1102 * \param object A pointer to an existing SEEKTABLE object.
1103 * \param sample_numbers An array of sample numbers for the seek points.
1104 * \param num The number of seek point templates to append.
1106 * \code object != NULL \endcode
1107 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1108 * \retval FLAC__bool
1109 * \c false if memory allocation fails, else \c true.
1111 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
1113 /** Append a set of evenly-spaced seek point templates to the end of a
1117 * As with the other ..._seektable_template_... functions, you should
1118 * call FLAC__metadata_object_seektable_template_sort() when finished
1119 * to make the seek table legal.
1121 * \param object A pointer to an existing SEEKTABLE object.
1122 * \param num The number of placeholder points to append.
1123 * \param total_samples The total number of samples to be encoded;
1124 * the seekpoints will be spaced approximately
1125 * \a total_samples / \a num samples apart.
1127 * \code object != NULL \endcode
1128 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1129 * \retval FLAC__bool
1130 * \c false if memory allocation fails, else \c true.
1132 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
1134 /** Sort a seek table's seek points according to the format specification,
1135 * removing duplicates.
1137 * \param object A pointer to a seek table to be sorted.
1138 * \param compact If \c false, behaves like FLAC__format_seektable_sort().
1139 * If \c true, duplicates are deleted and the seek table is
1140 * shrunk appropriately; the number of placeholder points
1141 * present in the seek table will be the same after the call
1144 * \code object != NULL \endcode
1145 * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode
1146 * \retval FLAC__bool
1147 * \c false if realloc fails, else \c true.
1149 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
1151 /** Sets the vendor string in a VORBIS_COMMENT block.
1153 * If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1154 * takes ownership of the \c entry->entry pointer. Returns \c false if
1155 * \a copy == \c true and malloc fails.
1157 * \param object A pointer to an existing VORBIS_COMMENT object.
1158 * \param entry The entry to set the vendor string to.
1159 * \param copy See above.
1161 * \code object != NULL \endcode
1162 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1163 * \code (entry->entry != NULL && entry->length > 0) ||
1164 * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1165 * \retval FLAC__bool
1166 * \c false if \a copy is \c true and malloc fails, else \c true.
1168 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1170 /** Resize the comment array.
1172 * If the size shrinks, elements will truncated; if it grows, new empty
1173 * fields will be added to the end.
1175 * \param object A pointer to an existing VORBIS_COMMENT object.
1176 * \param new_num_comments The desired length of the array; may be \c 0.
1178 * \code object != NULL \endcode
1179 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1180 * \code (object->data.vorbis_comment.comments == NULL && object->data.vorbis_comment.num_comments == 0) ||
1181 * (object->data.vorbis_comment.comments != NULL && object->data.vorbis_comment.num_comments > 0) \endcode
1182 * \retval FLAC__bool
1183 * \c false if memory allocation error, else \c true.
1185 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
1187 /** Sets a comment in a VORBIS_COMMENT block.
1189 * If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1190 * takes ownership of the \c entry->entry pointer. Returns \c false if
1191 * \a copy == \c true and malloc fails.
1193 * \param object A pointer to an existing VORBIS_COMMENT object.
1194 * \param comment_num Index into comment array to set.
1195 * \param entry The entry to set the comment to.
1196 * \param copy See above.
1198 * \code object != NULL \endcode
1199 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1200 * \code comment_num < object->data.vorbis_comment.num_comments \endcode
1201 * \code (entry->entry != NULL && entry->length > 0) ||
1202 * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1203 * \retval FLAC__bool
1204 * \c false if \a copy is \c true and malloc fails, else \c true.
1206 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1208 /** Insert a comment in a VORBIS_COMMENT block at the given index.
1210 * If \a copy is \c true, a copy of the entry is stored; otherwise, the object
1211 * takes ownership of the \c entry->entry pointer. Returns \c false if
1212 * \a copy == \c true and malloc fails.
1214 * \param object A pointer to an existing VORBIS_COMMENT object.
1215 * \param comment_num The index at which to insert the comment. The comments
1216 * at and after \a comment_num move right one position.
1217 * To append a comment to the end, set \a comment_num to
1218 * \c object->data.vorbis_comment.num_comments .
1219 * \param entry The comment to insert.
1220 * \param copy See above.
1222 * \code object != NULL \endcode
1223 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1224 * \code object->data.vorbis_comment.num_comments >= comment_num \endcode
1225 * \code (entry->entry != NULL && entry->length > 0) ||
1226 * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1227 * \retval FLAC__bool
1228 * \c false if \a copy is \c true and malloc fails, else \c true.
1230 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
1232 /** Delete a comment in a VORBIS_COMMENT block at the given index.
1234 * \param object A pointer to an existing VORBIS_COMMENT object.
1235 * \param comment_num The index of the comment to delete.
1237 * \code object != NULL \endcode
1238 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1239 * \code object->data.vorbis_comment.num_comments > comment_num \endcode
1240 * \code (entry->entry != NULL && entry->length > 0) ||
1241 * (entry->entry == NULL && entry->length == 0 && copy == false) \endcode
1242 * \retval FLAC__bool
1243 * \c false if realloc fails, else \c true.
1245 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
1247 /*@@@@ add to unit tests */
1248 /** Check if the given Vorbis comment entry's field name matches the given
1251 * \param entry A pointer to an existing Vorbis comment entry.
1252 * \param field_name The field name to check.
1253 * \param field_name_length The length of \a field_name, not including the
1254 * terminating \c NULL.
1256 * \code entry != NULL \endcode
1257 * \code (entry->entry != NULL && entry->length > 0) \endcode
1258 * \retval FLAC__bool
1259 * \c true if the field names match, else \c false
1261 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, unsigned field_name_length);
1263 /*@@@@ add to unit tests */
1264 /** Find a Vorbis comment with the given field name.
1266 * The search begins at entry number \a offset; use and offset of 0 to
1267 * search from the beginning of the comment array.
1269 * \param object A pointer to an existing VORBIS_COMMENT object.
1270 * \param offset The offset into the comment array from where to start
1272 * \param field_name The field name of the comment to find.
1274 * \code object != NULL \endcode
1275 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1277 * The offset in the comment array of the first comment whose field
1278 * name matches \a field_name, or \c -1 if no match was found.
1280 FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
1282 /*@@@@ add to unit tests */
1283 /** Remove first Vorbis comment matching the given field name.
1285 * \param object A pointer to an existing VORBIS_COMMENT object.
1286 * \param field_name The field name of comment to delete.
1288 * \code object != NULL \endcode
1289 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1291 * \c -1 for memory allocation error, \c 0 for no matching entries,
1292 * \c 1 for one matching entry deleted.
1294 FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
1296 /*@@@@ add to unit tests */
1297 /** Remove all Vorbis comments matching the given field name.
1299 * \param object A pointer to an existing VORBIS_COMMENT object.
1300 * \param field_name The field name of comments to delete.
1302 * \code object != NULL \endcode
1303 * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode
1305 * \c -1 for memory allocation error, \c 0 for no matching entries,
1306 * else the number of matching entries deleted.
1308 FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
1310 /** Create a new CUESHEET track instance.
1312 * The object will be "empty"; i.e. values and data pointers will be \c 0.
1314 * \retval FLAC__StreamMetadata_CueSheet_Track*
1315 * \c NULL if there was an error allocating memory, else the new instance.
1317 FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new();
1319 /** Create a copy of an existing CUESHEET track object.
1321 * The copy is a "deep" copy, i.e. dynamically allocated data within the
1322 * object is also copied. The caller takes ownership of the new object and
1323 * is responsible for freeing it with
1324 * FLAC__metadata_object_cuesheet_track_delete().
1326 * \param object Pointer to object to copy.
1328 * \code object != NULL \endcode
1329 * \retval FLAC__StreamMetadata_CueSheet_Track*
1330 * \c NULL if there was an error allocating memory, else the new instance.
1332 FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
1334 /** Delete a CUESHEET track object
1336 * \param object A pointer to an existing CUESHEET track object.
1338 * \code object != NULL \endcode
1340 FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
1342 /** Resize a track's index point array.
1344 * If the size shrinks, elements will truncated; if it grows, new blank
1345 * indices will be added to the end.
1347 * \param object A pointer to an existing CUESHEET object.
1348 * \param track_num The index of the track to modify. NOTE: this is not
1349 * necessarily the same as the track's \a number field.
1350 * \param new_num_indices The desired length of the array; may be \c 0.
1352 * \code object != NULL \endcode
1353 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1354 * \code object->data.cue_sheet.num_tracks > track_num \endcode
1355 * \code (object->data.cue_sheet.tracks[track_num].indices == NULL && object->data.cue_sheet.tracks[track_num].num_indices == 0) ||
1356 * (object->data.cue_sheet.tracks[track_num].indices != NULL && object->data.cue_sheet.tracks[track_num].num_indices > 0) \endcode
1357 * \retval FLAC__bool
1358 * \c false if memory allocation error, else \c true.
1360 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
1362 /** Insert an index point in a CUESHEET track at the given index.
1364 * \param object A pointer to an existing CUESHEET object.
1365 * \param track_num The index of the track to modify. NOTE: this is not
1366 * necessarily the same as the track's \a number field.
1367 * \param index_num The index into the track's index array at which to
1368 * insert the index point. NOTE: this is not necessarily
1369 * the same as the index point's \a number field. The
1370 * indices at and after \a index_num move right one
1371 * position. To append an index point to the end, set
1373 * \c object->data.cue_sheet.tracks[track_num].num_indices .
1374 * \param index The index point to insert.
1376 * \code object != NULL \endcode
1377 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1378 * \code object->data.cue_sheet.num_tracks > track_num \endcode
1379 * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode
1380 * \retval FLAC__bool
1381 * \c false if realloc fails, else \c true.
1383 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index);
1385 /** Insert a blank index point in a CUESHEET track at the given index.
1387 * A blank index point is one in which all field values are zero.
1389 * \param object A pointer to an existing CUESHEET object.
1390 * \param track_num The index of the track to modify. NOTE: this is not
1391 * necessarily the same as the track's \a number field.
1392 * \param index_num The index into the track's index array at which to
1393 * insert the index point. NOTE: this is not necessarily
1394 * the same as the index point's \a number field. The
1395 * indices at and after \a index_num move right one
1396 * position. To append an index point to the end, set
1398 * \c object->data.cue_sheet.tracks[track_num].num_indices .
1400 * \code object != NULL \endcode
1401 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1402 * \code object->data.cue_sheet.num_tracks > track_num \endcode
1403 * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode
1404 * \retval FLAC__bool
1405 * \c false if realloc fails, else \c true.
1407 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
1409 /** Delete an index point in a CUESHEET track at the given index.
1411 * \param object A pointer to an existing CUESHEET object.
1412 * \param track_num The index into the track array of the track to
1413 * modify. NOTE: this is not necessarily the same
1414 * as the track's \a number field.
1415 * \param index_num The index into the track's index array of the index
1416 * to delete. NOTE: this is not necessarily the same
1417 * as the index's \a number field.
1419 * \code object != NULL \endcode
1420 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1421 * \code object->data.cue_sheet.num_tracks > track_num \endcode
1422 * \code object->data.cue_sheet.tracks[track_num].num_indices > index_num \endcode
1423 * \retval FLAC__bool
1424 * \c false if realloc fails, else \c true.
1426 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
1428 /** Resize the track array.
1430 * If the size shrinks, elements will truncated; if it grows, new blank
1431 * tracks will be added to the end.
1433 * \param object A pointer to an existing CUESHEET object.
1434 * \param new_num_tracks The desired length of the array; may be \c 0.
1436 * \code object != NULL \endcode
1437 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1438 * \code (object->data.cue_sheet.tracks == NULL && object->data.cue_sheet.num_tracks == 0) ||
1439 * (object->data.cue_sheet.tracks != NULL && object->data.cue_sheet.num_tracks > 0) \endcode
1440 * \retval FLAC__bool
1441 * \c false if memory allocation error, else \c true.
1443 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
1445 /** Sets a track in a CUESHEET block.
1447 * If \a copy is \c true, a copy of the track is stored; otherwise, the object
1448 * takes ownership of the \a track pointer. Returns \c false if
1449 * \a copy == \c true and malloc fails.
1451 * \param object A pointer to an existing CUESHEET object.
1452 * \param track_num Index into track array to set. NOTE: this is not
1453 * necessarily the same as the track's \a number field.
1454 * \param track The track to set the track to. You may safely pass in
1455 * a const pointer if \a copy is \c true.
1456 * \param copy See above.
1458 * \code object != NULL \endcode
1459 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1460 * \code track_num < object->data.cue_sheet.num_tracks \endcode
1461 * \code (track->indices != NULL && track->num_indices > 0) ||
1462 * (track->indices == NULL && track->num_indices == 0)
1463 * \retval FLAC__bool
1464 * \c false if \a copy is \c true and malloc fails, else \c true.
1466 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
1468 /** Insert a track in a CUESHEET block at the given index.
1470 * If \a copy is \c true, a copy of the track is stored; otherwise, the object
1471 * takes ownership of the \a track pointer. Returns \c false if
1472 * \a copy == \c true and malloc fails.
1474 * \param object A pointer to an existing CUESHEET object.
1475 * \param track_num The index at which to insert the track. NOTE: this
1476 * is not necessarily the same as the track's \a number
1477 * field. The tracks at and after \a track_num move right
1478 * one position. To append a track to the end, set
1479 * \a track_num to \c object->data.cue_sheet.num_tracks .
1480 * \param track The track to insert. You may safely pass in a const
1481 * pointer if \a copy is \c true.
1482 * \param copy See above.
1484 * \code object != NULL \endcode
1485 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1486 * \code object->data.cue_sheet.num_tracks >= track_num \endcode
1487 * \retval FLAC__bool
1488 * \c false if \a copy is \c true and malloc fails, else \c true.
1490 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
1492 /** Insert a blank track in a CUESHEET block at the given index.
1494 * A blank track is one in which all field values are zero.
1496 * \param object A pointer to an existing CUESHEET object.
1497 * \param track_num The index at which to insert the track. NOTE: this
1498 * is not necessarily the same as the track's \a number
1499 * field. The tracks at and after \a track_num move right
1500 * one position. To append a track to the end, set
1501 * \a track_num to \c object->data.cue_sheet.num_tracks .
1503 * \code object != NULL \endcode
1504 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1505 * \code object->data.cue_sheet.num_tracks >= track_num \endcode
1506 * \retval FLAC__bool
1507 * \c false if \a copy is \c true and malloc fails, else \c true.
1509 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
1511 /** Delete a track in a CUESHEET block at the given index.
1513 * \param object A pointer to an existing CUESHEET object.
1514 * \param track_num The index into the track array of the track to
1515 * delete. NOTE: this is not necessarily the same
1516 * as the track's \a number field.
1518 * \code object != NULL \endcode
1519 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1520 * \code object->data.cue_sheet.num_tracks > track_num \endcode
1521 * \retval FLAC__bool
1522 * \c false if realloc fails, else \c true.
1524 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
1526 /** Check a cue sheet to see if it conforms to the FLAC specification.
1527 * See the format specification for limits on the contents of the
1530 * \param object A pointer to an existing CUESHEET object.
1531 * \param check_cd_da_subset If \c true, check CUESHEET against more
1532 * stringent requirements for a CD-DA (audio) disc.
1533 * \param violation Address of a pointer to a string. If there is a
1534 * violation, a pointer to a string explanation of the
1535 * violation will be returned here. \a violation may be
1536 * \c NULL if you don't need the returned string. Do not
1537 * free the returned string; it will always point to static
1540 * \code object != NULL \endcode
1541 * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode
1542 * \retval FLAC__bool
1543 * \c false if cue sheet is illegal, else \c true.
1545 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);