Mercurial > hg > svcore
comparison data/model/WaveFileModel.cpp @ 236:3e6fee4e4257
* remove some debug and some obsolete moc file includes
author | Chris Cannam |
---|---|
date | Mon, 26 Feb 2007 14:55:08 +0000 |
parents | 03a24547cf3c |
children | 96a6dd889c68 |
comparison
equal
deleted
inserted
replaced
235:84ff7ba52993 | 236:3e6fee4e4257 |
---|---|
28 #include <math.h> | 28 #include <math.h> |
29 #include <sndfile.h> | 29 #include <sndfile.h> |
30 | 30 |
31 #include <cassert> | 31 #include <cassert> |
32 | 32 |
33 //#define DEBUG_WAVE_FILE_MODEL 1 | |
34 | |
33 using std::cerr; | 35 using std::cerr; |
34 using std::endl; | 36 using std::endl; |
35 | 37 |
36 PowerOfSqrtTwoZoomConstraint | 38 PowerOfSqrtTwoZoomConstraint |
37 WaveFileModel::m_zoomConstraint; | 39 WaveFileModel::m_zoomConstraint; |
93 WaveFileModel::isReady(int *completion) const | 95 WaveFileModel::isReady(int *completion) const |
94 { | 96 { |
95 bool ready = (isOK() && (m_fillThread == 0)); | 97 bool ready = (isOK() && (m_fillThread == 0)); |
96 double c = double(m_lastFillExtent) / double(getEndFrame() - getStartFrame()); | 98 double c = double(m_lastFillExtent) / double(getEndFrame() - getStartFrame()); |
97 if (completion) *completion = int(c * 100.0 + 0.01); | 99 if (completion) *completion = int(c * 100.0 + 0.01); |
98 // std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; | 100 #ifdef DEBUG_WAVE_FILE_MODEL |
101 std::cerr << "WaveFileModel::isReady(): ready = " << ready << ", completion = " << (completion ? *completion : -1) << std::endl; | |
102 #endif | |
99 return ready; | 103 return ready; |
100 } | 104 } |
101 | 105 |
102 Model * | 106 Model * |
103 WaveFileModel::clone() const | 107 WaveFileModel::clone() const |
141 assert(end >= start); | 145 assert(end >= start); |
142 } | 146 } |
143 | 147 |
144 if (!m_reader || !m_reader->isOK()) return 0; | 148 if (!m_reader || !m_reader->isOK()) return 0; |
145 | 149 |
146 // std::cerr << "WaveFileModel::getValues(" << channel << ", " | 150 #ifdef DEBUG_WAVE_FILE_MODEL |
147 // << start << ", " << end << "): calling reader" << std::endl; | 151 std::cerr << "WaveFileModel::getValues(" << channel << ", " |
152 << start << ", " << end << "): calling reader" << std::endl; | |
153 #endif | |
148 | 154 |
149 SampleBlock frames; | 155 SampleBlock frames; |
150 m_reader->getInterleavedFrames(start, end - start, frames); | 156 m_reader->getInterleavedFrames(start, end - start, frames); |
151 | 157 |
152 size_t i = 0; | 158 size_t i = 0; |
298 size_t endIndex = end / cacheBlock; | 304 size_t endIndex = end / cacheBlock; |
299 | 305 |
300 float max = 0.0, min = 0.0, total = 0.0; | 306 float max = 0.0, min = 0.0, total = 0.0; |
301 size_t i = 0, count = 0; | 307 size_t i = 0, count = 0; |
302 | 308 |
309 #ifdef DEBUG_WAVE_FILE_MODEL | |
303 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", end " << end << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; | 310 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", end " << end << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; |
311 #endif | |
304 | 312 |
305 for (i = 0; i < endIndex - startIndex; ) { | 313 for (i = 0; i < endIndex - startIndex; ) { |
306 | 314 |
307 size_t index = (i + startIndex) * channels + channel; | 315 size_t index = (i + startIndex) * channels + channel; |
308 if (index >= cache.size()) break; | 316 if (index >= cache.size()) break; |
325 if (count > 0) { | 333 if (count > 0) { |
326 ranges.push_back(Range(min, max, total / count)); | 334 ranges.push_back(Range(min, max, total / count)); |
327 } | 335 } |
328 } | 336 } |
329 | 337 |
338 #ifdef DEBUG_WAVE_FILE_MODEL | |
330 cerr << "returning " << ranges.size() << " ranges" << endl; | 339 cerr << "returning " << ranges.size() << " ranges" << endl; |
340 #endif | |
331 return; | 341 return; |
332 } | 342 } |
333 | 343 |
334 WaveFileModel::Range | 344 WaveFileModel::Range |
335 WaveFileModel::getRange(size_t channel, size_t start, size_t end) const | 345 WaveFileModel::getRange(size_t channel, size_t start, size_t end) const |
394 connect(m_fillThread, SIGNAL(finished()), this, SLOT(cacheFilled())); | 404 connect(m_fillThread, SIGNAL(finished()), this, SLOT(cacheFilled())); |
395 | 405 |
396 m_mutex.unlock(); | 406 m_mutex.unlock(); |
397 m_fillThread->start(); | 407 m_fillThread->start(); |
398 | 408 |
399 // std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; | 409 #ifdef DEBUG_WAVE_FILE_MODEL |
410 std::cerr << "WaveFileModel::fillCache: started fill thread" << std::endl; | |
411 #endif | |
400 } | 412 } |
401 | 413 |
402 void | 414 void |
403 WaveFileModel::fillTimerTimedOut() | 415 WaveFileModel::fillTimerTimedOut() |
404 { | 416 { |
405 if (m_fillThread) { | 417 if (m_fillThread) { |
406 size_t fillExtent = m_fillThread->getFillExtent(); | 418 size_t fillExtent = m_fillThread->getFillExtent(); |
407 // cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; | 419 #ifdef DEBUG_WAVE_FILE_MODEL |
420 cerr << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; | |
421 #endif | |
408 if (fillExtent > m_lastFillExtent) { | 422 if (fillExtent > m_lastFillExtent) { |
409 emit modelChanged(m_lastFillExtent, fillExtent); | 423 emit modelChanged(m_lastFillExtent, fillExtent); |
410 m_lastFillExtent = fillExtent; | 424 m_lastFillExtent = fillExtent; |
411 } | 425 } |
412 } else { | 426 } else { |
413 // cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; | 427 #ifdef DEBUG_WAVE_FILE_MODEL |
428 cerr << "WaveFileModel::fillTimerTimedOut: no thread" << std::endl; | |
429 #endif | |
414 emit modelChanged(); | 430 emit modelChanged(); |
415 } | 431 } |
416 } | 432 } |
417 | 433 |
418 void | 434 void |
423 m_fillThread = 0; | 439 m_fillThread = 0; |
424 delete m_updateTimer; | 440 delete m_updateTimer; |
425 m_updateTimer = 0; | 441 m_updateTimer = 0; |
426 m_mutex.unlock(); | 442 m_mutex.unlock(); |
427 emit modelChanged(); | 443 emit modelChanged(); |
428 // cerr << "WaveFileModel::cacheFilled" << endl; | 444 #ifdef DEBUG_WAVE_FILE_MODEL |
445 cerr << "WaveFileModel::cacheFilled" << endl; | |
446 #endif | |
429 } | 447 } |
430 | 448 |
431 void | 449 void |
432 WaveFileModel::RangeCacheFillThread::run() | 450 WaveFileModel::RangeCacheFillThread::run() |
433 { | 451 { |
551 } | 569 } |
552 | 570 |
553 delete[] range; | 571 delete[] range; |
554 | 572 |
555 m_fillExtent = m_frameCount; | 573 m_fillExtent = m_frameCount; |
556 | 574 |
557 // for (size_t ct = 0; ct < 2; ++ct) { | 575 #ifdef DEBUG_WAVE_FILE_MODEL |
558 // cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; | 576 for (size_t ct = 0; ct < 2; ++ct) { |
559 // } | 577 cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl; |
578 } | |
579 #endif | |
560 } | 580 } |
561 | 581 |
562 void | 582 void |
563 WaveFileModel::toXml(QTextStream &out, | 583 WaveFileModel::toXml(QTextStream &out, |
564 QString indent, | 584 QString indent, |
576 return Model::toXmlString(indent, | 596 return Model::toXmlString(indent, |
577 QString("type=\"wavefile\" file=\"%1\" %2") | 597 QString("type=\"wavefile\" file=\"%1\" %2") |
578 .arg(m_path).arg(extraAttributes)); | 598 .arg(m_path).arg(extraAttributes)); |
579 } | 599 } |
580 | 600 |
581 | |
582 #ifdef INCLUDE_MOCFILES | |
583 #ifdef INCLUDE_MOCFILES | |
584 #include "WaveFileModel.moc.cpp" | |
585 #endif | |
586 #endif | |
587 |