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.

history.hpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 ModuleBypass : ModuleAction {
  50. bool bypass;
  51. void undo() override;
  52. void redo() override;
  53. };
  54. struct ParamChange : ModuleAction {
  55. int paramId;
  56. float oldValue;
  57. float newValue;
  58. void undo() override;
  59. void redo() override;
  60. };
  61. struct CableAdd : Action {
  62. int cableId;
  63. int outputModuleId;
  64. int outputId;
  65. int inputModuleId;
  66. int inputId;
  67. void undo() override;
  68. void redo() override;
  69. };
  70. struct CableRemove : Action {
  71. int cableId;
  72. int outputModuleId;
  73. int outputId;
  74. int inputModuleId;
  75. int inputId;
  76. void undo() override;
  77. void redo() override;
  78. };
  79. struct State {
  80. std::vector<Action*> actions;
  81. int actionIndex = 0;
  82. ~State();
  83. void push(Action *action);
  84. void undo();
  85. void redo();
  86. };
  87. } // namespace history
  88. } // namespace rack