From 80c878e198cde92fcb14be699b0983e3e936789d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 29 Dec 2008 00:39:33 +0000 Subject: [PATCH] Fix crash on clip insertion redo: 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 | 24 +++++++++++++++++++----- src/kdenlivedoc.h | 4 ++-- src/mainwindow.cpp | 21 ++++++++++++--------- src/projectlist.cpp | 3 ++- src/renderer.cpp | 15 +++++++++++---- src/renderer.h | 2 +- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index a9b12106..ec7322e7 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -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 "<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 properties; QDomNamedNodeMap attributes = elem.attributes(); diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 92245fd1..8cc4b42d 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2b1eb67d..85dcd0ad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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(); diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 72372e4d..0e58a447 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -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) { diff --git a/src/renderer.cpp b/src/renderer.cpp index 40354c53..d1361955 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -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: "<get_service()); diff --git a/src/renderer.h b/src/renderer.h index 217eb79b..98b109c2 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -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 mltGetTransitionParamsFromXml(QDomElement xml); QMap m_slowmotionProducers; void buildConsumer(); -- 2.39.2