Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
37:8cd725696138 | 38:5c20bb3e6c94 |
---|---|
1665 if (!path.endsWith(".wav")) path = path + ".wav"; | 1665 if (!path.endsWith(".wav")) path = path + ".wav"; |
1666 | 1666 |
1667 bool ok = false; | 1667 bool ok = false; |
1668 QString error; | 1668 QString error; |
1669 | 1669 |
1670 WavFileWriter *writer = 0; | |
1671 MultiSelection ms = m_viewManager->getSelection(); | 1670 MultiSelection ms = m_viewManager->getSelection(); |
1672 MultiSelection::SelectionList selections = m_viewManager->getSelections(); | 1671 MultiSelection::SelectionList selections = m_viewManager->getSelections(); |
1673 | 1672 |
1674 bool multiple = false; | 1673 bool multiple = false; |
1675 | 1674 |
1676 if (selections.empty()) { | 1675 MultiSelection *selectionToWrite = 0; |
1677 | 1676 |
1678 writer = new WavFileWriter(path, getMainModel()->getSampleRate(), | 1677 if (selections.size() == 1) { |
1679 getMainModel(), 0); | |
1680 | |
1681 } else if (selections.size() == 1) { | |
1682 | 1678 |
1683 QStringList items; | 1679 QStringList items; |
1684 items << tr("Export the selected region only") | 1680 items << tr("Export the selected region only") |
1685 << tr("Export the whole audio file"); | 1681 << tr("Export the whole audio file"); |
1686 | 1682 |
1690 tr("Which region from the original audio file do you want to export?"), | 1686 tr("Which region from the original audio file do you want to export?"), |
1691 items, 0, &ok); | 1687 items, 0, &ok); |
1692 | 1688 |
1693 if (!ok || item.isEmpty()) return; | 1689 if (!ok || item.isEmpty()) return; |
1694 | 1690 |
1695 if (item == items[0]) { | 1691 if (item == items[0]) selectionToWrite = &ms; |
1696 | 1692 |
1697 writer = new WavFileWriter(path, getMainModel()->getSampleRate(), | 1693 } else if (selections.size() > 1) { |
1698 getMainModel(), &ms); | |
1699 | |
1700 } else { | |
1701 | |
1702 writer = new WavFileWriter(path, getMainModel()->getSampleRate(), | |
1703 getMainModel(), 0); | |
1704 } | |
1705 } else { | |
1706 | 1694 |
1707 QStringList items; | 1695 QStringList items; |
1708 items << tr("Export the selected regions into a single audio file") | 1696 items << tr("Export the selected regions into a single audio file") |
1709 << tr("Export the selected regions into separate files") | 1697 << tr("Export the selected regions into separate files") |
1710 << tr("Export the whole audio file"); | 1698 << tr("Export the whole audio file"); |
1711 | 1699 |
1712 bool ok = false; | |
1713 QString item = ListInputDialog::getItem | 1700 QString item = ListInputDialog::getItem |
1714 (this, tr("Select region to export"), | 1701 (this, tr("Select region to export"), |
1715 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), | 1702 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"), |
1716 items, 0, &ok); | 1703 items, 0, &ok); |
1717 | 1704 |
1718 if (!ok || item.isEmpty()) return; | 1705 if (!ok || item.isEmpty()) return; |
1719 | 1706 |
1720 if (item == items[0]) { | 1707 if (item == items[0]) { |
1721 | 1708 |
1722 writer = new WavFileWriter(path, getMainModel()->getSampleRate(), | 1709 selectionToWrite = &ms; |
1723 getMainModel(), &ms); | 1710 |
1724 | 1711 } else if (item == items[1]) { |
1725 } else if (item == items[2]) { | |
1726 | |
1727 writer = new WavFileWriter(path, getMainModel()->getSampleRate(), | |
1728 getMainModel(), 0); | |
1729 | |
1730 } else { | |
1731 | 1712 |
1732 multiple = true; | 1713 multiple = true; |
1733 | 1714 |
1734 int n = 1; | 1715 int n = 1; |
1735 QString base = path; | 1716 QString base = path; |
1747 if (QFileInfo(subpath).exists()) { | 1728 if (QFileInfo(subpath).exists()) { |
1748 error = tr("Fragment file %1 already exists, aborting").arg(subpath); | 1729 error = tr("Fragment file %1 already exists, aborting").arg(subpath); |
1749 break; | 1730 break; |
1750 } | 1731 } |
1751 | 1732 |
1752 WavFileWriter subwriter(subpath, getMainModel()->getSampleRate(), | 1733 WavFileWriter subwriter(subpath, |
1753 getMainModel(), &subms); | 1734 getMainModel()->getSampleRate(), |
1754 subwriter.write(); | 1735 getMainModel()->getChannelCount()); |
1736 subwriter.writeModel(getMainModel(), &subms); | |
1755 ok = subwriter.isOK(); | 1737 ok = subwriter.isOK(); |
1756 | 1738 |
1757 if (!ok) { | 1739 if (!ok) { |
1758 error = subwriter.getError(); | 1740 error = subwriter.getError(); |
1759 break; | 1741 break; |
1760 } | 1742 } |
1761 } | 1743 } |
1762 } | 1744 } |
1763 } | 1745 } |
1764 | 1746 |
1765 if (writer) { | 1747 if (!multiple) { |
1766 writer->write(); | 1748 WavFileWriter writer(path, |
1767 ok = writer->isOK(); | 1749 getMainModel()->getSampleRate(), |
1768 error = writer->getError(); | 1750 getMainModel()->getChannelCount()); |
1769 delete writer; | 1751 writer.writeModel(getMainModel(), selectionToWrite); |
1752 ok = writer.isOK(); | |
1753 error = writer.getError(); | |
1770 } | 1754 } |
1771 | 1755 |
1772 if (ok) { | 1756 if (ok) { |
1773 if (!multiple) { | 1757 if (!multiple) { |
1774 m_recentFiles.addFile(path); | 1758 m_recentFiles.addFile(path); |