Browse Source

Add ModuleBypass. Serialize Module::bypass.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
19d9fdd041
5 changed files with 39 additions and 9 deletions
  1. +0
    -1
      include/app/ModuleWidget.hpp
  2. +7
    -0
      include/history.hpp
  3. +9
    -6
      src/app/ModuleWidget.cpp
  4. +10
    -2
      src/engine/Module.cpp
  5. +13
    -0
      src/history.cpp

+ 0
- 1
include/app/ModuleWidget.hpp View File

@@ -41,7 +41,6 @@ struct ModuleWidget : OpaqueWidget {
void save(std::string filename);
void loadDialog();
void saveDialog();
void toggleBypass();

/** Disconnects cables from all ports
Called when the user clicks Disconnect Cables in the context menu.


+ 7
- 0
include/history.hpp View File

@@ -62,6 +62,13 @@ struct ModuleMove : ModuleAction {
};


struct ModuleBypass : ModuleAction {
bool bypass;
void undo() override;
void redo() override;
};


struct ParamChange : ModuleAction {
int paramId;
float oldValue;


+ 9
- 6
src/app/ModuleWidget.cpp View File

@@ -243,10 +243,13 @@ void ModuleWidget::saveDialog() {
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() {
@@ -392,7 +395,7 @@ void ModuleWidget::onHoverKey(const event::HoverKey &e) {
} break;
case GLFW_KEY_E: {
if (app()->window->isModPressed() && !app()->window->isShiftPressed()) {
toggleBypass();
ModuleWidget_bypassAction(this);
e.consume(this);
}
} break;
@@ -527,7 +530,7 @@ struct ModuleBypassItem : MenuItem {
rightText = CHECKMARK_STRING " " + rightText;
}
void onAction(const event::Action &e) override {
moduleWidget->toggleBypass();
ModuleWidget_bypassAction(moduleWidget);
}
};



+ 10
- 2
src/engine/Module.cpp View File

@@ -30,6 +30,10 @@ json_t *Module::toJson() {
}
json_object_set_new(rootJ, "params", paramsJ);

// bypass
if (bypass)
json_object_set_new(rootJ, "bypass", json_boolean(bypass));

// data
json_t *dataJ = dataToJson();
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
json_t *dataJ = json_object_get(rootJ, "data");
if (dataJ) {
if (dataJ)
dataFromJson(dataJ);
}
}

void Module::reset() {


+ 13
- 0
src/history.cpp View File

@@ -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() {
ModuleWidget *moduleWidget = app()->scene->rackWidget->getModule(moduleId);
assert(moduleWidget);


Loading…
Cancel
Save