Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 188:f86b74d1b143
* Simplify maker names in plugin menu
* Make sure derived models have a name (based on the transform)
* Don't start deriving a model from a derived model until the derived model is
ready
* Tidy up completion management in writable wave file model
* Make writable models save/reload correctly from session file (i.e.
regenerating from the original transform)
* Same for dense 3d models -- don't save the data, just the transform details
* Add a comment describing the SV file format
author | Chris Cannam |
---|---|
date | Fri, 13 Oct 2006 12:51:05 +0000 |
parents | 89b05b679dc3 |
children | bf1f256864de |
comparison
equal
deleted
inserted
replaced
187:89b05b679dc3 | 188:f86b74d1b143 |
---|---|
80 WaveFileModel::isReady(int *completion) const | 80 WaveFileModel::isReady(int *completion) const |
81 { | 81 { |
82 bool ready = (isOK() && (m_fillThread == 0)); | 82 bool ready = (isOK() && (m_fillThread == 0)); |
83 double c = double(m_lastFillExtent) / double(getEndFrame() - getStartFrame()); | 83 double c = double(m_lastFillExtent) / double(getEndFrame() - getStartFrame()); |
84 if (completion) *completion = int(c * 100.0 + 0.01); | 84 if (completion) *completion = int(c * 100.0 + 0.01); |
85 std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; | 85 // std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; |
86 return ready; | 86 return ready; |
87 } | 87 } |
88 | 88 |
89 Model * | 89 Model * |
90 WaveFileModel::clone() const | 90 WaveFileModel::clone() const |
369 | 369 |
370 void | 370 void |
371 WaveFileModel::fillCache() | 371 WaveFileModel::fillCache() |
372 { | 372 { |
373 m_mutex.lock(); | 373 m_mutex.lock(); |
374 | |
374 m_updateTimer = new QTimer(this); | 375 m_updateTimer = new QTimer(this); |
375 connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(fillTimerTimedOut())); | 376 connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(fillTimerTimedOut())); |
376 m_updateTimer->start(100); | 377 m_updateTimer->start(100); |
378 | |
377 m_fillThread = new RangeCacheFillThread(*this); | 379 m_fillThread = new RangeCacheFillThread(*this); |
378 connect(m_fillThread, SIGNAL(finished()), this, SLOT(cacheFilled())); | 380 connect(m_fillThread, SIGNAL(finished()), this, SLOT(cacheFilled())); |
381 | |
379 m_mutex.unlock(); | 382 m_mutex.unlock(); |
380 m_fillThread->start(); | 383 m_fillThread->start(); |
381 std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; | 384 |
385 // std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; | |
382 } | 386 } |
383 | 387 |
384 void | 388 void |
385 WaveFileModel::fillTimerTimedOut() | 389 WaveFileModel::fillTimerTimedOut() |
386 { | 390 { |
387 if (m_fillThread) { | 391 if (m_fillThread) { |
388 size_t fillExtent = m_fillThread->getFillExtent(); | 392 size_t fillExtent = m_fillThread->getFillExtent(); |
389 cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; | 393 // cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; |
390 if (fillExtent > m_lastFillExtent) { | 394 if (fillExtent > m_lastFillExtent) { |
391 emit modelChanged(m_lastFillExtent, fillExtent); | 395 emit modelChanged(m_lastFillExtent, fillExtent); |
392 m_lastFillExtent = fillExtent; | 396 m_lastFillExtent = fillExtent; |
393 } | 397 } |
394 } else { | 398 } else { |
395 cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; | 399 // cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; |
396 emit modelChanged(); | 400 emit modelChanged(); |
397 } | 401 } |
398 } | 402 } |
399 | 403 |
400 void | 404 void |
405 m_fillThread = 0; | 409 m_fillThread = 0; |
406 delete m_updateTimer; | 410 delete m_updateTimer; |
407 m_updateTimer = 0; | 411 m_updateTimer = 0; |
408 m_mutex.unlock(); | 412 m_mutex.unlock(); |
409 emit modelChanged(); | 413 emit modelChanged(); |
410 cerr << "WaveFileModel::cacheFilled" << endl; | 414 // cerr << "WaveFileModel::cacheFilled" << endl; |
411 } | 415 } |
412 | 416 |
413 void | 417 void |
414 WaveFileModel::RangeCacheFillThread::run() | 418 WaveFileModel::RangeCacheFillThread::run() |
415 { | 419 { |
427 size_t channels = m_model.getChannelCount(); | 431 size_t channels = m_model.getChannelCount(); |
428 bool updating = m_model.m_reader->isUpdating(); | 432 bool updating = m_model.m_reader->isUpdating(); |
429 | 433 |
430 if (updating) { | 434 if (updating) { |
431 while (channels == 0 && !m_model.m_exiting) { | 435 while (channels == 0 && !m_model.m_exiting) { |
432 std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl; | 436 // std::cerr << "WaveFileModel::fill: Waiting for channels..." << std::endl; |
433 sleep(1); | 437 sleep(1); |
434 channels = m_model.getChannelCount(); | 438 channels = m_model.getChannelCount(); |
435 } | 439 } |
436 } | 440 } |
437 | 441 |
444 while (first || updating) { | 448 while (first || updating) { |
445 | 449 |
446 updating = m_model.m_reader->isUpdating(); | 450 updating = m_model.m_reader->isUpdating(); |
447 m_frameCount = m_model.getFrameCount(); | 451 m_frameCount = m_model.getFrameCount(); |
448 | 452 |
449 std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; | 453 // std::cerr << "WaveFileModel::fill: frame = " << frame << ", count = " << m_frameCount << std::endl; |
450 | 454 |
451 while (frame < m_frameCount) { | 455 while (frame < m_frameCount) { |
452 | 456 |
453 if (updating && (frame + readBlockSize > m_frameCount)) break; | 457 if (updating && (frame + readBlockSize > m_frameCount)) break; |
454 | 458 |
525 | 529 |
526 delete[] range; | 530 delete[] range; |
527 | 531 |
528 m_fillExtent = m_frameCount; | 532 m_fillExtent = m_frameCount; |
529 | 533 |
530 for (size_t ct = 0; ct < 2; ++ct) { | 534 // for (size_t ct = 0; ct < 2; ++ct) { |
531 cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; | 535 // cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; |
532 } | 536 // } |
533 } | 537 } |
534 | 538 |
535 void | 539 void |
536 WaveFileModel::toXml(QTextStream &out, | 540 WaveFileModel::toXml(QTextStream &out, |
537 QString indent, | 541 QString indent, |