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