]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Add animation feature to Slideshow Clip.
[kdenlive] / src / renderer.cpp
index 47d9bc67aae36aa73405c3beeff363418b72586a..c60864502164bbdfb5f92886d3aaeb46f670c3cd 100644 (file)
@@ -27,6 +27,7 @@
 #include "kdenlivesettings.h"
 #include "kthumb.h"
 #include "definitions.h"
+#include "slideshowclip.h"
 
 #include <mlt++/Mlt.h>
 
@@ -712,13 +713,31 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
     Mlt::Frame *frame = producer->get_frame();
 
     if (xml.attribute("type").toInt() == SLIDESHOW) {
-        if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
+        int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
+        if (ttl) producer->set("ttl", ttl);
+        if (!xml.attribute("animation").isEmpty()) {
+            Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
+            if (filter && filter->is_valid()) {
+                int cycle = ttl;
+                QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
+                if (!geometry.isEmpty()) {
+                    if (xml.attribute("animation").contains("low-pass")) {
+                        Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
+                        if (blur && blur->is_valid())
+                            producer->attach(*blur);
+                    }
+                    filter->set("transition.geometry", geometry.toUtf8().data());
+                    filter->set("transition.cycle", cycle);
+                    producer->attach(*filter);
+                }
+            }
+        }
         if (xml.attribute("fade") == "1") {
             // user wants a fade effect to slideshow
             Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
             if (filter && filter->is_valid()) {
-                if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
-                if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
+                if (ttl) filter->set("cycle", ttl);
+                if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
                 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
                     char *tmp = decodedString(xml.attribute("luma_file"));
                     filter->set("luma.resource", tmp);
@@ -728,8 +747,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
                         filter->set("luma.softness", (double) soft / 100.0);
                     }
                 }
-                Mlt::Service clipService(producer->get_service());
-                clipService.attach(*filter);
+                producer->attach(*filter);
             }
         }
         if (xml.attribute("crop") == "1") {
@@ -1527,6 +1545,7 @@ void Render::showFrame(Mlt::Frame& frame)
 }
 #endif
 
+
 /*
  * MLT playlist direct manipulation.
  */
@@ -1789,7 +1808,7 @@ bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
     int ct = 0;
     Mlt::Filter *filter = sourceService.filter(ct);
     while (filter) {
-        if (filter->get("kdenlive_ix") != 0) {
+        if (filter->get_int("kdenlive_ix") != 0) {
             filtersList.append(filter);
         }
         ct++;
@@ -2072,7 +2091,7 @@ void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
     int ct = 0;
     Mlt::Filter *filter = sourceService.filter(ct);
     while (filter) {
-        if (filter->get("kdenlive_ix") != 0) {
+        if (filter->get_int("kdenlive_ix") != 0) {
             sourceService.detach(*filter);
             destService.attach(*filter);
         } else ct++;
@@ -2258,7 +2277,6 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou
 
 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
 {
-    kDebug() << "REMOVE TK EFF: " << track << ", IX: " << index;
     Mlt::Service service(m_mltProducer->parent().get_service());
     bool success = false;
     Mlt::Tractor tractor(service);
@@ -2267,19 +2285,21 @@ bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
     Mlt::Service clipService(trackPlaylist.get_service());
 
     m_isBlocked = true;
+    mlt_service_lock(service.get_service());
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get("kdenlive_ix") == index) {
+        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get_int("kdenlive_ix") == index.toInt()) {
             if (clipService.detach(*filter) == 0) success = true;
         } else if (updateIndex) {
             // Adjust the other effects index
-            if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+            if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
             ct++;
         } else ct++;
         filter = clipService.filter(ct);
     }
     m_isBlocked = false;
+    mlt_service_unlock(service.get_service());
     refresh();
     return success;
 }
@@ -2314,20 +2334,22 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
 
 //    if (tag.startsWith("ladspa")) tag = "ladspa";
     m_isBlocked = true;
+    mlt_service_lock(service.get_service());
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
+        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
             if (clipService.detach(*filter) == 0) success = true;
             //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
         } else if (updateIndex) {
             // Adjust the other effects index
-            if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+            if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
             ct++;
         } else ct++;
         filter = clipService.filter(ct);
     }
     m_isBlocked = false;
+    mlt_service_unlock(service.get_service());
     if (doRefresh) refresh();
     return success;
 }
@@ -2359,7 +2381,6 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
     }
 
     Mlt::Service clipService(clip->get_service());
