fast drag/drop rework, modify labels in mwin->cwin locks, mods to cut/paste, marks...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / edl.C
index 5f23b1b1cd945c4ecc045a627495074b9bc140cf..d033b8d5377c00401f16be10989748eb12494041 100644 (file)
@@ -49,6 +49,7 @@
 #include "playbackconfig.h"
 #include "playabletracks.h"
 #include "plugin.h"
+#include "pluginset.h"
 #include "preferences.h"
 #include "recordconfig.h"
 #include "recordlabel.h"
@@ -794,24 +795,42 @@ int EDL::clear(double start, double end,
        return 0;
 }
 
+static int dead_edit_cmp(Edit**ap, Edit**bp)
+{
+       Edit *a = *ap, *b = *bp;
+       if( a->track != b->track ) return 0;
+       return a->startproject > b->startproject ? -1 : 1;
+}
+
 void EDL::delete_edits(ArrayList<Edit*> *edits, int collapse)
 {
-       if( session->labels_follow_edits )
-               delete_edit_labels(edits, collapse);
+       edits->sort(dead_edit_cmp);
        for( int i=0; i<edits->size(); ++i ) {
                Edit *edit = edits->get(i);
                Track *track = edit->track;
                int64_t start = edit->startproject;
-               int end = start + edit->length;
-               track->clear(start, end, 1, 0,
-                       session->plugins_follow_edits,
-                       session->autos_follow_edits, 0);
-               if( !collapse )
-                       track->paste_silence(start, end,
-                               session->plugins_follow_edits,
-                               session->autos_follow_edits);
+               int64_t length = edit->length;
+               int64_t end = start + length;
+               if( session->autos_follow_edits ) {
+                       track->automation->clear(start, end, 0, collapse);
+               }
+               if( session->plugins_follow_edits ) {
+                       for( int k=0; k<track->plugin_set.size(); ++k ) {
+                               PluginSet *plugin_set = track->plugin_set[k];
+                               plugin_set->clear(start, end, 1);
+                               if( !collapse )
+                                       plugin_set->paste_silence(start, end, 1);
+                               plugin_set->optimize();
+                       }
+               }
+               Edit *dead_edit = edit;
+               if( collapse ) {
+                       while( (edit=edit->next) )
+                               edit->startproject -= length;
+               }
+               delete dead_edit;
+               track->edits->optimize();
        }
-       optimize();
 }
 
 class Range {
@@ -891,58 +910,33 @@ void EDL::move_edit_labels(ArrayList<Edit*> *edits, double dist)
 }
 
 
-void EDL::modify_edithandles(double oldposition,
-       double newposition,
-       int currentend,
-       int handle_mode,
-       int edit_labels,
-       int edit_plugins,
-       int edit_autos)
+void EDL::modify_edithandles(double oldposition, double newposition,
+       int currentend, int handle_mode, int edit_labels,
+       int edit_plugins, int edit_autos, int group_id)
 {
-       tracks->modify_edithandles(oldposition,
-               newposition,
-               currentend,
-               handle_mode,
-               edit_labels,
-               edit_plugins,
-               edit_autos);
-       labels->modify_handles(oldposition,
-               newposition,
-               currentend,
-               handle_mode,
-               edit_labels);
-}
-
-void EDL::modify_pluginhandles(double oldposition,
-       double newposition,
-       int currentend,
-       int handle_mode,
-       int edit_labels,
-       int edit_autos,
-       Edits *trim_edits)
-{
-       tracks->modify_pluginhandles(oldposition,
-               newposition,
-               currentend,
-               handle_mode,
-               edit_labels,
-               edit_autos,
-               trim_edits);
+       tracks->modify_edithandles(oldposition, newposition,
+               currentend, handle_mode, edit_labels,
+               edit_plugins, edit_autos, group_id);
+       labels->modify_handles(oldposition, newposition,
+               currentend, handle_mode, edit_labels);
+}
+
+void EDL::modify_pluginhandles(double oldposition, double newposition,
+       int currentend, int handle_mode, int edit_labels,
+       int edit_autos, Edits *trim_edits)
+{
+       tracks->modify_pluginhandles(oldposition, newposition,
+               currentend, handle_mode, edit_labels,
+               edit_autos, trim_edits);
        optimize();
 }
 
-void EDL::paste_silence(double start,
-       double end,
-       int edit_labels,
-       int edit_plugins,
-       int edit_autos)
+void EDL::paste_silence(double start, double end,
+       int edit_labels, int edit_plugins, int edit_autos)
 {
        if( edit_labels )
                labels->paste_silence(start, end);
-       tracks->paste_silence(start,
-               end,
-               edit_plugins,
-               edit_autos);
+       tracks->paste_silence(start, end, edit_plugins, edit_autos);
 }
 
 
@@ -1276,13 +1270,15 @@ void EDL::get_shared_tracks(Track *track,
        }
 }
 
-// aligned frame time
+// aligned frame time, account for sample truncation
 double EDL::frame_align(double position, int round)
 {
-       double frame_pos = position * session->frame_rate;
-       frame_pos = (int64_t)(frame_pos + (round ? 0.5 : 1e-6));
-       position = frame_pos / session->frame_rate;
-       return position;
+       if( !round && session->sample_rate > 0 ) {
+               int64_t sample_pos = position * session->sample_rate;
+               position = (sample_pos+2.) / session->sample_rate;
+       }
+       int64_t frame_pos = (position * session->frame_rate + (round ? 0.5 : 1e-6));
+       return frame_pos / session->frame_rate;
 }
 
 // Convert position to frames if alignment is enabled.