]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Fix opening of title with profile different than current one
[kdenlive] / src / renderer.cpp
index c9c9611803ee7fa7b4b6c5c08fe21a20908e5fb5..acc2c3888a12c2f3f8aa795669ff8d37686460c3 100644 (file)
@@ -77,13 +77,11 @@ Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget
         m_winid(winid)
 {
     kDebug() << "//////////  USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
-    m_refreshTimer = new QTimer(this);
-    connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
 
     /*if (rendererName == "project") m_monitorId = 10000;
     else m_monitorId = 10001;*/
-    m_osdTimer = new QTimer(this);
-    connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
+    /*m_osdTimer = new QTimer(this);
+    connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
 
     buildConsumer();
 
@@ -101,8 +99,23 @@ Render::~Render()
 
 void Render::closeMlt()
 {
-    delete m_osdTimer;
-    delete m_refreshTimer;
+    //delete m_osdTimer;
+    if (m_mltProducer) {
+        Mlt::Service service(m_mltProducer->get_service());
+        if (service.type() == tractor_type) {
+            Mlt::Tractor tractor(service);
+            int trackNb = tractor.count();
+
+            while (trackNb > 0) {
+                Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+                trackPlaylist.clear();
+                trackNb--;
+            }
+        }
+    }
+
+    kDebug() << "// // // CLOSE RENDERER " << m_name;
     delete m_mltConsumer;
     delete m_mltProducer;
     delete m_blackClip;
@@ -198,15 +211,31 @@ int Render::resetProfile()
     m_mltConsumer = NULL;
     QString scene = sceneList();
     int pos = 0;
+
+    delete m_blackClip;
+    m_blackClip = NULL;
+
     if (m_mltProducer) {
         pos = m_mltProducer->position();
+
+        Mlt::Service service(m_mltProducer->get_service());
+        if (service.type() == tractor_type) {
+            Mlt::Tractor tractor(service);
+            int trackNb = tractor.count();
+            while (trackNb > 0) {
+                Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+                trackPlaylist.clear();
+                trackNb--;
+            }
+        }
+
         delete m_mltProducer;
     }
     m_mltProducer = NULL;
 
-    //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
-    /*if (m_mltProfile) delete m_mltProfile;
-    m_mltProfile = NULL;*/
+    if (m_mltProfile) delete m_mltProfile;
+    m_mltProfile = NULL;
 
     buildConsumer();
 
@@ -512,14 +541,23 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
 {
     KUrl url = KUrl(xml.attribute("resource", QString()));
     Mlt::Producer *producer = NULL;
-    if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
+    /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
         emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
         return;
-    }
+    }*/
     if (xml.attribute("type").toInt() == COLOR) {
         char *tmp = decodedString("colour:" + xml.attribute("colour"));
         producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
         delete[] tmp;
+    } else if (xml.attribute("type").toInt() == TEXT) {
+        char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
+        producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
+        delete[] tmp;
+        if (xml.hasAttribute("xmldata")) {
+            char *tmp = decodedString(xml.attribute("xmldata"));
+            producer->set("xmldata", tmp);
+            delete[] tmp;
+        }
     } else if (url.isEmpty()) {
         QDomDocument doc;
         QDomElement mlt = doc.createElement("mlt");
@@ -843,6 +881,19 @@ int Render::setSceneList(QString playlist, int position)
         m_mltProducer->set_speed(0);
         //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
 
+
+        Mlt::Service service(m_mltProducer->get_service());
+        if (service.type() == tractor_type) {
+            Mlt::Tractor tractor(service);
+            int trackNb = tractor.count();
+            while (trackNb > 0) {
+                Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+                trackPlaylist.clear();
+                trackNb--;
+            }
+        }
+
         delete m_mltProducer;
         m_mltProducer = NULL;
         emit stopped();
@@ -956,6 +1007,7 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone)
         tmppath = decodedString(desc);
         Mlt::Playlist list;
         list.insert_at(0, prod, 0);
+        delete prod;
         list.set("title", tmppath);
         delete[] tmppath;
         xmlConsumer.connect(list);
@@ -1037,7 +1089,7 @@ void Render::setVolume(double /*volume*/)
      if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
     }*/
     refresh();
-    m_osdTimer->setSingleShot(2500);
+    //m_osdTimer->setSingleShot(2500);
 }
 
 void Render::slotOsdTimeout()
@@ -1072,23 +1124,6 @@ void Render::start()
     m_isBlocked = false;
 }
 
