]> git.sesse.net Git - kdenlive/commitdiff
- Fix effect update upon clip duration change
authorTill Theato <root@ttill.de>
Wed, 20 Apr 2011 09:48:20 +0000 (09:48 +0000)
committerTill Theato <root@ttill.de>
Wed, 20 Apr 2011 09:48:20 +0000 (09:48 +0000)
- Use Geometry.serialise with in and out point to update "Pan and Zoom"
- small cleanup

svn path=/trunk/kdenlive/; revision=5541

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

index 22baf363bbff70c637bfedb6bed2876190f92924..5e1851d3cbf092ca4aaa88b53a4ff776ecfb0bcf 100644 (file)
@@ -1731,7 +1731,7 @@ QList <int> ClipItem::updatePanZoom(int width, int height, int cut)
                 continue;
             if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
                 effectPositions << i;
-                updateGeometryKeyframes(effect, j, width, height, cut);
+//                 updateGeometryKeyframes(effect, j, width, height, cut);
             }
         }
     }
@@ -1810,7 +1810,7 @@ QMap<int, QDomElement> ClipItem::adjustEffectsToDuration(int width, int height,
             if (type == "geometry" && !param.hasAttribute("fixed")) {
                 if (!effects.contains(i))
                     effects[i] = effect.cloneNode().toElement();
-                updateGeometryKeyframes(effect, j, width, height, 0);
+                updateGeometryKeyframes(effect, j, width, height, oldInfo);
             } else if (type == "simplekeyframe" || type == "keyframe") {
                 if (!effects.contains(i))
                     effects[i] = effect.cloneNode().toElement();
@@ -1903,64 +1903,13 @@ bool ClipItem::updateNormalKeyframes(QDomElement parameter)
     return false;
 }
 
-void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, int cut)
+void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo)
 {
-    // TODO: properly update when clip resized from start
-
     QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement();
 
-    int in = cropStart().frames(fps());
-    int out = in + cropDuration().frames(fps());
-    int dur = out - in - 1;
-
-    effect.setAttribute("in", in);
-    effect.setAttribute("out", out);
-
-    Mlt::Geometry geometry(param.attribute("value").toUtf8().data(), dur, width, height);
-    Mlt::GeometryItem item;
-    bool endFrameAdded = false;
-    if (cut == 0) {
-        while (!geometry.next_key(&item, dur)) {
-            if (!endFrameAdded) {
-                // add keyframe at the end with interpolated value
-
-                // but only once ;)
-                endFrameAdded = true;
-
-                Mlt::GeometryItem endItem;
-                Mlt::GeometryItem interp;
-                geometry.fetch(&interp, dur - 1);
-                endItem.frame(dur - 1);
-                endItem.x(interp.x());
-                endItem.y(interp.y());
-                endItem.w(interp.w());
-                endItem.h(interp.h());
-                endItem.mix(interp.mix());
-                geometry.insert(&endItem);
-            }
-            geometry.remove(item.frame());
-        }
-    } else {
-        Mlt::Geometry origGeometry(param.attribute("value").toUtf8().data(), dur, width, height);
-        // remove keyframes before cut point
-        while (!geometry.prev_key(&item, cut - 1) && item.frame() < cut)
-            geometry.remove(item.frame());
-
-        // add a keyframe at new pos 0
-        origGeometry.fetch(&item, cut);
-        item.frame(0);
-        geometry.insert(&item);
-
-        // move exisiting keyframes by -cut
-        while (!origGeometry.next_key(&item, cut)) {
-            geometry.remove(item.frame());
-            origGeometry.remove(item.frame());
-            item.frame(item.frame() - cut);
-            geometry.insert(&item);
-        }
-    }
+    Mlt::Geometry geometry(param.attribute("value").toUtf8().data(), oldInfo.cropDuration.frames(m_fps), width, height);
 
-    param.setAttribute("value", geometry.serialise());
+    param.setAttribute("value", geometry.serialise(cropStart().frames(m_fps), (cropStart() + cropDuration()).frames(m_fps) - 1));
 }
 
 #include "clipitem.moc"
index 710a031f836c4752804c8d4c2e80c35525eff15e..9c6f4434fb02007cd84c30e2f6e6297992b23bae 100644 (file)
@@ -167,7 +167,7 @@ public:
      * 
      * Can be used for all effects using mlt_geometry with keyframes, but at the moment Pan & Zoom is the only one. */
     QList <int> updatePanZoom(int width, int height, int cut = 0);
-    void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, int cut = 0);
+    void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo);
     bool updateNormalKeyframes(QDomElement parameter);
 
     /** @brief Adjusts effects after a clip duration change. */
index 44e932e02aa0fed328abc003640a310dbb936c56..0cf15cdf4cebf03bb953c1e021ed13bbbd4649c7 100644 (file)
@@ -6663,8 +6663,7 @@ void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs)
 
 void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoCommand* command)
 {
-    QMap<int, QDomElement> effects;
-    item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo);
+    QMap<int, QDomElement> effects = item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo);
 
     if (effects.count()) {
         QMap<int, QDomElement>::const_iterator i = effects.constBegin();
index e224186e807606c50cb093ab6106f1b7ad04df16..c2e34f25f40b393696fb8e21938df07f78932230 100644 (file)
@@ -2631,10 +2631,12 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
     if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
         // This is a keyframe effect, to edit it, we remove it and re-add it.
         bool success = mltRemoveEffect(track, position, index, false);
-        if (!success) kDebug() << "// ERROR Removing effect : " << index;
-        if (position < GenTime()) success = mltAddTrackEffect(track, params);
-        else success = mltAddEffect(track, position, params);
-        if (!success) kDebug() << "// ERROR Adding effect : " << index;
+//         if (!success) kDebug() << "// ERROR Removing effect : " << index;
+        if (position < GenTime())
+            success = mltAddTrackEffect(track, params);
+        else
+            success = mltAddEffect(track, position, params);
+//         if (!success) kDebug() << "// ERROR Adding effect : " << index;
         return success;
     }
     if (position < GenTime()) {
@@ -2653,33 +2655,22 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
         return false;
     }
 
-    Mlt::Service clipService(clip->get_service());
     int duration = clip->get_playtime();
     bool doRefresh = true;
     // Check if clip is visible in monitor
     int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
-    if (diff < 0 || diff > duration) doRefresh = false;
-    delete clip;
+    if (diff < 0 || diff > duration)
+        doRefresh = false;
     m_isBlocked = true;
     int ct = 0;
-    /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
-    kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
-    while (filter) {
-        kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
-        ct++;
-        filter = clipService.filter(ct);
-    }
-    kDebug() << "++++++++++++++++++++++++++";
-    ct = 0;
-    filter = clipService.filter(ct); */
 
-    Mlt::Filter *filter = clipService.filter(ct);
+    Mlt::Filter *filter = clip->filter(ct);
     while (filter) {
         if (filter->get_int("kdenlive_ix") == index.toInt()) {
             break;
         }
         ct++;
-        filter = clipService.filter(ct);
+        filter = clip->filter(ct);
     }
 
     if (!filter) {
@@ -2698,11 +2689,10 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
         filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
     }
 
-    // Pan and Zoom will be updated upon clip duration change
-    if (params.paramValue("id") == "pan_zoom") {
-        filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
-    }
+    if (params.paramValue("id") == "pan_zoom")
+        filter->set_in_and_out(clip->get_in(), clip->get_out() + 1);
 
+    delete clip;
     mlt_service_unlock(service.get_service());
 
     m_isBlocked = false;