comparison base/EventSeries.h @ 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 513192aa9b03
comparison
equal deleted inserted replaced
1639:7482da1cd920 1640:e7f557789f99
40 * very slow in bulk. 40 * very slow in bulk.
41 */ 41 */
42 class EventSeries : public XmlExportable 42 class EventSeries : public XmlExportable
43 { 43 {
44 public: 44 public:
45 EventSeries() { } 45 EventSeries() : m_finalDurationlessEventFrame(0) { }
46 ~EventSeries() =default; 46 ~EventSeries() =default;
47 47
48 EventSeries(const EventSeries &) =default; 48 EventSeries(const EventSeries &) =default;
49 EventSeries &operator=(const EventSeries &) =default; 49 EventSeries &operator=(const EventSeries &) =default;
50 EventSeries &operator=(EventSeries &&) =default; 50 EventSeries &operator=(EventSeries &&) =default;
59 bool contains(const Event &e) const; 59 bool contains(const Event &e) const;
60 bool isEmpty() const; 60 bool isEmpty() const;
61 int count() const; 61 int count() const;
62 62
63 /** 63 /**
64 * Return the frame of the first event in the series. If there are
65 * no events, return 0.
66 */
67 sv_frame_t getStartFrame() const;
68
69 /**
70 * Return the frame plus duration of the event in the series that
71 * ends last. If there are no events, return 0.
72 */
73 sv_frame_t getEndFrame() const;
74
75 /**
64 * Retrieve all events any part of which falls within the range in 76 * Retrieve all events any part of which falls within the range in
65 * frames defined by the given frame f and duration d. 77 * frames defined by the given frame f and duration d.
66 * 78 *
67 * - An event without duration is spanned by the range if its own 79 * - An event without duration is spanned by the range if its own
68 * frame is greater than or equal to f and less than f + d. 80 * frame is greater than or equal to f and less than f + d.
147 /** 159 /**
148 * Return the event at the given numerical index in the series, 160 * Return the event at the given numerical index in the series,
149 * where 0 = the first event and count()-1 = the last. 161 * where 0 = the first event and count()-1 = the last.
150 */ 162 */
151 Event getEventByIndex(int index) const; 163 Event getEventByIndex(int index) const;
164
165 /**
166 * Return the index of the first event in the series that does not
167 * compare inferior to the given event. If there is no such event,
168 * return count().
169 */
170 int getIndexForEvent(const Event &e) const;
152 171
153 /** 172 /**
154 * Emit to XML as a dataset element. 173 * Emit to XML as a dataset element.
155 */ 174 */
156 void toXml(QTextStream &out, 175 void toXml(QTextStream &out,
190 * identical copies of a given event we have. 209 * identical copies of a given event we have.
191 */ 210 */
192 typedef std::map<sv_frame_t, std::vector<Event>> FrameEventMap; 211 typedef std::map<sv_frame_t, std::vector<Event>> FrameEventMap;
193 FrameEventMap m_seams; 212 FrameEventMap m_seams;
194 213
214 /**
215 * The frame of the last durationless event we have in the series.
216 * This is to support a fast-ish getEndFrame(): we can easily keep
217 * this up-to-date when events are added or removed, and we can
218 * easily find the end frame of the last with-duration event from
219 * the seam map, but it's not so easy to continuously update an
220 * overall end frame or to find the last frame of all events
221 * without this.
222 */
223 sv_frame_t m_finalDurationlessEventFrame;
224
195 /** Create a seam at the given frame, copying from the prior seam 225 /** Create a seam at the given frame, copying from the prior seam
196 * if there is one. If a seam already exists at the given frame, 226 * if there is one. If a seam already exists at the given frame,
197 * leave it untouched. 227 * leave it untouched.
198 */ 228 */
199 void createSeam(sv_frame_t frame) { 229 void createSeam(sv_frame_t frame) {