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