]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Ask to change profile if first clip does not match project profile:
[kdenlive] / src / renderer.cpp
index 4d6d315383fc2403927407b3cbde0d1317a9ef0b..392189bd69bac2da3a8a97a14de4ae99ea3b7d87 100644 (file)
@@ -27,6 +27,7 @@
 #include "kdenlivesettings.h"
 #include "kthumb.h"
 #include "definitions.h"
+#include "slideshowclip.h"
 
 #include <mlt++/Mlt.h>
 
@@ -65,8 +66,9 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
 #endif
 
     self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
-    if (frame_ptr->convert_image)
+    if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
         self->emitFrameUpdated(frame);
+    }
     if (frame.get_double("_speed") == 0.0) {
         self->emitConsumerStopped();
     } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
@@ -79,6 +81,7 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
 Render::Render(const QString & rendererName, int winid, int /* extid */, QString profile, QWidget *parent) :
         QObject(parent),
         m_isBlocked(0),
+        sendFrameForAnalysis(false),
         m_name(rendererName),
         m_mltConsumer(NULL),
         m_mltProducer(NULL),
@@ -368,6 +371,11 @@ char *Render::decodedString(QString str)
     return pix;
 }
 */
+int Render::frameRenderWidth() const
+{
+    return m_mltProfile->width();
+}
+
 int Render::renderWidth() const
 {
     return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
@@ -620,7 +628,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
         char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
         producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
         delete[] tmp;
-        if (producer && xml.hasAttribute("xmldata")) {
+        if (producer && producer->is_valid() && xml.hasAttribute("xmldata")) {
             tmp = decodedString(xml.attribute("xmldata"));
             producer->set("xmldata", tmp);
             delete[] tmp;
@@ -676,7 +684,7 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int
         if (aindex != 0) producer->set("audio_index", aindex);
     }
 
-    // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken although outpoint is larger
+    // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
     if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
             || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
         producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
@@ -712,13 +720,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 +754,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") {
@@ -2916,15 +2941,22 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
     int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
     //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
     Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
+
     int previousStart = clip->get_in();
     int newDuration = (int) clipDuration.frames(m_fps) - 1;
-    int currentOut = (int)(info.cropStart + info.cropDuration).frames(m_fps) - 1;
     int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
+
+    int currentOut;
+    if (info.cropStart < GenTime())
+        currentOut = newDuration - info.cropStart.frames(m_fps);
+    else
+        currentOut = newDuration + previousStart;
     if (currentOut > clip->get_length()) {
         clip->parent().set("length", currentOut + 1);
         clip->parent().set("out", currentOut);
         clip->set("length", currentOut + 1);
     }
+
     /*if (newDuration > clip->get_out()) {
         clip->parent().set_in_and_out(0, newDuration + 1);
         clip->set_in_and_out(0, newDuration + 1);
@@ -3043,7 +3075,7 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
     }
     int previousStart = clip->get_in();
     int previousOut = clip->get_out();
-    delete clip;
+
     m_isBlocked = true;
     previousStart += moveFrame;
     if (previousStart < 0) {
@@ -3051,10 +3083,20 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
         previousOut -= previousStart;
         previousStart = 0;
     }
+
+    int length = previousOut + 1;
+    if (length > clip->get_length()) {
+        clip->parent().set("length", length + 1);
+        clip->parent().set("out", length);
+        clip->set("length", length + 1);
+    }
+    delete clip;
+
     // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
     trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
-    if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
-    else {
+    if (moveFrame > 0) {
+        trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
+    } else {
         //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
         int blankIndex = clipIndex - 1;
         int blankLength = trackPlaylist.clip_length(blankIndex);
@@ -3392,7 +3434,7 @@ void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b
         mltAddTransition(tag, a_track, b_track, in, out, xml, false);
     }
 
-    if (m_mltProducer->position() > in.frames(m_fps) && m_mltProducer->position() < out.frames(m_fps)) refresh();
+    if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
 }
 
 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
@@ -4064,5 +4106,16 @@ QString Render::updateSceneListFps(double current_fps, double new_fps, QString s
     return doc.toString();
 }
 
+
+void Render::sendFrameUpdate()
+{
+    if (m_mltProducer) {
+        Mlt::Frame * frame = m_mltProducer->get_frame();
+        emitFrameUpdated(*frame);
+        delete frame;
+    }
+}
+
+
 #include "renderer.moc"