1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "FLAC++/metadata.h"
21 #include "FLAC/assert.h"
22 #include <stdlib.h> // for malloc(), free()
23 #include <string.h> // for memcpy() etc.
28 // local utility routines
32 Prototype *construct_block(::FLAC__StreamMetadata *object)
35 switch(object->type) {
36 case FLAC__METADATA_TYPE_STREAMINFO:
37 ret = new StreamInfo(object, /*copy=*/false);
39 case FLAC__METADATA_TYPE_PADDING:
40 ret = new Padding(object, /*copy=*/false);
42 case FLAC__METADATA_TYPE_APPLICATION:
43 ret = new Application(object, /*copy=*/false);
45 case FLAC__METADATA_TYPE_SEEKTABLE:
46 ret = new SeekTable(object, /*copy=*/false);
48 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
49 ret = new VorbisComment(object, /*copy=*/false);
51 case FLAC__METADATA_TYPE_CUESHEET:
52 ret = new CueSheet(object, /*copy=*/false);
63 FLACPP_API Prototype *clone(const Prototype *object)
65 FLAC__ASSERT(0 != object);
67 const StreamInfo *streaminfo = dynamic_cast<const StreamInfo *>(object);
68 const Padding *padding = dynamic_cast<const Padding *>(object);
69 const Application *application = dynamic_cast<const Application *>(object);
70 const SeekTable *seektable = dynamic_cast<const SeekTable *>(object);
71 const VorbisComment *vorbiscomment = dynamic_cast<const VorbisComment *>(object);
72 const CueSheet *cuesheet = dynamic_cast<const CueSheet *>(object);
75 return new StreamInfo(*streaminfo);
77 return new Padding(*padding);
78 else if(0 != application)
79 return new Application(*application);
80 else if(0 != seektable)
81 return new SeekTable(*seektable);
82 else if(0 != vorbiscomment)
83 return new VorbisComment(*vorbiscomment);
84 else if(0 != cuesheet)
85 return new CueSheet(*cuesheet);
96 Prototype::Prototype(const Prototype &object):
97 object_(::FLAC__metadata_object_clone(object.object_)),
100 FLAC__ASSERT(object.is_valid());
103 Prototype::Prototype(const ::FLAC__StreamMetadata &object):
104 object_(::FLAC__metadata_object_clone(&object)),
109 Prototype::Prototype(const ::FLAC__StreamMetadata *object):
110 object_(::FLAC__metadata_object_clone(object)),
113 FLAC__ASSERT(0 != object);
116 Prototype::Prototype(::FLAC__StreamMetadata *object, bool copy):
117 object_(copy? ::FLAC__metadata_object_clone(object) : object),
120 FLAC__ASSERT(0 != object);
123 Prototype::~Prototype()
128 void Prototype::clear()
130 if(0 != object_ && !is_reference_)
131 FLAC__metadata_object_delete(object_);
135 void Prototype::operator=(const Prototype &object)
137 FLAC__ASSERT(object.is_valid());
139 is_reference_ = false;
140 object_ = ::FLAC__metadata_object_clone(object.object_);
143 void Prototype::operator=(const ::FLAC__StreamMetadata &object)
146 is_reference_ = false;
147 object_ = ::FLAC__metadata_object_clone(&object);
150 void Prototype::operator=(const ::FLAC__StreamMetadata *object)
152 FLAC__ASSERT(0 != object);
154 is_reference_ = false;
155 object_ = ::FLAC__metadata_object_clone(object);
158 bool Prototype::get_is_last() const
160 FLAC__ASSERT(is_valid());
161 return (bool)object_->is_last;
164 FLAC__MetadataType Prototype::get_type() const
166 FLAC__ASSERT(is_valid());
167 return object_->type;
170 unsigned Prototype::get_length() const
172 FLAC__ASSERT(is_valid());
173 return object_->length;
176 void Prototype::set_is_last(bool value)
178 FLAC__ASSERT(is_valid());
179 object_->is_last = value;
187 StreamInfo::StreamInfo():
188 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO), /*copy=*/false)
191 StreamInfo::~StreamInfo()
194 unsigned StreamInfo::get_min_blocksize() const
196 FLAC__ASSERT(is_valid());
197 return object_->data.stream_info.min_blocksize;
200 unsigned StreamInfo::get_max_blocksize() const
202 FLAC__ASSERT(is_valid());
203 return object_->data.stream_info.max_blocksize;
206 unsigned StreamInfo::get_min_framesize() const
208 FLAC__ASSERT(is_valid());
209 return object_->data.stream_info.min_framesize;
212 unsigned StreamInfo::get_max_framesize() const
214 FLAC__ASSERT(is_valid());
215 return object_->data.stream_info.max_framesize;
218 unsigned StreamInfo::get_sample_rate() const
220 FLAC__ASSERT(is_valid());
221 return object_->data.stream_info.sample_rate;
224 unsigned StreamInfo::get_channels() const
226 FLAC__ASSERT(is_valid());
227 return object_->data.stream_info.channels;
230 unsigned StreamInfo::get_bits_per_sample() const
232 FLAC__ASSERT(is_valid());
233 return object_->data.stream_info.bits_per_sample;
236 FLAC__uint64 StreamInfo::get_total_samples() const
238 FLAC__ASSERT(is_valid());
239 return object_->data.stream_info.total_samples;
242 const FLAC__byte *StreamInfo::get_md5sum() const
244 FLAC__ASSERT(is_valid());
245 return object_->data.stream_info.md5sum;
248 void StreamInfo::set_min_blocksize(unsigned value)
250 FLAC__ASSERT(is_valid());
251 FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE);
252 FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE);
253 object_->data.stream_info.min_blocksize = value;
256 void StreamInfo::set_max_blocksize(unsigned value)
258 FLAC__ASSERT(is_valid());
259 FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE);
260 FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE);
261 object_->data.stream_info.max_blocksize = value;
264 void StreamInfo::set_min_framesize(unsigned value)
266 FLAC__ASSERT(is_valid());
267 FLAC__ASSERT(value < (1u < FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
268 object_->data.stream_info.min_framesize = value;
271 void StreamInfo::set_max_framesize(unsigned value)
273 FLAC__ASSERT(is_valid());
274 FLAC__ASSERT(value < (1u < FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
275 object_->data.stream_info.max_framesize = value;
278 void StreamInfo::set_sample_rate(unsigned value)
280 FLAC__ASSERT(is_valid());
281 FLAC__ASSERT(FLAC__format_sample_rate_is_valid(value));
282 object_->data.stream_info.sample_rate = value;
285 void StreamInfo::set_channels(unsigned value)
287 FLAC__ASSERT(is_valid());
288 FLAC__ASSERT(value > 0);
289 FLAC__ASSERT(value <= FLAC__MAX_CHANNELS);
290 object_->data.stream_info.channels = value;
293 void StreamInfo::set_bits_per_sample(unsigned value)
295 FLAC__ASSERT(is_valid());
296 FLAC__ASSERT(value >= FLAC__MIN_BITS_PER_SAMPLE);
297 FLAC__ASSERT(value <= FLAC__MAX_BITS_PER_SAMPLE);
298 object_->data.stream_info.bits_per_sample = value;
301 void StreamInfo::set_total_samples(FLAC__uint64 value)
303 FLAC__ASSERT(is_valid());
304 FLAC__ASSERT(value < (1u << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN));
305 object_->data.stream_info.total_samples = value;
308 void StreamInfo::set_md5sum(const FLAC__byte value[16])
310 FLAC__ASSERT(is_valid());
311 FLAC__ASSERT(0 != value);
312 memcpy(object_->data.stream_info.md5sum, value, 16);
321 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING), /*copy=*/false)
327 void Padding::set_length(unsigned length)
329 FLAC__ASSERT(is_valid());
330 object_->length = length;
338 Application::Application():
339 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION), /*copy=*/false)
342 Application::~Application()
345 const FLAC__byte *Application::get_id() const
347 FLAC__ASSERT(is_valid());
348 return object_->data.application.id;
351 const FLAC__byte *Application::get_data() const
353 FLAC__ASSERT(is_valid());
354 return object_->data.application.data;
357 void Application::set_id(const FLAC__byte value[4])
359 FLAC__ASSERT(is_valid());
360 FLAC__ASSERT(0 != value);
361 memcpy(object_->data.application.id, value, 4);
364 bool Application::set_data(const FLAC__byte *data, unsigned length)
366 FLAC__ASSERT(is_valid());
367 return (bool)::FLAC__metadata_object_application_set_data(object_, (FLAC__byte*)data, length, true);
370 bool Application::set_data(FLAC__byte *data, unsigned length, bool copy)
372 FLAC__ASSERT(is_valid());
373 return (bool)::FLAC__metadata_object_application_set_data(object_, data, length, copy);
381 SeekTable::SeekTable():
382 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE), /*copy=*/false)
385 SeekTable::~SeekTable()
388 unsigned SeekTable::get_num_points() const
390 FLAC__ASSERT(is_valid());
391 return object_->data.seek_table.num_points;
394 ::FLAC__StreamMetadata_SeekPoint SeekTable::get_point(unsigned index) const
396 FLAC__ASSERT(is_valid());
397 FLAC__ASSERT(index < object_->data.seek_table.num_points);
398 return object_->data.seek_table.points[index];
401 void SeekTable::set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point)
403 FLAC__ASSERT(is_valid());
404 FLAC__ASSERT(index < object_->data.seek_table.num_points);
405 ::FLAC__metadata_object_seektable_set_point(object_, index, point);
408 bool SeekTable::insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point)
410 FLAC__ASSERT(is_valid());
411 FLAC__ASSERT(index <= object_->data.seek_table.num_points);
412 return (bool)::FLAC__metadata_object_seektable_insert_point(object_, index, point);
415 bool SeekTable::delete_point(unsigned index)
417 FLAC__ASSERT(is_valid());
418 FLAC__ASSERT(index < object_->data.seek_table.num_points);
419 return (bool)::FLAC__metadata_object_seektable_delete_point(object_, index);
422 bool SeekTable::is_legal() const
424 FLAC__ASSERT(is_valid());
425 return (bool)::FLAC__metadata_object_seektable_is_legal(object_);
430 // VorbisComment::Entry
433 VorbisComment::Entry::Entry()
438 VorbisComment::Entry::Entry(const char *field, unsigned field_length)
441 construct(field, field_length);
444 VorbisComment::Entry::Entry(const char *field_name, const char *field_value, unsigned field_value_length)
447 construct(field_name, field_value, field_value_length);
450 VorbisComment::Entry::Entry(const Entry &entry)
452 FLAC__ASSERT(entry.is_valid());
454 construct((const char *)entry.entry_.entry, entry.entry_.length);
457 void VorbisComment::Entry::operator=(const Entry &entry)
459 FLAC__ASSERT(entry.is_valid());
461 construct((const char *)entry.entry_.entry, entry.entry_.length);
464 VorbisComment::Entry::~Entry()
469 bool VorbisComment::Entry::is_valid() const
474 unsigned VorbisComment::Entry::get_field_length() const
476 FLAC__ASSERT(is_valid());
477 return entry_.length;
480 unsigned VorbisComment::Entry::get_field_name_length() const
482 FLAC__ASSERT(is_valid());
483 return field_name_length_;
486 unsigned VorbisComment::Entry::get_field_value_length() const
488 FLAC__ASSERT(is_valid());
489 return field_value_length_;
492 ::FLAC__StreamMetadata_VorbisComment_Entry VorbisComment::Entry::get_entry() const
494 FLAC__ASSERT(is_valid());
498 const char *VorbisComment::Entry::get_field() const
500 FLAC__ASSERT(is_valid());
501 return (const char *)entry_.entry;
504 const char *VorbisComment::Entry::get_field_name() const
506 FLAC__ASSERT(is_valid());
510 const char *VorbisComment::Entry::get_field_value() const
512 FLAC__ASSERT(is_valid());
516 bool VorbisComment::Entry::set_field(const char *field, unsigned field_length)
518 FLAC__ASSERT(is_valid());
519 FLAC__ASSERT(0 != field);
523 if(0 == (entry_.entry = (FLAC__byte*)malloc(field_length))) {
527 entry_.length = field_length;
528 memcpy(entry_.entry, field, field_length);
529 (void) parse_field();
535 bool VorbisComment::Entry::set_field_name(const char *field_name)
537 FLAC__ASSERT(is_valid());
538 FLAC__ASSERT(0 != field_name);
542 if(0 == (field_name_ = strdup(field_name))) {
546 field_name_length_ = strlen(field_name_);
553 bool VorbisComment::Entry::set_field_value(const char *field_value, unsigned field_value_length)
555 FLAC__ASSERT(is_valid());
556 FLAC__ASSERT(0 != field_value);
560 if(0 == (field_value_ = (char *)malloc(field_value_length))) {
564 field_value_length_ = field_value_length;
565 memcpy(field_value_, field_value, field_value_length);
572 void VorbisComment::Entry::zero()
578 field_name_length_ = 0;
580 field_value_length_ = 0;
583 void VorbisComment::Entry::clear()
591 void VorbisComment::Entry::clear_entry()
593 if(0 != entry_.entry) {
600 void VorbisComment::Entry::clear_field_name()
602 if(0 != field_name_) {
605 field_name_length_ = 0;
609 void VorbisComment::Entry::clear_field_value()
611 if(0 != field_value_) {
614 field_value_length_ = 0;
618 void VorbisComment::Entry::construct(const char *field, unsigned field_length)
620 if(set_field(field, field_length))
624 void VorbisComment::Entry::construct(const char *field_name, const char *field_value, unsigned field_value_length)
626 if(set_field_name(field_name) && set_field_value(field_value, field_value_length))
630 void VorbisComment::Entry::compose_field()
634 if(0 == (entry_.entry = (FLAC__byte*)malloc(field_name_length_ + 1 + field_value_length_))) {
638 memcpy(entry_.entry, field_name_, field_name_length_);
639 entry_.length += field_name_length_;
640 memcpy(entry_.entry + entry_.length, "=", 1);
642 memcpy(entry_.entry + entry_.length, field_value_, field_value_length_);
643 entry_.length += field_value_length_;
648 void VorbisComment::Entry::parse_field()
653 const char *p = (const char *)memchr(entry_.entry, '=', entry_.length);
656 p = (const char *)entry_.entry + entry_.length;
658 field_name_length_ = p - (const char *)entry_.entry;
659 if(0 == (field_name_ = (char *)malloc(field_name_length_ + 1))) { // +1 for the trailing \0
663 memcpy(field_name_, entry_.entry, field_name_length_);
664 field_name_[field_name_length_] = '\0';
666 if(entry_.length - field_name_length_ == 0) {
667 field_value_length_ = 0;
668 if(0 == (field_value_ = (char *)malloc(0))) {
674 field_value_length_ = entry_.length - field_name_length_ - 1;
675 if(0 == (field_value_ = (char *)malloc(field_value_length_))) {
679 memcpy(field_value_, ++p, field_value_length_);
690 VorbisComment::VorbisComment():
691 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT), /*copy=*/false)
694 VorbisComment::~VorbisComment()
697 unsigned VorbisComment::get_num_comments() const
699 FLAC__ASSERT(is_valid());
700 return object_->data.vorbis_comment.num_comments;
703 VorbisComment::Entry VorbisComment::get_vendor_string() const
705 FLAC__ASSERT(is_valid());
706 return Entry((const char *)object_->data.vorbis_comment.vendor_string.entry, object_->data.vorbis_comment.vendor_string.length);
709 VorbisComment::Entry VorbisComment::get_comment(unsigned index) const
711 FLAC__ASSERT(is_valid());
712 FLAC__ASSERT(index < object_->data.vorbis_comment.num_comments);
713 return Entry((const char *)object_->data.vorbis_comment.comments[index].entry, object_->data.vorbis_comment.comments[index].length);
716 bool VorbisComment::set_vendor_string(const VorbisComment::Entry &entry)
718 FLAC__ASSERT(is_valid());
719 // vendor_string is a special kind of entry
720 ::FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
721 vendor_string.length = entry.get_field_name_length();
722 vendor_string.entry = (FLAC__byte*)entry.get_field_name(); // we can cheat on const-ness because we make a copy below:
723 return (bool)::FLAC__metadata_object_vorbiscomment_set_vendor_string(object_, vendor_string, /*copy=*/true);
726 bool VorbisComment::set_comment(unsigned index, const VorbisComment::Entry &entry)
728 FLAC__ASSERT(is_valid());
729 FLAC__ASSERT(index < object_->data.vorbis_comment.num_comments);
730 return (bool)::FLAC__metadata_object_vorbiscomment_set_comment(object_, index, entry.get_entry(), /*copy=*/true);
733 bool VorbisComment::insert_comment(unsigned index, const VorbisComment::Entry &entry)
735 FLAC__ASSERT(is_valid());
736 FLAC__ASSERT(index <= object_->data.vorbis_comment.num_comments);
737 return (bool)::FLAC__metadata_object_vorbiscomment_insert_comment(object_, index, entry.get_entry(), /*copy=*/true);
740 bool VorbisComment::delete_comment(unsigned index)
742 FLAC__ASSERT(is_valid());
743 FLAC__ASSERT(index < object_->data.vorbis_comment.num_comments);
744 return (bool)::FLAC__metadata_object_vorbiscomment_delete_comment(object_, index);
752 CueSheet::Track::Track():
753 object_(::FLAC__metadata_object_cuesheet_track_new())
756 CueSheet::Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track *track):
757 object_(::FLAC__metadata_object_cuesheet_track_clone(track))
760 CueSheet::Track::Track(const Track &track):
761 object_(::FLAC__metadata_object_cuesheet_track_clone(track.object_))
764 void CueSheet::Track::operator=(const Track &track)
766 object_ = ::FLAC__metadata_object_cuesheet_track_clone(track.object_);
769 CueSheet::Track::~Track()
775 bool CueSheet::Track::is_valid() const
777 return(0 != object_);
780 ::FLAC__StreamMetadata_CueSheet_Index CueSheet::Track::get_index(unsigned i) const
782 FLAC__ASSERT(is_valid());
783 FLAC__ASSERT(i < object_->num_indices);
784 return object_->indices[i];
787 void CueSheet::Track::set_isrc(const char value[12])
789 FLAC__ASSERT(is_valid());
790 FLAC__ASSERT(0 != value);
791 memcpy(object_->isrc, value, 12);
792 object_->isrc[12] = '\0';
795 void CueSheet::Track::set_type(unsigned value)
797 FLAC__ASSERT(is_valid());
798 FLAC__ASSERT(value <= 1);
799 object_->type = value;
802 void CueSheet::Track::set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index)
804 FLAC__ASSERT(is_valid());
805 FLAC__ASSERT(i < object_->num_indices);
806 object_->indices[i] = index;
814 CueSheet::CueSheet():
815 Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET), /*copy=*/false)
818 CueSheet::~CueSheet()
821 const char *CueSheet::get_media_catalog_number() const
823 FLAC__ASSERT(is_valid());
824 return object_->data.cue_sheet.media_catalog_number;
827 FLAC__uint64 CueSheet::get_lead_in() const
829 FLAC__ASSERT(is_valid());
830 return object_->data.cue_sheet.lead_in;
833 unsigned CueSheet::get_num_tracks() const
835 FLAC__ASSERT(is_valid());
836 return object_->data.cue_sheet.num_tracks;
839 CueSheet::Track CueSheet::get_track(unsigned i) const
841 FLAC__ASSERT(is_valid());
842 FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
843 return Track(object_->data.cue_sheet.tracks + i);
846 void CueSheet::set_media_catalog_number(const char value[128])
848 FLAC__ASSERT(is_valid());
849 FLAC__ASSERT(0 != value);
850 memcpy(object_->data.cue_sheet.media_catalog_number, value, 128);
851 object_->data.cue_sheet.media_catalog_number[128] = '\0';
854 void CueSheet::set_lead_in(FLAC__uint64 value)
856 FLAC__ASSERT(is_valid());
857 object_->data.cue_sheet.lead_in = value;
860 void CueSheet::set_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index)
862 FLAC__ASSERT(is_valid());
863 FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks);
864 FLAC__ASSERT(index_num < object_->data.cue_sheet.tracks[track_num].num_indices);
865 object_->data.cue_sheet.tracks[track_num].indices[index_num] = index;
868 bool CueSheet::insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index)
870 FLAC__ASSERT(is_valid());
871 FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks);
872 FLAC__ASSERT(index_num <= object_->data.cue_sheet.tracks[track_num].num_indices);
873 return (bool)::FLAC__metadata_object_cuesheet_track_insert_index(object_, track_num, index_num, index);
876 bool CueSheet::delete_index(unsigned track_num, unsigned index_num)
878 FLAC__ASSERT(is_valid());
879 FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks);
880 FLAC__ASSERT(index_num < object_->data.cue_sheet.tracks[track_num].num_indices);
881 return (bool)::FLAC__metadata_object_cuesheet_track_delete_index(object_, track_num, index_num);
884 bool CueSheet::set_track(unsigned i, const CueSheet::Track &track)
886 FLAC__ASSERT(is_valid());
887 FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
888 // We can safely const_cast since copy=true
889 return (bool)::FLAC__metadata_object_cuesheet_set_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true);
892 bool CueSheet::insert_track(unsigned i, const CueSheet::Track &track)
894 FLAC__ASSERT(is_valid());
895 FLAC__ASSERT(i <= object_->data.cue_sheet.num_tracks);
896 // We can safely const_cast since copy=true
897 return (bool)::FLAC__metadata_object_cuesheet_insert_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true);
900 bool CueSheet::delete_track(unsigned i)
902 FLAC__ASSERT(is_valid());
903 FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks);
904 return (bool)::FLAC__metadata_object_cuesheet_delete_track(object_, i);
907 bool CueSheet::is_legal(bool check_cd_da_subset, const char **violation) const
909 FLAC__ASSERT(is_valid());
910 return (bool)::FLAC__metadata_object_cuesheet_is_legal(object_, check_cd_da_subset, violation);
914 // ============================================================
918 // ============================================================
920 FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo)
922 FLAC__ASSERT(0 != filename);
924 ::FLAC__StreamMetadata s;
926 if(::FLAC__metadata_get_streaminfo(filename, &s)) {
935 // ============================================================
939 // ============================================================
941 SimpleIterator::SimpleIterator():
942 iterator_(::FLAC__metadata_simple_iterator_new())
945 SimpleIterator::~SimpleIterator()
950 void SimpleIterator::clear()
953 FLAC__metadata_simple_iterator_delete(iterator_);
957 bool SimpleIterator::init(const char *filename, bool read_only, bool preserve_file_stats)
959 FLAC__ASSERT(0 != filename);
960 FLAC__ASSERT(is_valid());
961 return (bool)::FLAC__metadata_simple_iterator_init(iterator_, filename, read_only, preserve_file_stats);
964 bool SimpleIterator::is_valid() const
966 return 0 != iterator_;
969 SimpleIterator::Status SimpleIterator::status()
971 FLAC__ASSERT(is_valid());
972 return Status(::FLAC__metadata_simple_iterator_status(iterator_));
975 bool SimpleIterator::is_writable() const
977 FLAC__ASSERT(is_valid());
978 return (bool)::FLAC__metadata_simple_iterator_is_writable(iterator_);
981 bool SimpleIterator::next()
983 FLAC__ASSERT(is_valid());
984 return (bool)::FLAC__metadata_simple_iterator_next(iterator_);
987 bool SimpleIterator::prev()
989 FLAC__ASSERT(is_valid());
990 return (bool)::FLAC__metadata_simple_iterator_prev(iterator_);
993 ::FLAC__MetadataType SimpleIterator::get_block_type() const
995 FLAC__ASSERT(is_valid());
996 return ::FLAC__metadata_simple_iterator_get_block_type(iterator_);
999 Prototype *SimpleIterator::get_block()
1001 FLAC__ASSERT(is_valid());
1002 return local::construct_block(::FLAC__metadata_simple_iterator_get_block(iterator_));
1005 bool SimpleIterator::set_block(Prototype *block, bool use_padding)
1007 FLAC__ASSERT(0 != block);
1008 FLAC__ASSERT(is_valid());
1009 return (bool)::FLAC__metadata_simple_iterator_set_block(iterator_, block->object_, use_padding);
1012 bool SimpleIterator::insert_block_after(Prototype *block, bool use_padding)
1014 FLAC__ASSERT(0 != block);
1015 FLAC__ASSERT(is_valid());
1016 return (bool)::FLAC__metadata_simple_iterator_insert_block_after(iterator_, block->object_, use_padding);
1019 bool SimpleIterator::delete_block(bool use_padding)
1021 FLAC__ASSERT(is_valid());
1022 return (bool)::FLAC__metadata_simple_iterator_delete_block(iterator_, use_padding);
1026 // ============================================================
1030 // ============================================================
1033 chain_(::FLAC__metadata_chain_new())
1044 FLAC__metadata_chain_delete(chain_);
1048 bool Chain::is_valid() const
1053 Chain::Status Chain::status()
1055 FLAC__ASSERT(is_valid());
1056 return Status(::FLAC__metadata_chain_status(chain_));
1059 bool Chain::read(const char *filename)
1061 FLAC__ASSERT(0 != filename);
1062 FLAC__ASSERT(is_valid());
1063 return (bool)::FLAC__metadata_chain_read(chain_, filename);
1066 bool Chain::write(bool use_padding, bool preserve_file_stats)
1068 FLAC__ASSERT(is_valid());
1069 return (bool)::FLAC__metadata_chain_write(chain_, use_padding, preserve_file_stats);
1072 void Chain::merge_padding()
1074 FLAC__ASSERT(is_valid());
1075 ::FLAC__metadata_chain_merge_padding(chain_);
1078 void Chain::sort_padding()
1080 FLAC__ASSERT(is_valid());
1081 ::FLAC__metadata_chain_sort_padding(chain_);
1085 Iterator::Iterator():
1086 iterator_(::FLAC__metadata_iterator_new())
1089 Iterator::~Iterator()
1094 void Iterator::clear()
1097 FLAC__metadata_iterator_delete(iterator_);
1101 bool Iterator::is_valid() const
1103 return 0 != iterator_;
1106 void Iterator::init(Chain &chain)
1108 FLAC__ASSERT(is_valid());
1109 FLAC__ASSERT(chain.is_valid());
1110 ::FLAC__metadata_iterator_init(iterator_, chain.chain_);
1113 bool Iterator::next()
1115 FLAC__ASSERT(is_valid());
1116 return (bool)::FLAC__metadata_iterator_next(iterator_);
1119 bool Iterator::prev()
1121 FLAC__ASSERT(is_valid());
1122 return (bool)::FLAC__metadata_iterator_prev(iterator_);
1125 ::FLAC__MetadataType Iterator::get_block_type() const
1127 FLAC__ASSERT(is_valid());
1128 return ::FLAC__metadata_iterator_get_block_type(iterator_);
1131 Prototype *Iterator::get_block()
1133 FLAC__ASSERT(is_valid());
1134 Prototype *block = local::construct_block(::FLAC__metadata_iterator_get_block(iterator_));
1136 block->set_reference(true);
1140 bool Iterator::set_block(Prototype *block)
1142 FLAC__ASSERT(0 != block);
1143 FLAC__ASSERT(is_valid());
1144 bool ret = (bool)::FLAC__metadata_iterator_set_block(iterator_, block->object_);
1146 block->set_reference(true);
1152 bool Iterator::delete_block(bool replace_with_padding)
1154 FLAC__ASSERT(is_valid());
1155 return (bool)::FLAC__metadata_iterator_delete_block(iterator_, replace_with_padding);
1158 bool Iterator::insert_block_before(Prototype *block)
1160 FLAC__ASSERT(0 != block);
1161 FLAC__ASSERT(is_valid());
1162 bool ret = (bool)::FLAC__metadata_iterator_insert_block_before(iterator_, block->object_);
1164 block->set_reference(true);
1170 bool Iterator::insert_block_after(Prototype *block)
1172 FLAC__ASSERT(0 != block);
1173 FLAC__ASSERT(is_valid());
1174 bool ret = (bool)::FLAC__metadata_iterator_insert_block_after(iterator_, block->object_);
1176 block->set_reference(true);