]> git.sesse.net Git - kdenlive/commitdiff
Fix crash on clip insertion redo:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 29 Dec 2008 00:39:33 +0000 (00:39 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 29 Dec 2008 00:39:33 +0000 (00:39 +0000)
http://www.kdenlive.org:80/mantis/bug_view_page.php?bug_id=526

Fix timeline position not restored after loading project file

svn path=/branches/KDE4/; revision=2851

src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/projectlist.cpp
src/renderer.cpp
src/renderer.h

index a9b1210654f04f65b881095ad678abd295467755..ec7322e7b4ea5eecb5f85eccca27749070ef8c2c 100644 (file)
@@ -43,8 +43,7 @@
 #include "titlewidget.h"
 #include "mainwindow.h"
 
-
-KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7), m_autosave(NULL) {
+KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent): QObject(parent), m_render(render), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7), m_autosave(NULL) {
     m_clipManager = new ClipManager(this);
     m_autoSaveTimer = new QTimer(this);
     m_autoSaveTimer->setSingleShot(true);
@@ -186,7 +185,12 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
     else m_timecode.setFormat((int) m_fps);
 
+    m_render->setSceneList(m_document.toString(), m_startPos);
+    //kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
+    checkProjectClips();
+
     connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
+
 }
 
 KdenliveDoc::~KdenliveDoc() {
@@ -968,6 +972,7 @@ QUndoStack *KdenliveDoc::commandStack() {
     return m_commandStack;
 }
 
+/*
 void KdenliveDoc::setRenderer(Render *render) {
     if (m_render) return;
     m_render = render;
@@ -979,7 +984,7 @@ void KdenliveDoc::setRenderer(Render *render) {
         checkProjectClips();
     }
     emit progressInfo(QString(), -1);
-}
+}*/
 
 void KdenliveDoc::checkProjectClips() {
     if (m_render == NULL) return;
@@ -1147,6 +1152,10 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
     int subtrack = clipId.section('_', 1, 1).toInt();
     DocClipBase *clip = m_clipManager->getClipById(producerId);
     if (clip == NULL) {
+        /*kDebug()<<"// CLIP "<<clipId<<" NOT OFUND in LIST, CREATING";
+        QDomDocument doc;
+        doc.appendChild(doc.importNode(elem, true));
+        kDebug() << "IMPORTED CLIP: \n" << doc.toString()<<"\n";*/
         elem.setAttribute("id", producerId);
         QString path = elem.attribute("resource");
         QString extension;
@@ -1186,9 +1195,14 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem)
         clip = new DocClipBase(m_clipManager, elem, producerId);
         m_clipManager->addClip(clip);
     }
-    if (createClipItem) emit addProjectClip(clip);
+    if (createClipItem) {
+        emit addProjectClip(clip);
+        qApp->processEvents();
+        m_render->getFileProperties(clip->toXML(), clip->getId());
+    }
 }
 
+
 void KdenliveDoc::setNewClipResource(const QString &id, const QString &path) {
     QDomNodeList prods = m_document.elementsByTagName("producer");
     int maxprod = prods.count();
@@ -1247,7 +1261,7 @@ QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &match
 void KdenliveDoc::addClipInfo(QDomElement elem, QString clipId) {
     DocClipBase *clip = m_clipManager->getClipById(clipId);
     if (clip == NULL) {
-        addClip(elem, clipId);
+        addClip(elem, clipId, false);
     } else {
         QMap <QString, QString> properties;
         QDomNamedNodeMap attributes = elem.attributes();
index 92245fd1d186dfb30c8929c7577199815f4cf76e..8cc4b42d1f9b29bfa18a09de1c74f20fbe8c4032 100644 (file)
@@ -48,7 +48,7 @@ class TrackInfo;
 class KdenliveDoc: public QObject {
 Q_OBJECT public:
 
-    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, MainWindow *parent = 0);
+    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent = 0);
     ~KdenliveDoc();
     QDomNodeList producersList();
     double fps() const;
@@ -59,7 +59,7 @@ Q_OBJECT public:
     void backupMltPlaylist();
     Timecode timecode() const;
     QDomDocument toXml();
-    void setRenderer(Render *render);
+    //void setRenderer(Render *render);
     QUndoStack *commandStack();
     QString producerName(const QString &id);
     void setProducerDuration(const QString &id, int duration);
index 2b1eb67d66a55e12abbb63143c72626d9f6d38cd..85dcd0adc09ba10d4426f62612419b2a8ab82e1d 100644 (file)
@@ -482,14 +482,14 @@ void MainWindow::slotSetClipDuration(const QString &id, int duration) {
 
 void MainWindow::slotConnectMonitors() {
 
-    m_projectList->setRenderer(m_clipMonitor->render);
+    m_projectList->setRenderer(m_projectMonitor->render);
     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
-    connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
-    connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
-    connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
+    connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_projectMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
+    connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
+    connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
 
-    connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
+    connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
 
     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
 
@@ -963,7 +963,7 @@ void MainWindow::newFile(bool showProjectSettings) {
         projectTracks = w->tracks();
         delete w;
     }
-    KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
+    KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
     TrackView *trackView = new TrackView(doc, this);
     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
@@ -1076,6 +1076,7 @@ void MainWindow::openFile() {
 void MainWindow::openLastFile() {
     KSharedConfigPtr config = KGlobal::config();
     KUrl::List urls = m_fileOpenRecent->urls();
+    //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction ?
     if (urls.isEmpty()) newFile(false);
     else openFile(urls.last());
 }
@@ -1121,7 +1122,7 @@ void MainWindow::openFile(const KUrl &url) {
 
 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
     KdenliveDoc *doc;
-    doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
+    doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), m_projectMonitor->render, this);
     if (stale == NULL) {
         stale = new KAutoSaveFile(url, doc);
         doc->m_autosave = stale;
@@ -1135,6 +1136,8 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
     TrackView *trackView = new TrackView(doc, this);
     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
+    trackView->setDuration(trackView->duration());
+    trackView->projectView()->setCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
     slotGotProgressInfo(QString(), -1);
     m_clipMonitor->refreshMonitor(true);
@@ -1384,7 +1387,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
             effectStack->clear();
         }
-        m_activeDocument->setRenderer(NULL);
+        //m_activeDocument->setRenderer(NULL);
         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
         m_clipMonitor->stop();
     }
@@ -1445,7 +1448,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
     m_activeTimeline = trackView;
     if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
-    doc->setRenderer(m_projectMonitor->render);
+    //doc->setRenderer(m_projectMonitor->render);
     m_commandStack->setActiveStack(doc->commandStack());
     KdenliveSettings::setProject_display_ratio(doc->dar());
     m_projectList->updateAllClips();
index 72372e4da80983c37e372e1bf5fb2271d8c8610c..0e58a44791e169726f0aa1c98cc06a36f7604332 100644 (file)
@@ -319,6 +319,7 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
 }
 
 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
+    if (getProperties) listView->setEnabled(false);
     const QString parent = clip->getProperty("groupid");
     //kDebug() << "Adding clip with groupid: " << parent;
     ProjectItem *item = NULL;
@@ -356,7 +357,6 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
         }
         if (!annotation.isEmpty()) item->setText(2, annotation);
     }
