comparison data/fileio/ResamplingWavFileReader.cpp @ 392:183ee2a55fc7

* More work to abstract out interactive components used in the data library, so that it does not need to depend on QtGui.
author Chris Cannam
date Fri, 14 Mar 2008 17:14:21 +0000
parents 1d656dcda8ef
children be49bf95d4a5
comparison
equal deleted inserted replaced
391:5858cc462d0a 392:183ee2a55fc7
15 15
16 #include "ResamplingWavFileReader.h" 16 #include "ResamplingWavFileReader.h"
17 17
18 #include "WavFileReader.h" 18 #include "WavFileReader.h"
19 #include "base/Profiler.h" 19 #include "base/Profiler.h"
20 #include "base/ProgressReporter.h"
20 21
21 #include <QProgressDialog>
22 #include <QFileInfo> 22 #include <QFileInfo>
23 #include <QApplication>
24 23
25 ResamplingWavFileReader::ResamplingWavFileReader(FileSource source, 24 ResamplingWavFileReader::ResamplingWavFileReader(FileSource source,
26 ResampleMode resampleMode, 25 ResampleMode resampleMode,
27 CacheMode mode, 26 CacheMode mode,
28 size_t targetRate) : 27 size_t targetRate,
28 ProgressReporter *reporter) :
29 CodedAudioFileReader(mode, targetRate), 29 CodedAudioFileReader(mode, targetRate),
30 m_source(source), 30 m_source(source),
31 m_path(source.getLocalFilename()), 31 m_path(source.getLocalFilename()),
32 m_cancelled(false), 32 m_cancelled(false),
33 m_processed(0), 33 m_processed(0),
34 m_completion(0), 34 m_completion(0),
35 m_original(0), 35 m_original(0),
36 m_progress(0), 36 m_reporter(reporter),
37 m_decodeThread(0) 37 m_decodeThread(0)
38 { 38 {
39 m_channelCount = 0; 39 m_channelCount = 0;
40 m_fileRate = 0; 40 m_fileRate = 0;
41 41
55 55
56 initialiseDecodeCache(); 56 initialiseDecodeCache();
57 57
58 if (resampleMode == ResampleAtOnce) { 58 if (resampleMode == ResampleAtOnce) {
59 59
60 if (dynamic_cast<QApplication *>(QCoreApplication::instance())) { 60 if (m_reporter) {
61 m_progress = new QProgressDialog 61 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled()));
62 (QObject::tr("Resampling %1...").arg(QFileInfo(m_path).fileName()), 62 m_reporter->setMessage
63 QObject::tr("Stop"), 0, 100); 63 (tr("Resampling %1...").arg(QFileInfo(m_path).fileName()));
64 m_progress->hide();
65 } 64 }
66 65
67 size_t blockSize = 16384; 66 size_t blockSize = 16384;
68 size_t total = m_original->getFrameCount(); 67 size_t total = m_original->getFrameCount();
69 68
83 if (isDecodeCacheInitialised()) finishDecodeCache(); 82 if (isDecodeCacheInitialised()) finishDecodeCache();
84 83
85 delete m_original; 84 delete m_original;
86 m_original = 0; 85 m_original = 0;
87 86
88 delete m_progress; 87 } else {
89 m_progress = 0;
90 88
91 } else { 89 if (m_reporter) m_reporter->setProgress(100);
92 90
93 m_decodeThread = new DecodeThread(this); 91 m_decodeThread = new DecodeThread(this);
94 m_decodeThread->start(); 92 m_decodeThread->start();
95 } 93 }
96 } 94 }
102 m_decodeThread->wait(); 100 m_decodeThread->wait();
103 delete m_decodeThread; 101 delete m_decodeThread;
104 } 102 }
105 103
106 delete m_original; 104 delete m_original;
105 }
106
107 void
108 ResamplingWavFileReader::cancelled()
109 {
110 m_cancelled = true;
107 } 111 }
108 112
109 void 113 void
110 ResamplingWavFileReader::DecodeThread::run() 114 ResamplingWavFileReader::DecodeThread::run()
111 { 115 {
149 float(m_original->getFrameCount())); 153 float(m_original->getFrameCount()));
150 154
151 if (progress > 99) progress = 99; 155 if (progress > 99) progress = 99;
152 m_completion = progress; 156 m_completion = progress;
153 157
154 if (m_progress) { 158 if (m_reporter) {
155 if (progress > m_progress->value()) { 159 m_reporter->setProgress(progress);
156 m_progress->setValue(progress);
157 m_progress->show();
158 m_progress->raise();
159 qApp->processEvents();
160 if (m_progress->wasCanceled()) {
161 m_cancelled = true;
162 }
163 }
164 } 160 }
165 } 161 }
166 162
167 void 163 void
168 ResamplingWavFileReader::getSupportedExtensions(std::set<QString> &extensions) 164 ResamplingWavFileReader::getSupportedExtensions(std::set<QString> &extensions)