CuteLogger
Fast and simple logging solution for Qt based applications
timelinecommands.h
1 /*
2  * Copyright (c) 2013-2022 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 enum {
34  UndoIdTrimClipIn,
35  UndoIdTrimClipOut,
36  UndoIdFadeIn,
37  UndoIdFadeOut,
38  UndoIdTrimTransitionIn,
39  UndoIdTrimTransitionOut,
40  UndoIdAddTransitionByTrimIn,
41  UndoIdAddTransitionByTrimOut,
42  UndoIdUpdate,
43  UndoIdMoveClip
44 };
45 
46 class AppendCommand : public QUndoCommand
47 {
48 public:
49  AppendCommand(MultitrackModel &model, int trackIndex, const QString &xml, bool skipProxy = false,
50  QUndoCommand *parent = 0);
51  void redo();
52  void undo();
53 private:
54  MultitrackModel &m_model;
55  int m_trackIndex;
56  QString m_xml;
57  UndoHelper m_undoHelper;
58  bool m_skipProxy;
59 };
60 
61 class InsertCommand : public QUndoCommand
62 {
63 public:
64  InsertCommand(MultitrackModel &model, MarkersModel &markersModel, int trackIndex, int position,
65  const QString &xml, bool seek = true, QUndoCommand *parent = 0);
66  void redo();
67  void undo();
68 private:
69  MultitrackModel &m_model;
70  MarkersModel &m_markersModel;
71  int m_trackIndex;
72  int m_position;
73  QString m_xml;
74  QStringList m_oldTracks;
75  UndoHelper m_undoHelper;
76  bool m_seek;
77  bool m_rippleAllTracks;
78  bool m_rippleMarkers;
79  int m_markersShift;
80 };
81 
82 class OverwriteCommand : public QUndoCommand
83 {
84 public:
85  OverwriteCommand(MultitrackModel &model, int trackIndex, int position, const QString &xml,
86  bool seek = true, QUndoCommand *parent = 0);
87  void redo();
88  void undo();
89 private:
90  MultitrackModel &m_model;
91  int m_trackIndex;
92  int m_position;
93  QString m_xml;
94  UndoHelper m_undoHelper;
95  bool m_seek;
96 };
97 
98 class LiftCommand : public QUndoCommand
99 {
100 public:
101  LiftCommand(MultitrackModel &model, int trackIndex, int clipIndex, QUndoCommand *parent = 0);
102  void redo();
103  void undo();
104 private:
105  MultitrackModel &m_model;
106  int m_trackIndex;
107  int m_clipIndex;
108  UndoHelper m_undoHelper;
109 };
110 
111 class RemoveCommand : public QUndoCommand
112 {
113 public:
114  RemoveCommand(MultitrackModel &model, MarkersModel &markersModel, int trackIndex, int clipIndex,
115  QUndoCommand *parent = 0);
116  void redo();
117  void undo();
118 private:
119  MultitrackModel &m_model;
120  MarkersModel &m_markersModel;
121  int m_trackIndex;
122  int m_clipIndex;
123  UndoHelper m_undoHelper;
124  bool m_rippleAllTracks;
125  bool m_rippleMarkers;
126  int m_markerRemoveStart;
127  int m_markerRemoveEnd;
128  QList<Markers::Marker> m_markers;
129 };
130 
131 class NameTrackCommand : public QUndoCommand
132 {
133 public:
134  NameTrackCommand(MultitrackModel &model, int trackIndex, const QString &name,
135  QUndoCommand *parent = 0);
136  void redo();
137  void undo();
138 private:
139  MultitrackModel &m_model;
140  int m_trackIndex;
141  QString m_name;
142  QString m_oldName;
143 };
144 
145 class MergeCommand : public QUndoCommand
146 {
147 public:
148  MergeCommand(MultitrackModel &model, int trackIndex, int clipIndex, QUndoCommand *parent = 0);
149  void redo();
150  void undo();
151 private:
152  MultitrackModel &m_model;
153  int m_trackIndex;
154  int m_clipIndex;
155  UndoHelper m_undoHelper;
156 };
157 
158 class MuteTrackCommand : public QUndoCommand
159 {
160 public:
161  MuteTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
162  void redo();
163  void undo();
164 private:
165  MultitrackModel &m_model;
166  int m_trackIndex;
167  bool m_oldValue;
168 };
169 
170 class HideTrackCommand : public QUndoCommand
171 {
172 public:
173  HideTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
174  void redo();
175  void undo();
176 private:
177  MultitrackModel &m_model;
178  int m_trackIndex;
179  bool m_oldValue;
180 };
181 
182 class CompositeTrackCommand : public QUndoCommand
183 {
184 public:
185  CompositeTrackCommand(MultitrackModel &model, int trackIndex, bool value, QUndoCommand *parent = 0);
186  void redo();
187  void undo();
188 private:
189  MultitrackModel &m_model;
190  int m_trackIndex;
191  bool m_value;
192  bool m_oldValue;
193 };
194 
195 class LockTrackCommand : public QUndoCommand
196 {
197 public:
198  LockTrackCommand(MultitrackModel &model, int trackIndex, bool value, QUndoCommand *parent = 0);
199  void redo();
200  void undo();
201 private:
202  MultitrackModel &m_model;
203  int m_trackIndex;
204  bool m_value;
205  bool m_oldValue;
206 };
207 
208 class MoveClipCommand : public QUndoCommand
209 {
210 public:
211  MoveClipCommand(MultitrackModel &model, MarkersModel &markersModel, int trackDelta, bool ripple,
212  QUndoCommand *parent = 0);
213  void redo();
214  void undo();
215  QMultiMap<int, Mlt::Producer> &selection()
216  {
217  return m_selection;
218  }
219 protected:
220  int id() const
221  {
222  return UndoIdMoveClip;
223  }
224  bool mergeWith(const QUndoCommand *other);
225 private:
226  void redoMarkers();
227  MultitrackModel &m_model;
228  MarkersModel &m_markersModel;
229  int m_trackDelta;
230  bool m_ripple;
231  bool m_rippleAllTracks;
232  bool m_rippleMarkers;
233  UndoHelper m_undoHelper;
234  QMultiMap<int, Mlt::Producer> m_selection; // ordered by position
235  bool m_redo;
236  int m_start;
237  int m_trackIndex;
238  int m_clipIndex;
239  int m_markerOldStart;
240  int m_markerNewStart;
241  QList<Markers::Marker> m_markers;
242 };
243 
244 class TrimCommand : public QUndoCommand
245 {
246 public:
247  explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
248  void setUndoHelper(UndoHelper *helper)
249  {
250  m_undoHelper.reset(helper);
251  }
252 
253 protected:
254  QScopedPointer<UndoHelper> m_undoHelper;
255 };
256 
257 class TrimClipInCommand : public TrimCommand
258 {
259 public:
260  TrimClipInCommand(MultitrackModel &model, MarkersModel &markersModel, int trackIndex, int clipIndex,
261  int delta, bool ripple, bool redo = true, QUndoCommand *parent = 0);
262  void redo();
263  void undo();
264 protected:
265  int id() const
266  {
267  return UndoIdTrimClipIn;
268  }
269  bool mergeWith(const QUndoCommand *other);
270 private:
271  MultitrackModel &m_model;
272  MarkersModel &m_markersModel;
273  int m_trackIndex;
274  int m_clipIndex;
275  int m_delta;
276  bool m_ripple;
277  bool m_rippleAllTracks;
278  bool m_rippleMarkers;
279  bool m_redo;
280  int m_markerRemoveStart;
281  int m_markerRemoveEnd;
282  QList<Markers::Marker> m_markers;
283 };
284 
285 class TrimClipOutCommand : public TrimCommand
286 {
287 public:
288  TrimClipOutCommand(MultitrackModel &model, MarkersModel &markersModel, int trackIndex,
289  int clipIndex, int delta, bool ripple, bool redo = true, QUndoCommand *parent = 0);
290  void redo();
291  void undo();
292 protected:
293  int id() const
294  {
295  return UndoIdTrimClipOut;
296  }
297  bool mergeWith(const QUndoCommand *other);
298 private:
299  MultitrackModel &m_model;
300  MarkersModel &m_markersModel;
301  int m_trackIndex;
302  int m_clipIndex;
303  int m_delta;
304  bool m_ripple;
305  bool m_rippleAllTracks;
306  bool m_rippleMarkers;
307  bool m_redo;
308  int m_markerRemoveStart;
309  int m_markerRemoveEnd;
310  QList<Markers::Marker> m_markers;
311 };
312 
313 class SplitCommand : public QUndoCommand
314 {
315 public:
316  SplitCommand(MultitrackModel &model, int trackIndex, int clipIndex, int position,
317  QUndoCommand *parent = 0);
318  void redo();
319  void undo();
320 private:
321  MultitrackModel &m_model;
322  int m_trackIndex;
323  int m_clipIndex;
324  int m_position;
325  UndoHelper m_undoHelper;
326 };
327 
328 class FadeInCommand : public QUndoCommand
329 {
330 public:
331  FadeInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int duration,
332  QUndoCommand *parent = 0);
333  void redo();
334  void undo();
335 protected:
336  int id() const
337  {
338  return UndoIdFadeIn;
339  }
340  bool mergeWith(const QUndoCommand *other);
341 private:
342  MultitrackModel &m_model;
343  int m_trackIndex;
344  int m_clipIndex;
345  int m_duration;
346  int m_previous;
347 };
348 
349 class FadeOutCommand : public QUndoCommand
350 {
351 public:
352  FadeOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int duration,
353  QUndoCommand *parent = 0);
354  void redo();
355  void undo();
356 protected:
357  int id() const
358  {
359  return UndoIdFadeOut;
360  }
361  bool mergeWith(const QUndoCommand *other);
362 private:
363  MultitrackModel &m_model;
364  int m_trackIndex;
365  int m_clipIndex;
366  int m_duration;
367  int m_previous;
368 };
369 
370 class AddTransitionCommand : public QUndoCommand
371 {
372 public:
373  AddTransitionCommand(TimelineDock &timeline, int trackIndex, int clipIndex, int position,
374  bool ripple, QUndoCommand *parent = 0);
375  void redo();
376  void undo();
377  int getTransitionIndex() const
378  {
379  return m_transitionIndex;
380  }
381 private:
382  TimelineDock &m_timeline;
383  MultitrackModel &m_model;
384  MarkersModel &m_markersModel;
385  int m_trackIndex;
386  int m_clipIndex;
387  int m_position;
388  int m_transitionIndex;
389  bool m_ripple;
390  UndoHelper m_undoHelper;
391  bool m_rippleAllTracks;
392  bool m_rippleMarkers;
393  int m_markerOldStart;
394  int m_markerNewStart;
395  QList<Markers::Marker> m_markers;
396 };
397 
398 class TrimTransitionInCommand : public TrimCommand
399 {
400 public:
401  TrimTransitionInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
402  bool redo = true, QUndoCommand *parent = 0);
403  void redo();
404  void undo();
405 protected:
406  int id() const
407  {
408  return UndoIdTrimTransitionIn;
409  }
410  bool mergeWith(const QUndoCommand *other);
411 private:
412  MultitrackModel &m_model;
413  int m_trackIndex;
414  int m_clipIndex;
415  int m_delta;
416  bool m_notify;
417  bool m_redo;
418 };
419 
420 class TrimTransitionOutCommand : public TrimCommand
421 {
422 public:
423  TrimTransitionOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
424  bool redo = true, QUndoCommand *parent = 0);
425  void redo();
426  void undo();
427 protected:
428  int id() const
429  {
430  return UndoIdTrimTransitionOut;
431  }
432  bool mergeWith(const QUndoCommand *other);
433 private:
434  MultitrackModel &m_model;
435  int m_trackIndex;
436  int m_clipIndex;
437  int m_delta;
438  bool m_notify;
439  bool m_redo;
440 };
441 
442 class AddTransitionByTrimInCommand : public TrimCommand
443 {
444 public:
445  AddTransitionByTrimInCommand(TimelineDock &timeline, int trackIndex, int clipIndex, int duration,
446  int trimDelta, bool redo = true, QUndoCommand *parent = 0);
447  void redo();
448  void undo();
449 protected:
450  int id() const
451  {
452  return UndoIdAddTransitionByTrimIn;
453  }
454  bool mergeWith(const QUndoCommand *other);
455 private:
456  TimelineDock &m_timeline;
457  int m_trackIndex;
458  int m_clipIndex;
459  int m_duration;
460  int m_trimDelta;
461  bool m_notify;
462  bool m_redo;
463 };
464 
465 class RemoveTransitionByTrimInCommand : public TrimCommand
466 {
467 public:
468  RemoveTransitionByTrimInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
469  bool redo = true, QUndoCommand *parent = 0);
470  void redo();
471  void undo();
472 private:
473  MultitrackModel &m_model;
474  int m_trackIndex;
475  int m_clipIndex;
476  int m_delta;
477  bool m_redo;
478 };
479 
480 class RemoveTransitionByTrimOutCommand : public TrimCommand
481 {
482 public:
483  RemoveTransitionByTrimOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
484  bool redo = true, QUndoCommand *parent = 0);
485  void redo();
486  void undo();
487 private:
488  MultitrackModel &m_model;
489  int m_trackIndex;
490  int m_clipIndex;
491  int m_delta;
492  bool m_redo;
493 };
494 
495 class AddTransitionByTrimOutCommand : public TrimCommand
496 {
497 public:
498  AddTransitionByTrimOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int duration,
499  int trimDelta, bool redo = true, QUndoCommand *parent = 0);
500  void redo();
501  void undo();
502 protected:
503  int id() const
504  {
505  return UndoIdAddTransitionByTrimOut;
506  }
507  bool mergeWith(const QUndoCommand *other);
508 private:
509  MultitrackModel &m_model;
510  int m_trackIndex;
511  int m_clipIndex;
512  int m_duration;
513  int m_trimDelta;
514  bool m_notify;
515  bool m_redo;
516 };
517 
518 class AddTrackCommand: public QUndoCommand
519 {
520 public:
521  AddTrackCommand(MultitrackModel &model, bool isVideo, QUndoCommand *parent = 0);
522  void redo();
523  void undo();
524 private:
525  MultitrackModel &m_model;
526  int m_trackIndex;
527  bool m_isVideo;
528 };
529 
530 class InsertTrackCommand : public QUndoCommand
531 {
532 public:
533  InsertTrackCommand(MultitrackModel &model, int trackIndex, TrackType trackType = PlaylistTrackType,
534  QUndoCommand *parent = 0);
535  void redo();
536  void undo();
537 private:
538  MultitrackModel &m_model;
539  int m_trackIndex;
540  TrackType m_trackType;
541 };
542 
543 class RemoveTrackCommand : public QUndoCommand
544 {
545 public:
546  RemoveTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
547  void redo();
548  void undo();
549 private:
550  MultitrackModel &m_model;
551  int m_trackIndex;
552  TrackType m_trackType;
553  QString m_trackName;
554  UndoHelper m_undoHelper;
555  QScopedPointer<Mlt::Producer> m_filtersProducer;
556 };
557 
558 class MoveTrackCommand : public QUndoCommand
559 {
560 public:
561  MoveTrackCommand(MultitrackModel &model, int fromTrackIndex, int toTrackIndex,
562  QUndoCommand *parent = 0);
563  void redo();
564  void undo();
565 private:
566  MultitrackModel &m_model;
567  int m_fromTrackIndex;
568  int m_toTrackIndex;
569 };
570 
571 class ChangeBlendModeCommand : public QObject, public QUndoCommand
572 {
573  Q_OBJECT
574 public:
575  ChangeBlendModeCommand(Mlt::Transition &transition, const QString &propertyName,
576  const QString &mode, QUndoCommand *parent = 0);
577  void redo();
578  void undo();
579 signals:
580  void modeChanged(QString &mode);
581 private:
582  Mlt::Transition m_transition;
583  QString m_propertyName;
584  QString m_newMode;
585  QString m_oldMode;
586 };
587 
588 class UpdateCommand : public QUndoCommand
589 {
590 public:
591  UpdateCommand(TimelineDock &timeline, int trackIndex, int clipIndex, int position,
592  QUndoCommand *parent = 0);
593  void setXmlAfter(const QString &xml);
594  void setPosition(int trackIndex, int clipIndex, int position);
595  int trackIndex() const
596  {
597  return m_trackIndex;
598  }
599  int clipIndex() const
600  {
601  return m_clipIndex;
602  }
603  int position() const
604  {
605  return m_position;
606  }
607  void redo();
608  void undo();
609 private:
610  TimelineDock &m_timeline;
611  int m_trackIndex;
612  int m_clipIndex;
613  int m_position;
614  QString m_xmlAfter;
615  bool m_isFirstRedo;
616  UndoHelper m_undoHelper;
617  bool m_ripple;
618 };
619 
620 class DetachAudioCommand: public QUndoCommand
621 {
622 public:
623  DetachAudioCommand(MultitrackModel &model, int trackIndex, int clipIndex, int position,
624  const QString &xml, QUndoCommand *parent = 0);
625  void redo();
626  void undo();
627 private:
628  MultitrackModel &m_model;
629  int m_trackIndex;
630  int m_clipIndex;
631  int m_position;
632  int m_targetTrackIndex;
633  QString m_xml;
634  UndoHelper m_undoHelper;
635  bool m_trackAdded;
636 };
637 
638 class ReplaceCommand : public QUndoCommand
639 {
640 public:
641  ReplaceCommand(MultitrackModel &model, int trackIndex, int clipIndex, const QString &xml,
642  QUndoCommand *parent = nullptr);
643  void redo();
644  void undo();
645 private:
646  MultitrackModel &m_model;
647  int m_trackIndex;
648  int m_clipIndex;
649  QString m_xml;
650  bool m_isFirstRedo;
651  UndoHelper m_undoHelper;
652 };
653 
654 
655 class AlignClipsCommand : public QUndoCommand
656 {
657 public:
658  AlignClipsCommand(MultitrackModel &model, QUndoCommand *parent = 0);
659  void addAlignment(QUuid uuid, int offset, double speedCompensation);
660  void redo();
661  void undo();
662 
663 private:
664  MultitrackModel &m_model;
665  UndoHelper m_undoHelper;
666  bool m_redo;
667  struct Alignment {
668  QUuid uuid;
669  int offset;
670  double speed;
671  };
672  QVector<Alignment> m_alignments;
673 };
674 
675 
676 } // namespace Timeline
677 
678 #endif