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