rework deglitch/optimize/stop_playback, sams ladspa icons, reticle color, tweak frame...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / edits.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2017 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "aedit.h"
23 #include "asset.h"
24 #include "assets.h"
25 #include "automation.h"
26 #include "bcsignals.h"
27 #include "cache.h"
28 #include "clip.h"
29 #include "edit.h"
30 #include "edits.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "file.h"
34 #include "filexml.h"
35 #include "filesystem.h"
36 #include "localsession.h"
37 #include "nestededls.h"
38 #include "plugin.h"
39 #include "strategies.inc"
40 #include "track.h"
41 #include "transition.h"
42 #include "transportque.inc"
43
44 #include <string.h>
45
46 Edits::Edits(EDL *edl, Track *track)
47  : List<Edit>()
48 {
49         this->edl = edl;
50         this->track = track;
51 }
52
53 Edits::~Edits()
54 {
55 }
56
57
58 void Edits::equivalent_output(Edits *edits, int64_t *result)
59 {
60 // For the case of plugin sets, a new plugin set may be created with
61 // plugins only starting after 0.  We only want to restart brender at
62 // the first plugin in this case.
63         for(Edit *current = first, *that_current = edits->first;
64                 current || that_current;
65                 current = NEXT,
66                 that_current = that_current->next)
67         {
68 //printf("Edits::equivalent_output 1 %d\n", *result);
69                 if(!current && that_current)
70                 {
71                         int64_t position1 = length();
72                         int64_t position2 = that_current->startproject;
73                         if(*result < 0 || *result > MIN(position1, position2))
74                                 *result = MIN(position1, position2);
75                         break;
76                 }
77                 else
78                 if(current && !that_current)
79                 {
80                         int64_t position1 = edits->length();
81                         int64_t position2 = current->startproject;
82                         if(*result < 0 || *result > MIN(position1, position2))
83                                 *result = MIN(position1, position2);
84                         break;
85                 }
86                 else
87                 {
88 //printf("Edits::equivalent_output 2 %d\n", *result);
89                         current->equivalent_output(that_current, result);
90 //printf("Edits::equivalent_output 3 %d\n", *result);
91                 }
92         }
93 }
94
95 void Edits::copy_from(Edits *edits)
96 {
97         while(last) delete last;
98         for(Edit *current = edits->first; current; current = NEXT)
99         {
100                 Edit *new_edit = append(create_edit());
101                 new_edit->copy_from(current);
102         }
103 }
104
105
106 Edits& Edits::operator=(Edits& edits)
107 {
108 printf("Edits::operator= 1\n");
109         copy_from(&edits);
110         return *this;
111 }
112
113
114 void Edits::insert_asset(Asset *asset,
115         EDL *nested_edl,
116         int64_t length,
117         int64_t position,
118         int track_number)
119 {
120         Edit *new_edit = insert_new_edit(position);
121
122         new_edit->nested_edl = nested_edl;
123         new_edit->asset = asset;
124         new_edit->startsource = 0;
125         new_edit->startproject = position;
126         new_edit->length = length;
127
128         if(nested_edl)
129         {
130                 if(track->data_type == TRACK_AUDIO)
131                         new_edit->channel = track_number % nested_edl->session->audio_channels;
132                 else
133                         new_edit->channel = 0;
134         }
135
136         if(asset && !nested_edl)
137         {
138                 if(asset->audio_data)
139                         new_edit->channel = track_number % asset->channels;
140                 else
141                 if(asset->video_data)
142                         new_edit->channel = track_number % asset->layers;
143         }
144
145 //printf("Edits::insert_asset %d %d\n", new_edit->channel, new_edit->length);
146         for(Edit *current = new_edit->next; current; current = NEXT)
147         {
148                 current->startproject += length;
149         }
150 }
151
152 void Edits::insert_edits(Edits *source_edits,
153         int64_t position,
154         int64_t min_length,
155         int edit_autos)
156 {
157         //int64_t clipboard_end = position + min_length;
158 // Length pasted so far
159         int64_t source_len = 0;
160
161 // Fill region between end of edit table and beginning of pasted segment
162 // with silence.  Can't call from insert_new_edit because it's recursive.
163         if(position > length())
164         {
165                 paste_silence(length(), position);
166         }
167
168
169         for(Edit *source_edit = source_edits->first;
170                 source_edit;
171                 source_edit = source_edit->next)
172         {
173                 EDL *dest_nested_edl = 0;
174                 if(source_edit->nested_edl)
175                         dest_nested_edl = edl->nested_edls->get_copy(source_edit->nested_edl);
176
177 // Update Assets
178                 Asset *dest_asset = 0;
179                 if(source_edit->asset)
180                         dest_asset = edl->assets->update(source_edit->asset);
181 // Open destination area
182                 Edit *dest_edit = insert_new_edit(position + source_edit->startproject);
183
184                 dest_edit->copy_from(source_edit);
185                 dest_edit->asset = dest_asset;
186                 dest_edit->nested_edl = dest_nested_edl;
187                 dest_edit->startproject = position + source_edit->startproject;
188
189
190
191 // Shift keyframes in source edit to their position in the
192 // destination edit for plugin case
193                 if(edit_autos) dest_edit->shift_keyframes(position);
194
195 // Shift following edits and keyframes in following edits by length
196 // in current source edit.
197                 for(Edit *future_edit = dest_edit->next;
198                         future_edit;
199                         future_edit = future_edit->next)
200                 {
201                         future_edit->startproject += dest_edit->length;
202                         future_edit->shift_keyframes(dest_edit->length);
203                 }
204
205                 source_len += source_edit->length;
206         }
207
208
209
210
211 // Fill remaining clipboard length with silence
212         if(source_len < min_length)
213         {
214 //printf("Edits::insert_edits %d\n", __LINE__);
215                 paste_silence(position + source_len, position + min_length);
216         }
217 }
218
219
220 // Native units
221 // Can't paste silence in here because it's used by paste_silence.
222 Edit* Edits::insert_new_edit(int64_t position)
223 {
224 //printf("Edits::insert_new_edit 1\n");
225         Edit *current = split_edit(position);
226         if(current) current = PREVIOUS;
227
228 //printf("Edits::insert_new_edit 1\n");
229         Edit *new_edit = create_edit();
230 //printf("Edits::insert_new_edit 1\n");
231         insert_after(current, new_edit);
232         new_edit->startproject = position;
233 //printf("Edits::insert_new_edit 2\n");
234         return new_edit;
235 }
236
237 Edit* Edits::split_edit(int64_t position)
238 {
239 // Get edit containing position
240         Edit *edit = editof(position, PLAY_FORWARD, 0);
241         if(!edit) return 0;
242 // Split would have created a 0 length
243 //      if(edit->startproject == position) return edit;
244 // Create anyway so the return value comes before position
245
246         Edit *new_edit = create_edit();
247         insert_after(edit, new_edit);
248         new_edit->copy_from(edit);
249         new_edit->length = new_edit->startproject + new_edit->length - position;
250         edit->length = position - edit->startproject;
251         new_edit->startproject = position;
252         new_edit->startsource += edit->length;
253
254 // Decide what to do with the transition
255         if(edit->length && edit->transition) {
256                 delete new_edit->transition;
257                 new_edit->transition = 0;
258         }
259
260         if(edit->transition && edit->transition->length > edit->length)
261                 edit->transition->length = edit->length;
262         if(new_edit->transition && new_edit->transition->length > new_edit->length)
263                 new_edit->transition->length = new_edit->length;
264         return new_edit;
265 }
266
267 int Edits::save(FileXML *xml, const char *output_path)
268 {
269         copy(0, length(), xml, output_path);
270         return 0;
271 }
272
273 void Edits::resample(double old_rate, double new_rate)
274 {
275         for(Edit *current = first; current; current = NEXT)
276         {
277                 current->startproject = Units::to_int64((double)current->startproject /
278                         old_rate *
279                         new_rate);
280                 if(PREVIOUS) PREVIOUS->length = current->startproject - PREVIOUS->startproject;
281                 current->startsource = Units::to_int64((double)current->startsource /
282                         old_rate *
283                         new_rate);
284                 if(!NEXT) current->length = Units::to_int64((double)current->length /
285                         old_rate *
286                         new_rate);
287                 if(current->transition)
288                 {
289                         current->transition->length = Units::to_int64(
290                                 (double)current->transition->length /
291                                 old_rate *
292                                 new_rate);
293                 }
294                 current->resample(old_rate, new_rate);
295         }
296 }
297
298 int Edits::is_glitch(Edit *edit)
299 {
300         if( track->data_type != TRACK_AUDIO ) return 0;
301         int64_t threshold = edl->session->frame_rate > 0 ?
302                 0.5 * edl->session->sample_rate / edl->session->frame_rate : 0;
303 // audio edit shorter than .5 frames is a glitch
304         return edit->length < threshold ? 1 : 0;
305 }
306
307 int Edits::optimize()
308 {
309         int result = 1;
310         Edit *current;
311
312 //printf("Edits::optimize %d\n", __LINE__);
313 // Sort edits by starting point
314         while(result)
315         {
316                 result = 0;
317
318                 for(current = first; current; current = NEXT)
319                 {
320                         Edit *next_edit = NEXT;
321
322                         if(next_edit && next_edit->startproject < current->startproject)
323                         {
324                                 swap(next_edit, current);
325                                 result = 1;
326                         }
327                 }
328         }
329
330 // Insert silence between edits which aren't consecutive
331         for(current = last; current; current = current->previous)
332         {
333                 if(current->previous)
334                 {
335                         Edit *previous_edit = current->previous;
336                         if(current->startproject -
337                                 previous_edit->startproject -
338                                 previous_edit->length > 0)
339                         {
340                                 Edit *new_edit = create_edit();
341                                 insert_before(current, new_edit);
342                                 new_edit->startproject = previous_edit->startproject + previous_edit->length;
343                                 new_edit->length = current->startproject -
344                                         previous_edit->startproject -
345                                         previous_edit->length;
346                         }
347                 }
348                 else
349                 if(current->startproject > 0)
350                 {
351                         Edit *new_edit = create_edit();
352                         insert_before(current, new_edit);
353                         new_edit->length = current->startproject;
354                 }
355         }
356
357         result = 1;
358         while(result) {
359                 result = 0;
360
361 // delete 0 length edits
362                 for( current = first; !result && current; ) {
363                         Edit* next = current->next;
364                         if( current->length == 0 ) {
365                                 if( next && current->transition && !next->transition) {
366                                         next->transition = current->transition;
367                                         next->transition->edit = next;
368                                         current->transition = 0;
369                                 }
370                                 delete current;
371                                 result = 1;
372                                 break;
373                         }
374                         current = next;
375                 }
376
377 // merge same files or transitions, and deglitch
378                 if( !result && track->data_type != TRACK_SUBTITLE ) {
379                         current = first;
380                         if( current && !current->hard_right &&
381                             current->next && !current->next->hard_left &&
382                             is_glitch(current) ) {
383 // if the first edit is a glitch, change it to silence
384                                 current->asset = 0;
385                                 current->nested_edl = 0;
386                         }
387                         Edit *next_edit = 0;
388                         for( ; current && (next_edit=current->next); current=NEXT ) {
389 // both edges are not hard edges
390                                 if( current->hard_right || next_edit->hard_left ) continue;
391 // next edit is a glitch
392                                 if( is_glitch(next_edit) )
393                                         break;
394 // both edits are silence & not a plugin
395                                 if( !current->is_plugin && current->silence() &&
396                                     !next_edit->is_plugin && next_edit->silence() )
397                                         break;
398 // source channels are identical & assets are identical
399                                 if( !result && current->channel == next_edit->channel &&
400                                     current->asset == next_edit->asset &&
401                                     current->nested_edl == next_edit->nested_edl ) {
402 //  and stop and start in the same frame
403                                         int64_t current_end = current->startsource + current->length;
404                                         int64_t next_start = next_edit->startsource;
405                                         if( current_end == next_start ||
406                                             EQUIV(edl->frame_align(track->from_units(current_end), 1),
407                                                   edl->frame_align(track->from_units(next_start), 1)) )
408                                                 break;
409                                 }
410                         }
411                         if( next_edit ) {
412                                 int64_t current_start = current->startproject;
413                                 int64_t next_end = next_edit->startproject + next_edit->length;
414                                 current->length = next_end - current_start;
415                                 remove(next_edit);
416                                 result = 1;
417                         }
418                 }
419
420                 if( last && last->silence() && !last->transition ) {
421                         delete last;
422                         result = 1;
423                 }
424         }
425
426         return 0;
427 }
428
429
430 // ===================================== file operations
431
432 void Edits::load(FileXML *file, int track_offset)
433 {
434         int64_t startproject = 0;
435
436         while( last ) delete last;
437
438         while( !file->read_tag() ) {
439 //printf("Edits::load 1 %s\n", file->tag.get_title());
440                 if(!strcmp(file->tag.get_title(), "EDIT")) {
441                         load_edit(file, startproject, track_offset);
442                 }
443                 else if(!strcmp(file->tag.get_title(), "/EDITS"))
444                         break;
445         }
446
447 //track->dump();
448         optimize();
449 }
450
451 int Edits::load_edit(FileXML *file, int64_t &startproject, int track_offset)
452 {
453         Edit* current = append_new_edit();
454         current->load_properties(file, startproject);
455
456         startproject += current->length;
457
458         while( !file->read_tag() ) {
459                 if(file->tag.title_is("NESTED_EDL")) {
460                         char path[BCTEXTLEN];
461                         path[0] = 0;
462                         file->tag.get_property("SRC", path);
463 //printf("Edits::load_edit %d path=%s\n", __LINE__, path);
464                         if(path[0] != 0) {
465                                 current->nested_edl = edl->nested_edls->get(path);
466                         }
467 // printf("Edits::load_edit %d nested_edl->path=%s\n",
468 // __LINE__,
469 // current->nested_edl->path);
470                 }
471                 else if(file->tag.title_is("FILE")) {
472                         char filename[BCTEXTLEN];
473                         filename[0] = 0;
474                         file->tag.get_property("SRC", filename);
475 // Extend path
476                         if(filename[0] != 0) {
477                                 char directory[BCTEXTLEN], edl_directory[BCTEXTLEN];
478                                 FileSystem fs;
479                                 fs.set_current_dir("");
480                                 fs.extract_dir(directory, filename);
481                                 if(!strlen(directory)) {
482                                         fs.extract_dir(edl_directory, file->filename);
483                                         fs.join_names(directory, edl_directory, filename);
484                                         strcpy(filename, directory);
485                                 }
486                                 current->asset = edl->assets->get_asset(filename);
487                         }
488                         else {
489                                 current->asset = 0;
490                         }
491 //printf("Edits::load_edit 5\n");
492                 }
493                 else if(file->tag.title_is("TRANSITION")) {
494                         current->transition = new Transition(edl, current, "",
495                                 track->to_units(edl->session->default_transition_length, 1));
496                                 current->transition->load_xml(file);
497                 }
498                 else if(file->tag.title_is("/EDIT"))
499                         break;
500         }
501
502 //printf("Edits::load_edit %d\n", __LINE__);
503 //track->dump();
504 //printf("Edits::load_edit %d\n", __LINE__);
505         return 0;
506 }
507
508 // ============================================= accounting
509
510 int64_t Edits::length()
511 {
512         return last ? last->startproject + last->length : 0;
513 }
514
515
516
517 Edit* Edits::editof(int64_t position, int direction, int use_nudge)
518 {
519         Edit *current = 0;
520         if(use_nudge && track) position += track->nudge;
521
522         if(direction == PLAY_FORWARD) {
523                 for(current = last; current; current = PREVIOUS) {
524                         if(current->startproject <= position && current->startproject + current->length > position)
525                                 return current;
526                 }
527         }
528         else
529         if(direction == PLAY_REVERSE) {
530                 for(current = first; current; current = NEXT) {
531                         if(current->startproject < position && current->startproject + current->length >= position)
532                                 return current;
533                 }
534         }
535
536         return 0;     // return 0 on failure
537 }
538
539 Edit* Edits::get_playable_edit(int64_t position, int use_nudge)
540 {
541         Edit *current;
542         if(track && use_nudge) position += track->nudge;
543
544 // Get the current edit
545         for(current = first; current; current = NEXT) {
546                 if(current->startproject <= position &&
547                         current->startproject + current->length > position)
548                         break;
549         }
550
551 // Get the edit's asset
552 // TODO: descend into nested EDLs
553         if(current) {
554                 if(!current->asset)
555                         current = 0;
556         }
557
558         return current;     // return 0 on failure
559 }
560
561 // ================================================ editing
562
563
564
565 int Edits::copy(int64_t start, int64_t end, FileXML *file, const char *output_path)
566 {
567         Edit *current_edit;
568
569         file->tag.set_title("EDITS");
570         file->append_tag();
571         file->append_newline();
572
573         for(current_edit = first; current_edit; current_edit = current_edit->next)
574         {
575                 current_edit->copy(start, end, file, output_path);
576         }
577
578         file->tag.set_title("/EDITS");
579         file->append_tag();
580         file->append_newline();
581         return 0;
582 }
583
584
585
586 void Edits::clear(int64_t start, int64_t end)
587 {
588         if( start >= end ) return;
589
590         Edit* edit1 = editof(start, PLAY_FORWARD, 0);
591         Edit* edit2 = editof(end, PLAY_FORWARD, 0);
592         Edit* current_edit;
593
594         if(end == start) return;        // nothing selected
595         if(!edit1 && !edit2) return;       // nothing selected
596
597
598         if(!edit2) {                // edit2 beyond end of track
599                 edit2 = last;
600                 end = this->length();
601         }
602
603         if( edit1 && edit2 && edit1 != edit2)
604         {
605 // in different edits
606
607 //printf("Edits::clear 3.5 %d %d %d %d\n", edit1->startproject, edit1->length, edit2->startproject, edit2->length);
608                 edit1->length = start - edit1->startproject;
609                 edit2->length -= end - edit2->startproject;
610                 edit2->startsource += end - edit2->startproject;
611                 edit2->startproject += end - edit2->startproject;
612
613 // delete
614                 for(current_edit = edit1->next; current_edit && current_edit != edit2;) {
615                         Edit* next = current_edit->next;
616                         remove(current_edit);
617                         current_edit = next;
618                 }
619 // shift
620                 for(current_edit = edit2; current_edit; current_edit = current_edit->next) {
621                         current_edit->startproject -= end - start;
622                 }
623         }
624         else {
625 // in same edit. paste_edit depends on this
626 // create a new edit
627                 current_edit = split_edit(start);
628                 if( current_edit ) {
629                         current_edit->length -= end - start;
630                         current_edit->startsource += end - start;
631 // shift
632                         while( (current_edit=current_edit->next) != 0 ) {
633                                 current_edit->startproject -= end - start;
634                         }
635                 }
636         }
637
638         optimize();
639 }
640
641 // Used by edit handle and plugin handle movement but plugin handle movement
642 // can only effect other plugins.
643 void Edits::clear_recursive(int64_t start, int64_t end,
644         int edit_edits, int edit_labels, int edit_plugins, int edit_autos,
645         Edits *trim_edits)
646 {
647 //printf("Edits::clear_recursive 1\n");
648         track->clear(start, end,
649                 edit_edits, edit_labels, edit_plugins, edit_autos, 0,
650                 trim_edits);
651 }
652
653
654 int Edits::clear_handle(double start, double end,
655         int edit_plugins, int edit_autos, double &distance)
656 {
657         Edit *current_edit;
658
659         distance = 0.0; // if nothing is found, distance is 0!
660         for(current_edit = first;
661                 current_edit && current_edit->next;
662                 current_edit = current_edit->next) {
663
664
665
666                 if(current_edit->asset && current_edit->next->asset) {
667
668                         if(current_edit->asset->equivalent(*current_edit->next->asset, 0, 0, edl)) {
669
670 // Got two consecutive edits in same source
671                                 if(edl->equivalent(track->from_units(current_edit->next->startproject),
672                                         start)) {
673 // handle selected
674                                         int length = -current_edit->length;
675                                         current_edit->length = current_edit->next->startsource - current_edit->startsource;
676                                         length += current_edit->length;
677
678 // Lengthen automation
679                                         if(edit_autos)
680                                                 track->automation->paste_silence(current_edit->next->startproject,
681                                                         current_edit->next->startproject + length);
682
683 // Lengthen effects
684                                         if(edit_plugins)
685                                                 track->shift_effects(current_edit->next->startproject,
686                                                         length,
687                                                         edit_autos);
688
689                                         for(current_edit = current_edit->next; current_edit; current_edit = current_edit->next)
690                                         {
691                                                 current_edit->startproject += length;
692                                         }
693
694                                         distance = track->from_units(length);
695                                         optimize();
696                                         break;
697                                 }
698                         }
699                 }
700         }
701
702         return 0;
703 }
704
705 int Edits::modify_handles(double oldposition, double newposition, int currentend,
706         int edit_mode, int edit_edits, int edit_labels, int edit_plugins, int edit_autos,
707         Edits *trim_edits)
708 {
709         int result = 0;
710         Edit *current_edit;
711
712 //printf("Edits::modify_handles 1 %d %f %f\n", currentend, newposition, oldposition);
713         if(currentend == 0) {
714 // left handle
715                 for(current_edit = first; current_edit && !result;) {
716                         if(edl->equivalent(track->from_units(current_edit->startproject),
717                                 oldposition)) {
718 // edit matches selection
719 //printf("Edits::modify_handles 3 %f %f\n", newposition, oldposition);
720                                 oldposition = track->from_units(current_edit->startproject);
721                                 result = 1;
722
723                                 if(newposition >= oldposition) {
724 //printf("Edits::modify_handle 1 %s %f %f\n", track->title, oldposition, newposition);
725 // shift start of edit in
726                                         current_edit->shift_start_in(edit_mode,
727                                                 track->to_units(newposition, 0),
728                                                 track->to_units(oldposition, 0),
729                                                 edit_edits,
730                                                 edit_labels,
731                                                 edit_plugins,
732                                                 edit_autos,
733                                                 trim_edits);
734                                 }
735                                 else
736                                 {
737 //printf("Edits::modify_handle 2 %s\n", track->title);
738 // move start of edit out
739                                         current_edit->shift_start_out(edit_mode,
740                                                 track->to_units(newposition, 0),
741                                                 track->to_units(oldposition, 0),
742                                                 edit_edits,
743                                                 edit_labels,
744                                                 edit_plugins,
745                                                 edit_autos,
746                                                 trim_edits);
747                                 }
748                         }
749
750                         if(!result) current_edit = current_edit->next;
751                 }
752         }
753         else {
754 // right handle selected
755                 for(current_edit = first; current_edit && !result;) {
756                         if(edl->equivalent(track->from_units(current_edit->startproject) +
757                                 track->from_units(current_edit->length), oldposition)) {
758                 oldposition = track->from_units(current_edit->startproject) +
759                                         track->from_units(current_edit->length);
760                                 result = 1;
761
762 //printf("Edits::modify_handle 3\n");
763                                 if(newposition <= oldposition) {
764 // shift end of edit in
765 //printf("Edits::modify_handle 4\n");
766                                         current_edit->shift_end_in(edit_mode,
767                                                 track->to_units(newposition, 0),
768                                                 track->to_units(oldposition, 0),
769                                                 edit_edits,
770                                                 edit_labels,
771                                                 edit_plugins,
772                                                 edit_autos,
773                                                 trim_edits);
774 //printf("Edits::modify_handle 5\n");
775                                 }
776                                 else
777                                 {
778 // move end of edit out
779 //printf("Edits::modify_handle %d edit_mode=%d\n", __LINE__, edit_mode);
780                                         current_edit->shift_end_out(edit_mode,
781                                                 track->to_units(newposition, 0),
782                                                 track->to_units(oldposition, 0),
783                                                 edit_edits,
784                                                 edit_labels,
785                                                 edit_plugins,
786                                                 edit_autos,
787                                                 trim_edits);
788 //printf("Edits::modify_handle 7\n");
789                                 }
790                         }
791
792                         if(!result) current_edit = current_edit->next;
793 //printf("Edits::modify_handle 8\n");
794                 }
795         }
796
797         optimize();
798         return 0;
799 }
800
801
802 void Edits::paste_silence(int64_t start, int64_t end)
803 {
804         Edit *new_edit = editof(start, PLAY_FORWARD, 0);
805         if (!new_edit) return;
806
807         if( !new_edit->silence() ) {
808                 new_edit = insert_new_edit(start);
809                 new_edit->length = end - start;
810         }
811         else
812                 new_edit->length += end - start;
813
814         for(Edit *current = new_edit->next; current; current = NEXT) {
815                 current->startproject += end - start;
816         }
817
818         return;
819 }
820
821 Edit *Edits::create_silence(int64_t start, int64_t end)
822 {
823         Edit *new_edit = insert_new_edit(start);
824         new_edit->length = end - start;
825         for(Edit *current = new_edit->next; current; current = NEXT) {
826                 current->startproject += end - start;
827         }
828         return new_edit;
829 }
830
831 Edit* Edits::shift(int64_t position, int64_t difference)
832 {
833         Edit *new_edit = split_edit(position);
834
835         for(Edit *current = first; current; current = NEXT) {
836                 if(current->startproject >= position) {
837                         current->shift(difference);
838                 }
839         }
840         return new_edit;
841 }
842
843
844 void Edits::shift_keyframes_recursive(int64_t position, int64_t length)
845 {
846         track->shift_keyframes(position, length);
847 }
848
849 void Edits::shift_effects_recursive(int64_t position, int64_t length, int edit_autos)
850 {
851         track->shift_effects(position, length, edit_autos);
852 }
853