comparison audioio/AudioGenerator.cpp @ 29:dd2084d32652

* Create temporary directory, cleaned up on exit, and use it to store (inter alia) audio samples for the sample-player plugin. * Ensure newly added layers always have unique names * Make sure configure pairs for real-time plugins are stored in the configuration Xml along with parameter & program settings
author Chris Cannam
date Mon, 10 Apr 2006 13:52:32 +0000
parents cc48a7189152
children f38b8abd3540
comparison
equal deleted inserted replaced
28:ca4ee67b2358 29:dd2084d32652
30 #include "plugin/api/alsa/seq_event.h" 30 #include "plugin/api/alsa/seq_event.h"
31 31
32 #include <iostream> 32 #include <iostream>
33 #include <math.h> 33 #include <math.h>
34 34
35 #include <QDir>
36 #include <QFile>
37
35 const size_t 38 const size_t
36 AudioGenerator::m_pluginBlockSize = 2048; 39 AudioGenerator::m_pluginBlockSize = 2048;
37 40
38 //#define DEBUG_AUDIO_GENERATOR 1 41 //#define DEBUG_AUDIO_GENERATOR 1
39 42
156 } 159 }
157 160
158 return ""; 161 return "";
159 } 162 }
160 163
164 QString
165 AudioGenerator::getSampleDir()
166 {
167 if (m_sampleDir != "") return m_sampleDir;
168
169 QString tmppath = m_viewManager->getTemporaryDirectory();
170
171 QDir tmpdir(tmppath);
172 if (!tmpdir.mkdir("samples")) {
173 std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create "
174 << "directory " << tmpdir.filePath("samples").toStdString() << std::endl;
175 }
176
177 m_sampleDir = tmpdir.filePath("samples");
178
179 QDir sampleResourceDir(":/samples", "*.wav");
180
181 for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) {
182
183 QString fileName(sampleResourceDir[i]);
184 QFile file(sampleResourceDir.filePath(fileName));
185
186 if (!file.copy(QDir(m_sampleDir).filePath(fileName))) {
187 std::cerr << "WARNING: AudioGenerator::getSampleDir: "
188 << "Unable to copy " << fileName.toStdString()
189 << " into temporary directory \""
190 << m_sampleDir.toStdString() << "\"" << std::endl;
191 }
192 }
193
194 return m_sampleDir;
195 }
196
197 void
198 AudioGenerator::setSamplePath(RealTimePluginInstance *plugin)
199 {
200 QString samplePath = QString("%1:%2%3%4%5%6")
201 .arg(getSampleDir())
202 .arg(QDir::homePath())
203 .arg(QDir::separator())
204 .arg(".sv")
205 .arg(QDir::separator())
206 .arg("samples");
207
208 plugin->configure("samplepath", samplePath.toStdString());
209 }
210
161 RealTimePluginInstance * 211 RealTimePluginInstance *
162 AudioGenerator::loadPluginFor(const Model *model) 212 AudioGenerator::loadPluginFor(const Model *model)
163 { 213 {
164 QString pluginId, configurationXml; 214 QString pluginId, configurationXml;
165 215
176 } 226 }
177 227
178 if (pluginId == "") return 0; 228 if (pluginId == "") return 0;
179 229
180 RealTimePluginInstance *plugin = loadPlugin(pluginId, ""); 230 RealTimePluginInstance *plugin = loadPlugin(pluginId, "");
231 if (!plugin) return 0;
232
181 if (configurationXml != "") { 233 if (configurationXml != "") {
182 PluginXml(plugin).setParametersFromXml(configurationXml); 234 PluginXml(plugin).setParametersFromXml(configurationXml);
183 } 235 }
184 236
185 if (parameters) { 237 if (parameters) {
203 255
204 RealTimePluginInstance *instance = 256 RealTimePluginInstance *instance =
205 factory->instantiatePlugin 257 factory->instantiatePlugin
206 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); 258 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount);
207 259
208 if (instance) { 260 if (!instance) {
209 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { 261 std::cerr << "Failed to instantiate plugin " << pluginId.toStdString() << std::endl;
210 instance->setParameterValue(i, instance->getParameterDefault(i)); 262 }
211 } 263
212 std::string defaultProgram = instance->getProgram(0, 0); 264 setSamplePath(instance);
213 if (defaultProgram != "") { 265
214 std::cerr << "first selecting default program " << defaultProgram << std::endl; 266 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) {
215 instance->selectProgram(defaultProgram); 267 instance->setParameterValue(i, instance->getParameterDefault(i));
216 } 268 }
217 if (program != "") { 269 std::string defaultProgram = instance->getProgram(0, 0);
218 std::cerr << "now selecting desired program " << program.toStdString() << std::endl; 270 if (defaultProgram != "") {
219 instance->selectProgram(program.toStdString()); 271 std::cerr << "first selecting default program " << defaultProgram << std::endl;
220 } 272 instance->selectProgram(defaultProgram);
221 instance->setIdealChannelCount(m_targetChannelCount); // reset! 273 }
222 } else { 274 if (program != "") {
223 std::cerr << "Failed to instantiate plugin" << std::endl; 275 std::cerr << "now selecting desired program " << program.toStdString() << std::endl;
224 } 276 instance->selectProgram(program.toStdString());
277 }
278 instance->setIdealChannelCount(m_targetChannelCount); // reset!
225 279
226 return instance; 280 return instance;
227 } 281 }
228 282
229 void 283 void