]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
cleanup
[kdenlive] / src / renderer.cpp
index 64cbbf72a6d06295b0d625955fe82651bb0d861e..7bfb8473bfa2c99b9df6af3ac79c7a05877c9400 100644 (file)
@@ -44,7 +44,7 @@
 
 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 ?
+    // 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) {
         self->emitConsumerStopped();
@@ -53,31 +53,27 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
     }
 }
 
-Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent) :
+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)
+        m_winid(winid)
 {
-    kDebug() << "//////////  USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
-    refreshTimer = new QTimer(this);
-    connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
+    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;*/
-    osdTimer = new QTimer(this);
-    connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
-
-    m_osdProfile =   KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
+    m_osdTimer = new QTimer(this);
+    connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
 
     buildConsumer();
 
@@ -94,8 +90,8 @@ Render::~Render()
 
 void Render::closeMlt()
 {
-    delete osdTimer;
-    delete refreshTimer;
+    delete m_osdTimer;
+    delete m_refreshTimer;
     delete m_mltConsumer;
     delete m_mltProducer;
     delete m_blackClip;
@@ -152,6 +148,8 @@ void Render::buildConsumer()
     }
 
     QString audioDriver = KdenliveSettings::audiodrivername();
+    if (audioDriver.isEmpty())
+        audioDriver = KdenliveSettings::autoaudiodrivername();
     if (!audioDriver.isEmpty()) {
         tmp = decodedString(audioDriver);
         m_mltConsumer->set("audio_driver", tmp);
@@ -199,7 +197,7 @@ int Render::resetProfile()
     setSceneList(scene, pos);
 
     /*char *tmp = decodedString(scene);
-    Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
+    Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
     delete[] tmp;
     m_mltProducer = producer;
     m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
@@ -273,7 +271,7 @@ QPixmap Render::extractFrame(int frame_position, int width, int height)
     if (width == -1) {
         width = renderWidth();
         height = renderHeight();
-    }
+    } else if (width % 2 == 1) width++;
     QPixmap pix(width, height);
     if (!m_mltProducer) {
         pix.fill(Qt::black);
@@ -503,17 +501,17 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
     }
     if (xml.attribute("type").toInt() == COLOR) {
         char *tmp = decodedString("colour:" + xml.attribute("colour"));
-        producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
+        producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
         delete[] tmp;
     } else if (url.isEmpty()) {
         QDomDocument doc;
-        QDomElement westley = doc.createElement("westley");
+        QDomElement mlt = doc.createElement("mlt");
         QDomElement play = doc.createElement("playlist");
-        doc.appendChild(westley);
-        westley.appendChild(play);
+        doc.appendChild(mlt);
+        mlt.appendChild(play);
         play.appendChild(doc.importNode(xml, true));
         char *tmp = decodedString(doc.toString());
-        producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
+        producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
         delete[] tmp;
     } else {
         char *tmp = decodedString(url.path());
@@ -523,7 +521,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
 
     if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
         kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
-        emit removeInvalidClip(clipId);
+        emit removeInvalidClip(clipId, replaceProducer);
         delete producer;
         return;
     }
@@ -597,7 +595,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
         filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
 
         if (frame->get_int("test_image") == 0) {
-            if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
+            if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
                 filePropertyMap["type"] = "playlist";
                 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
             } else if (frame->get_int("test_audio") == 0)
@@ -674,11 +672,11 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
         }
 
         if (KdenliveSettings::dropbframes()) {
-            kDebug() << "// LOOKING FOR H264 on: " << default_video;
+            kDebug() << "// LOOKING FOR H264 on: " << default_video;
             snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
             kDebug() << "PROP: " << property << " = " << producer->get(property);
             if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
-                kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
+                kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
                 producer->set("skip_loop_filter", "all");
                 producer->set("skip_frame", "bidir");
             }
@@ -718,14 +716,14 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
 }
 
 
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
 #if 0
 void Render::initSceneList()
 {
     kDebug() << "--------  INIT SCENE LIST ------_";
     QDomDocument doc;
-    QDomElement westley = doc.createElement("westley");
-    doc.appendChild(westley);
+    QDomElement mlt = doc.createElement("mlt");
+    doc.appendChild(mlt);
     QDomElement prod = doc.createElement("producer");
     prod.setAttribute("resource", "colour");
     prod.setAttribute("colour", "red");
@@ -748,17 +746,17 @@ void Render::initSceneList()
     QDomElement playlist5 = doc.createElement("playlist");
     multitrack.appendChild(playlist5);
     tractor.appendChild(multitrack);
-    westley.appendChild(tractor);
+    mlt.appendChild(tractor);
     // kDebug()<<doc.toString();
     /*
-       QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
+       QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
     setSceneList(doc, 0);
 }
 #endif
 
 
 
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
 void Render::setProducer(Mlt::Producer *producer, int position)
 {
     if (m_winid == -1) return;
@@ -783,7 +781,7 @@ void Render::setProducer(Mlt::Producer *producer, int position)
     m_mltProducer->set("skip_loop_filter", "all");
         m_mltProducer->set("skip_frame", "bidir");
     }*/
-    if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
+    if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
 
     m_fps = m_mltProducer->get_fps();
     connectPlaylist();
@@ -796,13 +794,13 @@ void Render::setProducer(Mlt::Producer *producer, int position)
 
 
 
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
 void Render::setSceneList(QDomDocument list, int position)
 {
     setSceneList(list.toString(), position);
 }
 
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
 void Render::setSceneList(QString playlist, int position)
 {
     if (m_winid == -1) return;
@@ -812,14 +810,17 @@ void Render::setSceneList(QString playlist, int position)
 
     //kWarning() << "//////  RENDER, SET SCENE LIST: " << playlist;
 
-    if (m_mltConsumer) {
-        m_mltConsumer->stop();
-        //m_mltConsumer->set("refresh", 0);
-    } else {
+    if (m_mltConsumer == NULL) {
+        kWarning() << "///////  ERROR, TRYING TO USE NULL MLT CONSUMER";
         m_isBlocked = false;
         return;
     }
 
+    if (!m_mltConsumer->is_stopped()) {
+        m_mltConsumer->stop();
+        //m_mltConsumer->set("refresh", 0);
+    }
+
     if (m_mltProducer) {
         m_mltProducer->set_speed(0);
         //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
@@ -831,12 +832,14 @@ void Render::setSceneList(QString playlist, int position)
 
     blockSignals(true);
     char *tmp = decodedString(playlist);
-    m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
-    delete[] tmp;
+    m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
 
     if (!m_mltProducer || !m_mltProducer->is_valid()) {
         kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
+        m_mltProducer = m_blackClip->cut(0, 50);
     }
+    delete[] tmp;
+
     m_mltProducer->optimise();
 
     /*if (KdenliveSettings::osdtimecode()) {
@@ -844,7 +847,7 @@ void Render::setSceneList(QString playlist, int position)
     delete m_osdInfo;
     QString attr = "attr_check";
     mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
-    mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
+    mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
     mlt_producer_attach( m_mltProducer->get_producer(), filter );
     mlt_filter_close( filter );
 
@@ -863,14 +866,15 @@ void Render::setSceneList(QString playlist, int position)
     }*/
 
     m_fps = m_mltProducer->get_fps();
-    kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
-    connectPlaylist();
-    fillSlowMotionProducers();
     if (position != 0) {
-        //TODO: seek to correct place after opening project.
-        //  Needs to be done from another place since it crashes here.
+        // Seek to correct place after opening project.
         m_mltProducer->seek(position);
     }
+
+    kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
+    connectPlaylist();
+    fillSlowMotionProducers();
+
     m_isBlocked = false;
     blockSignals(false);
     emit refreshDocumentProducers();
@@ -878,20 +882,20 @@ void Render::setSceneList(QString playlist, int position)
     //if (position != 0) emit rendererPosition(position);
 }
 
-/** Create the producer from the Westley QDomDocument */
+/** Create the producer from the MLT XML QDomDocument */
 const QString Render::sceneList()
 {
     QString playlist;
-    Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
+    Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
     m_mltProducer->optimise();
-    westleyConsumer.set("terminate_on_pause", 1);
+    xmlConsumer.set("terminate_on_pause", 1);
     Mlt::Producer prod(m_mltProducer->get_producer());
     bool split = m_isSplitView;
     if (split) slotSplitView(false);
-    westleyConsumer.connect(prod);
-    westleyConsumer.start();
-    while (!westleyConsumer.is_stopped()) {}
-    playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
+    xmlConsumer.connect(prod);
+    xmlConsumer.start();
+    while (!xmlConsumer.is_stopped()) {}
+    playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
     if (split) slotSplitView(true);
     return playlist;
 }
@@ -903,8 +907,8 @@ bool Render::saveSceneList(QString path, QDomElement kdenliveData)
     doc.setContent(sceneList(), false);
     if (!kdenliveData.isNull()) {
         // add Kdenlive specific tags
-        QDomNode wes = doc.elementsByTagName("westley").at(0);
-        wes.appendChild(doc.importNode(kdenliveData, true));
+        QDomNode mlt = doc.elementsByTagName("mlt").at(0);
+        mlt.appendChild(doc.importNode(kdenliveData, true));
     }
     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
         kWarning() << "//////  ERROR writing to file: " << path;
@@ -923,11 +927,11 @@ bool Render::saveSceneList(QString path, QDomElement kdenliveData)
 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);
+    char *tmppath = decodedString("xml:" + url.path());
+    Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
     m_mltProducer->optimise();
     delete[] tmppath;
-    westleyConsumer.set("terminate_on_pause", 1);
+    xmlConsumer.set("terminate_on_pause", 1);
     if (m_name == "clip") {
         Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
         tmppath = decodedString(desc);
@@ -935,7 +939,7 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone)
         list.insert_at(0, prod, 0);
         list.set("title", tmppath);
         delete[] tmppath;
-        westleyConsumer.connect(list);
+        xmlConsumer.connect(list);
 
     } else {
         //TODO: not working yet, save zone from timeline
@@ -947,10 +951,10 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone)
         tmppath = decodedString(desc);
         //prod->set("title", tmppath);
         delete[] tmppath;
-        westleyConsumer.connect(*p1); //list);
+        xmlConsumer.connect(*p1); //list);
     }
 
-    westleyConsumer.start();
+    xmlConsumer.start();
 }
 
 double Render::fps() const
