VCV Rack API v2
Loading...
Searching...
No Matches
history.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <deque>
4
5#include <jansson.h>
6
7#include <common.hpp>
8#include <math.hpp>
9#include <color.hpp>
10#include <plugin/Model.hpp>
11
12
13namespace rack {
14
15
16namespace app {
17struct ModuleWidget;
18struct CableWidget;
19} // namespace app
20
21
23namespace history {
24
25
31struct Action {
33 std::string name;
34 virtual ~Action() {}
35 virtual void undo() {}
36 virtual void redo() {}
37};
38
39
40template <class TAction>
41struct InverseAction : TAction {
42 void undo() override {
43 TAction::redo();
44 }
45 void redo() override {
46 TAction::undo();
47 }
48};
49
50
54 std::vector<Action*> actions;
56 void undo() override;
57 void redo() override;
58 void push(Action* action);
59 bool isEmpty();
60};
61
62
67 int64_t moduleId;
68};
69
70
74 json_t* moduleJ;
76 name = "add module";
77 }
80 void undo() override;
81 void redo() override;
82};
83
84
85struct ModuleRemove : InverseAction<ModuleAdd> {
87 name = "remove module";
88 }
89};
90
91
95 void undo() override;
96 void redo() override;
98 name = "move module";
99 }
100};
101
102
105 void undo() override;
106 void redo() override;
108 name = "bypass module";
109 }
110};
111
112
114 json_t* oldModuleJ;
115 json_t* newModuleJ;
117 name = "change module";
118 }
120 void undo() override;
121 void redo() override;
122};
123
124
127 float oldValue;
128 float newValue;
129 void undo() override;
130 void redo() override;
132 name = "change parameter";
133 }
134};
135
136
137struct CableAdd : Action {
138 int64_t cableId;
143 NVGcolor color;
145 void undo() override;
146 void redo() override;
148 name = "add cable";
149 }
150};
151
152
153struct CableRemove : InverseAction<CableAdd> {
155 name = "remove cable";
156 }
157};
158
159
161 int64_t cableId;
162 NVGcolor newColor;
163 NVGcolor oldColor;
165 void undo() override;
166 void redo() override;
168 name = "change cable color";
169 }
170};
171
172
173struct State {
174 struct Internal;
175 Internal* internal;
176
177 std::deque<Action*> actions;
181
185 void push(Action* action);
186 void undo();
187 void redo();
188 bool canUndo();
189 bool canRedo();
190 std::string getUndoName();
191 std::string getRedoName();
192 void setSaved();
193 bool isSaved();
194};
195
196
197} // namespace history
198} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:30
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Definition CableWidget.hpp:16
Manages an engine::Module in the rack.
Definition ModuleWidget.hpp:17
An undo action with an inverse redo action.
Definition history.hpp:31
std::string name
Name of the action, lowercase.
Definition history.hpp:33
virtual ~Action()
Definition history.hpp:34
virtual void undo()
Definition history.hpp:35
virtual void redo()
Definition history.hpp:36
Definition history.hpp:137
void redo() override
int64_t outputModuleId
Definition history.hpp:141
int64_t cableId
Definition history.hpp:138
NVGcolor color
Definition history.hpp:143
int outputId
Definition history.hpp:142
int inputId
Definition history.hpp:140
void setCable(app::CableWidget *cw)
CableAdd()
Definition history.hpp:147
void undo() override
int64_t inputModuleId
Definition history.hpp:139
Definition history.hpp:160
CableColorChange()
Definition history.hpp:167
void setCable(app::CableWidget *cw)
NVGcolor oldColor
Definition history.hpp:163
NVGcolor newColor
Definition history.hpp:162
int64_t cableId
Definition history.hpp:161
Definition history.hpp:153
CableRemove()
Definition history.hpp:154
Batches multiple actions into one.
Definition history.hpp:52
std::vector< Action * > actions
Ordered by time occurred.
Definition history.hpp:54
void push(Action *action)
Definition history.hpp:41
void undo() override
Definition history.hpp:42
void redo() override
Definition history.hpp:45
An action operating on a module.
Definition history.hpp:66
int64_t moduleId
Definition history.hpp:67
Definition history.hpp:71
void setModule(app::ModuleWidget *mw)
void redo() override
void undo() override
json_t * moduleJ
Definition history.hpp:74
ModuleAdd()
Definition history.hpp:75
math::Vec pos
Definition history.hpp:73
plugin::Model * model
Definition history.hpp:72
Definition history.hpp:103
bool bypassed
Definition history.hpp:104
ModuleBypass()
Definition history.hpp:107
Definition history.hpp:113
json_t * newModuleJ
Definition history.hpp:115
json_t * oldModuleJ
Definition history.hpp:114
ModuleChange()
Definition history.hpp:116
Definition history.hpp:92
ModuleMove()
Definition history.hpp:97
math::Vec newPos
Definition history.hpp:94
math::Vec oldPos
Definition history.hpp:93
Definition history.hpp:85
ModuleRemove()
Definition history.hpp:86
Definition history.hpp:125
float oldValue
Definition history.hpp:127
float newValue
Definition history.hpp:128
int paramId
Definition history.hpp:126
ParamChange()
Definition history.hpp:131
Definition history.hpp:173
int actionIndex
Definition history.hpp:178
void push(Action *action)
int savedIndex
Action index of saved patch state.
Definition history.hpp:180
PRIVATE void clear()
std::string getUndoName()
std::deque< Action * > actions
Definition history.hpp:177
std::string getRedoName()
Internal * internal
Definition history.hpp:175
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Type information for a module.
Definition Model.hpp:34