Mercurial > hg > tony
comparison src/MainWindow.cpp @ 85:ca570861c105
Note and pitch track export functions
author | Chris Cannam |
---|---|
date | Mon, 02 Dec 2013 17:12:59 +0000 |
parents | 170c334c54b9 |
children | 66a60668c31c |
comparison
equal
deleted
inserted
replaced
84:0cbe560f0fa1 | 85:ca570861c105 |
---|---|
284 setupRecentFilesMenu(); | 284 setupRecentFilesMenu(); |
285 connect(&m_recentFiles, SIGNAL(recentChanged()), | 285 connect(&m_recentFiles, SIGNAL(recentChanged()), |
286 this, SLOT(setupRecentFilesMenu())); | 286 this, SLOT(setupRecentFilesMenu())); |
287 | 287 |
288 menu->addSeparator(); | 288 menu->addSeparator(); |
289 action = new QAction(tr("Export Annotation Layer..."), this); | 289 action = new QAction(tr("Export Pitch Track Data..."), this); |
290 action->setStatusTip(tr("Export layer data to a file")); | 290 action->setStatusTip(tr("Export pitch-track data to a file")); |
291 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer())); | 291 connect(action, SIGNAL(triggered()), this, SLOT(exportPitchLayer())); |
292 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool))); | |
293 menu->addAction(action); | |
294 | |
295 action = new QAction(tr("Export Note Data..."), this); | |
296 action->setStatusTip(tr("Export note data to a file")); | |
297 connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer())); | |
292 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool))); | 298 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool))); |
293 menu->addAction(action); | 299 menu->addAction(action); |
294 | 300 |
295 menu->addSeparator(); | 301 menu->addSeparator(); |
296 action = new QAction(il.load("exit"), tr("&Quit"), this); | 302 action = new QAction(il.load("exit"), tr("&Quit"), this); |
1113 QString path = getSaveFileName(FileFinder::SessionFile); | 1119 QString path = getSaveFileName(FileFinder::SessionFile); |
1114 | 1120 |
1115 if (path == "") return; | 1121 if (path == "") return; |
1116 | 1122 |
1117 if (!saveSessionFile(path)) { | 1123 if (!saveSessionFile(path)) { |
1118 QMessageBox::critical(this, tr("Failed to save file"), | 1124 QMessageBox::critical(this, tr("Failed to save file"), |
1119 tr("Session file \"%1\" could not be saved.").arg(path)); | 1125 tr("Session file \"%1\" could not be saved.").arg(path)); |
1120 } else { | 1126 } else { |
1121 setWindowTitle(tr("%1: %2") | 1127 setWindowTitle(tr("%1: %2") |
1122 .arg(QApplication::applicationName()) | 1128 .arg(QApplication::applicationName()) |
1123 .arg(QFileInfo(path).fileName())); | 1129 .arg(QFileInfo(path).fileName())); |
1124 m_sessionFile = path; | 1130 m_sessionFile = path; |
1125 CommandHistory::getInstance()->documentSaved(); | 1131 CommandHistory::getInstance()->documentSaved(); |
1126 documentRestored(); | 1132 documentRestored(); |
1127 m_recentFiles.addFile(path); | 1133 m_recentFiles.addFile(path); |
1128 } | 1134 } |
1129 } | 1135 } |
1130 | 1136 |
1131 void | 1137 QString |
1132 MainWindow::exportLayer() | 1138 MainWindow::exportToSVL(QString path, Layer *layer) |
1133 { | 1139 { |
1134 Pane *pane = m_paneStack->getCurrentPane(); | 1140 Model *model = layer->getModel(); |
1135 if (!pane) return; | 1141 |
1136 | 1142 QFile file(path); |
1137 Layer *layer = pane->getSelectedLayer(); | 1143 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { |
1144 return tr("Failed to open file %1 for writing").arg(path); | |
1145 } else { | |
1146 QTextStream out(&file); | |
1147 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
1148 << "<!DOCTYPE sonic-visualiser>\n" | |
1149 << "<sv>\n" | |
1150 << " <data>\n"; | |
1151 | |
1152 model->toXml(out, " "); | |
1153 | |
1154 out << " </data>\n" | |
1155 << " <display>\n"; | |
1156 | |
1157 layer->toXml(out, " "); | |
1158 | |
1159 out << " </display>\n" | |
1160 << "</sv>\n"; | |
1161 | |
1162 return ""; | |
1163 } | |
1164 } | |
1165 | |
1166 void | |
1167 MainWindow::exportPitchLayer() | |
1168 { | |
1169 Layer *layer = 0; | |
1170 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | |
1171 Pane *pane = m_paneStack->getPane(i); | |
1172 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
1173 layer = qobject_cast<TimeValueLayer *>(pane->getLayer(j)); | |
1174 if (layer) break; | |
1175 } | |
1176 if (layer) break; | |
1177 } | |
1178 | |
1138 if (!layer) return; | 1179 if (!layer) return; |
1139 | 1180 |
1140 Model *model = layer->getModel(); | 1181 SparseTimeValueModel *model = |
1182 qobject_cast<SparseTimeValueModel *>(layer->getModel()); | |
1141 if (!model) return; | 1183 if (!model) return; |
1142 | 1184 |
1143 FileFinder::FileType type = FileFinder::LayerFileNoMidi; | 1185 FileFinder::FileType type = FileFinder::LayerFileNoMidi; |
1144 | 1186 |
1145 if (dynamic_cast<FlexiNoteModel *>(model)) type = FileFinder::LayerFile; | |
1146 | |
1147 QString path = getSaveFileName(type); | 1187 QString path = getSaveFileName(type); |
1148 | 1188 |
1149 if (path == "") return; | 1189 if (path == "") return; |
1150 | 1190 |
1151 if (QFileInfo(path).suffix() == "") path += ".svl"; | 1191 if (QFileInfo(path).suffix() == "") path += ".svl"; |
1154 | 1194 |
1155 QString error; | 1195 QString error; |
1156 | 1196 |
1157 if (suffix == "xml" || suffix == "svl") { | 1197 if (suffix == "xml" || suffix == "svl") { |
1158 | 1198 |
1159 QFile file(path); | 1199 error = exportToSVL(path, layer); |
1160 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | 1200 |
1161 error = tr("Failed to open file %1 for writing").arg(path); | 1201 } else if (suffix == "ttl" || suffix == "n3") { |
1162 } else { | 1202 |
1163 QTextStream out(&file); | 1203 RDFExporter exporter(path, model); |
1164 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | 1204 exporter.write(); |
1165 << "<!DOCTYPE sonic-visualiser>\n" | 1205 if (!exporter.isOK()) { |
1166 << "<sv>\n" | 1206 error = exporter.getError(); |
1167 << " <data>\n"; | |
1168 | |
1169 model->toXml(out, " "); | |
1170 | |
1171 out << " </data>\n" | |
1172 << " <display>\n"; | |
1173 | |
1174 layer->toXml(out, " "); | |
1175 | |
1176 out << " </display>\n" | |
1177 << "</sv>\n"; | |
1178 } | 1207 } |
1179 | 1208 |
1180 // } else if (suffix == "mid" || suffix == "midi") { | 1209 } else { |
1181 // | 1210 |
1182 // FlexiNoteModel *nm = dynamic_cast<FlexiNoteModel *>(model); | 1211 CSVFileWriter writer(path, model, |
1183 // | 1212 ((suffix == "csv") ? "," : "\t")); |
1184 // if (!nm) { | 1213 writer.write(); |
1185 // error = tr("Can't export non-note layers to MIDI"); | 1214 |
1186 // } else { | 1215 if (!writer.isOK()) { |
1187 // MIDIFileWriter writer(path, nm); | 1216 error = writer.getError(); |
1188 // writer.write(); | 1217 } |
1189 // if (!writer.isOK()) { | 1218 } |
1190 // error = writer.getError(); | 1219 |
1191 // } | 1220 if (error != "") { |
1192 // } | 1221 QMessageBox::critical(this, tr("Failed to write file"), error); |
1222 } else { | |
1223 m_recentFiles.addFile(path); | |
1224 emit activity(tr("Export layer to \"%1\"").arg(path)); | |
1225 } | |
1226 } | |
1227 | |
1228 void | |
1229 MainWindow::exportNoteLayer() | |
1230 { | |
1231 Layer *layer = 0; | |
1232 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | |
1233 Pane *pane = m_paneStack->getPane(i); | |
1234 for (int j = 0; j < pane->getLayerCount(); ++j) { | |
1235 layer = qobject_cast<FlexiNoteLayer *>(pane->getLayer(j)); | |
1236 if (layer) break; | |
1237 } | |
1238 if (layer) break; | |
1239 } | |
1240 | |
1241 if (!layer) return; | |
1242 | |
1243 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel()); | |
1244 if (!model) return; | |
1245 | |
1246 FileFinder::FileType type = FileFinder::LayerFile; | |
1247 | |
1248 QString path = getSaveFileName(type); | |
1249 | |
1250 if (path == "") return; | |
1251 | |
1252 if (QFileInfo(path).suffix() == "") path += ".svl"; | |
1253 | |
1254 QString suffix = QFileInfo(path).suffix().toLower(); | |
1255 | |
1256 QString error; | |
1257 | |
1258 if (suffix == "xml" || suffix == "svl") { | |
1259 | |
1260 error = exportToSVL(path, layer); | |
1261 | |
1262 } else if (suffix == "mid" || suffix == "midi") { | |
1263 | |
1264 MIDIFileWriter writer(path, model, model->getSampleRate()); | |
1265 writer.write(); | |
1266 if (!writer.isOK()) { | |
1267 error = writer.getError(); | |
1268 } | |
1193 | 1269 |
1194 } else if (suffix == "ttl" || suffix == "n3") { | 1270 } else if (suffix == "ttl" || suffix == "n3") { |
1195 | 1271 |
1196 if (!RDFExporter::canExportModel(model)) { | 1272 RDFExporter exporter(path, model); |
1197 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)"); | 1273 exporter.write(); |
1198 } else { | 1274 if (!exporter.isOK()) { |
1199 RDFExporter exporter(path, model); | 1275 error = exporter.getError(); |
1200 exporter.write(); | |
1201 if (!exporter.isOK()) { | |
1202 error = exporter.getError(); | |
1203 } | |
1204 } | 1276 } |
1205 | 1277 |
1206 } else { | 1278 } else { |
1207 | 1279 |
1208 CSVFileWriter writer(path, model, | 1280 CSVFileWriter writer(path, model, |