@@ -1015,7 +1019,7 @@ void Render::setVolume(double /*volume*/)
      if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
     }*/
     refresh();
-    osdTimer->setSingleShot(2500);
+    m_osdTimer->setSingleShot(2500);
 }
 
 void Render::slotOsdTimeout()
@@ -1217,7 +1221,7 @@ void Render::seekToFrame(int pos)
 void Render::askForRefresh()
 {
     // Use a Timer so that we don't refresh too much
-    refreshTimer->start(200);
+    m_refreshTimer->start(200);
 }
 
 void Render::doRefresh()
@@ -1230,7 +1234,7 @@ void Render::refresh()
 {
     if (!m_mltProducer || m_isBlocked)
         return;
-    refreshTimer->stop();
+    m_refreshTimer->stop();
     if (m_mltConsumer) {
         m_mltConsumer->set("refresh", 1);
     }
@@ -1339,19 +1343,19 @@ void Render::mltCheckLength()
     }
 
     Mlt::Producer blackTrackProducer(tractor.track(0));
-    int blackDuration = blackTrackProducer.get_playtime() - 1;
 
-    if (blackDuration != duration) {
+    if (blackTrackProducer.get_playtime() - 1 != duration) {
         Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
-        blackTrackPlaylist.clear();
-        int dur = duration;
-        while (dur > 14000) {
-            blackTrackPlaylist.append(*m_blackClip, 0, 13999);
-            dur = dur - 14000;
-        }
-        if (dur > 0) {
-            blackTrackPlaylist.append(*m_blackClip, 0, dur);
+        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 == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
+            blackTrackPlaylist.clear();
+            blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
+        } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
+        delete blackclip;
         m_mltProducer->set("out", duration);
         emit durationChanged(duration);
     }
@@ -1359,13 +1363,13 @@ void Render::mltCheckLength()
 
 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
 {
-    if (!m_mltProducer) {
-        kDebug() << "PLAYLIST NOT INITIALISED //////";
+    if (m_mltProducer == NULL) {
+        kDebug() << "PLAYLIST NOT INITIALISED //////";
         return;
     }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
-        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
         return;
     }
 
@@ -1459,7 +1463,8 @@ void Render::mltCutClip(int track, GenTime position)
     int ct = 0;
     Mlt::Filter *filter = clipService.filter(ct);
     while (filter) {
-        if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "")) {
+        // Only duplicate Kdenlive filters, and skip the fade in effects
+        if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
             // 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"));
@@ -1545,12 +1550,12 @@ bool Render::mltRemoveClip(int track, GenTime position)
 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
 {
     if (!m_mltProducer) {
-        kDebug() << "PLAYLIST NOT INITIALISED //////";
+        kDebug() << "PLAYLIST NOT INITIALISED //////";
         return -1;
     }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
-        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
         return -1;
     }
 
@@ -1569,12 +1574,12 @@ int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
 int Render::mltTrackDuration(int track)
 {
     if (!m_mltProducer) {
-        kDebug() << "PLAYLIST NOT INITIALISED //////";
+        kDebug() << "PLAYLIST NOT INITIALISED //////";
         return -1;
     }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
-        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
         return -1;
     }
 
@@ -1588,12 +1593,12 @@ int Render::mltTrackDuration(int track)
 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 //////";
+        kDebug() << "PLAYLIST NOT INITIALISED //////";
         return;
     }
     Mlt::Producer parentProd(m_mltProducer->parent());
     if (parentProd.get_producer() == NULL) {
-        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
+        kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
         return;
     }
     //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
@@ -1623,7 +1628,7 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
             }
             trackPlaylist.consolidate_blanks(0);
         }
