merged hv7 mod
[goodguy/history.git] / cinelerra-5.1 / cinelerra / edits.C
index a8e668f844c3dedf15322cc0abc320e7600a2525..4f54457bdc6f464db93c2938b36bea968dc12b6c 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
  * CINELERRA
- * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
+ * Copyright (C) 2008-2017 Adam Williams <broadcast at earthling dot net>
  *
  * 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
@@ -768,7 +768,7 @@ int Edits::modify_handles(double oldposition, double newposition, int currentend
                                else
                                {
 // move end of edit out
-//printf("Edits::modify_handle 6\n");
+//printf("Edits::modify_handle %d edit_mode=%d\n", __LINE__, edit_mode);
                                        current_edit->shift_end_out(edit_mode,
                                                track->to_units(newposition, 0),
                                                track->to_units(oldposition, 0),
@@ -843,3 +843,124 @@ void Edits::shift_effects_recursive(int64_t position, int64_t length, int edit_a
        track->shift_effects(position, length, edit_autos);
 }
 
+// only used for audio but also used for plugins which inherit from Edits
+void Edits::deglitch(int64_t position)
+{
+// range from the splice junk appears
+       int64_t threshold = (int64_t)((double)edl->session->sample_rate / 
+               edl->session->frame_rate) / 2;
+       Edit *current = 0;
+
+// the last edit before the splice
+       Edit *edit1 = 0;
+       if(first)
+       {
+               for(current = first; current; current = NEXT)
+               {
+                       if(current->startproject + current->length >= position - threshold)
+                       {
+                               edit1 = current;
+                               break;
+                       }
+               }
+
+// ignore if it ends after the splice
+               if(current && current->startproject + current->length >= position)
+               {
+                       edit1 = 0;
+               }
+       }
+
+// the first edit after the splice
+       Edit *edit2 = 0;
+       if(last)
+       {
+               for(current = last; current; current = PREVIOUS)
+               {
+                       if(current->startproject < position + threshold)
+                       {
+                               edit2 = current;
+                               break;
+                       }
+               }
+
+       // ignore if it starts before the splice
+               if(current && current->startproject < position)
+               {
+                       edit2 = 0;
+               }
+       }
+
+
+
+
+// printf("Edits::deglitch %d position=%ld edit1=%p edit2=%p\n", __LINE__,
+// position, 
+// edit1, 
+// edit2);
+// delete junk between the edits
+       if(edit1 != edit2)
+       {
+               if(edit1 != 0)
+               {
+// end the starting edit later
+                       current = edit1->next;
+                       while(current != 0 &&
+                               current != edit2 &&
+                               current->startproject < position)
+                       {
+                               Edit* next = NEXT;
+
+                               edit1->length += current->length;
+                               remove(current);
+
+                               current = next;
+                       }
+               }
+               
+               if(edit2 != 0)
+               {
+// start the ending edit earlier
+                       current = edit2->previous;
+                       while(current != 0 && 
+                               current != edit1 &&
+                               current->startproject >= position)
+                       {
+                               Edit *previous = PREVIOUS;
+
+                               int64_t length = current->length;
+//printf("Edits::deglitch %d length=%ld\n", __LINE__, length);
+                               if(!edit2->silence() && 
+                                       length > edit2->startsource)
+                               {
+                                       length = edit2->startsource;
+                               }
+
+                               // shift edit2 by using material from its source
+                               edit2->startproject -= length;
+                               edit2->startsource -= length;
+                               // assume enough is at the end
+                               edit2->length += length;
+
+                               // shift edit2 & its source earlier by remainder
+                               if(length < current->length)
+                               {
+                                       int64_t remainder = current->length - length;
+                                       edit2->startproject -= remainder;
+                                       // assume enough is at the end
+                                       edit2->length += remainder;
+                               }
+
+                               remove(current);
+
+
+                               current = previous;
+                       }
+               }
+       }
+       
+}
+
+
+
+