I’m trying to create a module with a main module and then expander modules.
On the left side of the chain, I always want a Main module, with the possibility of adding any number of Expander Modules.
I have this code to notice the main module that the new expander was added or removed, and therefore to collect all expanders into a std::map<moduleName, std::vector<Module*>>
structure.
This is code in Expander Module to propagate this message to Main Module.
/** NLMmk3_DrumSequencerExpander.cpp *//
void onExpanderChange(const ExpanderChangeEvent& e) override {
if (e.side == 0 || e.side == 1) {
DEBUG("ON EXPANDER CHANGE side left/right");
Module* module = getLeftExpander().module;
while (module != nullptr) {
if (module->getModel() == modelNLMmk3) {
// set the newly needed value
bool* value = (bool*) module->getRightExpander().producerMessage;
*value = true;
// no need to request flip, it will be done by the main module
module->getRightExpander().requestMessageFlip();
return;
}
module = module->getLeftExpander().module;
}
}
}
And this is the code in main module to handle given collection of Expander Modules
/** NLMmk3_MainModule.cpp *//
void collectAllExpanders()
{
setExpandersConnectedLights(0.f);
DEBUG("Clearing expanders");
printAllExpanders();
this->expanders = {};
DEBUG("Collecting expanders:");
Module *module = getRightExpander().module;
while (module != nullptr) {
if (allowedSubmodules.find(module->model) != allowedSubmodules.end()) {
float colorParam = module->getParam(0).getValue();
DEBUG("\tFound expander: %s with color <%d>", module->model->name.c_str(), (int)colorParam); //g
if (this->expanders.find(module->getModel()) == this->expanders.end()) {
this->expanders[module->getModel()] = {};
}
this->expanders[module->getModel()].push_back(module);
}
module = module->getRightExpander().module;
}
setExpandersConnectedLights(1.f);
}
The problem I have is when I switch two modules that are next to each other, I get this message:
969 debug src/NLMmk3_DrumSequencerExpander.cpp:46 onExpanderChange] on module with COLOR -536870912
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:45 onExpanderChange]
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:46 onExpanderChange] on module with COLOR -1073741824
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:45 onExpanderChange]
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:46 onExpanderChange] on module with COLOR -536870912
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:45 onExpanderChange]
[10.969 debug src/NLMmk3_DrumSequencerExpander.cpp:46 onExpanderChange] on module with COLOR -1073741824
Therefore, somehow, I get into infinite loop in while loop on Expander::onExpanderChange
, and I just can’t understand why.
Additionally I’m adding the GitHub repo link.