File: edit_commands.cpp

package info (click to toggle)
zytrax 0%2Bgit20201215-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,488 kB
  • sloc: cpp: 41,800; ansic: 3,387; makefile: 8; sh: 3
file content (281 lines) | stat: -rw-r--r-- 8,304 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "edit_commands.h"
#if 0
void EditCommands::automation_set_point(Automation *p_automation, int p_pattern, Tick p_offset, float p_value) {

	String action_name; // action is too generic, for performance and memory, name is omitted.

	CommandBase *undo=NULL;
	if (p_automation->has_point(p_pattern,p_offset)) {
		float prev = p_automation->get_point(p_pattern,p_offset);
		undo=command(p_automation,&Automation::set_point,p_pattern,p_offset,prev);
	} else {

		undo=command(p_automation,&Automation::remove_point,p_pattern,p_offset);
	}

	add_action(
		action_name,
		command(p_automation,&Automation::set_point,p_pattern,p_offset,p_value),
		undo
	);



}

void EditCommands::automation_remove_point(Automation *p_automation, int p_pattern, Tick p_offset) {

	String action_name; // action is too generic, for performance and memory, name is omitted.

	if (!p_automation->has_point(p_pattern,p_offset))
		return; //removing what isn't there is pointless..

	float prev = p_automation->get_point(p_pattern,p_offset);

	add_action(
		action_name,
		command(p_automation,&Automation::remove_point,p_pattern,p_offset),
		command(p_automation,&Automation::set_point,p_pattern,p_offset,prev)
	);

}

void EditCommands::track_add_audio_effect(Track *p_track, AudioEffect *p_effect,int p_pos) {

	String action_name = "Add Effect: "+p_effect->get_info()->caption;

	if (p_pos<0)
		p_pos=p_track->get_audio_effect_count();
	else if (p_pos>p_track->get_audio_effect_count())
		p_pos=p_track->get_audio_effect_count();

	add_action(
		action_name,
		command(p_track,&Track::add_audio_effect,p_effect,p_pos)->with_data(p_effect),
		command(p_track,&Track::remove_audio_effect,p_pos)
	);

}
void EditCommands::track_remove_audio_effect(Track *p_track, int p_pos) {

	ERR_FAIL_INDEX(p_pos,p_track->get_audio_effect_count());
	AudioEffect* effect = p_track->get_audio_effect(p_pos);

	String action_name = "Remove Effect: "+effect->get_info()->caption;

	add_action(
		action_name,
		command(p_track,&Track::remove_audio_effect,p_pos),
		command(p_track,&Track::add_audio_effect,effect,p_pos)->with_data(effect)
	);

}

void EditCommands::track_add_automation(Track *p_track, Automation *p_automation,int p_pos) {

	String action_name = "Add Automation: "+p_automation->get_control_port()->get_name();

	if (p_pos<0)
		p_pos=p_track->get_automation_count();
	else if (p_pos>p_track->get_automation_count())
		p_pos=p_track->get_automation_count();

	add_action(
		action_name,
		command(p_track,&Track::add_automation,p_automation,p_pos)->with_data(p_automation),
		command(p_track,&Track::remove_automation,p_pos)
	);

}
void EditCommands::track_remove_automation(Track *p_track, int p_pos) {

	ERR_FAIL_INDEX(p_pos,p_track->get_automation_count());
	Automation* automation = p_track->get_automation(p_pos);

	String action_name = "Remove Automation: "+automation->get_control_port()->get_name();

	add_action(
		action_name,
		command(p_track,&Track::remove_automation,p_pos),
		command(p_track,&Track::add_automation,automation,p_pos)->with_data(automation)
	);

}

void EditCommands::song_pattern_set_beats(Song *p_song, int p_pattern, int p_beats) {


	String action_name = "Pattern "+String::num(p_pattern)+" Set Beats";
	int old_beats = p_song->pattern_get_beats(p_pattern);
	add_action(
		action_name,
		command(p_song,&Song::pattern_set_beats,p_pattern,p_beats),
		command(p_song,&Song::pattern_set_beats,p_pattern,old_beats)
	);

}

void EditCommands::song_pattern_set_measure(Song *p_song, int p_pattern, int p_measure) {

	String action_name = "Pattern "+String::num(p_pattern)+" Set Measure";
	int old_measure = p_song->pattern_get_measure(p_pattern);
	add_action(
		action_name,
		command(p_song,&Song::pattern_set_measure,p_pattern,p_measure),
		command(p_song,&Song::pattern_set_measure,p_pattern,old_measure)
	);

}
void EditCommands::song_pattern_set_bars(Song *p_song, int p_pattern, int p_bars) {

	String action_name = "Pattern "+String::num(p_pattern)+" Set Bars";
	int old_bars = p_song->pattern_get_bars(p_pattern);
	add_action(
		action_name,
		command(p_song,&Song::pattern_set_bars,p_pattern,p_bars),
		command(p_song,&Song::pattern_set_bars,p_pattern,old_bars)
	);

}

