Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 141:9a8c73ffdce0
* Make it possible to import an entire session from an RDF document.
However, at the moment the timings of events appear to be constrained
by how far the audio decoder has got through its audio file at the
time the event is queried -- need to investigate.
author | Chris Cannam |
---|---|
date | Fri, 21 Nov 2008 18:03:14 +0000 |
parents | 9ccaa8fd9b9f |
children | 8b31cdd7e005 |
comparison
equal
deleted
inserted
replaced
140:9ccaa8fd9b9f | 141:9a8c73ffdce0 |
---|---|
1127 QString path = source.getLocalFilename(); | 1127 QString path = source.getLocalFilename(); |
1128 | 1128 |
1129 if (source.getExtension() == "rdf" || source.getExtension() == "n3" || | 1129 if (source.getExtension() == "rdf" || source.getExtension() == "n3" || |
1130 source.getExtension() == "ttl") { | 1130 source.getExtension() == "ttl") { |
1131 | 1131 |
1132 RDFImporter importer("file://" + path, getMainModel()->getSampleRate()); | 1132 RDFImporter importer(QUrl::fromLocalFile(path).toString(), |
1133 getMainModel()->getSampleRate()); | |
1133 if (importer.isOK()) { | 1134 if (importer.isOK()) { |
1134 | 1135 |
1135 std::vector<Model *> models; | 1136 std::vector<Model *> models; |
1136 | 1137 |
1137 { | 1138 { |
1316 { | 1317 { |
1317 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; | 1318 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl; |
1318 | 1319 |
1319 if (!source.isAvailable()) return FileOpenFailed; | 1320 if (!source.isAvailable()) return FileOpenFailed; |
1320 | 1321 |
1322 if (source.getExtension() == "rdf" || source.getExtension() == "n3" || | |
1323 source.getExtension() == "ttl") { | |
1324 return openSessionFromRDF(source); | |
1325 } | |
1326 | |
1321 if (source.getExtension() != "sv") { | 1327 if (source.getExtension() != "sv") { |
1322 if (source.getExtension() == "xml") { | 1328 if (source.getExtension() == "xml") { |
1323 source.waitForData(); | 1329 source.waitForData(); |
1324 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == | 1330 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) == |
1325 SVFileReader::SVSessionFile) { | 1331 SVFileReader::SVSessionFile) { |
1412 } else { | 1418 } else { |
1413 setWindowTitle(QApplication::applicationName()); | 1419 setWindowTitle(QApplication::applicationName()); |
1414 } | 1420 } |
1415 | 1421 |
1416 return ok ? FileOpenSucceeded : FileOpenFailed; | 1422 return ok ? FileOpenSucceeded : FileOpenFailed; |
1423 } | |
1424 | |
1425 MainWindowBase::FileOpenStatus | |
1426 MainWindowBase::openSessionFromRDF(FileSource source) | |
1427 { | |
1428 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl; | |
1429 | |
1430 if (!source.isAvailable()) return FileOpenFailed; | |
1431 | |
1432 source.waitForData(); | |
1433 | |
1434 RDFImporter importer | |
1435 (QUrl::fromLocalFile(source.getLocalFilename()).toString()); | |
1436 | |
1437 QString audioUrl = importer.getAudioAvailableUrl(); | |
1438 if (audioUrl == "") { | |
1439 std::cerr << "MainWindowBase::openSessionFromRDF: No audio URL in RDF, can't open a session without audio" << std::endl; | |
1440 return FileOpenFailed; | |
1441 } | |
1442 | |
1443 size_t rate = 0; | |
1444 | |
1445 if (Preferences::getInstance()->getResampleOnLoad()) { | |
1446 rate = m_playSource->getSourceSampleRate(); | |
1447 } | |
1448 | |
1449 WaveFileModel *newModel = new WaveFileModel(audioUrl, rate); | |
1450 | |
1451 if (!newModel->isOK()) { | |
1452 delete newModel; | |
1453 std::cerr << "MainWindowBase::openSessionFromRDF: Cannot open audio URL \"" << audioUrl.toStdString() << "\" referred to in RDF, can't open a session without audio" << std::endl; | |
1454 return FileOpenFailed; | |
1455 } | |
1456 | |
1457 if (!checkSaveModified()) { | |
1458 delete newModel; | |
1459 return FileOpenCancelled; | |
1460 } | |
1461 | |
1462 closeSession(); | |
1463 createDocument(); | |
1464 | |
1465 m_viewManager->clearSelections(); | |
1466 | |
1467 m_document->setMainModel(newModel); | |
1468 | |
1469 AddPaneCommand *command = new AddPaneCommand(this); | |
1470 CommandHistory::getInstance()->addCommand(command); | |
1471 | |
1472 Pane *pane = command->getPane(); | |
1473 | |
1474 if (m_timeRulerLayer) { | |
1475 m_document->addLayerToView(pane, m_timeRulerLayer); | |
1476 } | |
1477 | |
1478 Layer *newLayer = m_document->createImportedLayer(newModel); | |
1479 | |
1480 if (newLayer) { | |
1481 m_document->addLayerToView(pane, newLayer); | |
1482 } | |
1483 | |
1484 FileOpenStatus layerStatus = openLayer(source); | |
1485 | |
1486 setupMenus(); | |
1487 | |
1488 setWindowTitle(tr("%1: %2") | |
1489 .arg(QApplication::applicationName()) | |
1490 .arg(source.getLocation())); | |
1491 CommandHistory::getInstance()->clear(); | |
1492 CommandHistory::getInstance()->documentSaved(); | |
1493 m_documentModified = false; | |
1494 | |
1495 return layerStatus; | |
1417 } | 1496 } |
1418 | 1497 |
1419 void | 1498 void |
1420 MainWindowBase::createPlayTarget() | 1499 MainWindowBase::createPlayTarget() |
1421 { | 1500 { |