MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / addModule

Method addModule

src/override/Engine.cpp:737–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

735
736
737void Engine::addModule(Module* module) {
738 std::lock_guard<SharedMutex> lock(internal->mutex);
739 DISTRHO_SAFE_ASSERT_RETURN(module != nullptr,);
740 // Check that the module is not already added
741 auto it = std::find(internal->modules.begin(), internal->modules.end(), module);
742 DISTRHO_SAFE_ASSERT_RETURN(it == internal->modules.end(),);
743 auto tit = std::find(internal->terminalModules.begin(), internal->terminalModules.end(), module);
744 DISTRHO_SAFE_ASSERT_RETURN(tit == internal->terminalModules.end(),);
745 // Set ID if unset or collides with an existing ID
746 while (module->id < 0 || internal->modulesCache.find(module->id) != internal->modulesCache.end()) {
747 // Randomly generate ID
748 module->id = random::u64() % (1ull << 53);
749 }
750 // Add module
751 if (TerminalModule* const terminalModule = asTerminalModule(module))
752 internal->terminalModules.push_back(terminalModule);
753 else
754 internal->modules.push_back(module);
755 internal->modulesCache[module->id] = module;
756 // Dispatch AddEvent
757 Module::AddEvent eAdd;
758 module->onAdd(eAdd);
759 // Dispatch SampleRateChangeEvent
760 Module::SampleRateChangeEvent eSrc;
761 eSrc.sampleRate = internal->sampleRate;
762 eSrc.sampleTime = internal->sampleTime;
763 module->onSampleRateChange(eSrc);
764 // Update ParamHandles' module pointers
765 for (ParamHandle* paramHandle : internal->paramHandles) {
766 if (paramHandle->moduleId == module->id)
767 paramHandle->module = module;
768 }
769#if DEBUG_ORDERED_MODULES
770 printf("New module: %s - %ld\n", module->model->getFullName().c_str(), module->id);
771#endif
772}
773
774
775void Engine::removeModule(Module* module) {

Callers 9

uiIdleFunction · 0.80
uiIdleFunction · 0.80
uiIdleFunction · 0.80
cloneActionMethod · 0.80
uiIdleFunction · 0.80
uiIdleFunction · 0.80
uiIdleFunction · 0.80
uiIdleFunction · 0.80
onActionMethod · 0.80

Calls 10

findFunction · 0.85
u64Function · 0.85
asTerminalModuleFunction · 0.85
push_backMethod · 0.80
c_strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
onAddMethod · 0.45
onSampleRateChangeMethod · 0.45
getFullNameMethod · 0.45

Tested by

no test coverage detected