# HG changeset patch # User Chris Cannam # Date 1227290594 0 # Node ID 9a8c73ffdce0ca65a9fa34d046c7600a2ba0d633 # Parent 9ccaa8fd9b9ffe5b01f6a6d05feaca9018365e05 * 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. diff -r 9ccaa8fd9b9f -r 9a8c73ffdce0 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Thu Nov 20 10:59:14 2008 +0000 +++ b/framework/MainWindowBase.cpp Fri Nov 21 18:03:14 2008 +0000 @@ -1129,7 +1129,8 @@ if (source.getExtension() == "rdf" || source.getExtension() == "n3" || source.getExtension() == "ttl") { - RDFImporter importer("file://" + path, getMainModel()->getSampleRate()); + RDFImporter importer(QUrl::fromLocalFile(path).toString(), + getMainModel()->getSampleRate()); if (importer.isOK()) { std::vector models; @@ -1318,6 +1319,11 @@ if (!source.isAvailable()) return FileOpenFailed; + if (source.getExtension() == "rdf" || source.getExtension() == "n3" || + source.getExtension() == "ttl") { + return openSessionFromRDF(source); + } + if (source.getExtension() != "sv") { if (source.getExtension() == "xml") { source.waitForData(); @@ -1416,6 +1422,79 @@ return ok ? FileOpenSucceeded : FileOpenFailed; } +MainWindowBase::FileOpenStatus +MainWindowBase::openSessionFromRDF(FileSource source) +{ + std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl; + + if (!source.isAvailable()) return FileOpenFailed; + + source.waitForData(); + + RDFImporter importer + (QUrl::fromLocalFile(source.getLocalFilename()).toString()); + + QString audioUrl = importer.getAudioAvailableUrl(); + if (audioUrl == "") { + std::cerr << "MainWindowBase::openSessionFromRDF: No audio URL in RDF, can't open a session without audio" << std::endl; + return FileOpenFailed; + } + + size_t rate = 0; + + if (Preferences::getInstance()->getResampleOnLoad()) { + rate = m_playSource->getSourceSampleRate(); + } + + WaveFileModel *newModel = new WaveFileModel(audioUrl, rate); + + if (!newModel->isOK()) { + delete newModel; + std::cerr << "MainWindowBase::openSessionFromRDF: Cannot open audio URL \"" << audioUrl.toStdString() << "\" referred to in RDF, can't open a session without audio" << std::endl; + return FileOpenFailed; + } + + if (!checkSaveModified()) { + delete newModel; + return FileOpenCancelled; + } + + closeSession(); + createDocument(); + + m_viewManager->clearSelections(); + + m_document->setMainModel(newModel); + + AddPaneCommand *command = new AddPaneCommand(this); + CommandHistory::getInstance()->addCommand(command); + + Pane *pane = command->getPane(); + + if (m_timeRulerLayer) { + m_document->addLayerToView(pane, m_timeRulerLayer); + } + + Layer *newLayer = m_document->createImportedLayer(newModel); + + if (newLayer) { + m_document->addLayerToView(pane, newLayer); + } + + FileOpenStatus layerStatus = openLayer(source); + + setupMenus(); + + setWindowTitle(tr("%1: %2") + .arg(QApplication::applicationName()) + .arg(source.getLocation())); + CommandHistory::getInstance()->clear(); + CommandHistory::getInstance()->documentSaved(); + m_documentModified = false; + + return layerStatus; +} + void MainWindowBase::createPlayTarget() { diff -r 9ccaa8fd9b9f -r 9a8c73ffdce0 framework/MainWindowBase.h --- a/framework/MainWindowBase.h Thu Nov 20 10:59:14 2008 +0000 +++ b/framework/MainWindowBase.h Fri Nov 21 18:03:14 2008 +0000 @@ -249,6 +249,8 @@ virtual void contextHelpChanged(const QString &); virtual void inProgressSelectionChanged(); + virtual FileOpenStatus openSessionFromRDF(FileSource source); + virtual void closeSession() = 0; protected: