forked from olive-editor/olive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.cpp
193 lines (158 loc) · 4.91 KB
/
sequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "sequence.h"
#include <QCoreApplication>
#include "debug.h"
Sequence::Sequence() {
playhead = 0;
using_workarea = false;
workarea_in = 0;
workarea_out = 0;
wrapper_sequence = false;
}
Sequence::~Sequence() {}
SequencePtr Sequence::copy() {
SequencePtr s(new Sequence());
s->name = QCoreApplication::translate("Sequence", "%1 (copy)").arg(name);
s->width = width;
s->height = height;
s->frame_rate = frame_rate;
s->audio_frequency = audio_frequency;
s->audio_layout = audio_layout;
// deep copy all of the sequence's clips
s->clips.resize(clips.size());
for (int i=0;i<clips.size();i++) {
ClipPtr c = clips.at(i);
if (c == nullptr) {
s->clips[i] = nullptr;
} else {
ClipPtr copy = c->copy(s);
copy->linked = c->linked;
s->clips[i] = copy;
}
}
// copy all of the sequence's markers
s->markers = markers;
return s;
}
long Sequence::getEndFrame() {
long end = 0;
for (int j=0;j<clips.size();j++) {
ClipPtr c = clips.at(j);
if (c != nullptr && c->timeline_out() > end) {
end = c->timeline_out();
}
}
return end;
}
void Sequence::RefreshClips(Media *m) {
for (int i=0;i<clips.size();i++) {
ClipPtr c = clips.at(i);
if (c != nullptr
&& (m == nullptr || c->media() == m)) {
c->Close(true);
c->refresh();
}
}
}
QVector<Clip *> Sequence::SelectedClips()
{
QVector<Clip*> selected_clips;
for (int i=0;i<clips.size();i++) {
Clip* c = clips.at(i).get();
if (c != nullptr && IsClipSelected(c, true)) {
selected_clips.append(c);
}
}
return selected_clips;
}
QVector<int> Sequence::SelectedClipIndexes()
{
QVector<int> selected_clips;
for (int i=0;i<clips.size();i++) {
Clip* c = clips.at(i).get();
if (c != nullptr && IsClipSelected(c, true)) {
selected_clips.append(i);
}
}
return selected_clips;
}
Effect *Sequence::GetSelectedGizmo()
{
Effect* gizmo_ptr = nullptr;
for (int i=0;i<clips.size();i++) {
Clip* c = clips.at(i).get();
if (c != nullptr
&& c->IsActiveAt(playhead)
&& IsClipSelected(c, true)) {
// This clip is selected and currently active - we'll use this for gizmos
if (!c->effects.isEmpty()) {
// find which effect has gizmos selected, or default to the first gizmo effect we find if there is
// none selected
for (int j=0;j<c->effects.size();j++) {
Effect* e = c->effects.at(j).get();
// retrieve gizmo data from effect
if (e->are_gizmos_enabled()) {
if (gizmo_ptr == nullptr) {
gizmo_ptr = e;
}
if (e->container->selected) {
gizmo_ptr = e;
break;
}
}
}
}
if (gizmo_ptr != nullptr) {
break;
}
}
}
return gizmo_ptr;
}
bool Sequence::IsClipSelected(int clip_index, bool containing)
{
return IsClipSelected(clips.at(clip_index).get(), containing);
}
bool Sequence::IsClipSelected(Clip *clip, bool containing)
{
for (int i=0;i<selections.size();i++) {
const Selection& s = selections.at(i);
if (clip->track() == s.track && ((clip->timeline_in() >= s.in && clip->timeline_out() <= s.out && containing)
|| (!containing && !(clip->timeline_in() < s.in && clip->timeline_out() < s.in)
&& !(clip->timeline_in() > s.in && clip->timeline_out() > s.in)))) {
return true;
}
}
return false;
}
void Sequence::getTrackLimits(int* video_tracks, int* audio_tracks) {
int vt = 0;
int at = 0;
for (int j=0;j<clips.size();j++) {
ClipPtr c = clips.at(j);
if (c != nullptr) {
if (c->track() < 0 && c->track() < vt) { // video clip
vt = c->track();
} else if (c->track() > at) {
at = c->track();
}
}
}
if (video_tracks != nullptr) *video_tracks = vt;
if (audio_tracks != nullptr) *audio_tracks = at;
}
// static variable for the currently active sequence
SequencePtr olive::ActiveSequence = nullptr;