From df7240ac843c20193999e3e8a7654173e407144a Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Sat, 16 Nov 2002 06:32:30 +0000 Subject: [PATCH] add more CUESHEET convenience functions --- include/FLAC/metadata.h | 22 +++++++++---- src/libFLAC/include/private/metadata.h | 1 + src/libFLAC/metadata_object.c | 44 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/include/FLAC/metadata.h b/include/FLAC/metadata.h index 3f414c8e..1f15a7f8 100644 --- a/include/FLAC/metadata.h +++ b/include/FLAC/metadata.h @@ -1294,28 +1294,38 @@ FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__Str */ FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name); -/*@@@@ document, add to unit tests */ +/*@@@@ document */ +FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(); + +/*@@@@ document */ +FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object); + +/*@@@@ document */ +FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object); + +/*@@@@ document */ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices); -/*@@@@ document, add to unit tests */ +/*@@@@ document */ 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); -/*@@@@ document, add to unit tests */ +/*@@@@ document */ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num); /*@@@@ document */ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks); /*@@@@ document */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track track, FLAC__bool copy); +/*@@@@ you may safely un-const the \a track pointer if \a copy is \c true */ +FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy); /*@@@@ document */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track track, FLAC__bool copy); +/*@@@@ you may safely un-const the \a track pointer if \a copy is \c true */ +FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy); /*@@@@ document */ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num); -/*@@@@ add to unit tests */ /** Check a cue sheet to see if it conforms to the FLAC specification. * See the format specification for limits on the contents of the * cue sheet. diff --git a/src/libFLAC/include/private/metadata.h b/src/libFLAC/include/private/metadata.h index de845d38..193fbbb6 100644 --- a/src/libFLAC/include/private/metadata.h +++ b/src/libFLAC/include/private/metadata.h @@ -23,5 +23,6 @@ #include "FLAC/metadata.h" void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object); +void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object); #endif diff --git a/src/libFLAC/metadata_object.c b/src/libFLAC/metadata_object.c index 9adb6f53..371b33b4 100644 --- a/src/libFLAC/metadata_object.c +++ b/src/libFLAC/metadata_object.c @@ -207,6 +207,7 @@ static void cuesheet_calculate_length_(FLAC__StreamMetadata *object) object->length = ( FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN ) / 8; @@ -1025,6 +1026,43 @@ FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__S return ok? (int)matching : -1; } +FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new() +{ + return (FLAC__StreamMetadata_CueSheet_Track*)calloc(1, sizeof(FLAC__StreamMetadata_CueSheet_Track)); +} + +FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object) +{ + FLAC__StreamMetadata_CueSheet_Track *to; + + FLAC__ASSERT(0 != object); + + if(0 != (to = FLAC__metadata_object_cuesheet_track_new())) { + if(!copy_track_(to, object)) { + FLAC__metadata_object_cuesheet_track_delete(to); + return 0; + } + } + + return to; +} + +void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object) +{ + FLAC__ASSERT(0 != object); + + if(0 != object->indices) { + FLAC__ASSERT(object->num_indices > 0); + free(object->indices); + } +} + +FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object) +{ + FLAC__metadata_object_cuesheet_track_delete_data(object); + free(object); +} + FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices) { FLAC__StreamMetadata_CueSheet_Track *track; @@ -1150,12 +1188,12 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMet return true; } -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track track, FLAC__bool copy) +FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) { - return cuesheet_set_track_(object, &object->data.cue_sheet.tracks[track_num], &track, copy); + return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy); } -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track track, FLAC__bool copy) +FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) { FLAC__StreamMetadata_CueSheet *cs;