-void Render::clear()
-{
-    kDebug() << " *********  RENDER CLEAR";
-    if (m_mltConsumer) {
-        //m_mltConsumer->set("refresh", 0);
-        if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
-    }
-
-    if (m_mltProducer) {
-        //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
-        m_mltProducer->set_speed(0.0);
-        delete m_mltProducer;
-        m_mltProducer = NULL;
-        emit stopped();
-    }
-}
-
 void Render::stop()
 {
     if (m_mltProducer == NULL) return;
@@ -1247,12 +1282,6 @@ void Render::seekToFrameDiff(int diff)
     refresh();
 }
 
-void Render::askForRefresh()
-{
-    // Use a Timer so that we don't refresh too much
-    m_refreshTimer->start(300);
-}
-
 void Render::doRefresh()
 {
     // Use a Timer so that we don't refresh too much
@@ -1263,7 +1292,6 @@ void Render::refresh()
 {
     if (!m_mltProducer || m_isBlocked)
         return;
-    m_refreshTimer->stop();
     if (m_mltConsumer) {
         m_mltConsumer->set("refresh", 1);
     }
@@ -1366,87 +1394,103 @@ void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
 /** MLT PLAYLIST DIRECT MANIPULATON  **/
 
 
-void Render::mltCheckLength()
+void Render::mltCheckLength(Mlt::Tractor *tractor)
 {
     //kDebug()<<"checking track length: "<<track<<"..........";
 
-    Mlt::Service service(m_mltProducer->get_service());
-    Mlt::Tractor tractor(service);
-
-    int trackNb = tractor.count();
+    int trackNb = tractor->count();
     int duration = 0;
     int trackDuration;
     if (trackNb == 1) {
-        Mlt::Producer trackProducer(tractor.track(0));
+        Mlt::Producer trackProducer(tractor->track(0));
         duration = trackProducer.get_playtime() - 1;
         m_mltProducer->set("out", duration);
         emit durationChanged(duration);
         return;
     }
     while (trackNb > 1) {
-        Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+        Mlt::Producer trackProducer(tractor->track(trackNb - 1));
         trackDuration = trackProducer.get_playtime() - 1;
-
         //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
         if (trackDuration > duration) duration = trackDuration;
         trackNb--;
     }
 
-    Mlt::Producer blackTrackProducer(tractor.track(0));
+    Mlt::Producer blackTrackProducer(tractor->track(0));
 
     if (blackTrackProducer.get_playtime() - 1 != duration) {
         Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
         Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
-        if (duration > m_blackClip->get_length()) {
-            m_blackClip->set("length", duration);
-            if (blackclip) blackclip->set("length", duration);
+        if (blackclip && blackclip->is_blank()) {
+            delete blackclip;
+            blackclip = NULL;
         }
-        if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
+
+        if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
             blackTrackPlaylist.clear();
-            blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
-        } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
+            m_blackClip->set("length", duration);
+            m_blackClip->set("out", duration - 1);
+            blackclip = m_blackClip->cut(0, duration - 1);
+            blackTrackPlaylist.insert_at(0, blackclip, 1);
+        } else {
+            if (duration > blackclip->parent().get_length()) {
+                blackclip->parent().set("length", duration);
+                blackclip->parent().set("out", duration - 1);
+                blackclip->set("length", duration);
+            }
+            blackTrackPlaylist.resize_clip(0, 0, duration - 1);
+        }
+
         delete blackclip;
         m_mltProducer->set("out", duration);
         emit durationChanged(duration);
     }
 }
 
-void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
+int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
 {
     if (m_mltProducer == NULL) {
         kDebug() << "PLAYLIST NOT INITIALISED //////";
-        return;
+        return -1;
     }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
         kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
-        return;
+        return -1;
     }
 
     Mlt::Service service(parentProd.get_service());
+    if (service.type() != tractor_type) {
+        kWarning() << "// TRACTOR PROBLEM";
+        return -1;
+    }
     Mlt::Tractor tractor(service);
     if (info.track > tractor.count() - 1) {
         kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
-        return;
+        return -1;
     }
     mlt_service_lock(service.get_service());
     Mlt::Producer trackProducer(tractor.track(info.track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
     //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
 
-    if (element.attribute("speed", "1.0").toDouble() != 1.0) {
+    if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 1) {
         // We want a slowmotion producer
         double speed = element.attribute("speed", "1.0").toDouble();
+        int strobe = element.attribute("strobe", "1").toInt();
         QString url = QString::fromUtf8(prod->get("resource"));
         url.append('?' + QString::number(speed));
+        if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
         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);
+            if (strobe > 1) slowprod->set("strobe", strobe);
             delete[] tmp;
             QString id = prod->get("id");
             if (id.contains('_')) id = id.section('_', 0, 0);
             QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
+            if (strobe > 1) producerid.append(':' + QString::number(strobe));
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
@@ -1456,16 +1500,16 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
     }
 
     Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
-    int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
-
+    int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1);
+    delete clip;
     /*if (QString(prod->get("transparency")).toInt() == 1)
         mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
 
+    if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
     mlt_service_unlock(service.get_service());
-
-    if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
-    //tractor.multitrack()->refresh();
-    //tractor.refresh();
+    /*tractor.multitrack()->refresh();
+    tractor.refresh();*/
+    return 0;
 }
 
 
