Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 383:94fc0591ea43 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | f39d33b0b265 |
children |
comparison
equal
deleted
inserted
replaced
349:f39d33b0b265 | 383:94fc0591ea43 |
---|---|
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 } |
128 } else { | 133 } else { |
129 | 134 |
130 m_decodeThread = new DecodeThread(this); | 135 m_decodeThread = new DecodeThread(this); |
131 m_decodeThread->start(); | 136 m_decodeThread->start(); |
132 | 137 |
133 while (m_channelCount == 0 && !m_done) { | 138 while ((m_channelCount == 0 || m_fileRate == 0) && !m_done) { |
134 usleep(10); | 139 usleep(10); |
135 } | 140 } |
136 } | 141 } |
137 } | 142 } |
138 | 143 |
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 = 100; |
357 int progress = int(percent); | 362 if (duration > 0.0) percent = ((elapsed * 100.0) / duration); |
358 if (progress < 1) progress = 1; | 363 int p = int(percent); |
359 if (progress > 99) progress = 99; | 364 if (p < 1) p = 1; |
360 m_completion = progress; | 365 if (p > 99) p = 99; |
361 if (m_progress) { | 366 if (m_completion != p || (m_progress && !m_progress->isVisible())) { |
362 if (progress > m_progress->value()) { | 367 m_completion = p; |
363 m_progress->setValue(progress); | 368 emit progress(m_completion); |
364 m_progress->show(); | 369 if (m_progress) { |
365 m_progress->raise(); | 370 if (m_completion > m_progress->value()) { |
366 qApp->processEvents(); | 371 m_progress->setValue(m_completion); |
367 if (m_progress->wasCanceled()) { | 372 m_progress->show(); |
368 m_cancelled = true; | 373 m_progress->raise(); |
374 qApp->processEvents(); | |
375 if (m_progress->wasCanceled()) { | |
376 m_cancelled = true; | |
377 } | |
369 } | 378 } |
370 } | 379 } |
371 } | 380 } |
372 } | 381 } |
373 | 382 |