Mercurial > hg > sonic-visualiser
changeset 38:5c20bb3e6c94
* Restructure WavFileWriter a bit to permit writing from raw data as well as
from an existing model
author | Chris Cannam |
---|---|
date | Tue, 03 Oct 2006 10:06:37 +0000 |
parents | 8cd725696138 |
children | f18093617b78 |
files | main/MainWindow.cpp |
diffstat | 1 files changed, 20 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/main/MainWindow.cpp Mon Sep 25 12:05:41 2006 +0000 +++ b/main/MainWindow.cpp Tue Oct 03 10:06:37 2006 +0000 @@ -1667,18 +1667,14 @@ bool ok = false; QString error; - WavFileWriter *writer = 0; MultiSelection ms = m_viewManager->getSelection(); MultiSelection::SelectionList selections = m_viewManager->getSelections(); bool multiple = false; - if (selections.empty()) { - - writer = new WavFileWriter(path, getMainModel()->getSampleRate(), - getMainModel(), 0); - - } else if (selections.size() == 1) { + MultiSelection *selectionToWrite = 0; + + if (selections.size() == 1) { QStringList items; items << tr("Export the selected region only") @@ -1692,24 +1688,15 @@ if (!ok || item.isEmpty()) return; - if (item == items[0]) { - - writer = new WavFileWriter(path, getMainModel()->getSampleRate(), - getMainModel(), &ms); - - } else { - - writer = new WavFileWriter(path, getMainModel()->getSampleRate(), - getMainModel(), 0); - } - } else { + if (item == items[0]) selectionToWrite = &ms; + + } 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"); - bool ok = false; 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?"), @@ -1719,15 +1706,9 @@ if (item == items[0]) { - writer = new WavFileWriter(path, getMainModel()->getSampleRate(), - getMainModel(), &ms); - - } else if (item == items[2]) { - - writer = new WavFileWriter(path, getMainModel()->getSampleRate(), - getMainModel(), 0); - - } else { + selectionToWrite = &ms; + + } else if (item == items[1]) { multiple = true; @@ -1749,9 +1730,10 @@ break; } - WavFileWriter subwriter(subpath, getMainModel()->getSampleRate(), - getMainModel(), &subms); - subwriter.write(); + WavFileWriter subwriter(subpath, + getMainModel()->getSampleRate(), + getMainModel()->getChannelCount()); + subwriter.writeModel(getMainModel(), &subms); ok = subwriter.isOK(); if (!ok) { @@ -1762,11 +1744,13 @@ } } - if (writer) { - writer->write(); - ok = writer->isOK(); - error = writer->getError(); - delete writer; + if (!multiple) { + WavFileWriter writer(path, + getMainModel()->getSampleRate(), + getMainModel()->getChannelCount()); + writer.writeModel(getMainModel(), selectionToWrite); + ok = writer.isOK(); + error = writer.getError(); } if (ok) {