# HG changeset patch
# User Chris Cannam
# Date 1386004379 0
# Node ID ca570861c10569b275d5764c998c27dfcec41ec5
# Parent 0cbe560f0fa1a5c2c342a5ed8abf351ae7da9c89
Note and pitch track export functions
diff -r 0cbe560f0fa1 -r ca570861c105 .hgsubstate
--- a/.hgsubstate Mon Dec 02 15:47:58 2013 +0000
+++ b/.hgsubstate Mon Dec 02 17:12:59 2013 +0000
@@ -1,4 +1,4 @@
236814e07bd07473958c1ff89103124536a0c3c8 dataquay
-1e61f0c26593467bd21f4eda3dc168c048ce4897 svapp
-dba8a02b0413335ee34cf302aef7754daebd0b8d svcore
+ae1eedd6951fcdb1424ff1c082f4ac789e371e1d svapp
+23ecd10c2eb63af570fdc510c94ae66dd2992e0c svcore
212644efa523f61316450bc6ee92f3f5158f68f3 svgui
diff -r 0cbe560f0fa1 -r ca570861c105 src/MainWindow.cpp
--- a/src/MainWindow.cpp Mon Dec 02 15:47:58 2013 +0000
+++ b/src/MainWindow.cpp Mon Dec 02 17:12:59 2013 +0000
@@ -286,9 +286,15 @@
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()));
+ action = new QAction(tr("Export Pitch Track Data..."), this);
+ action->setStatusTip(tr("Export pitch-track data to a file"));
+ connect(action, SIGNAL(triggered()), this, SLOT(exportPitchLayer()));
+ connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
+ menu->addAction(action);
+
+ action = new QAction(tr("Export Note Data..."), this);
+ action->setStatusTip(tr("Export note data to a file"));
+ connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer()));
connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
menu->addAction(action);
@@ -1115,35 +1121,69 @@
if (path == "") return;
if (!saveSessionFile(path)) {
- QMessageBox::critical(this, tr("Failed to save file"),
- tr("Session file \"%1\" could not be saved.").arg(path));
+ QMessageBox::critical(this, tr("Failed to save file"),
+ tr("Session file \"%1\" could not be saved.").arg(path));
} else {
- setWindowTitle(tr("%1: %2")
+ setWindowTitle(tr("%1: %2")
.arg(QApplication::applicationName())
- .arg(QFileInfo(path).fileName()));
- m_sessionFile = path;
- CommandHistory::getInstance()->documentSaved();
- documentRestored();
+ .arg(QFileInfo(path).fileName()));
+ m_sessionFile = path;
+ CommandHistory::getInstance()->documentSaved();
+ documentRestored();
m_recentFiles.addFile(path);
}
}
+QString
+MainWindow::exportToSVL(QString path, Layer *layer)
+{
+ Model *model = layer->getModel();
+
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ return 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";
+
+ return "";
+ }
+}
+
void
-MainWindow::exportLayer()
+MainWindow::exportPitchLayer()
{
- Pane *pane = m_paneStack->getCurrentPane();
- if (!pane) return;
+ Layer *layer = 0;
+ for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
+ Pane *pane = m_paneStack->getPane(i);
+ for (int j = 0; j < pane->getLayerCount(); ++j) {
+ layer = qobject_cast(pane->getLayer(j));
+ if (layer) break;
+ }
+ if (layer) break;
+ }
- Layer *layer = pane->getSelectedLayer();
if (!layer) return;
- Model *model = layer->getModel();
+ SparseTimeValueModel *model =
+ qobject_cast(layer->getModel());
if (!model) return;
FileFinder::FileType type = FileFinder::LayerFileNoMidi;
- if (dynamic_cast(model)) type = FileFinder::LayerFile;
-
QString path = getSaveFileName(type);
if (path == "") return;
@@ -1156,51 +1196,83 @@
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();
- // }
- // }
+ error = exportToSVL(path, layer);
} 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();
- }
+ 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::exportNoteLayer()
+{
+ Layer *layer = 0;
+ for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
+ Pane *pane = m_paneStack->getPane(i);
+ for (int j = 0; j < pane->getLayerCount(); ++j) {
+ layer = qobject_cast(pane->getLayer(j));
+ if (layer) break;
+ }
+ if (layer) break;
+ }
+
+ if (!layer) return;
+
+ FlexiNoteModel *model = qobject_cast(layer->getModel());
+ if (!model) return;
+
+ FileFinder::FileType 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") {
+
+ error = exportToSVL(path, layer);
+
+ } else if (suffix == "mid" || suffix == "midi") {
+
+ MIDIFileWriter writer(path, model, model->getSampleRate());
+ writer.write();
+ if (!writer.isOK()) {
+ error = writer.getError();
+ }
+
+ } else if (suffix == "ttl" || suffix == "n3") {
+
+ RDFExporter exporter(path, model);
+ exporter.write();
+ if (!exporter.isOK()) {
+ error = exporter.getError();
}
} else {
diff -r 0cbe560f0fa1 -r ca570861c105 src/MainWindow.h
--- a/src/MainWindow.h Mon Dec 02 15:47:58 2013 +0000
+++ b/src/MainWindow.h Mon Dec 02 17:12:59 2013 +0000
@@ -38,7 +38,8 @@
virtual void openRecentFile();
virtual void saveSession();
virtual void saveSessionAs();
- virtual void exportLayer();
+ virtual void exportPitchLayer();
+ virtual void exportNoteLayer();
virtual void newSession();
virtual void closeSession();
@@ -127,6 +128,8 @@
KeyReference *m_keyReference;
+ QString exportToSVL(QString path, Layer *layer);
+
virtual void setupMenus();
virtual void setupFileMenu();
virtual void setupEditMenu();