# HG changeset patch # User Chris Cannam # Date 1489585293 0 # Node ID 8f016d8c021a55e25de67143680c104899ac0e10 # Parent 25aa28a2725251b464a9a781d58fa3f4acca8e40 Add Save All function, as proposed by Yi Ting Tan diff -r 25aa28a27252 -r 8f016d8c021a src/MainWindow.cpp --- a/src/MainWindow.cpp Wed Mar 15 11:31:49 2017 +0000 +++ b/src/MainWindow.cpp Wed Mar 15 13:41:33 2017 +0000 @@ -444,6 +444,12 @@ connect(this, SIGNAL(canExportNotes(bool)), action, SLOT(setEnabled(bool))); menu->addAction(action); + action = new QAction(tr("Save Session and All Layers"), this); + action->setStatusTip(tr("Save the current session, pitch and note layers with the same filename as the audio but different extensions.")); + connect(action, SIGNAL(triggered()), this, SLOT(saveAll())); + connect(this, SIGNAL(canSaveAll(bool)), action, SLOT(setEnabled(bool))); + menu->addAction(action); + menu->addSeparator(); action = new QAction(tr("Browse Recorded Audio"), this); @@ -1426,6 +1432,8 @@ m_analyser->isVisible(Analyser::Notes) && m_analyser->getLayer(Analyser::Notes); + emit canSaveAll(haveMainModel && havePitchTrack && haveNotes); + emit canExportPitchTrack(havePitchTrack); emit canExportNotes(haveNotes); emit canSnapNotes(haveSelection && haveNotes); @@ -2019,9 +2027,15 @@ void MainWindow::saveSessionInAudioPath() { - if (m_audioFile == "") return; - - if (!waitForInitialAnalysis()) return; + (void)trySaveSessionInAudioPath(); +} + +bool +MainWindow::trySaveSessionInAudioPath() +{ + if (m_audioFile == "") return false; + + if (!waitForInitialAnalysis()) return false; // We do not want to save mid-analysis regions -- that would cause // confusion on reloading @@ -2047,13 +2061,44 @@ tr("File exists
The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
QMessageBox::Ok,
QMessageBox::Cancel) != QMessageBox::Ok) {
- return;
+ return false;
}
}
+ if (!saveSessionFile(path)) {
+ QMessageBox::critical(this, tr("Failed to save file"),
+ tr("Session file \"%1\" could not be saved.").arg(path));
+ return false;
+ } else {
+ setWindowTitle(tr("%1: %2")
+ .arg(QApplication::applicationName())
+ .arg(QFileInfo(path).fileName()));
+ m_sessionFile = path;
+ CommandHistory::getInstance()->documentSaved();
+ documentRestored();
+ m_recentFiles.addFile(path);
+ return true;
+ }
+}
+
+void
+MainWindow::saveSessionAs()
+{
+ // We do not want to save mid-analysis regions -- that would cause
+ // confusion on reloading
+ m_analyser->clearReAnalysis();
+ clearSelection();
+
+ QString path = getSaveFileName(FileFinder::SessionFile);
+
+ if (path == "") {
+ return;
+ }
+
if (!waitForInitialAnalysis()) {
QMessageBox::warning(this, tr("File not saved"),
tr("Wait cancelled: the session has not been saved."));
+ return;
}
if (!saveSessionFile(path)) {
@@ -2071,37 +2116,18 @@
}
void
-MainWindow::saveSessionAs()
+MainWindow::saveAll()
{
- // We do not want to save mid-analysis regions -- that would cause
- // confusion on reloading
- m_analyser->clearReAnalysis();
- clearSelection();
-
- QString path = getSaveFileName(FileFinder::SessionFile);
-
- if (path == "") {
- return;
- }
-
- if (!waitForInitialAnalysis()) {
- QMessageBox::warning(this, tr("File not saved"),
- tr("Wait cancelled: the session has not been saved."));
- return;
- }
-
- if (!saveSessionFile(path)) {
- QMessageBox::critical(this, tr("Failed to save file"),
- tr("Session file \"%1\" could not be saved.").arg(path));
- } else {
- setWindowTitle(tr("%1: %2")
- .arg(QApplication::applicationName())
- .arg(QFileInfo(path).fileName()));
- m_sessionFile = path;
- CommandHistory::getInstance()->documentSaved();
- documentRestored();
- m_recentFiles.addFile(path);
- }
+ if (!trySaveSessionInAudioPath()) return;
+
+ QString filepath = QFileInfo(m_audioFile).absoluteDir().canonicalPath();
+ QString basename = QFileInfo(m_audioFile).completeBaseName();
+
+ QString pitchPath = QDir(filepath).filePath(basename + "_track.txt");
+ QString notesPath = QDir(filepath).filePath(basename + "_notes.txt");
+
+ exportPitchLayerTo(pitchPath);
+ exportNoteLayerTo(notesPath);
}
QString
@@ -2245,6 +2271,12 @@
if (path == "") return;
+ exportPitchLayerTo(path);
+}
+
+void
+MainWindow::exportPitchLayerTo(QString path)
+{
if (!waitForInitialAnalysis()) return;
if (QFileInfo(path).suffix() == "") path += ".svl";
@@ -2253,6 +2285,13 @@
QString error;
+ Layer *layer = m_analyser->getLayer(Analyser::PitchTrack);
+ if (!layer) return;
+
+ SparseTimeValueModel *model =
+ qobject_cast