Mercurial > hg > svcore
comparison data/model/DeferredNotifier.h @ 1752:6d09d68165a4 by-id
Further review of ById: make IDs only available when adding a model to the ById store, not by querying the item directly. This means any id encountered in the wild must have been added to the store at some point (even if later released), which simplifies reasoning about lifecycles
author | Chris Cannam |
---|---|
date | Fri, 05 Jul 2019 15:28:07 +0100 |
parents | 7a56bb85030f |
children |
comparison
equal
deleted
inserted
replaced
1751:77543124651b | 1752:6d09d68165a4 |
---|---|
28 enum Mode { | 28 enum Mode { |
29 NOTIFY_ALWAYS, | 29 NOTIFY_ALWAYS, |
30 NOTIFY_DEFERRED | 30 NOTIFY_DEFERRED |
31 }; | 31 }; |
32 | 32 |
33 DeferredNotifier(Model *m, Mode mode) : m_model(m), m_mode(mode) { } | 33 DeferredNotifier(Model *m, ModelId id, Mode mode) : |
34 m_model(m), m_modelId(id), m_mode(mode) { } | |
34 | 35 |
35 Mode getMode() const { | 36 Mode getMode() const { |
36 return m_mode; | 37 return m_mode; |
37 } | 38 } |
38 void switchMode(Mode newMode) { | 39 void switchMode(Mode newMode) { |
39 m_mode = newMode; | 40 m_mode = newMode; |
40 } | 41 } |
41 | 42 |
42 void update(sv_frame_t frame, sv_frame_t duration) { | 43 void update(sv_frame_t frame, sv_frame_t duration) { |
43 if (m_mode == NOTIFY_ALWAYS) { | 44 if (m_mode == NOTIFY_ALWAYS) { |
44 m_model->modelChangedWithin(frame, frame + duration); | 45 m_model->modelChangedWithin(m_modelId, frame, frame + duration); |
45 } else { | 46 } else { |
46 QMutexLocker locker(&m_mutex); | 47 QMutexLocker locker(&m_mutex); |
47 m_extents.sample(frame); | 48 m_extents.sample(frame); |
48 m_extents.sample(frame + duration); | 49 m_extents.sample(frame + duration); |
49 } | 50 } |
58 from = m_extents.getMin(); | 59 from = m_extents.getMin(); |
59 to = m_extents.getMax(); | 60 to = m_extents.getMax(); |
60 } | 61 } |
61 } | 62 } |
62 if (shouldEmit) { | 63 if (shouldEmit) { |
63 m_model->modelChangedWithin(from, to); | 64 m_model->modelChangedWithin(m_modelId, from, to); |
64 QMutexLocker locker(&m_mutex); | 65 QMutexLocker locker(&m_mutex); |
65 m_extents.reset(); | 66 m_extents.reset(); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 private: | 70 private: |
70 Model *m_model; | 71 Model *m_model; |
72 ModelId m_modelId; | |
71 Mode m_mode; | 73 Mode m_mode; |
72 QMutex m_mutex; | 74 QMutex m_mutex; |
73 Extents<sv_frame_t> m_extents; | 75 Extents<sv_frame_t> m_extents; |
74 }; | 76 }; |
75 | 77 |