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