comparison data/model/WritableWaveFileModel.cpp @ 300:5877d68815c7

* Change WaveFileModel API from getValues(start,end) to getData(start,count). It's much less error-prone to pass in frame counts instead of start/end locations. Should have done this ages ago. This closes #1794563. * Add option to apply a transform to only the selection region, instead of the whole audio. * (to make the above work properly) Add start frame offset to wave models
author Chris Cannam
date Mon, 01 Oct 2007 13:48:38 +0000
parents 92e8dbde73cd
children 70a232b1f12a
comparison
equal deleted inserted replaced
299:576be0d0d218 300:5877d68815c7
35 m_writer(0), 35 m_writer(0),
36 m_reader(0), 36 m_reader(0),
37 m_sampleRate(sampleRate), 37 m_sampleRate(sampleRate),
38 m_channels(channels), 38 m_channels(channels),
39 m_frameCount(0), 39 m_frameCount(0),
40 m_startFrame(0),
40 m_completion(0) 41 m_completion(0)
41 { 42 {
42 if (path.isEmpty()) { 43 if (path.isEmpty()) {
43 try { 44 try {
44 QDir dir(TempDirectory::getInstance()->getPath()); 45 QDir dir(TempDirectory::getInstance()->getPath());
73 m_model = 0; 74 m_model = 0;
74 delete m_reader; 75 delete m_reader;
75 m_reader = 0; 76 m_reader = 0;
76 return; 77 return;
77 } 78 }
79 m_model->setStartFrame(m_startFrame);
78 80
79 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); 81 connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
80 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), 82 connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
81 this, SIGNAL(modelChanged(size_t, size_t))); 83 this, SIGNAL(modelChanged(size_t, size_t)));
82 } 84 }
84 WritableWaveFileModel::~WritableWaveFileModel() 86 WritableWaveFileModel::~WritableWaveFileModel()
85 { 87 {
86 delete m_model; 88 delete m_model;
87 delete m_writer; 89 delete m_writer;
88 delete m_reader; 90 delete m_reader;
91 }
92
93 void
94 WritableWaveFileModel::setStartFrame(size_t startFrame)
95 {
96 m_startFrame = startFrame;
97 if (m_model) m_model->setStartFrame(startFrame);
89 } 98 }
90 99
91 bool 100 bool
92 WritableWaveFileModel::addSamples(float **samples, size_t count) 101 WritableWaveFileModel::addSamples(float **samples, size_t count)
93 { 102 {
159 assert(0); //!!! 168 assert(0); //!!!
160 return 0; 169 return 0;
161 } 170 }
162 171
163 size_t 172 size_t
164 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, 173 WritableWaveFileModel::getData(int channel, size_t start, size_t count,
165 float *buffer) const 174 float *buffer) const
166 { 175 {
167 if (!m_model || m_model->getChannelCount() == 0) return 0; 176 if (!m_model || m_model->getChannelCount() == 0) return 0;
168 return m_model->getValues(channel, start, end, buffer); 177 return m_model->getData(channel, start, count, buffer);
169 } 178 }
170 179
171 size_t 180 size_t
172 WritableWaveFileModel::getValues(int channel, size_t start, size_t end, 181 WritableWaveFileModel::getData(int channel, size_t start, size_t count,
173 double *buffer) const 182 double *buffer) const
174 { 183 {
175 if (!m_model || m_model->getChannelCount() == 0) return 0; 184 if (!m_model || m_model->getChannelCount() == 0) return 0;
176 // std::cerr << "WritableWaveFileModel::getValues(" << channel << ", " 185 // std::cerr << "WritableWaveFileModel::getValues(" << channel << ", "
177 // << start << ", " << end << "): calling model" << std::endl; 186 // << start << ", " << end << "): calling model" << std::endl;
178 return m_model->getValues(channel, start, end, buffer); 187 return m_model->getData(channel, start, count, buffer);
179 } 188 }
180 189
181 void 190 void
182 WritableWaveFileModel::getRanges(size_t channel, size_t start, size_t end, 191 WritableWaveFileModel::getSummaries(size_t channel, size_t start, size_t count,
183 RangeBlock &ranges, 192 RangeBlock &ranges,
184 size_t &blockSize) const 193 size_t &blockSize) const
185 { 194 {
186 ranges.clear(); 195 ranges.clear();
187 if (!m_model || m_model->getChannelCount() == 0) return; 196 if (!m_model || m_model->getChannelCount() == 0) return;
188 m_model->getRanges(channel, start, end, ranges, blockSize); 197 m_model->getSummaries(channel, start, count, ranges, blockSize);
189 } 198 }
190 199
191 WritableWaveFileModel::Range 200 WritableWaveFileModel::Range
192 WritableWaveFileModel::getRange(size_t channel, size_t start, size_t end) const 201 WritableWaveFileModel::getSummary(size_t channel, size_t start, size_t count) const
193 { 202 {
194 if (!m_model || m_model->getChannelCount() == 0) return Range(); 203 if (!m_model || m_model->getChannelCount() == 0) return Range();
195 return m_model->getRange(channel, start, end); 204 return m_model->getSummary(channel, start, count);
196 } 205 }
197 206
198 void 207 void
199 WritableWaveFileModel::toXml(QTextStream &out, 208 WritableWaveFileModel::toXml(QTextStream &out,
200 QString indent, 209 QString indent,