Tag Parser  6.2.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/conversion/stringbuilder.h>
6 
7 #include <memory>
8 
9 using namespace std;
10 using namespace ChronoUtilities;
11 using namespace ConversionUtilities;
12 
13 namespace Media {
14 
23 MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement) :
24  m_chapterAtomElement(chapterAtomElement)
25 {}
26 
31 {}
32 
42 {
43  // clear previous values and status
44  static const string context("parsing \"ChapterAtom\"-element");
46  clear();
47  // iterate through childs of "ChapterAtom"-element
48  for(EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
49  chapterAtomChild->parse();
50  switch(chapterAtomChild->id()) {
52  m_id = chapterAtomChild->readUInteger();
53  break;
55  break;
57  m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
58  break;
60  m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
61  break;
63  m_hidden = chapterAtomChild->readUInteger() == 1;
64  break;
66  m_enabled = chapterAtomChild->readUInteger() == 1;
67  break;
71  break;
73  for(EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement; chapterTrackElement = chapterTrackElement->nextSibling()) {
74  chapterTrackElement->parse();
75  switch(chapterTrackElement->id()) {
77  m_tracks.emplace_back(chapterTrackElement->readUInteger());
78  break;
79  default:
80  addNotification(NotificationType::Warning, "\"ChapterTrack\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
81  }
82  }
83  break;
85  m_names.emplace_back();
86  for(EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement; chapterDisplayElement = chapterDisplayElement->nextSibling()) {
87  chapterDisplayElement->parse();
88  switch(chapterDisplayElement->id()) {
90  if(m_names.back().empty()) {
91  m_names.back().assign(chapterDisplayElement->readString());
92  } else {
93  addNotification(NotificationType::Warning, "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
94  }
95  break;
97  m_names.back().languages().emplace_back(chapterDisplayElement->readString());
98  break;
100  m_names.back().countries().emplace_back(chapterDisplayElement->readString());
101  break;
102  }
103  }
104  break;
106  break;
108  m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
109  default:
110  addNotification(NotificationType::Warning, "\"ChapterAtom\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
111  }
112  }
113  // "eng" is default language
114  for(LocaleAwareString &name : m_names) {
115  if(name.languages().empty()) {
116  name.languages().emplace_back("eng");
117  }
118  }
119 }
120 
122 {
124  m_nestedChapters.clear();
125 }
126 
127 } // namespace Media
128 
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