diff main/MainWindow.cpp @ 2242:e9c77a4c865e single-point

Add /exportlayer OSC command
author Chris Cannam
date Thu, 28 Mar 2019 14:34:29 +0000
parents ca0ee1fe88c7
children a54082a29106 f78177863e26
line wrap: on
line diff
--- 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<NoteModel *>(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 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-                << "<!DOCTYPE sonic-visualiser>\n"
-                << "<sv>\n"
-                << "  <data>\n";
-
-            model->toXml(out, "    ");
-
-            out << "  </data>\n"
-                << "  <display>\n";
-
-            layer->toXml(out, "    ");
-
-            out << "  </display>\n"
-                << "</sv>\n";
-        }
-
-    } else if (suffix == "mid" || suffix == "midi") {
-
-        NoteModel *nm = dynamic_cast<NoteModel *>(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);