-    if (getProperties) requestClipInfo(clip->toXML(), clip->getId());
 }
 
 void ProjectList::requestClipInfo(const QDomElement xml, const QString id) {
@@ -617,6 +617,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         emit receivedClipDuration(clipId, item->clipMaxDuration());
     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
     if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
+    else listView->setEnabled(true);
 }
 
 void ProjectList::slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h) {
index 40354c538c6af730d2e401d9f6d84b85c89af2bd..d13619554574520e535fd07877366b0ae87f8176 100644 (file)
@@ -95,6 +95,7 @@ void Render::buildConsumer() {
     char *tmp;
     tmp = decodedString(KdenliveSettings::current_profile());
     m_mltProfile = new Mlt::Profile(tmp);
+    setenv("MLT_PROFILE", tmp, 1);
     delete[] tmp;
 
 
@@ -150,20 +151,25 @@ int Render::resetProfile() {
         kDebug() << "reset to same profile, nothing to do";
         return 1;
     }
+    kDebug() << "// RESETTING PROFILE FROM: " << currentProfile << " TO: " << KdenliveSettings::current_profile();
     if (m_isSplitView) slotSplitView(false);
     if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
     m_mltConsumer->purge();
     delete m_mltConsumer;
     m_mltConsumer = NULL;
     QString scene = sceneList();
-    if (m_mltProducer) delete m_mltProducer;
+    int pos = 0;
+    if (m_mltProducer) {
+        pos = m_mltProducer->position();
+        delete m_mltProducer;
+    }
     m_mltProducer = NULL;
     if (m_mltProfile) delete m_mltProfile;
     m_mltProfile = NULL;
     buildConsumer();
 
     //kDebug() << "//RESET WITHSCENE: " << scene;
-    setSceneList(scene);
+    setSceneList(scene, pos);
 
     char *tmp = decodedString(scene);
     Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
@@ -810,7 +816,8 @@ void Render::setSceneList(QString playlist, int position) {
     }
     m_isBlocked = false;
     blockSignals(false);
-    emit rendererPosition(position);
+    //kDebug()<<"// SETSCN LST, POS: "<<position;
+    //if (position != 0) emit rendererPosition(position);
 }
 
 /** Create the producer from the Westley QDomDocument */
@@ -1209,7 +1216,7 @@ void Render::exportCurrentFrame(KUrl url, bool notify) {
 /** MLT PLAYLIST DIRECT MANIPULATON  **/
 
 
-void Render::mltCheckLength(bool reload) {
+void Render::mltCheckLength() {
     //kDebug()<<"checking track length: "<<track<<"..........";
 
     Mlt::Service service(m_mltProducer->get_service());
index 217eb79bda9e9bca7783ee72496022f48f1f27ba..98b109c259f38e02ee4de57d10a5292a967cde62 100644 (file)
@@ -217,7 +217,7 @@ private:   // Private attributes & methods
 
     /** Sets the description of this renderer to desc. */
     void closeMlt();
-    void mltCheckLength(bool reload = true);
+    void mltCheckLength();
     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
     void buildConsumer();