Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 407:88ad01799040
* Save alignments to session file. Needs much testing.
author | Chris Cannam |
---|---|
date | Tue, 29 Apr 2008 15:34:17 +0000 |
parents | 62789d79b98f |
children | 115f60df1e4d |
comparison
equal
deleted
inserted
replaced
406:d095214ffbaf | 407:88ad01799040 |
---|---|
40 connect(m_rawPath, SIGNAL(modelChanged(size_t, size_t)), | 40 connect(m_rawPath, SIGNAL(modelChanged(size_t, size_t)), |
41 this, SLOT(pathChanged(size_t, size_t))); | 41 this, SLOT(pathChanged(size_t, size_t))); |
42 | 42 |
43 connect(m_rawPath, SIGNAL(completionChanged()), | 43 connect(m_rawPath, SIGNAL(completionChanged()), |
44 this, SLOT(pathCompletionChanged())); | 44 this, SLOT(pathCompletionChanged())); |
45 } | 45 |
46 | 46 constructPath(); |
47 constructPath(); | 47 constructReversePath(); |
48 constructReversePath(); | 48 } |
49 | |
50 if (m_rawPath && m_rawPath->isReady()) { | |
51 pathCompletionChanged(); | |
52 } | |
49 } | 53 } |
50 | 54 |
51 AlignmentModel::~AlignmentModel() | 55 AlignmentModel::~AlignmentModel() |
52 { | 56 { |
57 if (m_inputModel) m_inputModel->aboutToDelete(); | |
53 delete m_inputModel; | 58 delete m_inputModel; |
59 | |
60 if (m_rawPath) m_rawPath->aboutToDelete(); | |
54 delete m_rawPath; | 61 delete m_rawPath; |
62 | |
63 if (m_path) m_path->aboutToDelete(); | |
55 delete m_path; | 64 delete m_path; |
65 | |
66 if (m_reversePath) m_reversePath->aboutToDelete(); | |
56 delete m_reversePath; | 67 delete m_reversePath; |
57 } | 68 } |
58 | 69 |
59 bool | 70 bool |
60 AlignmentModel::isOK() const | 71 AlignmentModel::isOK() const |
155 void | 166 void |
156 AlignmentModel::pathChanged() | 167 AlignmentModel::pathChanged() |
157 { | 168 { |
158 if (m_pathComplete) { | 169 if (m_pathComplete) { |
159 std::cerr << "AlignmentModel: deleting raw path model" << std::endl; | 170 std::cerr << "AlignmentModel: deleting raw path model" << std::endl; |
171 if (m_rawPath) m_rawPath->aboutToDelete(); | |
160 delete m_rawPath; | 172 delete m_rawPath; |
161 m_rawPath = 0; | 173 m_rawPath = 0; |
162 } | 174 } |
163 } | 175 } |
164 | 176 |
190 | 202 |
191 if (m_pathComplete) { | 203 if (m_pathComplete) { |
192 | 204 |
193 constructPath(); | 205 constructPath(); |
194 constructReversePath(); | 206 constructReversePath(); |
195 | 207 |
208 if (m_inputModel) m_inputModel->aboutToDelete(); | |
196 delete m_inputModel; | 209 delete m_inputModel; |
197 m_inputModel = 0; | 210 m_inputModel = 0; |
198 } | 211 } |
199 } | 212 } |
200 | 213 |
235 | 248 |
236 void | 249 void |
237 AlignmentModel::constructReversePath() const | 250 AlignmentModel::constructReversePath() const |
238 { | 251 { |
239 if (!m_reversePath) { | 252 if (!m_reversePath) { |
253 /*!!! | |
240 if (!m_rawPath) { | 254 if (!m_rawPath) { |
241 std::cerr << "ERROR: AlignmentModel::constructReversePath: " | 255 std::cerr << "ERROR: AlignmentModel::constructReversePath: " |
242 << "No raw path available" << std::endl; | 256 << "No raw path available" << std::endl; |
243 return; | 257 return; |
244 } | 258 } |
245 m_reversePath = new PathModel | 259 m_reversePath = new PathModel |
246 (m_rawPath->getSampleRate(), m_rawPath->getResolution(), false); | 260 (m_rawPath->getSampleRate(), m_rawPath->getResolution(), false); |
261 */ | |
262 if (!m_path) { | |
263 std::cerr << "ERROR: AlignmentModel::constructReversePath: " | |
264 << "No forward path available" << std::endl; | |
265 return; | |
266 } | |
267 m_reversePath = new PathModel | |
268 (m_path->getSampleRate(), m_path->getResolution(), false); | |
247 } else { | 269 } else { |
270 /*!!! | |
248 if (!m_rawPath) return; | 271 if (!m_rawPath) return; |
272 */ | |
273 if (!m_path) return; | |
249 } | 274 } |
250 | 275 |
251 m_reversePath->clear(); | 276 m_reversePath->clear(); |
252 | 277 /*!!! |
253 SparseTimeValueModel::PointList points = m_rawPath->getPoints(); | 278 SparseTimeValueModel::PointList points = m_rawPath->getPoints(); |
254 | 279 |
255 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); | 280 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); |
256 i != points.end(); ++i) { | 281 i != points.end(); ++i) { |
257 long frame = i->frame; | 282 long frame = i->frame; |
258 float value = i->value; | 283 float value = i->value; |
259 long rframe = lrintf(value * m_aligned->getSampleRate()); | 284 long rframe = lrintf(value * m_aligned->getSampleRate()); |
260 m_reversePath->addPoint(PathPoint(rframe, frame)); | 285 m_reversePath->addPoint(PathPoint(rframe, frame)); |
261 } | 286 } |
287 */ | |
288 | |
289 PathModel::PointList points = m_path->getPoints(); | |
290 | |
291 for (PathModel::PointList::const_iterator i = points.begin(); | |
292 i != points.end(); ++i) { | |
293 long frame = i->frame; | |
294 long rframe = i->mapframe; | |
295 m_reversePath->addPoint(PathPoint(rframe, frame)); | |
296 } | |
262 | 297 |
263 #ifdef DEBUG_ALIGNMENT_MODEL | 298 #ifdef DEBUG_ALIGNMENT_MODEL |
264 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 299 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; |
265 #endif | 300 #endif |
266 } | 301 } |
331 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | 366 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; |
332 #endif | 367 #endif |
333 | 368 |
334 return resultFrame; | 369 return resultFrame; |
335 } | 370 } |
371 | |
372 void | |
373 AlignmentModel::setPath(PathModel *path) | |
374 { | |
375 if (m_path) m_path->aboutToDelete(); | |
376 delete m_path; | |
377 m_path = path; | |
378 constructReversePath(); | |
379 } | |
336 | 380 |
381 void | |
382 AlignmentModel::toXml(QTextStream &stream, | |
383 QString indent, | |
384 QString extraAttributes) const | |
385 { | |
386 if (!m_path) { | |
387 std::cerr << "AlignmentModel::toXml: no path" << std::endl; | |
388 return; | |
389 } | |
390 | |
391 m_path->toXml(stream, indent, ""); | |
392 | |
393 Model::toXml(stream, indent, | |
394 QString("type=\"alignment\" reference=\"%1\" aligned=\"%2\" path=\"%3\" %4") | |
395 .arg(getObjectExportId(m_reference)) | |
396 .arg(getObjectExportId(m_aligned)) | |
397 .arg(getObjectExportId(m_path)) | |
398 .arg(extraAttributes)); | |
399 } | |
400 | |
401 |