Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 145:937456ffe33e
* Much more sensible pane layouts, etc., when loading RDF; also offer
choice of adding to current session or starting new session if RDF
references audio (needs some refinement)
author | Chris Cannam |
---|---|
date | Fri, 28 Nov 2008 15:45:20 +0000 |
parents | 675443abbc05 |
children | f90dcec6dd9a |
comparison
equal
deleted
inserted
replaced
144:675443abbc05 | 145:937456ffe33e |
---|---|
853 | 853 |
854 bool canImportLayer = (getMainModel() != 0 && | 854 bool canImportLayer = (getMainModel() != 0 && |
855 m_paneStack != 0 && | 855 m_paneStack != 0 && |
856 m_paneStack->getCurrentPane() != 0); | 856 m_paneStack->getCurrentPane() != 0); |
857 | 857 |
858 bool rdf = (source.getExtension() == "rdf" || | |
859 source.getExtension() == "n3" || | |
860 source.getExtension() == "ttl"); | |
861 | |
862 bool rdfSession = false; | |
863 if (rdf) { | |
864 RDFImporter::RDFDocumentType rdfType = | |
865 RDFImporter::identifyDocumentType | |
866 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | |
867 if (rdfType == RDFImporter::AudioRefAndAnnotations || | |
868 rdfType == RDFImporter::AudioRef) { | |
869 rdfSession = true; | |
870 } else if (rdfType == RDFImporter::NotRDF) { | |
871 rdf = false; | |
872 } | |
873 } | |
874 | |
875 if (rdf) { | |
876 if (rdfSession) { | |
877 if (!canImportLayer || shouldCreateNewSessionForRDFAudio()) { | |
878 return openSession(source); | |
879 } else { | |
880 return openLayer(source); | |
881 } | |
882 } else { | |
883 if ((status = openSession(source)) != FileOpenFailed) { | |
884 return status; | |
885 } else if (!canImportLayer) { | |
886 return FileOpenWrongMode; | |
887 } else if ((status = openLayer(source)) != FileOpenFailed) { | |
888 return status; | |
889 } else { | |
890 return FileOpenFailed; | |
891 } | |
892 } | |
893 } | |
894 | |
858 if ((status = openAudio(source, mode)) != FileOpenFailed) { | 895 if ((status = openAudio(source, mode)) != FileOpenFailed) { |
859 return status; | 896 return status; |
860 } else if ((status = openSession(source)) != FileOpenFailed) { | 897 } else if ((status = openSession(source)) != FileOpenFailed) { |
861 return status; | 898 return status; |
862 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) { | 899 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) { |
1124 if (!source.isAvailable()) return FileOpenFailed; | 1161 if (!source.isAvailable()) return FileOpenFailed; |
1125 source.waitForData(); | 1162 source.waitForData(); |
1126 | 1163 |
1127 QString path = source.getLocalFilename(); | 1164 QString path = source.getLocalFilename(); |
1128 | 1165 |
1129 if (source.getExtension() == "rdf" || source.getExtension() == "n3" || | 1166 RDFImporter::RDFDocumentType rdfType = |
1130 source.getExtension() == "ttl") { | 1167 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString()); |
1131 | 1168 |
1132 RDFImporter importer(QUrl::fromLocalFile(path).toString(), | 1169 if (rdfType != RDFImporter::NotRDF) { |
1133 getMainModel()->getSampleRate()); | 1170 |
1134 if (importer.isOK()) { | 1171 return openLayersFromRDF(source); |
1135 | |
1136 std::vector<Model *> models; | |
1137 | |
1138 { | |
1139 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this); | |
1140 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); | |
1141 models = importer.getDataModels(&dialog); | |
1142 } | |
1143 | |
1144 if (models.empty()) { | |
1145 return FileOpenFailed; | |
1146 } | |
1147 | |
1148 for (int i = 0; i < models.size(); ++i) { | |
1149 Layer *newLayer = m_document->createImportedLayer(models[i]); | |
1150 if (newLayer) { | |
1151 if (newLayer->isLayerOpaque() || | |
1152 dynamic_cast<Colour3DPlotLayer *>(newLayer)) { | |
1153 //!!! general garbage. we should be using | |
1154 // a separate loader class that uses callbacks | |
1155 // and directly calls on the document, much | |
1156 // more like SVFileReader | |
1157 AddPaneCommand *command = new AddPaneCommand(this); | |
1158 CommandHistory::getInstance()->addCommand(command); | |
1159 pane = command->getPane(); | |
1160 } | |
1161 m_document->addLayerToView(pane, newLayer); | |
1162 } | |
1163 } | |
1164 | |
1165 m_recentFiles.addFile(source.getLocation()); | |
1166 return FileOpenSucceeded; | |
1167 } | |
1168 | |
1169 return FileOpenFailed; | |
1170 | 1172 |
1171 } else if (source.getExtension() == "svl" || | 1173 } else if (source.getExtension() == "svl" || |
1172 (source.getExtension() == "xml" && | 1174 (source.getExtension() == "xml" && |
1173 (SVFileReader::identifyXmlFile(source.getLocalFilename()) | 1175 (SVFileReader::identifyXmlFile(source.getLocalFilename()) |
1174 == SVFileReader::SVLayerFile))) { | 1176 == SVFileReader::SVLayerFile))) { |
1326 MainWindowBase::openSession(FileSource source) | 1328 MainWindowBase::openSession(FileSource source) |
1327 { | 1329 { |
1328 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; | 1330 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; |
1329 | 1331 |
1330 if (!source.isAvailable()) return FileOpenFailed; | 1332 if (!source.isAvailable()) return FileOpenFailed; |
1331 | 1333 source.waitForData(); |
1332 if (source.getExtension() == "rdf" || source.getExtension() == "n3" || | |
1333 source.getExtension() == "ttl") { | |
1334 return openSessionFromRDF(source); | |
1335 } | |
1336 | 1334 |
1337 if (source.getExtension() != "sv") { | 1335 if (source.getExtension() != "sv") { |
1336 | |
1337 RDFImporter::RDFDocumentType rdfType = | |
1338 RDFImporter::identifyDocumentType | |
1339 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | |
1340 | |
1341 if (rdfType == RDFImporter::AudioRefAndAnnotations || | |
1342 rdfType == RDFImporter::AudioRef) { | |
1343 return openSessionFromRDF(source); | |
1344 } else if (rdfType != RDFImporter::NotRDF) { | |
1345 return FileOpenFailed; | |
1346 } | |
1347 | |
1338 if (source.getExtension() == "xml") { | 1348 if (source.getExtension() == "xml") { |
1339 source.waitForData(); | |
1340 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == | 1349 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == |
1341 SVFileReader::SVSessionFile) { | 1350 SVFileReader::SVSessionFile) { |
1342 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl; | 1351 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl; |
1343 } else { | 1352 } else { |
1344 return FileOpenFailed; | 1353 return FileOpenFailed; |
1345 } | 1354 } |
1346 } else { | 1355 } else { |
1347 return FileOpenFailed; | 1356 return FileOpenFailed; |
1348 } | 1357 } |
1349 } | 1358 } |
1350 source.waitForData(); | |
1351 | 1359 |
1352 QXmlInputSource *inputSource = 0; | 1360 QXmlInputSource *inputSource = 0; |
1353 BZipFileDevice *bzFile = 0; | 1361 BZipFileDevice *bzFile = 0; |
1354 QFile *rawFile = 0; | 1362 QFile *rawFile = 0; |
1355 | 1363 |
1436 MainWindowBase::openSessionFromRDF(FileSource source) | 1444 MainWindowBase::openSessionFromRDF(FileSource source) |
1437 { | 1445 { |
1438 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl; | 1446 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl; |
1439 | 1447 |
1440 if (!source.isAvailable()) return FileOpenFailed; | 1448 if (!source.isAvailable()) return FileOpenFailed; |
1441 | |
1442 source.waitForData(); | 1449 source.waitForData(); |
1443 | 1450 |
1444 RDFImporter importer | 1451 if (!checkSaveModified()) { |
1445 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | 1452 return FileOpenCancelled; |
1446 | 1453 } |
1447 QString audioUrl = importer.getAudioAvailableUrl(); | |
1448 if (audioUrl == "") { | |
1449 std::cerr << "MainWindowBase::openSessionFromRDF: No audio URL in RDF, can't open a session without audio" << std::endl; | |
1450 return FileOpenFailed; | |
1451 } | |
1452 | |
1453 size_t rate = 0; | |
1454 | |
1455 if (Preferences::getInstance()->getResampleOnLoad()) { | |
1456 rate = m_playSource->getSourceSampleRate(); | |
1457 } | |
1458 | |
1459 { | |
1460 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this); | |
1461 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); | |
1462 | |
1463 FileSource audioSource(audioUrl, &dialog); | |
1464 | |
1465 if (!audioSource.isAvailable()) { | |
1466 std::cerr << "MainWindowBase::openSessionFromRDF: Cannot open audio URL \"" << audioUrl.toStdString() << "\" referred to in RDF, can't open a session without audio" << std::endl; | |
1467 return FileOpenFailed; | |
1468 } | |
1469 | |
1470 if (!checkSaveModified()) { | |
1471 return FileOpenCancelled; | |
1472 } | |
1473 | |
1474 closeSession(); | |
1475 createDocument(); | |
1476 | |
1477 audioSource.waitForData(); | |
1478 | |
1479 WaveFileModel *newModel = new WaveFileModel(audioSource); | |
1480 | |
1481 m_viewManager->clearSelections(); | |
1482 | 1454 |
1483 AddPaneCommand *command = new AddPaneCommand(this); | 1455 closeSession(); |
1484 CommandHistory::getInstance()->addCommand(command); | 1456 createDocument(); |
1485 | 1457 |
1486 Pane *pane = command->getPane(); | 1458 FileOpenStatus status = openLayersFromRDF(source); |
1487 | |
1488 if (m_timeRulerLayer) { | |
1489 m_document->addLayerToView(pane, m_timeRulerLayer); | |
1490 } | |
1491 | |
1492 Layer *newLayer = m_document->createMainModelLayer(LayerFactory::Waveform); | |
1493 m_document->addLayerToView(pane, newLayer); | |
1494 | |
1495 m_document->setMainModel(newModel); | |
1496 } | |
1497 | |
1498 FileOpenStatus layerStatus = openLayer(source); | |
1499 | 1459 |
1500 setupMenus(); | 1460 setupMenus(); |
1501 | 1461 |
1502 setWindowTitle(tr("%1: %2") | 1462 setWindowTitle(tr("%1: %2") |
1503 .arg(QApplication::applicationName()) | 1463 .arg(QApplication::applicationName()) |
1504 .arg(source.getLocation())); | 1464 .arg(source.getLocation())); |
1505 CommandHistory::getInstance()->clear(); | 1465 CommandHistory::getInstance()->clear(); |
1506 CommandHistory::getInstance()->documentSaved(); | 1466 CommandHistory::getInstance()->documentSaved(); |
1507 m_documentModified = false; | 1467 m_documentModified = false; |
1508 | 1468 |
1509 return layerStatus; | 1469 return status; |
1470 } | |
1471 | |
1472 MainWindowBase::FileOpenStatus | |
1473 MainWindowBase::openLayersFromRDF(FileSource source) | |
1474 { | |
1475 size_t rate = 0; | |
1476 | |
1477 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this); | |
1478 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash())); | |
1479 | |
1480 if (getMainModel()) { | |
1481 rate = getMainModel()->getSampleRate(); | |
1482 } else if (Preferences::getInstance()->getResampleOnLoad()) { | |
1483 rate = m_playSource->getSourceSampleRate(); | |
1484 } | |
1485 | |
1486 RDFImporter importer | |
1487 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate); | |
1488 | |
1489 if (!importer.isOK()) { | |
1490 return FileOpenFailed; | |
1491 } | |
1492 | |
1493 std::vector<Model *> models = importer.getDataModels(&dialog); | |
1494 | |
1495 dialog.setMessage(tr("Importing from RDF...")); | |
1496 | |
1497 if (models.empty()) { | |
1498 return FileOpenFailed; | |
1499 } | |
1500 | |
1501 std::set<Model *> added; | |
1502 | |
1503 for (int i = 0; i < models.size(); ++i) { | |
1504 | |
1505 Model *m = models[i]; | |
1506 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m); | |
1507 | |
1508 if (w) { | |
1509 | |
1510 Pane *pane = addPaneToStack(); | |
1511 Layer *layer = 0; | |
1512 | |
1513 if (m_timeRulerLayer) { | |
1514 m_document->addLayerToView(pane, m_timeRulerLayer); | |
1515 } | |
1516 | |
1517 if (!getMainModel()) { | |
1518 m_document->setMainModel(w); | |
1519 layer = m_document->createMainModelLayer(LayerFactory::Waveform); | |
1520 } else { | |
1521 layer = m_document->createImportedLayer(w); | |
1522 } | |
1523 | |
1524 m_document->addLayerToView(pane, layer); | |
1525 | |
1526 added.insert(w); | |
1527 | |
1528 for (int j = 0; j < models.size(); ++j) { | |
1529 | |
1530 Model *dm = models[j]; | |
1531 | |
1532 if (dm == m) continue; | |
1533 if (dm->getSourceModel() != m) continue; | |
1534 | |
1535 layer = m_document->createImportedLayer(dm); | |
1536 | |
1537 if (layer->isLayerOpaque() || | |
1538 dynamic_cast<Colour3DPlotLayer *>(layer)) { | |
1539 | |
1540 Pane *singleLayerPane = addPaneToStack(); | |
1541 if (m_timeRulerLayer) { | |
1542 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer); | |
1543 } | |
1544 m_document->addLayerToView(singleLayerPane, layer); | |
1545 | |
1546 } else { | |
1547 | |
1548 if (pane->getLayerCount() > 4) { | |
1549 pane = addPaneToStack(); | |
1550 } | |
1551 | |
1552 m_document->addLayerToView(pane, layer); | |
1553 } | |
1554 | |
1555 added.insert(dm); | |
1556 } | |
1557 } | |
1558 } | |
1559 | |
1560 for (int i = 0; i < models.size(); ++i) { | |
1561 | |
1562 Model *m = models[i]; | |
1563 | |
1564 if (added.find(m) == added.end()) { | |
1565 | |
1566 Layer *layer = m_document->createImportedLayer(m); | |
1567 if (!layer) return FileOpenFailed; | |
1568 | |
1569 Pane *singleLayerPane = addPaneToStack(); | |
1570 if (m_timeRulerLayer) { | |
1571 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer); | |
1572 } | |
1573 m_document->addLayerToView(singleLayerPane, layer); | |
1574 } | |
1575 } | |
1576 | |
1577 m_recentFiles.addFile(source.getLocation()); | |
1578 return FileOpenSucceeded; | |
1510 } | 1579 } |
1511 | 1580 |
1512 void | 1581 void |
1513 MainWindowBase::createPlayTarget() | 1582 MainWindowBase::createPlayTarget() |
1514 { | 1583 { |