Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 357:b92513201610
* better progress reporting in FileSource
* fix set-to-default for audio dials with mappers
author | Chris Cannam |
---|---|
date | Fri, 04 Jan 2008 17:08:10 +0000 |
parents | edda24bb85fc |
children | f1ff248a793e |
comparison
equal
deleted
inserted
replaced
356:ca3b91119482 | 357:b92513201610 |
---|---|
15 */ | 15 */ |
16 | 16 |
17 #ifdef HAVE_MAD | 17 #ifdef HAVE_MAD |
18 | 18 |
19 #include "MP3FileReader.h" | 19 #include "MP3FileReader.h" |
20 #include "ProgressPrinter.h" | |
21 | |
20 #include "system/System.h" | 22 #include "system/System.h" |
21 | 23 |
22 #include <sys/types.h> | 24 #include <sys/types.h> |
23 #include <sys/stat.h> | 25 #include <sys/stat.h> |
24 #include <fcntl.h> | 26 #include <fcntl.h> |
109 if (dynamic_cast<QApplication *>(QCoreApplication::instance())) { | 111 if (dynamic_cast<QApplication *>(QCoreApplication::instance())) { |
110 m_progress = new QProgressDialog | 112 m_progress = new QProgressDialog |
111 (QObject::tr("Decoding %1...").arg(QFileInfo(m_path).fileName()), | 113 (QObject::tr("Decoding %1...").arg(QFileInfo(m_path).fileName()), |
112 QObject::tr("Stop"), 0, 100); | 114 QObject::tr("Stop"), 0, 100); |
113 m_progress->hide(); | 115 m_progress->hide(); |
116 } else { | |
117 ProgressPrinter *pp = new ProgressPrinter(tr("Decoding..."), this); | |
118 connect(this, SIGNAL(progress(int)), pp, SLOT(progress(int))); | |
114 } | 119 } |
115 | 120 |
116 if (!decode(m_filebuffer, m_fileSize)) { | 121 if (!decode(m_filebuffer, m_fileSize)) { |
117 m_error = QString("Failed to decode file %1.").arg(m_path); | 122 m_error = QString("Failed to decode file %1.").arg(m_path); |
118 } | 123 } |
341 m_channelCount = channels; | 346 m_channelCount = channels; |
342 | 347 |
343 initialiseDecodeCache(); | 348 initialiseDecodeCache(); |
344 | 349 |
345 if (m_cacheMode == CacheInTemporaryFile) { | 350 if (m_cacheMode == CacheInTemporaryFile) { |
346 m_completion = 1; | 351 // m_completion = 1; |
347 std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl; | 352 std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl; |
348 startSerialised("MP3FileReader::Decode"); | 353 startSerialised("MP3FileReader::Decode"); |
349 } | 354 } |
350 } | 355 } |
351 | 356 |
352 if (m_bitrateDenom > 0) { | 357 if (m_bitrateDenom > 0) { |
353 double bitrate = m_bitrateNum / m_bitrateDenom; | 358 double bitrate = m_bitrateNum / m_bitrateDenom; |
354 double duration = double(m_fileSize * 8) / bitrate; | 359 double duration = double(m_fileSize * 8) / bitrate; |
355 double elapsed = double(m_frameCount) / m_sampleRate; | 360 double elapsed = double(m_frameCount) / m_sampleRate; |
356 double percent = ((elapsed * 100.0) / duration); | 361 double percent = ((elapsed * 100.0) / duration); |
357 int progress = int(percent); | 362 int p = int(percent); |
358 if (progress < 1) progress = 1; | 363 if (p < 1) p = 1; |
359 if (progress > 99) progress = 99; | 364 if (p > 99) p = 99; |
360 m_completion = progress; | 365 if (m_completion != p || (m_progress && !m_progress->isVisible())) { |
361 if (m_progress) { | 366 m_completion = p; |
362 if (progress > m_progress->value()) { | 367 emit progress(m_completion); |
363 m_progress->setValue(progress); | 368 if (m_progress) { |
364 m_progress->show(); | 369 if (m_completion > m_progress->value()) { |
365 m_progress->raise(); | 370 m_progress->setValue(m_completion); |
366 qApp->processEvents(); | 371 m_progress->show(); |
367 if (m_progress->wasCanceled()) { | 372 m_progress->raise(); |
368 m_cancelled = true; | 373 qApp->processEvents(); |
374 if (m_progress->wasCanceled()) { | |
375 m_cancelled = true; | |
376 } | |
369 } | 377 } |
370 } | 378 } |
371 } | 379 } |
372 } | 380 } |
373 | 381 |