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"
36 #include <QStyleOptionGraphicsItem>
37 #include <QGraphicsScene>
40 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, int strobe, bool generateThumbs) :
41 AbstractClipItem(info, QRectF(), fps),
47 m_startPix(QPixmap()),
52 m_startThumbRequested(false),
53 m_endThumbRequested(false),
60 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
61 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
63 // set speed independant info
64 m_speedIndependantInfo = m_info;
65 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
66 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
68 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
69 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
71 if (m_speed == 1.0) m_clipName = m_clip->name();
73 m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
75 m_producer = m_clip->getId();
76 m_clipType = m_clip->clipType();
77 //m_cropStart = info.cropStart;
78 m_maxDuration = m_clip->maxDuration();
80 m_audioThumbReady = m_clip->audioThumbCreated();
81 //setAcceptsHoverEvents(true);
82 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
84 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
85 m_baseColor = QColor(141, 166, 215);
87 m_startThumbTimer.setSingleShot(true);
88 connect(&m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
89 m_endThumbTimer.setSingleShot(true);
90 connect(&m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
92 connect(this, SIGNAL(getThumb(int, int)), m_clip->thumbProducer(), SLOT(extractImage(int, int)));
94 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
95 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
96 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
98 } else if (m_clipType == COLOR) {
99 QString colour = m_clip->getProperty("colour");
100 colour = colour.replace(0, 2, "#");
101 m_baseColor = QColor(colour.left(7));
102 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
103 m_baseColor = QColor(141, 166, 215);
104 if (m_clipType == TEXT) {
105 connect(this, SIGNAL(getThumb(int, int)), m_clip->thumbProducer(), SLOT(extractImage(int, int)));
106 connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
108 //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
109 } else if (m_clipType == AUDIO) {
110 m_baseColor = QColor(141, 215, 166);
111 connect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
116 ClipItem::~ClipItem()
119 if (scene()) scene()->removeItem(this);
120 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
121 disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QImage)), this, SLOT(slotThumbReady(int, QImage)));
122 disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
127 ClipItem *ClipItem::clone(ItemInfo info) const
129 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed, m_strobe);
130 if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
131 else if (m_clipType != COLOR) {
132 if (info.cropStart == m_info.cropStart) duplicate->slotSetStartThumb(m_startPix);
133 if (info.cropStart + (info.endPos - info.startPos) == m_info.cropStart + (m_info.endPos - m_info.startPos)) duplicate->slotSetEndThumb(m_endPix);
135 //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
136 duplicate->setEffectList(m_effectList);
137 duplicate->setVideoOnly(m_videoOnly);
138 duplicate->setAudioOnly(m_audioOnly);
139 //duplicate->setSpeed(m_speed);
143 void ClipItem::setEffectList(const EffectsList effectList)
145 m_effectList.clone(effectList);
146 m_effectNames = m_effectList.effectNames().join(" / ");
147 if (!m_effectList.isEmpty()) setSelectedEffect(0);
150 const EffectsList ClipItem::effectList() const
155 int ClipItem::selectedEffectIndex() const
157 return m_selectedEffect;
160 void ClipItem::initEffect(QDomElement effect, int diff)
162 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
164 if (effect.attribute("kdenlive_ix").toInt() == 0)
165 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
167 if (effect.attribute("id") == "freeze" && diff > 0) {
168 EffectsList::setParameter(effect, "frame", QString::number(diff));
171 // Init parameter value & keyframes if required
172 QDomNodeList params = effect.elementsByTagName("parameter");
173 for (int i = 0; i < params.count(); i++) {
174 QDomElement e = params.item(i).toElement();
175 kDebug() << "// init eff: " << e.attribute("name");
177 // Check if this effect has a variable parameter
178 if (e.attribute("default").startsWith('%')) {
179 double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
180 e.setAttribute("default", evaluatedValue);
181 if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
182 e.setAttribute("value", evaluatedValue);
186 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
187 QString def = e.attribute("default");
188 // Effect has a keyframe type parameter, we need to set the values
189 if (e.attribute("keyframes").isEmpty()) {
190 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def + ';' + QString::number((cropStart() + cropDuration()).frames(m_fps) - 1) + ':' + def);
191 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
196 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
197 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
198 int end = (cropDuration() + cropStart()).frames(m_fps);
200 if (effect.attribute("id") == "fadeout") {
201 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
202 int effectDuration = EffectsList::parameter(effect, "in").toInt();
203 if (effectDuration > cropDuration().frames(m_fps)) {
204 effectDuration = cropDuration().frames(m_fps) / 2;
206 start -= effectDuration;
208 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
209 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
211 } else if (effect.attribute("id") == "fade_to_black") {
212 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
213 int effectDuration = EffectsList::parameter(effect, "in").toInt();
214 if (effectDuration > cropDuration().frames(m_fps)) {
215 effectDuration = cropDuration().frames(m_fps) / 2;
217 start -= effectDuration;
219 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
220 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
223 EffectsList::setParameter(effect, "in", QString::number(start));
224 EffectsList::setParameter(effect, "out", QString::number(end));
225 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
226 int start = cropStart().frames(m_fps);
228 if (effect.attribute("id") == "fadein") {
229 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
230 int effectDuration = EffectsList::parameter(effect, "out").toInt();
231 if (effectDuration > cropDuration().frames(m_fps)) {
232 effectDuration = cropDuration().frames(m_fps) / 2;
234 end += effectDuration;
236 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
237 } else if (effect.attribute("id") == "fade_from_black") {
238 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
239 int effectDuration = EffectsList::parameter(effect, "out").toInt();
240 if (effectDuration > cropDuration().frames(m_fps)) {
241 effectDuration = cropDuration().frames(m_fps) / 2;
243 end += effectDuration;
245 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
247 EffectsList::setParameter(effect, "in", QString::number(start));
248 EffectsList::setParameter(effect, "out", QString::number(end));
253 bool ClipItem::checkKeyFrames()
255 bool clipEffectsModified = false;
256 for (int ix = 0; ix < m_effectList.count(); ix ++) {
257 QString kfr = keyframes(ix);
258 if (!kfr.isEmpty()) {
259 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
260 QStringList newKeyFrames;
261 bool cutKeyFrame = false;
262 bool modified = false;
264 double lastValue = -1;
265 int start = cropStart().frames(m_fps);
266 int end = (cropStart() + cropDuration()).frames(m_fps);
267 foreach(const QString &str, keyframes) {
268 int pos = str.section(':', 0, 0).toInt();
269 double val = str.section(':', 1, 1).toDouble();
270 if (pos - start < 0) {
271 // a keyframe is defined before the start of the clip
273 } else if (cutKeyFrame) {
274 // create new keyframe at clip start, calculate interpolated value
276 int diff = pos - lastPos;
277 double ratio = (double)(start - lastPos) / diff;
278 double newValue = lastValue + (val - lastValue) * ratio;
279 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
286 // create new keyframe at clip end, calculate interpolated value
287 int diff = pos - lastPos;
289 double ratio = (double)(end - lastPos) / diff;
290 double newValue = lastValue + (val - lastValue) * ratio;
291 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
296 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
304 setKeyframes(ix, newKeyFrames.join(";"));
305 clipEffectsModified = true;
309 return clipEffectsModified;
312 void ClipItem::setKeyframes(const int ix, const QString keyframes)
314 QDomElement effect = getEffectAt(ix);
315 if (effect.attribute("disabled") == "1") return;
316 QDomNodeList params = effect.elementsByTagName("parameter");
317 for (int i = 0; i < params.count(); i++) {
318 QDomElement e = params.item(i).toElement();
319 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
320 e.setAttribute("keyframes", keyframes);
321 if (ix == m_selectedEffect) {
323 double max = e.attribute("max").toDouble();
324 double min = e.attribute("min").toDouble();
325 m_keyframeFactor = 100.0 / (max - min);
326 m_keyframeDefault = e.attribute("default").toDouble();
327 m_selectedKeyframe = 0;
328 m_editedKeyframe = -1;
330 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
331 foreach(const QString &str, keyframes) {
332 int pos = str.section(':', 0, 0).toInt();
333 double val = str.section(':', 1, 1).toDouble();
334 m_keyframes[pos] = val;
345 void ClipItem::setSelectedEffect(const int ix)
347 m_selectedEffect = ix;
348 QDomElement effect = effectAt(m_selectedEffect);
349 if (effect.isNull() == false) {
350 QDomNodeList params = effect.elementsByTagName("parameter");
351 if (effect.attribute("disabled") != "1")
352 for (int i = 0; i < params.count(); i++) {
353 QDomElement e = params.item(i).toElement();
354 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
356 double max = e.attribute("max").toDouble();
357 double min = e.attribute("min").toDouble();
358 m_keyframeFactor = 100.0 / (max - min);
359 m_keyframeDefault = e.attribute("default").toDouble();
360 m_selectedKeyframe = 0;
361 m_editedKeyframe = -1;
363 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
364 foreach(const QString &str, keyframes) {
365 int pos = str.section(':', 0, 0).toInt();
366 double val = str.section(':', 1, 1).toDouble();
367 m_keyframes[pos] = val;
374 if (!m_keyframes.isEmpty()) {
380 QString ClipItem::keyframes(const int index)
383 QDomElement effect = effectAt(index);
384 QDomNodeList params = effect.elementsByTagName("parameter");
386 for (int i = 0; i < params.count(); i++) {
387 QDomElement e = params.item(i).toElement();
388 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
389 result = e.attribute("keyframes");
396 void ClipItem::updateKeyframeEffect()
398 // regenerate xml parameter from the clip keyframes
399 QDomElement effect = getEffectAt(m_selectedEffect);
400 if (effect.attribute("disabled") == "1") return;
401 QDomNodeList params = effect.elementsByTagName("parameter");
403 for (int i = 0; i < params.count(); i++) {
404 QDomElement e = params.item(i).toElement();
405 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
407 if (m_keyframes.count() > 0) {
408 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
409 while (i != m_keyframes.constEnd()) {
410 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
414 // Effect has a keyframe type parameter, we need to set the values
415 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
416 e.setAttribute("keyframes", keyframes);
422 QDomElement ClipItem::selectedEffect()
424 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
425 return effectAt(m_selectedEffect);
428 void ClipItem::resetThumbs(bool clearExistingThumbs)
430 if (clearExistingThumbs) {
431 m_startPix = QPixmap();
432 m_endPix = QPixmap();
433 m_audioThumbCachePic.clear();
439 void ClipItem::refreshClip(bool checkDuration)
441 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
442 m_maxDuration = m_clip->maxDuration();
443 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
444 if (m_maxDuration != GenTime() && m_info.cropStart + m_info.cropDuration > m_maxDuration) {
445 // Clip duration changed, make sure to stay in correct range
446 if (m_info.cropStart > m_maxDuration) {
447 m_info.cropStart = GenTime();
448 m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
449 updateRectGeometry();
451 m_info.cropDuration = m_maxDuration;
452 updateRectGeometry();
457 if (m_clipType == COLOR) {
458 QString colour = m_clip->getProperty("colour");
459 colour = colour.replace(0, 2, "#");
460 m_baseColor = QColor(colour.left(7));
461 } else resetThumbs(checkDuration);
464 void ClipItem::slotFetchThumbs()
466 if (scene() == NULL || m_clipType == AUDIO || m_clipType == COLOR) return;
467 if (m_clipType == IMAGE) {
468 if (m_startPix.isNull()) {
469 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
475 if (m_clipType == TEXT) {
476 if (m_startPix.isNull()) slotGetStartThumb();
480 if (m_endPix.isNull() && m_startPix.isNull()) {
481 m_startThumbRequested = true;
482 m_endThumbRequested = true;
483 emit getThumb((int)m_speedIndependantInfo.cropStart.frames(m_fps), (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
485 if (m_endPix.isNull()) {
488 if (m_startPix.isNull()) {
494 void ClipItem::slotGetStartThumb()
496 m_startThumbRequested = true;
497 emit getThumb((int)m_speedIndependantInfo.cropStart.frames(m_fps), -1);
500 void ClipItem::slotGetEndThumb()
502 m_endThumbRequested = true;
503 emit getThumb(-1, (int)(m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1);
507 void ClipItem::slotSetStartThumb(QImage img)
509 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
510 QPixmap pix = QPixmap::fromImage(img);
512 QRectF r = sceneBoundingRect();
513 r.setRight(pix.width() + 2);
518 void ClipItem::slotSetEndThumb(QImage img)
520 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
521 QPixmap pix = QPixmap::fromImage(img);
523 QRectF r = sceneBoundingRect();
524 r.setLeft(r.right() - pix.width() - 2);
529 void ClipItem::slotThumbReady(int frame, QImage img)
531 if (scene() == NULL) return;
532 QRectF r = boundingRect();
533 QPixmap pix = QPixmap::fromImage(img);
534 double width = pix.width() / projectScene()->scale().x();
535 if (m_startThumbRequested && frame == m_speedIndependantInfo.cropStart.frames(m_fps)) {
537 m_startThumbRequested = false;
538 update(r.left(), r.top(), width, pix.height());
539 if (m_clipType == IMAGE || m_clipType == TEXT) {
540 update(r.right() - width, r.top(), width, pix.height());
542 } else if (m_endThumbRequested && frame == (m_speedIndependantInfo.cropStart + m_speedIndependantInfo.cropDuration).frames(m_fps) - 1) {
544 m_endThumbRequested = false;
545 update(r.right() - width, r.top(), width, pix.height());
549 void ClipItem::slotSetStartThumb(const QPixmap pix)
554 void ClipItem::slotSetEndThumb(const QPixmap pix)
559 QPixmap ClipItem::startThumb() const
564 QPixmap ClipItem::endThumb() const
569 void ClipItem::slotGotAudioData()
571 m_audioThumbReady = true;
572 if (m_clipType == AV && !isAudioOnly()) {
573 QRectF r = boundingRect();
574 r.setTop(r.top() + r.height() / 2 - 1);
579 int ClipItem::type() const
584 DocClipBase *ClipItem::baseClip() const
589 QDomElement ClipItem::xml() const
591 QDomElement xml = m_clip->toXML();
592 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
593 if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
594 if (m_audioOnly) xml.setAttribute("audio_only", 1);
595 else if (m_videoOnly) xml.setAttribute("video_only", 1);
599 int ClipItem::clipType() const
604 QString ClipItem::clipName() const
609 void ClipItem::setClipName(const QString &name)
614 const QString ClipItem::clipProducer() const
619 void ClipItem::flashClip()
621 if (m_timeLine == 0) {
622 m_timeLine = new QTimeLine(750, this);
623 m_timeLine->setUpdateInterval(80);
624 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
625 m_timeLine->setFrameRange(0, 100);
626 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
628 //m_timeLine->start();
631 void ClipItem::animate(qreal /*value*/)
633 QRectF r = boundingRect();
639 void ClipItem::paint(QPainter *painter,
640 const QStyleOptionGraphicsItem *option,
644 if (parentItem()) paintColor = QColor(255, 248, 149);
645 else paintColor = m_baseColor;
646 if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
648 painter->setMatrixEnabled(false);
649 const QRectF mapped = painter->matrix().mapRect(rect()).adjusted(0.5, 0, 0.5, 0);
650 const QRectF exposed = option->exposedRect;
651 painter->setClipRect(mapped);
652 painter->fillRect(mapped, paintColor);
655 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
656 QPen pen = painter->pen();
657 pen.setColor(QColor(255, 255, 255, 150));
658 const QRectF source(0.0, 0.0, (double) m_startPix.width(), (double) m_startPix.height());
659 painter->setPen(pen);
660 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
661 const QPointF top = mapped.topRight() - QPointF(m_startPix.width() - 1, 0);
662 painter->drawPixmap(top, m_startPix);
663 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
664 painter->drawLine(l2);
665 } else if (!m_endPix.isNull()) {
666 const QPointF top = mapped.topRight() - QPointF(m_endPix.width() - 1, 0);
667 painter->drawPixmap(top, m_endPix);
668 QLineF l2(top.x(), mapped.top(), top.x(), mapped.bottom());
669 painter->drawLine(l2);
671 if (!m_startPix.isNull()) {
672 painter->drawPixmap(mapped.topLeft(), m_startPix);
673 QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
674 painter->drawLine(l2);
676 painter->setPen(Qt::black);
679 // draw audio thumbnails
680 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (rect().height() / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
682 double startpixel = exposed.left();
685 double endpixel = exposed.right();
688 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
690 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
692 if (m_clipType == AV && !isAudioOnly()) {
694 mappedRect.setTop(mappedRect.bottom() - mapped.height() / 2);
695 } else mappedRect = mapped;
697 double scale = painter->matrix().m11();
698 int channels = baseClip()->getProperty("channels").toInt();
699 if (scale != m_framePixelWidth)
700 m_audioThumbCachePic.clear();
701 double cropLeft = m_info.cropStart.frames(m_fps);
702 const int clipStart = mappedRect.x();
703 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
704 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
705 cropLeft = cropLeft * scale;
708 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
711 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
712 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
713 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
717 // Draw effects names
718 if (!m_effectNames.isEmpty() && mapped.width() > 40) {
719 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
721 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
722 qreal value = m_timeLine->currentValue();
723 txtBounding.setWidth(txtBounding.width() * value);
724 bgColor.setRgb(50 + 200 *(1.0 - value), 50, 50, 100 + 50 * value);
725 } else bgColor.setRgb(50, 50, 90, 180);
727 QPainterPath rounded;
728 rounded.moveTo(txtBounding.bottomRight());
729 rounded.arcTo(txtBounding.right() - txtBounding.height() - 2, txtBounding.top() - txtBounding.height(), txtBounding.height() * 2, txtBounding.height() * 2, 270, 90);
730 rounded.lineTo(txtBounding.topLeft());
731 rounded.lineTo(txtBounding.bottomLeft());
732 painter->fillPath(rounded, bgColor);
733 painter->setPen(Qt::lightGray);
734 painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_effectNames);
738 QColor frameColor(paintColor.darker());
739 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
740 frameColor = QColor(Qt::red);
742 frameColor.setAlpha(160);
744 const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
745 //painter->fillRect(txtBounding2, frameColor);
746 painter->setBrush(frameColor);
747 painter->setPen(Qt::NoPen);
748 painter->drawRoundedRect(txtBounding2, 3, 3);
749 painter->setBrush(QBrush(Qt::NoBrush));
751 //painter->setPen(QColor(0, 0, 0, 180));
752 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
754 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_videoPix);
755 } else if (m_audioOnly) {
756 painter->drawPixmap(txtBounding2.topLeft() - QPointF(17, -1), m_audioPix);
758 painter->setPen(Qt::white);
759 painter->drawText(txtBounding2, Qt::AlignCenter, m_clipName);
763 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
764 QList < CommentedTime >::Iterator it = markers.begin();
767 QBrush markerBrush(QColor(120, 120, 0, 140));
768 QPen pen = painter->pen();
769 pen.setColor(QColor(255, 255, 255, 200));
770 pen.setStyle(Qt::DotLine);
772 for (; it != markers.end(); ++it) {
773 pos = GenTime((int)((*it).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
774 if (pos > GenTime()) {
775 if (pos > cropDuration()) break;
776 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
777 QLineF l2 = painter->matrix().map(l);
778 //framepos = scale * pos.frames(m_fps);
779 //QLineF l(framepos, 5, framepos, itemHeight - 5);
780 painter->setPen(pen);
781 painter->drawLine(l2);
782 if (KdenliveSettings::showmarkers()) {
783 framepos = rect().x() + pos.frames(m_fps);
784 const QRectF r1(framepos + 0.04, 10, rect().width() - framepos - 2, rect().height() - 10);
785 const QRectF r2 = painter->matrix().mapRect(r1);
786 const QRectF txtBounding3 = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
787 painter->setBrush(markerBrush);
788 painter->setPen(Qt::NoPen);
789 painter->drawRoundedRect(txtBounding3, 3, 3);
790 painter->setBrush(QBrush(Qt::NoBrush));
791 painter->setPen(Qt::white);
792 painter->drawText(txtBounding3, Qt::AlignCenter, (*it).comment());
794 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
798 // draw start / end fades
801 fades = QBrush(QColor(200, 50, 50, 150));
802 } else fades = QBrush(QColor(200, 200, 200, 200));
804 if (m_startFade != 0) {
805 QPainterPath fadeInPath;
806 fadeInPath.moveTo(0, 0);
807 fadeInPath.lineTo(0, rect().height());
808 fadeInPath.lineTo(m_startFade, 0);
809 fadeInPath.closeSubpath();
810 QPainterPath f1 = painter->matrix().map(fadeInPath);
811 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
812 /*if (isSelected()) {
813 QLineF l(m_startFade * scale, 0, 0, itemHeight);
814 painter->drawLine(l);
817 if (m_endFade != 0) {
818 QPainterPath fadeOutPath;
819 fadeOutPath.moveTo(rect().width(), 0);
820 fadeOutPath.lineTo(rect().width(), rect().height());
821 fadeOutPath.lineTo(rect().width() - m_endFade, 0);
822 fadeOutPath.closeSubpath();
823 QPainterPath f1 = painter->matrix().map(fadeOutPath);
824 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
825 /*if (isSelected()) {
826 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
827 painter->drawLine(l);
832 painter->setPen(QPen(Qt::lightGray));
833 // draw effect or transition keyframes
834 if (mapped.width() > 20) drawKeyFrames(painter, exposed);
836 //painter->setMatrixEnabled(true);
839 // expand clip rect to allow correct painting of clip border
840 QPen pen1(frameColor);
841 painter->setPen(pen1);
842 painter->setClipping(false);
843 painter->drawRect(painter->matrix().mapRect(rect()));
847 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
849 if (isItemLocked()) return NONE;
850 const double scale = projectScene()->scale().x();
851 double maximumOffset = 6 / scale;
852 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
853 m_editedKeyframe = mouseOverKeyFrames(pos, maximumOffset);
854 if (m_editedKeyframe != -1) return KEYFRAME;
856 QRectF rect = sceneBoundingRect();
857 int addtransitionOffset = 10;
858 // Don't allow add transition if track height is very small
859 if (rect.height() < 30) addtransitionOffset = 0;
861 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
862 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
863 // xgettext:no-c-format
864 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
866 } else if (pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
867 // xgettext:no-c-format
868 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
870 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
871 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
872 // xgettext:no-c-format
873 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
875 } else if ((rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
876 // xgettext:no-c-format
877 setToolTip(i18n("Clip duration: %1s", cropDuration().seconds()));
879 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
880 setToolTip(i18n("Add transition"));
881 return TRANSITIONSTART;
882 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
883 setToolTip(i18n("Add transition"));
884 return TRANSITIONEND;
886 setToolTip(QString());
890 QList <GenTime> ClipItem::snapMarkers() const
892 QList < GenTime > snaps;
893 QList < GenTime > markers = baseClip()->snapMarkers();
896 for (int i = 0; i < markers.size(); i++) {
898 pos = GenTime((int)(markers.at(i).frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
899 if (pos > GenTime()) {
900 if (pos > cropDuration()) break;
901 else snaps.append(pos + startPos());
907 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
909 QList < CommentedTime > snaps;
910 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
913 for (int i = 0; i < markers.size(); i++) {
914 pos = GenTime((int)(markers.at(i).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
915 if (pos > GenTime()) {
916 if (pos > cropDuration()) break;
917 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
923 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
925 QRectF re = sceneBoundingRect();
926 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
928 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
929 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
931 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
932 //kDebug() << "creating " << startCache;
933 //if (framePixelWidth!=pixelForOneFrame ||
934 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
936 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
937 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
938 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
940 bool fullAreaDraw = pixelForOneFrame < 10;
941 QMap<int, QPainterPath > positiveChannelPaths;
942 QMap<int, QPainterPath > negativeChannelPaths;
943 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
945 audiopen.setWidth(0);
946 pixpainter.setPen(audiopen);
947 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
948 //pixpainter.drawLine(0,0,100,re.height());
949 // Bail out, if caller provided invalid data
951 kWarning() << "Unable to draw image with " << channels << "number of channels";
955 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
957 for (int i = 0; i < channels; i++) {
959 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
960 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
963 for (int samples = 0; samples <= 100; samples++) {
964 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
965 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
966 if (frame < 0 || sample < 0 || sample > 19)
968 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
970 for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
972 int y = channelHeight * channel + channelHeight / 2;
973 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
975 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
976 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
978 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
979 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
982 for (int channel = 0; channel < channels ; channel++)
983 if (fullAreaDraw && samples == 100) {
984 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
985 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
986 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
987 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
991 pixpainter.setPen(QPen(QColor(0, 0, 0)));
992 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
994 for (int i = 0; i < channels; i++) {
996 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
997 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
999 pixpainter.drawPath(positiveChannelPaths[i]);
1002 //audioThumbWasDrawn=true;
1003 m_framePixelWidth = pixelForOneFrame;
1008 int ClipItem::fadeIn() const
1013 int ClipItem::fadeOut() const
1019 void ClipItem::setFadeIn(int pos)
1021 if (pos == m_startFade) return;
1022 int oldIn = m_startFade;
1023 if (pos < 0) pos = 0;
1024 if (pos > cropDuration().frames(m_fps)) pos = (int)(cropDuration().frames(m_fps));
1026 QRectF rect = boundingRect();
1027 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1030 void ClipItem::setFadeOut(int pos)
1032 if (pos == m_endFade) return;
1033 int oldOut = m_endFade;
1034 if (pos < 0) pos = 0;
1035 if (pos > cropDuration().frames(m_fps)) pos = (int)(cropDuration().frames(m_fps));
1037 QRectF rect = boundingRect();
1038 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1044 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1046 //if (e->pos().x() < 20) m_hover = true;
1048 if (isItemLocked()) return;
1050 QRectF r = boundingRect();
1051 double width = 35 / projectScene()->scale().x();
1052 double height = r.height() / 2;
1053 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1054 update(r.x(), r.y() + height, width, height);
1055 update(r.right() - width, r.y() + height, width, height);
1059 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1061 if (isItemLocked()) return;
1063 QRectF r = boundingRect();
1064 double width = 35 / projectScene()->scale().x();
1065 double height = r.height() / 2;
1066 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1067 update(r.x(), r.y() + height, width, height);
1068 update(r.right() - width, r.y() + height, width, height);
1072 void ClipItem::resizeStart(int posx)
1074 const int min = (startPos() - cropStart()).frames(m_fps);
1075 if (posx < min) posx = min;
1076 if (posx == startPos().frames(m_fps)) return;
1077 const int previous = cropStart().frames(m_fps);
1078 AbstractClipItem::resizeStart(posx);
1080 // set speed independant info
1081 m_speedIndependantInfo = m_info;
1082 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
1083 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
1085 if ((int) cropStart().frames(m_fps) != previous) {
1086 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1087 m_startThumbTimer.start(150);
1092 void ClipItem::resizeEnd(int posx)
1094 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1095 if (posx > max && maxDuration() != GenTime()) posx = max;
1096 if (posx == endPos().frames(m_fps)) return;
1097 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1098 const int previous = cropDuration().frames(m_fps);
1099 AbstractClipItem::resizeEnd(posx);
1101 // set speed independant info
1102 m_speedIndependantInfo = m_info;
1103 m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
1104 m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
1106 if ((int) cropDuration().frames(m_fps) != previous) {
1107 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1108 m_endThumbTimer.start(150);
1114 bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1116 bool modified = false;
1117 for (int i = 0; i < m_effectList.count(); i++) {
1118 QDomElement effect = m_effectList.at(i);
1119 QDomNodeList params = effect.elementsByTagName("parameter");
1120 for (int j = 0; j < params.count(); j++) {
1121 QDomElement e = params.item(i).toElement();
1122 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
1123 // parse keyframes and adjust values
1124 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1125 QMap <int, double> kfr;
1128 foreach(const QString &str, keyframes) {
1129 pos = str.section(':', 0, 0).toInt();
1130 val = str.section(':', 1, 1).toDouble();
1131 if (pos == previous) {
1135 if ((fromStart && pos >= current) || (!fromStart && pos <= current)) {
1143 QMap<int, double>::const_iterator k = kfr.constBegin();
1144 while (k != kfr.constEnd()) {
1145 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1148 e.setAttribute("keyframes", newkfr);
1154 if (modified && m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1159 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1161 if (change == QGraphicsItem::ItemSelectedChange) {
1162 if (value.toBool()) setZValue(10);
1165 if (change == ItemPositionChange && scene()) {
1166 // calculate new position.
1167 //if (parentItem()) return pos();
1168 QPointF newPos = value.toPointF();
1169 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1170 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1171 xpos = qMax(xpos, 0);
1173 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1174 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1175 newTrack = qMax(newTrack, 0);
1176 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1177 // Only one clip is moving
1178 QRectF sceneShape = rect();
1179 sceneShape.translate(newPos);
1180 QList<QGraphicsItem*> items;
1181 if (projectScene()->editMode() == NORMALEDIT)
1182 items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1183 items.removeAll(this);
1184 bool forwardMove = newPos.x() > pos().x();
1186 if (!items.isEmpty()) {
1187 for (int i = 0; i < items.count(); i++) {
1188 if (!items.at(i)->isEnabled()) continue;
1189 if (items.at(i)->type() == type()) {
1191 QPointF otherPos = items.at(i)->pos();
1192 if ((int) otherPos.y() != (int) pos().y()) {
1196 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1198 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1203 sceneShape.translate(QPointF(-offset, 0));
1204 newPos.setX(newPos.x() - offset);
1206 sceneShape.translate(QPointF(offset, 0));
1207 newPos.setX(newPos.x() + offset);
1209 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1210 subitems.removeAll(this);
1211 for (int j = 0; j < subitems.count(); j++) {
1212 if (!subitems.at(j)->isEnabled()) continue;
1213 if (subitems.at(j)->type() == type()) {
1214 // move was not successful, revert to previous pos
1215 m_info.startPos = GenTime((int) pos().x(), m_fps);
1221 m_info.track = newTrack;
1222 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1228 m_info.track = newTrack;
1229 m_info.startPos = GenTime((int) newPos.x(), m_fps);
1230 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1233 return QGraphicsItem::itemChange(change, value);
1237 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1240 int ClipItem::effectsCounter()
1242 return effectsCount() + 1;
1245 int ClipItem::effectsCount()
1247 return m_effectList.count();
1250 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1252 return m_effectList.hasEffect(tag, id);
1255 QStringList ClipItem::effectNames()
1257 return m_effectList.effectNames();
1260 QDomElement ClipItem::effectAt(int ix) const
1262 if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
1263 return m_effectList.at(ix).cloneNode().toElement();
1266 QDomElement ClipItem::getEffectAt(int ix) const
1268 if (ix > m_effectList.count() - 1 || ix < 0 || m_effectList.at(ix).isNull()) return QDomElement();
1269 return m_effectList.at(ix);
1272 void ClipItem::setEffectAt(int ix, QDomElement effect)
1274 if (ix < 0 || ix > (m_effectList.count() - 1) || effect.isNull()) {
1275 kDebug() << "Invalid effect index: " << ix;
1278 //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1279 effect.setAttribute("kdenlive_ix", ix + 1);
1280 m_effectList.replace(ix, effect);
1281 m_effectNames = m_effectList.effectNames().join(" / ");
1282 QString id = effect.attribute("id");
1283 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1286 QRectF r = boundingRect();
1292 EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animate*/)
1294 bool needRepaint = false;
1296 if (!effect.hasAttribute("kdenlive_ix")) {
1297 ix = effectsCounter();
1298 } else ix = effect.attribute("kdenlive_ix").toInt();
1299 if (!m_effectList.isEmpty() && ix <= m_effectList.count()) {
1301 m_effectList.insert(ix - 1, effect);
1302 for (int i = ix; i < m_effectList.count(); i++) {
1303 int index = m_effectList.item(i).attribute("kdenlive_ix").toInt();
1304 if (index >= ix) m_effectList.item(i).setAttribute("kdenlive_ix", index + 1);
1306 } else m_effectList.append(effect);
1307 EffectsParameterList parameters;
1308 parameters.addParam("tag", effect.attribute("tag"));
1309 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1310 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1311 if (effect.hasAttribute("disabled")) parameters.addParam("disabled", effect.attribute("disabled"));
1314 QString effectId = effect.attribute("id");
1315 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1316 parameters.addParam("id", effectId);
1318 QDomNodeList params = effect.elementsByTagName("parameter");
1320 for (int i = 0; i < params.count(); i++) {
1321 QDomElement e = params.item(i).toElement();
1323 if (e.attribute("type") == "simplekeyframe") {
1324 QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1325 double factor = e.attribute("factor", "1").toDouble();
1327 for (int j = 0; j < values.count(); j++) {
1328 QString pos = values.at(j).section(":", 0, 0);
1329 double val = values.at(j).section(":", 1, 1).toDouble() / factor;
1330 values[j] = pos + "=" + QString::number(val);
1333 parameters.addParam(e.attribute("name"), values.join(";"));
1334 /*parameters.addParam("max", e.attribute("max"));
1335 parameters.addParam("min", e.attribute("min"));
1336 parameters.addParam("factor", );*/
1337 } else if (e.attribute("type") == "keyframe") {
1338 parameters.addParam("keyframes", e.attribute("keyframes"));
1339 parameters.addParam("max", e.attribute("max"));
1340 parameters.addParam("min", e.attribute("min"));
1341 parameters.addParam("factor", e.attribute("factor", "1"));
1342 parameters.addParam("starttag", e.attribute("starttag", "start"));
1343 parameters.addParam("endtag", e.attribute("endtag", "end"));
1346 if (e.attribute("factor", "1") == "1") {
1347 parameters.addParam(e.attribute("name"), e.attribute("value"));
1349 // check if it is a fade effect
1350 if (effectId == "fadein") {
1352 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1353 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1354 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1356 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1357 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1358 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1360 } else if (effectId == "fade_from_black") {
1362 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1363 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1364 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1366 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1367 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1368 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1370 } else if (effectId == "fadeout") {
1372 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1373 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1374 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1376 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1377 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1378 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1380 } else if (effectId == "fade_to_black") {
1382 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1383 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1384 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1386 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1387 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1388 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1393 if (e.attribute("factor").startsWith('%')) {
1394 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1395 } else fact = e.attribute("factor", "1").toDouble();
1396 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
1400 m_effectNames = m_effectList.effectNames().join(" / ");
1401 if (fade > 0) m_startFade = fade;
1402 else if (fade < 0) m_endFade = -fade;
1404 if (m_selectedEffect == -1) {
1405 setSelectedEffect(0);
1406 } else if (m_selectedEffect == ix - 1) setSelectedEffect(m_selectedEffect);
1407 if (needRepaint) update(boundingRect());
1411 else { /*if (!needRepaint) */
1412 QRectF r = boundingRect();
1419 EffectsParameterList ClipItem::getEffectArgs(const QDomElement effect)
1421 EffectsParameterList parameters;
1422 parameters.addParam("tag", effect.attribute("tag"));
1423 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1424 parameters.addParam("id", effect.attribute("id"));
1425 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1426 if (effect.hasAttribute("disabled")) parameters.addParam("disabled", effect.attribute("disabled"));
1428 QDomNodeList params = effect.elementsByTagName("parameter");
1429 for (int i = 0; i < params.count(); i++) {
1430 QDomElement e = params.item(i).toElement();
1431 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1432 if (e.attribute("type") == "simplekeyframe") {
1434 QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1435 double factor = e.attribute("factor", "1").toDouble();
1436 for (int j = 0; j < values.count(); j++) {
1437 QString pos = values.at(j).section(":", 0, 0);
1438 double val = values.at(j).section(":", 1, 1).toDouble() / factor;
1439 values[j] = pos + "=" + QString::number(val);
1441 // kDebug() << "/ / / /SENDING KEYFR:" << values;
1442 parameters.addParam(e.attribute("name"), values.join(";"));
1443 /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
1444 parameters.addParam("max", e.attribute("max"));
1445 parameters.addParam("min", e.attribute("min"));
1446 parameters.addParam("factor", e.attribute("factor", "1"));*/
1447 } else if (e.attribute("type") == "keyframe") {
1448 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1449 parameters.addParam("keyframes", e.attribute("keyframes"));
1450 parameters.addParam("max", e.attribute("max"));
1451 parameters.addParam("min", e.attribute("min"));
1452 parameters.addParam("factor", e.attribute("factor", "1"));
1453 parameters.addParam("starttag", e.attribute("starttag", "start"));
1454 parameters.addParam("endtag", e.attribute("endtag", "end"));
1455 } else if (e.attribute("namedesc").contains(';')) {
1456 QString format = e.attribute("format");
1457 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1458 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1460 QTextStream txtNeu(&neu);
1461 if (values.size() > 0)
1462 txtNeu << (int)values[0].toDouble();
1463 for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
1464 txtNeu << separators[i];
1465 txtNeu << (int)(values[i+1].toDouble());
1467 parameters.addParam("start", neu);
1469 if (e.attribute("factor", "1") != "1") {
1471 if (e.attribute("factor").startsWith('%')) {
1472 fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
1473 } else fact = e.attribute("factor", "1").toDouble();
1474 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
1476 parameters.addParam(e.attribute("name"), e.attribute("value"));
1483 void ClipItem::deleteEffect(QString index)
1485 bool needRepaint = false;
1488 for (int i = 0; i < m_effectList.count(); ++i) {
1489 ix = m_effectList.at(i).attribute("kdenlive_ix");
1491 QString effectId = m_effectList.at(i).attribute("id");
1492 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1493 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1496 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1497 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1500 } else if (EffectsList::hasKeyFrames(m_effectList.at(i))) needRepaint = true;
1501 m_effectList.removeAt(i);
1503 } else if (ix.toInt() > index.toInt()) {
1504 m_effectList.item(i).setAttribute("kdenlive_ix", ix.toInt() - 1);
1507 m_effectNames = m_effectList.effectNames().join(" / ");
1509 if (m_effectList.isEmpty() || m_selectedEffect + 1 == index.toInt()) {
1510 // Current effect was removed
1511 if (index.toInt() > m_effectList.count() - 1) {
1512 setSelectedEffect(m_effectList.count() - 1);
1513 } else setSelectedEffect(index.toInt());
1515 if (needRepaint) update(boundingRect());
1517 QRectF r = boundingRect();
1521 //if (!m_effectList.isEmpty()) flashClip();
1524 double ClipItem::speed() const
1529 int ClipItem::strobe() const
1534 void ClipItem::setSpeed(const double speed, const int strobe)
1538 if (m_speed == 1.0) m_clipName = baseClip()->name();
1539 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1540 m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / m_speed + 0.5), m_fps);
1541 m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / m_speed + 0.5), m_fps);
1545 GenTime ClipItem::maxDuration() const
1547 return GenTime((int)(m_maxDuration.frames(m_fps) / m_speed + 0.5), m_fps);
1550 GenTime ClipItem::speedIndependantCropStart() const
1552 return m_speedIndependantInfo.cropStart;
1555 GenTime ClipItem::speedIndependantCropDuration() const
1557 return m_speedIndependantInfo.cropDuration;
1561 const ItemInfo ClipItem::speedIndependantInfo() const
1563 return m_speedIndependantInfo;
1567 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1569 const QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1571 doc.setContent(effects, true);
1572 const QDomElement e = doc.documentElement();
1573 if (scene() && !scene()->views().isEmpty()) {
1575 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1576 if (view) view->slotAddEffect(e, m_info.startPos, track());
1581 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1583 if (isItemLocked()) event->setAccepted(false);
1584 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1587 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1592 void ClipItem::addTransition(Transition* t)
1594 m_transitionsList.append(t);
1595 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1597 QDomElement e = doc.documentElement();
1598 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1601 void ClipItem::setVideoOnly(bool force)
1603 m_videoOnly = force;
1606 void ClipItem::setAudioOnly(bool force)
1608 m_audioOnly = force;
1609 if (m_audioOnly) m_baseColor = QColor(141, 215, 166);
1611 if (m_clipType == COLOR) {
1612 QString colour = m_clip->getProperty("colour");
1613 colour = colour.replace(0, 2, "#");
1614 m_baseColor = QColor(colour.left(7));
1615 } else if (m_clipType == AUDIO) m_baseColor = QColor(141, 215, 166);
1616 else m_baseColor = QColor(141, 166, 215);
1618 m_audioThumbCachePic.clear();
1621 bool ClipItem::isAudioOnly() const
1626 bool ClipItem::isVideoOnly() const
1632 #include "clipitem.moc"