Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 1 | /* libFLAC++ - Free Lossless Audio Codec library |
| 2 | * Copyright (C) 2002 Josh Coalson |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | */ |
| 19 | |
| 20 | #ifndef FLACPP__METADATA_H |
| 21 | #define FLACPP__METADATA_H |
| 22 | |
| 23 | #include "FLAC/metadata.h" |
| 24 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 25 | // =============================================================== |
| 26 | // |
| 27 | // Full documentation for the metadata interface can be found |
| 28 | // in the C layer in include/FLAC/metadata.h |
| 29 | // |
| 30 | // =============================================================== |
| 31 | |
| 32 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 33 | namespace FLAC { |
| 34 | namespace Metadata { |
| 35 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 36 | // ============================================================ |
| 37 | // |
| 38 | // Metadata objects |
| 39 | // |
| 40 | // ============================================================ |
| 41 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 42 | class Prototype; |
| 43 | |
| 44 | Prototype *clone(const Prototype *); |
| 45 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 46 | // NOTE: When the get_*() methods return you a const pointer, |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 47 | // DO NOT disobey and write into it. Always use the set_*() |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 48 | // methods. |
| 49 | |
Josh Coalson | 8396175 | 2002-07-09 06:12:59 +0000 | [diff] [blame^] | 50 | //! |
| 51 | //! Base class for all metadata blocks. |
| 52 | //! |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 53 | class Prototype { |
| 54 | protected: |
Josh Coalson | 8396175 | 2002-07-09 06:12:59 +0000 | [diff] [blame^] | 55 | //! |
| 56 | //! Constructs a copy of the given object. This form |
| 57 | //! always performs a deep copy. |
| 58 | //! |
| 59 | Prototype(const Prototype &object); |
| 60 | |
| 61 | //! |
| 62 | //! Constructs a copy of the given object. This form |
| 63 | //! always performs a deep copy. |
| 64 | //! |
| 65 | Prototype(const ::FLAC__StreamMetadata &object); |
| 66 | |
| 67 | //! |
| 68 | //! Constructs a copy of the given object. This form |
| 69 | //! always performs a deep copy. |
| 70 | //! |
| 71 | Prototype(const ::FLAC__StreamMetadata *object); |
| 72 | |
| 73 | //! |
| 74 | //! Constructs an object with copy control. When 'copy' |
| 75 | //! is true, behaves identically to |
| 76 | //! FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object). |
| 77 | //! When 'copy' is false, the instance takes ownership of |
| 78 | //! the pointer and the ::FLAC__StreamMetadata object will |
| 79 | //! be freed by the destructor. |
| 80 | //! |
| 81 | Prototype(::FLAC__StreamMetadata *object, bool copy); |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 82 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 83 | void operator=(const Prototype &); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 84 | void operator=(const ::FLAC__StreamMetadata &); // this form always copies |
| 85 | void operator=(const ::FLAC__StreamMetadata *); // this form always copies |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 86 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 87 | virtual void clear(); |
| 88 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 89 | ::FLAC__StreamMetadata *object_; |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 90 | public: |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 91 | virtual ~Prototype(); |
| 92 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 93 | inline bool operator==(const Prototype &) const; |
| 94 | inline bool operator==(const ::FLAC__StreamMetadata &) const; |
| 95 | inline bool operator==(const ::FLAC__StreamMetadata *) const; |
| 96 | inline bool operator!=(const Prototype &) const; |
| 97 | inline bool operator!=(const ::FLAC__StreamMetadata &) const; |
| 98 | inline bool operator!=(const ::FLAC__StreamMetadata *) const; |
| 99 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 100 | friend class SimpleIterator; |
| 101 | friend class Iterator; |
| 102 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 103 | inline bool is_valid() const; |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 104 | |
| 105 | bool get_is_last() const; |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 106 | FLAC__MetadataType get_type() const; |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 107 | unsigned get_length() const; // NOTE: does not include the header, per spec |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 108 | |
| 109 | void set_is_last(bool); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 110 | private: |
Josh Coalson | 5ac8bd1 | 2002-05-29 05:53:57 +0000 | [diff] [blame] | 111 | Prototype(); // Private and undefined so you can't use it |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 112 | |
| 113 | // These are used only by Iterator |
| 114 | bool is_reference_; |
| 115 | inline void set_reference(bool x) { is_reference_ = x; } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 118 | inline bool Prototype::operator==(const Prototype &object) const |
Josh Coalson | d57c8d3 | 2002-06-11 06:15:28 +0000 | [diff] [blame] | 119 | { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 120 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 121 | inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const |
Josh Coalson | d57c8d3 | 2002-06-11 06:15:28 +0000 | [diff] [blame] | 122 | { return (bool)::FLAC__metadata_object_is_equal(object_, &object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 123 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 124 | inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const |
Josh Coalson | d57c8d3 | 2002-06-11 06:15:28 +0000 | [diff] [blame] | 125 | { return (bool)::FLAC__metadata_object_is_equal(object_, object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 126 | |
| 127 | inline bool Prototype::operator!=(const Prototype &object) const |
| 128 | { return !operator==(object); } |
| 129 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 130 | inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 131 | { return !operator==(object); } |
| 132 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 133 | inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 134 | { return !operator==(object); } |
| 135 | |
| 136 | inline bool Prototype::is_valid() const |
| 137 | { return 0 != object_; } |
| 138 | |
| 139 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 140 | class StreamInfo : public Prototype { |
| 141 | public: |
| 142 | StreamInfo(); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 143 | inline StreamInfo(const StreamInfo &object): Prototype(object) { } |
| 144 | inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { } |
| 145 | inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { } |
| 146 | inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 147 | ~StreamInfo(); |
| 148 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 149 | inline void operator=(const StreamInfo &object) { Prototype::operator=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 150 | inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } |
| 151 | inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 152 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 153 | inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 154 | inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } |
| 155 | inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 156 | inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 157 | inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } |
| 158 | inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 159 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 160 | unsigned get_min_blocksize() const; |
| 161 | unsigned get_max_blocksize() const; |
| 162 | unsigned get_min_framesize() const; |
| 163 | unsigned get_max_framesize() const; |
| 164 | unsigned get_sample_rate() const; |
| 165 | unsigned get_channels() const; |
| 166 | unsigned get_bits_per_sample() const; |
| 167 | FLAC__uint64 get_total_samples() const; |
| 168 | const FLAC__byte *get_md5sum() const; |
| 169 | |
| 170 | void set_min_blocksize(unsigned value); |
| 171 | void set_max_blocksize(unsigned value); |
| 172 | void set_min_framesize(unsigned value); |
| 173 | void set_max_framesize(unsigned value); |
| 174 | void set_sample_rate(unsigned value); |
| 175 | void set_channels(unsigned value); |
| 176 | void set_bits_per_sample(unsigned value); |
| 177 | void set_total_samples(FLAC__uint64 value); |
| 178 | void set_md5sum(const FLAC__byte value[16]); |
| 179 | }; |
| 180 | |
| 181 | class Padding : public Prototype { |
| 182 | public: |
| 183 | Padding(); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 184 | inline Padding(const Padding &object): Prototype(object) { } |
| 185 | inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { } |
| 186 | inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { } |
| 187 | inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 188 | ~Padding(); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 189 | |
| 190 | inline void operator=(const Padding &object) { Prototype::operator=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 191 | inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } |
| 192 | inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 193 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 194 | inline bool operator==(const Padding &object) const { return Prototype::operator==(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 195 | inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } |
| 196 | inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 197 | inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 198 | inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } |
| 199 | inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 200 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 201 | void set_length(unsigned length); |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | class Application : public Prototype { |
| 205 | public: |
| 206 | Application(); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 207 | inline Application(const Application &object): Prototype(object) { } |
| 208 | inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { } |
| 209 | inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { } |
| 210 | inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 211 | ~Application(); |
| 212 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 213 | inline void operator=(const Application &object) { Prototype::operator=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 214 | inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } |
| 215 | inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 216 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 217 | inline bool operator==(const Application &object) const { return Prototype::operator==(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 218 | inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } |
| 219 | inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 220 | inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 221 | inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } |
| 222 | inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 223 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 224 | const FLAC__byte *get_id() const; |
| 225 | const FLAC__byte *get_data() const; |
| 226 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 227 | void set_id(const FLAC__byte value[4]); |
| 228 | bool set_data(const FLAC__byte *data, unsigned length); // this form always copies |
| 229 | bool set_data(FLAC__byte *data, unsigned length, bool copy); |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | class SeekTable : public Prototype { |
| 233 | public: |
| 234 | SeekTable(); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 235 | inline SeekTable(const SeekTable &object): Prototype(object) { } |
| 236 | inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { } |
| 237 | inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { } |
| 238 | inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 239 | ~SeekTable(); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 240 | |
| 241 | inline void operator=(const SeekTable &object) { Prototype::operator=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 242 | inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } |
| 243 | inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 244 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 245 | inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 246 | inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } |
| 247 | inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 248 | inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 249 | inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } |
| 250 | inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 251 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 252 | unsigned get_num_points() const; |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 253 | ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const; |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 254 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 255 | void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point); |
| 256 | bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point); |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 257 | bool delete_point(unsigned index); |
Josh Coalson | 28e08d8 | 2002-06-05 05:56:41 +0000 | [diff] [blame] | 258 | |
| 259 | bool is_legal() const; |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | class VorbisComment : public Prototype { |
| 263 | public: |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 264 | class Entry { |
| 265 | public: |
| 266 | Entry(); |
| 267 | Entry(const char *field, unsigned field_length); |
| 268 | Entry(const char *field_name, const char *field_value, unsigned field_value_length); |
| 269 | Entry(const Entry &entry); |
| 270 | void operator=(const Entry &entry); |
| 271 | |
| 272 | virtual ~Entry(); |
| 273 | |
| 274 | virtual bool is_valid() const; |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 275 | |
| 276 | unsigned get_field_length() const; |
| 277 | unsigned get_field_name_length() const; |
| 278 | unsigned get_field_value_length() const; |
| 279 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 280 | ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const; |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 281 | const char *get_field() const; |
| 282 | const char *get_field_name() const; |
| 283 | const char *get_field_value() const; |
| 284 | |
| 285 | bool set_field(const char *field, unsigned field_length); |
| 286 | bool set_field_name(const char *field_name); |
| 287 | bool set_field_value(const char *field_value, unsigned field_value_length); |
| 288 | protected: |
| 289 | bool is_valid_; |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 290 | ::FLAC__StreamMetadata_VorbisComment_Entry entry_; |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 291 | char *field_name_; |
| 292 | unsigned field_name_length_; |
| 293 | char *field_value_; |
| 294 | unsigned field_value_length_; |
| 295 | private: |
| 296 | void zero(); |
| 297 | void clear(); |
| 298 | void clear_entry(); |
| 299 | void clear_field_name(); |
| 300 | void clear_field_value(); |
| 301 | void construct(const char *field, unsigned field_length); |
| 302 | void construct(const char *field_name, const char *field_value, unsigned field_value_length); |
| 303 | void compose_field(); |
| 304 | void parse_field(); |
| 305 | }; |
| 306 | |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 307 | VorbisComment(); |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 308 | inline VorbisComment(const VorbisComment &object): Prototype(object) { } |
| 309 | inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { } |
| 310 | inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { } |
| 311 | inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 312 | ~VorbisComment(); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 313 | |
| 314 | inline void operator=(const VorbisComment &object) { Prototype::operator=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 315 | inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } |
| 316 | inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 317 | |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 318 | inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 319 | inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } |
| 320 | inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 321 | inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); } |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 322 | inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } |
| 323 | inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } |
Josh Coalson | 57ba6f4 | 2002-06-07 05:27:37 +0000 | [diff] [blame] | 324 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 325 | unsigned get_num_comments() const; |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 326 | Entry get_vendor_string() const; // only the Entry's field name should be used |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 327 | Entry get_comment(unsigned index) const; |
| 328 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 329 | bool set_vendor_string(const Entry &entry); // only the Entry's field name will be used |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 330 | bool set_comment(unsigned index, const Entry &entry); |
| 331 | bool insert_comment(unsigned index, const Entry &entry); |
| 332 | bool delete_comment(unsigned index); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 335 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 336 | // ============================================================ |
| 337 | // |
| 338 | // Level 0 |
| 339 | // |
| 340 | // ============================================================ |
| 341 | |
| 342 | bool get_streaminfo(const char *filename, StreamInfo &streaminfo); |
| 343 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 344 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 345 | // ============================================================ |
| 346 | // |
| 347 | // Level 1 |
| 348 | // |
| 349 | // ---------------------------------------------------------- |
| 350 | // |
| 351 | // The flow through the iterator in the C++ layer is similar |
| 352 | // to the C layer: |
| 353 | // |
| 354 | // * Create a SimpleIterator instance |
| 355 | // * Check SimpleIterator::is_valid() |
| 356 | // * Call SimpleIterator::init() and check the return |
| 357 | // * Traverse and/or edit. Edits are written to file |
| 358 | // immediately. |
| 359 | // * Destroy the SimpleIterator instance |
| 360 | // |
| 361 | // ---------------------------------------------------------- |
| 362 | // |
| 363 | // The ownership of pointers in the C++ layer follows that in |
| 364 | // the C layer, i.e. |
| 365 | // * The objects returned by get_block() are yours to |
| 366 | // modify, but changes are not reflected in the FLAC file |
| 367 | // until you call set_block(). The objects are also |
| 368 | // yours to delete; they are not automatically deleted |
| 369 | // when passed to set_block() or insert_block_after(). |
| 370 | // |
| 371 | // ============================================================ |
| 372 | |
| 373 | class SimpleIterator { |
| 374 | public: |
| 375 | class Status { |
| 376 | public: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 377 | inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { } |
| 378 | inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; } |
| 379 | inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; } |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 380 | protected: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 381 | ::FLAC__Metadata_SimpleIteratorStatus status_; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | SimpleIterator(); |
| 385 | virtual ~SimpleIterator(); |
| 386 | |
| 387 | bool init(const char *filename, bool preserve_file_stats = false); |
| 388 | |
| 389 | bool is_valid() const; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 390 | Status status(); |
| 391 | bool is_writable() const; |
| 392 | |
| 393 | bool next(); |
| 394 | bool prev(); |
| 395 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 396 | ::FLAC__MetadataType get_block_type() const; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 397 | Prototype *get_block(); |
| 398 | bool set_block(Prototype *block, bool use_padding = true); |
| 399 | bool insert_block_after(Prototype *block, bool use_padding = true); |
| 400 | bool delete_block(bool use_padding = true); |
| 401 | |
| 402 | protected: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 403 | ::FLAC__Metadata_SimpleIterator *iterator_; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 404 | void clear(); |
| 405 | }; |
| 406 | |
Josh Coalson | b2b5358 | 2002-05-31 06:20:50 +0000 | [diff] [blame] | 407 | |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 408 | // ============================================================ |
| 409 | // |
| 410 | // Level 2 |
| 411 | // |
| 412 | // ---------------------------------------------------------- |
| 413 | // |
| 414 | // The flow through the iterator in the C++ layer is similar |
| 415 | // to the C layer: |
| 416 | // |
| 417 | // * Create a Chain instance |
| 418 | // * Check Chain::is_valid() |
| 419 | // * Call Chain::read() and check the return |
| 420 | // * Traverse and/or edit with an Iterator or with |
| 421 | // Chain::merge_padding() or Chain::sort_padding() |
| 422 | // * Write changes back to FLAC file with Chain::write() |
| 423 | // * Destroy the Chain instance |
| 424 | // |
| 425 | // ---------------------------------------------------------- |
| 426 | // |
| 427 | // The ownership of pointers in the C++ layer follows that in |
| 428 | // the C layer, i.e. |
| 429 | // * The objects returned by Iterator::get_block() are |
| 430 | // owned by the iterator and should not be deleted. |
| 431 | // When you modify the block, you are directly editing |
| 432 | // what's in the chain and do not need to call |
| 433 | // Iterator::set_block(). However the changes will not |
| 434 | // be reflected in the FLAC file until the chain is |
| 435 | // written with Chain::write(). |
| 436 | // |
| 437 | // * When you pass an object to Iterator::set_block(), |
| 438 | // Iterator::insert_block_before(), or |
| 439 | // Iterator::insert_block_after(), the iterator takes |
| 440 | // ownership of the block and it will be deleted with the |
| 441 | // chain. |
| 442 | // |
| 443 | // ============================================================ |
| 444 | |
| 445 | class Chain { |
| 446 | public: |
| 447 | class Status { |
| 448 | public: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 449 | inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { } |
| 450 | inline operator ::FLAC__Metadata_ChainStatus() const { return status_; } |
| 451 | inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; } |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 452 | protected: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 453 | ::FLAC__Metadata_ChainStatus status_; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | Chain(); |
| 457 | virtual ~Chain(); |
| 458 | |
| 459 | friend class Iterator; |
| 460 | |
| 461 | bool is_valid() const; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 462 | Status status(); |
| 463 | |
| 464 | bool read(const char *filename); |
| 465 | bool write(bool use_padding = true, bool preserve_file_stats = false); |
| 466 | |
| 467 | void merge_padding(); |
| 468 | void sort_padding(); |
| 469 | |
| 470 | protected: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 471 | ::FLAC__Metadata_Chain *chain_; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 472 | virtual void clear(); |
| 473 | }; |
| 474 | |
| 475 | class Iterator { |
| 476 | public: |
| 477 | Iterator(); |
| 478 | virtual ~Iterator(); |
| 479 | |
| 480 | bool is_valid() const; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 481 | |
Josh Coalson | 999be3b | 2002-06-10 04:42:35 +0000 | [diff] [blame] | 482 | void init(Chain &chain); |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 483 | |
| 484 | bool next(); |
| 485 | bool prev(); |
| 486 | |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 487 | ::FLAC__MetadataType get_block_type() const; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 488 | Prototype *get_block(); |
| 489 | bool set_block(Prototype *block); |
| 490 | bool delete_block(bool replace_with_padding); |
| 491 | bool insert_block_before(Prototype *block); |
| 492 | bool insert_block_after(Prototype *block); |
| 493 | |
| 494 | protected: |
Josh Coalson | cc68251 | 2002-06-08 04:53:42 +0000 | [diff] [blame] | 495 | ::FLAC__Metadata_Iterator *iterator_; |
Josh Coalson | fb74f10 | 2002-05-22 05:33:29 +0000 | [diff] [blame] | 496 | virtual void clear(); |
Josh Coalson | fda98fb | 2002-05-17 06:33:39 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | }; |
| 500 | }; |
| 501 | |
| 502 | #endif |