comparison src/MainWindow.cpp @ 26:97b1fa2d1c53

added some code to export -- still not quite right, only csv/txt exports work
author matthiasm
date Sat, 15 Jun 2013 16:04:30 +0100
parents 6479a92f1e0c
children 7e17d5d38c83
comparison
equal deleted inserted replaced
25:6479a92f1e0c 26:97b1fa2d1c53
21 #include "framework/Document.h" 21 #include "framework/Document.h"
22 22
23 #include "view/Pane.h" 23 #include "view/Pane.h"
24 #include "view/PaneStack.h" 24 #include "view/PaneStack.h"
25 #include "data/model/WaveFileModel.h" 25 #include "data/model/WaveFileModel.h"
26 #include "data/model/NoteModel.h"
27 #include "data/model/FlexiNoteModel.h"
28 #include "data/model/NoteModel.h"
26 #include "view/ViewManager.h" 29 #include "view/ViewManager.h"
27 #include "base/Preferences.h" 30 #include "base/Preferences.h"
28 #include "layer/WaveformLayer.h" 31 #include "layer/WaveformLayer.h"
29 #include "layer/TimeInstantLayer.h" 32 #include "layer/TimeInstantLayer.h"
30 #include "layer/TimeValueLayer.h" 33 #include "layer/TimeValueLayer.h"
38 #include "audioio/PlaySpeedRangeMapper.h" 41 #include "audioio/PlaySpeedRangeMapper.h"
39 #include "base/Profiler.h" 42 #include "base/Profiler.h"
40 #include "base/UnitDatabase.h" 43 #include "base/UnitDatabase.h"
41 #include "layer/ColourDatabase.h" 44 #include "layer/ColourDatabase.h"
42 45
46 #include "data/fileio/CSVFileWriter.h"
47 #include "data/fileio/MIDIFileWriter.h"
48 #include "rdf/RDFExporter.h"
49
43 // For version information 50 // For version information
44 #include "vamp/vamp.h" 51 #include "vamp/vamp.h"
45 #include "vamp-sdk/PluginBase.h" 52 #include "vamp-sdk/PluginBase.h"
46 #include "plugin/api/ladspa.h" 53 #include "plugin/api/ladspa.h"
47 #include "plugin/api/dssi.h" 54 #include "plugin/api/dssi.h"
269 m_recentFilesMenu = menu->addMenu(tr("Open &Recent")); 276 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
270 m_recentFilesMenu->setTearOffEnabled(true); 277 m_recentFilesMenu->setTearOffEnabled(true);
271 setupRecentFilesMenu(); 278 setupRecentFilesMenu();
272 connect(&m_recentFiles, SIGNAL(recentChanged()), 279 connect(&m_recentFiles, SIGNAL(recentChanged()),
273 this, SLOT(setupRecentFilesMenu())); 280 this, SLOT(setupRecentFilesMenu()));
281
282 menu->addSeparator();
283 action = new QAction(tr("Export Annotation Layer..."), this);
284 action->setStatusTip(tr("Export layer data to a file"));
285 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
286 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
287 menu->addAction(action);
274 288
275 menu->addSeparator(); 289 menu->addSeparator();
276 action = new QAction(il.load("exit"), tr("&Quit"), this); 290 action = new QAction(il.load("exit"), tr("&Quit"), this);
277 action->setShortcut(tr("Ctrl+Q")); 291 action->setShortcut(tr("Ctrl+Q"));
278 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName())); 292 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
1040 m_recentFiles.addFile(path); 1054 m_recentFiles.addFile(path);
1041 } 1055 }
1042 } 1056 }
1043 1057
1044 void 1058 void
1059 MainWindow::exportLayer()
1060 {
1061 Pane *pane = m_paneStack->getCurrentPane();
1062 if (!pane) return;
1063
1064 Layer *layer = pane->getSelectedLayer();
1065 if (!layer) return;
1066
1067 Model *model = layer->getModel();
1068 if (!model) return;
1069
1070 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
1071
1072 if (dynamic_cast<FlexiNoteModel *>(model)) type = FileFinder::LayerFile;
1073
1074 QString path = getSaveFileName(type);
1075
1076 if (path == "") return;
1077
1078 if (QFileInfo(path).suffix() == "") path += ".svl";
1079
1080 QString suffix = QFileInfo(path).suffix().toLower();
1081
1082 QString error;
1083
1084 if (suffix == "xml" || suffix == "svl") {
1085
1086 QFile file(path);
1087 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1088 error = tr("Failed to open file %1 for writing").arg(path);
1089 } else {
1090 QTextStream out(&file);
1091 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1092 << "<!DOCTYPE sonic-visualiser>\n"
1093 << "<sv>\n"
1094 << " <data>\n";
1095
1096 model->toXml(out, " ");
1097
1098 out << " </data>\n"
1099 << " <display>\n";
1100
1101 layer->toXml(out, " ");
1102
1103 out << " </display>\n"
1104 << "</sv>\n";
1105 }
1106
1107 // } else if (suffix == "mid" || suffix == "midi") {
1108 //
1109 // FlexiNoteModel *nm = dynamic_cast<FlexiNoteModel *>(model);
1110 //
1111 // if (!nm) {
1112 // error = tr("Can't export non-note layers to MIDI");
1113 // } else {
1114 // MIDIFileWriter writer(path, nm);
1115 // writer.write();
1116 // if (!writer.isOK()) {
1117 // error = writer.getError();
1118 // }
1119 // }
1120
1121 } else if (suffix == "ttl" || suffix == "n3") {
1122
1123 if (!RDFExporter::canExportModel(model)) {
1124 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)");
1125 } else {
1126 RDFExporter exporter(path, model);
1127 exporter.write();
1128 if (!exporter.isOK()) {
1129 error = exporter.getError();
1130 }
1131 }
1132
1133 } else {
1134
1135 CSVFileWriter writer(path, model,
1136 ((suffix == "csv") ? "," : "\t"));
1137 writer.write();
1138
1139 if (!writer.isOK()) {
1140 error = writer.getError();
1141 }
1142 }
1143
1144 if (error != "") {
1145 QMessageBox::critical(this, tr("Failed to write file"), error);
1146 } else {
1147 m_recentFiles.addFile(path);
1148 emit activity(tr("Export layer to \"%1\"").arg(path));
1149 }
1150 }
1151
1152
1153 void
1045 MainWindow::renameCurrentLayer() 1154 MainWindow::renameCurrentLayer()
1046 { 1155 {
1047 Pane *pane = m_paneStack->getCurrentPane(); 1156 Pane *pane = m_paneStack->getCurrentPane();
1048 if (pane) { 1157 if (pane) {
1049 Layer *layer = pane->getSelectedLayer(); 1158 Layer *layer = pane->getSelectedLayer();