# HG changeset patch # User Chris Cannam # Date 1553783669 0 # Node ID e9c77a4c865ea7a96768f80658fa83cb13d60a57 # Parent c517286ee999c6ea079ba73e2b02f520aa6a1ea2 Add /exportlayer OSC command diff -r c517286ee999 -r e9c77a4c865e README.OSC --- a/README.OSC Thu Mar 28 13:42:03 2019 +0000 +++ b/README.OSC Thu Mar 28 14:34:29 2019 +0000 @@ -86,6 +86,13 @@ WAV file. This action will try to fail rather than overwrite an existing file, but you probably shouldn't rely on that. + /exportlayer + + Export the current layer to a file, of type determined from the + file's suffix. See /setcurrent for how to change which layer is + current. This action will try to fail rather than overwrite an + existing file, but you probably shouldn't rely on that. + /jump /jump end /jump selection diff -r c517286ee999 -r e9c77a4c865e main/MainWindow.cpp --- a/main/MainWindow.cpp Thu Mar 28 13:42:03 2019 +0000 +++ b/main/MainWindow.cpp Thu Mar 28 14:34:29 2019 +0000 @@ -85,7 +85,6 @@ #include "layer/ColourDatabase.h" #include "widgets/ModelDataTableDialog.h" #include "rdf/PluginRDFIndexer.h" -#include "rdf/RDFExporter.h" #include "Surveyer.h" #include "NetworkPermissionTester.h" @@ -3002,81 +3001,14 @@ if (!model) return; FileFinder::FileType type = FileFinder::LayerFileNoMidi; - if (dynamic_cast(model)) type = FileFinder::LayerFile; - QString path = getSaveFileName(type); if (path == "") return; - if (QFileInfo(path).suffix() == "") path += ".svl"; - - QString suffix = QFileInfo(path).suffix().toLower(); - QString error; - if (suffix == "xml" || suffix == "svl") { - - QFile file(path); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - error = tr("Failed to open file %1 for writing").arg(path); - } else { - QTextStream out(&file); - out.setCodec(QTextCodec::codecForName("UTF-8")); - out << "\n" - << "\n" - << "\n" - << " \n"; - - model->toXml(out, " "); - - out << " \n" - << " \n"; - - layer->toXml(out, " "); - - out << " \n" - << "\n"; - } - - } else if (suffix == "mid" || suffix == "midi") { - - NoteModel *nm = dynamic_cast(model); - - if (!nm) { - error = tr("Can't export non-note layers to MIDI"); - } else { - MIDIFileWriter writer(path, nm, nm->getSampleRate()); - writer.write(); - if (!writer.isOK()) { - error = writer.getError(); - } - } - - } else if (suffix == "ttl" || suffix == "n3") { - - if (!RDFExporter::canExportModel(model)) { - error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); - } else { - RDFExporter exporter(path, model); - exporter.write(); - if (!exporter.isOK()) { - error = exporter.getError(); - } - } - - } else { - - CSVFileWriter writer(path, model, - ((suffix == "csv") ? "," : "\t")); - writer.write(); - - if (!writer.isOK()) { - error = writer.getError(); - } - } - - if (error != "") { + if (!exportLayerTo(layer, path, error)) { QMessageBox::critical(this, tr("Failed to write file"), error); } else { m_recentFiles.addFile(path); diff -r c517286ee999 -r e9c77a4c865e main/OSCHandler.cpp --- a/main/OSCHandler.cpp Thu Mar 28 13:42:03 2019 +0000 +++ b/main/OSCHandler.cpp Thu Mar 28 14:34:29 2019 +0000 @@ -118,6 +118,30 @@ } } + } else if (message.getMethod() == "exportlayer") { + + QString path; + if (message.getArgCount() == 1 && + message.getArg(0).canConvert(QVariant::String)) { + path = message.getArg(0).toString(); + if (QFileInfo(path).exists()) { + SVDEBUG << "OSCHandler: Refusing to overwrite existing file in layer export" << endl; + } else { + Pane *currentPane = nullptr; + Layer *currentLayer = nullptr; + if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); + if (currentPane) currentLayer = currentPane->getSelectedLayer(); + if (currentLayer) { + QString error; + if (!exportLayerTo(currentLayer, path, error)) { + SVCERR << "OSCHandler: Failed to export current layer to " << path << ": " << error << endl; + } + } else { + SVCERR << "OSCHandler: No current layer to export" << endl; + } + } + } + } else if (message.getMethod() == "jump" || message.getMethod() == "play") {