Mercurial > hg > tony
comparison src/MainWindow.cpp @ 522:8f016d8c021a saveall
Add Save All function, as proposed by Yi Ting Tan
author | Chris Cannam |
---|---|
date | Wed, 15 Mar 2017 13:41:33 +0000 |
parents | 25aa28a27252 |
children |
comparison
equal
deleted
inserted
replaced
521:25aa28a27252 | 522:8f016d8c021a |
---|---|
442 action->setStatusTip(tr("Export note data to a CSV, RDF, layer XML, or MIDI file")); | 442 action->setStatusTip(tr("Export note data to a CSV, RDF, layer XML, or MIDI file")); |
443 connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer())); | 443 connect(action, SIGNAL(triggered()), this, SLOT(exportNoteLayer())); |
444 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool))); | 444 connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool))); |
445 menu->addAction(action); | 445 menu->addAction(action); |
446 | 446 |
447 action = new QAction(tr("Save Session and All Layers"), this); | |
448 action->setStatusTip(tr("Save the current session, pitch and note layers with the same filename as the audio but different extensions.")); | |
449 connect(action, SIGNAL(triggered()), this, SLOT(saveAll())); | |
450 connect(this, SIGNAL(canSaveAll(bool)), action, SLOT(setEnabled(bool))); | |
451 menu->addAction(action); | |
452 | |
447 menu->addSeparator(); | 453 menu->addSeparator(); |
448 | 454 |
449 action = new QAction(tr("Browse Recorded Audio"), this); | 455 action = new QAction(tr("Browse Recorded Audio"), this); |
450 action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser")); | 456 action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser")); |
451 connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio())); | 457 connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio())); |
1423 m_analyser->getLayer(Analyser::PitchTrack); | 1429 m_analyser->getLayer(Analyser::PitchTrack); |
1424 | 1430 |
1425 bool haveNotes = | 1431 bool haveNotes = |
1426 m_analyser->isVisible(Analyser::Notes) && | 1432 m_analyser->isVisible(Analyser::Notes) && |
1427 m_analyser->getLayer(Analyser::Notes); | 1433 m_analyser->getLayer(Analyser::Notes); |
1434 | |
1435 emit canSaveAll(haveMainModel && havePitchTrack && haveNotes); | |
1428 | 1436 |
1429 emit canExportPitchTrack(havePitchTrack); | 1437 emit canExportPitchTrack(havePitchTrack); |
1430 emit canExportNotes(haveNotes); | 1438 emit canExportNotes(haveNotes); |
1431 emit canSnapNotes(haveSelection && haveNotes); | 1439 emit canSnapNotes(haveSelection && haveNotes); |
1432 | 1440 |
2017 } | 2025 } |
2018 | 2026 |
2019 void | 2027 void |
2020 MainWindow::saveSessionInAudioPath() | 2028 MainWindow::saveSessionInAudioPath() |
2021 { | 2029 { |
2022 if (m_audioFile == "") return; | 2030 (void)trySaveSessionInAudioPath(); |
2023 | 2031 } |
2024 if (!waitForInitialAnalysis()) return; | 2032 |
2033 bool | |
2034 MainWindow::trySaveSessionInAudioPath() | |
2035 { | |
2036 if (m_audioFile == "") return false; | |
2037 | |
2038 if (!waitForInitialAnalysis()) return false; | |
2025 | 2039 |
2026 // We do not want to save mid-analysis regions -- that would cause | 2040 // We do not want to save mid-analysis regions -- that would cause |
2027 // confusion on reloading | 2041 // confusion on reloading |
2028 m_analyser->clearReAnalysis(); | 2042 m_analyser->clearReAnalysis(); |
2029 clearSelection(); | 2043 clearSelection(); |
2045 if (shouldVerify && QFileInfo(path).exists()) { | 2059 if (shouldVerify && QFileInfo(path).exists()) { |
2046 if (QMessageBox::question(0, tr("File exists"), | 2060 if (QMessageBox::question(0, tr("File exists"), |
2047 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path), | 2061 tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path), |
2048 QMessageBox::Ok, | 2062 QMessageBox::Ok, |
2049 QMessageBox::Cancel) != QMessageBox::Ok) { | 2063 QMessageBox::Cancel) != QMessageBox::Ok) { |
2050 return; | 2064 return false; |
2051 } | 2065 } |
2066 } | |
2067 | |
2068 if (!saveSessionFile(path)) { | |
2069 QMessageBox::critical(this, tr("Failed to save file"), | |
2070 tr("Session file \"%1\" could not be saved.").arg(path)); | |
2071 return false; | |
2072 } else { | |
2073 setWindowTitle(tr("%1: %2") | |
2074 .arg(QApplication::applicationName()) | |
2075 .arg(QFileInfo(path).fileName())); | |
2076 m_sessionFile = path; | |
2077 CommandHistory::getInstance()->documentSaved(); | |
2078 documentRestored(); | |
2079 m_recentFiles.addFile(path); | |
2080 return true; | |
2081 } | |
2082 } | |
2083 | |
2084 void | |
2085 MainWindow::saveSessionAs() | |
2086 { | |
2087 // We do not want to save mid-analysis regions -- that would cause | |
2088 // confusion on reloading | |
2089 m_analyser->clearReAnalysis(); | |
2090 clearSelection(); | |
2091 | |
2092 QString path = getSaveFileName(FileFinder::SessionFile); | |
2093 | |
2094 if (path == "") { | |
2095 return; | |
2052 } | 2096 } |
2053 | 2097 |
2054 if (!waitForInitialAnalysis()) { | 2098 if (!waitForInitialAnalysis()) { |
2055 QMessageBox::warning(this, tr("File not saved"), | 2099 QMessageBox::warning(this, tr("File not saved"), |
2056 tr("Wait cancelled: the session has not been saved.")); | 2100 tr("Wait cancelled: the session has not been saved.")); |
2101 return; | |
2057 } | 2102 } |
2058 | 2103 |
2059 if (!saveSessionFile(path)) { | 2104 if (!saveSessionFile(path)) { |
2060 QMessageBox::critical(this, tr("Failed to save file"), | 2105 QMessageBox::critical(this, tr("Failed to save file"), |
2061 tr("Session file \"%1\" could not be saved.").arg(path)); | 2106 tr("Session file \"%1\" could not be saved.").arg(path)); |
2069 m_recentFiles.addFile(path); | 2114 m_recentFiles.addFile(path); |
2070 } | 2115 } |
2071 } | 2116 } |
2072 | 2117 |
2073 void | 2118 void |
2074 MainWindow::saveSessionAs() | 2119 MainWindow::saveAll() |
2075 { | 2120 { |
2076 // We do not want to save mid-analysis regions -- that would cause | 2121 if (!trySaveSessionInAudioPath()) return; |
2077 // confusion on reloading | 2122 |
2078 m_analyser->clearReAnalysis(); | 2123 QString filepath = QFileInfo(m_audioFile).absoluteDir().canonicalPath(); |
2079 clearSelection(); | 2124 QString basename = QFileInfo(m_audioFile).completeBaseName(); |
2080 | 2125 |
2081 QString path = getSaveFileName(FileFinder::SessionFile); | 2126 QString pitchPath = QDir(filepath).filePath(basename + "_track.txt"); |
2082 | 2127 QString notesPath = QDir(filepath).filePath(basename + "_notes.txt"); |
2083 if (path == "") { | 2128 |
2084 return; | 2129 exportPitchLayerTo(pitchPath); |
2085 } | 2130 exportNoteLayerTo(notesPath); |
2086 | |
2087 if (!waitForInitialAnalysis()) { | |
2088 QMessageBox::warning(this, tr("File not saved"), | |
2089 tr("Wait cancelled: the session has not been saved.")); | |
2090 return; | |
2091 } | |
2092 | |
2093 if (!saveSessionFile(path)) { | |
2094 QMessageBox::critical(this, tr("Failed to save file"), | |
2095 tr("Session file \"%1\" could not be saved.").arg(path)); | |
2096 } else { | |
2097 setWindowTitle(tr("%1: %2") | |
2098 .arg(QApplication::applicationName()) | |
2099 .arg(QFileInfo(path).fileName())); | |
2100 m_sessionFile = path; | |
2101 CommandHistory::getInstance()->documentSaved(); | |
2102 documentRestored(); | |
2103 m_recentFiles.addFile(path); | |
2104 } | |
2105 } | 2131 } |
2106 | 2132 |
2107 QString | 2133 QString |
2108 MainWindow::exportToSVL(QString path, Layer *layer) | 2134 MainWindow::exportToSVL(QString path, Layer *layer) |
2109 { | 2135 { |
2243 | 2269 |
2244 QString path = getSaveFileName(type); | 2270 QString path = getSaveFileName(type); |
2245 | 2271 |
2246 if (path == "") return; | 2272 if (path == "") return; |
2247 | 2273 |
2274 exportPitchLayerTo(path); | |
2275 } | |
2276 | |
2277 void | |
2278 MainWindow::exportPitchLayerTo(QString path) | |
2279 { | |
2248 if (!waitForInitialAnalysis()) return; | 2280 if (!waitForInitialAnalysis()) return; |
2249 | 2281 |
2250 if (QFileInfo(path).suffix() == "") path += ".svl"; | 2282 if (QFileInfo(path).suffix() == "") path += ".svl"; |
2251 | 2283 |
2252 QString suffix = QFileInfo(path).suffix().toLower(); | 2284 QString suffix = QFileInfo(path).suffix().toLower(); |
2253 | 2285 |
2254 QString error; | 2286 QString error; |
2287 | |
2288 Layer *layer = m_analyser->getLayer(Analyser::PitchTrack); | |
2289 if (!layer) return; | |
2290 | |
2291 SparseTimeValueModel *model = | |
2292 qobject_cast<SparseTimeValueModel *>(layer->getModel()); | |
2293 if (!model) return; | |
2255 | 2294 |
2256 if (suffix == "xml" || suffix == "svl") { | 2295 if (suffix == "xml" || suffix == "svl") { |
2257 | 2296 |
2258 error = exportToSVL(path, layer); | 2297 error = exportToSVL(path, layer); |
2259 | 2298 |
2299 | 2338 |
2300 QString path = getSaveFileName(type); | 2339 QString path = getSaveFileName(type); |
2301 | 2340 |
2302 if (path == "") return; | 2341 if (path == "") return; |
2303 | 2342 |
2343 exportNoteLayerTo(path); | |
2344 } | |
2345 | |
2346 void | |
2347 MainWindow::exportNoteLayerTo(QString path) | |
2348 { | |
2304 if (QFileInfo(path).suffix() == "") path += ".svl"; | 2349 if (QFileInfo(path).suffix() == "") path += ".svl"; |
2305 | 2350 |
2306 QString suffix = QFileInfo(path).suffix().toLower(); | 2351 QString suffix = QFileInfo(path).suffix().toLower(); |
2307 | 2352 |
2308 QString error; | 2353 QString error; |
2354 | |
2355 Layer *layer = m_analyser->getLayer(Analyser::Notes); | |
2356 if (!layer) return; | |
2357 | |
2358 FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel()); | |
2359 if (!model) return; | |
2309 | 2360 |
2310 if (suffix == "xml" || suffix == "svl") { | 2361 if (suffix == "xml" || suffix == "svl") { |
2311 | 2362 |
2312 error = exportToSVL(path, layer); | 2363 error = exportToSVL(path, layer); |
2313 | 2364 |