1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
29 #include "profilesdialog.h"
31 #include "rotoscoping/rotowidget.h"
39 #include <QStyleOptionGraphicsItem>
40 #include <QGraphicsScene>
43 static int FRAME_SIZE;
45 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, int frame_width, bool generateThumbs) :
46 AbstractClipItem(info, QRectF(), fps),
52 m_startPix(QPixmap()),
57 m_startThumbRequested(false),
58 m_endThumbRequested(false),
63 m_limitedKeyFrames(false)
66 m_effectList = EffectsList(true);
67 FRAME_SIZE = frame_width;
68 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double) itemHeight());
69 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1 + itemOffset());
71 // set speed independant info
72 if (m_speed <= 0 && m_speed > -1)
74 m_speedIndependantInfo = m_info;
75 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
76 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
78 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
79 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
82 m_clipName = m_clip->name();
84 m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
86 m_producer = m_clip->getId();
87 m_clipType = m_clip->clipType();
88 //m_cropStart = info.cropStart;
89 m_maxDuration = m_clip->maxDuration();
91 m_audioThumbReady = m_clip->audioThumbCreated();
92 //setAcceptsHoverEvents(true);
93 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
95 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
96 m_baseColor = QColor(141, 166, 215);
97 if (!m_clip->isPlaceHolder()) {
99 m_startThumbTimer.setSingleShot(true);
100 connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
101 m_endThumbTimer.setSingleShot(true);
102 connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
103 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
104 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
105 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
108 } else if (m_clipType == COLOR) {
109 QString colour = m_clip->getProperty("colour");
110 colour = colour.replace(0, 2, "#");
111 m_baseColor = QColor(colour.left(7));
112 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
113 m_baseColor = QColor(141, 166, 215);
114 if (m_clipType == TEXT) {
115 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
117 //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
118 } else if (m_clipType == AUDIO) {
119 m_baseColor = QColor(141, 215, 166);
120 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
125 ClipItem::~ClipItem()
128 m_endThumbTimer.stop();
129 m_startThumbTimer.stop();
130 if (scene()) scene()->removeItem(this);
131 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
132 //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
133 //disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
138 ClipItem *ClipItem::clone(ItemInfo info) const
140 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe, FRAME_SIZE);
141 if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
142 else if (m_clipType != COLOR) {
143 if (info.cropStart == m_info.cropStart) duplicate->slotSetStartThumb(m_startPix);
144 if (info.cropStart + (info.endPos - info.startPos) == m_info.cropStart + m_info.cropDuration) {
145 duplicate->slotSetEndThumb(m_endPix);
148 //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
149 duplicate->setEffectList(m_effectList);
150 duplicate->setVideoOnly(m_videoOnly);
151 duplicate->setAudioOnly(m_audioOnly);
152 duplicate->setFades(fadeIn(), fadeOut());
153 //duplicate->setSpeed(m_speed);
157 void ClipItem::setEffectList(const EffectsList effectList)
159 m_effectList.clone(effectList);
160 m_effectNames = m_effectList.effectNames().join(" / ");
161 if (!m_effectList.isEmpty()) {
162 for (int i = 0; i < m_effectList.count(); i++) {
163 QDomElement effect = m_effectList.at(i);
164 QString effectId = effect.attribute("id");
165 // check if it is a fade effect
166 QDomNodeList params = effect.elementsByTagName("parameter");
168 for (int j = 0; j < params.count(); j++) {
169 QDomElement e = params.item(j).toElement();
171 if (effectId == "fadein") {
172 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
173 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
174 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
176 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
177 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
178 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
180 } else if (effectId == "fade_from_black") {
181 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
182 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
183 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
185 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
186 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
187 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
189 } else if (effectId == "fadeout") {
190 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
191 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
192 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
194 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
195 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
196 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
198 } else if (effectId == "fade_to_black") {
199 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
200 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
201 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
203 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
204 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
205 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
215 setSelectedEffect(0);
219 const EffectsList ClipItem::effectList() const
224 int ClipItem::selectedEffectIndex() const
226 return m_selectedEffect;
229 void ClipItem::initEffect(QDomElement effect, int diff, int offset)
231 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
234 if (effect.attribute("id") == "freeze" && diff > 0) {
235 EffectsList::setParameter(effect, "frame", QString::number(diff));
238 // Init parameter value & keyframes if required
239 QDomNodeList params = effect.elementsByTagName("parameter");
240 for (int i = 0; i < params.count(); i++) {
241 QDomElement e = params.item(i).toElement();
246 // Check if this effect has a variable parameter
247 if (e.attribute("default").contains('%')) {
248 double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
249 e.setAttribute("default", evaluatedValue);
250 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
251 e.setAttribute("value", evaluatedValue);
255 if (effect.attribute("id") == "crop") {
256 // default use_profile to 1 for clips with proxies to avoid problems when rendering
257 if (e.attribute("name") == "use_profile" && !(m_clip->getProperty("proxy").isEmpty() || m_clip->getProperty("proxy") == "-"))
258 e.setAttribute("value", "1");
261 if (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") {
262 if (e.attribute("keyframes").isEmpty()) {
263 // Effect has a keyframe type parameter, we need to set the values
264 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + e.attribute("default"));
266 else if (offset != 0) {
267 // adjust keyframes to this clip
268 QString adjusted = adjustKeyframes(e.attribute("keyframes"), offset - cropStart().frames(m_fps));
269 e.setAttribute("keyframes", adjusted);
273 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
274 // Effects with a geometry parameter need to sync in / out with parent clip
275 effect.setAttribute("in", QString::number(cropStart().frames(m_fps)));
276 effect.setAttribute("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
277 effect.setAttribute("_sync_in_out", "1");
280 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
281 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
282 int end = (cropDuration() + cropStart()).frames(m_fps) - 1;
284 if (effect.attribute("id") == "fadeout") {
285 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
286 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
287 if (effectDuration > cropDuration().frames(m_fps)) {
288 effectDuration = cropDuration().frames(m_fps) / 2;
290 start -= effectDuration;
292 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
293 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
295 } else if (effect.attribute("id") == "fade_to_black") {
296 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
297 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
298 if (effectDuration > cropDuration().frames(m_fps)) {
299 effectDuration = cropDuration().frames(m_fps) / 2;
301 start -= effectDuration;
303 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
304 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
307 EffectsList::setParameter(effect, "in", QString::number(start));
308 EffectsList::setParameter(effect, "out", QString::number(end));
309 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
310 int start = cropStart().frames(m_fps);
312 if (effect.attribute("id") == "fadein") {
313 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
314 int effectDuration = EffectsList::parameter(effect, "out").toInt();
315 if (offset != 0) effectDuration -= offset;
316 if (effectDuration > cropDuration().frames(m_fps)) {
317 effectDuration = cropDuration().frames(m_fps) / 2;
319 end += effectDuration;
321 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt() - offset;
322 } else if (effect.attribute("id") == "fade_from_black") {
323 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
324 int effectDuration = EffectsList::parameter(effect, "out").toInt();
325 if (offset != 0) effectDuration -= offset;
326 if (effectDuration > cropDuration().frames(m_fps)) {
327 effectDuration = cropDuration().frames(m_fps) / 2;
329 end += effectDuration;
331 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt() - offset;
333 EffectsList::setParameter(effect, "in", QString::number(start));
334 EffectsList::setParameter(effect, "out", QString::number(end));
339 const QString ClipItem::adjustKeyframes(QString keyframes, int offset)
343 const QStringList list = keyframes.split(';', QString::SkipEmptyParts);
344 foreach(const QString &keyframe, list) {
345 int pos = keyframe.section(':', 0, 0).toInt() - offset;
346 QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1);
347 result.append(newKey);
349 return result.join(";");
352 bool ClipItem::checkKeyFrames()
354 bool clipEffectsModified = false;
356 // go through all effects this clip has
357 for (int ix = 0; ix < m_effectList.count(); ++ix) {
358 QStringList keyframeParams = keyframes(ix);
359 QStringList newKeyFrameParams;
360 bool effModified = false;
362 // go through all params which have keyframes
363 foreach(const QString &kfr, keyframeParams) {
364 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
365 QStringList newKeyFrames;
366 bool cutKeyFrame = false;
367 bool modified = false;
369 double lastValue = -1;
370 int start = cropStart().frames(m_fps);
371 int end = (cropStart() + cropDuration()).frames(m_fps);
373 // go through all keyframes for one param
374 foreach(const QString &str, keyframes) {
375 int pos = str.section(':', 0, 0).toInt();
376 double val = locale.toDouble(str.section(':', 1, 1));
377 if (pos - start < 0) {
378 // a keyframe is defined before the start of the clip
380 } else if (cutKeyFrame) {
381 // create new keyframe at clip start, calculate interpolated value
383 int diff = pos - lastPos;
384 double ratio = (double)(start - lastPos) / diff;
385 double newValue = lastValue + (val - lastValue) * ratio;
386 newKeyFrames.append(QString::number(start) + ':' + locale.toString(newValue));
393 // create new keyframe at clip end, calculate interpolated value
394 int diff = pos - lastPos;
396 double ratio = (double)(end - lastPos) / diff;
397 double newValue = lastValue + (val - lastValue) * ratio;
398 newKeyFrames.append(QString::number(end) + ':' + locale.toString(newValue));
403 newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
410 newKeyFrameParams.append(newKeyFrames.join(";"));
417 setKeyframes(ix, newKeyFrameParams);
418 clipEffectsModified = true;
421 return clipEffectsModified;
424 void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
426 QDomElement effect = m_effectList.at(ix);
427 if (effect.attribute("disable") == "1") return;
429 QDomNodeList params = effect.elementsByTagName("parameter");
430 int keyframeParams = 0;
431 for (int i = 0; i < params.count(); i++) {
432 QDomElement e = params.item(i).toElement();
433 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
434 e.setAttribute("keyframes", keyframes.at(keyframeParams));
435 if (ix == m_selectedEffect && keyframeParams == 0) {
438 double max = locale.toDouble(e.attribute("max"));
439 double min = locale.toDouble(e.attribute("min"));
440 m_keyframeFactor = 100.0 / (max - min);
441 m_keyframeOffset = min;
442 m_keyframeDefault = locale.toDouble(e.attribute("default"));
443 m_selectedKeyframe = 0;
445 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
446 foreach(const QString &str, keyframes) {
447 int pos = str.section(':', 0, 0).toInt();
448 double val = locale.toDouble(str.section(':', 1, 1));
449 m_keyframes[pos] = val;
451 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
452 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
461 void ClipItem::setSelectedEffect(const int ix)
463 m_selectedEffect = ix;
465 QDomElement effect = effectAtIndex(m_selectedEffect);
466 if (!effect.isNull() && effect.attribute("disable") != "1") {
467 QDomNodeList params = effect.elementsByTagName("parameter");
468 for (int i = 0; i < params.count(); i++) {
469 QDomElement e = params.item(i).toElement();
470 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
472 m_limitedKeyFrames = e.attribute("type") == "keyframe";
474 double max = locale.toDouble(e.attribute("max"));
475 double min = locale.toDouble(e.attribute("min"));
476 m_keyframeFactor = 100.0 / (max - min);
477 m_keyframeOffset = min;
478 m_keyframeDefault = locale.toDouble(e.attribute("default"));
479 m_selectedKeyframe = 0;
482 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
483 foreach(const QString &str, keyframes) {
484 int pos = str.section(':', 0, 0).toInt();
485 double val = locale.toDouble(str.section(':', 1, 1));
486 m_keyframes[pos] = val;
488 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end())
489 m_editedKeyframe = -1;
496 if (!m_keyframes.isEmpty()) {
502 QStringList ClipItem::keyframes(const int index)
505 QDomElement effect = m_effectList.at(index);
506 QDomNodeList params = effect.elementsByTagName("parameter");
508 for (int i = 0; i < params.count(); i++) {
509 QDomElement e = params.item(i).toElement();
510 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe"))
511 result.append(e.attribute("keyframes"));
516 void ClipItem::updateKeyframeEffect()
518 // regenerate xml parameter from the clip keyframes
519 QDomElement effect = getEffectAtIndex(m_selectedEffect);
520 if (effect.attribute("disable") == "1") return;
521 QDomNodeList params = effect.elementsByTagName("parameter");
522 QDomElement e = params.item(m_visibleParam).toElement();
526 if (m_keyframes.count() > 0) {
527 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
528 while (i != m_keyframes.constEnd()) {
529 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
533 // Effect has a keyframe type parameter, we need to set the values
534 e.setAttribute("keyframes", keyframes);
538 QDomElement ClipItem::selectedEffect()
540 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
541 return effectAtIndex(m_selectedEffect);
544 void ClipItem::resetThumbs(bool clearExistingThumbs)
546 if (clearExistingThumbs) {
547 m_startPix = QPixmap();
548 m_endPix = QPixmap();
549 m_audioThumbCachePic.clear();
555 void ClipItem::refreshClip(bool checkDuration, bool forceResetThumbs)
557 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
558 m_maxDuration = m_clip->maxDuration();
559 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
560 if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
561 // Clip duration changed, make sure to stay in correct range
562 if (m_info.cropStart > m_maxDuration) {
563 m_info.cropStart = GenTime();
564 m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
566 m_info.cropDuration = m_maxDuration;
568 updateRectGeometry();
572 if (m_clipType == COLOR) {
573 QString colour = m_clip->getProperty("colour");
574 colour = colour.replace(0, 2, "#");
575 m_baseColor = QColor(colour.left(7));
577 } else resetThumbs(forceResetThumbs);
580 void ClipItem::slotFetchThumbs()
582 if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
583 if (m_clipType == IMAGE) {
584 if (m_startPix.isNull()) {
585 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
591 if (m_clipType == TEXT) {
592 if (m_startPix.isNull()) slotGetStartThumb();
597 if (m_startPix.isNull()) {
598 m_startThumbRequested = true;
599 frames.append((int)m_speedIndependantInfo.cropStart.frames(m_fps));
602 if (m_endPix.isNull()) {
603 m_endThumbRequested = true;
604 frames.append((int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
607 if (!frames.isEmpty()) m_clip->slotExtractImage(frames);
610 void ClipItem::stopThumbs()
612 // Clip is about to be deleted, make sure we don't request thumbnails
613 disconnect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
614 disconnect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
617 void ClipItem::slotGetStartThumb()
619 m_startThumbRequested = true;
620 m_clip->slotExtractImage(QList<int>() << (int)m_speedIndependantInfo.cropStart.frames(m_fps));
623 void ClipItem::slotGetEndThumb()
625 m_endThumbRequested = true;
626 m_clip->slotExtractImage(QList<int>() << (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
630 void ClipItem::slotSetStartThumb(QImage img)
632 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
633 QPixmap pix = QPixmap::fromImage(img);
635 QRectF r = sceneBoundingRect();
636 r.setRight(pix.width() + 2);
641 void ClipItem::slotSetEndThumb(QImage img)
643 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
644 QPixmap pix = QPixmap::fromImage(img);
646 QRectF r = sceneBoundingRect();
647 r.setLeft(r.right() - pix.width() - 2);
652 void ClipItem::slotThumbReady(int frame, QImage img)
654 if (scene() == NULL) return;
655 QRectF r = boundingRect();
656 QPixmap pix = QPixmap::fromImage(img);
657 double width = pix.width() / projectScene()->scale().x();
658 if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
660 m_startThumbRequested = false;
661 update(r.left(), r.top(), width, pix.height());
662 if (m_clipType == IMAGE || m_clipType == TEXT) {
663 update(r.right() - width, r.top(), width, pix.height());
665 } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
667 m_endThumbRequested = false;
668 update(r.right() - width, r.top(), width, pix.height());
672 void ClipItem::slotSetStartThumb(const QPixmap pix)
677 void ClipItem::slotSetEndThumb(const QPixmap pix)
682 QPixmap ClipItem::startThumb() const
687 QPixmap ClipItem::endThumb() const
692 void ClipItem::slotGotAudioData()
694 m_audioThumbReady = true;
695 if (m_clipType == AV && !isAudioOnly()) {
696 QRectF r = boundingRect();
697 r.setTop(r.top() + r.height() / 2 - 1);
702 int ClipItem::type() const
707 DocClipBase *ClipItem::baseClip() const
712 QDomElement ClipItem::xml() const
717 QDomElement ClipItem::itemXml() const
719 QDomElement xml = m_clip->toXML();
720 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
721 if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
722 if (m_audioOnly) xml.setAttribute("audio_only", 1);
723 else if (m_videoOnly) xml.setAttribute("video_only", 1);
727 int ClipItem::clipType() const
732 QString ClipItem::clipName() const
737 void ClipItem::setClipName(const QString &name)
742 const QString ClipItem::clipProducer() const
747 void ClipItem::flashClip()
749 if (m_timeLine == 0) {
750 m_timeLine = new QTimeLine(750, this);
751 m_timeLine->setUpdateInterval(80);
752 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
753 m_timeLine->setFrameRange(0, 100);
754 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
756 //m_timeLine->start();
759 void ClipItem::animate(qreal /*value*/)
761 QRectF r = boundingRect();
767 void ClipItem::paint(QPainter *painter,
768 const QStyleOptionGraphicsItem *option,
771 QPalette palette = scene()->palette();
776 if (parentItem()) paintColor = QColor(255, 248, 149);
777 else paintColor = m_baseColor;
778 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
779 textColor = palette.highlightedText().color();
780 textBgColor = palette.highlight().color();
781 paintColor = paintColor.darker();
782 framePen.setColor(textBgColor);
785 textColor = palette.text().color();
786 textBgColor = palette.window().color();
787 textBgColor.setAlpha(200);
788 framePen.setColor(paintColor.darker());
790 const QRectF exposed = option->exposedRect;
791 const QRectF mappedExposed = painter->worldTransform().mapRect(exposed);
792 const QRectF mapped = painter->worldTransform().mapRect(rect());
793 painter->setWorldMatrixEnabled(false);
795 p.addRect(mappedExposed);
797 q.addRoundedRect(mapped.adjusted(0, 0, -0.5, 0), 3, 3);
798 painter->setClipPath(p.intersected(q));
799 painter->setPen(Qt::NoPen);
800 painter->fillRect(mappedExposed, paintColor);
801 painter->setPen(paintColor.darker());
803 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
804 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
805 const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
806 painter->drawPixmap(top, m_startPix);
807 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
808 painter->drawLine(l2);
809 } else if (!m_endPix.isNull()) {
810 const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
811 painter->drawPixmap(top, m_endPix);
812 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
813 painter->drawLine(l2);
815 if (!m_startPix.isNull()) {
816 painter->drawPixmap(mapped.topLeft(), m_startPix);
817 QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
818 painter->drawLine(l2);
821 // if we are in full zoom, paint thumbnail for every frame
822 if (m_clip->thumbProducer() && clipType() != COLOR && clipType() != AUDIO && !m_audioOnly && painter->worldTransform().m11() == FRAME_SIZE) {
823 int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
824 int left = qMax((int) m_info.cropStart.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x() - offset);
825 int right = qMin((int)(m_info.cropStart + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x() - offset);
826 QPointF startPos = mapped.topLeft();
827 int startOffset = m_info.cropStart.frames(m_fps);
828 if (clipType() == IMAGE || clipType() == TEXT) {
829 for (int i = left; i <= right; i++) {
830 painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
834 #if KDE_IS_VERSION(4,5,0)
835 if (m_clip && m_clip->thumbProducer()) {
836 QString path = m_clip->fileURL().path() + '_';
839 pen.setStyle(Qt::DotLine);
841 for (int i = left; i <= right; i++) {
842 img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
843 QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
844 if (img.isNull()) missing << i;
845 else painter->drawImage(xpos, img);
846 painter->drawLine(xpos, xpos + QPointF(0, mapped.height()));
848 if (!missing.isEmpty()) {
849 m_clip->thumbProducer()->queryIntraThumbs(missing);
850 connect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
858 // draw audio thumbnails
859 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
861 double startpixel = exposed.left();
864 double endpixel = exposed.right();
867 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
869 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
871 if (m_clipType == AV && !isAudioOnly()) {
873 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
874 } else mappedRect = mapped;
876 double scale = painter->worldTransform().m11();
878 if (isEnabled() && m_clip) channels = m_clip->getProperty("channels").toInt();
879 if (scale != m_framePixelWidth)
880 m_audioThumbCachePic.clear();
881 double cropLeft = m_info.cropStart.frames(m_fps);
882 const int clipStart = mappedRect.x();
883 const int mappedStartPixel = painter->worldTransform().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
884 const int mappedEndPixel = painter->worldTransform().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
885 cropLeft = cropLeft * scale;
888 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
891 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
892 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
893 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
897 // only paint details if clip is big enough
898 if (mapped.width() > 20) {
900 // Draw effects names
901 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
902 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
903 QColor bColor = palette.window().color();
904 QColor tColor = palette.text().color();
905 tColor.setAlpha(220);
906 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
907 qreal value = m_timeLine->currentValue();
908 txtBounding.setWidth(txtBounding.width() * value);
909 bColor.setAlpha(100 + 50 * value);
912 painter->setBrush(bColor);
913 painter->setPen(Qt::NoPen);
914 painter->drawRoundedRect(txtBounding.adjusted(-1, -2, 4, -1), 3, 3);
915 painter->setPen(tColor);
916 painter->drawText(txtBounding.adjusted(2, 0, 1, -1), Qt::AlignCenter, m_effectNames);
920 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignRight | Qt::AlignTop, m_clipName + ' ').adjusted(0, -1, 0, -1);
921 painter->setPen(Qt::NoPen);
922 if (m_isMainSelectedClip) {
923 framePen.setColor(Qt::red);
924 textBgColor = Qt::red;
926 painter->fillRect(txtBounding2.adjusted(-3, 0, 0, 0), textBgColor);
927 painter->setBrush(QBrush(Qt::NoBrush));
928 painter->setPen(textColor);
930 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
931 } else if (m_audioOnly) {
932 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
934 painter->drawText(txtBounding2, Qt::AlignLeft, m_clipName);
938 if (isEnabled() && m_clip) {
939 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
940 QList < CommentedTime >::Iterator it = markers.begin();
943 QBrush markerBrush(QColor(120, 120, 0, 140));
944 QPen pen = painter->pen();
946 for (; it != markers.end(); ++it) {
947 pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
948 if (pos > GenTime()) {
949 if (pos > cropDuration()) break;
950 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
951 QLineF l2 = painter->worldTransform().map(l);
952 pen.setColor(CommentedTime::markerColor((*it).markerType()));
953 pen.setStyle(Qt::DotLine);
954 painter->setPen(pen);
955 painter->drawLine(l2);
956 if (KdenliveSettings::showmarkers()) {
957 framepos = rect().x() + pos.frames(m_fps);
958 const QRectF r1(framepos + 0.04, rect().height()/3, rect().width() - framepos - 2, rect().height() / 2);
959 const QRectF r2 = painter->worldTransform().mapRect(r1);
960 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
961 painter->setBrush(markerBrush);
962 pen.setStyle(Qt::SolidLine);
963 painter->setPen(pen);
964 painter->drawRect(txtBounding3);
965 painter->setBrush(Qt::NoBrush);
966 painter->setPen(Qt::white);
967 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
969 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
974 // draw start / end fades
977 fades = QBrush(QColor(200, 50, 50, 150));
978 } else fades = QBrush(QColor(200, 200, 200, 200));
980 if (m_startFade != 0) {
981 QPainterPath fadeInPath;
982 fadeInPath.moveTo(0, 0);
983 fadeInPath.lineTo(0, rect().height());
984 fadeInPath.lineTo(m_startFade, 0);
985 fadeInPath.closeSubpath();
986 QPainterPath f1 = painter->worldTransform().map(fadeInPath);
987 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
988 /*if (isSelected()) {
989 QLineF l(m_startFade * scale, 0, 0, itemHeight);
990 painter->drawLine(l);
993 if (m_endFade != 0) {
994 QPainterPath fadeOutPath;
995 fadeOutPath.moveTo(rect().width(), 0);
996 fadeOutPath.lineTo(rect().width(), rect().height());
997 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
998 fadeOutPath.closeSubpath();
999 QPainterPath f1 = painter->worldTransform().map(fadeOutPath);
1000 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
1001 /*if (isSelected()) {
1002 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
1003 painter->drawLine(l);
1008 painter->setPen(QPen(Qt::lightGray));
1009 // draw effect or transition keyframes
1010 drawKeyFrames(painter, m_limitedKeyFrames);
1014 // expand clip rect to allow correct painting of clip border
1015 painter->setClipping(false);
1016 painter->setRenderHint(QPainter::Antialiasing, true);
1017 framePen.setWidthF(1.5);
1018 painter->setPen(framePen);
1019 painter->drawRoundedRect(mapped.adjusted(0, 0, -0.5, -0.5), 3, 3);
1023 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
1025 if (isItemLocked()) return NONE;
1026 const double scale = projectScene()->scale().x();
1027 double maximumOffset = 6 / scale;
1028 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1029 int kf = mouseOverKeyFrames(pos, maximumOffset);
1031 m_editedKeyframe = kf;
1035 QRectF rect = sceneBoundingRect();
1036 int addtransitionOffset = 10;
1037 // Don't allow add transition if track height is very small. No transitions for audio only clips
1038 if (rect.height() < 30 || isAudioOnly() || m_clipType == AUDIO) addtransitionOffset = 0;
1040 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1042 } else if ((pos.x() <= rect.x() + rect.width() / 2) && pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
1044 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1046 } else if ((pos.x() >= rect.x() + rect.width() / 2) && (rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
1048 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1049 return TRANSITIONSTART;
1050 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1051 return TRANSITIONEND;
1057 int ClipItem::itemHeight()
1059 return KdenliveSettings::trackheight() - 2;
1062 void ClipItem::resetFrameWidth(int width)
1068 QList <GenTime> ClipItem::snapMarkers() const
1070 QList < GenTime > snaps;
1071 if (!m_clip) return snaps;
1072 QList < GenTime > markers = m_clip->snapMarkers();
1075 for (int i = 0; i < markers.size(); i++) {
1076 pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1077 if (pos > GenTime()) {
1078 if (pos > cropDuration()) break;
1079 else snaps.append(pos + startPos());
1085 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
1087 QList < CommentedTime > snaps;
1088 if (!m_clip) return snaps;
1089 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
1092 for (int i = 0; i < markers.size(); i++) {
1093 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1094 if (pos > GenTime()) {
1095 if (pos > cropDuration()) break;
1096 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment(), markers.at(i).markerType()));
1102 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
1104 QRectF re = sceneBoundingRect();
1105 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
1107 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
1108 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
1110 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
1111 //kDebug() << "creating " << startCache;
1112 //if (framePixelWidth!=pixelForOneFrame ||
1113 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
1115 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
1116 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
1117 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
1119 bool fullAreaDraw = pixelForOneFrame < 10;
1120 QMap<int, QPainterPath > positiveChannelPaths;
1121 QMap<int, QPainterPath > negativeChannelPaths;
1122 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
1124 audiopen.setWidth(0);
1125 pixpainter.setPen(audiopen);
1126 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
1127 //pixpainter.drawLine(0,0,100,re.height());
1128 // Bail out, if caller provided invalid data
1129 if (channels <= 0) {
1130 kWarning() << "Unable to draw image with " << channels << "number of channels";
1134 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
1136 for (int i = 0; i < channels; i++) {
1138 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1139 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
1142 for (int samples = 0; samples <= 100; samples++) {
1143 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
1144 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
1145 if (frame < 0 || sample < 0 || sample > 19)
1147 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameCache[(int)frame];
1149 for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
1151 int y = channelHeight * channel + channelHeight / 2;
1152 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
1154 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
1155 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
1157 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
1158 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
1161 for (int channel = 0; channel < channels ; channel++)
1162 if (fullAreaDraw && samples == 100) {
1163 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1164 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1165 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1166 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1170 pixpainter.setPen(QPen(QColor(0, 0, 0)));
1171 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
1173 for (int i = 0; i < channels; i++) {
1175 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
1176 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
1178 pixpainter.drawPath(positiveChannelPaths[i]);
1181 //audioThumbWasDrawn=true;
1182 m_framePixelWidth = pixelForOneFrame;
1187 int ClipItem::fadeIn() const
1192 int ClipItem::fadeOut() const
1198 void ClipItem::setFadeIn(int pos)
1200 if (pos == m_startFade) return;
1201 int oldIn = m_startFade;
1202 m_startFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1203 QRectF rect = boundingRect();
1204 update(rect.x(), rect.y(), qMax(oldIn, m_startFade), rect.height());
1207 void ClipItem::setFadeOut(int pos)
1209 if (pos == m_endFade) return;
1210 int oldOut = m_endFade;
1211 m_endFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1212 QRectF rect = boundingRect();
1213 update(rect.x() + rect.width() - qMax(oldOut, m_endFade), rect.y(), qMax(oldOut, m_endFade), rect.height());
1217 void ClipItem::setFades(int in, int out)
1225 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1227 //if (e->pos().x() < 20) m_hover = true;
1229 if (isItemLocked()) return;
1231 QRectF r = boundingRect();
1232 double width = 35 / projectScene()->scale().x();
1233 double height = r.height() / 2;
1234 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1235 update(r.x(), r.y() + height, width, height);
1236 update(r.right() - width, r.y() + height, width, height);
1240 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1242 if (isItemLocked()) return;
1244 QRectF r = boundingRect();
1245 double width = 35 / projectScene()->scale().x();
1246 double height = r.height() / 2;
1247 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1248 update(r.x(), r.y() + height, width, height);
1249 update(r.right() - width, r.y() + height, width, height);
1253 void ClipItem::resizeStart(int posx, bool /*size*/, bool emitChange)
1255 bool sizeLimit = false;
1256 if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
1257 const int min = (startPos() - cropStart()).frames(m_fps);
1258 if (posx < min) posx = min;
1262 if (posx == startPos().frames(m_fps)) return;
1263 const int previous = cropStart().frames(m_fps);
1264 AbstractClipItem::resizeStart(posx, sizeLimit);
1266 // set speed independant info
1267 m_speedIndependantInfo = m_info;
1268 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1269 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1271 if ((int) cropStart().frames(m_fps) != previous) {
1272 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1273 m_startThumbTimer.start(150);
1276 if (emitChange) slotUpdateRange();
1279 void ClipItem::slotUpdateRange()
1281 if (m_isMainSelectedClip) emit updateRange();
1284 void ClipItem::resizeEnd(int posx, bool emitChange)
1286 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1287 if (posx > max && maxDuration() != GenTime()) posx = max;
1288 if (posx == endPos().frames(m_fps)) return;
1289 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1290 const int previous = cropDuration().frames(m_fps);
1291 AbstractClipItem::resizeEnd(posx);
1293 // set speed independant info
1294 m_speedIndependantInfo = m_info;
1295 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1296 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1298 if ((int) cropDuration().frames(m_fps) != previous) {
1299 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1300 m_endThumbTimer.start(150);
1303 if (emitChange) slotUpdateRange();
1307 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1309 if (change == QGraphicsItem::ItemSelectedChange) {
1310 if (value.toBool()) setZValue(10);
1313 if (change == ItemPositionChange && scene()) {
1314 // calculate new position.
1315 //if (parentItem()) return pos();
1316 QPointF newPos = value.toPointF();
1317 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1318 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1319 xpos = qMax(xpos, 0);
1321 // Warning: newPos gives a position relative to the click event, so hack to get absolute pos
1322 int yOffset = property("y_absolute").toInt() + newPos.y();
1323 int newTrack = yOffset / KdenliveSettings::trackheight();
1324 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1325 newTrack = qMax(newTrack, 0);
1326 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1327 // Only one clip is moving
1328 QRectF sceneShape = rect();
1329 sceneShape.translate(newPos);
1330 QList<QGraphicsItem*> items;
1331 if (projectScene()->editMode() == NORMALEDIT)
1332 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1333 items.removeAll(this);
1334 bool forwardMove = newPos.x() > pos().x();
1336 if (!items.isEmpty()) {
1337 for (int i = 0; i < items.count(); i++) {
1338 if (!items.at(i)->isEnabled()) continue;
1339 if (items.at(i)->type() == type()) {
1341 QPointF otherPos = items.at(i)->pos();
1342 if ((int) otherPos.y() != (int) pos().y()) {
1346 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1348 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1353 sceneShape.translate(QPointF(-offset, 0));
1354 newPos.setX(newPos.x() - offset);
1356 sceneShape.translate(QPointF(offset, 0));
1357 newPos.setX(newPos.x() + offset);
1359 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1360 subitems.removeAll(this);
1361 for (int j = 0; j < subitems.count(); j++) {
1362 if (!subitems.at(j)->isEnabled()) continue;
1363 if (subitems.at(j)->type() == type()) {
1364 // move was not successful, revert to previous pos
1365 m_info.startPos = GenTime((int) pos().x(), m_fps);
1371 m_info.track = newTrack;
1372 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1378 m_info.track = newTrack;
1379 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1380 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1383 return QGraphicsItem::itemChange(change, value);
1387 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1390 int ClipItem::effectsCounter()
1392 return effectsCount() + 1;
1395 int ClipItem::effectsCount()
1397 return m_effectList.count();
1400 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1402 return m_effectList.hasEffect(tag, id);
1405 QStringList ClipItem::effectNames()
1407 return m_effectList.effectNames();
1410 QDomElement ClipItem::effect(int ix) const
1412 if (ix >= m_effectList.count() || ix < 0) return QDomElement();
1413 return m_effectList.at(ix).cloneNode().toElement();
1416 QDomElement ClipItem::effectAtIndex(int ix) const
1418 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1419 return m_effectList.itemFromIndex(ix).cloneNode().toElement();
1422 QDomElement ClipItem::getEffectAtIndex(int ix) const
1424 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1425 return m_effectList.itemFromIndex(ix);
1428 void ClipItem::updateEffect(QDomElement effect)
1430 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1431 m_effectList.updateEffect(effect);
1432 m_effectNames = m_effectList.effectNames().join(" / ");
1433 QString id = effect.attribute("id");
1434 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1437 QRectF r = boundingRect();
1443 void ClipItem::enableEffects(QList <int> indexes, bool disable)
1445 m_effectList.enableEffects(indexes, disable);
1448 bool ClipItem::moveEffect(QDomElement effect, int ix)
1450 if (ix <= 0 || ix > (m_effectList.count()) || effect.isNull()) {
1451 kDebug() << "Invalid effect index: " << ix;
1454 m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
1455 effect.setAttribute("kdenlive_ix", ix);
1456 m_effectList.insert(effect);
1457 m_effectNames = m_effectList.effectNames().join(" / ");
1458 QString id = effect.attribute("id");
1459 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1462 QRectF r = boundingRect();
1469 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
1471 bool needRepaint = false;
1474 QDomElement insertedEffect;
1475 if (!effect.hasAttribute("kdenlive_ix")) {
1476 // effect dropped from effect list
1477 ix = effectsCounter();
1478 } else ix = effect.attribute("kdenlive_ix").toInt();
1479 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1481 insertedEffect = m_effectList.insert(effect);
1482 } else insertedEffect = m_effectList.append(effect);
1484 // Update index to the real one
1485 effect.setAttribute("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1489 if (effect.attribute("tag") == "affine") {
1490 // special case: the affine effect needs in / out points
1491 effectIn = effect.attribute("in").toInt();
1492 effectOut = effect.attribute("out").toInt();
1495 effectIn = EffectsList::parameter(effect, "in").toInt();
1496 effectOut = EffectsList::parameter(effect, "out").toInt();
1499 EffectsParameterList parameters;
1500 parameters.addParam("tag", insertedEffect.attribute("tag"));
1501 parameters.addParam("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1502 if (insertedEffect.hasAttribute("src")) parameters.addParam("src", insertedEffect.attribute("src"));
1503 if (insertedEffect.hasAttribute("disable")) parameters.addParam("disable", insertedEffect.attribute("disable"));
1505 QString effectId = insertedEffect.attribute("id");
1506 if (effectId.isEmpty()) effectId = insertedEffect.attribute("tag");
1507 parameters.addParam("id", effectId);
1509 QDomNodeList params = insertedEffect.elementsByTagName("parameter");
1511 bool needInOutSync = false;
1513 // check if it is a fade effect
1514 if (effectId == "fadein") {
1516 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1517 fade = effectOut - effectIn;
1519 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1520 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1521 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1523 } else if (effectId == "fade_from_black") {
1524 kDebug()<<"// FOUND FTB:"<<effectOut<<" - "<<effectIn;
1526 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1527 fade = effectOut - effectIn;
1529 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1530 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1531 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1533 } else if (effectId == "fadeout") {
1535 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1536 fade = effectIn - effectOut;
1538 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1539 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1540 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1542 } else if (effectId == "fade_to_black") {
1544 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1545 fade = effectIn - effectOut;
1547 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1548 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1549 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1553 for (int i = 0; i < params.count(); i++) {
1554 QDomElement e = params.item(i).toElement();
1556 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
1557 // Effects with a geometry parameter need to sync in / out with parent clip
1558 needInOutSync = true;
1560 if (e.attribute("type") == "simplekeyframe") {
1561 QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1562 double factor = locale.toDouble(e.attribute("factor", "1"));
1563 double offset = e.attribute("offset", "0").toDouble();
1564 if (factor != 1 || offset != 0) {
1565 for (int j = 0; j < values.count(); j++) {
1566 QString pos = values.at(j).section(':', 0, 0);
1567 double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor;
1568 values[j] = pos + '=' + locale.toString(val);
1571 parameters.addParam(e.attribute("name"), values.join(";"));
1572 /*parameters.addParam("max", e.attribute("max"));
1573 parameters.addParam("min", e.attribute("min"));
1574 parameters.addParam("factor", );*/
1575 } else if (e.attribute("type") == "keyframe") {
1576 parameters.addParam("keyframes", e.attribute("keyframes"));
1577 parameters.addParam("max", e.attribute("max"));
1578 parameters.addParam("min", e.attribute("min"));
1579 parameters.addParam("factor", e.attribute("factor", "1"));
1580 parameters.addParam("offset", e.attribute("offset", "0"));
1581 parameters.addParam("starttag", e.attribute("starttag", "start"));
1582 parameters.addParam("endtag", e.attribute("endtag", "end"));
1583 } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") {
1584 parameters.addParam(e.attribute("name"), e.attribute("value"));
1588 if (e.attribute("factor").contains('%')) {
1589 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1591 fact = locale.toDouble(e.attribute("factor", "1"));
1593 double offset = e.attribute("offset", "0").toDouble();
1594 parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact));
1598 if (needInOutSync) {
1599 parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
1600 parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
1601 parameters.addParam("_sync_in_out", "1");
1603 m_effectNames = m_effectList.effectNames().join(" / ");
1604 if (fade > 0) m_startFade = fade;
1605 else if (fade < 0) m_endFade = -fade;
1607 if (m_selectedEffect == -1) {
1608 setSelectedEffect(0);
1609 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1610 if (needRepaint) update(boundingRect());
1614 else { /*if (!needRepaint) */
1615 QRectF r = boundingRect();
1622 void ClipItem::deleteEffect(QString index)
1624 bool needRepaint = false;
1625 int ix = index.toInt();
1627 QDomElement effect = m_effectList.itemFromIndex(ix);
1628 QString effectId = effect.attribute("id");
1629 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1630 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1633 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1634 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1637 } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
1638 m_effectList.removeAt(ix);
1639 m_effectNames = m_effectList.effectNames().join(" / ");
1641 if (m_effectList.isEmpty() || m_selectedEffect == ix) {
1642 // Current effect was removed
1643 if (ix > m_effectList.count()) {
1644 setSelectedEffect(m_effectList.count());
1645 } else setSelectedEffect(ix);
1647 if (needRepaint) update(boundingRect());
1649 QRectF r = boundingRect();
1653 //if (!m_effectList.isEmpty()) flashClip();
1656 double ClipItem::speed() const
1661 int ClipItem::strobe() const
1666 void ClipItem::setSpeed(const double speed, const int strobe)
1669 if (m_speed <= 0 && m_speed > -1)
1672 if (m_speed == 1.0) m_clipName = m_clip->name();
1673 else m_clipName = m_clip->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1674 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1675 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1679 GenTime ClipItem::maxDuration() const
1681 return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1684 GenTime ClipItem::speedIndependantCropStart() const
1686 return m_speedIndependantInfo.cropStart;
1689 GenTime ClipItem::speedIndependantCropDuration() const
1691 return m_speedIndependantInfo.cropDuration;
1695 const ItemInfo ClipItem::speedIndependantInfo() const
1697 return m_speedIndependantInfo;
1700 int ClipItem::nextFreeEffectGroupIndex() const
1702 int freeGroupIndex = 0;
1703 for (int i = 0; i < m_effectList.count(); i++) {
1704 QDomElement effect = m_effectList.at(i);
1705 EffectInfo effectInfo;
1706 effectInfo.fromString(effect.attribute("kdenlive_info"));
1707 if (effectInfo.groupIndex >= freeGroupIndex) {
1708 freeGroupIndex = effectInfo.groupIndex + 1;
1711 return freeGroupIndex;
1715 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1717 if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
1718 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
1719 event->acceptProposedAction();
1721 doc.setContent(effects, true);
1722 QDomElement e = doc.documentElement();
1723 if (e.tagName() == "effectgroup") {
1724 // dropped an effect group
1725 QDomNodeList effectlist = e.elementsByTagName("effect");
1726 int freeGroupIndex = nextFreeEffectGroupIndex();
1727 EffectInfo effectInfo;
1728 for (int i = 0; i < effectlist.count(); i++) {
1729 QDomElement effect = effectlist.at(i).toElement();
1730 effectInfo.fromString(effect.attribute("kdenlive_info"));
1731 effectInfo.groupIndex = freeGroupIndex;
1732 effect.setAttribute("kdenlive_info", effectInfo.toString());
1733 effect.removeAttribute("kdenlive_ix");
1736 // single effect dropped
1737 e.removeAttribute("kdenlive_ix");
1739 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1740 if (view) view->slotAddEffect(e, m_info.startPos, track());
1746 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1748 if (isItemLocked()) event->setAccepted(false);
1749 else if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
1750 event->acceptProposedAction();
1751 } else event->setAccepted(false);
1754 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1759 void ClipItem::addTransition(Transition* t)
1761 m_transitionsList.append(t);
1762 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1764 QDomElement e = doc.documentElement();
1765 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1768 void ClipItem::setVideoOnly(bool force)
1770 m_videoOnly = force;
1773 void ClipItem::setAudioOnly(bool force)
1775 m_audioOnly = force;
1776 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1778 if (m_clipType == COLOR) {
1779 QString colour = m_clip->getProperty("colour");
1780 colour = colour.replace(0, 2, "#");
1781 m_baseColor = QColor(colour.left(7));
1782 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1783 else m_baseColor = QColor(141, 166, 215);
1785 m_audioThumbCachePic.clear();
1788 bool ClipItem::isAudioOnly() const
1793 bool ClipItem::isVideoOnly() const
1798 void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
1800 if (effect.attribute("disable") == "1") return;
1802 effect.setAttribute("active_keyframe", pos);
1803 m_editedKeyframe = pos;
1804 QDomNodeList params = effect.elementsByTagName("parameter");
1805 for (int i = 0; i < params.count(); i++) {
1806 QDomElement e = params.item(i).toElement();
1807 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1808 QString kfr = e.attribute("keyframes");
1809 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1812 foreach(const QString &str, keyframes) {
1813 int kpos = str.section(':', 0, 0).toInt();
1814 double newval = locale.toDouble(str.section(':', 1, 1));
1817 } else if (!added) {
1818 if (i == m_visibleParam)
1819 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1821 newkfr.append(QString::number(pos) + ':' + locale.toString(newval));
1822 if (kpos > pos) newkfr.append(str);
1824 } else newkfr.append(str);
1827 if (i == m_visibleParam)
1828 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1830 newkfr.append(QString::number(pos) + ':' + e.attribute("default"));
1832 e.setAttribute("keyframes", newkfr.join(";"));
1837 void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double value)
1839 if (effect.attribute("disable") == "1") return;
1841 effect.setAttribute("active_keyframe", newpos);
1842 QDomNodeList params = effect.elementsByTagName("parameter");
1843 int start = cropStart().frames(m_fps);
1844 int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
1845 for (int i = 0; i < params.count(); i++) {
1846 QDomElement e = params.item(i).toElement();
1847 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1848 QString kfr = e.attribute("keyframes");
1849 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1851 foreach(const QString &str, keyframes) {
1852 if (str.section(':', 0, 0).toInt() != oldpos) {
1854 } else if (newpos != -1) {
1855 newpos = qMax(newpos, start);
1856 newpos = qMin(newpos, end);
1857 if (i == m_visibleParam)
1858 newkfr.append(QString::number(newpos) + ':' + locale.toString(value));
1860 newkfr.append(QString::number(newpos) + ':' + str.section(':', 1, 1));
1863 e.setAttribute("keyframes", newkfr.join(";"));
1867 updateKeyframes(effect);
1871 void ClipItem::updateKeyframes(QDomElement effect)
1873 m_keyframes.clear();
1876 QDomNodeList params = effect.elementsByTagName("parameter");
1877 QDomElement e = params.item(m_visibleParam).toElement();
1878 if (e.attribute("intimeline") != "1") {
1879 setSelectedEffect(m_selectedEffect);
1882 m_limitedKeyFrames = e.attribute("type") == "keyframe";
1883 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1884 foreach(const QString &str, keyframes) {
1885 int pos = str.section(':', 0, 0).toInt();
1886 double val = locale.toDouble(str.section(':', 1, 1));
1887 m_keyframes[pos] = val;
1889 if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
1892 Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
1895 return m_clip->audioProducer(track);
1896 else if (isVideoOnly())
1897 return m_clip->videoProducer(track);
1899 return m_clip->getProducer(trackSpecific ? track : -1);
1902 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
1904 QMap<int, QDomElement> effects;
1905 for (int i = 0; i < m_effectList.count(); i++) {
1906 QDomElement effect = m_effectList.at(i);
1908 if (effect.attribute("id").startsWith("fade")) {
1909 QString id = effect.attribute("id");
1910 int in = EffectsList::parameter(effect, "in").toInt();
1911 int out = EffectsList::parameter(effect, "out").toInt();
1912 int clipEnd = (cropStart() + cropDuration()).frames(m_fps) - 1;
1913 if (id == "fade_from_black" || id == "fadein") {
1914 if (in != cropStart().frames(m_fps)) {
1915 effects[i] = effect.cloneNode().toElement();
1916 int duration = out - in;
1917 in = cropStart().frames(m_fps);
1918 out = in + duration;
1919 EffectsList::setParameter(effect, "in", QString::number(in));
1920 EffectsList::setParameter(effect, "out", QString::number(out));
1922 if (out > clipEnd) {
1923 if (!effects.contains(i))
1924 effects[i] = effect.cloneNode().toElement();
1925 EffectsList::setParameter(effect, "out", QString::number(clipEnd));
1927 if (effects.contains(i))
1928 setFadeIn(out - in);
1930 if (out != clipEnd) {
1931 effects[i] = effect.cloneNode().toElement();
1932 int diff = out - clipEnd;
1933 in = qMax(in - diff, (int) cropStart().frames(m_fps));
1935 EffectsList::setParameter(effect, "in", QString::number(in));
1936 EffectsList::setParameter(effect, "out", QString::number(out));
1938 if (in < cropStart().frames(m_fps)) {
1939 if (!effects.contains(i))
1940 effects[i] = effect.cloneNode().toElement();
1941 EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
1943 if (effects.contains(i))
1944 setFadeOut(out - in);
1947 } else if (effect.attribute("id") == "freeze" && cropStart() != oldInfo.cropStart) {
1948 effects[i] = effect.cloneNode().toElement();
1949 int diff = (oldInfo.cropStart - cropStart()).frames(m_fps);
1950 int frame = EffectsList::parameter(effect, "frame").toInt();
1951 EffectsList::setParameter(effect, "frame", QString::number(frame - diff));
1953 } else if (effect.attribute("id") == "pan_zoom") {
1954 effect.setAttribute("in", cropStart().frames(m_fps));
1955 effect.setAttribute("out", (cropStart() + cropDuration()).frames(m_fps) - 1);
1958 QDomNodeList params = effect.elementsByTagName("parameter");
1959 for (int j = 0; j < params.count(); j++) {
1960 QDomElement param = params.item(j).toElement();
1962 QString type = param.attribute("type");
1963 if (type == "geometry" && !param.hasAttribute("fixed")) {
1964 if (!effects.contains(i))
1965 effects[i] = effect.cloneNode().toElement();
1966 updateGeometryKeyframes(effect, j, width, height, oldInfo);
1967 } else if (type == "simplekeyframe" || type == "keyframe") {
1968 if (!effects.contains(i))
1969 effects[i] = effect.cloneNode().toElement();
1970 updateNormalKeyframes(param, oldInfo);
1972 } else if (type == "roto-spline") {
1973 if (!effects.contains(i))
1974 effects[i] = effect.cloneNode().toElement();
1975 QString value = param.attribute("value");
1976 if (adjustRotoDuration(&value, cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1))
1977 param.setAttribute("value", value);
1985 bool ClipItem::updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo)
1987 int in = cropStart().frames(m_fps);
1988 int out = (cropStart() + cropDuration()).frames(m_fps) - 1;
1989 int oldin = oldInfo.cropStart.frames(m_fps);
1991 bool keyFrameUpdated = false;
1993 const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
1994 QMap <int, double> keyframes;
1995 foreach (QString keyframe, data) {
1996 int keyframepos = keyframe.section(':', 0, 0).toInt();
1997 // if keyframe was at clip start, update it
1998 if (keyframepos == oldin) {
2000 keyFrameUpdated = true;
2002 keyframes[keyframepos] = locale.toDouble(keyframe.section(':', 1, 1));
2006 QMap<int, double>::iterator i = keyframes.end();
2008 double lastValue = 0;
2012 * Take care of resize from start
2014 bool startFound = false;
2015 while (i-- != keyframes.begin()) {
2016 if (i.key() < in && !startFound) {
2019 keyframes[in] = i.value();
2021 relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
2022 keyframes[in] = i.value() + (lastValue - i.value()) * relPos;
2026 lastValue = i.value();
2028 i = keyframes.erase(i);
2032 * Take care of resize from end
2034 i = keyframes.begin();
2036 bool endFound = false;
2037 while (i != keyframes.end()) {
2038 if (i.key() > out && !endFound) {
2041 keyframes[out] = i.value();
2043 relPos = (out - lastPos) / (qreal)(i.key() - lastPos + 1);
2044 keyframes[out] = lastValue + (i.value() - lastValue) * relPos;
2048 lastValue = i.value();
2050 i = keyframes.erase(i);
2055 if (startFound || endFound || keyFrameUpdated) {
2057 QMap<int, double>::const_iterator k = keyframes.constBegin();
2058 while (k != keyframes.constEnd()) {
2059 newkfr.append(QString::number(k.key()) + ':' + QString::number(qRound(k.value())) + ';');
2062 parameter.setAttribute("keyframes", newkfr);
2069 void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
2071 QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
2072 int offset = oldInfo.cropStart.frames(m_fps);
2073 QString data = param.attribute("value");
2075 QStringList kfrs = data.split(';');
2077 foreach (const QString &keyframe, kfrs) {
2078 if (keyframe.contains('=')) {
2079 int pos = keyframe.section('=', 0, 0).toInt();
2081 data.append(QString::number(pos) + '=' + keyframe.section('=', 1) + ";");
2083 else data.append(keyframe + ';');
2086 Mlt::Geometry geometry(data.toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
2087 param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
2090 void ClipItem::slotGotThumbsCache()
2092 disconnect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
2097 #include "clipitem.moc"