comparison 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
comparison
equal deleted inserted replaced
82:bf42d8d63885 83:b2067aff8cd6
126 m_release(0), 126 m_release(0),
127 m_sampleData(0), 127 m_sampleData(0),
128 m_sampleCount(0), 128 m_sampleCount(0),
129 m_sampleRate(sampleRate), 129 m_sampleRate(sampleRate),
130 m_sampleNo(0), 130 m_sampleNo(0),
131 m_samplePath("samples"), 131 m_sampleDir("samples"),
132 m_sampleSearchComplete(false), 132 m_sampleSearchComplete(false),
133 m_pendingProgramChange(-1) 133 m_pendingProgramChange(-1)
134 { 134 {
135 } 135 }
136 136
209 } 209 }
210 210
211 char * 211 char *
212 SamplePlayer::configure(LADSPA_Handle handle, const char *key, const char *value) 212 SamplePlayer::configure(LADSPA_Handle handle, const char *key, const char *value)
213 { 213 {
214 if (key && !strcmp(key, "samplepath")) { 214 if (key && !strcmp(key, "sampledir")) {
215 215
216 SamplePlayer *player = (SamplePlayer *)handle; 216 SamplePlayer *player = (SamplePlayer *)handle;
217 217
218 QMutexLocker locker(&player->m_mutex); 218 QMutexLocker locker(&player->m_mutex);
219 219
220 220 if (QFileInfo(value).exists() &&
221 //!!! What do we do if receiving an antique path pointing at things that no longer exist? 221 QFileInfo(value).isDir()) {
222 222
223 player->m_samplePath = value; 223 player->m_sampleDir = value;
224 224
225 if (player->m_sampleSearchComplete) { 225 if (player->m_sampleSearchComplete) {
226 player->m_sampleSearchComplete = false; 226 player->m_sampleSearchComplete = false;
227 player->searchSamples(); 227 player->searchSamples();
228 }
229
230 return 0;
231
232 } else {
233 return strdup("Sample directory does not exist, leaving unchanged");
228 } 234 }
229
230 return 0;
231 } 235 }
232 236
233 return strdup("Unknown configure key"); 237 return strdup("Unknown configure key");
234 } 238 }
235 239
343 { 347 {
344 if (m_sampleSearchComplete) return; 348 if (m_sampleSearchComplete) return;
345 349
346 m_samples.clear(); 350 m_samples.clear();
347 351
348 std::cerr << "Current working directory is \"" << getcwd(0, 0) << "\"" << std::endl; 352 std::cerr << "SamplePlayer::searchSamples: Directory is \""
349 353 << m_sampleDir.toLocal8Bit().data() << "\"" << std::endl;
350 std::cerr << "SamplePlayer::searchSamples: Path is \"" 354
351 << m_samplePath.toLocal8Bit().data() << "\"" << std::endl; 355 QDir dir(m_sampleDir, "*.wav");
352 356
353 QStringList dirList = m_samplePath.split(QRegExp("[:;]")); 357 for (unsigned int i = 0; i < dir.count(); ++i) {
354 358 QFileInfo file(dir.filePath(dir[i]));
355 for (QStringList::iterator i = dirList.begin(); i != dirList.end(); ++i) { 359 if (file.isReadable()) {
356 360 m_samples.push_back(std::pair<QString, QString>
357 QDir dir(*i, "*.wav"); 361 (file.baseName(), file.filePath()));
358 362 std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl;
359 for (unsigned int i = 0; i < dir.count(); ++i) {
360 QFileInfo file(dir.filePath(dir[i]));
361 if (file.isReadable()) {
362 m_samples.push_back(std::pair<QString, QString>
363 (file.baseName(), file.filePath()));
364 std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl;
365 }
366 } 363 }
367 } 364 }
368 365
369 m_sampleSearchComplete = true; 366 m_sampleSearchComplete = true;
370 } 367 }
371 368
372 void 369 void
373 SamplePlayer::loadSampleData(QString path) 370 SamplePlayer::loadSampleData(QString path)