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.

123 lines
1.8KB

  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. /** An action operating on a module
  15. Subclass this to create your own custom actions for your module.
  16. */
  17. struct ModuleAction : Action {
  18. int moduleId;
  19. };
  20. struct ModuleAdd : ModuleAction {
  21. Model *model;
  22. math::Vec pos;
  23. void undo() override;
  24. void redo() override;
  25. };
  26. struct ModuleRemove : ModuleAction {
  27. Model *model;
  28. math::Vec pos;
  29. json_t *moduleJ;
  30. struct CableInfo {
  31. int cableId;
  32. int outputModuleId;
  33. int outputId;
  34. int inputModuleId;
  35. int inputId;
  36. };
  37. std::vector<CableInfo> cableInfos;
  38. ~ModuleRemove();
  39. void undo() override;
  40. void redo() override;
  41. };
  42. struct ModuleMove : ModuleAction {
  43. math::Vec oldPos;
  44. math::Vec newPos;
  45. void undo() override;
  46. void redo() override;
  47. };
  48. struct ParamChange : ModuleAction {
  49. int paramId;
  50. float oldValue;
  51. float newValue;
  52. void undo() override;
  53. void redo() override;
  54. };
  55. struct CableAdd : Action {
  56. int cableId;
  57. int outputModuleId;
  58. int outputId;
  59. int inputModuleId;
  60. int inputId;
  61. void undo() override;
  62. void redo() override;
  63. };
  64. struct CableRemove : Action {
  65. int cableId;
  66. int outputModuleId;
  67. int outputId;
  68. int inputModuleId;
  69. int inputId;
  70. void undo() override;
  71. void redo() override;
  72. };
  73. struct CableMove : Action {
  74. int cableId;
  75. int oldOutputModuleId;
  76. int oldOutputId;
  77. int oldInputModuleId;
  78. int oldInputId;
  79. int newOutputModuleId;
  80. int newOutputId;
  81. int newInputModuleId;
  82. int newInputId;
  83. void undo() override;
  84. void redo() override;
  85. };
  86. struct State {
  87. std::vector<Action*> actions;
  88. int actionIndex = 0;
  89. ~State();
  90. void push(Action *action);
  91. void undo();
  92. void redo();
  93. };
  94. } // namespace history
  95. } // namespace rack