Tag Parser  9.1.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mp4tag.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_MP4TAG_H
2 #define TAG_PARSER_MP4TAG_H
3 
4 #include "./mp4tagfield.h"
5 
6 #include "../fieldbasedtag.h"
7 
8 namespace TagParser {
9 
10 class Mp4Atom;
11 class Mp4Tag;
12 
14  Mp4ExtendedFieldId(const char *mean = nullptr, const char *name = nullptr, bool updateOnly = false);
16 
17  operator bool() const;
18  bool matches(const Mp4TagField &field) const;
19 
21  const char *mean;
23  const char *name;
25  bool updateOnly;
26 };
27 
31 inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(const char *mean, const char *name, bool updateOnly)
32  : mean(mean)
33  , name(name)
34  , updateOnly(updateOnly)
35 {
36 }
37 
41 inline Mp4ExtendedFieldId::operator bool() const
42 {
43  return mean && name;
44 }
45 
49 inline bool Mp4ExtendedFieldId::matches(const Mp4TagField &field) const
50 {
51  return field.mean() == mean && field.name() == name;
52 }
53 
55  friend class Mp4Tag;
56 
57 public:
58  void make(std::ostream &stream, Diagnostics &diag);
59  const Mp4Tag &tag() const;
60  std::uint64_t requiredSize() const;
61 
62 private:
63  Mp4TagMaker(Mp4Tag &tag, Diagnostics &diag);
64 
65  Mp4Tag &m_tag;
66  std::vector<Mp4TagFieldMaker> m_maker;
67  std::uint64_t m_metaSize;
68  std::uint64_t m_ilstSize;
69  bool m_omitPreDefinedGenre;
70 };
71 
75 inline const Mp4Tag &Mp4TagMaker::tag() const
76 {
77  return m_tag;
78 }
79 
83 inline std::uint64_t Mp4TagMaker::requiredSize() const
84 {
85  return m_metaSize;
86 }
87 
92 public:
94  using Compare = std::less<typename FieldType::IdentifierType>;
95 };
96 
97 class TAG_PARSER_EXPORT Mp4Tag : public FieldMapBasedTag<Mp4Tag> {
98  friend class FieldMapBasedTag<Mp4Tag>;
99 
100 public:
101  Mp4Tag();
102 
103  static constexpr TagType tagType = TagType::Mp4Tag;
104  static constexpr const char *tagName = "MP4/iTunes tag";
105  static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
106  bool canEncodingBeUsed(TagTextEncoding encoding) const override;
107 
108  bool supportsField(KnownField field) const override;
110  const TagValue &value(KnownField value) const override;
112  std::vector<const TagValue *> values(KnownField field) const override;
113  const TagValue &value(const std::string &mean, const std::string &name) const;
114  const TagValue &value(const char *mean, const char *name) const;
116  bool setValue(KnownField field, const TagValue &value) override;
118  bool setValues(KnownField field, const std::vector<TagValue> &values) override;
119  bool setValue(const std::string &mean, const std::string &name, const TagValue &value);
120  bool setValue(const char *mean, const char *name, const TagValue &value);
122  bool hasField(KnownField value) const override;
123  bool supportsMultipleValues(KnownField) const override;
124 
125  void parse(Mp4Atom &metaAtom, Diagnostics &diag);
126  Mp4TagMaker prepareMaking(Diagnostics &diag);
127  void make(std::ostream &stream, Diagnostics &diag);
128 
129 protected:
130  IdentifierType internallyGetFieldId(KnownField field) const;
131  KnownField internallyGetKnownField(const IdentifierType &id) const;
132 };
133 
138 {
139 }
140 
141 inline bool Mp4Tag::supportsField(KnownField field) const
142 {
143  switch (field) {
145  return true;
146  default:
148  }
149 }
150 
154 inline const TagValue &Mp4Tag::value(const std::string &mean, const std::string &name) const
155 {
156  return value(mean.data(), name.data());
157 }
158 
162 inline bool Mp4Tag::setValue(const std::string &mean, const std::string &name, const TagValue &value)
163 {
164  return setValue(mean.data(), name.data(), value);
165 }
166 
173 {
174  return false;
175 }
176 
177 } // namespace TagParser
178 
179 #endif // TAG_PARSER_MP4TAG_H
mp4tagfield.h
TagParser::TagTextEncoding::Utf8
TagParser::FieldMapBasedTag::supportsField
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
Definition: fieldbasedtag.h:335
TagParser::Mp4TagMaker::requiredSize
std::uint64_t requiredSize() const
Returns the number of bytes which will be written when making the tag.
Definition: mp4tag.h:83
TagParser::Mp4Tag::supportsMultipleValues
bool supportsMultipleValues(KnownField) const override
Returns false for all fields (for now).
Definition: mp4tag.h:172
TagParser::TagTextEncoding
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:25
TagParser::Mp4ExtendedFieldId::updateOnly
bool updateOnly
Whether only existing fields should be updated but no new extended field should be created.
Definition: mp4tag.h:25
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::Mp4ExtendedFieldId::name
const char * name
name parameter
Definition: mp4tag.h:23
TagParser::Mp4ExtendedFieldId
The Mp4ExtendedFieldId specifies parameter for an extended field denoted via Mp4TagAtomIds::Extended.
Definition: mp4tag.h:13
TagParser::Mp4ExtendedFieldId::mean
const char * mean
mean parameter, usually Mp4TagExtendedMeanIds::iTunes
Definition: mp4tag.h:21
TagParser::Mp4TagMaker
The Mp4TagMaker class helps writing MP4 tags.
Definition: mp4tag.h:54
TagParser::Mp4Tag::supportsField
bool supportsField(KnownField field) const override
Returns an indication whether the specified field is supported by the tag.
Definition: mp4tag.h:141
TagParser::Mp4TagMaker::tag
const Mp4Tag & tag() const
Returns the associated tag.
Definition: mp4tag.h:75
TagParser::Mp4Tag::value
const TagValue & value(KnownField value) const override
Returns the value of the specified field.
Definition: mp4tag.cpp:62
TagParser::TagType::Mp4Tag
TagParser::Mp4ExtendedFieldId::Mp4ExtendedFieldId
Mp4ExtendedFieldId(const char *mean=nullptr, const char *name=nullptr, bool updateOnly=false)
Constructs a new instance with the specified parameter.
Definition: mp4tag.h:31
TagParser::KnownField::EncoderSettings
TagParser::KnownField
KnownField
Specifies the field.
Definition: tag.h:42
TagParser::FieldMapBasedTag
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
Definition: fieldbasedtag.h:31
TagParser::TagValue
The TagValue class wraps values of different types. It is meant to be assigned to a tag field.
Definition: tagvalue.h:75
TagParser::Mp4Tag
Implementation of TagParser::Tag for the MP4 container.
Definition: mp4tag.h:97
TagParser::FieldMapBasedTagTraits< Mp4Tag >::Compare
std::less< typename FieldType::IdentifierType > Compare
Definition: mp4tag.h:94
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagParser::Mp4ExtendedFieldId::matches
bool matches(const Mp4TagField &field) const
Returns whether the current parameter match the specified field.
Definition: mp4tag.h:49
TagParser::Mp4Tag::setValue
bool setValue(KnownField field, const TagValue &value) override
Assigns the given value to the specified field.
Definition: mp4tag.cpp:220
TagParser::FieldMapBasedTagTraits
Defines traits for the specified ImplementationType.
Definition: fieldbasedtag.h:17
TagParser::Mp4TagField::mean
const std::string & mean() const
Returns the "mean" for "extended" fields.
Definition: mp4tagfield.h:161
TagParser::Mp4Atom
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:38
TagParser::Mp4Tag::Mp4Tag
Mp4Tag()
Constructs a new tag.
Definition: mp4tag.h:137
TagParser::Mp4TagField
The Mp4TagField class is used by Mp4Tag to store the fields.
Definition: mp4tagfield.h:98
TagParser::TagType
TagType
Specifies the tag type.
Definition: tag.h:20
TagParser::Mp4TagField::name
const std::string & name() const
Returns the "name" for "extended" fields.
Definition: mp4tagfield.h:145