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 (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
274 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
275 int end = (cropDuration() + cropStart()).frames(m_fps) - 1;
277 if (effect.attribute("id") == "fadeout") {
278 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
279 int effectDuration = EffectsList::parameter(effect, "in").toInt();
280 if (effectDuration > cropDuration().frames(m_fps)) {
281 effectDuration = cropDuration().frames(m_fps) / 2;
283 start -= effectDuration;
285 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
286 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
288 } else if (effect.attribute("id") == "fade_to_black") {
289 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
290 int effectDuration = EffectsList::parameter(effect, "in").toInt();
291 if (effectDuration > cropDuration().frames(m_fps)) {
292 effectDuration = cropDuration().frames(m_fps) / 2;
294 start -= effectDuration;
296 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
297 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
300 EffectsList::setParameter(effect, "in", QString::number(start));
301 EffectsList::setParameter(effect, "out", QString::number(end));
302 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
303 int start = cropStart().frames(m_fps);
305 if (effect.attribute("id") == "fadein") {
306 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
307 int effectDuration = EffectsList::parameter(effect, "out").toInt();
308 if (effectDuration > cropDuration().frames(m_fps)) {
309 effectDuration = cropDuration().frames(m_fps) / 2;
311 end += effectDuration;
313 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
314 } else if (effect.attribute("id") == "fade_from_black") {
315 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
316 int effectDuration = EffectsList::parameter(effect, "out").toInt();
317 if (effectDuration > cropDuration().frames(m_fps)) {
318 effectDuration = cropDuration().frames(m_fps) / 2;
320 end += effectDuration;
322 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
324 EffectsList::setParameter(effect, "in", QString::number(start));
325 EffectsList::setParameter(effect, "out", QString::number(end));
330 const QString ClipItem::adjustKeyframes(QString keyframes, int offset)
334 const QStringList list = keyframes.split(';', QString::SkipEmptyParts);
335 foreach(const QString &keyframe, list) {
336 int pos = keyframe.section(':', 0, 0).toInt() - offset;
337 QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1);
338 result.append(newKey);
340 return result.join(";");
343 bool ClipItem::checkKeyFrames()
345 bool clipEffectsModified = false;
347 // go through all effects this clip has
348 for (int ix = 0; ix < m_effectList.count(); ++ix) {
349 QStringList keyframeParams = keyframes(ix);
350 QStringList newKeyFrameParams;
351 bool effModified = false;
353 // go through all params which have keyframes
354 foreach(const QString &kfr, keyframeParams) {
355 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
356 QStringList newKeyFrames;
357 bool cutKeyFrame = false;
358 bool modified = false;
360 double lastValue = -1;
361 int start = cropStart().frames(m_fps);
362 int end = (cropStart() + cropDuration()).frames(m_fps);
364 // go through all keyframes for one param
365 foreach(const QString &str, keyframes) {
366 int pos = str.section(':', 0, 0).toInt();
367 double val = locale.toDouble(str.section(':', 1, 1));
368 if (pos - start < 0) {
369 // a keyframe is defined before the start of the clip
371 } else if (cutKeyFrame) {
372 // create new keyframe at clip start, calculate interpolated value
374 int diff = pos - lastPos;
375 double ratio = (double)(start - lastPos) / diff;
376 double newValue = lastValue + (val - lastValue) * ratio;
377 newKeyFrames.append(QString::number(start) + ':' + locale.toString(newValue));
384 // create new keyframe at clip end, calculate interpolated value
385 int diff = pos - lastPos;
387 double ratio = (double)(end - lastPos) / diff;
388 double newValue = lastValue + (val - lastValue) * ratio;
389 newKeyFrames.append(QString::number(end) + ':' + locale.toString(newValue));
394 newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
401 newKeyFrameParams.append(newKeyFrames.join(";"));
408 setKeyframes(ix, newKeyFrameParams);
409 clipEffectsModified = true;
412 return clipEffectsModified;
415 void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
417 QDomElement effect = m_effectList.at(ix);
418 if (effect.attribute("disable") == "1") return;
420 QDomNodeList params = effect.elementsByTagName("parameter");
421 int keyframeParams = 0;
422 for (int i = 0; i < params.count(); i++) {
423 QDomElement e = params.item(i).toElement();
424 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
425 e.setAttribute("keyframes", keyframes.at(keyframeParams));
426 if (ix == m_selectedEffect && keyframeParams == 0) {
429 double max = locale.toDouble(e.attribute("max"));
430 double min = locale.toDouble(e.attribute("min"));
431 m_keyframeFactor = 100.0 / (max - min);
432 m_keyframeOffset = min;
433 m_keyframeDefault = locale.toDouble(e.attribute("default"));
434 m_selectedKeyframe = 0;
436 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
437 foreach(const QString &str, keyframes) {
438 int pos = str.section(':', 0, 0).toInt();
439 double val = locale.toDouble(str.section(':', 1, 1));
440 m_keyframes[pos] = val;
442 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
443 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
452 void ClipItem::setSelectedEffect(const int ix)
454 m_selectedEffect = ix;
456 QDomElement effect = effectAtIndex(m_selectedEffect);
457 if (!effect.isNull() && effect.attribute("disable") != "1") {
458 QDomNodeList params = effect.elementsByTagName("parameter");
459 for (int i = 0; i < params.count(); i++) {
460 QDomElement e = params.item(i).toElement();
461 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
463 m_limitedKeyFrames = e.attribute("type") == "keyframe";
465 double max = locale.toDouble(e.attribute("max"));
466 double min = locale.toDouble(e.attribute("min"));
467 m_keyframeFactor = 100.0 / (max - min);
468 m_keyframeOffset = min;
469 m_keyframeDefault = locale.toDouble(e.attribute("default"));
470 m_selectedKeyframe = 0;
473 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
474 foreach(const QString &str, keyframes) {
475 int pos = str.section(':', 0, 0).toInt();
476 double val = locale.toDouble(str.section(':', 1, 1));
477 m_keyframes[pos] = val;
479 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end())
480 m_editedKeyframe = -1;
487 if (!m_keyframes.isEmpty()) {
493 QStringList ClipItem::keyframes(const int index)
496 QDomElement effect = m_effectList.at(index);
497 QDomNodeList params = effect.elementsByTagName("parameter");
499 for (int i = 0; i < params.count(); i++) {
500 QDomElement e = params.item(i).toElement();
501 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe"))
502 result.append(e.attribute("keyframes"));
507 void ClipItem::updateKeyframeEffect()
509 // regenerate xml parameter from the clip keyframes
510 QDomElement effect = getEffectAtIndex(m_selectedEffect);
511 if (effect.attribute("disable") == "1") return;
512 QDomNodeList params = effect.elementsByTagName("parameter");
513 QDomElement e = params.item(m_visibleParam).toElement();
517 if (m_keyframes.count() > 0) {
518 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
519 while (i != m_keyframes.constEnd()) {
520 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
524 // Effect has a keyframe type parameter, we need to set the values
525 e.setAttribute("keyframes", keyframes);
529 QDomElement ClipItem::selectedEffect()
531 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
532 return effectAtIndex(m_selectedEffect);
535 void ClipItem::resetThumbs(bool clearExistingThumbs)
537 if (clearExistingThumbs) {
538 m_startPix = QPixmap();
539 m_endPix = QPixmap();
540 m_audioThumbCachePic.clear();
546 void ClipItem::refreshClip(bool checkDuration, bool forceResetThumbs)
548 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
549 m_maxDuration = m_clip->maxDuration();
550 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
551 if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
552 // Clip duration changed, make sure to stay in correct range
553 if (m_info.cropStart > m_maxDuration) {
554 m_info.cropStart = GenTime();
555 m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
557 m_info.cropDuration = m_maxDuration;
559 updateRectGeometry();
563 if (m_clipType == COLOR) {
564 QString colour = m_clip->getProperty("colour");
565 colour = colour.replace(0, 2, "#");
566 m_baseColor = QColor(colour.left(7));
568 } else resetThumbs(forceResetThumbs);
571 void ClipItem::slotFetchThumbs()
573 if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
574 if (m_clipType == IMAGE) {
575 if (m_startPix.isNull()) {
576 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
582 if (m_clipType == TEXT) {
583 if (m_startPix.isNull()) slotGetStartThumb();
588 if (m_startPix.isNull()) {
589 m_startThumbRequested = true;
590 frames.append((int)m_speedIndependantInfo.cropStart.frames(m_fps));
593 if (m_endPix.isNull()) {
594 m_endThumbRequested = true;
595 frames.append((int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
598 if (!frames.isEmpty()) m_clip->slotExtractImage(frames);
601 void ClipItem::stopThumbs()
603 // Clip is about to be deleted, make sure we don't request thumbnails
604 disconnect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
605 disconnect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
608 void ClipItem::slotGetStartThumb()
610 m_startThumbRequested = true;
611 m_clip->slotExtractImage(QList<int>() << (int)m_speedIndependantInfo.cropStart.frames(m_fps));
614 void ClipItem::slotGetEndThumb()
616 m_endThumbRequested = true;
617 m_clip->slotExtractImage(QList<int>() << (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
621 void ClipItem::slotSetStartThumb(QImage img)
623 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
624 QPixmap pix = QPixmap::fromImage(img);
626 QRectF r = sceneBoundingRect();
627 r.setRight(pix.width() + 2);
632 void ClipItem::slotSetEndThumb(QImage img)
634 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
635 QPixmap pix = QPixmap::fromImage(img);
637 QRectF r = sceneBoundingRect();
638 r.setLeft(r.right() - pix.width() - 2);
643 void ClipItem::slotThumbReady(int frame, QImage img)
645 if (scene() == NULL) return;
646 QRectF r = boundingRect();
647 QPixmap pix = QPixmap::fromImage(img);
648 double width = pix.width() / projectScene()->scale().x();
649 if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
651 m_startThumbRequested = false;
652 update(r.left(), r.top(), width, pix.height());
653 if (m_clipType == IMAGE || m_clipType == TEXT) {
654 update(r.right() - width, r.top(), width, pix.height());
656 } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
658 m_endThumbRequested = false;
659 update(r.right() - width, r.top(), width, pix.height());
663 void ClipItem::slotSetStartThumb(const QPixmap pix)
668 void ClipItem::slotSetEndThumb(const QPixmap pix)
673 QPixmap ClipItem::startThumb() const
678 QPixmap ClipItem::endThumb() const
683 void ClipItem::slotGotAudioData()
685 m_audioThumbReady = true;
686 if (m_clipType == AV && !isAudioOnly()) {
687 QRectF r = boundingRect();
688 r.setTop(r.top() + r.height() / 2 - 1);
693 int ClipItem::type() const
698 DocClipBase *ClipItem::baseClip() const
703 QDomElement ClipItem::xml() const
708 QDomElement ClipItem::itemXml() const
710 QDomElement xml = m_clip->toXML();
711 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
712 if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
713 if (m_audioOnly) xml.setAttribute("audio_only", 1);
714 else if (m_videoOnly) xml.setAttribute("video_only", 1);
718 int ClipItem::clipType() const
723 QString ClipItem::clipName() const
728 void ClipItem::setClipName(const QString &name)
733 const QString ClipItem::clipProducer() const
738 void ClipItem::flashClip()
740 if (m_timeLine == 0) {
741 m_timeLine = new QTimeLine(750, this);
742 m_timeLine->setUpdateInterval(80);
743 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
744 m_timeLine->setFrameRange(0, 100);
745 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
747 //m_timeLine->start();
750 void ClipItem::animate(qreal /*value*/)
752 QRectF r = boundingRect();
758 void ClipItem::paint(QPainter *painter,
759 const QStyleOptionGraphicsItem *option,
764 if (parentItem()) paintColor = QColor(255, 248, 149);
765 else paintColor = m_baseColor;
766 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
767 paintColor = paintColor.darker();
768 framePen.setColor(Qt::red);
769 framePen.setWidthF(2.0);
772 framePen.setColor(paintColor.darker());
775 const QRectF exposed = option->exposedRect;
776 painter->setClipRect(exposed);
777 painter->fillRect(exposed, paintColor);
778 painter->setWorldMatrixEnabled(false);;
779 const QRectF mapped = painter->worldTransform().mapRect(rect());
781 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
782 QPen pen = painter->pen();
783 pen.setColor(QColor(255, 255, 255, 150));
784 painter->setPen(pen);
785 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
786 const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
787 painter->drawPixmap(top, m_startPix);
788 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
789 painter->drawLine(l2);
790 } else if (!m_endPix.isNull()) {
791 const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
792 painter->drawPixmap(top, m_endPix);
793 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
794 painter->drawLine(l2);
796 if (!m_startPix.isNull()) {
797 painter->drawPixmap(mapped.topLeft(), m_startPix);
798 QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
799 painter->drawLine(l2);
802 // if we are in full zoom, paint thumbnail for every frame
803 if (m_clip->thumbProducer() && clipType() != COLOR && clipType() != AUDIO && !m_audioOnly && painter->worldTransform().m11() == FRAME_SIZE) {
804 int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
805 int left = qMax((int) m_info.cropStart.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x() - offset);
806 int right = qMin((int)(m_info.cropStart + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x() - offset);
807 QPointF startPos = mapped.topLeft();
808 int startOffset = m_info.cropStart.frames(m_fps);
809 if (clipType() == IMAGE || clipType() == TEXT) {
810 for (int i = left; i <= right; i++) {
811 painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
815 #if KDE_IS_VERSION(4,5,0)
816 if (m_clip && m_clip->thumbProducer()) {
817 QString path = m_clip->fileURL().path() + "_";
820 pen.setStyle(Qt::DotLine);
821 painter->setPen(pen);
823 for (int i = left; i <= right; i++) {
824 img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
825 QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
826 if (img.isNull()) missing << i;
827 else painter->drawImage(xpos, img);
828 painter->drawLine(xpos, xpos + QPointF(0, mapped.height()));
830 if (!missing.isEmpty()) {
831 m_clip->thumbProducer()->queryIntraThumbs(missing);
832 connect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
838 painter->setPen(Qt::black);
841 // draw audio thumbnails
842 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
844 double startpixel = exposed.left();
847 double endpixel = exposed.right();
850 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
852 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
854 if (m_clipType == AV && !isAudioOnly()) {
856 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
857 } else mappedRect = mapped;
859 double scale = painter->worldTransform().m11();
861 if (isEnabled() && m_clip) channels = m_clip->getProperty("channels").toInt();
862 if (scale != m_framePixelWidth)
863 m_audioThumbCachePic.clear();
864 double cropLeft = m_info.cropStart.frames(m_fps);
865 const int clipStart = mappedRect.x();
866 const int mappedStartPixel = painter->worldTransform().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
867 const int mappedEndPixel = painter->worldTransform().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
868 cropLeft = cropLeft * scale;
871 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
874 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
875 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
876 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
880 // only paint details if clip is big enough
881 if (mapped.width() > 20) {
883 // Draw effects names
884 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
885 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
887 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
888 qreal value = m_timeLine->currentValue();
889 txtBounding.setWidth(txtBounding.width() * value);
890 bgColor.setRgb(50 + 200 *(1.0 - value), 50, 50, 100 + 50 * value);
891 } else bgColor.setRgb(50, 50, 90, 180);
893 QPainterPath rounded;
894 rounded.moveTo(txtBounding.bottomRight());
895 rounded.arcTo(txtBounding.right() - txtBounding.height() - 2, txtBounding.top() - txtBounding.height(), txtBounding.height() * 2, txtBounding.height() * 2, 270, 90);
896 rounded.lineTo(txtBounding.topLeft());
897 rounded.lineTo(txtBounding.bottomLeft());
898 painter->fillPath(rounded, bgColor);
899 painter->setPen(Qt::lightGray);
900 painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_effectNames);
903 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
904 painter->setBrush(framePen.color());
905 painter->setPen(Qt::NoPen);
906 painter->drawRoundedRect(txtBounding2, 3, 3);
907 painter->setBrush(QBrush(Qt::NoBrush));
910 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
911 } else if (m_audioOnly) {
912 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
914 painter->setPen(Qt::white);
915 painter->drawText(txtBounding2, Qt::AlignCenter, m_clipName);
919 if (isEnabled() && m_clip) {
920 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
921 QList < CommentedTime >::Iterator it = markers.begin();
924 QBrush markerBrush(QColor(120, 120, 0, 140));
925 QPen pen = painter->pen();
926 pen.setColor(QColor(255, 255, 255, 200));
927 pen.setStyle(Qt::DotLine);
929 for (; it != markers.end(); ++it) {
930 pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
931 if (pos > GenTime()) {
932 if (pos > cropDuration()) break;
933 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
934 QLineF l2 = painter->worldTransform().map(l);
935 painter->setPen(pen);
936 painter->drawLine(l2);
937 if (KdenliveSettings::showmarkers()) {
938 framepos = rect().x() + pos.frames(m_fps);
939 const QRectF r1(framepos + 0.04, 10, rect().width() - framepos - 2, rect().height() - 10);
940 const QRectF r2 = painter->worldTransform().mapRect(r1);
941 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
942 painter->setBrush(markerBrush);
943 painter->setPen(Qt::NoPen);
944 painter->drawRoundedRect(txtBounding3, 3, 3);
945 painter->setBrush(QBrush(Qt::NoBrush));
946 painter->setPen(Qt::white);
947 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
949 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
954 // draw start / end fades
957 fades = QBrush(QColor(200, 50, 50, 150));
958 } else fades = QBrush(QColor(200, 200, 200, 200));
960 if (m_startFade != 0) {
961 QPainterPath fadeInPath;
962 fadeInPath.moveTo(0, 0);
963 fadeInPath.lineTo(0, rect().height());
964 fadeInPath.lineTo(m_startFade, 0);
965 fadeInPath.closeSubpath();
966 QPainterPath f1 = painter->worldTransform().map(fadeInPath);
967 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
968 /*if (isSelected()) {
969 QLineF l(m_startFade * scale, 0, 0, itemHeight);
970 painter->drawLine(l);
973 if (m_endFade != 0) {
974 QPainterPath fadeOutPath;
975 fadeOutPath.moveTo(rect().width(), 0);
976 fadeOutPath.lineTo(rect().width(), rect().height());
977 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
978 fadeOutPath.closeSubpath();
979 QPainterPath f1 = painter->worldTransform().map(fadeOutPath);
980 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
981 /*if (isSelected()) {
982 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
983 painter->drawLine(l);
988 painter->setPen(QPen(Qt::lightGray));
989 // draw effect or transition keyframes
990 drawKeyFrames(painter, m_limitedKeyFrames);
994 // expand clip rect to allow correct painting of clip border
995 painter->setClipping(false);
996 painter->setPen(framePen);
997 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
998 painter->drawRect(mapped.adjusted(0.5, 0.5, -0.5, -0.5));
1001 painter->drawRect(mapped.adjusted(0, 0, -0.5, 0));
1006 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
1008 if (isItemLocked()) return NONE;
1009 const double scale = projectScene()->scale().x();
1010 double maximumOffset = 6 / scale;
1011 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1012 int kf = mouseOverKeyFrames(pos, maximumOffset);
1014 m_editedKeyframe = kf;
1018 QRectF rect = sceneBoundingRect();
1019 int addtransitionOffset = 10;
1020 // Don't allow add transition if track height is very small
1021 if (rect.height() < 30) addtransitionOffset = 0;
1023 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1025 } else if ((pos.x() <= rect.x() + rect.width() / 2) && pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
1027 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1029 } else if ((pos.x() >= rect.x() + rect.width() / 2) && (rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
1031 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1032 return TRANSITIONSTART;
1033 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1034 return TRANSITIONEND;
1040 int ClipItem::itemHeight()
1042 return KdenliveSettings::trackheight() - 2;
1045 void ClipItem::resetFrameWidth(int width)
1051 QList <GenTime> ClipItem::snapMarkers() const
1053 QList < GenTime > snaps;
1054 QList < GenTime > markers = baseClip()->snapMarkers();
1057 for (int i = 0; i < markers.size(); i++) {
1058 pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1059 if (pos > GenTime()) {
1060 if (pos > cropDuration()) break;
1061 else snaps.append(pos + startPos());
1067 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
1069 QList < CommentedTime > snaps;
1070 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
1073 for (int i = 0; i < markers.size(); i++) {
1074 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1075 if (pos > GenTime()) {
1076 if (pos > cropDuration()) break;
1077 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
1083 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
1085 QRectF re = sceneBoundingRect();
1086 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
1088 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
1089 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
1091 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
1092 //kDebug() << "creating " << startCache;
1093 //if (framePixelWidth!=pixelForOneFrame ||
1094 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
1096 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
1097 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
1098 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
1100 bool fullAreaDraw = pixelForOneFrame < 10;
1101 QMap<int, QPainterPath > positiveChannelPaths;
1102 QMap<int, QPainterPath > negativeChannelPaths;
1103 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
1105 audiopen.setWidth(0);
1106 pixpainter.setPen(audiopen);
1107 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
1108 //pixpainter.drawLine(0,0,100,re.height());
1109 // Bail out, if caller provided invalid data
1110 if (channels <= 0) {
1111 kWarning() << "Unable to draw image with " << channels << "number of channels";
1115 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
1117 for (int i = 0; i < channels; i++) {
1119 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1120 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1123 for (int samples = 0; samples <= 100; samples++) {
1124 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
1125 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
1126 if (frame < 0 || sample < 0 || sample > 19)
1128 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
1130 for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
1132 int y = channelHeight * channel + channelHeight / 2;
1133 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
1135 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
1136 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
1138 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
1139 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
1142 for (int channel = 0; channel < channels ; channel++)
1143 if (fullAreaDraw && samples == 100) {
1144 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1145 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1146 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1147 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1151 pixpainter.setPen(QPen(QColor(0, 0, 0)));
1152 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
1154 for (int i = 0; i < channels; i++) {
1156 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
1157 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
1159 pixpainter.drawPath(positiveChannelPaths[i]);
1162 //audioThumbWasDrawn=true;
1163 m_framePixelWidth = pixelForOneFrame;
1168 int ClipItem::fadeIn() const
1173 int ClipItem::fadeOut() const
1179 void ClipItem::setFadeIn(int pos)
1181 if (pos == m_startFade) return;
1182 int oldIn = m_startFade;
1183 m_startFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1184 QRectF rect = boundingRect();
1185 update(rect.x(), rect.y(), qMax(oldIn, m_startFade), rect.height());
1188 void ClipItem::setFadeOut(int pos)
1190 if (pos == m_endFade) return;
1191 int oldOut = m_endFade;
1192 m_endFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1193 QRectF rect = boundingRect();
1194 update(rect.x() + rect.width() - qMax(oldOut, m_endFade), rect.y(), qMax(oldOut, m_endFade), rect.height());
1198 void ClipItem::setFades(int in, int out)
1206 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1208 //if (e->pos().x() < 20) m_hover = true;
1210 if (isItemLocked()) return;
1212 QRectF r = boundingRect();
1213 double width = 35 / projectScene()->scale().x();
1214 double height = r.height() / 2;
1215 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1216 update(r.x(), r.y() + height, width, height);
1217 update(r.right() - width, r.y() + height, width, height);
1221 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1223 if (isItemLocked()) return;
1225 QRectF r = boundingRect();
1226 double width = 35 / projectScene()->scale().x();
1227 double height = r.height() / 2;
1228 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1229 update(r.x(), r.y() + height, width, height);
1230 update(r.right() - width, r.y() + height, width, height);
1234 void ClipItem::resizeStart(int posx, bool /*size*/)
1236 bool sizeLimit = false;
1237 if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
1238 const int min = (startPos() - cropStart()).frames(m_fps);
1239 if (posx < min) posx = min;
1243 if (posx == startPos().frames(m_fps)) return;
1244 const int previous = cropStart().frames(m_fps);
1245 AbstractClipItem::resizeStart(posx, sizeLimit);
1247 // set speed independant info
1248 m_speedIndependantInfo = m_info;
1249 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1250 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1252 if ((int) cropStart().frames(m_fps) != previous) {
1253 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1254 m_startThumbTimer.start(150);
1259 void ClipItem::resizeEnd(int posx)
1261 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1262 if (posx > max && maxDuration() != GenTime()) posx = max;
1263 if (posx == endPos().frames(m_fps)) return;
1264 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1265 const int previous = cropDuration().frames(m_fps);
1266 AbstractClipItem::resizeEnd(posx);
1268 // set speed independant info
1269 m_speedIndependantInfo = m_info;
1270 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1271 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1273 if ((int) cropDuration().frames(m_fps) != previous) {
1274 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1275 m_endThumbTimer.start(150);
1281 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1283 if (change == QGraphicsItem::ItemSelectedChange) {
1284 if (value.toBool()) setZValue(10);
1287 if (change == ItemPositionChange && scene()) {
1288 // calculate new position.
1289 //if (parentItem()) return pos();
1290 QPointF newPos = value.toPointF();
1291 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1292 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1293 xpos = qMax(xpos, 0);
1295 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1296 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1297 newTrack = qMax(newTrack, 0);
1298 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1299 // Only one clip is moving
1300 QRectF sceneShape = rect();
1301 sceneShape.translate(newPos);
1302 QList<QGraphicsItem*> items;
1303 if (projectScene()->editMode() == NORMALEDIT)
1304 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1305 items.removeAll(this);
1306 bool forwardMove = newPos.x() > pos().x();
1308 if (!items.isEmpty()) {
1309 for (int i = 0; i < items.count(); i++) {
1310 if (!items.at(i)->isEnabled()) continue;
1311 if (items.at(i)->type() == type()) {
1313 QPointF otherPos = items.at(i)->pos();
1314 if ((int) otherPos.y() != (int) pos().y()) {
1318 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1320 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1325 sceneShape.translate(QPointF(-offset, 0));
1326 newPos.setX(newPos.x() - offset);
1328 sceneShape.translate(QPointF(offset, 0));
1329 newPos.setX(newPos.x() + offset);
1331 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1332 subitems.removeAll(this);
1333 for (int j = 0; j < subitems.count(); j++) {
1334 if (!subitems.at(j)->isEnabled()) continue;
1335 if (subitems.at(j)->type() == type()) {
1336 // move was not successful, revert to previous pos
1337 m_info.startPos = GenTime((int) pos().x(), m_fps);
1343 m_info.track = newTrack;
1344 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1350 m_info.track = newTrack;
1351 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1352 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1355 return QGraphicsItem::itemChange(change, value);
1359 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1362 int ClipItem::effectsCounter()
1364 return effectsCount() + 1;
1367 int ClipItem::effectsCount()
1369 return m_effectList.count();
1372 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1374 return m_effectList.hasEffect(tag, id);
1377 QStringList ClipItem::effectNames()
1379 return m_effectList.effectNames();
1382 QDomElement ClipItem::effect(int ix) const
1384 if (ix >= m_effectList.count() || ix < 0) return QDomElement();
1385 return m_effectList.at(ix).cloneNode().toElement();
1388 QDomElement ClipItem::effectAtIndex(int ix) const
1390 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1391 return m_effectList.itemFromIndex(ix).cloneNode().toElement();
1394 QDomElement ClipItem::getEffectAtIndex(int ix) const
1396 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1397 return m_effectList.itemFromIndex(ix);
1400 void ClipItem::updateEffect(QDomElement effect)
1402 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1403 m_effectList.updateEffect(effect);
1404 m_effectNames = m_effectList.effectNames().join(" / ");
1405 QString id = effect.attribute("id");
1406 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1409 QRectF r = boundingRect();
1415 void ClipItem::enableEffects(QList <int> indexes, bool disable)
1417 m_effectList.enableEffects(indexes, disable);
1420 bool ClipItem::moveEffect(QDomElement effect, int ix)
1422 if (ix <= 0 || ix > (m_effectList.count()) || effect.isNull()) {
1423 kDebug() << "Invalid effect index: " << ix;
1426 m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
1427 effect.setAttribute("kdenlive_ix", ix);
1428 m_effectList.insert(effect);
1429 m_effectNames = m_effectList.effectNames().join(" / ");
1430 QString id = effect.attribute("id");
1431 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1434 QRectF r = boundingRect();
1441 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
1443 bool needRepaint = false;
1446 QDomElement insertedEffect;
1447 if (!effect.hasAttribute("kdenlive_ix")) {
1448 // effect dropped from effect list
1449 ix = effectsCounter();
1450 } else ix = effect.attribute("kdenlive_ix").toInt();
1451 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1453 insertedEffect = m_effectList.insert(effect);
1454 } else insertedEffect = m_effectList.append(effect);
1456 // Update index to the real one
1457 effect.setAttribute("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1459 EffectsParameterList parameters;
1460 parameters.addParam("tag", insertedEffect.attribute("tag"));
1461 parameters.addParam("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1462 if (insertedEffect.hasAttribute("src")) parameters.addParam("src", insertedEffect.attribute("src"));
1463 if (insertedEffect.hasAttribute("disable")) parameters.addParam("disable", insertedEffect.attribute("disable"));
1465 QString effectId = insertedEffect.attribute("id");
1466 if (effectId.isEmpty()) effectId = insertedEffect.attribute("tag");
1467 parameters.addParam("id", effectId);
1469 // special case: the affine effect needs in / out points
1471 QDomNodeList params = insertedEffect.elementsByTagName("parameter");
1473 bool needInOutSync = false;
1474 for (int i = 0; i < params.count(); i++) {
1475 QDomElement e = params.item(i).toElement();
1477 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
1478 // Effects with a geometry parameter need to sync in / out with parent clip
1479 needInOutSync = true;
1481 if (e.attribute("type") == "simplekeyframe") {
1482 QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1483 double factor = locale.toDouble(e.attribute("factor", "1"));
1484 double offset = e.attribute("offset", "0").toDouble();
1485 if (factor != 1 || offset != 0) {
1486 for (int j = 0; j < values.count(); j++) {
1487 QString pos = values.at(j).section(':', 0, 0);
1488 double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor;
1489 values[j] = pos + "=" + locale.toString(val);
1492 parameters.addParam(e.attribute("name"), values.join(";"));
1493 /*parameters.addParam("max", e.attribute("max"));
1494 parameters.addParam("min", e.attribute("min"));
1495 parameters.addParam("factor", );*/
1496 } else if (e.attribute("type") == "keyframe") {
1497 parameters.addParam("keyframes", e.attribute("keyframes"));
1498 parameters.addParam("max", e.attribute("max"));
1499 parameters.addParam("min", e.attribute("min"));
1500 parameters.addParam("factor", e.attribute("factor", "1"));
1501 parameters.addParam("offset", e.attribute("offset", "0"));
1502 parameters.addParam("starttag", e.attribute("starttag", "start"));
1503 parameters.addParam("endtag", e.attribute("endtag", "end"));
1504 } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") {
1505 parameters.addParam(e.attribute("name"), e.attribute("value"));
1507 // check if it is a fade effect
1508 if (effectId == "fadein") {
1510 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1511 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1512 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1514 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1515 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1516 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1518 } else if (effectId == "fade_from_black") {
1520 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1521 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1522 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1524 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1525 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1526 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1528 } else if (effectId == "fadeout") {
1530 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1531 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1532 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1534 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1535 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1536 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1538 } else if (effectId == "fade_to_black") {
1540 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1541 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1542 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1544 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1545 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1546 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1551 if (e.attribute("factor").contains('%')) {
1552 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1554 fact = locale.toDouble(e.attribute("factor", "1"));
1556 double offset = e.attribute("offset", "0").toDouble();
1557 parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact));
1561 if (needInOutSync) {
1562 parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
1563 parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
1564 parameters.addParam("_sync_in_out", "1");
1566 m_effectNames = m_effectList.effectNames().join(" / ");
1567 if (fade > 0) m_startFade = fade;
1568 else if (fade < 0) m_endFade = -fade;
1570 if (m_selectedEffect == -1) {
1571 setSelectedEffect(0);
1572 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1573 if (needRepaint) update(boundingRect());
1577 else { /*if (!needRepaint) */
1578 QRectF r = boundingRect();
1585 void ClipItem::deleteEffect(QString index)
1587 bool needRepaint = false;
1588 int ix = index.toInt();
1590 QDomElement effect = m_effectList.itemFromIndex(ix);
1591 QString effectId = effect.attribute("id");
1592 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1593 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1596 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1597 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1600 } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
1601 m_effectList.removeAt(ix);
1602 m_effectNames = m_effectList.effectNames().join(" / ");
1604 if (m_effectList.isEmpty() || m_selectedEffect == ix) {
1605 // Current effect was removed
1606 if (ix > m_effectList.count()) {
1607 setSelectedEffect(m_effectList.count());
1608 } else setSelectedEffect(ix);
1610 if (needRepaint) update(boundingRect());
1612 QRectF r = boundingRect();
1616 //if (!m_effectList.isEmpty()) flashClip();
1619 double ClipItem::speed() const
1624 int ClipItem::strobe() const
1629 void ClipItem::setSpeed(const double speed, const int strobe)
1632 if (m_speed <= 0 && m_speed > -1)
1635 if (m_speed == 1.0) m_clipName = baseClip()->name();
1636 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1637 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1638 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1642 GenTime ClipItem::maxDuration() const
1644 return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1647 GenTime ClipItem::speedIndependantCropStart() const
1649 return m_speedIndependantInfo.cropStart;
1652 GenTime ClipItem::speedIndependantCropDuration() const
1654 return m_speedIndependantInfo.cropDuration;
1658 const ItemInfo ClipItem::speedIndependantInfo() const
1660 return m_speedIndependantInfo;
1663 int ClipItem::nextFreeEffectGroupIndex() const
1665 int freeGroupIndex = 0;
1666 for (int i = 0; i < m_effectList.count(); i++) {
1667 QDomElement effect = m_effectList.at(i);
1668 EffectInfo effectInfo;
1669 effectInfo.fromString(effect.attribute("kdenlive_info"));
1670 if (effectInfo.groupIndex >= freeGroupIndex) {
1671 freeGroupIndex = effectInfo.groupIndex + 1;
1674 return freeGroupIndex;
1678 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1680 if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
1681 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
1682 event->acceptProposedAction();
1684 doc.setContent(effects, true);
1685 QDomElement e = doc.documentElement();
1686 if (e.tagName() == "effectgroup") {
1687 // dropped an effect group
1688 QDomNodeList effectlist = e.elementsByTagName("effect");
1689 int freeGroupIndex = nextFreeEffectGroupIndex();
1690 EffectInfo effectInfo;
1691 for (int i = 0; i < effectlist.count(); i++) {
1692 QDomElement effect = effectlist.at(i).toElement();
1693 effectInfo.fromString(effect.attribute("kdenlive_info"));
1694 effectInfo.groupIndex = freeGroupIndex;
1695 effect.setAttribute("kdenlive_info", effectInfo.toString());
1696 effect.removeAttribute("kdenlive_ix");
1699 // single effect dropped
1700 e.removeAttribute("kdenlive_ix");
1702 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1703 if (view) view->slotAddEffect(e, m_info.startPos, track());
1709 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1711 if (isItemLocked()) event->setAccepted(false);
1712 else if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
1713 event->acceptProposedAction();
1714 } else event->setAccepted(false);
1717 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1722 void ClipItem::addTransition(Transition* t)
1724 m_transitionsList.append(t);
1725 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1727 QDomElement e = doc.documentElement();
1728 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1731 void ClipItem::setVideoOnly(bool force)
1733 m_videoOnly = force;
1736 void ClipItem::setAudioOnly(bool force)
1738 m_audioOnly = force;
1739 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1741 if (m_clipType == COLOR) {
1742 QString colour = m_clip->getProperty("colour");
1743 colour = colour.replace(0, 2, "#");
1744 m_baseColor = QColor(colour.left(7));
1745 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1746 else m_baseColor = QColor(141, 166, 215);
1748 m_audioThumbCachePic.clear();
1751 bool ClipItem::isAudioOnly() const
1756 bool ClipItem::isVideoOnly() const
1761 void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
1763 if (effect.attribute("disable") == "1") return;
1765 effect.setAttribute("active_keyframe", pos);
1766 m_editedKeyframe = pos;
1767 QDomNodeList params = effect.elementsByTagName("parameter");
1768 for (int i = 0; i < params.count(); i++) {
1769 QDomElement e = params.item(i).toElement();
1770 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1771 QString kfr = e.attribute("keyframes");
1772 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1775 foreach(const QString &str, keyframes) {
1776 int kpos = str.section(':', 0, 0).toInt();
1777 double newval = locale.toDouble(str.section(':', 1, 1));
1780 } else if (!added) {
1781 if (i == m_visibleParam)
1782 newkfr.append(QString::number(pos) + ":" + QString::number(val));
1784 newkfr.append(QString::number(pos) + ":" + locale.toString(newval));
1785 if (kpos > pos) newkfr.append(str);
1787 } else newkfr.append(str);
1790 if (i == m_visibleParam)
1791 newkfr.append(QString::number(pos) + ":" + QString::number(val));
1793 newkfr.append(QString::number(pos) + ":" + e.attribute("default"));
1795 e.setAttribute("keyframes", newkfr.join(";"));
1800 void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double value)
1802 if (effect.attribute("disable") == "1") return;
1804 effect.setAttribute("active_keyframe", newpos);
1805 QDomNodeList params = effect.elementsByTagName("parameter");
1806 int start = cropStart().frames(m_fps);
1807 int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
1808 for (int i = 0; i < params.count(); i++) {
1809 QDomElement e = params.item(i).toElement();
1810 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1811 QString kfr = e.attribute("keyframes");
1812 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1814 foreach(const QString &str, keyframes) {
1815 if (str.section(':', 0, 0).toInt() != oldpos) {
1817 } else if (newpos != -1) {
1818 newpos = qMax(newpos, start);
1819 newpos = qMin(newpos, end);
1820 if (i == m_visibleParam)
1821 newkfr.append(QString::number(newpos) + ":" + locale.toString(value));
1823 newkfr.append(QString::number(newpos) + ":" + str.section(':', 1, 1));
1826 e.setAttribute("keyframes", newkfr.join(";"));
1830 updateKeyframes(effect);
1834 void ClipItem::updateKeyframes(QDomElement effect)
1836 m_keyframes.clear();
1839 QDomNodeList params = effect.elementsByTagName("parameter");
1840 QDomElement e = params.item(m_visibleParam).toElement();
1841 if (e.attribute("intimeline") != "1") {
1842 setSelectedEffect(m_selectedEffect);
1845 m_limitedKeyFrames = e.attribute("type") == "keyframe";
1846 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1847 foreach(const QString &str, keyframes) {
1848 int pos = str.section(':', 0, 0).toInt();
1849 double val = locale.toDouble(str.section(':', 1, 1));
1850 m_keyframes[pos] = val;
1852 if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
1855 Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
1858 return m_clip->audioProducer(track);
1859 else if (isVideoOnly())
1860 return m_clip->videoProducer();
1862 return m_clip->getProducer(trackSpecific ? track : -1);
1865 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
1867 QMap<int, QDomElement> effects;
1868 for (int i = 0; i < m_effectList.count(); i++) {
1869 QDomElement effect = m_effectList.at(i);
1871 if (effect.attribute("id").startsWith("fade")) {
1872 QString id = effect.attribute("id");
1873 int in = EffectsList::parameter(effect, "in").toInt();
1874 int out = EffectsList::parameter(effect, "out").toInt();
1875 int clipEnd = (cropStart() + cropDuration()).frames(m_fps) - 1;
1876 if (id == "fade_from_black" || id == "fadein") {
1877 if (in != cropStart().frames(m_fps)) {
1878 effects[i] = effect.cloneNode().toElement();
1879 int duration = out - in;
1880 in = cropStart().frames(m_fps);
1881 out = in + duration;
1882 EffectsList::setParameter(effect, "in", QString::number(in));
1883 EffectsList::setParameter(effect, "out", QString::number(out));
1885 if (out > clipEnd) {
1886 if (!effects.contains(i))
1887 effects[i] = effect.cloneNode().toElement();
1888 EffectsList::setParameter(effect, "out", QString::number(clipEnd));
1890 if (effects.contains(i))
1891 setFadeIn(out - in);
1893 if (out != clipEnd) {
1894 effects[i] = effect.cloneNode().toElement();
1895 int diff = out - clipEnd;
1896 in = qMax(in - diff, (int) cropStart().frames(m_fps));
1898 EffectsList::setParameter(effect, "in", QString::number(in));
1899 EffectsList::setParameter(effect, "out", QString::number(out));
1901 if (in < cropStart().frames(m_fps)) {
1902 if (!effects.contains(i))
1903 effects[i] = effect.cloneNode().toElement();
1904 EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
1906 if (effects.contains(i))
1907 setFadeOut(out - in);
1910 } else if (effect.attribute("id") == "freeze" && cropStart() != oldInfo.cropStart) {
1911 effects[i] = effect.cloneNode().toElement();
1912 int diff = (oldInfo.cropStart - cropStart()).frames(m_fps);
1913 int frame = EffectsList::parameter(effect, "frame").toInt();
1914 EffectsList::setParameter(effect, "frame", QString::number(frame - diff));
1918 QDomNodeList params = effect.elementsByTagName("parameter");
1919 for (int j = 0; j < params.count(); j++) {
1920 QDomElement param = params.item(j).toElement();
1922 QString type = param.attribute("type");
1923 if (type == "geometry" && !param.hasAttribute("fixed")) {
1924 if (!effects.contains(i))
1925 effects[i] = effect.cloneNode().toElement();
1926 updateGeometryKeyframes(effect, j, width, height, oldInfo);
1927 } else if (type == "simplekeyframe" || type == "keyframe") {
1928 if (!effects.contains(i))
1929 effects[i] = effect.cloneNode().toElement();
1930 updateNormalKeyframes(param);
1932 } else if (type == "roto-spline") {
1933 if (!effects.contains(i))
1934 effects[i] = effect.cloneNode().toElement();
1935 QString value = param.attribute("value");
1936 if (adjustRotoDuration(&value, cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1))
1937 param.setAttribute("value", value);
1945 bool ClipItem::updateNormalKeyframes(QDomElement parameter)
1947 int in = cropStart().frames(m_fps);
1948 int out = (cropStart() + cropDuration()).frames(m_fps) - 1;
1951 const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
1952 QMap <int, double> keyframes;
1953 foreach (QString keyframe, data)
1954 keyframes[keyframe.section(':', 0, 0).toInt()] = locale.toDouble(keyframe.section(':', 1, 1));
1957 QMap<int, double>::iterator i = keyframes.end();
1959 double lastValue = 0;
1963 * Take care of resize from start
1965 bool startFound = false;
1966 while (i-- != keyframes.begin()) {
1967 if (i.key() < in && !startFound) {
1970 keyframes[in] = i.value();
1972 relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
1973 keyframes[in] = i.value() + (lastValue - i.value()) * relPos;
1977 lastValue = i.value();
1979 i = keyframes.erase(i);
1983 * Take care of resize from end
1985 i = keyframes.begin();
1987 bool endFound = false;
1988 while (i != keyframes.end()) {
1989 if (i.key() > out && !endFound) {
1992 keyframes[out] = i.value();
1994 relPos = (out - lastPos) / (qreal)(i.key() - lastPos + 1);
1995 keyframes[out] = lastValue + (i.value() - lastValue) * relPos;
1999 lastValue = i.value();
2001 i = keyframes.erase(i);
2006 if (startFound || endFound) {
2008 QMap<int, double>::const_iterator k = keyframes.constBegin();
2009 while (k != keyframes.constEnd()) {
2010 newkfr.append(QString::number(k.key()) + ':' + QString::number(qRound(k.value())) + ';');
2013 parameter.setAttribute("keyframes", newkfr);
2020 void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
2023 QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
2024 int offset = oldInfo.cropStart.frames(m_fps);
2025 QString data = param.attribute("value");
2027 QStringList kfrs = data.split(';');
2029 foreach (QString keyframe, kfrs) {
2030 if (keyframe.contains('=')) {
2031 int pos = keyframe.section('=', 0, 0).toInt();
2033 data.append(QString::number(pos) + "=" + keyframe.section('=', 1) + ";");
2035 else data.append(keyframe + ";");
2038 Mlt::Geometry geometry(data.toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
2039 param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
2042 void ClipItem::slotGotThumbsCache()
2044 disconnect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
2048 #include "clipitem.moc"