# HG changeset patch
# User Chris Cannam
# Date 1553783640 0
# Node ID 49cf3787cf22012e4f979cb4453ed573019c214d
# Parent 94f518af106cde0ef82fb39041f99c3c5ed5834e
Add exportLayerTo (moved here from MainWindow)
diff -r 94f518af106c -r 49cf3787cf22 framework/MainWindowBase.cpp
--- a/framework/MainWindowBase.cpp Thu Mar 28 13:37:40 2019 +0000
+++ b/framework/MainWindowBase.cpp Thu Mar 28 14:34:00 2019 +0000
@@ -54,10 +54,12 @@
#include "data/fileio/PlaylistFileReader.h"
#include "data/fileio/WavFileWriter.h"
#include "data/fileio/MIDIFileWriter.h"
+#include "data/fileio/CSVFileWriter.h"
#include "data/fileio/BZipFileDevice.h"
#include "data/fileio/FileSource.h"
#include "data/fileio/AudioFileReaderFactory.h"
#include "rdf/RDFImporter.h"
+#include "rdf/RDFExporter.h"
#include "base/RecentFiles.h"
@@ -2765,6 +2767,79 @@
}
}
+bool
+MainWindowBase::exportLayerTo(Layer *layer, QString path, QString &error)
+{
+ if (QFileInfo(path).suffix() == "") path += ".svl";
+
+ QString suffix = QFileInfo(path).suffix().toLower();
+
+ Model *model = layer->getModel();
+
+ 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();
+ }
+ }
+
+ return (error == "");
+}
+
void
MainWindowBase::toXml(QTextStream &out, bool asTemplate)
{
diff -r 94f518af106c -r 49cf3787cf22 framework/MainWindowBase.h
--- a/framework/MainWindowBase.h Thu Mar 28 13:37:40 2019 +0000
+++ b/framework/MainWindowBase.h Thu Mar 28 14:34:00 2019 +0000
@@ -139,6 +139,8 @@
virtual bool saveSessionFile(QString path);
virtual bool saveSessionTemplate(QString path);
+ virtual bool exportLayerTo(Layer *layer, QString path, QString &error);
+
void cueOSCScript(QString filename);
/// Implementation of FrameTimer interface method