Tag Parser  6.2.2
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 ID3V2TAG_H
2 #define ID3V2TAG_H
3 
4 #include "./id3v2frame.h"
5 
6 #include "../fieldbasedtag.h"
7 
8 #include <map>
9 
10 namespace Media
11 {
12 
13 class Id3v2Tag;
14 
16 {
17  bool operator()(const uint32 &lhs, const uint32 &rhs) const;
18 };
19 
21 {
22  friend class Id3v2Tag;
23 
24 public:
25  void make(std::ostream &stream, uint32 padding);
26  const Id3v2Tag &tag() const;
27  uint64 requiredSize() const;
28 
29 private:
30  Id3v2TagMaker(Id3v2Tag &tag);
31 
32  Id3v2Tag &m_tag;
33  uint32 m_framesSize;
34  uint32 m_requiredSize;
35  std::vector<Id3v2FrameMaker> m_maker;
36 };
37 
41 inline const Id3v2Tag &Id3v2TagMaker::tag() const
42 {
43  return m_tag;
44 }
45 
50 inline uint64 Id3v2TagMaker::requiredSize() const
51 {
52  return m_requiredSize;
53 }
54 
55 class TAG_PARSER_EXPORT Id3v2Tag : public FieldMapBasedTag<Id3v2Frame, FrameComparer>
56 {
57 public:
58  Id3v2Tag();
59 
60  static constexpr TagType tagType = TagType::Id3v2Tag;
61  TagType type() const;
62  const char *typeName() const;
63  TagTextEncoding proposedTextEncoding() const;
64  bool canEncodingBeUsed(TagTextEncoding encoding) const;
65  uint32 fieldId(KnownField value) const;
66  KnownField knownField(const uint32 &id) const;
67  TagDataType proposedDataType(const uint32 &id) const;
69  const TagValue &value(const typename Id3v2Frame::identifierType &id) const;
71  bool setValue(const typename Id3v2Frame::identifierType &id, const TagValue &value);
72  bool supportsDescription(KnownField field) const;
73  bool supportsMimeType(KnownField field) const;
74 
75  void parse(std::istream &sourceStream, const uint64 maximalSize = 0);
76  Id3v2TagMaker prepareMaking();
77  void make(std::ostream &targetStream, uint32 padding);
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 private:
92  byte m_majorVersion;
93  byte m_revisionVersion;
94  byte m_flags;
95  uint32 m_sizeExcludingHeader;
96  uint32 m_extendedHeaderSize;
97  uint32 m_paddingSize;
98 };
99 
104  m_majorVersion(4),
105  m_revisionVersion(0),
106  m_flags(0),
107  m_sizeExcludingHeader(0),
108  m_extendedHeaderSize(0),
109  m_paddingSize(0)
110 {}
111 
112 inline TagType Id3v2Tag::type() const
113 {
114  return TagType::Id3v2Tag;
115 }
116 
117 inline const char *Id3v2Tag::typeName() const
118 {
119  return "ID3v2 tag";
120 }
121 
123 {
124  return m_majorVersion > 3 ? TagTextEncoding::Utf8 : TagTextEncoding::Utf16LittleEndian;
125 }
126 
127 inline bool Id3v2Tag::canEncodingBeUsed(TagTextEncoding encoding) const
128 {
129  return encoding == TagTextEncoding::Latin1 || (encoding == TagTextEncoding::Utf8 && m_majorVersion > 3) || encoding == TagTextEncoding::Utf16BigEndian || encoding == TagTextEncoding::Utf16LittleEndian;
130 }
131 
133 {
134  return field == KnownField::Cover;
135 }
136 
137 inline bool Id3v2Tag::supportsMimeType(KnownField field) const
138 {
139  return field == KnownField::Cover;
140 }
141 
145 inline byte Id3v2Tag::majorVersion() const
146 {
147  return m_majorVersion;
148 }
149 
153 inline byte Id3v2Tag::revisionVersion() const
154 {
155  return m_revisionVersion;
156 }
157 
164 inline bool Id3v2Tag::isVersionSupported() const
165 {
166  return m_majorVersion == 2 || m_majorVersion == 3 || m_majorVersion == 4;
167 }
168 
172 inline byte Id3v2Tag::flags() const
173 {
174  return m_flags;
175 }
176 
181 {
182  return m_flags & 0x80;
183 }
184 
188 inline bool Id3v2Tag::hasExtendedHeader() const
189 {
190  return (m_majorVersion >= 3) && (m_flags & 0x40);
191 }
192 
196 inline bool Id3v2Tag::isExperimental() const
197 {
198  return (m_majorVersion >= 3) && (m_flags & 0x20);
199 }
200 
204 inline bool Id3v2Tag::hasFooter() const
205 {
206  return (m_majorVersion >= 3) && (m_flags & 0x10);
207 }
208 
212 inline uint32 Id3v2Tag::extendedHeaderSize() const
213 {
214  return m_extendedHeaderSize;
215 }
216 
221 inline uint32 Id3v2Tag::paddingSize() const
222 {
223  return m_paddingSize;
224 }
225 
226 }
227 
228 #endif // ID3V2TAG_H
The TagValue class wraps values of different types.
Definition: tagvalue.h:63
Defines the order which is used to store ID3v2 frames.
Definition: id3v2tag.h:15
Id3v2Tag()
Constructs a new tag.
Definition: id3v2tag.h:103
TagFieldTraits< Id3v2Frame >::identifierType identifierType
bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition: id3v2tag.h:132
uint32 extendedHeaderSize() const
Returns the size of the extended header if one is present; otherwise returns 0.
Definition: id3v2tag.h:212
KnownField
Specifies the field.
Definition: tag.h:42
byte majorVersion() const
Returns the major version if known; otherwise returns 0.
Definition: id3v2tag.h:145
bool hasFooter() const
Returns an indication whether a footer is present.
Definition: id3v2tag.h:204
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:21
bool supportsMimeType(KnownField field) const
Returns an indications whether the specified field supports mime types.
Definition: id3v2tag.h:137
bool isUnsynchronisationUsed() const
Returns an indication whether unsynchronisation is used.
Definition: id3v2tag.h:180
byte revisionVersion() const
Returns the revision version if known; otherwise returns 0.
Definition: id3v2tag.h:153
const Id3v2Tag & tag() const
Returns the associated tag.
Definition: id3v2tag.h:41
byte flags() const
Returns the flags read from the ID3v2 header.
Definition: id3v2tag.h:172
uint64 requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition: id3v2tag.h:50
TagType type() const
Returns the type of the tag as Media::TagType.
Definition: id3v2tag.h:112
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition: id3v2tag.h:122
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
Definition: fieldbasedtag.h:25
bool isExperimental() const
Returns an indication whether the tag is labeled as experimental.
Definition: id3v2tag.h:196
Implementation of Media::Tag for ID3v2 tags.
Definition: id3v2tag.h:55
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:221
TagType
Specifies the tag type.
Definition: tag.h:21
const char * typeName() const
Returns the type name of the tag as C-style string.
Definition: id3v2tag.h:117
bool isVersionSupported() const
Returns an indication whether the version is supported by the Id3v2Tag class.
Definition: id3v2tag.h:164
TagDataType
Specifies the data type.
Definition: tagvalue.h:50
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
bool canEncodingBeUsed(TagTextEncoding encoding) const
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition: id3v2tag.h:127
The Id3v2TagMaker class helps writing ID3v2 tags.
Definition: id3v2tag.h:20
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
bool hasExtendedHeader() const
Returns an indication whether an extended header is used.
Definition: id3v2tag.h:188