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,
773 if (parentItem()) paintColor = QColor(255, 248, 149);
774 else paintColor = m_baseColor;
775 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
776 paintColor = paintColor.darker();
777 framePen.setColor(Qt::red);
778 framePen.setWidthF(2.0);
781 framePen.setColor(paintColor.darker());
784 const QRectF exposed = option->exposedRect;
785 painter->setClipRect(exposed);
786 painter->fillRect(exposed, paintColor);
787 painter->setWorldMatrixEnabled(false);;
788 const QRectF mapped = painter->worldTransform().mapRect(rect());
790 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
791 QPen pen = painter->pen();
792 pen.setColor(QColor(255, 255, 255, 150));
793 painter->setPen(pen);
794 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
795 const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
796 painter->drawPixmap(top, m_startPix);
797 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
798 painter->drawLine(l2);
799 } else if (!m_endPix.isNull()) {
800 const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
801 painter->drawPixmap(top, m_endPix);
802 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
803 painter->drawLine(l2);
805 if (!m_startPix.isNull()) {
806 painter->drawPixmap(mapped.topLeft(), m_startPix);
807 QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
808 painter->drawLine(l2);
811 // if we are in full zoom, paint thumbnail for every frame
812 if (m_clip->thumbProducer() && clipType() != COLOR && clipType() != AUDIO && !m_audioOnly && painter->worldTransform().m11() == FRAME_SIZE) {
813 int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
814 int left = qMax((int) m_info.cropStart.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x() - offset);
815 int right = qMin((int)(m_info.cropStart + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x() - offset);
816 QPointF startPos = mapped.topLeft();
817 int startOffset = m_info.cropStart.frames(m_fps);
818 if (clipType() == IMAGE || clipType() == TEXT) {
819 for (int i = left; i <= right; i++) {
820 painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
824 #if KDE_IS_VERSION(4,5,0)
825 if (m_clip && m_clip->thumbProducer()) {
826 QString path = m_clip->fileURL().path() + '_';
829 pen.setStyle(Qt::DotLine);
830 painter->setPen(pen);
832 for (int i = left; i <= right; i++) {
833 img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
834 QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
835 if (img.isNull()) missing << i;
836 else painter->drawImage(xpos, img);
837 painter->drawLine(xpos, xpos + QPointF(0, mapped.height()));
839 if (!missing.isEmpty()) {
840 m_clip->thumbProducer()->queryIntraThumbs(missing);
841 connect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
847 painter->setPen(Qt::black);
850 // draw audio thumbnails
851 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
853 double startpixel = exposed.left();
856 double endpixel = exposed.right();
859 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
861 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
863 if (m_clipType == AV && !isAudioOnly()) {
865 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
866 } else mappedRect = mapped;
868 double scale = painter->worldTransform().m11();
870 if (isEnabled() && m_clip) channels = m_clip->getProperty("channels").toInt();
871 if (scale != m_framePixelWidth)
872 m_audioThumbCachePic.clear();
873 double cropLeft = m_info.cropStart.frames(m_fps);
874 const int clipStart = mappedRect.x();
875 const int mappedStartPixel = painter->worldTransform().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
876 const int mappedEndPixel = painter->worldTransform().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
877 cropLeft = cropLeft * scale;
880 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
883 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
884 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
885 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
889 // only paint details if clip is big enough
890 if (mapped.width() > 20) {
892 // Draw effects names
893 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
894 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
896 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
897 qreal value = m_timeLine->currentValue();
898 txtBounding.setWidth(txtBounding.width() * value);
899 bgColor.setRgb(50 + 200 *(1.0 - value), 50, 50, 100 + 50 * value);
900 } else bgColor.setRgb(50, 50, 90, 180);
902 QPainterPath rounded;
903 rounded.moveTo(txtBounding.bottomRight());
904 rounded.arcTo(txtBounding.right() - txtBounding.height() - 2, txtBounding.top() - txtBounding.height(), txtBounding.height() * 2, txtBounding.height() * 2, 270, 90);
905 rounded.lineTo(txtBounding.topLeft());
906 rounded.lineTo(txtBounding.bottomLeft());
907 painter->fillPath(rounded, bgColor);
908 painter->setPen(Qt::lightGray);
909 painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_effectNames);
912 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
913 painter->setBrush(framePen.color());
914 painter->setPen(Qt::NoPen);
915 painter->drawRoundedRect(txtBounding2, 3, 3);
916 painter->setBrush(QBrush(Qt::NoBrush));
919 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
920 } else if (m_audioOnly) {
921 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
923 painter->setPen(Qt::white);
924 painter->drawText(txtBounding2, Qt::AlignCenter, m_clipName);
928 if (isEnabled() && m_clip) {
929 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
930 QList < CommentedTime >::Iterator it = markers.begin();
933 QBrush markerBrush(QColor(120, 120, 0, 140));
934 QPen pen = painter->pen();
935 pen.setColor(QColor(255, 255, 255, 200));
936 pen.setStyle(Qt::DotLine);
938 for (; it != markers.end(); ++it) {
939 pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
940 if (pos > GenTime()) {
941 if (pos > cropDuration()) break;
942 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
943 QLineF l2 = painter->worldTransform().map(l);
944 painter->setPen(pen);
945 painter->drawLine(l2);
946 if (KdenliveSettings::showmarkers()) {
947 framepos = rect().x() + pos.frames(m_fps);
948 const QRectF r1(framepos + 0.04, 10, rect().width() - framepos - 2, rect().height() - 10);
949 const QRectF r2 = painter->worldTransform().mapRect(r1);
950 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
951 painter->setBrush(markerBrush);
952 painter->setPen(Qt::NoPen);
953 painter->drawRoundedRect(txtBounding3, 3, 3);
954 painter->setBrush(QBrush(Qt::NoBrush));
955 painter->setPen(Qt::white);
956 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
958 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
963 // draw start / end fades
966 fades = QBrush(QColor(200, 50, 50, 150));
967 } else fades = QBrush(QColor(200, 200, 200, 200));
969 if (m_startFade != 0) {
970 QPainterPath fadeInPath;
971 fadeInPath.moveTo(0, 0);
972 fadeInPath.lineTo(0, rect().height());
973 fadeInPath.lineTo(m_startFade, 0);
974 fadeInPath.closeSubpath();
975 QPainterPath f1 = painter->worldTransform().map(fadeInPath);
976 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
977 /*if (isSelected()) {
978 QLineF l(m_startFade * scale, 0, 0, itemHeight);
979 painter->drawLine(l);
982 if (m_endFade != 0) {
983 QPainterPath fadeOutPath;
984 fadeOutPath.moveTo(rect().width(), 0);
985 fadeOutPath.lineTo(rect().width(), rect().height());
986 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
987 fadeOutPath.closeSubpath();
988 QPainterPath f1 = painter->worldTransform().map(fadeOutPath);
989 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
990 /*if (isSelected()) {
991 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
992 painter->drawLine(l);
997 painter->setPen(QPen(Qt::lightGray));
998 // draw effect or transition keyframes
999 drawKeyFrames(painter, m_limitedKeyFrames);
1003 // expand clip rect to allow correct painting of clip border
1004 painter->setClipping(false);
1005 painter->setPen(framePen);
1006 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1007 painter->drawRect(mapped.adjusted(0.5, 0.5, -0.5, -0.5));
1010 painter->drawRect(mapped.adjusted(0, 0, -0.5, 0));
1015 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
1017 if (isItemLocked()) return NONE;
1018 const double scale = projectScene()->scale().x();
1019 double maximumOffset = 6 / scale;
1020 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1021 int kf = mouseOverKeyFrames(pos, maximumOffset);
1023 m_editedKeyframe = kf;
1027 QRectF rect = sceneBoundingRect();
1028 int addtransitionOffset = 10;
1029 // Don't allow add transition if track height is very small
1030 if (rect.height() < 30) addtransitionOffset = 0;
1032 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1034 } else if ((pos.x() <= rect.x() + rect.width() / 2) && pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
1036 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1038 } else if ((pos.x() >= rect.x() + rect.width() / 2) && (rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
1040 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1041 return TRANSITIONSTART;
1042 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1043 return TRANSITIONEND;
1049 int ClipItem::itemHeight()
1051 return KdenliveSettings::trackheight() - 2;
1054 void ClipItem::resetFrameWidth(int width)
1060 QList <GenTime> ClipItem::snapMarkers() const
1062 QList < GenTime > snaps;
1063 QList < GenTime > markers = baseClip()->snapMarkers();
1066 for (int i = 0; i < markers.size(); i++) {
1067 pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1068 if (pos > GenTime()) {
1069 if (pos > cropDuration()) break;
1070 else snaps.append(pos + startPos());
1076 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
1078 QList < CommentedTime > snaps;
1079 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
1082 for (int i = 0; i < markers.size(); i++) {
1083 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1084 if (pos > GenTime()) {
1085 if (pos > cropDuration()) break;
1086 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
1092 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
1094 QRectF re = sceneBoundingRect();
1095 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
1097 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
1098 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
1100 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
1101 //kDebug() << "creating " << startCache;
1102 //if (framePixelWidth!=pixelForOneFrame ||
1103 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
1105 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
1106 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
1107 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
1109 bool fullAreaDraw = pixelForOneFrame < 10;
1110 QMap<int, QPainterPath > positiveChannelPaths;
1111 QMap<int, QPainterPath > negativeChannelPaths;
1112 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
1114 audiopen.setWidth(0);
1115 pixpainter.setPen(audiopen);
1116 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
1117 //pixpainter.drawLine(0,0,100,re.height());
1118 // Bail out, if caller provided invalid data
1119 if (channels <= 0) {
1120 kWarning() << "Unable to draw image with " << channels << "number of channels";
1124 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
1126 for (int i = 0; i < channels; i++) {
1128 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1129 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1132 for (int samples = 0; samples <= 100; samples++) {
1133 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
1134 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
1135 if (frame < 0 || sample < 0 || sample > 19)
1137 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
1139 for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
1141 int y = channelHeight * channel + channelHeight / 2;
1142 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
1144 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
1145 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
1147 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
1148 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
1151 for (int channel = 0; channel < channels ; channel++)
1152 if (fullAreaDraw && samples == 100) {
1153 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1154 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1155 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1156 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1160 pixpainter.setPen(QPen(QColor(0, 0, 0)));
1161 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
1163 for (int i = 0; i < channels; i++) {
1165 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
1166 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
1168 pixpainter.drawPath(positiveChannelPaths[i]);
1171 //audioThumbWasDrawn=true;
1172 m_framePixelWidth = pixelForOneFrame;
1177 int ClipItem::fadeIn() const
1182 int ClipItem::fadeOut() const
1188 void ClipItem::setFadeIn(int pos)
1190 if (pos == m_startFade) return;
1191 int oldIn = m_startFade;
1192 m_startFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1193 QRectF rect = boundingRect();
1194 update(rect.x(), rect.y(), qMax(oldIn, m_startFade), rect.height());
1197 void ClipItem::setFadeOut(int pos)
1199 if (pos == m_endFade) return;
1200 int oldOut = m_endFade;
1201 m_endFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1202 QRectF rect = boundingRect();
1203 update(rect.x() + rect.width() - qMax(oldOut, m_endFade), rect.y(), qMax(oldOut, m_endFade), rect.height());
1207 void ClipItem::setFades(int in, int out)
1215 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1217 //if (e->pos().x() < 20) m_hover = true;
1219 if (isItemLocked()) return;
1221 QRectF r = boundingRect();
1222 double width = 35 / projectScene()->scale().x();
1223 double height = r.height() / 2;
1224 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1225 update(r.x(), r.y() + height, width, height);
1226 update(r.right() - width, r.y() + height, width, height);
1230 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1232 if (isItemLocked()) return;
1234 QRectF r = boundingRect();
1235 double width = 35 / projectScene()->scale().x();
1236 double height = r.height() / 2;
1237 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1238 update(r.x(), r.y() + height, width, height);
1239 update(r.right() - width, r.y() + height, width, height);
1243 void ClipItem::resizeStart(int posx, bool /*size*/)
1245 bool sizeLimit = false;
1246 if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
1247 const int min = (startPos() - cropStart()).frames(m_fps);
1248 if (posx < min) posx = min;
1252 if (posx == startPos().frames(m_fps)) return;
1253 const int previous = cropStart().frames(m_fps);
1254 AbstractClipItem::resizeStart(posx, sizeLimit);
1256 // set speed independant info
1257 m_speedIndependantInfo = m_info;
1258 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1259 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1261 if ((int) cropStart().frames(m_fps) != previous) {
1262 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1263 m_startThumbTimer.start(150);
1268 void ClipItem::resizeEnd(int posx)
1270 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1271 if (posx > max && maxDuration() != GenTime()) posx = max;
1272 if (posx == endPos().frames(m_fps)) return;
1273 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1274 const int previous = cropDuration().frames(m_fps);
1275 AbstractClipItem::resizeEnd(posx);
1277 // set speed independant info
1278 m_speedIndependantInfo = m_info;
1279 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1280 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1282 if ((int) cropDuration().frames(m_fps) != previous) {
1283 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1284 m_endThumbTimer.start(150);
1290 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1292 if (change == QGraphicsItem::ItemSelectedChange) {
1293 if (value.toBool()) setZValue(10);
1296 if (change == ItemPositionChange && scene()) {
1297 // calculate new position.
1298 //if (parentItem()) return pos();
1299 QPointF newPos = value.toPointF();
1300 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1301 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1302 xpos = qMax(xpos, 0);
1304 // Warning: newPos gives a position relative to the click event, so hack to get absolute pos
1305 int yOffset = property("y_absolute").toInt() + newPos.y();
1306 int newTrack = yOffset / KdenliveSettings::trackheight();
1307 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1308 newTrack = qMax(newTrack, 0);
1309 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1310 // Only one clip is moving
1311 QRectF sceneShape = rect();
1312 sceneShape.translate(newPos);
1313 QList<QGraphicsItem*> items;
1314 if (projectScene()->editMode() == NORMALEDIT)
1315 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1316 items.removeAll(this);
1317 bool forwardMove = newPos.x() > pos().x();
1319 if (!items.isEmpty()) {
1320 for (int i = 0; i < items.count(); i++) {
1321 if (!items.at(i)->isEnabled()) continue;
1322 if (items.at(i)->type() == type()) {
1324 QPointF otherPos = items.at(i)->pos();
1325 if ((int) otherPos.y() != (int) pos().y()) {
1329 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1331 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1336 sceneShape.translate(QPointF(-offset, 0));
1337 newPos.setX(newPos.x() - offset);
1339 sceneShape.translate(QPointF(offset, 0));
1340 newPos.setX(newPos.x() + offset);
1342 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1343 subitems.removeAll(this);
1344 for (int j = 0; j < subitems.count(); j++) {
1345 if (!subitems.at(j)->isEnabled()) continue;
1346 if (subitems.at(j)->type() == type()) {
1347 // move was not successful, revert to previous pos
1348 m_info.startPos = GenTime((int) pos().x(), m_fps);
1354 m_info.track = newTrack;
1355 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1361 m_info.track = newTrack;
1362 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1363 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1366 return QGraphicsItem::itemChange(change, value);
1370 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1373 int ClipItem::effectsCounter()
1375 return effectsCount() + 1;
1378 int ClipItem::effectsCount()
1380 return m_effectList.count();
1383 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1385 return m_effectList.hasEffect(tag, id);
1388 QStringList ClipItem::effectNames()
1390 return m_effectList.effectNames();
1393 QDomElement ClipItem::effect(int ix) const
1395 if (ix >= m_effectList.count() || ix < 0) return QDomElement();
1396 return m_effectList.at(ix).cloneNode().toElement();
1399 QDomElement ClipItem::effectAtIndex(int ix) const
1401 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1402 return m_effectList.itemFromIndex(ix).cloneNode().toElement();
1405 QDomElement ClipItem::getEffectAtIndex(int ix) const
1407 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1408 return m_effectList.itemFromIndex(ix);
1411 void ClipItem::updateEffect(QDomElement effect)
1413 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1414 m_effectList.updateEffect(effect);
1415 m_effectNames = m_effectList.effectNames().join(" / ");
1416 QString id = effect.attribute("id");
1417 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1420 QRectF r = boundingRect();
1426 void ClipItem::enableEffects(QList <int> indexes, bool disable)
1428 m_effectList.enableEffects(indexes, disable);
1431 bool ClipItem::moveEffect(QDomElement effect, int ix)
1433 if (ix <= 0 || ix > (m_effectList.count()) || effect.isNull()) {
1434 kDebug() << "Invalid effect index: " << ix;
1437 m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
1438 effect.setAttribute("kdenlive_ix", ix);
1439 m_effectList.insert(effect);
1440 m_effectNames = m_effectList.effectNames().join(" / ");
1441 QString id = effect.attribute("id");
1442 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1445 QRectF r = boundingRect();
1452 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
1454 bool needRepaint = false;
1457 QDomElement insertedEffect;
1458 if (!effect.hasAttribute("kdenlive_ix")) {
1459 // effect dropped from effect list
1460 ix = effectsCounter();
1461 } else ix = effect.attribute("kdenlive_ix").toInt();
1462 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1464 insertedEffect = m_effectList.insert(effect);
1465 } else insertedEffect = m_effectList.append(effect);
1467 // Update index to the real one
1468 effect.setAttribute("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1472 if (effect.attribute("tag") == "affine") {
1473 // special case: the affine effect needs in / out points
1474 effectIn = effect.attribute("in").toInt();
1475 effectOut = effect.attribute("out").toInt();
1478 effectIn = EffectsList::parameter(effect, "in").toInt();
1479 effectOut = EffectsList::parameter(effect, "out").toInt();
1482 EffectsParameterList parameters;
1483 parameters.addParam("tag", insertedEffect.attribute("tag"));
1484 parameters.addParam("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1485 if (insertedEffect.hasAttribute("src")) parameters.addParam("src", insertedEffect.attribute("src"));
1486 if (insertedEffect.hasAttribute("disable")) parameters.addParam("disable", insertedEffect.attribute("disable"));
1488 QString effectId = insertedEffect.attribute("id");
1489 if (effectId.isEmpty()) effectId = insertedEffect.attribute("tag");
1490 parameters.addParam("id", effectId);
1492 QDomNodeList params = insertedEffect.elementsByTagName("parameter");
1494 bool needInOutSync = false;
1496 // check if it is a fade effect
1497 if (effectId == "fadein") {
1499 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1500 fade = effectOut - effectIn;
1502 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1503 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1504 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1506 } else if (effectId == "fade_from_black") {
1507 kDebug()<<"// FOUND FTB:"<<effectOut<<" - "<<effectIn;
1509 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1510 fade = effectOut - effectIn;
1512 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1513 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1514 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1516 } else if (effectId == "fadeout") {
1518 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1519 fade = effectIn - effectOut;
1521 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1522 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1523 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1525 } else if (effectId == "fade_to_black") {
1527 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1528 fade = effectIn - effectOut;
1530 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1531 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1532 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1536 for (int i = 0; i < params.count(); i++) {
1537 QDomElement e = params.item(i).toElement();
1539 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
1540 // Effects with a geometry parameter need to sync in / out with parent clip
1541 needInOutSync = true;
1543 if (e.attribute("type") == "simplekeyframe") {
1544 QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1545 double factor = locale.toDouble(e.attribute("factor", "1"));
1546 double offset = e.attribute("offset", "0").toDouble();
1547 if (factor != 1 || offset != 0) {
1548 for (int j = 0; j < values.count(); j++) {
1549 QString pos = values.at(j).section(':', 0, 0);
1550 double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor;
1551 values[j] = pos + '=' + locale.toString(val);
1554 parameters.addParam(e.attribute("name"), values.join(";"));
1555 /*parameters.addParam("max", e.attribute("max"));
1556 parameters.addParam("min", e.attribute("min"));
1557 parameters.addParam("factor", );*/
1558 } else if (e.attribute("type") == "keyframe") {
1559 parameters.addParam("keyframes", e.attribute("keyframes"));
1560 parameters.addParam("max", e.attribute("max"));
1561 parameters.addParam("min", e.attribute("min"));
1562 parameters.addParam("factor", e.attribute("factor", "1"));
1563 parameters.addParam("offset", e.attribute("offset", "0"));
1564 parameters.addParam("starttag", e.attribute("starttag", "start"));
1565 parameters.addParam("endtag", e.attribute("endtag", "end"));
1566 } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") {
1567 parameters.addParam(e.attribute("name"), e.attribute("value"));
1571 if (e.attribute("factor").contains('%')) {
1572 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1574 fact = locale.toDouble(e.attribute("factor", "1"));
1576 double offset = e.attribute("offset", "0").toDouble();
1577 parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact));
1581 if (needInOutSync) {
1582 parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
1583 parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
1584 parameters.addParam("_sync_in_out", "1");
1586 m_effectNames = m_effectList.effectNames().join(" / ");
1587 if (fade > 0) m_startFade = fade;
1588 else if (fade < 0) m_endFade = -fade;
1590 if (m_selectedEffect == -1) {
1591 setSelectedEffect(0);
1592 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1593 if (needRepaint) update(boundingRect());
1597 else { /*if (!needRepaint) */
1598 QRectF r = boundingRect();
1605 void ClipItem::deleteEffect(QString index)
1607 bool needRepaint = false;
1608 int ix = index.toInt();
1610 QDomElement effect = m_effectList.itemFromIndex(ix);
1611 QString effectId = effect.attribute("id");
1612 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1613 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1616 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1617 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1620 } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
1621 m_effectList.removeAt(ix);
1622 m_effectNames = m_effectList.effectNames().join(" / ");
1624 if (m_effectList.isEmpty() || m_selectedEffect == ix) {
1625 // Current effect was removed
1626 if (ix > m_effectList.count()) {
1627 setSelectedEffect(m_effectList.count());
1628 } else setSelectedEffect(ix);
1630 if (needRepaint) update(boundingRect());
1632 QRectF r = boundingRect();
1636 //if (!m_effectList.isEmpty()) flashClip();
1639 double ClipItem::speed() const
1644 int ClipItem::strobe() const
1649 void ClipItem::setSpeed(const double speed, const int strobe)
1652 if (m_speed <= 0 && m_speed > -1)
1655 if (m_speed == 1.0) m_clipName = baseClip()->name();
1656 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1657 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1658 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1662 GenTime ClipItem::maxDuration() const
1664 return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1667 GenTime ClipItem::speedIndependantCropStart() const
1669 return m_speedIndependantInfo.cropStart;
1672 GenTime ClipItem::speedIndependantCropDuration() const
1674 return m_speedIndependantInfo.cropDuration;
1678 const ItemInfo ClipItem::speedIndependantInfo() const
1680 return m_speedIndependantInfo;
1683 int ClipItem::nextFreeEffectGroupIndex() const
1685 int freeGroupIndex = 0;
1686 for (int i = 0; i < m_effectList.count(); i++) {
1687 QDomElement effect = m_effectList.at(i);
1688 EffectInfo effectInfo;
1689 effectInfo.fromString(effect.attribute("kdenlive_info"));
1690 if (effectInfo.groupIndex >= freeGroupIndex) {
1691 freeGroupIndex = effectInfo.groupIndex + 1;
1694 return freeGroupIndex;
1698 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1700 if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
1701 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
1702 event->acceptProposedAction();
1704 doc.setContent(effects, true);
1705 QDomElement e = doc.documentElement();
1706 if (e.tagName() == "effectgroup") {
1707 // dropped an effect group
1708 QDomNodeList effectlist = e.elementsByTagName("effect");
1709 int freeGroupIndex = nextFreeEffectGroupIndex();
1710 EffectInfo effectInfo;
1711 for (int i = 0; i < effectlist.count(); i++) {
1712 QDomElement effect = effectlist.at(i).toElement();
1713 effectInfo.fromString(effect.attribute("kdenlive_info"));
1714 effectInfo.groupIndex = freeGroupIndex;
1715 effect.setAttribute("kdenlive_info", effectInfo.toString());
1716 effect.removeAttribute("kdenlive_ix");
1719 // single effect dropped
1720 e.removeAttribute("kdenlive_ix");
1722 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1723 if (view) view->slotAddEffect(e, m_info.startPos, track());
1729 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1731 if (isItemLocked()) event->setAccepted(false);
1732 else if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
1733 event->acceptProposedAction();
1734 } else event->setAccepted(false);
1737 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1742 void ClipItem::addTransition(Transition* t)
1744 m_transitionsList.append(t);
1745 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1747 QDomElement e = doc.documentElement();
1748 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1751 void ClipItem::setVideoOnly(bool force)
1753 m_videoOnly = force;
1756 void ClipItem::setAudioOnly(bool force)
1758 m_audioOnly = force;
1759 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1761 if (m_clipType == COLOR) {
1762 QString colour = m_clip->getProperty("colour");
1763 colour = colour.replace(0, 2, "#");
1764 m_baseColor = QColor(colour.left(7));
1765 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1766 else m_baseColor = QColor(141, 166, 215);
1768 m_audioThumbCachePic.clear();
1771 bool ClipItem::isAudioOnly() const
1776 bool ClipItem::isVideoOnly() const
1781 void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
1783 if (effect.attribute("disable") == "1") return;
1785 effect.setAttribute("active_keyframe", pos);
1786 m_editedKeyframe = pos;
1787 QDomNodeList params = effect.elementsByTagName("parameter");
1788 for (int i = 0; i < params.count(); i++) {
1789 QDomElement e = params.item(i).toElement();
1790 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1791 QString kfr = e.attribute("keyframes");
1792 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1795 foreach(const QString &str, keyframes) {
1796 int kpos = str.section(':', 0, 0).toInt();
1797 double newval = locale.toDouble(str.section(':', 1, 1));
1800 } else if (!added) {
1801 if (i == m_visibleParam)
1802 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1804 newkfr.append(QString::number(pos) + ':' + locale.toString(newval));
1805 if (kpos > pos) newkfr.append(str);
1807 } else newkfr.append(str);
1810 if (i == m_visibleParam)
1811 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1813 newkfr.append(QString::number(pos) + ':' + e.attribute("default"));
1815 e.setAttribute("keyframes", newkfr.join(";"));
1820 void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double value)
1822 if (effect.attribute("disable") == "1") return;
1824 effect.setAttribute("active_keyframe", newpos);
1825 QDomNodeList params = effect.elementsByTagName("parameter");
1826 int start = cropStart().frames(m_fps);
1827 int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
1828 for (int i = 0; i < params.count(); i++) {
1829 QDomElement e = params.item(i).toElement();
1830 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1831 QString kfr = e.attribute("keyframes");
1832 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1834 foreach(const QString &str, keyframes) {
1835 if (str.section(':', 0, 0).toInt() != oldpos) {
1837 } else if (newpos != -1) {
1838 newpos = qMax(newpos, start);
1839 newpos = qMin(newpos, end);
1840 if (i == m_visibleParam)
1841 newkfr.append(QString::number(newpos) + ':' + locale.toString(value));
1843 newkfr.append(QString::number(newpos) + ':' + str.section(':', 1, 1));
1846 e.setAttribute("keyframes", newkfr.join(";"));
1850 updateKeyframes(effect);
1854 void ClipItem::updateKeyframes(QDomElement effect)
1856 m_keyframes.clear();
1859 QDomNodeList params = effect.elementsByTagName("parameter");
1860 QDomElement e = params.item(m_visibleParam).toElement();
1861 if (e.attribute("intimeline") != "1") {
1862 setSelectedEffect(m_selectedEffect);
1865 m_limitedKeyFrames = e.attribute("type") == "keyframe";
1866 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1867 foreach(const QString &str, keyframes) {
1868 int pos = str.section(':', 0, 0).toInt();
1869 double val = locale.toDouble(str.section(':', 1, 1));
1870 m_keyframes[pos] = val;
1872 if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
1875 Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
1878 return m_clip->audioProducer(track);
1879 else if (isVideoOnly())
1880 return m_clip->videoProducer();
1882 return m_clip->getProducer(trackSpecific ? track : -1);
1885 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
1887 QMap<int, QDomElement> effects;
1888 for (int i = 0; i < m_effectList.count(); i++) {
1889 QDomElement effect = m_effectList.at(i);
1891 if (effect.attribute("id").startsWith("fade")) {
1892 QString id = effect.attribute("id");
1893 int in = EffectsList::parameter(effect, "in").toInt();
1894 int out = EffectsList::parameter(effect, "out").toInt();
1895 int clipEnd = (cropStart() + cropDuration()).frames(m_fps) - 1;
1896 if (id == "fade_from_black" || id == "fadein") {
1897 if (in != cropStart().frames(m_fps)) {
1898 effects[i] = effect.cloneNode().toElement();
1899 int duration = out - in;
1900 in = cropStart().frames(m_fps);
1901 out = in + duration;
1902 EffectsList::setParameter(effect, "in", QString::number(in));
1903 EffectsList::setParameter(effect, "out", QString::number(out));
1905 if (out > clipEnd) {
1906 if (!effects.contains(i))
1907 effects[i] = effect.cloneNode().toElement();
1908 EffectsList::setParameter(effect, "out", QString::number(clipEnd));
1910 if (effects.contains(i))
1911 setFadeIn(out - in);
1913 if (out != clipEnd) {
1914 effects[i] = effect.cloneNode().toElement();
1915 int diff = out - clipEnd;
1916 in = qMax(in - diff, (int) cropStart().frames(m_fps));
1918 EffectsList::setParameter(effect, "in", QString::number(in));
1919 EffectsList::setParameter(effect, "out", QString::number(out));
1921 if (in < cropStart().frames(m_fps)) {
1922 if (!effects.contains(i))
1923 effects[i] = effect.cloneNode().toElement();
1924 EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
1926 if (effects.contains(i))
1927 setFadeOut(out - in);
1930 } else if (effect.attribute("id") == "freeze" && cropStart() != oldInfo.cropStart) {
1931 effects[i] = effect.cloneNode().toElement();
1932 int diff = (oldInfo.cropStart - cropStart()).frames(m_fps);
1933 int frame = EffectsList::parameter(effect, "frame").toInt();
1934 EffectsList::setParameter(effect, "frame", QString::number(frame - diff));
1936 } else if (effect.attribute("id") == "pan_zoom") {
1937 effect.setAttribute("in", cropStart().frames(m_fps));
1938 effect.setAttribute("out", (cropStart() + cropDuration()).frames(m_fps) - 1);
1941 QDomNodeList params = effect.elementsByTagName("parameter");
1942 for (int j = 0; j < params.count(); j++) {
1943 QDomElement param = params.item(j).toElement();
1945 QString type = param.attribute("type");
1946 if (type == "geometry" && !param.hasAttribute("fixed")) {
1947 if (!effects.contains(i))
1948 effects[i] = effect.cloneNode().toElement();
1949 updateGeometryKeyframes(effect, j, width, height, oldInfo);
1950 } else if (type == "simplekeyframe" || type == "keyframe") {
1951 if (!effects.contains(i))
1952 effects[i] = effect.cloneNode().toElement();
1953 updateNormalKeyframes(param, oldInfo);
1955 } else if (type == "roto-spline") {
1956 if (!effects.contains(i))
1957 effects[i] = effect.cloneNode().toElement();
1958 QString value = param.attribute("value");
1959 if (adjustRotoDuration(&value, cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1))
1960 param.setAttribute("value", value);
1968 bool ClipItem::updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo)
1970 int in = cropStart().frames(m_fps);
1971 int out = (cropStart() + cropDuration()).frames(m_fps) - 1;
1972 int oldin = oldInfo.cropStart.frames(m_fps);
1974 bool keyFrameUpdated = false;
1976 const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
1977 QMap <int, double> keyframes;
1978 foreach (QString keyframe, data) {
1979 int keyframepos = keyframe.section(':', 0, 0).toInt();
1980 // if keyframe was at clip start, update it
1981 if (keyframepos == oldin) {
1983 keyFrameUpdated = true;
1985 keyframes[keyframepos] = locale.toDouble(keyframe.section(':', 1, 1));
1989 QMap<int, double>::iterator i = keyframes.end();
1991 double lastValue = 0;
1995 * Take care of resize from start
1997 bool startFound = false;
1998 while (i-- != keyframes.begin()) {
1999 if (i.key() < in && !startFound) {
2002 keyframes[in] = i.value();
2004 relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
2005 keyframes[in] = i.value() + (lastValue - i.value()) * relPos;
2009 lastValue = i.value();
2011 i = keyframes.erase(i);
2015 * Take care of resize from end
2017 i = keyframes.begin();
2019 bool endFound = false;
2020 while (i != keyframes.end()) {
2021 if (i.key() > out && !endFound) {
2024 keyframes[out] = i.value();
2026 relPos = (out - lastPos) / (qreal)(i.key() - lastPos + 1);
2027 keyframes[out] = lastValue + (i.value() - lastValue) * relPos;
2031 lastValue = i.value();
2033 i = keyframes.erase(i);
2038 if (startFound || endFound || keyFrameUpdated) {
2040 QMap<int, double>::const_iterator k = keyframes.constBegin();
2041 while (k != keyframes.constEnd()) {
2042 newkfr.append(QString::number(k.key()) + ':' + QString::number(qRound(k.value())) + ';');
2045 parameter.setAttribute("keyframes", newkfr);
2052 void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
2054 QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
2055 int offset = oldInfo.cropStart.frames(m_fps);
2056 QString data = param.attribute("value");
2058 QStringList kfrs = data.split(';');
2060 foreach (const QString &keyframe, kfrs) {
2061 if (keyframe.contains('=')) {
2062 int pos = keyframe.section('=', 0, 0).toInt();
2064 data.append(QString::number(pos) + '=' + keyframe.section('=', 1) + ";");
2066 else data.append(keyframe + ';');
2069 Mlt::Geometry geometry(data.toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
2070 param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
2073 void ClipItem::slotGotThumbsCache()
2075 disconnect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
2079 #include "clipitem.moc"