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.inc"
28 #include "bcsignals.h"
31 #include "bccmodels.h"
36 #include "edlsession.h"
39 #include "indexstate.h"
40 #include "interlacemodes.h"
42 #include "localsession.h"
43 #include "maskautos.h"
47 #include "playbackconfig.h"
48 #include "playabletracks.h"
50 #include "preferences.h"
51 #include "recordconfig.h"
52 #include "recordlabel.h"
53 #include "sharedlocation.h"
56 #include "transportque.inc"
57 #include "versioninfo.h"
64 EDL::EDL(EDL *parent_edl)
67 this->parent_edl = parent_edl;
71 folders.set_array_delete();
83 remove_vwindow_edls();
88 folders.remove_all_objects();
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 folders.remove_all_objects();
151 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
152 remove_vwindow_edls();
156 // Search for start of master EDL.
158 // The parent_edl test caused clip creation to fail since those XML files
159 // contained an EDL tag.
161 // The parent_edl test is required to make EDL loading work because
162 // when loading an EDL the EDL tag is already read by the parent.
166 result = file->read_tag();
168 !file->tag.title_is("XML") &&
169 !file->tag.title_is("EDL"));
171 return result ? result : read_xml(file, load_flags);
174 int EDL::read_xml(FileXML *file, uint32_t load_flags)
177 // Track numbering offset for replacing undo data.
178 int track_offset = 0;
180 // Get path for backups
181 file->tag.get_property("path", path);
184 if( (load_flags & LOAD_ALL) == LOAD_ALL ||
185 (load_flags & LOAD_EDITS) == LOAD_EDITS ) {
186 while(tracks->last) delete tracks->last;
189 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
191 mixers.remove_all_objects();
194 if( load_flags & LOAD_TIMEBAR ) {
195 while(labels->last) delete labels->last;
196 local_session->unset_inpoint();
197 local_session->unset_outpoint();
200 // This was originally in LocalSession::load_xml
201 if( load_flags & LOAD_SESSION ) {
202 local_session->clipboard_length = 0;
206 result = file->read_tag();
209 if( file->tag.title_is("/XML") ||
210 file->tag.title_is("/EDL") ||
211 file->tag.title_is("/CLIP_EDL") ||
212 file->tag.title_is("/NESTED_EDL") ||
213 file->tag.title_is("/VWINDOW_EDL") ) {
217 if( file->tag.title_is("CLIPBOARD") ) {
218 local_session->clipboard_length =
219 file->tag.get_property("LENGTH", (double)0);
222 if( file->tag.title_is("VIDEO") ) {
223 if( (load_flags & LOAD_VCONFIG) &&
224 (load_flags & LOAD_SESSION) )
225 session->load_video_config(file, 0, load_flags);
227 result = file->skip_tag();
230 if( file->tag.title_is("AUDIO") ) {
231 if( (load_flags & LOAD_ACONFIG) &&
232 (load_flags & LOAD_SESSION) )
233 session->load_audio_config(file, 0, load_flags);
235 result = file->skip_tag();
238 if( file->tag.title_is("FOLDER") ) {
239 char folder[BCTEXTLEN];
240 strcpy(folder, file->read_text());
244 if( file->tag.title_is("MIXERS") ) {
245 if( (load_flags & LOAD_SESSION) )
248 result = file->skip_tag();
251 if( file->tag.title_is("ASSETS") ) {
252 if( load_flags & LOAD_ASSETS )
253 assets->load(file, load_flags);
255 result = file->skip_tag();
258 if( file->tag.title_is(labels->xml_tag) ) {
259 if( load_flags & LOAD_TIMEBAR )
260 labels->load(file, load_flags);
262 result = file->skip_tag();
265 if( file->tag.title_is("LOCALSESSION") ) {
266 if( (load_flags & LOAD_SESSION) ||
267 (load_flags & LOAD_TIMEBAR) )
268 local_session->load_xml(file, load_flags);
270 result = file->skip_tag();
273 if( file->tag.title_is("SESSION") ) {
274 if( (load_flags & LOAD_SESSION) &&
276 session->load_xml(file, 0, load_flags);
278 result = file->skip_tag();
281 if( file->tag.title_is("TRACK") ) {
282 tracks->load(file, track_offset, load_flags);
286 // Causes clip creation to fail because that involves an opening EDL tag.
287 if( file->tag.title_is("CLIP_EDL") && !parent_edl ) {
288 EDL *new_edl = new EDL(this);
289 new_edl->create_objects();
290 new_edl->read_xml(file, LOAD_ALL);
291 if( (load_flags & LOAD_ALL) == LOAD_ALL )
292 clips.add_clip(new_edl);
293 new_edl->remove_user();
296 if( file->tag.title_is("NESTED_EDL") ) {
297 EDL *nested_edl = new EDL;
298 nested_edl->create_objects();
299 nested_edl->read_xml(file, LOAD_ALL);
300 if( (load_flags & LOAD_ALL) == LOAD_ALL )
301 nested_edls.add_clip(nested_edl);
302 nested_edl->remove_user();
305 if( file->tag.title_is("VWINDOW_EDL") && !parent_edl ) {
306 EDL *new_edl = new EDL(this);
307 new_edl->create_objects();
308 new_edl->read_xml(file, LOAD_ALL);
311 if( (load_flags & LOAD_ALL) == LOAD_ALL ) {
312 // if( vwindow_edl && !vwindow_edl_shared )
313 // vwindow_edl->remove_user();
314 // vwindow_edl_shared = 0;
315 // vwindow_edl = new_edl;
317 append_vwindow_edl(new_edl, 0);
321 // Discard if not replacing EDL
323 new_edl->remove_user();
336 // Output path is the path of the output file if name truncation is desired.
337 // It is a "" if complete names should be used.
338 // Called recursively by copy for clips, thus the string can't be terminated.
339 // The string is not terminated in this call.
340 int EDL::save_xml(FileXML *file, const char *output_path)
342 copy(0, tracks->total_length(), 1, file, output_path, 0);
346 int EDL::copy_all(EDL *edl)
348 if( this == edl ) return 0;
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 //printf("EDL::copy_session %p %s\n", this, this->path);
411 folders.remove_all_objects();
412 for( int i=0; i<edl->folders.size(); ++i )
413 folders.append(cstrdup(edl->folders[i]));
417 session->copy(edl->session);
420 if( !session_only ) {
421 local_session->copy_from(edl->local_session);
425 int EDL::copy_assets(double start,
429 const char *output_path)
431 ArrayList<Asset*> asset_list;
434 file->tag.set_title("ASSETS");
436 file->append_newline();
438 // Copy everything for a save
440 for( Asset *asset=assets->first; asset; asset=asset->next ) {
441 asset_list.append(asset);
445 // Copy just the ones being used.
446 for( current = tracks->first; current; current = NEXT ) {
447 if( !current->record ) continue;
448 current->copy_assets(start, end, &asset_list);
452 // Paths relativised here
453 for( int i=0; i<asset_list.size(); ++i ) {
454 asset_list[i]->write(file, 0, output_path);
457 file->tag.set_title("/ASSETS");
459 file->append_newline();
460 file->append_newline();
465 int EDL::copy(double start, double end, int all,
466 FileXML *file, const char *output_path, int rewind_it)
468 file->tag.set_title("EDL");
469 file->tag.set_property("VERSION", CINELERRA_VERSION);
470 // Save path for restoration of the project title from a backup.
471 if( this->path[0] ) file->tag.set_property("PATH", path);
472 return copy(start, end, all,
473 "/EDL", file, output_path, rewind_it);
476 int EDL::copy_clip(double start, double end, int all,
477 FileXML *file, const char *output_path, int rewind_it)
479 file->tag.set_title("CLIP_EDL");
480 return copy(start, end, all,
481 "/CLIP_EDL", file, output_path, rewind_it);
483 int EDL::copy_nested_edl(double start, double end, int all,
484 FileXML *file, const char *output_path, int rewind_it)
486 file->tag.set_title("NESTED_EDL");
487 if( this->path[0] ) file->tag.set_property("PATH", path);
488 return copy(start, end, all,
489 "/NESTED_EDL", file, output_path, rewind_it);
491 int EDL::copy_vwindow_edl(double start, double end, int all,
492 FileXML *file, const char *output_path, int rewind_it)
494 file->tag.set_title("VWINDOW_EDL");
495 return copy(start, end, all,
496 "/VWINDOW_EDL", file, output_path, rewind_it);
499 int EDL::copy(double start, double end, int all,
500 const char *closer, FileXML *file,
501 const char *output_path, int rewind_it)
504 file->append_newline();
505 // Set clipboard samples only if copying to clipboard
507 file->tag.set_title("CLIPBOARD");
508 file->tag.set_property("LENGTH", end - start);
510 file->tag.set_title("/CLIPBOARD");
512 file->append_newline();
513 file->append_newline();
515 //printf("EDL::copy 1\n");
518 local_session->save_xml(file, start);
520 //printf("EDL::copy 1\n");
525 // Need to copy all this from child EDL if pasting is desired.
527 session->save_xml(file);
528 session->save_video_config(file);
529 session->save_audio_config(file);
532 for( int i=0; i<folders.size(); ++i ) {
533 file->tag.set_title("FOLDER");
535 file->append_text(folders[i]);
536 file->tag.set_title("/FOLDER");
538 file->append_newline();
542 copy_assets(start, end, file, all, output_path);
544 for( int i=0; i<nested_edls.size(); ++i )
545 nested_edls[i]->copy_nested_edl(0, tracks->total_length(), 1,
546 file, output_path, 0);
549 // Don't want this if using clipboard
551 for( int i=0; i<total_vwindow_edls(); ++i )
552 get_vwindow_edl(i)->copy_vwindow_edl(0, tracks->total_length(), 1,
553 file, output_path, 0);
555 for( int i=0; i<clips.size(); ++i )
556 clips[i]->copy_clip(0, tracks->total_length(), 1,
557 file, output_path, 0);
562 file->append_newline();
563 file->append_newline();
566 labels->copy(start, end, file);
567 tracks->copy(start, end, all, file, output_path);
570 file->tag.set_title(closer);
572 file->append_newline();
574 // For editing operations we want to rewind it for immediate pasting.
575 // For clips and saving to disk leave it alone.
577 file->terminate_string();
583 EDL *EDL::get_nested(EDL *nested_edl, const char *path)
585 for( int i=0; i<nested_edls.size(); ++i ) {
586 EDL *dst = nested_edls[i];
587 if( !strcmp(path, dst->path) ) return dst;
589 return new_nested(nested_edl, path);
592 EDL *EDL::new_nested(EDL *nested_edl, const char *path)
594 EDL *new_edl = new EDL; // no parent for nested clip
595 new_edl->create_objects();
596 new_edl->copy_session(this);
597 new_edl->create_nested(nested_edl, path);
601 void EDL::create_nested(EDL *nested_edl, const char *path)
604 strcpy(local_session->clip_title, path);
605 // save a ref to nested edl for garbage delete
606 EDL *nest = clips.get_copy(nested_edl);
607 // Keep frame rate, sample rate, and output size unchanged.
608 // Nest all video & audio outputs
609 session->video_tracks = 1;
610 session->audio_tracks = nest->session->audio_channels;
611 create_default_tracks();
612 insert_asset(0, nest, 0, 0, 0);
617 int min_w = session->output_w, min_h = session->output_h;
618 for( Track *track=tracks->first; track!=0; track=track->next ) {
619 if( track->data_type != TRACK_VIDEO ) continue;
620 int w = min_w, h = min_h;
621 for( Edit *current=track->edits->first; current!=0; current=NEXT ) {
622 Indexable* indexable = current->get_source();
623 if( !indexable ) continue;
624 int edit_w = indexable->get_w(), edit_h = indexable->get_h();
625 if( w < edit_w ) w = edit_w;
626 if( h < edit_h ) h = edit_h;
628 if( track->track_w == w && track->track_h == h ) continue;
629 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
630 translate_masks( (w - track->track_w) / 2, (h - track->track_h) / 2);
631 track->track_w = w; track->track_h = h;
635 void EDL::rechannel()
637 for( Track *current=tracks->first; current; current=NEXT ) {
638 if( current->data_type == TRACK_AUDIO ) {
639 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
640 ((PanAuto*)autos->default_auto)->rechannel();
641 for( PanAuto *keyframe = (PanAuto*)autos->first;
642 keyframe; keyframe = (PanAuto*)keyframe->next ) {
643 keyframe->rechannel();
649 void EDL::resample(double old_rate, double new_rate, int data_type)
651 for( Track *current=tracks->first; current; current=NEXT ) {
652 if( current->data_type == data_type ) {
653 current->resample(old_rate, new_rate);
659 void EDL::synchronize_params(EDL *edl)
661 local_session->synchronize_params(edl->local_session);
662 for( Track *this_track=tracks->first, *that_track=edl->tracks->first;
663 this_track && that_track;
664 this_track=this_track->next, that_track=that_track->next ) {
665 this_track->synchronize_params(that_track);
669 int EDL::trim_selection(double start,
683 tracks->total_length(),
692 int EDL::equivalent(double position1, double position2)
694 double threshold = session->cursor_on_frames ?
695 0.5 / session->frame_rate : 1.0 / session->sample_rate;
696 return fabs(position2 - position1) < threshold ? 1 : 0;
699 double EDL::equivalent_output(EDL *edl)
702 session->equivalent_output(edl->session, &result);
703 tracks->equivalent_output(edl->tracks, &result);
708 void EDL::set_path(const char *path)
710 strcpy(this->path, path);
713 void EDL::set_inpoint(double position)
715 if( equivalent(local_session->get_inpoint(), position) &&
716 local_session->get_inpoint() >= 0 ) {
717 local_session->unset_inpoint();
720 local_session->set_inpoint(align_to_frame(position, 0));
721 if( local_session->get_outpoint() <= local_session->get_inpoint() )
722 local_session->unset_outpoint();
726 void EDL::set_outpoint(double position)
728 if( equivalent(local_session->get_outpoint(), position) &&
729 local_session->get_outpoint() >= 0 ) {
730 local_session->unset_outpoint();
733 local_session->set_outpoint(align_to_frame(position, 0));
734 if( local_session->get_inpoint() >= local_session->get_outpoint() )
735 local_session->unset_inpoint();
739 void EDL::unset_inoutpoint()
741 local_session->unset_inpoint();
742 local_session->unset_outpoint();
745 int EDL::blade(double position)
747 return tracks->blade(position);
750 int EDL::clear(double start, double end,
751 int clear_labels, int clear_plugins, int edit_autos)
755 tracks->clear_handle(start,
761 if( clear_labels && distance > 0 )
762 labels->paste_silence(start,
776 // Need to put at beginning so a subsequent paste operation starts at the
778 double position = local_session->get_selectionstart();
779 local_session->set_selectionend(position);
780 local_session->set_selectionstart(position);
784 void EDL::modify_edithandles(double oldposition,
792 tracks->modify_edithandles(oldposition,
799 labels->modify_handles(oldposition,
806 void EDL::modify_pluginhandles(double oldposition,
814 tracks->modify_pluginhandles(oldposition,
824 void EDL::paste_silence(double start,
831 labels->paste_silence(start, end);
832 tracks->paste_silence(start,
839 void EDL::remove_from_project(ArrayList<EDL*> *clips)
841 for( int i=0; i<clips->size(); ++i ) {
842 this->clips.remove_clip(clips->get(i));
846 void EDL::remove_from_project(ArrayList<Indexable*> *assets)
850 for( int j=0; j<clips.size(); ++j ) {
851 clips[j]->remove_from_project(assets);
854 // Remove from VWindow EDLs
855 for( int i=0; i<total_vwindow_edls(); ++i )
856 get_vwindow_edl(i)->remove_from_project(assets);
858 for( int i=0; i<assets->size(); ++i ) {
859 // Remove from tracks
860 for( Track *track=tracks->first; track; track=track->next ) {
861 track->remove_asset(assets->get(i));
864 // Remove from assets
865 if( !parent_edl && assets->get(i)->is_asset ) {
866 this->assets->remove_asset((Asset*)assets->get(i));
869 if( !parent_edl && !assets->get(i)->is_asset ) {
870 this->nested_edls.remove_clip((EDL*)assets->get(i));
875 void EDL::update_assets(EDL *src)
877 for( Asset *current=src->assets->first; current; current=NEXT ) {
878 assets->update(current);
882 int EDL::get_tracks_height(Theme *theme)
884 int total_pixels = 0;
885 for( Track *current=tracks->first; current; current=NEXT ) {
886 total_pixels += current->vertical_span(theme);
891 int64_t EDL::get_tracks_width()
893 int64_t total_pixels = 0;
894 for( Track *current=tracks->first; current; current=NEXT ) {
895 int64_t pixels = current->horizontal_span();
896 if( pixels > total_pixels ) total_pixels = pixels;
898 //printf("EDL::get_tracks_width %d\n", total_pixels);
902 // int EDL::calculate_output_w(int single_channel)
904 // if( single_channel ) return session->output_w;
907 // for( int i=0; i<session->video_channels; ++i )
909 // if( session->vchannel_x[i] + session->output_w > widest ) widest = session->vchannel_x[i] + session->output_w;
914 // int EDL::calculate_output_h(int single_channel)
916 // if( single_channel ) return session->output_h;
919 // for( int i=0; i<session->video_channels; ++i )
921 // if( session->vchannel_y[i] + session->output_h > tallest ) tallest = session->vchannel_y[i] + session->output_h;
926 // Get the total output size scaled to aspect ratio
927 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
929 if( (float)session->output_w / session->output_h > get_aspect_ratio() )
930 h = (w = session->output_w) / get_aspect_ratio();
932 w = (h = session->output_h) * get_aspect_ratio();
935 float EDL::get_aspect_ratio()
937 return session->aspect_w / session->aspect_h;
940 int EDL::dump(FILE *fp)
943 fprintf(fp,"CLIP\n");
946 fprintf(fp," clip_title: %s\n"
947 " parent_edl: %p\n", local_session->clip_title, parent_edl);
948 fprintf(fp," selectionstart %f\n selectionend %f\n loop_start %f\n loop_end %f\n",
949 local_session->get_selectionstart(1),
950 local_session->get_selectionend(1),
951 local_session->loop_start,
952 local_session->loop_end);
953 for( int i=0; i<TOTAL_PANES; ++i ) {
954 fprintf(fp," pane %d view_start=%jd track_start=%d\n", i,
955 local_session->view_start[i],
956 local_session->track_start[i]);
960 fprintf(fp,"audio_channels: %d audio_tracks: %d sample_rate: %jd\n",
961 session->audio_channels,
962 session->audio_tracks,
963 session->sample_rate);
964 fprintf(fp," video_channels: %d\n"
965 " video_tracks: %d\n"
966 " frame_rate: %.2f\n"
967 " frames_per_foot: %.2f\n"
972 " color_model: %d\n",
973 session->video_channels,
974 session->video_tracks,
976 session->frames_per_foot,
981 session->color_model);
983 fprintf(fp," CLIPS");
984 fprintf(fp," total: %d\n", clips.size());
985 for( int i=0; i<clips.size(); ++i ) {
990 fprintf(fp," NESTED_EDLS");
991 fprintf(fp," total: %d\n", nested_edls.size());
992 for( int i=0; i<nested_edls.size(); ++i )
993 fprintf(fp," %s\n", nested_edls[i]->path);
995 fprintf(fp," VWINDOW EDLS");
996 fprintf(fp," total: %d\n", total_vwindow_edls());
998 for( int i=0; i<total_vwindow_edls(); ++i ) {
999 fprintf(fp," %s\n", get_vwindow_edl(i)->local_session->clip_title);
1002 fprintf(fp," ASSETS\n");
1005 fprintf(fp," LABELS\n");
1007 fprintf(fp," TRACKS\n");
1009 //printf("EDL::dump 2\n");
1013 EDL* EDL::add_clip(EDL *edl)
1015 // Copy argument. New edls are deleted from MWindow::load_filenames.
1016 EDL *new_edl = new EDL(this);
1017 new_edl->create_objects();
1018 new_edl->copy_all(edl);
1019 clips.append(new_edl);
1023 void EDL::insert_asset(Asset *asset,
1027 RecordLabels *labels)
1029 // Insert asset into asset table
1030 Asset *new_asset = 0;
1031 EDL *new_nested_edl = 0;
1033 if( asset ) new_asset = assets->update(asset);
1034 if( nested_edl ) new_nested_edl = nested_edls.get_copy(nested_edl);
1038 Track *current = first_track ? first_track : tracks->first;
1041 // Fix length of single frame
1046 if( new_nested_edl ) {
1047 length = new_nested_edl->tracks->total_length();
1049 channels = new_nested_edl->session->audio_channels;
1053 // Insert 1 frame for undefined length
1054 if( new_asset->video_length < 0 ) {
1055 length = session->si_useduration ?
1056 session->si_duration :
1057 1.0 / session->frame_rate;
1060 length = new_asset->frame_rate > 0 ?
1061 (double)new_asset->video_length / new_asset->frame_rate :
1062 1.0 / session->frame_rate;
1064 layers = new_asset->layers;
1065 channels = new_asset->channels;
1068 for( ; current && vtrack<layers; current=NEXT ) {
1069 if( !current->record || current->data_type != TRACK_VIDEO ) continue;
1070 current->insert_asset(new_asset, new_nested_edl,
1071 length, position, vtrack++);
1076 if( new_asset->audio_length < 0 ) {
1077 // Insert 1 frame for undefined length & video
1078 if( new_asset->video_data )
1079 length = (double)1.0 / new_asset->frame_rate;
1081 // Insert 1 second for undefined length & no video
1085 length = (double)new_asset->audio_length /
1086 new_asset->sample_rate;
1089 current = tracks->first;
1090 for( ; current && atrack < channels; current=NEXT ) {
1091 if( !current->record || current->data_type != TRACK_AUDIO ) continue;
1092 current->insert_asset(new_asset, new_nested_edl,
1093 length, position, atrack++);
1096 // Insert labels from a recording window.
1098 for( RecordLabel *label=labels->first; label; label=label->next ) {
1099 this->labels->toggle_label(label->position, label->position);
1106 void EDL::set_index_file(Indexable *indexable)
1108 if( indexable->is_asset )
1109 assets->update_index((Asset*)indexable);
1111 nested_edls.update_index((EDL*)indexable);
1114 void EDL::optimize()
1116 //printf("EDL::optimize 1\n");
1117 if( local_session->preview_start < 0 ) local_session->preview_start = 0;
1118 double length = tracks->total_length();
1119 if( local_session->preview_end > length ) local_session->preview_end = length;
1120 if( local_session->preview_start >= local_session->preview_end ) {
1121 local_session->preview_start = 0;
1122 local_session->preview_end = length;
1124 for( Track *current=tracks->first; current; current=NEXT )
1125 current->optimize();
1130 static Mutex id_lock;
1131 id_lock.lock("EDL::next_id");
1132 int result = EDLSession::current_id++;
1137 void EDL::get_shared_plugins(Track *source,
1138 ArrayList<SharedLocation*> *plugin_locations,
1139 int omit_recordable,
1142 for( Track *track=tracks->first; track; track=track->next ) {
1143 if( track->record && omit_recordable ) continue;
1144 if( track == source || track->data_type != data_type ) continue;
1145 for( int i=0; i<track->plugin_set.size(); ++i ) {
1146 Plugin *plugin = track->get_current_plugin(
1147 local_session->get_selectionstart(1),
1148 i, PLAY_FORWARD, 1, 0);
1149 if( plugin && plugin->plugin_type != PLUGIN_STANDALONE ) continue;
1150 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1155 void EDL::get_shared_tracks(Track *track,
1156 ArrayList<SharedLocation*> *module_locations,
1157 int omit_recordable, int data_type)
1159 for( Track *current=tracks->first; current; current=NEXT ) {
1160 if( omit_recordable && current->record ) continue;
1161 if( current == track || current->data_type != data_type ) continue;
1162 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1166 // aligned frame time
1167 double EDL::frame_align(double position, int round)
1169 double frame_pos = position * session->frame_rate;
1170 frame_pos = (int64_t)(frame_pos + (round ? 0.5 : 1e-6));
1171 position = frame_pos / session->frame_rate;
1175 // Convert position to frames if alignment is enabled.
1176 double EDL::align_to_frame(double position, int round)
1178 if( session->cursor_on_frames )
1179 position = frame_align(position, round);
1184 void EDL::new_folder(const char *folder)
1186 for( int i=0; i<folders.size(); ++i )
1187 if( !strcasecmp(folders[i], folder) ) return;
1188 folders.append(cstrdup(folder));
1191 void EDL::delete_folder(const char *folder)
1193 int i = folders.size();
1194 while( --i >= 0 && strcasecmp(folders[i], folder) );
1195 if( i >= 0 ) folders.remove_number(i);
1198 int EDL::get_use_vconsole(VEdit* *playable_edit,
1199 int64_t position, int direction, PlayableTracks *playable_tracks)
1201 int share_playable_tracks = 1;
1203 VTrack *playable_track = 0;
1204 const int debug = 0;
1207 // Calculate playable tracks when being called as a nested EDL
1208 if( !playable_tracks ) {
1209 share_playable_tracks = 0;
1210 playable_tracks = new PlayableTracks(this,
1211 position, direction, TRACK_VIDEO, 1);
1215 // Total number of playable tracks is 1
1216 if( playable_tracks->size() != 1 ) {
1220 playable_track = (VTrack*)playable_tracks->get(0);
1223 // Don't need playable tracks anymore
1224 if( !share_playable_tracks ) {
1225 delete playable_tracks;
1228 if( debug ) printf("EDL::get_use_vconsole %d playable_tracks->size()=%d\n",
1229 __LINE__, playable_tracks->size());
1230 if( result ) return 1;
1233 // Test mutual conditions between direct copy rendering and this.
1234 if( !playable_track->direct_copy_possible(position,
1238 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1240 *playable_edit = (VEdit*)playable_track->edits->editof(position,
1242 // No edit at current location
1243 if( !*playable_edit ) return 1;
1244 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1247 // Edit is nested EDL
1248 if( (*playable_edit)->nested_edl ) {
1250 EDL *nested_edl = (*playable_edit)->nested_edl;
1251 int64_t nested_position = (int64_t)((position -
1252 (*playable_edit)->startproject +
1253 (*playable_edit)->startsource) *
1254 nested_edl->session->frame_rate /
1255 session->frame_rate);
1258 VEdit *playable_edit_temp = 0;
1259 if( session->output_w != nested_edl->session->output_w ||
1260 session->output_h != nested_edl->session->output_h ||
1261 nested_edl->get_use_vconsole(&playable_edit_temp,
1270 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1271 // Edit is not a nested EDL
1272 Asset *asset = (*playable_edit)->asset;
1274 if( !asset ) return 1;
1275 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1277 // Asset and output device must have the same dimensions
1278 if( asset->width != session->output_w ||
1279 asset->height != session->output_h )
1283 if( debug ) printf("EDL::get_use_vconsole %d\n", __LINE__);
1284 // Asset and output device must have same resulting de-interlacing method
1285 if( ilaceautofixmethod2(session->interlace_mode,
1286 asset->interlace_autofixoption, asset->interlace_mode,
1287 asset->interlace_fixmethod) != ILACE_FIXMETHOD_NONE )
1290 // If we get here the frame is going to be directly copied. Whether it is
1291 // decompressed in hardware depends on the colormodel.
1297 int EDL::get_audio_channels()
1299 return session->audio_channels;
1302 int EDL::get_sample_rate()
1304 return session->sample_rate;
1307 int64_t EDL::get_audio_samples()
1309 return (int64_t)(tracks->total_length() *
1310 session->sample_rate);
1313 int EDL::have_audio()
1318 int EDL::have_video()
1326 return session->output_w;
1331 return session->output_h;
1334 double EDL::get_frame_rate()
1336 return session->frame_rate;
1339 int EDL::get_video_layers()
1344 int64_t EDL::get_video_frames()
1346 return (int64_t)(tracks->total_length() *
1347 session->frame_rate);
1351 void EDL::remove_vwindow_edls()
1353 for( int i=0; i<total_vwindow_edls(); ++i ) {
1354 get_vwindow_edl(i)->remove_user();
1356 vwindow_edls.remove_all();
1359 void EDL::remove_vwindow_edl(EDL *edl)
1361 if( vwindow_edls.number_of(edl) >= 0 ) {
1363 vwindow_edls.remove(edl);
1368 EDL* EDL::get_vwindow_edl(int number)
1370 return vwindow_edls.get(number);
1373 int EDL::total_vwindow_edls()
1375 return vwindow_edls.size();
1378 void EDL::append_vwindow_edl(EDL *edl, int increase_counter)
1380 if(vwindow_edls.number_of(edl) >= 0) return;
1382 if(increase_counter) edl->add_user();
1383 vwindow_edls.append(edl);
1387 double EDL::next_edit(double position)
1389 Units::fix_double(&position);
1390 double new_position = tracks->total_length();
1392 double max_rate = get_frame_rate();
1393 int sample_rate = get_sample_rate();
1394 if( sample_rate > max_rate ) max_rate = sample_rate;
1395 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1397 // Test for edit handles after position
1398 for( Track *track=tracks->first; track; track=track->next ) {
1399 if( !track->record ) continue;
1400 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1401 double edit_end = track->from_units(edit->startproject + edit->length);
1402 Units::fix_double(&edit_end);
1403 if( fabs(edit_end-position) < min_movement ) continue;
1404 if( edit_end > position && edit_end < new_position )
1405 new_position = edit_end;
1408 return new_position;
1411 double EDL::prev_edit(double position)
1413 Units::fix_double(&position);
1414 double new_position = -1;
1416 double max_rate = get_frame_rate();
1417 int sample_rate = get_sample_rate();
1418 if( sample_rate > max_rate ) max_rate = sample_rate;
1419 double min_movement = max_rate > 0 ? 1. / max_rate : 1e-6;
1421 // Test for edit handles before cursor position
1422 for( Track *track=tracks->first; track; track=track->next ) {
1423 if( !track->record ) continue;
1424 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1425 double edit_end = track->from_units(edit->startproject);
1426 Units::fix_double(&edit_end);
1427 if( fabs(edit_end-position) < min_movement ) continue;
1428 if( edit_end < position && edit_end > new_position )
1429 new_position = edit_end;
1432 return new_position;