Mercurial > hg > svapp
comparison framework/SVFileReader.cpp @ 629:10046d544e76
Further work on #1773 "Loading a session with features extracted from multiplexed inputs". Re-read the aggregate wave models from the session file; also re-order the way they are written so as to improve the likelihood of successfully re-reading them (! - as it stood before, there was some chance involved)
author | Chris Cannam |
---|---|
date | Mon, 15 Oct 2018 15:50:39 +0100 |
parents | 15a566f26114 |
children | ca64cc9047d0 |
comparison
equal
deleted
inserted
replaced
628:b936872faff2 | 629:10046d544e76 |
---|---|
34 #include "data/model/FlexiNoteModel.h" | 34 #include "data/model/FlexiNoteModel.h" |
35 #include "data/model/RegionModel.h" | 35 #include "data/model/RegionModel.h" |
36 #include "data/model/TextModel.h" | 36 #include "data/model/TextModel.h" |
37 #include "data/model/ImageModel.h" | 37 #include "data/model/ImageModel.h" |
38 #include "data/model/AlignmentModel.h" | 38 #include "data/model/AlignmentModel.h" |
39 #include "data/model/AggregateWaveModel.h" | |
39 | 40 |
40 #include "transform/TransformFactory.h" | 41 #include "transform/TransformFactory.h" |
41 | 42 |
42 #include "view/Pane.h" | 43 #include "view/Pane.h" |
43 | 44 |
207 m_inView = true; | 208 m_inView = true; |
208 ok = readView(attributes); | 209 ok = readView(attributes); |
209 | 210 |
210 } else if (name == "derivation") { | 211 } else if (name == "derivation") { |
211 | 212 |
213 makeAggregateModels(); // must be done before derivations that use them | |
212 ok = readDerivation(attributes); | 214 ok = readDerivation(attributes); |
213 | 215 |
214 } else if (name == "playparameters") { | 216 } else if (name == "playparameters") { |
215 | 217 |
216 ok = readPlayParameters(attributes); | 218 ok = readPlayParameters(attributes); |
401 // dimensions from session file is a really bad idea | 403 // dimensions from session file is a really bad idea |
402 return true; | 404 return true; |
403 } | 405 } |
404 | 406 |
405 void | 407 void |
408 SVFileReader::makeAggregateModels() | |
409 { | |
410 std::map<int, PendingAggregateRec> stillPending; | |
411 | |
412 for (auto p: m_pendingAggregates) { | |
413 | |
414 int id = p.first; | |
415 const PendingAggregateRec &rec = p.second; | |
416 bool skip = false; | |
417 | |
418 AggregateWaveModel::ChannelSpecList specs; | |
419 for (int componentId: rec.components) { | |
420 bool found = false; | |
421 if (m_models.find(componentId) != m_models.end()) { | |
422 RangeSummarisableTimeValueModel *rs = | |
423 dynamic_cast<RangeSummarisableTimeValueModel *> | |
424 (m_models[componentId]); | |
425 if (rs) { | |
426 specs.push_back(AggregateWaveModel::ModelChannelSpec | |
427 (rs, -1)); | |
428 found = true; | |
429 } | |
430 } | |
431 if (!found) { | |
432 SVDEBUG << "SVFileReader::makeAggregateModels:" | |
433 << "Unknown component model id " | |
434 << componentId << " in aggregate model id " << id | |
435 << ", hoping we won't be needing it just yet" | |
436 << endl; | |
437 skip = true; | |
438 } | |
439 } | |
440 | |
441 if (skip) { | |
442 stillPending[id] = rec; | |
443 } else { | |
444 AggregateWaveModel *model = new AggregateWaveModel(specs); | |
445 model->setObjectName(rec.name); | |
446 | |
447 SVDEBUG << "SVFileReader::makeAggregateModels: created aggregate model id " | |
448 << id << " with " << specs.size() << " components" << endl; | |
449 | |
450 m_models[id] = model; | |
451 } | |
452 } | |
453 | |
454 m_pendingAggregates = stillPending; | |
455 } | |
456 | |
457 void | |
406 SVFileReader::addUnaddedModels() | 458 SVFileReader::addUnaddedModels() |
407 { | 459 { |
460 makeAggregateModels(); | |
461 | |
408 std::set<Model *> unaddedModels; | 462 std::set<Model *> unaddedModels; |
409 | 463 |
410 for (std::map<int, Model *>::iterator i = m_models.begin(); | 464 for (std::map<int, Model *>::iterator i = m_models.begin(); |
411 i != m_models.end(); ++i) { | 465 i != m_models.end(); ++i) { |
412 if (m_addedModels.find(i->second) == m_addedModels.end()) { | 466 if (m_addedModels.find(i->second) == m_addedModels.end()) { |
505 m_document->setMainModel(model); | 559 m_document->setMainModel(model); |
506 m_addedModels.insert(model); | 560 m_addedModels.insert(model); |
507 } | 561 } |
508 // Derived models will be added when their derivation | 562 // Derived models will be added when their derivation |
509 // is found. | 563 // is found. |
564 | |
565 return true; | |
566 | |
567 } else if (type == "aggregatewave") { | |
568 | |
569 QString components = attributes.value("components"); | |
570 QStringList componentIdStrings = components.split(","); | |
571 std::vector<int> componentIds; | |
572 for (auto cid: componentIdStrings) { | |
573 bool ok = false; | |
574 int id = cid.toInt(&ok); | |
575 if (!ok) { | |
576 SVCERR << "SVFileReader::readModel: Failed to convert component model id from part \"" << cid << "\" in \"" << components << "\"" << endl; | |
577 } else { | |
578 componentIds.push_back(id); | |
579 } | |
580 } | |
581 PendingAggregateRec rec { name, sampleRate, componentIds }; | |
582 m_pendingAggregates[id] = rec; | |
583 | |
584 // The aggregate model will be constructed from its pending | |
585 // record in makeAggregateModels; it can't happen here because | |
586 // the component models might not all have been observed yet | |
587 // (an unfortunate accident of the way the file is written) | |
510 | 588 |
511 return true; | 589 return true; |
512 | 590 |
513 } else if (type == "dense") { | 591 } else if (type == "dense") { |
514 | 592 |