Mercurial > hg > sonic-visualiser
changeset 631:2484381b53a1
Add "Export Audio Data" to export audio waveform data into CSV or similar
author | Chris Cannam |
---|---|
date | Wed, 09 Oct 2013 14:56:48 +0100 |
parents | 9680e1056ac6 |
children | 2b5be7b71f88 |
files | .hgsubstate main/MainWindow.cpp main/MainWindow.h |
diffstat | 3 files changed, 75 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Tue Oct 01 11:18:54 2013 +0100 +++ b/.hgsubstate Wed Oct 09 14:56:48 2013 +0100 @@ -1,4 +1,4 @@ 236814e07bd07473958c1ff89103124536a0c3c8 dataquay -2925a4bbca5e86036d564aaac1bcf7fd11226ca9 svapp -1d439494604c3237775c3a18e4edb7e0c1fdc2d6 svcore -0aea4b9e4c3dca9c42f9181748bdfde924a8574f svgui +3fc0df28953377c96e501f41db6fb80d29d6aa4a svapp +38bb7c8e415d488ddb7786ab177a44d9f183e6ab svcore +b5d3dea6d869898c0996d7aa2f8b03747ebb3926 svgui
--- a/main/MainWindow.cpp Tue Oct 01 11:18:54 2013 +0100 +++ b/main/MainWindow.cpp Wed Oct 09 14:56:48 2013 +0100 @@ -525,6 +525,12 @@ 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); @@ -2338,6 +2344,18 @@ void MainWindow::exportAudio() { + exportAudio(false); +} + +void +MainWindow::exportAudioData() +{ + exportAudio(true); +} + +void +MainWindow::exportAudio(bool asData) +{ if (!getMainModel()) return; RangeSummarisableTimeValueModel *model = getMainModel(); @@ -2399,7 +2417,12 @@ } } - QString path = getSaveFileName(FileFinder::AudioFile); + QString path; + if (asData) { + path = getSaveFileName(FileFinder::CSVFile); + } else { + path = getSaveFileName(FileFinder::AudioFile); + } if (path == "") return; bool ok = false; @@ -2430,25 +2453,33 @@ } else if (selections.size() > 1) { - QStringList items; - items << tr("Export the selected regions into a single audio file") - << tr("Export the selected regions into separate files") - << tr("Export the whole audio file"); - - QString item = ListInputDialog::getItem - (this, tr("Select region to export"), - tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), - items, 0, &ok); + bool multiple = false; + + if (!asData) { // Multi-file export not supported for data + + QStringList items; + items << tr("Export the selected regions into a single file") + << tr("Export the selected regions into separate files") + << tr("Export the whole file"); + + QString item = ListInputDialog::getItem + (this, tr("Select region to export"), + tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), + items, 0, &ok); - if (!ok || item.isEmpty()) return; - - if (item == items[0]) { - + if (!ok || item.isEmpty()) return; + + if (item == items[0]) { + selectionToWrite = &ms; + } else if (item == items[1]) { + multiple = true; + } + + } else { // asData selectionToWrite = &ms; - - } else if (item == items[1]) { - - multiple = true; + } + + if (multiple) { // Can only happen when asData false int n = 1; QString base = path; @@ -2484,13 +2515,26 @@ } if (!multiple) { - WavFileWriter writer(path, - model->getSampleRate(), - model->getChannelCount(), - WavFileWriter::WriteToTemporary); - writer.writeModel(model, selectionToWrite); - ok = writer.isOK(); - error = writer.getError(); + if (asData) { + CSVFileWriter writer(path, model, + ((QFileInfo(path).suffix() == "csv") ? + "," : "\t")); + if (selectionToWrite) { + writer.writeSelection(selectionToWrite); + } else { + writer.write(); + } + ok = writer.isOK(); + error = writer.getError(); + } else { + WavFileWriter writer(path, + model->getSampleRate(), + model->getChannelCount(), + WavFileWriter::WriteToTemporary); + writer.writeModel(model, selectionToWrite); + ok = writer.isOK(); + error = writer.getError(); + } } if (ok) {
--- a/main/MainWindow.h Tue Oct 01 11:18:54 2013 +0100 +++ b/main/MainWindow.h Wed Oct 09 14:56:48 2013 +0100 @@ -92,6 +92,7 @@ virtual void openRecentFile(); virtual void applyTemplate(); virtual void exportAudio(); + virtual void exportAudioData(); virtual void importLayer(); virtual void exportLayer(); virtual void exportImage(); @@ -297,6 +298,8 @@ virtual void closeEvent(QCloseEvent *e); virtual bool checkSaveModified(); + virtual void exportAudio(bool asData); + virtual void updateVisibleRangeDisplay(Pane *p) const; virtual void updatePositionStatusDisplays() const;