]> git.sesse.net Git - kdenlive/commitdiff
Cleanup, fix mem leaks, fix unused clips not correctly updated on profile change
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 1 Aug 2009 09:08:52 +0000 (09:08 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 1 Aug 2009 09:08:52 +0000 (09:08 +0000)
svn path=/trunk/kdenlive/; revision=3793

src/clipmanager.cpp
src/clipmanager.h
src/mainwindow.cpp
src/monitormanager.cpp
src/projectlist.cpp
src/projectlist.h
src/renderer.cpp
src/renderer.h
src/titledocument.cpp

index 032a8524958ee280f8b6a0244f353fc5f9dc0e84..2437fdade9d3de9f298c32f16af7cc2983cb2685 100644 (file)
@@ -219,6 +219,13 @@ void ClipManager::updatePreviewSettings()
     }
 }
 
+void ClipManager::clearUnusedProducers()
+{
+    for (int i = 0; i < m_clipList.count(); i++) {
+        if (m_clipList.at(i)->numReferences() == 0) m_clipList.at(i)->deleteProducers();
+    }
+}
+
 void ClipManager::resetProducersList(QList <Mlt::Producer *> prods)
 {
     for (int i = 0; i < m_clipList.count(); i++) {
@@ -236,6 +243,7 @@ void ClipManager::resetProducersList(QList <Mlt::Producer *> prods)
             kDebug() << "// // // REPLACE CLIP: " << id;
         }
     }
+    emit checkAllClips();
 }
 
 void ClipManager::slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId)
index 6eca717a67bd9ca322574d834c29fbd6f2c5765a..88d98858fd65ac8c62230d31ee088a5f5f5970e9 100644 (file)
@@ -75,6 +75,7 @@ Q_OBJECT public:
     void endAudioThumbsGeneration(const QString &requestedId);
     void askForAudioThumb(const QString &id);
     QString projectFolder() const;
+    void clearUnusedProducers();
     void resetProducersList(QList <Mlt::Producer *> prods);
     void addFolder(const QString&, const QString&);
     void deleteFolder(const QString&);
@@ -106,6 +107,7 @@ private:   // Private attributes
 
 signals:
     void reloadClip(const QString &);
+    void checkAllClips();
 };
 
 #endif
index 01070e7c29b7efb9df9e475d12f9410c6077b456..dccb563c4a51cf92d00b57174a35765bd789d35b 100644 (file)
@@ -1626,16 +1626,20 @@ void MainWindow::slotEditProjectSettings()
             KdenliveSettings::setCurrent_profile(profile);
             KdenliveSettings::setProject_fps(m_activeDocument->fps());
             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
+
+            m_activeDocument->clipManager()->clearUnusedProducers();
             m_monitorManager->resetProfiles(m_activeDocument->timecode());
+
             m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeTimeline->tracksNumber());
             m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
-            m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
+            //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
             m_activeTimeline->updateProjectFps();
+
             // We need to desactivate & reactivate monitors to get a refresh
-            m_monitorManager->switchMonitors();
+            //m_monitorManager->switchMonitors();
         }
     }
     delete w;
index b52c4dbd6106a40cacbb7d5cffa5819a48eb5dbf..7e2d184af9eddfd9fccf54e1486b5238affe3996 100644 (file)
@@ -159,7 +159,8 @@ void MonitorManager::resetProfiles(Timecode tc)
 {
     if (m_blocked) return;
     m_timecode = tc;
-    QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
+    slotResetProfiles();
+    //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
 }
 
 void MonitorManager::slotResetProfiles()
index 64f21e593125ac8ea650e5f02907b71cedfa401c..8aeb54978598e056b36b456897006fcd00f93dca 100644 (file)
@@ -772,6 +772,7 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     m_doc = doc;
 
     connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
+    connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
 
     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
     QMapIterator<QString, QString> f(flist);