@@ -1514,6 +1558,8 @@ void Render::mltCutClip(int track, GenTime position)
     }
     Mlt::Service clipService(original->get_service());
     Mlt::Service dupService(clip->get_service());
+    delete original;
+    delete clip;
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
@@ -1582,7 +1628,8 @@ bool Render::mltRemoveClip(int track, GenTime position)
     }
     //kDebug()<<"////  Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
     m_isBlocked = true;
-    trackPlaylist.replace_with_blank(clipIndex);
+    Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
+    delete clip;
     trackPlaylist.consolidate_blanks(0);
     /*if (QString(clip.parent().get("transparency")).toInt() == 1)
         mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
@@ -1597,7 +1644,7 @@ bool Render::mltRemoveClip(int track, GenTime position)
     kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
     }*/
     mlt_service_unlock(service.get_service());
-    if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
+    if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
     m_isBlocked = false;
     return true;
 }
@@ -1679,7 +1726,11 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
                 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
                 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
                 int position = trackPlaylist.clip_start(clipIndex);
-                trackPlaylist.remove_region(position, - diff - 1);
+                int blankDuration = trackPlaylist.clip_length(clipIndex);
+                diff = -diff;
+                if (blankDuration - diff == 0)
+                    trackPlaylist.remove(clipIndex);
+                else trackPlaylist.remove_region(position, diff);
             }
             trackPlaylist.consolidate_blanks(0);
         }
@@ -1736,7 +1787,10 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
                     if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
                     if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
                     int position = trackPlaylist.clip_start(clipIndex);
-                    trackPlaylist.remove_region(position, - diff - 1);
+                    int blankDuration = trackPlaylist.clip_length(clipIndex);
+                    if (diff + blankDuration == 0)
+                        trackPlaylist.remove(clipIndex);
+                    else trackPlaylist.remove_region(position, - diff);
                 }
                 trackPlaylist.consolidate_blanks(0);
             }
@@ -1769,7 +1823,7 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
         }
     }
     mlt_service_unlock(service.get_service());
-    mltCheckLength();
+    mltCheckLength(&tractor);
     m_mltConsumer->set("refresh", 1);
 }
 
@@ -1791,7 +1845,7 @@ void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
     }
 }
 
-int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
+int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod)
 {
     m_isBlocked = true;
     int newLength = 0;
@@ -1824,22 +1878,25 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     QString serv = clipparent.get("mlt_service");
     QString id = clipparent.get("id");
     //kDebug() << "CLIP SERVICE: " << serv;
-    if (serv == "avformat" && speed != 1.0) {
+    if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
         mlt_service_lock(service.get_service());
         QString url = QString::fromUtf8(clipparent.get("resource"));
         url.append('?' + QString::number(speed));
+        if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
         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);
+            if (strobe > 1) slowprod->set("strobe", strobe);
             delete[] tmp;
             QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
+            if (strobe > 1) producerid.append(':' + QString::number(strobe));
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
             m_slowmotionProducers.insert(url, slowprod);
         }
-        trackPlaylist.replace_with_blank(clipIndex);
+        Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
         trackPlaylist.consolidate_blanks(0);
         // Check that the blank space is long enough for our new duration
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
@@ -1852,15 +1909,16 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
 
         // move all effects to the correct producer
         mltPasteEffects(clip, cut);
-
-        trackPlaylist.insert_at(startPos, *cut, 1);
+        trackPlaylist.insert_at(startPos, cut, 1);
+        delete cut;
+        delete clip;
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
         mlt_service_unlock(service.get_service());
