You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
1.7KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include "math.hpp"
  4. #include "plugin/Model.hpp"
  5. #include <vector>
  6. #include <jansson.h>
  7. namespace rack {
  8. namespace history {
  9. struct Action {
  10. virtual ~Action() {}
  11. virtual void undo() {}
  12. virtual void redo() {}
  13. };
  14. /** Batches multiple actions into one */
  15. struct ComplexAction : Action {
  16. /** Ordered by time occurred. Undoing will replay them backwards. */
  17. std::vector<Action*> actions;
  18. ~ComplexAction();
  19. void undo() override;
  20. void redo() override;
  21. void push(Action *action);
  22. };
  23. /** An action operating on a module
  24. Subclass this to create your own custom actions for your module.
  25. */
  26. struct ModuleAction : Action {
  27. int moduleId;
  28. };
  29. struct ModuleAdd : ModuleAction {
  30. Model *model;
  31. math::Vec pos;
  32. void undo() override;
  33. void redo() override;
  34. };
  35. struct ModuleRemove : ModuleAction {
  36. Model *model;
  37. math::Vec pos;
  38. json_t *moduleJ;
  39. ~ModuleRemove();
  40. void undo() override;
  41. void redo() override;
  42. };
  43. struct ModuleMove : ModuleAction {
  44. math::Vec oldPos;
  45. math::Vec newPos;
  46. void undo() override;
  47. void redo() override;
  48. };
  49. struct ParamChange : ModuleAction {
  50. int paramId;
  51. float oldValue;
  52. float newValue;
  53. void undo() override;
  54. void redo() override;
  55. };
  56. struct CableAdd : Action {
  57. int cableId;
  58. int outputModuleId;
  59. int outputId;
  60. int inputModuleId;
  61. int inputId;
  62. void undo() override;
  63. void redo() override;
  64. };
  65. struct CableRemove : Action {
  66. int cableId;
  67. int outputModuleId;
  68. int outputId;
  69. int inputModuleId;
  70. int inputId;
  71. void undo() override;
  72. void redo() override;
  73. };
  74. struct State {
  75. std::vector<Action*> actions;
  76. int actionIndex = 0;
  77. ~State();
  78. void push(Action *action);
  79. void undo();
  80. void redo();
  81. };
  82. } // namespace history
  83. } // namespace rack