5 #include "automation.h"
6 #include "awindowgui.inc"
9 #include "colormodels.h"
12 #include "edlsession.h"
16 #include "localsession.h"
19 #include "playbackconfig.h"
21 #include "preferences.h"
22 #include "recordconfig.h"
23 #include "recordlabel.h"
24 #include "sharedlocation.h"
27 #include "transportque.inc"
30 EDL::EDL(EDL *parent_edl)
32 this->parent_edl = parent_edl;
37 vwindow_edl_shared = 0;
39 folders.set_array_delete();
40 new_folder(CLIP_FOLDER);
41 new_folder(MEDIA_FOLDER);
49 //printf("EDL::~EDL 1\n");
64 if(vwindow_edl && !vwindow_edl_shared)
74 folders.remove_all_objects();
75 clips.remove_all_objects();
76 //printf("EDL::~EDL 2\n");
80 int EDL::create_objects()
82 tracks = new Tracks(this);
85 assets = new Assets(this);
86 session = new EDLSession(this);
90 assets = parent_edl->assets;
91 session = parent_edl->session;
94 local_session = new LocalSession(this);
95 labels = new Labels(this, "LABELS");
96 // last_playback_position = 0;
100 EDL& EDL::operator=(EDL &edl)
102 printf("EDL::operator= 1\n");
107 int EDL::load_defaults(Defaults *defaults)
110 session->load_defaults(defaults);
112 local_session->load_defaults(defaults);
116 int EDL::save_defaults(Defaults *defaults)
119 session->save_defaults(defaults);
121 local_session->save_defaults(defaults);
125 void EDL::boundaries()
127 session->boundaries();
128 local_session->boundaries();
131 int EDL::create_default_tracks()
134 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++)
140 tracks->add_audio_track(0, 0);
145 int EDL::load_xml(ArrayList<PluginServer*> *plugindb,
150 // Track numbering offset for replacing undo data.
151 int track_offset = 0;
153 folders.remove_all_objects();
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.
166 result = file->read_tag();
168 !file->tag.title_is("XML") &&
169 !file->tag.title_is("EDL"));
174 // Get path for backups
176 file->tag.get_property("PROJECT_PATH", project_path);
179 if((load_flags & LOAD_ALL) == LOAD_ALL ||
180 (load_flags & LOAD_EDITS) == LOAD_EDITS)
182 while(tracks->last) delete tracks->last;
185 if((load_flags & LOAD_ALL) == LOAD_ALL)
187 clips.remove_all_objects();
190 if(load_flags & LOAD_TIMEBAR)
192 while(labels->last) delete labels->last;
193 local_session->unset_inpoint();
194 local_session->unset_outpoint();
198 result = file->read_tag();
202 if(file->tag.title_is("/XML") ||
203 file->tag.title_is("/EDL") ||
204 file->tag.title_is("/CLIP_EDL") ||
205 file->tag.title_is("/VWINDOW_EDL"))
210 if(file->tag.title_is("CLIPBOARD"))
212 local_session->clipboard_length = file->tag.get_property("LENGTH", 0);
215 if(file->tag.title_is("VIDEO"))
217 if((load_flags & LOAD_VCONFIG) &&
218 (load_flags & LOAD_SESSION))
219 session->load_video_config(file, 0, load_flags);
222 if(file->tag.title_is("AUDIO"))
224 if((load_flags & LOAD_ACONFIG) &&
225 (load_flags & LOAD_SESSION))
226 session->load_audio_config(file, 0, load_flags);
229 if(file->tag.title_is("FOLDER"))
231 char folder[BCTEXTLEN];
232 strcpy(folder, file->read_text());
236 if(file->tag.title_is("ASSETS"))
238 if(load_flags & LOAD_ASSETS)
239 assets->load(plugindb, file, load_flags);
242 if(file->tag.title_is(labels->xml_tag))
244 if(load_flags & LOAD_TIMEBAR)
245 labels->load(file, load_flags);
248 if(file->tag.title_is("LOCALSESSION"))
250 if((load_flags & LOAD_SESSION) ||
251 (load_flags & LOAD_TIMEBAR))
252 local_session->load_xml(file, load_flags);
255 if(file->tag.title_is("SESSION"))
257 if((load_flags & LOAD_SESSION) &&
259 session->load_xml(file, 0, load_flags);
262 if(file->tag.title_is("TRACK"))
264 tracks->load(file, track_offset, load_flags);
268 // Causes clip creation to fail because that involves an opening EDL tag.
269 if(file->tag.title_is("CLIP_EDL") && !parent_edl)
271 EDL *new_edl = new EDL(this);
272 new_edl->create_objects();
273 new_edl->load_xml(plugindb, file, LOAD_ALL);
275 if((load_flags & LOAD_ALL) == LOAD_ALL)
276 clips.append(new_edl);
281 if(file->tag.title_is("VWINDOW_EDL") && !parent_edl)
283 EDL *new_edl = new EDL(this);
284 new_edl->create_objects();
285 new_edl->load_xml(plugindb, file, LOAD_ALL);
288 if((load_flags & LOAD_ALL) == LOAD_ALL)
290 if(vwindow_edl && !vwindow_edl_shared) delete vwindow_edl;
291 vwindow_edl = new_edl;
292 vwindow_edl_shared = 0;
302 //printf("EDL::load_xml 4\n");
305 //printf("EDL::load_xml 6 %p\n", parent_edl);
311 // Output path is the path of the output file if name truncation is desired.
312 // It is a "" if complete names should be used.
313 // Called recursively by copy for clips, thus the string can't be terminated.
314 // The string is not terminated in this call.
315 int EDL::save_xml(ArrayList<PluginServer*> *plugindb,
322 tracks->total_length(),
333 int EDL::copy_all(EDL *edl)
338 tracks->copy_from(edl->tracks);
339 labels->copy_from(edl->labels);
343 void EDL::copy_clips(EDL *edl)
345 if(vwindow_edl && !vwindow_edl_shared) delete vwindow_edl;
347 vwindow_edl_shared = 0;
350 vwindow_edl = new EDL(this);
351 vwindow_edl->create_objects();
352 vwindow_edl->copy_all(edl->vwindow_edl);
354 clips.remove_all_objects();
355 for(int i = 0; i < edl->clips.total; i++)
357 add_clip(edl->clips.values[i]);
361 void EDL::copy_assets(EDL *edl)
365 assets->copy_from(edl->assets);
369 void EDL::copy_session(EDL *edl)
371 strcpy(this->project_path, edl->project_path);
373 folders.remove_all_objects();
374 for(int i = 0; i < edl->folders.total; i++)
377 folders.append(new_folder = new char[strlen(edl->folders.values[i]) + 1]);
378 strcpy(new_folder, edl->folders.values[i]);
383 session->copy(edl->session);
386 local_session->copy_from(edl->local_session);
389 int EDL::copy_assets(double start,
393 ArrayList<PluginServer*> *plugindb,
396 ArrayList<Asset*> asset_list;
399 file->tag.set_title("ASSETS");
401 file->append_newline();
403 // Copy everything for a save
406 for(Asset *asset = assets->first;
410 asset_list.append(asset);
414 // Copy just the ones being used.
416 for(current = tracks->first;
422 current->copy_assets(start,
429 // Paths relativised here
430 for(int i = 0; i < asset_list.total; i++)
432 asset_list.values[i]->write(file,
437 file->tag.set_title("/ASSETS");
439 file->append_newline();
440 file->append_newline();
444 int EDL::copy(double start,
450 ArrayList<PluginServer*> *plugindb,
454 //printf("EDL::copy 1\n");
457 file->tag.set_title("CLIP_EDL");
460 file->tag.set_title("VWINDOW_EDL");
463 file->tag.set_title("EDL");
464 file->tag.set_property("VERSION", CINELERRA_VERSION);
465 // Save path for restoration of the project title from a backup.
466 if(this->project_path[0])
468 file->tag.set_property("PROJECT_PATH", project_path);
473 file->append_newline();
475 // Set clipboard samples only if copying to clipboard
478 file->tag.set_title("CLIPBOARD");
479 file->tag.set_property("LENGTH", end - start);
481 file->tag.set_title("/CLIPBOARD");
483 file->append_newline();
484 file->append_newline();
486 //printf("EDL::copy 1\n");
489 local_session->save_xml(file, start);
491 //printf("EDL::copy 1\n");
496 // Need to copy all this from child EDL if pasting is desired.
498 session->save_xml(file);
499 session->save_video_config(file);
500 session->save_audio_config(file);
503 for(int i = 0; i < folders.total; i++)
505 file->tag.set_title("FOLDER");
507 file->append_text(folders.values[i]);
508 file->tag.set_title("/FOLDER");
510 file->append_newline();
523 // Don't want this if using clipboard
529 vwindow_edl->save_xml(plugindb,
536 for(int i = 0; i < clips.total; i++)
537 clips.values[i]->save_xml(plugindb,
544 file->append_newline();
545 file->append_newline();
549 //printf("EDL::copy 1\n");
551 labels->copy(start, end, file);
552 //printf("EDL::copy 1\n");
553 tracks->copy(start, end, all, file, output_path);
554 //printf("EDL::copy 2\n");
558 file->tag.set_title("/CLIP_EDL");
561 file->tag.set_title("/VWINDOW_EDL");
563 file->tag.set_title("/EDL");
565 file->append_newline();
568 // For editing operations we want to rewind it for immediate pasting.
569 // For clips and saving to disk leave it alone.
572 file->terminate_string();
578 void EDL::rechannel()
580 for(Track *current = tracks->first; current; current = NEXT)
582 if(current->data_type == TRACK_AUDIO)
584 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
585 ((PanAuto*)autos->default_auto)->rechannel();
586 for(PanAuto *keyframe = (PanAuto*)autos->first;
588 keyframe = (PanAuto*)keyframe->next)
590 keyframe->rechannel();
596 void EDL::resample(double old_rate, double new_rate, int data_type)
598 for(Track *current = tracks->first; current; current = NEXT)
600 if(current->data_type == data_type)
602 current->resample(old_rate, new_rate);
608 void EDL::synchronize_params(EDL *edl)
610 local_session->synchronize_params(edl->local_session);
611 for(Track *this_track = tracks->first, *that_track = edl->tracks->first;
612 this_track && that_track;
613 this_track = this_track->next,
614 that_track = that_track->next)
616 this_track->synchronize_params(that_track);
620 int EDL::trim_selection(double start,
633 tracks->total_length(),
641 int EDL::equivalent(double position1, double position2)
643 double threshold = (double).5 / session->frame_rate;
644 if(session->cursor_on_frames)
645 threshold = (double).5 / session->frame_rate;
647 threshold = (double)1 / session->sample_rate;
649 if(fabs(position2 - position1) < threshold)
655 double EDL::equivalent_output(EDL *edl)
658 session->equivalent_output(edl->session, &result);
659 tracks->equivalent_output(edl->tracks, &result);
664 void EDL::set_project_path(char *path)
666 strcpy(this->project_path, path);
669 void EDL::set_inpoint(double position)
671 if(equivalent(local_session->get_inpoint(), position) &&
672 local_session->get_inpoint() >= 0)
674 local_session->unset_inpoint();
678 local_session->set_inpoint(align_to_frame(position, 0));
679 if(local_session->get_outpoint() <= local_session->get_inpoint())
680 local_session->unset_outpoint();
684 void EDL::set_outpoint(double position)
686 if(equivalent(local_session->get_outpoint(), position) &&
687 local_session->get_outpoint() >= 0)
689 local_session->unset_outpoint();
693 local_session->set_outpoint(align_to_frame(position, 0));
694 if(local_session->get_inpoint() >= local_session->get_outpoint())
695 local_session->unset_inpoint();
700 int EDL::clear(double start,
708 tracks->clear_handle(start,
713 if(clear_labels && distance > 0)
714 labels->paste_silence(start,
728 // Need to put at beginning so a subsequent paste operation starts at the
730 double position = local_session->get_selectionstart();
731 local_session->set_selectionend(position);
732 local_session->set_selectionstart(position);
736 void EDL::modify_edithandles(double oldposition,
743 tracks->modify_edithandles(oldposition,
749 labels->modify_handles(oldposition,
756 void EDL::modify_pluginhandles(double oldposition,
763 tracks->modify_pluginhandles(oldposition,
772 void EDL::paste_silence(double start,
778 labels->paste_silence(start, end);
779 tracks->paste_silence(start,
785 void EDL::remove_from_project(ArrayList<EDL*> *clips)
787 for(int i = 0; i < clips->total; i++)
789 for(int j = 0; j < this->clips.total; j++)
791 if(this->clips.values[j] == clips->values[i])
793 this->clips.remove_object(clips->values[i]);
799 void EDL::remove_from_project(ArrayList<Asset*> *assets)
803 for(int j = 0; j < clips.total; j++)
805 clips.values[j]->remove_from_project(assets);
808 // Remove from VWindow
810 vwindow_edl->remove_from_project(assets);
812 for(int i = 0; i < assets->total; i++)
814 // Remove from tracks
815 for(Track *track = tracks->first; track; track = track->next)
817 track->remove_asset(assets->values[i]);
820 // Remove from assets
823 this->assets->remove_asset(assets->values[i]);
828 void EDL::update_assets(EDL *src)
830 for(Asset *current = src->assets->first;
834 assets->update(current);
838 int EDL::get_tracks_height(Theme *theme)
840 int total_pixels = 0;
841 for(Track *current = tracks->first;
845 total_pixels += current->vertical_span(theme);
850 int64_t EDL::get_tracks_width()
852 int64_t total_pixels = 0;
853 for(Track *current = tracks->first;
857 int64_t pixels = current->horizontal_span();
858 if(pixels > total_pixels) total_pixels = pixels;
860 //printf("EDL::get_tracks_width %d\n", total_pixels);
864 // int EDL::calculate_output_w(int single_channel)
866 // if(single_channel) return session->output_w;
869 // for(int i = 0; i < session->video_channels; i++)
871 // if(session->vchannel_x[i] + session->output_w > widest) widest = session->vchannel_x[i] + session->output_w;
876 // int EDL::calculate_output_h(int single_channel)
878 // if(single_channel) return session->output_h;
881 // for(int i = 0; i < session->video_channels; i++)
883 // if(session->vchannel_y[i] + session->output_h > tallest) tallest = session->vchannel_y[i] + session->output_h;
888 // Get the total output size scaled to aspect ratio
889 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
891 w = session->output_w;
892 h = session->output_h;
894 if((float)session->output_w / session->output_h > get_aspect_ratio())
897 (session->output_w / get_aspect_ratio() / session->output_h);
902 (h * get_aspect_ratio() / session->output_w);
906 float EDL::get_aspect_ratio()
908 return session->aspect_w / session->aspect_h;
917 printf("clip_title: %s parent_edl: %p\n", local_session->clip_title, parent_edl);
918 printf("selectionstart %f selectionend %f loop_start %f loop_end %f\n",
919 local_session->get_selectionstart(1),
920 local_session->get_selectionend(1),
921 local_session->loop_start,
922 local_session->loop_end);
926 printf("audio_channels: %d "
927 "audio_tracks: %d \n"
929 session->audio_channels,
930 session->audio_tracks,
931 session->sample_rate);
932 printf("video_channels: %d "
935 "frames_per_foot: %.2f\n"
941 session->video_channels,
942 session->video_tracks,
944 session->frames_per_foot,
949 session->color_model);
952 printf(" total: %d\n", clips.total);
954 for(int i = 0; i < clips.total; i++)
957 clips.values[i]->dump();
968 //printf("EDL::dump 2\n");
972 EDL* EDL::add_clip(EDL *edl)
974 // Copy argument. New edls are deleted from MWindow::load_filenames.
975 EDL *new_edl = new EDL(this);
976 new_edl->create_objects();
977 new_edl->copy_all(edl);
978 clips.append(new_edl);
982 void EDL::insert_asset(Asset *asset,
985 RecordLabels *labels)
987 // Insert asset into asset table
988 Asset *new_asset = assets->update(asset);
993 Track *current = first_track ? first_track : tracks->first;
996 // Fix length of single frame
1000 if(new_asset->video_length < 0)
1002 if(session->si_useduration)
1003 length = session->si_duration;
1005 length = 1.0 / session->frame_rate;
1008 if(new_asset->frame_rate > 0)
1009 length = ((double)new_asset->video_length / new_asset->frame_rate);
1011 length = 1.0 / session->frame_rate;
1014 current && vtrack < new_asset->layers;
1017 if(!current->record ||
1018 current->data_type != TRACK_VIDEO)
1021 current->insert_asset(new_asset,
1030 for(current = tracks->first;
1031 current && atrack < new_asset->channels;
1034 if(!current->record ||
1035 current->data_type != TRACK_AUDIO)
1038 current->insert_asset(new_asset,
1039 (double)new_asset->audio_length /
1040 new_asset->sample_rate,
1050 for(RecordLabel *label = labels->first; label; label = label->next)
1052 this->labels->toggle_label(label->position, label->position);
1059 void EDL::set_index_file(Asset *asset)
1061 assets->update_index(asset);
1064 void EDL::optimize()
1066 //printf("EDL::optimize 1\n");
1067 double length = tracks->total_length();
1068 if(local_session->preview_end > length) local_session->preview_end = length;
1069 if(local_session->preview_start > length ||
1070 local_session->preview_start < 0) local_session->preview_start = 0;
1071 for(Track *current = tracks->first; current; current = NEXT)
1072 current->optimize();
1077 return EDLSession::current_id++;
1080 void EDL::get_shared_plugins(Track *source,
1081 ArrayList<SharedLocation*> *plugin_locations)
1083 for(Track *track = tracks->first; track; track = track->next)
1085 if(track != source &&
1086 track->data_type == source->data_type)
1088 for(int i = 0; i < track->plugin_set.total; i++)
1090 Plugin *plugin = track->get_current_plugin(
1091 local_session->get_selectionstart(1),
1096 if(plugin && plugin->plugin_type == PLUGIN_STANDALONE)
1098 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1105 void EDL::get_shared_tracks(Track *track, ArrayList<SharedLocation*> *module_locations)
1107 for(Track *current = tracks->first; current; current = NEXT)
1109 if(current != track &&
1110 current->data_type == track->data_type)
1112 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1117 // Convert position to frames if cursor alignment is enabled
1118 double EDL::align_to_frame(double position, int round)
1120 //printf("EDL::align_to_frame 1 %f\n", position);
1121 if(session->cursor_on_frames)
1123 // Seconds -> Frames
1124 double temp = (double)position * session->frame_rate;
1125 //printf("EDL::align_to_frame 2 %f\n", temp);
1127 // Assert some things
1128 if(session->sample_rate == 0)
1129 printf("EDL::align_to_frame: sample_rate == 0\n");
1131 if(session->frame_rate == 0)
1132 printf("EDL::align_to_frame: frame_rate == 0\n");
1135 // Always round down negative numbers
1136 // but round up only if requested
1139 temp = Units::round(temp);
1148 temp = Units::to_int64(temp);
1150 //printf("EDL::align_to_frame 3 %f\n", temp);
1152 // Frames -> Seconds
1153 temp /= session->frame_rate;
1155 //printf("EDL::align_to_frame 5 %f\n", temp);
1159 //printf("EDL::align_to_frame 3 %d\n", position);
1166 void EDL::new_folder(char *folder)
1168 for(int i = 0; i < folders.total; i++)
1170 if(!strcasecmp(folders.values[i], folder)) return;
1174 folders.append(new_folder = new char[strlen(folder) + 1]);
1175 strcpy(new_folder, folder);
1178 void EDL::delete_folder(char *folder)
1181 for(i = 0; i < folders.total; i++)
1183 if(!strcasecmp(folders.values[i], folder))
1189 if(i < folders.total) delete folders.values[i];
1191 for( ; i < folders.total - 1; i++)
1193 folders.values[i] = folders.values[i + 1];