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