1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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 2 of the License, or *
7 * (at your option) any later version. *
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. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
29 #include "profilesdialog.h"
31 #include "rotoscoping/rotowidget.h"
39 #include <QStyleOptionGraphicsItem>
40 #include <QGraphicsScene>
43 static int FRAME_SIZE;
45 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) :
46 AbstractClipItem(info, QRectF(), fps),
52 m_startPix(QPixmap()),
57 m_startThumbRequested(false),
58 m_endThumbRequested(false),
63 m_limitedKeyFrames(false)
66 m_effectList = EffectsList(true);
67 FRAME_SIZE = frame_width;
68 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double) itemHeight());
69 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1 + itemOffset());
71 // set speed independant info
72 if (m_speed <= 0 && m_speed > -1)
74 m_speedIndependantInfo = m_info;
75 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
76 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
78 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
79 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
82 m_clipName = m_clip->name();
84 m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
86 m_producer = m_clip->getId();
87 m_clipType = m_clip->clipType();
88 //m_cropStart = info.cropStart;
89 m_maxDuration = m_clip->maxDuration();
91 m_audioThumbReady = m_clip->audioThumbCreated();
92 //setAcceptsHoverEvents(true);
93 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
95 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
96 m_baseColor = QColor(141, 166, 215);
97 if (!m_clip->isPlaceHolder()) {
99 m_startThumbTimer.setSingleShot(true);
100 connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
101 m_endThumbTimer.setSingleShot(true);
102 connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
103 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
104 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
105 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
108 } else if (m_clipType == COLOR) {
109 QString colour = m_clip->getProperty("colour");
110 colour = colour.replace(0, 2, "#");
111 m_baseColor = QColor(colour.left(7));
112 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
113 m_baseColor = QColor(141, 166, 215);
114 if (m_clipType == TEXT) {
115 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
117 //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
118 } else if (m_clipType == AUDIO) {
119 m_baseColor = QColor(141, 215, 166);
120 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
125 ClipItem::~ClipItem()
128 m_endThumbTimer.stop();
129 m_startThumbTimer.stop();
130 if (scene()) scene()->removeItem(this);
131 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
132 //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
133 //disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
138 ClipItem *ClipItem::clone(ItemInfo info) const
140 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe, FRAME_SIZE);
141 if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
142 else if (m_clipType != COLOR) {
143 if (info.cropStart == m_info.cropStart) duplicate->slotSetStartThumb(m_startPix);
144 if (info.cropStart + (info.endPos - info.startPos) == m_info.cropStart + m_info.cropDuration) {
145 duplicate->slotSetEndThumb(m_endPix);
148 //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
149 duplicate->setEffectList(m_effectList);
150 duplicate->setVideoOnly(m_videoOnly);
151 duplicate->setAudioOnly(m_audioOnly);
152 duplicate->setFades(fadeIn(), fadeOut());
153 //duplicate->setSpeed(m_speed);
157 void ClipItem::setEffectList(const EffectsList effectList)
159 m_effectList.clone(effectList);
160 m_effectNames = m_effectList.effectNames().join(" / ");
161 if (!m_effectList.isEmpty()) {
162 for (int i = 0; i < m_effectList.count(); i++) {
163 QDomElement effect = m_effectList.at(i);
164 QString effectId = effect.attribute("id");
165 // check if it is a fade effect
166 QDomNodeList params = effect.elementsByTagName("parameter");
168 for (int j = 0; j < params.count(); j++) {
169 QDomElement e = params.item(j).toElement();
171 if (effectId == "fadein") {
172 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
173 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
174 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
176 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
177 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
178 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
180 } else if (effectId == "fade_from_black") {
181 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
182 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
183 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
185 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
186 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
187 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
189 } else if (effectId == "fadeout") {
190 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
191 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
192 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
194 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
195 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
196 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
198 } else if (effectId == "fade_to_black") {
199 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
200 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
201 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
203 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
204 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
205 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
215 setSelectedEffect(0);
219 const EffectsList ClipItem::effectList() const
224 int ClipItem::selectedEffectIndex() const
226 return m_selectedEffect;
229 void ClipItem::initEffect(QDomElement effect, int diff, int offset)
231 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
234 if (effect.attribute("id") == "freeze" && diff > 0) {
235 EffectsList::setParameter(effect, "frame", QString::number(diff));
238 // Init parameter value & keyframes if required
239 QDomNodeList params = effect.elementsByTagName("parameter");
240 for (int i = 0; i < params.count(); i++) {
241 QDomElement e = params.item(i).toElement();
246 // Check if this effect has a variable parameter
247 if (e.attribute("default").contains('%')) {
248 double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
249 e.setAttribute("default", evaluatedValue);
250 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
251 e.setAttribute("value", evaluatedValue);
255 if (effect.attribute("id") == "crop") {
256 // default use_profile to 1 for clips with proxies to avoid problems when rendering
257 if (e.attribute("name") == "use_profile" && !(m_clip->getProperty("proxy").isEmpty() || m_clip->getProperty("proxy") == "-"))
258 e.setAttribute("value", "1");
261 if (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") {
262 if (e.attribute("keyframes").isEmpty()) {
263 // Effect has a keyframe type parameter, we need to set the values
264 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + e.attribute("default"));
266 else if (offset != 0) {
267 // adjust keyframes to this clip
268 QString adjusted = adjustKeyframes(e.attribute("keyframes"), offset - cropStart().frames(m_fps));
269 e.setAttribute("keyframes", adjusted);
273 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
274 // Effects with a geometry parameter need to sync in / out with parent clip
275 effect.setAttribute("in", QString::number(cropStart().frames(m_fps)));
276 effect.setAttribute("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
277 effect.setAttribute("_sync_in_out", "1");
280 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
281 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
282 int end = (cropDuration() + cropStart()).frames(m_fps) - 1;
284 if (effect.attribute("id") == "fadeout") {
285 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
286 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
287 if (effectDuration > cropDuration().frames(m_fps)) {
288 effectDuration = cropDuration().frames(m_fps) / 2;
290 start -= effectDuration;
292 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
293 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
295 } else if (effect.attribute("id") == "fade_to_black") {
296 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
297 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
298 if (effectDuration > cropDuration().frames(m_fps)) {
299 effectDuration = cropDuration().frames(m_fps) / 2;
301 start -= effectDuration;
303 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
304 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
307 EffectsList::setParameter(effect, "in", QString::number(start));
308 EffectsList::setParameter(effect, "out", QString::number(end));
309 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
310 int start = cropStart().frames(m_fps);
312 if (effect.attribute("id") == "fadein") {
313 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
314 int effectDuration = EffectsList::parameter(effect, "out").toInt();
315 if (offset != 0) effectDuration -= offset;
316 if (effectDuration > cropDuration().frames(m_fps)) {
317 effectDuration = cropDuration().frames(m_fps) / 2;
319 end += effectDuration;
321 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt() - offset;
322 } else if (effect.attribute("id") == "fade_from_black") {
323 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
324 int effectDuration = EffectsList::parameter(effect, "out").toInt();
325 if (offset != 0) effectDuration -= offset;
326 if (effectDuration > cropDuration().frames(m_fps)) {
327 effectDuration = cropDuration().frames(m_fps) / 2;
329 end += effectDuration;
331 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt() - offset;
333 EffectsList::setParameter(effect, "in", QString::number(start));
334 EffectsList::setParameter(effect, "out", QString::number(end));
339 const QString ClipItem::adjustKeyframes(QString keyframes, int offset)
343 const QStringList list = keyframes.split(';', QString::SkipEmptyParts);
344 foreach(const QString &keyframe, list) {
345 int pos = keyframe.section(':', 0, 0).toInt() - offset;
346 QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1);
347 result.append(newKey);
349 return result.join(";");
352 bool ClipItem::checkKeyFrames()
354 bool clipEffectsModified = false;
356 // go through all effects this clip has
357 for (int ix = 0; ix < m_effectList.count(); ++ix) {
358 QStringList keyframeParams = keyframes(ix);
359 QStringList newKeyFrameParams;
360 bool effModified = false;
362 // go through all params which have keyframes
363 foreach(const QString &kfr, keyframeParams) {
364 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
365 QStringList newKeyFrames;
366 bool cutKeyFrame = false;
367 bool modified = false;
369 double lastValue = -1;
370 int start = cropStart().frames(m_fps);
371 int end = (cropStart() + cropDuration()).frames(m_fps);
373 // go through all keyframes for one param
374 foreach(const QString &str, keyframes) {
375 int pos = str.section(':', 0, 0).toInt();
376 double val = locale.toDouble(str.section(':', 1, 1));
377 if (pos - start < 0) {
378 // a keyframe is defined before the start of the clip
380 } else if (cutKeyFrame) {
381 // create new keyframe at clip start, calculate interpolated value
383 int diff = pos - lastPos;
384 double ratio = (double)(start - lastPos) / diff;
385 double newValue = lastValue + (val - lastValue) * ratio;
386 newKeyFrames.append(QString::number(start) + ':' + locale.toString(newValue));
393 // create new keyframe at clip end, calculate interpolated value
394 int diff = pos - lastPos;
396 double ratio = (double)(end - lastPos) / diff;
397 double newValue = lastValue + (val - lastValue) * ratio;
398 newKeyFrames.append(QString::number(end) + ':' + locale.toString(newValue));
403 newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
410 newKeyFrameParams.append(newKeyFrames.join(";"));
417 setKeyframes(ix, newKeyFrameParams);
418 clipEffectsModified = true;
421 return clipEffectsModified;
424 void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
426 QDomElement effect = m_effectList.at(ix);
427 if (effect.attribute("disable") == "1") return;
429 QDomNodeList params = effect.elementsByTagName("parameter");
430 int keyframeParams = 0;
431 for (int i = 0; i < params.count(); i++) {
432 QDomElement e = params.item(i).toElement();
433 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
434 e.setAttribute("keyframes", keyframes.at(keyframeParams));
435 if (ix == m_selectedEffect && keyframeParams == 0) {
438 double max = locale.toDouble(e.attribute("max"));
439 double min = locale.toDouble(e.attribute("min"));
440 m_keyframeFactor = 100.0 / (max - min);
441 m_keyframeOffset = min;
442 m_keyframeDefault = locale.toDouble(e.attribute("default"));
443 m_selectedKeyframe = 0;
445 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
446 foreach(const QString &str, keyframes) {
447 int pos = str.section(':', 0, 0).toInt();
448 double val = locale.toDouble(str.section(':', 1, 1));
449 m_keyframes[pos] = val;
451 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
452 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
461 void ClipItem::setSelectedEffect(const int ix)
463 m_selectedEffect = ix;
465 QDomElement effect = effectAtIndex(m_selectedEffect);
466 if (!effect.isNull() && effect.attribute("disable") != "1") {
467 QDomNodeList params = effect.elementsByTagName("parameter");
468 for (int i = 0; i < params.count(); i++) {
469 QDomElement e = params.item(i).toElement();
470 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
472 m_limitedKeyFrames = e.attribute("type") == "keyframe";
474 double max = locale.toDouble(e.attribute("max"));
475 double min = locale.toDouble(e.attribute("min"));
476 m_keyframeFactor = 100.0 / (max - min);
477 m_keyframeOffset = min;
478 m_keyframeDefault = locale.toDouble(e.attribute("default"));
479 m_selectedKeyframe = 0;
482 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
483 foreach(const QString &str, keyframes) {
484 int pos = str.section(':', 0, 0).toInt();
485 double val = locale.toDouble(str.section(':', 1, 1));
486 m_keyframes[pos] = val;
488 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end())
489 m_editedKeyframe = -1;
496 if (!m_keyframes.isEmpty()) {
502 QStringList ClipItem::keyframes(const int index)
505 QDomElement effect = m_effectList.at(index);
506 QDomNodeList params = effect.elementsByTagName("parameter");
508 for (int i = 0; i < params.count(); i++) {
509 QDomElement e = params.item(i).toElement();
510 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe"))
511 result.append(e.attribute("keyframes"));
516 void ClipItem::updateKeyframeEffect()
518 // regenerate xml parameter from the clip keyframes
519 QDomElement effect = getEffectAtIndex(m_selectedEffect);
520 if (effect.attribute("disable") == "1") return;
521 QDomNodeList params = effect.elementsByTagName("parameter");
522 QDomElement e = params.item(m_visibleParam).toElement();
526 if (m_keyframes.count() > 0) {
527 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
528 while (i != m_keyframes.constEnd()) {
529 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
533 // Effect has a keyframe type parameter, we need to set the values
534 e.setAttribute("keyframes", keyframes);
538 QDomElement ClipItem::selectedEffect()
540 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
541 return effectAtIndex(m_selectedEffect);
544 void ClipItem::resetThumbs(bool clearExistingThumbs)
546 if (clearExistingThumbs) {
547 m_startPix = QPixmap();
548 m_endPix = QPixmap();
549 m_audioThumbCachePic.clear();
555 void ClipItem::refreshClip(bool checkDuration, bool forceResetThumbs)
557 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
558 m_maxDuration = m_clip->maxDuration();
559 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
560 if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
561 // Clip duration changed, make sure to stay in correct range
562 if (m_info.cropStart > m_maxDuration) {
563 m_info.cropStart = GenTime();
564 m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
566 m_info.cropDuration = m_maxDuration;
568 updateRectGeometry();
572 if (m_clipType == COLOR) {
573 QString colour = m_clip->getProperty("colour");
574 colour = colour.replace(0, 2, "#");
575 m_baseColor = QColor(colour.left(7));
577 } else resetThumbs(forceResetThumbs);
580 void ClipItem::slotFetchThumbs()
582 if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
583 if (m_clipType == IMAGE) {
584 if (m_startPix.isNull()) {
585 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
591 if (m_clipType == TEXT) {
592 if (m_startPix.isNull()) slotGetStartThumb();
597 if (m_startPix.isNull()) {
598 m_startThumbRequested = true;
599 frames.append((int)m_speedIndependantInfo.cropStart.frames(m_fps));
602 if (m_endPix.isNull()) {
603 m_endThumbRequested = true;
604 frames.append((int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
607 if (!frames.isEmpty()) m_clip->slotExtractImage(frames);
610 void ClipItem::stopThumbs()
612 // Clip is about to be deleted, make sure we don't request thumbnails
613 disconnect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
614 disconnect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
617 void ClipItem::slotGetStartThumb()
619 m_startThumbRequested = true;
620 m_clip->slotExtractImage(QList<int>() << (int)m_speedIndependantInfo.cropStart.frames(m_fps));
623 void ClipItem::slotGetEndThumb()
625 m_endThumbRequested = true;
626 m_clip->slotExtractImage(QList<int>() << (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
630 void ClipItem::slotSetStartThumb(QImage img)
632 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
633 QPixmap pix = QPixmap::fromImage(img);
635 QRectF r = sceneBoundingRect();
636 r.setRight(pix.width() + 2);
641 void ClipItem::slotSetEndThumb(QImage img)
643 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
644 QPixmap pix = QPixmap::fromImage(img);
646 QRectF r = sceneBoundingRect();
647 r.setLeft(r.right() - pix.width() - 2);
652 void ClipItem::slotThumbReady(int frame, QImage img)
654 if (scene() == NULL) return;
655 QRectF r = boundingRect();
656 QPixmap pix = QPixmap::fromImage(img);
657 double width = pix.width() / projectScene()->scale().x();
658 if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
660 m_startThumbRequested = false;
661 update(r.left(), r.top(), width, pix.height());
662 if (m_clipType == IMAGE || m_clipType == TEXT) {
663 update(r.right() - width, r.top(), width, pix.height());
665 } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
667 m_endThumbRequested = false;
668 update(r.right() - width, r.top(), width, pix.height());
672 void ClipItem::slotSetStartThumb(const QPixmap pix)
677 void ClipItem::slotSetEndThumb(const QPixmap pix)
682 QPixmap ClipItem::startThumb() const
687 QPixmap ClipItem::endThumb() const
692 void ClipItem::slotGotAudioData()
694 m_audioThumbReady = true;
695 if (m_clipType == AV && !isAudioOnly()) {
696 QRectF r = boundingRect();
697 r.setTop(r.top() + r.height() / 2 - 1);
702 int ClipItem::type() const
707 DocClipBase *ClipItem::baseClip() const
712 QDomElement ClipItem::xml() const
717 QDomElement ClipItem::itemXml() const
719 QDomElement xml = m_clip->toXML();
720 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
721 if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
722 if (m_audioOnly) xml.setAttribute("audio_only", 1);
723 else if (m_videoOnly) xml.setAttribute("video_only", 1);
727 int ClipItem::clipType() const
732 QString ClipItem::clipName() const
737 void ClipItem::setClipName(const QString &name)
742 const QString ClipItem::clipProducer() const
747 void ClipItem::flashClip()
749 if (m_timeLine == 0) {
750 m_timeLine = new QTimeLine(750, this);
751 m_timeLine->setUpdateInterval(80);
752 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
753 m_timeLine->setFrameRange(0, 100);
754 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
756 //m_timeLine->start();
759 void ClipItem::animate(qreal /*value*/)
761 QRectF r = boundingRect();
767 void ClipItem::paint(QPainter *painter,
768 const QStyleOptionGraphicsItem *option,
771 QPalette palette = scene()->palette();
776 if (parentItem()) paintColor = QColor(255, 248, 149);
777 else paintColor = m_baseColor;
778 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
779 textColor = palette.highlightedText().color();
780 textBgColor = palette.highlight().color();
781 paintColor = paintColor.darker();
782 framePen.setColor(textBgColor);
785 textColor = palette.text().color();
786 textBgColor = palette.window().color();
787 textBgColor.setAlpha(200);
788 framePen.setColor(paintColor.darker());
790 const QRectF exposed = option->exposedRect;
791 const QRectF mappedExposed = painter->worldTransform().mapRect(exposed);
792 const QRectF mapped = painter->worldTransform().mapRect(rect());
793 painter->setWorldMatrixEnabled(false);
795 p.addRect(mappedExposed);
797 q.addRoundedRect(mapped, 3, 3);
798 painter->setClipPath(p.intersected(q));
799 painter->setPen(Qt::NoPen);
800 painter->fillRect(mappedExposed, paintColor);
801 painter->setPen(paintColor.darker());
803 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
804 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
805 const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
806 painter->drawPixmap(top, m_startPix);
807 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
808 painter->drawLine(l2);
809 } else if (!m_endPix.isNull()) {
810 const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
811 painter->drawPixmap(top, m_endPix);
812 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
813 painter->drawLine(l2);
815 if (!m_startPix.isNull()) {
816 painter->drawPixmap(mapped.topLeft(), m_startPix);
817 QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
818 painter->drawLine(l2);
821 // if we are in full zoom, paint thumbnail for every frame
822 if (m_clip->thumbProducer() && clipType() != COLOR && clipType() != AUDIO && !m_audioOnly && painter->worldTransform().m11() == FRAME_SIZE) {
823 int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
824 int left = qMax((int) m_info.cropStart.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x() - offset);
825 int right = qMin((int)(m_info.cropStart + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x() - offset);
826 QPointF startPos = mapped.topLeft();
827 int startOffset = m_info.cropStart.frames(m_fps);
828 if (clipType() == IMAGE || clipType() == TEXT) {
829 for (int i = left; i <= right; i++) {
830 painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
834 #if KDE_IS_VERSION(4,5,0)
835 if (m_clip && m_clip->thumbProducer()) {
836 QString path = m_clip->fileURL().path() + '_';
839 pen.setStyle(Qt::DotLine);
841 for (int i = left; i <= right; i++) {
842 img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
843 QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
844 if (img.isNull()) missing << i;
845 else painter->drawImage(xpos, img);
846 painter->drawLine(xpos, xpos + QPointF(0, mapped.height()));
848 if (!missing.isEmpty()) {
849 m_clip->thumbProducer()->queryIntraThumbs(missing);
850 connect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
858 // draw audio thumbnails
859 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
861 double startpixel = exposed.left();
864 double endpixel = exposed.right();
867 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
869 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
871 if (m_clipType == AV && !isAudioOnly()) {
873 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
874 } else mappedRect = mapped;
876 double scale = painter->worldTransform().m11();
878 if (isEnabled() && m_clip) channels = m_clip->getProperty("channels").toInt();
879 if (scale != m_framePixelWidth)
880 m_audioThumbCachePic.clear();
881 double cropLeft = m_info.cropStart.frames(m_fps);
882 const int clipStart = mappedRect.x();
883 const int mappedStartPixel = painter->worldTransform().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
884 const int mappedEndPixel = painter->worldTransform().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
885 cropLeft = cropLeft * scale;
888 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
891 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
892 if (!m_audioThumbCachePic.value(startCache).isNull())
893 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic.value(startCache));
897 if (m_isMainSelectedClip) {
898 framePen.setColor(Qt::red);
899 textBgColor = Qt::red;
902 // only paint details if clip is big enough
903 if (mapped.width() > 20) {
905 // Draw effects names
906 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
907 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
908 QColor bColor = palette.window().color();
909 QColor tColor = palette.text().color();
910 tColor.setAlpha(220);
911 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
912 qreal value = m_timeLine->currentValue();
913 txtBounding.setWidth(txtBounding.width() * value);
914 bColor.setAlpha(100 + 50 * value);
917 painter->setBrush(bColor);
918 painter->setPen(Qt::NoPen);
919 painter->drawRoundedRect(txtBounding.adjusted(-1, -2, 4, -1), 3, 3);
920 painter->setPen(tColor);
921 painter->drawText(txtBounding.adjusted(2, 0, 1, -1), Qt::AlignCenter, m_effectNames);
925 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignRight | Qt::AlignTop, m_clipName + ' ').adjusted(0, -1, 0, -1);
926 painter->setPen(Qt::NoPen);
927 painter->fillRect(txtBounding2.adjusted(-3, 0, 0, 0), textBgColor);
928 painter->setBrush(QBrush(Qt::NoBrush));
929 painter->setPen(textColor);
931 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
932 } else if (m_audioOnly) {
933 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
935 painter->drawText(txtBounding2, Qt::AlignLeft, m_clipName);
939 if (isEnabled() && m_clip) {
940 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
941 QList < CommentedTime >::Iterator it = markers.begin();
944 QBrush markerBrush(QColor(120, 120, 0, 140));
945 QPen pen = painter->pen();
947 for (; it != markers.end(); ++it) {
948 pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
949 if (pos > GenTime()) {
950 if (pos > cropDuration()) break;
951 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
952 QLineF l2 = painter->worldTransform().map(l);
953 pen.setColor(CommentedTime::markerColor((*it).markerType()));
954 pen.setStyle(Qt::DotLine);
955 painter->setPen(pen);
956 painter->drawLine(l2);
957 if (KdenliveSettings::showmarkers()) {
958 framepos = rect().x() + pos.frames(m_fps);
959 const QRectF r1(framepos + 0.04, rect().height()/3, rect().width() - framepos - 2, rect().height() / 2);
960 const QRectF r2 = painter->worldTransform().mapRect(r1);
961 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
962 painter->setBrush(markerBrush);
963 pen.setStyle(Qt::SolidLine);
964 painter->setPen(pen);
965 painter->drawRect(txtBounding3);
966 painter->setBrush(Qt::NoBrush);
967 painter->setPen(Qt::white);
968 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
970 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
975 // draw start / end fades
978 fades = QBrush(QColor(200, 50, 50, 150));
979 } else fades = QBrush(QColor(200, 200, 200, 200));
981 if (m_startFade != 0) {
982 QPainterPath fadeInPath;
983 fadeInPath.moveTo(0, 0);
984 fadeInPath.lineTo(0, rect().height());
985 fadeInPath.lineTo(m_startFade, 0);
986 fadeInPath.closeSubpath();
987 QPainterPath f1 = painter->worldTransform().map(fadeInPath);
988 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
989 /*if (isSelected()) {
990 QLineF l(m_startFade * scale, 0, 0, itemHeight);
991 painter->drawLine(l);
994 if (m_endFade != 0) {
995 QPainterPath fadeOutPath;
996 fadeOutPath.moveTo(rect().width(), 0);
997 fadeOutPath.lineTo(rect().width(), rect().height());
998 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
999 fadeOutPath.closeSubpath();
1000 QPainterPath f1 = painter->worldTransform().map(fadeOutPath);
1001 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
1002 /*if (isSelected()) {
1003 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
1004 painter->drawLine(l);
1009 painter->setPen(QPen(Qt::lightGray));
1010 // draw effect or transition keyframes
1011 drawKeyFrames(painter, m_limitedKeyFrames);
1015 // expand clip rect to allow correct painting of clip border
1016 painter->setClipping(false);
1017 painter->setRenderHint(QPainter::Antialiasing, true);
1018 framePen.setWidthF(1.5);
1019 painter->setPen(framePen);
1020 painter->drawRoundedRect(mapped.adjusted(0.5, 0, -0.5, 0), 3, 3);
1024 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
1026 if (isItemLocked()) return NONE;
1027 const double scale = projectScene()->scale().x();
1028 double maximumOffset = 6 / scale;
1029 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1030 int kf = mouseOverKeyFrames(pos, maximumOffset);
1032 m_editedKeyframe = kf;
1036 QRectF rect = sceneBoundingRect();
1037 int addtransitionOffset = 10;
1038 // Don't allow add transition if track height is very small. No transitions for audio only clips
1039 if (rect.height() < 30 || isAudioOnly() || m_clipType == AUDIO) addtransitionOffset = 0;
1041 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1043 } else if ((pos.x() <= rect.x() + rect.width() / 2) && pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
1045 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1047 } else if ((pos.x() >= rect.x() + rect.width() / 2) && (rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
1049 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1050 return TRANSITIONSTART;
1051 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1052 return TRANSITIONEND;
1058 int ClipItem::itemHeight()
1060 return KdenliveSettings::trackheight() - 2;
1063 void ClipItem::resetFrameWidth(int width)
1069 QList <GenTime> ClipItem::snapMarkers() const
1071 QList < GenTime > snaps;
1072 if (!m_clip) return snaps;
1073 QList < GenTime > markers = m_clip->snapMarkers();
1076 for (int i = 0; i < markers.size(); i++) {
1077 pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1078 if (pos > GenTime()) {
1079 if (pos > cropDuration()) break;
1080 else snaps.append(pos + startPos());
1086 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
1088 QList < CommentedTime > snaps;
1089 if (!m_clip) return snaps;
1090 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
1093 for (int i = 0; i < markers.size(); i++) {
1094 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1095 if (pos > GenTime()) {
1096 if (pos > cropDuration()) break;
1097 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment(), markers.at(i).markerType()));
1103 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
1105 // Bail out, if caller provided invalid data
1106 if (channels <= 0) {
1107 kWarning() << "Unable to draw image with " << channels << "number of channels";
1110 QRectF re = sceneBoundingRect();
1111 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
1113 if (KdenliveSettings::normaliseaudiothumbs()) {
1114 factor = m_clip->getProperty("audio_max").toInt();
1117 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
1118 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
1119 bool fullAreaDraw = pixelForOneFrame < 10;
1120 bool simplifiedAudio = !KdenliveSettings::displayallchannels();
1122 audiopen.setWidth(0);
1123 if (simplifiedAudio) channels = 1;
1124 int channelHeight = re.height() / channels;
1125 QMap<int, QPainterPath > positiveChannelPaths;
1126 QMap<int, QPainterPath > negativeChannelPaths;
1128 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
1129 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
1131 if (m_audioThumbCachePic.value(startCache).isNull() || m_framePixelWidth != pixelForOneFrame) {
1132 QPixmap pix(100, (int)(re.height()));
1133 pix.fill(QColor(180, 180, 180, 150));
1134 m_audioThumbCachePic[startCache] = pix;
1136 positiveChannelPaths.clear();
1137 negativeChannelPaths.clear();
1139 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
1141 for (int i = 0; i < channels; i++) {
1142 if (simplifiedAudio) {
1143 positiveChannelPaths[i].moveTo(-1, channelHeight);
1145 else if (fullAreaDraw) {
1146 positiveChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1147 negativeChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1150 positiveChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1151 audiopen.setColor(QColor(60, 60, 60, 50));
1152 pixpainter.setPen(audiopen);
1153 pixpainter.drawLine(0, channelHeight*i + channelHeight / 2, 100, channelHeight*i + channelHeight / 2);
1157 for (int samples = 0; samples <= 100; samples++) {
1158 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
1159 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
1160 if (frame < 0 || sample < 0 || sample > 19)
1162 const QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameCache.value((int)frame);
1164 for (int channel = 0; channel < channels && !frame_channel_data.value(channel).isEmpty(); channel++) {
1165 int y = channelHeight * channel + channelHeight / 2;
1166 if (simplifiedAudio) {
1167 double delta = qAbs((frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / factor);
1168 positiveChannelPaths[channel].lineTo(samples, channelHeight - delta);
1169 } else if (fullAreaDraw) {
1170 double delta = qAbs((frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / (2 * factor));
1171 positiveChannelPaths[channel].lineTo(samples, y + delta);
1172 negativeChannelPaths[channel].lineTo(samples, y - delta);
1174 double delta = (frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / (2 * factor);
1175 positiveChannelPaths[channel].lineTo(samples, y + delta);
1179 for (int channel = 0; channel < channels; channel++) {
1180 if (simplifiedAudio) {
1181 positiveChannelPaths[channel].lineTo(101, channelHeight);
1182 } else if (fullAreaDraw) {
1183 int y = channelHeight * channel + channelHeight / 2;
1184 positiveChannelPaths[channel].lineTo(101, y);
1185 negativeChannelPaths[channel].lineTo(101, y);
1188 if (fullAreaDraw || simplifiedAudio) {
1189 audiopen.setColor(QColor(80, 80, 80, 200));
1190 pixpainter.setPen(audiopen);
1191 pixpainter.setBrush(QBrush(QColor(120, 120, 120, 200)));
1194 audiopen.setColor(QColor(60, 60, 60, 100));
1195 pixpainter.setPen(audiopen);
1196 pixpainter.setBrush(Qt::NoBrush);
1198 for (int i = 0; i < channels; i++) {
1200 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths.value(i)));
1202 pixpainter.drawPath(positiveChannelPaths.value(i));
1205 m_framePixelWidth = pixelForOneFrame;
1208 int ClipItem::fadeIn() const
1213 int ClipItem::fadeOut() const
1219 void ClipItem::setFadeIn(int pos)
1221 if (pos == m_startFade) return;
1222 int oldIn = m_startFade;
1223 m_startFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1224 QRectF rect = boundingRect();
1225 update(rect.x(), rect.y(), qMax(oldIn, m_startFade), rect.height());
1228 void ClipItem::setFadeOut(int pos)
1230 if (pos == m_endFade) return;
1231 int oldOut = m_endFade;
1232 m_endFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1233 QRectF rect = boundingRect();
1234 update(rect.x() + rect.width() - qMax(oldOut, m_endFade), rect.y(), qMax(oldOut, m_endFade), rect.height());
1238 void ClipItem::setFades(int in, int out)
1246 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1248 //if (e->pos().x() < 20) m_hover = true;
1250 if (isItemLocked()) return;
1252 QRectF r = boundingRect();
1253 double width = 35 / projectScene()->scale().x();
1254 double height = r.height() / 2;
1255 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1256 update(r.x(), r.y() + height, width, height);
1257 update(r.right() - width, r.y() + height, width, height);
1261 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1263 if (isItemLocked()) return;
1265 QRectF r = boundingRect();
1266 double width = 35 / projectScene()->scale().x();
1267 double height = r.height() / 2;
1268 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1269 update(r.x(), r.y() + height, width, height);
1270 update(r.right() - width, r.y() + height, width, height);
1274 void ClipItem::resizeStart(int posx, bool /*size*/, bool emitChange)
1276 bool sizeLimit = false;
1277 if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
1278 const int min = (startPos() - cropStart()).frames(m_fps);
1279 if (posx < min) posx = min;
1283 if (posx == startPos().frames(m_fps)) return;
1284 const int previous = cropStart().frames(m_fps);
1285 AbstractClipItem::resizeStart(posx, sizeLimit);
1287 // set speed independant info
1288 m_speedIndependantInfo = m_info;
1289 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1290 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1292 if ((int) cropStart().frames(m_fps) != previous) {
1293 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1294 m_startThumbTimer.start(150);
1297 if (emitChange) slotUpdateRange();
1300 void ClipItem::slotUpdateRange()
1302 if (m_isMainSelectedClip) emit updateRange();
1305 void ClipItem::resizeEnd(int posx, bool emitChange)
1307 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1308 if (posx > max && maxDuration() != GenTime()) posx = max;
1309 if (posx == endPos().frames(m_fps)) return;
1310 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1311 const int previous = cropDuration().frames(m_fps);
1312 AbstractClipItem::resizeEnd(posx);
1314 // set speed independant info
1315 m_speedIndependantInfo = m_info;
1316 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1317 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1319 if ((int) cropDuration().frames(m_fps) != previous) {
1320 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1321 m_endThumbTimer.start(150);
1324 if (emitChange) slotUpdateRange();
1328 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1330 if (change == QGraphicsItem::ItemSelectedChange) {
1331 if (value.toBool()) setZValue(10);
1334 if (change == ItemPositionChange && scene()) {
1335 // calculate new position.
1336 //if (parentItem()) return pos();
1337 QPointF newPos = value.toPointF();
1338 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1339 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1340 xpos = qMax(xpos, 0);
1342 // Warning: newPos gives a position relative to the click event, so hack to get absolute pos
1343 int yOffset = property("y_absolute").toInt() + newPos.y();
1344 int newTrack = yOffset / KdenliveSettings::trackheight();
1345 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1346 newTrack = qMax(newTrack, 0);
1347 QStringList lockedTracks = property("locked_tracks").toStringList();
1348 if (lockedTracks.contains(QString::number(newTrack))) {
1349 // Trying to move to a locked track
1352 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1353 // Only one clip is moving
1354 QRectF sceneShape = rect();
1355 sceneShape.translate(newPos);
1356 QList<QGraphicsItem*> items;
1357 if (projectScene()->editMode() == NORMALEDIT)
1358 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1359 items.removeAll(this);
1360 bool forwardMove = newPos.x() > pos().x();
1362 if (!items.isEmpty()) {
1363 for (int i = 0; i < items.count(); i++) {
1364 if (!items.at(i)->isEnabled()) continue;
1365 if (items.at(i)->type() == type()) {
1367 QPointF otherPos = items.at(i)->pos();
1368 if ((int) otherPos.y() != (int) pos().y()) {
1372 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1374 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1379 sceneShape.translate(QPointF(-offset, 0));
1380 newPos.setX(newPos.x() - offset);
1382 sceneShape.translate(QPointF(offset, 0));
1383 newPos.setX(newPos.x() + offset);
1385 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1386 subitems.removeAll(this);
1387 for (int j = 0; j < subitems.count(); j++) {
1388 if (!subitems.at(j)->isEnabled()) continue;
1389 if (subitems.at(j)->type() == type()) {
1390 // move was not successful, revert to previous pos
1391 m_info.startPos = GenTime((int) pos().x(), m_fps);
1397 m_info.track = newTrack;
1398 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1404 m_info.track = newTrack;
1405 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1406 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1409 return QGraphicsItem::itemChange(change, value);
1413 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1416 int ClipItem::effectsCounter()
1418 return effectsCount() + 1;
1421 int ClipItem::effectsCount()
1423 return m_effectList.count();
1426 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1428 return m_effectList.hasEffect(tag, id);
1431 QStringList ClipItem::effectNames()
1433 return m_effectList.effectNames();
1436 QDomElement ClipItem::effect(int ix) const
1438 if (ix >= m_effectList.count() || ix < 0) return QDomElement();
1439 return m_effectList.at(ix).cloneNode().toElement();
1442 QDomElement ClipItem::effectAtIndex(int ix) const
1444 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1445 return m_effectList.itemFromIndex(ix).cloneNode().toElement();
1448 QDomElement ClipItem::getEffectAtIndex(int ix) const
1450 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1451 return m_effectList.itemFromIndex(ix);
1454 void ClipItem::updateEffect(QDomElement effect)
1456 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1457 m_effectList.updateEffect(effect);
1458 m_effectNames = m_effectList.effectNames().join(" / ");
1459 QString id = effect.attribute("id");
1460 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1463 QRectF r = boundingRect();
1469 void ClipItem::enableEffects(QList <int> indexes, bool disable)
1471 m_effectList.enableEffects(indexes, disable);
1474 bool ClipItem::moveEffect(QDomElement effect, int ix)
1476 if (ix <= 0 || ix > (m_effectList.count()) || effect.isNull()) {
1477 kDebug() << "Invalid effect index: " << ix;
1480 m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
1481 effect.setAttribute("kdenlive_ix", ix);
1482 m_effectList.insert(effect);
1483 m_effectNames = m_effectList.effectNames().join(" / ");
1484 QString id = effect.attribute("id");
1485 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1488 QRectF r = boundingRect();
1495 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
1497 bool needRepaint = false;
1500 QDomElement insertedEffect;
1501 if (!effect.hasAttribute("kdenlive_ix")) {
1502 // effect dropped from effect list
1503 ix = effectsCounter();
1504 } else ix = effect.attribute("kdenlive_ix").toInt();
1505 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1507 insertedEffect = m_effectList.insert(effect);
1508 } else insertedEffect = m_effectList.append(effect);
1510 // Update index to the real one
1511 effect.setAttribute("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1515 if (effect.attribute("tag") == "affine") {
1516 // special case: the affine effect needs in / out points
1517 effectIn = effect.attribute("in").toInt();
1518 effectOut = effect.attribute("out").toInt();
1521 effectIn = EffectsList::parameter(effect, "in").toInt();
1522 effectOut = EffectsList::parameter(effect, "out").toInt();
1525 EffectsParameterList parameters;
1526 parameters.addParam("tag", insertedEffect.attribute("tag"));
1527 parameters.addParam("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1528 if (insertedEffect.hasAttribute("src")) parameters.addParam("src", insertedEffect.attribute("src"));
1529 if (insertedEffect.hasAttribute("disable")) parameters.addParam("disable", insertedEffect.attribute("disable"));
1531 QString effectId = insertedEffect.attribute("id");
1532 if (effectId.isEmpty()) effectId = insertedEffect.attribute("tag");
1533 parameters.addParam("id", effectId);
1535 QDomNodeList params = insertedEffect.elementsByTagName("parameter");
1537 bool needInOutSync = false;
1539 // check if it is a fade effect
1540 if (effectId == "fadein") {
1542 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1543 fade = effectOut - effectIn;
1545 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1546 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1547 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1549 } else if (effectId == "fade_from_black") {
1551 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1552 fade = effectOut - effectIn;
1554 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1555 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1556 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1558 } else if (effectId == "fadeout") {
1560 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1561 fade = effectIn - effectOut;
1563 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1564 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1565 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1567 } else if (effectId == "fade_to_black") {
1569 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1570 fade = effectIn - effectOut;
1572 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1573 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1574 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1578 for (int i = 0; i < params.count(); i++) {
1579 QDomElement e = params.item(i).toElement();
1581 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
1582 // Effects with a geometry parameter need to sync in / out with parent clip
1583 needInOutSync = true;
1585 if (e.attribute("type") == "simplekeyframe") {
1586 QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1587 double factor = locale.toDouble(e.attribute("factor", "1"));
1588 double offset = e.attribute("offset", "0").toDouble();
1589 if (factor != 1 || offset != 0) {
1590 for (int j = 0; j < values.count(); j++) {
1591 QString pos = values.at(j).section(':', 0, 0);
1592 double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor;
1593 values[j] = pos + '=' + locale.toString(val);
1596 parameters.addParam(e.attribute("name"), values.join(";"));
1597 /*parameters.addParam("max", e.attribute("max"));
1598 parameters.addParam("min", e.attribute("min"));
1599 parameters.addParam("factor", );*/
1600 } else if (e.attribute("type") == "keyframe") {
1601 parameters.addParam("keyframes", e.attribute("keyframes"));
1602 parameters.addParam("max", e.attribute("max"));
1603 parameters.addParam("min", e.attribute("min"));
1604 parameters.addParam("factor", e.attribute("factor", "1"));
1605 parameters.addParam("offset", e.attribute("offset", "0"));
1606 parameters.addParam("starttag", e.attribute("starttag", "start"));
1607 parameters.addParam("endtag", e.attribute("endtag", "end"));
1608 } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") {
1609 parameters.addParam(e.attribute("name"), e.attribute("value"));
1613 if (e.attribute("factor").contains('%')) {
1614 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1616 fact = locale.toDouble(e.attribute("factor", "1"));
1618 double offset = e.attribute("offset", "0").toDouble();
1619 parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact));
1623 if (needInOutSync) {
1624 parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
1625 parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
1626 parameters.addParam("_sync_in_out", "1");
1628 m_effectNames = m_effectList.effectNames().join(" / ");
1629 if (fade > 0) m_startFade = fade;
1630 else if (fade < 0) m_endFade = -fade;
1632 if (m_selectedEffect == -1) {
1633 setSelectedEffect(0);
1634 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1635 if (needRepaint) update(boundingRect());
1639 else { /*if (!needRepaint) */
1640 QRectF r = boundingRect();
1647 void ClipItem::deleteEffect(QString index)
1649 bool needRepaint = false;
1650 int ix = index.toInt();
1652 QDomElement effect = m_effectList.itemFromIndex(ix);
1653 QString effectId = effect.attribute("id");
1654 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1655 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1658 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1659 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1662 } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
1663 m_effectList.removeAt(ix);
1664 m_effectNames = m_effectList.effectNames().join(" / ");
1666 if (m_effectList.isEmpty() || m_selectedEffect == ix) {
1667 // Current effect was removed
1668 if (ix > m_effectList.count()) {
1669 setSelectedEffect(m_effectList.count());
1670 } else setSelectedEffect(ix);
1672 if (needRepaint) update(boundingRect());
1674 QRectF r = boundingRect();
1678 //if (!m_effectList.isEmpty()) flashClip();
1681 double ClipItem::speed() const
1686 int ClipItem::strobe() const
1691 void ClipItem::setSpeed(const double speed, const int strobe)
1694 if (m_speed <= 0 && m_speed > -1)
1697 if (m_speed == 1.0) m_clipName = m_clip->name();
1698 else m_clipName = m_clip->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1699 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1700 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1704 GenTime ClipItem::maxDuration() const
1706 return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1709 GenTime ClipItem::speedIndependantCropStart() const
1711 return m_speedIndependantInfo.cropStart;
1714 GenTime ClipItem::speedIndependantCropDuration() const
1716 return m_speedIndependantInfo.cropDuration;
1720 const ItemInfo ClipItem::speedIndependantInfo() const
1722 return m_speedIndependantInfo;
1725 int ClipItem::nextFreeEffectGroupIndex() const
1727 int freeGroupIndex = 0;
1728 for (int i = 0; i < m_effectList.count(); i++) {
1729 QDomElement effect = m_effectList.at(i);
1730 EffectInfo effectInfo;
1731 effectInfo.fromString(effect.attribute("kdenlive_info"));
1732 if (effectInfo.groupIndex >= freeGroupIndex) {
1733 freeGroupIndex = effectInfo.groupIndex + 1;
1736 return freeGroupIndex;
1740 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1742 if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
1743 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
1744 event->acceptProposedAction();
1746 doc.setContent(effects, true);
1747 QDomElement e = doc.documentElement();
1748 if (e.tagName() == "effectgroup") {
1749 // dropped an effect group
1750 QDomNodeList effectlist = e.elementsByTagName("effect");
1751 int freeGroupIndex = nextFreeEffectGroupIndex();
1752 EffectInfo effectInfo;
1753 for (int i = 0; i < effectlist.count(); i++) {
1754 QDomElement effect = effectlist.at(i).toElement();
1755 effectInfo.fromString(effect.attribute("kdenlive_info"));
1756 effectInfo.groupIndex = freeGroupIndex;
1757 effect.setAttribute("kdenlive_info", effectInfo.toString());
1758 effect.removeAttribute("kdenlive_ix");
1761 // single effect dropped
1762 e.removeAttribute("kdenlive_ix");
1764 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1765 if (view) view->slotAddEffect(e, m_info.startPos, track());
1771 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1773 if (isItemLocked()) event->setAccepted(false);
1774 else if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
1775 event->acceptProposedAction();
1776 } else event->setAccepted(false);
1779 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1784 void ClipItem::addTransition(Transition* t)
1786 m_transitionsList.append(t);
1787 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1789 QDomElement e = doc.documentElement();
1790 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1793 void ClipItem::setVideoOnly(bool force)
1795 m_videoOnly = force;
1798 void ClipItem::setAudioOnly(bool force)
1800 m_audioOnly = force;
1801 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1803 if (m_clipType == COLOR) {
1804 QString colour = m_clip->getProperty("colour");
1805 colour = colour.replace(0, 2, "#");
1806 m_baseColor = QColor(colour.left(7));
1807 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1808 else m_baseColor = QColor(141, 166, 215);
1810 m_audioThumbCachePic.clear();
1813 bool ClipItem::isAudioOnly() const
1818 bool ClipItem::isVideoOnly() const
1823 void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
1825 if (effect.attribute("disable") == "1") return;
1827 effect.setAttribute("active_keyframe", pos);
1828 m_editedKeyframe = pos;
1829 QDomNodeList params = effect.elementsByTagName("parameter");
1830 for (int i = 0; i < params.count(); i++) {
1831 QDomElement e = params.item(i).toElement();
1832 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1833 QString kfr = e.attribute("keyframes");
1834 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1837 foreach(const QString &str, keyframes) {
1838 int kpos = str.section(':', 0, 0).toInt();
1839 double newval = locale.toDouble(str.section(':', 1, 1));
1842 } else if (!added) {
1843 if (i == m_visibleParam)
1844 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1846 newkfr.append(QString::number(pos) + ':' + locale.toString(newval));
1847 if (kpos > pos) newkfr.append(str);
1849 } else newkfr.append(str);
1852 if (i == m_visibleParam)
1853 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1855 newkfr.append(QString::number(pos) + ':' + e.attribute("default"));
1857 e.setAttribute("keyframes", newkfr.join(";"));
1862 void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double value)
1864 if (effect.attribute("disable") == "1") return;
1866 effect.setAttribute("active_keyframe", newpos);
1867 QDomNodeList params = effect.elementsByTagName("parameter");
1868 int start = cropStart().frames(m_fps);
1869 int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
1870 for (int i = 0; i < params.count(); i++) {
1871 QDomElement e = params.item(i).toElement();
1872 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1873 QString kfr = e.attribute("keyframes");
1874 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1876 foreach(const QString &str, keyframes) {
1877 if (str.section(':', 0, 0).toInt() != oldpos) {
1879 } else if (newpos != -1) {
1880 newpos = qMax(newpos, start);
1881 newpos = qMin(newpos, end);
1882 if (i == m_visibleParam)
1883 newkfr.append(QString::number(newpos) + ':' + locale.toString(value));
1885 newkfr.append(QString::number(newpos) + ':' + str.section(':', 1, 1));
1888 e.setAttribute("keyframes", newkfr.join(";"));
1892 updateKeyframes(effect);
1896 void ClipItem::updateKeyframes(QDomElement effect)
1898 m_keyframes.clear();
1901 QDomNodeList params = effect.elementsByTagName("parameter");
1902 QDomElement e = params.item(m_visibleParam).toElement();
1903 if (e.attribute("intimeline") != "1") {
1904 setSelectedEffect(m_selectedEffect);
1907 m_limitedKeyFrames = e.attribute("type") == "keyframe";
1908 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1909 foreach(const QString &str, keyframes) {
1910 int pos = str.section(':', 0, 0).toInt();
1911 double val = locale.toDouble(str.section(':', 1, 1));
1912 m_keyframes[pos] = val;
1914 if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
1917 Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
1920 return m_clip->audioProducer(track);
1921 else if (isVideoOnly())
1922 return m_clip->videoProducer(track);
1924 return m_clip->getProducer(trackSpecific ? track : -1);
1927 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
1929 QMap<int, QDomElement> effects;
1930 for (int i = 0; i < m_effectList.count(); i++) {
1931 QDomElement effect = m_effectList.at(i);
1933 if (effect.attribute("id").startsWith("fade")) {
1934 QString id = effect.attribute("id");
1935 int in = EffectsList::parameter(effect, "in").toInt();
1936 int out = EffectsList::parameter(effect, "out").toInt();
1937 int clipEnd = (cropStart() + cropDuration()).frames(m_fps) - 1;
1938 if (id == "fade_from_black" || id == "fadein") {
1939 if (in != cropStart().frames(m_fps)) {
1940 effects[i] = effect.cloneNode().toElement();
1941 int duration = out - in;
1942 in = cropStart().frames(m_fps);
1943 out = in + duration;
1944 EffectsList::setParameter(effect, "in", QString::number(in));
1945 EffectsList::setParameter(effect, "out", QString::number(out));
1947 if (out > clipEnd) {
1948 if (!effects.contains(i))
1949 effects[i] = effect.cloneNode().toElement();
1950 EffectsList::setParameter(effect, "out", QString::number(clipEnd));
1952 if (effects.contains(i)) {
1953 setFadeIn(out - in);
1956 if (out != clipEnd) {
1957 effects[i] = effect.cloneNode().toElement();
1958 int diff = out - clipEnd;
1959 in = qMax(in - diff, (int) cropStart().frames(m_fps));
1961 EffectsList::setParameter(effect, "in", QString::number(in));
1962 EffectsList::setParameter(effect, "out", QString::number(out));
1964 if (in < cropStart().frames(m_fps)) {
1965 if (!effects.contains(i))
1966 effects[i] = effect.cloneNode().toElement();
1967 EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
1969 if (effects.contains(i))
1970 setFadeOut(out - in);
1973 } else if (effect.attribute("id") == "freeze" && cropStart() != oldInfo.cropStart) {
1974 effects[i] = effect.cloneNode().toElement();
1975 int diff = (oldInfo.cropStart - cropStart()).frames(m_fps);
1976 int frame = EffectsList::parameter(effect, "frame").toInt();
1977 EffectsList::setParameter(effect, "frame", QString::number(frame - diff));
1979 } else if (effect.attribute("id") == "pan_zoom") {
1980 effect.setAttribute("in", cropStart().frames(m_fps));
1981 effect.setAttribute("out", (cropStart() + cropDuration()).frames(m_fps) - 1);
1984 QDomNodeList params = effect.elementsByTagName("parameter");
1985 for (int j = 0; j < params.count(); j++) {
1986 QDomElement param = params.item(j).toElement();
1988 QString type = param.attribute("type");
1989 if (type == "geometry" && !param.hasAttribute("fixed")) {
1990 if (!effects.contains(i))
1991 effects[i] = effect.cloneNode().toElement();
1992 updateGeometryKeyframes(effect, j, width, height, oldInfo);
1993 } else if (type == "simplekeyframe" || type == "keyframe") {
1994 if (!effects.contains(i))
1995 effects[i] = effect.cloneNode().toElement();
1996 updateNormalKeyframes(param, oldInfo);
1998 } else if (type == "roto-spline") {
1999 if (!effects.contains(i))
2000 effects[i] = effect.cloneNode().toElement();
2001 QString value = param.attribute("value");
2002 if (adjustRotoDuration(&value, cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1))
2003 param.setAttribute("value", value);
2011 bool ClipItem::updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo)
2013 int in = cropStart().frames(m_fps);
2014 int out = (cropStart() + cropDuration()).frames(m_fps) - 1;
2015 int oldin = oldInfo.cropStart.frames(m_fps);
2017 bool keyFrameUpdated = false;
2019 const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
2020 QMap <int, double> keyframes;
2021 foreach (QString keyframe, data) {
2022 int keyframepos = keyframe.section(':', 0, 0).toInt();
2023 // if keyframe was at clip start, update it
2024 if (keyframepos == oldin) {
2026 keyFrameUpdated = true;
2028 keyframes[keyframepos] = locale.toDouble(keyframe.section(':', 1, 1));
2032 QMap<int, double>::iterator i = keyframes.end();
2034 double lastValue = 0;
2038 * Take care of resize from start
2040 bool startFound = false;
2041 while (i-- != keyframes.begin()) {
2042 if (i.key() < in && !startFound) {
2045 keyframes[in] = i.value();
2047 relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
2048 keyframes[in] = i.value() + (lastValue - i.value()) * relPos;
2052 lastValue = i.value();
2054 i = keyframes.erase(i);
2058 * Take care of resize from end
2060 i = keyframes.begin();
2062 bool endFound = false;
2063 while (i != keyframes.end()) {
2064 if (i.key() > out && !endFound) {
2067 keyframes[out] = i.value();
2069 relPos = (out - lastPos) / (qreal)(i.key() - lastPos + 1);
2070 keyframes[out] = lastValue + (i.value() - lastValue) * relPos;
2074 lastValue = i.value();
2076 i = keyframes.erase(i);
2081 if (startFound || endFound || keyFrameUpdated) {
2083 QMap<int, double>::const_iterator k = keyframes.constBegin();
2084 while (k != keyframes.constEnd()) {
2085 newkfr.append(QString::number(k.key()) + ':' + QString::number(qRound(k.value())) + ';');
2088 parameter.setAttribute("keyframes", newkfr);
2095 void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
2097 QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
2098 int offset = oldInfo.cropStart.frames(m_fps);
2099 QString data = param.attribute("value");
2101 QStringList kfrs = data.split(';');
2103 foreach (const QString &keyframe, kfrs) {
2104 if (keyframe.contains('=')) {
2105 int pos = keyframe.section('=', 0, 0).toInt();
2107 data.append(QString::number(pos) + '=' + keyframe.section('=', 1) + ";");
2109 else data.append(keyframe + ';');
2112 Mlt::Geometry geometry(data.toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
2113 param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
2116 void ClipItem::slotGotThumbsCache()
2118 disconnect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
2123 #include "clipitem.moc"