Mercurial > hg > svcore
comparison base/Event.h @ 1623:676e32fa403e single-point
Permit hashing
author | Chris Cannam |
---|---|
date | Mon, 11 Mar 2019 11:17:18 +0000 |
parents | 2f9deb8d3295 |
children | 895186c43fce |
comparison
equal
deleted
inserted
replaced
1622:172bd3374adf | 1623:676e32fa403e |
---|---|
38 * sparse models. | 38 * sparse models. |
39 */ | 39 */ |
40 class Event | 40 class Event |
41 { | 41 { |
42 public: | 42 public: |
43 Event() : | |
44 m_haveValue(false), m_haveLevel(false), m_haveReferenceFrame(false), | |
45 m_value(0.f), m_level(0.f), m_frame(0), | |
46 m_duration(0), m_referenceFrame(0), m_label() { } | |
47 | |
43 Event(sv_frame_t frame) : | 48 Event(sv_frame_t frame) : |
44 m_haveValue(false), m_haveLevel(false), m_haveReferenceFrame(false), | 49 m_haveValue(false), m_haveLevel(false), m_haveReferenceFrame(false), |
45 m_value(0.f), m_level(0.f), m_frame(frame), | 50 m_value(0.f), m_level(0.f), m_frame(frame), |
46 m_duration(0), m_referenceFrame(0), m_label() { } | 51 m_duration(0), m_referenceFrame(0), m_label() { } |
47 | 52 |
261 if (!valueIsMidiPitch) { | 266 if (!valueIsMidiPitch) { |
262 n.frequency = frequency; | 267 n.frequency = frequency; |
263 } | 268 } |
264 | 269 |
265 return n; | 270 return n; |
271 } | |
272 | |
273 uint hash(uint seed = 0) const { | |
274 uint h = qHash(m_label, seed); | |
275 if (m_haveValue) h ^= qHash(m_value); | |
276 if (m_haveLevel) h ^= qHash(m_level); | |
277 h ^= qHash(m_frame); | |
278 h ^= qHash(m_duration); | |
279 if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame); | |
280 return h; | |
266 } | 281 } |
267 | 282 |
268 private: | 283 private: |
269 // The order of fields here is chosen to minimise overall size of struct. | 284 // The order of fields here is chosen to minimise overall size of struct. |
270 // We potentially store very many of these objects. | 285 // We potentially store very many of these objects. |
278 sv_frame_t m_duration; | 293 sv_frame_t m_duration; |
279 sv_frame_t m_referenceFrame; | 294 sv_frame_t m_referenceFrame; |
280 QString m_label; | 295 QString m_label; |
281 }; | 296 }; |
282 | 297 |
298 inline uint qHash(const Event &e, uint seed = 0) { | |
299 return e.hash(seed); | |
300 } | |
301 | |
283 typedef std::vector<Event> EventVector; | 302 typedef std::vector<Event> EventVector; |
284 | 303 |
285 #endif | 304 #endif |