forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountproducerwidget.cpp
More file actions
223 lines (189 loc) · 7.13 KB
/
countproducerwidget.cpp
File metadata and controls
223 lines (189 loc) · 7.13 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* Copyright (c) 2016-2018 Meltytech, LLC
*
* 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 "shotcut_mlt_properties.h"
#include "countproducerwidget.h"
#include "ui_countproducerwidget.h"
#include "util.h"
#include "mltcontroller.h"
#include <MltProfile.h>
void setLength(Mlt::Properties* p, int length)
{
p->set("length", length);
p->set("out", length - 1);
p->set("in", 0);
}
CountProducerWidget::CountProducerWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CountProducerWidget)
{
ui->setupUi(this);
Util::setColorsToHighlight(ui->nameLabel);
ui->directionCombo->addItem(tr("Down"), QVariant("down"));
ui->directionCombo->addItem(tr("Up"), QVariant("up"));
ui->directionCombo->setCurrentIndex(0);
ui->styleCombo->addItem(tr("Seconds"), QVariant("seconds"));
ui->styleCombo->addItem(tr("Seconds + 1"), QVariant("seconds+1"));
ui->styleCombo->addItem(tr("Frames"), QVariant("frames"));
ui->styleCombo->addItem(tr("Timecode"), QVariant("timecode"));
ui->styleCombo->addItem(tr("Clock"), QVariant("clock"));
ui->styleCombo->setCurrentIndex(0);
ui->soundCombo->addItem(tr("2-Pop"), QVariant("2pop"));
ui->soundCombo->addItem(tr("Silent"), QVariant("silent"));
ui->soundCombo->addItem(tr("Frame 0"), QVariant("frame0"));
ui->soundCombo->setCurrentIndex(0);
ui->backgroundCombo->addItem(tr("Clock"), QVariant("clock"));
ui->backgroundCombo->addItem(tr("None"), QVariant("none"));
ui->backgroundCombo->setCurrentIndex(0);
ui->dropCheckBox->setChecked(true);
ui->durationSpinBox->setValue(qRound(MLT.profile().fps() * 10.0)); // 10 seconds
ui->preset->saveDefaultPreset(getPreset());
ui->preset->loadPresets();
}
CountProducerWidget::~CountProducerWidget()
{
delete ui;
}
QString CountProducerWidget::currentDirection() const
{
return ui->directionCombo->itemData(ui->directionCombo->currentIndex()).toString();
}
QString CountProducerWidget::currentStyle() const
{
return ui->styleCombo->itemData(ui->styleCombo->currentIndex()).toString();
}
QString CountProducerWidget::currentSound() const
{
return ui->soundCombo->itemData(ui->soundCombo->currentIndex()).toString();
}
QString CountProducerWidget::currentBackground() const
{
return ui->backgroundCombo->itemData(ui->backgroundCombo->currentIndex()).toString();
}
Mlt::Producer* CountProducerWidget::newProducer(Mlt::Profile& profile)
{
Mlt::Producer* p = new Mlt::Producer(profile, "count:");
p->set("direction", currentDirection().toLatin1().constData());
p->set("style", currentStyle().toLatin1().constData());
p->set("sound", currentSound().toLatin1().constData());
p->set("background", currentBackground().toLatin1().constData());
p->set("drop", ui->dropCheckBox->isChecked());
setLength(p, ui->durationSpinBox->value());
p->set(kShotcutCaptionProperty, ui->nameLabel->text().toUtf8().constData());
p->set(kShotcutDetailProperty, detail().toUtf8().constData());
return p;
}
Mlt::Properties CountProducerWidget::getPreset() const
{
Mlt::Properties p;
p.set("direction", currentDirection().toLatin1().constData());
p.set("style", currentStyle().toLatin1().constData());
p.set("sound", currentSound().toLatin1().constData());
p.set("background", currentBackground().toLatin1().constData());
p.set("drop", ui->dropCheckBox->isChecked());
setLength(&p, ui->durationSpinBox->value());
return p;
}
void CountProducerWidget::loadPreset(Mlt::Properties& p)
{
if (!p.get("direction") || !p.get("style")) return;
int index = -1;
index = ui->directionCombo->findData(QVariant(p.get("direction")));
ui->directionCombo->setCurrentIndex(index);
index = ui->styleCombo->findData(QVariant(p.get("style")));
ui->styleCombo->setCurrentIndex(index);
index = ui->soundCombo->findData(QVariant(p.get("sound")));
ui->soundCombo->setCurrentIndex(index);
index = ui->backgroundCombo->findData(QVariant(p.get("background")));
ui->backgroundCombo->setCurrentIndex(index);
ui->dropCheckBox->setChecked(p.get("drop"));
ui->durationSpinBox->setValue(p.get_int("length"));
if (m_producer) {
m_producer->set("direction", p.get("direction"));
m_producer->set("style", p.get("style"));
m_producer->set("sound", p.get("sound"));
m_producer->set("background", p.get("background"));
m_producer->set("drop", p.get("drop"));
setLength(producer(), ui->durationSpinBox->value());
m_producer->set(kShotcutDetailProperty, detail().toUtf8().constData());
emit producerChanged(producer());
}
}
void CountProducerWidget::on_directionCombo_activated(int /*index*/)
{
if (m_producer) {
m_producer->set("direction", currentDirection().toLatin1().constData());
m_producer->set(kShotcutDetailProperty, detail().toUtf8().constData());
emit producerChanged(producer());
}
}
void CountProducerWidget::on_styleCombo_activated(int /*index*/)
{
if (m_producer) {
m_producer->set("style", currentStyle().toLatin1().constData());
m_producer->set(kShotcutDetailProperty, detail().toUtf8().constData());
emit producerChanged(producer());
}
}
void CountProducerWidget::on_soundCombo_activated(int /*index*/)
{
if (m_producer) {
m_producer->set("sound", currentSound().toLatin1().constData());
emit producerChanged(producer());
}
}
void CountProducerWidget::on_backgroundCombo_activated(int /*index*/)
{
if (m_producer) {
m_producer->set("background", currentBackground().toLatin1().constData());
emit producerChanged(producer());
}
}
void CountProducerWidget::on_dropCheckBox_clicked(bool checked)
{
if (m_producer) {
m_producer->set("drop", checked);
emit producerChanged(producer());
}
}
void CountProducerWidget::on_durationSpinBox_editingFinished()
{
if (!m_producer)
return;
if (ui->durationSpinBox->value() == m_producer->get_length())
return;
if (m_producer) {
setLength(producer(), ui->durationSpinBox->value());
MLT.stop();
emit producerReopened();
emit producerChanged(producer());
MLT.seek(0);
}
}
void CountProducerWidget::on_preset_selected(void* p)
{
Mlt::Properties* properties = (Mlt::Properties*) p;
loadPreset(*properties);
delete properties;
}
void CountProducerWidget::on_preset_saveClicked()
{
ui->preset->savePreset(getPreset());
}
QString CountProducerWidget::detail() const
{
return QString(tr("Count: %1 %2")).arg(ui->directionCombo->currentText()).arg(ui->styleCombo->currentText());
}