diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index e63c9a5e..06a15d36 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -286,8 +286,11 @@ struct Module { onSampleRateChange(); } - struct ExpanderChangeEvent {}; - /** Called after the Engine sample rate changes. + struct ExpanderChangeEvent { + /** False for left, true for right. */ + bool side; + }; + /** Called after an expander is added, removed, or changed on either the left or right side of the Module. */ virtual void onExpanderChange(const ExpanderChangeEvent& e) {} diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index e9850eb6..be53edb6 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -335,7 +335,7 @@ void RackWidget::pastePresetClipboardAction() { } } -static void RackWidget_updateAdjacent(RackWidget* that) { +static void RackWidget_updateExpanders(RackWidget* that) { for (widget::Widget* w : that->moduleContainer->children) { math::Vec pLeft = w->box.pos.div(RACK_GRID_SIZE).round(); math::Vec pRight = w->box.getTopRight().div(RACK_GRID_SIZE).round(); @@ -375,7 +375,7 @@ void RackWidget::addModule(ModuleWidget* m) { assert(m->box.size.y == RACK_GRID_HEIGHT); moduleContainer->addChild(m); - RackWidget_updateAdjacent(this); + RackWidget_updateExpanders(this); } void RackWidget::addModuleAtMouse(ModuleWidget* mw) { @@ -418,7 +418,7 @@ bool RackWidget::requestModulePos(ModuleWidget* mw, math::Vec pos) { // Accept requested position mw->setPosition(mwBox.pos); - RackWidget_updateAdjacent(this); + RackWidget_updateExpanders(this); return true; } @@ -520,7 +520,7 @@ void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) { xLimit = newPos.x + w->box.size.x; } - RackWidget_updateAdjacent(this); + RackWidget_updateExpanders(this); } ModuleWidget* RackWidget::getModule(int64_t moduleId) { diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 12bb1fdc..f2ee9c78 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -226,17 +226,27 @@ struct Engine::Internal { }; -static void Engine_updateExpander(Engine* that, Module::Expander* expander) { - if (expander->moduleId >= 0) { - if (!expander->module || expander->module->id != expander->moduleId) { - expander->module = that->getModule(expander->moduleId); +static void Engine_updateExpander(Engine* that, Module* module, bool side) { + Module::Expander& expander = side ? module->rightExpander : module->leftExpander; + Module* oldExpanderModule = expander.module; + + if (expander.moduleId >= 0) { + if (!expander.module || expander.module->id != expander.moduleId) { + expander.module = that->getModule(expander.moduleId); } } else { - if (expander->module) { - expander->module = NULL; + if (expander.module) { + expander.module = NULL; } } + + if (expander.module != oldExpanderModule) { + // Trigger ExpanderChangeEvent event + Module::ExpanderChangeEvent e; + e.side = side; + module->onExpanderChange(e); + } } @@ -571,8 +581,8 @@ void Engine::step(int frames) { // Update expander pointers for (Module* module : internal->modules) { - Engine_updateExpander(this, &module->leftExpander); - Engine_updateExpander(this, &module->rightExpander); + Engine_updateExpander(this, module, false); + Engine_updateExpander(this, module, true); } // Launch workers diff --git a/src/patch.cpp b/src/patch.cpp index 8df2a684..c2693a3a 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -153,7 +153,8 @@ void PatchManager::saveTemplateDialog() { void PatchManager::saveAutosave() { - INFO("Saving autosave"); + std::string patchPath = system::join(asset::autosavePath, "patch.json"); + INFO("Saving autosave %s", patchPath.c_str()); json_t* rootJ = toJson(); if (!rootJ) return; @@ -161,7 +162,6 @@ void PatchManager::saveAutosave() { // Write to temporary path and then rename it to the correct path system::createDirectories(asset::autosavePath); - std::string patchPath = system::join(asset::autosavePath, "patch.json"); std::string tmpPath = patchPath + ".tmp"; FILE* file = std::fopen(tmpPath.c_str(), "w"); if (!file) { @@ -265,8 +265,8 @@ void PatchManager::loadTemplateDialog() { void PatchManager::loadAutosave() { - INFO("Loading autosave"); std::string patchPath = system::join(asset::autosavePath, "patch.json"); + INFO("Loading autosave %s", patchPath.c_str()); FILE* file = std::fopen(patchPath.c_str(), "r"); if (!file) { // Exit silently