[vlmc-devel] Timeline: Fix losing linked clips info sometimes

Yikai Lu git at videolan.org
Wed Jul 5 18:56:03 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Thu Jul  6 00:05:21 2017 +0900| [094a8a17ba568d3a62b012145091961c6559a58b] | committer: Yikai Lu

Timeline: Fix losing linked clips info sometimes

> https://code.videolan.org/videolan/vlmc/commit/094a8a17ba568d3a62b012145091961c6559a58b
---

 src/Gui/timeline/Clip.qml     |  2 +-
 src/Gui/timeline/main.qml     | 54 ++++++++++++++++++++++---------------------
 src/Workflow/MainWorkflow.cpp |  7 ++++++
 3 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/Gui/timeline/Clip.qml b/src/Gui/timeline/Clip.qml
index d46b7e64..b95e67d6 100644
--- a/src/Gui/timeline/Clip.qml
+++ b/src/Gui/timeline/Clip.qml
@@ -32,7 +32,7 @@ Rectangle {
     property int end
     property string libraryUuid // Library UUID: For thumbnails
     property string uuid // Instance UUID
-    property var linkedClips: [] // Uuid
+    property var linkedClips: linkedClipsDict[uuid] // Uuid
     property string type
     property bool selected: false
 
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index 8c7dd1e7..80e9528f 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -20,6 +20,7 @@ Rectangle {
     property var allClips: [] // Actual clip item objects
     property var selectedClips: [] // Actual clip item objects
     property var groups: [] // list of lists of clip uuids
+    property var linkedClipsDict: ({}) // Uuid
     property alias isMagneticMode: magneticModeButton.selected
     property bool isCutMode: false
 
@@ -243,6 +244,12 @@ Rectangle {
         }
     }
 
+    function updateLinkedClips( uuid ) {
+        var item = findClipItem( uuid );
+        if ( item )
+            item.linkedClips = linkedClipsDict[uuid];
+    }
+
     function zoomIn( ratio ) {
         var newPpu = ppu;
         var newUnit = unit;
@@ -615,6 +622,7 @@ Rectangle {
             var clipInfo = workflow.clipInfo( uuid );
             var type = clipInfo["audio"] ? "Audio" : "Video";
             clipInfo["selected"] = false;
+            linkedClipsDict[uuid] = clipInfo["linkedClips"];
             addClip( type, clipInfo["trackId"], clipInfo );
             adjustTracks( type );
 
@@ -625,6 +633,8 @@ Rectangle {
             var clipInfo = workflow.clipInfo( uuid );
             var type = clipInfo["audio"] ? "Audio" : "Video";
             var oldClip = findClipFromTrackContainer( type, uuid );
+            linkedClipsDict[uuid] = clipInfo["linkedClips"];
+            updateLinkedClips( uuid );
 
             if ( clipInfo["trackId"] !== oldClip["trackId"] ) {
                 addClip( type, clipInfo["trackId"], clipInfo );
@@ -651,35 +661,27 @@ Rectangle {
         }
 
         onClipLinked: {
-            var item = findClipItem( uuidA );
-            if ( item )
-                findClipItem( uuidA ).linkedClips.push( uuidB );
-            item = findClipItem( uuidB );
-            if ( item )
-                findClipItem( uuidB ).linkedClips.push( uuidA );
+            linkedClipsDict[uuidA].push( uuidB );
+            linkedClipsDict[uuidB].push( uuidA );
+            updateLinkedClips( uuidA );
+            updateLinkedClips( uuidB );
         }
 
         onClipUnlinked: {
-            var item = findClipItem( uuidA );
-            if ( item )
-            {
-                for ( var i = 0; i < item.linkedClips.length; ++i )
-                    if ( item.linkedClips[i] === uuidB )
-                    {
-                        item.linkedClips.splice( i, 1 );
-                        break;
-                    }
-            }
-            item = findClipItem( uuidB );
-            if ( item )
-            {
-                for ( i = 0; i < item.linkedClips.length; ++i )
-                    if ( item.linkedClips[i] === uuidA )
-                    {
-                        item.linkedClips.splice( i, 1 );
-                        break;
-                    }
-            }
+            for ( var i = 0; i < linkedClipsDict[uuidA].length; ++i )
+                if ( linkedClipsDict[uuidA][i] === uuidB )
+                {
+                    linkedClipsDict[uuidA].splice( i, 1 );
+                    break;
+                }
+            for ( i = 0; i < linkedClipsDict[uuidB].length; ++i )
+                if ( linkedClipsDict[uuidB][i] === uuidA )
+                {
+                    linkedClipsDict[uuidB].splice( i, 1 );
+                    break;
+                }
+            updateLinkedClips( uuidA );
+            updateLinkedClips( uuidB );
         }
 
         onEffectsUpdated: {
diff --git a/src/Workflow/MainWorkflow.cpp b/src/Workflow/MainWorkflow.cpp
index 8685307e..e9ad6059 100644
--- a/src/Workflow/MainWorkflow.cpp
+++ b/src/Workflow/MainWorkflow.cpp
@@ -51,6 +51,7 @@
 #include "Tools/OutputEventWatcher.h"
 #include "Workflow/Types.h"
 
+#include <QJsonArray>
 #include <QMutex>
 
 MainWorkflow::MainWorkflow( Settings* projectSettings, int trackCount ) :
@@ -213,6 +214,12 @@ MainWorkflow::clipInfo( const QString& uuid )
         h["length"] = (qint64)( clip->input()->length() );
         h["name"] = clip->media()->title();
         h["audio"] = c->isAudio;
+
+        QStringList linkedClipList;
+        for ( const auto& linkedClipUuid : c->linkedClips )
+            linkedClipList << linkedClipUuid.toString();
+        h["linkedClips"] = QJsonArray::fromStringList( linkedClipList );
+
         h["position"] = m_sequenceWorkflow->position( uuid );
         h["trackId"] = m_sequenceWorkflow->trackId( uuid );
         h["filters"] = EffectHelper::toVariant( clip->input() );



More information about the Vlmc-devel mailing list