forked from olive-editor/olive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transition.cpp
138 lines (114 loc) · 4.65 KB
/
transition.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
/***
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 "transition.h"
#include "mainwindow.h"
#include "clip.h"
#include "sequence.h"
#include "debug.h"
#include "io/clipboard.h"
#include "effects/internal/crossdissolvetransition.h"
#include "effects/internal/linearfadetransition.h"
#include "effects/internal/exponentialfadetransition.h"
#include "effects/internal/logarithmicfadetransition.h"
#include "effects/internal/cubetransition.h"
#include "ui/labelslider.h"
#include "panels/panels.h"
#include "panels/timeline.h"
#include <QMessageBox>
#include <QCoreApplication>
Transition::Transition(Clip *c, Clip *s, const EffectMeta* em) :
Effect(c, em), secondary_clip(s),
length(30)
{
length_field = add_row(tr("Length"), false)->add_field(EFFECT_FIELD_DOUBLE, "length");
connect(length_field, SIGNAL(changed()), this, SLOT(set_length_from_slider()));
length_field->set_double_default_value(30);
length_field->set_double_minimum_value(0);
LabelSlider* length_ui_ele = static_cast<LabelSlider*>(length_field->ui_element);
length_ui_ele->set_display_type(LABELSLIDER_FRAMENUMBER);
length_ui_ele->set_frame_rate(parent_clip->sequence == nullptr ? parent_clip->cached_frame_rate() : parent_clip->sequence->frame_rate);
}
TransitionPtr Transition::copy(Clip *c, Clip *s) {
return Transition::Create(c, s, meta, length);
}
void Transition::save(QXmlStreamWriter &stream) {
stream.writeAttribute("length", QString::number(get_true_length()));
Effect::save(stream);
}
void Transition::set_length(long l) {
length = l;
length_field->set_double_value(l);
}
long Transition::get_true_length() {
return length;
}
long Transition::get_length() {
if (secondary_clip != nullptr) {
return length * 2;
}
return length;
}
Clip* Transition::get_opened_clip() {
if (parent_clip->opening_transition.get() == this) {
return parent_clip;
} else if (secondary_clip != nullptr && secondary_clip->opening_transition.get() == this) {
return secondary_clip;
}
return nullptr;
}
Clip* Transition::get_closed_clip() {
if (parent_clip->closing_transition.get() == this) {
return parent_clip;
} else if (secondary_clip != nullptr && secondary_clip->closing_transition.get() == this) {
return secondary_clip;
}
return nullptr;
}
void Transition::set_length_from_slider() {
set_length(length_field->get_double_value(0));
update_ui(false);
}
TransitionPtr Transition::CreateFromMeta(Clip* c, Clip* s, const EffectMeta* em) {
if (!em->filename.isEmpty()) {
// load effect from file
return TransitionPtr(new Transition(c, s, em));
} else if (em->internal >= 0 && em->internal < TRANSITION_INTERNAL_COUNT) {
// must be an internal effect
switch (em->internal) {
case TRANSITION_INTERNAL_CROSSDISSOLVE: return TransitionPtr(new CrossDissolveTransition(c, s, em));
case TRANSITION_INTERNAL_LINEARFADE: return TransitionPtr(new LinearFadeTransition(c, s, em));
case TRANSITION_INTERNAL_EXPONENTIALFADE: return TransitionPtr(new ExponentialFadeTransition(c, s, em));
case TRANSITION_INTERNAL_LOGARITHMICFADE: return TransitionPtr(new LogarithmicFadeTransition(c, s, em));
case TRANSITION_INTERNAL_CUBE: return TransitionPtr(new CubeTransition(c, s, em));
}
} else {
qCritical() << "Invalid transition data";
QMessageBox::critical(olive::MainWindow,
QCoreApplication::translate("transition", "Invalid transition"),
QCoreApplication::translate("transition", "No candidate for transition '%1'. This transition may be corrupt. Try reinstalling it or Olive.").arg(em->name)
);
}
return nullptr;
}
TransitionPtr Transition::Create(Clip* c, Clip* s, const EffectMeta* em, long length) {
TransitionPtr t(CreateFromMeta(c, s, em));
if (t != nullptr) {
if (length > 0) {
t->set_length(length);
}
return t;
}
return nullptr;
}