-        // now move transitions
+        // now move transitions
         mlt_service serv = m_mltProducer->parent().get_service();
         mlt_service nextservice = mlt_service_get_producer(serv);
         mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
@@ -1682,7 +1687,7 @@ void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int>
             }
             trackNb--;
         }
-        // now move transitions
+        // now move transitions
         mlt_service serv = m_mltProducer->parent().get_service();
         mlt_service nextservice = mlt_service_get_producer(serv);
         mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
@@ -1858,7 +1863,7 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up
             if (clipService.detach(*filter) == 0) success = true;
             kDebug() << " / / / DLEETED EFFECT: " << ct;
         } else if (updateIndex) {
-            // Adjust the other effects index
+            // 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);
             ct++;
         } else ct++;
@@ -2029,7 +2034,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
     //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
     Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
     if (!clip) {
-        kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
+        kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
         return false;
     }
     Mlt::Service clipService(clip->get_service());
@@ -2046,7 +2051,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
 
     if (!filter) {
         kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
-        // filter was not found, it was probably a disabled filter, so add it to the correct place...
+        // filter was not found, it was probably a disabled filter, so add it to the correct place...
         int ct = 0;
         filter = clipService.filter(ct);
         QList <Mlt::Filter *> filtersList;
@@ -2083,7 +2088,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par
 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
 {
 
-    kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
+    kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
     Mlt::Service service(m_mltProducer->parent().get_service());
 
     Mlt::Tractor tractor(service);
@@ -2092,7 +2097,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
     //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
     Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
     if (!clip) {
-        kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
+        kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
         return;
     }
     Mlt::Service clipService(clip->get_service());
@@ -2178,21 +2183,24 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
         return false;
     }
     int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
-    kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
+    //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
     Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
     int previousStart = clip->get_in();
-    int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
     int newDuration = (int) clipDuration.frames(m_fps) - 1;
+    int diff = newDuration - trackPlaylist.clip_length(clipIndex) - 1;
+    if (newDuration > clip->get_length()) {
+        clip->parent().set("length", newDuration + 1);
+        clip->set("length", newDuration + 1);
+    }
     trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
     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 << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
+    //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 (clipIndex < trackPlaylist.count()) {
-            // If this is not the last clip in playlist
+            // 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;
@@ -2509,7 +2517,7 @@ 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);
@@ -2640,7 +2648,7 @@ QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
     for (int i = 0;i < attribs.count();i++) {
         QDomElement e = attribs.item(i).toElement();
         QString name = e.attribute("name");
-        //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
+        //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
         map[name] = e.attribute("default");
         if (!e.attribute("value").isEmpty()) {
             map[name] = e.attribute("value");
@@ -2826,6 +2834,8 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
     QString key;
     if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
     //kDebug() << " ------  ADDING TRANSITION PARAMs: " << args.count();
+    if (xml.hasAttribute("id"))
+        transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
 
     for (it = args.begin(); it != args.end(); ++it) {
         key = it.key();
@@ -2833,7 +2843,6 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
         char *value = decodedString(it.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;
     }
@@ -2847,8 +2856,8 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in,
 void Render::mltSavePlaylist()
 {
     kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
-    Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
-    fileConsumer.set("resource", "/tmp/playlist.westley");
+    Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
+    fileConsumer.set("resource", "/tmp/playlist.mlt");
 
     Mlt::Service service(m_mltProducer->get_service());
 
@@ -2931,9 +2940,13 @@ void Render::mltInsertTrack(int ix, bool videoTrack)
 
     Mlt::Tractor tractor(service);
 
-    Mlt::Playlist playlist;// = new Mlt::Playlist();
+    Mlt::Playlist playlist;
     int ct = tractor.count();
-    // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
+    if (ix > ct) {
+        kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
+        ix = ct;
+    }
+
     int pos = ix;
     if (pos < ct) {
         Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));