comparison plugin/plugins/SamplePlayer.cpp @ 75:163f3428bbe0

* 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 d397ea0a79f5
children f277a171749d
comparison
equal deleted inserted replaced
74:47fd14e29813 75:163f3428bbe0
94 const DSSI_Descriptor 94 const DSSI_Descriptor
95 SamplePlayer::dssiDescriptor = 95 SamplePlayer::dssiDescriptor =
96 { 96 {
97 2, // DSSI API version 97 2, // DSSI API version
98 &ladspaDescriptor, 98 &ladspaDescriptor,
99 0, // Configure 99 configure,
100 getProgram, 100 getProgram,
101 selectProgram, 101 selectProgram,
102 getMidiController, 102 getMidiController,
103 runSynth, 103 runSynth,
104 0, // Run synth adding 104 0, // Run synth adding
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_sampleSearchComplete(false), 132 m_sampleSearchComplete(false),
132 m_pendingProgramChange(-1) 133 m_pendingProgramChange(-1)
133 { 134 {
134 } 135 }
135 136
203 204
204 void 205 void
205 SamplePlayer::cleanup(LADSPA_Handle handle) 206 SamplePlayer::cleanup(LADSPA_Handle handle)
206 { 207 {
207 delete (SamplePlayer *)handle; 208 delete (SamplePlayer *)handle;
209 }
210
211 char *
212 SamplePlayer::configure(LADSPA_Handle handle, const char *key, const char *value)
213 {
214 if (key && !strcmp(key, "samplepath")) {
215
216 SamplePlayer *player = (SamplePlayer *)handle;
217
218 QMutexLocker locker(&player->m_mutex);
219
220 player->m_samplePath = value;
221
222 if (player->m_sampleSearchComplete) {
223 player->m_sampleSearchComplete = false;
224 player->searchSamples();
225 }
226
227 return 0;
228 }
229
230 return strdup("Unknown configure key");
208 } 231 }
209 232
210 const DSSI_Program_Descriptor * 233 const DSSI_Program_Descriptor *
211 SamplePlayer::getProgram(LADSPA_Handle handle, unsigned long program) 234 SamplePlayer::getProgram(LADSPA_Handle handle, unsigned long program)
212 { 235 {
315 void 338 void
316 SamplePlayer::searchSamples() 339 SamplePlayer::searchSamples()
317 { 340 {
318 if (m_sampleSearchComplete) return; 341 if (m_sampleSearchComplete) return;
319 342
320 //!!!
321 // QString path = "/usr/share/hydrogen/data/drumkits/EasternHop-1";
322
323 std::cerr << "Current working directory is \"" << getcwd(0, 0) << "\"" << std::endl; 343 std::cerr << "Current working directory is \"" << getcwd(0, 0) << "\"" << std::endl;
324 344
325 QString path = "samples";
326
327 std::cerr << "SamplePlayer::searchSamples: Path is \"" 345 std::cerr << "SamplePlayer::searchSamples: Path is \""
328 << path.toLocal8Bit().data() << "\"" << std::endl; 346 << m_samplePath.toLocal8Bit().data() << "\"" << std::endl;
329 347
330 QDir dir(path, "*.wav"); 348 QStringList dirList = m_samplePath.split(QRegExp("[:;]"));
331 for (unsigned int i = 0; i < dir.count(); ++i) { 349
332 QFileInfo file(dir.filePath(dir[i])); 350 for (QStringList::iterator i = dirList.begin(); i != dirList.end(); ++i) {
333 m_samples.push_back(std::pair<QString, QString> 351
334 (file.baseName(), file.filePath())); 352 QDir dir(*i, "*.wav");
335 std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl; 353
354 for (unsigned int i = 0; i < dir.count(); ++i) {
355 QFileInfo file(dir.filePath(dir[i]));
356 if (file.isReadable()) {
357 m_samples.push_back(std::pair<QString, QString>
358 (file.baseName(), file.filePath()));
359 std::cerr << "Found: " << dir[i].toLocal8Bit().data() << std::endl;
360 }
361 }
336 } 362 }
337 363
338 m_sampleSearchComplete = true; 364 m_sampleSearchComplete = true;
339 } 365 }
340 366