Browse Source

Dispatch ExpanderChangeEvent when removing modules.

tags/v2.5.0
Andrew Belt 7 months ago
parent
commit
b04beb9680
3 changed files with 40 additions and 25 deletions
  1. +2
    -0
      include/engine/Module.hpp
  2. +26
    -25
      src/engine/Engine.cpp
  3. +12
    -0
      src/engine/Module.cpp

+ 2
- 0
include/engine/Module.hpp View File

@@ -469,6 +469,8 @@ struct Module {
PRIVATE int meterIndex(); PRIVATE int meterIndex();
PRIVATE void doProcess(const ProcessArgs& args); PRIVATE void doProcess(const ProcessArgs& args);
PRIVATE static void jsonStripIds(json_t* rootJ); PRIVATE static void jsonStripIds(json_t* rootJ);
/** Sets module of expander and dispatches ExpanderChangeEvent if changed. */
PRIVATE void setExpanderModule(Module* module, uint8_t side);
}; };






+ 26
- 25
src/engine/Engine.cpp View File

@@ -235,26 +235,21 @@ struct Engine::Internal {




static void Engine_updateExpander_NoLock(Engine* that, Module* module, uint8_t side) { static void Engine_updateExpander_NoLock(Engine* that, Module* module, uint8_t side) {
Module::Expander& expander = side ? module->rightExpander : module->leftExpander;
Module* oldExpanderModule = expander.module;
Module::Expander& expander = module->getExpander(side);


if (expander.moduleId >= 0) { if (expander.moduleId >= 0) {
// Check if moduleId has changed from current module
if (!expander.module || expander.module->id != expander.moduleId) { if (!expander.module || expander.module->id != expander.moduleId) {
expander.module = that->getModule_NoLock(expander.moduleId);
Module* expanderModule = that->getModule_NoLock(expander.moduleId);
module->setExpanderModule(expanderModule, side);
} }
} }
else { else {
// Check if moduleId has unset module
if (expander.module) { if (expander.module) {
expander.module = NULL;
module->setExpanderModule(NULL, side);
} }
} }

if (expander.module != oldExpanderModule) {
// Dispatch ExpanderChangeEvent
Module::ExpanderChangeEvent e;
e.side = side;
module->onExpanderChange(e);
}
} }




@@ -502,8 +497,8 @@ void Engine::stepBlock(int frames) {


// Update expander pointers // Update expander pointers
for (Module* module : internal->modules) { for (Module* module : internal->modules) {
Engine_updateExpander_NoLock(this, module, false);
Engine_updateExpander_NoLock(this, module, true);
Engine_updateExpander_NoLock(this, module, 0);
Engine_updateExpander_NoLock(this, module, 1);
} }


// Launch workers // Launch workers
@@ -760,23 +755,25 @@ void Engine::removeModule_NoLock(Module* module) {
} }
// Update expanders of other modules // Update expanders of other modules
for (Module* m : internal->modules) { for (Module* m : internal->modules) {
if (m->leftExpander.module == module) {
m->leftExpander.moduleId = -1;
m->leftExpander.module = NULL;
}
if (m->rightExpander.module == module) {
m->rightExpander.moduleId = -1;
m->rightExpander.module = NULL;
for (uint8_t side = 0; side < 2; side++) {
Module::Expander& expander = m->getExpander(!side);
if (expander.moduleId == module->id) {
expander.moduleId = -1;
}
if (expander.module == module) {
m->setExpanderModule(NULL, !side);
}
} }
} }
// Update expanders of this module
for (uint8_t side = 0; side < 2; side++) {
Module::Expander& expander = module->getExpander(side);
expander.moduleId = -1;
module->setExpanderModule(NULL, side);
}
// Remove module // Remove module
internal->modulesCache.erase(module->id); internal->modulesCache.erase(module->id);
internal->modules.erase(it); internal->modules.erase(it);
// Reset expanders
module->leftExpander.moduleId = -1;
module->leftExpander.module = NULL;
module->rightExpander.moduleId = -1;
module->rightExpander.module = NULL;
} }




@@ -795,6 +792,8 @@ Module* Engine::getModule(int64_t moduleId) {




Module* Engine::getModule_NoLock(int64_t moduleId) { Module* Engine::getModule_NoLock(int64_t moduleId) {
if (moduleId < 0)
return NULL;
auto it = internal->modulesCache.find(moduleId); auto it = internal->modulesCache.find(moduleId);
if (it == internal->modulesCache.end()) if (it == internal->modulesCache.end())
return NULL; return NULL;
@@ -1046,6 +1045,8 @@ bool Engine::hasCable(Cable* cable) {




Cable* Engine::getCable(int64_t cableId) { Cable* Engine::getCable(int64_t cableId) {
if (cableId < 0)
return NULL;
SharedLock<SharedMutex> lock(internal->mutex); SharedLock<SharedMutex> lock(internal->mutex);
auto it = internal->cablesCache.find(cableId); auto it = internal->cablesCache.find(cableId);
if (it == internal->cablesCache.end()) if (it == internal->cablesCache.end())


+ 12
- 0
src/engine/Module.cpp View File

@@ -392,6 +392,18 @@ void Module::jsonStripIds(json_t* rootJ) {
} }




void Module::setExpanderModule(Module* module, uint8_t side) {
Expander& expander = getExpander(side);

if (expander.module != module) {
expander.module = module;
// Dispatch ExpanderChangeEvent
Module::ExpanderChangeEvent e;
e.side = side;
onExpanderChange(e);
}
}



} // namespace engine } // namespace engine
} // namespace rack } // namespace rack

Loading…
Cancel
Save