@@ -853,14 +854,14 @@ void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
 {
     if (item) {
-        int height = 50;
-        int width = (int)(height  * m_render->dar());
         DocClipBase *clip = item->referencedClip();
         if (!clip) {
             slotProcessNextThumbnail();
             return;
         }
         QPixmap pix;
+        int height = 50;
+        int width = (int)(height  * m_render->dar());
         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
         else if (clip->clipType() == TEXT || clip->clipType() == IMAGE) pix = KThumb::getFrame(item->referencedClip()->producer(), 0, width, height);
         else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
index 4deff5c86b69315b8cdbe2ae18cf7e99c9f366f4..6a84ae05212e221cfb5f369d459983b6372cc8f3 100644 (file)
@@ -123,7 +123,6 @@ public:
     QDomElement producersList();
     void setRenderer(Render *projectRender);
     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
-    void updateAllClips();
     QByteArray headerInfo() const;
     void setHeaderInfo(const QByteArray &state);
     void setupMenu(QMenu *addMenu, QAction *defaultAction);
@@ -134,6 +133,7 @@ public:
 
 public slots:
     void setDocument(KdenliveDoc *doc);
+    void updateAllClips();
     void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace);
     void slotAddClip(DocClipBase *clip, bool getProperties);
index ea4f382f7811e4eb8320d220c196b5517b524eba..607f0d027e7bdb09d26030fbe18171e779233970 100644 (file)
@@ -100,21 +100,22 @@ Render::~Render()
 void Render::closeMlt()
 {
     //delete m_osdTimer;
-
-    Mlt::Service service(m_mltProducer->get_service());
-    if (service.type() == tractor_type) {
-        Mlt::Tractor tractor(service);
-        int trackNb = tractor.count();
-
-        while (trackNb > 1) {
-            Mlt::Producer trackProducer(tractor.track(trackNb - 1));
-            Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-            trackPlaylist.clear();
-            trackNb--;
+    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 > 1) {
+                Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+                trackPlaylist.clear();
+                trackNb--;
+            }
         }
     }
 
-    kDebug() << "// // // CLOSE RENDERER";
+    kDebug() << "// // // CLOSE RENDERER " << m_name;
     delete m_mltConsumer;
     delete m_mltProducer;
     delete m_blackClip;
@@ -212,13 +213,29 @@ int Render::resetProfile()
     int pos = 0;
     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 > 1) {
+                Mlt::Producer trackProducer(tractor.track(trackNb - 1));
+                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+                trackPlaylist.clear();
+                trackNb--;
+            }
+        }
+
+
         delete m_mltProducer;
     }
     m_mltProducer = NULL;
+    delete m_blackClip;
+    m_blackClip = 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();
 
@@ -864,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 > 1) {
+                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();
@@ -1094,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;
@@ -3208,9 +3221,8 @@ void Render::updatePreviewSettings()
     int pos = 0;
     if (m_mltProducer) {
         pos = m_mltProducer->position();
-        delete m_mltProducer;
     }
-    m_mltProducer = NULL;
+
     setSceneList(scene, pos);
 }
 
index b36efdb4fa9eaadc8078ac204ca7cd8de028386c..fd237706b28841872d0503a83958362cf3ecbb84 100644 (file)
@@ -280,7 +280,6 @@ public slots:  // Public slots
     void start();
     /** Stop Consumer */
     void stop();
-    void clear();
     int getLength();
     /** If the file is readable by mlt, return true, otherwise false */
     bool isValid(KUrl url);
index 99ca180a8d06ade43ccc5ad2066dcefa826554cb..5c077a0a296a768eb3b208cf054e2399f6bc89a4 100644 (file)
@@ -216,6 +216,14 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* startv, Q
 {
     QDomNodeList titles = doc.elementsByTagName("kdenlivetitle");
     //TODO: Check if the opened title size is equal to project size, otherwise warn user and rescale
+    if (doc.documentElement().hasAttribute("width") && doc.documentElement().hasAttribute("height")) {
+        int doc_width = doc.documentElement().attribute("width").toInt();
+        int doc_height = doc.documentElement().attribute("height").toInt();
+        if (doc_width != m_width || doc_height != m_height) {
+            KMessageBox::information(kapp->activeWindow(), i18n("This title clip was created with a different frame size. It will now be converted to the current project's size."), i18n("Resizing Title Clip"));
+            //TODO: convert using QTransform
+        }
+    }
     //TODO: get default title duration instead of hardcoded one
     if (doc.documentElement().hasAttribute("out"))
         *out = doc.documentElement().attribute("out").toDouble();