#pragma once #include "common.hpp" #include "math.hpp" #include "color.hpp" #include "plugin/Model.hpp" #include #include namespace rack { struct ModuleWidget; struct CableWidget; namespace history { struct Action { virtual ~Action() {} virtual void undo() {} virtual void redo() {} }; template struct InverseAction : TAction { void undo() override { TAction::redo(); } void redo() override { TAction::undo(); } }; /** Batches multiple actions into one */ struct ComplexAction : Action { /** Ordered by time occurred. Undoing will replay them backwards. */ std::vector actions; ~ComplexAction(); void undo() override; void redo() override; void push(Action *action); }; /** An action operating on a module Subclass this to create your own custom actions for your module. */ struct ModuleAction : Action { int moduleId; }; struct ModuleAdd : ModuleAction { Model *model; math::Vec pos; json_t *moduleJ; ~ModuleAdd(); void setModule(ModuleWidget *mw); void undo() override; void redo() override; }; struct ModuleRemove : InverseAction {}; struct ModuleMove : ModuleAction { math::Vec oldPos; math::Vec newPos; void undo() override; void redo() override; }; struct ModuleBypass : ModuleAction { bool bypass; void undo() override; void redo() override; }; struct ModuleChange : ModuleAction { json_t *oldModuleJ; json_t *newModuleJ; ~ModuleChange(); void undo() override; void redo() override; }; struct ParamChange : ModuleAction { int paramId; float oldValue; float newValue; void undo() override; void redo() override; }; struct CableAdd : Action { int cableId; int outputModuleId; int outputId; int inputModuleId; int inputId; NVGcolor color; void setCable(CableWidget *cw); void undo() override; void redo() override; }; struct CableRemove : InverseAction {}; struct State { std::vector actions; int actionIndex = 0; ~State(); void clear(); void push(Action *action); void undo(); void redo(); bool canUndo(); bool canRedo(); }; } // namespace history } // namespace rack