void EditCommands::song_order_set(Song *p_song,int p_order, int p_pattern) {

	String action_name = "Set Order "+String::num(p_order);
	int old_pattern = p_song->order_get(p_order);
	add_action(
		action_name,
		command(p_song,&Song::order_set,p_order,p_pattern),
		command(p_song,&Song::order_set,p_order,old_pattern)
	);

}
void EditCommands::song_track_add(Song *p_song,Track *p_track,int p_pos) {

	String type;
	switch(p_track->get_type()) {
		case Track::TYPE_AUDIO: type="Audio"; break;
		case Track::TYPE_PATTERN: type="Pattern"; break;
		case Track::TYPE_GLOBAL: type="Global"; break;
	}

	String action_name = "Add "+type+" Track";
	// validate p_pos
	if (p_pos<0)
		p_pos=p_song->get_track_count(); //by default add last
	else if (p_pos>p_song->get_track_count())
		p_pos=p_song->get_track_count();

	add_action(
		action_name,
		command(p_song,&Song::add_track,p_track,p_pos)->with_data(p_track),
		command(p_song,&Song::remove_track,p_pos)
	);

}
void EditCommands::song_track_remove(Song *p_song,int p_pos) {

	String action_name = "Remove Track "+String::num(p_pos);
	// validate p_pos
	if (p_pos<0 || p_pos>=p_song->get_track_count())
		return;

	Track *track = p_song->get_track(p_pos);
	ERR_FAIL_COND(!track);

	add_action(
		action_name,
		command(p_song,&Song::remove_track,p_pos),
		command(p_song,&Song::add_track,track,p_pos)->with_data(track)
	);

}

void EditCommands::pattern_track_set_note_columns(PatternTrack *p_pattern_track,int p_columns) {

	String action_name = "Pattern Track Set To "+String::num(p_columns)+ " Note Columns";
	// validate p_pos
	ERR_FAIL_COND(p_columns<1 || p_columns>256);

	int old_columns=p_pattern_track->get_note_columns();

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_note_columns,p_columns),
		command(p_pattern_track,&PatternTrack::set_note_columns,old_columns)
	);
}

void EditCommands::pattern_track_set_note(PatternTrack *p_pattern_track,int p_pattern, PatternPos p_pos, PatternNote p_note) {

	String action_name; //action too generic
	// validate p_pos

	PatternNote old_note = p_pattern_track->get_note(p_pattern,p_pos);
	if (old_note==p_note)
		return;

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_note,p_pattern,p_pos,p_note),
		command(p_pattern_track,&PatternTrack::set_note,p_pattern,p_pos,old_note)
	);

}

void EditCommands::pattern_track_set_command_columns(PatternTrack *p_pattern_track,int p_columns) {

	String action_name = "Pattern Track Set To "+String::num(p_columns)+ " Command Columns";
	// validate p_pos
	ERR_FAIL_COND(p_columns<0 || p_columns>256);

	int old_columns=p_pattern_track->get_note_columns();

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_note_columns,p_columns),
		command(p_pattern_track,&PatternTrack::set_note_columns,old_columns)
	);
}
void EditCommands::pattern_track_set_command(PatternTrack *p_pattern_track,int p_pattern, PatternPos p_pos, PatternCommand p_command) {

	String action_name; //action too generic
	// validate p_pos
	PatternCommand old_command = p_pattern_track->get_command(p_pattern,p_pos);
	if (old_command==p_command)
		return;

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_command,p_pattern,p_pos,p_command),
		command(p_pattern_track,&PatternTrack::set_command,p_pattern,p_pos,old_command)
	);

}

void EditCommands::pattern_track_set_swing(PatternTrack *p_pattern_track,float p_swing) {

	String action_name = "Pattern Track Set Swing";
	// validate p_pos
	float old_swing=p_pattern_track->get_swing();

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_swing,p_swing),
		command(p_pattern_track,&PatternTrack::set_swing,old_swing)
	);

}
void EditCommands::pattern_track_set_swing_step(PatternTrack *p_pattern_track,int p_swing_step) {

	String action_name = "Pattern Track Set Swing Step";
	// validate p_pos
	int old_swing_step=p_pattern_track->get_swing_step();

	add_action(
		action_name,
		command(p_pattern_track,&PatternTrack::set_swing_step,p_swing_step),
		command(p_pattern_track,&PatternTrack::set_swing_step,old_swing_step)
	);

}
#endif