News:

--

Main Menu

Differentiate cut and delete

Started by eumagga0x2a, September 26, 2016, 02:57:07 PM

Previous topic - Next topic

eumagga0x2a

As of now, Avidemux handles Cut (Ctrl+X) and Delete (DEL) as one and the same delete operation. This may be confusing to a user. The following patch implements Ctrl+X as copy to clipboard && delete (immediately) and tries to keep the current position if practicable (and swaps A_ResetMarkers() and ReSync()/A_Resync() in ACT_ResetSegments to avoid "Marker B is out of bounds" warnings).

diff --git a/avidemux/common/gui_main.cpp b/avidemux/common/gui_main.cpp
index 0828354..65d0cbd 100644
--- a/avidemux/common/gui_main.cpp
+++ b/avidemux/common/gui_main.cpp
@@ -535,31 +535,75 @@ void HandleAction (Action action)
             video_body->resetSeg();
             video_body->getVideoInfo (avifileinfo);

+            A_Resync();
             A_ResetMarkers();
-              ReSync ();

             // forget last project file
             video_body->setProjectName("");
         }
     break;

-    case ACT_Delete:
     case ACT_Cut:
         {
             uint64_t a=video_body->getMarkerAPts();
             uint64_t b=video_body->getMarkerBPts();
+            uint64_t c=video_body->getCurrentFramePts();
+            if(a>b)
+            {
+                uint64_t p=a;
+                a=b;
+                b=p;
+            }
+            video_body->copyToClipBoard(a,b);
             if(false==video_body->remove(a,b))
             {
                 GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cutting"),QT_TRANSLATE_NOOP("adm","Error while cutting out."));
             }
             else
             {
-              A_ResetMarkers();
-              A_Resync(); // total duration & stuff
-              // Rewind to first frame...
-              //A_Rewind();
-              GUI_GoToTime(a);
+                A_Resync(); // total duration & stuff
+                if(a<c && c<b)
+                {
+                    c=a;
+                }
+                if(c>=b)
+                {
+                    c-=b-a;
+                }
+                A_ResetMarkers();
+                GUI_GoToTime(c);
+            }
+        }
+    break;

+    case ACT_Delete:
+        {
+            uint64_t a=video_body->getMarkerAPts();
+            uint64_t b=video_body->getMarkerBPts();
+            uint64_t c=video_body->getCurrentFramePts();
+            if(a>b)
+            {
+                uint64_t p=a;
+                a=b;
+                b=p;
+            }
+            if(false==video_body->remove(a,b))
+            {
+                GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Delete"),QT_TRANSLATE_NOOP("adm","Error while deleting."));
+            }
+            else
+            {
+                A_Resync(); // total duration & stuff
+                if(a<c && c<b)
+                {
+                    c=a;
+                }
+                if(c>=b)
+                {
+                    c-=b-a;
+                }
+                A_ResetMarkers();
+                GUI_GoToTime(c);
             }
         }


mean

I simplified this one a bit, hopefully i did not break it

eumagga0x2a

Confirmed working as intended, thank you very much (and I promise to comment more and better)! My idea to differentiate error messages was completely bogus because in any case they would be related to the deleting part of the task.

The only thing in your version of the patch I failed to understand was the role of

            bool r;

in gui_main.cpp:552. It remains unused later. What am I missing?

Off-topic: GUI_close() at gui_main.cpp:1359 currently doesn't clear clipboard. Pasting from clipboard may not clear its content, but closing the video surely should (don't know ATM how to achieve this).

mean

the bool r is cruft,  i'll remove it

eumagga0x2a


eumagga0x2a

A short follow-up patch, my apologies. To avoid "Marker B is out of bounds" warnings on delete, it is necessary to swap calls to A_ResetMarkers and A_Resync (removing the stray r boolean in the same flush).

diff --git a/avidemux/common/gui_main.cpp b/avidemux/common/gui_main.cpp
index f822de1..ae18773 100644
--- a/avidemux/common/gui_main.cpp
+++ b/avidemux/common/gui_main.cpp
@@ -549,7 +549,6 @@ void HandleAction (Action action)
             uint64_t a=video_body->getMarkerAPts();
             uint64_t b=video_body->getMarkerBPts();
             uint64_t current=video_body->getCurrentFramePts();
-            bool r;
             if(a>b)
             {
                 uint64_t p=a;
@@ -566,6 +565,7 @@ void HandleAction (Action action)
                 GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cutting"),QT_TRANSLATE_NOOP("adm","Error while cutting out."));
                 break;
             }
+            A_ResetMarkers(); // when shortening video, first reset markers then resync
             A_Resync(); // total duration & stuff
         
             if(current>=a) // else current is before A, so nothing to do
@@ -578,7 +578,6 @@ void HandleAction (Action action)
                         current-=(b-a);
                 }
             }
-            A_ResetMarkers();
             GUI_GoToTime(current);
         }
     break;