| 5328 | } |
| 5329 | |
| 5330 | Processor* ApiHelpers::ModuleHandler::addModule(Chain* c, const String& type, const String& id, int index /*= -1*/) |
| 5331 | { |
| 5332 | WARN_IF_AUDIO_THREAD(true, IllegalAudioThreadOps::HeapBlockAllocation); |
| 5333 | |
| 5334 | for (int i = 0; i < c->getHandler()->getNumProcessors(); i++) |
| 5335 | { |
| 5336 | if (c->getHandler()->getProcessor(i)->getId() == id) |
| 5337 | { |
| 5338 | return c->getHandler()->getProcessor(i); |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | SuspendHelpers::ScopedTicket ticket(parent->getMainController()); |
| 5343 | |
| 5344 | parent->getMainController()->getJavascriptThreadPool().killVoicesAndExtendTimeOut(getScriptProcessor()); |
| 5345 | |
| 5346 | LockHelpers::freeToGo(parent->getMainController()); |
| 5347 | |
| 5348 | ScopedPointer<Processor> newProcessor = parent->getMainController()->createProcessor(c->getFactoryType(), type, id); |
| 5349 | |
| 5350 | if (newProcessor == nullptr) |
| 5351 | throw String("Module with type " + type + " could not be generated."); |
| 5352 | |
| 5353 | // Now we're safe... |
| 5354 | Processor* pFree = newProcessor.release(); |
| 5355 | |
| 5356 | auto addFunction = [c, index](Processor* p) |
| 5357 | { |
| 5358 | if (c == nullptr) |
| 5359 | { |
| 5360 | delete p; // Rather bad... |
| 5361 | jassertfalse; |
| 5362 | return SafeFunctionCall::OK; |
| 5363 | } |
| 5364 | |
| 5365 | if (index >= 0 && index < c->getHandler()->getNumProcessors()) |
| 5366 | { |
| 5367 | Processor* sibling = c->getHandler()->getProcessor(index); |
| 5368 | c->getHandler()->add(p, sibling); |
| 5369 | } |
| 5370 | else |
| 5371 | c->getHandler()->add(p, nullptr); |
| 5372 | |
| 5373 | return SafeFunctionCall::OK; |
| 5374 | }; |
| 5375 | |
| 5376 | |
| 5377 | |
| 5378 | |
| 5379 | |
| 5380 | parent->getMainController()->getGlobalAsyncModuleHandler().addAsync(pFree, addFunction); |
| 5381 | |
| 5382 | // will be owned by the job, then by the handler... |
| 5383 | return pFree; |
| 5384 | } |
| 5385 | |
| 5386 | hise::Modulator* ApiHelpers::ModuleHandler::addAndConnectToGlobalModulator(Chain* c, Modulator* globalModulator, const String& modName, bool connectAsStaticMod/*=false*/) |
| 5387 | { |
no test coverage detected