changeset 83:b2067aff8cd6

* Fix crash in spectrogram layer when replacing model * Change sample player's sample path to a single sample directory. This makes it immune to OS path separator differences, and ensures it can reject configure calls that try to set a nonexistent directory. Reloading play parameters (e.g. sample program) should now work. * some win32 fixes.
author Chris Cannam
date Wed, 26 Apr 2006 16:00:13 +0000
parents bf42d8d63885
children 97e085895524
files base/PlayParameterRepository.cpp base/System.h base/TempDirectory.cpp plugin/DSSIPluginInstance.cpp plugin/FeatureExtractionPluginFactory.cpp plugin/plugins/SamplePlayer.cpp plugin/plugins/SamplePlayer.h
diffstat 7 files changed, 49 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/base/PlayParameterRepository.cpp	Wed Apr 26 14:09:55 2006 +0000
+++ b/base/PlayParameterRepository.cpp	Wed Apr 26 16:00:13 2006 +0000
@@ -50,23 +50,27 @@
 
 	    std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl;
 
-	    m_playParameters[model] = new PlayParameters;
+            PlayParameters *params = new PlayParameters;
+	    m_playParameters[model] = params;
 
-            m_playParameters[model]->setPlayPluginId
+            params->setPlayPluginId
                 (AudioGenerator::getDefaultPlayPluginId(model));
 
-            m_playParameters[model]->setPlayPluginConfiguration
+            params->setPlayPluginConfiguration
                 (AudioGenerator::getDefaultPlayPluginConfiguration(model));
 
-	    connect(m_playParameters[model], SIGNAL(playParametersChanged()),
+	    connect(params, SIGNAL(playParametersChanged()),
 		    this, SLOT(playParametersChanged()));
 
-	    connect(m_playParameters[model], SIGNAL(playPluginIdChanged(QString)),
+	    connect(params, SIGNAL(playPluginIdChanged(QString)),
 		    this, SLOT(playPluginIdChanged(QString)));
 
-	    connect(m_playParameters[model], SIGNAL(playPluginConfigurationChanged(QString)),
+	    connect(params, SIGNAL(playPluginConfigurationChanged(QString)),
 		    this, SLOT(playPluginConfigurationChanged(QString)));
 
+            std::cerr << "Connected play parameters " << params << " for model "
+                      << model << " to this " << this << std::endl;
+
 	} else {
 
 	    std::cerr << "PlayParameterRepository: Model " << model << " not playable" <<  std::endl;
--- a/base/System.h	Wed Apr 26 14:09:55 2006 +0000
+++ b/base/System.h	Wed Apr 26 16:00:13 2006 +0000
@@ -32,7 +32,7 @@
 
 #define PLUGIN_GLOB  "*.dll"
 #define PATH_SEPARATOR ';'
-#define DEFAULT_VAMP_PATH "C:\\Program Files\\Vamp Plugins"
+#define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins"
 
 extern "C" {
 void gettimeofday(struct timeval *p, void *tz);
--- a/base/TempDirectory.cpp	Wed Apr 26 14:09:55 2006 +0000
+++ b/base/TempDirectory.cpp	Wed Apr 26 16:00:13 2006 +0000
@@ -156,11 +156,11 @@
     }
 
     QDir dir(tmpdir);
-    dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
+    dir.setFilter(QDir::Dirs | QDir::Files);
 
     for (unsigned int i = 0; i < dir.count(); ++i) {
 
-        if (dir[i] == "." || dir[i] == "..") continue; // just for paranoia
+        if (dir[i] == "." || dir[i] == "..") continue;
         QFileInfo fi(dir.filePath(dir[i]));
 
         if (fi.isDir()) {
--- a/plugin/DSSIPluginInstance.cpp	Wed Apr 26 14:09:55 2006 +0000
+++ b/plugin/DSSIPluginInstance.cpp	Wed Apr 26 16:00:13 2006 +0000
@@ -846,6 +846,8 @@
 	}
 	qm = qm + message;
 	free(message);
+
+        std::cerr << "DSSIPluginInstance::configure: warning: configure returned message: \"" << qm.toStdString() << "\"" << std::endl;
     }
 
     return qm;
--- a/plugin/FeatureExtractionPluginFactory.cpp	Wed Apr 26 14:09:55 2006 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Wed Apr 26 16:00:13 2006 +0000
@@ -71,6 +71,15 @@
                 envPath.replace(f, 5, home);
             }
         }
+#ifdef Q_WS_WIN32
+        char *cpfiles = getenv("ProgramFiles");
+        if (!cpfiles) cpfiles = "C:\\Program Files";
+        std::string pfiles(cpfiles);
+        int f;
+        while ((f = envPath.find("%ProgramFiles%")) >= 0 && f < envPath.length()) {
+            envPath.replace(f, 14, pfiles);
+        }
+#endif
     }
 
     std::cerr << "VAMP path is: \"" << envPath << "\"" << std::endl;
