]> git.sesse.net Git - kdenlive/commitdiff
Trying to fix a bug with the clip move undo command. No success.
authorSimon A. Eugster <simon.eu@gmail.com>
Wed, 15 Feb 2012 20:29:13 +0000 (21:29 +0100)
committerSimon A. Eugster <simon.eu@gmail.com>
Wed, 15 Feb 2012 20:29:13 +0000 (21:29 +0100)
src/CMakeLists.txt
src/commands/moveclipcommand.cpp
src/commands/moveclipcommand.h
src/customtrackview.cpp
src/customtrackview.h
src/definitions.cpp [new file with mode: 0644]
src/definitions.h
src/gentime.cpp
src/gentime.h
src/renderer.cpp

index f69796e3ee565294a5c23650f632aa414596e0b5..d26352fca094c8ac30c6724102951272f0be43b6 100644 (file)
@@ -133,6 +133,7 @@ list(APPEND kdenlive_SRCS
   customruler.cpp
   customtrackscene.cpp
   customtrackview.cpp
+  definitions.cpp
   docclipbase.cpp
   documentchecker.cpp
   documentvalidator.cpp
index 659c09faad669e31687fc9f1ad0a0f6dbeb88828..b590b97dcb4f69239df46fe507c174a2f14d04ce 100644 (file)
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                 2012    Simon A. Eugster <simon.eu@gmail.com>           *
  *                                                                         *
  *   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  *
 #include <KLocale>
 
 MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool doIt, QUndoCommand * parent) :
-        QUndoCommand(parent),
-        m_view(view),
-        m_startPos(start),
-        m_endPos(end),
-        m_doIt(doIt)
+    QUndoCommand(parent),
+    m_view(view),
+    m_startPos(start),
+    m_endPos(end),
+    m_doIt(doIt),
+    m_success(true)
 {
     setText(i18n("Move clip"));
     if (parent) {
@@ -38,19 +40,22 @@ MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, co
 }
 
 
-// virtual
 void MoveClipCommand::undo()
 {
-// kDebug()<<"----  undoing action";
     m_doIt = true;
-    m_view->moveClip(m_endPos, m_startPos, m_refresh);
+    // We can only undo what was done;
+    // if moveClip() failed in redo() the document does (or should) not change.
+    if (m_success) {
+        m_view->moveClip(m_endPos, m_startPos, m_refresh);
+    }
 }
-// virtual
 void MoveClipCommand::redo()
 {
-    //kDebug() << "----  redoing action";
-    if (m_doIt)
-        m_view->moveClip(m_startPos, m_endPos, m_refresh);
+    if (m_doIt) {
+        qDebug() << "Executing move clip command. End now:" << m_endPos;
+        m_success = m_view->moveClip(m_startPos, m_endPos, m_refresh, &m_endPos);
+        qDebug() << "Move clip command executed. End now: " << m_endPos;
+    }
     m_doIt = true;
 }
 
index 5b7d99ffecac95d1495be7a3dba530be8fd19886..3ab20cb22dd3e5b6f33f014580e234abbac23a33 100644 (file)
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                 2012    Simon A. Eugster <simon.eu@gmail.com>           *
  *                                                                         *
  *   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  *
@@ -37,9 +38,10 @@ public:
 private:
     CustomTrackView *m_view;
     const ItemInfo m_startPos;
-    const ItemInfo m_endPos;
+    ItemInfo m_endPos;
     bool m_doIt;
     bool m_refresh;
+    bool m_success;
 };
 
 #endif
index 7f30a686af0337ad07225efa7957e71530359cb6..1a0a8ebb1acdc8c70459fae14ea6e5877b12ad7b 100644 (file)
@@ -4292,18 +4292,24 @@ Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track)
     return clip;
 }
 
-void CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh)
+bool CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh, ItemInfo *out_actualEnd)
 {
     if (m_selectionGroup) resetSelectionGroup(false);
     ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track);
     if (!item) {
         emit displayMessage(i18n("Cannot move clip at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage);
         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";
-        return;
+        return false;
     }
     Mlt::Producer *prod = item->getProducer(end.track);
 
-    bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod);
+    qDebug() << "Moving item " << (long)item << " from .. to:";
+    qDebug().maybeSpace() << item->info();
+    qDebug() << start;
+    qDebug() << end;
+    bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track),
+                                                       (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()),
+                                                       prod);
     if (success) {
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
@@ -4333,6 +4339,12 @@ void CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool
         emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage);
     }
     if (refresh) m_document->renderer()->doRefresh();