-    } else if (speed == 1.0) {
+    } else if (speed == 1.0 && strobe < 2) {
         mlt_service_lock(service.get_service());
 
-        trackPlaylist.replace_with_blank(clipIndex);
+        Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
         trackPlaylist.consolidate_blanks(0);
 
         // Check that the blank space is long enough for our new duration
@@ -1878,7 +1936,9 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
         // move all effects to the correct producer
         mltPasteEffects(clip, cut);
 
-        trackPlaylist.insert_at(startPos, *cut, 1);
+        trackPlaylist.insert_at(startPos, cut, 1);
+        delete cut;
+        delete clip;
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
         mlt_service_unlock(service.get_service());
@@ -1888,22 +1948,25 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
         QString url = QString::fromUtf8(clipparent.get("resource"));
         url = url.section('?', 0, 0);
         url.append('?' + QString::number(speed));
+        if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
         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;
+            slowprod->set("strobe", strobe);
             QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
+            if (strobe > 1) producerid.append(':' + QString::number(strobe));
             tmp = decodedString(producerid);
             slowprod->set("id", tmp);
             delete[] tmp;
             m_slowmotionProducers.insert(url, slowprod);
         }
-        trackPlaylist.replace_with_blank(clipIndex);
+        Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
         trackPlaylist.consolidate_blanks(0);
 
         GenTime oldDuration = GenTime(clipLength, m_fps);
-        GenTime newDuration = oldDuration * oldspeed / speed;
+        GenTime newDuration = oldDuration * (oldspeed / speed);
 
         // Check that the blank space is long enough for our new duration
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
@@ -1918,7 +1981,9 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
         // move all effects to the correct producer
         mltPasteEffects(clip, cut);
 
-        trackPlaylist.insert_at(startPos, *cut, 1);
+        trackPlaylist.insert_at(startPos, cut, 1);
+        delete cut;
+        delete clip;
         clipIndex = trackPlaylist.get_clip_index_at(startPos);
         newLength = trackPlaylist.clip_length(clipIndex);
 
@@ -1926,14 +1991,13 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt
     }
 
     delete clip;
-    if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
+    if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
     m_isBlocked = false;
     return newLength;
 }
 
 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;
     Mlt::Tractor tractor(service);
@@ -1946,6 +2010,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
         return success;
     }
     Mlt::Service clipService(clip->get_service());
+    delete clip;
 //    if (tag.startsWith("ladspa")) tag = "ladspa";
     m_isBlocked = true;
     int ct = 0;
@@ -1953,7 +2018,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
     while (filter) {
         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;
+            //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
         } else if (updateIndex) {
             // Adjust the other effects index
             if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
@@ -1982,7 +2047,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
     }
     Mlt::Service clipService(clip->get_service());
     m_isBlocked = true;
-
+    delete clip;
     // temporarily remove all effects after insert point
     QList <Mlt::Filter *> filtersList;
     const int filter_ix = params.paramValue("kdenlive_ix").toInt();
@@ -2112,7 +2177,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
 
     if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
         // This is a keyframe effect, to edit it, we remove it and re-add it.
-        mltRemoveEffect(track, position, index, true);
+        mltRemoveEffect(track, position, index, false);
         bool success = mltAddEffect(track, position, params);
         return success;
     }
@@ -2130,6 +2195,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
         return false;
     }
     Mlt::Service clipService(clip->get_service());
+    delete clip;
     m_isBlocked = true;
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
@@ -2194,6 +2260,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
         return;
     }
     Mlt::Service clipService(clip->get_service());
+    delete clip;
     m_isBlocked = true;
     int ct = 0;
     QList <Mlt::Filter *> filtersList;
@@ -2282,6 +2349,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
     int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
     if (newDuration > clip->get_length()) {
         clip->parent().set("length", newDuration + 1);
+        clip->parent().set("out", newDuration);
         clip->set("length", newDuration + 1);
     }
     if (newDuration > clip->get_out()) {
@@ -2300,11 +2368,11 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
             // 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;
+                int blankDuration = trackPlaylist.clip_length(clipIndex);
                 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
-                if (diff - blankDuration == 1) {
+                if (diff - blankDuration == 0) {
                     trackPlaylist.remove(clipIndex);
-                } else trackPlaylist.remove_region(blankStart, diff - 1);
+                } else trackPlaylist.remove_region(blankStart, diff);
             } else {
                 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
             }
