changeset 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 ca4ee67b2358
children f38b8abd3540
files audioio/AudioCallbackPlaySource.cpp audioio/AudioGenerator.cpp audioio/AudioGenerator.h
diffstat 3 files changed, 79 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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<DenseTimeValueModel *>(model)) {
+            emit sampleRateMismatch(model->getSampleRate(), m_sourceSampleRate,
+                                    false);
+        }
     }
 
     size_t modelChannels = 1;
--- 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 <iostream>
 #include <math.h>
 
+#include <QDir>
+#include <QFile>
+
 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;
 }
 
--- 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,