@@ -41,7 +41,6 @@ struct ModuleWidget : OpaqueWidget { | |||||
void save(std::string filename); | void save(std::string filename); | ||||
void loadDialog(); | void loadDialog(); | ||||
void saveDialog(); | void saveDialog(); | ||||
void toggleBypass(); | |||||
/** Disconnects cables from all ports | /** Disconnects cables from all ports | ||||
Called when the user clicks Disconnect Cables in the context menu. | Called when the user clicks Disconnect Cables in the context menu. | ||||
@@ -62,6 +62,13 @@ struct ModuleMove : ModuleAction { | |||||
}; | }; | ||||
struct ModuleBypass : ModuleAction { | |||||
bool bypass; | |||||
void undo() override; | |||||
void redo() override; | |||||
}; | |||||
struct ParamChange : ModuleAction { | struct ParamChange : ModuleAction { | ||||
int paramId; | int paramId; | ||||
float oldValue; | float oldValue; | ||||
@@ -243,10 +243,13 @@ void ModuleWidget::saveDialog() { | |||||
save(pathStr); | save(pathStr); | ||||
} | } | ||||
void ModuleWidget::toggleBypass() { | |||||
if (!module) | |||||
return; | |||||
module->bypass ^= true; | |||||
void ModuleWidget_bypassAction(ModuleWidget *moduleWidget) { | |||||
// Push ModuleBypass history action | |||||
history::ModuleBypass *h = new history::ModuleBypass; | |||||
h->bypass = !moduleWidget->module->bypass; | |||||
h->moduleId = moduleWidget->module->id; | |||||
app()->history->push(h); | |||||
h->redo(); | |||||
} | } | ||||
void ModuleWidget::disconnect() { | void ModuleWidget::disconnect() { | ||||
@@ -392,7 +395,7 @@ void ModuleWidget::onHoverKey(const event::HoverKey &e) { | |||||
} break; | } break; | ||||
case GLFW_KEY_E: { | case GLFW_KEY_E: { | ||||
if (app()->window->isModPressed() && !app()->window->isShiftPressed()) { | if (app()->window->isModPressed() && !app()->window->isShiftPressed()) { | ||||
toggleBypass(); | |||||
ModuleWidget_bypassAction(this); | |||||
e.consume(this); | e.consume(this); | ||||
} | } | ||||
} break; | } break; | ||||
@@ -527,7 +530,7 @@ struct ModuleBypassItem : MenuItem { | |||||
rightText = CHECKMARK_STRING " " + rightText; | rightText = CHECKMARK_STRING " " + rightText; | ||||
} | } | ||||
void onAction(const event::Action &e) override { | void onAction(const event::Action &e) override { | ||||
moduleWidget->toggleBypass(); | |||||
ModuleWidget_bypassAction(moduleWidget); | |||||
} | } | ||||
}; | }; | ||||
@@ -30,6 +30,10 @@ json_t *Module::toJson() { | |||||
} | } | ||||
json_object_set_new(rootJ, "params", paramsJ); | json_object_set_new(rootJ, "params", paramsJ); | ||||
// bypass | |||||
if (bypass) | |||||
json_object_set_new(rootJ, "bypass", json_boolean(bypass)); | |||||
// data | // data | ||||
json_t *dataJ = dataToJson(); | json_t *dataJ = dataToJson(); | ||||
if (dataJ) { | if (dataJ) { | ||||
@@ -58,11 +62,15 @@ void Module::fromJson(json_t *rootJ) { | |||||
} | } | ||||
} | } | ||||
// bypass | |||||
json_t *bypassJ = json_object_get(rootJ, "bypass"); | |||||
if (bypassJ) | |||||
bypass = json_boolean_value(bypassJ); | |||||
// data | // data | ||||
json_t *dataJ = json_object_get(rootJ, "data"); | json_t *dataJ = json_object_get(rootJ, "data"); | ||||
if (dataJ) { | |||||
if (dataJ) | |||||
dataFromJson(dataJ); | dataFromJson(dataJ); | ||||
} | |||||
} | } | ||||
void Module::reset() { | void Module::reset() { | ||||
@@ -83,6 +83,19 @@ void ModuleMove::redo() { | |||||
} | } | ||||
void ModuleBypass::undo() { | |||||
ModuleWidget *moduleWidget = app()->scene->rackWidget->getModule(moduleId); | |||||
assert(moduleWidget); | |||||
moduleWidget->module->bypass = !bypass; | |||||
} | |||||
void ModuleBypass::redo() { | |||||
ModuleWidget *moduleWidget = app()->scene->rackWidget->getModule(moduleId); | |||||
assert(moduleWidget); | |||||
moduleWidget->module->bypass = bypass; | |||||
} | |||||
void ParamChange::undo() { | void ParamChange::undo() { | ||||
ModuleWidget *moduleWidget = app()->scene->rackWidget->getModule(moduleId); | ModuleWidget *moduleWidget = app()->scene->rackWidget->getModule(moduleId); | ||||
assert(moduleWidget); | assert(moduleWidget); | ||||