CuteLogger
Fast and simple logging solution for Qt based applications
timelinecommands.h
1 /*
2  * Copyright (c) 2013-2021 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef COMMANDS_H
19 #define COMMANDS_H
20 
21 #include "models/multitrackmodel.h"
22 #include "models/markersmodel.h"
23 #include "docks/timelinedock.h"
24 #include "undohelper.h"
25 #include <QUndoCommand>
26 #include <QString>
27 #include <QObject>
28 #include <MltTransition.h>
29 #include <MltProducer.h>
30 
31 namespace Timeline
32 {
33 
34 enum {
35  UndoIdTrimClipIn,
36  UndoIdTrimClipOut,
37  UndoIdFadeIn,
38  UndoIdFadeOut,
39  UndoIdTrimTransitionIn,
40  UndoIdTrimTransitionOut,
41  UndoIdAddTransitionByTrimIn,
42  UndoIdAddTransitionByTrimOut,
43  UndoIdUpdate
44 };
45 
46 class AppendCommand : public QUndoCommand
47 {
48 public:
49  AppendCommand(MultitrackModel& model, int trackIndex, const QString& xml, bool skipProxy = false, QUndoCommand * parent = 0);
50  void redo();
51  void undo();
52 private:
53  MultitrackModel& m_model;
54  int m_trackIndex;
55  QString m_xml;
56  UndoHelper m_undoHelper;
57  bool m_skipProxy;
58 };
59 
60 class InsertCommand : public QUndoCommand
61 {
62 public:
63  InsertCommand(MultitrackModel& model, MarkersModel& markersModel, int trackIndex, int position, const QString &xml, bool seek = true, QUndoCommand * parent = 0);
64  void redo();
65  void undo();
66 private:
67  MultitrackModel& m_model;
68  MarkersModel& m_markersModel;
69  int m_trackIndex;
70  int m_position;
71  QString m_xml;
72  QStringList m_oldTracks;
73  UndoHelper m_undoHelper;
74  bool m_seek;
75  bool m_rippleAllTracks;
76  bool m_rippleMarkers;
77  int m_markersShift;
78 };
79 
80 class OverwriteCommand : public QUndoCommand
81 {
82 public:
83  OverwriteCommand(MultitrackModel& model, int trackIndex, int position, const QString &xml, bool seek = true, QUndoCommand * parent = 0);
84  void redo();
85  void undo();
86 private:
87  MultitrackModel& m_model;
88  int m_trackIndex;
89  int m_position;
90  QString m_xml;
91  UndoHelper m_undoHelper;
92  bool m_seek;
93 };
94 
95 class LiftCommand : public QUndoCommand
96 {
97 public:
98  LiftCommand(MultitrackModel& model, int trackIndex, int clipIndex, QUndoCommand * parent = 0);
99  void redo();
100  void undo();
101 private:
102  MultitrackModel& m_model;
103  int m_trackIndex;
104  int m_clipIndex;
105  UndoHelper m_undoHelper;
106 };
107 
108 class RemoveCommand : public QUndoCommand
109 {
110 public:
111  RemoveCommand(MultitrackModel& model, MarkersModel& markersModel, int trackIndex, int clipIndex, QUndoCommand * parent = 0);
112  void redo();
113  void undo();
114 private:
115  MultitrackModel& m_model;
116  MarkersModel& m_markersModel;
117  int m_trackIndex;
118  int m_clipIndex;
119  UndoHelper m_undoHelper;
120  bool m_rippleAllTracks;
121  bool m_rippleMarkers;
122  int m_markerRemoveStart;
123  int m_markerRemoveEnd;
124  QList<Markers::Marker> m_markers;
125 };
126 
127 class NameTrackCommand : public QUndoCommand
128 {
129 public:
130  NameTrackCommand(MultitrackModel& model, int trackIndex, const QString& name, QUndoCommand * parent = 0);
131  void redo();
132  void undo();
133 private:
134  MultitrackModel& m_model;
135  int m_trackIndex;
136  QString m_name;
137  QString m_oldName;
138 };
139 
140 class MergeCommand : public QUndoCommand
141 {
142 public:
143  MergeCommand(MultitrackModel& model, int trackIndex, int clipIndex, QUndoCommand * parent = 0);
144  void redo();
145  void undo();
146 private:
147  MultitrackModel& m_model;
148  int m_trackIndex;
149  int m_clipIndex;
150  UndoHelper m_undoHelper;
151 };
152 
153 class MuteTrackCommand : public QUndoCommand
154 {
155 public:
156  MuteTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
157  void redo();
158  void undo();
159 private:
160  MultitrackModel& m_model;
161  int m_trackIndex;
162  bool m_oldValue;
163 };
164 
165 class HideTrackCommand : public QUndoCommand
166 {
167 public:
168  HideTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand * parent = 0);
169  void redo();
170  void undo();
171 private:
172  MultitrackModel& m_model;
173  int m_trackIndex;
174  bool m_oldValue;
175 };
176 
177 class CompositeTrackCommand : public QUndoCommand
178 {
179 public:
180  CompositeTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
181  void redo();
182  void undo();
183 private:
184  MultitrackModel& m_model;
185  int m_trackIndex;
186  bool m_value;
187  bool m_oldValue;
188 };
189 
190 class LockTrackCommand : public QUndoCommand
191 {
192 public:
193  LockTrackCommand(MultitrackModel& model, int trackIndex, bool value, QUndoCommand * parent = 0);
194  void redo();
195  void undo();
196 private:
197  MultitrackModel& m_model;
198  int m_trackIndex;
199  bool m_value;
200  bool m_oldValue;
201 };
202 
203 class MoveClipCommand : public QUndoCommand
204 {
205 public:
206  MoveClipCommand(MultitrackModel& model, MarkersModel& markersModel, int trackDelta, bool ripple, QUndoCommand * parent = 0);
207  void redo();
208  void undo();
209  QMultiMap<int, Mlt::Producer>& selection() { return m_selection; }
210 
211 private:
212  void redoMarkers();
213  MultitrackModel& m_model;
214  MarkersModel& m_markersModel;
215  int m_trackDelta;
216  bool m_ripple;
217  bool m_rippleAllTracks;
218  bool m_rippleMarkers;
219  UndoHelper m_undoHelper;
220  QMultiMap<int, Mlt::Producer> m_selection; // ordered by position
221  bool m_redo;
222  int m_start;
223  int m_trackIndex;
224  int m_clipIndex;
225  int m_markerOldStart;
226  int m_markerNewStart;
227  QList<Markers::Marker> m_markers;
228 };
229 
230 class TrimCommand : public QUndoCommand
231 {
232 public:
233  explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
234  void setUndoHelper(UndoHelper* helper) { m_undoHelper.reset(helper); }
235 
236 protected:
237  QScopedPointer<UndoHelper> m_undoHelper;
238 };
239 
240 class TrimClipInCommand : public TrimCommand
241 {
242 public:
243  TrimClipInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
244  void redo();
245  void undo();
246 protected:
247  int id() const { return UndoIdTrimClipIn; }
248  bool mergeWith(const QUndoCommand *other);
249 private:
250  MultitrackModel& m_model;
251  int m_trackIndex;
252  int m_clipIndex;
253  int m_delta;
254  bool m_ripple;
255  bool m_rippleAllTracks;
256  bool m_redo;
257 };
258 
259 class TrimClipOutCommand : public TrimCommand
260 {
261 public:
262  TrimClipOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand * parent = 0);
263  void redo();
264  void undo();
265 protected:
266  int id() const { return UndoIdTrimClipOut; }
267  bool mergeWith(const QUndoCommand *other);
268 private:
269  MultitrackModel& m_model;
270  int m_trackIndex;
271  int m_clipIndex;
272  int m_delta;
273  bool m_ripple;
274  bool m_rippleAllTracks;
275  bool m_redo;
276 };
277 
278 class SplitCommand : public QUndoCommand
279 {
280 public:
281  SplitCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, QUndoCommand * parent = 0);
282  void redo();
283  void undo();
284 private:
285  MultitrackModel& m_model;
286  int m_trackIndex;
287  int m_clipIndex;
288  int m_position;
289  UndoHelper m_undoHelper;
290 };
291 
292 class FadeInCommand : public QUndoCommand
293 {
294 public:
295  FadeInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
296  void redo();
297  void undo();
298 protected:
299  int id() const { return UndoIdFadeIn; }
300  bool mergeWith(const QUndoCommand *other);
301 private:
302  MultitrackModel& m_model;
303  int m_trackIndex;
304  int m_clipIndex;
305  int m_duration;
306  int m_previous;
307 };
308 
309 class FadeOutCommand : public QUndoCommand
310 {
311 public:
312  FadeOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, QUndoCommand * parent = 0);
313  void redo();
314  void undo();
315 protected:
316  int id() const { return UndoIdFadeOut; }
317  bool mergeWith(const QUndoCommand *other);
318 private:
319  MultitrackModel& m_model;
320  int m_trackIndex;
321  int m_clipIndex;
322  int m_duration;
323  int m_previous;
324 };
325 
326 class AddTransitionCommand : public QUndoCommand
327 {
328 public:
329  AddTransitionCommand(TimelineDock& timeline, int trackIndex, int clipIndex, int position, bool ripple, QUndoCommand * parent = 0);
330  void redo();
331  void undo();
332  int getTransitionIndex() const { return m_transitionIndex; }
333 private:
334  TimelineDock& m_timeline;
335  MultitrackModel& m_model;
336  MarkersModel& m_markersModel;
337  int m_trackIndex;
338  int m_clipIndex;
339  int m_position;
340  int m_transitionIndex;
341  bool m_ripple;
342  UndoHelper m_undoHelper;
343  bool m_rippleAllTracks;
344  bool m_rippleMarkers;
345  int m_markerOldStart;
346  int m_markerNewStart;
347  QList<Markers::Marker> m_markers;
348 };
349 
350 class TrimTransitionInCommand : public TrimCommand
351 {
352 public:
353  TrimTransitionInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
354  void redo();
355  void undo();
356 protected:
357  int id() const { return UndoIdTrimTransitionIn; }
358  bool mergeWith(const QUndoCommand *other);
359 private:
360  MultitrackModel& m_model;
361  int m_trackIndex;
362  int m_clipIndex;
363  int m_delta;
364  bool m_notify;
365  bool m_redo;
366 };
367 
368 class TrimTransitionOutCommand : public TrimCommand
369 {
370 public:
371  TrimTransitionOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
372  void redo();
373  void undo();
374 protected:
375  int id() const { return UndoIdTrimTransitionOut; }
376  bool mergeWith(const QUndoCommand *other);
377 private:
378  MultitrackModel& m_model;
379  int m_trackIndex;
380  int m_clipIndex;
381  int m_delta;
382  bool m_notify;
383  bool m_redo;
384 };
385 
386 class AddTransitionByTrimInCommand : public TrimCommand
387 {
388 public:
389  AddTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, int trimDelta, bool redo = true, QUndoCommand * parent = 0);
390  void redo();
391  void undo();
392 protected:
393  int id() const { return UndoIdAddTransitionByTrimIn; }
394  bool mergeWith(const QUndoCommand *other);
395 private:
396  MultitrackModel& m_model;
397  int m_trackIndex;
398  int m_clipIndex;
399  int m_duration;
400  int m_trimDelta;
401  bool m_notify;
402  bool m_redo;
403 };
404 
405 class RemoveTransitionByTrimInCommand : public TrimCommand
406 {
407 public:
408  RemoveTransitionByTrimInCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
409  void redo();
410  void undo();
411 private:
412  MultitrackModel& m_model;
413  int m_trackIndex;
414  int m_clipIndex;
415  int m_delta;
416  bool m_redo;
417 };
418 
419 class RemoveTransitionByTrimOutCommand : public TrimCommand
420 {
421 public:
422  RemoveTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int delta, bool redo = true, QUndoCommand * parent = 0);
423  void redo();
424  void undo();
425 private:
426  MultitrackModel& m_model;
427  int m_trackIndex;
428  int m_clipIndex;
429  int m_delta;
430  bool m_redo;
431 };
432 
433 class AddTransitionByTrimOutCommand : public TrimCommand
434 {
435 public:
436  AddTransitionByTrimOutCommand(MultitrackModel& model, int trackIndex, int clipIndex, int duration, int trimDelta, bool redo = true, QUndoCommand * parent = 0);
437  void redo();
438  void undo();
439 protected:
440  int id() const { return UndoIdAddTransitionByTrimOut; }
441  bool mergeWith(const QUndoCommand *other);
442 private:
443  MultitrackModel& m_model;
444  int m_trackIndex;
445  int m_clipIndex;
446  int m_duration;
447  int m_trimDelta;
448  bool m_notify;
449  bool m_redo;
450 };
451 
452 class AddTrackCommand: public QUndoCommand
453 {
454 public:
455  AddTrackCommand(MultitrackModel& model, bool isVideo, QUndoCommand* parent = 0);
456  void redo();
457  void undo();
458 private:
459  MultitrackModel& m_model;
460  int m_trackIndex;
461  bool m_isVideo;
462 };
463 
464 class InsertTrackCommand : public QUndoCommand
465 {
466 public:
467  InsertTrackCommand(MultitrackModel& model, int trackIndex, TrackType trackType = PlaylistTrackType, QUndoCommand* parent = 0);
468  void redo();
469  void undo();
470 private:
471  MultitrackModel& m_model;
472  int m_trackIndex;
473  TrackType m_trackType;
474 };
475 
476 class RemoveTrackCommand : public QUndoCommand
477 {
478 public:
479  RemoveTrackCommand(MultitrackModel& model, int trackIndex, QUndoCommand* parent = 0);
480  void redo();
481  void undo();
482 private:
483  MultitrackModel& m_model;
484  int m_trackIndex;
485  TrackType m_trackType;
486  QString m_trackName;
487  UndoHelper m_undoHelper;
488  QScopedPointer<Mlt::Producer> m_filtersProducer;
489 };
490 
491 class ChangeBlendModeCommand : public QObject, public QUndoCommand
492 {
493  Q_OBJECT
494 public:
495  ChangeBlendModeCommand(Mlt::Transition& transition, const QString& propertyName, const QString& mode, QUndoCommand* parent = 0);
496  void redo();
497  void undo();
498 signals:
499  void modeChanged(QString& mode);
500 private:
501  Mlt::Transition m_transition;
502  QString m_propertyName;
503  QString m_newMode;
504  QString m_oldMode;
505 };
506 
507 class UpdateCommand : public QUndoCommand
508 {
509 public:
510  UpdateCommand(TimelineDock& timeline, int trackIndex, int clipIndex, int position,
511  QUndoCommand * parent = 0);
512  void setXmlAfter(const QString& xml) { m_xmlAfter = xml; }
513  void setPosition(int trackIndex, int clipIndex, int position);
514  int trackIndex() const {return m_trackIndex;}
515  int clipIndex() const {return m_clipIndex;}
516  int position() const {return m_position;}
517  void redo();
518  void undo();
519 private:
520  TimelineDock& m_timeline;
521  int m_trackIndex;
522  int m_clipIndex;
523  int m_position;
524  QString m_xmlAfter;
525  bool m_isFirstRedo;
526  UndoHelper m_undoHelper;
527 };
528 
529 class DetachAudioCommand: public QUndoCommand
530 {
531 public:
532  DetachAudioCommand(MultitrackModel& model, int trackIndex, int clipIndex, int position, const QString& xml, QUndoCommand* parent = 0);
533  void redo();
534  void undo();
535 private:
536  MultitrackModel& m_model;
537  int m_trackIndex;
538  int m_clipIndex;
539  int m_position;
540  int m_targetTrackIndex;
541  QString m_xml;
542  UndoHelper m_undoHelper;
543  bool m_trackAdded;
544 };
545 
546 class ReplaceCommand : public QUndoCommand
547 {
548 public:
549  ReplaceCommand(MultitrackModel& model, int trackIndex, int clipIndex, const QString& xml, QUndoCommand* parent = nullptr);
550  void redo();
551  void undo();
552 private:
553  MultitrackModel& m_model;
554  int m_trackIndex;
555  int m_clipIndex;
556  QString m_xml;
557  bool m_isFirstRedo;
558  UndoHelper m_undoHelper;
559 };
560 
561 } // namespace Timeline
562 
563 #endif