comparison framework/Document.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 021d42e6c8cb
children 4612d44ae753
comparison
equal deleted inserted replaced
628:b936872faff2 629:10046d544e76
1303 } 1303 }
1304 1304
1305 // Write aggregate models first, so that when re-reading 1305 // Write aggregate models first, so that when re-reading
1306 // derivations we already know about their existence. But only 1306 // derivations we already know about their existence. But only
1307 // those that are actually used 1307 // those that are actually used
1308 //
1309 // Later note: This turns out not to be a great idea - we can't
1310 // use an aggregate model to drive a derivation unless its
1311 // component models have all also already been loaded. So we
1312 // really should have written non-aggregate read-only
1313 // (i.e. non-derived) wave-type models first, then aggregate
1314 // models, then models that have derivations. But we didn't do
1315 // that, so existing sessions will always have the aggregate
1316 // models first and we might as well stick with that.
1308 1317
1309 for (std::set<Model *>::iterator i = m_aggregateModels.begin(); 1318 for (std::set<Model *>::iterator i = m_aggregateModels.begin();
1310 i != m_aggregateModels.end(); ++i) { 1319 i != m_aggregateModels.end(); ++i) {
1311 1320
1312 SVDEBUG << "checking aggregate model " << *i << endl; 1321 SVDEBUG << "checking aggregate model " << *i << endl;
1323 aggregate->toXml(out, indent + " "); 1332 aggregate->toXml(out, indent + " ");
1324 } 1333 }
1325 1334
1326 std::set<Model *> written; 1335 std::set<Model *> written;
1327 1336
1328 for (ModelMap::const_iterator i = m_models.begin(); 1337 // Now write the other models in two passes: first the models that
1329 i != m_models.end(); ++i) { 1338 // aren't derived from anything (in case they are source
1330 1339 // components for an aggregate model, in which case we need to
1331 Model *model = i->first; 1340 // have seen them before we see any models derived from aggregates
1332 const ModelRecord &rec = i->second; 1341 // that use them - see the lament above) and then the models that
1333 1342 // have derivations.
1334 if (used.find(model) == used.end()) continue; 1343
1344 const int nonDerivedPass = 0, derivedPass = 1;
1345 for (int pass = nonDerivedPass; pass <= derivedPass; ++pass) {
1346
1347 for (ModelMap::const_iterator i = m_models.begin();
1348 i != m_models.end(); ++i) {
1349
1350 Model *model = i->first;
1351 const ModelRecord &rec = i->second;
1352
1353 if (used.find(model) == used.end()) continue;
1335 1354
1336 // We need an intelligent way to determine which models need 1355 // We need an intelligent way to determine which models
1337 // to be streamed (i.e. have been edited, or are small) and 1356 // need to be streamed (i.e. have been edited, or are
1338 // which should not be (i.e. remain as generated by a 1357 // small) and which should not be (i.e. remain as
1339 // transform, and are large). 1358 // generated by a transform, and are large).
1340 // 1359 //
1341 // At the moment we can get away with deciding not to stream 1360 // At the moment we can get away with deciding not to
1342 // dense 3d models or writable wave file models, provided they 1361 // stream dense 3d models or writable wave file models,
1343 // were generated from a transform, because at the moment there 1362 // provided they were generated from a transform, because
1344 // is no way to edit those model types so it should be safe to 1363 // at the moment there is no way to edit those model types
1345 // regenerate them. That won't always work in future though. 1364 // so it should be safe to regenerate them. That won't
1346 // It would be particularly nice to be able to ask the user, 1365 // always work in future though. It would be particularly
1347 // as well as making an intelligent guess. 1366 // nice to be able to ask the user, as well as making an
1348 1367 // intelligent guess.
1349 bool writeModel = true; 1368
1350 bool haveDerivation = false; 1369 bool writeModel = true;
1351 1370 bool haveDerivation = false;
1352 if (rec.source && rec.transform.getIdentifier() != "") { 1371
1353 haveDerivation = true; 1372 if (rec.source && rec.transform.getIdentifier() != "") {
1354 } 1373 haveDerivation = true;
1355
1356 if (haveDerivation) {
1357 if (dynamic_cast<const WritableWaveFileModel *>(model)) {
1358 writeModel = false;
1359 } else if (dynamic_cast<const DenseThreeDimensionalModel *>(model)) {
1360 writeModel = false;
1361 } 1374 }
1362 } 1375
1363 1376 if (pass == nonDerivedPass) {
1364 if (writeModel) { 1377 if (haveDerivation) {
1365 model->toXml(out, indent + " "); 1378 SVDEBUG << "skipping derived model " << model->objectName() << " during nonDerivedPass" << endl;
1366 written.insert(model); 1379 continue;
1367 } 1380 }
1368 1381 } else {
1369 if (haveDerivation) { 1382 if (!haveDerivation) {
1370 writeBackwardCompatibleDerivation(out, indent + " ", 1383 SVDEBUG << "skipping non-derived model " << model->objectName() << " during derivedPass" << endl;
1371 model, rec); 1384 continue;
1372 } 1385 }
1373 1386 }
1374 //!!! We should probably own the PlayParameterRepository 1387
1375 PlayParameters *playParameters = 1388 if (haveDerivation) {
1376 PlayParameterRepository::getInstance()->getPlayParameters(model); 1389 if (dynamic_cast<const WritableWaveFileModel *>(model)) {
1377 if (playParameters) { 1390 writeModel = false;
1378 playParameters->toXml 1391 } else if (dynamic_cast<const DenseThreeDimensionalModel *>(model)) {
1379 (out, indent + " ", 1392 writeModel = false;
1380 QString("model=\"%1\"") 1393 }
1381 .arg(XmlExportable::getObjectExportId(model))); 1394 }
1382 } 1395
1383 } 1396 if (writeModel) {
1384 1397 model->toXml(out, indent + " ");
1385 //!!! 1398 written.insert(model);
1399 }
1400
1401 if (haveDerivation) {
1402 writeBackwardCompatibleDerivation(out, indent + " ",
1403 model, rec);
1404 }
1405
1406 //!!! We should probably own the PlayParameterRepository
1407 PlayParameters *playParameters =
1408 PlayParameterRepository::getInstance()->getPlayParameters(model);
1409 if (playParameters) {
1410 playParameters->toXml
1411 (out, indent + " ",
1412 QString("model=\"%1\"")
1413 .arg(XmlExportable::getObjectExportId(model)));
1414 }
1415 }
1416 }
1386 1417
1387 // We should write out the alignment models here. AlignmentModel 1418 // We should write out the alignment models here. AlignmentModel
1388 // needs a toXml that writes out the export IDs of its reference 1419 // needs a toXml that writes out the export IDs of its reference
1389 // and aligned models, and then streams its path model. Note that 1420 // and aligned models, and then streams its path model. Note that
1390 // this will only work when the alignment is complete, so we 1421 // this will only work when the alignment is complete, so we