diff plugin/plugins/SamplePlayer.cpp @ 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 f277a171749d
children c30728d5625c
line wrap: on
line diff
--- 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;
 }