From a98256c6f4bfccb7341768e0a20f59dd1f430281 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 27 Nov 2021 06:48:56 -0500 Subject: [PATCH] Dispatch Module::SampleRateChange event when the Module is added to the engine. --- include/engine/Module.hpp | 2 +- src/engine/Engine.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index da4045a0..49d16914 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -389,7 +389,7 @@ struct Module { float sampleRate; float sampleTime; }; - /** Called after the Engine sample rate changes. + /** Called when the Engine sample rate changes, and when the Module is added to the Engine. */ virtual void onSampleRateChange(const SampleRateChangeEvent& e) { // Call deprecated event method by default diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index e7279f7c..ce473eab 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -806,6 +806,11 @@ void Engine::addModule(Module* module) { // Dispatch AddEvent Module::AddEvent eAdd; module->onAdd(eAdd); + // Dispatch SampleRateChangeEvent + Module::SampleRateChangeEvent eSrc; + eSrc.sampleRate = internal->sampleRate; + eSrc.sampleTime = internal->sampleTime; + module->onSampleRateChange(eSrc); // Update ParamHandles' module pointers for (ParamHandle* paramHandle : internal->paramHandles) { if (paramHandle->moduleId == module->id)