-// 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;
- }
- }
- }
-
-}
-
-
-
-