comparison main/MainWindow.cpp @ 320:dfb586b4d50d

* Very crudely, add an option for the audio file to be exported from when exporting audio
author Chris Cannam
date Tue, 24 Mar 2009 17:27:40 +0000
parents 75c3ab874c8e
children cf4e9827968b
comparison
equal deleted inserted replaced
319:cb189d3816e5 320:dfb586b4d50d
2089 void 2089 void
2090 MainWindow::exportAudio() 2090 MainWindow::exportAudio()
2091 { 2091 {
2092 if (!getMainModel()) return; 2092 if (!getMainModel()) return;
2093 2093
2094 RangeSummarisableTimeValueModel *model = getMainModel();
2095 std::set<RangeSummarisableTimeValueModel *> otherModels;
2096 RangeSummarisableTimeValueModel *current = model;
2097 if (m_paneStack) {
2098 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
2099 Pane *pane = m_paneStack->getPane(i);
2100 if (!pane) continue;
2101 for (int j = 0; j < pane->getLayerCount(); ++j) {
2102 Layer *layer = pane->getLayer(j);
2103 if (!layer) continue;
2104 cerr << "layer = " << layer->objectName().toStdString() << endl;
2105 Model *m = layer->getModel();
2106 RangeSummarisableTimeValueModel *wm =
2107 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
2108 if (wm) {
2109 cerr << "found: " << wm->objectName().toStdString() << endl;
2110 otherModels.insert(wm);
2111 if (pane == m_paneStack->getCurrentPane()) {
2112 current = wm;
2113 }
2114 }
2115 }
2116 }
2117 }
2118 if (!otherModels.empty()) {
2119 std::map<QString, RangeSummarisableTimeValueModel *> m;
2120 m[tr("1. %2").arg(model->objectName())] = model;
2121 int n = 2;
2122 int c = 0;
2123 for (std::set<RangeSummarisableTimeValueModel *>::const_iterator i
2124 = otherModels.begin();
2125 i != otherModels.end(); ++i) {
2126 if (*i == model) continue;
2127 m[tr("%1. %2").arg(n).arg((*i)->objectName())] = *i;
2128 ++n;
2129 if (*i == current) c = n-1;
2130 }
2131 QStringList items;
2132 for (std::map<QString, RangeSummarisableTimeValueModel *>
2133 ::const_iterator i = m.begin();
2134 i != m.end(); ++i) {
2135 items << i->first;
2136 }
2137 bool ok = false;
2138 QString item = QInputDialog::getItem
2139 (this, tr("Select audio file to export"),
2140 tr("Which audio file do you want to export from?"),
2141 items, c, false, &ok);
2142 if (!ok || item.isEmpty()) return;
2143 if (m.find(item) == m.end()) {
2144 cerr << "WARNING: Model " << item.toStdString()
2145 << " not found in list!" << endl;
2146 } else {
2147 model = m[item];
2148 }
2149 }
2150
2094 QString path = getSaveFileName(FileFinder::AudioFile); 2151 QString path = getSaveFileName(FileFinder::AudioFile);
2095
2096 if (path == "") return; 2152 if (path == "") return;
2097 2153
2098 bool ok = false; 2154 bool ok = false;
2099 QString error; 2155 QString error;
2100 2156
2160 error = tr("Fragment file %1 already exists, aborting").arg(subpath); 2216 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
2161 break; 2217 break;
2162 } 2218 }
2163 2219
2164 WavFileWriter subwriter(subpath, 2220 WavFileWriter subwriter(subpath,
2165 getMainModel()->getSampleRate(), 2221 model->getSampleRate(),
2166 getMainModel()->getChannelCount()); 2222 model->getChannelCount());
2167 subwriter.writeModel(getMainModel(), &subms); 2223 subwriter.writeModel(model, &subms);
2168 ok = subwriter.isOK(); 2224 ok = subwriter.isOK();
2169 2225
2170 if (!ok) { 2226 if (!ok) {
2171 error = subwriter.getError(); 2227 error = subwriter.getError();
2172 break; 2228 break;
2175 } 2231 }
2176 } 2232 }
2177 2233
2178 if (!multiple) { 2234 if (!multiple) {
2179 WavFileWriter writer(path, 2235 WavFileWriter writer(path,
2180 getMainModel()->getSampleRate(), 2236 model->getSampleRate(),
2181 getMainModel()->getChannelCount()); 2237 model->getChannelCount());
2182 writer.writeModel(getMainModel(), selectionToWrite); 2238 writer.writeModel(model, selectionToWrite);
2183 ok = writer.isOK(); 2239 ok = writer.isOK();
2184 error = writer.getError(); 2240 error = writer.getError();
2185 } 2241 }
2186 2242
2187 if (ok) { 2243 if (ok) {