comparison 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
comparison
equal deleted inserted replaced
2241:c517286ee999 2242:e9c77a4c865e
83 #include "base/Clipboard.h" 83 #include "base/Clipboard.h"
84 #include "base/UnitDatabase.h" 84 #include "base/UnitDatabase.h"
85 #include "layer/ColourDatabase.h" 85 #include "layer/ColourDatabase.h"
86 #include "widgets/ModelDataTableDialog.h" 86 #include "widgets/ModelDataTableDialog.h"
87 #include "rdf/PluginRDFIndexer.h" 87 #include "rdf/PluginRDFIndexer.h"
88 #include "rdf/RDFExporter.h"
89 88
90 #include "Surveyer.h" 89 #include "Surveyer.h"
91 #include "NetworkPermissionTester.h" 90 #include "NetworkPermissionTester.h"
92 #include "framework/VersionTester.h" 91 #include "framework/VersionTester.h"
93 92
3000 2999
3001 Model *model = layer->getModel(); 3000 Model *model = layer->getModel();
3002 if (!model) return; 3001 if (!model) return;
3003 3002
3004 FileFinder::FileType type = FileFinder::LayerFileNoMidi; 3003 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
3005
3006 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile; 3004 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
3007
3008 QString path = getSaveFileName(type); 3005 QString path = getSaveFileName(type);
3009 3006
3010 if (path == "") return; 3007 if (path == "") return;
3011 3008
3012 if (QFileInfo(path).suffix() == "") path += ".svl";
3013
3014 QString suffix = QFileInfo(path).suffix().toLower();
3015
3016 QString error; 3009 QString error;
3017 3010
3018 if (suffix == "xml" || suffix == "svl") { 3011 if (!exportLayerTo(layer, path, error)) {
3019
3020 QFile file(path);
3021 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3022 error = tr("Failed to open file %1 for writing").arg(path);
3023 } else {
3024 QTextStream out(&file);
3025 out.setCodec(QTextCodec::codecForName("UTF-8"));
3026 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3027 << "<!DOCTYPE sonic-visualiser>\n"
3028 << "<sv>\n"
3029 << " <data>\n";
3030
3031 model->toXml(out, " ");
3032
3033 out << " </data>\n"
3034 << " <display>\n";
3035
3036 layer->toXml(out, " ");
3037
3038 out << " </display>\n"
3039 << "</sv>\n";
3040 }
3041
3042 } else if (suffix == "mid" || suffix == "midi") {
3043
3044 NoteModel *nm = dynamic_cast<NoteModel *>(model);
3045
3046 if (!nm) {
3047 error = tr("Can't export non-note layers to MIDI");
3048 } else {
3049 MIDIFileWriter writer(path, nm, nm->getSampleRate());
3050 writer.write();
3051 if (!writer.isOK()) {
3052 error = writer.getError();
3053 }
3054 }
3055
3056 } else if (suffix == "ttl" || suffix == "n3") {
3057
3058 if (!RDFExporter::canExportModel(model)) {
3059 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)");
3060 } else {
3061 RDFExporter exporter(path, model);
3062 exporter.write();
3063 if (!exporter.isOK()) {
3064 error = exporter.getError();
3065 }
3066 }
3067
3068 } else {
3069
3070 CSVFileWriter writer(path, model,
3071 ((suffix == "csv") ? "," : "\t"));
3072 writer.write();
3073
3074 if (!writer.isOK()) {
3075 error = writer.getError();
3076 }
3077 }
3078
3079 if (error != "") {
3080 QMessageBox::critical(this, tr("Failed to write file"), error); 3012 QMessageBox::critical(this, tr("Failed to write file"), error);
3081 } else { 3013 } else {
3082 m_recentFiles.addFile(path); 3014 m_recentFiles.addFile(path);
3083 emit activity(tr("Export layer to \"%1\"").arg(path)); 3015 emit activity(tr("Export layer to \"%1\"").arg(path));
3084 } 3016 }