@@ -2313,7 +2381,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
     trackPlaylist.consolidate_blanks(0);
     mlt_service_unlock(service.get_service());
 
-    if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
+    if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
     /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
         //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
         mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
@@ -2456,19 +2524,21 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
     Mlt::Producer trackProducer(tractor.track(track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
     int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
-    Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
-    if (clipProducer.is_blank()) {
+    Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
+    if (clipProducer->is_blank()) {
         kDebug() << "// ERROR UPDATING CLIP PROD";
+        delete clipProducer;
         mlt_service_unlock(m_mltConsumer->get_service());
         m_isBlocked--;
         return;
     }
-    Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
+    Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
 
     // move all effects to the correct producer
-    mltPasteEffects(&clipProducer, clip);
-
+    mltPasteEffects(clipProducer, clip);
     trackPlaylist.insert_at(pos, clip, 1);
+    delete clip;
+    delete clipProducer;
     mlt_service_unlock(m_mltConsumer->get_service());
     m_isBlocked--;
 }
@@ -2488,10 +2558,11 @@ 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::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
-        if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
+        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);
+            delete clipProducer;
             //int ix = trackPlaylist.get_clip_index_at(moveEnd);
             kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
             mlt_service_unlock(service.get_service());
@@ -2500,6 +2571,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
         } else {
             trackPlaylist.consolidate_blanks(0);
             int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
+            delete clipProducer;
             /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
             mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
             }*/
@@ -2515,10 +2587,11 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
             m_isBlocked--;
             return false;
         } else {
-            Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
-            if (clipProducer.is_blank()) {
+            Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
+            if (clipProducer->is_blank()) {
                 // error, destination is not empty
                 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
+                delete clipProducer;
                 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
                 mlt_service_unlock(service.get_service());
                 m_isBlocked--;
@@ -2528,24 +2601,31 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
             destTrackPlaylist.consolidate_blanks(1);
             Mlt::Producer *clip;
             // check if we are moving a slowmotion producer
-            QString serv = clipProducer.parent().get("mlt_service");
-            QString currentid = clipProducer.parent().get("id");
+            QString serv = clipProducer->parent().get("mlt_service");
+            QString currentid = clipProducer->parent().get("id");
             if (serv == "framebuffer" || currentid.endsWith("_video")) {
-                clip = &clipProducer;
+                clip = clipProducer;
             } 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());
+                    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
-            mltPasteEffects(&clipProducer, clip);
+            mltPasteEffects(clipProducer, clip);
 
             int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
+            if (clip == clipProducer) {
+                delete clip;
+                clip = NULL;
+            } else {
+                delete clip;
+                delete clipProducer;
+            }
             destTrackPlaylist.consolidate_blanks(0);
             /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
                 kDebug() << "//////// moving clip transparency";
@@ -2556,7 +2636,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
         }
     }
     mlt_service_unlock(service.get_service());
-    if (checkLength) mltCheckLength();
+    if (checkLength) mltCheckLength(&tractor);
     m_isBlocked--;
     //askForRefresh();
     //m_mltConsumer->set("refresh", 1);
@@ -3004,6 +3084,8 @@ void Render::fillSlowMotionProducers()
                 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
                     // this is a slowmotion producer, add it to the list
                     QString url = QString::fromUtf8(nprod->get("resource"));
+                    int strobe = nprod->get_int("strobe");
+                    if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
                     if (!m_slowmotionProducers.contains(url)) {
                         m_slowmotionProducers.insert(url, nprod);
                     }
@@ -3130,7 +3212,17 @@ void Render::mltDeleteTrack(int ix)
     tractor.removeChild(track);
     //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
     setSceneList(doc.toString(), m_framePosition);
-    mltCheckLength();
+
+    if (m_mltProducer != NULL) {
+        Mlt::Producer parentProd(m_mltProducer->parent());
+        if (parentProd.get_producer() != NULL) {
+            Mlt::Service service(parentProd.get_service());
+            if (service.type() == tractor_type) {
+                Mlt::Tractor tractor(service);
+                mltCheckLength(&tractor);
+            }
+        }
+    }
 }
 
 
@@ -3149,9 +3241,8 @@ void Render::updatePreviewSettings()
     int pos = 0;
     if (m_mltProducer) {
         pos = m_mltProducer->position();
-        delete m_mltProducer;
     }
-    m_mltProducer = NULL;
+
     setSceneList(scene, pos);
 }