]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
const modifiers are useless on integral return types [PATCH by Ray Lehtiniemi]
[kdenlive] / src / renderer.cpp
index 4cd0774e4f99e838eee6b63d936c4a20041fefdc..79d24c2c8c87e0450a9033265e1fe2fa3c225c7b 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
-#include <stdlib.h>
 
-#include <QTimer>
-#include <QDir>
-#include <QApplication>
+#include "renderer.h"
+#include "kdenlivesettings.h"
+#include "kthumb.h"
+#include "definitions.h"
+
+#include <mlt++/Mlt.h>
 
 #include <KDebug>
 #include <KStandardDirs>
 #include <KLocale>
 #include <KTemporaryFile>
 
-#include "renderer.h"
-#include "kdenlivesettings.h"
-#include "kthumb.h"
-#include "definitions.h"
-
-#include <mlt++/Mlt.h>
+#include <QTimer>
+#include <QDir>
+#include <QApplication>
 
+#include <stdlib.h>
 
 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
     // detect if the producer has finished playing. Is there a better way to do it ?
@@ -114,6 +114,7 @@ void Render::buildConsumer() {
     m_mltConsumer->set("resize", 1);
     m_mltConsumer->set("window_id", m_winid);
     m_mltConsumer->set("terminate_on_pause", 1);
+    m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
 
     m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
     m_mltConsumer->set("rescale", "nearest");
@@ -235,11 +236,11 @@ char *Render::decodedString(QString str) {
     return pix;
 }
 */
-const int Render::renderWidth() const {
+int Render::renderWidth() const {
     return (int)(m_mltProfile->height() * m_mltProfile->dar());
 }
 
-const int Render::renderHeight() const {
+int Render::renderHeight() const {
     return m_mltProfile->height();
 }
 
@@ -269,7 +270,7 @@ QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
         filter << "*." + fileType;
         filter << "*." + fileType.toUpper();
         more = dir.entryList(filter, QDir::Files);
-        im.load(url.directory() + "/" + more.at(0));
+        im.load(url.directory() + '/' + more.at(0));
     } else im.load(url.path());
     //pixmap = im.scaled(width, height);
     return pixmap;
@@ -351,8 +352,8 @@ void Render::getImage(KUrl url, int frame_position, QPoint size)
             more = dir.entryList( QDir::Files );
             for ( it = more.begin() ; it != more.end() ; ++it ) {
                 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
-   if (!im.load(url.directory() + "/" + *it))
-       kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
+   if (!im.load(url.directory() + '/' + *it))
+       kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
    break;
   }
      }
@@ -392,7 +393,7 @@ bool Render::isValid(KUrl url) {
     return true;
 }
 
-const double Render::dar() const {
+double Render::dar() const {
     return m_mltProfile->dar();
 }
 
@@ -427,6 +428,7 @@ void Render::slotSplitView(bool doit) {
                     tmp = "0,50%:50%x50%";
                     break;
                 case 3:
+                default:
                     tmp = "50%,50%:50%x50%";
                     break;
                 }
@@ -460,16 +462,11 @@ void Render::slotSplitView(bool doit) {
     }
 }
 
-void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
-    int height = 50;
-    int width = (int)(height  * m_mltProfile->dar());
-    QMap < QString, QString > filePropertyMap;
-    QMap < QString, QString > metadataPropertyMap;
-
-    KUrl url = KUrl(xml.attribute("resource", QString::null));
+void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) {
+    KUrl url = KUrl(xml.attribute("resource", QString()));
     Mlt::Producer *producer = NULL;
     if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
-        emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
+        emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
         return;
     }
     if (xml.attribute("type").toInt() == COLOR) {
@@ -487,51 +484,47 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
         producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
         delete[] tmp;
     } else {
-        QString urlpath = url.path();
-        /*if (urlpath.contains(':')) {
-            if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
-            char *tmp = decodedString(urlpath);
-            producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
-            delete[] tmp;
-        }
-        else {*/
-        char *tmp = decodedString(urlpath);
+        char *tmp = decodedString(url.path());
         producer = new Mlt::Producer(*m_mltProfile, tmp);
         delete[] tmp;
-
-        if (xml.hasAttribute("force_aspect_ratio")) {
-            double aspect = xml.attribute("force_aspect_ratio").toDouble();
-            if (aspect > 0) producer->set("force_aspect_ratio", aspect);
-        }
-        if (xml.hasAttribute("threads")) {
-            int threads = xml.attribute("threads").toInt();
-            if (threads != 1) producer->set("threads", threads);
-        }
-        if (xml.hasAttribute("video_index")) {
-            int vindex = xml.attribute("video_index").toInt();
-            if (vindex != 0) producer->set("video_index", vindex);
-        }
-        if (xml.hasAttribute("audio_index")) {
-            int aindex = xml.attribute("audio_index").toInt();
-            if (aindex != 0) producer->set("audio_index", aindex);
-        }
-        //}
     }
 
     if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
