comparison data/model/IntervalModel.h @ 1069:32ab6c48efaa

Merge from branch tonioni
author Chris Cannam
date Mon, 20 Apr 2015 09:11:34 +0100
parents 0559f25b99f2
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1036:682d64f05e72 1069:32ab6c48efaa
27 27
28 template <typename PointType> 28 template <typename PointType>
29 class IntervalModel : public SparseValueModel<PointType> 29 class IntervalModel : public SparseValueModel<PointType>
30 { 30 {
31 public: 31 public:
32 IntervalModel(int sampleRate, int resolution, 32 IntervalModel(sv_samplerate_t sampleRate, int resolution,
33 bool notifyOnAdd = true) : 33 bool notifyOnAdd = true) :
34 SparseValueModel<PointType>(sampleRate, resolution, notifyOnAdd) 34 SparseValueModel<PointType>(sampleRate, resolution, notifyOnAdd)
35 { } 35 { }
36 36
37 IntervalModel(int sampleRate, int resolution, 37 IntervalModel(sv_samplerate_t sampleRate, int resolution,
38 float valueMinimum, float valueMaximum, 38 float valueMinimum, float valueMaximum,
39 bool notifyOnAdd = true) : 39 bool notifyOnAdd = true) :
40 SparseValueModel<PointType>(sampleRate, resolution, 40 SparseValueModel<PointType>(sampleRate, resolution,
41 valueMinimum, valueMaximum, 41 valueMinimum, valueMaximum,
42 notifyOnAdd) 42 notifyOnAdd)
46 * PointTypes have a duration, so this returns all points that span any 46 * PointTypes have a duration, so this returns all points that span any
47 * of the given range (as well as the usual additional few before 47 * of the given range (as well as the usual additional few before
48 * and after). Consequently this can be very slow (optimised data 48 * and after). Consequently this can be very slow (optimised data
49 * structures still to be done!). 49 * structures still to be done!).
50 */ 50 */
51 virtual typename SparseValueModel<PointType>::PointList getPoints(long start, long end) const; 51 virtual typename SparseValueModel<PointType>::PointList getPoints(sv_frame_t start, sv_frame_t end) const;
52 52
53 /** 53 /**
54 * PointTypes have a duration, so this returns all points that span the 54 * PointTypes have a duration, so this returns all points that span the
55 * given frame. Consequently this can be very slow (optimised 55 * given frame. Consequently this can be very slow (optimised
56 * data structures still to be done!). 56 * data structures still to be done!).
57 */ 57 */
58 virtual typename SparseValueModel<PointType>::PointList getPoints(long frame) const; 58 virtual typename SparseValueModel<PointType>::PointList getPoints(sv_frame_t frame) const;
59 59
60 virtual const typename SparseModel<PointType>::PointList &getPoints() const { 60 virtual const typename SparseModel<PointType>::PointList &getPoints() const {
61 return SparseModel<PointType>::getPoints(); 61 return SparseModel<PointType>::getPoints();
62 } 62 }
63 63
105 PointType point(*i); 105 PointType point(*i);
106 command->deletePoint(point); 106 command->deletePoint(point);
107 107
108 switch (column) { 108 switch (column) {
109 // column cannot be 0 or 1, those cases were handled above 109 // column cannot be 0 or 1, those cases were handled above
110 case 2: point.value = value.toDouble(); break; 110 case 2: point.value = float(value.toDouble()); break;
111 case 3: point.duration = value.toInt(); break; 111 case 3: point.duration = value.toInt(); break;
112 } 112 }
113 113
114 command->addPoint(point); 114 command->addPoint(point);
115 return command->finish(); 115 return command->finish();
123 } 123 }
124 }; 124 };
125 125
126 template <typename PointType> 126 template <typename PointType>
127 typename SparseValueModel<PointType>::PointList 127 typename SparseValueModel<PointType>::PointList
128 IntervalModel<PointType>::getPoints(long start, long end) const 128 IntervalModel<PointType>::getPoints(sv_frame_t start, sv_frame_t end) const
129 { 129 {
130 typedef IntervalModel<PointType> I; 130 typedef IntervalModel<PointType> I;
131 131
132 if (start > end) return typename I::PointList(); 132 if (start > end) return typename I::PointList();
133 133
144 typename I::PointList rv; 144 typename I::PointList rv;
145 145
146 for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) { 146 for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) {
147 --i; 147 --i;
148 if (i->frame < start) { 148 if (i->frame < start) {
149 if (i->frame + long(i->duration) >= start) { 149 if (i->frame + i->duration >= start) {
150 rv.insert(*i); 150 rv.insert(*i);
151 } 151 }
152 } else if (i->frame <= end) { 152 } else if (i->frame <= end) {
153 rv.insert(*i); 153 rv.insert(*i);
154 } 154 }
157 return rv; 157 return rv;
158 } 158 }
159 159
160 template <typename PointType> 160 template <typename PointType>
161 typename SparseValueModel<PointType>::PointList 161 typename SparseValueModel<PointType>::PointList
162 IntervalModel<PointType>::getPoints(long frame) const 162 IntervalModel<PointType>::getPoints(sv_frame_t frame) const
163 { 163 {
164 typedef IntervalModel<PointType> I; 164 typedef IntervalModel<PointType> I;
165 165
166 QMutex &mutex(I::m_mutex); 166 QMutex &mutex(I::m_mutex);
167 QMutexLocker locker(&mutex); 167 QMutexLocker locker(&mutex);
168 168
169 if (I::m_resolution == 0) return typename I::PointList(); 169 if (I::m_resolution == 0) return typename I::PointList();
170 170
171 long start = (frame / I::m_resolution) * I::m_resolution; 171 sv_frame_t start = (frame / I::m_resolution) * I::m_resolution;
172 long end = start + I::m_resolution; 172 sv_frame_t end = start + I::m_resolution;
173 173
174 PointType endPoint(end); 174 PointType endPoint(end);
175 175
176 typename I::PointListConstIterator endItr = I::m_points.upper_bound(endPoint); 176 typename I::PointListConstIterator endItr = I::m_points.upper_bound(endPoint);
177 177
178 typename I::PointList rv; 178 typename I::PointList rv;
179 179
180 for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) { 180 for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) {
181 --i; 181 --i;
182 if (i->frame < start) { 182 if (i->frame < start) {
183 if (i->frame + long(i->duration) >= start) { 183 if (i->frame + i->duration >= start) {
184 rv.insert(*i); 184 rv.insert(*i);
185 } 185 }
186 } else if (i->frame <= end) { 186 } else if (i->frame <= end) {
187 rv.insert(*i); 187 rv.insert(*i);
188 } 188 }