Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 383:94fc0591ea43 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | ba30f4a3e3be |
children |
comparison
equal
deleted
inserted
replaced
349:f39d33b0b265 | 383:94fc0591ea43 |
---|---|
15 | 15 |
16 #include "AlignmentModel.h" | 16 #include "AlignmentModel.h" |
17 | 17 |
18 #include "SparseTimeValueModel.h" | 18 #include "SparseTimeValueModel.h" |
19 | 19 |
20 //#define DEBUG_ALIGNMENT_MODEL 1 | |
21 | |
20 AlignmentModel::AlignmentModel(Model *reference, | 22 AlignmentModel::AlignmentModel(Model *reference, |
21 Model *aligned, | 23 Model *aligned, |
22 Model *inputModel, | 24 Model *inputModel, |
23 SparseTimeValueModel *path) : | 25 SparseTimeValueModel *path) : |
24 m_reference(reference), | 26 m_reference(reference), |
28 m_path(0), | 30 m_path(0), |
29 m_reversePath(0), | 31 m_reversePath(0), |
30 m_pathBegun(false), | 32 m_pathBegun(false), |
31 m_pathComplete(false) | 33 m_pathComplete(false) |
32 { | 34 { |
33 connect(m_rawPath, SIGNAL(modelChanged()), | 35 if (m_rawPath) { |
34 this, SLOT(pathChanged())); | 36 |
35 | 37 connect(m_rawPath, SIGNAL(modelChanged()), |
36 connect(m_rawPath, SIGNAL(modelChanged(size_t, size_t)), | 38 this, SLOT(pathChanged())); |
37 this, SLOT(pathChanged(size_t, size_t))); | 39 |
38 | 40 connect(m_rawPath, SIGNAL(modelChanged(size_t, size_t)), |
39 connect(m_rawPath, SIGNAL(completionChanged()), | 41 this, SLOT(pathChanged(size_t, size_t))); |
40 this, SLOT(pathCompletionChanged())); | 42 |
43 connect(m_rawPath, SIGNAL(completionChanged()), | |
44 this, SLOT(pathCompletionChanged())); | |
45 } | |
41 | 46 |
42 constructPath(); | 47 constructPath(); |
43 constructReversePath(); | 48 constructReversePath(); |
44 } | 49 } |
45 | 50 |
122 } | 127 } |
123 | 128 |
124 size_t | 129 size_t |
125 AlignmentModel::toReference(size_t frame) const | 130 AlignmentModel::toReference(size_t frame) const |
126 { | 131 { |
127 // std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; | 132 #ifdef DEBUG_ALIGNMENT_MODEL |
128 if (!m_path) constructPath(); | 133 std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; |
134 #endif | |
135 if (!m_path) { | |
136 if (!m_rawPath) return frame; | |
137 constructPath(); | |
138 } | |
129 return align(m_path, frame); | 139 return align(m_path, frame); |
130 } | 140 } |
131 | 141 |
132 size_t | 142 size_t |
133 AlignmentModel::fromReference(size_t frame) const | 143 AlignmentModel::fromReference(size_t frame) const |
134 { | 144 { |
135 // std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | 145 #ifdef DEBUG_ALIGNMENT_MODEL |
136 if (!m_reversePath) constructReversePath(); | 146 std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; |
147 #endif | |
148 if (!m_reversePath) { | |
149 if (!m_rawPath) return frame; | |
150 constructReversePath(); | |
151 } | |
137 return align(m_reversePath, frame); | 152 return align(m_reversePath, frame); |
138 } | 153 } |
139 | 154 |
140 void | 155 void |
141 AlignmentModel::pathChanged() | 156 AlignmentModel::pathChanged() |
164 if (!m_pathComplete) { | 179 if (!m_pathComplete) { |
165 | 180 |
166 int completion = 0; | 181 int completion = 0; |
167 m_rawPath->isReady(&completion); | 182 m_rawPath->isReady(&completion); |
168 | 183 |
169 // std::cerr << "AlignmentModel::pathCompletionChanged: completion = " | 184 #ifdef DEBUG_ALIGNMENT_MODEL |
170 // << completion << std::endl; | 185 std::cerr << "AlignmentModel::pathCompletionChanged: completion = " |
186 << completion << std::endl; | |
187 #endif | |
171 | 188 |
172 m_pathComplete = (completion == 100); | 189 m_pathComplete = (completion == 100); |
173 | 190 |
174 if (m_pathComplete) { | 191 if (m_pathComplete) { |
175 | 192 |
209 float value = i->value; | 226 float value = i->value; |
210 long rframe = lrintf(value * m_aligned->getSampleRate()); | 227 long rframe = lrintf(value * m_aligned->getSampleRate()); |
211 m_path->addPoint(PathPoint(frame, rframe)); | 228 m_path->addPoint(PathPoint(frame, rframe)); |
212 } | 229 } |
213 | 230 |
214 // std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 231 #ifdef DEBUG_ALIGNMENT_MODEL |
232 std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | |
233 #endif | |
215 } | 234 } |
216 | 235 |
217 void | 236 void |
218 AlignmentModel::constructReversePath() const | 237 AlignmentModel::constructReversePath() const |
219 { | 238 { |
239 float value = i->value; | 258 float value = i->value; |
240 long rframe = lrintf(value * m_aligned->getSampleRate()); | 259 long rframe = lrintf(value * m_aligned->getSampleRate()); |
241 m_reversePath->addPoint(PathPoint(rframe, frame)); | 260 m_reversePath->addPoint(PathPoint(rframe, frame)); |
242 } | 261 } |
243 | 262 |
244 // std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 263 #ifdef DEBUG_ALIGNMENT_MODEL |
264 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | |
265 #endif | |
245 } | 266 } |
246 | 267 |
247 size_t | 268 size_t |
248 AlignmentModel::align(PathModel *path, size_t frame) const | 269 AlignmentModel::align(PathModel *path, size_t frame) const |
249 { | 270 { |
255 // increasing. | 276 // increasing. |
256 | 277 |
257 const PathModel::PointList &points = path->getPoints(); | 278 const PathModel::PointList &points = path->getPoints(); |
258 | 279 |
259 if (points.empty()) { | 280 if (points.empty()) { |
260 // std::cerr << "AlignmentModel::align: No points" << std::endl; | 281 #ifdef DEBUG_ALIGNMENT_MODEL |
282 std::cerr << "AlignmentModel::align: No points" << std::endl; | |
283 #endif | |
261 return frame; | 284 return frame; |
262 } | 285 } |
263 | 286 |
287 #ifdef DEBUG_ALIGNMENT_MODEL | |
288 std::cerr << "AlignmentModel::align: frame " << frame << " requested" << std::endl; | |
289 #endif | |
290 | |
264 PathModel::Point point(frame); | 291 PathModel::Point point(frame); |
265 PathModel::PointList::const_iterator i = points.lower_bound(point); | 292 PathModel::PointList::const_iterator i = points.lower_bound(point); |
266 if (i == points.end()) --i; | 293 if (i == points.end()) { |
294 #ifdef DEBUG_ALIGNMENT_MODEL | |
295 std::cerr << "Note: i == points.end()" << std::endl; | |
296 #endif | |
297 --i; | |
298 } | |
267 while (i != points.begin() && i->frame > long(frame)) --i; | 299 while (i != points.begin() && i->frame > long(frame)) --i; |
268 | 300 |
269 long foundFrame = i->frame; | 301 long foundFrame = i->frame; |
270 long foundMapFrame = i->mapframe; | 302 long foundMapFrame = i->mapframe; |
271 | 303 |
272 long followingFrame = foundFrame; | 304 long followingFrame = foundFrame; |
273 long followingMapFrame = foundMapFrame; | 305 long followingMapFrame = foundMapFrame; |
274 | 306 |
275 if (++i != points.end()) { | 307 if (++i != points.end()) { |
308 #ifdef DEBUG_ALIGNMENT_MODEL | |
309 std::cerr << "another point available" << std::endl; | |
310 #endif | |
276 followingFrame = i->frame; | 311 followingFrame = i->frame; |
277 followingMapFrame = i->mapframe; | 312 followingMapFrame = i->mapframe; |
278 } | 313 } else { |
314 #ifdef DEBUG_ALIGNMENT_MODEL | |
315 std::cerr << "no other point available" << std::endl; | |
316 #endif | |
317 } | |
279 | 318 |
280 if (foundMapFrame < 0) return 0; | 319 if (foundMapFrame < 0) return 0; |
281 | 320 |
282 size_t resultFrame = foundMapFrame; | 321 size_t resultFrame = foundMapFrame; |
283 | 322 |
286 float(frame - foundFrame) / | 325 float(frame - foundFrame) / |
287 float(followingFrame - foundFrame); | 326 float(followingFrame - foundFrame); |
288 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); | 327 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); |
289 } | 328 } |
290 | 329 |
291 // std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | 330 #ifdef DEBUG_ALIGNMENT_MODEL |
331 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | |
332 #endif | |
292 | 333 |
293 return resultFrame; | 334 return resultFrame; |
294 } | 335 } |
295 | 336 |