-        kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
+        kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
         emit removeInvalidClip(clipId);
         return;
     }
 
+    if (xml.hasAttribute("force_aspect_ratio")) {
+        double aspect = xml.attribute("force_aspect_ratio").toDouble();
+        if (aspect > 0) producer->set("force_aspect_ratio", aspect);
+    }
+    if (xml.hasAttribute("threads")) {
+        int threads = xml.attribute("threads").toInt();
+        if (threads != 1) producer->set("threads", threads);
+    }
+    if (xml.hasAttribute("video_index")) {
+        int vindex = xml.attribute("video_index").toInt();
+        if (vindex != 0) producer->set("video_index", vindex);
+    }
+    if (xml.hasAttribute("audio_index")) {
+        int aindex = xml.attribute("audio_index").toInt();
+        if (aindex != 0) producer->set("audio_index", aindex);
+    }
+
     if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
 
     char *tmp = decodedString(clipId);
     producer->set("id", tmp);
     delete[] tmp;
+
+    int height = 50;
+    int width = (int)(height  * m_mltProfile->dar());
+    QMap < QString, QString > filePropertyMap;
+    QMap < QString, QString > metadataPropertyMap;
+
     int frameNumber = xml.attribute("thumbnail", "0").toInt();
     if (frameNumber != 0) producer->seek(frameNumber);
-    mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
 
     filePropertyMap["duration"] = QString::number(producer->get_playtime());
     //kDebug() << "///////  PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
@@ -565,7 +558,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
     filePropertyMap["fps"] = producer->get("source_fps");
 
     if (frame && frame->is_valid()) {
-        filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
+        filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
         filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
         filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
         filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
@@ -598,11 +591,11 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
                 pix.fill(Qt::black);
 
             mlt_pool_release(new_image);
-            emit replyGetImage(clipId, 0, pix, width, height);
+            emit replyGetImage(clipId, pix);
 
         } else if (frame->get_int("test_audio") == 0) {
             QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
-            emit replyGetImage(clipId, 0, pixmap, width, height);
+            emit replyGetImage(clipId, pixmap);
             filePropertyMap["type"] = "audio";
         }
     }
@@ -613,7 +606,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
     char property[200];
     if (producer->get_int("video_index") > -1) {
         /*if (context->duration == AV_NOPTS_VALUE) {
-        kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
+        kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
             emit removeInvalidClip(clipId);
             return;
         }*/
@@ -680,10 +673,10 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
         QString name = metadata.get_name(i);
         QString value = QString::fromUtf8(metadata.get(i));
         if (name.endsWith("markup") && !value.isEmpty())
-            metadataPropertyMap[ name.section(".", 0, -2)] = value;
+            metadataPropertyMap[ name.section('.', 0, -2)] = value;
     }
 
-    emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
+    emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
     kDebug() << "REquested fuile info for: " << url.path();
     if (frame) delete frame;
     //if (producer) delete producer;
@@ -845,7 +838,7 @@ void Render::setSceneList(QString playlist, int position) {
 }
 
 /** Create the producer from the Westley QDomDocument */
