4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
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.
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.
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
26 #include "automation.h"
27 #include "awindowgui.h"
28 #include "bccmodels.h"
30 #include "bcsignals.h"
36 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
43 #include "keyframes.h"
44 #include "indexstate.h"
46 #include "localsession.h"
47 #include "maskautos.h"
51 #include "playbackconfig.h"
52 #include "playabletracks.h"
54 #include "pluginset.h"
55 #include "preferences.h"
56 #include "recordconfig.h"
57 #include "recordlabel.h"
58 #include "sharedlocation.h"
61 #include "transportque.inc"
62 #include "versioninfo.h"
69 EDL::EDL(EDL *parent_edl)
72 this->parent_edl = parent_edl;
87 remove_vwindow_edls();
95 void EDL::create_objects()
97 tracks = new Tracks(this);
98 assets = !parent_edl ? new Assets(this) : parent_edl->assets;
99 session = !parent_edl ? new EDLSession(this) : parent_edl->session;
100 local_session = new LocalSession(this);
101 labels = new Labels(this, "LABELS");
104 EDL& EDL::operator=(EDL &edl)
106 printf("EDL::operator= 1\n");
111 int EDL::load_defaults(BC_Hash *defaults)
114 session->load_defaults(defaults);
116 local_session->load_defaults(defaults);
120 int EDL::save_defaults(BC_Hash *defaults)
123 session->save_defaults(defaults);
125 local_session->save_defaults(defaults);
129 void EDL::boundaries()
131 session->boundaries();
132 local_session->boundaries();
135 int EDL::create_default_tracks()
138 for( int i=0; i<session->video_tracks; ++i ) {
139 tracks->add_video_track(0, 0);
141 for( int i=0; i<session->audio_tracks; ++i ) {
142 tracks->add_audio_track(0, 0);
147 int EDL::load_xml(FileXML *file, uint32_t load_flags)
152 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
153 remove_vwindow_edls();
157 // Search for start of master EDL.
159 // The parent_edl test caused clip creation to fail since those XML files
160 // contained an EDL tag.
162 // The parent_edl test is required to make EDL loading work because
163 // when loading an EDL the EDL tag is already read by the parent.
167 result = file->read_tag();
169 !file->tag.title_is("XML") &&
170 !file->tag.title_is("EDL"));
172 return result ? result : read_xml(file, load_flags);
175 int EDL::read_xml(FileXML *file, uint32_t load_flags)
178 // Track numbering offset for replacing undo data.
179 int track_offset = 0;
181 // Get path for backups
182 file->tag.get_property("path", path);
185 if( (load_flags & LOAD_ALL) == LOAD_ALL ||
186 (load_flags & LOAD_EDITS) == LOAD_EDITS ) {
187 while(tracks->last) delete tracks->last;
190 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
192 mixers.remove_all_objects();
195 if( load_flags & LOAD_TIMEBAR ) {
196 while(labels->last) delete labels->last;
197 local_session->unset_inpoint();
198 local_session->unset_outpoint();
201 // This was originally in LocalSession::load_xml
202 if( load_flags & LOAD_SESSION ) {
203 local_session->clipboard_length = 0;
207 result = file->read_tag();
210 if( file->tag.title_is("/XML") ||
211 file->tag.title_is("/EDL") ||
212 file->tag.title_is("/CLIP_EDL") ||
213 file->tag.title_is("/NESTED_EDL") ||
214 file->tag.title_is("/VWINDOW_EDL") ) {
218 if( file->tag.title_is("CLIPBOARD") ) {
219 local_session->clipboard_length =
220 file->tag.get_property("LENGTH", (double)0);
223 if( file->tag.title_is("VIDEO") ) {
224 if( (load_flags & LOAD_VCONFIG) &&
225 (load_flags & LOAD_SESSION) )
226 session->load_video_config(file, 0, load_flags);
228 result = file->skip_tag();
231 if( file->tag.title_is("AUDIO") ) {
232 if( (load_flags & LOAD_ACONFIG) &&
233 (load_flags & LOAD_SESSION) )
234 session->load_audio_config(file, 0, load_flags);
236 result = file->skip_tag();
239 if( file->tag.title_is("FOLDERS") ) {
240 result = folders.load_xml(file);
243 if( file->tag.title_is("MIXERS") ) {
244 if( (load_flags & LOAD_SESSION) )
247 result = file->skip_tag();
250 if( file->tag.title_is("ASSETS") ) {
251 if( load_flags & LOAD_ASSETS )
252 assets->load(file, load_flags);
254 result = file->skip_tag();
257 if( file->tag.title_is(labels->xml_tag) ) {
258 if( load_flags & LOAD_TIMEBAR )
259 labels->load(file, load_flags);
261 result = file->skip_tag();
264 if( file->tag.title_is("LOCALSESSION") ) {
265 if( (load_flags & LOAD_SESSION) ||
266 (load_flags & LOAD_TIMEBAR) )
267 local_session->load_xml(file, load_flags);
269 result = file->skip_tag();
272 if( file->tag.title_is("SESSION") ) {
273 if( (load_flags & LOAD_SESSION) &&
275 session->load_xml(file, 0, load_flags);
277 result = file->skip_tag();
280 if( file->tag.title_is("TRACK") ) {
281 tracks->load(file, track_offset, load_flags);
285 // Causes clip creation to fail because that involves an opening EDL tag.
286 if( file->tag.title_is("CLIP_EDL") && !parent_edl ) {
287 EDL *new_edl = new EDL(this);
288 new_edl->create_objects();
289 new_edl->read_xml(file, LOAD_ALL);
290 if( (load_flags & LOAD_ALL) == LOAD_ALL )
291 clips.add_clip(new_edl);
292 new_edl->remove_user();
295 if( file->tag.title_is("NESTED_EDL") ) {
296 EDL *nested_edl = new EDL;
297 nested_edl->create_objects();
298 nested_edl->read_xml(file, LOAD_ALL);
299 if( (load_flags & LOAD_ALL) == LOAD_ALL )
300 nested_edls.get_nested(nested_edl);
301 nested_edl->remove_user();
304 if( file->tag.title_is("VWINDOW_EDL") && !parent_edl ) {
305 EDL *new_edl = new EDL(this);
306 new_edl->create_objects();
307 new_edl->read_xml(file, LOAD_ALL);
310 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
311 // if( vwindow_edl && !vwindow_edl_shared )
312 // vwindow_edl->remove_user();
313 // vwindow_edl_shared = 0;
314 // vwindow_edl = new_edl;
316 append_vwindow_edl(new_edl, 0);
320 // Discard if not replacing EDL
322 new_edl->remove_user();
335 // Output path is the path of the output file if name truncation is desired.
336 // It is a "" if complete names should be used.
337 // Called recursively by copy for clips, thus the string can't be terminated.
338 // The string is not terminated in this call.
339 int EDL::save_xml(FileXML *file, const char *output_path)
341 copy(COPY_EDL, file, output_path, 0);
345 int EDL::copy_all(EDL *edl)
347 if( this == edl ) return 0;
348 folder_no = edl->folder_no;
355 tracks->copy_from(edl->tracks);
356 labels->copy_from(edl->labels);
360 void EDL::copy_clips(EDL *edl)
362 if( this == edl ) return;
364 remove_vwindow_edls();
366 // if( vwindow_edl && !vwindow_edl_shared )
367 // vwindow_edl->remove_user();
369 // vwindow_edl_shared = 0;
371 for( int i=0; i<edl->total_vwindow_edls(); ++i ) {
372 EDL *new_edl = new EDL(this);
373 new_edl->create_objects();
374 new_edl->copy_all(edl->get_vwindow_edl(i));
375 append_vwindow_edl(new_edl, 0);
379 for( int i=0; i<edl->clips.size(); ++i ) add_clip(edl->clips[i]);
382 void EDL::copy_nested(EDL *edl)
384 if( this == edl ) return;
385 nested_edls.copy_nested(edl->nested_edls);
388 void EDL::copy_assets(EDL *edl)
390 if( this == edl ) return;
393 assets->copy_from(edl->assets);
397 void EDL::copy_mixers(EDL *edl)
399 if( this == edl ) return;
400 mixers.copy_from(edl->mixers);
403 void EDL::copy_session(EDL *edl, int session_only)
405 if( this == edl ) return;
407 if( !session_only ) {
408 strcpy(this->path, edl->path);
409 folders.copy_from(&edl->folders);
413 session->copy(edl->session);
416 if( session_only <= 0 ) {
417 local_session->copy_from(edl->local_session);
421 int EDL::copy_assets(int copy_flags, double start, double end,
422 FileXML *file, const char *output_path)
424 ArrayList<Asset*> asset_list;
427 file->tag.set_title("ASSETS");
429 file->append_newline();
431 // Copy everything for a save
432 if( (copy_flags & COPY_ALL_ASSETS) ) {
433 for( Asset *asset=assets->first; asset; asset=asset->next ) {
434 asset_list.append(asset);
437 if( (copy_flags & COPY_USED_ASSETS) ) {
438 // Copy just the ones being used.
439 for( current = tracks->first; current; current = NEXT ) {
440 if( !current->is_armed() ) continue;
441 current->copy_assets(start, end, &asset_list);
445 // Paths relativised here
446 for( int i=0; i<asset_list.size(); ++i ) {
447 asset_list[i]->write(file, 0, output_path);
450 file->tag.set_title("/ASSETS");
452 file->append_newline();
453 file->append_newline();
458 int EDL::copy(int copy_flags, double start, double end,
459 FileXML *file, const char *output_path, int rewind_it)
461 file->tag.set_title("EDL");
462 file->tag.set_property("VERSION", CINELERRA_VERSION);
463 // Save path for restoration of the project title from a backup.
464 if( this->path[0] ) file->tag.set_property("PATH", path);
465 return copy_xml(copy_flags, start, end, file, "/EDL", output_path, rewind_it);
467 int EDL::copy(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
469 return copy(copy_flags, 0., tracks->total_length(),
470 file, output_path, rewind_it);
473 int EDL::copy_clip(int copy_flags, double start, double end,
474 FileXML *file, const char *output_path, int rewind_it)
476 file->tag.set_title("CLIP_EDL");
477 return copy_xml(copy_flags, start, end, file, "/CLIP_EDL", output_path, rewind_it);
479 int EDL::copy_clip(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
481 return copy_clip(copy_flags, 0., tracks->total_length(),
482 file, output_path, rewind_it);
485 int EDL::copy_nested(int copy_flags, double start, double end,
486 FileXML *file, const char *output_path, int rewind_it)
488 file->tag.set_title("NESTED_EDL");
489 if( this->path[0] ) file->tag.set_property("PATH", path);
490 return copy_xml(copy_flags, start, end, file, "/NESTED_EDL", output_path, rewind_it);
492 int EDL::copy_nested(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
494 return copy_nested(copy_flags, 0., tracks->total_length(),
495 file, output_path, rewind_it);
498 int EDL::copy_vwindow(int copy_flags, double start, double end,
499 FileXML *file, const char *output_path, int rewind_it)
501 file->tag.set_title("VWINDOW_EDL");
502 return copy_xml(copy_flags, start, end, file, "/VWINDOW_EDL", output_path, rewind_it);
504 int EDL::copy_vwindow(int copy_flags, FileXML *file, const char *output_path, int rewind_it)
506 return copy_vwindow(copy_flags, 0., tracks->total_length(),
507 file, output_path, rewind_it);
510 int EDL::copy_xml(int copy_flags, double start, double end,
511 FileXML *file, const char *closer, const char *output_path,
515 file->append_newline();
516 // Set clipboard samples only if copying to clipboard
517 if( (copy_flags & COPY_LENGTH) ) {
518 file->tag.set_title("CLIPBOARD");
519 file->tag.set_property("LENGTH", end - start);
521 file->tag.set_title("/CLIPBOARD");
523 file->append_newline();
524 file->append_newline();
526 //printf("EDL::copy 1\n");
529 if( (copy_flags & COPY_LOCAL_SESSION) )
530 local_session->save_xml(file, start);
533 // Need to copy all this from child EDL if pasting is desired.
535 if( (copy_flags & COPY_SESSION) )
536 session->save_xml(file);
538 if( (copy_flags & COPY_VIDEO_CONFIG) )
539 session->save_video_config(file);
541 if( (copy_flags & COPY_AUDIO_CONFIG) )
542 session->save_audio_config(file);
544 if( (copy_flags & COPY_FOLDERS) )
545 folders.save_xml(file);
547 if( (copy_flags & (COPY_ALL_ASSETS | COPY_USED_ASSETS)) )
548 copy_assets(copy_flags, start, end, file, output_path);
550 if( (copy_flags & COPY_NESTED_EDL) ) {
551 for( int i=0; i<nested_edls.size(); ++i )
552 nested_edls[i]->copy_nested(copy_flags,
553 file, output_path, 0);
556 if( (copy_flags & COPY_CLIPS) ) {
557 for( int i=0; i<clips.size(); ++i )
558 clips[i]->copy_clip(copy_flags, file, output_path, 0);
561 if( (copy_flags & COPY_VWINDOWS) ) {
562 for( int i=0; i<total_vwindow_edls(); ++i )
563 get_vwindow_edl(i)->copy_vwindow(copy_flags,
564 file, output_path, 0);
567 if( (copy_flags & COPY_MIXERS) )
570 file->append_newline();
571 file->append_newline();
573 if( (copy_flags & COPY_LABELS) )
574 labels->copy(start, end, file);
576 tracks->copy(copy_flags, start, end, file, output_path);
579 file->tag.set_title(closer);
581 file->append_newline();
583 // For editing operations we want to rewind it for immediate pasting.
584 // For clips and saving to disk leave it alone.
586 file->terminate_string();
592 void EDL::copy_indexables(EDL *edl)
594 for( Track *track=edl->tracks->first; track; track=track->next ) {
595 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
597 assets->update(edit->asset);
598 if( edit->nested_edl )
599 nested_edls.get_nested(edit->nested_edl);
604 EDL *EDL::new_nested_edl(EDL *edl, const char *path)
606 EDL *nested = new EDL; // no parent for nested edl
607 nested->create_objects();
608 nested->copy_session(edl);
609 nested->set_path(path);
610 nested->update_index(edl);
611 nested->copy_indexables(edl);
612 nested->tracks->copy_from(edl->tracks);
613 nested_edls.append(nested);
617 EDL *EDL::get_nested_edl()
619 Track *track = tracks->first;
620 Edit *edit = track ? track->edits->first : 0;
621 EDL *nested = edit && !edit->next && !edit->asset ? edit->nested_edl : 0;
622 while( nested && (track=track->next)!=0 ) {
623 Edit *edit = track->edits->first;
624 if( !edit || edit->next ||
625 ( edit->nested_edl != nested &&
626 strcmp(edit->nested_edl->path, nested->path) ) )
633 EDL *EDL::create_nested_clip(EDL *nested)
635 EDL *new_edl = new EDL(this); // parent for clip edl
636 new_edl->create_objects();
637 new_edl->create_nested(nested);
641 void EDL::create_nested(EDL *nested)
643 int video_tracks = 0, audio_tracks = 0;
644 for( Track *track=nested->tracks->first; track!=0; track=track->next ) {
645 if( track->data_type == TRACK_VIDEO && track->is_armed() ) ++video_tracks;
646 if( track->data_type == TRACK_AUDIO && track->is_armed() ) ++audio_tracks;
648 // renderengine properties
649 if( video_tracks > 0 )
651 if( audio_tracks > 0 )
652 audio_tracks = nested->session->audio_channels;
654 // Keep frame rate, sample rate, and output size unchanged.
655 // Nest all video & audio outputs
656 session->video_channels = video_tracks;
657 session->audio_channels = audio_tracks;
658 session->video_tracks = 1;
659 session->audio_tracks = audio_tracks;
660 create_default_tracks();
661 insert_asset(0, nested, 0, 0, 0);
664 void EDL::overwrite_clip(EDL *clip)
666 int folder = folder_no;
667 char clip_title[BCTEXTLEN], clip_notes[BCTEXTLEN], clip_icon[BCSTRLEN];
669 strcpy(clip_title, local_session->clip_title);
670 strcpy(clip_notes, local_session->clip_notes);
671 strcpy(clip_icon, local_session->clip_icon);
676 strcpy(local_session->clip_title, clip_title);
677 strcpy(local_session->clip_notes, clip_notes);
678 strcpy(local_session->clip_icon, clip_icon);
680 if( !clip_icon[0] ) return;
681 // discard old clip icon to reconstruct
682 char clip_icon_path[BCTEXTLEN];
683 snprintf(clip_icon_path, sizeof(clip_icon_path),
684 "%s/%s", File::get_config_path(), clip_icon);
685 remove(clip_icon_path);
690 int min_w = session->output_w, min_h = session->output_h;
691 for( Track *track=tracks->first; track!=0; track=track->next ) {
692 if( track->data_type != TRACK_VIDEO ) continue;
693 int w = min_w, h = min_h;
694 for( Edit *current=track->edits->first; current!=0; current=NEXT ) {
695 Indexable* indexable = current->get_source();
696 if( !indexable ) continue;
697 int edit_w = indexable->get_w(), edit_h = indexable->get_h();
698 if( w < edit_w ) w = edit_w;
699 if( h < edit_h ) h = edit_h;
701 if( track->track_w == w && track->track_h == h ) continue;
702 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
703 translate_masks( (w - track->track_w) / 2, (h - track->track_h) / 2);
704 track->track_w = w; track->track_h = h;
708 void EDL::rechannel()
710 for( Track *current=tracks->first; current; current=NEXT ) {
711 if( current->data_type == TRACK_AUDIO ) {
712 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
713 ((PanAuto*)autos->default_auto)->rechannel();
714 for( PanAuto *keyframe = (PanAuto*)autos->first;
715 keyframe; keyframe = (PanAuto*)keyframe->next ) {
716 keyframe->rechannel();
722 void EDL::resample(double old_rate, double new_rate, int data_type)
724 for( Track *current=tracks->first; current; current=NEXT ) {
725 if( current->data_type == data_type ) {
726 current->resample(old_rate, new_rate);
732 void EDL::synchronize_params(EDL *edl)
734 local_session->synchronize_params(edl->local_session);
735 for( Track *this_track=tracks->first, *that_track=edl->tracks->first;
736 this_track && that_track;
737 this_track=this_track->next, that_track=that_track->next ) {
738 this_track->synchronize_params(that_track);
742 int EDL::trim_selection(double start,
756 tracks->total_length(),
765 int EDL::equivalent(double position1, double position2)
767 double threshold = session->cursor_on_frames ?
768 0.5 / session->frame_rate : 1.0 / session->sample_rate;
769 return fabs(position2 - position1) < threshold ? 1 : 0;
772 double EDL::equivalent_output(EDL *edl)
775 session->equivalent_output(edl->session, &result);
776 tracks->equivalent_output(edl->tracks, &result);
781 void EDL::set_path(const char *path)
783 if( &this->path[0] == path ) return;
784 strcpy(this->path, path);
787 void EDL::set_inpoint(double position)
789 if( equivalent(local_session->get_inpoint(), position) &&
790 local_session->get_inpoint() >= 0 ) {
791 local_session->unset_inpoint();
794 local_session->set_inpoint(align_to_frame(position, 0));
795 if( local_session->get_outpoint() <= local_session->get_inpoint() )
796 local_session->unset_outpoint();
800 void EDL::set_outpoint(double position)
802 if( equivalent(local_session->get_outpoint(), position) &&
803 local_session->get_outpoint() >= 0 ) {
804 local_session->unset_outpoint();
807 local_session->set_outpoint(align_to_frame(position, 0));
808 if( local_session->get_inpoint() >= local_session->get_outpoint() )
809 local_session->unset_inpoint();
813 void EDL::unset_inoutpoint()
815 local_session->unset_inpoint();
816 local_session->unset_outpoint();
819 int EDL::blade(double position)
821 return tracks->blade(position);
824 int EDL::clear(double start, double end,
825 int clear_labels, int clear_plugins, int edit_autos)
829 tracks->clear_handle(start,
835 if( clear_labels && distance > 0 )
836 labels->paste_silence(start,
850 // Need to put at beginning so a subsequent paste operation starts at the
852 double position = local_session->get_selectionstart();
853 local_session->set_selectionend(position);
854 local_session->set_selectionstart(position);
858 int EDL::clear_hard_edges(double start, double end)
860 return tracks->clear_hard_edges(start, end);
863 static int dead_edit_cmp(Edit**ap, Edit**bp)
865 Edit *a = *ap, *b = *bp;
866 if( a->track != b->track ) return 0;
867 return a->startproject > b->startproject ? -1 : 1;
870 void EDL::delete_edits(ArrayList<Edit*> *edits, int collapse)
872 edits->sort(dead_edit_cmp);
873 for( int i=0; i<edits->size(); ++i ) {
874 Edit *edit = edits->get(i);
875 Track *track = edit->track;
876 int64_t start = edit->startproject;
877 int64_t length = edit->length;
878 int64_t end = start + length;
879 if( session->autos_follow_edits ) {
880 track->automation->clear(start, end, 0, collapse);
882 if( session->plugins_follow_edits ) {
883 for( int k=0; k<track->plugin_set.size(); ++k ) {
884 PluginSet *plugin_set = track->plugin_set[k];
885 plugin_set->clear(start, end, 1);
887 plugin_set->paste_silence(start, end, 1);
888 plugin_set->optimize();
891 Edit *dead_edit = edit;
893 while( (edit=edit->next) )
894 edit->startproject -= length;
903 static int cmp(Range *ap, Range *bp);
905 bool operator ==(Range &that) { return this->start == that.start; }
906 bool operator >(Range &that) { return this->start > that.start; }
908 int Range::cmp(Range *ap, Range *bp) {
909 return ap->start < bp->start ? -1 : ap->start == bp->start ? 0 : 1;
912 static void get_edit_regions(ArrayList<Edit*> *edits, ArrayList<Range> ®ions)
914 // move edit inclusive labels by regions
915 for( int i=0; i<edits->size(); ++i ) {
916 Edit *edit = edits->get(i);
917 double pos = edit->track->from_units(edit->startproject);
918 double end = edit->track->from_units(edit->startproject + edit->length);
919 int n = regions.size(), k = n;
921 Range &range = regions[k];
922 if( pos >= range.end ) continue;
923 if( range.start >= end ) continue;
925 if( range.start > pos ) { range.start = pos; expand = 1; }
926 if( range.end < end ) { range.end = end; expand = 1; }
931 Range &range = regions.append();
932 range.start = pos; range.end = end;
935 regions.sort(Range::cmp);
938 void EDL::delete_edit_labels(ArrayList<Edit*> *edits, int collapse)
940 ArrayList<Range> regions;
941 get_edit_regions(edits, regions);
942 int n = regions.size(), k = n;
944 Range &range = regions[k];
945 labels->clear(range.start, range.end, collapse);
949 void EDL::move_edit_labels(ArrayList<Edit*> *edits, double dist)
951 ArrayList<Range> regions;
952 get_edit_regions(edits, regions);
953 int n = regions.size(), k = n;
954 Labels moved(this, 0);
956 Range &range = regions[k];
957 Label *label = labels->label_of(range.start);
958 for( Label *next=0; label && label->position <= range.end; label=next ) {
960 labels->remove_pointer(label);
961 label->position += dist;
964 Label *current = labels->first;
965 while( (label=moved.first) ) {
966 moved.remove_pointer(label);
967 while( current && current->position < label->position )
968 current = current->next;
969 if( current && current->position == label->position ) {
970 delete label; continue;
972 labels->insert_before(current, label);
977 void EDL::modify_edithandles(double oldposition, double newposition,
978 int currentend, int handle_mode, int edit_labels,
979 int edit_plugins, int edit_autos, int group_id)
981 tracks->modify_edithandles(oldposition, newposition,
982 currentend, handle_mode, edit_labels,
983 edit_plugins, edit_autos, group_id);
986 void EDL::modify_pluginhandles(double oldposition, double newposition,
987 int currentend, int handle_mode, int edit_labels,
988 int edit_autos, Edits *trim_edits)
990 tracks->modify_pluginhandles(oldposition, newposition,
991 currentend, handle_mode, edit_labels,
992 edit_autos, trim_edits);
996 void EDL::paste_silence(double start, double end,
997 int edit_labels, int edit_plugins, int edit_autos)
1000 labels->paste_silence(start, end);
1001 tracks->paste_silence(start, end, edit_plugins, edit_autos);
1005 void EDL::remove_from_project(ArrayList<EDL*> *clips)
1007 for( int i=0; i<clips->size(); ++i ) {
1008 this->clips.remove_clip(clips->get(i));
1012 void EDL::remove_from_project(ArrayList<Indexable*> *assets)
1014 // Remove from clips
1016 for( int j=0; j<clips.size(); ++j ) {
1017 clips[j]->remove_from_project(assets);
1020 // Remove from VWindow EDLs
1021 for( int i=0; i<total_vwindow_edls(); ++i )
1022 get_vwindow_edl(i)->remove_from_project(assets);
1024 for( int i=0; i<assets->size(); ++i ) {
1025 // Remove from tracks
1026 for( Track *track=tracks->first; track; track=track->next ) {
1027 track->remove_asset(assets->get(i));
1030 // Remove from assets
1031 if( !parent_edl && assets->get(i)->is_asset ) {
1032 this->assets->remove_asset((Asset*)assets->get(i));
1035 if( !parent_edl && !assets->get(i)->is_asset ) {
1036 this->nested_edls.remove_clip((EDL*)assets->get(i));
1041 void EDL::update_assets(EDL *src)
1043 for( Asset *current=src->assets->first; current; current=NEXT ) {
1044 assets->update(current);
1048 int EDL::get_tracks_height(Theme *theme)
1050 int total_pixels = 0;
1051 for( Track *current=tracks->first; current; current=NEXT ) {
1052 if( current->is_hidden() ) continue;
1053 total_pixels += current->vertical_span(theme);
1055 return total_pixels;
1058 int64_t EDL::get_tracks_width()
1060 int64_t total_pixels = 0;
1061 for( Track *current=tracks->first; current; current=NEXT ) {
1062 if( current->is_hidden() ) continue;
1063 int64_t pixels = current->horizontal_span();
1064 if( pixels > total_pixels ) total_pixels = pixels;
1066 //printf("EDL::get_tracks_width %d\n", total_pixels);
1067 return total_pixels;
1070 // int EDL::calculate_output_w(int single_channel)
1072 // if( single_channel ) return session->output_w;
1075 // for( int i=0; i<session->video_channels; ++i )
1077 // if( session->vchannel_x[i] + session->output_w > widest ) widest = session->vchannel_x[i] + session->output_w;
1082 // int EDL::calculate_output_h(int single_channel)
1084 // if( single_channel ) return session->output_h;
1087 // for( int i=0; i<session->video_channels; ++i )
1089 // if( session->vchannel_y[i] + session->output_h > tallest ) tallest = session->vchannel_y[i] + session->output_h;
1094 // Get the total output size scaled to aspect ratio
1095 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
1097 if( (float)session->output_w / session->output_h > get_aspect_ratio() )
1098 h = (w = session->output_w) / get_aspect_ratio();
1100 w = (h = session->output_h) * get_aspect_ratio();
1103 float EDL::get_aspect_ratio()
1105 return session->aspect_w / session->aspect_h;
1108 int EDL::dump(FILE *fp)
1111 fprintf(fp,"CLIP\n");
1113 fprintf(fp,"EDL\n");
1114 fprintf(fp," clip_title: %s\n"
1115 " parent_edl: %p\n", local_session->clip_title, parent_edl);
1116 fprintf(fp," selectionstart %f\n selectionend %f\n loop_start %f\n loop_end %f\n",
1117 local_session->get_selectionstart(1),
1118 local_session->get_selectionend(1),
1119 local_session->loop_start,
1120 local_session->loop_end);
1121 for( int i=0; i<TOTAL_PANES; ++i ) {
1122 fprintf(fp," pane %d view_start=%jd track_start=%d\n", i,
1123 local_session->view_start[i],
1124 local_session->track_start[i]);
1128 fprintf(fp,"audio_channels: %d audio_tracks: %d sample_rate: %jd\n",
1129 session->audio_channels,
1130 session->audio_tracks,
1131 session->sample_rate);
1132 fprintf(fp," video_channels: %d\n"
1133 " video_tracks: %d\n"
1134 " frame_rate: %.2f\n"
1135 " frames_per_foot: %.2f\n"
1140 " color_model: %d\n",
1141 session->video_channels,
1142 session->video_tracks,
1143 session->frame_rate,
1144 session->frames_per_foot,
1149 session->color_model);
1151 fprintf(fp," CLIPS");
1152 fprintf(fp," total: %d\n", clips.size());
1153 for( int i=0; i<clips.size(); ++i ) {
1158 fprintf(fp," NESTED_EDLS");
1159 fprintf(fp," total: %d\n", nested_edls.size());
1160 for( int i=0; i<nested_edls.size(); ++i )
1161 fprintf(fp," %s\n", nested_edls[i]->path);
1163 fprintf(fp," VWINDOW EDLS");
1164 fprintf(fp," total: %d\n", total_vwindow_edls());
1166 for( int i=0; i<total_vwindow_edls(); ++i ) {
1167 fprintf(fp," %s\n", get_vwindow_edl(i)->local_session->clip_title);
1170 fprintf(fp," ASSETS\n");
1173 fprintf(fp," LABELS\n");
1175 fprintf(fp," TRACKS\n");
1177 //printf("EDL::dump 2\n");
1181 EDL* EDL::add_clip(EDL *edl)
1183 // Copy argument. New edls are deleted from MWindow::load_filenames.
1184 EDL *new_edl = new EDL(this);
1185 new_edl->create_objects();
1186 new_edl->copy_all(edl);
1187 new_edl->folder_no = AW_CLIP_FOLDER;
1188 clips.append(new_edl);
1192 void EDL::insert_asset(Asset *asset,
1196 RecordLabels *labels)
1198 // Insert asset into asset table
1199 Asset *new_asset = 0;
1200 EDL *new_nested_edl = 0;
1202 if( asset ) new_asset = assets->update(asset);
1203 if( nested_edl ) new_nested_edl = nested_edls.get_nested(nested_edl);
1207 Track *current = first_track ? first_track : tracks->first;
1210 // Fix length of single frame
1215 if( new_nested_edl ) {
1216 length = new_nested_edl->tracks->total_length();
1217 layers = new_nested_edl->session->video_channels;
1218 channels = new_nested_edl->session->audio_channels;
1222 // Insert 1 frame for undefined length
1223 if( new_asset->video_length < 0 ) {
1224 length = session->si_useduration ?
1225 session->si_duration :
1226 1.0 / session->frame_rate;
1229 length = new_asset->frame_rate > 0 ?
1230 (double)new_asset->video_length / new_asset->frame_rate :
1231 1.0 / session->frame_rate;
1233 layers = new_asset->layers;
1234 channels = new_asset->channels;
1237 for( ; current && vtrack<layers; current=NEXT ) {
1238 if( !current->is_armed() || current->data_type != TRACK_VIDEO ) continue;
1239 current->insert_asset(new_asset, new_nested_edl,
1240 length, position, vtrack++);
1245 if( new_asset->audio_length < 0 ) {
1246 // Insert 1 frame for undefined length & video
1247 if( new_asset->video_data )
1248 length = (double)1.0 / new_asset->frame_rate;
1250 // Insert 1 second for undefined length & no video
1254 length = (double)new_asset->audio_length /
1255 new_asset->sample_rate;
1258 current = tracks->first;
1259 for( ; current && atrack < channels; current=NEXT ) {
1260 if( !current->is_armed() || current->data_type != TRACK_AUDIO ) continue;
1261 current->insert_asset(new_asset, new_nested_edl,
1262 length, position, atrack++);
1265 // Insert labels from a recording window.
1267 for( RecordLabel *label=labels->first; label; label=label->next ) {
1268 this->labels->toggle_label(label->position, label->position);
1275 void EDL::set_index_file(Indexable *indexable)
1277 if( indexable->is_asset )
1278 assets->update_index((Asset*)indexable);
1280 nested_edls.update_index((EDL*)indexable);
1283 void EDL::optimize()
1285 //printf("EDL::optimize 1\n");
1286 double length = tracks->total_length();
1287 double preview_start = local_session->preview_start;
1288 double preview_end = local_session->preview_end;
1289 if( preview_end < 0 || preview_end > length )
1290 preview_end = length;
1291 if( preview_start == 0 && preview_end >= length )
1292 local_session->preview_end = -1;
1293 if( preview_start > preview_end )
1294 local_session->preview_start = preview_end;
1295 for( Track *current=tracks->first; current; current=NEXT )
1296 current->optimize();
1301 static Mutex id_lock;
1302 id_lock.lock("EDL::next_id");
1303 int result = EDLSession::current_id++;
1308 void EDL::get_shared_plugins(Track *source,
1309 ArrayList<SharedLocation*> *plugin_locations,
1310 int omit_recordable,
1313 for( Track *track=tracks->first; track; track=track->next ) {
1314 if( track->is_armed() && omit_recordable ) continue;
1315 if( track == source || track->data_type != data_type ) continue;
1316 for( int i=0; i<track->plugin_set.size(); ++i ) {
1317 Plugin *plugin = track->get_current_plugin(
1318 local_session->get_selectionstart(1),
1319 i, PLAY_FORWARD, 1, 0);
1320 if( plugin && plugin->plugin_type != PLUGIN_STANDALONE ) continue;
1321 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1326 void EDL::get_shared_tracks(Track *track,
1327 ArrayList<SharedLocation*> *module_locations,
1328 int omit_recordable, int data_type)
1330 for( Track *current=tracks->first; current; current=NEXT ) {
1331 if( omit_recordable && current->is_armed() ) continue;
1332 if( current == track || current->data_type != data_type ) continue;
1333 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1337 // aligned frame time, account for sample truncation
1338 double EDL::frame_align(double position, int round)
1340 if( !round && session->sample_rate > 0 ) {
1341 int64_t sample_pos = position * session->sample_rate;
1342 position = (sample_pos+2.) / session->sample_rate;
1344 int64_t frame_pos = (position * session->frame_rate + (round ? 0.5 : 1e-6));
1345 return frame_pos / session->frame_rate;
1348 // Convert position to frames if alignment is enabled.
1349 double EDL::align_to_frame(double position, int round)
1351 if( session->cursor_on_frames )
1352 position = frame_align(position, round);
1357 BinFolder *EDL::get_folder(int no)
1359 for( int i=0; i<folders.size(); ++i ) {
1360 BinFolder *fp = folders[i];
1361 if( no == fp->awindow_folder ) return fp;
1366 int EDL::get_folder_number(const char *title)
1368 for( int i=0; i<AWINDOW_FOLDERS; ++i ) {
1369 if( !strcmp(title, AWindowGUI::folder_names[i]) )
1372 for( int i=0; i<folders.size(); ++i ) {
1373 if( !strcmp(title, folders[i]->title) )
1374 return folders[i]->awindow_folder;
1376 return AW_NO_FOLDER;
1379 const char *EDL::get_folder_name(int no)
1381 if( no >= 0 && no<AWINDOW_FOLDERS )
1382 return AWindowGUI::folder_names[no];
1383 BinFolder *fp = get_folder(no);
1384 return !fp ? "" : fp->title;
1387 int EDL::new_folder(const char *title, int is_clips)
1389 if( !title[0] ) return 1;
1390 int ret = get_folder_number(title);
1391 if( ret >= 0 ) return 1;
1392 int idx = AWINDOW_FOLDERS;
1393 for( int i=0; i<folders.size(); ++i ) {
1394 BinFolder *fp = folders[i];
1395 int no = fp->awindow_folder;
1396 if( no >= idx ) idx = no+1;
1398 folders.append(new BinFolder(idx, is_clips, title));
1402 int EDL::delete_folder(const char *title)
1404 int k = folders.size();
1405 while( --k >= 0 && strcmp(title, folders[k]->title) );
1407 folders.remove_object_number(k);
1411 int EDL::get_use_vconsole(VEdit* *playable_edit,
1412 int64_t position, int direction, PlayableTracks *playable_tracks)
1414 int share_playable_tracks = 1;
1416 VTrack *playable_track = 0;
1417 const int debug = 0;
1420 // Calculate playable tracks when being called as a nested EDL
1421 if( !playable_tracks ) {
1422 share_playable_tracks = 0;
1423 playable_tracks = new PlayableTracks(this,
1424 position, direction, TRACK_VIDEO, 1);
1428 // Total number of playable tracks is 1
1429 if( playable_tracks->size() != 1 ) {
1433 playable_track = (VTrack*)playable_tracks->get(0);
1436 // Don't need playable tracks anymore
1437 if( !share_playable_tracks ) {
1438 delete playable_tracks;
1441 if( debug ) printf("EDL::get_use_vconsole %d playable_tracks->size()=%d\n",
1442 __LINE__, playable_tracks->size());
1443 if( result ) return 1;
1446 // Test mutual conditions between direct copy rendering and this.
1447 if( !playable_track->direct_copy_possible(position,
1451 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1453 *playable_edit = (VEdit*)playable_track->edits->editof(position,
1455 // No edit at current location
1456 if( !*playable_edit ) return 1;
1457 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1460 // Edit is nested EDL
1461 if( (*playable_edit)->nested_edl ) {
1463 EDL *nested_edl = (*playable_edit)->nested_edl;
1464 int64_t nested_position = (int64_t)((position -
1465 (*playable_edit)->startproject +
1466 (*playable_edit)->startsource) *
1467 nested_edl->session->frame_rate /
1468 session->frame_rate);
1471 VEdit *playable_edit_temp = 0;
1472 if( session->output_w != nested_edl->session->output_w ||
1473 session->output_h != nested_edl->session->output_h ||
1474 nested_edl->get_use_vconsole(&playable_edit_temp,
1483 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1484 // Edit is not a nested EDL
1485 Asset *asset = (*playable_edit)->asset;
1487 if( !asset ) return 1;
1488 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1490 // Asset and output device must have the same dimensions
1491 if( asset->width != session->output_w ||
1492 asset->height != session->output_h )
1495 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1496 // If we get here the frame is going to be directly copied. Whether it is
1497 // decompressed in hardware depends on the colormodel.
1503 int EDL::get_audio_channels()
1505 return session->audio_channels;
1508 int EDL::get_sample_rate()
1510 return session->sample_rate;
1513 int64_t EDL::get_audio_samples()
1515 return (int64_t)(tracks->total_length() *
1516 session->sample_rate);
1519 int EDL::have_audio()
1524 int EDL::have_video()
1532 return session->output_w;
1537 return session->output_h;
1540 double EDL::get_frame_rate()
1542 return session->frame_rate;
1545 int EDL::get_video_layers()
1550 int64_t EDL::get_video_frames()
1552 return (int64_t)(tracks->total_length() *
1553 session->frame_rate);
1556 void EDL::remove_vwindow_edls()
1558 for( int i=0; i<total_vwindow_edls(); ++i ) {
1559 get_vwindow_edl(i)->remove_user();
1561 vwindow_edls.remove_all();
1564 void EDL::remove_vwindow_edl(EDL *edl)
1566 if( vwindow_edls.number_of(edl) >= 0 ) {
1568 vwindow_edls.remove(edl);
1573 EDL* EDL::get_vwindow_edl(int number)
1575 return vwindow_edls.get(number);
1578 int EDL::total_vwindow_edls()
1580 return vwindow_edls.size();
1583 void EDL::append_vwindow_edl(EDL *edl, int increase_counter)
1585 if(vwindow_edls.number_of(edl) >= 0) return;
1587 if(increase_counter) edl->add_user();
1588 vwindow_edls.append(edl);
1592 double EDL::next_edit(double position)
1594 Units::fix_double(&position);
1595 double new_position = tracks->total_length();
1597 double max_rate = get_frame_rate();
1598 int sample_rate = get_sample_rate();
1599 if( sample_rate > max_rate ) max_rate = sample_rate;
1600 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1602 // Test for edit handles after position
1603 for( Track *track=tracks->first; track; track=track->next ) {
1604 if( !track->is_armed() ) continue;
1605 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1606 double edit_end = track->from_units(edit->startproject + edit->length);
1607 Units::fix_double(&edit_end);
1608 if( fabs(edit_end-position) < min_movement ) continue;
1609 if( edit_end > position && edit_end < new_position )
1610 new_position = edit_end;
1613 return new_position;
1616 double EDL::prev_edit(double position)
1618 Units::fix_double(&position);
1619 double new_position = -1;
1621 double max_rate = get_frame_rate();
1622 int sample_rate = get_sample_rate();
1623 if( sample_rate > max_rate ) max_rate = sample_rate;
1624 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1626 // Test for edit handles before cursor position
1627 for( Track *track=tracks->first; track; track=track->next ) {
1628 if( !track->is_armed() ) continue;
1629 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1630 double edit_end = track->from_units(edit->startproject);
1631 Units::fix_double(&edit_end);
1632 if( fabs(edit_end-position) < min_movement ) continue;
1633 if( edit_end < position && edit_end > new_position )
1634 new_position = edit_end;
1637 return new_position;
1640 double EDL::skip_silence(double position)
1642 double result = position, nearest = DBL_MAX;
1643 for( Track *track=tracks->first; track; track=track->next ) {
1644 if( !track->play ) continue;
1645 Edit *edit = track->edits->editof(position, PLAY_FORWARD, 0);
1646 while( edit && edit->silence() ) edit = edit->next;
1647 if( !edit ) continue;
1648 double pos = track->from_units(edit->startproject);
1649 if( pos > position && pos < nearest )
1650 nearest = result = pos;
1655 void EDL::rescale_proxy(int orig_scale, int new_scale)
1657 if( orig_scale == new_scale ) return;
1659 float orig_w = (float)session->output_w * orig_scale;
1660 float orig_h = (float)session->output_h * orig_scale;
1662 session->output_w = Units::round(orig_w / new_scale);
1663 session->output_h = Units::round(orig_h / new_scale);
1667 for( Track *track=tracks->first; track; track=track->next ) {
1668 if( track->data_type != TRACK_VIDEO ) continue;
1669 orig_w = (float)track->track_w * orig_scale;
1670 orig_h = (float)track->track_h * orig_scale;
1671 track->track_w = Units::round(orig_w / new_scale);
1672 track->track_h = Units::round(orig_h / new_scale);
1673 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
1674 set_proxy(orig_scale, new_scale);
1675 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
1676 set_proxy(orig_scale, new_scale);
1677 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
1678 set_proxy(orig_scale, new_scale);
1679 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
1680 set_proxy(orig_scale, new_scale);
1681 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
1682 set_proxy(orig_scale, new_scale);
1686 void EDL::set_proxy(int new_scale, int new_use_scaler,
1687 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1689 int orig_scale = session->proxy_scale;
1690 session->proxy_scale = new_scale;
1691 int orig_use_scaler = session->proxy_use_scaler;
1692 session->proxy_use_scaler = new_use_scaler;
1693 if( orig_use_scaler ) orig_scale = 1;
1694 int scale = new_use_scaler ? new_scale : 1;
1695 int asset_scale = new_scale == 1 && !new_use_scaler ? 0 : scale;
1696 // change original assets to proxy assets
1697 int folder_no = new_use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
1698 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1699 Indexable *proxy_idxbl = proxy_assets->get(i);
1700 proxy_idxbl->folder_no = folder_no;
1701 if( !proxy_idxbl->is_asset ) continue;
1702 Asset *proxy_asset = assets->update((Asset *)proxy_idxbl);
1703 proxy_asset->width = proxy_asset->actual_width * scale;
1704 proxy_asset->height = proxy_asset->actual_height * scale;
1705 proxy_asset->proxy_scale = asset_scale;
1707 // rescale to full size asset in read_frame
1708 if( new_use_scaler ) new_scale = 1;
1709 rescale_proxy(orig_scale, new_scale);
1711 // replace track contents
1712 for( Track *track=tracks->first; track; track=track->next ) {
1713 if( track->data_type != TRACK_VIDEO ) continue;
1714 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1715 Indexable *idxbl = (Indexable *)edit->asset;
1716 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1717 if( !idxbl ) continue;
1718 int i = orig_assets->size();
1719 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1720 if( i < 0 ) continue;
1721 Indexable *proxy_idxbl = proxy_assets->get(i);
1722 Asset *proxy_asset = proxy_idxbl->is_asset ?
1723 assets->update((Asset *)proxy_idxbl) : 0;
1724 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1725 (EDL *)proxy_idxbl : 0;
1726 edit->asset = proxy_asset;
1727 edit->nested_edl = proxy_edl;
1730 for( int j=0,n=clips.size(); j<n; ++j ) {
1731 EDL *clip = clips[j];
1733 for( Track *track=clip->tracks->first; track; track=track->next ) {
1734 if( track->data_type != TRACK_VIDEO ) continue;
1735 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1736 Indexable *idxbl = (Indexable *)edit->asset;
1737 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1738 if( !idxbl ) continue;
1739 int i = orig_assets->size();
1740 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1741 if( i < 0 ) continue;
1742 Indexable *proxy_idxbl = proxy_assets->get(i);
1743 Asset *proxy_asset = proxy_idxbl->is_asset ?
1744 assets->update((Asset *)proxy_idxbl) : 0;
1745 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1746 (EDL *)proxy_idxbl : 0;
1747 edit->asset = proxy_asset;
1748 edit->nested_edl = proxy_edl;
1752 if( has_proxy && !orig_use_scaler )
1753 clip->rescale_proxy(orig_scale, new_scale);
1757 void EDL::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1759 int asset_scale = session->proxy_scale;
1760 if( asset_scale == 1 ) asset_scale = 0;
1761 int scale = !asset_scale ? 1 : asset_scale;
1762 // update proxy geom using scale
1763 for( int i=0; i<proxy_assets->size(); ++i ) {
1764 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
1765 proxy_asset->proxy_scale = asset_scale;
1766 proxy_asset->width = proxy_asset->actual_width * scale;
1767 proxy_asset->height = proxy_asset->actual_height * scale;
1770 // change original assets to proxy assets
1771 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1772 Asset *proxy_asset = assets->update((Asset *)proxy_assets->get(i));
1773 proxy_asset->folder_no = AW_PROXY_FOLDER;
1774 // replace track contents
1775 for( Track *track=tracks->first; track; track=track->next ) {
1776 if( track->data_type != TRACK_VIDEO ) continue;
1777 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1778 if( !edit->asset ) continue;
1779 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
1780 edit->asset = proxy_asset;
1787 Asset *EDL::get_proxy_asset()
1789 return folder_no == AW_PROXY_FOLDER ?
1790 tracks->first->edits->first->asset : 0;
1793 Track *EDL::add_new_track(int data_type)
1795 Track *new_track = 0;
1796 switch( data_type ) {
1798 ++session->video_tracks;
1799 new_track = tracks->add_video_track(0, 0);
1802 ++session->audio_tracks;
1803 new_track = tracks->add_audio_track(0, 0);
1805 case TRACK_SUBTITLE:
1806 new_track = tracks->add_subttl_track(0, 0);
1812 double EDL::get_cursor_position(int cursor_x, int pane_no)
1814 return (double)cursor_x * local_session->zoom_sample / session->sample_rate +
1815 (double)local_session->view_start[pane_no] *
1816 local_session->zoom_sample / session->sample_rate;
1818 int64_t EDL::get_position_cursorx(double position, int pane_no)
1820 return (int64_t)(position * session->sample_rate / local_session->zoom_sample)
1821 - local_session->view_start[pane_no];
1824 int EDL::in_use(Indexable *indexable)
1826 for( Track *track=tracks->first; track; track=track->next ) {
1827 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1828 Indexable *idxbl = (Indexable *)edit->asset;
1829 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1830 if( !idxbl ) continue;
1831 if( idxbl->id == indexable->id ) return 1;
1832 if( !indexable->is_asset != !idxbl->is_asset ) continue;
1833 if( !strcmp(idxbl->path, indexable->path) ) return 1;
1836 for( int i=0; i<clips.size(); ++i )
1837 if( clips[i]->in_use(indexable) ) return 1;
1838 for( int i=0; i<nested_edls.size(); ++i )
1839 if( nested_edls[i]->in_use(indexable) ) return 1;
1843 int EDL::regroup(int next_id)
1845 ArrayList<int> new_groups;
1846 for( Track *track=tracks->first; track; track=track->next ) {
1847 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1848 if( !edit->group_id ) continue;
1849 int k = new_groups.size();
1850 while( --k >= 0 && new_groups[k] != edit->group_id );
1851 if( k >= 0 ) continue;
1852 new_groups.append(edit->group_id);
1855 for( Track *track=tracks->first; track; track=track->next ) {
1856 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1857 if( !edit->group_id ) continue;
1858 int k = new_groups.size();
1859 while( --k >= 0 && new_groups[k] != edit->group_id );
1860 if( k < 0 ) continue;
1861 edit->group_id = k + next_id;
1864 return new_groups.size();
1867 EDL *EDL::selected_edits_to_clip(int packed,
1868 double *start_position, Track **start_track,
1869 int edit_labels, int edit_autos, int edit_plugins)
1871 double start = DBL_MAX, end = DBL_MIN;
1872 Track *first_track=0, *last_track = 0;
1873 for( Track *track=tracks->first; track; track=track->next ) {
1874 if( !track->is_armed() ) continue;
1876 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1877 if( !edit->is_selected || edit->silence() ) continue;
1878 double edit_pos = track->from_units(edit->startproject);
1879 if( start > edit_pos ) start = edit_pos;
1880 if( end < (edit_pos+=edit->length) ) end = edit_pos;
1883 if( empty ) continue;
1884 if( !first_track ) first_track = track;
1887 if( start_position ) *start_position = start;
1888 if( start_track ) *start_track = first_track;
1889 if( !first_track ) return 0;
1890 EDL *new_edl = new EDL();
1891 new_edl->create_objects();
1892 new_edl->copy_session(this);
1893 const char *text = _("new_edl edit");
1894 new_edl->set_path(text);
1895 strcpy(new_edl->local_session->clip_title, text);
1896 strcpy(new_edl->local_session->clip_notes, text);
1897 new_edl->session->video_tracks = 0;
1898 new_edl->session->audio_tracks = 0;
1899 for( Track *track=tracks->first; track; track=track->next ) {
1900 if( !track->is_armed() ) continue;
1902 if( first_track != track ) continue;
1905 Track *new_track = 0;
1907 new_track = new_edl->add_new_track(track->data_type);
1908 int64_t start_pos = track->to_units(start, 0);
1909 int64_t end_pos = track->to_units(end, 0);
1910 int64_t startproject = 0;
1911 Edit *edit = track->edits->first;
1912 for( ; edit; edit=edit->next ) {
1913 if( !edit->is_selected || edit->silence() ) continue;
1914 if( edit->startproject < start_pos ) continue;
1915 if( edit->startproject >= end_pos ) break;
1916 int64_t edit_start_pos = edit->startproject;
1917 int64_t edit_end_pos = edit->startproject + edit->length;
1919 new_track = new_edl->add_new_track(track->data_type);
1920 int64_t edit_pos = edit_start_pos - start_pos;
1921 if( !packed && edit_pos > startproject ) {
1922 Edit *silence = new Edit(new_edl, new_track);
1923 silence->startproject = startproject;
1924 silence->length = edit_pos - startproject;
1925 new_track->edits->append(silence);
1926 startproject = edit_pos;
1928 int64_t clip_start_pos = startproject;
1929 Edit *clip_edit = new Edit(new_edl, new_track);
1930 clip_edit->clone_from(edit);
1931 clip_edit->startproject = startproject;
1932 startproject += clip_edit->length;
1933 new_track->edits->append(clip_edit);
1935 double edit_start = track->from_units(edit_start_pos);
1936 double edit_end = track->from_units(edit_end_pos);
1937 double clip_start = new_track->from_units(clip_start_pos);
1938 Label *label = labels->first;
1939 for( ; label; label=label->next ) {
1940 if( label->position < edit_start ) continue;
1941 if( label->position >= edit_end ) break;
1942 double clip_position = label->position - edit_start + clip_start;
1943 Label *clip_label = new_edl->labels->first;
1944 while( clip_label && clip_label->position<clip_position )
1945 clip_label = clip_label->next;
1946 if( clip_label && clip_label->position == clip_position ) continue;
1947 Label *new_label = new Label(new_edl,
1948 new_edl->labels, clip_position, label->textstr);
1949 new_edl->labels->insert_before(clip_label, new_label);
1953 Automation *automation = track->automation;
1954 Automation *new_automation = new_track->automation;
1955 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
1956 Autos *autos = automation->autos[i];
1957 if( !autos ) continue;
1958 Autos *new_autos = new_automation->autos[i];
1959 new_autos->default_auto->copy_from(autos->default_auto);
1960 Auto *aut0 = autos->first;
1961 for( ; aut0; aut0=aut0->next ) {
1962 if( aut0->position < edit_start_pos ) continue;
1963 if( aut0->position >= edit_end_pos ) break;
1964 Auto *new_auto = new_autos->new_auto();
1965 new_auto->copy_from(aut0);
1966 int64_t clip_position = aut0->position - edit_start_pos + clip_start_pos;
1967 new_auto->position = clip_position;
1968 new_autos->append(new_auto);
1972 if( edit_plugins ) {
1973 while( new_track->plugin_set.size() < track->plugin_set.size() )
1974 new_track->plugin_set.append(0);
1975 for( int i=0; i<track->plugin_set.total; ++i ) {
1976 PluginSet *plugin_set = track->plugin_set[i];
1977 if( !plugin_set ) continue;
1978 PluginSet *new_plugin_set = new_track->plugin_set[i];
1979 if( !new_plugin_set ) {
1980 new_plugin_set = new PluginSet(new_edl, new_track);
1981 new_track->plugin_set[i] = new_plugin_set;
1983 Plugin *plugin = (Plugin*)plugin_set->first;
1984 int64_t startplugin = new_plugin_set->length();
1985 for( ; plugin ; plugin=(Plugin*)plugin->next ) {
1986 if( plugin->silence() ) continue;
1987 int64_t plugin_start_pos = plugin->startproject;
1988 int64_t plugin_end_pos = plugin_start_pos + plugin->length;
1989 if( plugin_end_pos < start_pos ) continue;
1990 if( plugin_start_pos > end_pos ) break;
1991 if( plugin_start_pos < edit_start_pos )
1992 plugin_start_pos = edit_start_pos;
1993 if( plugin_end_pos > edit_end_pos )
1994 plugin_end_pos = edit_end_pos;
1995 if( plugin_start_pos >= plugin_end_pos ) continue;
1996 int64_t plugin_pos = plugin_start_pos - start_pos;
1997 if( !packed && plugin_pos > startplugin ) {
1998 Plugin *silence = new Plugin(new_edl, new_track, "");
1999 silence->startproject = startplugin;
2000 silence->length = plugin_pos - startplugin;
2001 new_plugin_set->append(silence);
2002 startplugin = plugin_pos;
2004 Plugin *new_plugin = new Plugin(new_edl, new_track, plugin->title);
2005 new_plugin->copy_base(plugin);
2006 new_plugin->startproject = startplugin;
2007 new_plugin->length = plugin_end_pos - plugin_start_pos;
2008 startplugin += new_plugin->length;
2009 new_plugin_set->append(new_plugin);
2010 KeyFrames *keyframes = plugin->keyframes;
2011 KeyFrames *new_keyframes = new_plugin->keyframes;
2012 new_keyframes->default_auto->copy_from(keyframes->default_auto);
2013 new_keyframes->default_auto->position = new_plugin->startproject;
2014 KeyFrame *keyframe = (KeyFrame*)keyframes->first;
2015 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
2016 if( keyframe->position < edit_start_pos ) continue;
2017 if( keyframe->position >= edit_end_pos ) break;
2018 KeyFrame *clip_keyframe = new KeyFrame(new_edl, new_keyframes);
2019 clip_keyframe->copy_from(keyframe);
2020 int64_t key_position = keyframe->position - start_pos;
2022 key_position += new_plugin->startproject - plugin_pos;
2023 clip_keyframe->position = key_position;
2024 new_keyframes->append(clip_keyframe);
2030 if( last_track == track ) break;
2035 EDL *EDL::selected_edits_to_clip(int packed, double *start_position, Track **start_track)
2037 return selected_edits_to_clip(packed, start_position, start_track,
2038 session->labels_follow_edits,
2039 session->autos_follow_edits,
2040 session->plugins_follow_edits);
2043 void EDL::paste_edits(EDL *clip, Track *first_track, double position, int overwrite,
2044 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
2047 first_track = tracks->first;
2048 Track *src = clip->tracks->first;
2049 for( Track *track=first_track; track && src; track=track->next ) {
2050 if( !track->is_armed() ) continue;
2051 int64_t pos = track->to_units(position, 0);
2053 for( Edit *edit=src->edits->first; edit; edit=edit->next ) {
2054 if( edit->silence() ) continue;
2055 int64_t start = pos + edit->startproject;
2056 int64_t len = edit->length, end = start + len;
2058 track->edits->clear(start, end);
2059 Edit *dst = track->edits->insert_new_edit(start);
2060 dst->clone_from(edit);
2061 dst->startproject = start;
2062 dst->is_selected = 1;
2063 while( (dst=dst->next) != 0 )
2064 dst->startproject += edit->length;
2065 if( overwrite ) continue;
2066 if( edit_labels && track == first_track ) {
2067 double dst_pos = track->from_units(start);
2068 double dst_len = track->from_units(len);
2069 for( Label *label=labels->first; label; label=label->next ) {
2070 if( label->position >= dst_pos )
2071 label->position += dst_len;
2075 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2076 Autos *autos = track->automation->autos[i];
2077 if( !autos ) continue;
2078 for( Auto *aut0=autos->first; aut0; aut0=aut0->next ) {
2079 if( aut0->position >= start )
2080 aut0->position += edit->length;
2084 if( edit_plugins ) {
2085 for( int i=0; i<track->plugin_set.size(); ++i ) {
2086 PluginSet *plugin_set = track->plugin_set[i];
2087 Plugin *plugin = (Plugin *)plugin_set->first;
2088 for( ; plugin; plugin=(Plugin *)plugin->next ) {
2089 if( plugin->startproject >= start )
2090 plugin->startproject += edit->length;
2091 else if( plugin->startproject+plugin->length > end )
2092 plugin->length += edit->length;
2093 Auto *default_keyframe = plugin->keyframes->default_auto;
2094 if( default_keyframe->position >= start )
2095 default_keyframe->position += edit->length;
2096 KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
2097 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
2098 if( keyframe->position >= start )
2099 keyframe->position += edit->length;
2102 plugin_set->optimize();
2108 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2109 Autos *src_autos = src->automation->autos[i];
2110 if( !src_autos ) continue;
2111 Autos *autos = track->automation->autos[i];
2112 for( Auto *aut0=src_autos->first; aut0; aut0=aut0->next ) {
2113 int64_t auto_pos = pos + aut0->position;
2114 autos->insert_auto(auto_pos, aut0);
2118 if( edit_plugins ) {
2119 for( int i=0; i<src->plugin_set.size(); ++i ) {
2120 PluginSet *plugin_set = src->plugin_set[i];
2121 if( !plugin_set ) continue;
2122 while( i >= track->plugin_set.size() )
2123 track->plugin_set.append(0);
2124 PluginSet *dst_plugin_set = track->plugin_set[i];
2125 if( !dst_plugin_set ) {
2126 dst_plugin_set = new PluginSet(this, track);
2127 track->plugin_set[i] = dst_plugin_set;
2129 Plugin *plugin = (Plugin *)plugin_set->first;
2130 if( plugin ) track->expand_view = 1;
2131 for( ; plugin; plugin=(Plugin *)plugin->next ) {
2132 int64_t start = pos + plugin->startproject;
2133 int64_t end = start + plugin->length;
2134 if( overwrite || edit_edits )
2135 dst_plugin_set->clear(start, end, 1);
2136 Plugin *new_plugin = dst_plugin_set->insert_plugin(plugin->title,
2137 start, end-start, plugin->plugin_type, &plugin->shared_location,
2138 (KeyFrame*)plugin->keyframes->default_auto, 0);
2139 new_plugin->on = plugin->on;
2140 KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
2141 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
2142 int64_t keyframe_pos = pos + keyframe->position;
2143 new_plugin->keyframes->insert_auto(keyframe_pos, keyframe);
2145 while( (new_plugin=(Plugin *)new_plugin->next) ) {
2146 KeyFrame *keyframe = (KeyFrame*)new_plugin->keyframes->first;
2147 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next )
2148 keyframe->position += plugin->length;
2156 Label *edl_label = labels->first;
2157 for( Label *label=clip->labels->first; label; label=label->next ) {
2158 double label_pos = position + label->position;
2161 !(exists=equivalent(edl_label->position, label_pos)) &&
2162 edl_label->position < position ) edl_label = edl_label->next;
2163 if( exists ) continue;
2164 labels->insert_before(edl_label,
2165 new Label(this, labels, label_pos, label->textstr));
2171 void EDL::paste_edits(EDL *clip, Track *first_track, double position, int overwrite)
2173 paste_edits(clip, first_track, position, overwrite, 1,
2174 session->labels_follow_edits,
2175 session->autos_follow_edits,
2176 session->plugins_follow_edits);
2179 void EDL::replace_assets(ArrayList<Indexable*> &orig_idxbls, ArrayList<Asset*> &new_assets)
2181 for( Track *track=tracks->first; track; track=track->next ) {
2182 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2183 Indexable *idxbl = (Indexable *)edit->asset;
2184 if( !idxbl ) continue;
2185 int i = orig_idxbls.size();
2186 while( --i>=0 && strcmp(orig_idxbls[i]->path, idxbl->path) );
2187 if( i < 0 ) continue;
2188 Asset *new_asset = new_assets[i];
2189 if( track->data_type == TRACK_VIDEO && !new_asset->video_data ) continue;
2190 if( track->data_type == TRACK_AUDIO && !new_asset->audio_data ) continue;
2191 edit->asset = assets->update(new_assets[i]);
2195 for( int j=0,n=clips.size(); j<n; ++j )
2196 clips[j]->replace_assets(orig_idxbls, new_assets);
2201 int EDL::collect_effects(EDL *&group)
2203 // to remap shared plugins in copied plugin stack
2204 edl_shared_list shared_map;
2206 EDL *new_edl = new EDL(parent_edl ? parent_edl : this);
2207 new_edl->create_objects();
2208 Tracks *new_tracks = new_edl->tracks;
2209 Track *track = tracks->first;
2210 for( ; !ret && track; track=track->next ) {
2211 if( track->data_type != TRACK_AUDIO &&
2212 track->data_type != TRACK_VIDEO ) continue;
2213 Edit *edit = track->edits->first;
2214 while( edit && !edit->is_selected ) edit = edit->next;
2215 if( !edit ) continue;
2216 if( !track->is_armed() ) { ret = COLLECT_EFFECTS_RECORD; break; }
2217 Track *new_track = 0;
2218 edl_shared *location = 0;
2219 int64_t start_pos = edit->startproject;
2220 int64_t end_pos = start_pos + edit->length;
2221 int pluginsets = track->plugin_set.size();
2222 for( int i=0; i<pluginsets; ++i ) {
2223 PluginSet *plugins = track->plugin_set[i];
2224 Plugin *plugin = (Plugin *)plugins->first;
2225 for( ; plugin; plugin=(Plugin *)plugin->next ) {
2226 if( plugin->silence() ) continue;
2227 if( start_pos < plugin->startproject+plugin->length ) break;
2229 if( !plugin || plugin->startproject >= end_pos ) continue;
2231 location = &shared_map.append();
2232 location->trk = tracks->number_of(track);
2234 location->append(i);
2236 new_track = track->data_type == TRACK_AUDIO ?
2237 new_tracks->add_audio_track(0, 0) :
2238 new_tracks->add_video_track(0, 0) ;
2239 PluginSet *new_plugins = new PluginSet(new_edl, new_track);
2240 new_track->plugin_set.append(new_plugins);
2241 Plugin *new_plugin = (Plugin *)new_plugins->create_edit();
2242 new_plugin->copy_base(plugin);
2243 new_plugins->append(new_plugin);
2244 KeyFrame *keyframe = plugin->keyframes->
2245 get_prev_keyframe(start_pos, PLAY_FORWARD);
2246 KeyFrame *default_auto = (KeyFrame *)
2247 new_plugin->keyframes->default_auto;
2248 default_auto->copy_from(keyframe);
2249 default_auto->position = 0;
2250 default_auto->is_default = 1;
2252 if( !new_track ) { ret = COLLECT_EFFECTS_MISSING; break; }
2253 while( (edit=edit->next) && !edit->is_selected );
2254 if( edit ) ret = COLLECT_EFFECTS_MULTIPLE;
2256 track = new_edl->tracks->first;
2257 if( !ret && !track ) ret = COLLECT_EFFECTS_EMPTY;
2258 // remap shared plugins in copied new_edl
2259 for( ; !ret && track; track=track->next ) {
2260 int pluginsets = track->plugin_set.size();
2261 for( int i=0; i<pluginsets; ++i ) {
2262 PluginSet *plugins = track->plugin_set[i];
2263 Plugin *plugin = (Plugin *)plugins->first;
2264 for( ; plugin; plugin=(Plugin *)plugin->next ) {
2265 if( plugin->plugin_type != PLUGIN_SHAREDPLUGIN ) continue;
2266 int trk = plugin->shared_location.module;
2267 int set = plugin->shared_location.plugin;
2268 int m = shared_map.size(), n = -1;
2269 while( --m>=0 && shared_map[m].trk!=trk );
2271 edl_shared &location = shared_map[m];
2272 n = location.size();
2273 while( --n>=0 && location[n]!=set );
2275 if( n < 0 ) { ret = COLLECT_EFFECTS_MASTER; break; }
2276 plugin->shared_location.module = m;
2277 plugin->shared_location.plugin = n;
2284 new_edl->remove_user();
2288 void edl_SharedLocations::add(int trk, int plg)
2290 SharedLocation &s = append();
2291 s.module = trk; s.plugin = plg;
2294 // inserts pluginsets in group to first selected edit in tracks
2295 int EDL::insert_effects(EDL *group, Track *first_track)
2297 edl_SharedLocations edl_locs, new_locs;
2298 Track *new_track = group->tracks->first;
2299 if( !first_track ) first_track = tracks->first;
2300 Track *track = first_track;
2301 for( ; track && new_track; track=track->next ) {
2302 Edit *edit = track->edits->first;
2303 while( edit && !edit->is_selected ) edit = edit->next;
2304 if( !edit ) continue;
2305 if( !track->is_armed() ) return INSERT_EFFECTS_RECORD;
2306 if( track->data_type != new_track->data_type ) return INSERT_EFFECTS_TYPE;
2307 int gtrk = group->tracks->number_of(new_track);
2308 int trk = tracks->number_of(track);
2309 int psz = track->plugin_set.size();
2310 int new_pluginsets = new_track->plugin_set.size();
2311 for( int i=0; i<new_pluginsets; ++psz, ++i ) {
2312 new_locs.add(gtrk, i);
2313 edl_locs.add(trk, psz);
2315 while( (edit=edit->next) && !edit->is_selected );
2316 if( edit ) return INSERT_EFFECTS_MULTIPLE;
2317 new_track = new_track->next;
2319 if( new_track ) return INSERT_EFFECTS_MISSING;
2320 for( ; track; track=track->next ) {
2321 Edit *edit = track->edits->first;
2322 while( edit && !edit->is_selected ) edit = edit->next;
2323 if( edit ) return INSERT_EFFECTS_EXTRA;
2325 new_track = group->tracks->first;
2326 track = first_track;
2327 for( ; track && new_track; track=track->next ) {
2328 if( !track->is_armed() ) continue;
2329 Edit *edit = track->edits->first;
2330 while( edit && !edit->is_selected ) edit = edit->next;
2331 if( !edit ) continue;
2332 int64_t start_pos = edit->startproject;
2333 int64_t end_pos = start_pos + edit->length;
2334 int new_pluginsets = new_track->plugin_set.size();
2335 for( int i=0; i<new_pluginsets; ++i ) {
2336 Plugin *new_plugin = (Plugin *)new_track->plugin_set[i]->first;
2337 if( !new_plugin ) continue;
2338 PluginSet *plugins = new PluginSet(this, track);
2339 track->plugin_set.append(plugins);
2340 SharedLocation shared_location;
2341 if( new_plugin->plugin_type == PLUGIN_SHAREDPLUGIN ) {
2342 SharedLocation &new_loc = new_plugin->shared_location;
2343 int k = new_locs.size();
2344 while( --k>=0 && !new_loc.equivalent(&new_locs[k]) );
2345 if( k < 0 ) return INSERT_EFFECTS_MASTER;
2346 shared_location.copy_from(&edl_locs[k]);
2348 KeyFrame *default_keyframe = (KeyFrame *)new_plugin->keyframes->default_auto;
2349 plugins->insert_plugin(new_plugin->title,
2350 start_pos, end_pos - start_pos, new_plugin->plugin_type,
2351 &shared_location, default_keyframe, 0);
2352 track->expand_view = 1;
2354 new_track = new_track->next;