comparison framework/MainWindowBase.cpp @ 687:e0b0f3e163ca by-id

Update for removal of (public) getId from Model
author Chris Cannam
date Fri, 05 Jul 2019 15:35:11 +0100
parents 610fa108fbcc
children e56cc6fe7da2
comparison
equal deleted inserted replaced
686:610fa108fbcc 687:e0b0f3e163ca
176 } 176 }
177 } 177 }
178 178
179 qRegisterMetaType<sv_frame_t>("sv_frame_t"); 179 qRegisterMetaType<sv_frame_t>("sv_frame_t");
180 qRegisterMetaType<sv_samplerate_t>("sv_samplerate_t"); 180 qRegisterMetaType<sv_samplerate_t>("sv_samplerate_t");
181 qRegisterMetaType<ModelId>("ModelId");
181 182
182 #ifdef Q_WS_X11 183 #ifdef Q_WS_X11
183 XSetErrorHandler(handle_x11_error); 184 XSetErrorHandler(handle_x11_error);
184 #endif 185 #endif
185 186
1301 .toText(false).c_str()); 1302 .toText(false).c_str());
1302 1303
1303 Layer *layer = pane->getSelectedLayer(); 1304 Layer *layer = pane->getSelectedLayer();
1304 if (!layer) return; 1305 if (!layer) return;
1305 1306
1306 auto rm = ModelById::getAs<RegionModel>(layer->getModel()); 1307 ModelId modelId = layer->getModel();
1308
1309 auto rm = ModelById::getAs<RegionModel>(modelId);
1307 if (rm) { 1310 if (rm) {
1308 Event point(alignedStart, 1311 Event point(alignedStart,
1309 rm->getValueMaximum() + 1, 1312 rm->getValueMaximum() + 1,
1310 alignedDuration, 1313 alignedDuration,
1311 ""); 1314 "");
1312 ChangeEventsCommand *command = new ChangeEventsCommand 1315 ChangeEventsCommand *command = new ChangeEventsCommand
1313 (rm->getId().untyped, name); 1316 (modelId.untyped, name);
1314 command->add(point); 1317 command->add(point);
1315 c = command->finish(); 1318 c = command->finish();
1316 } 1319 }
1317 1320
1318 if (c) { 1321 if (c) {
1319 CommandHistory::getInstance()->addCommand(c, false); 1322 CommandHistory::getInstance()->addCommand(c, false);
1320 return; 1323 return;
1321 } 1324 }
1322 1325
1323 auto nm = ModelById::getAs<NoteModel>(layer->getModel()); 1326 auto nm = ModelById::getAs<NoteModel>(modelId);
1324 if (nm) { 1327 if (nm) {
1325 Event point(alignedStart, 1328 Event point(alignedStart,
1326 nm->getValueMinimum(), 1329 nm->getValueMinimum(),
1327 alignedDuration, 1330 alignedDuration,
1328 1.f, 1331 1.f,
1329 ""); 1332 "");
1330 ChangeEventsCommand *command = new ChangeEventsCommand 1333 ChangeEventsCommand *command = new ChangeEventsCommand
1331 (nm->getId().untyped, name); 1334 (modelId.untyped, name);
1332 command->add(point); 1335 command->add(point);
1333 c = command->finish(); 1336 c = command->finish();
1334 } 1337 }
1335 1338
1336 if (c) { 1339 if (c) {
1572 } else { 1575 } else {
1573 return FileOpenFailed; 1576 return FileOpenFailed;
1574 } 1577 }
1575 } 1578 }
1576 1579
1577 ModelById::add(newModel); 1580 auto newModelId = ModelById::add(newModel);
1578 1581 return addOpenedAudioModel(source, newModelId, mode, templateName, true);
1579 return addOpenedAudioModel(source, newModel->getId(),
1580 mode, templateName, true);
1581 } 1582 }
1582 1583
1583 MainWindowBase::FileOpenStatus 1584 MainWindowBase::FileOpenStatus
1584 MainWindowBase::addOpenedAudioModel(FileSource source, 1585 MainWindowBase::addOpenedAudioModel(FileSource source,
1585 ModelId newModel, 1586 ModelId newModel,
1951 1952
1952 SVDEBUG << "MainWindowBase::openLayer: Have model" << endl; 1953 SVDEBUG << "MainWindowBase::openLayer: Have model" << endl;
1953 1954
1954 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation())); 1955 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
1955 1956
1956 ModelId modelId = newModelPtr->getId(); 1957 ModelId modelId =
1957 ModelById::add(std::shared_ptr<Model>(newModelPtr)); 1958 ModelById::add(std::shared_ptr<Model>(newModelPtr));
1958 1959
1959 Layer *newLayer = m_document->createImportedLayer(modelId); 1960 Layer *newLayer = m_document->createImportedLayer(modelId);
1960 1961
1961 if (newLayer) { 1962 if (newLayer) {
1962 1963
2368 .arg(source.getLocation()).arg(importer.getErrorString())); 2369 .arg(source.getLocation()).arg(importer.getErrorString()));
2369 } 2370 }
2370 return FileOpenFailed; 2371 return FileOpenFailed;
2371 } 2372 }
2372 2373
2373 std::vector<Model *> modelPtrs = importer.getDataModels(&dialog); 2374 std::vector<ModelId> modelIds = importer.getDataModels(&dialog);
2374 2375
2375 dialog.setMessage(tr("Importing from RDF...")); 2376 dialog.setMessage(tr("Importing from RDF..."));
2376 2377
2377 if (modelPtrs.empty()) { 2378 if (modelIds.empty()) {
2378 QMessageBox::critical 2379 QMessageBox::critical
2379 (this, tr("Failed to import RDF"), 2380 (this, tr("Failed to import RDF"),
2380 tr("<b>Failed to import RDF</b><p>No suitable data models found for import from RDF document at \"%1\"</p>").arg(source.getLocation())); 2381 tr("<b>Failed to import RDF</b><p>No suitable data models found for import from RDF document at \"%1\"</p>").arg(source.getLocation()));
2381 return FileOpenFailed; 2382 return FileOpenFailed;
2382 } 2383 }
2383 2384
2384 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation())); 2385 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
2385
2386 std::set<ModelId> modelIds;
2387
2388 for (Model *modelPtr: modelPtrs) {
2389 modelIds.insert(modelPtr->getId());
2390 ModelById::add(std::shared_ptr<Model>(modelPtr));
2391 }
2392 2386
2393 std::set<ModelId> added; 2387 std::set<ModelId> added;
2394 2388
2395 for (auto modelId: modelIds) { 2389 for (auto modelId: modelIds) {
2396 2390
2686 connect(m_document, SIGNAL(layerInAView(Layer *, bool)), 2680 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
2687 this, SLOT(layerInAView(Layer *, bool))); 2681 this, SLOT(layerInAView(Layer *, bool)));
2688 2682
2689 connect(m_document, SIGNAL(modelAdded(ModelId )), 2683 connect(m_document, SIGNAL(modelAdded(ModelId )),
2690 this, SLOT(modelAdded(ModelId ))); 2684 this, SLOT(modelAdded(ModelId )));
2691 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)), 2685 connect(m_document, SIGNAL(mainModelChanged(ModelId)),
2692 this, SLOT(mainModelChanged(WaveFileModel *))); 2686 this, SLOT(mainModelChanged(ModelId)));
2693 connect(m_document, SIGNAL(modelAboutToBeDeleted(ModelId )),
2694 this, SLOT(modelAboutToBeDeleted(ModelId )));
2695 2687
2696 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)), 2688 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
2697 this, SLOT(modelGenerationFailed(QString, QString))); 2689 this, SLOT(modelGenerationFailed(QString, QString)));
2698 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)), 2690 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
2699 this, SLOT(modelRegenerationWarning(QString, QString, QString))); 2691 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
2700 connect(m_document, SIGNAL(alignmentComplete(AlignmentModel *)), 2692 connect(m_document, SIGNAL(alignmentComplete(ModelId)),
2701 this, SLOT(alignmentComplete(AlignmentModel *))); 2693 this, SLOT(alignmentComplete(ModelId)));
2702 connect(m_document, SIGNAL(alignmentFailed(QString)), 2694 connect(m_document, SIGNAL(alignmentFailed(QString)),
2703 this, SLOT(alignmentFailed(QString))); 2695 this, SLOT(alignmentFailed(QString)));
2704 2696
2705 m_document->setAutoAlignment(m_viewManager->getAlignMode()); 2697 m_document->setAutoAlignment(m_viewManager->getAlignMode());
2706 2698
3275 3267
3276 SVCERR << "MainWindowBase::record: Model is OK, continuing..." << endl; 3268 SVCERR << "MainWindowBase::record: Model is OK, continuing..." << endl;
3277 3269
3278 QString location = modelPtr->getLocation(); 3270 QString location = modelPtr->getLocation();
3279 3271
3280 auto modelId = modelPtr->getId(); 3272 auto modelId = ModelById::add(std::shared_ptr<Model>(modelPtr));
3281 ModelById::add(std::shared_ptr<Model>(modelPtr));
3282 3273
3283 if (m_audioRecordMode == RecordReplaceSession || !getMainModel()) { 3274 if (m_audioRecordMode == RecordReplaceSession || !getMainModel()) {
3284 3275
3285 //!!! duplication with openAudio here 3276 //!!! duplication with openAudio here
3286 3277