Browse Source

Implement Module::ExpanderChangeEvent event trigger.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
06c6590b51
4 changed files with 30 additions and 17 deletions
  1. +5
    -2
      include/engine/Module.hpp
  2. +4
    -4
      src/app/RackWidget.cpp
  3. +18
    -8
      src/engine/Engine.cpp
  4. +3
    -3
      src/patch.cpp

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

@@ -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) {}



+ 4
- 4
src/app/RackWidget.cpp View File

@@ -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) {


+ 18
- 8
src/engine/Engine.cpp View File

@@ -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


+ 3
- 3
src/patch.cpp View File

@@ -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


Loading…
Cancel
Save