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, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int, int)));
95 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
96 m_baseColor = QColor(141, 166, 215);
97 if (!m_clip->isPlaceHolder()) {
99 m_startThumbTimer.setSingleShot(true);
100 connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
101 m_endThumbTimer.setSingleShot(true);
102 connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
103 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
104 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
105 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
108 } else if (m_clipType == COLOR) {
109 QString colour = m_clip->getProperty("colour");
110 colour = colour.replace(0, 2, "#");
111 m_baseColor = QColor(colour.left(7));
112 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
113 m_baseColor = QColor(141, 166, 215);
114 if (m_clipType == TEXT) {
115 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
117 //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
118 } else if (m_clipType == AUDIO) {
119 m_baseColor = QColor(141, 215, 166);
120 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
125 ClipItem::~ClipItem()
128 m_endThumbTimer.stop();
129 m_startThumbTimer.stop();
130 if (scene()) scene()->removeItem(this);
131 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
132 //disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
133 //disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
138 ClipItem *ClipItem::clone(ItemInfo info) const
140 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe, FRAME_SIZE);
141 if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
142 else if (m_clipType != COLOR) {
143 if (info.cropStart == m_info.cropStart) duplicate->slotSetStartThumb(m_startPix);
144 if (info.cropStart + (info.endPos - info.startPos) == m_info.cropStart + m_info.cropDuration) {
145 duplicate->slotSetEndThumb(m_endPix);
148 //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
149 duplicate->setEffectList(m_effectList);
150 duplicate->setVideoOnly(m_videoOnly);
151 duplicate->setAudioOnly(m_audioOnly);
152 duplicate->setFades(fadeIn(), fadeOut());
153 //duplicate->setSpeed(m_speed);
157 void ClipItem::setEffectList(const EffectsList effectList)
159 m_effectList.clone(effectList);
160 m_effectNames = m_effectList.effectNames().join(" / ");
161 if (!m_effectList.isEmpty()) {
162 for (int i = 0; i < m_effectList.count(); i++) {
163 QDomElement effect = m_effectList.at(i);
164 QString effectId = effect.attribute("id");
165 // check if it is a fade effect
166 QDomNodeList params = effect.elementsByTagName("parameter");
168 for (int j = 0; j < params.count(); j++) {
169 QDomElement e = params.item(j).toElement();
171 if (effectId == "fadein") {
172 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
173 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
174 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
176 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
177 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
178 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
180 } else if (effectId == "fade_from_black") {
181 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
182 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
183 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
185 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
186 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
187 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
189 } else if (effectId == "fadeout") {
190 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
191 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
192 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
194 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
195 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
196 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
198 } else if (effectId == "fade_to_black") {
199 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
200 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
201 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
203 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
204 if (fadeout.attribute("name") == "out") fade += fadeout.attribute("value").toInt();
205 else if (fadeout.attribute("name") == "in") fade -= fadeout.attribute("value").toInt();
215 setSelectedEffect(0);
219 const EffectsList ClipItem::effectList() const
224 int ClipItem::selectedEffectIndex() const
226 return m_selectedEffect;
229 void ClipItem::initEffect(QDomElement effect, int diff, int offset)
231 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
234 if (effect.attribute("id") == "freeze" && diff > 0) {
235 EffectsList::setParameter(effect, "frame", QString::number(diff));
238 // Init parameter value & keyframes if required
239 QDomNodeList params = effect.elementsByTagName("parameter");
240 for (int i = 0; i < params.count(); i++) {
241 QDomElement e = params.item(i).toElement();
246 // Check if this effect has a variable parameter
247 if (e.attribute("default").contains('%')) {
248 double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
249 e.setAttribute("default", evaluatedValue);
250 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
251 e.setAttribute("value", evaluatedValue);
255 if (effect.attribute("id") == "crop") {
256 // default use_profile to 1 for clips with proxies to avoid problems when rendering
257 if (e.attribute("name") == "use_profile" && !(m_clip->getProperty("proxy").isEmpty() || m_clip->getProperty("proxy") == "-"))
258 e.setAttribute("value", "1");
261 if (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") {
262 if (e.attribute("keyframes").isEmpty()) {
263 // Effect has a keyframe type parameter, we need to set the values
264 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + e.attribute("default"));
266 else if (offset != 0) {
267 // adjust keyframes to this clip
268 QString adjusted = adjustKeyframes(e.attribute("keyframes"), offset - cropStart().frames(m_fps));
269 e.setAttribute("keyframes", adjusted);
273 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
274 // Effects with a geometry parameter need to sync in / out with parent clip
275 effect.setAttribute("in", QString::number(cropStart().frames(m_fps)));
276 effect.setAttribute("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
277 effect.setAttribute("_sync_in_out", "1");
280 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
281 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
282 int end = (cropDuration() + cropStart()).frames(m_fps) - 1;
284 if (effect.attribute("id") == "fadeout") {
285 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
286 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
287 if (effectDuration > cropDuration().frames(m_fps)) {
288 effectDuration = cropDuration().frames(m_fps) / 2;
290 start -= effectDuration;
292 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
293 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
295 } else if (effect.attribute("id") == "fade_to_black") {
296 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
297 int effectDuration = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
298 if (effectDuration > cropDuration().frames(m_fps)) {
299 effectDuration = cropDuration().frames(m_fps) / 2;
301 start -= effectDuration;
303 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
304 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
307 EffectsList::setParameter(effect, "in", QString::number(start));
308 EffectsList::setParameter(effect, "out", QString::number(end));
309 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
310 int start = cropStart().frames(m_fps);
312 if (effect.attribute("id") == "fadein") {
313 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
314 int effectDuration = EffectsList::parameter(effect, "out").toInt();
315 if (offset != 0) effectDuration -= offset;
316 if (effectDuration > cropDuration().frames(m_fps)) {
317 effectDuration = cropDuration().frames(m_fps) / 2;
319 end += effectDuration;
321 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt() - offset;
322 } else if (effect.attribute("id") == "fade_from_black") {
323 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
324 int effectDuration = EffectsList::parameter(effect, "out").toInt();
325 if (offset != 0) effectDuration -= offset;
326 if (effectDuration > cropDuration().frames(m_fps)) {
327 effectDuration = cropDuration().frames(m_fps) / 2;
329 end += effectDuration;
331 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt() - offset;
333 EffectsList::setParameter(effect, "in", QString::number(start));
334 EffectsList::setParameter(effect, "out", QString::number(end));
339 const QString ClipItem::adjustKeyframes(QString keyframes, int offset)
343 const QStringList list = keyframes.split(';', QString::SkipEmptyParts);
344 foreach(const QString &keyframe, list) {
345 int pos = keyframe.section(':', 0, 0).toInt() - offset;
346 QString newKey = QString::number(pos) + ":" + keyframe.section(':', 1);
347 result.append(newKey);
349 return result.join(";");
352 bool ClipItem::checkKeyFrames()
354 bool clipEffectsModified = false;
356 // go through all effects this clip has
357 for (int ix = 0; ix < m_effectList.count(); ++ix) {
358 QStringList keyframeParams = keyframes(ix);
359 QStringList newKeyFrameParams;
360 bool effModified = false;
362 // go through all params which have keyframes
363 foreach(const QString &kfr, keyframeParams) {
364 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
365 QStringList newKeyFrames;
366 bool cutKeyFrame = false;
367 bool modified = false;
369 double lastValue = -1;
370 int start = cropStart().frames(m_fps);
371 int end = (cropStart() + cropDuration()).frames(m_fps);
373 // go through all keyframes for one param
374 foreach(const QString &str, keyframes) {
375 int pos = str.section(':', 0, 0).toInt();
376 double val = locale.toDouble(str.section(':', 1, 1));
377 if (pos - start < 0) {
378 // a keyframe is defined before the start of the clip
380 } else if (cutKeyFrame) {
381 // create new keyframe at clip start, calculate interpolated value
383 int diff = pos - lastPos;
384 double ratio = (double)(start - lastPos) / diff;
385 double newValue = lastValue + (val - lastValue) * ratio;
386 newKeyFrames.append(QString::number(start) + ':' + locale.toString(newValue));
393 // create new keyframe at clip end, calculate interpolated value
394 int diff = pos - lastPos;
396 double ratio = (double)(end - lastPos) / diff;
397 double newValue = lastValue + (val - lastValue) * ratio;
398 newKeyFrames.append(QString::number(end) + ':' + locale.toString(newValue));
403 newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
410 newKeyFrameParams.append(newKeyFrames.join(";"));
417 setKeyframes(ix, newKeyFrameParams);
418 clipEffectsModified = true;
421 return clipEffectsModified;
424 void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
426 QDomElement effect = m_effectList.at(ix);
427 if (effect.attribute("disable") == "1") return;
429 QDomNodeList params = effect.elementsByTagName("parameter");
430 int keyframeParams = 0;
431 for (int i = 0; i < params.count(); i++) {
432 QDomElement e = params.item(i).toElement();
433 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
434 e.setAttribute("keyframes", keyframes.at(keyframeParams));
435 if (ix == m_selectedEffect && keyframeParams == 0) {
438 double max = locale.toDouble(e.attribute("max"));
439 double min = locale.toDouble(e.attribute("min"));
440 m_keyframeFactor = 100.0 / (max - min);
441 m_keyframeOffset = min;
442 m_keyframeDefault = locale.toDouble(e.attribute("default"));
443 m_selectedKeyframe = 0;
445 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
446 foreach(const QString &str, keyframes) {
447 int pos = str.section(':', 0, 0).toInt();
448 double val = locale.toDouble(str.section(':', 1, 1));
449 m_keyframes[pos] = val;
451 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
452 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
461 void ClipItem::setSelectedEffect(const int ix)
463 m_selectedEffect = ix;
465 QDomElement effect = effectAtIndex(m_selectedEffect);
466 if (!effect.isNull() && effect.attribute("disable") != "1") {
467 QDomNodeList params = effect.elementsByTagName("parameter");
468 for (int i = 0; i < params.count(); i++) {
469 QDomElement e = params.item(i).toElement();
470 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
472 m_limitedKeyFrames = e.attribute("type") == "keyframe";
474 double max = locale.toDouble(e.attribute("max"));
475 double min = locale.toDouble(e.attribute("min"));
476 m_keyframeFactor = 100.0 / (max - min);
477 m_keyframeOffset = min;
478 m_keyframeDefault = locale.toDouble(e.attribute("default"));
479 m_selectedKeyframe = 0;
482 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
483 foreach(const QString &str, keyframes) {
484 int pos = str.section(':', 0, 0).toInt();
485 double val = locale.toDouble(str.section(':', 1, 1));
486 m_keyframes[pos] = val;
488 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end())
489 m_editedKeyframe = -1;
496 if (!m_keyframes.isEmpty()) {
502 QStringList ClipItem::keyframes(const int index)
505 QDomElement effect = m_effectList.at(index);
506 QDomNodeList params = effect.elementsByTagName("parameter");
508 for (int i = 0; i < params.count(); i++) {
509 QDomElement e = params.item(i).toElement();
510 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe"))
511 result.append(e.attribute("keyframes"));
516 void ClipItem::updateKeyframeEffect()
518 // regenerate xml parameter from the clip keyframes
519 QDomElement effect = getEffectAtIndex(m_selectedEffect);
520 if (effect.attribute("disable") == "1") return;
521 QDomNodeList params = effect.elementsByTagName("parameter");
522 QDomElement e = params.item(m_visibleParam).toElement();
526 if (m_keyframes.count() > 0) {
527 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
528 while (i != m_keyframes.constEnd()) {
529 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
533 // Effect has a keyframe type parameter, we need to set the values
534 e.setAttribute("keyframes", keyframes);
538 QDomElement ClipItem::selectedEffect()
540 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
541 return effectAtIndex(m_selectedEffect);
544 void ClipItem::resetThumbs(bool clearExistingThumbs)
546 if (clearExistingThumbs) {
547 m_startPix = QPixmap();
548 m_endPix = QPixmap();
549 m_audioThumbCachePic.clear();
555 void ClipItem::refreshClip(bool checkDuration, bool forceResetThumbs)
557 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
558 m_maxDuration = m_clip->maxDuration();
559 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
560 if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
561 // Clip duration changed, make sure to stay in correct range
562 if (m_info.cropStart > m_maxDuration) {
563 m_info.cropStart = GenTime();
564 m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
566 m_info.cropDuration = m_maxDuration;
568 updateRectGeometry();
572 if (m_clipType == COLOR) {
573 QString colour = m_clip->getProperty("colour");
574 colour = colour.replace(0, 2, "#");
575 m_baseColor = QColor(colour.left(7));
577 } else resetThumbs(forceResetThumbs);
580 void ClipItem::slotFetchThumbs()
582 if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
583 if (m_clipType == IMAGE) {
584 if (m_startPix.isNull()) {
585 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
591 if (m_clipType == TEXT) {
592 if (m_startPix.isNull()) slotGetStartThumb();
597 if (m_startPix.isNull()) {
598 m_startThumbRequested = true;
599 frames.append((int)m_speedIndependantInfo.cropStart.frames(m_fps));
602 if (m_endPix.isNull()) {
603 m_endThumbRequested = true;
604 frames.append((int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
607 if (!frames.isEmpty()) m_clip->slotExtractImage(frames);
610 void ClipItem::stopThumbs()
612 // Clip is about to be deleted, make sure we don't request thumbnails
613 disconnect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
614 disconnect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
617 void ClipItem::slotGetStartThumb()
619 m_startThumbRequested = true;
620 m_clip->slotExtractImage(QList<int>() << (int)m_speedIndependantInfo.cropStart.frames(m_fps));
623 void ClipItem::slotGetEndThumb()
625 m_endThumbRequested = true;
626 m_clip->slotExtractImage(QList<int>() << (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
630 void ClipItem::slotSetStartThumb(QImage img)
632 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
633 QPixmap pix = QPixmap::fromImage(img);
635 QRectF r = sceneBoundingRect();
636 r.setRight(pix.width() + 2);
641 void ClipItem::slotSetEndThumb(QImage img)
643 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
644 QPixmap pix = QPixmap::fromImage(img);
646 QRectF r = sceneBoundingRect();
647 r.setLeft(r.right() - pix.width() - 2);
652 void ClipItem::slotThumbReady(int frame, QImage img)
654 if (scene() == NULL) return;
655 QRectF r = boundingRect();
656 QPixmap pix = QPixmap::fromImage(img);
657 double width = pix.width() / projectScene()->scale().x();
658 if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
660 m_startThumbRequested = false;
661 update(r.left(), r.top(), width, pix.height());
662 if (m_clipType == IMAGE || m_clipType == TEXT) {
663 update(r.right() - width, r.top(), width, pix.height());
665 } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
667 m_endThumbRequested = false;
668 update(r.right() - width, r.top(), width, pix.height());
672 void ClipItem::slotSetStartThumb(const QPixmap pix)
677 void ClipItem::slotSetEndThumb(const QPixmap pix)
682 QPixmap ClipItem::startThumb() const
687 QPixmap ClipItem::endThumb() const
692 void ClipItem::slotGotAudioData()
694 m_audioThumbReady = true;
695 if (m_clipType == AV && !isAudioOnly()) {
696 QRectF r = boundingRect();
697 r.setTop(r.top() + r.height() / 2 - 1);
702 int ClipItem::type() const
707 DocClipBase *ClipItem::baseClip() const
712 QDomElement ClipItem::xml() const
717 QDomElement ClipItem::itemXml() const
719 QDomElement xml = m_clip->toXML();
720 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
721 if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
722 if (m_audioOnly) xml.setAttribute("audio_only", 1);
723 else if (m_videoOnly) xml.setAttribute("video_only", 1);
727 int ClipItem::clipType() const
732 QString ClipItem::clipName() const
737 void ClipItem::setClipName(const QString &name)
742 const QString ClipItem::clipProducer() const
747 void ClipItem::flashClip()
749 if (m_timeLine == 0) {
750 m_timeLine = new QTimeLine(750, this);
751 m_timeLine->setUpdateInterval(80);
752 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
753 m_timeLine->setFrameRange(0, 100);
754 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
756 //m_timeLine->start();
759 void ClipItem::animate(qreal /*value*/)
761 QRectF r = boundingRect();
767 void ClipItem::paint(QPainter *painter,
768 const QStyleOptionGraphicsItem *option,
771 QPalette palette = scene()->palette();
776 if (parentItem()) paintColor = QColor(255, 248, 149);
777 else paintColor = m_baseColor;
778 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
779 textColor = palette.highlightedText().color();
780 textBgColor = palette.highlight().color();
781 paintColor = paintColor.darker();
782 framePen.setColor(textBgColor);
785 textColor = palette.text().color();
786 textBgColor = palette.window().color();
787 textBgColor.setAlpha(200);
788 framePen.setColor(paintColor.darker());
790 const QRectF exposed = option->exposedRect;
791 const QRectF mappedExposed = painter->worldTransform().mapRect(exposed);
792 const QRectF mapped = painter->worldTransform().mapRect(rect());
793 painter->setWorldMatrixEnabled(false);
795 p.addRect(mappedExposed);
797 q.addRoundedRect(mapped, 3, 3);
798 painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false);
799 painter->setClipPath(p.intersected(q));
800 painter->setPen(Qt::NoPen);
801 painter->fillRect(mappedExposed, paintColor);
802 painter->setPen(paintColor.darker());
804 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
806 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
807 if (thumbRect.isNull()) thumbRect = QRectF(0, 0, mapped.height() / m_startPix.height() * m_startPix.width(), mapped.height());
808 thumbRect.moveTopRight(mapped.topRight());
809 painter->drawPixmap(thumbRect, m_startPix, m_startPix.rect());
810 //const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
811 //painter->drawPixmap(top, m_startPix);
812 //QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
813 //painter->drawLine(l2);
814 } else if (!m_endPix.isNull()) {
815 if (thumbRect.isNull()) thumbRect = QRectF(0, 0, mapped.height() / m_endPix.height() * m_endPix.width(), mapped.height());
816 thumbRect.moveTopRight(mapped.topRight());
817 painter->drawPixmap(thumbRect, m_endPix, m_endPix.rect());
818 //const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
819 //painter->drawPixmap(top, m_endPix);
820 //QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
821 //painter->drawLine(l2);
823 if (!m_startPix.isNull()) {
824 if (thumbRect.isNull()) thumbRect = QRectF(0, 0, mapped.height() / m_startPix.height() * m_startPix.width(), mapped.height());
825 thumbRect.moveTopLeft(mapped.topLeft());
826 painter->drawPixmap(thumbRect, m_startPix, m_startPix.rect());
827 //painter->drawPixmap(mapped.topLeft(), m_startPix);
828 //QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
829 //painter->drawLine(l2);
832 // if we are in full zoom, paint thumbnail for every frame
833 if (m_clip->thumbProducer() && clipType() != COLOR && clipType() != AUDIO && !m_audioOnly && painter->worldTransform().m11() == FRAME_SIZE) {
834 int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
835 int left = qMax((int) m_info.cropStart.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x() - offset);
836 int right = qMin((int)(m_info.cropStart + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x() - offset);
837 QPointF startPos = mapped.topLeft();
838 int startOffset = m_info.cropStart.frames(m_fps);
839 if (clipType() == IMAGE || clipType() == TEXT) {
840 for (int i = left; i <= right; i++) {
841 painter->drawPixmap(startPos + QPointF(FRAME_SIZE *(i - startOffset), 0), m_startPix);
845 #if KDE_IS_VERSION(4,5,0)
846 if (m_clip && m_clip->thumbProducer()) {
847 QString path = m_clip->fileURL().path() + '_';
850 pen.setStyle(Qt::DotLine);
852 for (int i = left; i <= right; i++) {
853 img = m_clip->thumbProducer()->findCachedThumb(path + QString::number(i));
854 QPointF xpos = startPos + QPointF(FRAME_SIZE *(i - startOffset), 0);
855 if (img.isNull()) missing << i;
857 painter->drawImage(xpos, img);
859 painter->drawLine(xpos, xpos + QPointF(0, mapped.height()));
861 if (!missing.isEmpty()) {
862 m_clip->thumbProducer()->queryIntraThumbs(missing);
863 connect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
870 // draw audio thumbnails
871 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
873 double startpixel = exposed.left();
876 double endpixel = exposed.right();
879 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
881 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
883 if (m_clipType == AV && !isAudioOnly()) {
885 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
886 } else mappedRect = mapped;
888 double scale = painter->worldTransform().m11();
890 if (isEnabled() && m_clip) channels = m_clip->getProperty("channels").toInt();
891 if (scale != m_framePixelWidth)
892 m_audioThumbCachePic.clear();
893 double cropLeft = m_info.cropStart.frames(m_fps);
894 const int clipStart = mappedRect.x();
895 const int mappedStartPixel = painter->worldTransform().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
896 const int mappedEndPixel = painter->worldTransform().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
897 cropLeft = cropLeft * scale;
900 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels, (int) (mappedRect.height() + 0.5));
902 QRectF pixmapRect(0, mappedRect.y(), 100, mappedRect.height());
903 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
904 if (!m_audioThumbCachePic.value(startCache).isNull()) {
905 //painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic.value(startCache));
906 QPixmap pix(m_audioThumbCachePic.value(startCache));
907 pixmapRect.moveLeft(clipStart + startCache - cropLeft);
908 painter->drawPixmap(pixmapRect, pix, pix.rect());
913 if (m_isMainSelectedClip) {
914 framePen.setColor(Qt::red);
915 textBgColor = Qt::red;
918 // only paint details if clip is big enough
919 if (mapped.width() > 20) {
921 // Draw effects names
922 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
923 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
924 QColor bColor = palette.window().color();
925 QColor tColor = palette.text().color();
926 tColor.setAlpha(220);
927 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
928 qreal value = m_timeLine->currentValue();
929 txtBounding.setWidth(txtBounding.width() * value);
930 bColor.setAlpha(100 + 50 * value);
933 painter->setBrush(bColor);
934 painter->setPen(Qt::NoPen);
935 painter->drawRoundedRect(txtBounding.adjusted(-1, -2, 4, -1), 3, 3);
936 painter->setPen(tColor);
937 painter->drawText(txtBounding.adjusted(2, 0, 1, -1), Qt::AlignCenter, m_effectNames);
941 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignRight | Qt::AlignTop, m_clipName + ' ').adjusted(0, -1, 0, -1);
942 painter->setPen(Qt::NoPen);
943 painter->fillRect(txtBounding2.adjusted(-3, 0, 0, 0), textBgColor);
944 painter->setBrush(QBrush(Qt::NoBrush));
945 painter->setPen(textColor);
947 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
948 } else if (m_audioOnly) {
949 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
951 painter->drawText(txtBounding2, Qt::AlignLeft, m_clipName);
955 if (isEnabled() && m_clip) {
956 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
957 QList < CommentedTime >::Iterator it = markers.begin();
960 QBrush markerBrush(QColor(120, 120, 0, 140));
961 QPen pen = painter->pen();
963 for (; it != markers.end(); ++it) {
964 pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
965 if (pos > GenTime()) {
966 if (pos > cropDuration()) break;
967 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
968 QLineF l2 = painter->worldTransform().map(l);
969 pen.setColor(CommentedTime::markerColor((*it).markerType()));
970 pen.setStyle(Qt::DotLine);
971 painter->setPen(pen);
972 painter->drawLine(l2);
973 if (KdenliveSettings::showmarkers()) {
974 framepos = rect().x() + pos.frames(m_fps);
975 const QRectF r1(framepos + 0.04, rect().height()/3, rect().width() - framepos - 2, rect().height() / 2);
976 const QRectF r2 = painter->worldTransform().mapRect(r1);
977 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
978 painter->setBrush(markerBrush);
979 pen.setStyle(Qt::SolidLine);
980 painter->setPen(pen);
981 painter->drawRect(txtBounding3);
982 painter->setBrush(Qt::NoBrush);
983 painter->setPen(Qt::white);
984 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
986 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
991 // draw start / end fades
994 fades = QBrush(QColor(200, 50, 50, 150));
995 } else fades = QBrush(QColor(200, 200, 200, 200));
997 if (m_startFade != 0) {
998 QPainterPath fadeInPath;
999 fadeInPath.moveTo(0, 0);
1000 fadeInPath.lineTo(0, rect().height());
1001 fadeInPath.lineTo(m_startFade, 0);
1002 fadeInPath.closeSubpath();
1003 QPainterPath f1 = painter->worldTransform().map(fadeInPath);
1004 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
1005 /*if (isSelected()) {
1006 QLineF l(m_startFade * scale, 0, 0, itemHeight);
1007 painter->drawLine(l);
1010 if (m_endFade != 0) {
1011 QPainterPath fadeOutPath;
1012 fadeOutPath.moveTo(rect().width(), 0);
1013 fadeOutPath.lineTo(rect().width(), rect().height());
1014 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
1015 fadeOutPath.closeSubpath();
1016 QPainterPath f1 = painter->worldTransform().map(fadeOutPath);
1017 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
1018 /*if (isSelected()) {
1019 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
1020 painter->drawLine(l);
1025 painter->setPen(QPen(Qt::lightGray));
1026 // draw effect or transition keyframes
1027 drawKeyFrames(painter, m_limitedKeyFrames);
1031 // expand clip rect to allow correct painting of clip border
1032 painter->setClipping(false);
1033 painter->setRenderHint(QPainter::Antialiasing, true);
1034 framePen.setWidthF(1.5);
1035 painter->setPen(framePen);
1036 painter->drawRoundedRect(mapped.adjusted(0.5, 0, -0.5, 0), 3, 3);
1040 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
1042 if (isItemLocked()) return NONE;
1043 const double scale = projectScene()->scale().x();
1044 double maximumOffset = 6 / scale;
1045 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
1046 int kf = mouseOverKeyFrames(pos, maximumOffset);
1048 m_editedKeyframe = kf;
1052 QRectF rect = sceneBoundingRect();
1053 int addtransitionOffset = 10;
1054 // Don't allow add transition if track height is very small. No transitions for audio only clips
1055 if (rect.height() < 30 || isAudioOnly() || m_clipType == AUDIO) addtransitionOffset = 0;
1057 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1059 } else if ((pos.x() <= rect.x() + rect.width() / 2) && pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
1060 // If we are in a group, allow resize only if all clips start at same position
1062 QGraphicsItemGroup *dragGroup = static_cast <QGraphicsItemGroup *>(parentItem());
1063 QList<QGraphicsItem *> list = dragGroup->childItems();
1064 for (int i = 0; i < list.count(); i++) {
1065 if (list.at(i)->type() == AVWIDGET) {
1066 ClipItem *c = static_cast <ClipItem*>(list.at(i));
1067 if (c->startPos() != startPos()) return MOVE;
1072 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
1074 } else if ((pos.x() >= rect.x() + rect.width() / 2) && (rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
1075 // If we are in a group, allow resize only if all clips end at same position
1077 QGraphicsItemGroup *dragGroup = static_cast <QGraphicsItemGroup *>(parentItem());
1078 QList<QGraphicsItem *> list = dragGroup->childItems();
1079 for (int i = 0; i < list.count(); i++) {
1080 if (list.at(i)->type() == AVWIDGET) {
1081 ClipItem *c = static_cast <ClipItem*>(list.at(i));
1082 if (c->endPos() != endPos()) return MOVE;
1087 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1088 return TRANSITIONSTART;
1089 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
1090 return TRANSITIONEND;
1096 int ClipItem::itemHeight()
1098 return KdenliveSettings::trackheight() - 2;
1101 void ClipItem::resetFrameWidth(int width)
1107 QList <GenTime> ClipItem::snapMarkers() const
1109 QList < GenTime > snaps;
1110 if (!m_clip) return snaps;
1111 QList < GenTime > markers = m_clip->snapMarkers();
1114 for (int i = 0; i < markers.size(); i++) {
1115 pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1116 if (pos > GenTime()) {
1117 if (pos > cropDuration()) break;
1118 else snaps.append(pos + startPos());
1124 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
1126 QList < CommentedTime > snaps;
1127 if (!m_clip) return snaps;
1128 QList < CommentedTime > markers = m_clip->commentedSnapMarkers();
1131 for (int i = 0; i < markers.size(); i++) {
1132 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
1133 if (pos > GenTime()) {
1134 if (pos > cropDuration()) break;
1135 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment(), markers.at(i).markerType()));
1141 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels, int pixelHeight)
1143 // Bail out, if caller provided invalid data
1144 if (channels <= 0) {
1145 kWarning() << "Unable to draw image with " << channels << "number of channels";
1149 if (KdenliveSettings::normaliseaudiothumbs()) {
1150 factor = m_clip->getProperty("audio_max").toInt();
1153 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
1154 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
1155 bool fullAreaDraw = pixelForOneFrame < 10;
1156 bool simplifiedAudio = !KdenliveSettings::displayallchannels();
1158 audiopen.setWidth(0);
1159 if (simplifiedAudio) channels = 1;
1160 int channelHeight = pixelHeight / channels;
1161 QMap<int, QPainterPath > positiveChannelPaths;
1162 QMap<int, QPainterPath > negativeChannelPaths;
1164 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
1165 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
1167 if (m_audioThumbCachePic.value(startCache).isNull() || m_framePixelWidth != pixelForOneFrame) {
1168 QPixmap pix(100, pixelHeight);
1169 pix.fill(QColor(180, 180, 180, 150));
1170 m_audioThumbCachePic[startCache] = pix;
1172 positiveChannelPaths.clear();
1173 negativeChannelPaths.clear();
1175 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
1177 for (int i = 0; i < channels; i++) {
1178 if (simplifiedAudio) {
1179 positiveChannelPaths[i].moveTo(-1, channelHeight);
1181 else if (fullAreaDraw) {
1182 positiveChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1183 negativeChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1186 positiveChannelPaths[i].moveTo(-1, channelHeight*i + channelHeight / 2);
1187 audiopen.setColor(QColor(60, 60, 60, 50));
1188 pixpainter.setPen(audiopen);
1189 pixpainter.drawLine(0, channelHeight*i + channelHeight / 2, 100, channelHeight*i + channelHeight / 2);
1193 for (int samples = 0; samples <= 100; samples++) {
1194 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
1195 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
1196 if (frame < 0 || sample < 0 || sample > 19)
1198 const QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameCache.value((int)frame);
1200 for (int channel = 0; channel < channels && !frame_channel_data.value(channel).isEmpty(); channel++) {
1201 int y = channelHeight * channel + channelHeight / 2;
1202 if (simplifiedAudio) {
1203 double delta = qAbs((frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / factor);
1204 positiveChannelPaths[channel].lineTo(samples, channelHeight - delta);
1205 } else if (fullAreaDraw) {
1206 double delta = qAbs((frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / (2 * factor));
1207 positiveChannelPaths[channel].lineTo(samples, y + delta);
1208 negativeChannelPaths[channel].lineTo(samples, y - delta);
1210 double delta = (frame_channel_data.value(channel).at(sample) - 63.5) * channelHeight / (2 * factor);
1211 positiveChannelPaths[channel].lineTo(samples, y + delta);
1215 for (int channel = 0; channel < channels; channel++) {
1216 if (simplifiedAudio) {
1217 positiveChannelPaths[channel].lineTo(101, channelHeight);
1218 } else if (fullAreaDraw) {
1219 int y = channelHeight * channel + channelHeight / 2;
1220 positiveChannelPaths[channel].lineTo(101, y);
1221 negativeChannelPaths[channel].lineTo(101, y);
1224 if (fullAreaDraw || simplifiedAudio) {
1225 audiopen.setColor(QColor(80, 80, 80, 200));
1226 pixpainter.setPen(audiopen);
1227 pixpainter.setBrush(QBrush(QColor(120, 120, 120, 200)));
1230 audiopen.setColor(QColor(60, 60, 60, 100));
1231 pixpainter.setPen(audiopen);
1232 pixpainter.setBrush(Qt::NoBrush);
1234 pixpainter.setRenderHint(QPainter::Antialiasing, false);
1235 for (int i = 0; i < channels; i++) {
1237 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths.value(i)));
1239 pixpainter.drawPath(positiveChannelPaths.value(i));
1242 m_framePixelWidth = pixelForOneFrame;
1245 int ClipItem::fadeIn() const
1250 int ClipItem::fadeOut() const
1256 void ClipItem::setFadeIn(int pos)
1258 if (pos == m_startFade) return;
1259 int oldIn = m_startFade;
1260 m_startFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1261 QRectF rect = boundingRect();
1262 update(rect.x(), rect.y(), qMax(oldIn, m_startFade), rect.height());
1265 void ClipItem::setFadeOut(int pos)
1267 if (pos == m_endFade) return;
1268 int oldOut = m_endFade;
1269 m_endFade = qBound(0, pos, (int)cropDuration().frames(m_fps));
1270 QRectF rect = boundingRect();
1271 update(rect.x() + rect.width() - qMax(oldOut, m_endFade), rect.y(), qMax(oldOut, m_endFade), rect.height());
1275 void ClipItem::setFades(int in, int out)
1283 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1285 //if (e->pos().x() < 20) m_hover = true;
1287 if (isItemLocked()) return;
1289 QRectF r = boundingRect();
1290 double width = 35 / projectScene()->scale().x();
1291 double height = r.height() / 2;
1292 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1293 update(r.x(), r.y() + height, width, height);
1294 update(r.right() - width, r.y() + height, width, height);
1298 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1300 if (isItemLocked()) return;
1302 QRectF r = boundingRect();
1303 double width = 35 / projectScene()->scale().x();
1304 double height = r.height() / 2;
1305 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1306 update(r.x(), r.y() + height, width, height);
1307 update(r.right() - width, r.y() + height, width, height);
1311 void ClipItem::resizeStart(int posx, bool /*size*/, bool emitChange)
1313 bool sizeLimit = false;
1314 if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
1315 const int min = (startPos() - cropStart()).frames(m_fps);
1316 if (posx < min) posx = min;
1320 if (posx == startPos().frames(m_fps)) return;
1321 const int previous = cropStart().frames(m_fps);
1322 AbstractClipItem::resizeStart(posx, sizeLimit);
1324 // set speed independant info
1325 m_speedIndependantInfo = m_info;
1326 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1327 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1329 if ((int) cropStart().frames(m_fps) != previous) {
1330 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1331 m_startThumbTimer.start(150);
1334 if (emitChange) slotUpdateRange();
1337 void ClipItem::slotUpdateRange()
1339 if (m_isMainSelectedClip) emit updateRange();
1342 void ClipItem::resizeEnd(int posx, bool emitChange)
1344 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1345 if (posx > max && maxDuration() != GenTime()) posx = max;
1346 if (posx == endPos().frames(m_fps)) return;
1347 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1348 const int previous = cropDuration().frames(m_fps);
1349 AbstractClipItem::resizeEnd(posx);
1351 // set speed independant info
1352 m_speedIndependantInfo = m_info;
1353 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
1354 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
1356 if ((int) cropDuration().frames(m_fps) != previous) {
1357 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1358 m_endThumbTimer.start(150);
1361 if (emitChange) slotUpdateRange();
1365 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1367 if (change == QGraphicsItem::ItemSelectedChange) {
1368 if (value.toBool()) setZValue(10);
1371 if (change == ItemPositionChange && scene()) {
1372 // calculate new position.
1373 //if (parentItem()) return pos();
1374 QPointF newPos = value.toPointF();
1375 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1376 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1377 xpos = qMax(xpos, 0);
1379 // Warning: newPos gives a position relative to the click event, so hack to get absolute pos
1380 int yOffset = property("y_absolute").toInt() + newPos.y();
1381 int newTrack = yOffset / KdenliveSettings::trackheight();
1382 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1383 newTrack = qMax(newTrack, 0);
1384 QStringList lockedTracks = property("locked_tracks").toStringList();
1385 if (lockedTracks.contains(QString::number(newTrack))) {
1386 // Trying to move to a locked track
1389 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1390 // Only one clip is moving
1391 QRectF sceneShape = rect();
1392 sceneShape.translate(newPos);
1393 QList<QGraphicsItem*> items;
1394 if (projectScene()->editMode() == NORMALEDIT)
1395 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1396 items.removeAll(this);
1397 bool forwardMove = newPos.x() > pos().x();
1399 if (!items.isEmpty()) {
1400 for (int i = 0; i < items.count(); i++) {
1401 if (!items.at(i)->isEnabled()) continue;
1402 if (items.at(i)->type() == type()) {
1404 QPointF otherPos = items.at(i)->pos();
1405 if ((int) otherPos.y() != (int) pos().y()) {
1409 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1411 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1416 sceneShape.translate(QPointF(-offset, 0));
1417 newPos.setX(newPos.x() - offset);
1419 sceneShape.translate(QPointF(offset, 0));
1420 newPos.setX(newPos.x() + offset);
1422 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1423 subitems.removeAll(this);
1424 for (int j = 0; j < subitems.count(); j++) {
1425 if (!subitems.at(j)->isEnabled()) continue;
1426 if (subitems.at(j)->type() == type()) {
1427 // move was not successful, revert to previous pos
1428 m_info.startPos = GenTime((int) pos().x(), m_fps);
1434 m_info.track = newTrack;
1435 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1441 m_info.track = newTrack;
1442 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1443 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1446 return QGraphicsItem::itemChange(change, value);
1450 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1453 int ClipItem::effectsCounter()
1455 return effectsCount() + 1;
1458 int ClipItem::effectsCount()
1460 return m_effectList.count();
1463 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1465 return m_effectList.hasEffect(tag, id);
1468 QStringList ClipItem::effectNames()
1470 return m_effectList.effectNames();
1473 QDomElement ClipItem::effect(int ix) const
1475 if (ix >= m_effectList.count() || ix < 0) return QDomElement();
1476 return m_effectList.at(ix).cloneNode().toElement();
1479 QDomElement ClipItem::effectAtIndex(int ix) const
1481 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1482 return m_effectList.itemFromIndex(ix).cloneNode().toElement();
1485 QDomElement ClipItem::getEffectAtIndex(int ix) const
1487 if (ix > m_effectList.count() || ix <= 0) return QDomElement();
1488 return m_effectList.itemFromIndex(ix);
1491 void ClipItem::updateEffect(QDomElement effect)
1493 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1494 m_effectList.updateEffect(effect);
1495 m_effectNames = m_effectList.effectNames().join(" / ");
1496 QString id = effect.attribute("id");
1497 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1500 QRectF r = boundingRect();
1506 void ClipItem::enableEffects(QList <int> indexes, bool disable)
1508 m_effectList.enableEffects(indexes, disable);
1511 bool ClipItem::moveEffect(QDomElement effect, int ix)
1513 if (ix <= 0 || ix > (m_effectList.count()) || effect.isNull()) {
1514 kDebug() << "Invalid effect index: " << ix;
1517 m_effectList.removeAt(effect.attribute("kdenlive_ix").toInt());
1518 effect.setAttribute("kdenlive_ix", ix);
1519 m_effectList.insert(effect);
1520 m_effectNames = m_effectList.effectNames().join(" / ");
1521 QString id = effect.attribute("id");
1522 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1525 QRectF r = boundingRect();
1532 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool /*animate*/)
1534 bool needRepaint = false;
1537 QDomElement insertedEffect;
1538 if (!effect.hasAttribute("kdenlive_ix")) {
1539 // effect dropped from effect list
1540 ix = effectsCounter();
1541 } else ix = effect.attribute("kdenlive_ix").toInt();
1542 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1544 insertedEffect = m_effectList.insert(effect);
1545 } else insertedEffect = m_effectList.append(effect);
1547 // Update index to the real one
1548 effect.setAttribute("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1552 if (effect.attribute("tag") == "affine") {
1553 // special case: the affine effect needs in / out points
1554 effectIn = effect.attribute("in").toInt();
1555 effectOut = effect.attribute("out").toInt();
1558 effectIn = EffectsList::parameter(effect, "in").toInt();
1559 effectOut = EffectsList::parameter(effect, "out").toInt();
1562 EffectsParameterList parameters;
1563 parameters.addParam("tag", insertedEffect.attribute("tag"));
1564 parameters.addParam("kdenlive_ix", insertedEffect.attribute("kdenlive_ix"));
1565 if (insertedEffect.hasAttribute("src")) parameters.addParam("src", insertedEffect.attribute("src"));
1566 if (insertedEffect.hasAttribute("disable")) parameters.addParam("disable", insertedEffect.attribute("disable"));
1568 QString effectId = insertedEffect.attribute("id");
1569 if (effectId.isEmpty()) effectId = insertedEffect.attribute("tag");
1570 parameters.addParam("id", effectId);
1572 QDomNodeList params = insertedEffect.elementsByTagName("parameter");
1574 bool needInOutSync = false;
1576 // check if it is a fade effect
1577 if (effectId == "fadein") {
1579 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1580 fade = effectOut - effectIn;
1582 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1583 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1584 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1586 } else if (effectId == "fade_from_black") {
1588 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1589 fade = effectOut - effectIn;
1591 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1592 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1593 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1595 } else if (effectId == "fadeout") {
1597 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1598 fade = effectIn - effectOut;
1600 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1601 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1602 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1604 } else if (effectId == "fade_to_black") {
1606 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1607 fade = effectIn - effectOut;
1609 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1610 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1611 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1615 for (int i = 0; i < params.count(); i++) {
1616 QDomElement e = params.item(i).toElement();
1618 if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
1619 // Effects with a geometry parameter need to sync in / out with parent clip
1620 needInOutSync = true;
1622 if (e.attribute("type") == "simplekeyframe") {
1623 QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1624 double factor = locale.toDouble(e.attribute("factor", "1"));
1625 double offset = e.attribute("offset", "0").toDouble();
1626 if (factor != 1 || offset != 0) {
1627 for (int j = 0; j < values.count(); j++) {
1628 QString pos = values.at(j).section(':', 0, 0);
1629 double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor;
1630 values[j] = pos + '=' + locale.toString(val);
1633 parameters.addParam(e.attribute("name"), values.join(";"));
1634 /*parameters.addParam("max", e.attribute("max"));
1635 parameters.addParam("min", e.attribute("min"));
1636 parameters.addParam("factor", );*/
1637 } else if (e.attribute("type") == "keyframe") {
1638 parameters.addParam("keyframes", e.attribute("keyframes"));
1639 parameters.addParam("max", e.attribute("max"));
1640 parameters.addParam("min", e.attribute("min"));
1641 parameters.addParam("factor", e.attribute("factor", "1"));
1642 parameters.addParam("offset", e.attribute("offset", "0"));
1643 parameters.addParam("starttag", e.attribute("starttag", "start"));
1644 parameters.addParam("endtag", e.attribute("endtag", "end"));
1645 } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") {
1646 parameters.addParam(e.attribute("name"), e.attribute("value"));
1650 if (e.attribute("factor").contains('%')) {
1651 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1653 fact = locale.toDouble(e.attribute("factor", "1"));
1655 double offset = e.attribute("offset", "0").toDouble();
1656 parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact));
1660 if (needInOutSync) {
1661 parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
1662 parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps) - 1));
1663 parameters.addParam("_sync_in_out", "1");
1665 m_effectNames = m_effectList.effectNames().join(" / ");
1666 if (fade > 0) m_startFade = fade;
1667 else if (fade < 0) m_endFade = -fade;
1669 if (m_selectedEffect == -1) {
1670 setSelectedEffect(0);
1671 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1672 if (needRepaint) update(boundingRect());
1676 else { /*if (!needRepaint) */
1677 QRectF r = boundingRect();
1684 void ClipItem::deleteEffect(QString index)
1686 bool needRepaint = false;
1687 int ix = index.toInt();
1689 QDomElement effect = m_effectList.itemFromIndex(ix);
1690 QString effectId = effect.attribute("id");
1691 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1692 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1695 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1696 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1699 } else if (EffectsList::hasKeyFrames(effect)) needRepaint = true;
1700 m_effectList.removeAt(ix);
1701 m_effectNames = m_effectList.effectNames().join(" / ");
1703 if (m_effectList.isEmpty() || m_selectedEffect == ix) {
1704 // Current effect was removed
1705 if (ix > m_effectList.count()) {
1706 setSelectedEffect(m_effectList.count());
1707 } else setSelectedEffect(ix);
1709 if (needRepaint) update(boundingRect());
1711 QRectF r = boundingRect();
1715 //if (!m_effectList.isEmpty()) flashClip();
1718 double ClipItem::speed() const
1723 int ClipItem::strobe() const
1728 void ClipItem::setSpeed(const double speed, const int strobe)
1731 if (m_speed <= 0 && m_speed > -1)
1734 if (m_speed == 1.0) m_clipName = m_clip->name();
1735 else m_clipName = m_clip->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1736 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1737 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1741 GenTime ClipItem::maxDuration() const
1743 return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
1746 GenTime ClipItem::speedIndependantCropStart() const
1748 return m_speedIndependantInfo.cropStart;
1751 GenTime ClipItem::speedIndependantCropDuration() const
1753 return m_speedIndependantInfo.cropDuration;
1757 const ItemInfo ClipItem::speedIndependantInfo() const
1759 return m_speedIndependantInfo;
1762 int ClipItem::nextFreeEffectGroupIndex() const
1764 int freeGroupIndex = 0;
1765 for (int i = 0; i < m_effectList.count(); i++) {
1766 QDomElement effect = m_effectList.at(i);
1767 EffectInfo effectInfo;
1768 effectInfo.fromString(effect.attribute("kdenlive_info"));
1769 if (effectInfo.groupIndex >= freeGroupIndex) {
1770 freeGroupIndex = effectInfo.groupIndex + 1;
1773 return freeGroupIndex;
1777 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1779 if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
1780 const QString effects = QString::fromUtf8(event->mimeData()->data("kdenlive/effectslist"));
1781 event->acceptProposedAction();
1783 doc.setContent(effects, true);
1784 QDomElement e = doc.documentElement();
1785 if (e.tagName() == "effectgroup") {
1786 // dropped an effect group
1787 QDomNodeList effectlist = e.elementsByTagName("effect");
1788 int freeGroupIndex = nextFreeEffectGroupIndex();
1789 EffectInfo effectInfo;
1790 for (int i = 0; i < effectlist.count(); i++) {
1791 QDomElement effect = effectlist.at(i).toElement();
1792 effectInfo.fromString(effect.attribute("kdenlive_info"));
1793 effectInfo.groupIndex = freeGroupIndex;
1794 effect.setAttribute("kdenlive_info", effectInfo.toString());
1795 effect.removeAttribute("kdenlive_ix");
1798 // single effect dropped
1799 e.removeAttribute("kdenlive_ix");
1801 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1802 if (view) view->slotAddEffect(e, m_info.startPos, track());
1808 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1810 if (isItemLocked()) event->setAccepted(false);
1811 else if (event->mimeData()->hasFormat("kdenlive/effectslist")) {
1812 event->acceptProposedAction();
1813 } else event->setAccepted(false);
1816 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1821 void ClipItem::addTransition(Transition* t)
1823 m_transitionsList.append(t);
1824 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1826 QDomElement e = doc.documentElement();
1827 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1830 void ClipItem::setVideoOnly(bool force)
1832 m_videoOnly = force;
1835 void ClipItem::setAudioOnly(bool force)
1837 m_audioOnly = force;
1838 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1840 if (m_clipType == COLOR) {
1841 QString colour = m_clip->getProperty("colour");
1842 colour = colour.replace(0, 2, "#");
1843 m_baseColor = QColor(colour.left(7));
1844 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1845 else m_baseColor = QColor(141, 166, 215);
1847 m_audioThumbCachePic.clear();
1850 bool ClipItem::isAudioOnly() const
1855 bool ClipItem::isVideoOnly() const
1860 void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
1862 if (effect.attribute("disable") == "1") return;
1864 effect.setAttribute("active_keyframe", pos);
1865 m_editedKeyframe = pos;
1866 QDomNodeList params = effect.elementsByTagName("parameter");
1867 for (int i = 0; i < params.count(); i++) {
1868 QDomElement e = params.item(i).toElement();
1869 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1870 QString kfr = e.attribute("keyframes");
1871 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1874 foreach(const QString &str, keyframes) {
1875 int kpos = str.section(':', 0, 0).toInt();
1876 double newval = locale.toDouble(str.section(':', 1, 1));
1879 } else if (!added) {
1880 if (i == m_visibleParam)
1881 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1883 newkfr.append(QString::number(pos) + ':' + locale.toString(newval));
1884 if (kpos > pos) newkfr.append(str);
1886 } else newkfr.append(str);
1889 if (i == m_visibleParam)
1890 newkfr.append(QString::number(pos) + ':' + QString::number(val));
1892 newkfr.append(QString::number(pos) + ':' + e.attribute("default"));
1894 e.setAttribute("keyframes", newkfr.join(";"));
1899 void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double value)
1901 if (effect.attribute("disable") == "1") return;
1903 effect.setAttribute("active_keyframe", newpos);
1904 QDomNodeList params = effect.elementsByTagName("parameter");
1905 int start = cropStart().frames(m_fps);
1906 int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
1907 for (int i = 0; i < params.count(); i++) {
1908 QDomElement e = params.item(i).toElement();
1909 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1910 QString kfr = e.attribute("keyframes");
1911 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
1913 foreach(const QString &str, keyframes) {
1914 if (str.section(':', 0, 0).toInt() != oldpos) {
1916 } else if (newpos != -1) {
1917 newpos = qMax(newpos, start);
1918 newpos = qMin(newpos, end);
1919 if (i == m_visibleParam)
1920 newkfr.append(QString::number(newpos) + ':' + locale.toString(value));
1922 newkfr.append(QString::number(newpos) + ':' + str.section(':', 1, 1));
1925 e.setAttribute("keyframes", newkfr.join(";"));
1929 updateKeyframes(effect);
1933 void ClipItem::updateKeyframes(QDomElement effect)
1935 m_keyframes.clear();
1938 QDomNodeList params = effect.elementsByTagName("parameter");
1939 QDomElement e = params.item(m_visibleParam).toElement();
1940 if (e.attribute("intimeline") != "1") {
1941 setSelectedEffect(m_selectedEffect);
1944 m_limitedKeyFrames = e.attribute("type") == "keyframe";
1945 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1946 foreach(const QString &str, keyframes) {
1947 int pos = str.section(':', 0, 0).toInt();
1948 double val = locale.toDouble(str.section(':', 1, 1));
1949 m_keyframes[pos] = val;
1951 if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
1954 Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
1957 return m_clip->audioProducer(track);
1958 else if (isVideoOnly())
1959 return m_clip->videoProducer(track);
1961 return m_clip->getProducer(trackSpecific ? track : -1);
1964 QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height, ItemInfo oldInfo)
1966 QMap<int, QDomElement> effects;
1967 for (int i = 0; i < m_effectList.count(); i++) {
1968 QDomElement effect = m_effectList.at(i);
1970 if (effect.attribute("id").startsWith("fade")) {
1971 QString id = effect.attribute("id");
1972 int in = EffectsList::parameter(effect, "in").toInt();
1973 int out = EffectsList::parameter(effect, "out").toInt();
1974 int clipEnd = (cropStart() + cropDuration()).frames(m_fps) - 1;
1975 if (id == "fade_from_black" || id == "fadein") {
1976 if (in != cropStart().frames(m_fps)) {
1977 effects[i] = effect.cloneNode().toElement();
1978 int duration = out - in;
1979 in = cropStart().frames(m_fps);
1980 out = in + duration;
1981 EffectsList::setParameter(effect, "in", QString::number(in));
1982 EffectsList::setParameter(effect, "out", QString::number(out));
1984 if (out > clipEnd) {
1985 if (!effects.contains(i))
1986 effects[i] = effect.cloneNode().toElement();
1987 EffectsList::setParameter(effect, "out", QString::number(clipEnd));
1989 if (effects.contains(i)) {
1990 setFadeIn(out - in);
1993 if (out != clipEnd) {
1994 effects[i] = effect.cloneNode().toElement();
1995 int diff = out - clipEnd;
1996 in = qMax(in - diff, (int) cropStart().frames(m_fps));
1998 EffectsList::setParameter(effect, "in", QString::number(in));
1999 EffectsList::setParameter(effect, "out", QString::number(out));
2001 if (in < cropStart().frames(m_fps)) {
2002 if (!effects.contains(i))
2003 effects[i] = effect.cloneNode().toElement();
2004 EffectsList::setParameter(effect, "in", QString::number(cropStart().frames(m_fps)));
2006 if (effects.contains(i))
2007 setFadeOut(out - in);
2010 } else if (effect.attribute("id") == "freeze" && cropStart() != oldInfo.cropStart) {
2011 effects[i] = effect.cloneNode().toElement();
2012 int diff = (oldInfo.cropStart - cropStart()).frames(m_fps);
2013 int frame = EffectsList::parameter(effect, "frame").toInt();
2014 EffectsList::setParameter(effect, "frame", QString::number(frame - diff));
2016 } else if (effect.attribute("id") == "pan_zoom") {
2017 effect.setAttribute("in", cropStart().frames(m_fps));
2018 effect.setAttribute("out", (cropStart() + cropDuration()).frames(m_fps) - 1);
2021 QDomNodeList params = effect.elementsByTagName("parameter");
2022 for (int j = 0; j < params.count(); j++) {
2023 QDomElement param = params.item(j).toElement();
2025 QString type = param.attribute("type");
2026 if (type == "geometry" && !param.hasAttribute("fixed")) {
2027 if (!effects.contains(i))
2028 effects[i] = effect.cloneNode().toElement();
2029 updateGeometryKeyframes(effect, j, width, height, oldInfo);
2030 } else if (type == "simplekeyframe" || type == "keyframe") {
2031 if (!effects.contains(i))
2032 effects[i] = effect.cloneNode().toElement();
2033 updateNormalKeyframes(param, oldInfo);
2035 } else if (type == "roto-spline") {
2036 if (!effects.contains(i))
2037 effects[i] = effect.cloneNode().toElement();
2038 QString value = param.attribute("value");
2039 if (adjustRotoDuration(&value, cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1))
2040 param.setAttribute("value", value);
2048 bool ClipItem::updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo)
2050 int in = cropStart().frames(m_fps);
2051 int out = (cropStart() + cropDuration()).frames(m_fps) - 1;
2052 int oldin = oldInfo.cropStart.frames(m_fps);
2054 bool keyFrameUpdated = false;
2056 const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
2057 QMap <int, double> keyframes;
2058 foreach (QString keyframe, data) {
2059 int keyframepos = keyframe.section(':', 0, 0).toInt();
2060 // if keyframe was at clip start, update it
2061 if (keyframepos == oldin) {
2063 keyFrameUpdated = true;
2065 keyframes[keyframepos] = locale.toDouble(keyframe.section(':', 1, 1));
2069 QMap<int, double>::iterator i = keyframes.end();
2071 double lastValue = 0;
2075 * Take care of resize from start
2077 bool startFound = false;
2078 while (i-- != keyframes.begin()) {
2079 if (i.key() < in && !startFound) {
2082 keyframes[in] = i.value();
2084 relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
2085 keyframes[in] = i.value() + (lastValue - i.value()) * relPos;
2089 lastValue = i.value();
2091 i = keyframes.erase(i);
2095 * Take care of resize from end
2097 i = keyframes.begin();
2099 bool endFound = false;
2100 while (i != keyframes.end()) {
2101 if (i.key() > out && !endFound) {
2104 keyframes[out] = i.value();
2106 relPos = (out - lastPos) / (qreal)(i.key() - lastPos + 1);
2107 keyframes[out] = lastValue + (i.value() - lastValue) * relPos;
2111 lastValue = i.value();
2113 i = keyframes.erase(i);
2118 if (startFound || endFound || keyFrameUpdated) {
2120 QMap<int, double>::const_iterator k = keyframes.constBegin();
2121 while (k != keyframes.constEnd()) {
2122 newkfr.append(QString::number(k.key()) + ':' + QString::number(qRound(k.value())) + ';');
2125 parameter.setAttribute("keyframes", newkfr);
2132 void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
2134 QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
2135 int offset = oldInfo.cropStart.frames(m_fps);
2136 QString data = param.attribute("value");
2138 QStringList kfrs = data.split(';');
2140 foreach (const QString &keyframe, kfrs) {
2141 if (keyframe.contains('=')) {
2142 int pos = keyframe.section('=', 0, 0).toInt();
2144 data.append(QString::number(pos) + '=' + keyframe.section('=', 1) + ";");
2146 else data.append(keyframe + ';');
2149 Mlt::Geometry geometry(data.toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
2150 param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
2153 void ClipItem::slotGotThumbsCache()
2155 disconnect(m_clip->thumbProducer(), SIGNAL(thumbsCached()), this, SLOT(slotGotThumbsCache()));
2160 #include "clipitem.moc"