Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 742:c10cb8782576 coreaudio_tests
Merge from branch "default"
author | Chris Cannam |
---|---|
date | Sun, 01 Jul 2012 11:53:00 +0100 |
parents | 1424aa29ae95 |
children | e802e550a1f2 |
comparison
equal
deleted
inserted
replaced
666:4efa7429cd85 | 742:c10cb8782576 |
---|---|
139 | 139 |
140 size_t | 140 size_t |
141 AlignmentModel::toReference(size_t frame) const | 141 AlignmentModel::toReference(size_t frame) const |
142 { | 142 { |
143 #ifdef DEBUG_ALIGNMENT_MODEL | 143 #ifdef DEBUG_ALIGNMENT_MODEL |
144 std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; | 144 SVDEBUG << "AlignmentModel::toReference(" << frame << ")" << endl; |
145 #endif | 145 #endif |
146 if (!m_path) { | 146 if (!m_path) { |
147 if (!m_rawPath) return frame; | 147 if (!m_rawPath) return frame; |
148 constructPath(); | 148 constructPath(); |
149 } | 149 } |
152 | 152 |
153 size_t | 153 size_t |
154 AlignmentModel::fromReference(size_t frame) const | 154 AlignmentModel::fromReference(size_t frame) const |
155 { | 155 { |
156 #ifdef DEBUG_ALIGNMENT_MODEL | 156 #ifdef DEBUG_ALIGNMENT_MODEL |
157 std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | 157 SVDEBUG << "AlignmentModel::fromReference(" << frame << ")" << endl; |
158 #endif | 158 #endif |
159 if (!m_reversePath) { | 159 if (!m_reversePath) { |
160 if (!m_rawPath) return frame; | 160 if (!m_rawPath) return frame; |
161 constructReversePath(); | 161 constructReversePath(); |
162 } | 162 } |
192 | 192 |
193 int completion = 0; | 193 int completion = 0; |
194 m_rawPath->isReady(&completion); | 194 m_rawPath->isReady(&completion); |
195 | 195 |
196 #ifdef DEBUG_ALIGNMENT_MODEL | 196 #ifdef DEBUG_ALIGNMENT_MODEL |
197 std::cerr << "AlignmentModel::pathCompletionChanged: completion = " | 197 SVDEBUG << "AlignmentModel::pathCompletionChanged: completion = " |
198 << completion << std::endl; | 198 << completion << endl; |
199 #endif | 199 #endif |
200 | 200 |
201 m_pathComplete = (completion == 100); | 201 m_pathComplete = (completion == 100); |
202 | 202 |
203 if (m_pathComplete) { | 203 if (m_pathComplete) { |
240 long rframe = lrintf(value * m_aligned->getSampleRate()); | 240 long rframe = lrintf(value * m_aligned->getSampleRate()); |
241 m_path->addPoint(PathPoint(frame, rframe)); | 241 m_path->addPoint(PathPoint(frame, rframe)); |
242 } | 242 } |
243 | 243 |
244 #ifdef DEBUG_ALIGNMENT_MODEL | 244 #ifdef DEBUG_ALIGNMENT_MODEL |
245 std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 245 SVDEBUG << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl; |
246 #endif | 246 #endif |
247 } | 247 } |
248 | 248 |
249 void | 249 void |
250 AlignmentModel::constructReversePath() const | 250 AlignmentModel::constructReversePath() const |
251 { | 251 { |
252 if (!m_reversePath) { | 252 if (!m_reversePath) { |
253 /*!!! | |
254 if (!m_rawPath) { | |
255 std::cerr << "ERROR: AlignmentModel::constructReversePath: " | |
256 << "No raw path available" << std::endl; | |
257 return; | |
258 } | |
259 m_reversePath = new PathModel | |
260 (m_rawPath->getSampleRate(), m_rawPath->getResolution(), false); | |
261 */ | |
262 if (!m_path) { | 253 if (!m_path) { |
263 std::cerr << "ERROR: AlignmentModel::constructReversePath: " | 254 std::cerr << "ERROR: AlignmentModel::constructReversePath: " |
264 << "No forward path available" << std::endl; | 255 << "No forward path available" << std::endl; |
265 return; | 256 return; |
266 } | 257 } |
267 m_reversePath = new PathModel | 258 m_reversePath = new PathModel |
268 (m_path->getSampleRate(), m_path->getResolution(), false); | 259 (m_path->getSampleRate(), m_path->getResolution(), false); |
269 } else { | 260 } else { |
270 /*!!! | |
271 if (!m_rawPath) return; | |
272 */ | |
273 if (!m_path) return; | 261 if (!m_path) return; |
274 } | 262 } |
275 | 263 |
276 m_reversePath->clear(); | 264 m_reversePath->clear(); |
277 /*!!! | |
278 SparseTimeValueModel::PointList points = m_rawPath->getPoints(); | |
279 | |
280 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); | |
281 i != points.end(); ++i) { | |
282 long frame = i->frame; | |
283 float value = i->value; | |
284 long rframe = lrintf(value * m_aligned->getSampleRate()); | |
285 m_reversePath->addPoint(PathPoint(rframe, frame)); | |
286 } | |
287 */ | |
288 | 265 |
289 PathModel::PointList points = m_path->getPoints(); | 266 PathModel::PointList points = m_path->getPoints(); |
290 | 267 |
291 for (PathModel::PointList::const_iterator i = points.begin(); | 268 for (PathModel::PointList::const_iterator i = points.begin(); |
292 i != points.end(); ++i) { | 269 i != points.end(); ++i) { |
294 long rframe = i->mapframe; | 271 long rframe = i->mapframe; |
295 m_reversePath->addPoint(PathPoint(rframe, frame)); | 272 m_reversePath->addPoint(PathPoint(rframe, frame)); |
296 } | 273 } |
297 | 274 |
298 #ifdef DEBUG_ALIGNMENT_MODEL | 275 #ifdef DEBUG_ALIGNMENT_MODEL |
299 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 276 SVDEBUG << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl; |
300 #endif | 277 #endif |
301 } | 278 } |
302 | 279 |
303 size_t | 280 size_t |
304 AlignmentModel::align(PathModel *path, size_t frame) const | 281 AlignmentModel::align(PathModel *path, size_t frame) const |
312 | 289 |
313 const PathModel::PointList &points = path->getPoints(); | 290 const PathModel::PointList &points = path->getPoints(); |
314 | 291 |
315 if (points.empty()) { | 292 if (points.empty()) { |
316 #ifdef DEBUG_ALIGNMENT_MODEL | 293 #ifdef DEBUG_ALIGNMENT_MODEL |
317 std::cerr << "AlignmentModel::align: No points" << std::endl; | 294 SVDEBUG << "AlignmentModel::align: No points" << endl; |
318 #endif | 295 #endif |
319 return frame; | 296 return frame; |
320 } | 297 } |
321 | 298 |
322 #ifdef DEBUG_ALIGNMENT_MODEL | 299 #ifdef DEBUG_ALIGNMENT_MODEL |
323 std::cerr << "AlignmentModel::align: frame " << frame << " requested" << std::endl; | 300 SVDEBUG << "AlignmentModel::align: frame " << frame << " requested" << endl; |
324 #endif | 301 #endif |
325 | 302 |
326 PathModel::Point point(frame); | 303 PathModel::Point point(frame); |
327 PathModel::PointList::const_iterator i = points.lower_bound(point); | 304 PathModel::PointList::const_iterator i = points.lower_bound(point); |
328 if (i == points.end()) { | 305 if (i == points.end()) { |
361 float(followingFrame - foundFrame); | 338 float(followingFrame - foundFrame); |
362 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); | 339 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); |
363 } | 340 } |
364 | 341 |
365 #ifdef DEBUG_ALIGNMENT_MODEL | 342 #ifdef DEBUG_ALIGNMENT_MODEL |
366 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | 343 SVDEBUG << "AlignmentModel::align: resultFrame = " << resultFrame << endl; |
367 #endif | 344 #endif |
368 | 345 |
369 return resultFrame; | 346 return resultFrame; |
370 } | 347 } |
371 | 348 |
373 AlignmentModel::setPath(PathModel *path) | 350 AlignmentModel::setPath(PathModel *path) |
374 { | 351 { |
375 if (m_path) m_path->aboutToDelete(); | 352 if (m_path) m_path->aboutToDelete(); |
376 delete m_path; | 353 delete m_path; |
377 m_path = path; | 354 m_path = path; |
355 #ifdef DEBUG_ALIGNMENT_MODEL | |
356 SVDEBUG << "AlignmentModel::setPath: path = " << m_path << endl; | |
357 #endif | |
378 constructReversePath(); | 358 constructReversePath(); |
359 #ifdef DEBUG_ALIGNMENT_MODEL | |
360 SVDEBUG << "AlignmentModel::setPath: after construction path = " | |
361 << m_path << ", rpath = " << m_reversePath << endl; | |
362 #endif | |
379 } | 363 } |
380 | 364 |
381 void | 365 void |
382 AlignmentModel::toXml(QTextStream &stream, | 366 AlignmentModel::toXml(QTextStream &stream, |
383 QString indent, | 367 QString indent, |
384 QString extraAttributes) const | 368 QString extraAttributes) const |
385 { | 369 { |
386 if (!m_path) { | 370 if (!m_path) { |
387 std::cerr << "AlignmentModel::toXml: no path" << std::endl; | 371 SVDEBUG << "AlignmentModel::toXml: no path" << endl; |
388 return; | 372 return; |
389 } | 373 } |
390 | 374 |
391 m_path->toXml(stream, indent, ""); | 375 m_path->toXml(stream, indent, ""); |
392 | 376 |