-    m_isBlocked = true;
     int duration = clip->get_playtime();
     if (doRefresh) {
         // Check if clip is visible in monitor
@@ -2376,9 +2397,12 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
     const int filter_ix = params.paramValue("kdenlive_ix").toInt();
     const QString region =  params.paramValue("region");
     int ct = 0;
+    m_isBlocked = true;
+    mlt_service_lock(service.get_service());
+
     Mlt::Filter *filter = service.filter(ct);
     while (filter) {
-        if (QString(filter->get("kdenlive_ix")).toInt() == filter_ix) {
+        if (filter->get_int("kdenlive_ix") == filter_ix) {
             // A filter at that position already existed, so we will increase all indexes later
             updateIndex = true;
             break;
@@ -2392,13 +2416,14 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
         ct = 0;
         filter = service.filter(ct);
         while (filter) {
-            if (QString(filter->get("kdenlive_ix")).toInt() >= filter_ix) {
-                if (updateIndex) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
+            if (filter->get_int("kdenlive_ix") >= filter_ix) {
+                if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
             }
             ct++;
             filter = service.filter(ct);
         }
         m_isBlocked = false;
+        mlt_service_unlock(service.get_service());
         if (doRefresh) refresh();
         return true;
     }
@@ -2409,7 +2434,7 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
     ct = 0;
     filter = service.filter(ct);
     while (filter) {
-        if (QString(filter->get("kdenlive_ix")).toInt() >= filter_ix) {
+        if (filter->get_int("kdenlive_ix") >= filter_ix) {
             filtersList.append(filter);
             service.detach(*filter);
         } else ct++;
@@ -2512,6 +2537,7 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
         } else {
             kDebug() << "filter is NULL";
             m_isBlocked = false;
+            mlt_service_unlock(service.get_service());
             return false;
         }
         params.removeParam("kdenlive_id");
@@ -2556,17 +2582,17 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int
     for (int i = 0; i < filtersList.count(); i++) {
         Mlt::Filter *filter = filtersList.at(i);
         if (updateIndex)
-            filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
+            filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
         service.attach(*filter);
     }
     m_isBlocked = false;
+    mlt_service_unlock(service.get_service());
     if (doRefresh) refresh();
     return true;
 }
 
 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
 {
-    kDebug() << "EDIT TK, FILTER: " << track;
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
     Mlt::Producer trackProducer(tractor.track(track));
@@ -2579,7 +2605,7 @@ bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
 
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if (filter->get("kdenlive_ix") == index) {
+        if (filter->get_int("kdenlive_ix") == index.toInt()) {
             break;
         }
         ct++;
@@ -2620,8 +2646,11 @@ 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.
-        mltRemoveEffect(track, position, index, false);
-        bool success = mltAddEffect(track, position, params);
+        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;
         return success;
     }
     if (position < GenTime()) {
@@ -2662,7 +2691,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
 
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if (filter->get("kdenlive_ix") == index) {
+        if (filter->get_int("kdenlive_ix") == index.toInt()) {
             break;
         }
         ct++;
@@ -2721,7 +2750,7 @@ void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, in
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        int pos = QString(filter->get("kdenlive_ix")).toInt();
+        int pos = filter->get_int("kdenlive_ix");
         if (pos == oldPos) {
             filter->set("kdenlive_ix", newPos);
         } else ct++;
@@ -2765,19 +2794,19 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
     bool found = false;
     if (newPos > oldPos) {
         while (filter) {
-            if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+            if (!found && filter->get_int("kdenlive_ix") == oldPos) {
                 filter->set("kdenlive_ix", newPos);
                 filtersList.append(filter);
                 clipService.detach(*filter);
                 filter = clipService.filter(ct);
-                while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
-                    filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+                while (filter && filter->get_int("kdenlive_ix") <= newPos) {
+                    filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
                     ct++;
                     filter = clipService.filter(ct);
                 }
                 found = true;
             }
-            if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
+            if (filter && filter->get_int("kdenlive_ix") > newPos) {
                 filtersList.append(filter);
                 clipService.detach(*filter);
             } else ct++;
@@ -2785,7 +2814,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
         }
     } else {
         while (filter) {
-            if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+            if (filter->get_int("kdenlive_ix") == oldPos) {
                 filter->set("kdenlive_ix", newPos);
                 filtersList.append(filter);
                 clipService.detach(*filter);
@@ -2796,7 +2825,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
         ct = 0;
         filter = clipService.filter(ct);
         while (filter) {
-            int pos = QString(filter->get("kdenlive_ix")).toInt();
+            int pos = filter->get_int("kdenlive_ix");
             if (pos >= newPos) {
                 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
                 filtersList.append(filter);
@@ -2830,19 +2859,19 @@ void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
     bool found = false;
     if (newPos > oldPos) {
         while (filter) {
-            if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+            if (!found && filter->get_int("kdenlive_ix") == oldPos) {
                 filter->set("kdenlive_ix", newPos);
                 filtersList.append(filter);
                 clipService.detach(*filter);
                 filter = clipService.filter(ct);
-                while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
-                    filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+                while (filter && filter->get_int("kdenlive_ix") <= newPos) {
+                    filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
                     ct++;
                     filter = clipService.filter(ct);
                 }
                 found = true;
             }
-            if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
+            if (filter && filter->get_int("kdenlive_ix") > newPos) {
                 filtersList.append(filter);
                 clipService.detach(*filter);
             } else ct++;
@@ -2850,7 +2879,7 @@ void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
         }
     } else {
         while (filter) {
-            if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
+            if (filter->get_int("kdenlive_ix") == oldPos) {
                 filter->set("kdenlive_ix", newPos);
                 filtersList.append(filter);
                 clipService.detach(*filter);
@@ -2861,7 +2890,7 @@ void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
         ct = 0;
         filter = clipService.filter(ct);
         while (filter) {
-            int pos = QString(filter->get("kdenlive_ix")).toInt();
+            int pos = filter->get_int("kdenlive_ix");
             if (pos >= newPos) {
                 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
                 filtersList.append(filter);