]> git.sesse.net Git - kdenlive/commitdiff
Do not switch monitor when not necessary, make sure we refresh monitor when adding...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 29 Oct 2012 11:35:31 +0000 (12:35 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 29 Oct 2012 11:35:31 +0000 (12:35 +0100)
17 files changed:
src/abstractmonitor.cpp
src/abstractmonitor.h
src/commands/CMakeLists.txt
src/commands/refreshmonitorcommand.cpp [new file with mode: 0644]
src/commands/refreshmonitorcommand.h [new file with mode: 0644]
src/customtrackview.cpp
src/customtrackview.h
src/mainwindow.cpp
src/monitor.cpp
src/monitormanager.cpp
src/monitormanager.h
src/projectlist.cpp
src/projectlist.h
src/projectlistview.cpp
src/projectlistview.h
src/renderer.cpp
src/renderer.h

index fa6f43c935e96852f7a65412a2061df3e89c48a1..e66a4bd18d98a9c72e297af264c5ba4a618c0cd8 100644 (file)
@@ -59,9 +59,9 @@ bool AbstractMonitor::isActive() const
     return m_monitorManager->isActive(m_id);
 }
 
-bool AbstractMonitor::slotActivateMonitor()
+bool AbstractMonitor::slotActivateMonitor(bool forceRefresh)
 {
-    return m_monitorManager->activateMonitor(m_id);
+    return m_monitorManager->activateMonitor(m_id, forceRefresh);
 }
 
 VideoContainer::VideoContainer(AbstractMonitor* monitor, QWidget *parent) :
index 0a8212888f3f3f16a9f90bd4ae9daeab2986dac9..eec0cfefb30cf0af7965febcf7bc4a34f9ef5cda 100644 (file)
@@ -105,7 +105,7 @@ public slots:
     virtual void start() = 0;
     virtual void slotPlay() = 0;
     virtual void slotMouseSeek(int eventDelta, bool fast) = 0;
-    bool slotActivateMonitor();
+    bool slotActivateMonitor(bool forceRefresh = false);
     virtual void slotSwitchFullScreen() = 0;
 
 protected:
index 5da8b75bcfcdbccc1b062d0c14ba5b12f79aa10d..cface28b86d46d634affe615d73ea1ae442554e4 100644 (file)
@@ -30,6 +30,7 @@ set(kdenlive_SRCS
   commands/razorclipcommand.cpp
   commands/razorgroupcommand.cpp
   commands/rebuildgroupcommand.cpp
+  commands/refreshmonitorcommand.cpp
   commands/resizeclipcommand.cpp
   commands/splitaudiocommand.cpp
   PARENT_SCOPE
diff --git a/src/commands/refreshmonitorcommand.cpp b/src/commands/refreshmonitorcommand.cpp
new file mode 100644 (file)
index 0000000..8130bbb
--- /dev/null
@@ -0,0 +1,46 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#include "refreshmonitorcommand.h"
+#include "customtrackview.h"
+
+
+RefreshMonitorCommand::RefreshMonitorCommand(CustomTrackView *view, bool execute, QUndoCommand * parent) :
+        QUndoCommand(parent),
+        m_view(view),
+        m_exec(execute)
+{
+}
+
+
+// virtual
+void RefreshMonitorCommand::undo()
+{
+    m_view->monitorRefresh();
+}
+// virtual
+void RefreshMonitorCommand::redo()
+{
+    if (m_exec)
+       m_view->monitorRefresh();
+    m_exec = true;
+}
+
+
diff --git a/src/commands/refreshmonitorcommand.h b/src/commands/refreshmonitorcommand.h
new file mode 100644 (file)
index 0000000..5a11a4c
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef REFRESHMONITORCOMMAND_H
+#define REFRESHMONITORCOMMAND_H
+
+#include <QUndoCommand>
+
+class CustomTrackView;
+
+class RefreshMonitorCommand : public QUndoCommand
+{
+public:
+    RefreshMonitorCommand(CustomTrackView *view, bool execute, QUndoCommand * parent = 0);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    bool m_exec;
+};
+
+#endif
+
index addd479fc335faed2f50d77d86aba51fa321aab8..84952f9bc9d3aeb10347f8103c766f77a425bead 100644 (file)
@@ -63,6 +63,7 @@
 #include "commands/configtrackscommand.h"
 #include "commands/rebuildgroupcommand.h"
 #include "commands/razorgroupcommand.h"
+#include "commands/refreshmonitorcommand.h"
 #include "profilesdialog.h"
 
 #include "lib/audio/audioEnvelope.h"
@@ -2711,7 +2712,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
             emit clipItemSelected((ClipItem*) m_dragItem, false);
         }
-        m_document->renderer()->doRefresh();
+        m_document->renderer()->refreshIfActive();
         event->setDropAction(Qt::MoveAction);
         event->accept();
 
