Tag Parser  6.1.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
matroskachapter.cpp
Go to the documentation of this file.
1 #include "./matroskachapter.h"
2 #include "./ebmlelement.h"
3 #include "./matroskaid.h"
4 
5 #include <c++utilities/misc/memory.h>
6 
7 using namespace std;
8 using namespace ChronoUtilities;
9 
10 namespace Media {
11 
20 MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement) :
21  m_chapterAtomElement(chapterAtomElement)
22 {}
23 
28 {}
29 
39 {
40  // clear previous values and status
41  static const string context("parsing \"ChapterAtom\"-element");
43  clear();
44  // iterate through childs of "ChapterAtom"-element
45  for(EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
46  chapterAtomChild->parse();
47  switch(chapterAtomChild->id()) {
49  m_id = chapterAtomChild->readUInteger();
50  break;
52  break;
54  m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
55  break;
57  m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
58  break;
60  m_hidden = chapterAtomChild->readUInteger() == 1;
61  break;
63  m_enabled = chapterAtomChild->readUInteger() == 1;
64  break;
68  break;
70  for(EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement; chapterTrackElement = chapterTrackElement->nextSibling()) {
71  chapterTrackElement->parse();
72  switch(chapterTrackElement->id()) {
74  m_tracks.emplace_back(chapterTrackElement->readUInteger());
75  break;
76  default:
77  addNotification(NotificationType::Warning, "\"ChapterTrack\"-element contains unknown child element \"" + chapterAtomChild->idToString() + "\". It will be ignored.", context);
78  }
79  }
80  break;
82  m_names.emplace_back();
83  for(EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement; chapterDisplayElement = chapterDisplayElement->nextSibling()) {
84  chapterDisplayElement->parse();
85  switch(chapterDisplayElement->id()) {
87  if(m_names.back().empty()) {
88  m_names.back().assign(chapterDisplayElement->readString());
89  } else {
90  addNotification(NotificationType::Warning, "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
91  }
92  break;
94  m_names.back().languages().emplace_back(chapterDisplayElement->readString());
95  break;
97  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
98  break;
99  }
100  }
101  break;
103  break;
105  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
106  default:
107  addNotification(NotificationType::Warning, "\"ChapterAtom\"-element contains unknown child element \"" + chapterAtomChild->idToString() + "\". It will be ignored.", context);
108  }
109  }
110  // "eng" is default language
111  for(LocaleAwareString &name : m_names) {
112  if(name.languages().empty()) {
113  name.languages().emplace_back("eng");
114  }
115  }
116 }
117 
119 {
121  m_nestedChapters.clear();
122 }
123 
124 } // namespace Media
125 
void invalidateStatus()
Invalidates the current status.
void internalParse()
Internally called to parse the chapter.
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition: ebmlelement.h:50
std::vector< uint64 > m_tracks
ChronoUtilities::TimeSpan m_startTime
STL namespace.
void addNotification(const Notification &notification)
This protected method is meant to be called by the derived class to add a notification.
The LocaleAwareString class is a standard string with locale information (languages, countries).
void clear()
Resets the object to its initial state.
ChronoUtilities::TimeSpan m_endTime
~MatroskaChapter()
Destroys the chapter.
implementationType * firstChild()
Returns the first child of the element.
virtual void clear()
Resets the object to its initial state.
std::vector< LocaleAwareString > m_names
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9