[vlmc-devel] SequenceWorkflow: Fix resize undo/redo

Hugo Beauzée-Luyssen git at videolan.org
Sun Oct 30 22:36:39 CET 2016


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sun Oct 30 18:45:07 2016 +0100| [e5719f600b940612e23cf5e8e1269ce09b16fbec] | committer: Hugo Beauzée-Luyssen

SequenceWorkflow: Fix resize undo/redo

We now duplicate the clips when resizing, otherwise multiple clips would
share the same begin/end during the resize

> https://code.videolan.org/videolan/vlmc/commit/e5719f600b940612e23cf5e8e1269ce09b16fbec
---

 src/Workflow/SequenceWorkflow.cpp | 21 ++++++++++++++++++++-
 src/Workflow/SequenceWorkflow.h   | 11 +++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/Workflow/SequenceWorkflow.cpp b/src/Workflow/SequenceWorkflow.cpp
index 71ed30e..f9c9154 100644
--- a/src/Workflow/SequenceWorkflow.cpp
+++ b/src/Workflow/SequenceWorkflow.cpp
@@ -132,7 +132,15 @@ SequenceWorkflow::resizeClip( const QUuid& uuid, qint64 newBegin, qint64 newEnd,
     auto trackId = c->trackId;
     auto position = c->pos;
     auto t = track( trackId, c->isAudio );
-    auto ret = t->resizeClip( t->clipIndexAt( position ), newBegin, newEnd );
+    auto clipIndex = t->clipIndexAt( position );
+    // This will only duplicate the clip once; no need to panic about endless duplications
+    if ( c->duplicateClipForResize( newBegin, newEnd ) == true )
+    {
+        vlmcDebug() << "Duplicating clip for resize" << c->uuid << "is now using" << c->clip->uuid();
+        t->remove( clipIndex );
+        t->insertAt( *c->clip->input(), position );
+    }
+    auto ret = t->resizeClip( clipIndex, newBegin, newEnd );
     if ( ret == false )
         return false;
     ret = moveClip( uuid, trackId, newPos );
@@ -334,5 +342,16 @@ SequenceWorkflow::ClipInstance::ClipInstance(QSharedPointer<::Clip> c, const QUu
     , trackId( tId )
     , pos( p )
     , isAudio( isAudio )
+    , m_hasClonedClip( false )
+{
+}
+
+bool
+SequenceWorkflow::ClipInstance::duplicateClipForResize( qint64 begin, qint64 end )
 {
+    if ( m_hasClonedClip == true )
+        return false;
+    clip = clip->media()->cut( begin, end );
+    m_hasClonedClip = true;
+    return true;
 }
diff --git a/src/Workflow/SequenceWorkflow.h b/src/Workflow/SequenceWorkflow.h
index 35bac2b..4986b9e 100644
--- a/src/Workflow/SequenceWorkflow.h
+++ b/src/Workflow/SequenceWorkflow.h
@@ -67,6 +67,17 @@ class SequenceWorkflow : public QObject
             QVector<QUuid>          linkedClips;
             // true is this instance represents an audio track, false otherwise
             bool                    isAudio;
+
+            ///
+            /// \brief duplicateClipForResize   Duplicates the used clip for enabling it to be resize independently
+            /// \param begin        The new begining for this clip
+            /// \param end          The new end for this clip
+            ///
+            bool                    duplicateClipForResize( qint64 begin, qint64 end );
+
+        private:
+            // true if this instance now contains its own Clip
+            bool                    m_hasClonedClip;
         };
 
         /**



More information about the Vlmc-devel mailing list