ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, bool generateThumbs)
- : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(1.0), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) {
+ : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(1.0), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) {
setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (qreal)(KdenliveSettings::trackheight() - 2));
setPos((qreal) info.startPos.frames(fps), (qreal)(info.track * KdenliveSettings::trackheight()) + 1);
if (info.cropStart == cropStart()) duplicate->slotSetStartThumb(m_startPix);
if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
- duplicate->setEffectList(m_effectList);
+ duplicate->setEffectList(m_effectList.clone());
duplicate->setSpeed(m_speed);
return duplicate;
}
}
}
+bool ClipItem::checkKeyFrames() {
+ bool clipEffectsModified = false;
+ for (int ix = 0; ix < m_effectList.count(); ix ++) {
+ QString kfr = keyframes(ix);
+ if (!kfr.isEmpty()) {
+ const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
+ QStringList newKeyFrames;
+ bool cutKeyFrame = false;
+ bool modified = false;
+ int lastPos = -1;
+ double lastValue = -1;
+ int start = m_cropStart.frames(m_fps);
+ int end = (m_cropStart + m_cropDuration).frames(m_fps);
+ foreach(const QString str, keyframes) {
+ int pos = str.section(":", 0, 0).toInt();
+ double val = str.section(":", 1, 1).toDouble();
+ if (pos - start < 0) {
+ // a keyframe is defined before the start of the clip
+ cutKeyFrame = true;
+ } else if (cutKeyFrame) {
+ // create new keyframe at clip start, calculate interpolated value
+ if (pos > start) {
+ int diff = pos - lastPos;
+ double ratio = (double)(start - lastPos) / diff;
+ double newValue = lastValue + (val - lastValue) * ratio;
+ newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
+ modified = true;
+ }
+ cutKeyFrame = false;
+ }
+ if (!cutKeyFrame) {
+ if (pos > end) {
+ // create new keyframe at clip end, calculate interpolated value
+ int diff = pos - lastPos;
+ if (diff != 0) {
+ double ratio = (double)(end - lastPos) / diff;
+ double newValue = lastValue + (val - lastValue) * ratio;
+ newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
+ modified = true;
+ }
+ break;
+ } else {
+ newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
+ }
+ }
+ lastPos = pos;
+ lastValue = val;
+ }
+ if (modified) {
+ // update KeyFrames
+ setKeyframes(ix, newKeyFrames.join(";"));
+ clipEffectsModified = true;
+ }
+ }
+ }
+ return clipEffectsModified;
+}
+
void ClipItem::setKeyframes(const int ix, const QString keyframes) {
QDomElement effect = effectAt(ix);
if (effect.attribute("disabled") == "1") return;
double maximumOffset;
if (scale > 3) maximumOffset = 25 / scale;
else maximumOffset = 6 / scale;
- QMatrix matrix;
- matrix.scale(scale, 0);
+
//kDebug()<<"// Item rect: "<<rect.x()<<". pos. "<<pos.x()<<", scale: "<<scale<<", ratio: "<<qAbs((int)(pos.x() - rect.x())) / scale;
if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
}
}
-void ClipItem::resizeEnd(int posx) {
+void ClipItem::resizeEnd(int posx, bool updateKeyFrames) {
const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
if (posx > max) posx = max;
if (posx == endPos().frames(m_fps)) return;
const int previous = (cropStart() + duration()).frames(m_fps);
AbstractClipItem::resizeEnd(posx);
- checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
+ if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
/*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
endThumbTimer->start(100);
// parse keyframes and adjust values
const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
QMap <int, double> kfr;
+ int pos;
+ double val;
foreach(const QString str, keyframes) {
- int pos = str.section(":", 0, 0).toInt();
- double val = str.section(":", 1, 1).toDouble();
+ pos = str.section(":", 0, 0).toInt();
+ val = str.section(":", 1, 1).toDouble();
if (pos == previous) kfr[current] = val;
else {
if (fromStart && pos >= current) kfr[pos] = val;
}*/
int ClipItem::effectsCounter() {
- return m_effectsCounter++;
+ return effectsCount() + 1;
}
int ClipItem::effectsCount() {
void ClipItem::setEffectAt(int ix, QDomElement effect) {
kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
+ effect.setAttribute("kdenlive_ix", ix + 1);
m_effectList.insert(ix, effect);
m_effectList.removeAt(ix + 1);
m_effectNames = m_effectList.effectNames().join(" / ");
bool needRepaint = false;
/*QDomDocument doc;
doc.appendChild(doc.importNode(effect, true));
- kDebug() << "/////// CLIP ADD EFFECT: "<< doc.toString();*/
+ kDebug() << "/////// CLIP ADD EFFECT: " << doc.toString();*/
m_effectList.append(effect);
effectParams["tag"] = effect.attribute("tag");
QString effectId = effect.attribute("id");
else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
}
} else {
- effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / f);
+ effectParams[e.attribute("name")] = QString::number(e.attribute("value").toDouble() / f);
}
}
}
void ClipItem::deleteEffect(QString index) {
bool needRepaint = false;
+ QString ix;
for (int i = 0; i < m_effectList.size(); ++i) {
- if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
+ ix = m_effectList.at(i).attribute("kdenlive_ix");
+ if (ix == index) {
if (m_effectList.at(i).attribute("id") == "fadein") {
m_startFade = 0;
needRepaint = true;
needRepaint = true;
}
m_effectList.removeAt(i);
- break;
- }
+ } else if (ix.toInt() > index.toInt()) m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
}
m_effectNames = m_effectList.effectNames().join(" / ");
if (needRepaint) update(boundingRect());