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 "preferences.h"
53 #include "recordconfig.h"
54 #include "recordlabel.h"
55 #include "sharedlocation.h"
58 #include "transportque.inc"
59 #include "versioninfo.h"
66 EDL::EDL(EDL *parent_edl)
69 this->parent_edl = parent_edl;
84 remove_vwindow_edls();
92 void EDL::create_objects()
94 tracks = new Tracks(this);
95 assets = !parent_edl ? new Assets(this) : parent_edl->assets;
96 session = !parent_edl ? new EDLSession(this) : parent_edl->session;
97 local_session = new LocalSession(this);
98 labels = new Labels(this, "LABELS");
101 EDL& EDL::operator=(EDL &edl)
103 printf("EDL::operator= 1\n");
108 int EDL::load_defaults(BC_Hash *defaults)
111 session->load_defaults(defaults);
113 local_session->load_defaults(defaults);
117 int EDL::save_defaults(BC_Hash *defaults)
120 session->save_defaults(defaults);
122 local_session->save_defaults(defaults);
126 void EDL::boundaries()
128 session->boundaries();
129 local_session->boundaries();
132 int EDL::create_default_tracks()
135 for( int i=0; i<session->video_tracks; ++i ) {
136 tracks->add_video_track(0, 0);
138 for( int i=0; i<session->audio_tracks; ++i ) {
139 tracks->add_audio_track(0, 0);
144 int EDL::load_xml(FileXML *file, uint32_t load_flags)
149 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
150 remove_vwindow_edls();
154 // Search for start of master EDL.
156 // The parent_edl test caused clip creation to fail since those XML files
157 // contained an EDL tag.
159 // The parent_edl test is required to make EDL loading work because
160 // when loading an EDL the EDL tag is already read by the parent.
164 result = file->read_tag();
166 !file->tag.title_is("XML") &&
167 !file->tag.title_is("EDL"));
169 return result ? result : read_xml(file, load_flags);
172 int EDL::read_xml(FileXML *file, uint32_t load_flags)
175 // Track numbering offset for replacing undo data.
176 int track_offset = 0;
178 // Get path for backups
179 file->tag.get_property("path", path);
182 if( (load_flags & LOAD_ALL) == LOAD_ALL ||
183 (load_flags & LOAD_EDITS) == LOAD_EDITS ) {
184 while(tracks->last) delete tracks->last;
187 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
189 mixers.remove_all_objects();
192 if( load_flags & LOAD_TIMEBAR ) {
193 while(labels->last) delete labels->last;
194 local_session->unset_inpoint();
195 local_session->unset_outpoint();
198 // This was originally in LocalSession::load_xml
199 if( load_flags & LOAD_SESSION ) {
200 local_session->clipboard_length = 0;
204 result = file->read_tag();
207 if( file->tag.title_is("/XML") ||
208 file->tag.title_is("/EDL") ||
209 file->tag.title_is("/CLIP_EDL") ||
210 file->tag.title_is("/NESTED_EDL") ||
211 file->tag.title_is("/VWINDOW_EDL") ) {
215 if( file->tag.title_is("CLIPBOARD") ) {
216 local_session->clipboard_length =
217 file->tag.get_property("LENGTH", (double)0);
220 if( file->tag.title_is("VIDEO") ) {
221 if( (load_flags & LOAD_VCONFIG) &&
222 (load_flags & LOAD_SESSION) )
223 session->load_video_config(file, 0, load_flags);
225 result = file->skip_tag();
228 if( file->tag.title_is("AUDIO") ) {
229 if( (load_flags & LOAD_ACONFIG) &&
230 (load_flags & LOAD_SESSION) )
231 session->load_audio_config(file, 0, load_flags);
233 result = file->skip_tag();
236 if( file->tag.title_is("FOLDERS") ) {
237 result = folders.load_xml(file);
240 if( file->tag.title_is("MIXERS") ) {
241 if( (load_flags & LOAD_SESSION) )
244 result = file->skip_tag();
247 if( file->tag.title_is("ASSETS") ) {
248 if( load_flags & LOAD_ASSETS )
249 assets->load(file, load_flags);
251 result = file->skip_tag();
254 if( file->tag.title_is(labels->xml_tag) ) {
255 if( load_flags & LOAD_TIMEBAR )
256 labels->load(file, load_flags);
258 result = file->skip_tag();
261 if( file->tag.title_is("LOCALSESSION") ) {
262 if( (load_flags & LOAD_SESSION) ||
263 (load_flags & LOAD_TIMEBAR) )
264 local_session->load_xml(file, load_flags);
266 result = file->skip_tag();
269 if( file->tag.title_is("SESSION") ) {
270 if( (load_flags & LOAD_SESSION) &&
272 session->load_xml(file, 0, load_flags);
274 result = file->skip_tag();
277 if( file->tag.title_is("TRACK") ) {
278 tracks->load(file, track_offset, load_flags);
282 // Causes clip creation to fail because that involves an opening EDL tag.
283 if( file->tag.title_is("CLIP_EDL") && !parent_edl ) {
284 EDL *new_edl = new EDL(this);
285 new_edl->create_objects();
286 new_edl->read_xml(file, LOAD_ALL);
287 if( (load_flags & LOAD_ALL) == LOAD_ALL )
288 clips.add_clip(new_edl);
289 new_edl->remove_user();
292 if( file->tag.title_is("NESTED_EDL") ) {
293 EDL *nested_edl = new EDL;
294 nested_edl->create_objects();
295 nested_edl->read_xml(file, LOAD_ALL);
296 if( (load_flags & LOAD_ALL) == LOAD_ALL )
297 nested_edls.get_nested(nested_edl);
298 nested_edl->remove_user();
301 if( file->tag.title_is("VWINDOW_EDL") && !parent_edl ) {
302 EDL *new_edl = new EDL(this);
303 new_edl->create_objects();
304 new_edl->read_xml(file, LOAD_ALL);
307 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
308 // if( vwindow_edl && !vwindow_edl_shared )
309 // vwindow_edl->remove_user();
310 // vwindow_edl_shared = 0;
311 // vwindow_edl = new_edl;
313 append_vwindow_edl(new_edl, 0);
317 // Discard if not replacing EDL
319 new_edl->remove_user();
332 // Output path is the path of the output file if name truncation is desired.
333 // It is a "" if complete names should be used.
334 // Called recursively by copy for clips, thus the string can't be terminated.
335 // The string is not terminated in this call.
336 int EDL::save_xml(FileXML *file, const char *output_path)
338 copy(1, file, output_path, 0);
342 int EDL::copy_all(EDL *edl)
344 if( this == edl ) return 0;
345 folder_no = edl->folder_no;
352 tracks->copy_from(edl->tracks);
353 labels->copy_from(edl->labels);
357 void EDL::copy_clips(EDL *edl)
359 if( this == edl ) return;
361 remove_vwindow_edls();
363 // if( vwindow_edl && !vwindow_edl_shared )
364 // vwindow_edl->remove_user();
366 // vwindow_edl_shared = 0;
368 for( int i=0; i<edl->total_vwindow_edls(); ++i ) {
369 EDL *new_edl = new EDL(this);
370 new_edl->create_objects();
371 new_edl->copy_all(edl->get_vwindow_edl(i));
372 append_vwindow_edl(new_edl, 0);
376 for( int i=0; i<edl->clips.size(); ++i ) add_clip(edl->clips[i]);
379 void EDL::copy_nested(EDL *edl)
381 if( this == edl ) return;
382 nested_edls.copy_nested(edl->nested_edls);
385 void EDL::copy_assets(EDL *edl)
387 if( this == edl ) return;
390 assets->copy_from(edl->assets);
394 void EDL::copy_mixers(EDL *edl)
396 if( this == edl ) return;
397 mixers.copy_from(edl->mixers);
400 void EDL::copy_session(EDL *edl, int session_only)
402 if( this == edl ) return;
404 if( !session_only ) {
405 strcpy(this->path, edl->path);
406 folders.copy_from(&edl->folders);
410 session->copy(edl->session);
413 if( session_only <= 0 ) {
414 local_session->copy_from(edl->local_session);
418 int EDL::copy_assets(double start,
422 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
433 for( Asset *asset=assets->first; asset; asset=asset->next ) {
434 asset_list.append(asset);
438 // Copy just the ones being used.
439 for( current = tracks->first; current; current = NEXT ) {
440 if( !current->record ) 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(double start, double end, int all,
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(start, end, all,
466 "/EDL", file, output_path, rewind_it);
468 int EDL::copy(int all, FileXML *file, const char *output_path, int rewind_it)
470 return copy(0, tracks->total_length(), all, file, output_path, rewind_it);
473 int EDL::copy_clip(double start, double end, int all,
474 FileXML *file, const char *output_path, int rewind_it)
476 file->tag.set_title("CLIP_EDL");
477 return copy(start, end, all,
478 "/CLIP_EDL", file, output_path, rewind_it);
480 int EDL::copy_clip(int all, FileXML *file, const char *output_path, int rewind_it)
482 return copy_clip(0, tracks->total_length(), all, file, output_path, rewind_it);
485 int EDL::copy_nested_edl(double start, double end, int all,
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(start, end, all,
491 "/NESTED_EDL", file, output_path, rewind_it);
493 int EDL::copy_nested_edl(int all, FileXML *file, const char *output_path, int rewind_it)
495 return copy_nested_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
498 int EDL::copy_vwindow_edl(double start, double end, int all,
499 FileXML *file, const char *output_path, int rewind_it)
501 file->tag.set_title("VWINDOW_EDL");
502 return copy(start, end, all,
503 "/VWINDOW_EDL", file, output_path, rewind_it);
505 int EDL::copy_vwindow_edl(int all, FileXML *file, const char *output_path, int rewind_it)
507 return copy_vwindow_edl(0, tracks->total_length(), all, file, output_path, rewind_it);
511 int EDL::copy(double start, double end, int all,
512 const char *closer, FileXML *file,
513 const char *output_path, int rewind_it)
516 file->append_newline();
517 // Set clipboard samples only if copying to clipboard
519 file->tag.set_title("CLIPBOARD");
520 file->tag.set_property("LENGTH", end - start);
522 file->tag.set_title("/CLIPBOARD");
524 file->append_newline();
525 file->append_newline();
527 //printf("EDL::copy 1\n");
530 local_session->save_xml(file, start);
532 //printf("EDL::copy 1\n");
537 // Need to copy all this from child EDL if pasting is desired.
539 session->save_xml(file);
540 session->save_video_config(file);
541 session->save_audio_config(file);
542 folders.save_xml(file);
545 copy_assets(start, end, file, all, output_path);
547 for( int i=0; i<nested_edls.size(); ++i )
548 nested_edls[i]->copy_nested_edl(0, tracks->total_length(), 1,
549 file, output_path, 0);
552 // Don't want this if using clipboard
554 for( int i=0; i<total_vwindow_edls(); ++i )
555 get_vwindow_edl(i)->copy_vwindow_edl(1, file, output_path, 0);
557 for( int i=0; i<clips.size(); ++i )
558 clips[i]->copy_clip(1, file, output_path, 0);
563 file->append_newline();
564 file->append_newline();
567 labels->copy(start, end, file);
568 tracks->copy(start, end, all, file, output_path);
571 file->tag.set_title(closer);
573 file->append_newline();
575 // For editing operations we want to rewind it for immediate pasting.
576 // For clips and saving to disk leave it alone.
578 file->terminate_string();
584 void EDL::copy_indexables(EDL *edl)
586 for( Track *track=edl->tracks->first; track; track=track->next ) {
587 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
589 assets->update(edit->asset);
590 if( edit->nested_edl )
591 nested_edls.get_nested(edit->nested_edl);
596 EDL *EDL::new_nested(EDL *edl, const char *path)
598 EDL *nested = new EDL; // no parent for nested edl
599 nested->create_objects();
600 nested->copy_session(edl);
601 nested->set_path(path);
602 nested->update_index(edl);
603 nested->copy_indexables(edl);
604 nested->tracks->copy_from(edl->tracks);
605 nested_edls.append(nested);
609 EDL *EDL::create_nested_clip(EDL *nested)
611 EDL *new_edl = new EDL(this); // parent for clip edl
612 new_edl->create_objects();
613 new_edl->create_nested(nested);
617 void EDL::create_nested(EDL *nested)
619 // Keep frame rate, sample rate, and output size unchanged.
620 // Nest all video & audio outputs
621 session->video_tracks = 1;
622 session->audio_tracks = nested->session->audio_channels;
623 create_default_tracks();
624 insert_asset(0, nested, 0, 0, 0);
629 int min_w = session->output_w, min_h = session->output_h;
630 for( Track *track=tracks->first; track!=0; track=track->next ) {
631 if( track->data_type != TRACK_VIDEO ) continue;
632 int w = min_w, h = min_h;
633 for( Edit *current=track->edits->first; current!=0; current=NEXT ) {
634 Indexable* indexable = current->get_source();
635 if( !indexable ) continue;
636 int edit_w = indexable->get_w(), edit_h = indexable->get_h();
637 if( w < edit_w ) w = edit_w;
638 if( h < edit_h ) h = edit_h;
640 if( track->track_w == w && track->track_h == h ) continue;
641 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
642 translate_masks( (w - track->track_w) / 2, (h - track->track_h) / 2);
643 track->track_w = w; track->track_h = h;
647 void EDL::rechannel()
649 for( Track *current=tracks->first; current; current=NEXT ) {
650 if( current->data_type == TRACK_AUDIO ) {
651 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
652 ((PanAuto*)autos->default_auto)->rechannel();
653 for( PanAuto *keyframe = (PanAuto*)autos->first;
654 keyframe; keyframe = (PanAuto*)keyframe->next ) {
655 keyframe->rechannel();
661 void EDL::resample(double old_rate, double new_rate, int data_type)
663 for( Track *current=tracks->first; current; current=NEXT ) {
664 if( current->data_type == data_type ) {
665 current->resample(old_rate, new_rate);
671 void EDL::synchronize_params(EDL *edl)
673 local_session->synchronize_params(edl->local_session);
674 for( Track *this_track=tracks->first, *that_track=edl->tracks->first;
675 this_track && that_track;
676 this_track=this_track->next, that_track=that_track->next ) {
677 this_track->synchronize_params(that_track);
681 int EDL::trim_selection(double start,
695 tracks->total_length(),
704 int EDL::equivalent(double position1, double position2)
706 double threshold = session->cursor_on_frames ?
707 0.5 / session->frame_rate : 1.0 / session->sample_rate;
708 return fabs(position2 - position1) < threshold ? 1 : 0;
711 double EDL::equivalent_output(EDL *edl)
714 session->equivalent_output(edl->session, &result);
715 tracks->equivalent_output(edl->tracks, &result);
720 void EDL::set_path(const char *path)
722 if( &this->path[0] == path ) return;
723 strcpy(this->path, path);
726 void EDL::set_inpoint(double position)
728 if( equivalent(local_session->get_inpoint(), position) &&
729 local_session->get_inpoint() >= 0 ) {
730 local_session->unset_inpoint();
733 local_session->set_inpoint(align_to_frame(position, 0));
734 if( local_session->get_outpoint() <= local_session->get_inpoint() )
735 local_session->unset_outpoint();
739 void EDL::set_outpoint(double position)
741 if( equivalent(local_session->get_outpoint(), position) &&
742 local_session->get_outpoint() >= 0 ) {
743 local_session->unset_outpoint();
746 local_session->set_outpoint(align_to_frame(position, 0));
747 if( local_session->get_inpoint() >= local_session->get_outpoint() )
748 local_session->unset_inpoint();
752 void EDL::unset_inoutpoint()
754 local_session->unset_inpoint();
755 local_session->unset_outpoint();
758 int EDL::blade(double position)
760 return tracks->blade(position);
763 int EDL::clear(double start, double end,
764 int clear_labels, int clear_plugins, int edit_autos)
768 tracks->clear_handle(start,
774 if( clear_labels && distance > 0 )
775 labels->paste_silence(start,
789 // Need to put at beginning so a subsequent paste operation starts at the
791 double position = local_session->get_selectionstart();
792 local_session->set_selectionend(position);
793 local_session->set_selectionstart(position);
797 void EDL::delete_edits(ArrayList<Edit*> *edits, int collapse)
799 if( session->labels_follow_edits )
800 delete_edit_labels(edits, collapse);
801 for( int i=0; i<edits->size(); ++i ) {
802 Edit *edit = edits->get(i);
803 Track *track = edit->track;
804 int64_t start = edit->startproject;
805 int end = start + edit->length;
806 track->clear(start, end, 1, 0,
807 session->plugins_follow_edits,
808 session->autos_follow_edits, 0);
810 track->paste_silence(start, end,
811 session->plugins_follow_edits,
812 session->autos_follow_edits);
819 static int cmp(Range *ap, Range *bp);
821 bool operator ==(Range &that) { return this->start == that.start; }
822 bool operator >(Range &that) { return this->start > that.start; }
824 int Range::cmp(Range *ap, Range *bp) {
825 return ap->start < bp->start ? -1 : ap->start == bp->start ? 0 : 1;
828 static void get_edit_regions(ArrayList<Edit*> *edits, ArrayList<Range> ®ions)
830 // move edit inclusive labels by regions
831 for( int i=0; i<edits->size(); ++i ) {
832 Edit *edit = edits->get(i);
833 double pos = edit->track->from_units(edit->startproject);
834 double end = edit->track->from_units(edit->startproject + edit->length);
835 int n = regions.size(), k = n;
837 Range &range = regions[k];
838 if( pos >= range.end ) continue;
839 if( range.start >= end ) continue;
841 if( range.start > pos ) { range.start = pos; expand = 1; }
842 if( range.end < end ) { range.end = end; expand = 1; }
847 Range &range = regions.append();
848 range.start = pos; range.end = end;
851 regions.sort(Range::cmp);
854 void EDL::delete_edit_labels(ArrayList<Edit*> *edits, int collapse)
856 ArrayList<Range> regions;
857 get_edit_regions(edits, regions);
858 int n = regions.size(), k = n;
860 Range &range = regions[k];
861 labels->clear(range.start, range.end, collapse);
865 void EDL::move_edit_labels(ArrayList<Edit*> *edits, double dist)
867 ArrayList<Range> regions;
868 get_edit_regions(edits, regions);
869 int n = regions.size(), k = n;
870 Labels moved(this, 0);
872 Range &range = regions[k];
873 Label *label = labels->label_of(range.start);
874 for( Label *next=0; label && label->position <= range.end; label=next ) {
876 labels->remove_pointer(label);
877 label->position += dist;
880 Label *current = labels->first;
881 while( (label=moved.first) ) {
882 moved.remove_pointer(label);
883 while( current && current->position < label->position )
884 current = current->next;
885 if( current && current->position == label->position ) {
886 delete label; continue;
888 labels->insert_before(current, label);
894 void EDL::modify_edithandles(double oldposition,
902 tracks->modify_edithandles(oldposition,
909 labels->modify_handles(oldposition,
916 void EDL::modify_pluginhandles(double oldposition,
924 tracks->modify_pluginhandles(oldposition,
934 void EDL::paste_silence(double start,
941 labels->paste_silence(start, end);
942 tracks->paste_silence(start,
949 void EDL::remove_from_project(ArrayList<EDL*> *clips)
951 for( int i=0; i<clips->size(); ++i ) {
952 this->clips.remove_clip(clips->get(i));
956 void EDL::remove_from_project(ArrayList<Indexable*> *assets)
960 for( int j=0; j<clips.size(); ++j ) {
961 clips[j]->remove_from_project(assets);
964 // Remove from VWindow EDLs
965 for( int i=0; i<total_vwindow_edls(); ++i )
966 get_vwindow_edl(i)->remove_from_project(assets);
968 for( int i=0; i<assets->size(); ++i ) {
969 // Remove from tracks
970 for( Track *track=tracks->first; track; track=track->next ) {
971 track->remove_asset(assets->get(i));
974 // Remove from assets
975 if( !parent_edl && assets->get(i)->is_asset ) {
976 this->assets->remove_asset((Asset*)assets->get(i));
979 if( !parent_edl && !assets->get(i)->is_asset ) {
980 this->nested_edls.remove_clip((EDL*)assets->get(i));
985 void EDL::update_assets(EDL *src)
987 for( Asset *current=src->assets->first; current; current=NEXT ) {
988 assets->update(current);
992 int EDL::get_tracks_height(Theme *theme)
994 int total_pixels = 0;
995 for( Track *current=tracks->first; current; current=NEXT ) {
996 total_pixels += current->vertical_span(theme);
1001 int64_t EDL::get_tracks_width()
1003 int64_t total_pixels = 0;
1004 for( Track *current=tracks->first; current; current=NEXT ) {
1005 int64_t pixels = current->horizontal_span();
1006 if( pixels > total_pixels ) total_pixels = pixels;
1008 //printf("EDL::get_tracks_width %d\n", total_pixels);
1009 return total_pixels;
1012 // int EDL::calculate_output_w(int single_channel)
1014 // if( single_channel ) return session->output_w;
1017 // for( int i=0; i<session->video_channels; ++i )
1019 // if( session->vchannel_x[i] + session->output_w > widest ) widest = session->vchannel_x[i] + session->output_w;
1024 // int EDL::calculate_output_h(int single_channel)
1026 // if( single_channel ) return session->output_h;
1029 // for( int i=0; i<session->video_channels; ++i )
1031 // if( session->vchannel_y[i] + session->output_h > tallest ) tallest = session->vchannel_y[i] + session->output_h;
1036 // Get the total output size scaled to aspect ratio
1037 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
1039 if( (float)session->output_w / session->output_h > get_aspect_ratio() )
1040 h = (w = session->output_w) / get_aspect_ratio();
1042 w = (h = session->output_h) * get_aspect_ratio();
1045 float EDL::get_aspect_ratio()
1047 return session->aspect_w / session->aspect_h;
1050 int EDL::dump(FILE *fp)
1053 fprintf(fp,"CLIP\n");
1055 fprintf(fp,"EDL\n");
1056 fprintf(fp," clip_title: %s\n"
1057 " parent_edl: %p\n", local_session->clip_title, parent_edl);
1058 fprintf(fp," selectionstart %f\n selectionend %f\n loop_start %f\n loop_end %f\n",
1059 local_session->get_selectionstart(1),
1060 local_session->get_selectionend(1),
1061 local_session->loop_start,
1062 local_session->loop_end);
1063 for( int i=0; i<TOTAL_PANES; ++i ) {
1064 fprintf(fp," pane %d view_start=%jd track_start=%d\n", i,
1065 local_session->view_start[i],
1066 local_session->track_start[i]);
1070 fprintf(fp,"audio_channels: %d audio_tracks: %d sample_rate: %jd\n",
1071 session->audio_channels,
1072 session->audio_tracks,
1073 session->sample_rate);
1074 fprintf(fp," video_channels: %d\n"
1075 " video_tracks: %d\n"
1076 " frame_rate: %.2f\n"
1077 " frames_per_foot: %.2f\n"
1082 " color_model: %d\n",
1083 session->video_channels,
1084 session->video_tracks,
1085 session->frame_rate,
1086 session->frames_per_foot,
1091 session->color_model);
1093 fprintf(fp," CLIPS");
1094 fprintf(fp," total: %d\n", clips.size());
1095 for( int i=0; i<clips.size(); ++i ) {
1100 fprintf(fp," NESTED_EDLS");
1101 fprintf(fp," total: %d\n", nested_edls.size());
1102 for( int i=0; i<nested_edls.size(); ++i )
1103 fprintf(fp," %s\n", nested_edls[i]->path);
1105 fprintf(fp," VWINDOW EDLS");
1106 fprintf(fp," total: %d\n", total_vwindow_edls());
1108 for( int i=0; i<total_vwindow_edls(); ++i ) {
1109 fprintf(fp," %s\n", get_vwindow_edl(i)->local_session->clip_title);
1112 fprintf(fp," ASSETS\n");
1115 fprintf(fp," LABELS\n");
1117 fprintf(fp," TRACKS\n");
1119 //printf("EDL::dump 2\n");
1123 EDL* EDL::add_clip(EDL *edl)
1125 // Copy argument. New edls are deleted from MWindow::load_filenames.
1126 EDL *new_edl = new EDL(this);
1127 new_edl->create_objects();
1128 new_edl->copy_all(edl);
1129 new_edl->folder_no = AW_CLIP_FOLDER;
1130 clips.append(new_edl);
1134 void EDL::insert_asset(Asset *asset,
1138 RecordLabels *labels)
1140 // Insert asset into asset table
1141 Asset *new_asset = 0;
1142 EDL *new_nested_edl = 0;
1144 if( asset ) new_asset = assets->update(asset);
1145 if( nested_edl ) new_nested_edl = nested_edls.get_nested(nested_edl);
1149 Track *current = first_track ? first_track : tracks->first;
1152 // Fix length of single frame
1157 if( new_nested_edl ) {
1158 length = new_nested_edl->tracks->total_length();
1160 channels = new_nested_edl->session->audio_channels;
1164 // Insert 1 frame for undefined length
1165 if( new_asset->video_length < 0 ) {
1166 length = session->si_useduration ?
1167 session->si_duration :
1168 1.0 / session->frame_rate;
1171 length = new_asset->frame_rate > 0 ?
1172 (double)new_asset->video_length / new_asset->frame_rate :
1173 1.0 / session->frame_rate;
1175 layers = new_asset->layers;
1176 channels = new_asset->channels;
1179 for( ; current && vtrack<layers; current=NEXT ) {
1180 if( !current->record || current->data_type != TRACK_VIDEO ) continue;
1181 current->insert_asset(new_asset, new_nested_edl,
1182 length, position, vtrack++);
1187 if( new_asset->audio_length < 0 ) {
1188 // Insert 1 frame for undefined length & video
1189 if( new_asset->video_data )
1190 length = (double)1.0 / new_asset->frame_rate;
1192 // Insert 1 second for undefined length & no video
1196 length = (double)new_asset->audio_length /
1197 new_asset->sample_rate;
1200 current = tracks->first;
1201 for( ; current && atrack < channels; current=NEXT ) {
1202 if( !current->record || current->data_type != TRACK_AUDIO ) continue;
1203 current->insert_asset(new_asset, new_nested_edl,
1204 length, position, atrack++);
1207 // Insert labels from a recording window.
1209 for( RecordLabel *label=labels->first; label; label=label->next ) {
1210 this->labels->toggle_label(label->position, label->position);
1217 void EDL::set_index_file(Indexable *indexable)
1219 if( indexable->is_asset )
1220 assets->update_index((Asset*)indexable);
1222 nested_edls.update_index((EDL*)indexable);
1225 void EDL::optimize()
1227 //printf("EDL::optimize 1\n");
1228 double length = tracks->total_length();
1229 double preview_start = local_session->preview_start;
1230 double preview_end = local_session->preview_end;
1231 if( preview_end < 0 || preview_end > length )
1232 preview_end = length;
1233 if( preview_start == 0 && preview_end >= length )
1234 local_session->preview_end = -1;
1235 if( preview_start > preview_end )
1236 local_session->preview_start = preview_end;
1237 for( Track *current=tracks->first; current; current=NEXT )
1238 current->optimize();
1243 static Mutex id_lock;
1244 id_lock.lock("EDL::next_id");
1245 int result = EDLSession::current_id++;
1250 void EDL::get_shared_plugins(Track *source,
1251 ArrayList<SharedLocation*> *plugin_locations,
1252 int omit_recordable,
1255 for( Track *track=tracks->first; track; track=track->next ) {
1256 if( track->record && omit_recordable ) continue;
1257 if( track == source || track->data_type != data_type ) continue;
1258 for( int i=0; i<track->plugin_set.size(); ++i ) {
1259 Plugin *plugin = track->get_current_plugin(
1260 local_session->get_selectionstart(1),
1261 i, PLAY_FORWARD, 1, 0);
1262 if( plugin && plugin->plugin_type != PLUGIN_STANDALONE ) continue;
1263 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1268 void EDL::get_shared_tracks(Track *track,
1269 ArrayList<SharedLocation*> *module_locations,
1270 int omit_recordable, int data_type)
1272 for( Track *current=tracks->first; current; current=NEXT ) {
1273 if( omit_recordable && current->record ) continue;
1274 if( current == track || current->data_type != data_type ) continue;
1275 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1279 // aligned frame time
1280 double EDL::frame_align(double position, int round)
1282 double frame_pos = position * session->frame_rate;
1283 frame_pos = (int64_t)(frame_pos + (round ? 0.5 : 1e-6));
1284 position = frame_pos / session->frame_rate;
1288 // Convert position to frames if alignment is enabled.
1289 double EDL::align_to_frame(double position, int round)
1291 if( session->cursor_on_frames )
1292 position = frame_align(position, round);
1297 BinFolder *EDL::get_folder(int no)
1299 for( int i=0; i<folders.size(); ++i ) {
1300 BinFolder *fp = folders[i];
1301 if( no == fp->awindow_folder ) return fp;
1306 int EDL::get_folder_number(const char *title)
1308 for( int i=0; i<AWINDOW_FOLDERS; ++i ) {
1309 if( !strcmp(title, AWindowGUI::folder_names[i]) )
1312 for( int i=0; i<folders.size(); ++i ) {
1313 if( !strcmp(title, folders[i]->title) )
1314 return folders[i]->awindow_folder;
1316 return AW_NO_FOLDER;
1319 const char *EDL::get_folder_name(int no)
1321 if( no >= 0 && no<AWINDOW_FOLDERS )
1322 return AWindowGUI::folder_names[no];
1323 BinFolder *fp = get_folder(no);
1324 return !fp ? "" : fp->title;
1327 int EDL::new_folder(const char *title, int is_clips)
1329 if( !title[0] ) return 1;
1330 int ret = get_folder_number(title);
1331 if( ret >= 0 ) return 1;
1332 int idx = AWINDOW_FOLDERS;
1333 for( int i=0; i<folders.size(); ++i ) {
1334 BinFolder *fp = folders[i];
1335 int no = fp->awindow_folder;
1336 if( no >= idx ) idx = no+1;
1338 folders.append(new BinFolder(idx, is_clips, title));
1342 int EDL::delete_folder(const char *title)
1344 int k = folders.size();
1345 while( --k >= 0 && strcmp(title, folders[k]->title) );
1347 folders.remove_object_number(k);
1351 int EDL::get_use_vconsole(VEdit* *playable_edit,
1352 int64_t position, int direction, PlayableTracks *playable_tracks)
1354 int share_playable_tracks = 1;
1356 VTrack *playable_track = 0;
1357 const int debug = 0;
1360 // Calculate playable tracks when being called as a nested EDL
1361 if( !playable_tracks ) {
1362 share_playable_tracks = 0;
1363 playable_tracks = new PlayableTracks(this,
1364 position, direction, TRACK_VIDEO, 1);
1368 // Total number of playable tracks is 1
1369 if( playable_tracks->size() != 1 ) {
1373 playable_track = (VTrack*)playable_tracks->get(0);
1376 // Don't need playable tracks anymore
1377 if( !share_playable_tracks ) {
1378 delete playable_tracks;
1381 if( debug ) printf("EDL::get_use_vconsole %d playable_tracks->size()=%d\n",
1382 __LINE__, playable_tracks->size());
1383 if( result ) return 1;
1386 // Test mutual conditions between direct copy rendering and this.
1387 if( !playable_track->direct_copy_possible(position,
1391 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1393 *playable_edit = (VEdit*)playable_track->edits->editof(position,
1395 // No edit at current location
1396 if( !*playable_edit ) return 1;
1397 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1400 // Edit is nested EDL
1401 if( (*playable_edit)->nested_edl ) {
1403 EDL *nested_edl = (*playable_edit)->nested_edl;
1404 int64_t nested_position = (int64_t)((position -
1405 (*playable_edit)->startproject +
1406 (*playable_edit)->startsource) *
1407 nested_edl->session->frame_rate /
1408 session->frame_rate);
1411 VEdit *playable_edit_temp = 0;
1412 if( session->output_w != nested_edl->session->output_w ||
1413 session->output_h != nested_edl->session->output_h ||
1414 nested_edl->get_use_vconsole(&playable_edit_temp,
1423 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1424 // Edit is not a nested EDL
1425 Asset *asset = (*playable_edit)->asset;
1427 if( !asset ) return 1;
1428 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1430 // Asset and output device must have the same dimensions
1431 if( asset->width != session->output_w ||
1432 asset->height != session->output_h )
1436 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1437 // Asset and output device must have same resulting de-interlacing method
1438 if( ilaceautofixmethod2(session->interlace_mode,
1439 asset->interlace_autofixoption, asset->interlace_mode,
1440 asset->interlace_fixmethod) != ILACE_FIXMETHOD_NONE )
1443 // If we get here the frame is going to be directly copied. Whether it is
1444 // decompressed in hardware depends on the colormodel.
1450 int EDL::get_audio_channels()
1452 return session->audio_channels;
1455 int EDL::get_sample_rate()
1457 return session->sample_rate;
1460 int64_t EDL::get_audio_samples()
1462 return (int64_t)(tracks->total_length() *
1463 session->sample_rate);
1466 int EDL::have_audio()
1471 int EDL::have_video()
1479 return session->output_w;
1484 return session->output_h;
1487 double EDL::get_frame_rate()
1489 return session->frame_rate;
1492 int EDL::get_video_layers()
1497 int64_t EDL::get_video_frames()
1499 return (int64_t)(tracks->total_length() *
1500 session->frame_rate);
1503 void EDL::remove_vwindow_edls()
1505 for( int i=0; i<total_vwindow_edls(); ++i ) {
1506 get_vwindow_edl(i)->remove_user();
1508 vwindow_edls.remove_all();
1511 void EDL::remove_vwindow_edl(EDL *edl)
1513 if( vwindow_edls.number_of(edl) >= 0 ) {
1515 vwindow_edls.remove(edl);
1520 EDL* EDL::get_vwindow_edl(int number)
1522 return vwindow_edls.get(number);
1525 int EDL::total_vwindow_edls()
1527 return vwindow_edls.size();
1530 void EDL::append_vwindow_edl(EDL *edl, int increase_counter)
1532 if(vwindow_edls.number_of(edl) >= 0) return;
1534 if(increase_counter) edl->add_user();
1535 vwindow_edls.append(edl);
1539 double EDL::next_edit(double position)
1541 Units::fix_double(&position);
1542 double new_position = tracks->total_length();
1544 double max_rate = get_frame_rate();
1545 int sample_rate = get_sample_rate();
1546 if( sample_rate > max_rate ) max_rate = sample_rate;
1547 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1549 // Test for edit handles after position
1550 for( Track *track=tracks->first; track; track=track->next ) {
1551 if( !track->record ) continue;
1552 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1553 double edit_end = track->from_units(edit->startproject + edit->length);
1554 Units::fix_double(&edit_end);
1555 if( fabs(edit_end-position) < min_movement ) continue;
1556 if( edit_end > position && edit_end < new_position )
1557 new_position = edit_end;
1560 return new_position;
1563 double EDL::prev_edit(double position)
1565 Units::fix_double(&position);
1566 double new_position = -1;
1568 double max_rate = get_frame_rate();
1569 int sample_rate = get_sample_rate();
1570 if( sample_rate > max_rate ) max_rate = sample_rate;
1571 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1573 // Test for edit handles before cursor position
1574 for( Track *track=tracks->first; track; track=track->next ) {
1575 if( !track->record ) continue;
1576 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1577 double edit_end = track->from_units(edit->startproject);
1578 Units::fix_double(&edit_end);
1579 if( fabs(edit_end-position) < min_movement ) continue;
1580 if( edit_end < position && edit_end > new_position )
1581 new_position = edit_end;
1584 return new_position;
1587 void EDL::rescale_proxy(int orig_scale, int new_scale)
1589 if( orig_scale == new_scale ) return;
1591 float orig_w = (float)session->output_w * orig_scale;
1592 float orig_h = (float)session->output_h * orig_scale;
1594 session->output_w = Units::round(orig_w / new_scale);
1595 session->output_h = Units::round(orig_h / new_scale);
1599 for( Track *track=tracks->first; track; track=track->next ) {
1600 if( track->data_type != TRACK_VIDEO ) continue;
1601 orig_w = (float)track->track_w * orig_scale;
1602 orig_h = (float)track->track_h * orig_scale;
1603 track->track_w = Units::round(orig_w / new_scale);
1604 track->track_h = Units::round(orig_h / new_scale);
1605 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
1606 set_proxy(orig_scale, new_scale);
1607 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
1608 set_proxy(orig_scale, new_scale);
1609 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
1610 set_proxy(orig_scale, new_scale);
1611 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
1612 set_proxy(orig_scale, new_scale);
1613 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
1614 set_proxy(orig_scale, new_scale);
1618 void EDL::set_proxy(int new_scale, int use_scaler,
1619 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1621 int orig_scale = session->proxy_scale;
1622 int orig_use_scaler = session->proxy_use_scaler;
1624 // rescale to full size asset in read_frame
1625 session->proxy_scale = new_scale;
1626 session->proxy_use_scaler = use_scaler;
1629 for( int i=0; i<proxy_assets->size(); ++i ) {
1630 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
1631 proxy_asset->width = orig_assets->get(i)->get_w();
1632 proxy_asset->height = orig_assets->get(i)->get_h();
1637 if( !orig_use_scaler )
1638 rescale_proxy(orig_scale, new_scale);
1640 // change original assets to proxy assets
1641 int folder_no = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
1642 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1643 Indexable *proxy_idxbl = proxy_assets->get(i);
1644 proxy_idxbl->folder_no = folder_no;
1645 if( !proxy_idxbl->is_asset ) continue;
1646 Asset *proxy_asset = assets->update((Asset *)proxy_idxbl);
1647 if( proxy_asset == (Asset *)proxy_idxbl ) continue;
1648 proxy_asset->width = proxy_idxbl->get_w();
1649 proxy_asset->height = proxy_idxbl->get_h();
1651 // replace track contents
1652 for( Track *track=tracks->first; track; track=track->next ) {
1653 if( track->data_type != TRACK_VIDEO ) continue;
1654 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1655 Indexable *idxbl = (Indexable *)edit->asset;
1656 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1657 if( !idxbl ) continue;
1658 int i = orig_assets->size();
1659 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1660 if( i < 0 ) continue;
1661 Indexable *proxy_idxbl = proxy_assets->get(i);
1662 Asset *proxy_asset = proxy_idxbl->is_asset ?
1663 assets->update((Asset *)proxy_idxbl) : 0;
1664 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1665 (EDL *)proxy_idxbl : 0;
1666 edit->asset = proxy_asset;
1667 edit->nested_edl = proxy_edl;
1670 for( int j=0,n=clips.size(); j<n; ++j ) {
1671 EDL *clip = clips[j];
1673 for( Track *track=clip->tracks->first; track; track=track->next ) {
1674 if( track->data_type != TRACK_VIDEO ) continue;
1675 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1676 Indexable *idxbl = (Indexable *)edit->asset;
1677 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1678 if( !idxbl ) continue;
1679 int i = orig_assets->size();
1680 while( --i>=0 && strcmp(orig_assets->get(i)->path, idxbl->path) );
1681 if( i < 0 ) continue;
1682 Indexable *proxy_idxbl = proxy_assets->get(i);
1683 Asset *proxy_asset = proxy_idxbl->is_asset ?
1684 assets->update((Asset *)proxy_idxbl) : 0;
1685 EDL *proxy_edl = !proxy_idxbl->is_asset ?
1686 (EDL *)proxy_idxbl : 0;
1687 edit->asset = proxy_asset;
1688 edit->nested_edl = proxy_edl;
1692 if( has_proxy && !orig_use_scaler )
1693 clip->rescale_proxy(orig_scale, new_scale);
1697 void EDL::add_proxy(int use_scaler,
1698 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
1701 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1702 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
1703 proxy_asset->width = orig_assets->get(i)->get_w();
1704 proxy_asset->height = orig_assets->get(i)->get_h();
1708 // change original assets to proxy assets
1709 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
1710 Asset *proxy_asset = assets->update((Asset *)proxy_assets->get(i));
1711 proxy_asset->folder_no = AW_PROXY_FOLDER;
1712 // replace track contents
1713 for( Track *track=tracks->first; track; track=track->next ) {
1714 if( track->data_type != TRACK_VIDEO ) continue;
1715 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1716 if( !edit->asset ) continue;
1717 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
1718 edit->asset = proxy_asset;
1725 Asset *EDL::get_proxy_asset()
1727 return folder_no == AW_PROXY_FOLDER ?
1728 tracks->first->edits->first->asset : 0;
1731 Track *EDL::add_new_track(int data_type)
1733 Track *new_track = 0;
1734 switch( data_type ) {
1736 ++session->video_tracks;
1737 new_track = tracks->add_video_track(0, 0);
1740 ++session->audio_tracks;
1741 new_track = tracks->add_audio_track(0, 0);
1743 case TRACK_SUBTITLE:
1744 new_track = tracks->add_subttl_track(0, 0);
1750 double EDL::get_cursor_position(int cursor_x, int pane_no)
1752 return (double)cursor_x * local_session->zoom_sample / session->sample_rate +
1753 (double)local_session->view_start[pane_no] *
1754 local_session->zoom_sample / session->sample_rate;
1756 int64_t EDL::get_position_cursorx(double position, int pane_no)
1758 return (int64_t)(position * session->sample_rate / local_session->zoom_sample)
1759 - local_session->view_start[pane_no];
1762 int EDL::in_use(Indexable *indexable)
1764 for( Track *track=tracks->first; track; track=track->next ) {
1765 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1766 Indexable *idxbl = (Indexable *)edit->asset;
1767 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
1768 if( !idxbl ) continue;
1769 if( idxbl->id == indexable->id ) return 1;
1770 if( !indexable->is_asset != !idxbl->is_asset ) continue;
1771 if( !strcmp(idxbl->path, indexable->path) ) return 1;
1774 for( int i=0; i<clips.size(); ++i )
1775 if( clips[i]->in_use(indexable) ) return 1;
1776 for( int i=0; i<nested_edls.size(); ++i )
1777 if( nested_edls[i]->in_use(indexable) ) return 1;
1781 int EDL::regroup(int next_id)
1783 ArrayList<int> new_groups;
1784 for( Track *track=tracks->first; track; track=track->next ) {
1785 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1786 if( !edit->group_id ) continue;
1787 int k = new_groups.size();
1788 while( --k >= 0 && new_groups[k] != edit->group_id );
1789 if( k >= 0 ) continue;
1790 new_groups.append(edit->group_id);
1793 for( Track *track=tracks->first; track; track=track->next ) {
1794 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1795 if( !edit->group_id ) continue;
1796 int k = new_groups.size();
1797 while( --k >= 0 && new_groups[k] != edit->group_id );
1798 if( k < 0 ) continue;
1799 edit->group_id = k + next_id;
1802 return new_groups.size();