-QString Render::sceneList() {
+const QString Render::sceneList() {
     QString playlist;
     Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
     m_mltProducer->optimise();
@@ -912,7 +905,7 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone) {
     westleyConsumer.start();
 }
 
-const double Render::fps() const {
+double Render::fps() const {
     return m_fps;
 }
 
@@ -939,7 +932,7 @@ void Render::refreshDisplay() {
     if (!m_mltProducer) return;
     //m_mltConsumer->set("refresh", 0);
 
-    mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
+    //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
     /*if (KdenliveSettings::osdtimecode()) {
         mlt_properties_set_int( properties, "meta.attr.timecode", 1);
         mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
@@ -1022,7 +1015,7 @@ void Render::stop() {
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
         kDebug() << "/////////////   RENDER STOPPED: " << m_name;
         m_isBlocked = true;
-        m_mltConsumer->set("refresh", 0);
+        //m_mltConsumer->set("refresh", 0);
         m_mltConsumer->stop();
         // delete m_mltConsumer;
         // m_mltConsumer = NULL;
@@ -1128,6 +1121,7 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
     if (!m_mltProducer || !m_mltConsumer)
         return;
     m_isBlocked = false;
+    if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
     m_mltProducer->set("out", stopTime.frames(m_fps));
     m_mltProducer->seek((int)(startTime.frames(m_fps)));
     m_mltProducer->set_speed(1.0);
@@ -1136,7 +1130,8 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
 }
 
 void Render::resetZoneMode() {
-    m_mltProducer->set("out", m_mltProducer->get_length() - 1);
+    if (!m_isZoneMode && !m_isLoopMode) return;
+    m_mltProducer->set("out", m_originalOut);
     //m_mltProducer->set("eof", "pause");
     m_isZoneMode = false;
     m_isLoopMode = false;
@@ -1218,8 +1213,8 @@ void Render::exportCurrentFrame(KUrl url, bool notify) {
         return;
     }
 
-    int height = 1080;//KdenliveSettings::defaultheight();
-    int width = 1940; //KdenliveSettings::displaywidth();
+    //int height = 1080;//KdenliveSettings::defaultheight();
+    //int width = 1940; //KdenliveSettings::displaywidth();
     //TODO: rewrite
     QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
     /*
@@ -1272,27 +1267,14 @@ void Render::mltCheckLength() {
     double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
 
     if (blackDuration != duration) {
-        blackTrackPlaylist.remove_region(0, (int)blackDuration);
-        int i = 0;
+        blackTrackPlaylist.clear();
         int dur = (int)duration;
-        QDomDocument doc;
-        QDomElement black = doc.createElement("producer");
-        black.setAttribute("mlt_service", "colour");
-        black.setAttribute("colour", "black");
-        black.setAttribute("id", "black");
-        ItemInfo info;
-        info.track = 0;
         while (dur > 14000) {
-            info.startPos = GenTime(i * 14000, m_fps);
-            info.endPos = info.startPos + GenTime(13999, m_fps);
-            mltInsertClip(info, black, m_blackClip);
+            blackTrackPlaylist.append(*m_blackClip, 0, 13999);
             dur = dur - 14000;
-            i++;
         }
         if (dur > 0) {
-            info.startPos = GenTime(i * 14000, m_fps);
-            info.endPos = info.startPos + GenTime(dur, m_fps);
-            mltInsertClip(info, black, m_blackClip);
+            blackTrackPlaylist.append(*m_blackClip, 0, dur);
         }
         m_mltProducer->set("out", duration);
         emit durationChanged((int)duration);
@@ -1320,8 +1302,8 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
     if (element.attribute("speed", "1.0").toDouble() != 1.0) {
         // We want a slowmotion producer
         double speed = element.attribute("speed", "1.0").toDouble();
-        QString url = prod->get("resource");
-        url.append("?" + QString::number(speed));
+        QString url = QString::fromUtf8(prod->get("resource"));
+        url.append('?' + QString::number(speed));
         Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
         if (!slowprod || slowprod->get_producer() == NULL) {
             char *tmp = decodedString(url);
@@ -1329,7 +1311,7 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
             delete[] tmp;
             QString id = prod->get("id");
             if (id.contains('_')) id = id.section('_', 0, 0);
-            QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
+            QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
@@ -1371,7 +1353,7 @@ void Render::mltCutClip(int track, GenTime position) {
     int blankDuration = trackPlaylist.clip_length(i) - 1;
     QString blk;
     if (trackPlaylist.is_blank(i)) blk = "(blank)";
-    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
+    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
 
     int cutPos = (int) position.frames(m_fps);
@@ -1422,7 +1404,7 @@ void Render::mltCutClip(int track, GenTime position) {
     int blankDuration = trackPlaylist.clip_length(i) - 1;
     QString blk;
     if (trackPlaylist.is_blank(i)) blk = "(blank)";
-    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
+    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
 
     m_isBlocked = false;
@@ -1451,7 +1433,7 @@ bool Render::mltRemoveClip(int track, GenTime position) {
     int blankDuration = trackPlaylist.clip_length(i) - 1;
     QString blk;
     if (trackPlaylist.is_blank(i)) blk = "(blank)";
-    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
+    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
 
     if (trackPlaylist.is_blank(clipIndex)) {
@@ -1472,7 +1454,7 @@ bool Render::mltRemoveClip(int track, GenTime position) {
     int blankDuration = trackPlaylist.clip_length(i) - 1;
     QString blk;
     if (trackPlaylist.is_blank(i)) blk = "(blank)";
-    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
+    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
 
     if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
@@ -1573,7 +1555,7 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
             Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
 
 
-            int clipNb = trackPlaylist.count();
+            //int clipNb = trackPlaylist.count();
             insertPos = trackClipStartList.value(trackNb - 1);
             if (insertPos != -1) {
                 insertPos += offset;
@@ -1636,7 +1618,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     int newLength = 0;
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
-    kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
+    //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
     Mlt::Tractor tractor(service);
     Mlt::Producer trackProducer(tractor.track(info.track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
@@ -1645,19 +1627,28 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     int clipLength = trackPlaylist.clip_length(clipIndex);
 
     Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
-    QString serv = clip.parent().get("mlt_service");
-    QString id = clip.parent().get("id");
-    kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
+    if (!clip.is_valid() || clip.is_blank()) {
+        // invalid clip
+        return -1;
+    }
+    Mlt::Producer clipparent = clip.parent();
+    if (!clipparent.is_valid() || clipparent.is_blank()) {
+        // invalid clip
+        return -1;
+    }
+    QString serv = clipparent.get("mlt_service");
+    QString id = clipparent.get("id");
+    //kDebug() << "CLIP SERVICE: " << serv;
     if (serv == "avformat" && speed != 1.0) {
         mlt_service_lock(service.get_service());
-        QString url = clip.parent().get("resource");
-        url.append("?" + QString::number(speed));
+        QString url = QString::fromUtf8(clipparent.get("resource"));
+        url.append('?' + QString::number(speed));
         Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
         if (!slowprod || slowprod->get_producer() == NULL) {
             char *tmp = decodedString(url);
             slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
             delete[] tmp;
-            QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
+            QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
@@ -1701,15 +1692,15 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
 
     } else if (serv == "framebuffer") {
         mlt_service_lock(service.get_service());
-        QString url = clip.parent().get("resource");
-        url = url.section("?", 0, 0);
-        url.append("?" + QString::number(speed));
+        QString url = QString::fromUtf8(clipparent.get("resource"));
+        url = url.section('?', 0, 0);
+        url.append('?' + QString::number(speed));
         Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
         if (!slowprod || slowprod->get_producer() == NULL) {
             char *tmp = decodedString(url);
             slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
             delete[] tmp;
-            QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
+            QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
@@ -1728,7 +1719,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);
@@ -1815,13 +1806,13 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
     QString kfr = params.paramValue("keyframes");
 
     if (!kfr.isEmpty()) {
-        QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
+        QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
         kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
         char *starttag = decodedString(params.paramValue("starttag", "start"));
         char *endtag = decodedString(params.paramValue("endtag", "end"));
         kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
         int duration = clip->get_playtime();
-        double max = params.paramValue("max").toDouble();
+        //double max = params.paramValue("max").toDouble();
         double min = params.paramValue("min").toDouble();
         double factor = params.paramValue("factor", "1").toDouble();
         params.removeParam("starttag");
@@ -1835,10 +1826,10 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
             Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
             if (filter && filter->is_valid()) {
                 filter->set("kdenlive_id", filterId);
-                int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
-                double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
-                int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
-                double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
+                int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
+                double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
+                int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
+                double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
                 if (x2 == -1) x2 = duration;
 
                 for (int j = 0; j < params.count(); j++) {
@@ -2072,7 +2063,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
     int blankDuration = trackPlaylist.clip_length(i) - 1;
     QString blk;
     if (trackPlaylist.is_blank(i)) blk = "(blank)";
-    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
+    kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
 
     if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
@@ -2087,21 +2078,25 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
     int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
     int newDuration = (int) clipDuration.frames(m_fps) - 1;
     trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
-    //trackPlaylist.consolidate_blanks(0);
+    trackPlaylist.consolidate_blanks(0);
     // skip to next clip
     clipIndex++;
     int diff = newDuration - previousDuration;
-    kDebug() << "////////  RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
+    kDebug() << "////////  RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
     if (diff > 0) {
         // clip was made longer, trim next blank if there is one.
-        if (trackPlaylist.is_blank(clipIndex)) {
-            int blankStart = trackPlaylist.clip_start(clipIndex);
-            int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
-            if (diff - blankDuration == 1) {
-                trackPlaylist.remove(clipIndex);
-            } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
-        } else {
-            kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
+        if (clipIndex < trackPlaylist.count()) {
+            // If this is not the last clip in playlist
+            if (trackPlaylist.is_blank(clipIndex)) {
+                int blankStart = trackPlaylist.clip_start(clipIndex);
+                int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
+                if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
+                if (diff - blankDuration == 1) {
+                    trackPlaylist.remove(clipIndex);
+                } else trackPlaylist.remove_region(blankStart, diff - 1);
+            } else {
+                kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
+            }
         }
     } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
 
@@ -2141,6 +2136,35 @@ void Render::mltChangeTrackState(int track, bool mute, bool blind) {
     refresh();
 }
 
+
+bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
+    Mlt::Service service(m_mltProducer->parent().get_service());
+    int frameOffset = (int) diff.frames(m_fps);
+    Mlt::Tractor tractor(service);
+    Mlt::Producer trackProducer(tractor.track(info.track));
+    Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+    if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
+        kDebug() << "////////  ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
+        return false;
+    }
+    mlt_service_lock(service.get_service());
+    int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
+    Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
+    if (clip == NULL) {
+        kDebug() << "////////  ERROR RSIZING NULL CLIP!!!!!!!!!!!";
+        mlt_service_unlock(service.get_service());
+        return false;
+    }
+    int previousStart = clip->get_in();
+    int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
+    m_isBlocked = true;
+    trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
+    m_isBlocked = false;
+    mlt_service_unlock(service.get_service());
+    m_mltConsumer->set("refresh", 1);
+    return true;
+}
+
 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
     //kDebug() << "////////  RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -2154,16 +2178,12 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
     }
     mlt_service_lock(service.get_service());
     int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
-    /*int previousStart = trackPlaylist.clip_start(clipIndex);
-    int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
-    //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
     Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
     if (clip == NULL) {
         kDebug() << "////////  ERROR RSIZING NULL CLIP!!!!!!!!!!!";
         mlt_service_unlock(service.get_service());
         return false;
     }
-    //m_mltConsumer->set("refresh", 0);
     int previousStart = clip->get_in();
     int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
     m_isBlocked = true;
@@ -2204,6 +2224,10 @@ bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTim
 
 
 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
+    if (prod == NULL || !prod->is_valid()) {
+        kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
+        return;
+    }
     kDebug() << "NEW PROD ID: " << prod->get("id");
     m_mltConsumer->set("refresh", 0);
     kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
@@ -2342,7 +2366,6 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n
 
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
-    Mlt::Field *field = tractor.field();
 
     mlt_service_lock(service.get_service());
     m_mltConsumer->set("refresh", 0);
@@ -2364,12 +2387,12 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n
         if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
             mlt_transition_set_in_and_out(tr, new_in, new_out);
             if (newTrack - startTrack != 0) {
-                kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
+                kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
 
                 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
                 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
                 mlt_properties_set_int(properties, "b_track", newTrack);
-                //kDebug() << "set new start & end :" << new_in << new_out<< "TR OFFSET: "<<trackOffset<<", TRACKS: "<<mlt_transition_get_a_track(tr)<<"x"<<mlt_transition_get_b_track(tr);
+                //kDebug() << "set new start & end :" << new_in << new_out<< "TR OFFSET: "<<trackOffset<<", TRACKS: "<<mlt_transition_get_a_track(tr)<<'x'<<mlt_transition_get_b_track(tr);
             }
             break;
         }
@@ -2399,7 +2422,6 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G
     m_isBlocked = true;
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
-    Mlt::Field *field = tractor.field();
 
     //m_mltConsumer->set("refresh", 0);
     mlt_service serv = m_mltProducer->parent().get_service();
@@ -2418,7 +2440,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G
         int currentIn = (int) mlt_transition_get_in(tr);
         int currentOut = (int) mlt_transition_get_out(tr);
 
-        // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
+        // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
 
         if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
             QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
@@ -2502,7 +2524,7 @@ QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
             //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
         }
 
-        if (e.attribute("namedesc").contains(";")) {
+        if (e.attribute("namedesc").contains(';')) {
             QString format = e.attribute("format");
             QStringList separators = format.split("%d", QString::SkipEmptyParts);
             QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
@@ -2577,7 +2599,6 @@ void Render::mltDeleteTransparency(int pos, int track, int id) {
 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
-    Mlt::Field *field = tractor.field();
 
     mlt_service_lock(service.get_service());
     m_mltConsumer->set("refresh", 0);
@@ -2588,16 +2609,16 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t
     mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
     QString mlt_type = mlt_properties_get(properties, "mlt_type");
     QString resource = mlt_properties_get(properties, "mlt_service");
-    kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
+    kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
     while (mlt_type == "transition") {
         mlt_transition tr = (mlt_transition) nextservice;
         int currentTrack = mlt_transition_get_b_track(tr);
         int currentIn = (int) mlt_transition_get_in(tr);
         //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
         int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
-        kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
+        kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
         if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
-            kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
+            kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
             mlt_transition_set_in_and_out(tr, newStart, newEnd);
             break;
         }
@@ -2616,7 +2637,6 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t
 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
-    Mlt::Field *field = tractor.field();
 
     mlt_service_lock(service.get_service());
     m_mltConsumer->set("refresh", 0);
@@ -2636,7 +2656,7 @@ void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int
         int currentOut = (int) mlt_transition_get_out(tr);
         //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
         int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
-        //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
+        //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
         if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
             kDebug() << "//////MOVING";
             mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
@@ -2718,10 +2738,10 @@ QList <Mlt::Producer *> Render::producersList() {
         int clipNb = trackPlaylist.count();
         //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
         for (int i = 0; i < clipNb; i++) {
-            Mlt::Producer nprod(trackPlaylist.get_clip(i)->get_parent());
-            if (nprod.is_valid() && !nprod.is_blank() && !ids.contains(nprod.get("id"))) {
-                ids.append(nprod.get("id"));
-                prods.append(&nprod);
+            Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
+            if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
+                ids.append(nprod->get("id"));
+                prods.append(nprod);
             }
         }
     }
@@ -2740,14 +2760,14 @@ void Render::fillSlowMotionProducers() {
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipNb = trackPlaylist.count();
         for (int i = 0; i < clipNb; i++) {
-            Mlt::Producer nprod(trackPlaylist.get_clip(i)->get_parent());
-            if (nprod.is_valid() && !nprod.is_blank()) {
-                QString id = nprod.get("id");
+            Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
+            if (nprod && !nprod->is_blank()) {
+                QString id = nprod->get("id");
                 if (id.startsWith("slowmotion:")) {
                     // this is a slowmotion producer, add it to the list
-                    QString url = nprod.get("resource");
+                    QString url = QString::fromUtf8(nprod->get("resource"));
                     if (!m_slowmotionProducers.contains(url)) {
-                        m_slowmotionProducers.insert(url, &nprod);
+                        m_slowmotionProducers.insert(url, nprod);
                     }
                 }
             }
@@ -2863,6 +2883,7 @@ void Render::mltDeleteTrack(int ix) {
     }
     tractor.removeChild(track);
     setSceneList(doc.toString(), m_framePosition);
+    mltCheckLength();
     return;
 
     blockSignals(true);
@@ -2940,10 +2961,11 @@ void Render::mltDeleteTrack(int ix) {
 void Render::updatePreviewSettings() {
     kDebug() << "////// RESTARTING CONSUMER";
     if (!m_mltConsumer || !m_mltProducer) return;
+    if (m_mltProducer->get_playtime() == 0) return;
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) return;
 
-    m_mltConsumer->set("refresh", 0);
+    //m_mltConsumer->set("refresh", 0);
     if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
     m_mltConsumer->purge();
     QString scene = sceneList();