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 bool isCable(app::CableWidget* cw) const;
146 void undo() override;
147 void redo() override;
149 name = "add cable";
150 }
151};
152
153
154struct CableRemove : InverseAction<CableAdd> {
156 name = "remove cable";
157 }
158};
159
160
162 int64_t cableId;
163 NVGcolor newColor;
164 NVGcolor oldColor;
166 void undo() override;
167 void redo() override;
169 name = "change cable color";
170 }
171};
172
173
174struct State {
175 struct Internal;
176 Internal* internal;
177
178 std::deque<Action*> actions;
182
186 void push(Action* action);
187 void undo();
188 void redo();
189 bool canUndo();
190 bool canRedo();
191 std::string getUndoName();
192 std::string getRedoName();
193 void setSaved();
194 bool isSaved();
195};
196
197
198} // namespace history
199} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:32
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Definition CableWidget.hpp:31
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
bool isCable(app::CableWidget *cw) const
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:148
void undo() override
int64_t inputModuleId
Definition history.hpp:139
Definition history.hpp:161
CableColorChange()
Definition history.hpp:168
void setCable(app::CableWidget *cw)
NVGcolor oldColor
Definition history.hpp:164
NVGcolor newColor
Definition history.hpp:163
int64_t cableId
Definition history.hpp:162
Definition history.hpp:154
CableRemove()
Definition history.hpp:155
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:174
int actionIndex
Definition history.hpp:179
void push(Action *action)
int savedIndex
Action index of saved patch state.
Definition history.hpp:181
PRIVATE void clear()
std::string getUndoName()
std::deque< Action * > actions
Definition history.hpp:178
std::string getRedoName()
Internal * internal
Definition history.hpp:176
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