@@ -3428,8 +3429,10 @@ void CustomTrackView::deleteClip(const QString &clipId)
         delete deleteCommand;
     } else {
         updateTrackDuration(-1, deleteCommand);
+       new RefreshMonitorCommand(this, false, deleteCommand);
         m_commandStack->push(deleteCommand);
     }
+    m_document->renderer()->doRefresh();    
 }
 
 void CustomTrackView::seekCursorPos(int pos)
@@ -4197,7 +4200,9 @@ void CustomTrackView::deleteSelectedClips()
         deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
     else deleteSelected->setText(i18n("Delete selected items"));
     updateTrackDuration(-1, deleteSelected);
+    new RefreshMonitorCommand(this, false, deleteSelected);
     m_commandStack->push(deleteSelected);
+    m_document->renderer()->doRefresh();
 }
 
 
@@ -6011,6 +6016,7 @@ void CustomTrackView::pasteClip()
         }
     }
     updateTrackDuration(-1, pasteClips);
+    new RefreshMonitorCommand(this, false, pasteClips);
     m_commandStack->push(pasteClips);
 }
 
@@ -6823,6 +6829,11 @@ void CustomTrackView::setAudioAndVideo()
     m_commandStack->push(videoCommand);
 }
 
+void CustomTrackView::monitorRefresh()
+{
+    m_document->renderer()->doRefresh();
+}
+
 void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly)
 {
     ClipItem *clip = getClipItemAt(pos, track);
index 5515c7e8185b33dbf86033e677f87187ca16e5d6..f27f9710d489ee7a850bf5f1e3d6bcdbd30c49e8 100644 (file)
@@ -205,6 +205,9 @@ public:
     int getFrameWidth();
     /** @brief Returns last requested seeking pos (or SEEK_INACTIVE if no seek). */
     int seekPosition() const;
+
+    /** @brief Trigger a monitor refresh. */
+    void monitorRefresh();
     
 public slots:
     /** @brief Send seek request to MLT. */
index da448cc912b9f2ecbd00fb994440b27f0c9b9cee..9139b6d2ec72b6ef2b6460a0131c4152f61b025a 100644 (file)
@@ -234,7 +234,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
 
     // Connect the project list
     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint, bool)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool)));
-    connect(m_projectList, SIGNAL(raiseClipMonitor()), m_clipMonitor, SLOT(slotActivateMonitor()));
+    connect(m_projectList, SIGNAL(raiseClipMonitor(bool)), m_clipMonitor, SLOT(slotActivateMonitor(bool)));
     connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
index 67b35e92117784819422d209cf54a9864490a173..02a9d92178e064c5042f6b2431f67c13afcca86c 100644 (file)
@@ -743,7 +743,7 @@ void Monitor::stop()
 void Monitor::start()
 {
     if (!isVisible() || !isActive()) return;
-    if (render) render->doRefresh();// start();
+    if (render) render->startConsumer();
 }
 
 void Monitor::refreshMonitor(bool visible)
@@ -842,7 +842,6 @@ void Monitor::slotSetClipProducer(DocClipBase *clip, QPoint zone, bool forceUpda
        if (m_currentClip) m_currentClip->lastSeekPosition = render->seekFramePosition();
         m_currentClip = clip;
        if (position == -1) position = clip->lastSeekPosition;
-        if (m_currentClip) slotActivateMonitor();
         updateMarkers(clip);
         Mlt::Producer *prod = NULL;
         if (clip) prod = clip->getCloneProducer();
index 09c6c1e149d46f761aab230ffc147251a0c3dbed..178ffc1d1aec12e4cf3724bcbef75bde06284cc1 100644 (file)
@@ -74,12 +74,14 @@ AbstractMonitor* MonitorManager::monitor(Kdenlive::MONITORID monitorName)
     return monitor;
 }
 
