# HG changeset patch # User matthiasm # Date 1371308670 -3600 # Node ID 97b1fa2d1c5348ab042cdd78c6a73cbc36d18e0a # Parent 6479a92f1e0caba9308c3f5629855b8b68a05f17 added some code to export -- still not quite right, only csv/txt exports work diff -r 6479a92f1e0c -r 97b1fa2d1c53 src/Analyser.cpp --- a/src/Analyser.cpp Sat Apr 20 08:38:37 2013 +0100 +++ b/src/Analyser.cpp Sat Jun 15 16:04:30 2013 +0100 @@ -48,7 +48,7 @@ m_fileModel = model; m_pane = pane; - TransformId f0 = "vamp:yintony:yintony:f0"; + TransformId f0 = "vamp:yintony:yintony:notepitchtrack"; TransformId notes = "vamp:yintony:yintony:notes"; // TransformId f0 = "vamp:cepstral-pitchtracker:cepstral-pitchtracker:f0"; diff -r 6479a92f1e0c -r 97b1fa2d1c53 src/MainWindow.cpp --- a/src/MainWindow.cpp Sat Apr 20 08:38:37 2013 +0100 +++ b/src/MainWindow.cpp Sat Jun 15 16:04:30 2013 +0100 @@ -23,6 +23,9 @@ #include "view/Pane.h" #include "view/PaneStack.h" #include "data/model/WaveFileModel.h" +#include "data/model/NoteModel.h" +#include "data/model/FlexiNoteModel.h" +#include "data/model/NoteModel.h" #include "view/ViewManager.h" #include "base/Preferences.h" #include "layer/WaveformLayer.h" @@ -40,6 +43,10 @@ #include "base/UnitDatabase.h" #include "layer/ColourDatabase.h" +#include "data/fileio/CSVFileWriter.h" +#include "data/fileio/MIDIFileWriter.h" +#include "rdf/RDFExporter.h" + // For version information #include "vamp/vamp.h" #include "vamp-sdk/PluginBase.h" @@ -273,6 +280,13 @@ this, SLOT(setupRecentFilesMenu())); menu->addSeparator(); + action = new QAction(tr("Export Annotation Layer..."), this); + action->setStatusTip(tr("Export layer data to a file")); + connect(action, SIGNAL(triggered()), this, SLOT(exportLayer())); + connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool))); + menu->addAction(action); + + menu->addSeparator(); action = new QAction(il.load("exit"), tr("&Quit"), this); action->setShortcut(tr("Ctrl+Q")); action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName())); @@ -1042,6 +1056,101 @@ } void +MainWindow::exportLayer() +{ + Pane *pane = m_paneStack->getCurrentPane(); + if (!pane) return; + + Layer *layer = pane->getSelectedLayer(); + if (!layer) return; + + Model *model = layer->getModel(); + 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 << "\n" + << "\n" + << "\n" + << " \n"; + + model->toXml(out, " "); + + out << " \n" + << " \n"; + + layer->toXml(out, " "); + + out << " \n" + << "\n"; + } + + // } else if (suffix == "mid" || suffix == "midi") { + // + // FlexiNoteModel *nm = dynamic_cast(model); + // + // if (!nm) { + // error = tr("Can't export non-note layers to MIDI"); + // } else { + // MIDIFileWriter writer(path, nm); + // 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 != "") { + QMessageBox::critical(this, tr("Failed to write file"), error); + } else { + m_recentFiles.addFile(path); + emit activity(tr("Export layer to \"%1\"").arg(path)); + } +} + + +void MainWindow::renameCurrentLayer() { Pane *pane = m_paneStack->getCurrentPane(); diff -r 6479a92f1e0c -r 97b1fa2d1c53 src/MainWindow.h --- a/src/MainWindow.h Sat Apr 20 08:38:37 2013 +0100 +++ b/src/MainWindow.h Sat Jun 15 16:04:30 2013 +0100 @@ -38,6 +38,7 @@ virtual void openRecentFile(); virtual void saveSession(); virtual void saveSessionAs(); + virtual void exportLayer(); virtual void newSession(); virtual void closeSession();