--- a/plugin/plugins/SamplePlayer.cpp	Wed Apr 26 14:09:55 2006 +0000
+++ b/plugin/plugins/SamplePlayer.cpp	Wed Apr 26 16:00:13 2006 +0000
@@ -128,7 +128,7 @@
     m_sampleCount(0),
     m_sampleRate(sampleRate),
     m_sampleNo(0),
-    m_samplePath("samples"),
+    m_sampleDir("samples"),
     m_sampleSearchComplete(false),
     m_pendingProgramChange(-1)
 {
@@ -211,23 +211,27 @@
 char *
 SamplePlayer::configure(LADSPA_Handle handle, const char *key, const char *value)
 {
-    if (key && !strcmp(key, "samplepath")) {
+    if (key && !strcmp(key, "sampledir")) {
 
         SamplePlayer *player = (SamplePlayer *)handle;
 
 	QMutexLocker locker(&player->m_mutex);
 
+        if (QFileInfo(value).exists() &&
+            QFileInfo(value).isDir()) {
 
-        //!!! What do we do if receiving an antique path pointing at things that no longer exist?
+            player->m_sampleDir = value;
 
-        player->m_samplePath = value;
+            if (player->m_sampleSearchComplete) {
+                player->m_sampleSearchComplete = false;
+                player->searchSamples();
+            }
 
-        if (player->m_sampleSearchComplete) {
-            player->m_sampleSearchComplete = false;
-            player->searchSamples();
+            return 0;
+
+        } else {
+            return strdup("Sample directory does not exist, leaving unchanged");
         }
-
-        return 0;
     }
 
     return strdup("Unknown configure key");
@@ -345,27 +349,20 @@
 
     m_samples.clear();
 
-    std::cerr << "Current working directory is \"" << getcwd(0, 0) << "\"" << std::endl;
+    std::cerr << "SamplePlayer::searchSamples: Directory is \""
+	      << m_sampleDir.toLocal8Bit().data() << "\"" << std::endl;
 
-    std::cerr << "SamplePlayer::searchSamples: Path is \""
-	      << m_samplePath.toLocal8Bit().data() << "\"" << std::endl;
-
-    QStringList dirList = m_samplePath.split(QRegExp("[:;]"));
-
-    for (QStringList::iterator i = dirList.begin(); i != dirList.end(); ++i) {
-
-        QDir dir(*i, "*.wav");
-
-        for (unsigned int i = 0; i < dir.count(); ++i) {
-            QFileInfo file(dir.filePath(dir[i]));
-            if (file.isReadable()) {
-                m_samples.push_back(std::pair<QString, QString>
-                                    (file.baseName(), file.filePath()));
-                std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl;
-            }
+    QDir dir(m_sampleDir, "*.wav");
+    
+    for (unsigned int i = 0; i < dir.count(); ++i) {
+        QFileInfo file(dir.filePath(dir[i]));
+        if (file.isReadable()) {
+            m_samples.push_back(std::pair<QString, QString>
+                                (file.baseName(), file.filePath()));
+            std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl;
         }
     }
-
+    
     m_sampleSearchComplete = true;
 }
 
--- a/plugin/plugins/SamplePlayer.h	Wed Apr 26 14:09:55 2006 +0000
+++ b/plugin/plugins/SamplePlayer.h	Wed Apr 26 16:00:13 2006 +0000
@@ -91,7 +91,7 @@
     int m_velocities[Polyphony];
     long m_sampleNo;
 
-    QString m_samplePath;
+    QString m_sampleDir;
     QString m_program;
     std::vector<std::pair<QString, QString> > m_samples; // program name, path
     bool m_sampleSearchComplete;