Mercurial > hg > tony
changeset 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 | |
files | src/MainWindow.cpp src/MainWindow.h |
diffstat | 2 files changed, 92 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- 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("<b>File exists</b><p>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<SparseTimeValueModel *>(layer->getModel()); + if (!model) return; + if (suffix == "xml" || suffix == "svl") { error = exportToSVL(path, layer); @@ -2301,12 +2340,24 @@ if (path == "") return; + exportNoteLayerTo(path); +} + +void +MainWindow::exportNoteLayerTo(QString path) +{ if (QFileInfo(path).suffix() == "") path += ".svl"; QString suffix = QFileInfo(path).suffix().toLower(); QString error; + Layer *layer = m_analyser->getLayer(Analyser::Notes); + if (!layer) return; + + FlexiNoteModel *model = qobject_cast<FlexiNoteModel *>(layer->getModel()); + if (!model) return; + if (suffix == "xml" || suffix == "svl") { error = exportToSVL(path, layer);
--- a/src/MainWindow.h Wed Mar 15 11:31:49 2017 +0000 +++ b/src/MainWindow.h Wed Mar 15 13:41:33 2017 +0000 @@ -32,6 +32,7 @@ virtual ~MainWindow(); signals: + void canSaveAll(bool); void canExportPitchTrack(bool); void canExportNotes(bool); void canSnapNotes(bool); @@ -49,6 +50,7 @@ virtual void saveSession(); virtual void saveSessionInAudioPath(); virtual void saveSessionAs(); + virtual void saveAll(); virtual void exportPitchLayer(); virtual void exportNoteLayer(); virtual void importPitchLayer(); @@ -242,6 +244,11 @@ virtual void auxSnapNotes(Selection s); virtual void closeEvent(QCloseEvent *e); + + bool trySaveSessionInAudioPath(); + void exportNoteLayerTo(QString path); + void exportPitchLayerTo(QString path); + bool checkSaveModified(); bool waitForInitialAnalysis();