Tag Parser  7.0.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
id3v2tag.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_ID3V2TAG_H
2 #define TAG_PARSER_ID3V2TAG_H
3 
4 #include "./id3v2frame.h"
5 
6 #include "../fieldbasedtag.h"
7 
8 #include <map>
9 
10 namespace TagParser {
11 
12 class Id3v2Tag;
13 
15  bool operator()(const uint32 &lhs, const uint32 &rhs) const;
16 };
17 
19  friend class Id3v2Tag;
20 
21 public:
22  void make(std::ostream &stream, uint32 padding, Diagnostics &diag);
23  const Id3v2Tag &tag() const;
24  uint64 requiredSize() const;
25 
26 private:
27  Id3v2TagMaker(Id3v2Tag &tag, Diagnostics &diag);
28 
29  Id3v2Tag &m_tag;
30  uint32 m_framesSize;
31  uint32 m_requiredSize;
32  std::vector<Id3v2FrameMaker> m_maker;
33 };
34 
38 inline const Id3v2Tag &Id3v2TagMaker::tag() const
39 {
40  return m_tag;
41 }
42 
47 inline uint64 Id3v2TagMaker::requiredSize() const
48 {
49  return m_requiredSize;
50 }
51 
56 public:
59 };
60 
61 class TAG_PARSER_EXPORT Id3v2Tag : public FieldMapBasedTag<Id3v2Tag> {
62  friend class FieldMapBasedTag<Id3v2Tag>;
63 
64 public:
65  Id3v2Tag();
66 
67  static constexpr TagType tagType = TagType::Id3v2Tag;
68  static constexpr const char *tagName = "ID3v2 tag";
69  static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf16LittleEndian;
70  TagTextEncoding proposedTextEncoding() const override;
71  bool canEncodingBeUsed(TagTextEncoding encoding) const override;
72  bool supportsDescription(KnownField field) const override;
73  bool supportsMimeType(KnownField field) const override;
74 
75  void parse(std::istream &sourceStream, const uint64 maximalSize, Diagnostics &diag);
76  Id3v2TagMaker prepareMaking(Diagnostics &diag);
77  void make(std::ostream &targetStream, uint32 padding, Diagnostics &diag);
78 
79  byte majorVersion() const;
80  byte revisionVersion() const;
81  void setVersion(byte majorVersion, byte revisionVersion);
82  bool isVersionSupported() const;
83  byte flags() const;
84  bool isUnsynchronisationUsed() const;
85  bool hasExtendedHeader() const;
86  bool isExperimental() const;
87  bool hasFooter() const;
88  uint32 extendedHeaderSize() const;
89  uint32 paddingSize() const;
90 
91 protected:
92  IdentifierType internallyGetFieldId(KnownField field) const;
93  KnownField internallyGetKnownField(const IdentifierType &id) const;
94  TagDataType internallyGetProposedDataType(const uint32 &id) const;
95 
96 private:
97  byte m_majorVersion;
98  byte m_revisionVersion;
99  byte m_flags;
100  uint32 m_sizeExcludingHeader;
101  uint32 m_extendedHeaderSize;
102  uint32 m_paddingSize;
103 };
104 
109  : m_majorVersion(4)
110  , m_revisionVersion(0)
111  , m_flags(0)
112  , m_sizeExcludingHeader(0)
113  , m_extendedHeaderSize(0)
114  , m_paddingSize(0)
115 {
116 }
117 
119 {
120  return m_majorVersion > 3 ? TagTextEncoding::Utf8 : TagTextEncoding::Utf16LittleEndian;
121 }
122 
123 inline bool Id3v2Tag::canEncodingBeUsed(TagTextEncoding encoding) const
124 {
125  return encoding == TagTextEncoding::Latin1 || (encoding == TagTextEncoding::Utf8 && m_majorVersion > 3)
127 }
128 
130 {
131  return field == KnownField::Cover;
132 }
133 
134 inline bool Id3v2Tag::supportsMimeType(KnownField field) const
135 {
136  return field == KnownField::Cover;
137 }
138 
142 inline byte Id3v2Tag::majorVersion() const
143 {
144  return m_majorVersion;
145 }
146 
150 inline byte Id3v2Tag::revisionVersion() const
151 {
152  return m_revisionVersion;
153 }
154 
161 inline bool Id3v2Tag::isVersionSupported() const
162 {
163  return m_majorVersion == 2 || m_majorVersion == 3 || m_majorVersion == 4;
164 }
165 
169 inline byte Id3v2Tag::flags() const
170 {
171  return m_flags;
172 }
173 
178 {
179  return m_flags & 0x80;
180 }
181 
185 inline bool Id3v2Tag::hasExtendedHeader() const
186 {
187  return (m_majorVersion >= 3) && (m_flags & 0x40);
188 }
189 
193 inline bool Id3v2Tag::isExperimental() const
194 {
195  return (m_majorVersion >= 3) && (m_flags & 0x20);
196 }
197 
201 inline bool Id3v2Tag::hasFooter() const
202 {
203  return (m_majorVersion >= 3) && (m_flags & 0x10);
204 }
205 
209 inline uint32 Id3v2Tag::extendedHeaderSize() const
210 {
211  return m_extendedHeaderSize;
212 }
213 
218 inline uint32 Id3v2Tag::paddingSize() const
219 {
220  return m_paddingSize;
221 }
222 
223 } // namespace TagParser
224 
225 #endif // TAG_PARSER_ID3V2TAG_H
bool supportsDescription(KnownField field) const override
Returns an indications whether the specified field supports descriptions.
Definition: id3v2tag.h:129
uint32 paddingSize() const
Returns the size of the padding between the tag and the first MPEG frame if one is present; otherwise...
Definition: id3v2tag.h:218
TagTextEncoding proposedTextEncoding() const override
Returns the proposed text encoding.
Definition: id3v2tag.h:118
bool isUnsynchronisationUsed() const
Returns an indication whether unsynchronisation is used.
Definition: id3v2tag.h:177
TagDataType
Specifies the data type.
Definition: tagvalue.h:51
byte flags() const
Returns the flags read from the ID3v2 header.
Definition: id3v2tag.h:169
const Id3v2Tag & tag() const
Returns the associated tag.
Definition: id3v2tag.h:38
KnownField
Specifies the field.
Definition: tag.h:40
byte revisionVersion() const
Returns the revision version if known; otherwise returns 0.
Definition: id3v2tag.h:150
uint64 requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition: id3v2tag.h:47
Id3v2Tag()
Constructs a new tag.
Definition: id3v2tag.h:108
bool isVersionSupported() const
Returns an indication whether the version is supported by the Id3v2Tag class.
Definition: id3v2tag.h:161
bool hasFooter() const
Returns an indication whether a footer is present.
Definition: id3v2tag.h:201
bool hasExtendedHeader() const
Returns an indication whether an extended header is used.
Definition: id3v2tag.h:185
bool supportsMimeType(KnownField field) const override
Returns an indications whether the specified field supports mime types.
Definition: id3v2tag.h:134
uint32 extendedHeaderSize() const
Returns the size of the extended header if one is present; otherwise returns 0.
Definition: id3v2tag.h:209
bool canEncodingBeUsed(TagTextEncoding encoding) const override
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition: id3v2tag.h:123
byte majorVersion() const
Returns the major version if known; otherwise returns 0.
Definition: id3v2tag.h:142
bool isExperimental() const
Returns an indication whether the tag is labeled as experimental.
Definition: id3v2tag.h:193
TagType
Specifies the tag type.
Definition: tag.h:20
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:22
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.