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
31namespace Timeline {
32
33enum {
34 UndoIdTrimClipIn,
35 UndoIdTrimClipOut,
36 UndoIdFadeIn,
37 UndoIdFadeOut,
38 UndoIdTrimTransitionIn,
39 UndoIdTrimTransitionOut,
40 UndoIdAddTransitionByTrimIn,
41 UndoIdAddTransitionByTrimOut,
42 UndoIdUpdate,
43 UndoIdMoveClip
44};
45
46class AppendCommand : public QUndoCommand
47{
48public:
49 AppendCommand(MultitrackModel &model, int trackIndex, const QString &xml, bool skipProxy = false,
50 QUndoCommand *parent = 0);
51 void redo();
52 void undo();
53private:
54 MultitrackModel &m_model;
55 int m_trackIndex;
56 QString m_xml;
57 UndoHelper m_undoHelper;
58 bool m_skipProxy;
59};
60
61class InsertCommand : public QUndoCommand
62{
63public:
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();
68private:
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
82class OverwriteCommand : public QUndoCommand
83{
84public:
85 OverwriteCommand(MultitrackModel &model, int trackIndex, int position, const QString &xml,
86 bool seek = true, QUndoCommand *parent = 0);
87 void redo();
88 void undo();
89private:
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
98class LiftCommand : public QUndoCommand
99{
100public:
101 LiftCommand(MultitrackModel &model, int trackIndex, int clipIndex, QUndoCommand *parent = 0);
102 void redo();
103 void undo();
104private:
105 MultitrackModel &m_model;
106 int m_trackIndex;
107 int m_clipIndex;
108 UndoHelper m_undoHelper;
109};
110
111class RemoveCommand : public QUndoCommand
112{
113public:
114 RemoveCommand(MultitrackModel &model, MarkersModel &markersModel, int trackIndex, int clipIndex,
115 QUndoCommand *parent = 0);
116 void redo();
117 void undo();
118private:
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
131class NameTrackCommand : public QUndoCommand
132{
133public:
134 NameTrackCommand(MultitrackModel &model, int trackIndex, const QString &name,
135 QUndoCommand *parent = 0);
136 void redo();
137 void undo();
138private:
139 MultitrackModel &m_model;
140 int m_trackIndex;
141 QString m_name;
142 QString m_oldName;
143};
144
145class MergeCommand : public QUndoCommand
146{
147public:
148 MergeCommand(MultitrackModel &model, int trackIndex, int clipIndex, QUndoCommand *parent = 0);
149 void redo();
150 void undo();
151private:
152 MultitrackModel &m_model;
153 int m_trackIndex;
154 int m_clipIndex;
155 UndoHelper m_undoHelper;
156};
157
158class MuteTrackCommand : public QUndoCommand
159{
160public:
161 MuteTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
162 void redo();
163 void undo();
164private:
165 MultitrackModel &m_model;
166 int m_trackIndex;
167 bool m_oldValue;
168};
169
170class HideTrackCommand : public QUndoCommand
171{
172public:
173 HideTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
174 void redo();
175 void undo();
176private:
177 MultitrackModel &m_model;
178 int m_trackIndex;
179 bool m_oldValue;
180};
181
182class CompositeTrackCommand : public QUndoCommand
183{
184public:
185 CompositeTrackCommand(MultitrackModel &model, int trackIndex, bool value, QUndoCommand *parent = 0);
186 void redo();
187 void undo();
188private:
189 MultitrackModel &m_model;
190 int m_trackIndex;
191 bool m_value;
192 bool m_oldValue;
193};
194
195class LockTrackCommand : public QUndoCommand
196{
197public:
198 LockTrackCommand(MultitrackModel &model, int trackIndex, bool value, QUndoCommand *parent = 0);
199 void redo();
200 void undo();
201private:
202 MultitrackModel &m_model;
203 int m_trackIndex;
204 bool m_value;
205 bool m_oldValue;
206};
207
208class MoveClipCommand : public QUndoCommand
209{
210public:
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 }
219protected:
220 int id() const
221 {
222 return UndoIdMoveClip;
223 }
224 bool mergeWith(const QUndoCommand *other);
225private:
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
244class TrimCommand : public QUndoCommand
245{
246public:
247 explicit TrimCommand(QUndoCommand *parent = 0) : QUndoCommand(parent) {}
248 void setUndoHelper(UndoHelper *helper)
249 {
250 m_undoHelper.reset(helper);
251 }
252
253protected:
254 QScopedPointer<UndoHelper> m_undoHelper;
255};
256
257class TrimClipInCommand : public TrimCommand
258{
259public:
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();
264protected:
265 int id() const
266 {
267 return UndoIdTrimClipIn;
268 }
269 bool mergeWith(const QUndoCommand *other);
270private:
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
285class TrimClipOutCommand : public TrimCommand
286{
287public:
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();
292protected:
293 int id() const
294 {
295 return UndoIdTrimClipOut;
296 }
297 bool mergeWith(const QUndoCommand *other);
298private:
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
313class SplitCommand : public QUndoCommand
314{
315public:
316 SplitCommand(MultitrackModel &model, int trackIndex, int clipIndex, int position,
317 QUndoCommand *parent = 0);
318 void redo();
319 void undo();
320private:
321 MultitrackModel &m_model;
322 int m_trackIndex;
323 int m_clipIndex;
324 int m_position;
325 UndoHelper m_undoHelper;
326};
327
328class FadeInCommand : public QUndoCommand
329{
330public:
331 FadeInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int duration,
332 QUndoCommand *parent = 0);
333 void redo();
334 void undo();
335protected:
336 int id() const
337 {
338 return UndoIdFadeIn;
339 }
340 bool mergeWith(const QUndoCommand *other);
341private:
342 MultitrackModel &m_model;
343 int m_trackIndex;
344 int m_clipIndex;
345 int m_duration;
346 int m_previous;
347};
348
349class FadeOutCommand : public QUndoCommand
350{
351public:
352 FadeOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int duration,
353 QUndoCommand *parent = 0);
354 void redo();
355 void undo();
356protected:
357 int id() const
358 {
359 return UndoIdFadeOut;
360 }
361 bool mergeWith(const QUndoCommand *other);
362private:
363 MultitrackModel &m_model;
364 int m_trackIndex;
365 int m_clipIndex;
366 int m_duration;
367 int m_previous;
368};
369
370class AddTransitionCommand : public QUndoCommand
371{
372public:
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 }
381private:
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
398class TrimTransitionInCommand : public TrimCommand
399{
400public:
401 TrimTransitionInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
402 bool redo = true, QUndoCommand *parent = 0);
403 void redo();
404 void undo();
405protected:
406 int id() const
407 {
408 return UndoIdTrimTransitionIn;
409 }
410 bool mergeWith(const QUndoCommand *other);
411private:
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
420class TrimTransitionOutCommand : public TrimCommand
421{
422public:
423 TrimTransitionOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
424 bool redo = true, QUndoCommand *parent = 0);
425 void redo();
426 void undo();
427protected:
428 int id() const
429 {
430 return UndoIdTrimTransitionOut;
431 }
432 bool mergeWith(const QUndoCommand *other);
433private:
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
442class AddTransitionByTrimInCommand : public TrimCommand
443{
444public:
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();
449protected:
450 int id() const
451 {
452 return UndoIdAddTransitionByTrimIn;
453 }
454 bool mergeWith(const QUndoCommand *other);
455private:
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
465class RemoveTransitionByTrimInCommand : public TrimCommand
466{
467public:
468 RemoveTransitionByTrimInCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
469 bool redo = true, QUndoCommand *parent = 0);
470 void redo();
471 void undo();
472private:
473 MultitrackModel &m_model;
474 int m_trackIndex;
475 int m_clipIndex;
476 int m_delta;
477 bool m_redo;
478};
479
480class RemoveTransitionByTrimOutCommand : public TrimCommand
481{
482public:
483 RemoveTransitionByTrimOutCommand(MultitrackModel &model, int trackIndex, int clipIndex, int delta,
484 bool redo = true, QUndoCommand *parent = 0);
485 void redo();
486 void undo();
487private:
488 MultitrackModel &m_model;
489 int m_trackIndex;
490 int m_clipIndex;
491 int m_delta;
492 bool m_redo;
493};
494
495class AddTransitionByTrimOutCommand : public TrimCommand
496{
497public:
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();
502protected:
503 int id() const
504 {
505 return UndoIdAddTransitionByTrimOut;
506 }
507 bool mergeWith(const QUndoCommand *other);
508private:
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
518class AddTrackCommand: public QUndoCommand
519{
520public:
521 AddTrackCommand(MultitrackModel &model, bool isVideo, QUndoCommand *parent = 0);
522 void redo();
523 void undo();
524private:
525 MultitrackModel &m_model;
526 int m_trackIndex;
527 bool m_isVideo;
528};
529
530class InsertTrackCommand : public QUndoCommand
531{
532public:
533 InsertTrackCommand(MultitrackModel &model, int trackIndex, TrackType trackType = PlaylistTrackType,
534 QUndoCommand *parent = 0);
535 void redo();
536 void undo();
537private:
538 MultitrackModel &m_model;
539 int m_trackIndex;
540 TrackType m_trackType;
541};
542
543class RemoveTrackCommand : public QUndoCommand
544{
545public:
546 RemoveTrackCommand(MultitrackModel &model, int trackIndex, QUndoCommand *parent = 0);
547 void redo();
548 void undo();
549private:
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
558class MoveTrackCommand : public QUndoCommand
559{
560public:
561 MoveTrackCommand(MultitrackModel &model, int fromTrackIndex, int toTrackIndex,
562 QUndoCommand *parent = 0);
563 void redo();
564 void undo();
565private:
566 MultitrackModel &m_model;
567 int m_fromTrackIndex;
568 int m_toTrackIndex;
569};
570
571class ChangeBlendModeCommand : public QObject, public QUndoCommand
572{
573 Q_OBJECT
574public:
575 ChangeBlendModeCommand(Mlt::Transition &transition, const QString &propertyName,
576 const QString &mode, QUndoCommand *parent = 0);
577 void redo();
578 void undo();
579signals:
580 void modeChanged(QString &mode);
581private:
582 Mlt::Transition m_transition;
583 QString m_propertyName;
584 QString m_newMode;
585 QString m_oldMode;
586};
587
588class UpdateCommand : public QUndoCommand
589{
590public:
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();
609private:
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
620class DetachAudioCommand: public QUndoCommand
621{
622public:
623 DetachAudioCommand(MultitrackModel &model, int trackIndex, int clipIndex, int position,
624 const QString &xml, QUndoCommand *parent = 0);
625 void redo();
626 void undo();
627private:
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
638class ReplaceCommand : public QUndoCommand
639{
640public:
641 ReplaceCommand(MultitrackModel &model, int trackIndex, int clipIndex, const QString &xml,
642 QUndoCommand *parent = nullptr);
643 void redo();
644 void undo();
645private:
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
655class AlignClipsCommand : public QUndoCommand
656{
657public:
658 AlignClipsCommand(MultitrackModel &model, QUndoCommand *parent = 0);
659 void addAlignment(QUuid uuid, int offset, double speedCompensation);
660 void redo();
661 void undo();
662
663private:
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