]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Improve handling of missing clips:
[kdenlive] / src / renderer.cpp
index 8529da5cdec5f60b250286a05f7798ca5caaf6ab..110f4122c6fa6713b054e7b6905e19e4e048edb2 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()));
+    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,13 +90,11 @@ Render::~Render()
 
 void Render::closeMlt()
 {
-    delete osdTimer;
-    delete refreshTimer;
-    if (m_mltConsumer)
-        delete m_mltConsumer;
-    if (m_mltProducer)
-        delete m_mltProducer;
-    if (m_blackClip) delete m_blackClip;
+    delete m_osdTimer;
+    delete m_refreshTimer;
+    delete m_mltConsumer;
+    delete m_mltProducer;
+    delete m_blackClip;
     //delete m_osdInfo;
 }
 
@@ -111,7 +105,7 @@ void Render::buildConsumer()
     m_activeProfile = KdenliveSettings::current_profile();
     tmp = decodedString(m_activeProfile);
     setenv("MLT_PROFILE", tmp, 1);
-    if (m_blackClip) delete m_blackClip;
+    delete m_blackClip;
     m_blackClip = NULL;
 
     m_mltProfile = new Mlt::Profile(tmp);
@@ -525,7 +519,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;
     }
@@ -714,9 +708,9 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo
 
     emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
     kDebug() << "REquested fuile info for: " << url.path();
-    if (frame) delete frame;
+    delete frame;
     // FIXME: should delete this to avoid a leak...
-    //if (producer) delete producer;
+    //delete producer;
 }
 
 
@@ -834,11 +828,13 @@ 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;
 
     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()) {
@@ -1017,7 +1013,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()
@@ -1219,7 +1215,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()
@@ -1232,7 +1228,7 @@ void Render::refresh()
 {
     if (!m_mltProducer || m_isBlocked)
         return;
-    refreshTimer->stop();
+    m_refreshTimer->stop();
     if (m_mltConsumer) {
         m_mltConsumer->set("refresh", 1);
     }
@@ -1322,13 +1318,13 @@ void Render::mltCheckLength()
     Mlt::Tractor tractor(service);
 
     int trackNb = tractor.count();
-    double duration = 0;
-    double trackDuration;
+    int duration = 0;
+    int trackDuration;
     if (trackNb == 1) {
         Mlt::Producer trackProducer(tractor.track(0));
         duration = trackProducer.get_playtime() - 1;
         m_mltProducer->set("out", duration);
-        emit durationChanged((int) duration);
+        emit durationChanged(duration);
         return;
     }
     while (trackNb > 1) {
@@ -1341,12 +1337,12 @@ void Render::mltCheckLength()
     }
 
     Mlt::Producer blackTrackProducer(tractor.track(0));
-    double blackDuration = blackTrackProducer.get_playtime() - 1;
+    int blackDuration = blackTrackProducer.get_playtime() - 1;
 
     if (blackDuration != duration) {
         Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
         blackTrackPlaylist.clear();
-        int dur = (int)duration;
+        int dur = duration;
         while (dur > 14000) {
             blackTrackPlaylist.append(*m_blackClip, 0, 13999);
             dur = dur - 14000;
@@ -1355,7 +1351,7 @@ void Render::mltCheckLength()
             blackTrackPlaylist.append(*m_blackClip, 0, dur);
         }
         m_mltProducer->set("out", duration);
-        emit durationChanged((int)duration);
+        emit durationChanged(duration);
     }
 }
 
@@ -1461,7 +1457,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"));
@@ -2933,9 +2930,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));