]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
[valgrind] unfixed memleak
[kdenlive] / src / renderer.cpp
index 503f02ffbc994e219bc9f0acd3a125dbd85a7305..ab45295d0e75f6fedda923f5dab4b925cbe0bb98 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) {
+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 ?
     if (self->m_isBlocked) return;
     if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
@@ -52,7 +53,21 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
     }
 }
 
-Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid),  m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) {
+Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent) :
+        QObject(parent),
+        m_isBlocked(true),
+        m_name(rendererName),
+        m_mltConsumer(NULL),
+        m_mltProducer(NULL),
+        m_mltTextProducer(NULL),
+        m_framePosition(0),
+        m_isZoneMode(false),
+        m_isLoopMode(false),
+        m_isSplitView(false),
+        m_blackClip(NULL),
+        m_winid(winid),
+        m_externalwinid(extid)
+{
     kDebug() << "//////////  USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
     refreshTimer = new QTimer(this);
     connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
@@ -71,12 +86,14 @@ Render::Render(const QString & rendererName, int winid, int extid, QWidget *pare
     m_mltProducer->set_speed(0.0);
 }
 
-Render::~Render() {
+Render::~Render()
+{
     closeMlt();
 }
 
 
-void Render::closeMlt() {
+void Render::closeMlt()
+{
     delete osdTimer;
     delete refreshTimer;
     if (m_mltConsumer)
@@ -88,7 +105,8 @@ void Render::closeMlt() {
 }
 
 
-void Render::buildConsumer() {
+void Render::buildConsumer()
+{
     char *tmp;
     m_activeProfile = KdenliveSettings::current_profile();
     tmp = decodedString(m_activeProfile);
@@ -114,8 +132,11 @@ 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()));
+    tmp = decodedString(KdenliveSettings::window_background().name());
+    m_mltConsumer->set("window_background", tmp);
+    delete [] tmp;
 
+    // FIXME: the event object returned by the listen gets leaked...
     m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
     m_mltConsumer->set("rescale", "nearest");
 
@@ -149,7 +170,8 @@ void Render::buildConsumer() {
 
 }
 
-int Render::resetProfile() {
+int Render::resetProfile()
+{
     if (!m_mltConsumer) return 0;
     if (m_activeProfile == KdenliveSettings::current_profile()) {
         kDebug() << "reset to same profile, nothing to do";
@@ -201,7 +223,8 @@ int Render::resetProfile() {
 }
 
 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
-void Render::seek(GenTime time) {
+void Render::seek(GenTime time)
+{
     if (!m_mltProducer)
         return;
     m_isBlocked = false;
@@ -210,7 +233,8 @@ void Render::seek(GenTime time) {
 }
 
 //static
-char *Render::decodedString(QString str) {
+char *Render::decodedString(QString str)
+{
     /*QCString fn = QFile::encodeName(str);
     char *t = new char[fn.length() + 1];
     strcpy(t, (const char *)fn);*/
@@ -236,15 +260,18 @@ 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();
 }
 
-QPixmap Render::extractFrame(int frame_position, int width, int height) {
+QPixmap Render::extractFrame(int frame_position, int width, int height)
+{
     if (width == -1) {
         width = renderWidth();
         height = renderHeight();
@@ -257,7 +284,8 @@ QPixmap Render::extractFrame(int frame_position, int width, int height) {
     return KThumb::getFrame(m_mltProducer, frame_position, width, height);
 }
 
-QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
+QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
+{
     QImage im;
     QPixmap pixmap;
     if (url.fileName().startsWith(".all.")) {  //  check for slideshow
@@ -368,13 +396,15 @@ void Render::getImage(KUrl url, int frame_position, QPoint size)
 }*/
 
 
-double Render::consumerRatio() const {
+double Render::consumerRatio() const
+{
     if (!m_mltConsumer) return 1.0;
     return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
 }
 
 
-int Render::getLength() {
+int Render::getLength()
+{
 
     if (m_mltProducer) {
         // kDebug()<<"//////  LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
@@ -383,7 +413,8 @@ int Render::getLength() {
     return 0;
 }
 
-bool Render::isValid(KUrl url) {
+bool Render::isValid(KUrl url)
+{
     char *tmp = decodedString(url.path());
     Mlt::Producer producer(*m_mltProfile, tmp);
     delete[] tmp;
@@ -393,11 +424,13 @@ bool Render::isValid(KUrl url) {
     return true;
 }
 
-const double Render::dar() const {
+double Render::dar() const
+{
     return m_mltProfile->dar();
 }
 
-void Render::slotSplitView(bool doit) {
+void Render::slotSplitView(bool doit)
+{
     m_isSplitView = doit;
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
@@ -428,6 +461,7 @@ void Render::slotSplitView(bool doit) {
                     tmp = "0,50%:50%x50%";
                     break;
                 case 3:
+                default:
                     tmp = "50%,50%:50%x50%";
                     break;
                 }
@@ -461,16 +495,12 @@ void Render::slotSplitView(bool doit) {
     }
 }
 
-void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) {
-    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, replaceProducer);
+        emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
         return;
     }
     if (xml.attribute("type").toInt() == COLOR) {
@@ -488,51 +518,48 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
         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);
+        delete producer;
         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();
@@ -614,8 +641,9 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
     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);
+            delete producer;
             return;
         }*/
         // Get the video_index
@@ -681,19 +709,21 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
         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, replaceProducer);
     kDebug() << "REquested fuile info for: " << url.path();
     if (frame) delete frame;
+    // FIXME: should delete this to avoid a leak...
     //if (producer) delete producer;
 }
 
 
 /** Create the producer from the Westley QDomDocument */
 #if 0
-void Render::initSceneList() {
+void Render::initSceneList()
+{
     kDebug() << "--------  INIT SCENE LIST ------_";
     QDomDocument doc;
     QDomElement westley = doc.createElement("westley");
@@ -731,7 +761,8 @@ void Render::initSceneList() {
 
 
 /** Create the producer from the Westley QDomDocument */
-void Render::setProducer(Mlt::Producer *producer, int position) {
+void Render::setProducer(Mlt::Producer *producer, int position)
+{
     if (m_winid == -1) return;
 
     if (m_mltConsumer) {
@@ -768,14 +799,17 @@ void Render::setProducer(Mlt::Producer *producer, int position) {
 
 
 /** Create the producer from the Westley QDomDocument */
-void Render::setSceneList(QDomDocument list, int position) {
+void Render::setSceneList(QDomDocument list, int position)
+{
     setSceneList(list.toString(), position);
 }
 
 /** Create the producer from the Westley QDomDocument */
-void Render::setSceneList(QString playlist, int position) {
+void Render::setSceneList(QString playlist, int position)
+{
     if (m_winid == -1) return;
     m_isBlocked = true;
+    qDeleteAll(m_slowmotionProducers.values());
     m_slowmotionProducers.clear();
 
     //kWarning() << "//////  RENDER, SET SCENE LIST: " << playlist;
@@ -841,12 +875,14 @@ void Render::setSceneList(QString playlist, int position) {
     }
     m_isBlocked = false;
     blockSignals(false);
+    emit refreshDocumentProducers();
     //kDebug()<<"// SETSCN LST, POS: "<<position;
     //if (position != 0) emit rendererPosition(position);
 }
 
 /** Create the producer from the Westley QDomDocument */
-const QString Render::sceneList() {
+const QString Render::sceneList()
+{
     QString playlist;
     Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
     m_mltProducer->optimise();
@@ -862,7 +898,8 @@ const QString Render::sceneList() {
     return playlist;
 }
 
-void Render::saveSceneList(QString path, QDomElement kdenliveData) {
+bool Render::saveSceneList(QString path, QDomElement kdenliveData)
+{
     QFile file(path);
     QDomDocument doc;
     doc.setContent(sceneList(), false);
@@ -873,15 +910,20 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) {
     }
     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
         kWarning() << "//////  ERROR writing to file: " << path;
-        return;
+        return false;
+    }
+    file.write(doc.toString().toUtf8());
+    if (file.error() != QFile::NoError) {
+        file.close();
+        return false;
     }
-    QTextStream out(&file);
-    out << doc.toString();
     file.close();
+    return true;
 }
 
 
-void Render::saveZone(KUrl url, QString desc, QPoint zone) {
+void Render::saveZone(KUrl url, QString desc, QPoint zone)
+{
     kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
     char *tmppath = decodedString("westley:" + url.path());
     Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
@@ -913,11 +955,13 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone) {
     westleyConsumer.start();
 }
 
-const double Render::fps() const {
+double Render::fps() const
+{
     return m_fps;
 }
 
-void Render::connectPlaylist() {
+void Render::connectPlaylist()
+{
     if (!m_mltConsumer) return;
     //m_mltConsumer->set("refresh", "0");
     m_mltConsumer->connect(*m_mltProducer);
@@ -928,6 +972,7 @@ void Render::connectPlaylist() {
     /*
      if (m_mltConsumer->start() == -1) {
           KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
+          delete m_mltConsumer;
           m_mltConsumer = NULL;
      }
      else {
@@ -935,12 +980,13 @@ void Render::connectPlaylist() {
      }*/
 }
 
-void Render::refreshDisplay() {
+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#");
@@ -954,7 +1000,8 @@ void Render::refreshDisplay() {
     refresh();
 }
 
-void Render::setVolume(double volume) {
+void Render::setVolume(double /*volume*/)
+{
     if (!m_mltConsumer || !m_mltProducer) return;
     /*osdTimer->stop();
     m_mltConsumer->set("refresh", 0);
@@ -973,7 +1020,8 @@ void Render::setVolume(double volume) {
     osdTimer->setSingleShot(2500);
 }
 
-void Render::slotOsdTimeout() {
+void Render::slotOsdTimeout()
+{
     mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
     mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
     mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
@@ -981,7 +1029,8 @@ void Render::slotOsdTimeout() {
     refresh();
 }
 
-void Render::start() {
+void Render::start()
+{
     kDebug() << "-----  STARTING MONITOR: " << m_name;
     if (m_winid == -1) {
         kDebug() << "-----  BROKEN MONITOR: " << m_name << ", RESTART";
@@ -992,6 +1041,7 @@ void Render::start() {
         kDebug() << "-----  MONITOR: " << m_name << " WAS STOPPED";
         if (m_mltConsumer->start() == -1) {
             KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
+            delete m_mltConsumer;
             m_mltConsumer = NULL;
             return;
         } else {
@@ -1003,7 +1053,8 @@ void Render::start() {
     m_isBlocked = false;
 }
 
-void Render::clear() {
+void Render::clear()
+{
     kDebug() << " *********  RENDER CLEAR";
     if (m_mltConsumer) {
         //m_mltConsumer->set("refresh", 0);
@@ -1019,7 +1070,8 @@ void Render::clear() {
     }
 }
 
-void Render::stop() {
+void Render::stop()
+{
     if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
         kDebug() << "/////////////   RENDER STOPPED: " << m_name;
         m_isBlocked = true;
@@ -1040,7 +1092,8 @@ void Render::stop() {
     kDebug() << "/////////////   RENDER STOP3-------";
 }
 
-void Render::stop(const GenTime & startTime) {
+void Render::stop(const GenTime & startTime)
+{
 
     kDebug() << "/////////////   RENDER STOP-------2";
     if (m_mltProducer) {
@@ -1051,7 +1104,8 @@ void Render::stop(const GenTime & startTime) {
     m_mltConsumer->purge();
 }
 
-void Render::pause() {
+void Render::pause()
+{
     if (!m_mltProducer || !m_mltConsumer)
         return;
     if (m_mltProducer->get_speed() == 0.0) return;
@@ -1064,7 +1118,8 @@ void Render::pause() {
     m_mltConsumer->purge();
 }
 
-void Render::switchPlay() {
+void Render::switchPlay()
+{
     if (!m_mltProducer || !m_mltConsumer)
         return;
     if (m_isZoneMode) resetZoneMode();
@@ -1094,7 +1149,8 @@ void Render::switchPlay() {
     //refresh();
 }
 
-void Render::play(double speed) {
+void Render::play(double speed)
+{
     if (!m_mltProducer)
         return;
     // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
@@ -1107,7 +1163,8 @@ void Render::play(double speed) {
     refresh();
 }
 
-void Render::play(const GenTime & startTime) {
+void Render::play(const GenTime & startTime)
+{
     if (!m_mltProducer || !m_mltConsumer)
         return;
     m_isBlocked = false;
@@ -1116,7 +1173,8 @@ void Render::play(const GenTime & startTime) {
     m_mltConsumer->set("refresh", 1);
 }
 
-void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
+void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
+{
     if (!m_mltProducer || !m_mltConsumer)
         return;
     //m_mltProducer->set("eof", "loop");
@@ -1125,7 +1183,8 @@ void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
     playZone(startTime, stopTime);
 }
 
-void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
+void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
+{
     if (!m_mltProducer || !m_mltConsumer)
         return;
     m_isBlocked = false;
@@ -1137,7 +1196,8 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
     m_isZoneMode = true;
 }
 
-void Render::resetZoneMode() {
+void Render::resetZoneMode()
+{
     if (!m_isZoneMode && !m_isLoopMode) return;
     m_mltProducer->set("out", m_originalOut);
     //m_mltProducer->set("eof", "pause");
@@ -1145,7 +1205,8 @@ void Render::resetZoneMode() {
     m_isLoopMode = false;
 }
 
-void Render::seekToFrame(int pos) {
+void Render::seekToFrame(int pos)
+{
     //kDebug()<<" *********  RENDER SEEK TO POS";
     if (!m_mltProducer)
         return;
@@ -1155,17 +1216,20 @@ void Render::seekToFrame(int pos) {
     refresh();
 }
 
-void Render::askForRefresh() {
+void Render::askForRefresh()
+{
     // Use a Timer so that we don't refresh too much
     refreshTimer->start(200);
 }
 
-void Render::doRefresh() {
+void Render::doRefresh()
+{
     // Use a Timer so that we don't refresh too much
     if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
 }
 
-void Render::refresh() {
+void Render::refresh()
+{
     if (!m_mltProducer || m_isBlocked)
         return;
     refreshTimer->stop();
@@ -1174,29 +1238,34 @@ void Render::refresh() {
     }
 }
 
-double Render::playSpeed() {
+double Render::playSpeed()
+{
     if (m_mltProducer) return m_mltProducer->get_speed();
     return 0.0;
 }
 
-GenTime Render::seekPosition() const {
+GenTime Render::seekPosition() const
+{
     if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
     else return GenTime();
 }
 
 
-const QString & Render::rendererName() const {
+const QString & Render::rendererName() const
+{
     return m_name;
 }
 
 
-void Render::emitFrameNumber(double position) {
+void Render::emitFrameNumber(double position)
+{
     m_framePosition = position;
     emit rendererPosition((int) position);
     //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
 }
 
-void Render::emitConsumerStopped() {
+void Render::emitConsumerStopped()
+{
     // This is used to know when the playing stopped
     if (m_mltProducer) {
         double pos = m_mltProducer->position();
@@ -1210,19 +1279,21 @@ void Render::emitConsumerStopped() {
 
 
 
-void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
+void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
+{
     KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
 }
 
 
-void Render::exportCurrentFrame(KUrl url, bool notify) {
+void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
+{
     if (!m_mltProducer) {
         KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
         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);
     /*
@@ -1243,7 +1314,8 @@ void Render::exportCurrentFrame(KUrl url, bool notify) {
 /** MLT PLAYLIST DIRECT MANIPULATON  **/
 
 
-void Render::mltCheckLength() {
+void Render::mltCheckLength()
+{
     //kDebug()<<"checking track length: "<<track<<"..........";
 
     Mlt::Service service(m_mltProducer->get_service());
@@ -1254,16 +1326,14 @@ void Render::mltCheckLength() {
     double trackDuration;
     if (trackNb == 1) {
         Mlt::Producer trackProducer(tractor.track(0));
-        Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-        duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
+        duration = trackProducer.get_playtime() - 1;
         m_mltProducer->set("out", duration);
         emit durationChanged((int) duration);
         return;
     }
     while (trackNb > 1) {
         Mlt::Producer trackProducer(tractor.track(trackNb - 1));
-        Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-        trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
+        trackDuration = trackProducer.get_playtime() - 1;
 
         //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
         if (trackDuration > duration) duration = trackDuration;
@@ -1271,38 +1341,26 @@ void Render::mltCheckLength() {
     }
 
     Mlt::Producer blackTrackProducer(tractor.track(0));
-    Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
-    double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
+    double blackDuration = blackTrackProducer.get_playtime() - 1;
 
     if (blackDuration != duration) {
-        blackTrackPlaylist.remove_region(0, (int)blackDuration);
-        int i = 0;
+        Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
+        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);
     }
 }
 
-void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
+void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
+{
     if (!m_mltProducer) {
         kDebug() << "PLAYLIST NOT INITIALISED //////";
         return;
@@ -1323,7 +1381,7 @@ 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");
+        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) {
@@ -1355,7 +1413,8 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
 }
 
 
-void Render::mltCutClip(int track, GenTime position) {
+void Render::mltCutClip(int track, GenTime position)
+{
 
     m_isBlocked = true;
 
@@ -1402,7 +1461,7 @@ void Render::mltCutClip(int track, GenTime position) {
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if (filter->is_valid() && filter->get("kdenlive_id") != "") {
+        if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "")) {
             // looks like there is no easy way to duplicate a filter,
             // so we will create a new one and duplicate its properties
             Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
@@ -1431,14 +1490,16 @@ void Render::mltCutClip(int track, GenTime position) {
     m_isBlocked = false;
 }
 
-void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
+void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
+{
     // TODO: optimize
     mltRemoveClip(info.track, info.startPos);
     mltInsertClip(info, element, prod);
 }
 
 
-bool Render::mltRemoveClip(int track, GenTime position) {
+bool Render::mltRemoveClip(int track, GenTime position)
+{
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
 
@@ -1483,7 +1544,8 @@ bool Render::mltRemoveClip(int track, GenTime position) {
     return true;
 }
 
-int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
+int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
+{
     if (!m_mltProducer) {
         kDebug() << "PLAYLIST NOT INITIALISED //////";
         return -1;
@@ -1506,8 +1568,27 @@ int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
     return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
 }
 
+int Render::mltTrackDuration(int track)
+{
+    if (!m_mltProducer) {
+        kDebug() << "PLAYLIST NOT INITIALISED //////";
+        return -1;
+    }
+    Mlt::Producer parentProd(m_mltProducer->parent());
+    if (parentProd.get_producer() == NULL) {
+        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+        return -1;
+    }
 
-void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
+    Mlt::Service service(parentProd.get_service());
+    Mlt::Tractor tractor(service);
+
+    Mlt::Producer trackProducer(tractor.track(track));
+    return trackProducer.get_playtime() - 1;
+}
+
+void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
+{
     if (!m_mltProducer) {
         kDebug() << "PLAYLIST NOT INITIALISED //////";
         return;
@@ -1576,7 +1657,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;
@@ -1634,7 +1715,8 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
     m_mltConsumer->set("refresh", 1);
 }
 
-int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
+int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
+{
     m_isBlocked = true;
     int newLength = 0;
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -1662,7 +1744,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     //kDebug() << "CLIP SERVICE: " << serv;
     if (serv == "avformat" && speed != 1.0) {
         mlt_service_lock(service.get_service());
-        QString url = clipparent.get("resource");
+        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) {
@@ -1713,7 +1795,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
 
     } else if (serv == "framebuffer") {
         mlt_service_lock(service.get_service());
-        QString url = clipparent.get("resource");
+        QString url = QString::fromUtf8(clipparent.get("resource"));
         url = url.section('?', 0, 0);
         url.append('?' + QString::number(speed));
         Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
@@ -1754,7 +1836,8 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     return newLength;
 }
 
-bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) {
+bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
+{
     kDebug() << "// TRYing to remove effect at: " << index;
     Mlt::Service service(m_mltProducer->parent().get_service());
     bool success = false;
@@ -1773,7 +1856,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if ((index == "-1" && filter->get("kdenlive_id") != "")  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
+        if ((index == "-1" && strcmp(filter->get("kdenlive_id"), ""))  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
             if (clipService.detach(*filter) == 0) success = true;
             kDebug() << " / / / DLEETED EFFECT: " << ct;
         } else if (updateIndex) {
@@ -1789,7 +1872,8 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
 }
 
 
-bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
+bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
+{
 
     Mlt::Service service(m_mltProducer->parent().get_service());
 
@@ -1833,7 +1917,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
         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");
@@ -1926,7 +2010,8 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
     return true;
 }
 
-bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
+bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
+{
     QString index = params.paramValue("kdenlive_ix");
     QString tag =  params.paramValue("tag");
 
@@ -1997,7 +2082,8 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
     return true;
 }
 
-void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
+void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
+{
 
     kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -2068,7 +2154,8 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
     refresh();
 }
 
-bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
+bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
+{
     m_isBlocked = true;
 
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -2139,7 +2226,8 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
     return true;
 }
 
-void Render::mltChangeTrackState(int track, bool mute, bool blind) {
+void Render::mltChangeTrackState(int track, bool mute, bool blind)
+{
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
     Mlt::Producer trackProducer(tractor.track(track));
@@ -2158,7 +2246,8 @@ void Render::mltChangeTrackState(int track, bool mute, bool blind) {
 }
 
 
-bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
+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);
@@ -2186,7 +2275,8 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
     return true;
 }
 
-bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
+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());
     int moveFrame = (int) diff.frames(m_fps);
@@ -2239,12 +2329,14 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
     return true;
 }
 
-bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
+bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
+{
     return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
 }
 
 
-void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
+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;
@@ -2288,7 +2380,8 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
     m_isBlocked = false;
 }
 
-bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
+bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
+{
     m_isBlocked = true;
 
     m_mltConsumer->set("refresh", 0);
@@ -2303,10 +2396,10 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
     kDebug() << "//////  LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
     bool checkLength = false;
     if (endTrack == startTrack) {
-        //mlt_service_lock(service.get_service());
         Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
         if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
             // error, destination is not empty
+            if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
             //int ix = trackPlaylist.get_clip_index_at(moveEnd);
             kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
             mlt_service_unlock(m_mltConsumer->get_service());
@@ -2344,9 +2437,18 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
             Mlt::Producer *clip;
             // check if we are moving a slowmotion producer
             QString serv = clipProducer.parent().get("mlt_service");
-            if (serv == "framebuffer") {
+            QString currentid = clipProducer.parent().get("id");
+            if (serv == "framebuffer" || currentid.endsWith("_video")) {
                 clip = &clipProducer;
-            } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+            } else {
+                if (prod == NULL) {
+                    // Special case: prod is null when using placeholder clips.
+                    // in that case, use the producer existing in playlist. Note that
+                    // it will bypass the one producer per track logic and might cause
+                    // Sound cracks if clip is moved so that it overlaps another copy of itself
+                    clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
+                } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+            }
 
             // move all effects to the correct producer
             Mlt::Service clipService(clipProducer.get_service());
@@ -2380,14 +2482,14 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
     return true;
 }
 
-bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
+bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
+{
     int new_in = (int)newIn.frames(m_fps);
     int new_out = (int)newOut.frames(m_fps) - 1;
     if (new_in >= new_out) return false;
 
     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);
@@ -2430,7 +2532,8 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n
     return true;
 }
 
-void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
+void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
+{
     // kDebug() << "update transition"  << tag << " at pos " << in.frames(25);
     if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
     else {
@@ -2440,11 +2543,11 @@ void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b
     //mltSavePlaylist();
 }
 
-void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
+void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
+{
     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();
@@ -2479,7 +2582,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G
                 char *name = decodedString(key);
                 char *value = decodedString(it.value());
                 mlt_properties_set(transproperties, name, value);
-                kDebug() << " ------  UPDATING TRANS PARAM: " << name << ": " << value;
+                //kDebug() << " ------  UPDATING TRANS PARAM: " << name << ": " << value;
                 //filter->set("kdenlive_id", id);
                 delete[] name;
                 delete[] value;
@@ -2496,7 +2599,8 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G
     m_mltConsumer->set("refresh", 1);
 }
 
-void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
+void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
+{
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
     Mlt::Field *field = tractor.field();
@@ -2531,7 +2635,8 @@ void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime
     //if (do_refresh) m_mltConsumer->set("refresh", 1);
 }
 
-QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
+QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
+{
     QDomNodeList attribs = xml.elementsByTagName("parameter");
     QMap<QString, QString> map;
     for (int i = 0;i < attribs.count();i++) {
@@ -2569,7 +2674,8 @@ QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
     return map;
 }
 
-void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
+void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
+{
     kDebug() << "/////////  ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
@@ -2584,7 +2690,8 @@ void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
     refresh();
 }
 
-void Render::mltDeleteTransparency(int pos, int track, int id) {
+void Render::mltDeleteTransparency(int pos, int track, int id)
+{
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
     Mlt::Field *field = tractor.field();
@@ -2619,10 +2726,10 @@ void Render::mltDeleteTransparency(int pos, int track, int id) {
     //if (do_refresh) m_mltConsumer->set("refresh", 1);
 }
 
-void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, 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);
@@ -2658,10 +2765,10 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t
 
 }
 
-void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
+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);
@@ -2704,7 +2811,8 @@ void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int
 }
 
 
-bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
+bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
+{
     if (in >= out) return false;
     QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -2725,8 +2833,8 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
         key = it.key();
         char *name = decodedString(key);
         char *value = decodedString(it.value());
-        transition->set(name, value);
-        kDebug() << " ------  ADDING TRANS PARAM: " << name << ": " << value;
+        if (it.value().isEmpty() == false) transition->set(name, value);
+        //kDebug() << " ------  ADDING TRANS PARAM: " << name << ": " << value;
         //filter->set("kdenlive_id", id);
         delete[] name;
         delete[] value;
@@ -2738,7 +2846,8 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
     return true;
 }
 
-void Render::mltSavePlaylist() {
+void Render::mltSavePlaylist()
+{
     kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
     Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
     fileConsumer.set("resource", "/tmp/playlist.westley");
@@ -2749,8 +2858,9 @@ void Render::mltSavePlaylist() {
     fileConsumer.start();
 }
 
-QList <Mlt::Producer *> Render::producersList() {
-    QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
+QList <Mlt::Producer *> Render::producersList()
+{
+    QList <Mlt::Producer *> prods;
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) return prods;
     Mlt::Tractor tractor(service);
@@ -2758,22 +2868,29 @@ QList <Mlt::Producer *> Render::producersList() {
 
     int trackNb = tractor.count();
     for (int t = 1; t < trackNb; t++) {
-        Mlt::Producer trackProducer(tractor.track(t));
+        Mlt::Producer *tt = tractor.track(t);
+        Mlt::Producer trackProducer(tt);
+        delete tt;
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipNb = trackPlaylist.count();
         //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
         for (int i = 0; i < clipNb; i++) {
-            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);
+            Mlt::Producer *c = trackPlaylist.get_clip(i);
+            Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
+            if (nprod) {
+                if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
+                    ids.append(nprod->get("id"));
+                    prods.append(nprod);
+                } else delete nprod;
             }
+            delete c;
         }
     }
     return prods;
 }
 
-void Render::fillSlowMotionProducers() {
+void Render::fillSlowMotionProducers()
+{
     Mlt::Service service(m_mltProducer->parent().get_service());
     if (service.type() != tractor_type) return;
 
@@ -2781,26 +2898,31 @@ void Render::fillSlowMotionProducers() {
 
     int trackNb = tractor.count();
     for (int t = 1; t < trackNb; t++) {
-        Mlt::Producer trackProducer(tractor.track(t));
+        Mlt::Producer *tt = tractor.track(t);
+        Mlt::Producer trackProducer(tt);
+        delete tt;
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipNb = trackPlaylist.count();
         for (int i = 0; i < clipNb; i++) {
-            Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
-            if (nprod && !nprod->is_blank()) {
+            Mlt::Producer *c = trackPlaylist.get_clip(i);
+            Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
+            if (nprod) {
                 QString id = nprod->get("id");
-                if (id.startsWith("slowmotion:")) {
+                if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
                     // 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);
                     }
-                }
+                } else delete nprod;
             }
+            delete c;
         }
     }
 }
 
-void Render::mltInsertTrack(int ix, bool videoTrack) {
+void Render::mltInsertTrack(int ix, bool videoTrack)
+{
     blockSignals(true);
     m_isBlocked = true;
 
@@ -2875,7 +2997,8 @@ void Render::mltInsertTrack(int ix, bool videoTrack) {
 }
 
 
-void Render::mltDeleteTrack(int ix) {
+void Render::mltDeleteTrack(int ix)
+{
     QDomDocument doc;
     doc.setContent(sceneList(), false);
     int tracksCount = doc.elementsByTagName("track").count() - 1;
@@ -2983,7 +3106,8 @@ void Render::mltDeleteTrack(int ix) {
 }
 
 
-void Render::updatePreviewSettings() {
+void Render::updatePreviewSettings()
+{
     kDebug() << "////// RESTARTING CONSUMER";
     if (!m_mltConsumer || !m_mltProducer) return;
     if (m_mltProducer->get_playtime() == 0) return;