# HG changeset patch # User Chris Cannam # Date 1536764379 -3600 # Node ID 64dbd75b9296d779aeebef40d697faa0d337c134 # Parent b316a89ec6a61b634ce3a5dcfd6075ac7231889b# Parent 417bf3d64215d4da2bbe0f3c801cc58b18fbb4b3 Merge from branch import-audio-data diff -r b316a89ec6a6 -r 64dbd75b9296 main/MainWindow.cpp --- a/main/MainWindow.cpp Tue Sep 04 11:33:36 2018 +0100 +++ b/main/MainWindow.cpp Wed Sep 12 15:59:39 2018 +0100 @@ -32,6 +32,7 @@ #include "view/ViewManager.h" #include "base/Preferences.h" #include "base/ResourceFinder.h" +#include "base/RecordDirectory.h" #include "layer/WaveformLayer.h" #include "layer/TimeRulerLayer.h" #include "layer/TimeInstantLayer.h" @@ -59,6 +60,7 @@ #include "widgets/ActivityLog.h" #include "widgets/UnitConverter.h" #include "widgets/ProgressDialog.h" +#include "widgets/CSVAudioFormatDialog.h" #include "audio/AudioCallbackPlaySource.h" #include "audio/AudioCallbackRecordTarget.h" #include "audio/PlaySpeedRangeMapper.h" @@ -564,16 +566,6 @@ menu->addSeparator(); -/* - icon = il.load("fileopenaudio"); - action = new QAction(icon, tr("&Import Audio File..."), this); - action->setShortcut(tr("Ctrl+I")); - action->setStatusTip(tr("Import an existing audio file")); - connect(action, SIGNAL(triggered()), this, SLOT(importAudio())); - m_keyReference->registerShortcut(action); - menu->addAction(action); -*/ - // the Replace action we made earlier menu->addAction(raction); @@ -586,12 +578,6 @@ connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); menu->addAction(action); - action = new QAction(tr("Export Audio Data..."), this); - action->setStatusTip(tr("Export audio from selection into a data file")); - connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); - connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); - menu->addAction(action); - menu->addSeparator(); action = new QAction(tr("Import Annotation &Layer..."), this); @@ -611,6 +597,19 @@ menu->addAction(action); menu->addSeparator(); + + action = new QAction(tr("Convert Audio from Data File..."), this); + action->setStatusTip(tr("Convert and import audio sample values from a CSV data file")); + connect(action, SIGNAL(triggered()), this, SLOT(convertAudio())); + menu->addAction(action); + + action = new QAction(tr("Export Audio to Data File..."), this); + action->setStatusTip(tr("Export audio from selection into a CSV data file")); + connect(action, SIGNAL(triggered()), this, SLOT(exportAudioData())); + connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool))); + menu->addAction(action); + + menu->addSeparator(); action = new QAction(tr("Export Image File..."), this); action->setStatusTip(tr("Export a single pane to an image file")); @@ -626,7 +625,7 @@ menu->addSeparator(); - action = new QAction(tr("Browse Recorded Audio Folder"), this); + action = new QAction(tr("Browse Recorded and Converted Audio"), this); action->setStatusTip(tr("Open the Recorded Audio folder in the system file browser")); connect(action, SIGNAL(triggered()), this, SLOT(browseRecordedAudio())); menu->addAction(action); @@ -2878,6 +2877,69 @@ } void +MainWindow::convertAudio() +{ + QString path = getOpenFileName(FileFinder::CSVFile); + if (path == "") return; + + sv_samplerate_t defaultRate = 44100; + + CSVFormat format(path); + format.setModelType(CSVFormat::WaveFileModel); + format.setTimingType(CSVFormat::ImplicitTiming); + format.setTimeUnits(CSVFormat::TimeAudioFrames); + format.setSampleRate(defaultRate); // as a default for the dialog + + { + CSVAudioFormatDialog *dialog = new CSVAudioFormatDialog(this, format); + if (dialog->exec() != QDialog::Accepted) { + delete dialog; + return; + } + format = dialog->getFormat(); + delete dialog; + } + + FileOpenStatus status = FileOpenSucceeded; + + ProgressDialog *progress = new ProgressDialog + (tr("Importing audio data..."), true, 0, this, Qt::ApplicationModal); + + WaveFileModel *model = qobject_cast + (DataFileReaderFactory::loadCSV + (path, format, + getMainModel() ? getMainModel()->getSampleRate() : defaultRate, + progress)); + + if (progress->wasCancelled()) { + + delete model; + status = FileOpenCancelled; + + } else if (!model || !model->isOK()) { + + delete model; + status = FileOpenFailed; + + } else { + + status = addOpenedAudioModel(path, + model, + CreateAdditionalModel, + getDefaultSessionTemplate(), + false); + } + + delete progress; + + if (status == FileOpenFailed) { + emit hideSplash(); + QMessageBox::critical(this, tr("Failed to open file"), + tr("File open failed

Audio data file %1 could not be opened.").arg(path)); + } +} + +void MainWindow::importLayer() { Pane *pane = m_paneStack->getCurrentPane(); @@ -3168,8 +3230,8 @@ { if (!m_recordTarget) return; - QString path = m_recordTarget->getRecordContainerFolder(); - if (path == "") path = m_recordTarget->getRecordFolder(); + QString path = RecordDirectory::getRecordContainerDirectory(); + if (path == "") path = RecordDirectory::getRecordDirectory(); if (path == "") return; openLocalFolder(path); diff -r b316a89ec6a6 -r 64dbd75b9296 main/MainWindow.h --- a/main/MainWindow.h Tue Sep 04 11:33:36 2018 +0100 +++ b/main/MainWindow.h Wed Sep 12 15:59:39 2018 +0100 @@ -60,6 +60,7 @@ virtual void applyTemplate(); virtual void exportAudio(); virtual void exportAudioData(); + virtual void convertAudio(); virtual void importLayer(); virtual void exportLayer(); virtual void exportImage(); diff -r b316a89ec6a6 -r 64dbd75b9296 repoint-lock.json --- a/repoint-lock.json Tue Sep 04 11:33:36 2018 +0100 +++ b/repoint-lock.json Wed Sep 12 15:59:39 2018 +0100 @@ -4,13 +4,13 @@ "pin": "da86fb0bccb3" }, "svcore": { - "pin": "a250a54c11cc" + "pin": "b7cb203ee344" }, "svgui": { - "pin": "c0d8356e274f" + "pin": "8068a0bee550" }, "svapp": { - "pin": "e98a42e94d90" + "pin": "9e15607531b2" }, "checker": { "pin": "2e8a5f665a07" diff -r b316a89ec6a6 -r 64dbd75b9296 repoint-project.json --- a/repoint-project.json Tue Sep 04 11:33:36 2018 +0100 +++ b/repoint-project.json Wed Sep 12 15:59:39 2018 +0100 @@ -24,7 +24,7 @@ }, "svapp": { "vcs": "hg", - "service": "soundsoftware" + "service": "soundsoftware" }, "checker": { "vcs": "hg",