Mercurial > hg > svapp
comparison audioio/AudioGenerator.cpp @ 293:068235cf5bf7
Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:12:50 +0000 |
parents | ce71d2d9bdb7 |
children | 933b5aed341a |
comparison
equal
deleted
inserted
replaced
291:3fc0df289533 | 293:068235cf5bf7 |
---|---|
76 if (m_sampleDir != "") return; | 76 if (m_sampleDir != "") return; |
77 | 77 |
78 try { | 78 try { |
79 m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); | 79 m_sampleDir = TempDirectory::getInstance()->getSubDirectoryPath("samples"); |
80 } catch (DirectoryCreationFailed f) { | 80 } catch (DirectoryCreationFailed f) { |
81 std::cerr << "WARNING: AudioGenerator::initialiseSampleDir:" | 81 cerr << "WARNING: AudioGenerator::initialiseSampleDir:" |
82 << " Failed to create temporary sample directory" | 82 << " Failed to create temporary sample directory" |
83 << std::endl; | 83 << endl; |
84 m_sampleDir = ""; | 84 m_sampleDir = ""; |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 QDir sampleResourceDir(":/samples", "*.wav"); | 88 QDir sampleResourceDir(":/samples", "*.wav"); |
92 QString fileName(sampleResourceDir[i]); | 92 QString fileName(sampleResourceDir[i]); |
93 QFile file(sampleResourceDir.filePath(fileName)); | 93 QFile file(sampleResourceDir.filePath(fileName)); |
94 QString target = QDir(m_sampleDir).filePath(fileName); | 94 QString target = QDir(m_sampleDir).filePath(fileName); |
95 | 95 |
96 if (!file.copy(target)) { | 96 if (!file.copy(target)) { |
97 std::cerr << "WARNING: AudioGenerator::getSampleDir: " | 97 cerr << "WARNING: AudioGenerator::getSampleDir: " |
98 << "Unable to copy " << fileName.toStdString() | 98 << "Unable to copy " << fileName.toStdString() |
99 << " into temporary directory \"" | 99 << " into temporary directory \"" |
100 << m_sampleDir << "\"" << std::endl; | 100 << m_sampleDir << "\"" << endl; |
101 } else { | 101 } else { |
102 QFile tf(target); | 102 QFile tf(target); |
103 tf.setPermissions(tf.permissions() | | 103 tf.setPermissions(tf.permissions() | |
104 QFile::WriteOwner | | 104 QFile::WriteOwner | |
105 QFile::WriteUser); | 105 QFile::WriteUser); |
138 void | 138 void |
139 AudioGenerator::playPluginIdChanged(const Playable *playable, QString) | 139 AudioGenerator::playPluginIdChanged(const Playable *playable, QString) |
140 { | 140 { |
141 const Model *model = dynamic_cast<const Model *>(playable); | 141 const Model *model = dynamic_cast<const Model *>(playable); |
142 if (!model) { | 142 if (!model) { |
143 std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " | 143 cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " |
144 << playable << " is not a supported model type" | 144 << playable << " is not a supported model type" |
145 << std::endl; | 145 << endl; |
146 return; | 146 return; |
147 } | 147 } |
148 | 148 |
149 if (m_synthMap.find(model) == m_synthMap.end()) return; | 149 if (m_synthMap.find(model) == m_synthMap.end()) return; |
150 | 150 |
162 { | 162 { |
163 // SVDEBUG << "AudioGenerator::playPluginConfigurationChanged" << endl; | 163 // SVDEBUG << "AudioGenerator::playPluginConfigurationChanged" << endl; |
164 | 164 |
165 const Model *model = dynamic_cast<const Model *>(playable); | 165 const Model *model = dynamic_cast<const Model *>(playable); |
166 if (!model) { | 166 if (!model) { |
167 std::cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " | 167 cerr << "WARNING: AudioGenerator::playPluginIdChanged: playable " |
168 << playable << " is not a supported model type" | 168 << playable << " is not a supported model type" |
169 << std::endl; | 169 << endl; |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 if (m_synthMap.find(model) == m_synthMap.end()) { | 173 if (m_synthMap.find(model) == m_synthMap.end()) { |
174 SVDEBUG << "AudioGenerator::playPluginConfigurationChanged: We don't know about this plugin" << endl; | 174 SVDEBUG << "AudioGenerator::playPluginConfigurationChanged: We don't know about this plugin" << endl; |
229 { | 229 { |
230 RealTimePluginFactory *factory = | 230 RealTimePluginFactory *factory = |
231 RealTimePluginFactory::instanceFor(pluginId); | 231 RealTimePluginFactory::instanceFor(pluginId); |
232 | 232 |
233 if (!factory) { | 233 if (!factory) { |
234 std::cerr << "Failed to get plugin factory" << std::endl; | 234 cerr << "Failed to get plugin factory" << endl; |
235 return 0; | 235 return 0; |
236 } | 236 } |
237 | 237 |
238 RealTimePluginInstance *instance = | 238 RealTimePluginInstance *instance = |
239 factory->instantiatePlugin | 239 factory->instantiatePlugin |
240 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); | 240 (pluginId, 0, 0, m_sourceSampleRate, m_pluginBlockSize, m_targetChannelCount); |
241 | 241 |
242 if (!instance) { | 242 if (!instance) { |
243 std::cerr << "Failed to instantiate plugin " << pluginId << std::endl; | 243 cerr << "Failed to instantiate plugin " << pluginId << endl; |
244 return 0; | 244 return 0; |
245 } | 245 } |
246 | 246 |
247 setSampleDir(instance); | 247 setSampleDir(instance); |
248 | 248 |
249 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { | 249 for (unsigned int i = 0; i < instance->getParameterCount(); ++i) { |
250 instance->setParameterValue(i, instance->getParameterDefault(i)); | 250 instance->setParameterValue(i, instance->getParameterDefault(i)); |
251 } | 251 } |
252 std::string defaultProgram = instance->getProgram(0, 0); | 252 std::string defaultProgram = instance->getProgram(0, 0); |
253 if (defaultProgram != "") { | 253 if (defaultProgram != "") { |
254 // std::cerr << "first selecting default program " << defaultProgram << std::endl; | 254 // cerr << "first selecting default program " << defaultProgram << endl; |
255 instance->selectProgram(defaultProgram); | 255 instance->selectProgram(defaultProgram); |
256 } | 256 } |
257 if (program != "") { | 257 if (program != "") { |
258 // std::cerr << "now selecting desired program " << program << std::endl; | 258 // cerr << "now selecting desired program " << program << endl; |
259 instance->selectProgram(program.toStdString()); | 259 instance->selectProgram(program.toStdString()); |
260 } | 260 } |
261 instance->setIdealChannelCount(m_targetChannelCount); // reset! | 261 instance->setIdealChannelCount(m_targetChannelCount); // reset! |
262 | 262 |
263 return instance; | 263 return instance; |
346 size_t | 346 size_t |
347 AudioGenerator::mixModel(Model *model, size_t startFrame, size_t frameCount, | 347 AudioGenerator::mixModel(Model *model, size_t startFrame, size_t frameCount, |
348 float **buffer, size_t fadeIn, size_t fadeOut) | 348 float **buffer, size_t fadeIn, size_t fadeOut) |
349 { | 349 { |
350 if (m_sourceSampleRate == 0) { | 350 if (m_sourceSampleRate == 0) { |
351 std::cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << std::endl; | 351 cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << endl; |
352 return frameCount; | 352 return frameCount; |
353 } | 353 } |
354 | 354 |
355 QMutexLocker locker(&m_mutex); | 355 QMutexLocker locker(&m_mutex); |
356 | 356 |
362 if (!parameters) return frameCount; | 362 if (!parameters) return frameCount; |
363 | 363 |
364 bool playing = !parameters->isPlayMuted(); | 364 bool playing = !parameters->isPlayMuted(); |
365 if (!playing) { | 365 if (!playing) { |
366 #ifdef DEBUG_AUDIO_GENERATOR | 366 #ifdef DEBUG_AUDIO_GENERATOR |
367 std::cout << "AudioGenerator::mixModel(" << model << "): muted" << std::endl; | 367 cout << "AudioGenerator::mixModel(" << model << "): muted" << endl; |
368 #endif | 368 #endif |
369 return frameCount; | 369 return frameCount; |
370 } | 370 } |
371 | 371 |
372 if (m_soloing) { | 372 if (m_soloing) { |
373 if (m_soloModelSet.find(model) == m_soloModelSet.end()) { | 373 if (m_soloModelSet.find(model) == m_soloModelSet.end()) { |
374 #ifdef DEBUG_AUDIO_GENERATOR | 374 #ifdef DEBUG_AUDIO_GENERATOR |
375 std::cout << "AudioGenerator::mixModel(" << model << "): not one of the solo'd models" << std::endl; | 375 cout << "AudioGenerator::mixModel(" << model << "): not one of the solo'd models" << endl; |
376 #endif | 376 #endif |
377 return frameCount; | 377 return frameCount; |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
518 //calls to mixModel | 518 //calls to mixModel |
519 | 519 |
520 size_t got = blocks * m_pluginBlockSize; | 520 size_t got = blocks * m_pluginBlockSize; |
521 | 521 |
522 #ifdef DEBUG_AUDIO_GENERATOR | 522 #ifdef DEBUG_AUDIO_GENERATOR |
523 std::cout << "mixModel [synthetic note]: frames " << frames | 523 cout << "mixModel [synthetic note]: frames " << frames |
524 << ", blocks " << blocks << std::endl; | 524 << ", blocks " << blocks << endl; |
525 #endif | 525 #endif |
526 | 526 |
527 snd_seq_event_t onEv; | 527 snd_seq_event_t onEv; |
528 onEv.type = SND_SEQ_EVENT_NOTEON; | 528 onEv.type = SND_SEQ_EVENT_NOTEON; |
529 onEv.data.note.channel = 0; | 529 onEv.data.note.channel = 0; |
563 (noteOffs.begin()->frame, m_sourceSampleRate); | 563 (noteOffs.begin()->frame, m_sourceSampleRate); |
564 | 564 |
565 offEv.data.note.note = noteOffs.begin()->pitch; | 565 offEv.data.note.note = noteOffs.begin()->pitch; |
566 | 566 |
567 #ifdef DEBUG_AUDIO_GENERATOR | 567 #ifdef DEBUG_AUDIO_GENERATOR |
568 std::cerr << "mixModel [synthetic]: sending note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << std::endl; | 568 cerr << "mixModel [synthetic]: sending note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << endl; |
569 #endif | 569 #endif |
570 | 570 |
571 plugin->sendEvent(eventTime, &offEv); | 571 plugin->sendEvent(eventTime, &offEv); |
572 noteOffs.erase(noteOffs.begin()); | 572 noteOffs.erase(noteOffs.begin()); |
573 } | 573 } |
577 | 577 |
578 if (ni->isMidiPitchQuantized) { | 578 if (ni->isMidiPitchQuantized) { |
579 onEv.data.note.note = ni->midiPitch; | 579 onEv.data.note.note = ni->midiPitch; |
580 } else { | 580 } else { |
581 #ifdef DEBUG_AUDIO_GENERATOR | 581 #ifdef DEBUG_AUDIO_GENERATOR |
582 std::cerr << "mixModel [synthetic]: non-pitch-quantized notes are not supported [yet], quantizing" << std::endl; | 582 cerr << "mixModel [synthetic]: non-pitch-quantized notes are not supported [yet], quantizing" << endl; |
583 #endif | 583 #endif |
584 onEv.data.note.note = Pitch::getPitchForFrequency(ni->frequency); | 584 onEv.data.note.note = Pitch::getPitchForFrequency(ni->frequency); |
585 } | 585 } |
586 | 586 |
587 onEv.data.note.velocity = ni->velocity; | 587 onEv.data.note.velocity = ni->velocity; |
588 | 588 |
589 plugin->sendEvent(eventTime, &onEv); | 589 plugin->sendEvent(eventTime, &onEv); |
590 | 590 |
591 #ifdef DEBUG_AUDIO_GENERATOR | 591 #ifdef DEBUG_AUDIO_GENERATOR |
592 std::cout << "mixModel [synthetic]: note at frame " << noteFrame << ", block start " << (startFrame + i * m_pluginBlockSize) << ", resulting time " << eventTime << std::endl; | 592 cout << "mixModel [synthetic]: note at frame " << noteFrame << ", block start " << (startFrame + i * m_pluginBlockSize) << ", resulting time " << eventTime << endl; |
593 #endif | 593 #endif |
594 | 594 |
595 noteOffs.insert | 595 noteOffs.insert |
596 (NoteOff(onEv.data.note.note, noteFrame + ni->duration)); | 596 (NoteOff(onEv.data.note.note, noteFrame + ni->duration)); |
597 } | 597 } |
604 (noteOffs.begin()->frame, m_sourceSampleRate); | 604 (noteOffs.begin()->frame, m_sourceSampleRate); |
605 | 605 |
606 offEv.data.note.note = noteOffs.begin()->pitch; | 606 offEv.data.note.note = noteOffs.begin()->pitch; |
607 | 607 |
608 #ifdef DEBUG_AUDIO_GENERATOR | 608 #ifdef DEBUG_AUDIO_GENERATOR |
609 std::cerr << "mixModel [synthetic]: sending leftover note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << std::endl; | 609 cerr << "mixModel [synthetic]: sending leftover note-off event at time " << eventTime << " frame " << noteOffs.begin()->frame << " pitch " << noteOffs.begin()->pitch << endl; |
610 #endif | 610 #endif |
611 | 611 |
612 plugin->sendEvent(eventTime, &offEv); | 612 plugin->sendEvent(eventTime, &offEv); |
613 noteOffs.erase(noteOffs.begin()); | 613 noteOffs.erase(noteOffs.begin()); |
614 } | 614 } |
616 plugin->run(blockTime); | 616 plugin->run(blockTime); |
617 float **outs = plugin->getAudioOutputBuffers(); | 617 float **outs = plugin->getAudioOutputBuffers(); |
618 | 618 |
619 for (size_t c = 0; c < m_targetChannelCount; ++c) { | 619 for (size_t c = 0; c < m_targetChannelCount; ++c) { |
620 #ifdef DEBUG_AUDIO_GENERATOR | 620 #ifdef DEBUG_AUDIO_GENERATOR |
621 std::cout << "mixModel [synthetic]: adding " << m_pluginBlockSize << " samples from plugin output " << c << std::endl; | 621 cout << "mixModel [synthetic]: adding " << m_pluginBlockSize << " samples from plugin output " << c << endl; |
622 #endif | 622 #endif |
623 | 623 |
624 size_t sourceChannel = (c % plugin->getAudioOutputCount()); | 624 size_t sourceChannel = (c % plugin->getAudioOutputCount()); |
625 | 625 |
626 float channelGain = gain; | 626 float channelGain = gain; |