Mercurial > hg > svcore
comparison base/EventSeries.cpp @ 1640:e7f557789f99 single-point
Add and test getEndFrame (and getStartFrame)
author | Chris Cannam |
---|---|
date | Wed, 13 Mar 2019 11:54:13 +0000 |
parents | b57a75aa5ae3 |
children | d591836e47ef |
comparison
equal
deleted
inserted
replaced
1639:7482da1cd920 | 1640:e7f557789f99 |
---|---|
38 if (pitr != m_events.end() && *pitr == p) { | 38 if (pitr != m_events.end() && *pitr == p) { |
39 isUnique = false; | 39 isUnique = false; |
40 } | 40 } |
41 m_events.insert(pitr, p); | 41 m_events.insert(pitr, p); |
42 | 42 |
43 if (!p.hasDuration() && p.getFrame() > m_finalDurationlessEventFrame) { | |
44 m_finalDurationlessEventFrame = p.getFrame(); | |
45 } | |
46 | |
43 if (p.hasDuration() && isUnique) { | 47 if (p.hasDuration() && isUnique) { |
44 | 48 |
45 const sv_frame_t frame = p.getFrame(); | 49 const sv_frame_t frame = p.getFrame(); |
46 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); | 50 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); |
47 | 51 |
90 } | 94 } |
91 } | 95 } |
92 | 96 |
93 m_events.erase(pitr); | 97 m_events.erase(pitr); |
94 | 98 |
99 if (!p.hasDuration() && isUnique && | |
100 p.getFrame() == m_finalDurationlessEventFrame) { | |
101 m_finalDurationlessEventFrame = 0; | |
102 for (auto ritr = m_events.rbegin(); ritr != m_events.rend(); ++ritr) { | |
103 if (!ritr->hasDuration()) { | |
104 m_finalDurationlessEventFrame = ritr->getFrame(); | |
105 break; | |
106 } | |
107 } | |
108 } | |
109 | |
95 if (p.hasDuration() && isUnique) { | 110 if (p.hasDuration() && isUnique) { |
96 | 111 |
97 const sv_frame_t frame = p.getFrame(); | 112 const sv_frame_t frame = p.getFrame(); |
98 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); | 113 const sv_frame_t endFrame = p.getFrame() + p.getDuration(); |
99 | 114 |
179 void | 194 void |
180 EventSeries::clear() | 195 EventSeries::clear() |
181 { | 196 { |
182 m_events.clear(); | 197 m_events.clear(); |
183 m_seams.clear(); | 198 m_seams.clear(); |
199 m_finalDurationlessEventFrame = 0; | |
200 } | |
201 | |
202 sv_frame_t | |
203 EventSeries::getStartFrame() const | |
204 { | |
205 if (m_events.empty()) return 0; | |
206 return m_events.begin()->getFrame(); | |
207 } | |
208 | |
209 sv_frame_t | |
210 EventSeries::getEndFrame() const | |
211 { | |
212 sv_frame_t latest = 0; | |
213 | |
214 if (m_events.empty()) return latest; | |
215 | |
216 latest = m_finalDurationlessEventFrame; | |
217 | |
218 if (m_seams.empty()) return latest; | |
219 | |
220 sv_frame_t lastSeam = m_seams.rbegin()->first; | |
221 if (lastSeam > latest) { | |
222 latest = lastSeam; | |
223 } | |
224 | |
225 return latest; | |
184 } | 226 } |
185 | 227 |
186 EventVector | 228 EventVector |
187 EventSeries::getEventsSpanning(sv_frame_t frame, | 229 EventSeries::getEventsSpanning(sv_frame_t frame, |
188 sv_frame_t duration) const | 230 sv_frame_t duration) const |
360 throw std::logic_error("index out of range"); | 402 throw std::logic_error("index out of range"); |
361 } | 403 } |
362 return m_events[index]; | 404 return m_events[index]; |
363 } | 405 } |
364 | 406 |
407 int | |
408 EventSeries::getIndexForEvent(const Event &e) const | |
409 { | |
410 auto pitr = lower_bound(m_events.begin(), m_events.end(), e); | |
411 return distance(m_events.begin(), pitr); | |
412 } | |
413 | |
365 void | 414 void |
366 EventSeries::toXml(QTextStream &out, | 415 EventSeries::toXml(QTextStream &out, |
367 QString indent, | 416 QString indent, |
368 QString extraAttributes) const | 417 QString extraAttributes) const |
369 { | 418 { |