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"
38 #include "floatauto.h"
39 #include "floatautos.h"
41 #include "indexstate.h"
42 #include "interlacemodes.h"
44 #include "localsession.h"
45 #include "maskautos.h"
49 #include "playbackconfig.h"
50 #include "playabletracks.h"
52 #include "pluginset.h"
53 #include "preferences.h"
54 #include "recordconfig.h"
55 #include "recordlabel.h"
56 #include "sharedlocation.h"
59 #include "transportque.inc"
60 #include "versioninfo.h"
67 EDL::EDL(EDL *parent_edl)
70 this->parent_edl = parent_edl;
85 remove_vwindow_edls();
93 void EDL::create_objects()
95 tracks = new Tracks(this);
96 assets = !parent_edl ? new Assets(this) : parent_edl->assets;
97 session = !parent_edl ? new EDLSession(this) : parent_edl->session;
98 local_session = new LocalSession(this);
99 labels = new Labels(this, "LABELS");
102 EDL& EDL::operator=(EDL &edl)
104 printf("EDL::operator= 1\n");
109 int EDL::load_defaults(BC_Hash *defaults)
112 session->load_defaults(defaults);
114 local_session->load_defaults(defaults);
118 int EDL::save_defaults(BC_Hash *defaults)
121 session->save_defaults(defaults);
123 local_session->save_defaults(defaults);
127 void EDL::boundaries()
129 session->boundaries();
130 local_session->boundaries();
133 int EDL::create_default_tracks()
136 for( int i=0; i<session->video_tracks; ++i ) {
137 tracks->add_video_track(0, 0);
139 for( int i=0; i<session->audio_tracks; ++i ) {
140 tracks->add_audio_track(0, 0);
145 int EDL::load_xml(FileXML *file, uint32_t load_flags)
150 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
151 remove_vwindow_edls();
155 // Search for start of master EDL.
157 // The parent_edl test caused clip creation to fail since those XML files
158 // contained an EDL tag.
160 // The parent_edl test is required to make EDL loading work because
161 // when loading an EDL the EDL tag is already read by the parent.
165 result = file->read_tag();
167 !file->tag.title_is("XML") &&
168 !file->tag.title_is("EDL"));
170 return result ? result : read_xml(file, load_flags);
173 int EDL::read_xml(FileXML *file, uint32_t load_flags)
176 // Track numbering offset for replacing undo data.
177 int track_offset = 0;
179 // Get path for backups
180 file->tag.get_property("path", path);
183 if( (load_flags & LOAD_ALL) == LOAD_ALL ||
184 (load_flags & LOAD_EDITS) == LOAD_EDITS ) {
185 while(tracks->last) delete tracks->last;
188 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
190 mixers.remove_all_objects();
193 if( load_flags & LOAD_TIMEBAR ) {
194 while(labels->last) delete labels->last;
195 local_session->unset_inpoint();
196 local_session->unset_outpoint();
199 // This was originally in LocalSession::load_xml
200 if( load_flags & LOAD_SESSION ) {
201 local_session->clipboard_length = 0;
205 result = file->read_tag();
208 if( file->tag.title_is("/XML") ||
209 file->tag.title_is("/EDL") ||
210 file->tag.title_is("/CLIP_EDL") ||
211 file->tag.title_is("/NESTED_EDL") ||
212 file->tag.title_is("/VWINDOW_EDL") ) {
216 if( file->tag.title_is("CLIPBOARD") ) {
217 local_session->clipboard_length =
218 file->tag.get_property("LENGTH", (double)0);
221 if( file->tag.title_is("VIDEO") ) {
222 if( (load_flags & LOAD_VCONFIG) &&
223 (load_flags & LOAD_SESSION) )
224 session->load_video_config(file, 0, load_flags);
226 result = file->skip_tag();
229 if( file->tag.title_is("AUDIO") ) {
230 if( (load_flags & LOAD_ACONFIG) &&
231 (load_flags & LOAD_SESSION) )
232 session->load_audio_config(file, 0, load_flags);
234 result = file->skip_tag();
237 if( file->tag.title_is("FOLDERS") ) {
238 result = folders.load_xml(file);
241 if( file->tag.title_is("MIXERS") ) {
242 if( (load_flags & LOAD_SESSION) )
245 result = file->skip_tag();
248 if( file->tag.title_is("ASSETS") ) {
249 if( load_flags & LOAD_ASSETS )
250 assets->load(file, load_flags);
252 result = file->skip_tag();
255 if( file->tag.title_is(labels->xml_tag) ) {
256 if( load_flags & LOAD_TIMEBAR )
257 labels->load(file, load_flags);
259 result = file->skip_tag();
262 if( file->tag.title_is("LOCALSESSION") ) {
263 if( (load_flags & LOAD_SESSION) ||
264 (load_flags & LOAD_TIMEBAR) )
265 local_session->load_xml(file, load_flags);
267 result = file->skip_tag();
270 if( file->tag.title_is("SESSION") ) {
271 if( (load_flags & LOAD_SESSION) &&
273 session->load_xml(file, 0, load_flags);
275 result = file->skip_tag();
278 if( file->tag.title_is("TRACK") ) {
279 tracks->load(file, track_offset, load_flags);
283 // Causes clip creation to fail because that involves an opening EDL tag.
284 if( file->tag.title_is("CLIP_EDL") && !parent_edl ) {
285 EDL *new_edl = new EDL(this);
286 new_edl->create_objects();
287 new_edl->read_xml(file, LOAD_ALL);
288 if( (load_flags & LOAD_ALL) == LOAD_ALL )
289 clips.add_clip(new_edl);
290 new_edl->remove_user();
293 if( file->tag.title_is("NESTED_EDL") ) {
294 EDL *nested_edl = new EDL;
295 nested_edl->create_objects();
296 nested_edl->read_xml(file, LOAD_ALL);
297 if( (load_flags & LOAD_ALL) == LOAD_ALL )
298 nested_edls.get_nested(nested_edl);
299 nested_edl->remove_user();
302 if( file->tag.title_is("VWINDOW_EDL") && !parent_edl ) {
303 EDL *new_edl = new EDL(this);
304 new_edl->create_objects();
305 new_edl->read_xml(file, LOAD_ALL);
308 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
309 // if( vwindow_edl && !vwindow_edl_shared )
310 // vwindow_edl->remove_user();
311 // vwindow_edl_shared = 0;
312 // vwindow_edl = new_edl;
314 append_vwindow_edl(new_edl, 0);
318 // Discard if not replacing EDL
320 new_edl->remove_user();
333 // Output path is the path of the output file if name truncation is desired.
334 // It is a "" if complete names should be used.
335 // Called recursively by copy for clips, thus the string can't be terminated.
336 // The string is not terminated in this call.
337 int EDL::save_xml(FileXML *file, const char *output_path)
339 copy(1, file, output_path, 0);
343 int EDL::copy_all(EDL *edl)
345 if( this == edl ) return 0;
346 folder_no = edl->folder_no;
353 tracks->copy_from(edl->tracks);
354 labels->copy_from(edl->labels);
358 void EDL::copy_clips(EDL *edl)
360 if( this == edl ) return;
362 remove_vwindow_edls();
364 // if( vwindow_edl && !vwindow_edl_shared )
365 // vwindow_edl->remove_user();
367 // vwindow_edl_shared = 0;
369 for( int i=0; i<edl->total_vwindow_edls(); ++i ) {
370 EDL *new_edl = new EDL(this);
371 new_edl->create_objects();
372 new_edl->copy_all(edl->get_vwindow_edl(i));
373 append_vwindow_edl(new_edl, 0);
377 for( int i=0; i<edl->clips.size(); ++i ) add_clip(edl->clips[i]);
380 void EDL::copy_nested(EDL *edl)
382 if( this == edl ) return;
383 nested_edls.copy_nested(edl->nested_edls);
386 void EDL::copy_assets(EDL *edl)
388 if( this == edl ) return;
391 assets->copy_from(edl->assets);
395 void EDL::copy_mixers(EDL *edl)
397 if( this == edl ) return;
398 mixers.copy_from(edl->mixers);
401 void EDL::copy_session(EDL *edl, int session_only)
403 if( this == edl ) return;
405 if( !session_only ) {
406 strcpy(this->path, edl->path);
407 folders.copy_from(&edl->folders);
411 session->copy(edl->session);
414 if( session_only <= 0 ) {
415 local_session->copy_from(edl->local_session);
419 int EDL::copy_assets(double start,
423 const char *output_path)
425 ArrayList<Asset*> asset_list;
428 file->tag.set_title("ASSETS");
430 file->append_newline();
432 // Copy everything for a save
434 for( Asset *asset=assets->first; asset; asset=asset->next ) {
435 asset_list.append(asset);
439 // Copy just the ones being used.
440 for( current = tracks->first; current; current = NEXT ) {
441 if( !current->record ) continue;
442 current->copy_assets(start, end, &asset_list);
446 // Paths relativised here
447 for( int i=0; i<asset_list.size(); ++i ) {
448 asset_list[i]->write(file, 0, output_path);
451 file->tag.set_title("/ASSETS");
453 file->append_newline();
454 file->append_newline();
459 int EDL::copy(double start, double end, int all,
460 FileXML *file, const char *output_path, int rewind_it)
462 file->tag.set_title("EDL");
463 file->tag.set_property("VERSION", CINELERRA_VERSION);
464 // Save path for restoration of the project title from a backup.
465 if( this->path[0] ) file->tag.set_property("PATH", path);
466 return copy(start, end, all,
467 "/EDL", file, output_path, rewind_it);
469 int EDL::copy(int all, FileXML *file, const char *output_path, int rewind_it)
471 return copy(0, tracks->total_length(), all, file, output_path, rewind_it);
474 int EDL::copy_clip(double start, double end, int all,
475 FileXML *file, const char *output_path, int rewind_it)
477 file->tag.set_title("CLIP_EDL");
478 return copy(start, end, all,
479 "/CLIP_EDL", file, output_path, rewind_it);
481 int EDL::copy_clip(int all, FileXML *file, const char *output_path, int rewind_it)
483 return copy_clip(0, tracks->total_length(), all, file, output_path, rewind_it);
486 int EDL::copy_nested_edl(double start, double end, int all,
487 FileXML *file, const char *output_path, int rewind_it)
489 file->tag.set_title("NESTED_EDL");
490 if( this->path[0] ) file->tag.set_property("PATH", path);
491 return copy(start, end, all,
492 "/NESTED_EDL", file, output_path, rewind_it);
494 int EDL::copy_nested_edl(int all, FileXML *file, const char *output_path, int rewind_it)
496 return copy_nested_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
499 int EDL::copy_vwindow_edl(double start, double end, int all,
500 FileXML *file, const char *output_path, int rewind_it)
502 file->tag.set_title("VWINDOW_EDL");
503 return copy(start, end, all,
504 "/VWINDOW_EDL", file, output_path, rewind_it);
506 int EDL::copy_vwindow_edl(int all, FileXML *file, const char *output_path, int rewind_it)
508 return copy_vwindow_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
512 int EDL::copy(double start, double end, int all,
513 const char *closer, FileXML *file,
514 const char *output_path, int rewind_it)
517 file->append_newline();
518 // Set clipboard samples only if copying to clipboard
520 file->tag.set_title("CLIPBOARD");
521 file->tag.set_property("LENGTH", end - start);
523 file->tag.set_title("/CLIPBOARD");
525 file->append_newline();
526 file->append_newline();
528 //printf("EDL::copy 1\n");
531 local_session->save_xml(file, start);
533 //printf("EDL::copy 1\n");
538 // Need to copy all this from child EDL if pasting is desired.
540 session->save_xml(file);
541 session->save_video_config(file);
542 session->save_audio_config(file);
543 folders.save_xml(file);
546 copy_assets(start, end, file, all, output_path);
548 for( int i=0; i<nested_edls.size(); ++i )
549 nested_edls[i]->copy_nested_edl(0, tracks->total_length(), 1,
550 file, output_path, 0);
553 // Don't want this if using clipboard
555 for( int i=0; i<total_vwindow_edls(); ++i )
556 get_vwindow_edl(i)->copy_vwindow_edl(1, file, output_path, 0);
558 for( int i=0; i<clips.size(); ++i )
559 clips[i]->copy_clip(1, file, output_path, 0);
564 file->append_newline();
565 file->append_newline();
568 labels->copy(start, end, file);
569 tracks->copy(start, end, all, file, output_path);
572 file->tag.set_title(closer);
574 file->append_newline();
576 // For editing operations we want to rewind it for immediate pasting.
577 // For clips and saving to disk leave it alone.
579 file->terminate_string();
585 void EDL::copy_indexables(EDL *edl)
587 for( Track *track=edl->tracks->first; track; track=track->next ) {
588 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
590 assets->update(edit->asset);
591 if( edit->nested_edl )
592 nested_edls.get_nested(edit->nested_edl);
597 EDL *EDL::new_nested(EDL *edl, const char *path)
599 EDL *nested = new EDL; // no parent for nested edl
600 nested->create_objects();
601 nested->copy_session(edl);
602 nested->set_path(path);
603 nested->update_index(edl);
604 nested->copy_indexables(edl);
605 nested->tracks->copy_from(edl->tracks);
606 nested_edls.append(nested);
610 EDL *EDL::create_nested_clip(EDL *nested)
612 EDL *new_edl = new EDL(this); // parent for clip edl
613 new_edl->create_objects();
614 new_edl->create_nested(nested);
618 void EDL::create_nested(EDL *nested)
620 // Keep frame rate, sample rate, and output size unchanged.
621 // Nest all video & audio outputs
622 session->video_tracks = 1;
623 session->audio_tracks = nested->session->audio_channels;
624 create_default_tracks();
625 insert_asset(0, nested, 0, 0, 0);
630 int min_w = session->output_w, min_h = session->output_h;
631 for( Track *track=tracks->first; track!=0; track=track->next ) {
632 if( track->data_type != TRACK_VIDEO ) continue;
633 int w = min_w, h = min_h;
634 for( Edit *current=track->edits->first; current!=0; current=NEXT ) {
635 Indexable* indexable = current->get_source();
636 if( !indexable ) continue;
637 int edit_w = indexable->get_w(), edit_h = indexable->get_h();
638 if( w < edit_w ) w = edit_w;
639 if( h < edit_h ) h = edit_h;
641 if( track->track_w == w && track->track_h == h ) continue;
642 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
643 translate_masks( (w - track->track_w) / 2, (h - track->track_h) / 2);
644 track->track_w = w; track->track_h = h;
648 void EDL::rechannel()
650 for( Track *current=tracks->first; current; current=NEXT ) {
651 if( current->data_type == TRACK_AUDIO ) {
652 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
653 ((PanAuto*)autos->default_auto)->rechannel();
654 for( PanAuto *keyframe = (PanAuto*)autos->first;
655 keyframe; keyframe = (PanAuto*)keyframe->next ) {
656 keyframe->rechannel();
662 void EDL::resample(double old_rate, double new_rate, int data_type)
664 for( Track *current=tracks->first; current; current=NEXT ) {
665 if( current->data_type == data_type ) {
666 current->resample(old_rate, new_rate);
672 void EDL::synchronize_params(EDL *edl)
674 local_session->synchronize_params(edl->local_session);
675 for( Track *this_track=tracks->first, *that_track=edl->tracks->first;
676 this_track && that_track;
677 this_track=this_track->next, that_track=that_track->next ) {
678 this_track->synchronize_params(that_track);
682 int EDL::trim_selection(double start,
696 tracks->total_length(),
705 int EDL::equivalent(double position1, double position2)
707 double threshold = session->cursor_on_frames ?
708 0.5 / session->frame_rate : 1.0 / session->sample_rate;
709 return fabs(position2 - position1) < threshold ? 1 : 0;
712 double EDL::equivalent_output(EDL *edl)
715 session->equivalent_output(edl->session, &result);
716 tracks->equivalent_output(edl->tracks, &result);
721 void EDL::set_path(const char *path)
723 if( &this->path[0] == path ) return;
724 strcpy(this->path, path);
727 void EDL::set_inpoint(double position)
729 if( equivalent(local_session->get_inpoint(), position) &&
730 local_session->get_inpoint() >= 0 ) {
731 local_session->unset_inpoint();
734 local_session->set_inpoint(align_to_frame(position, 0));
735 if( local_session->get_outpoint() <= local_session->get_inpoint() )
736 local_session->unset_outpoint();
740 void EDL::set_outpoint(double position)
742 if( equivalent(local_session->get_outpoint(), position) &&
743 local_session->get_outpoint() >= 0 ) {
744 local_session->unset_outpoint();
747 local_session->set_outpoint(align_to_frame(position, 0));
748 if( local_session->get_inpoint() >= local_session->get_outpoint() )
749 local_session->unset_inpoint();
753 void EDL::unset_inoutpoint()
755 local_session->unset_inpoint();
756 local_session->unset_outpoint();
759 int EDL::blade(double position)
761 return tracks->blade(position);
764 int EDL::clear(double start, double end,
765 int clear_labels, int clear_plugins, int edit_autos)
769 tracks->clear_handle(start,
775 if( clear_labels && distance > 0 )
776 labels->paste_silence(start,
790 // Need to put at beginning so a subsequent paste operation starts at the
792 double position = local_session->get_selectionstart();
793 local_session->set_selectionend(position);
794 local_session->set_selectionstart(position);
798 static int dead_edit_cmp(Edit**ap, Edit**bp)
800 Edit *a = *ap, *b = *bp;
801 if( a->track != b->track ) return 0;
802 return a->startproject > b->startproject ? -1 : 1;
805 void EDL::delete_edits(ArrayList<Edit*> *edits, int collapse)
807 edits->sort(dead_edit_cmp);
808 for( int i=0; i<edits->size(); ++i ) {
809 Edit *edit = edits->get(i);
810 Track *track = edit->track;
811 int64_t start = edit->startproject;
812 int64_t length = edit->length;
813 int64_t end = start + length;
814 if( session->autos_follow_edits ) {
815 track->automation->clear(start, end, 0, collapse);
817 if( session->plugins_follow_edits ) {
818 for( int k=0; k<track->plugin_set.size(); ++k ) {
819 PluginSet *plugin_set = track->plugin_set[k];
820 plugin_set->clear(start, end, 1);
822 plugin_set->paste_silence(start, end, 1);
823 plugin_set->optimize();
826 Edit *dead_edit = edit;
828 while( (edit=edit->next) )
829 edit->startproject -= length;
832 track->edits->optimize();
838 static int cmp(Range *ap, Range *bp);
840 bool operator ==(Range &that) { return this->start == that.start; }
841 bool operator >(Range &that) { return this->start > that.start; }
843 int Range::cmp(Range *ap, Range *bp) {
844 return ap->start < bp->start ? -1 : ap->start == bp->start ? 0 : 1;
847 static void get_edit_regions(ArrayList<Edit*> *edits, ArrayList<Range> ®ions)
849 // move edit inclusive labels by regions
850 for( int i=0; i<edits->size(); ++i ) {
851 Edit *edit = edits->get(i);
852 double pos = edit->track->from_units(edit->startproject);
853 double end = edit->track->from_units(edit->startproject + edit->length);
854 int n = regions.size(), k = n;
856 Range &range = regions[k];
857 if( pos >= range.end ) continue;
858 if( range.start >= end ) continue;
860 if( range.start > pos ) { range.start = pos; expand = 1; }
861 if( range.end < end ) { range.end = end; expand = 1; }
866 Range &range = regions.append();
867 range.start = pos; range.end = end;
870 regions.sort(Range::cmp);
873 void EDL::delete_edit_labels(ArrayList<Edit*> *edits, int collapse)
875 ArrayList<Range> regions;
876 get_edit_regions(edits, regions);
877 int n = regions.size(), k = n;
879 Range &range = regions[k];
880 labels->clear(range.start, range.end, collapse);
884 void EDL::move_edit_labels(ArrayList<Edit*> *edits, double dist)
886 ArrayList<Range> regions;
887 get_edit_regions(edits, regions);
888 int n = regions.size(), k = n;
889 Labels moved(this, 0);
891 Range &range = regions[k];
892 Label *label = labels->label_of(range.start);
893 for( Label *next=0; label && label->position <= range.end; label=next ) {
895 labels->remove_pointer(label);
896 label->position += dist;
899 Label *current = labels->first;
900 while( (label=moved.first) ) {
901 moved.remove_pointer(label);
902 while( current && current->position < label->position )
903 current = current->next;
904 if( current && current->position == label->position ) {
905 delete label; continue;
907 labels->insert_before(current, label);
912 void EDL::modify_edithandles(double oldposition, double newposition,
913 int currentend, int handle_mode, int edit_labels,
914 int edit_plugins, int edit_autos, int group_id)
916 tracks->modify_edithandles(oldposition, newposition,
917 currentend, handle_mode, edit_labels,
918 edit_plugins, edit_autos, group_id);
921 void EDL::modify_pluginhandles(double oldposition, double newposition,
922 int currentend, int handle_mode, int edit_labels,
923 int edit_autos, Edits *trim_edits)
925 tracks->modify_pluginhandles(oldposition, newposition,
926 currentend, handle_mode, edit_labels,
927 edit_autos, trim_edits);
931 void EDL::paste_silence(double start, double end,
932 int edit_labels, int edit_plugins, int edit_autos)
935 labels->paste_silence(start, end);
936 tracks->paste_silence(start, end, edit_plugins, edit_autos);
940 void EDL::remove_from_project(ArrayList<EDL*> *clips)
942 for( int i=0; i<clips->size(); ++i ) {
943 this->clips.remove_clip(clips->get(i));
947 void EDL::remove_from_project(ArrayList<Indexable*> *assets)
951 for( int j=0; j<clips.size(); ++j ) {
952 clips[j]->remove_from_project(assets);
955 // Remove from VWindow EDLs
956 for( int i=0; i<total_vwindow_edls(); ++i )
957 get_vwindow_edl(i)->remove_from_project(assets);
959 for( int i=0; i<assets->size(); ++i ) {
960 // Remove from tracks
961 for( Track *track=tracks->first; track; track=track->next ) {
962 track->remove_asset(assets->get(i));
965 // Remove from assets
966 if( !parent_edl && assets->get(i)->is_asset ) {
967 this->assets->remove_asset((Asset*)assets->get(i));
970 if( !parent_edl && !assets->get(i)->is_asset ) {
971 this->nested_edls.remove_clip((EDL*)assets->get(i));
976 void EDL::update_assets(EDL *src)
978 for( Asset *current=src->assets->first; current; current=NEXT ) {
979 assets->update(current);
983 int EDL::get_tracks_height(Theme *theme)
985 int total_pixels = 0;
986 for( Track *current=tracks->first; current; current=NEXT ) {
987 total_pixels += current->vertical_span(theme);
992 int64_t EDL::get_tracks_width()
994 int64_t total_pixels = 0;
995 for( Track *current=tracks->first; current; current=NEXT ) {
996 int64_t pixels = current->horizontal_span();
997 if( pixels > total_pixels ) total_pixels = pixels;
999 //printf("EDL::get_tracks_width %d\n", total_pixels);
1000 return total_pixels;
1003 // int EDL::calculate_output_w(int single_channel)
1005 // if( single_channel ) return session->output_w;
1008 // for( int i=0; i<session->video_channels; ++i )
1010 // if( session->vchannel_x[i] + session->output_w > widest ) widest = session->vchannel_x[i] + session->output_w;
1015 // int EDL::calculate_output_h(int single_channel)
1017 // if( single_channel ) return session->output_h;
1020 // for( int i=0; i<session->video_channels; ++i )
1022 // if( session->vchannel_y[i] + session->output_h > tallest ) tallest = session->vchannel_y[i] + session->output_h;
1027 // Get the total output size scaled to aspect ratio
1028 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
1030 if( (float)session->output_w / session->output_h > get_aspect_ratio() )
1031 h = (w = session->output_w) / get_aspect_ratio();
1033 w = (h = session->output_h) * get_aspect_ratio();
1036 float EDL::get_aspect_ratio()
1038 return session->aspect_w / session->aspect_h;
1041 int EDL::dump(FILE *fp)
1044 fprintf(fp,"CLIP\n");
1046 fprintf(fp,"EDL\n");
1047 fprintf(fp," clip_title: %s\n"
1048 " parent_edl: %p\n", local_session->clip_title, parent_edl);
1049 fprintf(fp," selectionstart %f\n selectionend %f\n loop_start %f\n loop_end %f\n",
1050 local_session->get_selectionstart(1),
1051 local_session->get_selectionend(1),
1052 local_session->loop_start,
1053 local_session->loop_end);
1054 for( int i=0; i<TOTAL_PANES; ++i ) {
1055 fprintf(fp," pane %d view_start=%jd track_start=%d\n", i,
1056 local_session->view_start[i],
1057 local_session->track_start[i]);
1061 fprintf(fp,"audio_channels: %d audio_tracks: %d sample_rate: %jd\n",
1062 session->audio_channels,
1063 session->audio_tracks,
1064 session->sample_rate);
1065 fprintf(fp," video_channels: %d\n"
1066 " video_tracks: %d\n"
1067 " frame_rate: %.2f\n"
1068 " frames_per_foot: %.2f\n"
1073 " color_model: %d\n",
1074 session->video_channels,
1075 session->video_tracks,
1076 session->frame_rate,
1077 session->frames_per_foot,
1082 session->color_model);
1084 fprintf(fp," CLIPS");
1085 fprintf(fp," total: %d\n", clips.size());
1086 for( int i=0; i<clips.size(); ++i ) {
1091 fprintf(fp," NESTED_EDLS");
1092 fprintf(fp," total: %d\n", nested_edls.size());
1093 for( int i=0; i<nested_edls.size(); ++i )
1094 fprintf(fp," %s\n", nested_edls[i]->path);
1096 fprintf(fp," VWINDOW EDLS");
1097 fprintf(fp," total: %d\n", total_vwindow_edls());
1099 for( int i=0; i<total_vwindow_edls(); ++i ) {
1100 fprintf(fp," %s\n", get_vwindow_edl(i)->local_session->clip_title);
1103 fprintf(fp," ASSETS\n");
1106 fprintf(fp," LABELS\n");
1108 fprintf(fp," TRACKS\n");
1110 //printf("EDL::dump 2\n");
1114 EDL* EDL::add_clip(EDL *edl)
1116 // Copy argument. New edls are deleted from MWindow::load_filenames.
1117 EDL *new_edl = new EDL(this);
1118 new_edl->create_objects();
1119 new_edl->copy_all(edl);
1120 new_edl->folder_no = AW_CLIP_FOLDER;
1121 clips.append(new_edl);
1125 void EDL::insert_asset(Asset *asset,
1129 RecordLabels *labels)
1131 // Insert asset into asset table
1132 Asset *new_asset = 0;
1133 EDL *new_nested_edl = 0;
1135 if( asset ) new_asset = assets->update(asset);
1136 if( nested_edl ) new_nested_edl = nested_edls.get_nested(nested_edl);
1140 Track *current = first_track ? first_track : tracks->first;
1143 // Fix length of single frame
1148 if( new_nested_edl ) {
1149 length = new_nested_edl->tracks->total_length();
1151 channels = new_nested_edl->session->audio_channels;
1155 // Insert 1 frame for undefined length
1156 if( new_asset->video_length < 0 ) {
1157 length = session->si_useduration ?
1158 session->si_duration :
1159 1.0 / session->frame_rate;
1162 length = new_asset->frame_rate > 0 ?
1163 (double)new_asset->video_length / new_asset->frame_rate :
1164 1.0 / session->frame_rate;
1166 layers = new_asset->layers;
1167 channels = new_asset->channels;
1170 for( ; current && vtrack<layers; current=NEXT ) {
1171 if( !current->record || current->data_type != TRACK_VIDEO ) continue;
1172 current->insert_asset(new_asset, new_nested_edl,
1173 length, position, vtrack++);
1178 if( new_asset->audio_length < 0 ) {
1179 // Insert 1 frame for undefined length & video
1180 if( new_asset->video_data )
1181 length = (double)1.0 / new_asset->frame_rate;
1183 // Insert 1 second for undefined length & no video
1187 length = (double)new_asset->audio_length /
1188 new_asset->sample_rate;
1191 current = tracks->first;
1192 for( ; current && atrack < channels; current=NEXT ) {
1193 if( !current->record || current->data_type != TRACK_AUDIO ) continue;
1194 current->insert_asset(new_asset, new_nested_edl,
1195 length, position, atrack++);
1198 // Insert labels from a recording window.
1200 for( RecordLabel *label=labels->first; label; label=label->next ) {
1201 this->labels->toggle_label(label->position, label->position);
1208 void EDL::set_index_file(Indexable *indexable)
1210 if( indexable->is_asset )
1211 assets->update_index((Asset*)indexable);
1213 nested_edls.update_index((EDL*)indexable);
1216 void EDL::optimize()
1218 //printf("EDL::optimize 1\n");
1219 double length = tracks->total_length();
1220 double preview_start = local_session->preview_start;
1221 double preview_end = local_session->preview_end;
1222 if( preview_end < 0 || preview_end > length )
1223 preview_end = length;
1224 if( preview_start == 0 && preview_end >= length )
1225 local_session->preview_end = -1;
1226 if( preview_start > preview_end )
1227 local_session->preview_start = preview_end;
1228 for( Track *current=tracks->first; current; current=NEXT )
1229 current->optimize();
1234 static Mutex id_lock;
1235 id_lock.lock("EDL::next_id");
1236 int result = EDLSession::current_id++;
1241 void EDL::get_shared_plugins(Track *source,
1242 ArrayList<SharedLocation*> *plugin_locations,
1243 int omit_recordable,
1246 for( Track *track=tracks->first; track; track=track->next ) {
1247 if( track->record && omit_recordable ) continue;
1248 if( track == source || track->data_type != data_type ) continue;
1249 for( int i=0; i<track->plugin_set.size(); ++i ) {
1250 Plugin *plugin = track->get_current_plugin(
1251 local_session->get_selectionstart(1),
1252 i, PLAY_FORWARD, 1, 0);
1253 if( plugin && plugin->plugin_type != PLUGIN_STANDALONE ) continue;
1254 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1259 void EDL::get_shared_tracks(Track *track,
1260 ArrayList<SharedLocation*> *module_locations,
1261 int omit_recordable, int data_type)
1263 for( Track *current=tracks->first; current; current=NEXT ) {
1264 if( omit_recordable && current->record ) continue;
1265 if( current == track || current->data_type != data_type ) continue;
1266 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1270 // aligned frame time, account for sample truncation
1271 double EDL::frame_align(double position, int round)
1273 if( !round && session->sample_rate > 0 ) {
1274 int64_t sample_pos = position * session->sample_rate;
1275 position = (sample_pos+2.) / session->sample_rate;
1277 int64_t frame_pos = (position * session->frame_rate + (round ? 0.5 : 1e-6));
1278 return frame_pos / session->frame_rate;
1281 // Convert position to frames if alignment is enabled.
1282 double EDL::align_to_frame(double position, int round)
1284 if( session->cursor_on_frames )
1285 position = frame_align(position, round);
1290 BinFolder *EDL::get_folder(int no)
1292 for( int i=0; i<folders.size(); ++i ) {
1293 BinFolder *fp = folders[i];
1294 if( no == fp->awindow_folder ) return fp;
1299 int EDL::get_folder_number(const char *title)
1301 for( int i=0; i<AWINDOW_FOLDERS; ++i ) {
1302 if( !strcmp(title, AWindowGUI::folder_names[i]) )
1305 for( int i=0; i<folders.size(); ++i ) {
1306 if( !strcmp(title, folders[i]->title) )
1307 return folders[i]->awindow_folder;
1309 return AW_NO_FOLDER;
1312 const char *EDL::get_folder_name(int no)
1314 if( no >= 0 && no<AWINDOW_FOLDERS )
1315 return AWindowGUI::folder_names[no];
1316 BinFolder *fp = get_folder(no);
1317 return !fp ? "" : fp->title;
1320 int EDL::new_folder(const char *title, int is_clips)
1322 if( !title[0] ) return 1;
1323 int ret = get_folder_number(title);
1324 if( ret >= 0 ) return 1;
1325 int idx = AWINDOW_FOLDERS;
1326 for( int i=0; i<folders.size(); ++i ) {
1327 BinFolder *fp = folders[i];
1328 int no = fp->awindow_folder;
1329 if( no >= idx ) idx = no+1;
1331 folders.append(new BinFolder(idx, is_clips, title));
1335 int EDL::delete_folder(const char *title)
1337 int k = folders.size();
1338 while( --k >= 0 && strcmp(title, folders[k]->title) );
1340 folders.remove_object_number(k);
1344 int EDL::get_use_vconsole(VEdit* *playable_edit,
1345 int64_t position, int direction, PlayableTracks *playable_tracks)
1347 int share_playable_tracks = 1;
1349 VTrack *playable_track = 0;
1350 const int debug = 0;
1353 // Calculate playable tracks when being called as a nested EDL
1354 if( !playable_tracks ) {
1355 share_playable_tracks = 0;
1356 playable_tracks = new PlayableTracks(this,
1357 position, direction, TRACK_VIDEO, 1);
1361 // Total number of playable tracks is 1
1362 if( playable_tracks->size() != 1 ) {
1366 playable_track = (VTrack*)playable_tracks->get(0);
1369 // Don't need playable tracks anymore
1370 if( !share_playable_tracks ) {
1371 delete playable_tracks;
1374 if( debug ) printf("EDL::get_use_vconsole %d playable_tracks->size()=%d\n",
1375 __LINE__, playable_tracks->size());
1376 if( result ) return 1;
1379 // Test mutual conditions between direct copy rendering and this.
1380 if( !playable_track->direct_copy_possible(position,
1384 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1386 *playable_edit = (VEdit*)playable_track->edits->editof(position,
1388 // No edit at current location
1389 if( !*playable_edit ) return 1;
1390 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1393 // Edit is nested EDL
1394 if( (*playable_edit)->nested_edl ) {
1396 EDL *nested_edl = (*playable_edit)->nested_edl;
1397 int64_t nested_position = (int64_t)((position -
1398 (*playable_edit)->startproject +
1399 (*playable_edit)->startsource) *
1400 nested_edl->session->frame_rate /
1401 session->frame_rate);
1404 VEdit *playable_edit_temp = 0;
1405 if( session->output_w != nested_edl->session->output_w ||
1406 session->output_h != nested_edl->session->output_h ||
1407 nested_edl->get_use_vconsole(&playable_edit_temp,
1416 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1417 // Edit is not a nested EDL
1418 Asset *asset = (*playable_edit)->asset;
1420 if( !asset ) return 1;
1421 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1423 // Asset and output device must have the same dimensions
1424 if( asset->width != session->output_w ||
1425 asset->height != session->output_h )
1429 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1430 // Asset and output device must have same resulting de-interlacing method
1431 if( ilaceautofixmethod2(session->interlace_mode,
1432 asset->interlace_autofixoption, asset->interlace_mode,
1433 asset->interlace_fixmethod) != ILACE_FIXMETHOD_NONE )
1436 // If we get here the frame is going to be directly copied. Whether it is
1437 // decompressed in hardware depends on the colormodel.
1443 int EDL::get_audio_channels()
1445 return session->audio_channels;
1448 int EDL::get_sample_rate()
1450 return session->sample_rate;
1453 int64_t EDL::get_audio_samples()
1455 return (int64_t)(tracks->total_length() *
1456 session->sample_rate);
1459 int EDL::have_audio()
1464 int EDL::have_video()
1472 return session->output_w;
1477 return session->output_h;
1480 double EDL::get_frame_rate()
1482 return session->frame_rate;
1485 int EDL::get_video_layers()
1490 int64_t EDL::get_video_frames()
1492 return (int64_t)(tracks->total_length() *
1493 session->frame_rate);
1496 void EDL::remove_vwindow_edls()
1498 for( int i=0; i<total_vwindow_edls(); ++i ) {
1499 get_vwindow_edl(i)->remove_user();
1501 vwindow_edls.remove_all();
1504 void EDL::remove_vwindow_edl(EDL *edl)
1506 if( vwindow_edls.number_of(edl) >= 0 ) {
1508 vwindow_edls.remove(edl);
1513 EDL* EDL::get_vwindow_edl(int number)
1515 return vwindow_edls.get(number);
1518 int EDL::total_vwindow_edls()
1520 return vwindow_edls.size();
1523 void EDL::append_vwindow_edl(EDL *edl, int increase_counter)
1525 if(vwindow_edls.number_of(edl) >= 0) return;
1527 if(increase_counter) edl->add_user();
1528 vwindow_edls.append(edl);
1532 double EDL::next_edit(double position)
1534 Units::fix_double(&position);
1535 double new_position = tracks->total_length();
1537 double max_rate = get_frame_rate();
1538 int sample_rate = get_sample_rate();
1539 if( sample_rate > max_rate ) max_rate = sample_rate;
1540 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1542 // Test for edit handles after position
1543 for( Track *track=tracks->first; track; track=track->next ) {
1544 if( !track->record ) continue;
1545 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1546 double edit_end = track->from_units(edit->startproject + edit->length);
1547 Units::fix_double(&edit_end);
1548 if( fabs(edit_end-position) < min_movement ) continue;
1549 if( edit_end > position && edit_end < new_position )
1550 new_position = edit_end;
1553 return new_position;
1556 double EDL::prev_edit(double position)
1558 Units::fix_double(&position);
1559 double new_position = -1;
1561 double max_rate = get_frame_rate();
1562 int sample_rate = get_sample_rate();
1563 if( sample_rate > max_rate ) max_rate = sample_rate;
1564 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1566 // Test for edit handles before cursor position
1567 for( Track *track=tracks->first; track; track=track->next ) {
1568 if( !track->record ) continue;
1569 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1570 double edit_end = track->from_units(edit->startproject);
1571 Units::fix_double(&edit_end);
1572 if( fabs(edit_end-position) < min_movement ) continue;
1573 if( edit_end < position && edit_end > new_position )
1574 new_position = edit_end;
1577 return new_position;
1580 void EDL::rescale_proxy(int orig_scale, int new_scale)
1582 if( orig_scale == new_scale ) return;
1584 float orig_w = (float)session->output_w * orig_scale;
1585 float orig_h = (float)session->output_h * orig_scale;
1587 session->output_w = Units::round(orig_w / new_scale);
1588 session->output_h = Units::round(orig_h / new_scale);
1592 for( Track *track=tracks->first; track; track=track->next ) {
1593 if( track->data_type != TRACK_VIDEO ) continue;
1594 orig_w = (float)track->track_w * orig_scale;
1595 orig_h = (float)track->track_h * orig_scale;
1596 track->track_w = Units::round(orig_w / new_scale);
1597 track->track_h = Units::round(orig_h / new_scale);
1598 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
1599 set_proxy(orig_scale, new_scale);
1600 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
1601 set_proxy(orig_scale, new_scale);
1602 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
1603 set_proxy(orig_scale, new_scale);
1604 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
1605 set_proxy(orig_scale, new_scale);
1606 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
1607 set_proxy(orig_scale, new_scale);
1611 void EDL::set_proxy(int new_scale, int use_scaler,
1612 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1614 int orig_scale = session->proxy_scale;
1615 int orig_use_scaler = session->proxy_use_scaler;
1617 // rescale to full size asset in read_frame
1618 session->proxy_scale = new_scale;
1619 session->proxy_use_scaler = use_scaler;
1622 for( int i=0; i<proxy_assets->size(); ++i ) {
1623 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
1624 proxy_asset->width = orig_assets->get(i)->get_w();
1625 proxy_asset->height = orig_assets->get(i)->get_h();
1630 if( !orig_use_scaler )
1631 rescale_proxy(orig_scale, new_scale);
1633 // change original assets to proxy assets
1634 int folder_no = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
1635 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1636 Indexable *proxy_idxbl = proxy_assets->get(i);
1637 proxy_idxbl->folder_no = folder_no;
1638 if( !proxy_idxbl->is_asset ) continue;
1639 Asset *proxy_asset = assets->update((Asset *)proxy_idxbl);
1640 if( proxy_asset == (Asset *)proxy_idxbl ) continue;
1641 proxy_asset->width = proxy_idxbl->get_w();
1642 proxy_asset->height = proxy_idxbl->get_h();
1644 // replace track contents
1645 for( Track *track=tracks->first; track; track=track->next ) {
1646 if( track->data_type != TRACK_VIDEO ) continue;
1647 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1648 Indexable *idxbl = (Indexable *)edit->asset;
1649 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1650 if( !idxbl ) continue;
1651 int i = orig_assets->size();
1652 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1653 if( i < 0 ) continue;
1654 Indexable *proxy_idxbl = proxy_assets->get(i);
1655 Asset *proxy_asset = proxy_idxbl->is_asset ?
1656 assets->update((Asset *)proxy_idxbl) : 0;
1657 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1658 (EDL *)proxy_idxbl : 0;
1659 edit->asset = proxy_asset;
1660 edit->nested_edl = proxy_edl;
1663 for( int j=0,n=clips.size(); j<n; ++j ) {
1664 EDL *clip = clips[j];
1666 for( Track *track=clip->tracks->first; track; track=track->next ) {
1667 if( track->data_type != TRACK_VIDEO ) continue;
1668 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1669 Indexable *idxbl = (Indexable *)edit->asset;
1670 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1671 if( !idxbl ) continue;
1672 int i = orig_assets->size();
1673 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1674 if( i < 0 ) continue;
1675 Indexable *proxy_idxbl = proxy_assets->get(i);
1676 Asset *proxy_asset = proxy_idxbl->is_asset ?
1677 assets->update((Asset *)proxy_idxbl) : 0;
1678 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1679 (EDL *)proxy_idxbl : 0;
1680 edit->asset = proxy_asset;
1681 edit->nested_edl = proxy_edl;
1685 if( has_proxy && !orig_use_scaler )
1686 clip->rescale_proxy(orig_scale, new_scale);
1690 void EDL::add_proxy(int use_scaler,
1691 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1694 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1695 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
1696 proxy_asset->width = orig_assets->get(i)->get_w();
1697 proxy_asset->height = orig_assets->get(i)->get_h();
1701 // change original assets to proxy assets
1702 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1703 Asset *proxy_asset = assets->update((Asset *)proxy_assets->get(i));
1704 proxy_asset->folder_no = AW_PROXY_FOLDER;
1705 // replace track contents
1706 for( Track *track=tracks->first; track; track=track->next ) {
1707 if( track->data_type != TRACK_VIDEO ) continue;
1708 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1709 if( !edit->asset ) continue;
1710 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
1711 edit->asset = proxy_asset;
1718 Asset *EDL::get_proxy_asset()
1720 return folder_no == AW_PROXY_FOLDER ?
1721 tracks->first->edits->first->asset : 0;
1724 Track *EDL::add_new_track(int data_type)
1726 Track *new_track = 0;
1727 switch( data_type ) {
1729 ++session->video_tracks;
1730 new_track = tracks->add_video_track(0, 0);
1733 ++session->audio_tracks;
1734 new_track = tracks->add_audio_track(0, 0);
1736 case TRACK_SUBTITLE:
1737 new_track = tracks->add_subttl_track(0, 0);
1743 double EDL::get_cursor_position(int cursor_x, int pane_no)
1745 return (double)cursor_x * local_session->zoom_sample / session->sample_rate +
1746 (double)local_session->view_start[pane_no] *
1747 local_session->zoom_sample / session->sample_rate;
1749 int64_t EDL::get_position_cursorx(double position, int pane_no)
1751 return (int64_t)(position * session->sample_rate / local_session->zoom_sample)
1752 - local_session->view_start[pane_no];
1755 int EDL::in_use(Indexable *indexable)
1757 for( Track *track=tracks->first; track; track=track->next ) {
1758 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1759 Indexable *idxbl = (Indexable *)edit->asset;
1760 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1761 if( !idxbl ) continue;
1762 if( idxbl->id == indexable->id ) return 1;
1763 if( !indexable->is_asset != !idxbl->is_asset ) continue;
1764 if( !strcmp(idxbl->path, indexable->path) ) return 1;
1767 for( int i=0; i<clips.size(); ++i )
1768 if( clips[i]->in_use(indexable) ) return 1;
1769 for( int i=0; i<nested_edls.size(); ++i )
1770 if( nested_edls[i]->in_use(indexable) ) return 1;
1774 int EDL::regroup(int next_id)
1776 ArrayList<int> new_groups;
1777 for( Track *track=tracks->first; track; track=track->next ) {
1778 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1779 if( !edit->group_id ) continue;
1780 int k = new_groups.size();
1781 while( --k >= 0 && new_groups[k] != edit->group_id );
1782 if( k >= 0 ) continue;
1783 new_groups.append(edit->group_id);
1786 for( Track *track=tracks->first; track; track=track->next ) {
1787 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1788 if( !edit->group_id ) continue;
1789 int k = new_groups.size();
1790 while( --k >= 0 && new_groups[k] != edit->group_id );
1791 if( k < 0 ) continue;
1792 edit->group_id = k + next_id;
1795 return new_groups.size();