Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 187:89b05b679dc3
* Fixes to update logic in writable wave file model
author | Chris Cannam |
---|---|
date | Thu, 12 Oct 2006 16:10:49 +0000 |
parents | bd1260261412 |
children | f86b74d1b143 |
comparison
equal
deleted
inserted
replaced
186:06ad01f3e553 | 187:89b05b679dc3 |
---|---|
43 m_updateTimer(0), | 43 m_updateTimer(0), |
44 m_lastFillExtent(0), | 44 m_lastFillExtent(0), |
45 m_exiting(false) | 45 m_exiting(false) |
46 { | 46 { |
47 m_reader = AudioFileReaderFactory::createReader(path); | 47 m_reader = AudioFileReaderFactory::createReader(path); |
48 connect(m_reader, SIGNAL(frameCountChanged()), | |
49 this, SLOT(frameCountChanged())); | |
50 setObjectName(QFileInfo(path).fileName()); | 48 setObjectName(QFileInfo(path).fileName()); |
51 if (isOK()) fillCache(); | 49 if (isOK()) fillCache(); |
52 } | 50 } |
53 | 51 |
54 WaveFileModel::WaveFileModel(QString path, AudioFileReader *reader) : | 52 WaveFileModel::WaveFileModel(QString path, AudioFileReader *reader) : |
58 m_updateTimer(0), | 56 m_updateTimer(0), |
59 m_lastFillExtent(0), | 57 m_lastFillExtent(0), |
60 m_exiting(false) | 58 m_exiting(false) |
61 { | 59 { |
62 m_reader = reader; | 60 m_reader = reader; |
63 connect(m_reader, SIGNAL(frameCountChanged()), | |
64 this, SLOT(frameCountChanged())); | |
65 setObjectName(QFileInfo(path).fileName()); | 61 setObjectName(QFileInfo(path).fileName()); |
66 if (isOK()) { | 62 fillCache(); |
67 std::cerr << "OK; filling cache" << std::endl; | |
68 fillCache(); | |
69 } | |
70 } | 63 } |
71 | 64 |
72 WaveFileModel::~WaveFileModel() | 65 WaveFileModel::~WaveFileModel() |
73 { | 66 { |
74 m_exiting = true; | 67 m_exiting = true; |
387 m_fillThread->start(); | 380 m_fillThread->start(); |
388 std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; | 381 std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; |
389 } | 382 } |
390 | 383 |
391 void | 384 void |
392 WaveFileModel::frameCountChanged() | |
393 { | |
394 m_mutex.lock(); | |
395 if (m_updateTimer) { | |
396 std::cerr << "WaveFileModel::frameCountChanged: updating existing fill thread" << std::endl; | |
397 m_fillThread->frameCountChanged(); | |
398 m_mutex.unlock(); | |
399 } else { | |
400 std::cerr << "WaveFileModel::frameCountChanged: restarting [inefficient]" << std::endl; | |
401 m_cache[0].clear(); | |
402 m_cache[1].clear(); | |
403 m_mutex.unlock(); | |
404 fillCache(); | |
405 } | |
406 } | |
407 | |
408 void | |
409 WaveFileModel::fillTimerTimedOut() | 385 WaveFileModel::fillTimerTimedOut() |
410 { | 386 { |
411 if (m_fillThread) { | 387 if (m_fillThread) { |
412 size_t fillExtent = m_fillThread->getFillExtent(); | 388 size_t fillExtent = m_fillThread->getFillExtent(); |
413 cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; | 389 cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; |
433 emit modelChanged(); | 409 emit modelChanged(); |
434 cerr << "WaveFileModel::cacheFilled" << endl; | 410 cerr << "WaveFileModel::cacheFilled" << endl; |
435 } | 411 } |
436 | 412 |
437 void | 413 void |
438 WaveFileModel::RangeCacheFillThread::frameCountChanged() | |
439 { | |
440 m_frameCount = m_model.getFrameCount(); | |
441 std::cerr << "WaveFileModel::RangeCacheFillThread::frameCountChanged: now " | |
442 << m_frameCount << std::endl; | |
443 } | |
444 | |
445 void | |
446 WaveFileModel::RangeCacheFillThread::run() | 414 WaveFileModel::RangeCacheFillThread::run() |
447 { | 415 { |
448 size_t cacheBlockSize[2]; | 416 size_t cacheBlockSize[2]; |
449 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); | 417 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); |
450 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * | 418 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * |
455 SampleBlock block; | 423 SampleBlock block; |
456 | 424 |
457 if (!m_model.isOK()) return; | 425 if (!m_model.isOK()) return; |
458 | 426 |
459 size_t channels = m_model.getChannelCount(); | 427 size_t channels = m_model.getChannelCount(); |
428 bool updating = m_model.m_reader->isUpdating(); | |
429 | |
430 if (updating) { | |
431 while (channels == 0 && !m_model.m_exiting) { | |
432 std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl; | |
433 sleep(1); | |
434 channels = m_model.getChannelCount(); | |
435 } | |
436 } | |
460 | 437 |
461 Range *range = new Range[2 * channels]; | 438 Range *range = new Range[2 * channels]; |
462 size_t count[2]; | 439 size_t count[2]; |
463 count[0] = count[1] = 0; | 440 count[0] = count[1] = 0; |
464 | 441 |
465 bool first = true; | 442 bool first = true; |
466 bool updating = m_model.m_reader->isUpdating(); | |
467 | 443 |
468 while (first || updating) { | 444 while (first || updating) { |
469 | 445 |
470 updating = m_model.m_reader->isUpdating(); | 446 updating = m_model.m_reader->isUpdating(); |
447 m_frameCount = m_model.getFrameCount(); | |
471 | 448 |
472 std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; | 449 std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; |
473 | 450 |
474 while (frame < m_frameCount) { | 451 while (frame < m_frameCount) { |
475 | 452 |
520 m_fillExtent = frame; | 497 m_fillExtent = frame; |
521 } | 498 } |
522 | 499 |
523 first = false; | 500 first = false; |
524 if (m_model.m_exiting) break; | 501 if (m_model.m_exiting) break; |
525 if (updating) sleep(1); | 502 if (updating) { |
503 sleep(1); | |
504 } | |
526 } | 505 } |
527 | 506 |
528 if (!m_model.m_exiting) { | 507 if (!m_model.m_exiting) { |
529 | 508 |
530 QMutexLocker locker(&m_model.m_mutex); | 509 QMutexLocker locker(&m_model.m_mutex); |