# HG changeset patch # User Chris Cannam # Date 1144677152 0 # Node ID dd2084d32652cb80078ecea9adf0d97272e5131a # Parent ca4ee67b235800bda969c3517884a9cf64fa2942 * 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 diff -r ca4ee67b2358 -r dd2084d32652 audioio/AudioCallbackPlaySource.cpp --- a/audioio/AudioCallbackPlaySource.cpp Thu Apr 06 12:29:02 2006 +0000 +++ b/audioio/AudioCallbackPlaySource.cpp Mon Apr 10 13:52:32 2006 +0000 @@ -88,6 +88,8 @@ delete m_writeBuffers; + delete m_audioGenerator; + m_bufferScavenger.scavenge(true); } @@ -117,8 +119,10 @@ << " vs " << m_sourceSampleRate << "), playback will be wrong" << std::endl; - emit sampleRateMismatch(model->getSampleRate(), m_sourceSampleRate, - false); + if (dynamic_cast(model)) { + emit sampleRateMismatch(model->getSampleRate(), m_sourceSampleRate, + false); + } } size_t modelChannels = 1; diff -r ca4ee67b2358 -r dd2084d32652 audioio/AudioGenerator.cpp --- a/audioio/AudioGenerator.cpp Thu Apr 06 12:29:02 2006 +0000 +++ b/audioio/AudioGenerator.cpp Mon Apr 10 13:52:32 2006 +0000 @@ -32,6 +32,9 @@ #include #include +#include +#include + const size_t AudioGenerator::m_pluginBlockSize = 2048; @@ -158,6 +161,53 @@ return ""; } +QString +AudioGenerator::getSampleDir() +{ + if (m_sampleDir != "") return m_sampleDir; + + QString tmppath = m_viewManager->getTemporaryDirectory(); + + QDir tmpdir(tmppath); + if (!tmpdir.mkdir("samples")) { + std::cerr << "WARNING: AudioGenerator::getSampleDir: Failed to create " + << "directory " << tmpdir.filePath("samples").toStdString() << std::endl; + } + + m_sampleDir = tmpdir.filePath("samples"); + + QDir sampleResourceDir(":/samples", "*.wav"); + + for (unsigned int i = 0; i < sampleResourceDir.count(); ++i) { + + QString fileName(sampleResourceDir[i]); + QFile file(sampleResourceDir.filePath(fileName)); + + if (!file.copy(QDir(m_sampleDir).filePath(fileName))) { + std::cerr << "WARNING: AudioGenerator::getSampleDir: " + << "Unable to copy " << fileName.toStdString() + << " into temporary directory \"" + << m_sampleDir.toStdString() << "\"" << std::endl; + } + } + + return m_sampleDir; +} + +void +AudioGenerator::setSamplePath(RealTimePluginInstance *plugin) +{ + QString samplePath = QString("%1:%2%3%4%5%6") + .arg(getSampleDir()) + .arg(QDir::homePath()) + .arg(QDir::separator()) + .arg(".sv") + .arg(QDir::separator()) + .arg("samples"); + + plugin->configure("samplepath", samplePath.toStdString()); +} + RealTimePluginInstance * AudioGenerator::loadPluginFor(const Model *model) { @@ -178,6 +228,8 @@ if (pluginId == "") return 0; RealTimePluginInstance *plugin = loadPlugin(pluginId, ""); + if (!plugin) return 0; + if (configurationXml != "") { PluginXml(plugin).setParametersFromXml(configurationXml); } @@ -205,24 +257,26 @@ factory->instantiatePlugin (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); - if (instance) { - for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { - instance->setParameterValue(i, instance->getParameterDefault(i)); - } - std::string defaultProgram = instance->getProgram(0, 0); - if (defaultProgram != "") { - std::cerr << "first selecting default program " << defaultProgram << std::endl; - instance->selectProgram(defaultProgram); - } - if (program != "") { - std::cerr << "now selecting desired program " << program.toStdString() << std::endl; - instance->selectProgram(program.toStdString()); - } - instance->setIdealChannelCount(m_targetChannelCount); // reset! - } else { - std::cerr << "Failed to instantiate plugin" << std::endl; + if (!instance) { + std::cerr << "Failed to instantiate plugin " << pluginId.toStdString() << std::endl; } + setSamplePath(instance); + + for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { + instance->setParameterValue(i, instance->getParameterDefault(i)); + } + std::string defaultProgram = instance->getProgram(0, 0); + if (defaultProgram != "") { + std::cerr << "first selecting default program " << defaultProgram << std::endl; + instance->selectProgram(defaultProgram); + } + if (program != "") { + std::cerr << "now selecting desired program " << program.toStdString() << std::endl; + instance->selectProgram(program.toStdString()); + } + instance->setIdealChannelCount(m_targetChannelCount); // reset! + return instance; } diff -r ca4ee67b2358 -r dd2084d32652 audioio/AudioGenerator.h --- a/audioio/AudioGenerator.h Thu Apr 06 12:29:02 2006 +0000 +++ b/audioio/AudioGenerator.h Mon Apr 10 13:52:32 2006 +0000 @@ -120,9 +120,12 @@ QMutex m_mutex; PluginMap m_synthMap; NoteOffMap m_noteOffs; + QString m_sampleDir; virtual RealTimePluginInstance *loadPluginFor(const Model *model); virtual RealTimePluginInstance *loadPlugin(QString id, QString program); + QString getSampleDir(); + void setSamplePath(RealTimePluginInstance *plugin); virtual size_t mixDenseTimeValueModel (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,