-bool MonitorManager::activateMonitor(Kdenlive::MONITORID name)
+bool MonitorManager::activateMonitor(Kdenlive::MONITORID name, bool forceRefresh)
 {
     if (m_clipMonitor == NULL || m_projectMonitor == NULL)
         return false;
-    if (m_activeMonitor && m_activeMonitor->id() == name)
+    if (m_activeMonitor && m_activeMonitor->id() == name) {
+       if (forceRefresh) m_activeMonitor->start();
         return false;
+    }
     m_activeMonitor = NULL;
     for (int i = 0; i < m_monitorsList.count(); i++) {
         if (m_monitorsList.at(i)->id() == name) {
index 880b6d1279a924390725468115922258b7a12e46..8ce0e3f3ff4d8f4eaee822263ed141ac64148b26 100644 (file)
@@ -50,7 +50,7 @@ public slots:
 
     /** @brief Activates a monitor.
      * @param name name of the monitor to activate */
-    bool activateMonitor(Kdenlive::MONITORID);
+    bool activateMonitor(Kdenlive::MONITORID, bool forceRefresh = false);
     bool isActive(Kdenlive::MONITORID id) const;
     void slotPlay();
     void slotPause();
index 022b1971b9eb8c2a4fd17c27b8664c41ff4c67aa..3cb9cad7bf7e33c779d9775286fca617fd6029a1 100644 (file)
@@ -310,7 +310,7 @@ ProjectList::ProjectList(QWidget *parent) :
     connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
-    connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
+    connect(m_listView, SIGNAL(focusMonitor(bool)), this, SIGNAL(raiseClipMonitor(bool)));
     connect(m_listView, SIGNAL(pauseMonitor()), this, SIGNAL(pauseMonitor()));
     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
     connect(m_listView, SIGNAL(addClip()), this, SIGNAL(pauseMonitor()));
index ef290dad26df73769eb2040760d2dd8dfe103b57..49bccdf0e87374f87c74e332bdc6b876378a2eb5 100644 (file)
@@ -515,7 +515,7 @@ signals:
     void updateProfile(const QString &);
     void processNextThumbnail();
     /** @brief Activate the clip monitor. */
-    void raiseClipMonitor();
+    void raiseClipMonitor(bool forceRefresh);
     /** @brief Set number of running jobs. */
     void jobCount(int);
     void cancelRunningJob(const QString, stringMap);
index 21e212c220bc467f3bcfc1913610add2187bf636..74f306bfb13024f3dac537739f60905813344e87 100644 (file)
@@ -333,7 +333,7 @@ void ProjectListView::mouseReleaseEvent(QMouseEvent *event)
 {
     QTreeWidget::mouseReleaseEvent(event);
     QTreeWidgetItem *underMouse = itemAt(event->pos());
-    if (underMouse) emit focusMonitor();
+    if (underMouse) emit focusMonitor(true);
 }
 
 // virtual
index 26e2c58158995870c03ff2e332b35730ed0f1270..55a0e212987156df519f812d57b30bf97c05c17a 100644 (file)
@@ -70,7 +70,7 @@ signals:
     void addClip();
     void addClip(const QList <QUrl>, const QString &, const QString &);
     void showProperties(DocClipBase *);
-    void focusMonitor();
+    void focusMonitor(bool forceRefresh);
     void pauseMonitor();
     void addClipCut(const QString&, int, int);
     void projectModified();
index 12e30d94d2714c4c33e49c43096b2b8d28d486ad..d54c90e6f8d414a4d3fb72154306026d10d17f19 100644 (file)
@@ -1095,8 +1095,10 @@ int Render::setProducer(Mlt::Producer *producer, int position)
         if (producer) delete producer;
         return -1;
     }
+    bool monitorIsActive = false;
     m_mltConsumer->set("refresh", 0);
     if (!m_mltConsumer->is_stopped()) {
+       monitorIsActive = true;
         m_mltConsumer->stop();
     }
     m_mltConsumer->purge();
@@ -1160,8 +1162,15 @@ int Render::setProducer(Mlt::Producer *producer, int position)
     }
     m_mltProducer = producer;
     m_mltProducer->set_speed(0);
+    if (monitorIsActive) startConsumer();
     emit durationChanged(m_mltProducer->get_playtime());
-    if (m_mltConsumer->start() == -1) {
+    position = m_mltProducer->position();
+    emit rendererPosition(position);
+    return 0;
+}
+
+void Render::startConsumer() {
+  if (m_mltConsumer->is_stopped() && m_mltConsumer->start() == -1) {
         // ARGH CONSUMER BROKEN!!!!
         KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
         if (m_showFrameEvent) delete m_showFrameEvent;
@@ -1170,18 +1179,14 @@ int Render::setProducer(Mlt::Producer *producer, int position)
         m_pauseEvent = NULL;
         delete m_mltConsumer;
         m_mltConsumer = NULL;
-        return -1;
+        return;
     }
-
-    position = m_mltProducer->position();
     m_mltConsumer->set("refresh", 1);
     // Make sure the first frame is displayed, otherwise if we change producer too fast
     // We can crash the avformat producer
     Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show");
     m_mltConsumer->wait_for(ev);
     delete ev;
-    emit rendererPosition(position);
-    return 0;
 }
 
 int Render::setSceneList(QDomDocument list, int position)
@@ -1641,6 +1646,11 @@ void Render::seekToFrameDiff(int diff)
     else seek(requestedSeekPosition + diff);
 }
 
+void Render::refreshIfActive()
+{
+    if (!m_mltConsumer->is_stopped() && m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
+}
+
 void Render::doRefresh()
 {
     if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
index f1ca980ce43f5420cd1622136deebafbe24d9cc6..9813d6270c9e9892d24e7f6d072ddba3bbe6c204 100644 (file)
@@ -199,6 +199,10 @@ Q_OBJECT public:
     double dar() const;
     /** @brief Returns sample aspect ratio. */
     double sar() const;
+    /** @brief If monitor is active, refresh it. */
+    void refreshIfActive();
+    /** @brief Start the MLT monitor consumer. */
+    void startConsumer();
 
     /*
      * Playlist manipulation.