| 760 | |
| 761 | |
| 762 | void Engine::addModule_NoLock(Module* module) { |
| 763 | assert(module); |
| 764 | // Check that the module is not already added |
| 765 | auto it = std::find(internal->modules.begin(), internal->modules.end(), module); |
| 766 | assert(it == internal->modules.end()); |
| 767 | // Set ID if unset or collides with an existing ID |
| 768 | while (module->id < 0 || internal->modulesCache.find(module->id) != internal->modulesCache.end()) { |
| 769 | // Randomly generate ID |
| 770 | module->id = random::u64() % (1ull << 53); |
| 771 | } |
| 772 | // Add module |
| 773 | internal->modules.push_back(module); |
| 774 | internal->modulesCache[module->id] = module; |
| 775 | // Dispatch AddEvent |
| 776 | Module::AddEvent eAdd; |
| 777 | module->onAdd(eAdd); |
| 778 | // Dispatch SampleRateChangeEvent |
| 779 | Module::SampleRateChangeEvent eSrc; |
| 780 | eSrc.sampleRate = internal->sampleRate; |
| 781 | eSrc.sampleTime = internal->sampleTime; |
| 782 | module->onSampleRateChange(eSrc); |
| 783 | // Update ParamHandles' module pointers |
| 784 | for (ParamHandle* paramHandle : internal->paramHandles) { |
| 785 | if (paramHandle->moduleId == module->id) |
| 786 | paramHandle->module = module; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | |
| 791 | void Engine::removeModule(Module* module) { |
nothing calls this directly
no test coverage detected