]> git.sesse.net Git - kdenlive/commitdiff
Fix issues with changing clip speed:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 23 Feb 2009 21:27:14 +0000 (21:27 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 23 Feb 2009 21:27:14 +0000 (21:27 +0000)
http://www.kdenlive.org:80/mantis/view.php?id=670

svn path=/branches/KDE4/; revision=3071

src/clipitem.cpp
src/customtrackview.cpp
src/renderer.cpp

index d0cf6bec8be185426428ab366386d8035c86776d..5d10de57a48cd7929969ca71b18a0d5ddeb68b8e 100644 (file)
@@ -113,7 +113,7 @@ ClipItem::~ClipItem() {
 
 ClipItem *ClipItem::clone(ItemInfo info) const {
     ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
-    if (info.cropStart == cropStart()) duplicate->slotSetStartThumb(m_startPix);
+    if (info.cropStart == m_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.clone());
@@ -159,14 +159,14 @@ void ClipItem::initEffect(QDomElement effect) {
         if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
             int end = (duration() + cropStart()).frames(m_fps);
             int start = end;
-            if (effect.attribute("id") == "fadeout" ) {
+            if (effect.attribute("id") == "fadeout") {
                 if (m_effectList.hasEffect("", "fade_to_black") == -1) {
                     start -= EffectsList::parameter(effect, "in").toInt();
                 } else {
                     QDomElement fadeout = m_effectList.getEffectByTag("", "fade_to_black");
                     start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
                 }
-            } else if (effect.attribute("id") == "fade_to_black" ) {
+            } else if (effect.attribute("id") == "fade_to_black") {
                 if (m_effectList.hasEffect("", "fadeout") == -1) {
                     start -= EffectsList::parameter(effect, "in").toInt();
                 } else {
@@ -179,12 +179,12 @@ void ClipItem::initEffect(QDomElement effect) {
         } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
             int start = cropStart().frames(m_fps);
             int end = start;
-            if (effect.attribute("id") == "fadein" ) {
+            if (effect.attribute("id") == "fadein") {
                 if (m_effectList.hasEffect("", "fade_from_black") == -1)
                     end += EffectsList::parameter(effect, "out").toInt();
                 else
                     end += EffectsList::parameter(m_effectList.getEffectByTag("", "fade_from_black"), "out").toInt();
-            } else if (effect.attribute("id") == "fade_from_black" ) {
+            } else if (effect.attribute("id") == "fade_from_black") {
                 if (m_effectList.hasEffect("", "fadein") == -1)
                     end += EffectsList::parameter(effect, "out").toInt();
                 else
@@ -1154,7 +1154,7 @@ void ClipItem::setEffectAt(int ix, QDomElement effect) {
     m_effectList.insert(ix, effect);
     m_effectList.removeAt(ix + 1);
     m_effectNames = m_effectList.effectNames().join(" / ");
-       QString id = effect.attribute("id");
+    QString id = effect.attribute("id");
     if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
         update(boundingRect());
     else {
@@ -1326,7 +1326,7 @@ void ClipItem::deleteEffect(QString index) {
         if (ix == index) {
             QString effectId = m_effectList.at(i).attribute("id");
             if ((effectId == "fadein" && hasEffect("", "fade_from_black") == -1) ||
-                (effectId == "fade_from_black" && hasEffect("", "fadein") == -1)) {
+                    (effectId == "fade_from_black" && hasEffect("", "fadein") == -1)) {
                 m_startFade = 0;
                 needRepaint = true;
             } else if ((effectId == "fadeout" && hasEffect("", "fade_to_black") == -1) ||
index 0d03219095d5b003dd8a364651b19af6c3068494..19193cf9c55b31069e317a27205fc2902555fbc4 100644 (file)
@@ -1067,10 +1067,10 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = (ClipItem *)itemList.at(i);
-           if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") {
-               emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
-               continue;
-           }
+            if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") {
+                emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
+                continue;
+            }
             item->initEffect(effect);
             if (effect.attribute("tag") == "ladspa") {
                 QString ladpsaFile = m_document->getLadspaFile();
@@ -1175,17 +1175,22 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
             m_blockRefresh = false;
             return;
         }
+        if (item->parentItem()) {
+            // Item is part of a group, reset group
+            resetSelectionGroup();
+        }
         kDebug() << "/////////  CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
 
         m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
+        double speed = item->speed();
         newPos.startPos = cutTime;
         newPos.endPos = info.endPos;
-        newPos.cropStart = item->cropStart() + (cutTime - info.startPos);
+        if (speed == 1) newPos.cropStart = item->info().cropStart + (cutTime - info.startPos);
+        else newPos.cropStart = item->info().cropStart + (cutTime - info.startPos) * speed;
         newPos.track = info.track;
         ClipItem *dup = item->clone(newPos);
-        kDebug() << "// REsizing item to: " << cutPos;
         item->resizeEnd(cutPos, false);
         scene()->addItem(dup);
         if (item->checkKeyFrames()) slotRefreshEffects(item);
@@ -2354,9 +2359,14 @@ void CustomTrackView::changeClipSpeed() {
 void CustomTrackView::doChangeClipSpeed(ItemInfo info, const double speed, const double oldspeed, const QString &id) {
     DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
+    if (!item) {
+        kDebug() << "ERROR: Cannot find clip for speed change";
+        emit displayMessage(i18n("Cannot find clip for speed change"), ErrorMessage);
+        return;
+    }
     info.track = m_document->tracksCount() - item->track();
     int endPos = m_document->renderer()->mltChangeClipSpeed(info, speed, oldspeed, baseclip->producer());
-    //kDebug() << "//CH CLIP SPEED: " << speed << "x" << oldspeed << ", END POS: " << endPos;
+    kDebug() << "//CH CLIP SPEED: " << speed << "x" << oldspeed << ", END POS: " << endPos;
     item->setSpeed(speed);
     item->updateRectGeometry();
     if (item->cropDuration().frames(m_document->fps()) > endPos)
@@ -2672,6 +2682,10 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
         kDebug() << "----------------  ERROR, CANNOT find clip to resize at... "; // << startPos;
         return;
     }
+    if (item->parentItem()) {
+        // Item is part of a group, reset group
+        resetSelectionGroup();
+    }
     bool snap = KdenliveSettings::snaptopoints();
     KdenliveSettings::setSnaptopoints(false);
     if (resizeClipStart && start.startPos != end.startPos) {
@@ -2679,6 +2693,7 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
         bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - item->startPos());
         if (success) {
+            kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25);
             item->resizeStart((int) end.startPos.frames(m_document->fps()));
             updateClipFade(item);
         } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
@@ -3360,7 +3375,7 @@ void CustomTrackView::setInPoint() {
         return;
     }
     ItemInfo startInfo = clip->info();
-    ItemInfo endInfo = clip->info();
+    ItemInfo endInfo = startInfo;
     endInfo.startPos = GenTime(m_cursorPos, m_document->fps());
     if (endInfo.startPos >= startInfo.endPos) {
         // Check for invalid resize
index c0fc881dbfaaeb93e4a0e75a2808f6f7179dea04..5021b7aa9d093de2425f4b8e3dd4726e925067e9 100644 (file)
@@ -1731,7 +1731,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
         Mlt::Producer *cut;
         if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
             GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
-            cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
+            cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
         } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
 
         trackPlaylist.insert_at(startPos, *cut, 1);