Tag Parser  6.1.1
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  TagType type() const;
61  const char *typeName() const;
62  TagTextEncoding proposedTextEncoding() const;
63  bool canEncodingBeUsed(TagTextEncoding encoding) const;
64  uint32 fieldId(KnownField value) const;
65  KnownField knownField(const uint32 &id) const;
66  TagDataType proposedDataType(const uint32 &id) const;
68  const TagValue &value(const typename Id3v2Frame::identifierType &id) const;
70  bool setValue(const typename Id3v2Frame::identifierType &id, const TagValue &value);
71  bool supportsDescription(KnownField field) const;
72  bool supportsMimeType(KnownField field) const;
73 
74  void parse(std::istream &sourceStream, const uint64 maximalSize = 0);
75  Id3v2TagMaker prepareMaking();
76  void make(std::ostream &targetStream, uint32 padding);
77 
78  byte majorVersion() const;
79  byte revisionVersion() const;
80  void setVersion(byte majorVersion, byte revisionVersion);
81  bool isVersionSupported() const;
82  byte flags() const;
83  bool isUnsynchronisationUsed() const;
84  bool hasExtendedHeader() const;
85  bool isExperimental() const;
86  bool hasFooter() const;
87  uint32 extendedHeaderSize() const;
88  uint32 paddingSize() const;
89 
90 private:
91  byte m_majorVersion;
92  byte m_revisionVersion;
93  byte m_flags;
94  uint32 m_sizeExcludingHeader;
95  uint32 m_extendedHeaderSize;
96  uint32 m_paddingSize;
97 };
98 
103  m_majorVersion(4),
104  m_revisionVersion(0),
105  m_flags(0),
106  m_sizeExcludingHeader(0),
107  m_extendedHeaderSize(0),
108  m_paddingSize(0)
109 {}
110 
111 inline TagType Id3v2Tag::type() const
112 {
113  return TagType::Id3v2Tag;
114 }
115 
116 inline const char *Id3v2Tag::typeName() const
117 {
118  return "ID3v2 tag";
119 }
120 
122 {
123  return m_majorVersion > 3 ? TagTextEncoding::Utf8 : TagTextEncoding::Utf16LittleEndian;
124 }
125 
126 inline bool Id3v2Tag::canEncodingBeUsed(TagTextEncoding encoding) const
127 {
128  return encoding == TagTextEncoding::Latin1 || (encoding == TagTextEncoding::Utf8 && m_majorVersion > 3) || encoding == TagTextEncoding::Utf16BigEndian || encoding == TagTextEncoding::Utf16LittleEndian;
129 }
130 
132 {
133  return field == KnownField::Cover;
134 }
135 
136 inline bool Id3v2Tag::supportsMimeType(KnownField field) const
137 {
138  return field == KnownField::Cover;
139 }
140 
144 inline byte Id3v2Tag::majorVersion() const
145 {
146  return m_majorVersion;
147 }
148 
152 inline byte Id3v2Tag::revisionVersion() const
153 {
154  return m_revisionVersion;
155 }
156 
163 inline bool Id3v2Tag::isVersionSupported() const
164 {
165  return m_majorVersion == 2 || m_majorVersion == 3 || m_majorVersion == 4;
166 }
167 
171 inline byte Id3v2Tag::flags() const
172 {
173  return m_flags;
174 }
175 
180 {
181  return m_flags & 0x80;
182 }
183 
187 inline bool Id3v2Tag::hasExtendedHeader() const
188 {
189  return (m_majorVersion >= 3) && (m_flags & 0x40);
190 }
191 
195 inline bool Id3v2Tag::isExperimental() const
196 {
197  return (m_majorVersion >= 3) && (m_flags & 0x20);
198 }
199 
203 inline bool Id3v2Tag::hasFooter() const
204 {
205  return (m_majorVersion >= 3) && (m_flags & 0x10);
206 }
207 
211 inline uint32 Id3v2Tag::extendedHeaderSize() const
212 {
213  return m_extendedHeaderSize;
214 }
215 
220 inline uint32 Id3v2Tag::paddingSize() const
221 {
222  return m_paddingSize;
223 }
224 
225 }
226 
227 #endif // ID3V2TAG_H
The TagValue class wraps values of different types.
Definition: tagvalue.h:64
Defines the order which is used to store ID3v2 frames.
Definition: id3v2tag.h:15
Id3v2Tag()
Constructs a new tag.
Definition: id3v2tag.h:102
TagFieldTraits< Id3v2Frame >::identifierType identifierType
bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition: id3v2tag.h:131
uint32 extendedHeaderSize() const
Returns the size of the extended header if one is present; otherwise returns 0.
Definition: id3v2tag.h:211
KnownField
Specifies the field.
Definition: tag.h:42
byte majorVersion() const
Returns the major version if known; otherwise returns 0.
Definition: id3v2tag.h:144
bool hasFooter() const
Returns an indication whether a footer is present.
Definition: id3v2tag.h:203
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:22
bool supportsMimeType(KnownField field) const
Returns an indications whether the specified field supports mime types.
Definition: id3v2tag.h:136
bool isUnsynchronisationUsed() const
Returns an indication whether unsynchronisation is used.
Definition: id3v2tag.h:179
byte revisionVersion() const
Returns the revision version if known; otherwise returns 0.
Definition: id3v2tag.h:152
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:171
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:111
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition: id3v2tag.h:121
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:195
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:220
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:116
bool isVersionSupported() const
Returns an indication whether the version is supported by the Id3v2Tag class.
Definition: id3v2tag.h:163
TagDataType
Specifies the data type.
Definition: tagvalue.h:51
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:126
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:187