+    if (out_actualEnd != NULL) {
+        *out_actualEnd = item->info();
+        qDebug() << "Actual end position updated:" << *out_actualEnd;
+    }
+    qDebug() << item->info();
+    return success;
 }
 
 void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime &offset, const int trackOffset, bool reverseMove)
@@ -6029,7 +6041,7 @@ void CustomTrackView::alignAudio()
                 QUndoCommand *moveCommand = new QUndoCommand();
                 moveCommand->setText(i18n("Auto-align clip"));
                 new MoveClipCommand(this, start, end, true, moveCommand);
-                moveClip(start, end, true);
+//                moveClip(start, end, true);
                 updateTrackDuration(clip->track(), moveCommand);
                 m_commandStack->push(moveCommand);
 
index 5d932b5d69011259e77d80f9914fea26fc154de6..66ee744b8a791d0a67854e7e5a2d6b7145933cee 100644 (file)
@@ -61,7 +61,13 @@ public:
     void configTracks(QList <TrackInfo> trackInfos);
     int cursorPos();
     void checkAutoScroll();
-    void moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh);
+    /**
+      Move the clip at \c start to \c end.
+
+      If \c out_actualEnd is not NULL, it will be set to the position the clip really ended up at.
+      For example, attempting to move a clip to t = -1 s will actually move it to t = 0 s.
+      */
+    bool moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh, ItemInfo *out_actualEnd = NULL);
     void moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime &offset, const int trackOffset, bool reverseMove = false);
     /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
     void moveTransition(const ItemInfo &start, const ItemInfo &end, bool refresh);
diff --git a/src/definitions.cpp b/src/definitions.cpp
new file mode 100644 (file)
index 0000000..2112faf
--- /dev/null
@@ -0,0 +1,12 @@
+#include "definitions.h"
+
+QDebug operator << (QDebug qd, const ItemInfo &info)
+{
+    qd << "ItemInfo " << &info;
+    qd << "\tTrack" << info.track;
+    qd << "\tStart pos: " << info.startPos.toString();
+    qd << "\tEnd pos: " << info.endPos.toString();
+    qd << "\tCrop start: " << info.cropStart.toString();
+    qd << "\tCrop duration: " << info.cropDuration.toString();
+    return qd.maybeSpace();
+}
index 9c69a485806da5b53252f000ed7db63b1b0c8cdc..a9c55c85aad0105b6a2e5ce471952c493725497d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <QTreeWidgetItem>
 #include <KLocale>
+#include <QDebug>
 
 const int MAXCLIPDURATION = 15000;
 
@@ -215,5 +216,7 @@ private:
 
 };
 
+QDebug operator << (QDebug qd, const ItemInfo &info);
+
 
 #endif
index 21eb7b70af76466539db9460a1688a296003f0e1..82e0d9c7a61839795d273abea24aa9c102af7d8a 100644 (file)
@@ -54,3 +54,8 @@ GenTime& GenTime::roundNearestFrame(double framesPerSecond)
     m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond;
     return *this;
 }
+
+QString GenTime::toString() const
+{
+    return QString("%1 s").arg(m_time, 0, 'f', 2);
+}
index 34f7bc59a2fc158bea78ab68a9303a2481928648..e927eabbc9f54a2f8f6cd4a633463ce0e6c33dbf 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef GENTIME_H
 #define GENTIME_H
 
+#include <QString>
 #include <cmath>
 
 /**
@@ -52,6 +53,8 @@ public:
     * @param framesPerSecond Number of frames per second */
     GenTime & roundNearestFrame(double framesPerSecond);
 
+    QString toString() const;
+
 
     /*
      * Operators.
index 3dd02443f01c6d1c5783c37d01bed8a249109e9d..9bb3c8a88d8f29f39ea5c1816ac4e9d6b01f9c38 100644 (file)
@@ -3344,6 +3344,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
         Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
         if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
             // error, destination is not empty
+            kDebug() << "Cannot move: Destination is not empty";
             service.unlock();
             return false;
         } else {